X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Flibgame%2Fgadgets.c;h=7b92820009b1138c5d1f8a2dd40a414bdf6e46a1;hb=caf3da0a0e3af75eb8d10f83e5105581402b387e;hp=89276bcdbb1561d9d4c3cad38f03f829a1d8d077;hpb=5f9fbeb32ecd4c70ed6d6df8809719af619b40c0;p=rocksndiamonds.git diff --git a/src/libgame/gadgets.c b/src/libgame/gadgets.c index 89276bcd..7b928200 100644 --- a/src/libgame/gadgets.c +++ b/src/libgame/gadgets.c @@ -68,7 +68,7 @@ void DUMP_GADGET_MAP_STATE() { struct GadgetInfo *gi = gadget_list_first_entry; - while (gi) + while (gi != NULL) { printf("-XXX-1-> '%s': %s\n", gi->info_text, (gi->mapped ? "mapped" : "not mapped")); @@ -80,22 +80,28 @@ void DUMP_GADGET_MAP_STATE() static struct GadgetInfo *getGadgetInfoFromMousePosition(int mx, int my) { - struct GadgetInfo *gi = gadget_list_first_entry; + struct GadgetInfo *gi; - while (gi) + /* open selectboxes may overlap other active gadgets, so check them first */ + for (gi = gadget_list_first_entry; gi != NULL; gi = gi->next) { if (gi->mapped && gi->active && - ((mx >= gi->x && mx < gi->x + gi->width && - my >= gi->y && my < gi->y + gi->height) || - (gi->type & GD_TYPE_SELECTBOX && gi->selectbox.open && - mx >= gi->selectbox.x && mx < gi->selectbox.x+gi->selectbox.width && - my >= gi->selectbox.y && my < gi->selectbox.y+gi->selectbox.height))) - break; + gi->type & GD_TYPE_SELECTBOX && gi->selectbox.open && + mx >= gi->selectbox.x && mx < gi->selectbox.x + gi->selectbox.width && + my >= gi->selectbox.y && my < gi->selectbox.y + gi->selectbox.height) + return gi; + } - gi = gi->next; + /* check all other gadgets */ + for (gi = gadget_list_first_entry; gi != NULL; gi = gi->next) + { + if (gi->mapped && gi->active && + mx >= gi->x && mx < gi->x + gi->width && + my >= gi->y && my < gi->y + gi->height) + return gi; } - return gi; + return NULL; } static void default_callback_info(void *ptr) @@ -1033,7 +1039,7 @@ static void MultiMapGadgets(int mode) static boolean map_state[MAX_NUM_GADGETS]; int map_count = 0; - while (gi) + while (gi != NULL) { if ((mode & MULTIMAP_PLAYFIELD && gi->x < gfx.sx + gfx.sxsize) || @@ -1267,7 +1273,7 @@ void HandleGadgets(int mx, int my, int button) if (button == 0 && !release_event) gi = new_gi; - if (gi) + if (gi != NULL) { int last_x = gi->event.x; int last_y = gi->event.y;