0/**********************************************************************************************
1*
2* rcore_<platform> template - Functions to manage window, graphics device and inputs
3*
4* PLATFORM: <PLATFORM>
5* - TODO: Define the target platform for the core
6*
7* LIMITATIONS:
8* - Limitation 01
9* - Limitation 02
10*
11* POSSIBLE IMPROVEMENTS:
12* - Improvement 01
13* - Improvement 02
14*
15* ADDITIONAL NOTES:
16* - TRACELOG() function is located in raylib [utils] module
17*
18* CONFIGURATION:
19* #define RCORE_PLATFORM_CUSTOM_FLAG
20* Custom flag for rcore on target platform -not used-
21*
22* DEPENDENCIES:
23* - <platform-specific SDK dependency>
24* - gestures: Gestures system for touch-ready devices (or simulated from mouse inputs)
25*
26*
27* LICENSE: zlib/libpng
28*
29* Copyright (c) 2013-2025 Ramon Santamaria (@raysan5) and contributors
30*
31* This software is provided "as-is", without any express or implied warranty. In no event
32* will the authors be held liable for any damages arising from the use of this software.
33*
34* Permission is granted to anyone to use this software for any purpose, including commercial
35* applications, and to alter it and redistribute it freely, subject to the following restrictions:
36*
37* 1. The origin of this software must not be misrepresented; you must not claim that you
38* wrote the original software. If you use this software in a product, an acknowledgment
39* in the product documentation would be appreciated but is not required.
40*
41* 2. Altered source versions must be plainly marked as such, and must not be misrepresented
42* as being the original software.
43*
44* 3. This notice may not be removed or altered from any source distribution.
45*
46**********************************************************************************************/
48// TODO: Include the platform specific libraries
50//----------------------------------------------------------------------------------
51// Types and Structures Definition
52//----------------------------------------------------------------------------------
53typedef struct {
54 // TODO: Define the platform specific variables required
56} PlatformData;
58//----------------------------------------------------------------------------------
59// Global Variables Definition
60//----------------------------------------------------------------------------------
61extern CoreData CORE; // Global CORE state context
63static PlatformData platform = { 0 }; // Platform specific data
65//----------------------------------------------------------------------------------
66// Module Internal Functions Declaration
67//----------------------------------------------------------------------------------
68int InitPlatform(void); // Initialize platform (graphics, inputs and more)
69bool InitGraphicsDevice(void); // Initialize graphics device
71//----------------------------------------------------------------------------------
72// Module Functions Declaration
73//----------------------------------------------------------------------------------
74// NOTE: Functions declaration is provided by raylib.h
76//----------------------------------------------------------------------------------
77// Module Functions Definition: Window and Graphics Device
78//----------------------------------------------------------------------------------
80// Check if application should close
81bool WindowShouldClose(void)
82{
83 if (CORE.Window.ready) return CORE.Window.shouldClose;
84 else return true;
85}
87// Toggle fullscreen mode
88void ToggleFullscreen(void)
89{
90 TRACELOG(LOG_WARNING, "ToggleFullscreen() not available on target platform");
91}
93// Toggle borderless windowed mode
94void ToggleBorderlessWindowed(void)
95{
96 TRACELOG(LOG_WARNING, "ToggleBorderlessWindowed() not available on target platform");
97}
99// Set window state: maximized, if resizable
100void MaximizeWindow(void)
101{
102 TRACELOG(LOG_WARNING, "MaximizeWindow() not available on target platform");
103}
105// Set window state: minimized
106void MinimizeWindow(void)
107{
108 TRACELOG(LOG_WARNING, "MinimizeWindow() not available on target platform");
109}
111// Restore window from being minimized/maximized
112void RestoreWindow(void)
113{
114 TRACELOG(LOG_WARNING, "RestoreWindow() not available on target platform");
115}
117// Set window configuration state using flags
118void SetWindowState(unsigned int flags)
119{
120 TRACELOG(LOG_WARNING, "SetWindowState() not available on target platform");
121}
123// Clear window configuration state flags
124void ClearWindowState(unsigned int flags)
125{
126 TRACELOG(LOG_WARNING, "ClearWindowState() not available on target platform");
127}
129// Set icon for window
130void SetWindowIcon(Image image)
131{
132 TRACELOG(LOG_WARNING, "SetWindowIcon() not available on target platform");
133}
135// Set icon for window
136void SetWindowIcons(Image *images, int count)
137{
138 TRACELOG(LOG_WARNING, "SetWindowIcons() not available on target platform");
139}
141// Set title for window
142void SetWindowTitle(const char *title)
143{
144 CORE.Window.title = title;
145}
147// Set window position on screen (windowed mode)
148void SetWindowPosition(int x, int y)
149{
150 TRACELOG(LOG_WARNING, "SetWindowPosition() not available on target platform");
151}
153// Set monitor for the current window
154void SetWindowMonitor(int monitor)
155{
156 TRACELOG(LOG_WARNING, "SetWindowMonitor() not available on target platform");
157}
159// Set window minimum dimensions (FLAG_WINDOW_RESIZABLE)
160void SetWindowMinSize(int width, int height)
161{
162 CORE.Window.screenMin.width = width;
163 CORE.Window.screenMin.height = height;
164}
166// Set window maximum dimensions (FLAG_WINDOW_RESIZABLE)
167void SetWindowMaxSize(int width, int height)
168{
169 CORE.Window.screenMax.width = width;
170 CORE.Window.screenMax.height = height;
171}
173// Set window dimensions
174void SetWindowSize(int width, int height)
175{
176 TRACELOG(LOG_WARNING, "SetWindowSize() not available on target platform");
177}
179// Set window opacity, value opacity is between 0.0 and 1.0
180void SetWindowOpacity(float opacity)
181{
182 TRACELOG(LOG_WARNING, "SetWindowOpacity() not available on target platform");
183}
185// Set window focused
186void SetWindowFocused(void)
187{
188 TRACELOG(LOG_WARNING, "SetWindowFocused() not available on target platform");
189}
191// Get native window handle
192void *GetWindowHandle(void)
193{
194 TRACELOG(LOG_WARNING, "GetWindowHandle() not implemented on target platform");
195 return NULL;
196}
198// Get number of monitors
199int GetMonitorCount(void)
200{
201 TRACELOG(LOG_WARNING, "GetMonitorCount() not implemented on target platform");
202 return 1;
203}
205// Get current monitor where window is placed
206int GetCurrentMonitor(void)
207{
208 TRACELOG(LOG_WARNING, "GetCurrentMonitor() not implemented on target platform");
209 return 0;
210}
212// Get selected monitor position
213Vector2 GetMonitorPosition(int monitor)
214{
215 TRACELOG(LOG_WARNING, "GetMonitorPosition() not implemented on target platform");
216 return (Vector2){ 0, 0 };
217}
219// Get selected monitor width (currently used by monitor)
220int GetMonitorWidth(int monitor)
221{
222 TRACELOG(LOG_WARNING, "GetMonitorWidth() not implemented on target platform");
223 return 0;
224}
226// Get selected monitor height (currently used by monitor)
227int GetMonitorHeight(int monitor)
228{
229 TRACELOG(LOG_WARNING, "GetMonitorHeight() not implemented on target platform");
230 return 0;
231}
233// Get selected monitor physical width in millimetres
234int GetMonitorPhysicalWidth(int monitor)
235{
236 TRACELOG(LOG_WARNING, "GetMonitorPhysicalWidth() not implemented on target platform");
237 return 0;
238}
240// Get selected monitor physical height in millimetres
241int GetMonitorPhysicalHeight(int monitor)
242{
243 TRACELOG(LOG_WARNING, "GetMonitorPhysicalHeight() not implemented on target platform");
244 return 0;
245}
247// Get selected monitor refresh rate
248int GetMonitorRefreshRate(int monitor)
249{
250 TRACELOG(LOG_WARNING, "GetMonitorRefreshRate() not implemented on target platform");
251 return 0;
252}
254// Get the human-readable, UTF-8 encoded name of the selected monitor
255const char *GetMonitorName(int monitor)
256{
257 TRACELOG(LOG_WARNING, "GetMonitorName() not implemented on target platform");
258 return "";
259}
261// Get window position XY on monitor
262Vector2 GetWindowPosition(void)
263{
264 TRACELOG(LOG_WARNING, "GetWindowPosition() not implemented on target platform");
265 return (Vector2){ 0, 0 };
266}
268// Get window scale DPI factor for current monitor
269Vector2 GetWindowScaleDPI(void)
270{
271 TRACELOG(LOG_WARNING, "GetWindowScaleDPI() not implemented on target platform");
272 return (Vector2){ 1.0f, 1.0f };
273}
275// Set clipboard text content
276void SetClipboardText(const char *text)
277{
278 TRACELOG(LOG_WARNING, "SetClipboardText() not implemented on target platform");
279}
281// Get clipboard text content
282// NOTE: returned string is allocated and freed by GLFW
283const char *GetClipboardText(void)
284{
285 TRACELOG(LOG_WARNING, "GetClipboardText() not implemented on target platform");
286 return NULL;
287}
289// Get clipboard image
290Image GetClipboardImage(void)
291{
292 Image image = { 0 };
294 TRACELOG(LOG_WARNING, "GetClipboardImage() not implemented on target platform");
296 return image;
297}
299// Show mouse cursor
300void ShowCursor(void)
301{
302 CORE.Input.Mouse.cursorHidden = false;
303}
305// Hides mouse cursor
306void HideCursor(void)
307{
308 CORE.Input.Mouse.cursorHidden = true;
309}
311// Enables cursor (unlock cursor)
312void EnableCursor(void)
313{
314 // Set cursor position in the middle
315 SetMousePosition(CORE.Window.screen.width/2, CORE.Window.screen.height/2);
317 CORE.Input.Mouse.cursorHidden = false;
318}
320// Disables cursor (lock cursor)
321void DisableCursor(void)
322{
323 // Set cursor position in the middle
324 SetMousePosition(CORE.Window.screen.width/2, CORE.Window.screen.height/2);
326 CORE.Input.Mouse.cursorHidden = true;
327}
329// Swap back buffer with front buffer (screen drawing)
330void SwapScreenBuffer(void)
331{
332 eglSwapBuffers(platform.device, platform.surface);
333}
335//----------------------------------------------------------------------------------
336// Module Functions Definition: Misc
337//----------------------------------------------------------------------------------
339// Get elapsed time measure in seconds since InitTimer()
340double GetTime(void)
341{
342 double time = 0.0;
344 struct timespec ts = { 0 };
345 clock_gettime(CLOCK_MONOTONIC, &ts);
346 unsigned long long int nanoSeconds = (unsigned long long int)ts.tv_sec*1000000000LLU + (unsigned long long int)ts.tv_nsec;
347 time = (double)(nanoSeconds - CORE.Time.base)*1e-9; // Elapsed time since InitTimer()
349 return time;
350}
352// Open URL with default system browser (if available)
353// NOTE: This function is only safe to use if you control the URL given.
354// A user could craft a malicious string performing another action.
355// Only call this function yourself not with user input or make sure to check the string yourself.
356// Ref: https://github.com/raysan5/raylib/issues/686
357void OpenURL(const char *url)
358{
359 // Security check to (partially) avoid malicious code on target platform
360 if (strchr(url, '\'') != NULL) TRACELOG(LOG_WARNING, "SYSTEM: Provided URL could be potentially malicious, avoid [\'] character");
361 else
362 {
363 // TODO: Load url using default browser
364 }
365}
367//----------------------------------------------------------------------------------
368// Module Functions Definition: Inputs
369//----------------------------------------------------------------------------------
371// Set internal gamepad mappings
372int SetGamepadMappings(const char *mappings)
373{
374 TRACELOG(LOG_WARNING, "SetGamepadMappings() not implemented on target platform");
375 return 0;
376}
378// Set gamepad vibration
379void SetGamepadVibration(int gamepad, float leftMotor, float rightMotor, float duration)
380{
381 TRACELOG(LOG_WARNING, "SetGamepadVibration() not implemented on target platform");
382}
384// Set mouse position XY
385void SetMousePosition(int x, int y)
386{
387 CORE.Input.Mouse.currentPosition = (Vector2){ (float)x, (float)y };
388 CORE.Input.Mouse.previousPosition = CORE.Input.Mouse.currentPosition;
389}
391// Set mouse cursor
392void SetMouseCursor(int cursor)
393{
394 TRACELOG(LOG_WARNING, "SetMouseCursor() not implemented on target platform");
395}
397// Get physical key name.
398const char *GetKeyName(int key)
399{
400 TRACELOG(LOG_WARNING, "GetKeyName() not implemented on target platform");
401 return "";
402}
404// Register all input events
405void PollInputEvents(void)
406{
407#if defined(SUPPORT_GESTURES_SYSTEM)
408 // NOTE: Gestures update must be called every frame to reset gestures correctly
409 // because ProcessGestureEvent() is just called on an event, not every frame
410 UpdateGestures();
411#endif
413 // Reset keys/chars pressed registered
414 CORE.Input.Keyboard.keyPressedQueueCount = 0;
415 CORE.Input.Keyboard.charPressedQueueCount = 0;
417 // Reset key repeats
418 for (int i = 0; i < MAX_KEYBOARD_KEYS; i++) CORE.Input.Keyboard.keyRepeatInFrame[i] = 0;
420 // Reset last gamepad button/axis registered state
421 CORE.Input.Gamepad.lastButtonPressed = 0; // GAMEPAD_BUTTON_UNKNOWN
422 //CORE.Input.Gamepad.axisCount = 0;
424 // Register previous touch states
425 for (int i = 0; i < MAX_TOUCH_POINTS; i++) CORE.Input.Touch.previousTouchState[i] = CORE.Input.Touch.currentTouchState[i];
427 // Reset touch positions
428 // TODO: It resets on target platform the mouse position and not filled again until a move-event,
429 // so, if mouse is not moved it returns a (0, 0) position... this behaviour should be reviewed!
430 //for (int i = 0; i < MAX_TOUCH_POINTS; i++) CORE.Input.Touch.position[i] = (Vector2){ 0, 0 };
432 // Register previous keys states
433 // NOTE: Android supports up to 260 keys
434 for (int i = 0; i < 260; i++)
435 {
436 CORE.Input.Keyboard.previousKeyState[i] = CORE.Input.Keyboard.currentKeyState[i];
437 CORE.Input.Keyboard.keyRepeatInFrame[i] = 0;
438 }
440 // TODO: Poll input events for current platform
441}
443//----------------------------------------------------------------------------------
444// Module Internal Functions Definition
445//----------------------------------------------------------------------------------
447// Initialize platform: graphics, inputs and more
448int InitPlatform(void)
449{
450 // TODO: Initialize graphic device: display/window
451 // It usually requires setting up the platform display system configuration
452 // and connexion with the GPU through some system graphic API
453 // raylib uses OpenGL so, platform should create that kind of connection
454 // Below example illustrates that process using EGL library
455 //----------------------------------------------------------------------------
456 FLAG_SET(CORE.Window.flags, FLAG_FULLSCREEN_MODE);
458 if (FLAG_IS_SET(CORE.Window.flags, FLAG_MSAA_4X_HINT))
459 {
460 // TODO: Enable MSAA
462 TRACELOG(LOG_INFO, "DISPLAY: Trying to enable MSAA x4");
463 }
465 // TODO: Init display and graphic device
467 // TODO: Check display, device and context activation
468 bool result = true;
469 if (result)
470 {
471 CORE.Window.ready = true;
473 CORE.Window.render.width = CORE.Window.screen.width;
474 CORE.Window.render.height = CORE.Window.screen.height;
475 CORE.Window.currentFbo.width = CORE.Window.render.width;
476 CORE.Window.currentFbo.height = CORE.Window.render.height;
478 TRACELOG(LOG_INFO, "DISPLAY: Device initialized successfully");
479 TRACELOG(LOG_INFO, " > Display size: %i x %i", CORE.Window.display.width, CORE.Window.display.height);
480 TRACELOG(LOG_INFO, " > Screen size: %i x %i", CORE.Window.screen.width, CORE.Window.screen.height);
481 TRACELOG(LOG_INFO, " > Render size: %i x %i", CORE.Window.render.width, CORE.Window.render.height);
482 TRACELOG(LOG_INFO, " > Viewport offsets: %i, %i", CORE.Window.renderOffset.x, CORE.Window.renderOffset.y);
483 }
484 else
485 {
486 TRACELOG(LOG_FATAL, "PLATFORM: Failed to initialize graphics device");
487 return -1;
488 }
489 //----------------------------------------------------------------------------
491 // If everything work as expected, we can continue
492 CORE.Window.render.width = CORE.Window.screen.width;
493 CORE.Window.render.height = CORE.Window.screen.height;
494 CORE.Window.currentFbo.width = CORE.Window.render.width;
495 CORE.Window.currentFbo.height = CORE.Window.render.height;
497 TRACELOG(LOG_INFO, "DISPLAY: Device initialized successfully");
498 TRACELOG(LOG_INFO, " > Display size: %i x %i", CORE.Window.display.width, CORE.Window.display.height);
499 TRACELOG(LOG_INFO, " > Screen size: %i x %i", CORE.Window.screen.width, CORE.Window.screen.height);
500 TRACELOG(LOG_INFO, " > Render size: %i x %i", CORE.Window.render.width, CORE.Window.render.height);
501 TRACELOG(LOG_INFO, " > Viewport offsets: %i, %i", CORE.Window.renderOffset.x, CORE.Window.renderOffset.y);
503 // TODO: Load OpenGL extensions
504 // NOTE: GL procedures address loader is required to load extensions
505 //----------------------------------------------------------------------------
506 rlLoadExtensions(eglGetProcAddress);
507 //----------------------------------------------------------------------------
509 // TODO: Initialize input events system
510 // It could imply keyboard, mouse, gamepad, touch...
511 // Depending on the platform libraries/SDK it could use a callback mechanism
512 // For system events and inputs evens polling on a per-frame basis, use PollInputEvents()
513 //----------------------------------------------------------------------------
514 // ...
515 //----------------------------------------------------------------------------
517 // TODO: Initialize timing system
518 //----------------------------------------------------------------------------
519 InitTimer();
520 //----------------------------------------------------------------------------
522 // TODO: Initialize storage system
523 //----------------------------------------------------------------------------
524 CORE.Storage.basePath = GetWorkingDirectory();
525 //----------------------------------------------------------------------------
527 TRACELOG(LOG_INFO, "PLATFORM: CUSTOM: Initialized successfully");
529 return 0;
530}
532// Close platform
533void ClosePlatform(void)
534{
535 // TODO: De-initialize graphics, inputs and more
536}
538// EOF
index : raylib-jai
---