nux-1.16.0
Events.cpp
00001 /*
00002  * Copyright 2010 Inalogic® Inc.
00003  *
00004  * This program is free software: you can redistribute it and/or modify it
00005  * under the terms of the GNU Lesser General Public License, as
00006  * published by the  Free Software Foundation; either version 2.1 or 3.0
00007  * of the License.
00008  *
00009  * This program is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranties of
00011  * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
00012  * PURPOSE.  See the applicable version of the GNU Lesser General Public
00013  * License for more details.
00014  *
00015  * You should have received a copy of both the GNU Lesser General Public
00016  * License along with this program. If not, see <http://www.gnu.org/licenses/>
00017  *
00018  * Authored by: Jay Taoko <jaytaoko@inalogic.com>
00019  *
00020  */
00021 
00022 #include "GLResource.h"
00023 #include "Events.h"
00024 
00025 
00026 namespace nux
00027 {
00028   MouseButton GetEventButton(unsigned long button_state)
00029   {
00030     if ((button_state & NUX_EVENT_BUTTON1_DOWN) || (button_state & NUX_EVENT_BUTTON1_UP))
00031       return NUX_MOUSE_BUTTON1;
00032     else if ((button_state & NUX_EVENT_BUTTON2_DOWN) || (button_state & NUX_EVENT_BUTTON2_UP))
00033       return NUX_MOUSE_BUTTON2;
00034     else if ((button_state & NUX_EVENT_BUTTON3_DOWN) || (button_state & NUX_EVENT_BUTTON3_UP))
00035       return NUX_MOUSE_BUTTON3;
00036     else if ((button_state & NUX_EVENT_BUTTON4_DOWN) || (button_state & NUX_EVENT_BUTTON4_UP))
00037       return NUX_MOUSE_BUTTON4;
00038 
00039     return NUX_INVALID_MOUSE_BUTTON;
00040   }
00041   
00042   bool GetButtonState(unsigned long button_state, MouseButton button)
00043   {
00044     if (button == NUX_MOUSE_BUTTON1)
00045       return (button_state & NUX_STATE_BUTTON1_DOWN) ? true : false;
00046     else if (button == NUX_MOUSE_BUTTON2)
00047       return (button_state & NUX_STATE_BUTTON2_DOWN) ? true : false;
00048     else if (button == NUX_MOUSE_BUTTON3)
00049       return (button_state & NUX_STATE_BUTTON3_DOWN) ? true : false;
00050     else if (button == NUX_MOUSE_BUTTON4)
00051       return (button_state & NUX_STATE_BUTTON4_DOWN) ? true : false;
00052 
00053     return false;    
00054   }
00055   
00056   bool GetKeyModifierState(unsigned long key_modifiers_states, KeyModifier key_modifier)
00057   {
00058     return ((key_modifiers_states & key_modifier) != 0);
00059   }
00060 
00061   Event::Event()
00062   {
00063     Memset (e_text, 0, sizeof (e_text));
00064 
00065     for (int i = 0; i < NUX_MAX_VK; i++)
00066     {
00067       VirtualKeycodeState[i] = 0;
00068     }
00069 
00070     ascii_code = 0;
00071     virtual_code = 0;
00072     e_key_modifiers = 0;
00073     e_key_repeat_count = 0;
00074     e_mouse_state = 0;
00075     e_x = -1;
00076     e_y = -1;
00077     e_x_root = 0;
00078     e_y_root = 0;
00079     e_dx = 0;
00080     e_dy = 0;
00081     e_clicks = 0;
00082     e_is_click = 0;
00083     e_keysym = 0;
00084     e_wheeldelta = 0;
00085     e_x11_keycode = 0;
00086 #if defined (NUX_OS_LINUX)
00087     e_x11_timestamp = 0;
00088     e_x11_window = 0;
00089     e_x11_state = 0;
00090 #endif
00091 
00092     //Application = 0;
00093   }
00094 
00095   void Event::Reset()
00096   {
00097     e_event = NUX_NO_EVENT;
00098     Memset (e_text, 0, sizeof (e_text));
00099     e_keysym = 0;
00100     e_key_repeat_count = 0;
00101     e_wheeldelta = 0;
00102   }
00103 
00104   int Event::GetX() const
00105   {
00106     return e_x;
00107   }
00108   int Event::GetY() const
00109   {
00110     return e_y;
00111   }
00112   int Event::GetRootX() const
00113   {
00114     return e_x_root;
00115   }
00116   int Event::GetRootY() const
00117   {
00118     return e_y_root;
00119   }
00120   int Event::GetDeltaX() const
00121   {
00122     return e_dx;
00123   }
00124   int Event::GetDeltaY() const
00125   {
00126     return e_dy;
00127   }
00128 
00129   unsigned long Event::GetKeyState()    const
00130   {
00131     return e_key_modifiers;
00132   }
00133 
00134   unsigned long Event::GetMouseState() const
00135   {
00136     return e_mouse_state;
00137   }
00138 
00139   MouseButton Event::GetEventButton() const
00140   {
00141     if ((e_mouse_state & NUX_EVENT_BUTTON1_DOWN) || (e_mouse_state & NUX_EVENT_BUTTON1_UP))
00142       return NUX_MOUSE_BUTTON1;
00143     else if ((e_mouse_state & NUX_EVENT_BUTTON2_DOWN) || (e_mouse_state & NUX_EVENT_BUTTON2_UP))
00144       return NUX_MOUSE_BUTTON2;
00145     else if ((e_mouse_state & NUX_EVENT_BUTTON3_DOWN) || (e_mouse_state & NUX_EVENT_BUTTON3_UP))
00146       return NUX_MOUSE_BUTTON3;
00147     else if ((e_mouse_state & NUX_EVENT_BUTTON4_DOWN) || (e_mouse_state & NUX_EVENT_BUTTON4_UP))
00148       return NUX_MOUSE_BUTTON4;
00149 
00150     return NUX_INVALID_MOUSE_BUTTON;
00151   }
00152 
00153   bool Event::GetButtonState(MouseButton button) const
00154   {
00155     if (button == 1)
00156       return (e_mouse_state & NUX_STATE_BUTTON1_DOWN) ? true : false;
00157     else if (button == 2)
00158       return (e_mouse_state & NUX_STATE_BUTTON2_DOWN) ? true : false;
00159     else if (button == 3)
00160       return (e_mouse_state & NUX_STATE_BUTTON3_DOWN) ? true : false;
00161     else if (button == 4)
00162       return (e_mouse_state & NUX_STATE_BUTTON4_DOWN) ? true : false;
00163 
00164     return false;
00165   }
00166 
00167   bool Event::GetKeyModifierState(KeyModifier key_modifier) const
00168   {
00169     return ((e_key_modifiers & key_modifier) != 0);
00170   }
00171 
00173 
00177   unsigned long Event::GetKeySym() const
00178   {
00179     return e_keysym;
00180   }
00181   unsigned short Event::GetKeyRepeatCount() const
00182   {
00183     return e_key_repeat_count;
00184   }
00185 
00186   const TCHAR* Event::GetText() const
00187   {
00188     return e_text;
00189   }
00190 
00191 
00193 
00198   unsigned long Event::GetVirtualKeyState (unsigned long VirtualKey) const
00199   {
00200     if (VirtualKey >= NUX_MAX_VK)
00201       return 0;
00202 
00203     if (VirtualKey <= 0)
00204       return 0;
00205 
00206     return VirtualKeycodeState[VirtualKey];
00207   }
00208 
00209 
00210 }
00211 
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends