+
+/* ---------- new screen button stuff -------------------------------------- */
+
+/* graphic position and size values for buttons and scrollbars */
+#define SC_SCROLLBUTTON_XPOS 64
+#define SC_SCROLLBUTTON_YPOS 0
+#define SC_SCROLLBAR_XPOS 0
+#define SC_SCROLLBAR_YPOS 64
+
+#define SC_SCROLLBUTTON_XSIZE 32
+#define SC_SCROLLBUTTON_YSIZE 32
+
+#define SC_SCROLL_UP_XPOS (SXSIZE - SC_SCROLLBUTTON_XSIZE)
+#define SC_SCROLL_UP_YPOS SC_SCROLLBUTTON_YSIZE
+#define SC_SCROLL_DOWN_XPOS SC_SCROLL_UP_XPOS
+#define SC_SCROLL_DOWN_YPOS (SYSIZE - SC_SCROLLBUTTON_YSIZE)
+#define SC_SCROLL_VERTICAL_XPOS SC_SCROLL_UP_XPOS
+#define SC_SCROLL_VERTICAL_YPOS (SC_SCROLL_UP_YPOS + SC_SCROLLBUTTON_YSIZE)
+#define SC_SCROLL_VERTICAL_XSIZE SC_SCROLLBUTTON_XSIZE
+#define SC_SCROLL_VERTICAL_YSIZE (SYSIZE - 3 * SC_SCROLLBUTTON_YSIZE)
+
+#define SC_BORDER_SIZE 14
+
+static struct
+{
+ int xpos, ypos;
+ int x, y;
+ int gadget_id;
+ char *infotext;
+} scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
+{
+ {
+ SC_SCROLLBUTTON_XPOS + 0 * SC_SCROLLBUTTON_XSIZE, SC_SCROLLBUTTON_YPOS,
+ SC_SCROLL_UP_XPOS, SC_SCROLL_UP_YPOS,
+ SCREEN_CTRL_ID_SCROLL_UP,
+ "scroll level series up"
+ },
+ {
+ SC_SCROLLBUTTON_XPOS + 1 * SC_SCROLLBUTTON_XSIZE, SC_SCROLLBUTTON_YPOS,
+ SC_SCROLL_DOWN_XPOS, SC_SCROLL_DOWN_YPOS,
+ SCREEN_CTRL_ID_SCROLL_DOWN,
+ "scroll level series down"
+ }
+};
+
+static struct
+{
+ int xpos, ypos;
+ int x, y;
+ int width, height;
+ int type;
+ int gadget_id;
+ char *infotext;
+} scrollbar_info[NUM_SCREEN_SCROLLBARS] =
+{
+ {
+ SC_SCROLLBAR_XPOS, SC_SCROLLBAR_YPOS,
+ SX + SC_SCROLL_VERTICAL_XPOS, SY + SC_SCROLL_VERTICAL_YPOS,
+ SC_SCROLL_VERTICAL_XSIZE, SC_SCROLL_VERTICAL_YSIZE,
+ GD_TYPE_SCROLLBAR_VERTICAL,
+ SCREEN_CTRL_ID_SCROLL_VERTICAL,
+ "scroll level series vertically"
+ }
+};
+
+static void CreateScreenScrollbuttons()
+{
+ Bitmap *gd_bitmap = pix[PIX_MORE];
+ struct GadgetInfo *gi;
+ unsigned long event_mask;
+ int i;
+
+ for (i=0; i<NUM_SCREEN_SCROLLBUTTONS; i++)
+ {
+ int id = scrollbutton_info[i].gadget_id;
+ int x, y, width, height;
+ int gd_x1, gd_x2, gd_y1, gd_y2;
+
+ x = scrollbutton_info[i].x;
+ y = scrollbutton_info[i].y;
+
+ event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
+
+ x += SX;
+ y += SY;
+ width = SC_SCROLLBUTTON_XSIZE;
+ height = SC_SCROLLBUTTON_YSIZE;
+ gd_x1 = scrollbutton_info[i].xpos;
+ gd_y1 = scrollbutton_info[i].ypos;
+ gd_x2 = gd_x1;
+ gd_y2 = gd_y1 + SC_SCROLLBUTTON_YSIZE;
+
+ gi = CreateGadget(GDI_CUSTOM_ID, id,
+ GDI_CUSTOM_TYPE_ID, i,
+ GDI_INFO_TEXT, scrollbutton_info[i].infotext,
+ GDI_X, x,
+ GDI_Y, y,
+ GDI_WIDTH, width,
+ GDI_HEIGHT, height,
+ GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
+ GDI_STATE, GD_BUTTON_UNPRESSED,
+ GDI_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y1,
+ GDI_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y2,
+ GDI_EVENT_MASK, event_mask,
+ GDI_CALLBACK_ACTION, HandleScreenGadgets,
+ GDI_END);
+
+ if (gi == NULL)
+ Error(ERR_EXIT, "cannot create gadget");
+
+ screen_gadget[id] = gi;
+ }
+}
+
+static void CreateScreenScrollbars()
+{
+ int i;
+
+ for (i=0; i<NUM_SCREEN_SCROLLBARS; i++)
+ {
+ int id = scrollbar_info[i].gadget_id;
+ Bitmap *gd_bitmap = pix[PIX_MORE];
+ int gd_x1, gd_x2, gd_y1, gd_y2;
+ struct GadgetInfo *gi;
+ int items_max, items_visible, item_position;
+ unsigned long event_mask;
+ int num_page_entries = MAX_MENU_ENTRIES_ON_SCREEN - 1;
+
+#if 0
+ if (num_leveldirs <= MAX_MENU_ENTRIES_ON_SCREEN)
+ num_page_entries = num_leveldirs;
+ else
+ num_page_entries = MAX_MENU_ENTRIES_ON_SCREEN - 1;
+
+ items_max = MAX(num_leveldirs, num_page_entries);
+ items_visible = num_page_entries;
+ item_position = 0;
+#else
+ items_max = num_page_entries;
+ items_visible = num_page_entries;
+ item_position = 0;
+#endif
+
+ event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
+
+ gd_x1 = scrollbar_info[i].xpos;
+ gd_x2 = gd_x1 + scrollbar_info[i].width;
+ gd_y1 = scrollbar_info[i].ypos;
+ gd_y2 = scrollbar_info[i].ypos;
+
+ gi = CreateGadget(GDI_CUSTOM_ID, id,
+ GDI_CUSTOM_TYPE_ID, i,
+ GDI_INFO_TEXT, scrollbar_info[i].infotext,
+ GDI_X, scrollbar_info[i].x,
+ GDI_Y, scrollbar_info[i].y,
+ GDI_WIDTH, scrollbar_info[i].width,
+ GDI_HEIGHT, scrollbar_info[i].height,
+ GDI_TYPE, scrollbar_info[i].type,
+ GDI_SCROLLBAR_ITEMS_MAX, items_max,
+ GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
+ GDI_SCROLLBAR_ITEM_POSITION, item_position,
+ GDI_STATE, GD_BUTTON_UNPRESSED,
+ GDI_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y1,
+ GDI_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y2,
+ GDI_BORDER_SIZE, SC_BORDER_SIZE,
+ GDI_EVENT_MASK, event_mask,
+ GDI_CALLBACK_ACTION, HandleScreenGadgets,
+ GDI_END);
+
+ if (gi == NULL)
+ Error(ERR_EXIT, "cannot create gadget");
+
+ screen_gadget[id] = gi;
+ }
+}
+
+void CreateScreenGadgets()
+{
+ CreateScreenScrollbuttons();
+ CreateScreenScrollbars();
+}
+
+void MapChooseLevelGadgets()
+{
+ int num_leveldirs = numLevelDirInfoInGroup(leveldir_current);
+ int i;
+
+ if (num_leveldirs <= MAX_MENU_ENTRIES_ON_SCREEN)
+ return;
+
+ for (i=0; i<NUM_SCREEN_GADGETS; i++)
+ MapGadget(screen_gadget[i]);
+}
+
+void UnmapChooseLevelGadgets()
+{
+ int i;
+
+ for (i=0; i<NUM_SCREEN_GADGETS; i++)
+ UnmapGadget(screen_gadget[i]);
+}
+
+static void HandleScreenGadgets(struct GadgetInfo *gi)
+{
+ int id = gi->custom_id;
+
+ if (game_status != CHOOSELEVEL)
+ return;
+
+ switch (id)
+ {
+ case SCREEN_CTRL_ID_SCROLL_UP:
+ HandleChooseLevel(SX,SY + 32, 0,0, MB_MENU_MARK);
+ break;
+
+ case SCREEN_CTRL_ID_SCROLL_DOWN:
+ HandleChooseLevel(SX,SY + SYSIZE - 32, 0,0, MB_MENU_MARK);
+ break;
+
+ case SCREEN_CTRL_ID_SCROLL_VERTICAL:
+ HandleChooseLevel(0,0, 999,gi->event.item_position, MB_MENU_INITIALIZE);
+ break;
+
+ default:
+ break;
+ }
+}