From: Holger Schemel Date: Mon, 1 Feb 1999 02:23:00 +0000 (+0100) Subject: rnd-19990201-1 X-Git-Tag: 1.3.0^2~5 X-Git-Url: https://git.artsoft.org/?p=rocksndiamonds.git;a=commitdiff_plain;h=41364660abbcb81a83f5018be3655352ecdf1ac9 rnd-19990201-1 --- diff --git a/src/Makefile b/src/Makefile index 4c0a427b..37352916 100644 --- a/src/Makefile +++ b/src/Makefile @@ -69,9 +69,9 @@ CONFIG = $(CONFIG_GAME_DIR) $(SOUNDS) $(JOYSTICK) \ $(CONFIG_SCORE_ENTRIES) $(XPM_INCLUDE_FILE) # DEBUG = -DDEBUG -g -Wall -ansi -pedantic -DEBUG = -DDEBUG -g -Wall +# DEBUG = -DDEBUG -g -Wall # DEBUG = -O3 -Wall -ansi -pedantic -# DEBUG = -O3 -Wall +DEBUG = -O3 -Wall # DEBUG = -O3 # SYSTEM = -Aa -D_HPUX_SOURCE -Dhpux # for HP-UX (obsolete) diff --git a/src/buttons.c b/src/buttons.c index 5fba665c..7c1e9c9a 100644 --- a/src/buttons.c +++ b/src/buttons.c @@ -2297,7 +2297,7 @@ void HandleGadgets(int mx, int my, int button) static unsigned long pressed_delay = 0; static int last_button = 0; static int last_mx = 0, last_my = 0; - int scrollbar_mouse_pos; + int scrollbar_mouse_pos = 0; struct GadgetInfo *new_gi, *gi; boolean press_event; boolean release_event; diff --git a/src/editor.c b/src/editor.c index 23f12d07..ab28fe0c 100644 --- a/src/editor.c +++ b/src/editor.c @@ -2814,21 +2814,22 @@ static void FloodFill(int from_x, int from_y, int fill_element) } /* 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 +#define TEXT_INIT 0 +#define TEXT_SETCURSOR 1 +#define TEXT_WRITECHAR 2 +#define TEXT_BACKSPACE 3 +#define TEXT_NEWLINE 4 +#define TEXT_END 5 +#define TEXT_QUERY_TYPING 6 -static void DrawLevelText(int sx, int sy, char letter, int mode) +static int 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; + int lx = 0, ly = 0; /* map lower case letters to upper case and convert special characters */ if (letter >= 'a' && letter <= 'z') @@ -2847,7 +2848,7 @@ static void DrawLevelText(int sx, int sy, char letter, int mode) if (mode != TEXT_INIT) { if (!typing) - return; + return FALSE; if (mode != TEXT_SETCURSOR) { @@ -2897,7 +2898,7 @@ static void DrawLevelText(int sx, int sy, char letter, int mode) if (sx > start_sx) { Feld[lx - 1][ly] = delete_buffer[sx - start_sx - 1]; - DrawMiniElement(sx - 1, sy, new_element3); + DrawMiniElement(sx - 1, sy, Feld[lx - 1][ly]); DrawLevelText(sx - 1, sy, 0, TEXT_SETCURSOR); } break; @@ -2915,9 +2916,14 @@ static void DrawLevelText(int sx, int sy, char letter, int mode) typing = FALSE; break; + case TEXT_QUERY_TYPING: + break; + default: break; } + + return typing; } static void SetTextCursor(int unused_sx, int unused_sy, int sx, int sy, @@ -3069,7 +3075,7 @@ static void HandleDrawingAreas(struct GadgetInfo *gi) int sx = gi->event.x, sy = gi->event.y; int min_sx = 0, min_sy = 0; int max_sx = gi->drawing.area_xsize - 1, max_sy = gi->drawing.area_ysize - 1; - int lx, ly; + int lx = 0, ly = 0; int min_lx = 0, min_ly = 0; int max_lx = lev_fieldx - 1, max_ly = lev_fieldy - 1; int x, y; @@ -3832,7 +3838,8 @@ void HandleLevelEditorKeyInput(KeySym key) char letter = getCharFromKeySym(key); int button = MB_LEFT; - if (drawing_function == GADGET_ID_TEXT) + if (drawing_function == GADGET_ID_TEXT && + DrawLevelText(0, 0, 0, TEXT_QUERY_TYPING) == TRUE) { if (letter) DrawLevelText(0, 0, letter, TEXT_WRITECHAR); diff --git a/src/events.c b/src/events.c index b5d3c18c..a336f013 100644 --- a/src/events.c +++ b/src/events.c @@ -169,7 +169,7 @@ void SleepWhileUnmapped() } } - if (game_status==PLAYING) + if (game_status == PLAYING) XAutoRepeatOff(display); } @@ -274,13 +274,36 @@ void HandleFocusEvent(XFocusChangeEvent *event) if (event->type == FocusOut) { + int i; + XAutoRepeatOn(display); old_joystick_status = joystick_status; joystick_status = JOYSTICK_OFF; + + /* simulate key release events for still pressed keys */ key_joystick_mapping = 0; + for (i=0; itype == FocusIn) { + /* When there are two Rocks'n'Diamonds windows which overlap and + the player moves the pointer from one game window to the other, + a 'FocusOut' event is generated for the window the pointer is + leaving and a 'FocusIn' event is generated for the window the + pointer is entering. In some cases, it can happen that the + 'FocusIn' event is handled by the one game process before the + 'FocusOut' event by the other game process. In this case the + X11 environment would end up with activated keyboard auto repeat, + because unfortunately this is a global setting and not (which + would be far better) set for each X11 window individually. + The effect would be keyboard auto repeat while playing the game + (game_status == PLAYING), which is not desired. + To avoid this special case, we just wait 1/50 second before + processing the 'FocusIn' event. + */ + + Delay(20); if (game_status == PLAYING) XAutoRepeatOff(display); if (old_joystick_status != -1) diff --git a/src/files.c b/src/files.c index 0c4a7f43..71d01e94 100644 --- a/src/files.c +++ b/src/files.c @@ -1203,7 +1203,7 @@ static struct SetupFileList *loadSetupFileList(char *filename) /* cut trailing comment or whitespace from input line */ for (line_ptr = line; *line_ptr; line_ptr++) { - if (*line_ptr == '#' || *line_ptr == '\n') + if (*line_ptr == '#' || *line_ptr == '\n' || *line_ptr == '\r') { *line_ptr = '\0'; break; diff --git a/src/main.h b/src/main.h index 8e5a427c..f25774b4 100644 --- a/src/main.h +++ b/src/main.h @@ -1273,7 +1273,7 @@ extern char *element_info[]; #define TAPES_DIRECTORY "tapes" #define SCORES_DIRECTORY "scores" -#define PROGRAM_VERSION_STRING "1.2.1" +#define PROGRAM_VERSION_STRING "1.3.0" #define PROGRAM_TITLE_STRING "Rocks'n'Diamonds" #define PROGRAM_AUTHOR_STRING "Holger Schemel" #define WINDOW_TITLE_STRING PROGRAM_TITLE_STRING " " PROGRAM_VERSION_STRING diff --git a/src/misc.c b/src/misc.c index 9aec199e..fd85aedd 100644 --- a/src/misc.c +++ b/src/misc.c @@ -243,6 +243,7 @@ char *getLoginName() char *getRealName() { +#ifndef MSDOS struct passwd *pwd; if ((pwd = getpwuid(getuid())) == NULL || strlen(pwd->pw_gecos) == 0) @@ -272,6 +273,9 @@ char *getRealName() return real_name; } +#else + return ANONYMOUS_NAME; +#endif } char *getHomeDir() diff --git a/src/msdos.c b/src/msdos.c index b64b9fab..598aa5d2 100644 --- a/src/msdos.c +++ b/src/msdos.c @@ -37,6 +37,7 @@ extern JOYSTICK_INFO joy[]; extern int i_love_bill; /* internal variables of msdos.c */ +static boolean keyboard_auto_repeat = TRUE; static int key_press_state[MAX_SCANCODES]; static XEvent event_buffer[MAX_EVENT_BUFFER]; static int pending_events; @@ -250,6 +251,42 @@ void XMapWindow(Display *display, Window window) unhide_mouse(display); } +static unsigned long AllocColorCell(int r, int g, int b) +{ + byte pixel_mapping = 0; + int i; + + r >>= 10; + g >>= 10; + b >>= 10; + + /* try to use existing colors from the global colormap */ + for (i=0; idefault_screen = 0; @@ -385,7 +427,7 @@ void XFillRectangle(Display *display, Drawable d, GC gc, int x, int y, mouse_off = hide_mouse(display, x, y, width, height); } - rectfill((BITMAP *)d, x, y, x + width, y + height, + rectfill((BITMAP *)d, x, y, x + width - 1, y + height - 1, ((XGCValues *)gc)->foreground); if (mouse_off) @@ -460,7 +502,12 @@ static BITMAP *Image_to_AllegroBitmap(Image *image) byte *src_ptr = image->data; byte pixel_mapping[MAX_COLORS]; unsigned int depth = 8; + +#if 0 int i, j, x, y; +#else + int i, x, y; +#endif /* allocate new allegro bitmap structure */ if ((bitmap = create_bitmap_ex(depth, image->width, image->height)) == NULL) @@ -471,11 +518,16 @@ static BITMAP *Image_to_AllegroBitmap(Image *image) /* try to use existing colors from the global colormap */ for (i=0; irgb.color_used[i]) continue; + +#if 0 r = image->rgb.red[i] >> 10; g = image->rgb.green[i] >> 10; b = image->rgb.blue[i] >> 10; @@ -502,6 +554,12 @@ static BITMAP *Image_to_AllegroBitmap(Image *image) pixel_mapping[i] = j; } +#else + pixel_mapping[i] = AllocColorCell(image->rgb.red[i], + image->rgb.green[i], + image->rgb.blue[i]); +#endif + } /* copy bitmap data */ @@ -633,7 +691,7 @@ static void NewKeyEvent(int key_press_state, KeySym keysym) xkey->state = (unsigned int)keysym; } -#define HANDLE_RAW_KB_ALL_KEYS 0 +#define HANDLE_RAW_KB_ALL_KEYS 0 #define HANDLE_RAW_KB_MODIFIER_KEYS_ONLY 1 static int modifier_scancode[] = @@ -701,6 +759,26 @@ static void HandleKeyboardEvent() else if (ascii == '.') keysym = XK_KP_Separator; } + else if (ascii >= ' ' && ascii <= 'Z') + keysym = XK_space + (KeySym)(ascii - ' '); + else if (ascii == '^') + keysym = XK_asciicircum; + else if (ascii == '_') + keysym = XK_underscore; + else if (ascii == 'Ä') + keysym = XK_Adiaeresis; + else if (ascii == 'Ö') + keysym = XK_Odiaeresis; + else if (ascii == 'Ü') + keysym = XK_Udiaeresis; + else if (ascii == 'ä') + keysym = XK_adiaeresis; + else if (ascii == 'ö') + keysym = XK_odiaeresis; + else if (ascii == 'ü') + keysym = XK_udiaeresis; + else if (ascii == 'ß') + keysym = XK_ssharp; NewKeyEvent(KeyPress, keysym); } @@ -720,15 +798,22 @@ int XPending(Display *display) XMotionEvent *xmotion; int i; + /* When using 'HandleKeyboardRaw()', keyboard input is also stored in + the allegro keyboard input buffer and would be available a second + time by calling 'HandleKeyboardEvent()'. To avoid double keyboard + events, the allegro function 'clear_keybuf()' must be called each + time when switching from calling 'HandleKeyboardRaw()' to calling + 'HandleKeyboardEvent()' to get keyboard input, which is actually + done by 'XAutoRepeatOn()' which sets keyboard_auto_repeat to TRUE. */ + /* keyboard event */ - if (game_status == PLAYING) - HandleKeyboardRaw(HANDLE_RAW_KB_ALL_KEYS); - else + if (keyboard_auto_repeat) HandleKeyboardEvent(); + else + HandleKeyboardRaw(HANDLE_RAW_KB_ALL_KEYS); /* mouse motion event */ - /* generate mouse motion event only if any mouse buttons are pressed */ - if (mouse_pos != last_mouse_pos && mouse_b) + if (mouse_pos != last_mouse_pos) { last_mouse_pos = mouse_pos; pending_events++; @@ -812,6 +897,27 @@ void XDestroyImage(XImage *ximage) { } +Bool XQueryPointer(Display *display, Window window, + Window *root, Window *child, int *root_x, int *root_y, + int *win_x, int *win_y, unsigned int *mask) +{ + *win_x = mouse_x - display->screens[display->default_screen].x; + *win_y = mouse_y - display->screens[display->default_screen].y; + + return True; +} + +void XAutoRepeatOn(Display *display) +{ + keyboard_auto_repeat = TRUE; + clear_keybuf(); +} + +void XAutoRepeatOff(Display *display) +{ + keyboard_auto_repeat = FALSE; +} + void NetworkServer(int port, int serveronly) { Error(ERR_WARN, "networking not supported in DOS version"); diff --git a/src/msdos.h b/src/msdos.h index 32d6a4c2..508bb844 100644 --- a/src/msdos.h +++ b/src/msdos.h @@ -444,8 +444,6 @@ #define XFlush(a) #define XGetImage(a,b,c,d,e,f,g,h) ((XImage *) NULL) -#define XAutoRepeatOn(a) -#define XAutoRepeatOff(a) #define XDisplayName(a) ((char *) NULL) #define XFreeColors(a,b,c,d,e) #define XpmFreeAttributes(a) @@ -711,4 +709,8 @@ int XLookupString(XKeyEvent *, char *, int, KeySym *, XComposeStatus *); void XSetForeground(Display *, GC, unsigned long); void XDrawLine(Display *, Drawable, GC, int, int, int, int); void XDestroyImage(XImage *); +Bool XQueryPointer(Display *, Window, Window *, Window *, int *, int *, + int *, int *, unsigned int *); +void XAutoRepeatOn(Display *); +void XAutoRepeatOff(Display *); void NetworkServer(int, int); diff --git a/src/tools.c b/src/tools.c index 0d1f8b91..f68804f5 100644 --- a/src/tools.c +++ b/src/tools.c @@ -543,7 +543,7 @@ void DrawPlayer(struct PlayerInfo *player) */ #endif - static last_dir = MV_LEFT; + static int last_dir = MV_LEFT; if (player->Pushing) { @@ -2430,8 +2430,8 @@ void CreateToolButtons() for (i=0; i