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
This commit is contained in:
xavi92 2024-08-12 21:41:58 +00:00
parent 9b5aa6ad58
commit 171a1d1ea4
8 changed files with 43 additions and 50 deletions

View file

@ -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;
}

View file

@ -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 *);

View file

@ -34,12 +34,10 @@ gfuiCheckboxInit(void)
static void
gfuiChecked(void *idv)
{
GfuiCheckboxSetChecked(GfuiScreen, (long)idv, false);
GfuiUnSelectCurrent();
tGfuiObject* object = static_cast <tGfuiObject *>(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 <tGfuiObject *>(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)

View file

@ -31,13 +31,9 @@ gfuiInitCombobox(void)
static void
gfuiLeftArrow(void *idv)
{
tGfuiObject *object;
tGfuiObject *object = static_cast<tGfuiObject *>(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<tGfuiObject *>(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);

View file

@ -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);

View file

@ -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;

View file

@ -79,13 +79,17 @@ void gfuiScrollBarMinus(tGfuiObject *object)
static void
gfuiScrollPlus(void *idv)
{
gfuiScrollBarPlus(gfuiGetObject(GfuiScreen, (long)idv));
const tGfuiObject* object = static_cast<const tGfuiObject *>(idv);
gfuiScrollBarPlus(gfuiGetObject(GfuiScreen, object->id));
}
static void
gfuiScrollMinus(void *idv)
{
gfuiScrollBarMinus(gfuiGetObject(GfuiScreen, (long)idv));
const tGfuiObject* object = static_cast<const tGfuiObject *>(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;
}

View file

@ -41,13 +41,9 @@ gfuiInitScrollList(void)
static void
gfuiScroll(tScrollBarInfo *sinfo)
{
tGfuiObject *object;
tGfuiObject *object = static_cast<tGfuiObject *>(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: