From 171a1d1ea4322374b71561c93921bf964d7eb67c Mon Sep 17 00:00:00 2001 From: xavi92 Date: Mon, 12 Aug 2024 21:41:58 +0000 Subject: [PATCH] tgfclient: Do not cast integers to pointers These casts were dangerous and not accepted by more modern compilers, such as GCC 14. In fact, all of them could be trivially replaced with safe and portable alternatives. git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@9535 30fe4595-0a0c-4342-8851-515496e4dcbd Former-commit-id: ba9c39525f91274c60086272d12b3b9b6bf7a451 Former-commit-id: f13171db00171b7c9d190019cbe807829a56103d --- src/libs/tgfclient/gui.cpp | 8 ++++---- src/libs/tgfclient/gui.h | 2 +- src/libs/tgfclient/guicheckbox.cpp | 20 ++++++++------------ src/libs/tgfclient/guicombobox.cpp | 16 ++++------------ src/libs/tgfclient/guimenu.cpp | 8 +++++++- src/libs/tgfclient/guiobject.cpp | 13 ++++++------- src/libs/tgfclient/guiscrollbar.cpp | 16 ++++++++++------ src/libs/tgfclient/guiscrollist.cpp | 10 +++------- 8 files changed, 43 insertions(+), 50 deletions(-) diff --git a/src/libs/tgfclient/gui.cpp b/src/libs/tgfclient/gui.cpp index 44cd87ecd..a04aafa2c 100644 --- a/src/libs/tgfclient/gui.cpp +++ b/src/libs/tgfclient/gui.cpp @@ -254,7 +254,7 @@ GfuiIdle(void) if (GfuiScreen->mouse == 1) { /* button down */ gfuiUpdateFocus(); - gfuiMouseAction((void*)0); + gfuiMouseAction(0); GfuiApp().eventLoop().postRedisplay(); } } @@ -570,13 +570,13 @@ gfuiMouseButton(int button, int state, int x, int y) { GfuiScreen->mouse = 1; gfuiUpdateFocus(); - gfuiMouseAction((void*)0); + gfuiMouseAction(0); } else { GfuiScreen->mouse = 0; gfuiUpdateFocus(); - gfuiMouseAction((void*)1); + gfuiMouseAction(1); } GfuiApp().eventLoop().postRedisplay(); } @@ -588,7 +588,7 @@ gfuiMouseMotion(int x, int y) GfuiMouse.X = (x - (ScrW - ViewW)/2) * (int)GfuiScreen->width / ViewW; GfuiMouse.Y = (ViewH - y + (ScrH - ViewH)/2) * (int)GfuiScreen->height / ViewH; gfuiUpdateFocus(); - gfuiMouseAction((void*)(long)(1 - GfuiScreen->mouse)); + gfuiMouseAction(1 - GfuiScreen->mouse); GfuiApp().eventLoop().postRedisplay(); DelayRepeat = REPEAT1; } diff --git a/src/libs/tgfclient/gui.h b/src/libs/tgfclient/gui.h index 3fb75d572..da36b0e51 100644 --- a/src/libs/tgfclient/gui.h +++ b/src/libs/tgfclient/gui.h @@ -372,7 +372,7 @@ extern void GfuiDrawCursor(); extern void GfuiDraw(tGfuiObject *obj);; extern void gfuiUpdateFocus(); extern void gfuiDrawString(int x, int y, GfuiFontClass *font, const char *string); -extern void gfuiMouseAction(void *action); +extern void gfuiMouseAction(int action); extern void gfuiMouseWheelAction(int x, int y, unsigned int direction); extern void gfuiSelectNext(void *); extern void gfuiSelectPrev(void *); diff --git a/src/libs/tgfclient/guicheckbox.cpp b/src/libs/tgfclient/guicheckbox.cpp index 090be5985..4ab66e823 100644 --- a/src/libs/tgfclient/guicheckbox.cpp +++ b/src/libs/tgfclient/guicheckbox.cpp @@ -34,12 +34,10 @@ gfuiCheckboxInit(void) static void gfuiChecked(void *idv) { - GfuiCheckboxSetChecked(GfuiScreen, (long)idv, false); - GfuiUnSelectCurrent(); + tGfuiObject* object = static_cast (idv); - tGfuiObject* object = gfuiGetObject(GfuiScreen, (long)idv); - if (!object) - return; + GfuiCheckboxSetChecked(GfuiScreen, object->id, false); + GfuiUnSelectCurrent(); tGfuiCheckbox* checkbox = &(object->u.checkbox); @@ -51,12 +49,10 @@ gfuiChecked(void *idv) static void gfuiUnchecked(void *idv) { - GfuiCheckboxSetChecked(GfuiScreen, (long)idv, true); - GfuiUnSelectCurrent(); + tGfuiObject* object = static_cast (idv); - tGfuiObject* object = gfuiGetObject(GfuiScreen, (long)idv); - if (!object) - return; + GfuiCheckboxSetChecked(GfuiScreen, object->id, true); + GfuiUnSelectCurrent(); tGfuiCheckbox* checkbox = &(object->u.checkbox); @@ -99,14 +95,14 @@ GfuiCheckboxCreate(void *scr, int font, int x, int y, int imagewidth, int imageh GfuiGrButtonCreate(scr, "data/img/checked.png", "data/img/checked.png", "data/img/checked.png", "data/img/checked.png", x, y, imagewidth, imageheight, GFUI_MIRROR_NONE, false, GFUI_MOUSE_UP, - (void*)(long)(object->id), gfuiChecked, + object, gfuiChecked, userDataOnFocus, onFocus, onFocusLost); checkbox->uncheckId = GfuiGrButtonCreate(scr, "data/img/unchecked.png", "data/img/unchecked.png", "data/img/unchecked.png", "data/img/unchecked.png", x, y, imagewidth, imageheight, GFUI_MIRROR_NONE, false, GFUI_MOUSE_UP, - (void*)(long)(object->id), gfuiUnchecked, + object, gfuiUnchecked, userDataOnFocus, onFocus, onFocusLost); // Compute total height (text or buttons) diff --git a/src/libs/tgfclient/guicombobox.cpp b/src/libs/tgfclient/guicombobox.cpp index e48f00941..5cfca2476 100644 --- a/src/libs/tgfclient/guicombobox.cpp +++ b/src/libs/tgfclient/guicombobox.cpp @@ -31,13 +31,9 @@ gfuiInitCombobox(void) static void gfuiLeftArrow(void *idv) { - tGfuiObject *object; + tGfuiObject *object = static_cast(idv); tGfuiCombobox *combobox; - object = gfuiGetObject(GfuiScreen, (long)idv); - if (!object) - return; - combobox = &(object->u.combobox); if (combobox->pInfo->vecChoices.empty()) @@ -58,13 +54,9 @@ gfuiLeftArrow(void *idv) static void gfuiRightArrow(void *idv) { - tGfuiObject *object; + tGfuiObject *object = static_cast(idv); tGfuiCombobox *combobox; - object = gfuiGetObject(GfuiScreen, (long)idv); - if (!object) - return; - combobox = &(object->u.combobox); if (combobox->pInfo->vecChoices.empty()) @@ -142,13 +134,13 @@ GfuiComboboxCreate(void *scr, int font, int x, int y, int width, "data/img/arrowleft-disabled.png", "data/img/arrowleft-normal.png", "data/img/arrowleft-focused.png", "data/img/arrowleft-pushed.png", x, y, arrowsWidth, arrowsHeight, GFUI_MIRROR_NONE, - GFUI_MOUSE_UP, (void*)(long)(object->id), gfuiLeftArrow, 0, 0, 0); + GFUI_MOUSE_UP, object, gfuiLeftArrow, 0, 0, 0); gfuiGrButtonInit(&combobox->rightButton, "data/img/arrowright-disabled.png", "data/img/arrowright-normal.png", "data/img/arrowright-focused.png", "data/img/arrowright-pushed.png", x + width - combobox->leftButton.width, y, arrowsWidth, arrowsHeight, GFUI_MIRROR_NONE, - GFUI_MOUSE_UP, (void*)(long)(object->id), gfuiRightArrow, 0, 0, 0); + GFUI_MOUSE_UP, object, gfuiRightArrow, 0, 0, 0); diff --git a/src/libs/tgfclient/guimenu.cpp b/src/libs/tgfclient/guimenu.cpp index 628f0d82a..9b07a776d 100644 --- a/src/libs/tgfclient/guimenu.cpp +++ b/src/libs/tgfclient/guimenu.cpp @@ -57,6 +57,12 @@ onFocusLostHideTip(void* cbinfo) ((tMenuCallbackInfo*)cbinfo)->labelId, GFUI_INVISIBLE); } +static void +onPerformAction(void* cbinfo) +{ + gfuiMouseAction(2); +} + /*********************************************************************************** * Menu XML descriptor management */ @@ -78,7 +84,7 @@ void GfuiMenuDefaultKeysAdd(void* scr) { GfuiAddKey(scr, GFUIK_TAB, "Select Next Entry", NULL, gfuiSelectNext, NULL); - GfuiAddKey(scr, GFUIK_RETURN, "Perform Action", (void*)2, gfuiMouseAction, NULL); + GfuiAddKey(scr, GFUIK_RETURN, "Perform Action", NULL, onPerformAction, NULL); GfuiAddKey(scr, GFUIK_UP, "Select Previous Entry", NULL, gfuiSelectPrev, NULL); GfuiAddKey(scr, GFUIK_DOWN, "Select Next Entry", NULL, gfuiSelectNext, NULL); GfuiAddKey(scr, GFUIK_PAGEUP, "Select Previous Entry", NULL, gfuiSelectPrev, NULL); diff --git a/src/libs/tgfclient/guiobject.cpp b/src/libs/tgfclient/guiobject.cpp index 1a918dc1d..e6c1793af 100644 --- a/src/libs/tgfclient/guiobject.cpp +++ b/src/libs/tgfclient/guiobject.cpp @@ -560,36 +560,35 @@ GfuiEnable(void *scr, int id, int flag) } void -gfuiMouseAction(void *vaction) +gfuiMouseAction(int action) { tGfuiObject *curObject; - long action = (long)vaction; curObject = GfuiScreen->hasFocus; if (curObject != NULL) { switch (curObject->widget) { case GFUI_BUTTON: - gfuiButtonAction((int)action); + gfuiButtonAction(action); if(action) playMenuSfx(SFX_CLICK); break; case GFUI_GRBUTTON: - gfuiGrButtonAction((int)action); + gfuiGrButtonAction(action); if(action) playMenuSfx(SFX_CLICK); break; case GFUI_SCROLLIST: - gfuiScrollListAction((int)action); + gfuiScrollListAction(action); if(action) playMenuSfx(SFX_CLICK); break; case GFUI_EDITBOX: - gfuiEditboxAction((int)action); + gfuiEditboxAction(action); if(action) playMenuSfx(SFX_CLICK); break; case GFUI_COMBOBOX: - gfuiComboboxAction((int)action); + gfuiComboboxAction(action); if(action) playMenuSfx(SFX_CLICK); break; diff --git a/src/libs/tgfclient/guiscrollbar.cpp b/src/libs/tgfclient/guiscrollbar.cpp index 744368319..5dbe06e20 100644 --- a/src/libs/tgfclient/guiscrollbar.cpp +++ b/src/libs/tgfclient/guiscrollbar.cpp @@ -79,13 +79,17 @@ void gfuiScrollBarMinus(tGfuiObject *object) static void gfuiScrollPlus(void *idv) { - gfuiScrollBarPlus(gfuiGetObject(GfuiScreen, (long)idv)); + const tGfuiObject* object = static_cast(idv); + + gfuiScrollBarPlus(gfuiGetObject(GfuiScreen, object->id)); } static void gfuiScrollMinus(void *idv) { - gfuiScrollBarMinus(gfuiGetObject(GfuiScreen, (long)idv)); + const tGfuiObject* object = static_cast(idv); + + gfuiScrollBarMinus(gfuiGetObject(GfuiScreen, object->id)); } /** Create a new scroll bar. @@ -141,14 +145,14 @@ GfuiScrollBarCreate(void *scr, int x, int y, int length, int thickness, int butL "data/img/arrow-left-focused.png", "data/img/arrow-left-pushed.png", x, y, butLength, thickness, butMirror, false, 1, - (void*)(long)(object->id), gfuiScrollMinus, + object, gfuiScrollMinus, NULL, (tfuiCallback)NULL, (tfuiCallback)NULL); const tGfuiGrButton* pArrowBut = &(gfuiGetObject(scr, arrowButId)->u.grbutton); GfuiGrButtonCreate(scr, "data/img/arrow-right.png", "data/img/arrow-right.png", "data/img/arrow-right-focused.png", "data/img/arrow-right-pushed.png", x + length - pArrowBut->width, y, butLength, thickness, butMirror, false, 1, - (void*)(long)(object->id), gfuiScrollPlus, + object, gfuiScrollPlus, NULL, (tfuiCallback)NULL, (tfuiCallback)NULL); break; } @@ -161,14 +165,14 @@ GfuiScrollBarCreate(void *scr, int x, int y, int length, int thickness, int butL "data/img/arrow-down-focused.png", "data/img/arrow-down-pushed.png", x, y, thickness, butLength, butMirror, false, 1, - (void*)(long)(object->id), gfuiScrollPlus, + object, gfuiScrollPlus, NULL, (tfuiCallback)NULL, (tfuiCallback)NULL); const tGfuiGrButton* pArrowBut = &(gfuiGetObject(scr, arrowButId)->u.grbutton); GfuiGrButtonCreate(scr, "data/img/arrow-up.png", "data/img/arrow-up.png", "data/img/arrow-up-focused.png", "data/img/arrow-up-pushed.png", x, y + length - pArrowBut->height, thickness, butLength, butMirror, false, 1, - (void*)(long)(object->id), gfuiScrollMinus, + object, gfuiScrollMinus, NULL, (tfuiCallback)NULL, (tfuiCallback)NULL); break; } diff --git a/src/libs/tgfclient/guiscrollist.cpp b/src/libs/tgfclient/guiscrollist.cpp index 2d5ff6857..799111285 100644 --- a/src/libs/tgfclient/guiscrollist.cpp +++ b/src/libs/tgfclient/guiscrollist.cpp @@ -41,13 +41,9 @@ gfuiInitScrollList(void) static void gfuiScroll(tScrollBarInfo *sinfo) { - tGfuiObject *object; + tGfuiObject *object = static_cast(sinfo->userData); tGfuiScrollList *scrollist; - object = gfuiGetObject(GfuiScreen, (long)(sinfo->userData)); - if (object == NULL) { - return; - } if (object->widget != GFUI_SCROLLIST) { return; } @@ -174,14 +170,14 @@ GfuiScrollListCreate(void *scr, int font, int x, int y, int width, int height, GfuiScrollBarCreate(scr, x + width, y, height, scrollBarWidth, scrollBarButHeight, GFUI_VERT_SCROLLBAR, GFUI_SB_RIGHT, - 0, 10, 10, 10, (void *)(long)(object->id), gfuiScroll); + 0, 10, 10, 10, object, gfuiScroll); break; case GFUI_SB_LEFT: scrollist->scrollBar = GfuiScrollBarCreate(scr, x - scrollBarWidth, y, height, scrollBarWidth, scrollBarButHeight, GFUI_VERT_SCROLLBAR, GFUI_SB_LEFT, - 0, 10, 10, 10, (void *)(long)(object->id), gfuiScroll); + 0, 10, 10, 10, object, gfuiScroll); break; case GFUI_SB_NONE: default: