Home | History | Annotate | Download | only in picogui
      1 /*
      2     SDL - Simple DirectMedia Layer
      3     Copyright (C) 1997-2006 Sam Lantinga
      4 
      5     This library is free software; you can redistribute it and/or
      6     modify it under the terms of the GNU Lesser General Public
      7     License as published by the Free Software Foundation; either
      8     version 2.1 of the License, or (at your option) any later version.
      9 
     10     This library is distributed in the hope that it will be useful,
     11     but WITHOUT ANY WARRANTY; without even the implied warranty of
     12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     13     Lesser General Public License for more details.
     14 
     15     You should have received a copy of the GNU Lesser General Public
     16     License along with this library; if not, write to the Free Software
     17     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
     18 
     19     Sam Lantinga
     20     slouken (at) libsdl.org
     21 
     22     Micah Dowty
     23     micahjd (at) users.sourceforge.net
     24 */
     25 #include "SDL_config.h"
     26 
     27 #include "SDL.h"
     28 #include "../../events/SDL_sysevents.h"
     29 #include "../../events/SDL_events_c.h"
     30 #include "SDL_pgvideo.h"
     31 #include "SDL_pgevents_c.h"
     32 
     33 int PG_HandleClose(struct pgEvent *evt)
     34 {
     35         SDL_PrivateQuit();
     36 	return 1;               /* Intercept the event's normal quit handling */
     37 }
     38 
     39 int PG_HandleResize(struct pgEvent *evt)
     40 {
     41         SDL_PrivateResize(evt->e.size.w, evt->e.size.h);
     42 	return 0;
     43 }
     44 
     45 int PG_HandleKey(struct pgEvent *evt)
     46 {
     47         SDL_keysym sym;
     48 	SDL_memset(&sym,0,sizeof(sym));
     49 	sym.sym = evt->e.kbd.key;
     50 	sym.mod = evt->e.kbd.mods;
     51         SDL_PrivateKeyboard(evt->type == PG_WE_KBD_KEYDOWN, &sym);
     52 	return 0;
     53 }
     54 
     55 int PG_HandleChar(struct pgEvent *evt)
     56 {
     57         SDL_keysym sym;
     58 	SDL_memset(&sym,0,sizeof(sym));
     59 	sym.unicode = evt->e.kbd.key;
     60 	sym.mod = evt->e.kbd.mods;
     61         SDL_PrivateKeyboard(evt->type == PG_WE_KBD_KEYDOWN, &sym);
     62 	return 0;
     63 }
     64 
     65 int PG_HandleMouseButton(struct pgEvent *evt)
     66 {
     67         /* We need to focus the canvas when it's clicked */
     68         if (evt->extra) {
     69 	        SDL_VideoDevice *this = (SDL_VideoDevice *) evt->extra;
     70 		pgFocus(this->hidden->wCanvas);
     71 	}
     72         SDL_PrivateMouseButton(evt->type == PG_WE_PNTR_DOWN, evt->e.pntr.chbtn,
     73 			       evt->e.pntr.x, evt->e.pntr.y);
     74 	return 0;
     75 }
     76 
     77 int PG_HandleMouseMotion(struct pgEvent *evt)
     78 {
     79         SDL_PrivateMouseMotion(evt->e.pntr.btn,0,evt->e.pntr.x, evt->e.pntr.y);
     80 	return 0;
     81 }
     82 
     83 void PG_PumpEvents(_THIS)
     84 {
     85         /* Process all pending events */
     86         pgEventPoll();
     87 }
     88 
     89 void PG_InitOSKeymap(_THIS)
     90 {
     91         /* We need no keymap */
     92 }
     93 
     94 void PG_InitEvents(_THIS)
     95 {
     96         /* Turn on all the mouse and keyboard triggers for our canvas, normally less important
     97 	 * events like mouse movement are ignored to save bandwidth. */
     98         pgSetWidget(this->hidden->wCanvas, PG_WP_TRIGGERMASK,
     99 		    pgGetWidget(this->hidden->wCanvas, PG_WP_TRIGGERMASK) |
    100 		    PG_TRIGGER_UP | PG_TRIGGER_DOWN | PG_TRIGGER_MOVE |
    101 		    PG_TRIGGER_KEYUP | PG_TRIGGER_KEYDOWN | PG_TRIGGER_CHAR,0);
    102 
    103 	/* Start our canvas out focused, so we get keyboard input */
    104 	pgFocus(this->hidden->wCanvas);
    105 
    106         /* Set up bindings for all the above event handlers */
    107         pgBind(this->hidden->wApp,    PG_WE_CLOSE, &PG_HandleClose, NULL);
    108         pgBind(this->hidden->wCanvas, PG_WE_BUILD, &PG_HandleResize, NULL);
    109         pgBind(this->hidden->wCanvas, PG_WE_KBD_CHAR, &PG_HandleChar, NULL);
    110         pgBind(this->hidden->wCanvas, PG_WE_KBD_KEYUP, &PG_HandleKey, NULL);
    111         pgBind(this->hidden->wCanvas, PG_WE_KBD_KEYDOWN, &PG_HandleKey, NULL);
    112         pgBind(this->hidden->wCanvas, PG_WE_PNTR_MOVE, &PG_HandleMouseMotion, NULL);
    113         pgBind(this->hidden->wCanvas, PG_WE_PNTR_UP, &PG_HandleMouseButton, NULL);
    114         pgBind(this->hidden->wCanvas, PG_WE_PNTR_DOWN, &PG_HandleMouseButton, this);
    115 }
    116 
    117 /* end of SDL_pgevents.c ... */
    118