X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Feditor.c;h=bf3704bdf94cc097f9d691b3f58d06a0c7184d99;hb=5ed4de42ced8e7dce5b786ba3d5fd1a6f6a7d7f6;hp=08e8d3935c420ef9f10e6a174357c8170ee54d8a;hpb=cb500a67f432a59fed5f5bf971c1ebad66843ae1;p=rocksndiamonds.git diff --git a/src/editor.c b/src/editor.c index 08e8d393..bf3704bd 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 | GD_EVENT_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,7 +547,7 @@ static void CreateControlButtons() if (gi == NULL) Error(ERR_EXIT, "cannot create gadget"); - level_editor_gadget[i] = gi; + level_editor_gadget[id] = gi; } } @@ -555,13 +561,18 @@ 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; + unsigned long event_mask; + + event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED; 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 +580,51 @@ 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, event_mask, + 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 | + GD_EVENT_OFF_BORDERS; + + 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 +645,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 +672,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 +780,7 @@ void DrawLevelEd() CreateLevelEditorGadgets(); MapControlButtons(); + MapMainDrawingArea(); /* OpenDoor(DOOR_OPEN_1 | DOOR_OPEN_2); @@ -934,9 +975,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 +1081,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 +1232,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 +1378,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 +1648,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 +1713,7 @@ static void DrawPropertiesWindow(int element) }; ClearWindow(); + UnmapLevelEditorWindowGadgets(); DrawGraphic(1, 1, el2gfx(element)); DrawText(SX + 3*TILEX, SY + 5*TILEY/4, "Element Properties", @@ -1850,12 +1902,6 @@ static void CopyLevelToUndoBuffer() for(x=0; xevent.off_borders; 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 sx = gi->event.x, sy = gi->event.y; + 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; + button_press_event = (gi->event.type == GD_EVENT_PRESSED); + button_release_event = (gi->event.type == GD_EVENT_RELEASED); + + sx = (sx < 0 ? 0 : sx > 2*SCR_FIELDX - 1 ? 2*SCR_FIELDX - 1 : sx); + sy = (sy < 0 ? 0 : sy > 2*SCR_FIELDY - 1 ? 2*SCR_FIELDY - 1 : sy); + lx = sx + level_xpos; + ly = sy + level_ypos; - if (mx < SX || mx >= SX + SXSIZE || my < SY || my >= SY + SYSIZE) + lx = (lx < 0 ? 0 : lx > lev_fieldx - 1 ? lev_fieldx - 1 : lx); + ly = (ly < 0 ? 0 : ly > lev_fieldy - 1 ? lev_fieldy - 1 : ly); + sx = lx - level_xpos; + sy = ly - 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,10 +2060,11 @@ 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) { - draw_func(start_sx, start_sy, sx, sy, last_element, TRUE); + draw_func(start_sx, start_sy, sx, sy, new_element, TRUE); CopyLevelToUndoBuffer(); } else if (last_sx != sx || last_sy != sy) @@ -2031,150 +2089,50 @@ static void HandleDrawingFunctions(int mx, int my, int button) default: break; } - - last_element = new_element; } -static void HandlePressedControlButtons() +static void HandleCounterButtons(struct GadgetInfo *gi) { - static unsigned long button_delay = 0; - int i; + int id = gi->custom_id; + int button = gi->event.button; + int step = (button == 1 ? 1 : button == 2 ? 5 : 10); - /* buttons with action when held pressed */ - int gadget_id[] = + switch (id) { - ED_CTRL_ID_WRAP_UP, - ED_CTRL_ID_WRAP_LEFT, - ED_CTRL_ID_WRAP_RIGHT, - ED_CTRL_ID_WRAP_DOWN, - ED_CTRL_ID_SCORE_DOWN, - ED_CTRL_ID_SCORE_UP, - -1 - }; - - if (!DelayReached(&button_delay, GADGET_FRAME_DELAY)) - return; + 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; - for (i=0; gadget_id[i] != -1; i++) - { - int id = gadget_id[i]; - int state = level_editor_gadget[id]->state; - int button = level_editor_gadget[id]->event.button; - int step = (button == 1 ? 1 : button == 2 ? 5 : 10); + DrawCounterValueField(ED_COUNTER_SCORE, *gadget_score_value); + break; - if (state != GD_BUTTON_PRESSED) - continue; - - switch (id) - { - 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_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; - } + default: + break; } } static void HandleControlButtons(struct GadgetInfo *gi) { - /* - int event_type = gi->event.type; - */ + int id = gi->custom_id; 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 +2148,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 +2249,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 +2360,14 @@ static void HandleControlButtons(struct GadgetInfo *gi) break; default: - /* - if (event_type == GD_EVENT_PRESSED) - printf("HandleControlButtons: GD_EVENT_PRESSED\n"); - else if (event_type == GD_EVENT_RELEASED) - printf("HandleControlButtons: GD_EVENT_RELEASED\n"); + if (gi->event.type == GD_EVENT_PRESSED) + printf("default: HandleControlButtons: GD_EVENT_PRESSED\n"); + else if (gi->event.type == GD_EVENT_RELEASED) + printf("default: HandleControlButtons: GD_EVENT_RELEASED\n"); + else if (gi->event.type == GD_EVENT_MOVING) + printf("default: HandleControlButtons: GD_EVENT_MOVING\n"); else - printf("HandleControlButtons: ?\n"); - */ + printf("default: HandleControlButtons: ?\n"); break; } }