element_shift<elements_in_list-MAX_ELEM_X*MAX_ELEM_Y)) &&
DelayReached(&choice_delay, GADGET_FRAME_DELAY))
{
- int i, step;
+ int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
+ int i;
+#if 0
step = (button==1 ? MAX_ELEM_X : button==2 ? 5*MAX_ELEM_X :
elements_in_list);
element_shift += (choice==ED_BUTTON_EUP ? -step : step);
+#else
+ step = step * MAX_ELEM_X * (choice == ED_BUTTON_EUP ? -1 : +1);
+ element_shift += step;
+#endif
+
if (element_shift<0)
element_shift = 0;
if (element_shift>elements_in_list-MAX_ELEM_X*MAX_ELEM_Y)
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;
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)
{
}
break;
+ case ED_CTRL_ID_TEXT:
+ if (button_press_event)
+ DrawLevelText(sx, sy, 0, TEXT_INIT);
+ break;
+
default:
break;
}
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();
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);
+ }
+}
void UnmapLevelEditorGadgets();
void DrawLevelEd(void);
void LevelEd(int, int, int);
+void HandleLevelEditorKeyInput(KeySym);
void LevelNameTyping(KeySym);
#endif
Delay(10);
}
+ /* refresh window contents from drawing buffer, if needed */
+ BackToFront();
+
if (game_status == EXITGAME)
return;
}
break;
case LEVELED:
+ HandleLevelEditorKeyInput(key);
LevelNameTyping(key);
break;
{ 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 */
if ((bitmap = Image_to_AllegroBitmap(image)) == NULL)
return NULL;
- set_pallete(global_colormap);
+ set_palette(global_colormap);
return bitmap;
}
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)