diff options
author | Campbell Barton <campbell@blender.org> | 2022-06-17 10:18:06 +0300 |
---|---|---|
committer | Campbell Barton <campbell@blender.org> | 2022-06-17 10:18:06 +0300 |
commit | f59418fd92f1d27556ea6bc15fabbdb138cc8e95 (patch) | |
tree | 3ac91a4a838894e48e29586599eae3c2b01ed413 /intern/ghost | |
parent | 5cda99ff526449e3d4b564b6d10e552a1703b96f (diff) |
Cleanup: use booleans for GHOST C-API
Also use GHOST_ prefix for public functions.
Diffstat (limited to 'intern/ghost')
-rw-r--r-- | intern/ghost/GHOST_C-api.h | 32 | ||||
-rw-r--r-- | intern/ghost/intern/GHOST_C-api.cpp | 59 | ||||
-rw-r--r-- | intern/ghost/intern/GHOST_CallbackEventConsumer.cpp | 2 | ||||
-rw-r--r-- | intern/ghost/test/gears/GHOST_C-Test.c | 12 | ||||
-rw-r--r-- | intern/ghost/test/multitest/MultiTest.c | 6 |
5 files changed, 56 insertions, 55 deletions
diff --git a/intern/ghost/GHOST_C-api.h b/intern/ghost/GHOST_C-api.h index c92e6ba78c1..d27be40af0c 100644 --- a/intern/ghost/GHOST_C-api.h +++ b/intern/ghost/GHOST_C-api.h @@ -20,7 +20,7 @@ extern "C" { * \param event: The event received. * \param userdata: The callback's user data, supplied to #GHOST_CreateSystem. */ -typedef int (*GHOST_EventCallbackProcPtr)(GHOST_EventHandle event, GHOST_TUserDataPtr userdata); +typedef bool (*GHOST_EventCallbackProcPtr)(GHOST_EventHandle event, GHOST_TUserDataPtr userdata); /** * Creates the one and only system. @@ -206,7 +206,7 @@ extern GHOST_TUserDataPtr GHOST_GetWindowUserData(GHOST_WindowHandle windowhandl */ extern void GHOST_SetWindowUserData(GHOST_WindowHandle windowhandle, GHOST_TUserDataPtr userdata); -extern int GHOST_IsDialogWindow(GHOST_WindowHandle windowhandle); +extern bool GHOST_IsDialogWindow(GHOST_WindowHandle windowhandle); /** * Dispose a window. @@ -223,7 +223,7 @@ extern GHOST_TSuccess GHOST_DisposeWindow(GHOST_SystemHandle systemhandle, * \param windowhandle: Handle to the window to be checked. * \return Indication of validity. */ -extern int GHOST_ValidWindow(GHOST_SystemHandle systemhandle, GHOST_WindowHandle windowhandle); +extern bool GHOST_ValidWindow(GHOST_SystemHandle systemhandle, GHOST_WindowHandle windowhandle); /** * Begins full screen mode. @@ -235,7 +235,7 @@ extern int GHOST_ValidWindow(GHOST_SystemHandle systemhandle, GHOST_WindowHandle */ extern GHOST_WindowHandle GHOST_BeginFullScreen(GHOST_SystemHandle systemhandle, GHOST_DisplaySetting *setting, - const int stereoVisual); + const bool stereoVisual); /** * Ends full screen mode. @@ -249,7 +249,7 @@ extern GHOST_TSuccess GHOST_EndFullScreen(GHOST_SystemHandle systemhandle); * \param systemhandle: The handle to the system. * \return The current status. */ -extern int GHOST_GetFullScreen(GHOST_SystemHandle systemhandle); +extern bool GHOST_GetFullScreen(GHOST_SystemHandle systemhandle); /** * Get the Window under the cursor. @@ -369,7 +369,7 @@ extern GHOST_TSuccess GHOST_SetCustomCursorShape(GHOST_WindowHandle windowhandle * \param windowhandle: The handle to the window. * \return The visibility state of the cursor. */ -extern int GHOST_GetCursorVisibility(GHOST_WindowHandle windowhandle); +extern bool GHOST_GetCursorVisibility(GHOST_WindowHandle windowhandle); /** * Shows or hides the cursor. @@ -377,7 +377,7 @@ extern int GHOST_GetCursorVisibility(GHOST_WindowHandle windowhandle); * \param visible: The new visibility state of the cursor. * \return Indication of success. */ -extern GHOST_TSuccess GHOST_SetCursorVisibility(GHOST_WindowHandle windowhandle, int visible); +extern GHOST_TSuccess GHOST_SetCursorVisibility(GHOST_WindowHandle windowhandle, bool visible); /** * Returns the current location of the cursor (location in screen coordinates) @@ -436,7 +436,7 @@ extern GHOST_TSuccess GHOST_SetCursorGrab(GHOST_WindowHandle windowhandle, */ extern GHOST_TSuccess GHOST_GetModifierKeyState(GHOST_SystemHandle systemhandle, GHOST_TModifierKeyMask mask, - int *isDown); + bool *r_is_down); /** * Returns the state of a mouse button (outside the message queue). @@ -447,7 +447,7 @@ extern GHOST_TSuccess GHOST_GetModifierKeyState(GHOST_SystemHandle systemhandle, */ extern GHOST_TSuccess GHOST_GetButtonState(GHOST_SystemHandle systemhandle, GHOST_TButtonMask mask, - int *isDown); + bool *r_is_down); #ifdef WITH_INPUT_NDOF /*************************************************************************************** @@ -468,7 +468,7 @@ extern void GHOST_setNDOFDeadZone(float deadzone); /** * Tells if the ongoing drag'n'drop object can be accepted upon mouse drop */ -extern void GHOST_setAcceptDragOperation(GHOST_WindowHandle windowhandle, bool canAccept); +extern void GHOST_setAcceptDragOperation(GHOST_WindowHandle windowhandle, bool can_accept); /** * Returns the event type. @@ -534,7 +534,7 @@ extern void GHOST_SetTimerTaskUserData(GHOST_TimerTaskHandle timertaskhandle, * \param windowhandle: The handle to the window. * \return The validity of the window. */ -extern int GHOST_GetValid(GHOST_WindowHandle windowhandle); +extern bool GHOST_GetValid(GHOST_WindowHandle windowhandle); /** * Returns the type of drawing context used in this window. @@ -894,22 +894,22 @@ extern void GHOST_putClipboard(const char *buffer, bool selection); * \param action: console state * \return current status (1 -visible, 0 - hidden) */ -extern int setConsoleWindowState(GHOST_TConsoleWindowState action); +extern bool GHOST_setConsoleWindowState(GHOST_TConsoleWindowState action); /** * Use native pixel size (MacBook pro 'retina'), if supported. */ -extern int GHOST_UseNativePixels(void); +extern bool GHOST_UseNativePixels(void); /** * Warp the cursor, if supported. */ -extern int GHOST_SupportsCursorWarp(void); +extern bool GHOST_SupportsCursorWarp(void); /** * Support positioning windows (when false `wmWindow.x,y` are meaningless). */ -extern int GHOST_SupportsWindowPosition(void); +extern bool GHOST_SupportsWindowPosition(void); /** * Assign the callback which generates a back-trace (may be NULL). @@ -919,7 +919,7 @@ extern void GHOST_SetBacktraceHandler(GHOST_TBacktraceFn backtrace_fn); /** * Focus window after opening, or put them in the background. */ -extern void GHOST_UseWindowFocus(int use_focus); +extern void GHOST_UseWindowFocus(bool use_focus); /** * If window was opened using native pixel size, it returns scaling factor. diff --git a/intern/ghost/intern/GHOST_C-api.cpp b/intern/ghost/intern/GHOST_C-api.cpp index b1a15fdf4d7..c8127f59941 100644 --- a/intern/ghost/intern/GHOST_C-api.cpp +++ b/intern/ghost/intern/GHOST_C-api.cpp @@ -177,11 +177,11 @@ void GHOST_SetWindowUserData(GHOST_WindowHandle windowhandle, GHOST_TUserDataPtr window->setUserData(userdata); } -int GHOST_IsDialogWindow(GHOST_WindowHandle windowhandle) +bool GHOST_IsDialogWindow(GHOST_WindowHandle windowhandle) { GHOST_IWindow *window = (GHOST_IWindow *)windowhandle; - return (int)window->isDialog(); + return window->isDialog(); } GHOST_TSuccess GHOST_DisposeWindow(GHOST_SystemHandle systemhandle, @@ -193,17 +193,17 @@ GHOST_TSuccess GHOST_DisposeWindow(GHOST_SystemHandle systemhandle, return system->disposeWindow(window); } -int GHOST_ValidWindow(GHOST_SystemHandle systemhandle, GHOST_WindowHandle windowhandle) +bool GHOST_ValidWindow(GHOST_SystemHandle systemhandle, GHOST_WindowHandle windowhandle) { GHOST_ISystem *system = (GHOST_ISystem *)systemhandle; GHOST_IWindow *window = (GHOST_IWindow *)windowhandle; - return (int)system->validWindow(window); + return system->validWindow(window); } GHOST_WindowHandle GHOST_BeginFullScreen(GHOST_SystemHandle systemhandle, GHOST_DisplaySetting *setting, - const int stereoVisual) + const bool stereoVisual) { GHOST_ISystem *system = (GHOST_ISystem *)systemhandle; GHOST_IWindow *window = nullptr; @@ -228,11 +228,11 @@ GHOST_TSuccess GHOST_EndFullScreen(GHOST_SystemHandle systemhandle) return system->endFullScreen(); } -int GHOST_GetFullScreen(GHOST_SystemHandle systemhandle) +bool GHOST_GetFullScreen(GHOST_SystemHandle systemhandle) { GHOST_ISystem *system = (GHOST_ISystem *)systemhandle; - return (int)system->getFullScreen(); + return system->getFullScreen(); } GHOST_WindowHandle GHOST_GetWindowUnderCursor(GHOST_SystemHandle systemhandle, @@ -326,18 +326,18 @@ GHOST_TSuccess GHOST_SetCustomCursorShape(GHOST_WindowHandle windowhandle, return window->setCustomCursorShape(bitmap, mask, sizex, sizey, hotX, hotY, canInvertColor); } -int GHOST_GetCursorVisibility(GHOST_WindowHandle windowhandle) +bool GHOST_GetCursorVisibility(GHOST_WindowHandle windowhandle) { GHOST_IWindow *window = (GHOST_IWindow *)windowhandle; - return (int)window->getCursorVisibility(); + return window->getCursorVisibility(); } -GHOST_TSuccess GHOST_SetCursorVisibility(GHOST_WindowHandle windowhandle, int visible) +GHOST_TSuccess GHOST_SetCursorVisibility(GHOST_WindowHandle windowhandle, bool visible) { GHOST_IWindow *window = (GHOST_IWindow *)windowhandle; - return window->setCursorVisibility(visible ? true : false); + return window->setCursorVisibility(visible); } GHOST_TSuccess GHOST_GetCursorPosition(GHOST_SystemHandle systemhandle, int32_t *x, int32_t *y) @@ -392,28 +392,28 @@ void GHOST_GetCursorGrabState(GHOST_WindowHandle windowhandle, GHOST_TSuccess GHOST_GetModifierKeyState(GHOST_SystemHandle systemhandle, GHOST_TModifierKeyMask mask, - int *isDown) + bool *r_is_down) { GHOST_ISystem *system = (GHOST_ISystem *)systemhandle; GHOST_TSuccess result; - bool isdown = false; + bool is_down = false; - result = system->getModifierKeyState(mask, isdown); - *isDown = (int)isdown; + result = system->getModifierKeyState(mask, is_down); + *r_is_down = is_down; return result; } GHOST_TSuccess GHOST_GetButtonState(GHOST_SystemHandle systemhandle, GHOST_TButtonMask mask, - int *isDown) + bool *r_is_down) { GHOST_ISystem *system = (GHOST_ISystem *)systemhandle; GHOST_TSuccess result; - bool isdown = false; + bool is_down = false; - result = system->getButtonState(mask, isdown); - *isDown = (int)isdown; + result = system->getButtonState(mask, is_down); + *r_is_down = is_down; return result; } @@ -426,11 +426,11 @@ void GHOST_setNDOFDeadZone(float deadzone) } #endif -void GHOST_setAcceptDragOperation(GHOST_WindowHandle windowhandle, bool canAccept) +void GHOST_setAcceptDragOperation(GHOST_WindowHandle windowhandle, bool can_accept) { GHOST_IWindow *window = (GHOST_IWindow *)windowhandle; - window->setAcceptDragOperation(canAccept); + window->setAcceptDragOperation(can_accept); } GHOST_TEventType GHOST_GetEventType(GHOST_EventHandle eventhandle) @@ -489,11 +489,11 @@ void GHOST_SetTimerTaskUserData(GHOST_TimerTaskHandle timertaskhandle, GHOST_TUs timertask->setUserData(userdata); } -int GHOST_GetValid(GHOST_WindowHandle windowhandle) +bool GHOST_GetValid(GHOST_WindowHandle windowhandle) { GHOST_IWindow *window = (GHOST_IWindow *)windowhandle; - return (int)window->getValid(); + return window->getValid(); } GHOST_TDrawingContextType GHOST_GetDrawingContextType(GHOST_WindowHandle windowhandle) @@ -817,25 +817,26 @@ void GHOST_putClipboard(const char *buffer, bool selection) system->putClipboard(buffer, selection); } -int setConsoleWindowState(GHOST_TConsoleWindowState action) +bool GHOST_setConsoleWindowState(GHOST_TConsoleWindowState action) { GHOST_ISystem *system = GHOST_ISystem::getSystem(); - return system->setConsoleWindowState(action); + /* FIXME: use `bool` instead of int for this value. */ + return (bool)system->setConsoleWindowState(action); } -int GHOST_UseNativePixels(void) +bool GHOST_UseNativePixels(void) { GHOST_ISystem *system = GHOST_ISystem::getSystem(); return system->useNativePixel(); } -int GHOST_SupportsCursorWarp(void) +bool GHOST_SupportsCursorWarp(void) { GHOST_ISystem *system = GHOST_ISystem::getSystem(); return system->supportsCursorWarp(); } -int GHOST_SupportsWindowPosition(void) +bool GHOST_SupportsWindowPosition(void) { GHOST_ISystem *system = GHOST_ISystem::getSystem(); return system->supportsWindowPosition(); @@ -846,7 +847,7 @@ void GHOST_SetBacktraceHandler(GHOST_TBacktraceFn backtrace_fn) GHOST_ISystem::setBacktraceFn(backtrace_fn); } -void GHOST_UseWindowFocus(int use_focus) +void GHOST_UseWindowFocus(bool use_focus) { GHOST_ISystem *system = GHOST_ISystem::getSystem(); return system->useWindowFocus(use_focus); diff --git a/intern/ghost/intern/GHOST_CallbackEventConsumer.cpp b/intern/ghost/intern/GHOST_CallbackEventConsumer.cpp index 72aeebdc876..9f14d56cd9a 100644 --- a/intern/ghost/intern/GHOST_CallbackEventConsumer.cpp +++ b/intern/ghost/intern/GHOST_CallbackEventConsumer.cpp @@ -22,5 +22,5 @@ GHOST_CallbackEventConsumer::GHOST_CallbackEventConsumer(GHOST_EventCallbackProc bool GHOST_CallbackEventConsumer::processEvent(GHOST_IEvent *event) { - return m_eventCallback((GHOST_EventHandle)event, m_userData) != 0; + return m_eventCallback((GHOST_EventHandle)event, m_userData); } diff --git a/intern/ghost/test/gears/GHOST_C-Test.c b/intern/ghost/test/gears/GHOST_C-Test.c index 71f3a6f43b4..46c8fda0665 100644 --- a/intern/ghost/test/gears/GHOST_C-Test.c +++ b/intern/ghost/test/gears/GHOST_C-Test.c @@ -31,7 +31,7 @@ #endif /* defined(WIN32) || defined(__APPLE__) */ static void gearsTimerProc(GHOST_TimerTaskHandle task, uint64_t time); -int processEvent(GHOST_EventHandle hEvent, GHOST_TUserDataPtr userData); +bool processEvent(GHOST_EventHandle hEvent, GHOST_TUserDataPtr userData); static GLfloat view_rotx = 20.0, view_roty = 30.0, view_rotz = 0.0; static GLfloat fAngle = 0.0; @@ -269,9 +269,9 @@ static void setViewPortGL(GHOST_WindowHandle hWindow) GHOST_DisposeRectangle(hRect); } -int processEvent(GHOST_EventHandle hEvent, GHOST_TUserDataPtr userData) +bool processEvent(GHOST_EventHandle hEvent, GHOST_TUserDataPtr userData) { - int handled = 1; + bool handled = true; int cursor; int visibility; GHOST_TEventKeyData *keyData = NULL; @@ -389,10 +389,10 @@ int processEvent(GHOST_EventHandle hEvent, GHOST_TUserDataPtr userData) } break; case GHOST_kEventWindowActivate: - handled = 0; + handled = false; break; case GHOST_kEventWindowDeactivate: - handled = 0; + handled = false; break; case GHOST_kEventWindowUpdate: { GHOST_WindowHandle window2 = GHOST_GetEventWindow(hEvent); @@ -404,7 +404,7 @@ int processEvent(GHOST_EventHandle hEvent, GHOST_TUserDataPtr userData) } break; default: - handled = 0; + handled = false; break; } return handled; diff --git a/intern/ghost/test/multitest/MultiTest.c b/intern/ghost/test/multitest/MultiTest.c index 35b1de65171..157e4f1b0f2 100644 --- a/intern/ghost/test/multitest/MultiTest.c +++ b/intern/ghost/test/multitest/MultiTest.c @@ -812,7 +812,7 @@ struct _MultiTestApp { int exit; }; -static int multitest_event_handler(GHOST_EventHandle evt, GHOST_TUserDataPtr data) +static bool multitest_event_handler(GHOST_EventHandle evt, GHOST_TUserDataPtr data) { MultiTestApp *app = data; GHOST_WindowHandle win; @@ -820,7 +820,7 @@ static int multitest_event_handler(GHOST_EventHandle evt, GHOST_TUserDataPtr dat win = GHOST_GetEventWindow(evt); if (win && !GHOST_ValidWindow(app->sys, win)) { loggerwindow_log(app->logger, "WARNING: bad event, non-valid window\n"); - return 1; + return true; } if (win) { @@ -845,7 +845,7 @@ static int multitest_event_handler(GHOST_EventHandle evt, GHOST_TUserDataPtr dat } } - return 1; + return true; } /**/ |