rnd-19981219-1
authorHolger Schemel <info@artsoft.org>
Sat, 19 Dec 1998 20:20:15 +0000 (21:20 +0100)
committerHolger Schemel <info@artsoft.org>
Sat, 30 Aug 2014 08:32:32 +0000 (10:32 +0200)
src/editor.c
src/editor.h
src/events.c
src/misc.c
src/msdos.c
src/tools.c

index bf3704bdf94cc097f9d691b3f58d06a0c7184d99..fd964c68f7a2b4d496d080ddaa3dd37165ad7454 100644 (file)
@@ -1032,11 +1032,18 @@ void LevelEd(int mx, int my, int button)
          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)
@@ -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);
+  }
+}
index 2b1e839a7fc07fc174ea4742e1853da032b9ccb7..f996701424c6b6046fd6c68f4637a73c17b5daf2 100644 (file)
@@ -28,6 +28,7 @@ void InitLevelEditorGadgets();
 void UnmapLevelEditorGadgets();
 void DrawLevelEd(void);
 void LevelEd(int, int, int);
+void HandleLevelEditorKeyInput(KeySym);
 void LevelNameTyping(KeySym);
 
 #endif
index e46b177553430e80ffb8fdac0ad6f0246d65921c..3870ed81ea871f01269abdc7553c60a2b9072644 100644 (file)
@@ -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;
 
index 39d1fdc45864f5c8022f6891efdb08ca9a49b51e..7f6bc4bc7ef705f72ebda309f7c825053990a360 100644 (file)
@@ -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 */
index efcd80205918fd491e3524139bab1884c4fd071f..7c60e7512b624f327a752f8142cf7bfc125484a2 100644 (file)
@@ -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;
 }
index 4bbe67f21b9bf21be5ecf2d1c2b7f93ec78183bb..670397fe3d11b4a5bb3e129d2b497fe266f5e0af 100644 (file)
@@ -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)