rnd-20030405-1-src
authorHolger Schemel <info@artsoft.org>
Fri, 4 Apr 2003 23:48:12 +0000 (01:48 +0200)
committerHolger Schemel <info@artsoft.org>
Sat, 30 Aug 2014 08:40:57 +0000 (10:40 +0200)
src/conftime.h
src/events.c
src/libgame/misc.c
src/libgame/misc.h
src/libgame/sdl.c
src/libgame/sdl.h
src/libgame/system.c
src/libgame/system.h
src/libgame/x11.c
src/libgame/x11.h

index 90226b295725efa4e8fc266cfb8954de22811549..ab0f201c94b1258d209689195b9046cd98683a32 100644 (file)
@@ -1 +1 @@
-#define COMPILE_DATE_STRING "[2003-04-04 23:16]"
+#define COMPILE_DATE_STRING "[2003-04-05 01:37]"
index b5be2a1610394fd4e33fa3078d2e3e5124eeff8c..c88a27b8dfb80324151e36d6112e1226cb9e90ef 100644 (file)
 #define KEY_PRESSED            TRUE
 
 
+static boolean cursor_inside_playfield = FALSE;
+static boolean playfield_cursor_set = FALSE;
+static unsigned long playfield_cursor_delay = 0;
+
+
 /* event filter especially needed for SDL event filtering due to
    delay problems with lots of mouse motion events when mouse button
    not pressed (X11 can handle this with 'PointerMotionHintMask') */
@@ -39,18 +44,19 @@ int FilterMouseMotionEvents(const Event *event)
   if (event->type != EVENT_MOTIONNOTIFY)
     return 1;
 
-  /* when playing, display a different mouse pointer inside the playfield */
   if (game_status == PLAYING)
   {
-    static boolean inside_field = FALSE;
     MotionEvent *motion = (MotionEvent *)event;
 
-    if ((motion->x >= SX && motion->x < SX + SXSIZE &&
-        motion->y >= SY && motion->y < SY + SYSIZE) != inside_field)
-    {
-      inside_field = !inside_field;
+    cursor_inside_playfield =
+      (motion->x >= SX && motion->x < SX + SXSIZE &&
+       motion->y >= SY && motion->y < SY + SYSIZE);
 
-      SetMouseCursor(inside_field ? CURSOR_PLAYFIELD : CURSOR_DEFAULT);
+    if (playfield_cursor_set)
+    {
+      SetMouseCursor(CURSOR_DEFAULT);
+      DelayReached(&playfield_cursor_delay, 0);
+      playfield_cursor_set = FALSE;
     }
   }
 
@@ -111,7 +117,17 @@ void EventLoop(void)
       }
     }
     else
+    {
+      /* when playing, display a special mouse pointer inside the playfield */
+      if (game_status == PLAYING && cursor_inside_playfield &&
+         DelayReached(&playfield_cursor_delay, 1000))
+      {
+       SetMouseCursor(CURSOR_PLAYFIELD);
+       playfield_cursor_set = TRUE;
+      }
+
       HandleNoEvent();
+    }
 
     /* don't use all CPU time when idle; the main loop while playing
        has its own synchronization and is CPU friendly, too */
index cffa180b240647cf965a734315ffefb92efb3986..321372535fa01086b4881bb31c626b68489d5272 100644 (file)
@@ -215,8 +215,8 @@ boolean FrameReached(unsigned long *frame_counter_var,
 {
   unsigned long actual_frame_counter = FrameCounter;
 
-  if (actual_frame_counter < *frame_counter_var + frame_delay &&
-      actual_frame_counter >= *frame_counter_var)
+  if (actual_frame_counter >= *frame_counter_var &&
+      actual_frame_counter < *frame_counter_var + frame_delay)
     return FALSE;
 
   *frame_counter_var = actual_frame_counter;
@@ -229,8 +229,8 @@ boolean DelayReached(unsigned long *counter_var,
 {
   unsigned long actual_counter = Counter();
 
-  if (actual_counter < *counter_var + delay &&
-      actual_counter >= *counter_var)
+  if (actual_counter >= *counter_var &&
+      actual_counter < *counter_var + delay)
     return FALSE;
 
   *counter_var = actual_counter;
@@ -246,8 +246,8 @@ void WaitUntilDelayReached(unsigned long *counter_var, unsigned long delay)
   {
     actual_counter = Counter();
 
-    if (actual_counter < *counter_var + delay &&
-       actual_counter >= *counter_var)
+    if (actual_counter >= *counter_var &&
+       actual_counter < *counter_var + delay)
       sleep_milliseconds((*counter_var + delay - actual_counter) / 2);
     else
       break;
index 2a727278931a41c64f3853a84c83812d8c960922..3b9d945b7169cd03fc55bdeeff856c824ed0df55 100644 (file)
 #define BYTE_ORDER_BIG_ENDIAN          0
 #define BYTE_ORDER_LITTLE_ENDIAN       1
 
+/* values for cursor bitmap creation */
+#define BIT_ORDER_MSB                  0
+#define BIT_ORDER_LSB                  1
+
 /* values for createDirectory() */
 #define PERMS_PRIVATE                  0
 #define PERMS_PUBLIC                   1
index 51c2baf83e8ef9e4f5f5508c3ac9b34a158f8e36..f479fd9960b804faa6ae41bc42b1a8040b3971c2 100644 (file)
@@ -1237,65 +1237,29 @@ Bitmap *SDLLoadImage(char *filename)
 /* custom cursor fuctions                                                    */
 /* ------------------------------------------------------------------------- */
 
-static SDL_Cursor *create_cursor(const char **image)
+static SDL_Cursor *create_cursor(struct MouseCursorInfo *cursor_info)
 {
-  int i, row, col;
-  Uint8 data[4*32];
-  Uint8 mask[4*32];
-  int hot_x, hot_y;
-
-  i = -1;
-  for (row=0; row<32; ++row)
-  {
-    for (col=0; col<32; ++col)
-    {
-      if (col % 8)
-      {
-        data[i] <<= 1;
-        mask[i] <<= 1;
-      }
-      else
-      {
-        i++;
-        data[i] = mask[i] = 0;
-      }
-
-      switch (image[4+row][col])
-      {
-        case 'X':
-         data[i] |= 0x01;
-         mask[i] |= 0x01;
-         break;
-        case '.':
-         mask[i] |= 0x01;
-         break;
-        case ' ':
-         break;
-      }
-    }
-  }
-
-  sscanf(image[4+row], "%d,%d", &hot_x, &hot_y);
-
-  return SDL_CreateCursor(data, mask, 32, 32, hot_x, hot_y);
+  return SDL_CreateCursor(cursor_info->data, cursor_info->mask,
+                         cursor_info->width, cursor_info->height,
+                         cursor_info->hot_x, cursor_info->hot_y);
 }
 
-void SDLSetMouseCursor(const char **cursor_image)
+void SDLSetMouseCursor(struct MouseCursorInfo *cursor_info)
 {
-  static const char **last_cursor_image = NULL;
+  static struct MouseCursorInfo *last_cursor_info = NULL;
   static SDL_Cursor *cursor_default = NULL;
   static SDL_Cursor *cursor_current = NULL;
 
   if (cursor_default == NULL)
     cursor_default = SDL_GetCursor();
 
-  if (cursor_image != NULL && cursor_image != last_cursor_image)
+  if (cursor_info != NULL && cursor_info != last_cursor_info)
   {
-    cursor_current = create_cursor(cursor_image);
-    last_cursor_image = cursor_image;
+    cursor_current = create_cursor(cursor_info);
+    last_cursor_info = cursor_info;
   }
 
-  SDL_SetCursor(cursor_image ? cursor_current : cursor_default);
+  SDL_SetCursor(cursor_info ? cursor_current : cursor_default);
 }
 
 
index c2f55ee9e56e645378ae0e8d1851738e7ff25d9c..fcf19341a81fd08372a5edd2c67881b012147611 100644 (file)
@@ -28,6 +28,9 @@
 #define TARGET_STRING          "SDL"
 #define FULLSCREEN_STATUS      FULLSCREEN_AVAILABLE
 
+#define CURSOR_MAX_WIDTH       32
+#define CURSOR_MAX_HEIGHT      32
+
 
 /* SDL type definitions */
 
@@ -67,6 +70,15 @@ struct SDLSurfaceInfo
   GC stored_clip_gc;
 };
 
+struct MouseCursorInfo
+{
+  int width, height;
+  int hot_x, hot_y;
+
+  char data[CURSOR_MAX_WIDTH * CURSOR_MAX_HEIGHT / 8];
+  char mask[CURSOR_MAX_WIDTH * CURSOR_MAX_HEIGHT / 8];
+};
+
 struct XY
 {
   short x, y;
@@ -339,7 +351,7 @@ void SDLZoomBitmap(Bitmap *, Bitmap *);
 
 Bitmap *SDLLoadImage(char *);
 
-void SDLSetMouseCursor(const char **);
+void SDLSetMouseCursor(struct MouseCursorInfo *);
 
 inline void SDLOpenAudio(void);
 inline void SDLCloseAudio(void);
index 45fb77c1e86471cc7861b27ec3af6ab88b045770..18776bd423a17d02bd5e6396a81f70883a09e9c9 100644 (file)
@@ -855,84 +855,79 @@ void CreateBitmapWithSmallBitmaps(Bitmap *src_bitmap)
 /* mouse pointer functions                                                   */
 /* ------------------------------------------------------------------------- */
 
-/* cursor bitmap in XPM format */
+/* XPM */
 static const char *cursor_image_playfield[] =
 {
   /* width height num_colors chars_per_pixel */
-  "    32    32        3            1",
+  "    16    16        3            1",
 
   /* colors */
   "X c #000000",
   ". c #ffffff",
   "  c None",
 
-  " X                              ",
-  "X.X                             ",
-  " X                              ",
-  "                                ",
-  "                                ",
-  "                                ",
-  "                                ",
-  "                                ",
-  "                                ",
-  "                                ",
-  "                                ",
-  "                                ",
-  "                                ",
-  "                                ",
-  "                                ",
-  "                                ",
-  "                                ",
-  "                                ",
-  "                                ",
-  "                                ",
-  "                                ",
-  "                                ",
-  "                                ",
-  "                                ",
-  "                                ",
-  "                                ",
-  "                                ",
-  "                                ",
-  "                                ",
-  "                                ",
-  "                                ",
-  "                                ",
+  /* pixels */
+  " X              ",
+  "X.X             ",
+  " X              ",
+  "                ",
+  "                ",
+  "                ",
+  "                ",
+  "                ",
+  "                ",
+  "                ",
+  "                ",
+  "                ",
+  "                ",
+  "                ",
+  "                ",
+  "                ",
+
+  /* hot spot */
   "1,1"
 };
 
+#if defined(TARGET_SDL)
+static const int cursor_bit_order = BIT_ORDER_MSB;
+#elif defined(TARGET_X11_NATIVE)
+static const int cursor_bit_order = BIT_ORDER_LSB;
+#endif
+
 static struct MouseCursorInfo *get_cursor_from_image(const char **image)
 {
   struct MouseCursorInfo *cursor;
-  int row, col, i;
+  boolean bit_order_msb = (cursor_bit_order == BIT_ORDER_MSB);
+  int header_lines = 4;
+  int x, y, i;
 
   cursor = checked_calloc(sizeof(struct MouseCursorInfo));
 
+  sscanf(image[0], " %d %d ", &cursor->width, &cursor->height);
+
   i = -1;
-  for (row=0; row<32; ++row)
+  for (y=0; y < cursor->width; y++)
   {
-    for (col=0; col<32; ++col)
+    for (x=0; x < cursor->height; x++)
     {
-      if (col % 8)
-      {
-        cursor->data[i] <<= 1;
-        cursor->mask[i] <<= 1;
-      }
-      else
+      int bit_nr = x % 8;
+      int bit_mask = 0x01 << (bit_order_msb ? 7 - bit_nr : bit_nr );
+
+      if (bit_nr == 0)
       {
         i++;
         cursor->data[i] = cursor->mask[i] = 0;
       }
 
-      switch (image[4+row][col])
+      switch (image[header_lines + y][x])
       {
         case 'X':
-         cursor->data[i] |= 0x01;
-         cursor->mask[i] |= 0x01;
+         cursor->data[i] |= bit_mask;
+         cursor->mask[i] |= bit_mask;
          break;
 
         case '.':
-         cursor->mask[i] |= 0x01;
+         cursor->mask[i] |= bit_mask;
          break;
 
         case ' ':
@@ -941,17 +936,14 @@ static struct MouseCursorInfo *get_cursor_from_image(const char **image)
     }
   }
 
-  sscanf(image[4+row], "%d,%d", &cursor->hot_x, &cursor->hot_y);
-
-  cursor->width = 32;
-  cursor->height = 32;
+  sscanf(image[header_lines + y], "%d,%d", &cursor->hot_x, &cursor->hot_y);
 
   return cursor;
 }
 
 void SetMouseCursor(int mode)
 {
-  struct MouseCursorInfo *cursor_playfield = NULL;
+  static struct MouseCursorInfo *cursor_playfield = NULL;
 
   if (cursor_playfield == NULL)
     cursor_playfield = get_cursor_from_image(cursor_image_playfield);
index c8afb2de3187d3aed2f8236c1447a1cbbfa6c61e..a2eda6d6eccfa7c89a644d96a7d4684128c8f1eb 100644 (file)
 #define CURSOR_DEFAULT         0
 #define CURSOR_PLAYFIELD       1
 
-#define CURSOR_MAX_WIDTH       32
-#define CURSOR_MAX_HEIGHT      32
-
 
 /* maximum number of parallel players supported by libgame functions */
 #define MAX_PLAYERS            4
@@ -363,15 +360,6 @@ struct JoystickInfo
   int fd[MAX_PLAYERS];         /* file descriptor of player's joystick */
 };
 
-struct MouseCursorInfo
-{
-  int width, height;
-  int hot_x, hot_y;
-
-  char data[CURSOR_MAX_WIDTH * CURSOR_MAX_HEIGHT / 8];
-  char mask[CURSOR_MAX_WIDTH * CURSOR_MAX_HEIGHT / 8];
-};
-
 struct SetupJoystickInfo
 {
   char *device_name;           /* device name of player's joystick */
index 61d1a1a5d2b06d7759ea32533004215b3ffe6286..278230de2cc7ea417641c1d93981f93c9d7c2f4e 100644 (file)
@@ -429,82 +429,46 @@ inline Pixel X11GetPixelFromRGB(unsigned int color_r, unsigned int color_g,
 
 #if defined(TARGET_X11_NATIVE)
 
-static Cursor create_cursor(const char **image)
+static Cursor create_cursor(struct MouseCursorInfo *cursor_info)
 {
   Pixmap pixmap_data, pixmap_mask;
   XColor color_fg, color_bg;
   Cursor cursor;
 
-  int i, row, col;
-  char data[4*32];
-  char mask[4*32];
-  int hot_x, hot_y;
-
-  int data_width = 32, data_height = 32;
-  int mask_width = 32, mask_height = 32;
-
-  i = -1;
-  for (row=0; row<32; ++row)
-  {
-    for (col=0; col<32; ++col)
-    {
-      if (col % 8)
-      {
-        data[i] <<= 1;
-        mask[i] <<= 1;
-      }
-      else
-      {
-        i++;
-        data[i] = mask[i] = 0;
-      }
-
-      switch (image[4+row][col])
-      {
-        case 'X':
-         data[i] |= 0x01;
-         mask[i] |= 0x01;
-         break;
-        case '.':
-         mask[i] |= 0x01;
-         break;
-        case ' ':
-         break;
-      }
-    }
-  }
-
-  sscanf(image[4+row], "%d,%d", &hot_x, &hot_y);
-
   /* shape and mask are single plane pixmaps */
-  pixmap_data = XCreatePixmapFromBitmapData(display, window->drawable, data,
-                                           data_width, data_height, 1, 0, 1);
-  pixmap_mask = XCreatePixmapFromBitmapData(display, window->drawable, mask,
-                                           mask_width, mask_height, 1, 0, 1);
+  pixmap_data =
+    XCreatePixmapFromBitmapData(display, window->drawable, cursor_info->data,
+                               cursor_info->width, cursor_info->height,
+                               1, 0, 1);
+  pixmap_mask =
+    XCreatePixmapFromBitmapData(display, window->drawable, cursor_info->mask,
+                               cursor_info->width, cursor_info->height,
+                               1, 0, 1);
 
   XParseColor(display, cmap, "black", &color_fg);
   XParseColor(display, cmap, "white", &color_bg);
 
   cursor = XCreatePixmapCursor(display, pixmap_data, pixmap_mask,
-                              &color_fg, &color_bg, hot_x, hot_y);
+                              &color_fg, &color_bg,
+                              cursor_info->hot_x, cursor_info->hot_y);
 
   return cursor;
 }
 
-void X11SetMouseCursor(const char **cursor_image)
+void X11SetMouseCursor(struct MouseCursorInfo *cursor_info)
 {
-  static const char **last_cursor_image = NULL;
+  static struct MouseCursorInfo *last_cursor_info = NULL;
   static Cursor cursor_default = None;
   static Cursor cursor_current = None;
 
-  if (cursor_image != NULL && cursor_image != last_cursor_image)
+  if (cursor_info != NULL && cursor_info != last_cursor_info)
   {
-    cursor_current = create_cursor(cursor_image);
-    last_cursor_image = cursor_image;
+    cursor_current = create_cursor(cursor_info);
+    last_cursor_info = cursor_info;
   }
 
   XDefineCursor(display, window->drawable,
-               cursor_image ? cursor_current : cursor_default);
+               cursor_info ? cursor_current : cursor_default);
 }
 #endif /* TARGET_X11_NATIVE */
 
index a4a0577fd1402dab9d3823c7f18e90d0a459556b..4ef96acbd976f5553dcbb751d58375626bb51c7e 100644 (file)
@@ -45,6 +45,9 @@
 
 #define FULLSCREEN_STATUS      FULLSCREEN_NOT_AVAILABLE
 
+#define CURSOR_MAX_WIDTH       32
+#define CURSOR_MAX_HEIGHT      32
+
 
 /* X11 type definitions */
 
@@ -80,6 +83,15 @@ struct X11DrawableInfo
   GC clip_gc;          /* can be 'stored_clip_gc' or one-tile-only clip GC  */
 };
 
+struct MouseCursorInfo
+{
+  int width, height;
+  int hot_x, hot_y;
+
+  char data[CURSOR_MAX_WIDTH * CURSOR_MAX_HEIGHT / 8];
+  char mask[CURSOR_MAX_WIDTH * CURSOR_MAX_HEIGHT / 8];
+};
+
 struct XY
 {
   short x, y;
@@ -321,7 +333,7 @@ inline Pixel X11GetPixel(Bitmap *, int, int);
 inline Pixel X11GetPixelFromRGB(unsigned int, unsigned int, unsigned int);
 
 #if defined(TARGET_X11_NATIVE)
-void X11SetMouseCursor(const char **);
+void X11SetMouseCursor(struct MouseCursorInfo *);
 #endif
 
 #endif /* X11_H */