| 1 | /********************************************************************************************** |
| 2 | * |
| 3 | * raylib.utils - Some common utility functions |
| 4 | * |
| 5 | * |
| 6 | * LICENSE: zlib/libpng |
| 7 | * |
| 8 | * Copyright (c) 2014-2020 Ramon Santamaria (@raysan5) |
| 9 | * |
| 10 | * This software is provided "as-is", without any express or implied warranty. In no event |
| 11 | * will the authors be held liable for any damages arising from the use of this software. |
| 12 | * |
| 13 | * Permission is granted to anyone to use this software for any purpose, including commercial |
| 14 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: |
| 15 | * |
| 16 | * 1. The origin of this software must not be misrepresented; you must not claim that you |
| 17 | * wrote the original software. If you use this software in a product, an acknowledgment |
| 18 | * in the product documentation would be appreciated but is not required. |
| 19 | * |
| 20 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented |
| 21 | * as being the original software. |
| 22 | * |
| 23 | * 3. This notice may not be removed or altered from any source distribution. |
| 24 | * |
| 25 | **********************************************************************************************/ |
| 26 | |
| 27 | #ifndef UTILS_H |
| 28 | #define UTILS_H |
| 29 | |
| 30 | #if defined(PLATFORM_ANDROID) |
| 31 | #include <stdio.h> // Required for: FILE |
| 32 | #include <android/asset_manager.h> // Required for: AAssetManager |
| 33 | #endif |
| 34 | |
| 35 | #if defined(SUPPORT_TRACELOG) |
| 36 | #define TRACELOG(level, ...) TraceLog(level, __VA_ARGS__) |
| 37 | |
| 38 | #if defined(SUPPORT_TRACELOG_DEBUG) |
| 39 | #define TRACELOGD(...) TraceLog(LOG_DEBUG, __VA_ARGS__) |
| 40 | #else |
| 41 | #define TRACELOGD(...) (void)0 |
| 42 | #endif |
| 43 | #else |
| 44 | #define TRACELOG(level, ...) (void)0 |
| 45 | #define TRACELOGD(...) (void)0 |
| 46 | #endif |
| 47 | |
| 48 | //---------------------------------------------------------------------------------- |
| 49 | // Some basic Defines |
| 50 | //---------------------------------------------------------------------------------- |
| 51 | #if defined(PLATFORM_ANDROID) |
| 52 | #define fopen(name, mode) android_fopen(name, mode) |
| 53 | #endif |
| 54 | |
| 55 | //---------------------------------------------------------------------------------- |
| 56 | // Types and Structures Definition |
| 57 | //---------------------------------------------------------------------------------- |
| 58 | #ifdef __cplusplus |
| 59 | extern "C" { // Prevents name mangling of functions |
| 60 | #endif |
| 61 | |
| 62 | //---------------------------------------------------------------------------------- |
| 63 | // Global Variables Definition |
| 64 | //---------------------------------------------------------------------------------- |
| 65 | // Nop... |
| 66 | |
| 67 | //---------------------------------------------------------------------------------- |
| 68 | // Module Functions Declaration |
| 69 | //---------------------------------------------------------------------------------- |
| 70 | #if defined(PLATFORM_ANDROID) |
| 71 | void InitAssetManager(AAssetManager *manager, const char *dataPath); // Initialize asset manager from android app |
| 72 | FILE *android_fopen(const char *fileName, const char *mode); // Replacement for fopen() -> Read-only! |
| 73 | #endif |
| 74 | |
| 75 | #if defined(PLATFORM_UWP) |
| 76 | // UWP Messages System |
| 77 | typedef enum { |
| 78 | UWP_MSG_NONE = 0, |
| 79 | |
| 80 | // Send |
| 81 | UWP_MSG_SHOW_MOUSE, |
| 82 | UWP_MSG_HIDE_MOUSE, |
| 83 | UWP_MSG_LOCK_MOUSE, |
| 84 | UWP_MSG_UNLOCK_MOUSE, |
| 85 | UWP_MSG_SET_MOUSE_LOCATION, // paramVector0 (pos) |
| 86 | |
| 87 | // Receive (Into C) |
| 88 | UWP_MSG_REGISTER_KEY, // paramInt0 (key), paramChar0 (status) |
| 89 | UWP_MSG_REGISTER_CLICK, // paramInt0 (button), paramChar0 (status) |
| 90 | UWP_MSG_SCROLL_WHEEL_UPDATE, // paramInt0 (delta) |
| 91 | UWP_MSG_UPDATE_MOUSE_LOCATION, // paramVector0 (pos) |
| 92 | UWP_MSG_SET_GAMEPAD_ACTIVE, // paramInt0 (gamepad), paramBool0 (active or not) |
| 93 | UWP_MSG_SET_GAMEPAD_BUTTON, // paramInt0 (gamepad), paramInt1 (button), paramChar0 (status) |
| 94 | UWP_MSG_SET_GAMEPAD_AXIS, // paramInt0 (gamepad), int1 (axis), paramFloat0 (value) |
| 95 | UWP_MSG_SET_DISPLAY_DIMS, // paramVector0 (display dimensions) |
| 96 | UWP_MSG_HANDLE_RESIZE, // paramVector0 (new dimensions) - Onresized event |
| 97 | UWP_MSG_SET_GAME_TIME, // paramInt0 |
| 98 | } UWPMessageType; |
| 99 | |
| 100 | typedef struct UWPMessage { |
| 101 | UWPMessageType type; // Message type |
| 102 | |
| 103 | Vector2 paramVector0; // Vector parameters |
| 104 | int paramInt0; // Int parameter |
| 105 | int paramInt1; // Int parameter |
| 106 | char paramChar0; // Char parameters |
| 107 | float paramFloat0; // Float parameters |
| 108 | double paramDouble0; // Double parameters |
| 109 | bool paramBool0; // Bool parameters |
| 110 | |
| 111 | // More parameters can be added and fed to functions |
| 112 | } UWPMessage; |
| 113 | |
| 114 | // Allocate UWP Message |
| 115 | RLAPI UWPMessage* CreateUWPMessage(void); |
| 116 | |
| 117 | // Free UWP Message |
| 118 | RLAPI void DeleteUWPMessage(UWPMessage* msg); |
| 119 | |
| 120 | // Get messages into C++ |
| 121 | RLAPI bool UWPHasMessages(void); |
| 122 | RLAPI UWPMessage* UWPGetMessage(void); |
| 123 | RLAPI void UWPSendMessage(UWPMessage* msg); |
| 124 | |
| 125 | // For C to call |
| 126 | #ifndef __cplusplus // Hide from C++ code |
| 127 | void SendMessageToUWP(UWPMessage* msg); |
| 128 | bool HasMessageFromUWP(void); |
| 129 | UWPMessage* GetMessageFromUWP(void); |
| 130 | #endif |
| 131 | |
| 132 | #endif //defined(PLATFORM_UWP) |
| 133 | |
| 134 | #ifdef __cplusplus |
| 135 | } |
| 136 | #endif |
| 137 | |
| 138 | #endif // UTILS_H |
| 139 | |