X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Feditor.c;h=d92e27781d48dbf20e0e95667e1a2917854e249c;hb=e6856beb007b3f09036a04290c6b162953ddfece;hp=7c453d92dd8f8090959ce9e4f4e85fe5fba48336;hpb=6467d24a3a0f19645cd5ea89b4ca18a95021d657;p=rocksndiamonds.git diff --git a/src/editor.c b/src/editor.c index 7c453d92..d92e2778 100644 --- a/src/editor.c +++ b/src/editor.c @@ -101,7 +101,7 @@ #define ED_CTRL_ID_RANDOM_PLACEMENT 12 #define ED_CTRL_ID_BRUSH 13 #define ED_CTRL_ID_WRAP_DOWN 14 -#define ED_CTRL_ID_UNUSED2 15 +#define ED_CTRL_ID_PICK_ELEMENT 15 #define ED_CTRL_ID_UNDO 16 #define ED_CTRL_ID_INFO 17 #define ED_CTRL_ID_SAVE 18 @@ -121,7 +121,10 @@ #define ED_CTRL_ID_ELEMCONT_7 34 #define ED_CTRL_ID_AMOEBA_CONTENT 35 -#define ED_NUM_GADGETS 36 +/* text input identifiers */ +#define ED_CTRL_ID_LEVEL_NAME 36 + +#define ED_NUM_GADGETS 37 /* values for counter gadgets */ #define ED_COUNTER_SCORE 0 @@ -145,14 +148,16 @@ static struct static void DrawDrawingWindow(); static void DrawPropertiesWindow(); static void CopyLevelToUndoBuffer(); -static void HandleDrawingAreas(struct GadgetInfo *); -static void HandleCounterButtons(struct GadgetInfo *); static void HandleControlButtons(struct GadgetInfo *); +static void HandleCounterButtons(struct GadgetInfo *); +static void HandleDrawingAreas(struct GadgetInfo *); +static void HandleTextInputGadgets(struct GadgetInfo *); static struct GadgetInfo *level_editor_gadget[ED_NUM_GADGETS]; static boolean level_editor_gadgets_created = FALSE; static int drawing_function = ED_CTRL_ID_SINGLE_ITEMS; +static int last_drawing_function = ED_CTRL_ID_SINGLE_ITEMS; static int properties_element = 0; static short ElementContent[MAX_ELEMCONT][3][3]; @@ -607,7 +612,8 @@ static void CreateControlButtons() id == ED_CTRL_ID_RECTANGLE || id == ED_CTRL_ID_FILLED_BOX || id == ED_CTRL_ID_FLOOD_FILL || - id == ED_CTRL_ID_BRUSH) + id == ED_CTRL_ID_BRUSH || + id == ED_CTRL_ID_PICK_ELEMENT) { button_type = GD_TYPE_RADIO_BUTTON; radio_button_nr = 1; @@ -794,6 +800,39 @@ static void CreateDrawingAreas() level_editor_gadget[id] = gi; } +static void CreateTextInputGadgets() +{ + Pixmap gd_pixmap = pix[PIX_DOOR]; + int gd_x, gd_y; + struct GadgetInfo *gi; + unsigned long event_mask; + int id; + + gd_x = DOOR_GFX_PAGEX4 + ED_WIN_COUNT_XPOS; + gd_y = DOOR_GFX_PAGEY1 + ED_WIN_COUNT_YPOS; + event_mask = GD_EVENT_TEXT_RETURN | GD_EVENT_TEXT_LEAVING; + + /* text input gadget for the level name */ + id = ED_CTRL_ID_LEVEL_NAME; + gi = CreateGadget(GDI_CUSTOM_ID, id, + GDI_X, SX + ED_COUNT_ELEMCONT_XPOS, + GDI_Y, SY + ED_AREA_ELEMCONT_YPOS + 3 * TILEX, + 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_EVENT_MASK, event_mask, + GDI_CALLBACK, HandleTextInputGadgets, + GDI_END); + + if (gi == NULL) + Error(ERR_EXIT, "cannot create gadget"); + + level_editor_gadget[id] = gi; +} + static void CreateLevelEditorGadgets() { if (level_editor_gadgets_created) @@ -802,6 +841,7 @@ static void CreateLevelEditorGadgets() CreateControlButtons(); CreateCounterButtons(); CreateDrawingAreas(); + CreateTextInputGadgets(); level_editor_gadgets_created = TRUE; } @@ -827,6 +867,11 @@ static void MapDrawingArea(int id) MapGadget(level_editor_gadget[id]); } +static void MapTextInputGadget(int id) +{ + MapGadget(level_editor_gadget[id]); +} + static void MapMainDrawingArea() { MapDrawingArea(ED_CTRL_ID_DRAWING_LEVEL); @@ -1149,6 +1194,39 @@ void AdjustLevelScrollPosition() level_ypos = -1; } +static void PickDrawingElement(int button, int element) +{ + if (button < 1 || button > 3) + return; + + if (button == 1) + { + new_element1 = element; + DrawMiniGraphicExt(drawto, gc, + DX + ED_WIN_MB_LEFT_XPOS, + DY + ED_WIN_MB_LEFT_YPOS, + el2gfx(new_element1)); + } + else if (button == 2) + { + new_element2 = element; + DrawMiniGraphicExt(drawto, gc, + DX + ED_WIN_MB_MIDDLE_XPOS, + DY + ED_WIN_MB_MIDDLE_YPOS, + el2gfx(new_element2)); + } + else + { + new_element3 = element; + DrawMiniGraphicExt(drawto, gc, + DX + ED_WIN_MB_RIGHT_XPOS, + DY + ED_WIN_MB_RIGHT_YPOS, + el2gfx(new_element3)); + } + + redraw_mask |= REDRAW_DOOR_1; +} + void LevelEd(int mx, int my, int button) { static int last_button = 0; @@ -1249,26 +1327,7 @@ void LevelEd(int mx, int my, int button) else new_element = EL_LEERRAUM; - if (last_button==1) - new_element1 = new_element; - else if (last_button==2) - new_element2 = new_element; - else if (last_button==3) - new_element3 = new_element; - - DrawMiniGraphicExt(drawto,gc, - DX+ED_WIN_MB_LEFT_XPOS, - DY+ED_WIN_MB_LEFT_YPOS, - el2gfx(new_element1)); - DrawMiniGraphicExt(drawto,gc, - DX+ED_WIN_MB_MIDDLE_XPOS, - DY+ED_WIN_MB_MIDDLE_YPOS, - el2gfx(new_element2)); - DrawMiniGraphicExt(drawto,gc, - DX+ED_WIN_MB_RIGHT_XPOS, - DY+ED_WIN_MB_RIGHT_YPOS, - el2gfx(new_element3)); - redraw_mask |= REDRAW_DOOR_1; + PickDrawingElement(last_button, new_element); if (!HAS_CONTENT(properties_element)) { @@ -2070,6 +2129,9 @@ static void DrawPropertiesWindow() else DrawElementContentAreas(); } + + /* TEST ONLY: level name text input gadget */ + MapTextInputGadget(ED_CTRL_ID_LEVEL_NAME); } static void swap_numbers(int *i1, int *i2) @@ -2462,7 +2524,11 @@ static void HandleDrawingAreas(struct GadgetInfo *gi) int new_element; int button = gi->event.button; int sx = gi->event.x, sy = gi->event.y; + int min_sx = 0, min_sy = 0; + int max_sx = gi->drawing.area_xsize - 1, max_sy = gi->drawing.area_ysize - 1; int lx, ly; + int min_lx = 0, min_ly = 0; + int max_lx = lev_fieldx - 1, max_ly = lev_fieldy - 1; int x, y; /* @@ -2473,23 +2539,24 @@ static void HandleDrawingAreas(struct GadgetInfo *gi) button_press_event = (gi->event.type == GD_EVENT_PRESSED); button_release_event = (gi->event.type == GD_EVENT_RELEASED); + /* make sure to stay inside drawing area boundaries */ + sx = (sx < min_sx ? min_sx : sx > max_sx ? max_sx : sx); + sy = (sy < min_sy ? min_sy : sy > max_sy ? max_sy : sy); + if (draw_level) { - 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); + /* get positions inside level field */ lx = sx + level_xpos; ly = sy + level_ypos; - lx = (lx < 0 ? 0 : lx > lev_fieldx - 1 ? lev_fieldx - 1 : lx); - ly = (ly < 0 ? 0 : ly > lev_fieldy - 1 ? lev_fieldy - 1 : ly); + /* make sure to stay inside level field boundaries */ + lx = (lx < min_lx ? min_lx : lx > max_lx ? max_lx : lx); + ly = (ly < min_ly ? min_ly : ly > max_ly ? max_ly : ly); + + /* correct drawing area positions accordingly */ sx = lx - level_xpos; sy = ly - level_ypos; } - else - { - sx = (sx < 0 ? 0 : sx > 2 ? 2 : sx); - sy = (sy < 0 ? 0 : sy > 2 ? 2 : sy); - } if (button_press_event) started_inside_drawing_area = inside_drawing_area; @@ -2642,6 +2709,13 @@ static void HandleDrawingAreas(struct GadgetInfo *gi) } break; + case ED_CTRL_ID_PICK_ELEMENT: + if (button_press_event) + PickDrawingElement(button, Feld[lx][ly]); + if (button_release_event) + ClickOnGadget(level_editor_gadget[last_drawing_function]); + break; + default: break; } @@ -2716,6 +2790,8 @@ static void HandleControlButtons(struct GadgetInfo *gi) case ED_CTRL_ID_FILLED_BOX: case ED_CTRL_ID_FLOOD_FILL: case ED_CTRL_ID_BRUSH: + case ED_CTRL_ID_PICK_ELEMENT: + last_drawing_function = drawing_function; drawing_function = id; break; @@ -2946,19 +3022,7 @@ void HandleLevelEditorKeyInput(KeySym key) { if (edit_mode == ED_MODE_DRAWING && drawing_function == ED_CTRL_ID_TEXT) { - char *keyname = getKeyNameFromKeySym(key); - char letter = 0; - - if (strlen(keyname) == 1) - letter = keyname[0]; - else if (strcmp(keyname, "space") == 0) - letter = ' '; - else if (strcmp(keyname, "less") == 0) - letter = '<'; - else if (strcmp(keyname, "equal") == 0) - letter = '='; - else if (strcmp(keyname, "greater") == 0) - letter = '>'; + char letter = getCharFromKeySym(key); /* map lower case letters to upper case */ if (letter >= 'a' && letter <= 'z') @@ -2978,3 +3042,19 @@ void HandleLevelEditorKeyInput(KeySym key) DrawLevelText(0, 0, 0, TEXT_NEWLINE); } } + + +static void HandleTextInputGadgets(struct GadgetInfo *gi) +{ + int id = gi->custom_id; + + switch (id) + { + case ED_CTRL_ID_LEVEL_NAME: + strcpy(level.name, gi->text_value); + break; + + default: + break; + } +}