Page MenuHomePhabricator (Chris)

No OneTemporary

Authored By
Unknown
Size
2 KB
Referenced Files
None
Subscribers
None
diff --git a/util/allegro-joystick.cpp b/util/allegro-joystick.cpp
new file mode 100644
index 00000000..6846775f
--- /dev/null
+++ b/util/allegro-joystick.cpp
@@ -0,0 +1,51 @@
+#include <allegro.h>
+#include "allegro-joystick.h"
+
+void AllegroJoystick::poll(){
+ ::poll_joystick();
+}
+
+JoystickInput AllegroJoystick::readAll(){
+ JoystickInput input;
+ JOYSTICK_INFO * info = &joy[0];
+ switch(info->num_buttons > 4 ? 4 : info->num_buttons){
+ case 4: input.button4 = info->button[3].b;
+ case 3: input.button3 = info->button[2].b;
+ case 2: input.button2 = info->button[1].b;
+ case 1: input.button1 = info->button[0].b;
+ case 0: {
+ break;
+ }
+ }
+ if (info->num_sticks > 0){
+ if (info->stick[0].num_axis > 0){
+ int position = info->stick[0].axis[0].pos;
+ if (position < 0){
+ input.left = true;
+ } else if (position > 0){
+ input.right = true;
+ }
+ }
+ if (info->stick[0].num_axis > 1){
+ int position = info->stick[0].axis[1].pos;
+ if (position < 0){
+ input.up = true;
+ } else if (position > 0){
+ input.down = true;
+ }
+ }
+ }
+ return input;
+}
+
+bool AllegroJoystick::pressed(){
+ JoystickInput input = readAll();
+ return input.up || input.down || input.left || input.right ||
+ input.button1 || input.button2 || input.button3 || input.button4;
+}
+
+AllegroJoystick::~AllegroJoystick(){
+}
+
+AllegroJoystick::AllegroJoystick(){
+}
diff --git a/util/allegro-joystick.h b/util/allegro-joystick.h
new file mode 100644
index 00000000..31b1aef6
--- /dev/null
+++ b/util/allegro-joystick.h
@@ -0,0 +1,20 @@
+#ifndef _paintown_allegro_joystick_h
+#define _paintown_allegro_joystick_h
+
+#include <allegro.h>
+#include "joystick.h"
+
+class AllegroJoystick: public Joystick {
+public:
+ virtual void poll();
+ virtual JoystickInput readAll();
+ virtual bool pressed();
+
+ virtual ~AllegroJoystick();
+
+ friend class Joystick;
+protected:
+ AllegroJoystick();
+};
+
+#endif
diff --git a/util/joystick.cpp b/util/joystick.cpp
index 631ef7f3..2ab6b8fc 100644
--- a/util/joystick.cpp
+++ b/util/joystick.cpp
@@ -1,19 +1,26 @@
#include <stdlib.h>
#include "joystick.h"
+/*
#ifdef LINUX
#include "linux_joystick.h"
#endif
+*/
+
+#include "allegro-joystick.h"
Joystick * Joystick::create(){
+ return new AllegroJoystick();
+/*
#ifdef LINUX
return new LinuxJoystick();
#endif
return NULL;
+*/
}
Joystick::Joystick(){
}
Joystick::~Joystick(){
}

File Metadata

Mime Type
text/x-diff
Expires
Thu, Jun 11, 1:45 PM (3 w, 4 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
69309
Default Alt Text
(2 KB)

Event Timeline