X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Fevents.c;h=b5d3c18c4473bfdee23c1b4bbf70b19512eafa42;hb=6b83db8bee17d70c4e89dc3e3b703b7032aa5f27;hp=ed76f9a655beac4341b36a1cb80bb4cfda26b5fb;hpb=f9a30d8f0565691424cc9fd2643a50a176dae903;p=rocksndiamonds.git diff --git a/src/events.c b/src/events.c index ed76f9a6..b5d3c18c 100644 --- a/src/events.c +++ b/src/events.c @@ -20,8 +20,14 @@ #include "misc.h" #include "tape.h" #include "joystick.h" +#include "buttons.h" #include "network.h" +/* values for key_status */ +#define KEY_NOT_PRESSED FALSE +#define KEY_RELEASED FALSE +#define KEY_PRESSED TRUE + void EventLoop(void) { while(1) @@ -65,6 +71,9 @@ void EventLoop(void) Delay(10); } + /* refresh window contents from drawing buffer, if needed */ + BackToFront(); + if (game_status == EXITGAME) return; } @@ -207,7 +216,7 @@ void HandleButtonEvent(XButtonEvent *event) { motion_status = FALSE; - if (event->type==ButtonPress) + if (event->type == ButtonPress) button_status = event->button; else button_status = MB_RELEASED; @@ -217,16 +226,44 @@ void HandleButtonEvent(XButtonEvent *event) void HandleMotionEvent(XMotionEvent *event) { + Window root, child; + int root_x, root_y; + int win_x, win_y; + unsigned int mask; + + if (!XQueryPointer(display, window, &root, &child, &root_x, &root_y, + &win_x, &win_y, &mask)) + return; + + if (!button_status && game_status != LEVELED) + return; + motion_status = TRUE; - HandleButton(event->x, event->y, button_status); + HandleButton(win_x, win_y, button_status); } void HandleKeyEvent(XKeyEvent *event) { int key_status = (event->type == KeyPress ? KEY_PRESSED : KEY_RELEASED); - unsigned int event_state = (game_status != PLAYING ? event->state : 0); - KeySym key = XLookupKeysym(event, event_state); + KeySym key; + + if (game_status == PLAYING) + { + /* use '0' instead of 'event->state' to get the key without modifiers */ + key = XLookupKeysym(event, 0); + } + else + { + /* get the key with all modifiers */ + char buffer[10]; + int buffer_size = 10; + XComposeStatus compose; + int char_count; + + char_count = XLookupString(event, buffer, buffer_size, &key, &compose); + buffer[char_count] = '\0'; + } HandleKey(key, key_status); } @@ -253,42 +290,49 @@ void HandleFocusEvent(XFocusChangeEvent *event) void HandleClientMessageEvent(XClientMessageEvent *event) { +#ifndef MSDOS if ((event->window == window) && (event->data.l[0] == XInternAtom(display, "WM_DELETE_WINDOW", FALSE))) CloseAllAndExit(0); +#endif } void HandleButton(int mx, int my, int button) { static int old_mx = 0, old_my = 0; - if (mx<0 || my<0) + if (button < 0) { mx = old_mx; my = old_my; + button = -button; } else { old_mx = mx; old_my = my; - HandleVideoButtons(mx,my,button); - HandleSoundButtons(mx,my,button); - HandleGameButtons(mx,my,button); + /* + HandleVideoButtons(mx,my, button); + HandleSoundButtons(mx,my, button); + HandleGameButtons(mx,my, button); + */ } + HandleGadgets(mx, my, button); + switch(game_status) { case MAINMENU: - HandleMainMenu(mx,my,0,0,button); + HandleMainMenu(mx,my, 0,0, button); break; case TYPENAME: - HandleTypeName(0,XK_Return); + HandleTypeName(0, XK_Return); break; case CHOOSELEVEL: - HandleChooseLevel(mx,my,0,0,button); + HandleChooseLevel(mx,my, 0,0, button); break; case HALLOFFAME: @@ -296,7 +340,6 @@ void HandleButton(int mx, int my, int button) break; case LEVELED: - LevelEd(mx,my,button); break; case HELPSCREEN: @@ -304,11 +347,11 @@ void HandleButton(int mx, int my, int button) break; case SETUP: - HandleSetupScreen(mx,my,0,0,button); + HandleSetupScreen(mx,my, 0,0, button); break; case SETUPINPUT: - HandleSetupInputScreen(mx,my,0,0,button); + HandleSetupInputScreen(mx,my, 0,0, button); break; case PLAYING: @@ -323,7 +366,12 @@ void HandleButton(int mx, int my, int button) int x = LEVELX(sx); int y = LEVELY(sy); - printf("INFO: Feld[%d][%d] == %d\n", x,y, Feld[x][y]); + printf("INFO: SCREEN(%d, %d), LEVEL(%d, %d)\n", sx, sy, x, y); + + if (!IN_LEV_FIELD(x, y)) + break; + + printf(" Feld[%d][%d] == %d\n", x,y, Feld[x][y]); printf(" Store[%d][%d] == %d\n", x,y, Store[x][y]); printf(" Store2[%d][%d] == %d\n", x,y, Store2[x][y]); printf(" StorePlayer[%d][%d] == %d\n", x,y, StorePlayer[x][y]); @@ -420,15 +468,35 @@ void HandleKey(KeySym key, int key_status) /* allow quick escape to the main menu with the Escape key */ if (key == XK_Escape && game_status != MAINMENU) { - CloseDoor(DOOR_CLOSE_1 | DOOR_NO_DELAY); + if (game_status == LEVELED) + { + /* draw smaller door */ + XCopyArea(display, pix[PIX_DOOR], drawto, gc, + DOOR_GFX_PAGEX7, 64, + 108, 64, + EX - 4, EY - 12); + redraw_mask |= REDRAW_ALL; + } + + CloseDoor(DOOR_CLOSE_1 | DOOR_OPEN_2 | DOOR_NO_DELAY); game_status = MAINMENU; DrawMainMenu(); return; } + + +#ifndef DEBUG + if (game_status == PLAYING && (tape.playing || tape.pausing)) return; +#endif + + + + HandleGadgetsKeyInput(key); + switch(game_status) { case TYPENAME: @@ -476,7 +544,7 @@ void HandleKey(KeySym key, int key_status) break; case LEVELED: - LevelNameTyping(key); + HandleLevelEditorKeyInput(key); break; case PLAYING: @@ -496,7 +564,12 @@ void HandleKey(KeySym key, int key_status) case XK_8: case XK_9: if (key == XK_0) - GameFrameDelay = 500; + { + if (GameFrameDelay == 500) + GameFrameDelay = GAME_FRAME_DELAY; + else + GameFrameDelay = 500; + } else GameFrameDelay = (key - XK_0) * 10; printf("Game speed == %d%% (%d ms delay between two frames)\n", @@ -514,6 +587,22 @@ void HandleKey(KeySym key, int key_status) break; #endif +#if 1 + case XK_m: + if (MoveSpeed == 8) + { + MoveSpeed = 4; + ScrollStepSize = TILEX/4; + } + else + { + MoveSpeed = 8; + ScrollStepSize = TILEX/8; + } + printf("MoveSpeed == %d\n", MoveSpeed); + break; +#endif + case XK_f: ScrollStepSize = TILEX/8; printf("ScrollStepSize == %d (1/8)\n", ScrollStepSize); @@ -545,80 +634,6 @@ void HandleKey(KeySym key, int key_status) #if 0 - case XK_x: - - { - int i,j,k, num_steps = 8, step_size = TILEX / num_steps; - static long scroll_delay=0; - long scroll_delay_value = 4*4 / num_steps; - - printf("Scroll test\n"); - - for(i=0;i<3;i++) - { - for(j=0;j