OSDN Git Service

Merge pull request #476 from semtiko/master
[mikumikustudio/libgdx-mikumikustudio.git] / backends / gdx-backend-jglfw / src / com / badlogic / gdx / backends / jglfw / JglfwInput.java
1
2 package com.badlogic.gdx.backends.jglfw;
3
4 import static com.badlogic.jglfw.Glfw.*;
5
6 import java.awt.Color;
7 import java.awt.FlowLayout;
8 import java.awt.event.WindowEvent;
9 import java.awt.event.WindowFocusListener;
10
11 import javax.swing.JDialog;
12 import javax.swing.JLabel;
13 import javax.swing.JOptionPane;
14 import javax.swing.JPanel;
15 import javax.swing.JTextField;
16 import javax.swing.OverlayLayout;
17 import javax.swing.SwingUtilities;
18 import javax.swing.border.EmptyBorder;
19 import javax.swing.event.DocumentEvent;
20 import javax.swing.event.DocumentListener;
21
22 import com.badlogic.gdx.Input;
23 import com.badlogic.gdx.InputProcessor;
24 import com.badlogic.gdx.InputProcessorQueue;
25 import com.badlogic.jglfw.GlfwCallbackAdapter;
26
27 /** An implementation of the {@link Input} interface hooking GLFW panel for input.
28  * @author mzechner
29  * @author Nathan Sweet */
30 public class JglfwInput implements Input {
31         final JglfwApplication app;
32         final InputProcessorQueue processorQueue;
33         InputProcessor processor;
34         int pressedKeys = 0;
35         boolean justTouched;
36         int deltaX, deltaY;
37         long currentEventTime;
38
39         public JglfwInput (final JglfwApplication app, boolean queueEvents) {
40                 this.app = app;
41
42                 InputProcessor inputProcessor = new InputProcessor() {
43                         private int mouseX, mouseY;
44
45                         public boolean keyDown (int keycode) {
46                                 pressedKeys++;
47                                 app.graphics.requestRendering();
48                                 return processor != null ? processor.keyDown(keycode) : false;
49                         }
50
51                         public boolean keyUp (int keycode) {
52                                 pressedKeys--;
53                                 app.graphics.requestRendering();
54                                 return processor != null ? processor.keyUp(keycode) : false;
55                         }
56
57                         public boolean keyTyped (char character) {
58                                 app.graphics.requestRendering();
59                                 return processor != null ? processor.keyTyped(character) : false;
60                         }
61
62                         public boolean touchDown (int screenX, int screenY, int pointer, int button) {
63                                 justTouched = true;
64                                 app.graphics.requestRendering();
65                                 return processor != null ? processor.touchDown(screenX, screenY, pointer, button) : false;
66                         }
67
68                         public boolean touchUp (int screenX, int screenY, int pointer, int button) {
69                                 app.graphics.requestRendering();
70                                 return processor != null ? processor.touchUp(screenX, screenY, pointer, button) : false;
71                         }
72
73                         public boolean touchDragged (int screenX, int screenY, int pointer) {
74                                 deltaX = screenX - mouseX;
75                                 deltaY = screenY - mouseY;
76                                 mouseX = screenX;
77                                 mouseY = screenY;
78                                 app.graphics.requestRendering();
79                                 return processor != null ? processor.touchDragged(mouseX, mouseY, 0) : false;
80                         }
81
82                         public boolean mouseMoved (int screenX, int screenY) {
83                                 deltaX = screenX - mouseX;
84                                 deltaY = screenY - mouseX;
85                                 mouseX = screenX;
86                                 mouseY = screenY;
87                                 app.graphics.requestRendering();
88                                 return processor != null ? processor.mouseMoved(mouseX, mouseY) : false;
89                         }
90
91                         public boolean scrolled (int amount) {
92                                 app.graphics.requestRendering();
93                                 return processor != null ? processor.scrolled(amount) : false;
94                         }
95                 };
96
97                 if (queueEvents)
98                         inputProcessor = processorQueue = new InputProcessorQueue(inputProcessor);
99                 else
100                         processorQueue = null;
101
102                 app.getCallbacks().add(new GlfwInputProcessor(inputProcessor));
103         }
104
105         public void update () {
106                 justTouched = false;
107                 if (processorQueue != null)
108                         processorQueue.drain(); // Main loop is handled elsewhere and events are queued.
109                 else {
110                         currentEventTime = System.nanoTime();
111                         glfwPollEvents(); // Use GLFW main loop to process events.
112                 }
113         }
114
115         public float getAccelerometerX () {
116                 return 0;
117         }
118
119         public float getAccelerometerY () {
120                 return 0;
121         }
122
123         public float getAccelerometerZ () {
124                 return 0;
125         }
126
127         public int getX () {
128                 return glfwGetCursorPosX(app.graphics.window);
129         }
130
131         public int getX (int pointer) {
132                 return pointer > 0 ? 0 : getX();
133         }
134
135         public int getY () {
136                 return glfwGetCursorPosY(app.graphics.window);
137         }
138
139         public int getY (int pointer) {
140                 return pointer > 0 ? 0 : getY();
141         }
142
143         public int getDeltaX () {
144                 return deltaX;
145         }
146
147         public int getDeltaX (int pointer) {
148                 return pointer > 0 ? 0 : deltaX;
149         }
150
151         public int getDeltaY () {
152                 return deltaY;
153         }
154
155         public int getDeltaY (int pointer) {
156                 return pointer > 0 ? 0 : deltaY;
157         }
158
159         public boolean isTouched () {
160                 return glfwGetMouseButton(app.graphics.window, 0) || glfwGetMouseButton(app.graphics.window, 1)
161                         || glfwGetMouseButton(app.graphics.window, 2);
162         }
163
164         public boolean isTouched (int pointer) {
165                 return pointer > 0 ? false : isTouched();
166         }
167
168         public boolean justTouched () {
169                 return justTouched;
170         }
171
172         public boolean isButtonPressed (int button) {
173                 return glfwGetMouseButton(app.graphics.window, button);
174         }
175
176         public boolean isKeyPressed (int key) {
177                 if (key == Input.Keys.ANY_KEY) return pressedKeys > 0;
178                 if (key == Input.Keys.SYM)
179                         return glfwGetKey(app.graphics.window, GLFW_KEY_LEFT_SUPER) || glfwGetKey(app.graphics.window, GLFW_KEY_RIGHT_SUPER);
180                 return glfwGetKey(app.graphics.window, getJglfwKeyCode(key));
181         }
182
183         public void setOnscreenKeyboardVisible (boolean visible) {
184         }
185
186         public void vibrate (int milliseconds) {
187         }
188
189         public void vibrate (long[] pattern, int repeat) {
190         }
191
192         public void cancelVibrate () {
193         }
194
195         public float getAzimuth () {
196                 return 0;
197         }
198
199         public float getPitch () {
200                 return 0;
201         }
202
203         public float getRoll () {
204                 return 0;
205         }
206
207         public void getRotationMatrix (float[] matrix) {
208         }
209
210         public long getCurrentEventTime () {
211                 return processorQueue != null ? processorQueue.getCurrentEventTime() : currentEventTime;
212         }
213
214         public void setCatchBackKey (boolean catchBack) {
215         }
216
217         public void setCatchMenuKey (boolean catchMenu) {
218         }
219
220         public void setInputProcessor (InputProcessor processor) {
221                 this.processor = processor;
222         }
223
224         public InputProcessor getInputProcessor () {
225                 return processor;
226         }
227
228         public boolean isPeripheralAvailable (Peripheral peripheral) {
229                 return peripheral == Peripheral.HardwareKeyboard;
230         }
231
232         public int getRotation () {
233                 return 0;
234         }
235
236         public Orientation getNativeOrientation () {
237                 return Orientation.Landscape;
238         }
239
240         public void setCursorCatched (boolean captured) {
241                 glfwSetInputMode(app.graphics.window, GLFW_CURSOR_MODE, captured ? GLFW_CURSOR_CAPTURED : GLFW_CURSOR_NORMAL);
242         }
243
244         public boolean isCursorCatched () {
245                 return glfwGetInputMode(app.graphics.window, GLFW_CURSOR_MODE) == GLFW_CURSOR_CAPTURED;
246         }
247
248         public void setCursorPosition (int x, int y) {
249                 glfwSetCursorPos(app.graphics.window, x, y);
250         }
251
252         public void getTextInput (final TextInputListener listener, final String title, final String text) {
253                 SwingUtilities.invokeLater(new Runnable() {
254                         public void run () {
255                                 final String output = JOptionPane.showInputDialog(null, title, text);
256                                 app.postRunnable(new Runnable() {
257                                         public void run () {
258                                                 if (output != null)
259                                                         listener.input(output);
260                                                 else
261                                                         listener.canceled();
262                                         }
263                                 });
264                         }
265                 });
266         }
267
268         public void getPlaceholderTextInput (final TextInputListener listener, final String title, final String placeholder) {
269                 SwingUtilities.invokeLater(new Runnable() {
270                         public void run () {
271                                 JPanel panel = new JPanel(new FlowLayout());
272
273                                 JPanel textPanel = new JPanel() {
274                                         public boolean isOptimizedDrawingEnabled () {
275                                                 return false;
276                                         };
277                                 };
278                                 textPanel.setLayout(new OverlayLayout(textPanel));
279                                 panel.add(textPanel);
280
281                                 final JTextField textField = new JTextField(20);
282                                 textField.setAlignmentX(0.0f);
283                                 textPanel.add(textField);
284
285                                 final JLabel placeholderLabel = new JLabel(placeholder);
286                                 placeholderLabel.setForeground(Color.GRAY);
287                                 placeholderLabel.setAlignmentX(0.0f);
288                                 textPanel.add(placeholderLabel, 0);
289
290                                 textField.getDocument().addDocumentListener(new DocumentListener() {
291                                         public void removeUpdate (DocumentEvent event) {
292                                                 this.updated();
293                                         }
294
295                                         public void insertUpdate (DocumentEvent event) {
296                                                 this.updated();
297                                         }
298
299                                         public void changedUpdate (DocumentEvent event) {
300                                                 this.updated();
301                                         }
302
303                                         private void updated () {
304                                                 placeholderLabel.setVisible(textField.getText().length() == 0);
305                                         }
306                                 });
307
308                                 JOptionPane pane = new JOptionPane(panel, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null, null,
309                                         null);
310                                 pane.setComponentOrientation(JOptionPane.getRootFrame().getComponentOrientation());
311                                 pane.selectInitialValue();
312
313                                 placeholderLabel.setBorder(new EmptyBorder(textField.getBorder().getBorderInsets(textField)));
314
315                                 JDialog dialog = pane.createDialog(null, title);
316                                 dialog.addWindowFocusListener(new WindowFocusListener() {
317                                         public void windowLostFocus (WindowEvent arg0) {
318                                         }
319
320                                         public void windowGainedFocus (WindowEvent arg0) {
321                                                 textField.requestFocusInWindow();
322                                         }
323                                 });
324                                 dialog.setVisible(true);
325                                 dialog.dispose();
326
327                                 Object selectedValue = pane.getValue();
328                                 if (selectedValue != null && (selectedValue instanceof Integer) && (Integer)selectedValue == JOptionPane.OK_OPTION)
329                                         listener.input(textField.getText());
330                                 else
331                                         listener.canceled();
332                         }
333                 });
334         }
335
336         static char characterForKeyCode (int key) {
337                 // Map certain key codes to character codes.
338                 switch (key) {
339                 case Keys.BACKSPACE:
340                         return 8;
341                 case Keys.TAB:
342                         return '\t';
343                 case Keys.FORWARD_DEL:
344                         return 127;
345                 }
346                 return 0;
347         }
348
349         static public int getGdxKeyCode (int lwjglKeyCode) {
350                 switch (lwjglKeyCode) {
351                 case GLFW_KEY_LEFT_BRACKET:
352                         return Input.Keys.LEFT_BRACKET;
353                 case GLFW_KEY_RIGHT_BRACKET:
354                         return Input.Keys.RIGHT_BRACKET;
355                 case GLFW_KEY_GRAVE_ACCENT:
356                         return Input.Keys.GRAVE;
357                 case GLFW_KEY_KP_MULTIPLY:
358                         return Input.Keys.STAR;
359                 case GLFW_KEY_NUM_LOCK:
360                         return Input.Keys.NUM;
361                 case GLFW_KEY_KP_DECIMAL:
362                         return Input.Keys.PERIOD;
363                 case GLFW_KEY_KP_DIVIDE:
364                         return Input.Keys.SLASH;
365                 case GLFW_KEY_MENU:
366                         return Input.Keys.MENU;
367                 case GLFW_KEY_RIGHT_SUPER:
368                         return Input.Keys.SYM;
369                 case GLFW_KEY_LEFT_SUPER:
370                         return Input.Keys.SYM;
371                 case GLFW_KEY_KP_EQUAL:
372                         return Input.Keys.EQUALS;
373                 case GLFW_KEY_EQUAL:
374                         return Input.Keys.EQUALS;
375                 case GLFW_KEY_KP_ENTER:
376                         return Input.Keys.ENTER;
377                 case GLFW_KEY_0:
378                         return Input.Keys.NUM_0;
379                 case GLFW_KEY_1:
380                         return Input.Keys.NUM_1;
381                 case GLFW_KEY_2:
382                         return Input.Keys.NUM_2;
383                 case GLFW_KEY_3:
384                         return Input.Keys.NUM_3;
385                 case GLFW_KEY_4:
386                         return Input.Keys.NUM_4;
387                 case GLFW_KEY_5:
388                         return Input.Keys.NUM_5;
389                 case GLFW_KEY_6:
390                         return Input.Keys.NUM_6;
391                 case GLFW_KEY_7:
392                         return Input.Keys.NUM_7;
393                 case GLFW_KEY_8:
394                         return Input.Keys.NUM_8;
395                 case GLFW_KEY_9:
396                         return Input.Keys.NUM_9;
397                 case GLFW_KEY_A:
398                         return Input.Keys.A;
399                 case GLFW_KEY_B:
400                         return Input.Keys.B;
401                 case GLFW_KEY_C:
402                         return Input.Keys.C;
403                 case GLFW_KEY_D:
404                         return Input.Keys.D;
405                 case GLFW_KEY_E:
406                         return Input.Keys.E;
407                 case GLFW_KEY_F:
408                         return Input.Keys.F;
409                 case GLFW_KEY_G:
410                         return Input.Keys.G;
411                 case GLFW_KEY_H:
412                         return Input.Keys.H;
413                 case GLFW_KEY_I:
414                         return Input.Keys.I;
415                 case GLFW_KEY_J:
416                         return Input.Keys.J;
417                 case GLFW_KEY_K:
418                         return Input.Keys.K;
419                 case GLFW_KEY_L:
420                         return Input.Keys.L;
421                 case GLFW_KEY_M:
422                         return Input.Keys.M;
423                 case GLFW_KEY_N:
424                         return Input.Keys.N;
425                 case GLFW_KEY_O:
426                         return Input.Keys.O;
427                 case GLFW_KEY_P:
428                         return Input.Keys.P;
429                 case GLFW_KEY_Q:
430                         return Input.Keys.Q;
431                 case GLFW_KEY_R:
432                         return Input.Keys.R;
433                 case GLFW_KEY_S:
434                         return Input.Keys.S;
435                 case GLFW_KEY_T:
436                         return Input.Keys.T;
437                 case GLFW_KEY_U:
438                         return Input.Keys.U;
439                 case GLFW_KEY_V:
440                         return Input.Keys.V;
441                 case GLFW_KEY_W:
442                         return Input.Keys.W;
443                 case GLFW_KEY_X:
444                         return Input.Keys.X;
445                 case GLFW_KEY_Y:
446                         return Input.Keys.Y;
447                 case GLFW_KEY_Z:
448                         return Input.Keys.Z;
449                 case GLFW_KEY_LALT:
450                         return Input.Keys.ALT_LEFT;
451                 case GLFW_KEY_RALT:
452                         return Input.Keys.ALT_RIGHT;
453                 case GLFW_KEY_BACKSLASH:
454                         return Input.Keys.BACKSLASH;
455                 case GLFW_KEY_COMMA:
456                         return Input.Keys.COMMA;
457                 case GLFW_KEY_DELETE:
458                         return Input.Keys.FORWARD_DEL;
459                 case GLFW_KEY_LEFT:
460                         return Input.Keys.DPAD_LEFT;
461                 case GLFW_KEY_RIGHT:
462                         return Input.Keys.DPAD_RIGHT;
463                 case GLFW_KEY_UP:
464                         return Input.Keys.DPAD_UP;
465                 case GLFW_KEY_DOWN:
466                         return Input.Keys.DPAD_DOWN;
467                 case GLFW_KEY_ENTER:
468                         return Input.Keys.ENTER;
469                 case GLFW_KEY_HOME:
470                         return Input.Keys.HOME;
471                 case GLFW_KEY_MINUS:
472                         return Input.Keys.MINUS;
473                 case GLFW_KEY_PERIOD:
474                         return Input.Keys.PERIOD;
475                 case GLFW_KEY_KP_ADD:
476                         return Input.Keys.PLUS;
477                 case GLFW_KEY_SEMICOLON:
478                         return Input.Keys.SEMICOLON;
479                 case GLFW_KEY_LSHIFT:
480                         return Input.Keys.SHIFT_LEFT;
481                 case GLFW_KEY_RSHIFT:
482                         return Input.Keys.SHIFT_RIGHT;
483                 case GLFW_KEY_SLASH:
484                         return Input.Keys.SLASH;
485                 case GLFW_KEY_SPACE:
486                         return Input.Keys.SPACE;
487                 case GLFW_KEY_TAB:
488                         return Input.Keys.TAB;
489                 case GLFW_KEY_LEFT_CONTROL:
490                         return Input.Keys.CONTROL_LEFT;
491                 case GLFW_KEY_RIGHT_CONTROL:
492                         return Input.Keys.CONTROL_RIGHT;
493                 case GLFW_KEY_ESCAPE:
494                         return Input.Keys.ESCAPE;
495                 case GLFW_KEY_END:
496                         return Input.Keys.END;
497                 case GLFW_KEY_INSERT:
498                         return Input.Keys.INSERT;
499                 case GLFW_KEY_BACKSPACE:
500                         return Input.Keys.DEL;
501                 case GLFW_KEY_KP_SUBTRACT:
502                         return Input.Keys.MINUS;
503                 case GLFW_KEY_APOSTROPHE:
504                         return Input.Keys.APOSTROPHE;
505                 case GLFW_KEY_F1:
506                         return Input.Keys.F1;
507                 case GLFW_KEY_F2:
508                         return Input.Keys.F2;
509                 case GLFW_KEY_F3:
510                         return Input.Keys.F3;
511                 case GLFW_KEY_F4:
512                         return Input.Keys.F4;
513                 case GLFW_KEY_F5:
514                         return Input.Keys.F5;
515                 case GLFW_KEY_F6:
516                         return Input.Keys.F6;
517                 case GLFW_KEY_F7:
518                         return Input.Keys.F7;
519                 case GLFW_KEY_F8:
520                         return Input.Keys.F8;
521                 case GLFW_KEY_F9:
522                         return Input.Keys.F9;
523                 case GLFW_KEY_F10:
524                         return Input.Keys.F10;
525                 case GLFW_KEY_F11:
526                         return Input.Keys.F11;
527                 case GLFW_KEY_F12:
528                         return Input.Keys.F12;
529                 case GLFW_KEY_KP_0:
530                         return Input.Keys.NUMPAD_0;
531                 case GLFW_KEY_KP_1:
532                         return Input.Keys.NUMPAD_1;
533                 case GLFW_KEY_KP_2:
534                         return Input.Keys.NUMPAD_2;
535                 case GLFW_KEY_KP_3:
536                         return Input.Keys.NUMPAD_3;
537                 case GLFW_KEY_KP_4:
538                         return Input.Keys.NUMPAD_4;
539                 case GLFW_KEY_KP_5:
540                         return Input.Keys.NUMPAD_5;
541                 case GLFW_KEY_KP_6:
542                         return Input.Keys.NUMPAD_6;
543                 case GLFW_KEY_KP_7:
544                         return Input.Keys.NUMPAD_7;
545                 case GLFW_KEY_KP_8:
546                         return Input.Keys.NUMPAD_8;
547                 case GLFW_KEY_KP_9:
548                         return Input.Keys.NUMPAD_9;
549                 default:
550                         return Input.Keys.UNKNOWN;
551                 }
552         }
553
554         static public int getJglfwKeyCode (int gdxKeyCode) {
555                 switch (gdxKeyCode) {
556                 case Input.Keys.LEFT_BRACKET:
557                         return GLFW_KEY_LEFT_BRACKET;
558                 case Input.Keys.RIGHT_BRACKET:
559                         return GLFW_KEY_RIGHT_BRACKET;
560                 case Input.Keys.GRAVE:
561                         return GLFW_KEY_GRAVE_ACCENT;
562                 case Input.Keys.STAR:
563                         return GLFW_KEY_KP_MULTIPLY;
564                 case Input.Keys.NUM:
565                         return GLFW_KEY_NUM_LOCK;
566                 case Input.Keys.EQUALS:
567                         return GLFW_KEY_MENU;
568                 case Input.Keys.MENU:
569                         return GLFW_KEY_MENU;
570                 case Input.Keys.SYM:
571                         return GLFW_KEY_LEFT_SUPER;
572                 case Input.Keys.NUM_0:
573                         return GLFW_KEY_0;
574                 case Input.Keys.NUM_1:
575                         return GLFW_KEY_1;
576                 case Input.Keys.NUM_2:
577                         return GLFW_KEY_2;
578                 case Input.Keys.NUM_3:
579                         return GLFW_KEY_3;
580                 case Input.Keys.NUM_4:
581                         return GLFW_KEY_4;
582                 case Input.Keys.NUM_5:
583                         return GLFW_KEY_5;
584                 case Input.Keys.NUM_6:
585                         return GLFW_KEY_6;
586                 case Input.Keys.NUM_7:
587                         return GLFW_KEY_7;
588                 case Input.Keys.NUM_8:
589                         return GLFW_KEY_8;
590                 case Input.Keys.NUM_9:
591                         return GLFW_KEY_9;
592                 case Input.Keys.A:
593                         return GLFW_KEY_A;
594                 case Input.Keys.B:
595                         return GLFW_KEY_B;
596                 case Input.Keys.C:
597                         return GLFW_KEY_C;
598                 case Input.Keys.D:
599                         return GLFW_KEY_D;
600                 case Input.Keys.E:
601                         return GLFW_KEY_E;
602                 case Input.Keys.F:
603                         return GLFW_KEY_F;
604                 case Input.Keys.G:
605                         return GLFW_KEY_G;
606                 case Input.Keys.H:
607                         return GLFW_KEY_H;
608                 case Input.Keys.I:
609                         return GLFW_KEY_I;
610                 case Input.Keys.J:
611                         return GLFW_KEY_J;
612                 case Input.Keys.K:
613                         return GLFW_KEY_K;
614                 case Input.Keys.L:
615                         return GLFW_KEY_L;
616                 case Input.Keys.M:
617                         return GLFW_KEY_M;
618                 case Input.Keys.N:
619                         return GLFW_KEY_N;
620                 case Input.Keys.O:
621                         return GLFW_KEY_O;
622                 case Input.Keys.P:
623                         return GLFW_KEY_P;
624                 case Input.Keys.Q:
625                         return GLFW_KEY_Q;
626                 case Input.Keys.R:
627                         return GLFW_KEY_R;
628                 case Input.Keys.S:
629                         return GLFW_KEY_S;
630                 case Input.Keys.T:
631                         return GLFW_KEY_T;
632                 case Input.Keys.U:
633                         return GLFW_KEY_U;
634                 case Input.Keys.V:
635                         return GLFW_KEY_V;
636                 case Input.Keys.W:
637                         return GLFW_KEY_W;
638                 case Input.Keys.X:
639                         return GLFW_KEY_X;
640                 case Input.Keys.Y:
641                         return GLFW_KEY_Y;
642                 case Input.Keys.Z:
643                         return GLFW_KEY_Z;
644                 case Input.Keys.ALT_LEFT:
645                         return GLFW_KEY_LALT;
646                 case Input.Keys.ALT_RIGHT:
647                         return GLFW_KEY_RALT;
648                 case Input.Keys.BACKSLASH:
649                         return GLFW_KEY_BACKSLASH;
650                 case Input.Keys.COMMA:
651                         return GLFW_KEY_COMMA;
652                 case Input.Keys.FORWARD_DEL:
653                         return GLFW_KEY_DELETE;
654                 case Input.Keys.DPAD_LEFT:
655                         return GLFW_KEY_LEFT;
656                 case Input.Keys.DPAD_RIGHT:
657                         return GLFW_KEY_RIGHT;
658                 case Input.Keys.DPAD_UP:
659                         return GLFW_KEY_UP;
660                 case Input.Keys.DPAD_DOWN:
661                         return GLFW_KEY_DOWN;
662                 case Input.Keys.ENTER:
663                         return GLFW_KEY_ENTER;
664                 case Input.Keys.HOME:
665                         return GLFW_KEY_HOME;
666                 case Input.Keys.MINUS:
667                         return GLFW_KEY_MINUS;
668                 case Input.Keys.PERIOD:
669                         return GLFW_KEY_PERIOD;
670                 case Input.Keys.PLUS:
671                         return GLFW_KEY_KP_ADD;
672                 case Input.Keys.SEMICOLON:
673                         return GLFW_KEY_SEMICOLON;
674                 case Input.Keys.SHIFT_LEFT:
675                         return GLFW_KEY_LSHIFT;
676                 case Input.Keys.SHIFT_RIGHT:
677                         return GLFW_KEY_RSHIFT;
678                 case Input.Keys.SLASH:
679                         return GLFW_KEY_SLASH;
680                 case Input.Keys.SPACE:
681                         return GLFW_KEY_SPACE;
682                 case Input.Keys.TAB:
683                         return GLFW_KEY_TAB;
684                 case Input.Keys.DEL:
685                         return GLFW_KEY_BACKSPACE;
686                 case Input.Keys.CONTROL_LEFT:
687                         return GLFW_KEY_LEFT_CONTROL;
688                 case Input.Keys.CONTROL_RIGHT:
689                         return GLFW_KEY_RIGHT_CONTROL;
690                 case Input.Keys.ESCAPE:
691                         return GLFW_KEY_ESCAPE;
692                 case Input.Keys.F1:
693                         return GLFW_KEY_F1;
694                 case Input.Keys.F2:
695                         return GLFW_KEY_F2;
696                 case Input.Keys.F3:
697                         return GLFW_KEY_F3;
698                 case Input.Keys.F4:
699                         return GLFW_KEY_F4;
700                 case Input.Keys.F5:
701                         return GLFW_KEY_F5;
702                 case Input.Keys.F6:
703                         return GLFW_KEY_F6;
704                 case Input.Keys.F7:
705                         return GLFW_KEY_F7;
706                 case Input.Keys.F8:
707                         return GLFW_KEY_F8;
708                 case Input.Keys.F9:
709                         return GLFW_KEY_F9;
710                 case Input.Keys.F10:
711                         return GLFW_KEY_F10;
712                 case Input.Keys.F11:
713                         return GLFW_KEY_F11;
714                 case Input.Keys.F12:
715                         return GLFW_KEY_F12;
716                 case Input.Keys.NUMPAD_0:
717                         return GLFW_KEY_KP_0;
718                 case Input.Keys.NUMPAD_1:
719                         return GLFW_KEY_KP_1;
720                 case Input.Keys.NUMPAD_2:
721                         return GLFW_KEY_KP_2;
722                 case Input.Keys.NUMPAD_3:
723                         return GLFW_KEY_KP_3;
724                 case Input.Keys.NUMPAD_4:
725                         return GLFW_KEY_KP_4;
726                 case Input.Keys.NUMPAD_5:
727                         return GLFW_KEY_KP_5;
728                 case Input.Keys.NUMPAD_6:
729                         return GLFW_KEY_KP_6;
730                 case Input.Keys.NUMPAD_7:
731                         return GLFW_KEY_KP_7;
732                 case Input.Keys.NUMPAD_8:
733                         return GLFW_KEY_KP_8;
734                 case Input.Keys.NUMPAD_9:
735                         return GLFW_KEY_KP_9;                   
736                 default:
737                         return 0;
738                 }
739         }
740
741         /** Receives GLFW input and calls InputProcessor methods.
742          * @author Nathan Sweet */
743         static class GlfwInputProcessor extends GlfwCallbackAdapter {
744                 private int mouseX, mouseY, mousePressed;
745                 private char lastCharacter;
746                 private InputProcessor processor;
747
748                 public GlfwInputProcessor (InputProcessor processor) {
749                         if (processor == null) throw new IllegalArgumentException("processor cannot be null.");
750                         this.processor = processor;
751                 }
752
753                 public void key (long window, int key, int action) {
754                         switch (action) {
755                         case GLFW_PRESS:
756
757                                 key = getGdxKeyCode(key);
758                                 processor.keyDown(key);
759
760                                 lastCharacter = 0;
761                                 char character = characterForKeyCode(key);
762                                 if (character != 0) character(window, character);
763                                 break;
764
765                         case GLFW_RELEASE:
766                                 processor.keyUp(getGdxKeyCode(key));
767                                 break;
768
769                         case GLFW_REPEAT:
770                                 if (lastCharacter != 0) processor.keyTyped(lastCharacter);
771                                 break;
772                         }
773                 }
774
775                 public void character (long window, char character) {
776                         lastCharacter = character;
777                         processor.keyTyped(character);
778                 }
779
780                 public void scroll (long window, double scrollX, double scrollY) {
781                         processor.scrolled((int)-Math.signum(scrollY));
782                 }
783
784                 public void mouseButton (long window, int button, boolean pressed) {
785                         if (pressed) {
786                                 mousePressed++;
787                                 processor.touchDown(mouseX, mouseY, 0, button);
788                         } else {
789                                 mousePressed = Math.max(0, mousePressed - 1);
790                                 processor.touchUp(mouseX, mouseY, 0, button);
791                         }
792                 }
793
794                 public void cursorPos (long window, int x, int y) {
795                         mouseX = x;
796                         mouseY = y;
797                         if (mousePressed > 0)
798                                 processor.touchDragged(x, y, 0);
799                         else
800                                 processor.mouseMoved(x, y);
801                 }
802         }
803 }