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

mouse_be.cpp

Go to the documentation of this file.
00001 /*
00002         $Id: mouse_be.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 */
00024 #include <ggi/ggi.h>
00025 
00026 #include <Display/Display/GGI/display_ggi.h>
00027 #include <API/Display/Input/inputaxis.h>
00028 #include <API/Display/Input/inputbuffer.h>
00029 #include <API/Display/Input/inputbutton.h>
00030 #include <Display/Input/GGI/mouse_ggi.h>
00031 #include <API/Display/Input/inputcursor.h>
00032 #include <Display/Input/GGI/mouse_ggi.h>
00033 #include <API/Display/Input/inputhat.h>
00034 #include <Display/Input/GGI/mouse_ggi.h>
00035 #include <Core/System/Be/app_beos.h>
00036 
00037 /*************************************
00038   CL_Mouse_GGI
00039 *************************************/
00040 
00041 CL_Mouse_GGI::CL_Mouse_GGI(CL_GGI_DisplayCard *_card)
00042 {
00043         card = _card;
00044         m_vis = card->vis;
00045 
00046         cursor = new CL_InputCursor_Mouse_GGI(card);
00047         buttons.add(new CL_InputButton_Mouse_GGI(),0);
00048         buttons.add(new CL_InputButton_Mouse_GGI(),1);
00049         buttons.add(new CL_InputButton_Mouse_GGI(),2);
00050 
00051         CL_System_Generic::keep_alives.add(this);
00052 }
00053 
00054 CL_Mouse_GGI::~CL_Mouse_GGI()
00055 {
00056         delete cursor;
00057 
00058         int num_buttons = buttons.get_num_items();
00059         for (int i=0; i<num_buttons; i++) delete buttons[i];
00060 
00061         CL_System_Generic::keep_alives.del(this);
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 (buttons[button_num] == NULL)
00073                 buttons.add(new CL_InputButton_Mouse_GGI(),button_num);
00074         return buttons[button_num];
00075 }
00076 
00077 int CL_Mouse_GGI::get_num_axes() const
00078 {
00079         return 0;
00080 }
00081 
00082 CL_InputAxis *CL_Mouse_GGI::get_axis(int /*axis_num*/)
00083 {
00084         return NULL;
00085 }
00086 
00087 int CL_Mouse_GGI::get_num_hats() const
00088 {
00089         return 0;
00090 }
00091 
00092 CL_InputHat *CL_Mouse_GGI::get_hat(int /*hat_num*/)
00093 {
00094         return NULL;
00095 }
00096 
00097 int CL_Mouse_GGI::get_num_buffers() const
00098 {
00099         return 0;
00100 }
00101 
00102 CL_InputBuffer *CL_Mouse_GGI::get_buffer(int /*buffer_num*/)
00103 {
00104         return NULL;
00105 }
00106 
00107 int CL_Mouse_GGI::get_num_cursors() const
00108 {
00109         return 1;
00110 }
00111 
00112 bool CL_Mouse_GGI::keep_alive()
00113 {
00114         ggi_event_mask  mask;
00115         ggi_event               event;
00116         struct timeval  tv = {0,0};
00117 
00118         mask = ggiEventPoll( m_vis, emPointer, &tv );
00119         
00120         while (mask)
00121         {
00122                 ggiEventRead( m_vis, &event, emPointer );
00123         
00124                 switch (event.any.type)
00125                 {
00126                         case evPtrButtonPress:
00127                                 buttons[event.pbutton.button-1]->button_state = true;
00128                                 break;
00129                         case evPtrButtonRelease:
00130                                 buttons[event.pbutton.button-1]->button_state = false;
00131                                 break;
00132                         case evPtrAbsolute:
00133                                 cursor->x = event.pmove.x ;
00134                                 cursor->y = event.pmove.y;
00135                                 if (cursor->x<0) cursor->x = 0;
00136                                 if (cursor->y<0) cursor->y = 0;
00137                                 if (cursor->x>cursor->get_max_x()) cursor->x = cursor->get_max_x();
00138                                 if (cursor->y>cursor->get_max_y()) cursor->y = cursor->get_max_y();
00139                                 break;
00140                         default:
00141                                 break;
00142                 }
00143                 
00144                 mask = ggiEventPoll( m_vis, emPointer, &tv );
00145         }
00146 
00147         return false;
00148 }
00149 
00150 CL_InputCursor *CL_Mouse_GGI::get_cursor(int /*cursor_num*/)
00151 {
00152         return cursor;
00153 }
00154 
00155 /*******************************
00156   CL_InputButton_Mouse_GGI
00157 *******************************/
00158 
00159 CL_InputButton_Mouse_GGI::CL_InputButton_Mouse_GGI()
00160 {
00161         button_state = false;
00162 }
00163 
00164 CL_InputButton_Mouse_GGI::~CL_InputButton_Mouse_GGI()
00165 {
00166 }
00167 
00168 bool CL_InputButton_Mouse_GGI::is_pressed()
00169 {
00170         return button_state;
00171 }
00172 
00173 /*******************************
00174   CL_InputCursor_Mouse_GGI
00175 *******************************/
00176 
00177 CL_InputCursor_Mouse_GGI::CL_InputCursor_Mouse_GGI(
00178         CL_GGI_DisplayCard *_card)
00179 {
00180         card = _card;
00181         x = 0;
00182         y = 0;
00183 }
00184 
00185 CL_InputCursor_Mouse_GGI::~CL_InputCursor_Mouse_GGI()
00186 {
00187 }
00188 
00189 
00190 float CL_InputCursor_Mouse_GGI::get_x()
00191 {
00192         return x;
00193 }
00194 
00195 float CL_InputCursor_Mouse_GGI::get_y()
00196 {
00197         return y;
00198 }
00199 
00200 float CL_InputCursor_Mouse_GGI::get_max_x()
00201 {
00202         return card->get_width();
00203 }
00204 
00205 float CL_InputCursor_Mouse_GGI::get_max_y()
00206 {
00207         return card->get_height();
00208 }
00209 
00210 #endif

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