X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Fevents.c;h=b5be2a1610394fd4e33fa3078d2e3e5124eeff8c;hb=de8b3ae622eae10f1caf96872fb1790f7bd9644b;hp=604345d90f07054d1639ee0f285d45c1123547db;hpb=da14f69fd95c7bd5a0d70cdf4935af06f1f20a04;p=rocksndiamonds.git diff --git a/src/events.c b/src/events.c index 604345d9..b5be2a16 100644 --- a/src/events.c +++ b/src/events.c @@ -1,14 +1,14 @@ /*********************************************************** -* Rocks'n'Diamonds -- McDuffin Strikes Back! * +* Rocks'n'Diamonds -- McDuffin Strikes Back! * *----------------------------------------------------------* -* (c) 1995-98 Artsoft Entertainment * -* Holger Schemel * -* Oststrasse 11a * -* 33604 Bielefeld * -* phone: ++49 +521 290471 * -* email: aeglos@valinor.owl.de * +* (c) 1995-2002 Artsoft Entertainment * +* Holger Schemel * +* Detmolder Strasse 189 * +* 33604 Bielefeld * +* Germany * +* e-mail: info@artsoft.org * *----------------------------------------------------------* -* events.c * +* events.c * ***********************************************************/ #include "libgame/libgame.h" @@ -19,8 +19,8 @@ #include "tools.h" #include "game.h" #include "editor.h" +#include "files.h" #include "tape.h" -#include "joystick.h" #include "network.h" /* values for key_status */ @@ -30,21 +30,54 @@ /* event filter especially needed for SDL event filtering due to - delay problems with lots of mouse motion events when mouse - button not pressed */ + delay problems with lots of mouse motion events when mouse button + not pressed (X11 can handle this with 'PointerMotionHintMask') */ int FilterMouseMotionEvents(const Event *event) { + /* non-motion events are directly passed to event handler functions */ if (event->type != EVENT_MOTIONNOTIFY) return 1; - /* get mouse motion events without pressed button only in level editor */ + /* 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; + + SetMouseCursor(inside_field ? CURSOR_PLAYFIELD : CURSOR_DEFAULT); + } + } + + /* skip mouse motion events without pressed button outside level editor */ if (button_status == MB_RELEASED && game_status != LEVELED) return 0; else return 1; } +/* this is only really needed for non-SDL targets to filter unwanted events; + when using SDL with properly installed event filter, this function can be + replaced with a simple "NextEvent()" call, but it doesn't hurt either */ + +static boolean NextValidEvent(Event *event) +{ + while (PendingEvent()) + { + NextEvent(event); + + if (FilterMouseMotionEvents(event)) + return TRUE; + } + + return FALSE; +} + void EventLoop(void) { while(1) @@ -53,9 +86,7 @@ void EventLoop(void) { Event event; - NextEvent(&event); - - if (FilterMouseMotionEvents(&event)) + if (NextValidEvent(&event)) { switch(event.type) { @@ -111,7 +142,11 @@ void HandleOtherEvents(Event *event) break; case EVENT_UNMAPNOTIFY: +#if 0 + /* This causes the game to stop not only when iconified, but also + when on another virtual desktop, which might be not desired. */ SleepWhileUnmapped(); +#endif break; case EVENT_FOCUSIN: @@ -161,6 +196,16 @@ void ClearEventQueue() } } +void ClearPlayerAction() +{ + int i; + + /* simulate key release events for still pressed keys */ + key_joystick_mapping = 0; + for (i=0; ix, y = event->y; - int width = event->width, height = event->height; - - if (setup.direct_draw && game_status==PLAYING) - { - int xx,yy; - int x1 = (x-SX)/TILEX, y1 = (y-SY)/TILEY; - int x2 = (x-SX+width)/TILEX, y2 = (y-SY+height)/TILEY; - - SetDrawtoField(DRAW_BACKBUFFER); - - for(xx=0; xx=x1 && xx<=x2 && yy>=y1 && yy<=y2) - DrawScreenField(xx,yy); - DrawAllPlayers(); - - SetDrawtoField(DRAW_DIRECT); - } - - if (setup.soft_scrolling && game_status == PLAYING) - { - int fx = FX, fy = FY; - - fx += (ScreenMovDir & (MV_LEFT|MV_RIGHT) ? ScreenGfxPos : 0); - fy += (ScreenMovDir & (MV_UP|MV_DOWN) ? ScreenGfxPos : 0); - - BlitBitmap(fieldbuffer, backbuffer, fx,fy, SXSIZE,SYSIZE, SX,SY); - } - - BlitBitmap(drawto, window, x,y, width,height, x,y); - + RedrawPlayfield(FALSE, event->x, event->y, event->width, event->height); FlushDisplay(); #endif } @@ -285,16 +299,11 @@ void HandleFocusEvent(FocusChangeEvent *event) if (event->type == EVENT_FOCUSOUT) { - int i; - KeyboardAutoRepeatOn(); - old_joystick_status = joystick_status; - joystick_status = JOYSTICK_OFF; + old_joystick_status = joystick.status; + joystick.status = JOYSTICK_NOT_AVAILABLE; - /* simulate key release events for still pressed keys */ - key_joystick_mapping = 0; - for (i=0; itype == EVENT_FOCUSIN) { @@ -320,7 +329,7 @@ void HandleFocusEvent(FocusChangeEvent *event) KeyboardAutoRepeatOff(); } if (old_joystick_status != -1) - joystick_status = old_joystick_status; + joystick.status = old_joystick_status; } } @@ -377,10 +386,6 @@ void HandleButton(int mx, int my, int button) HandleSetupScreen(mx,my, 0,0, button); break; - case SETUPINPUT: - HandleSetupInputScreen(mx,my, 0,0, button); - break; - case PLAYING: #ifdef DEBUG if (button == MB_RELEASED) @@ -438,6 +443,9 @@ void HandleKey(Key key, int key_status) if (game_status == PLAYING) { + /* only needed for single-step tape recording mode */ + static boolean clear_button_2[MAX_PLAYERS] = { FALSE,FALSE,FALSE,FALSE }; + static boolean bomb_placed[MAX_PLAYERS] = { FALSE,FALSE,FALSE,FALSE }; int pnr; for (pnr=0; pnr