-#define COMPILE_DATE_STRING "[2003-04-04 23:16]"
+#define COMPILE_DATE_STRING "[2003-04-05 01:37]"
#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') */
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;
}
}
}
}
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 */
{
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;
{
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;
{
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;
#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
/* 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);
}
#define TARGET_STRING "SDL"
#define FULLSCREEN_STATUS FULLSCREEN_AVAILABLE
+#define CURSOR_MAX_WIDTH 32
+#define CURSOR_MAX_HEIGHT 32
+
/* SDL type definitions */
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;
Bitmap *SDLLoadImage(char *);
-void SDLSetMouseCursor(const char **);
+void SDLSetMouseCursor(struct MouseCursorInfo *);
inline void SDLOpenAudio(void);
inline void SDLCloseAudio(void);
/* 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 ' ':
}
}
- 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);
#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
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 */
#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 */
#define FULLSCREEN_STATUS FULLSCREEN_NOT_AVAILABLE
+#define CURSOR_MAX_WIDTH 32
+#define CURSOR_MAX_HEIGHT 32
+
/* X11 type definitions */
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;
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 */