From: Holger Schemel Date: Sat, 19 Dec 1998 20:20:15 +0000 (+0100) Subject: rnd-19981219-1 X-Git-Tag: 1.3.0^2~52 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=df4588617a9478bdb512aab7432ef2d3777eb529;p=rocksndiamonds.git rnd-19981219-1 --- diff --git a/src/editor.c b/src/editor.c index bf3704bd..fd964c68 100644 --- a/src/editor.c +++ b/src/editor.c @@ -1032,11 +1032,18 @@ void LevelEd(int mx, int my, int button) element_shiftelements_in_list-MAX_ELEM_X*MAX_ELEM_Y) @@ -1890,6 +1897,122 @@ static void FloodFill(int from_x, int from_y, int fill_element) safety--; } +static void DrawAreaBorder(int from_x, int from_y, int to_x, int to_y) +{ + unsigned long border_color = ReadPixel(pix[PIX_SMALLFONT], 2, 16); + int from_sx = SX + from_x * MINI_TILEX; + int from_sy = SY + from_y * MINI_TILEX; + int to_sx = SX + to_x * MINI_TILEX + MINI_TILEX - 1; + int to_sy = SY + to_y * MINI_TILEX + MINI_TILEY - 1; + + XSetForeground(display, gc, border_color); + + XDrawLine(display, drawto, gc, from_sx, from_sy, to_sx, from_sy); + XDrawLine(display, drawto, gc, to_sx, from_sy, to_sx, to_sy); + XDrawLine(display, drawto, gc, to_sx, to_sy, from_sx, to_sy); + XDrawLine(display, drawto, gc, from_sx, to_sy, from_sx, from_sy); + + XSetForeground(display, gc, BlackPixel(display,screen)); + + if (from_x == to_x && from_y == to_y) + MarkTileDirty(from_x/2, from_y/2); + else + redraw_mask |= REDRAW_FIELD; +} + +/* values for DrawLeveltext() modes */ +#define TEXT_INIT 0 +#define TEXT_SETCURSOR 1 +#define TEXT_WRITECHAR 2 +#define TEXT_BACKSPACE 3 +#define TEXT_NEWLINE 4 +#define TEXT_END 5 + +static void DrawLevelText(int sx, int sy, char letter, int mode) +{ + static short delete_buffer[MAX_LEV_FIELDX]; + static int start_sx, start_sy; + static int last_sx, last_sy; + static boolean typing = FALSE; + int letter_element = EL_CHAR_ASCII0 + letter; + int lx, ly; + + if (mode != TEXT_INIT) + { + if (!typing) + return; + + if (mode != TEXT_SETCURSOR) + { + sx = last_sx; + sy = last_sy; + } + + lx = last_sx + level_xpos; + ly = last_sy + level_ypos; + } + + switch (mode) + { + case TEXT_INIT: + if (typing) + DrawLevelText(0, 0, 0, TEXT_END); + + typing = TRUE; + start_sx = last_sx = sx; + start_sy = last_sy = sy; + DrawLevelText(sx, sy, 0, TEXT_SETCURSOR); + break; + + case TEXT_SETCURSOR: + DrawMiniElement(last_sx, last_sy, Feld[lx][ly]); + DrawAreaBorder(sx, sy, sx, sy); + last_sx = sx; + last_sy = sy; + break; + + case TEXT_WRITECHAR: + if (letter_element >= EL_CHAR_START && letter_element <= EL_CHAR_END) + { + delete_buffer[sx - start_sx] = Feld[lx][ly]; + Feld[lx][ly] = letter_element; + + if (sx + 1 < 2*SCR_FIELDX && lx + 1 < lev_fieldx) + DrawLevelText(sx + 1, sy, 0, TEXT_SETCURSOR); + else if (sy + 1 < 2*SCR_FIELDY && ly + 1 < lev_fieldy) + DrawLevelText(start_sx, sy + 1, 0, TEXT_SETCURSOR); + else + DrawLevelText(0, 0, 0, TEXT_END); + } + break; + + case TEXT_BACKSPACE: + if (sx > start_sx) + { + Feld[lx - 1][ly] = delete_buffer[sx - start_sx - 1]; + DrawMiniElement(sx - 1, sy, new_element3); + DrawLevelText(sx - 1, sy, 0, TEXT_SETCURSOR); + } + break; + + case TEXT_NEWLINE: + if (sy + 1 < 2*SCR_FIELDY - 1 && ly + 1 < lev_fieldy - 1) + DrawLevelText(start_sx, sy + 1, 0, TEXT_SETCURSOR); + else + DrawLevelText(0, 0, 0, TEXT_END); + break; + + case TEXT_END: + CopyLevelToUndoBuffer(); + DrawMiniElement(sx, sy, Feld[lx][ly]); + typing = FALSE; + break; + + default: + break; + } +} + static void CopyLevelToUndoBuffer() { int x, y; @@ -2058,9 +2181,9 @@ static void HandleDrawingAreas(struct GadgetInfo *gi) if (button_press_event) { - last_sx = start_sx = sx; - last_sy = start_sy = sy; draw_func(sx, sy, sx, sy, new_element, FALSE); + start_sx = last_sx = sx; + start_sy = last_sy = sy; } else if (button_release_event) { @@ -2086,6 +2209,11 @@ static void HandleDrawingAreas(struct GadgetInfo *gi) } break; + case ED_CTRL_ID_TEXT: + if (button_press_event) + DrawLevelText(sx, sy, 0, TEXT_INIT); + break; + default: break; } @@ -2129,6 +2257,9 @@ static void HandleControlButtons(struct GadgetInfo *gi) button == 2 ? new_element2 : button == 3 ? new_element3 : 0); + if (edit_mode == ED_MODE_DRAWING && drawing_function == ED_CTRL_ID_TEXT) + DrawLevelText(0, 0, 0, TEXT_END); + if (id < ED_NUM_CTRL1_BUTTONS && edit_mode != ED_MODE_DRAWING) { DrawDrawingWindow(); @@ -2371,3 +2502,40 @@ static void HandleControlButtons(struct GadgetInfo *gi) break; } } + +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 = '>'; + + /* map lower case letters to upper case */ + if (letter >= 'a' && letter <= 'z') + letter += (int)('A' - 'a'); + else if (letter == 'ä') + letter = 'Ä'; + else if (letter == 'ä') + letter = 'Ö'; + else if (letter == 'ä') + letter = 'Ü'; + + 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); + } +} diff --git a/src/editor.h b/src/editor.h index 2b1e839a..f9967014 100644 --- a/src/editor.h +++ b/src/editor.h @@ -28,6 +28,7 @@ void InitLevelEditorGadgets(); void UnmapLevelEditorGadgets(); void DrawLevelEd(void); void LevelEd(int, int, int); +void HandleLevelEditorKeyInput(KeySym); void LevelNameTyping(KeySym); #endif diff --git a/src/events.c b/src/events.c index e46b1775..3870ed81 100644 --- a/src/events.c +++ b/src/events.c @@ -71,6 +71,9 @@ void EventLoop(void) Delay(10); } + /* refresh window contents from drawing buffer, if needed */ + BackToFront(); + if (game_status == EXITGAME) return; } @@ -505,6 +508,7 @@ void HandleKey(KeySym key, int key_status) break; case LEVELED: + HandleLevelEditorKeyInput(key); LevelNameTyping(key); break; diff --git a/src/misc.c b/src/misc.c index 39d1fdc4..7f6bc4bc 100644 --- a/src/misc.c +++ b/src/misc.c @@ -581,27 +581,53 @@ void translate_keyname(KeySym *keysym, char **x11name, char **name, int mode) { XK_End, "XK_End", "end" }, { XK_Page_Up, "XK_Page_Up", "page up" }, { XK_Page_Down, "XK_Page_Down", "page down" }, - { XK_space, "XK_space", "space" }, - /* even more special keys */ - { XK_adiaeresis, "XK_adiaeresis", "ä" }, - { XK_odiaeresis, "XK_odiaeresis", "ö" }, - { XK_udiaeresis, "XK_udiaeresis", "ü" }, + + /* ASCII 0x20 to 0x40 keys (except numbers) */ + { XK_space, "XK_space", "space" }, + { XK_exclam, "XK_exclam", "!" }, + { XK_quotedbl, "XK_quotedbl", "\"" }, + { XK_numbersign, "XK_numbersign", "#" }, + { XK_dollar, "XK_dollar", "$" }, + { XK_percent, "XK_percent", "%" }, + { XK_ampersand, "XK_ampersand", "&" }, { XK_apostrophe, "XK_apostrophe", "'" }, + { XK_parenleft, "XK_parenleft", "(" }, + { XK_parenright, "XK_parenright", ")" }, + { XK_asterisk, "XK_asterisk", "*" }, { XK_plus, "XK_plus", "+" }, - { XK_minus, "XK_minus", "-" }, - { XK_equal, "XK_equal", "equal" }, { XK_comma, "XK_comma", "," }, + { XK_minus, "XK_minus", "-" }, { XK_period, "XK_period", "." }, - { XK_colon, "XK_colon", ";" }, { XK_slash, "XK_slash", "/" }, - { XK_numbersign, "XK_numbersign", "#" }, - { XK_backslash, "XK_backslash", "backslash" }, - { XK_braceleft, "XK_braceleft", "brace left" }, - { XK_braceright, "XK_braceright", "brace right" }, + { XK_colon, "XK_colon", ":" }, + { XK_semicolon, "XK_semicolon", ";" }, { XK_less, "XK_less", "less" }, + { XK_equal, "XK_equal", "equal" }, { XK_greater, "XK_greater", "greater" }, + { XK_question, "XK_question", "?" }, + { XK_at, "XK_at", "@" }, + + /* more ASCII keys */ + { XK_bracketleft, "XK_bracketleft", "[" }, + { XK_backslash, "XK_backslash", "backslash" }, + { XK_bracketright, "XK_bracketright", "]" }, { XK_asciicircum, "XK_asciicircum", "circumflex" }, + { XK_underscore, "XK_underscore", "_" }, + { XK_grave, "XK_grave", "grave" }, + { XK_quoteleft, "XK_quoteleft", "quote left" }, + { XK_braceleft, "XK_braceleft", "brace left" }, + { XK_bar, "XK_bar", "bar" }, + { XK_braceright, "XK_braceright", "brace right" }, + { XK_asciitilde, "XK_asciitilde", "ascii tilde" }, + + /* special (non-ASCII) keys */ + { XK_Adiaeresis, "XK_Adiaeresis", "Ä" }, + { XK_Odiaeresis, "XK_Odiaeresis", "Ö" }, + { XK_Udiaeresis, "XK_Udiaeresis", "Ü" }, + { XK_adiaeresis, "XK_adiaeresis", "ä" }, + { XK_odiaeresis, "XK_odiaeresis", "ö" }, + { XK_udiaeresis, "XK_udiaeresis", "ü" }, { XK_ssharp, "XK_ssharp", "sharp s" }, /* end-of-array identifier */ diff --git a/src/msdos.c b/src/msdos.c index efcd8020..7c60e751 100644 --- a/src/msdos.c +++ b/src/msdos.c @@ -525,7 +525,7 @@ static BITMAP *Read_PCX_to_AllegroBitmap(char *filename) if ((bitmap = Image_to_AllegroBitmap(image)) == NULL) return NULL; - set_pallete(global_colormap); + set_palette(global_colormap); return bitmap; } diff --git a/src/tools.c b/src/tools.c index 4bbe67f2..670397fe 100644 --- a/src/tools.c +++ b/src/tools.c @@ -1736,10 +1736,15 @@ unsigned int MoveDoor(unsigned int door_state) int ReadPixel(Drawable d, int x, int y) { - static XImage *pixelimage; + XImage *pixel_image; + unsigned long pixel_value; - pixelimage = XGetImage(display, d, x, y, 1, 1, AllPlanes, ZPixmap); - return(XGetPixel(pixelimage, 0, 0)); + pixel_image = XGetImage(display, d, x, y, 1, 1, AllPlanes, ZPixmap); + pixel_value = XGetPixel(pixel_image, 0, 0); + + XDestroyImage(pixel_image); + + return pixel_value; } int el2gfx(int element)