From: Holger Schemel Date: Mon, 11 Jan 1999 01:58:14 +0000 (+0100) Subject: rnd-19990111-1 X-Git-Tag: 1.3.0^2~27 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=ed4b7eed89c292042403561e1ed1449e60888b45;p=rocksndiamonds.git rnd-19990111-1 --- diff --git a/src/buttons.c b/src/buttons.c index bd8a1120..45967348 100644 --- a/src/buttons.c +++ b/src/buttons.c @@ -1626,11 +1626,12 @@ struct GadgetInfo *CreateGadget(int first_tag, ...) { int max_textsize = MAX_GADGET_TEXTSIZE; - if (new_gadget->text_size) - max_textsize = MIN(new_gadget->text_size, MAX_GADGET_TEXTSIZE - 1); + if (new_gadget->text.size) + max_textsize = MIN(new_gadget->text.size, MAX_GADGET_TEXTSIZE - 1); - strncpy(new_gadget->text_value, va_arg(ap, char *), max_textsize); - new_gadget->text_value[max_textsize] = '\0'; + strncpy(new_gadget->text.value, va_arg(ap, char *), max_textsize); + new_gadget->text.value[max_textsize] = '\0'; + new_gadget->text.cursor_position = strlen(new_gadget->text.value); } break; @@ -1639,12 +1640,12 @@ struct GadgetInfo *CreateGadget(int first_tag, ...) int tag_value = va_arg(ap, int); int max_textsize = MIN(tag_value, MAX_GADGET_TEXTSIZE - 1); - new_gadget->text_size = max_textsize; - new_gadget->text_value[max_textsize] = '\0'; + new_gadget->text.size = max_textsize; + new_gadget->text.value[max_textsize] = '\0'; if (new_gadget->width == 0 && new_gadget->height == 0) { - new_gadget->width = (new_gadget->text_size + 1) * FONT2_XSIZE + 6; + new_gadget->width = (new_gadget->text.size + 1) * FONT2_XSIZE + 6; new_gadget->height = ED_WIN_COUNT_YSIZE; } } @@ -1840,36 +1841,41 @@ static void DrawGadget(struct GadgetInfo *gi, boolean pressed, boolean direct) case GD_TYPE_TEXTINPUT: { int i; + char cursor_letter; + char cursor_string[3]; + char text[MAX_GADGET_TEXTSIZE + 1]; + int font_color = (pressed ? FC_YELLOW : FC_GREEN); + int border = gi->design_border; + strcpy(text, gi->text.value); + strcat(text, " "); /* left part of gadget */ XCopyArea(display, gd->pixmap, drawto, gc, - gd->x, gd->y, - gi->design_border, gi->height, - gi->x, gi->y); + gd->x, gd->y, border, gi->height, gi->x, gi->y); /* middle part of gadget */ - for (i=0; i<=gi->text_size; i++) + for (i=0; i<=gi->text.size; i++) XCopyArea(display, gd->pixmap, drawto, gc, - gd->x + gi->design_border, gd->y, - FONT2_XSIZE, gi->height, - gi->x + gi->design_border + i * FONT2_XSIZE, gi->y); + gd->x + border, gd->y, FONT2_XSIZE, gi->height, + gi->x + border + i * FONT2_XSIZE, gi->y); /* right part of gadget */ XCopyArea(display, gd->pixmap, drawto, gc, - 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); + gd->x + ED_WIN_COUNT_XSIZE - border, gd->y, + border, gi->height, gi->x + gi->width - border, gi->y); /* gadget text value */ - DrawText(gi->x + gi->design_border, gi->y + gi->design_border, - gi->text_value, FS_SMALL, (pressed ? FC_GREEN : FC_YELLOW)); + DrawText(gi->x + border, gi->y + border, text, FS_SMALL, font_color); + + cursor_letter = gi->text.value[gi->text.cursor_position]; + cursor_string[0] = '~'; + cursor_string[1] = (cursor_letter != '\0' ? cursor_letter : ' '); + cursor_string[2] = '\0'; /* draw cursor, if active */ - DrawText(gi->x + gi->design_border + - strlen(gi->text_value) * FONT2_XSIZE, - gi->y + gi->design_border, - (pressed ? "<" : " "), - FS_SMALL, FC_RED); + if (pressed) + DrawText(gi->x + border + gi->text.cursor_position * FONT2_XSIZE, + gi->y + border, cursor_string, FS_SMALL, font_color); } break; @@ -2004,6 +2010,8 @@ void AdjustScrollbar(struct GadgetInfo *gi, int items_max, int item_pos) DrawGadget(gi, DG_UNPRESSED, DG_DIRECT); } +static struct GadgetInfo *last_gi = NULL; + void MapGadget(struct GadgetInfo *gi) { if (gi == NULL) @@ -2020,9 +2028,10 @@ void UnmapGadget(struct GadgetInfo *gi) return; gi->mapped = FALSE; -} -static struct GadgetInfo *last_gi = NULL; + if (gi == last_gi) + last_gi = NULL; +} void HandleGadgets(int mx, int my, int button) { @@ -2062,18 +2071,34 @@ void HandleGadgets(int mx, int my, int button) 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) + /* special treatment for text input gadgets */ + if (last_gi && last_gi->type == GD_TYPE_TEXTINPUT && last_gi->mapped && + button != 0 && !motion_status) { struct GadgetInfo *gi = last_gi; - DrawGadget(gi, DG_UNPRESSED, DG_DIRECT); + if (new_gi == last_gi) + { + /* if mouse button pressed inside activated text gadget, set cursor */ + gi->text.cursor_position = (mx - gi->x) / FONT2_XSIZE; - if (gi->event_mask & GD_EVENT_TEXT_LEAVING) - gi->callback_action(gi); + if (gi->text.cursor_position < 0) + gi->text.cursor_position = 0; + else if (gi->text.cursor_position > strlen(gi->text.value)) + gi->text.cursor_position = strlen(gi->text.value); - last_gi = NULL; + DrawGadget(gi, DG_PRESSED, DG_DIRECT); + } + else + { + /* if mouse button pressed outside text input gadget, deactivate it */ + DrawGadget(gi, DG_UNPRESSED, DG_DIRECT); + + if (gi->event_mask & GD_EVENT_TEXT_LEAVING) + gi->callback_action(gi); + + last_gi = NULL; + } } gadget_pressed = @@ -2130,7 +2155,10 @@ void HandleGadgets(int mx, int my, int button) last_info_gi = new_gi; if (new_gi != NULL) + { + new_gi->event.type = 0; new_gi->callback_info(new_gi); + } else default_callback_info(NULL); } @@ -2311,24 +2339,47 @@ void HandleGadgets(int mx, int my, int button) void HandleGadgetsKeyInput(KeySym key) { struct GadgetInfo *gi = last_gi; + char text[MAX_GADGET_TEXTSIZE]; int text_length; + int cursor_pos; char letter; - if (gi == NULL || gi->type != GD_TYPE_TEXTINPUT) + if (gi == NULL || gi->type != GD_TYPE_TEXTINPUT || !gi->mapped) return; - text_length = strlen(gi->text_value); + text_length = strlen(gi->text.value); + cursor_pos = gi->text.cursor_position; letter = getCharFromKeySym(key); - if (letter && text_length < gi->text_size) + if (letter && text_length < gi->text.size) + { + strcpy(text, gi->text.value); + strcpy(&gi->text.value[cursor_pos + 1], &text[cursor_pos]); + gi->text.value[cursor_pos] = letter; + gi->text.cursor_position++; + DrawGadget(gi, DG_PRESSED, DG_DIRECT); + } + else if (key == XK_Left && cursor_pos > 0) + { + gi->text.cursor_position--; + DrawGadget(gi, DG_PRESSED, DG_DIRECT); + } + else if (key == XK_Right && cursor_pos < text_length) + { + gi->text.cursor_position++; + DrawGadget(gi, DG_PRESSED, DG_DIRECT); + } + else if (key == XK_BackSpace && cursor_pos > 0) { - gi->text_value[text_length] = letter; - gi->text_value[text_length + 1] = '\0'; + strcpy(text, gi->text.value); + strcpy(&gi->text.value[cursor_pos - 1], &text[cursor_pos]); + gi->text.cursor_position--; DrawGadget(gi, DG_PRESSED, DG_DIRECT); } - else if ((key == XK_Delete || key == XK_BackSpace) && text_length > 0) + else if (key == XK_Delete && cursor_pos < text_length) { - gi->text_value[text_length - 1] = '\0'; + strcpy(text, gi->text.value); + strcpy(&gi->text.value[cursor_pos], &text[cursor_pos + 1]); DrawGadget(gi, DG_PRESSED, DG_DIRECT); } else if (key == XK_Return) diff --git a/src/buttons.h b/src/buttons.h index 5d5b2ac3..65d09fcb 100644 --- a/src/buttons.h +++ b/src/buttons.h @@ -275,15 +275,15 @@ int CheckCountButtons(int, int, int); /* gadget types */ -#define GD_TYPE_NORMAL_BUTTON (1<<0) -#define GD_TYPE_RADIO_BUTTON (1<<1) -#define GD_TYPE_DRAWING_AREA (1<<2) -#define GD_TYPE_TEXTINPUT (1<<3) -#define GD_TYPE_TEXTOUTPUT (1<<4) -#define GD_TYPE_NUMBERINPUT (1<<5) -#define GD_TYPE_NUMBEROUTPUT (1<<6) -#define GD_TYPE_SCROLLBAR_VERTICAL (1<<7) -#define GD_TYPE_SCROLLBAR_HORIZONTAL (1<<8) +#define GD_TYPE_NORMAL_BUTTON (1 << 0) +#define GD_TYPE_RADIO_BUTTON (1 << 1) +#define GD_TYPE_DRAWING_AREA (1 << 2) +#define GD_TYPE_TEXTINPUT (1 << 3) +#define GD_TYPE_TEXTOUTPUT (1 << 4) +#define GD_TYPE_NUMBERINPUT (1 << 5) +#define GD_TYPE_NUMBEROUTPUT (1 << 6) +#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) @@ -291,13 +291,13 @@ int CheckCountButtons(int, int, int); GD_TYPE_SCROLLBAR_HORIZONTAL) /* gadget events */ -#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_OFF_BORDERS (1<<4) -#define GD_EVENT_TEXT_RETURN (1<<5) -#define GD_EVENT_TEXT_LEAVING (1<<6) +#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_OFF_BORDERS (1 << 4) +#define GD_EVENT_TEXT_RETURN (1 << 5) +#define GD_EVENT_TEXT_LEAVING (1 << 6) /* gadget button states */ #define GD_BUTTON_UNPRESSED 0 @@ -361,6 +361,13 @@ struct GadgetDrawingArea int item_xsize, item_ysize; /* size of each item in drawing area */ }; +struct GadgetTextInput +{ + char value[MAX_GADGET_TEXTSIZE]; /* text string in input field */ + int size; /* maximal size of input text */ + int cursor_position; /* actual cursor position */ +}; + struct GadgetScrollbar { int items_max; /* number of items to access */ @@ -386,8 +393,6 @@ struct GadgetInfo boolean radio_pressed; /* radio button state */ boolean mapped; /* gadget is active */ long number_value; - char text_value[MAX_GADGET_TEXTSIZE]; - int text_size; /* maximal size of input text */ struct GadgetDesign design[2]; /* 0: normal; 1: pressed */ struct GadgetDesign alt_design[2]; /* alternative design */ int design_border; /* border size of gadget decoration */ @@ -396,6 +401,7 @@ struct GadgetInfo gadget_function callback_info; /* function for pop-up info text */ gadget_function callback_action; /* function for gadget action */ struct GadgetDrawingArea drawing; /* fields for drawing area gadget */ + struct GadgetTextInput text; /* fields for text input gadget */ struct GadgetScrollbar scrollbar; /* fields for scrollbar gadget */ struct GadgetInfo *next; /* next list entry */ }; diff --git a/src/editor.c b/src/editor.c index 6d4b4ad9..44ad038d 100644 --- a/src/editor.c +++ b/src/editor.c @@ -114,6 +114,8 @@ #define ED_SCROLL_HORIZONTAL_YSIZE ED_SCROLLBUTTON_YSIZE /* control button identifiers */ +#define ED_CTRL_ID_NONE -1 + #define ED_CTRL_ID_SINGLE_ITEMS 0 #define ED_CTRL_ID_CONNECTED_ITEMS 1 #define ED_CTRL_ID_LINE 2 @@ -127,7 +129,7 @@ #define ED_CTRL_ID_UNUSED1 10 #define ED_CTRL_ID_WRAP_RIGHT 11 #define ED_CTRL_ID_RANDOM_PLACEMENT 12 -#define ED_CTRL_ID_BRUSH 13 +#define ED_CTRL_ID_GRAB_BRUSH 13 #define ED_CTRL_ID_WRAP_DOWN 14 #define ED_CTRL_ID_PICK_ELEMENT 15 #define ED_CTRL_ID_UNDO 16 @@ -268,7 +270,6 @@ static struct }, }; - /* forward declaration for internal use */ static void DrawDrawingWindow(); static void DrawPropertiesWindow(); @@ -743,7 +744,7 @@ 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_GRAB_BRUSH || id == ED_CTRL_ID_PICK_ELEMENT) { button_type = GD_TYPE_RADIO_BUTTON; @@ -1246,6 +1247,8 @@ void DrawLevelEd() if (!level_editor_gadgets_created) CreateLevelEditorGadgets(); + else + strcpy(level_editor_gadget[ED_CTRL_ID_LEVEL_NAME]->text.value, level.name); MapControlButtons(); @@ -2564,17 +2567,23 @@ static void SelectArea(int from_x, int from_y, int to_x, int to_y, #define CB_BRUSH_TO_LEVEL 2 #define CB_DELETE_OLD_CURSOR 3 -static void CopyBrushExt(int from_x, int from_y, int to_x, int to_y, int mode) +static void CopyBrushExt(int from_x, int from_y, int to_x, int to_y, + int button, int mode) { static short brush_buffer[ED_FIELDX][ED_FIELDY]; static int brush_width, brush_height; static int last_cursor_x = -1, last_cursor_y = -1; static boolean delete_old_brush; + int new_element; int x, y; if (mode == CB_DELETE_OLD_CURSOR && !delete_old_brush) return; + new_element = (button == 1 ? new_element1 : + button == 2 ? new_element2 : + button == 3 ? new_element3 : 0); + if (mode == CB_AREA_TO_BRUSH) { int from_lx, from_ly; @@ -2592,9 +2601,19 @@ static void CopyBrushExt(int from_x, int from_y, int to_x, int to_y, int mode) from_ly = from_y + level_ypos; for (y=0; y=0 && sx < ED_FIELDX && sy >=0 && sy < ED_FIELDY) @@ -2652,8 +2673,10 @@ static void CopyBrushExt(int from_x, int from_y, int to_x, int to_y, int mode) if (mode != CB_DELETE_OLD_CURSOR) DrawAreaBorder(border_from_x, border_from_y, border_to_x, border_to_y); + /* if (mode == CB_BRUSH_TO_LEVEL) CopyLevelToUndoBuffer(UNDO_IMMEDIATE); + */ last_cursor_x = cursor_x; last_cursor_y = cursor_y; @@ -2661,24 +2684,25 @@ static void CopyBrushExt(int from_x, int from_y, int to_x, int to_y, int mode) } } -static void CopyAreaToBrush(int from_x, int from_y, int to_x, int to_y) +static void CopyAreaToBrush(int from_x, int from_y, int to_x, int to_y, + int button) { - CopyBrushExt(from_x, from_y, to_x, to_y, CB_AREA_TO_BRUSH); + CopyBrushExt(from_x, from_y, to_x, to_y, button, CB_AREA_TO_BRUSH); } -static void CopyBrushToLevel(int x, int y) +static void CopyBrushToLevel(int x, int y, int button) { - CopyBrushExt(x, y, 0, 0, CB_BRUSH_TO_LEVEL); + CopyBrushExt(x, y, 0, 0, button, CB_BRUSH_TO_LEVEL); } static void CopyBrushToCursor(int x, int y) { - CopyBrushExt(x, y, 0, 0, CB_BRUSH_TO_CURSOR); + CopyBrushExt(x, y, 0, 0, 0, CB_BRUSH_TO_CURSOR); } static void DeleteBrushFromCursor() { - CopyBrushExt(0, 0, 0, 0, CB_DELETE_OLD_CURSOR); + CopyBrushExt(0, 0, 0, 0, 0, CB_DELETE_OLD_CURSOR); } static void FloodFill(int from_x, int from_y, int fill_element) @@ -2946,6 +2970,9 @@ static void HandleDrawingAreas(struct GadgetInfo *gi) int max_lx = lev_fieldx - 1, max_ly = lev_fieldy - 1; int x, y; + /* handle info callback for each invocation of action callback */ + gi->callback_info(gi); + /* if (edit_mode != ED_MODE_DRAWING) return; @@ -3000,7 +3027,9 @@ static void HandleDrawingAreas(struct GadgetInfo *gi) if (!button) break; - if (new_element != Feld[lx][ly]) + if (draw_with_brush) + CopyBrushToLevel(sx, sy, button); + else if (new_element != Feld[lx][ly]) { if (new_element == EL_SPIELFIGUR) { @@ -3066,7 +3095,7 @@ static void HandleDrawingAreas(struct GadgetInfo *gi) case ED_CTRL_ID_LINE: case ED_CTRL_ID_RECTANGLE: case ED_CTRL_ID_FILLED_BOX: - case ED_CTRL_ID_BRUSH: + case ED_CTRL_ID_GRAB_BRUSH: case ED_CTRL_ID_TEXT: { static int last_sx = -1; @@ -3081,7 +3110,7 @@ static void HandleDrawingAreas(struct GadgetInfo *gi) draw_func = DrawRectangle; else if (drawing_function == ED_CTRL_ID_FILLED_BOX) draw_func = DrawFilledBox; - else if (drawing_function == ED_CTRL_ID_BRUSH) + else if (drawing_function == ED_CTRL_ID_GRAB_BRUSH) draw_func = SelectArea; else /* (drawing_function == ED_CTRL_ID_TEXT) */ draw_func = SetTextCursor; @@ -3098,9 +3127,11 @@ static void HandleDrawingAreas(struct GadgetInfo *gi) else if (button_release_event) { draw_func(start_sx, start_sy, sx, sy, new_element, TRUE); - if (drawing_function == ED_CTRL_ID_BRUSH) + if (drawing_function == ED_CTRL_ID_GRAB_BRUSH) { - CopyAreaToBrush(start_sx, start_sy, sx, sy); + CopyAreaToBrush(start_sx, start_sy, sx, sy, button); + CopyBrushToCursor(sx, sy); + ClickOnGadget(level_editor_gadget[ED_CTRL_ID_SINGLE_ITEMS]); draw_with_brush = TRUE; } else if (drawing_function == ED_CTRL_ID_TEXT) @@ -3340,10 +3371,11 @@ static void HandleControlButtons(struct GadgetInfo *gi) case ED_CTRL_ID_RECTANGLE: case ED_CTRL_ID_FILLED_BOX: case ED_CTRL_ID_FLOOD_FILL: - case ED_CTRL_ID_BRUSH: + case ED_CTRL_ID_GRAB_BRUSH: case ED_CTRL_ID_PICK_ELEMENT: last_drawing_function = drawing_function; drawing_function = id; + draw_with_brush = FALSE; break; case ED_CTRL_ID_RANDOM_PLACEMENT: @@ -3538,16 +3570,109 @@ static void HandleControlButtons(struct GadgetInfo *gi) void HandleLevelEditorKeyInput(KeySym key) { - if (edit_mode == ED_MODE_DRAWING && drawing_function == ED_CTRL_ID_TEXT) + if (edit_mode == ED_MODE_DRAWING) { char letter = getCharFromKeySym(key); - if (letter) - DrawLevelText(0, 0, letter, TEXT_WRITECHAR); - else if (key == XK_Delete || key == XK_BackSpace) - DrawLevelText(0, 0, 0, TEXT_BACKSPACE); - else if (key == XK_Return) - DrawLevelText(0, 0, 0, TEXT_NEWLINE); + if (drawing_function == ED_CTRL_ID_TEXT) + { + if (letter) + DrawLevelText(0, 0, letter, TEXT_WRITECHAR); + else if (key == XK_Delete || key == XK_BackSpace) + DrawLevelText(0, 0, 0, TEXT_BACKSPACE); + else if (key == XK_Return) + DrawLevelText(0, 0, 0, TEXT_NEWLINE); + } + else if (button_status == MB_RELEASED) + { + int id; + + switch (letter) + { + case '.': + case 's': + id = ED_CTRL_ID_SINGLE_ITEMS; + break; + case 'd': + id = ED_CTRL_ID_CONNECTED_ITEMS; + break; + case 'l': + id = ED_CTRL_ID_LINE; + break; + case 't': + id = ED_CTRL_ID_TEXT; + break; + case 'r': + id = ED_CTRL_ID_RECTANGLE; + break; + case 'R': + id = ED_CTRL_ID_FILLED_BOX; + break; + case '?': + id = ED_CTRL_ID_PROPERTIES; + break; + case 'f': + id = ED_CTRL_ID_FLOOD_FILL; + break; + case 'b': + id = ED_CTRL_ID_GRAB_BRUSH; + break; + case ',': + id = ED_CTRL_ID_PICK_ELEMENT; + break; + + case 'U': + id = ED_CTRL_ID_UNDO; + break; + case 'I': + id = ED_CTRL_ID_INFO; + break; + case 'S': + id = ED_CTRL_ID_SAVE; + break; + case 'C': + id = ED_CTRL_ID_CLEAR; + break; + case 'T': + id = ED_CTRL_ID_TEST; + break; + case 'E': + id = ED_CTRL_ID_EXIT; + break; + + default: + id = ED_CTRL_ID_NONE; + break; + } + + if (id != ED_CTRL_ID_NONE) + ClickOnGadget(level_editor_gadget[id]); + else + { + switch (key) + { + case XK_Left: + id = ED_CTRL_ID_SCROLL_LEFT; + break; + case XK_Right: + id = ED_CTRL_ID_SCROLL_RIGHT; + break; + case XK_Up: + id = ED_CTRL_ID_SCROLL_UP; + break; + case XK_Down: + id = ED_CTRL_ID_SCROLL_DOWN; + break; + + default: + id = ED_CTRL_ID_NONE; + break; + } + + if (id != ED_CTRL_ID_NONE) + ClickOnGadget(level_editor_gadget[id]); + } + } } } @@ -3558,7 +3683,7 @@ static void HandleTextInputGadgets(struct GadgetInfo *gi) switch (id) { case ED_CTRL_ID_LEVEL_NAME: - strcpy(level.name, gi->text_value); + strcpy(level.name, gi->text.value); break; default: @@ -3602,6 +3727,8 @@ void HandleEditorGadgetInfoText(void *ptr) static void HandleDrawingAreaInfo(struct GadgetInfo *gi) { + static int start_lx, start_ly; + char *infotext; int id = gi->custom_id; int sx = gi->event.x; int sy = gi->event.y; @@ -3613,8 +3740,59 @@ static void HandleDrawingAreaInfo(struct GadgetInfo *gi) if (id == ED_CTRL_ID_DRAWING_LEVEL) { if (IN_LEV_FIELD(lx, ly)) - DrawTextF(INFOTEXT_XPOS - SX, INFOTEXT_YPOS - SY, FC_YELLOW, - "Level: %d, %d (Screen: %d, %d)", lx, ly, sx, sy); + { + if (gi->state == GD_BUTTON_PRESSED) + { + if (gi->event.type == GD_EVENT_PRESSED) + { + start_lx = lx; + start_ly = ly; + } + + switch (drawing_function) + { + case ED_CTRL_ID_SINGLE_ITEMS: + infotext = "Drawing single items"; + break; + case ED_CTRL_ID_CONNECTED_ITEMS: + infotext = "Drawing connected items"; + break; + case ED_CTRL_ID_LINE: + infotext = "Drawing line"; + break; + case ED_CTRL_ID_TEXT: + infotext = "Setting text cursor"; + break; + case ED_CTRL_ID_RECTANGLE: + infotext = "Drawing rectangle"; + break; + case ED_CTRL_ID_FILLED_BOX: + infotext = "Drawing filled box"; + break; + case ED_CTRL_ID_FLOOD_FILL: + infotext = "Flood fill"; + break; + case ED_CTRL_ID_GRAB_BRUSH: + infotext = "Grabbing brush"; + break; + case ED_CTRL_ID_PICK_ELEMENT: + infotext = "Picking element"; + break; + + default: + infotext = "Drawing position"; + break; + } + + DrawTextF(INFOTEXT_XPOS - SX, INFOTEXT_YPOS - SY, FC_YELLOW, + "%s: %d, %d", infotext, + ABS(lx - start_lx) + 1, + ABS(ly - start_ly) + 1); + } + else + DrawTextF(INFOTEXT_XPOS - SX, INFOTEXT_YPOS - SY, FC_YELLOW, + "Level position: %d, %d", lx, ly); + } /* misuse this function to draw brush cursor, if needed */ if (edit_mode == ED_MODE_DRAWING && draw_with_brush) diff --git a/src/misc.c b/src/misc.c index e917e13b..c3e5b205 100644 --- a/src/misc.c +++ b/src/misc.c @@ -621,9 +621,9 @@ void translate_keyname(KeySym *keysym, char **x11name, char **name, int mode) { XK_slash, "XK_slash", "/" }, { XK_colon, "XK_colon", ":" }, { XK_semicolon, "XK_semicolon", ";" }, - { XK_less, "XK_less", "less" }, - { XK_equal, "XK_equal", "equal" }, - { XK_greater, "XK_greater", "greater" }, + { XK_less, "XK_less", "<" }, + { XK_equal, "XK_equal", "=" }, + { XK_greater, "XK_greater", ">" }, { XK_question, "XK_question", "?" }, { XK_at, "XK_at", "@" }, @@ -847,12 +847,6 @@ char getCharFromKeySym(KeySym keysym) 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 = '>'; else if (strcmp(keyname, "circumflex") == 0) letter = '^'; diff --git a/src/tools.c b/src/tools.c index 972d7c23..fe3291fa 100644 --- a/src/tools.c +++ b/src/tools.c @@ -349,6 +349,7 @@ void DrawTextExt(Drawable d, GC gc, int x, int y, { int font_width, font_height, font_start; int font_pixmap; + boolean print_inverse = FALSE; if (font_size != FS_SMALL && font_size != FS_BIG) font_size = FS_SMALL; @@ -364,10 +365,16 @@ void DrawTextExt(Drawable d, GC gc, int x, int y, font_start = (font_type * (font_size == FS_BIG ? FONT1_YSIZE : FONT2_YSIZE) * FONT_LINES_PER_FONT); - while(*text) + while (*text) { char c = *text++; + if (c == '~' && font_size == FS_SMALL && font_type <= FC_YELLOW) + { + print_inverse = TRUE; + continue; + } + if (c >= 'a' && c <= 'z') c = 'A' + (c - 'a'); else if (c == 'ä' || c == 'Ä') @@ -378,10 +385,27 @@ void DrawTextExt(Drawable d, GC gc, int x, int y, c = 93; if (c >= 32 && c <= 95) - XCopyArea(display, pix[font_pixmap], d, gc, - ((c - 32) % FONT_CHARS_PER_LINE) * font_width, - ((c - 32) / FONT_CHARS_PER_LINE) * font_height + font_start, - font_width, font_height, x, y); + { + int src_x = ((c - 32) % FONT_CHARS_PER_LINE) * font_width; + int src_y = ((c - 32) / FONT_CHARS_PER_LINE) * font_height + font_start; + int dest_x = x, dest_y = y; + + if (print_inverse) + { + XCopyArea(display, pix[font_pixmap], d, gc, + FONT_CHARS_PER_LINE * font_width, + 3 * font_height + font_start, + font_width, font_height, x, y); + + XSetClipOrigin(display, clip_gc[font_pixmap], + dest_x - src_x, dest_y - src_y); + XCopyArea(display, pix[font_pixmap], drawto, clip_gc[font_pixmap], + 0, 0, font_width, font_height, dest_x, dest_y); + } + else + XCopyArea(display, pix[font_pixmap], d, gc, + src_x, src_y, font_width, font_height, dest_x, dest_y); + } x += font_width; }