Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

keyboard_ggi.cpp

Go to the documentation of this file.
00001 /*
00002         $Id: keyboard_ggi.cpp,v 1.1 2001/03/06 15:09:20 mbn Exp $
00003 
00004         ------------------------------------------------------------------------
00005         ClanLib, the platform independent game SDK.
00006 
00007         This library is distributed under the GNU LIBRARY GENERAL PUBLIC LICENSE
00008         version 2. See COPYING for details.
00009 
00010         For a total list of contributers see CREDITS.
00011 
00012         ------------------------------------------------------------------------
00013 */
00014 
00015 #include "Core/precomp.h"
00016 
00017 #ifdef USE_GGI
00018 
00019 #include <stdlib.h>
00020 #include <stdio.h>
00021 #include <string.h>
00022 #include <iostream>
00023 #include <unistd.h>
00024 
00025 #include <ggi/ggi.h>
00026 
00027 #include "keyboard_ggi.h"
00028 
00029 #include <API/Display/Input/input.h>
00030 #include <API/Display/Input/key.h>
00031 #include <Display/Input/GGI/keyboard_ggi.h>
00032 #include <Display/Display/GGI/display_ggi.h>
00033 #include <API/Display/Input/inputaxis.h>
00034 #include <Display/Input/GGI/keyboard_ggi.h>
00035 #include <API/Display/Input/inputbutton.h>
00036 #include <Display/Input/GGI/keyboard_ggi.h>
00037 #include <API/Display/Input/inputcursor.h>
00038 #include <API/Display/Input/inputhat.h>
00039 #include "Core/System/Generic/string_asm.h"
00040 
00041 /******************
00042   Keyboard
00043 ******************/
00044 
00045 CL_GGIKeyboard::CL_GGIKeyboard(CL_GGI_DisplayCard* card)
00046 {
00047         memset( &keymap, 0, sizeof(keymap) );
00048         
00049         m_vis = card->vis;
00050         
00051         buttons = new CL_InputButton_GGIKeyboard*[CL_NUM_KEYS];
00052         for (int i=0; i<CL_NUM_KEYS; i++) buttons[i] = NULL;
00053 }
00054 
00055 CL_GGIKeyboard::~CL_GGIKeyboard()
00056 {
00057         for (int i=0; i<CL_NUM_KEYS; i++) delete buttons[i];
00058         delete[] buttons;
00059 }
00060 
00061 void CL_GGIKeyboard::keep_alive()
00062 {
00063         ggi_event_mask  mask;
00064         ggi_event               event;
00065         struct timeval  tv = {0,0};
00066 
00067         mask = ggiEventPoll( m_vis, emKeyboard, &tv );
00068         
00069         while (mask)
00070         {
00071                 ggiEventRead( m_vis, &event, emKeyboard );
00072                 handle_event( &event );
00073                 
00074                 mask = ggiEventPoll( m_vis, emKeyboard, &tv );
00075         }
00076 }
00077 
00078 void CL_GGIKeyboard::handle_event(gii_event* event)
00079 {
00080         bool keydown;
00081 
00082         switch (event->any.type)
00083         {
00084                 case evKeyPress:
00085                 case evKeyRepeat:
00086                         keydown = true;
00087                         break;
00088                 case evKeyRelease:
00089                         keydown = false;
00090                         break;
00091                 default:
00092                         return;
00093         }
00094 
00095         CL_Key key;
00096         key.id = translate(event->key.label);
00097 
00098         if (event->key.sym < 256) 
00099         {
00100                 key.ascii = event->key.sym;
00101         }
00102         else
00103         {
00104                 key.ascii = -1;         
00105         }
00106 
00107         key.x = key.y = -1;
00108 
00109         if (keydown)
00110         {
00111                 key.state = CL_Key::Pressed;
00112                 CL_Input::sig_button_press(this, key);
00113         }
00114         else
00115         {
00116                 key.state = CL_Key::Released;
00117                 CL_Input::sig_button_release(this, key);
00118         }
00119         keymap[translate(event->key.label)] = keydown;
00120 }
00121 
00122 char CL_GGIKeyboard::translate(int kb_value)
00123 {
00124         switch (kb_value)
00125         {
00126         case GIIK_F1:   return CL_KEY_F1;
00127         case GIIK_F2:   return CL_KEY_F2;
00128         case GIIK_F3:   return CL_KEY_F3;
00129         case GIIK_F4:   return CL_KEY_F4;
00130         case GIIK_F5:   return CL_KEY_F5;
00131         case GIIK_F6:   return CL_KEY_F6;
00132         case GIIK_F7:   return CL_KEY_F7;
00133         case GIIK_F8:   return CL_KEY_F8;
00134         case GIIK_F9:   return CL_KEY_F9;
00135         case GIIK_F10:  return CL_KEY_F10;
00136         case GIIK_F11:  return CL_KEY_F11;
00137         case GIIK_F12:  return CL_KEY_F12;
00138         
00139         case GIIUC_A:   return CL_KEY_A;
00140         case GIIUC_B:   return CL_KEY_B;
00141         case GIIUC_C:   return CL_KEY_C;
00142         case GIIUC_D:   return CL_KEY_D;
00143         case GIIUC_E:   return CL_KEY_E;
00144         case GIIUC_F:   return CL_KEY_F;
00145         case GIIUC_G:   return CL_KEY_G;
00146         case GIIUC_H:   return CL_KEY_H;
00147         case GIIUC_I:   return CL_KEY_I;
00148         case GIIUC_J:   return CL_KEY_J;
00149         case GIIUC_K:   return CL_KEY_K;
00150         case GIIUC_L:   return CL_KEY_L;
00151         case GIIUC_M:   return CL_KEY_M;
00152         case GIIUC_N:   return CL_KEY_N;
00153         case GIIUC_O:   return CL_KEY_O;
00154         case GIIUC_P:   return CL_KEY_P;
00155         case GIIUC_Q:   return CL_KEY_Q;
00156         case GIIUC_R:   return CL_KEY_R;
00157         case GIIUC_S:   return CL_KEY_S;
00158         case GIIUC_T:   return CL_KEY_T;
00159         case GIIUC_U:   return CL_KEY_U;
00160         case GIIUC_V:   return CL_KEY_V;
00161         case GIIUC_W:   return CL_KEY_W;
00162         case GIIUC_X:   return CL_KEY_X;
00163         case GIIUC_Y:   return CL_KEY_Y;
00164         case GIIUC_Z:   return CL_KEY_Z;
00165         
00166         case GIIUC_0:   return CL_KEY_0;
00167         case GIIUC_1:   return CL_KEY_1;
00168         case GIIUC_2:   return CL_KEY_2;
00169         case GIIUC_3:   return CL_KEY_3;
00170         case GIIUC_4:   return CL_KEY_4;
00171         case GIIUC_5:   return CL_KEY_5;
00172         case GIIUC_6:   return CL_KEY_6;
00173         case GIIUC_7:   return CL_KEY_7;
00174         case GIIUC_8:   return CL_KEY_8;
00175         case GIIUC_9:   return CL_KEY_9;
00176         
00177         case GIIUC_Escape:      return CL_KEY_ESCAPE;
00178         case GIIK_Left: return CL_KEY_LEFT;
00179         case GIIK_Right:        return CL_KEY_RIGHT;
00180         case GIIK_Up:           return CL_KEY_UP;
00181         case GIIK_Down: return CL_KEY_DOWN;
00182         case GIIK_Enter:        return CL_KEY_ENTER;
00183 
00184         case GIIK_CtrlL:        return CL_KEY_LCTRL;
00185         case GIIK_CtrlR:        return CL_KEY_RCTRL;
00186         case GIIK_ShiftL:       return CL_KEY_LSHIFT;
00187         case GIIK_ShiftR:       return CL_KEY_RSHIFT;
00188         case GIIK_AltL: return CL_KEY_ALT;
00189         case GIIK_AltR: return CL_KEY_ALT;
00190         case GIIK_AltGr:        return CL_KEY_ALTGR;
00191         case GIIUC_Tab: return CL_KEY_TAB;
00192         case GIIUC_Space:       return CL_KEY_SPACE;
00193         case GIIUC_BackSpace:   return CL_KEY_BACKSPACE;
00194         case GIIK_Insert:       return CL_KEY_INSERT;
00195         case GIIK_Delete:       return CL_KEY_DELETE;
00196         case GIIK_Home: return CL_KEY_HOME;
00197         case GIIK_End:          return CL_KEY_END;
00198         case GIIK_PageUp:       return CL_KEY_PAGEUP;
00199         case GIIK_PageDown:     return CL_KEY_PAGEDOWN;
00200         case GIIK_Caps: return CL_KEY_CAPSLOCK;
00201         case GIIK_Num:          return CL_KEY_NUMLOCK;
00202         case GIIK_Scroll:       return CL_KEY_SCRLOCK;
00203         case GIIK_PrintScreen:  return CL_KEY_PRINT;
00204         case GIIK_Pause:        return CL_KEY_PAUSE;
00205         case GIIK_PSlash:       return CL_KEY_KP_DIV;
00206         case GIIK_PAsterisk:    return CL_KEY_KP_MULT;
00207         case GIIK_PMinus:       return CL_KEY_KP_MINUS;
00208         case GIIK_PPlus:        return CL_KEY_KP_PLUS;
00209         case GIIK_PEnter:       return CL_KEY_KP_ENTER;
00210         }
00211         
00212         return CL_KEY_NONE_OF_THE_ABOVE;
00213 }
00214 
00215 char *CL_GGIKeyboard::get_name() const
00216 {
00217         return "GGI keyboard";
00218 }
00219 
00220 int CL_GGIKeyboard::get_num_buttons() const
00221 {
00222         return CL_NUM_KEYS;
00223 }
00224 
00225 CL_InputButton *CL_GGIKeyboard::get_button(int button_num)
00226 {
00227         if (button_num < 0 || button_num >= CL_NUM_KEYS) return NULL;
00228 
00229         if (buttons[button_num] == NULL)
00230                 buttons[button_num] = new CL_InputButton_GGIKeyboard(button_num, keymap);
00231 
00232         return buttons[button_num];
00233 }
00234 
00235 int CL_GGIKeyboard::get_num_axes() const
00236 {
00237         return 0;
00238 }
00239 
00240 CL_InputAxis *CL_GGIKeyboard::get_axis(int /*axis_num*/)
00241 {
00242         return NULL;
00243 }
00244 
00245 int CL_GGIKeyboard::get_num_hats() const
00246 {
00247         return 0;
00248 }
00249 
00250 CL_InputHat *CL_GGIKeyboard::get_hat(int /*hat_num*/)
00251 {
00252         return NULL;
00253 }
00254 
00255 int CL_GGIKeyboard::get_num_cursors() const
00256 {
00257         return 0;
00258 }
00259 
00260 CL_InputCursor *CL_GGIKeyboard::get_cursor(int /*cursor_num*/)
00261 {
00262         return NULL;
00263 }
00264 
00265 /***************************
00266   CL_InputButton_GGIKeyboard
00267 ***************************/
00268 
00269 CL_InputButton_GGIKeyboard::CL_InputButton_GGIKeyboard(
00270         int _key, char *_keymap)
00271 {
00272         key = _key;
00273         keymap = _keymap;
00274 }
00275 
00276 bool CL_InputButton_GGIKeyboard::is_pressed()
00277 {
00278         return keymap[key];
00279 }
00280 
00281 #endif

Generated at Wed Apr 4 19:54:01 2001 for ClanLib by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001