X-Git-Url: https://git.artsoft.org/?p=rocksndiamonds.git;a=blobdiff_plain;f=src%2Fmsdos.c;fp=src%2Fmsdos.c;h=598aa5d2c5b3081c39b1cca2bd0514cacb96eb5d;hp=b64b9fab6ea36349c54a43f72d239d2409c1cad9;hb=41364660abbcb81a83f5018be3655352ecdf1ac9;hpb=0d2143d53f76e2780260996fae2b9f3ce4f29913 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");