1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319
|
/*
$Id: mouse_directfb.cpp,v 1.6 2001/12/22 17:03:33 sphair Exp $
------------------------------------------------------------------------
ClanLib, the platform independent game SDK.
This library is distributed under the GNU LIBRARY GENERAL PUBLIC LICENSE
version 2. See COPYING for details.
For a total list of contributers see CREDITS.
------------------------------------------------------------------------
*/
#include "Core/precomp.h"
#ifdef USE_DIRECTFB
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <iostream>
#include "API/Core/System/cl_assert.h"
#include "mouse_directfb.h"
#include <API/Display/Input/input.h>
#include <API/Display/Input/mouse.h>
#include <API/Display/Input/inputaxis.h>
#include <API/Display/Input/inputbutton.h>
#include <API/Display/Input/inputcursor.h>
#include <API/Display/Input/key.h>
#include <API/Display/Input/inputhat.h>
#include <Display/Input/DirectFB/mouse_directfb.h>
#include <Display/Display/DirectFB/display_directfb.h>
/*************************************
CL_DirectFBMouse
*************************************/
CL_DirectFBMouse::CL_DirectFBMouse (unsigned int id)
{
DFBResult ret;
ret = DirectFBCreate (&dfb);
if (ret)
{
DirectFBError ("CL_DirectFBMouse - DirectFBCreate", ret);
throw new CL_Error ("CL_DirectFBMouse - DirectFBCreate failed");
}
ret = dfb->GetInputDevice (dfb, id, &mouse);
if (ret)
{
DirectFBError ("CL_DirectFBMouse - GetInputDevice", ret);
dfb->Release (dfb);
throw new CL_Error ("CL_DirectFBMouse - GetInputDevice failed");
}
ret = mouse->CreateInputBuffer (mouse, &mousebuffer);
if (ret)
{
DirectFBError ("CL_DirectFBMouse - CreateInputBuffer", ret);
mouse->Release (mouse);
dfb->Release (dfb);
throw new CL_Error ("CL_DirectFBMouse - CreateInputBuffer failed");
}
mouse->GetDescription (mouse, &desc);
cursor = new CL_InputCursor_DirectFBMouse();
axes = new CL_InputAxis_DirectFBMouse*[desc.max_axis+1];
for (int i=0; i<=desc.max_axis; i++)
axes[i] = new CL_InputAxis_DirectFBMouse (mouse, (DFBInputDeviceAxisIdentifier) i);
buttons = new CL_InputButton_DirectFBMouse*[desc.max_button+1];
for (int i=0; i<=desc.max_button; i++)
buttons[i] = new CL_InputButton_DirectFBMouse (mouse, (DFBInputDeviceButtonIdentifier) i);
this->id = id;
}
CL_DirectFBMouse::~CL_DirectFBMouse()
{
delete cursor;
for (int i=0; i<=desc.max_button; i++)
delete buttons[i];
delete[] buttons;
for (int i=0; i<=desc.max_axis; i++)
delete axes[i];
delete[] axes;
}
char *CL_DirectFBMouse::get_name() const
{
if (id == DIDID_MOUSE)
return "DirectFB Primary Mouse";
else
return "DirectFB Additional Mouse";
}
CL_InputDevice::InputDeviceType CL_DirectFBMouse::get_type() const
{
return CL_InputDevice::type_mouse;
}
int CL_DirectFBMouse::get_num_buttons() const
{
return desc.max_button + 1;
}
CL_InputButton *CL_DirectFBMouse::get_button(int button_num)
{
if (button_num < 0 || button_num > desc.max_button)
return NULL;
return buttons[button_num];
}
int CL_DirectFBMouse::get_num_axes() const
{
return desc.max_axis + 1;
}
CL_InputAxis *CL_DirectFBMouse::get_axis(int axis_num)
{
if (axis_num < 0 || axis_num > desc.max_axis)
return NULL;
return axes[axis_num];
}
int CL_DirectFBMouse::get_num_hats() const
{
return 0;
}
CL_InputHat *CL_DirectFBMouse::get_hat(int hat_num)
{
return NULL;
}
int CL_DirectFBMouse::get_num_cursors() const
{
return 1;
}
void CL_DirectFBMouse::keep_alive()
{
DFBInputEvent evt;
while (mousebuffer->GetEvent (mousebuffer, &evt) == DFB_OK)
{
switch (evt.type)
{
case DIET_BUTTONPRESS:
CL_Input::sig_button_press(
this,
CL_Key(
evt.button,
CL_Key::Pressed,
-1,
cursor->get_x(),
cursor->get_y()));
break;
case DIET_BUTTONRELEASE:
CL_Input::sig_button_press(
this,
CL_Key(
evt.button,
CL_Key::Released,
-1,
cursor->get_x(),
cursor->get_y()));
break;
case DIET_AXISMOTION:
CL_Mouse::sig_move((int)cursor->get_x(), (int)cursor->get_y());
CL_Input::sig_mouse_move(this, (int)cursor->get_x(), (int)cursor->get_y());
break;
default:
break;
}
}
}
CL_InputCursor *CL_DirectFBMouse::get_cursor(int cursor_num)
{
return cursor;
}
/*******************************
CL_InputButton_DirectFBMouse
*******************************/
CL_InputButton_DirectFBMouse::CL_InputButton_DirectFBMouse (IDirectFBInputDevice *mouse,
DFBInputDeviceButtonIdentifier button)
{
mouse->AddRef (mouse);
this->mouse = mouse;
this->button = button;
}
CL_InputButton_DirectFBMouse::~CL_InputButton_DirectFBMouse()
{
mouse->Release (mouse);
}
bool CL_InputButton_DirectFBMouse::is_pressed()
{
DFBInputDeviceButtonState state;
mouse->GetButtonState (mouse, button, &state);
return (state == DIBS_DOWN);
}
/*******************************
CL_InputCursor_DirectFBMouse
*******************************/
CL_InputCursor_DirectFBMouse::CL_InputCursor_DirectFBMouse()
{
DFBResult ret;
ret = DirectFBCreate (&dfb);
if (ret)
{
DirectFBError ("CL_InputCursor_DirectFBMouse - DirectFBCreate", ret);
throw new CL_Error ("CL_InputCursor_DirectFBMouse - DirectFBCreate failed");
}
ret = dfb->GetDisplayLayer (dfb, DLID_PRIMARY, &layer);
if (ret)
{
DirectFBError ("CL_InputCursor_DirectFBMouse - GetDisplayLayer", ret);
dfb->Release (dfb);
throw new CL_Error ("CL_InputCursor_DirectFBMouse - GetDisplayLayer failed");
}
}
CL_InputCursor_DirectFBMouse::~CL_InputCursor_DirectFBMouse()
{
layer->Release (layer);
dfb->Release (dfb);
}
float CL_InputCursor_DirectFBMouse::get_x()
{
int x;
layer->GetCursorPosition (layer, &x, NULL);
return x;
}
float CL_InputCursor_DirectFBMouse::get_y()
{
int y;
layer->GetCursorPosition (layer, NULL, &y);
return y;
}
float CL_InputCursor_DirectFBMouse::get_max_x()
{
DFBDisplayLayerConfig dlc;
layer->GetConfiguration (layer, &dlc);
return dlc.width;
}
float CL_InputCursor_DirectFBMouse::get_max_y()
{
DFBDisplayLayerConfig dlc;
layer->GetConfiguration (layer, &dlc);
return dlc.height;
}
/*******************************
CL_InputAxis_DirectFBMouse
*******************************/
CL_InputAxis_DirectFBMouse::CL_InputAxis_DirectFBMouse(IDirectFBInputDevice *mouse,
DFBInputDeviceAxisIdentifier axis)
{
mouse->AddRef (mouse);
this->mouse = mouse;
this->axis = axis;
}
CL_InputAxis_DirectFBMouse::~CL_InputAxis_DirectFBMouse()
{
mouse->Release (mouse);
}
float CL_InputAxis_DirectFBMouse::get_pos()
{
int pos;
mouse->GetAxis (mouse, axis, &pos);
return pos;
}
#endif
|