/[pcsx2_0.9.7]/trunk/plugins/onepad/Linux/linux.cpp
ViewVC logotype

Contents of /trunk/plugins/onepad/Linux/linux.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 290 - (show annotations) (download)
Sat Dec 25 02:51:30 2010 UTC (9 years, 1 month ago) by william
File size: 4794 byte(s)
Auto Commited Import of: pcsx2-0.9.7-DEBUG (upstream: v0.9.7.4139 local: v0.9.7.283-latest) in ./trunk
1 /* OnePAD - author: arcum42(@gmail.com)
2 * Copyright (C) 2009
3 *
4 * Based on ZeroPAD, author zerofrog@gmail.com
5 * Copyright (C) 2006-2007
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
20 */
21
22 #include "joystick.h"
23 #include "onepad.h"
24
25 #include <string.h>
26 #include <gtk/gtk.h>
27 #include "linux.h"
28 #include <gdk/gdkx.h>
29
30 extern void PollForKeyboardInput(int pad);
31 extern void SetAutoRepeat(bool autorep);
32 Display *GSdsp;
33
34 extern string KeyName(int pad, int key);
35
36 void SysMessage(const char *fmt, ...)
37 {
38 va_list list;
39 char msg[512];
40
41 va_start(list, fmt);
42 vsprintf(msg, fmt, list);
43 va_end(list);
44
45 if (msg[strlen(msg)-1] == '\n') msg[strlen(msg)-1] = 0;
46
47 GtkWidget *dialog;
48 dialog = gtk_message_dialog_new (NULL,
49 GTK_DIALOG_DESTROY_WITH_PARENT,
50 GTK_MESSAGE_INFO,
51 GTK_BUTTONS_OK,
52 "%s", msg);
53 gtk_dialog_run (GTK_DIALOG (dialog));
54 gtk_widget_destroy (dialog);
55 }
56
57 EXPORT_C_(void) PADabout()
58 {
59 SysMessage("OnePad is a rewrite of Zerofrog's ZeroPad, done by arcum42.");
60 }
61
62 EXPORT_C_(s32) PADtest()
63 {
64 return 0;
65 }
66
67 s32 _PADopen(void *pDsp)
68 {
69 GtkScrolledWindow *win;
70
71 win = *(GtkScrolledWindow**) pDsp;
72
73 if (GTK_IS_WIDGET(win))
74 {
75 // Since we have a GtkScrolledWindow, for now we'll grab whatever display
76 // comes along instead. Later, we can fiddle with this, but I'm not sure the
77 // best way to get a Display* out of a GtkScrolledWindow. A GtkWindow I might
78 // be able to manage... --arcum42
79 GSdsp = GDK_DISPLAY_XDISPLAY(gdk_display_get_default());
80 }
81 else
82 {
83 GSdsp = *(Display**)pDsp;
84 }
85
86 SetAutoRepeat(false);
87 return 0;
88 }
89
90 void _PADclose()
91 {
92 SetAutoRepeat(true);
93
94 vector<JoystickInfo*>::iterator it = s_vjoysticks.begin();
95
96 // Delete everything in the vector vjoysticks.
97 while (it != s_vjoysticks.end())
98 {
99 delete *it;
100 it ++;
101 }
102
103 s_vjoysticks.clear();
104 }
105
106 EXPORT_C_(void) PADupdate(int pad)
107 {
108 // Poll keyboard.
109 PollForKeyboardInput(pad);
110
111 // joystick info
112 SDL_JoystickUpdate();
113
114 for (int i = 0; i < MAX_KEYS; i++)
115 {
116 int cpad = PadEnum[pad][0];
117
118 if (JoystickIdWithinBounds(key_to_joystick_id(cpad, i)))
119 {
120 JoystickInfo* pjoy = s_vjoysticks[key_to_joystick_id(cpad, i)];
121 int pad = (pjoy)->GetPAD();
122
123 switch (type_of_key(cpad, i))
124 {
125 case PAD_JOYBUTTONS:
126 {
127 int value = SDL_JoystickGetButton((pjoy)->GetJoy(), key_to_button(cpad, i));
128
129 if (value)
130 clear_bit(status[pad], i); // released
131 else
132 set_bit(status[pad], i); // pressed
133 break;
134 }
135 case PAD_HAT:
136 {
137 int value = SDL_JoystickGetHat((pjoy)->GetJoy(), key_to_axis(cpad, i));
138
139 if (key_to_hat_dir(cpad, i) == value)
140 {
141 clear_bit(status[pad], i);
142 //PAD_LOG("Registered %s\n", HatName(value), i);
143 //PAD_LOG("%s\n", KeyName(cpad, i).c_str());
144 }
145 else
146 {
147 set_bit(status[pad], i);
148 }
149 break;
150 }
151 case PAD_POV:
152 {
153 int value = pjoy->GetAxisFromKey(cpad, i);
154
155 PAD_LOG("%s: %d (%d)\n", KeyName(cpad, i).c_str(), value, key_to_pov_sign(cpad, i));
156 if (key_to_pov_sign(cpad, i) && (value < -2048))
157 {
158 //PAD_LOG("%s Released+.\n", KeyName(cpad, i).c_str());
159 clear_bit(status[pad], i);
160 }
161 else if (!key_to_pov_sign(cpad, i) && (value > 2048))
162 {
163 //PAD_LOG("%s Released-\n", KeyName(cpad, i).c_str());
164 clear_bit(status[pad], i);
165 }
166 else
167 {
168 //PAD_LOG("%s Pressed.\n", KeyName(cpad, i).c_str());
169 set_bit(status[pad], i);
170 }
171 break;
172 }
173 case PAD_JOYSTICK:
174 {
175 int value = pjoy->GetAxisFromKey(cpad, i);
176
177 switch (i)
178 {
179 case PAD_LX:
180 case PAD_LY:
181 case PAD_RX:
182 case PAD_RY:
183 if (abs(value) > (pjoy)->GetDeadzone(value))
184 Analog::ConfigurePad(pad, i, value);
185 else
186 Analog::ResetPad(pad, i);
187 break;
188 }
189 break;
190 }
191 default: break;
192 }
193 }
194 }
195 }
196
197
198 EXPORT_C_(void) PADconfigure()
199 {
200 LoadConfig();
201
202 DisplayDialog();
203 return;
204 }

  ViewVC Help
Powered by ViewVC 1.1.22