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

mouse_ggi.cpp

Go to the documentation of this file.
00001 /*
00002         $Id: mouse_ggi.cpp,v 1.1 2001/03/06 15:09:21 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 
00024 #include <ggi/ggi.h>
00025 
00026 #include "mouse_ggi.h"
00027 
00028 #include <API/Display/Input/input.h>
00029 #include <API/Display/Input/key.h>
00030 #include <API/Display/Input/inputaxis.h>
00031 #include <API/Display/Input/inputbutton.h>
00032 #include <API/Display/Input/inputcursor.h>
00033 #include <API/Display/Input/inputhat.h>
00034 #include <API/Core/System/cl_assert.h>
00035 #include <Display/Display/GGI/display_ggi.h>
00036 #include <Display/Input/GGI/mouse_ggi.h>
00037 
00038 /*************************************
00039   CL_Mouse_GGI
00040 *************************************/
00041 
00042 CL_Mouse_GGI::CL_Mouse_GGI(CL_GGI_DisplayCard *_card)
00043 {
00044         card = _card;
00045         m_vis = card->vis;
00046 
00047         cursor = new CL_InputCursor_Mouse_GGI(card);
00048         axes = new CL_InputAxis_Mouse_GGI[2];
00049         
00050         buttons = new CL_InputButton_Mouse_GGI*[3];
00051         buttons[0] = new CL_InputButton_Mouse_GGI();
00052         buttons[1] = new CL_InputButton_Mouse_GGI();
00053         buttons[2] = new CL_InputButton_Mouse_GGI();
00054 }
00055 
00056 CL_Mouse_GGI::~CL_Mouse_GGI()
00057 {
00058         delete cursor;
00059 
00060         for (int i=0; i<3; i++) delete buttons[i];
00061         delete[] buttons;
00062 }
00063 
00064 
00065 int CL_Mouse_GGI::get_num_buttons() const
00066 {
00067         return 3;
00068 }
00069 
00070 CL_InputButton *CL_Mouse_GGI::get_button(int button_num)
00071 {
00072         if (button_num >= 3 || button_num < 0) return NULL;
00073         
00074         if (buttons[button_num] == NULL)
00075                 buttons[button_num] = new CL_InputButton_Mouse_GGI();
00076 
00077         return buttons[button_num];
00078 }
00079 
00080 int CL_Mouse_GGI::get_num_axes() const
00081 {
00082         return 2;
00083 }
00084 
00085 CL_InputAxis *CL_Mouse_GGI::get_axis(int axis_num)
00086 {
00087         cl_assert(((unsigned int) axis_num)<2);
00088         return &axes[axis_num];
00089 }
00090 
00091 int CL_Mouse_GGI::get_num_hats() const
00092 {
00093         return 0;
00094 }
00095 
00096 CL_InputHat *CL_Mouse_GGI::get_hat(int /*hat_num*/)
00097 {
00098         return NULL;
00099 }
00100 
00101 int CL_Mouse_GGI::get_num_cursors() const
00102 {
00103         return 1;
00104 }
00105 
00106 void CL_Mouse_GGI::keep_alive()
00107 {
00108         ggi_event_mask  mask;
00109         ggi_event               event;
00110         struct timeval  tv = {0,0};
00111 
00112         mask = ggiEventPoll( m_vis, emPointer, &tv );
00113         
00114         axes[0].center = card->get_width()/2.0;
00115         axes[1].center = card->get_height()/2.0;
00116         
00117         while (mask)
00118         {
00119                 ggiEventRead( m_vis, &event, emPointer );
00120         
00121                 switch (event.any.type)
00122                 {
00123                         case evPtrButtonPress:
00124                                 buttons[event.pbutton.button-1]->button_state = true;
00125                                 CL_Input::sig_button_press(
00126                                         this, 
00127                                         CL_Key(event.pbutton.button-1, CL_Key::Pressed, -1, cursor->x, cursor->y));
00128                                 break;
00129                         case evPtrButtonRelease:
00130                                 buttons[event.pbutton.button-1]->button_state = false;
00131                                 CL_Input::sig_button_release(
00132                                         this, 
00133                                         CL_Key(event.pbutton.button-1, CL_Key::Released, -1, cursor->x, cursor->y));
00134                                 break;
00135                         case evPtrAbsolute:
00136                                 cursor->x = event.pmove.x ;
00137                                 cursor->y = event.pmove.y;
00138                                 if (cursor->x<0) cursor->x = 0;
00139                                 if (cursor->y<0) cursor->y = 0;
00140                                 if (cursor->x>cursor->get_max_x()) cursor->x = cursor->get_max_x();
00141                                 if (cursor->y>cursor->get_max_y()) cursor->y = cursor->get_max_y();
00142                                 axes[0].pos = cursor->x;
00143                                 axes[1].pos = cursor->y;
00144                                 CL_Input::sig_mouse_move(this, cursor->x, cursor->y);
00145                                 break;
00146                         default:
00147                                 break;
00148                 }
00149                 
00150                 mask = ggiEventPoll( m_vis, emPointer, &tv );
00151         }
00152 }
00153 
00154 CL_InputCursor *CL_Mouse_GGI::get_cursor(int /*cursor_num*/)
00155 {
00156         return cursor;
00157 }
00158 
00159 /*******************************
00160   CL_InputButton_Mouse_GGI
00161 *******************************/
00162 
00163 CL_InputButton_Mouse_GGI::CL_InputButton_Mouse_GGI()
00164 {
00165         button_state = false;
00166 }
00167 
00168 CL_InputButton_Mouse_GGI::~CL_InputButton_Mouse_GGI()
00169 {
00170 }
00171 
00172 bool CL_InputButton_Mouse_GGI::is_pressed()
00173 {
00174         return button_state;
00175 }
00176 
00177 /*******************************
00178   CL_InputCursor_Mouse_GGI
00179 *******************************/
00180 
00181 CL_InputCursor_Mouse_GGI::CL_InputCursor_Mouse_GGI(
00182         CL_GGI_DisplayCard *_card)
00183 {
00184         card = _card;
00185         x = 0;
00186         y = 0;
00187 }
00188 
00189 CL_InputCursor_Mouse_GGI::~CL_InputCursor_Mouse_GGI()
00190 {
00191 }
00192 
00193 
00194 float CL_InputCursor_Mouse_GGI::get_x()
00195 {
00196         return x;
00197 }
00198 
00199 float CL_InputCursor_Mouse_GGI::get_y()
00200 {
00201         return y;
00202 }
00203 
00204 float CL_InputCursor_Mouse_GGI::get_max_x()
00205 {
00206         return card->get_width();
00207 }
00208 
00209 float CL_InputCursor_Mouse_GGI::get_max_y()
00210 {
00211         return card->get_height();
00212 }
00213 
00214 /*******************************
00215   CL_InputAxis_Mouse_GGI
00216 *******************************/
00217 
00218 CL_InputAxis_Mouse_GGI::CL_InputAxis_Mouse_GGI()
00219 {
00220         pos = 0;
00221         center = 1;
00222 }
00223 
00224 CL_InputAxis_Mouse_GGI::~CL_InputAxis_Mouse_GGI()
00225 {
00226 }
00227 
00228 
00229 float CL_InputAxis_Mouse_GGI::get_pos()
00230 {
00231         return (pos - center) / center;
00232 }
00233 
00234 #endif

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