if (gi->mapped &&
mx >= gi->x && mx < gi->x + gi->width &&
my >= gi->y && my < gi->y + gi->height)
- break;
+ {
+
+#if 0
+ if (gi->type & GD_TYPE_SCROLLBAR)
+ {
+ int mpos, gpos;
+
+ if (gi->type == GD_TYPE_SCROLLBAR_HORIZONTAL)
+ {
+ mpos = mx;
+ gpos = gi->x;
+ }
+ else
+ {
+ mpos = my;
+ gpos = gi->y;
+ }
+
+ if (mpos >= gpos + gi->scrollbar.position &&
+ mpos < gpos + gi->scrollbar.position + gi->scrollbar.size)
+ break;
+ }
+ else
+#endif
+
+ break;
+ }
gi = gi->next;
}
}
break;
- case GDI_TEXT_BORDER:
- new_gadget->text_border = va_arg(ap, int);
- break;
-
case GDI_DESIGN_UNPRESSED:
new_gadget->design[GD_BUTTON_UNPRESSED].pixmap = va_arg(ap, Pixmap);
new_gadget->design[GD_BUTTON_UNPRESSED].x = va_arg(ap, int);
new_gadget->alt_design[GD_BUTTON_PRESSED].y = va_arg(ap, int);
break;
+ case GDI_DESIGN_BORDER:
+ new_gadget->design_border = va_arg(ap, int);
+ break;
+
case GDI_EVENT_MASK:
new_gadget->event_mask = va_arg(ap, unsigned long);
break;
}
break;
+ case GDI_SCROLLBAR_ITEMS_MAX:
+ new_gadget->scrollbar.items_max = va_arg(ap, int);
+ break;
+
+ case GDI_SCROLLBAR_ITEMS_VISIBLE:
+ new_gadget->scrollbar.items_visible = va_arg(ap, int);
+ break;
+
+ case GDI_SCROLLBAR_ITEM_POSITION:
+ new_gadget->scrollbar.item_position = va_arg(ap, int);
+ break;
+
case GDI_CALLBACK:
new_gadget->callback = va_arg(ap, gadget_callback_function);
break;
!new_gadget->design[GD_BUTTON_PRESSED].pixmap))
Error(ERR_EXIT, "gadget incomplete (missing Pixmap)");
- /* insert new gadget into gloabl gadget list */
+ if (new_gadget->type & GD_TYPE_SCROLLBAR)
+ {
+ struct GadgetScrollbar *gs = &new_gadget->scrollbar;
+
+ if (new_gadget->width == 0 || new_gadget->height == 0 ||
+ gs->items_max == 0 || gs->items_visible == 0)
+ Error(ERR_EXIT, "scrollbar gadget incomplete (missing tags)");
+
+ /* calculate internal scrollbar values */
+ gs->size_max = (new_gadget->type == GD_TYPE_SCROLLBAR_VERTICAL ?
+ new_gadget->height : new_gadget->width);
+ gs->size = gs->size_max * gs->items_visible / gs->items_max;
+ gs->position = gs->size_max * gs->item_position / gs->items_max;
+ gs->position_max = gs->size_max - gs->size;
+ }
+ /* insert new gadget into global gadget list */
if (gadget_list_last_entry)
{
gadget_list_last_entry->next = new_gadget;
gadget_list_last_entry = gadget_list_last_entry->next;
}
else
- {
gadget_list_first_entry = gadget_list_last_entry = new_gadget;
- }
return new_gadget;
}
/* left part of gadget */
XCopyArea(display, gd->pixmap, drawto, gc,
gd->x, gd->y,
- gi->text_border, gi->height,
+ gi->design_border, gi->height,
gi->x, gi->y);
/* middle part of gadget */
for (i=0; i<=gi->text_size; i++)
XCopyArea(display, gd->pixmap, drawto, gc,
- gd->x + gi->text_border, gd->y,
+ gd->x + gi->design_border, gd->y,
FONT2_XSIZE, gi->height,
- gi->x + gi->text_border + i * FONT2_XSIZE, gi->y);
+ gi->x + gi->design_border + i * FONT2_XSIZE, gi->y);
/* right part of gadget */
XCopyArea(display, gd->pixmap, drawto, gc,
- gd->x + ED_WIN_COUNT_XSIZE - gi->text_border, gd->y,
- gi->text_border, gi->height,
- gi->x + gi->width - gi->text_border, gi->y);
+ gd->x + ED_WIN_COUNT_XSIZE - gi->design_border, gd->y,
+ gi->design_border, gi->height,
+ gi->x + gi->width - gi->design_border, gi->y);
/* gadget text value */
- DrawText(gi->x + gi->text_border, gi->y + gi->text_border,
+ DrawText(gi->x + gi->design_border, gi->y + gi->design_border,
gi->text_value, FS_SMALL, (pressed ? FC_GREEN : FC_YELLOW));
/* draw cursor, if active */
- DrawText(gi->x + gi->text_border + strlen(gi->text_value)*FONT2_XSIZE,
- gi->y + gi->text_border,
+ DrawText(gi->x + gi->design_border +
+ strlen(gi->text_value) * FONT2_XSIZE,
+ gi->y + gi->design_border,
(pressed ? "<" : " "),
FS_SMALL, FC_RED);
}
break;
+ case GD_TYPE_SCROLLBAR_VERTICAL:
+ {
+ int i;
+ int xpos = gi->x;
+ int ypos = gi->y + gi->scrollbar.position;
+ int design_full = gi->width;
+ int design_body = design_full - 2 * gi->design_border;
+ int size_full = gi->scrollbar.size;
+ int size_body = size_full - 2 * gi->design_border;
+ int num_steps = size_body / design_body;
+ int step_size_remain = size_body - num_steps * design_body;
+
+ /* clear scrollbar area */
+ XFillRectangle(display, backbuffer, gc,
+ gi->x, gi->y, gi->width, gi->height);
+
+ /* upper part of gadget */
+ XCopyArea(display, gd->pixmap, drawto, gc,
+ gd->x, gd->y,
+ gi->width, gi->design_border,
+ xpos, ypos);
+
+ /* middle part of gadget */
+ for (i=0; i<num_steps; i++)
+ XCopyArea(display, gd->pixmap, drawto, gc,
+ gd->x, gd->y + gi->design_border,
+ gi->width, design_body,
+ xpos, ypos + gi->design_border + i * design_body);
+
+ /* remaining middle part of gadget */
+ if (step_size_remain > 0)
+ XCopyArea(display, gd->pixmap, drawto, gc,
+ gd->x, gd->y + gi->design_border,
+ gi->width, step_size_remain,
+ xpos, ypos + gi->design_border + num_steps * design_body);
+
+ /* lower part of gadget */
+ XCopyArea(display, gd->pixmap, drawto, gc,
+ gd->x, gd->y + design_full - gi->design_border,
+ gi->width, gi->design_border,
+ xpos, ypos + size_full - gi->design_border);
+ }
+ break;
+
+ case GD_TYPE_SCROLLBAR_HORIZONTAL:
+ {
+ int i;
+ int xpos = gi->x + gi->scrollbar.position;
+ int ypos = gi->y;
+ int design_full = gi->height;
+ int design_body = design_full - 2 * gi->design_border;
+ int size_full = gi->scrollbar.size;
+ int size_body = size_full - 2 * gi->design_border;
+ int num_steps = size_body / design_body;
+ int step_size_remain = size_body - num_steps * design_body;
+
+ /* clear scrollbar area */
+ XFillRectangle(display, backbuffer, gc,
+ gi->x, gi->y, gi->width, gi->height);
+
+ /* left part of gadget */
+ XCopyArea(display, gd->pixmap, drawto, gc,
+ gd->x, gd->y,
+ gi->design_border, gi->height,
+ xpos, ypos);
+
+ /* middle part of gadget */
+ for (i=0; i<num_steps; i++)
+ XCopyArea(display, gd->pixmap, drawto, gc,
+ gd->x + gi->design_border, gd->y,
+ design_body, gi->height,
+ xpos + gi->design_border + i * design_body, ypos);
+
+ /* remaining middle part of gadget */
+ if (step_size_remain > 0)
+ XCopyArea(display, gd->pixmap, drawto, gc,
+ gd->x + gi->design_border, gd->y,
+ step_size_remain, gi->height,
+ xpos + gi->design_border + num_steps * design_body, ypos);
+
+ /* right part of gadget */
+ XCopyArea(display, gd->pixmap, drawto, gc,
+ gd->x + design_full - gi->design_border, gd->y,
+ gi->design_border, gi->height,
+ xpos + size_full - gi->design_border, ypos);
+ }
+ break;
+
default:
return;
}
HandleGadgets(gi->x, gi->y, 0);
}
+void AdjustScrollbar(struct GadgetInfo *gi, int items_max, int item_pos)
+{
+ struct GadgetScrollbar *gs = &gi->scrollbar;
+
+ gs->items_max = items_max;
+ gs->item_position = item_pos;
+
+ gs->size = gs->size_max * gs->items_visible / gs->items_max;
+ gs->position = gs->size_max * gs->item_position / gs->items_max;
+ gs->position_max = gs->size_max - gs->size;
+
+ /* finetuning for maximal right/bottom position */
+ if (gs->item_position == gs->items_max - gs->items_visible)
+ gs->position = gs->position_max;
+
+ printf("gs->item_position == %d\n", gs->item_position);
+
+ if (gi->mapped)
+ DrawGadget(gi, DG_UNPRESSED, DG_DIRECT);
+}
+
void MapGadget(struct GadgetInfo *gi)
{
if (gi == NULL)
void HandleGadgets(int mx, int my, int button)
{
static unsigned long pressed_delay = 0;
-
+ static last_button = 0;
+ static last_mx = 0, last_my = 0;
+ int scrollbar_mouse_pos;
struct GadgetInfo *new_gi, *gi;
+ boolean press_event;
+ boolean release_event;
+ boolean mouse_moving;
boolean gadget_pressed;
boolean gadget_pressed_repeated;
boolean gadget_moving;
+ boolean gadget_moving_inside;
boolean gadget_moving_off_borders;
boolean gadget_released;
+ boolean gadget_released_inside;
boolean gadget_released_off_borders;
- if (gadget_list_first_entry == NULL) /* no gadgets defined */
+ /* check if there are any gadgets defined */
+ if (gadget_list_first_entry == NULL)
return;
+ /* check which gadget is under the mouse pointer */
new_gi = getGadgetInfoFromMousePosition(mx, my);
+ /* check if button state has changed since last invocation */
+ press_event = (button != 0 && last_button == 0);
+ release_event = (button == 0 && last_button != 0);
+ last_button = button;
+
+ /* check if mouse has been moved since last invocation */
+ mouse_moving = ((mx != last_mx || my != last_my) && motion_status);
+ last_mx = mx;
+ last_my = my;
+
/* if mouse button pressed outside text input gadget, deactivate it */
if (last_gi && last_gi->type == GD_TYPE_TEXTINPUT &&
button != 0 && new_gi != last_gi && !motion_status)
}
gadget_pressed =
- (button != 0 && last_gi == NULL && new_gi != NULL && !motion_status);
+ (button != 0 && last_gi == NULL && new_gi != NULL && press_event);
gadget_pressed_repeated =
(button != 0 && last_gi != NULL && new_gi == last_gi);
- gadget_moving =
- (button != 0 && last_gi != NULL && new_gi == last_gi && motion_status);
- gadget_moving_off_borders =
- (button != 0 && last_gi != NULL && new_gi != last_gi && motion_status);
- gadget_released =
- (button == 0 && last_gi != NULL && new_gi == last_gi);
- gadget_released_off_borders =
- (button == 0 && last_gi != NULL && new_gi != last_gi);
+
+ gadget_released = (button == 0 && last_gi != NULL);
+ gadget_released_inside = (gadget_released && new_gi == last_gi);
+ gadget_released_off_borders = (gadget_released && new_gi != last_gi);
+
+ gadget_moving = (button != 0 && last_gi != NULL && mouse_moving);
+ gadget_moving_inside = (gadget_moving && new_gi == last_gi);
+ gadget_moving_off_borders = (gadget_moving && new_gi != last_gi);
/* if new gadget pressed, store this gadget */
if (gadget_pressed)
/* 'gi' is actually handled gadget */
gi = last_gi;
+ /* if gadget is scrollbar, choose mouse position value */
+ if (gi && gi->type & GD_TYPE_SCROLLBAR)
+ scrollbar_mouse_pos =
+ (gi->type == GD_TYPE_SCROLLBAR_HORIZONTAL ? mx - gi->x : my - gi->y);
+
/* if mouse button released, no gadget needs to be handled anymore */
if (button == 0 && last_gi && last_gi->type != GD_TYPE_TEXTINPUT)
last_gi = NULL;
gi->radio_pressed = TRUE;
}
+ else if (gi->type & GD_TYPE_SCROLLBAR)
+ {
+ int mpos, gpos;
+
+ if (gi->type == GD_TYPE_SCROLLBAR_HORIZONTAL)
+ {
+ mpos = mx;
+ gpos = gi->x;
+ }
+ else
+ {
+ mpos = my;
+ gpos = gi->y;
+ }
+
+ if (mpos >= gpos + gi->scrollbar.position &&
+ mpos < gpos + gi->scrollbar.position + gi->scrollbar.size)
+ {
+ /* drag scrollbar */
+ gi->scrollbar.drag_position =
+ scrollbar_mouse_pos - gi->scrollbar.position;
+ }
+ else
+ {
+ /* click scrollbar one scrollbar length up/left or down/right */
+
+ struct GadgetScrollbar *gs = &gi->scrollbar;
+ int old_item_position = gs->item_position;
+ boolean changed_position = FALSE;
+
+ gs->item_position +=
+ gs->items_visible * (mpos < gpos + gi->scrollbar.position ? -1 : +1);
+
+ if (gs->item_position < 0)
+ gs->item_position = 0;
+ if (gs->item_position > gs->items_max - gs->items_visible)
+ gs->item_position = gs->items_max - gs->items_visible;
+
+ if (old_item_position != gs->item_position)
+ {
+ gi->event.item_position = gs->item_position;
+ changed_position = TRUE;
+
+ printf("gs->item_position == %d\n", gs->item_position);
+ }
+
+ AdjustScrollbar(gi, gs->items_max, gs->item_position);
+
+ gi->state = GD_BUTTON_UNPRESSED;
+ gi->event.type = GD_EVENT_MOVING;
+ gi->event.off_borders = FALSE;
+
+ if (gi->event_mask & GD_EVENT_MOVING && changed_position)
+ gi->callback(gi);
+
+ /* don't handle this scrollbar anymore while mouse button pressed */
+ last_gi = NULL;
+
+ return;
+ }
+ }
DrawGadget(gi, DG_PRESSED, DG_DIRECT);
if (gadget_moving)
{
- if (gi->state == GD_BUTTON_UNPRESSED)
- DrawGadget(gi, DG_PRESSED, DG_DIRECT);
+ boolean changed_position = FALSE;
- gi->state = GD_BUTTON_PRESSED;
- gi->event.type = GD_EVENT_MOVING;
- gi->event.off_borders = FALSE;
- if (gi->event_mask & GD_EVENT_MOVING)
- gi->callback(gi);
- }
+ if (gi->type & GD_TYPE_BUTTON)
+ {
+ if (gadget_moving_inside && gi->state == GD_BUTTON_UNPRESSED)
+ DrawGadget(gi, DG_PRESSED, DG_DIRECT);
+ else if (gadget_moving_off_borders && gi->state == GD_BUTTON_PRESSED)
+ DrawGadget(gi, DG_UNPRESSED, DG_DIRECT);
+ }
- if (gadget_moving_off_borders)
- {
- if (gi->state == GD_BUTTON_PRESSED &&
- gi->type != GD_TYPE_TEXTINPUT)
- DrawGadget(gi, DG_UNPRESSED, DG_DIRECT);
+ if (gi->type & GD_TYPE_SCROLLBAR)
+ {
+ struct GadgetScrollbar *gs = &gi->scrollbar;
+ int old_item_position = gs->item_position;
- gi->state = GD_BUTTON_UNPRESSED;
+ gs->position = scrollbar_mouse_pos - gs->drag_position;
+
+ if (gs->position < 0)
+ gs->position = 0;
+ if (gs->position > gs->position_max)
+ gs->position = gs->position_max;
+
+ gs->item_position = gs->items_max * gs->position / gs->size_max;
+
+ if (old_item_position != gs->item_position)
+ {
+ gi->event.item_position = gs->item_position;
+ changed_position = TRUE;
+
+ printf("gs->item_position == %d\n", gs->item_position);
+ }
+
+ DrawGadget(gi, DG_PRESSED, DG_DIRECT);
+ }
+
+ gi->state = (gadget_moving_inside || gi->type & GD_TYPE_SCROLLBAR ?
+ GD_BUTTON_PRESSED : GD_BUTTON_UNPRESSED);
gi->event.type = GD_EVENT_MOVING;
- gi->event.off_borders = TRUE;
+ gi->event.off_borders = gadget_moving_off_borders;
- if (gi->event_mask & GD_EVENT_MOVING &&
- gi->event_mask & GD_EVENT_OFF_BORDERS)
+ if (gi->event_mask & GD_EVENT_MOVING && changed_position &&
+ (gadget_moving_inside || gi->event_mask & GD_EVENT_OFF_BORDERS))
gi->callback(gi);
}
- if (gadget_released)
+ if (gadget_released_inside)
{
if (gi->type != GD_TYPE_TEXTINPUT)
DrawGadget(gi, DG_UNPRESSED, DG_DIRECT);
if (gadget_released_off_borders)
{
+ if (gi->type & GD_TYPE_SCROLLBAR)
+ DrawGadget(gi, DG_UNPRESSED, DG_DIRECT);
+
gi->event.type = GD_EVENT_RELEASED;
if (gi->event_mask & GD_EVENT_RELEASED &&
/* values for scrolling gadgets */
#define ED_SCROLL_UP_XPOS (SXSIZE - ED_SCROLLBUTTON_XSIZE)
#define ED_SCROLL_UP_YPOS (0)
-#define ED_SCROLL_DOWN_XPOS (SXSIZE - ED_SCROLLBUTTON_XSIZE)
+#define ED_SCROLL_DOWN_XPOS ED_SCROLL_UP_XPOS
#define ED_SCROLL_DOWN_YPOS (SYSIZE - TILEX - ED_SCROLLBUTTON_YSIZE)
#define ED_SCROLL_LEFT_XPOS (0)
#define ED_SCROLL_LEFT_YPOS (SYSIZE - ED_SCROLLBUTTON_YSIZE)
#define ED_SCROLL_RIGHT_XPOS (SXSIZE - TILEX - ED_SCROLLBUTTON_XSIZE)
-#define ED_SCROLL_RIGHT_YPOS (SYSIZE - ED_SCROLLBUTTON_YSIZE)
+#define ED_SCROLL_RIGHT_YPOS ED_SCROLL_LEFT_YPOS
+#define ED_SCROLL_VERTICAL_XPOS ED_SCROLL_UP_XPOS
+#define ED_SCROLL_VERTICAL_YPOS (ED_SCROLL_UP_YPOS + 20)
+#define ED_SCROLL_VERTICAL_XSIZE 30
+#define ED_SCROLL_VERTICAL_YSIZE (SYSIZE - TILEY - 2 * 20)
+#define ED_SCROLL_HORIZONTAL_XPOS (ED_SCROLL_LEFT_XPOS + 30)
+#define ED_SCROLL_HORIZONTAL_YPOS (SYSIZE - 30)
+#define ED_SCROLL_HORIZONTAL_XSIZE (SXSIZE - TILEX - 2*30)
+#define ED_SCROLL_HORIZONTAL_YSIZE 30
/* control button identifiers */
#define ED_CTRL_ID_SINGLE_ITEMS 0
#define ED_CTRL_ID_SCROLL_DOWN 38
#define ED_CTRL_ID_SCROLL_LEFT 39
#define ED_CTRL_ID_SCROLL_RIGHT 40
+#define ED_CTRL_ID_SCROLL_VERTICAL 41
+#define ED_CTRL_ID_SCROLL_HORIZONTAL 42
-#define ED_NUM_GADGETS 41
+#define ED_NUM_GADGETS 43
/* values for counter gadgets */
#define ED_COUNTER_SCORE 0
#define ED_NUM_COUNTERBUTTONS 2
#define ED_NUM_SCROLLBUTTONS 4
+#define ED_NUM_SCROLLBARS 2
/* values for CopyLevelToUndoBuffer() */
#define UNDO_IMMEDIATE 0
ED_SCROLL_RIGHT_XPOS, ED_SCROLL_RIGHT_YPOS, ED_CTRL_ID_SCROLL_RIGHT }
};
+static struct
+{
+ int xpos, ypos;
+ int x, y;
+ int width, height;
+ int type;
+ int gadget_id;
+} scrollbar_info[ED_NUM_SCROLLBARS] =
+{
+ { GAME_CONTROL_XPOS, GAME_CONTROL_YPOS - GAME_BUTTON_YSIZE,
+ ED_SCROLL_VERTICAL_XPOS, ED_SCROLL_VERTICAL_YPOS,
+ ED_SCROLL_VERTICAL_XSIZE, ED_SCROLL_VERTICAL_YSIZE,
+ GD_TYPE_SCROLLBAR_VERTICAL,
+ ED_CTRL_ID_SCROLL_VERTICAL },
+ { GAME_CONTROL_XPOS, GAME_CONTROL_YPOS - GAME_BUTTON_YSIZE,
+ ED_SCROLL_HORIZONTAL_XPOS, ED_SCROLL_HORIZONTAL_YPOS,
+ ED_SCROLL_HORIZONTAL_XSIZE, ED_SCROLL_HORIZONTAL_YSIZE,
+ GD_TYPE_SCROLLBAR_HORIZONTAL,
+ ED_CTRL_ID_SCROLL_HORIZONTAL },
+};
+
/* forward declaration for internal use */
static void DrawDrawingWindow();
GDI_TYPE, GD_TYPE_TEXTINPUT,
GDI_TEXT_VALUE, level.name,
GDI_TEXT_SIZE, 30,
- GDI_TEXT_BORDER, 3,
GDI_DESIGN_UNPRESSED, gd_pixmap, gd_x, gd_y,
GDI_DESIGN_PRESSED, gd_pixmap, gd_x, gd_y,
+ GDI_DESIGN_BORDER, 3,
GDI_EVENT_MASK, event_mask,
GDI_CALLBACK, HandleTextInputGadgets,
GDI_END);
level_editor_gadget[id] = gi;
}
+static void CreateScrollbarGadgets()
+{
+ int i;
+
+ for (i=0; i<ED_NUM_SCROLLBARS; i++)
+ {
+ int id = scrollbar_info[i].gadget_id;
+ Pixmap gd_pixmap = pix[PIX_DOOR];
+ int gd_x1, gd_x2, gd_y;
+ struct GadgetInfo *gi;
+ int items_max, items_visible, item_position;
+ unsigned long event_mask;
+
+ if (scrollbar_info[i].type == GD_TYPE_SCROLLBAR_HORIZONTAL)
+ {
+ items_max = lev_fieldx + 2;
+ items_visible = ED_FIELDX;
+ item_position = 0;
+ }
+ else
+ {
+ items_max = lev_fieldy + 2;
+ items_visible = ED_FIELDY;
+ item_position = 0;
+ }
+
+ event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
+
+ gd_x1 = DOOR_GFX_PAGEX4 + scrollbar_info[i].xpos;
+ gd_x2 = DOOR_GFX_PAGEX3 + scrollbar_info[i].xpos;
+ gd_y = DOOR_GFX_PAGEY1 + scrollbar_info[i].ypos;
+
+ gi = CreateGadget(GDI_CUSTOM_ID, id,
+ GDI_X, SX + scrollbar_info[i].x,
+ GDI_Y, SY + 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_pixmap, gd_x1, gd_y,
+ GDI_DESIGN_PRESSED, gd_pixmap, gd_x2, gd_y,
+ GDI_DESIGN_BORDER, 3,
+ GDI_EVENT_MASK, event_mask,
+ GDI_CALLBACK, HandleControlButtons,
+ GDI_END);
+
+ if (gi == NULL)
+ Error(ERR_EXIT, "cannot create gadget");
+
+ level_editor_gadget[id] = gi;
+ }
+}
+
static void CreateLevelEditorGadgets()
{
if (level_editor_gadgets_created)
CreateCounterButtons();
CreateDrawingAreas();
CreateTextInputGadgets();
+ CreateScrollbarGadgets();
level_editor_gadgets_created = TRUE;
}
for (i=0; i<ED_NUM_SCROLLBUTTONS; i++)
MapGadget(level_editor_gadget[scrollbutton_info[i].gadget_id]);
+ for (i=0; i<ED_NUM_SCROLLBARS; i++)
+ MapGadget(level_editor_gadget[scrollbar_info[i].gadget_id]);
+
MapDrawingArea(ED_CTRL_ID_DRAWING_LEVEL);
}
case ED_CTRL_ID_SCROLL_LEFT:
if (level_xpos >= 0)
{
+ int gadget_id = ED_CTRL_ID_SCROLL_HORIZONTAL;
+ struct GadgetInfo *gi = level_editor_gadget[gadget_id];
+ struct GadgetScrollbar *gs = &gi->scrollbar;
+
if (lev_fieldx < ED_FIELDX - 2)
break;
level_xpos -= step;
- if (level_xpos <- 1)
+ if (level_xpos < -1)
level_xpos = -1;
if (button == 1)
ScrollMiniLevel(level_xpos, level_ypos, ED_SCROLL_RIGHT);
else
DrawMiniLevel(level_xpos, level_ypos);
+
+ AdjustScrollbar(gi, gs->items_max, level_xpos + 1);
}
break;
case ED_CTRL_ID_SCROLL_RIGHT:
if (level_xpos <= lev_fieldx - ED_FIELDX)
{
+ int gadget_id = ED_CTRL_ID_SCROLL_HORIZONTAL;
+ struct GadgetInfo *gi = level_editor_gadget[gadget_id];
+ struct GadgetScrollbar *gs = &gi->scrollbar;
+
if (lev_fieldx < ED_FIELDX - 2)
break;
ScrollMiniLevel(level_xpos, level_ypos, ED_SCROLL_LEFT);
else
DrawMiniLevel(level_xpos, level_ypos);
+
+ AdjustScrollbar(gi, gs->items_max, level_xpos + 1);
}
break;
case ED_CTRL_ID_SCROLL_UP:
if (level_ypos >= 0)
{
+ int gadget_id = ED_CTRL_ID_SCROLL_VERTICAL;
+ struct GadgetInfo *gi = level_editor_gadget[gadget_id];
+ struct GadgetScrollbar *gs = &gi->scrollbar;
+
if (lev_fieldy < ED_FIELDY - 2)
break;
ScrollMiniLevel(level_xpos, level_ypos, ED_SCROLL_DOWN);
else
DrawMiniLevel(level_xpos, level_ypos);
+
+ AdjustScrollbar(gi, gs->items_max, level_ypos + 1);
}
break;
case ED_CTRL_ID_SCROLL_DOWN:
if (level_ypos <= lev_fieldy - ED_FIELDY)
{
+ int gadget_id = ED_CTRL_ID_SCROLL_VERTICAL;
+ struct GadgetInfo *gi = level_editor_gadget[gadget_id];
+ struct GadgetScrollbar *gs = &gi->scrollbar;
+
if (lev_fieldy < ED_FIELDY - 2)
break;
ScrollMiniLevel(level_xpos, level_ypos, ED_SCROLL_UP);
else
DrawMiniLevel(level_xpos, level_ypos);
+
+ AdjustScrollbar(gi, gs->items_max, level_ypos + 1);
}
break;
+ case ED_CTRL_ID_SCROLL_HORIZONTAL:
+ level_xpos = gi->event.item_position - 1;
+ DrawMiniLevel(level_xpos, level_ypos);
+ break;
+
+ case ED_CTRL_ID_SCROLL_VERTICAL:
+ level_ypos = gi->event.item_position - 1;
+ DrawMiniLevel(level_xpos, level_ypos);
+ break;
+
case ED_CTRL_ID_WRAP_LEFT:
WrapLevel(-step, 0);
break;