From: Holger Schemel Date: Sat, 9 Jan 1999 18:54:06 +0000 (+0100) Subject: rnd-19990109-1 X-Git-Tag: 1.3.0^2~32 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=0c2b6a7610933f9098ec233f7b4c2b52eac3535c;p=rocksndiamonds.git rnd-19990109-1 --- diff --git a/src/buttons.c b/src/buttons.c index 77c37437..bdac8670 100644 --- a/src/buttons.c +++ b/src/buttons.c @@ -1515,7 +1515,33 @@ static struct GadgetInfo *getGadgetInfoFromMousePosition(int mx, int my) 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; } @@ -1613,10 +1639,6 @@ struct GadgetInfo *CreateGadget(int first_tag, ...) } 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); @@ -1641,6 +1663,10 @@ struct GadgetInfo *CreateGadget(int first_tag, ...) 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; @@ -1699,6 +1725,18 @@ struct GadgetInfo *CreateGadget(int first_tag, ...) } 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; @@ -1718,17 +1756,30 @@ struct GadgetInfo *CreateGadget(int first_tag, ...) !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; } @@ -1778,34 +1829,123 @@ static void DrawGadget(struct GadgetInfo *gi, boolean pressed, boolean direct) /* 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; ipixmap, 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; ipixmap, 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; } @@ -1830,6 +1970,27 @@ void ClickOnGadget(struct GadgetInfo *gi) 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) @@ -1853,20 +2014,39 @@ static struct GadgetInfo *last_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) @@ -1882,17 +2062,17 @@ void HandleGadgets(int mx, int my, int button) } 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) @@ -1901,6 +2081,11 @@ void HandleGadgets(int mx, int my, int button) /* '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; @@ -1939,6 +2124,67 @@ void HandleGadgets(int mx, int my, int button) 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); @@ -1964,32 +2210,52 @@ void HandleGadgets(int mx, int my, int button) 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); @@ -2003,6 +2269,9 @@ void HandleGadgets(int mx, int my, int button) 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 && diff --git a/src/buttons.h b/src/buttons.h index 5a62e9a4..aca41e10 100644 --- a/src/buttons.h +++ b/src/buttons.h @@ -285,6 +285,11 @@ int CheckCountButtons(int, int, int); #define GD_TYPE_SCROLLBAR_VERTICAL (1<<7) #define GD_TYPE_SCROLLBAR_HORIZONTAL (1<<8) +#define GD_TYPE_BUTTON (GD_TYPE_NORMAL_BUTTON | \ + GD_TYPE_RADIO_BUTTON) +#define GD_TYPE_SCROLLBAR (GD_TYPE_SCROLLBAR_VERTICAL | \ + GD_TYPE_SCROLLBAR_HORIZONTAL) + /* gadget events */ #define GD_EVENT_PRESSED (1<<0) #define GD_EVENT_RELEASED (1<<1) @@ -317,16 +322,19 @@ int CheckCountButtons(int, int, int); #define GDI_NUMBER_MAX 12 #define GDI_TEXT_VALUE 13 #define GDI_TEXT_SIZE 14 -#define GDI_TEXT_BORDER 15 -#define GDI_DESIGN_UNPRESSED 16 -#define GDI_DESIGN_PRESSED 17 -#define GDI_ALT_DESIGN_UNPRESSED 18 -#define GDI_ALT_DESIGN_PRESSED 19 +#define GDI_DESIGN_UNPRESSED 15 +#define GDI_DESIGN_PRESSED 16 +#define GDI_ALT_DESIGN_UNPRESSED 17 +#define GDI_ALT_DESIGN_PRESSED 18 +#define GDI_DESIGN_BORDER 19 #define GDI_EVENT_MASK 20 #define GDI_EVENT 21 #define GDI_CALLBACK 22 #define GDI_AREA_SIZE 23 #define GDI_ITEM_SIZE 24 +#define GDI_SCROLLBAR_ITEMS_MAX 25 +#define GDI_SCROLLBAR_ITEMS_VISIBLE 26 +#define GDI_SCROLLBAR_ITEM_POSITION 27 typedef void (*gadget_callback_function)(void *); @@ -342,6 +350,7 @@ struct GadgetEvent int button; /* button number for button events */ int x, y; /* gadget position at event time */ boolean off_borders; /* mouse pointer outside gadget? */ + int item_x, item_y, item_position; /* new item position */ }; struct GadgetDrawingArea @@ -350,6 +359,18 @@ struct GadgetDrawingArea int item_xsize, item_ysize; /* size of each item in drawing area */ }; +struct GadgetScrollbar +{ + int items_max; /* number of items to access */ + int items_visible; /* number of visible items */ + int item_position; /* actual item position */ + int size_max; /* this is either width or height */ + int size; /* scrollbar size on screen */ + int position; /* scrollbar position on screen */ + int position_max; /* bottom/right scrollbar position */ + int drag_position; /* drag position on scrollbar */ +}; + struct GadgetInfo { int id; /* internal gadget identifier */ @@ -364,13 +385,14 @@ struct GadgetInfo long number_value; char text_value[MAX_GADGET_TEXTSIZE]; int text_size; /* maximal size of input text */ - int text_border; /* border size of text input gadget */ struct GadgetDesign design[2]; /* 0: normal; 1: pressed */ struct GadgetDesign alt_design[2]; /* alternative design */ + int design_border; /* border size of gadget decoration */ unsigned long event_mask; /* possible events for this gadget */ struct GadgetEvent event; /* actual gadget event */ gadget_callback_function callback; struct GadgetDrawingArea drawing; /* fields for drawing area gadget */ + struct GadgetScrollbar scrollbar; /* fields for scrollbar gadget */ struct GadgetInfo *next; /* next list entry */ }; @@ -378,6 +400,7 @@ struct GadgetInfo *CreateGadget(int, ...); void FreeGadget(struct GadgetInfo *); void ClickOnGadget(struct GadgetInfo *); +void AdjustScrollbar(struct GadgetInfo *, int, int); void MapGadget(struct GadgetInfo *); void UnmapGadget(struct GadgetInfo *); diff --git a/src/editor.c b/src/editor.c index 4b3110b1..7d885e14 100644 --- a/src/editor.c +++ b/src/editor.c @@ -89,12 +89,20 @@ /* 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 @@ -140,8 +148,10 @@ #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 @@ -149,6 +159,7 @@ #define ED_NUM_COUNTERBUTTONS 2 #define ED_NUM_SCROLLBUTTONS 4 +#define ED_NUM_SCROLLBARS 2 /* values for CopyLevelToUndoBuffer() */ #define UNDO_IMMEDIATE 0 @@ -181,6 +192,27 @@ static struct 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(); @@ -898,9 +930,9 @@ static void CreateTextInputGadgets() 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); @@ -911,6 +943,62 @@ static void CreateTextInputGadgets() level_editor_gadget[id] = gi; } +static void CreateScrollbarGadgets() +{ + int i; + + for (i=0; i= 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; @@ -2953,12 +3055,18 @@ static void HandleControlButtons(struct GadgetInfo *gi) 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; @@ -2969,12 +3077,18 @@ static void HandleControlButtons(struct GadgetInfo *gi) 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; @@ -2985,9 +3099,21 @@ static void HandleControlButtons(struct GadgetInfo *gi) 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;