[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Pingus-CVS] CVS: Games/Pingus/src/input axis.hxx,1.3,1.4 axis_factory.c
From: |
torangan |
Subject: |
[Pingus-CVS] CVS: Games/Pingus/src/input axis.hxx,1.3,1.4 axis_factory.cxx,1.3,1.4 axis_pointer.cxx,1.6,1.7 axis_pointer.hxx,1.5,1.6 axis_scroller.cxx,1.2,1.3 axis_scroller.hxx,1.1,1.2 button.hxx,1.3,1.4 button_axis.cxx,1.4,1.5 button_axis.hxx,1.3,1.4 controller.cxx,1.8,1.9 double_button.cxx,1.1,1.2 double_button.hxx,1.1,1.2 dummy_axis.hxx,1.1,1.2 dummy_button.hxx,1.1,1.2 dummy_pointer.hxx,1.1,1.2 dummy_scroller.hxx,1.1,1.2 inverted_axis.cxx,1.3,1.4 inverted_axis.hxx,1.4,1.5 inverted_scroller.cxx,1.1,1.2 inverted_scroller.hxx,1.1,1.2 joystick_axis.cxx,1.4,1.5 joystick_axis.hxx,1.3,1.4 joystick_button.cxx,1.2,1.3 joystick_button.hxx,1.2,1.3 joystick_scroller.cxx,1.2,1.3 joystick_scroller.hxx,1.1,1.2 key_button.cxx,1.1,1.2 key_button.hxx,1.2,1.3 mouse_axis.cxx,1.2,1.3 mouse_axis.hxx,1.4,1.5 mouse_button.cxx,1.2,1.3 mouse_button.hxx,1.2,1.3 mouse_pointer.cxx,1.2,1.3 mouse_pointer.hxx,1.3,1.4 mouse_scroller.cxx,1.1,1.2 mouse_scroller.hxx,1.1,1.2 multiple_axis.cxx,1.2,1.3 multiple_axis.hxx,1.2,1.3 multiple_button.cxx,1.3,1.4 multiple_button.hxx,1.4,1.5 multiple_pointer.cxx,1.4,1.5 multiple_pointer.hxx,1.3,1.4 multiple_scroller.cxx,1.1,1.2 multiple_scroller.hxx,1.1,1.2 pointer.hxx,1.4,1.5 pointer_scroller.cxx,1.1,1.2 pointer_scroller.hxx,1.1,1.2 scroller.hxx,1.1,1.2 scroller_factory.cxx,1.2,1.3 triple_button.cxx,1.1,1.2 triple_button.hxx,1.1,1.2 |
Date: |
14 Aug 2002 12:41:25 -0000 |
Update of /usr/local/cvsroot/Games/Pingus/src/input
In directory dark:/tmp/cvs-serv31471
Modified Files:
axis.hxx axis_factory.cxx axis_pointer.cxx axis_pointer.hxx
axis_scroller.cxx axis_scroller.hxx button.hxx button_axis.cxx
button_axis.hxx controller.cxx double_button.cxx
double_button.hxx dummy_axis.hxx dummy_button.hxx
dummy_pointer.hxx dummy_scroller.hxx inverted_axis.cxx
inverted_axis.hxx inverted_scroller.cxx inverted_scroller.hxx
joystick_axis.cxx joystick_axis.hxx joystick_button.cxx
joystick_button.hxx joystick_scroller.cxx
joystick_scroller.hxx key_button.cxx key_button.hxx
mouse_axis.cxx mouse_axis.hxx mouse_button.cxx
mouse_button.hxx mouse_pointer.cxx mouse_pointer.hxx
mouse_scroller.cxx mouse_scroller.hxx multiple_axis.cxx
multiple_axis.hxx multiple_button.cxx multiple_button.hxx
multiple_pointer.cxx multiple_pointer.hxx
multiple_scroller.cxx multiple_scroller.hxx pointer.hxx
pointer_scroller.cxx pointer_scroller.hxx scroller.hxx
scroller_factory.cxx triple_button.cxx triple_button.hxx
Log Message:
- some documentation
- some bugfixes
- little performance tuning
- increased usage of const where possible
- moved some code from get_X into update where it belongs
Index: axis.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/input/axis.hxx,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- axis.hxx 10 Jul 2002 14:06:20 -0000 1.3
+++ axis.hxx 14 Aug 2002 12:41:22 -0000 1.4
@@ -22,13 +22,18 @@
namespace Input
{
+ /// abstract base class which defines the axis interface
class Axis {
public:
virtual ~Axis () { }
- virtual float get_pos () =0;
- virtual float get_angle () =0;
+ /// yields the position of the axis in [-1;1]
+ virtual const float& get_pos () const =0;
+
+ /// yields the angle of axis in [0;360[ degree
+ virtual const float& get_angle () const =0;
+
virtual void update(float) =0;
};
}
Index: axis_factory.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/input/axis_factory.cxx,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- axis_factory.cxx 10 Jul 2002 14:06:20 -0000 1.3
+++ axis_factory.cxx 14 Aug 2002 12:41:22 -0000 1.4
@@ -123,13 +123,6 @@
Axis* AxisFactory::multiple_axis (xmlNodePtr cur)
{
- char * angle_str = reinterpret_cast<char *>(xmlGetProp(cur,
reinterpret_cast<const xmlChar*>("angle")));
- if (!angle_str)
- throw PingusError("MultipleAxis without angle parameter");
-
- float angle = strtod(angle_str, reinterpret_cast<char**>(NULL));
- free(angle_str);
-
std::vector<Axis*> axes;
cur = cur->children;
@@ -145,7 +138,10 @@
cur = cur->next;
}
- return new MultipleAxis(angle, axes);
+ if (!axes.size())
+ throw PingusError("MultipleAxis without any axis");
+
+ return new MultipleAxis(axes);
}
}
Index: axis_pointer.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/input/axis_pointer.cxx,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- axis_pointer.cxx 12 Aug 2002 22:52:04 -0000 1.6
+++ axis_pointer.cxx 14 Aug 2002 12:41:22 -0000 1.7
@@ -27,6 +27,7 @@
AxisPointer::AxisPointer (float speed_, const std::vector<Axis*>& axes_) :
speed(speed_), axes(axes_)
{
assert(axes.size() >= 2);
+ assert(axes[0]->get_angle() != axes[1]->get_angle());
}
AxisPointer::~AxisPointer ()
@@ -35,27 +36,27 @@
delete *it;
}
- float
- AxisPointer::get_x_pos ()
+ const float&
+ AxisPointer::get_x_pos () const
{
return x_pos;
}
- float
- AxisPointer::get_y_pos ()
+ const float&
+ AxisPointer::get_y_pos () const
{
return y_pos;
}
void
- AxisPointer::set_pos(float new_x, float new_y)
+ AxisPointer::set_pos (float new_x, float new_y)
{
x_pos = new_x;
y_pos = new_y;
}
void
- AxisPointer::update(float delta)
+ AxisPointer::update (float delta)
{
for (std::vector<Axis*>::const_iterator it = axes.begin(); it !=
axes.end(); it++)
{
Index: axis_pointer.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/input/axis_pointer.hxx,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- axis_pointer.hxx 11 Jul 2002 14:51:10 -0000 1.5
+++ axis_pointer.hxx 14 Aug 2002 12:41:22 -0000 1.6
@@ -28,6 +28,15 @@
class Axis;
+ /**
+ @brief maps two or more axes into a pointer
+
+ XML definition: <axis-pointer> <axis 1><axis 2>[... <axis N>]
</axis-pointer>
+
+ The number of axes used to create the pointer and their respective angles
is
+ unlimited as long as there are at least two axes and the first two axes
must have
+ different angles.
+ */
class AxisPointer : public Pointer {
private:
@@ -43,8 +52,8 @@
AxisPointer (float speed, const std::vector<Axis*>& axes_);
~AxisPointer ();
- virtual float get_x_pos ();
- virtual float get_y_pos ();
+ virtual const float& get_x_pos () const;
+ virtual const float& get_y_pos () const;
virtual void set_pos(float new_x, float new_y);
Index: axis_scroller.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/input/axis_scroller.cxx,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- axis_scroller.cxx 11 Jul 2002 14:51:10 -0000 1.2
+++ axis_scroller.cxx 14 Aug 2002 12:41:22 -0000 1.3
@@ -17,46 +17,62 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#include <math.h>
#include "axis.hxx"
#include "axis_scroller.hxx"
namespace Input {
- AxisScroller::AxisScroller (Axis* axis1_, Axis* axis2_, float speed_) :
axis1(axis1_), axis2(axis2_), speed(speed_)
+ AxisScroller::AxisScroller (const std::vector<Axis*>& axes_, float speed_) :
axes(axes_),
+
speed(speed_),
+
x_delta(0),
+
y_delta(0)
{
+ assert(axes.size() > 1);
+ assert(axes[0]->get_angle() != axes[1]->get_angle());
}
AxisScroller::~AxisScroller ()
{
- delete axis1;
- delete axis2;
+ for (unsigned int i=0; i < axes.size(); i++)
+ delete axes[i];
}
- float
- AxisScroller::get_x_delta ()
+ const float&
+ AxisScroller::get_x_delta () const
{
- return axis1->get_pos() * speed;
+ return x_delta;
}
- float
- AxisScroller::get_y_delta ()
+ const float&
+ AxisScroller::get_y_delta () const
{
- return axis2->get_pos() * speed;
+ return y_delta;
}
void
- AxisScroller::get_delta (float& x, float& y)
+ AxisScroller::get_delta (float& x, float& y) const
{
- x = axis1->get_pos() * speed;
- y = axis2->get_pos() * speed;
+ x = x_delta;
+ y = y_delta;
}
void
AxisScroller::update (float delta)
{
- axis1->update(delta);
- axis2->update(delta);
+ x_delta = 0;
+ y_delta = 0;
+
+ for (std::vector<Axis*>::const_iterator it = axes.begin(); it !=
axes.end(); it++)
+ {
+ (*it)->update(delta);
+
+ x_delta += cos((*it)->get_angle()) * speed * delta;
+ y_delta += sin((*it)->get_angle()) * speed * delta;
+ }
+
}
}
/* EOF */
+
Index: axis_scroller.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/input/axis_scroller.hxx,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- axis_scroller.hxx 11 Jul 2002 12:36:15 -0000 1.1
+++ axis_scroller.hxx 14 Aug 2002 12:41:22 -0000 1.2
@@ -20,26 +20,37 @@
#ifndef HEADER_PINGUS_INPUT_AXIS_SCROLLER_HXX
#define HEADER_PINGUS_INPUT_AXIS_SCROLLER_HXX
+#include <vector>
#include "scroller.hxx"
namespace Input {
class Axis;
+ /**
+ @brief create a Scroller out of two or more axes
+
+ XML definition: <axis-scroller speed="?"> <axis 1>...<axis N>
</axis-scroller>
+
+ This class requires at least two axes whereby it's enforced that the first
+ two have different angles.
+ */
class AxisScroller : public Scroller {
private:
- Axis* axis1;
- Axis* axis2;
- float speed;
+ std::vector<Axis*> axes;
+
+ const float speed;
+ float x_delta;
+ float y_delta;
public:
- AxisScroller (Axis* axis1_, Axis* axis2_, float speed_);
+ AxisScroller (const std::vector<Axis*>& axes_, float speed_);
~AxisScroller ();
- float get_x_delta ();
- float get_y_delta ();
+ const float& get_x_delta () const;
+ const float& get_y_delta () const;
- void get_delta (float& x, float& y);
+ void get_delta (float& x, float& y) const;
void update (float delta);
};
Index: button.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/input/button.hxx,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- button.hxx 8 Jul 2002 14:48:36 -0000 1.3
+++ button.hxx 14 Aug 2002 12:41:22 -0000 1.4
@@ -22,14 +22,16 @@
namespace Input
{
+ /// abstract base class which defines the button interface
class Button
{
public:
virtual ~Button () { }
- virtual bool is_pressed () =0;
- virtual void update (float) =0;
+ /// returns true if the button is pressed, false otherwise
+ virtual bool is_pressed () const =0;
+ virtual void update (float) =0;
};
}
Index: button_axis.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/input/button_axis.cxx,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- button_axis.cxx 11 Jul 2002 14:51:10 -0000 1.4
+++ button_axis.cxx 14 Aug 2002 12:41:22 -0000 1.5
@@ -37,29 +37,32 @@
delete button2;
}
- float
- ButtonAxis::get_pos ()
+ const float&
+ ButtonAxis::get_pos () const
{
- if (button1->is_pressed() == button2->is_pressed())
- return 0;
-
- if (button1->is_pressed())
- return -1.0f;
- else
- return 1.0f;
+ return pos;
}
- float
- ButtonAxis::get_angle ()
+ const float&
+ ButtonAxis::get_angle () const
{
return angle;
}
void
- ButtonAxis::update(float delta)
+ ButtonAxis::update (float delta)
{
button1->update(delta);
button2->update(delta);
+
+ if (button1->is_pressed() == button2->is_pressed())
+ pos = 0.0f;
+
+ if (button1->is_pressed())
+ pos = -1.0f;
+ else
+ pos = 1.0f;
+
}
}
Index: button_axis.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/input/button_axis.hxx,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- button_axis.hxx 11 Jul 2002 14:51:10 -0000 1.3
+++ button_axis.hxx 14 Aug 2002 12:41:22 -0000 1.4
@@ -27,22 +27,28 @@
class Button;
+ /**
+ @brief maps two buttons into an axis
+
+ XML definition: <button-axis angle=?> <some button 1><some button 2>
</button-axis>
+ */
class ButtonAxis : public Axis {
private:
float pos;
float angle;
- Button* button1;
- Button* button2;
+ Button* const button1;
+ Button* const button2;
public:
ButtonAxis (float angle_, Button* button1_, Button* button2_);
~ButtonAxis ();
- virtual float get_pos ();
- virtual float get_angle ();
+ virtual const float& get_pos () const;
+ virtual const float& get_angle () const;
+
virtual void update (float delta);
};
}
Index: controller.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/input/controller.cxx,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- controller.cxx 29 Jul 2002 10:41:17 -0000 1.8
+++ controller.cxx 14 Aug 2002 12:41:22 -0000 1.9
@@ -116,6 +116,9 @@
if (!scroller)
scroller = new DummyScroller;
+
+ if (!action_axis)
+ action_axis = new DummyAxis;
button_states.resize(buttons.size());
for (unsigned int i=0; i < buttons.size(); i++)
@@ -149,7 +152,9 @@
void
Controller::update (float delta)
{
- // FIXME: Memory leak
+ for (std::list<Event*>::iterator it = events.begin(); it != events.end();
it++)
+ delete *it;
+
events.clear ();
scroller ->update(delta);
Index: double_button.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/input/double_button.cxx,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- double_button.cxx 11 Jul 2002 14:51:10 -0000 1.1
+++ double_button.cxx 14 Aug 2002 12:41:22 -0000 1.2
@@ -54,7 +54,7 @@
}
bool
- DoubleButton::is_pressed ()
+ DoubleButton::is_pressed () const
{
return ( ! ignore_second && first_pressed && button2->is_pressed());
}
Index: double_button.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/input/double_button.hxx,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- double_button.hxx 11 Jul 2002 14:51:10 -0000 1.1
+++ double_button.hxx 14 Aug 2002 12:41:22 -0000 1.2
@@ -24,20 +24,29 @@
namespace Input {
+ /**
+ @brief allows two buttons to be used in combination
+
+ XML definition: <double-button><button1><button2></double-button>
+
+ This class allows combinations like CTRL-X whereby it's important that the
first
+ key is pressed before the second else the DoubleButton itself won't change
it's
+ own state to pressed.
+ */
class DoubleButton : public Button {
private:
- Button* button1;
- Button* button2;
- bool first_pressed;
- bool ignore_second;
+ Button* const button1;
+ Button* const button2;
+ bool first_pressed;
+ bool ignore_second;
public:
DoubleButton (Button* button1_, Button* button2_);
~DoubleButton ();
- virtual bool is_pressed ();
+ virtual bool is_pressed () const;
virtual void update (float delta);
};
}
Index: dummy_axis.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/input/dummy_axis.hxx,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- dummy_axis.hxx 10 Jul 2002 14:06:06 -0000 1.1
+++ dummy_axis.hxx 14 Aug 2002 12:41:22 -0000 1.2
@@ -24,12 +24,24 @@
namespace Input
{
+ /**
+ @brief Dummy Axis to be used if an axis is required but none defined
+
+ XML definition: none
+ */
class DummyAxis : public Axis {
+ private:
+ float pos;
+ float angle;
+
public:
- virtual float get_pos () { return 0; }
- virtual float get_angle () { return 0; }
+ DummyAxis () : pos(0.0f), angle(0.0f) { }
+
+ virtual const float& get_pos () const { return pos; }
+ virtual const float& get_angle () const { return angle; }
+
virtual void update(float) { }
};
}
Index: dummy_button.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/input/dummy_button.hxx,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- dummy_button.hxx 10 Jul 2002 14:06:06 -0000 1.1
+++ dummy_button.hxx 14 Aug 2002 12:41:22 -0000 1.2
@@ -24,10 +24,15 @@
namespace Input
{
+ /**
+ @brief dummy class to be used if a button is required but not defined
+
+ XML definition: none
+ */
class DummyButton : public Button {
public:
- virtual bool is_pressed () { return false; }
+ virtual bool is_pressed () const { return false; }
virtual void update (float) { }
};
}
Index: dummy_pointer.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/input/dummy_pointer.hxx,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- dummy_pointer.hxx 10 Jul 2002 14:06:06 -0000 1.1
+++ dummy_pointer.hxx 14 Aug 2002 12:41:22 -0000 1.2
@@ -24,12 +24,23 @@
namespace Input
{
+ /**
+ @brief dummy class to be used if a pointer is required but none defined
+
+ XML definition: none
+ */
class DummyPointer : public Pointer {
+ private:
+ const float pos;
+
public:
- virtual float get_x_pos () { return 0; }
- virtual float get_y_pos () { return 0; }
+ DummyPointer () : pos(0) { }
+
+ virtual const float& get_x_pos () const { return pos; }
+ virtual const float& get_y_pos () const { return pos; }
+
virtual void set_pos (float, float) { }
virtual void update (float) { }
};
Index: dummy_scroller.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/input/dummy_scroller.hxx,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- dummy_scroller.hxx 12 Jul 2002 15:08:01 -0000 1.1
+++ dummy_scroller.hxx 14 Aug 2002 12:41:22 -0000 1.2
@@ -24,13 +24,23 @@
namespace Input {
+ /**
+ @brief dummy class to be used if an Scroller is required but none defined
+
+ XML definition: none
+ */
class DummyScroller : public Scroller {
+ private:
+ const float delta;
+
public:
- float get_x_delta () { return 0; }
- float get_y_delta () { return 0; }
+ DummyScroller () : delta(0) { }
- void get_delta (float&, float&) { }
+ const float& get_x_delta () const { return delta; }
+ const float& get_y_delta () const { return delta; }
+
+ void get_delta (float& x_delta, float& y_delta) const { x_delta =
delta; y_delta = delta; }
void update (float) { }
};
Index: inverted_axis.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/input/inverted_axis.cxx,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- inverted_axis.cxx 11 Jul 2002 14:51:10 -0000 1.3
+++ inverted_axis.cxx 14 Aug 2002 12:41:22 -0000 1.4
@@ -31,20 +31,20 @@
delete axis;
}
- float
- InvertedAxis::get_pos ()
+ const float&
+ InvertedAxis::get_pos () const
{
return axis->get_pos();
}
- float
- InvertedAxis::get_angle ()
+ const float&
+ InvertedAxis::get_angle () const
{
return angle;
}
void
- InvertedAxis::update(float delta)
+ InvertedAxis::update (float delta)
{
axis->update(delta);
}
Index: inverted_axis.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/input/inverted_axis.hxx,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- inverted_axis.hxx 11 Jul 2002 14:51:10 -0000 1.4
+++ inverted_axis.hxx 14 Aug 2002 12:41:22 -0000 1.5
@@ -24,18 +24,24 @@
namespace Input
{
+ /**
+ @brief decorator class inverting the angle of an axis
+
+ XML definition: <inverted-axis> <axis> </inverted-axis>
+ */
class InvertedAxis : public Axis {
private:
- Axis* axis;
- float angle;
+ Axis* const axis;
+ float angle;
public:
InvertedAxis (Axis* axis_);
~InvertedAxis ();
- virtual float get_pos ();
- virtual float get_angle ();
+ virtual const float& get_pos () const;
+ virtual const float& get_angle () const;
+
virtual void update (float delta);
};
}
Index: inverted_scroller.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/input/inverted_scroller.cxx,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- inverted_scroller.cxx 12 Jul 2002 12:36:14 -0000 1.1
+++ inverted_scroller.cxx 14 Aug 2002 12:41:22 -0000 1.2
@@ -21,7 +21,9 @@
namespace Input {
- InvertedScroller::InvertedScroller (Scroller* scroller_, bool invert_x_,
bool invert_y_) : scroller(scroller_), invert_x(invert_x_), invert_y(invert_y_)
+ InvertedScroller::InvertedScroller (Scroller* scroller_, bool invert_x_,
bool invert_y_) : scroller(scroller_),
+
invert_x(invert_x_),
+
invert_y(invert_y_)
{
}
@@ -30,20 +32,20 @@
delete scroller;
}
- float
- InvertedScroller::get_x_delta ()
+ const float&
+ InvertedScroller::get_x_delta () const
{
return x_pos;
}
- float
- InvertedScroller::get_y_delta ()
+ const float&
+ InvertedScroller::get_y_delta () const
{
return y_pos;
}
void
- InvertedScroller::get_delta (float& x, float& y)
+ InvertedScroller::get_delta (float& x, float& y) const
{
x = x_pos;
y = y_pos;
Index: inverted_scroller.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/input/inverted_scroller.hxx,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- inverted_scroller.hxx 12 Jul 2002 12:36:14 -0000 1.1
+++ inverted_scroller.hxx 14 Aug 2002 12:41:22 -0000 1.2
@@ -24,22 +24,31 @@
namespace Input {
+ /**
+ @brief inverts the results of the contained scroller
+
+ XML definition: <inverted-scroller invert-x="0/1" invert-y="0/1"
speed="?"> <scroller> </inverted-scroller>
+
+ Wheter the X and/or the Y axis shall be inverted must be specified
explizitly.
+ */
class InvertedScroller : public Scroller {
private:
- Scroller* scroller;
- bool invert_x;
- bool invert_y;
- float x_pos;
- float y_pos;
+ Scroller* const scroller;
+
+ const bool invert_x;
+ const bool invert_y;
+
+ float x_pos;
+ float y_pos;
public:
InvertedScroller (Scroller* scroller_, bool invert_x_, bool invert_y_);
~InvertedScroller ();
- float get_x_delta ();
- float get_y_delta ();
+ const float& get_x_delta () const;
+ const float& get_y_delta () const;
- void get_delta (float& x, float& y);
+ void get_delta (float& x, float& y) const;
void update (float delta);
};
Index: joystick_axis.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/input/joystick_axis.cxx,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- joystick_axis.cxx 11 Jul 2002 15:24:35 -0000 1.4
+++ joystick_axis.cxx 14 Aug 2002 12:41:22 -0000 1.5
@@ -39,21 +39,22 @@
angle = static_cast<int>(angle) % 360;
}
- float
- JoystickAxis::get_pos ()
+ const float&
+ JoystickAxis::get_pos () const
{
- return CL_Input::joysticks[id]->get_axis(axis)->get_pos();
+ return pos;
}
- float
- JoystickAxis::get_angle ()
+ const float&
+ JoystickAxis::get_angle () const
{
return angle;
}
void
- JoystickAxis::update(float)
+ JoystickAxis::update (float)
{
+ pos = CL_Input::joysticks[id]->get_axis(axis)->get_pos();
}
}
Index: joystick_axis.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/input/joystick_axis.hxx,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- joystick_axis.hxx 9 Jul 2002 17:00:10 -0000 1.3
+++ joystick_axis.hxx 14 Aug 2002 12:41:22 -0000 1.4
@@ -24,19 +24,26 @@
namespace Input
{
+ /**
+ @brief represents an axis of a joystick
+
+ XML definition: <joystick-axis angle="?" id="joystick id" axis="axis of
the joystick"/>
+ */
class JoystickAxis : public Axis {
private:
int id;
int axis;
+ float pos;
float angle;
public:
JoystickAxis(int id_, int axis_, float angle_);
- virtual float get_pos ();
- virtual float get_angle ();
+ virtual const float& get_pos () const;
+ virtual const float& get_angle () const;
+
virtual void update (float);
};
}
Index: joystick_button.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/input/joystick_button.cxx,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- joystick_button.cxx 11 Jul 2002 15:24:35 -0000 1.2
+++ joystick_button.cxx 14 Aug 2002 12:41:22 -0000 1.3
@@ -40,7 +40,7 @@
}
bool
- JoystickButton::is_pressed()
+ JoystickButton::is_pressed() const
{
return CL_Input::joysticks[id]->get_button(button)->is_pressed();
}
Index: joystick_button.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/input/joystick_button.hxx,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- joystick_button.hxx 9 Jul 2002 17:00:10 -0000 1.2
+++ joystick_button.hxx 14 Aug 2002 12:41:22 -0000 1.3
@@ -24,6 +24,11 @@
namespace Input {
+ /**
+ @brief represents a button of a joystick
+
+ XML definition: <joystick-button id="joystick id" button="button num"/>
+ */
class JoystickButton : public Button {
private:
@@ -34,7 +39,7 @@
JoystickButton(int id_, int button_);
- virtual bool is_pressed ();
+ virtual bool is_pressed () const;
virtual void update (float);
};
}
Index: joystick_scroller.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/input/joystick_scroller.cxx,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- joystick_scroller.cxx 12 Jul 2002 12:36:14 -0000 1.2
+++ joystick_scroller.cxx 14 Aug 2002 12:41:22 -0000 1.3
@@ -22,10 +22,13 @@
namespace Input {
- JoystickScroller::JoystickScroller (int id_, float speed_) : id(id_),
speed(speed_)
+ JoystickScroller::JoystickScroller (int id_, float speed_) : id(id_),
+ axis1(new
JoystickAxis(id, 0, 0)),
+ axis2(new
JoystickAxis(id, 1, 90)),
+ speed(speed_),
+ x_delta(0),
+ y_delta(0)
{
- axis1 = new JoystickAxis(id, 0, 0);
- axis2 = new JoystickAxis(id, 1, 90);
}
JoystickScroller::~JoystickScroller ()
@@ -34,23 +37,23 @@
delete axis2;
}
- float
- JoystickScroller::get_x_delta ()
+ const float&
+ JoystickScroller::get_x_delta () const
{
- return axis1->get_pos() * speed;
+ return x_delta;
}
- float
- JoystickScroller::get_y_delta ()
+ const float&
+ JoystickScroller::get_y_delta () const
{
- return axis2->get_pos() * speed;
+ return y_delta;
}
void
- JoystickScroller::get_delta (float& x, float& y)
+ JoystickScroller::get_delta (float& x, float& y) const
{
- x = axis1->get_pos() * speed;
- y = axis2->get_pos() * speed;
+ x = x_delta;
+ y = y_delta;
}
void
@@ -58,6 +61,9 @@
{
axis1->update(delta);
axis2->update(delta);
+
+ x_delta = axis1->get_pos() * speed;
+ y_delta = axis2->get_pos() * speed;
}
}
Index: joystick_scroller.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/input/joystick_scroller.hxx,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- joystick_scroller.hxx 11 Jul 2002 14:51:10 -0000 1.1
+++ joystick_scroller.hxx 14 Aug 2002 12:41:22 -0000 1.2
@@ -26,21 +26,31 @@
class Axis;
+ /**
+ @brief maps the first two axes of a joystick into a Scroller
+
+ XML definition: <joystick-scroller id="joystick id" speed="?"/>
+ */
class JoystickScroller : public Scroller {
private:
- int id;
- Axis* axis1;
- Axis* axis2;
- float speed;
+ int id;
+
+ Axis* const axis1;
+ Axis* const axis2;
+
+ const float speed;
+
+ float x_delta;
+ float y_delta;
public:
JoystickScroller (int id_, float speed_);
~JoystickScroller ();
- float get_x_delta ();
- float get_y_delta ();
+ const float& get_x_delta () const;
+ const float& get_y_delta () const;
- void get_delta (float& x, float& y);
+ void get_delta (float& x, float& y) const;
void update (float delta);
};
Index: key_button.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/input/key_button.cxx,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- key_button.cxx 4 Jul 2002 11:32:18 -0000 1.1
+++ key_button.cxx 14 Aug 2002 12:41:22 -0000 1.2
@@ -22,15 +22,15 @@
namespace Input {
- KeyButton::KeyButton(int button_) : button(button_) { }
+ KeyButton::KeyButton (int button_) : button(button_) { }
void
- KeyButton::update(float)
+ KeyButton::update (float)
{
}
bool
- KeyButton::is_pressed()
+ KeyButton::is_pressed () const
{
return CL_Keyboard::get_keycode(button);
}
Index: key_button.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/input/key_button.hxx,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- key_button.hxx 9 Jul 2002 17:00:10 -0000 1.2
+++ key_button.hxx 14 Aug 2002 12:41:22 -0000 1.3
@@ -24,6 +24,11 @@
namespace Input {
+ /**
+ @brief maps a keyboard key to a button
+
+ XML definition: <key-button button="key name"/>
+ */
class KeyButton : public Button {
private:
@@ -33,7 +38,7 @@
KeyButton(int button_);
- virtual bool is_pressed ();
+ virtual bool is_pressed () const;
virtual void update (float);
};
}
Index: mouse_axis.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/input/mouse_axis.cxx,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- mouse_axis.cxx 11 Jul 2002 11:23:44 -0000 1.2
+++ mouse_axis.cxx 14 Aug 2002 12:41:22 -0000 1.3
@@ -41,20 +41,20 @@
}
}
- float
- MouseAxis::get_pos ()
+ const float&
+ MouseAxis::get_pos () const
{
return pos;
}
- float
- MouseAxis::get_angle ()
+ const float&
+ MouseAxis::get_angle () const
{
return angle;
}
void
- MouseAxis::update(float)
+ MouseAxis::update (float)
{
switch (axis)
{
Index: mouse_axis.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/input/mouse_axis.hxx,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- mouse_axis.hxx 11 Jul 2002 14:51:10 -0000 1.4
+++ mouse_axis.hxx 14 Aug 2002 12:41:22 -0000 1.5
@@ -24,6 +24,11 @@
namespace Input {
+ /**
+ @brief represents an axis of the mouse
+
+ XML definition: <mouse-axis angle="?" axis="0/1"/>
+ */
class MouseAxis : public Axis {
private:
@@ -35,8 +40,9 @@
public:
MouseAxis(int axis_, float angle_);
- virtual float get_pos ();
- virtual float get_angle ();
+ virtual const float& get_pos () const;
+ virtual const float& get_angle () const;
+
virtual void update (float);
};
}
Index: mouse_button.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/input/mouse_button.cxx,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- mouse_button.cxx 11 Jul 2002 15:24:35 -0000 1.2
+++ mouse_button.cxx 14 Aug 2002 12:41:22 -0000 1.3
@@ -25,19 +25,19 @@
namespace Input {
- MouseButton::MouseButton(int button_) : button(button_)
+ MouseButton::MouseButton (int button_) : button(button_)
{
if (button > CL_Input::pointers[0]->get_num_buttons())
throw PingusError("MouseButton: Invalid button id");
}
void
- MouseButton::update(float)
+ MouseButton::update (float)
{
}
bool
- MouseButton::is_pressed()
+ MouseButton::is_pressed () const
{
return CL_Input::pointers[0]->get_button(button)->is_pressed();
}
Index: mouse_button.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/input/mouse_button.hxx,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- mouse_button.hxx 9 Jul 2002 17:00:10 -0000 1.2
+++ mouse_button.hxx 14 Aug 2002 12:41:22 -0000 1.3
@@ -24,6 +24,11 @@
namespace Input {
+ /**
+ @brief represents a mouse button
+
+ XML definition: <mouse-button button="button num"/>
+ */
class MouseButton : public Button {
private:
@@ -31,9 +36,9 @@
public:
- MouseButton(int button_);
+ MouseButton (int button_);
- virtual bool is_pressed ();
+ virtual bool is_pressed () const;
virtual void update (float);
};
}
Index: mouse_pointer.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/input/mouse_pointer.cxx,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- mouse_pointer.cxx 5 Jul 2002 11:02:47 -0000 1.2
+++ mouse_pointer.cxx 14 Aug 2002 12:41:22 -0000 1.3
@@ -17,7 +17,6 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-//#include <ClanLib/Core/Math/cl_vector.h>
#include <ClanLib/Display/Input/input.h>
#include <ClanLib/Display/Input/inputdevice.h>
#include <ClanLib/Display/Input/inputcursor.h>
@@ -26,18 +25,16 @@
namespace Input
{
- //MousePointer::MousePointer(float x_angle_, float y_angle_) :
x_angle(x_angle_), y_angle(y_angle_) { }
-
- float
- MousePointer::get_x_pos ()
+ const float&
+ MousePointer::get_x_pos () const
{
- return CL_Input::pointers[0]->get_cursor(0)->get_x();
+ return x_pos;
}
- float
- MousePointer::get_y_pos ()
+ const float&
+ MousePointer::get_y_pos () const
{
- return CL_Input::pointers[0]->get_cursor(0)->get_y();
+ return y_pos;
}
void
@@ -47,36 +44,10 @@
}
void
- MousePointer::update(float /*delta*/)
+ MousePointer::update (float)
{
-/*
- CL_Vector pos_delta;
- float x_delta(0), y_delta(0);
-
- // Axis 1
- pos_delta.x = CL_Input::pointers[0]->get_axis(0)->get_pos();
- pos_delta.y = 0;
- pos_delta.z = 0;
-
- pos_delta.rotate(x_angle, CL_Vector(0, 0, 1));
-
- x_delta += pos_delta.x;
- y_delta += pos_delta.y;
-
- // Axis 2
- pos_delta.x = CL_Input::pointers[0]->get_axis(1)->get_pos();
- pos_delta.y = 0;
- pos_delta.z = 0;
-
- pos_delta.rotate(y_angle, CL_Vector(0, 0, 1));
-
- x_delta += pos_delta.x;
- y_delta += pos_delta.y;
-
-
- x_pos += x_delta * delta;
- y_pos += y_delta * delta;
-*/
+ x_pos = CL_Input::pointers[0]->get_cursor(0)->get_x();
+ y_pos = CL_Input::pointers[0]->get_cursor(0)->get_y();
}
}
Index: mouse_pointer.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/input/mouse_pointer.hxx,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- mouse_pointer.hxx 9 Jul 2002 17:00:10 -0000 1.3
+++ mouse_pointer.hxx 14 Aug 2002 12:41:22 -0000 1.4
@@ -24,18 +24,21 @@
namespace Input
{
+ /**
+ @brief maps the standard mouse into a pointer
+
+ XML definition: <mouse-pointer/>
+ */
class MousePointer : public Pointer {
-
+
private:
- //float x_angle;
- //float y_angle;
+ float x_pos;
+ float y_pos;
public:
- //MousePointer(float x_angle_, float y_angle_);
-
- virtual float get_x_pos ();
- virtual float get_y_pos ();
+ virtual const float& get_x_pos () const;
+ virtual const float& get_y_pos () const;
virtual void set_pos (float new_x, float new_y);
Index: mouse_scroller.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/input/mouse_scroller.cxx,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- mouse_scroller.cxx 11 Jul 2002 14:51:10 -0000 1.1
+++ mouse_scroller.cxx 14 Aug 2002 12:41:22 -0000 1.2
@@ -24,28 +24,31 @@
namespace Input {
- float
- MouseScroller::get_x_delta ()
+ const float&
+ MouseScroller::get_x_delta () const
{
- return CL_Input::pointers[0]->get_cursor(0)->get_x() - old_x;
+ return x_delta;
}
- float
- MouseScroller::get_y_delta ()
+ const float&
+ MouseScroller::get_y_delta () const
{
- return CL_Input::pointers[0]->get_cursor(0)->get_x() - old_y;
+ return y_delta;
}
void
- MouseScroller::get_delta (float& x, float& y)
+ MouseScroller::get_delta (float& x, float& y) const
{
- x = CL_Input::pointers[0]->get_cursor(0)->get_x() - old_x;
- y = CL_Input::pointers[0]->get_cursor(0)->get_y() - old_y;
+ x = x_delta;
+ y = y_delta;
}
void
MouseScroller::update (float)
{
+ x_delta = CL_Input::pointers[0]->get_cursor(0)->get_x() - old_x;
+ y_delta = CL_Input::pointers[0]->get_cursor(0)->get_x() - old_y;
+
old_x = CL_Input::pointers[0]->get_cursor(0)->get_x();
old_y = CL_Input::pointers[0]->get_cursor(0)->get_y();
}
Index: mouse_scroller.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/input/mouse_scroller.hxx,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- mouse_scroller.hxx 11 Jul 2002 14:51:10 -0000 1.1
+++ mouse_scroller.hxx 14 Aug 2002 12:41:22 -0000 1.2
@@ -24,16 +24,23 @@
namespace Input {
+ /**
+ @brief turns the mouse into a scroller
+
+ XML definition: <mouse-scroller/>
+ */
class MouseScroller : public Scroller {
private:
float old_x;
float old_y;
+ float x_delta;
+ float y_delta;
public:
- float get_x_delta ();
- float get_y_delta ();
+ const float& get_x_delta () const;
+ const float& get_y_delta () const;
- void get_delta (float& x, float& y);
+ void get_delta (float& x, float& y) const;
void update (float);
};
Index: multiple_axis.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/input/multiple_axis.cxx,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- multiple_axis.cxx 11 Jul 2002 14:51:10 -0000 1.2
+++ multiple_axis.cxx 14 Aug 2002 12:41:22 -0000 1.3
@@ -21,13 +21,9 @@
namespace Input
{
- MultipleAxis::MultipleAxis (float angle_, const std::vector<Axis*>& axes_) :
- angle(angle_), axes(axes_)
+ MultipleAxis::MultipleAxis (const std::vector<Axis*>& axes_) : axes(axes_),
+ pos(0),
angle(0)
{
- if (angle < 0)
- angle = (static_cast<int>(angle) % 360) + 360;
- else if (angle > 360)
- angle = static_cast<int>(angle) % 360;
}
MultipleAxis::~MultipleAxis ()
@@ -36,30 +32,32 @@
delete *it;
}
- float
- MultipleAxis::get_pos ()
+ const float&
+ MultipleAxis::get_pos () const
{
- for (std::vector<Axis*>::const_iterator it = axes.begin(); it !=
axes.end(); it++)
- {
- const float & temp = (*it)->get_pos();
- if (temp)
- return temp;
- }
-
- return 0;
+ return pos;
}
- float
- MultipleAxis::get_angle ()
+ const float&
+ MultipleAxis::get_angle () const
{
return angle;
}
void
- MultipleAxis::update(float delta)
+ MultipleAxis::update (float delta)
{
for (std::vector<Axis*>::const_iterator it = axes.begin(); it !=
axes.end(); it++)
- (*it)->update(delta);
+ {
+ (*it)->update(delta);
+ const float & temp = (*it)->get_pos();
+ if (temp)
+ {
+ pos = temp;
+ angle = (*it)->get_angle();
+ }
+
+ }
}
}
Index: multiple_axis.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/input/multiple_axis.hxx,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- multiple_axis.hxx 11 Jul 2002 14:51:10 -0000 1.2
+++ multiple_axis.hxx 14 Aug 2002 12:41:22 -0000 1.3
@@ -25,19 +25,29 @@
namespace Input {
+ /**
+ @brief wrapper class, mapping multiple axes to one
+
+ XML definition: <multiple-axis> <axis 1>...<axis n></multiple-axis>
+ <br><br>
+ angle and pos returned by this class will be the values returned by the
first class
+ yielding a pos that is not null or of the first axis if none is found
+ */
class MultipleAxis : public Axis {
private:
- float angle;
std::vector<Axis*> axes;
+ float pos;
+ float angle;
public:
- MultipleAxis (float angle_, const std::vector<Axis*>& axes_);
+ MultipleAxis (const std::vector<Axis*>& axes_);
~MultipleAxis ();
- virtual float get_pos ();
- virtual float get_angle ();
+ virtual const float& get_pos () const;
+ virtual const float& get_angle () const;
+
virtual void update (float delta);
};
}
Index: multiple_button.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/input/multiple_button.cxx,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- multiple_button.cxx 11 Jul 2002 14:51:10 -0000 1.3
+++ multiple_button.cxx 14 Aug 2002 12:41:22 -0000 1.4
@@ -39,9 +39,9 @@
}
bool
- MultipleButton::is_pressed ()
+ MultipleButton::is_pressed () const
{
- for (std::vector<Button*>::iterator it = buttons.begin(); it !=
buttons.end(); it++)
+ for (std::vector<Button*>::const_iterator it = buttons.begin(); it !=
buttons.end(); it++)
if ((*it)->is_pressed())
return true;
Index: multiple_button.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/input/multiple_button.hxx,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- multiple_button.hxx 11 Jul 2002 14:51:10 -0000 1.4
+++ multiple_button.hxx 14 Aug 2002 12:41:22 -0000 1.5
@@ -25,6 +25,13 @@
namespace Input {
+ /**
+ @brief wrapper class mapping multiple buttons into one
+
+ XML definition: <multiple-button> <button 1>...<button n>
</multiple-button>
+
+ A multiple button is pressed whenever at least one of the buttons
contained is pressed.
+ */
class MultipleButton : public Button {
private:
@@ -35,7 +42,7 @@
MultipleButton (const std::vector<Button*>& buttons_);
~MultipleButton ();
- virtual bool is_pressed ();
+ virtual bool is_pressed () const;
virtual void update (float delta);
};
}
Index: multiple_pointer.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/input/multiple_pointer.cxx,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- multiple_pointer.cxx 12 Aug 2002 22:52:04 -0000 1.4
+++ multiple_pointer.cxx 14 Aug 2002 12:41:22 -0000 1.5
@@ -21,8 +21,11 @@
namespace Input
{
- MultiplePointer::MultiplePointer (const std::vector<Pointer*>& pointers_) :
- pointers(pointers_),
x_pos_list(pointers.size()), y_pos_list(pointers.size())
+ MultiplePointer::MultiplePointer (const std::vector<Pointer*>& pointers_) :
pointers(pointers_),
+
old_x_pos(0),
+
old_y_pos(0),
+
x_pos(0),
+
y_pos(0)
{
}
@@ -32,14 +35,14 @@
delete pointers[i];
}
- float
- MultiplePointer::get_x_pos ()
+ const float&
+ MultiplePointer::get_x_pos () const
{
return x_pos;
}
- float
- MultiplePointer::get_y_pos ()
+ const float&
+ MultiplePointer::get_y_pos () const
{
return y_pos;
}
@@ -54,36 +57,38 @@
void
MultiplePointer::update (float delta)
{
- bool do_break = false;
+ unsigned int do_break = UINT_MAX;
for (unsigned int i = 0; i < pointers.size(); i++)
- {
- pointers[i]->update(delta);
+ pointers[i]->update(delta);
- if (pointers[i]->get_x_pos() != x_pos_list[i])
+ for (unsigned int i = 0; i < pointers.size(); i++)
+ {
+ if (pointers[i]->get_x_pos() != old_x_pos)
{
- x_pos_list[i] = pointers[i]->get_x_pos();
- x_pos = x_pos_list[i];
- do_break = true;
+ old_x_pos = x_pos;
+ x_pos = pointers[i]->get_x_pos();
+ do_break = i;
}
- if (pointers[i]->get_y_pos() != y_pos_list[i])
+ if (pointers[i]->get_y_pos() != old_y_pos)
{
- y_pos_list[i] = pointers[i]->get_y_pos();
- y_pos = y_pos_list[i];
- do_break = true;
+ old_y_pos = y_pos;
+ y_pos = pointers[i]->get_y_pos();
+ do_break = i;
}
- if (do_break)
+ if (do_break != UINT_MAX)
break;
}
- // no pointer changed, so there's no need to update the pointers
- if ( ! do_break)
+ // no pointer changed, so there's no need to update the other pointers
+ if (do_break == UINT_MAX)
return;
for (unsigned int n = 0; n < pointers.size(); n++)
- pointers[n]->set_pos(x_pos, y_pos);
+ if (n != do_break)
+ pointers[n]->set_pos(x_pos, y_pos);
}
}
Index: multiple_pointer.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/input/multiple_pointer.hxx,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- multiple_pointer.hxx 11 Jul 2002 14:51:10 -0000 1.3
+++ multiple_pointer.hxx 14 Aug 2002 12:41:22 -0000 1.4
@@ -25,12 +25,22 @@
namespace Input
{
+ /**
+ @brief wrapper class allowing multiple pointers to be used as one
+
+ XML definition: <multiple-pointer> <pointer 1>...<pointer N>
</multiple-pointer>
+
+ This class will check every contained pointer for changes and if any
changes all
+ pointers are updated to the new coordinates. If more than one pointer
changes at
+ the same time only the change of the first will be registered.
+ */
class MultiplePointer : public Pointer {
private:
std::vector<Pointer*> pointers;
- std::vector<float> x_pos_list;
- std::vector<float> y_pos_list;
+
+ float old_x_pos;
+ float old_y_pos;
float x_pos;
float y_pos;
@@ -40,12 +50,12 @@
MultiplePointer (const std::vector<Pointer*>& pointers_);
~MultiplePointer ();
- virtual float get_x_pos ();
- virtual float get_y_pos ();
+ virtual const float& get_x_pos () const;
+ virtual const float& get_y_pos () const;
- virtual void set_pos (float x_pos, float y_pos);
+ virtual void set_pos (float x_pos, float y_pos);
- virtual void update (float delta);
+ virtual void update (float delta);
};
}
Index: multiple_scroller.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/input/multiple_scroller.cxx,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- multiple_scroller.cxx 12 Jul 2002 12:36:14 -0000 1.1
+++ multiple_scroller.cxx 14 Aug 2002 12:41:22 -0000 1.2
@@ -29,20 +29,20 @@
delete *it;
}
- float
- MultipleScroller::get_x_delta ()
+ const float&
+ MultipleScroller::get_x_delta () const
{
return x_pos;
}
- float
- MultipleScroller::get_y_delta ()
+ const float&
+ MultipleScroller::get_y_delta () const
{
return y_pos;
}
void
- MultipleScroller::get_delta (float& x, float& y)
+ MultipleScroller::get_delta (float& x, float& y) const
{
x = x_pos;
y = y_pos;
Index: multiple_scroller.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/input/multiple_scroller.hxx,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- multiple_scroller.hxx 12 Jul 2002 12:36:14 -0000 1.1
+++ multiple_scroller.hxx 14 Aug 2002 12:41:22 -0000 1.2
@@ -25,9 +25,15 @@
namespace Input {
+ /**
+ @brief maps multiple Scrollers into one
+
+ XML definition: <multiple-scroller> <scroller 1>...<scroller N>
</multiple-scroller>
+ */
class MultipleScroller : public Scroller {
private:
std::vector<Scroller*> scrollers;
+
float x_pos;
float y_pos;
@@ -35,10 +41,10 @@
MultipleScroller (const std::vector<Scroller*>& scrollers_);
~MultipleScroller ();
- float get_x_delta ();
- float get_y_delta ();
+ const float& get_x_delta () const;
+ const float& get_y_delta () const;
- void get_delta (float& x, float& y);
+ void get_delta (float& x, float& y) const;
void update (float delta);
};
Index: pointer.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/input/pointer.hxx,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- pointer.hxx 5 Jul 2002 11:02:47 -0000 1.4
+++ pointer.hxx 14 Aug 2002 12:41:22 -0000 1.5
@@ -22,14 +22,20 @@
namespace Input
{
+ /// abstract base class defining the pointer interface
class Pointer
{
public:
virtual ~Pointer() { }
- virtual float get_x_pos () =0;
- virtual float get_y_pos () =0;
+ /// returns the X coordinate of the pointer
+ virtual const float& get_x_pos () const =0;
+
+ /// returns the Y coordinate of the pointer
+ virtual const float& get_y_pos () const =0;
+
+ /// sets the pointer to the given position
virtual void set_pos (float, float) =0;
virtual void update (float) =0;
Index: pointer_scroller.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/input/pointer_scroller.cxx,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- pointer_scroller.cxx 11 Jul 2002 12:36:15 -0000 1.1
+++ pointer_scroller.cxx 14 Aug 2002 12:41:22 -0000 1.2
@@ -34,20 +34,20 @@
delete modifier;
}
- float
- PointerScroller::get_x_delta ()
+ const float&
+ PointerScroller::get_x_delta () const
{
return x_delta;
}
- float
- PointerScroller::get_y_delta ()
+ const float&
+ PointerScroller::get_y_delta () const
{
return y_delta;
}
void
- PointerScroller::get_delta (float& x, float& y)
+ PointerScroller::get_delta (float& x, float& y) const
{
x = x_delta;
y = y_delta;
Index: pointer_scroller.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/input/pointer_scroller.hxx,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- pointer_scroller.hxx 11 Jul 2002 12:36:15 -0000 1.1
+++ pointer_scroller.hxx 14 Aug 2002 12:41:22 -0000 1.2
@@ -27,25 +27,34 @@
class Button;
class Pointer;
+ /**
+ @brief allows a Pointer to be used as a Scroller
+
+ XML definition: <pointer-scroller> <pointer><button> </pointer-scroller>
+
+ A PointerScroller creates ScrollEvents whenever the associated Button is
pressed.
+ The Pointer itself is then reset to it's original position to prevent the
visible
+ pointer from moving while the Pointer is used as a Scroller.
+ */
class PointerScroller : public Scroller {
private:
- Pointer* pointer;
- Button* modifier;
+ Pointer* const pointer;
+ Button* const modifier;
- float x_delta;
- float y_delta;
- float x_pos;
- float y_pos;
+ float x_delta;
+ float y_delta;
+ float x_pos;
+ float y_pos;
public:
PointerScroller (Pointer* pointer_, Button* modifier_);
~PointerScroller ();
- float get_x_delta ();
- float get_y_delta ();
+ const float& get_x_delta () const;
+ const float& get_y_delta () const;
- void get_delta (float& x, float& y);
+ void get_delta (float& x, float& y) const;
void update (float delta);
};
Index: scroller.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/input/scroller.hxx,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- scroller.hxx 11 Jul 2002 12:36:15 -0000 1.1
+++ scroller.hxx 14 Aug 2002 12:41:22 -0000 1.2
@@ -22,14 +22,19 @@
namespace Input {
+ /// abstract base class defining the scroller interface
class Scroller {
public:
virtual ~Scroller () { }
- virtual float get_x_delta () =0;
- virtual float get_y_delta () =0;
+ /// returns the scroll delta in X direction
+ virtual const float& get_x_delta () const =0;
- virtual void get_delta (float&, float&) =0;
+ /// returns the scroll delta in Y direction
+ virtual const float& get_y_delta () const =0;
+
+ /// writes the X/Y scroll delta into it's parameters
+ virtual void get_delta (float&, float&) const =0;
virtual void update (float) =0;
};
Index: scroller_factory.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/input/scroller_factory.cxx,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- scroller_factory.cxx 12 Jul 2002 12:36:14 -0000 1.2
+++ scroller_factory.cxx 14 Aug 2002 12:41:22 -0000 1.3
@@ -76,23 +76,23 @@
float speed = strtod(speed_str, reinterpret_cast<char**>(NULL));
free(speed_str);
-
- Axis *axis1, *axis2;
+
+ std::vector<Axis*> axes;
cur = cur->children;
- if (xmlIsBlankNode(cur))
- cur = cur->next;
-
- axis1 = AxisFactory::create(cur);
-
- cur = cur-> next;
-
- if (xmlIsBlankNode(cur))
- cur = cur->next;
-
- axis2 = AxisFactory::create(cur);
-
- return new AxisScroller(axis1, axis2, speed);
+ while (cur)
+ {
+ if (xmlIsBlankNode(cur))
+ {
+ cur = cur->next;
+ continue;
+ }
+
+ axes.push_back(AxisFactory::create(cur));
+ cur = cur->next;
+ }
+
+ return new AxisScroller(axes, speed);
}
Scroller*
Index: triple_button.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/input/triple_button.cxx,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- triple_button.cxx 11 Jul 2002 14:51:10 -0000 1.1
+++ triple_button.cxx 14 Aug 2002 12:41:22 -0000 1.2
@@ -21,8 +21,11 @@
namespace Input {
- TripleButton::TripleButton(Button* button1_, Button* button2_, Button*
button3_) : button1(button1_), button2(button2_), button3(button3_),
-
first_second_pressed(false), ignore_third(false)
+ TripleButton::TripleButton (Button* button1_, Button* button2_, Button*
button3_) : button1(button1_),
+
button2(button2_),
+
button3(button3_),
+
first_second_pressed(false),
+
ignore_third(false)
{
}
@@ -34,7 +37,7 @@
}
void
- TripleButton::update(float delta)
+ TripleButton::update (float delta)
{
button1->update(delta);
button2->update(delta);
@@ -56,7 +59,7 @@
}
bool
- TripleButton::is_pressed()
+ TripleButton::is_pressed() const
{
return ( ! ignore_third && first_second_pressed && button3->is_pressed());
}
Index: triple_button.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/input/triple_button.hxx,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- triple_button.hxx 11 Jul 2002 14:51:10 -0000 1.1
+++ triple_button.hxx 14 Aug 2002 12:41:22 -0000 1.2
@@ -24,20 +24,30 @@
namespace Input {
+ /**
+ @brief allows three buttons to be used in combination
+
+ XML definition: <triple-button> <button1><button2><button3>
</triple-button>
+
+ This class allows combinations like CTRL-ALT-R whereby it's important that
the first
+ two keys are pressed before the third else the TripleButton itself won't
change it's
+ own state to pressed. The order in which the first two keys are pressed is
of no
+ importance, such behaviour may be created by using nested DoubleButtons.
+ */
class TripleButton : public Button {
private:
- Button* button1;
- Button* button2;
- Button* button3;
- bool first_second_pressed;
- bool ignore_third;
+ Button* const button1;
+ Button* const button2;
+ Button* const button3;
+ bool first_second_pressed;
+ bool ignore_third;
public:
TripleButton (Button* button1_, Button* button2_, Button* button3_);
~TripleButton ();
- virtual bool is_pressed ();
+ virtual bool is_pressed () const;
virtual void update (float delta);
};
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Pingus-CVS] CVS: Games/Pingus/src/input axis.hxx,1.3,1.4 axis_factory.cxx,1.3,1.4 axis_pointer.cxx,1.6,1.7 axis_pointer.hxx,1.5,1.6 axis_scroller.cxx,1.2,1.3 axis_scroller.hxx,1.1,1.2 button.hxx,1.3,1.4 button_axis.cxx,1.4,1.5 button_axis.hxx,1.3,1.4 controller.cxx,1.8,1.9 double_button.cxx,1.1,1.2 double_button.hxx,1.1,1.2 dummy_axis.hxx,1.1,1.2 dummy_button.hxx,1.1,1.2 dummy_pointer.hxx,1.1,1.2 dummy_scroller.hxx,1.1,1.2 inverted_axis.cxx,1.3,1.4 inverted_axis.hxx,1.4,1.5 inverted_scroller.cxx,1.1,1.2 inverted_scroller.hxx,1.1,1.2 joystick_axis.cxx,1.4,1.5 joystick_axis.hxx,1.3,1.4 joystick_button.cxx,1.2,1.3 joystick_button.hxx,1.2,1.3 joystick_scroller.cxx,1.2,1.3 joystick_scroller.hxx,1.1,1.2 key_button.cxx,1.1,1.2 key_button.hxx,1.2,1.3 mouse_axis.cxx,1.2,1.3 mouse_axis.hxx,1.4,1.5 mouse_button.cxx,1.2,1.3 mouse_button.hxx,1.2,1.3 mouse_pointer.cxx,1.2,1.3 mouse_pointer.hxx,1.3,1.4 mouse_scroller.cxx,1.1,1.2 mouse_scroller.hxx,1.1,1.2 multiple_axis.cxx,1.2,1.3 multiple_axis.hxx,1.2,1.3 multiple_button.cxx,1.3,1.4 multiple_button.hxx,1.4,1.5 multiple_pointer.cxx,1.4,1.5 multiple_pointer.hxx,1.3,1.4 multiple_scroller.cxx,1.1,1.2 multiple_scroller.hxx,1.1,1.2 pointer.hxx,1.4,1.5 pointer_scroller.cxx,1.1,1.2 pointer_scroller.hxx,1.1,1.2 scroller.hxx,1.1,1.2 scroller_factory.cxx,1.2,1.3 triple_button.cxx,1.1,1.2 triple_button.hxx,1.1,1.2,
torangan <=
- Prev by Date:
[Pingus-CVS] CVS: Games/Pingus/src xml_helper.cxx,1.9,1.10
- Next by Date:
[Pingus-CVS] CVS: Games/Pingus/src/actions bomber.cxx,1.5,1.6 floater.cxx,1.8,1.9
- Previous by thread:
[Pingus-CVS] CVS: Games/Pingus/src xml_helper.cxx,1.9,1.10
- Next by thread:
[Pingus-CVS] CVS: Games/Pingus/src/actions bomber.cxx,1.5,1.6 floater.cxx,1.8,1.9
- Index(es):