rnd-20030708-1-src
[rocksndiamonds.git] / src / libgame / gadgets.c
index 7b92820009b1138c5d1f8a2dd40a414bdf6e46a1..619039aa2b1114ddb6979f140d996a198242b77d 100644 (file)
@@ -828,6 +828,7 @@ static void HandleGadgetTags(struct GadgetInfo *gi, int first_tag, va_list ap)
     int border_xsize = gi->border.xsize;
     int border_ysize = gi->border.ysize;
     int button_size = gi->border.xsize_selectbutton;
+    int bottom_screen_border = gfx.sy + gfx.sysize - font_height;
     Bitmap *src_bitmap;
     int src_x, src_y;
 
@@ -848,10 +849,10 @@ static void HandleGadgetTags(struct GadgetInfo *gi, int first_tag, va_list ap)
 
     gi->selectbox.x = gi->x;
     gi->selectbox.y = gi->y + gi->height;
-    if (gi->selectbox.y + gi->selectbox.height > gfx.real_sy + gfx.full_sysize)
+    if (gi->selectbox.y + gi->selectbox.height > bottom_screen_border)
       gi->selectbox.y = gi->y - gi->selectbox.height;
     if (gi->selectbox.y < 0)
-      gi->selectbox.y = gfx.real_sy + gfx.full_sysize - gi->selectbox.height;
+      gi->selectbox.y = bottom_screen_border - gi->selectbox.height;
 
     getFontCharSource(font_nr, FONT_ASCII_CURSOR, &src_bitmap, &src_x, &src_y);
     src_x += font_width / 2;
@@ -1130,6 +1131,13 @@ void HandleGadgets(int mx, int my, int button)
   if (gadget_list_first_entry == NULL)
     return;
 
+  /* simulated release of mouse button over last gadget */
+  if (mx == -1 && my == -1 && button == 0)
+  {
+    mx = last_mx;
+    my = last_my;
+  }
+
   /* check which gadget is under the mouse pointer */
   new_gi = getGadgetInfoFromMousePosition(mx, my);
 
@@ -1546,6 +1554,10 @@ void HandleGadgets(int mx, int my, int button)
        gi->event_mask & GD_EVENT_OFF_BORDERS)
       gi->callback_action(gi);
   }
+
+  /* handle gadgets unmapped/mapped between pressing and releasing */
+  if (release_event && !gadget_released && new_gi)
+    new_gi->state = GD_BUTTON_UNPRESSED;
 }
 
 void HandleGadgetsKeyInput(Key key)