From: Holger Schemel Date: Wed, 16 Dec 1998 22:43:10 +0000 (+0100) Subject: rnd-19981216-3 X-Git-Tag: 1.3.0^2~56 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=f6ba86f49b8d92a6cb8d06b42e580195d09b8183;p=rocksndiamonds.git rnd-19981216-3 --- diff --git a/src/buttons.c b/src/buttons.c index cffd190b..efb8ebf6 100644 --- a/src/buttons.c +++ b/src/buttons.c @@ -1523,6 +1523,11 @@ static struct GadgetInfo *getGadgetInfoFromMousePosition(int mx, int my) return gi; } +static void default_callback_function(void *ptr) +{ + return; +} + struct GadgetInfo *CreateGadget(int first_tag, ...) { struct GadgetInfo *new_gadget = checked_malloc(sizeof(struct GadgetInfo)); @@ -1532,76 +1537,136 @@ struct GadgetInfo *CreateGadget(int first_tag, ...) va_start(ap, first_tag); /* always start with reliable default values */ - memset(new_gadget, 0, sizeof(struct GadgetInfo)); - - new_gadget->id = getNewGadgetID(); + memset(new_gadget, 0, sizeof(struct GadgetInfo)); /* zero all fields */ + new_gadget->id = getNewGadgetID(); /* new gadget id */ + new_gadget->callback = default_callback_function; /* dummy function */ while (tag != GDI_END) { - - - -#if 0 - printf("tag: %d\n", tag); -#endif - - - switch(tag) { - case GDI_ID: - new_gadget->id = va_arg(ap, int); + case GDI_CUSTOM_ID: + new_gadget->custom_id = va_arg(ap, int); break; + case GDI_X: new_gadget->x = va_arg(ap, int); break; + case GDI_Y: new_gadget->y = va_arg(ap, int); break; + case GDI_WIDTH: new_gadget->width = va_arg(ap, int); break; + case GDI_HEIGHT: new_gadget->height = va_arg(ap, int); break; + case GDI_TYPE: new_gadget->type = va_arg(ap, unsigned long); break; + case GDI_STATE: new_gadget->state = va_arg(ap, unsigned long); break; + case GDI_ALT_STATE: new_gadget->state = va_arg(ap, boolean); break; + case GDI_NUMBER_VALUE: new_gadget->number_value = va_arg(ap, long); break; + case GDI_TEXT_VALUE: strcpy(new_gadget->text_value, va_arg(ap, char *)); 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->design[GD_BUTTON_UNPRESSED].y = va_arg(ap, int); break; + case GDI_DESIGN_PRESSED: new_gadget->design[GD_BUTTON_PRESSED].pixmap = va_arg(ap, Pixmap); new_gadget->design[GD_BUTTON_PRESSED].x = va_arg(ap, int); new_gadget->design[GD_BUTTON_PRESSED].y = va_arg(ap, int); break; + case GDI_ALT_DESIGN_UNPRESSED: new_gadget->alt_design[GD_BUTTON_UNPRESSED].pixmap= va_arg(ap, Pixmap); new_gadget->alt_design[GD_BUTTON_UNPRESSED].x = va_arg(ap, int); new_gadget->alt_design[GD_BUTTON_UNPRESSED].y = va_arg(ap, int); break; + case GDI_ALT_DESIGN_PRESSED: new_gadget->alt_design[GD_BUTTON_PRESSED].pixmap = va_arg(ap, Pixmap); new_gadget->alt_design[GD_BUTTON_PRESSED].x = va_arg(ap, int); new_gadget->alt_design[GD_BUTTON_PRESSED].y = va_arg(ap, int); break; + case GDI_EVENT_MASK: new_gadget->event_mask = va_arg(ap, unsigned long); break; + + case GDI_AREA_SIZE: + new_gadget->drawing.area_xsize = va_arg(ap, int); + new_gadget->drawing.area_ysize = va_arg(ap, int); + + /* determine dependent values for drawing area gadget, if needed */ + if (new_gadget->width == 0 && + new_gadget->height == 0 && + new_gadget->drawing.item_xsize !=0 && + new_gadget->drawing.item_ysize !=0) + { + new_gadget->width = + new_gadget->drawing.area_xsize * new_gadget->drawing.item_xsize; + new_gadget->height = + new_gadget->drawing.area_ysize * new_gadget->drawing.item_ysize; + } + else if (new_gadget->drawing.item_xsize == 0 && + new_gadget->drawing.item_ysize == 0 && + new_gadget->width != 0 && + new_gadget->height != 0) + { + new_gadget->drawing.item_xsize = + new_gadget->width / new_gadget->drawing.area_xsize; + new_gadget->drawing.item_ysize = + new_gadget->height / new_gadget->drawing.area_ysize; + } + break; + + case GDI_ITEM_SIZE: + new_gadget->drawing.item_xsize = va_arg(ap, int); + new_gadget->drawing.item_ysize = va_arg(ap, int); + + /* determine dependent values for drawing area gadget, if needed */ + if (new_gadget->width == 0 && + new_gadget->height == 0 && + new_gadget->drawing.area_xsize !=0 && + new_gadget->drawing.area_ysize !=0) + { + new_gadget->width = + new_gadget->drawing.area_xsize * new_gadget->drawing.item_xsize; + new_gadget->height = + new_gadget->drawing.area_ysize * new_gadget->drawing.item_ysize; + } + else if (new_gadget->drawing.area_xsize == 0 && + new_gadget->drawing.area_ysize == 0 && + new_gadget->width != 0 && + new_gadget->height != 0) + { + new_gadget->drawing.area_xsize = + new_gadget->width / new_gadget->drawing.item_xsize; + new_gadget->drawing.area_ysize = + new_gadget->height / new_gadget->drawing.item_ysize; + } + break; + case GDI_CALLBACK: new_gadget->callback = va_arg(ap, gadget_callback_function); break; @@ -1616,8 +1681,9 @@ struct GadgetInfo *CreateGadget(int first_tag, ...) va_end(ap); /* check if gadget complete */ - if (!new_gadget->design[GD_BUTTON_UNPRESSED].pixmap || - !new_gadget->design[GD_BUTTON_PRESSED].pixmap) + if (new_gadget->type != GD_TYPE_DRAWING_AREA && + (!new_gadget->design[GD_BUTTON_UNPRESSED].pixmap || + !new_gadget->design[GD_BUTTON_PRESSED].pixmap)) Error(ERR_EXIT, "gadget incomplete (missing Pixmap)"); /* insert new gadget into gloabl gadget list */ @@ -1659,6 +1725,9 @@ static void DrawGadget(struct GadgetInfo *gi, boolean pressed, boolean direct) &gi->alt_design[state] : &gi->design[state]); + if (gi->type != GD_TYPE_NORMAL_BUTTON) + return; + XCopyArea(display, gd->pixmap, drawto, gc, gd->x, gd->y, gi->width, gi->height, gi->x, gi->y); @@ -1690,14 +1759,145 @@ void UnmapGadget(struct GadgetInfo *gi) void HandleGadgets(int mx, int my, int button) { static struct GadgetInfo *gi = NULL; + static unsigned long pressed_delay = 0; + +#if 0 static boolean pressed = FALSE; +#endif + struct GadgetInfo *new_gi; + boolean gadget_pressed; + boolean gadget_pressed_repeated; + boolean gadget_moving_inside; + boolean gadget_moving_outside; + boolean gadget_released; if (gadget_list_first_entry == NULL) return; new_gi = getGadgetInfoFromMousePosition(mx,my); + gadget_pressed = + (button != 0 && gi == NULL && new_gi != NULL); + gadget_pressed_repeated = + (button != 0 && gi != NULL && new_gi == gi); + gadget_moving_inside = + (button != 0 && gi != NULL && new_gi == gi && motion_status); + gadget_moving_outside = + (button != 0 && gi != NULL && new_gi != gi && motion_status); + gadget_released = + (button == 0 && gi != NULL && new_gi == gi); + + if (gi) + { + gi->event.x = mx - gi->x; + gi->event.y = my - gi->y; + + if (gi->type == GD_TYPE_DRAWING_AREA) + { + gi->event.x /= gi->drawing.item_xsize; + gi->event.y /= gi->drawing.item_ysize; + } + } + + if (gadget_pressed) + { + gi = new_gi; + + DrawGadget(gi, TRUE, TRUE); + + gi->state = GD_BUTTON_PRESSED; + gi->event.type = GD_EVENT_PRESSED; + gi->event.button = button; + + /* initialize delay counter */ + pressed_delay = 0; + DelayReached(&pressed_delay, GADGET_FRAME_DELAY); + + + /* + printf("new gadget pressed\n"); + */ + + + if (gi->event_mask & GD_EVENT_PRESSED) + gi->callback(gi); + } + + if (gadget_pressed_repeated) + { + if (gi->event_mask & GD_EVENT_PRESSED_REPEATED && + DelayReached(&pressed_delay, GADGET_FRAME_DELAY)) + { + + + /* + printf("gadget pressed (repeated)\n"); + */ + + + gi->callback(gi); + } + } + + if (gadget_moving_inside) + { + if (gi->state == GD_BUTTON_UNPRESSED) + DrawGadget(gi, TRUE, TRUE); + + gi->state = GD_BUTTON_PRESSED; + gi->event.type = GD_EVENT_MOVING; + + + /* + printf("inside gadget\n"); + */ + + if (gi->event_mask & GD_EVENT_MOVING) + gi->callback(gi); + } + + if (gadget_moving_outside) + { + if (gi->state == GD_BUTTON_PRESSED) + DrawGadget(gi, FALSE, TRUE); + + gi->state = GD_BUTTON_UNPRESSED; + gi->event.type = GD_EVENT_MOVING; + + + /* + printf("outside gadget\n"); + */ + + + if (gi->event_mask & GD_EVENT_MOVING) + gi->callback(gi); + } + + if (gadget_released) + { + DrawGadget(gi, FALSE, TRUE); + + gi->state = GD_BUTTON_UNPRESSED; + gi->event.type = GD_EVENT_RELEASED; + + + /* + printf("gadget released\n"); + */ + + + if (gi->event_mask & GD_EVENT_RELEASED) + gi->callback(gi); + } + + if (button == 0) + gi = NULL; + + + +#if 0 if (button) { if (!motion_status) /* mouse button just pressed */ @@ -1710,6 +1910,14 @@ void HandleGadgets(int mx, int my, int button) gi->event.button = button; DrawGadget(gi, TRUE, TRUE); + /* initialize delay counter */ + pressed_delay = 0; + DelayReached(&pressed_delay, GADGET_FRAME_DELAY); + + + printf("new gadget pressed\n"); + + if (gi->event_mask & GD_EVENT_PRESSED) gi->callback(gi); @@ -1718,45 +1926,77 @@ void HandleGadgets(int mx, int my, int button) } else /* mouse movement with pressed mouse button */ { - if ((new_gi == NULL || new_gi != gi) && - gi != NULL && pressed) + if (new_gi != gi && gi != NULL) { + if (pressed) + DrawGadget(gi, FALSE, TRUE); gi->state = GD_BUTTON_UNPRESSED; - DrawGadget(gi, FALSE, TRUE); + gi->event.type = GD_EVENT_MOVING; + + + printf("outside gadget\n"); + + + + + if (gi->event_mask & GD_EVENT_MOVING) + gi->callback(gi); + pressed = FALSE; } - else if (new_gi != NULL && new_gi == gi) + else if (new_gi == gi && gi != NULL) { if (!pressed) DrawGadget(gi, TRUE, TRUE); gi->state = GD_BUTTON_PRESSED; gi->event.type = GD_EVENT_MOVING; + + printf("inside gadget\n"); + + + + if (gi->event_mask & GD_EVENT_MOVING) gi->callback(gi); pressed = TRUE; } } + + if (gi != NULL && + gi->event_mask & GD_EVENT_PRESSED_REPEATED && + gi->state == GD_BUTTON_PRESSED && + DelayReached(&pressed_delay, GADGET_FRAME_DELAY)) + { + printf("gadget pressed (repeated)\n"); + + + gi->callback(gi); + } } else /* mouse button just released */ { - if (new_gi != NULL && new_gi == gi && pressed) + if (new_gi == gi && gi != NULL && pressed) { gi->state = GD_BUTTON_UNPRESSED; gi->event.type = GD_EVENT_RELEASED; DrawGadget(gi, FALSE, TRUE); + + printf("gadget released\n"); + + + if (gi->event_mask & GD_EVENT_RELEASED) gi->callback(gi); - - gi = NULL; - pressed = FALSE; - } - else - { - gi = NULL; - pressed = FALSE; } + + gi = NULL; + pressed = FALSE; } +#endif + + + } diff --git a/src/buttons.h b/src/buttons.h index 94616e06..f555dd39 100644 --- a/src/buttons.h +++ b/src/buttons.h @@ -286,6 +286,8 @@ int CheckCountButtons(int, int, int); #define GD_EVENT_PRESSED (1<<0) #define GD_EVENT_RELEASED (1<<1) #define GD_EVENT_MOVING (1<<2) +#define GD_EVENT_REPEATED (1<<3) +#define GD_EVENT_PRESSED_REPEATED (GD_EVENT_PRESSED | GD_EVENT_REPEATED) /* gadget button states */ #define GD_BUTTON_UNPRESSED 0 @@ -296,7 +298,7 @@ int CheckCountButtons(int, int, int); /* gadget creation tags */ #define GDI_END 0 -#define GDI_ID 1 +#define GDI_CUSTOM_ID 1 #define GDI_X 2 #define GDI_Y 3 #define GDI_WIDTH 4 @@ -313,6 +315,8 @@ int CheckCountButtons(int, int, int); #define GDI_EVENT_MASK 15 #define GDI_EVENT 16 #define GDI_CALLBACK 17 +#define GDI_AREA_SIZE 18 +#define GDI_ITEM_SIZE 19 typedef void (*gadget_callback_function)(void *); @@ -326,11 +330,19 @@ struct GadgetEvent { unsigned long type; /* event type */ int button; /* button number for button events */ + int x, y; /* gadget position at event time */ +}; + +struct GadgetDrawingArea +{ + int area_xsize, area_ysize; /* size of drawing area (in items) */ + int item_xsize, item_ysize; /* size of each item in drawing area */ }; struct GadgetInfo { - int id; /* gadget identifier */ + int id; /* internal gadget identifier */ + int custom_id; /* custom gadget identifier */ int x, y; /* gadget position */ int width, height; /* gadget size */ unsigned long type; /* type (button, text input, ...) */ @@ -344,6 +356,7 @@ struct GadgetInfo 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 GadgetInfo *next; /* next list entry */ }; diff --git a/src/editor.c b/src/editor.c index 08e8d393..d19c8c26 100644 --- a/src/editor.c +++ b/src/editor.c @@ -37,7 +37,7 @@ #define ED_SCROLL_DOWN 8 /* screens in the level editor */ -#define ED_MODE_EDIT 0 +#define ED_MODE_DRAWING 0 #define ED_MODE_INFO 1 #define ED_MODE_PROPERTIES 2 @@ -94,11 +94,14 @@ #define ED_CTRL_ID_TEST 20 #define ED_CTRL_ID_EXIT 21 -/* other gadget identifiers */ +/* counter button identifiers */ #define ED_CTRL_ID_SCORE_DOWN 22 #define ED_CTRL_ID_SCORE_UP 23 -#define ED_NUM_GADGETS 24 +/* drawing area identifiers */ +#define ED_CTRL_ID_DRAWING_LEVEL 24 + +#define ED_NUM_GADGETS 25 /* values for counter gadgets */ #define ED_COUNTER_SCORE 0 @@ -115,10 +118,11 @@ static struct }; /* forward declaration for internal use */ +static void DrawDrawingWindow(); static void DrawPropertiesWindow(int); static void CopyLevelToUndoBuffer(); -static void HandleDrawingFunctions(int, int, int); -static void HandlePressedControlButtons(); +static void HandleDrawingAreas(struct GadgetInfo *); +static void HandleCounterButtons(struct GadgetInfo *); static void HandleControlButtons(struct GadgetInfo *); static struct GadgetInfo *level_editor_gadget[ED_NUM_GADGETS]; @@ -492,6 +496,7 @@ static void CreateControlButtons() int gd_x1, gd_x2, gd_y; int width, height; unsigned long event_mask; + int id = i; if (i < ED_NUM_CTRL1_BUTTONS) { @@ -522,11 +527,12 @@ static void CreateControlButtons() i == ED_CTRL_ID_WRAP_RIGHT || i == ED_CTRL_ID_WRAP_UP || i == ED_CTRL_ID_WRAP_DOWN) - event_mask = GD_EVENT_PRESSED; + event_mask = GD_EVENT_PRESSED_REPEATED; else event_mask = GD_EVENT_RELEASED; - gi = CreateGadget(GDI_X, EX + gd_xoffset, + gi = CreateGadget(GDI_CUSTOM_ID, id, + GDI_X, EX + gd_xoffset, GDI_Y, EY + gd_yoffset, GDI_WIDTH, width, GDI_HEIGHT, height, @@ -541,10 +547,36 @@ static void CreateControlButtons() if (gi == NULL) Error(ERR_EXIT, "cannot create gadget"); - level_editor_gadget[i] = gi; + level_editor_gadget[id] = gi; } } + + +#if 0 + +static void test1(struct GadgetInfo *gi) +{ + int event_type = gi->event.type; + + printf("HandleControlButtons: (%d,%d) (%d,%d) [%d] ", + gi->x, gi->y, + gi->event.x, gi->event.y, gi->event.button); + + if (event_type == GD_EVENT_PRESSED) + printf("GD_EVENT_PRESSED\n"); + else if (event_type == GD_EVENT_RELEASED) + printf("GD_EVENT_RELEASED\n"); + else if (event_type == GD_EVENT_MOVING) + printf("GD_EVENT_MOVING\n"); + else + printf("?\n"); +} + +#endif + + + static void CreateCounterButtons(int counter_id) { int i; @@ -555,13 +587,15 @@ static void CreateCounterButtons(int counter_id) struct GadgetInfo *gi; int gd_xoffset; int gd_x1, gd_x2, gd_y; + int id = counter_info[counter_id].gadget_id + i; gd_xoffset = (i == 0 ? ED_BUTTON_MINUS_XPOS : ED_BUTTON_PLUS_XPOS); gd_x1 = DOOR_GFX_PAGEX4 + gd_xoffset; gd_x2 = DOOR_GFX_PAGEX3 + gd_xoffset; gd_y = DOOR_GFX_PAGEY1 + ED_BUTTON_COUNT_YPOS; - gi = CreateGadget(GDI_X, SX + counter_info[counter_id].x + gd_xoffset, + gi = CreateGadget(GDI_CUSTOM_ID, id, + GDI_X, SX + counter_info[counter_id].x + gd_xoffset, GDI_Y, SY + counter_info[counter_id].y, GDI_WIDTH, ED_BUTTON_COUNT_XSIZE, GDI_HEIGHT, ED_BUTTON_COUNT_YSIZE, @@ -569,27 +603,49 @@ static void CreateCounterButtons(int counter_id) GDI_STATE, GD_BUTTON_UNPRESSED, GDI_DESIGN_UNPRESSED, gd_pixmap, gd_x1, gd_y, GDI_DESIGN_PRESSED, gd_pixmap, gd_x2, gd_y, - GDI_EVENT_MASK, GD_EVENT_PRESSED, - GDI_CALLBACK, HandleControlButtons, + GDI_EVENT_MASK, GD_EVENT_PRESSED_REPEATED, + GDI_CALLBACK, HandleCounterButtons, GDI_END); if (gi == NULL) Error(ERR_EXIT, "cannot create gadget"); - level_editor_gadget[counter_info[counter_id].gadget_id + i] = gi; + level_editor_gadget[id] = gi; } } +static void CreateDrawingAreas() +{ + struct GadgetInfo *gi; + unsigned long event_mask; + + event_mask = GD_EVENT_PRESSED | GD_EVENT_RELEASED | GD_EVENT_MOVING; + + gi = CreateGadget(GDI_CUSTOM_ID, ED_CTRL_ID_DRAWING_LEVEL, + GDI_X, SX, + GDI_Y, SY, + GDI_WIDTH, SXSIZE, + GDI_HEIGHT, SYSIZE, + GDI_TYPE, GD_TYPE_DRAWING_AREA, + GDI_ITEM_SIZE, MINI_TILEX, MINI_TILEY, + GDI_EVENT_MASK, event_mask, + GDI_CALLBACK, HandleDrawingAreas, + GDI_END); + + if (gi == NULL) + Error(ERR_EXIT, "cannot create gadget"); + + level_editor_gadget[ED_CTRL_ID_DRAWING_LEVEL] = gi; +} + static void CreateLevelEditorGadgets() { if (level_editor_gadgets_created) return; - /* create main control buttons */ CreateControlButtons(); - - /* create element score buttons */ CreateCounterButtons(ED_COUNTER_SCORE); + CreateDrawingAreas(); level_editor_gadgets_created = TRUE; } @@ -610,6 +666,11 @@ static void MapCounterButtons(int counter_id) MapGadget(level_editor_gadget[counter_info[counter_id].gadget_id + i]); } +static void MapMainDrawingArea() +{ + MapGadget(level_editor_gadget[ED_CTRL_ID_DRAWING_LEVEL]); +} + void UnmapLevelEditorWindowGadgets() { int i; @@ -632,7 +693,7 @@ void DrawLevelEd() level_xpos=-1; level_ypos=-1; - edit_mode = ED_MODE_EDIT; + edit_mode = ED_MODE_DRAWING; name_typing = FALSE; element_shift = 0; @@ -740,6 +801,7 @@ void DrawLevelEd() CreateLevelEditorGadgets(); MapControlButtons(); + MapMainDrawingArea(); /* OpenDoor(DOOR_OPEN_1 | DOOR_OPEN_2); @@ -934,9 +996,10 @@ void LevelEd(int mx, int my, int button) int y = (my-SY)/MINI_TILEY; */ - + /* HandlePressedControlButtons(); HandleDrawingFunctions(mx, my, button); + */ if (use_floodfill) /********** FLOOD FILL **********/ { @@ -1039,7 +1102,7 @@ void LevelEd(int mx, int my, int button) DrawPropertiesWindow(new_element); } - if (edit_mode == ED_MODE_EDIT) /********** EDIT-FENSTER **********/ + if (edit_mode == ED_MODE_DRAWING) /********** EDIT-FENSTER **********/ { @@ -1190,7 +1253,7 @@ void LevelEd(int mx, int my, int button) } - else /********** KONTROLL-FENSTER **********/ + else if (edit_mode == ED_MODE_INFO)/********** KONTROLL-FENSTER **********/ { int choice = CheckCountButtons(mx,my,button); int step = (button==1 ? 1 : button==2 ? 5 : button==3 ? 10 : 0); @@ -1336,7 +1399,7 @@ void LevelEd(int mx, int my, int button) VXSIZE,VYSIZE, DOOR_GFX_PAGEX1,DOOR_GFX_PAGEY2); OpenDoor(DOOR_OPEN_2); - edit_mode = ED_MODE_EDIT; + edit_mode = ED_MODE_DRAWING; break; case ED_BUTTON_CLEAR: if (Request("Are you sure to clear this level ?",REQ_ASK)) @@ -1606,6 +1669,15 @@ static void DrawCounterValueField(int counter_id, int value) #define TEXT_SPEED "Speed of growth" #define TEXT_DURATION "Duration when activated" +static void DrawDrawingWindow() +{ + ClearWindow(); + UnmapLevelEditorWindowGadgets(); + MapMainDrawingArea(); + AdjustLevelScrollPosition(); + DrawMiniLevel(level_xpos, level_ypos); +} + static void DrawPropertiesWindow(int element) { int i, x, y; @@ -1662,6 +1734,7 @@ static void DrawPropertiesWindow(int element) }; ClearWindow(); + UnmapLevelEditorWindowGadgets(); DrawGraphic(1, 1, el2gfx(element)); DrawText(SX + 3*TILEX, SY + 5*TILEY/4, "Element Properties", @@ -1894,27 +1967,49 @@ static void RandomPlacement(int button) DrawMiniLevel(level_xpos, level_ypos); } -static void HandleDrawingFunctions(int mx, int my, int button) +/* +static void HandleDrawingAreas(int mx, int my, int button) +*/ + +static void HandleDrawingAreas(struct GadgetInfo *gi) { static int last_button = 0; static int last_element = 0; + static boolean started_inside_drawing_area = FALSE; + boolean inside_drawing_area; boolean button_press_event; boolean button_release_event; int new_element; - int sx = (mx - SX) / MINI_TILEX; - int sy = (my - SY) / MINI_TILEY; - int lx = sx + level_xpos; - int ly = sy + level_ypos; + int button = gi->event.button; + int mx = SX + gi->event.x * MINI_TILEX; + int my = SX + gi->event.y * MINI_TILEY; + int min_mx = SX, max_mx = SX + SXSIZE -1; + int min_my = SY, max_my = SY + SYSIZE -1; + int sx, sy; + int lx, ly; int x, y; - if (edit_mode != ED_MODE_EDIT) + if (edit_mode != ED_MODE_DRAWING) return; button_press_event = (last_button == 0 && button != 0); button_release_event = (last_button != 0 && button == 0); last_button = button; - if (mx < SX || mx >= SX + SXSIZE || my < SY || my >= SY + SYSIZE) + inside_drawing_area = + (mx >= min_mx && mx <= max_mx && my >= min_my && my <= max_my); + + mx = (mx < min_mx ? min_mx : mx > max_mx ? max_mx : mx); + my = (my < min_my ? min_my : my > max_my ? max_my : my); + sx = (mx - SX) / MINI_TILEX; + sy = (my - SY) / MINI_TILEY; + lx = sx + level_xpos; + ly = sy + level_ypos; + + if (button_press_event) + started_inside_drawing_area = inside_drawing_area; + + if (!started_inside_drawing_area) return; if ((!button && !button_release_event) || @@ -2003,6 +2098,7 @@ static void HandleDrawingFunctions(int mx, int my, int button) { last_sx = start_sx = sx; last_sy = start_sy = sy; + draw_func(sx, sy, sx, sy, new_element, FALSE); } else if (button_release_event) { @@ -2035,6 +2131,10 @@ static void HandleDrawingFunctions(int mx, int my, int button) last_element = new_element; } + + +#if 0 + static void HandlePressedControlButtons() { static unsigned long button_delay = 0; @@ -2148,33 +2248,53 @@ static void HandlePressedControlButtons() } } +#endif + + + +static void HandleCounterButtons(struct GadgetInfo *gi) +{ + int id = gi->custom_id; + int button = gi->event.button; + int step = (button == 1 ? 1 : button == 2 ? 5 : 10); + + switch (id) + { + case ED_CTRL_ID_SCORE_DOWN: + case ED_CTRL_ID_SCORE_UP: + *gadget_score_value += (id == ED_CTRL_ID_SCORE_DOWN ? -step : step); + if (*gadget_score_value < 0) + *gadget_score_value = 0; + else if (*gadget_score_value > 255) + *gadget_score_value = 255; + + DrawCounterValueField(ED_COUNTER_SCORE, *gadget_score_value); + break; + + default: + break; + } +} + static void HandleControlButtons(struct GadgetInfo *gi) { - /* + int id = gi->custom_id; int event_type = gi->event.type; - */ int button = gi->event.button; + int step = (button == 1 ? 1 : button == 2 ? 5 : 10); int new_element; int player_present = FALSE; int level_changed = FALSE; - int id = -1; - int i, x, y; + int x, y; new_element = (button == 1 ? new_element1 : button == 2 ? new_element2 : button == 3 ? new_element3 : 0); - /* get the button id */ - for (i=0; iid == level_editor_gadget[i]->id) - id = i; - - if (id >= 0 && id < ED_NUM_CTRL1_BUTTONS && edit_mode != ED_MODE_EDIT) + if (id < ED_NUM_CTRL1_BUTTONS && edit_mode != ED_MODE_DRAWING) { - UnmapLevelEditorWindowGadgets(); - AdjustLevelScrollPosition(); - DrawMiniLevel(level_xpos, level_ypos); - edit_mode = ED_MODE_EDIT; + DrawDrawingWindow(); + edit_mode = ED_MODE_DRAWING; } switch (id) @@ -2190,6 +2310,70 @@ static void HandleControlButtons(struct GadgetInfo *gi) drawing_function = id; break; + case ED_CTRL_ID_WRAP_LEFT: + if (level_xpos >= 0) + { + if (lev_fieldx < 2*SCR_FIELDX - 2) + break; + + level_xpos -= step; + if (level_xpos <- 1) + level_xpos = -1; + if (button == 1) + ScrollMiniLevel(level_xpos, level_ypos, ED_SCROLL_RIGHT); + else + DrawMiniLevel(level_xpos, level_ypos); + } + break; + + case ED_CTRL_ID_WRAP_RIGHT: + if (level_xpos <= lev_fieldx - 2*SCR_FIELDX) + { + if (lev_fieldx < 2*SCR_FIELDX - 2) + break; + + level_xpos += step; + if (level_xpos > lev_fieldx - 2*SCR_FIELDX + 1) + level_xpos = lev_fieldx - 2*SCR_FIELDX + 1; + if (button == 1) + ScrollMiniLevel(level_xpos, level_ypos, ED_SCROLL_LEFT); + else + DrawMiniLevel(level_xpos, level_ypos); + } + break; + + case ED_CTRL_ID_WRAP_UP: + if (level_ypos >= 0) + { + if (lev_fieldy < 2*SCR_FIELDY - 2) + break; + + level_ypos -= step; + if (level_ypos < -1) + level_ypos = -1; + if (button == 1) + ScrollMiniLevel(level_xpos, level_ypos, ED_SCROLL_DOWN); + else + DrawMiniLevel(level_xpos, level_ypos); + } + break; + + case ED_CTRL_ID_WRAP_DOWN: + if (level_ypos <= lev_fieldy - 2*SCR_FIELDY) + { + if (lev_fieldy < 2*SCR_FIELDY - 2) + break; + + level_ypos += step; + if (level_ypos > lev_fieldy - 2*SCR_FIELDY + 1) + level_ypos = lev_fieldy - 2*SCR_FIELDY + 1; + if (button == 1) + ScrollMiniLevel(level_xpos, level_ypos, ED_SCROLL_UP); + else + DrawMiniLevel(level_xpos, level_ypos); + } + break; + case ED_CTRL_ID_PROPERTIES: DrawPropertiesWindow(new_element); edit_mode = ED_MODE_PROPERTIES; @@ -2227,7 +2411,7 @@ static void HandleControlButtons(struct GadgetInfo *gi) { AdjustLevelScrollPosition(); DrawMiniLevel(level_xpos, level_ypos); - edit_mode = ED_MODE_EDIT; + edit_mode = ED_MODE_DRAWING; } break; @@ -2338,14 +2522,14 @@ static void HandleControlButtons(struct GadgetInfo *gi) break; default: - /* if (event_type == GD_EVENT_PRESSED) - printf("HandleControlButtons: GD_EVENT_PRESSED\n"); + printf("default: HandleControlButtons: GD_EVENT_PRESSED\n"); else if (event_type == GD_EVENT_RELEASED) - printf("HandleControlButtons: GD_EVENT_RELEASED\n"); + printf("default: HandleControlButtons: GD_EVENT_RELEASED\n"); + else if (event_type == GD_EVENT_MOVING) + printf("default: HandleControlButtons: GD_EVENT_MOVING\n"); else - printf("HandleControlButtons: ?\n"); - */ + printf("default: HandleControlButtons: ?\n"); break; } } diff --git a/src/events.c b/src/events.c index 38f58f94..e46b1775 100644 --- a/src/events.c +++ b/src/events.c @@ -270,22 +270,24 @@ void HandleButton(int mx, int my, int button) { static int old_mx = 0, old_my = 0; - if (mx<0 || my<0) + if (button < 0) { mx = old_mx; my = old_my; + button = -button; } else { old_mx = mx; old_my = my; - HandleGadgets(mx,my, button); HandleVideoButtons(mx,my, button); HandleSoundButtons(mx,my, button); HandleGameButtons(mx,my, button); } + HandleGadgets(mx, my, button); + switch(game_status) { case MAINMENU: @@ -610,7 +612,7 @@ void HandleNoXEvent() { if (button_status && game_status != PLAYING) { - HandleButton(-1,-1, button_status); + HandleButton(0, 0, -button_status); return; }