OSDN Git Service

merged with 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 com.badlogic.gdx.Input;
7 import com.badlogic.gdx.InputProcessor;
8 import com.badlogic.gdx.InputProcessorQueue;
9 import com.badlogic.jglfw.GlfwCallbackAdapter;
10
11 import java.awt.Color;
12 import java.awt.FlowLayout;
13 import java.awt.event.WindowEvent;
14 import java.awt.event.WindowFocusListener;
15
16 import javax.swing.JDialog;
17 import javax.swing.JLabel;
18 import javax.swing.JOptionPane;
19 import javax.swing.JPanel;
20 import javax.swing.JTextField;
21 import javax.swing.OverlayLayout;
22 import javax.swing.SwingUtilities;
23 import javax.swing.border.EmptyBorder;
24 import javax.swing.event.DocumentEvent;
25 import javax.swing.event.DocumentListener;
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                 return glfwGetKey(app.graphics.window, getJglfwKeyCode(key));
179         }
180
181         public void setOnscreenKeyboardVisible (boolean visible) {
182         }
183
184         public void vibrate (int milliseconds) {
185         }
186
187         public void vibrate (long[] pattern, int repeat) {
188         }
189
190         public void cancelVibrate () {
191         }
192
193         public float getAzimuth () {
194                 return 0;
195         }
196
197         public float getPitch () {
198                 return 0;
199         }
200
201         public float getRoll () {
202                 return 0;
203         }
204
205         public void getRotationMatrix (float[] matrix) {
206         }
207
208         public long getCurrentEventTime () {
209                 return processorQueue != null ? processorQueue.getCurrentEventTime() : currentEventTime;
210         }
211
212         public void setCatchBackKey (boolean catchBack) {
213         }
214
215         public void setCatchMenuKey (boolean catchMenu) {
216         }
217
218         public void setInputProcessor (InputProcessor processor) {
219                 this.processor = processor;
220         }
221
222         public InputProcessor getInputProcessor () {
223                 return processor;
224         }
225
226         public boolean isPeripheralAvailable (Peripheral peripheral) {
227                 return peripheral == Peripheral.HardwareKeyboard;
228         }
229
230         public int getRotation () {
231                 return 0;
232         }
233
234         public Orientation getNativeOrientation () {
235                 return Orientation.Landscape;
236         }
237
238         public void setCursorCatched (boolean captured) {
239                 glfwSetInputMode(app.graphics.window, GLFW_CURSOR_MODE, captured ? GLFW_CURSOR_CAPTURED : GLFW_CURSOR_NORMAL);
240         }
241
242         public boolean isCursorCatched () {
243                 return glfwGetInputMode(app.graphics.window, GLFW_CURSOR_MODE) == GLFW_CURSOR_CAPTURED;
244         }
245
246         public void setCursorPosition (int x, int y) {
247                 glfwSetCursorPos(app.graphics.window, x, y);
248         }
249
250         public void getTextInput (final TextInputListener listener, final String title, final String text) {
251                 SwingUtilities.invokeLater(new Runnable() {
252                         public void run () {
253                                 final String output = JOptionPane.showInputDialog(null, title, text);
254                                 app.postRunnable(new Runnable() {
255                                         public void run () {
256                                                 if (output != null)
257                                                         listener.input(output);
258                                                 else
259                                                         listener.canceled();
260                                         }
261                                 });
262                         }
263                 });
264         }
265
266         public void getPlaceholderTextInput (final TextInputListener listener, final String title, final String placeholder) {
267                 SwingUtilities.invokeLater(new Runnable() {
268                         public void run () {
269                                 JPanel panel = new JPanel(new FlowLayout());
270
271                                 JPanel textPanel = new JPanel() {
272                                         public boolean isOptimizedDrawingEnabled () {
273                                                 return false;
274                                         };
275                                 };
276                                 textPanel.setLayout(new OverlayLayout(textPanel));
277                                 panel.add(textPanel);
278
279                                 final JTextField textField = new JTextField(20);
280                                 textField.setAlignmentX(0.0f);
281                                 textPanel.add(textField);
282
283                                 final JLabel placeholderLabel = new JLabel(placeholder);
284                                 placeholderLabel.setForeground(Color.GRAY);
285                                 placeholderLabel.setAlignmentX(0.0f);
286                                 textPanel.add(placeholderLabel, 0);
287
288                                 textField.getDocument().addDocumentListener(new DocumentListener() {
289                                         public void removeUpdate (DocumentEvent event) {
290                                                 this.updated();
291                                         }
292
293                                         public void insertUpdate (DocumentEvent event) {
294                                                 this.updated();
295                                         }
296
297                                         public void changedUpdate (DocumentEvent event) {
298                                                 this.updated();
299                                         }
300
301                                         private void updated () {
302                                                 placeholderLabel.setVisible(textField.getText().length() == 0);
303                                         }
304                                 });
305
306                                 JOptionPane pane = new JOptionPane(panel, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null, null,
307                                         null);
308                                 pane.setComponentOrientation(JOptionPane.getRootFrame().getComponentOrientation());
309                                 pane.selectInitialValue();
310
311                                 placeholderLabel.setBorder(new EmptyBorder(textField.getBorder().getBorderInsets(textField)));
312
313                                 JDialog dialog = pane.createDialog(null, title);
314                                 dialog.addWindowFocusListener(new WindowFocusListener() {
315                                         public void windowLostFocus (WindowEvent arg0) {
316                                         }
317
318                                         public void windowGainedFocus (WindowEvent arg0) {
319                                                 textField.requestFocusInWindow();
320                                         }
321                                 });
322                                 dialog.setVisible(true);
323                                 dialog.dispose();
324
325                                 Object selectedValue = pane.getValue();
326                                 if (selectedValue != null && (selectedValue instanceof Integer) && (Integer)selectedValue == JOptionPane.OK_OPTION)
327                                         listener.input(textField.getText());
328                                 else
329                                         listener.canceled();
330                         }
331                 });
332         }
333
334         static char characterForKeyCode (int key) {
335                 // Map certain key codes to character codes.
336                 switch (key) {
337                 case Keys.BACKSPACE:
338                         return 8;
339                 case Keys.TAB:
340                         return '\t';
341                 case Keys.FORWARD_DEL:
342                         return 127;
343                 }
344                 return 0;
345         }
346
347         static public int getGdxKeyCode (int lwjglKeyCode) {
348                 switch (lwjglKeyCode) {
349                 case GLFW_KEY_LEFT_BRACKET:
350                         return Input.Keys.LEFT_BRACKET;
351                 case GLFW_KEY_RIGHT_BRACKET:
352                         return Input.Keys.RIGHT_BRACKET;
353                 case GLFW_KEY_GRAVE_ACCENT:
354                         return Input.Keys.GRAVE;
355                 case GLFW_KEY_KP_MULTIPLY:
356                         return Input.Keys.STAR;
357                 case GLFW_KEY_NUM_LOCK:
358                         return Input.Keys.NUM;
359                 case GLFW_KEY_KP_DECIMAL:
360                         return Input.Keys.PERIOD;
361                 case GLFW_KEY_KP_DIVIDE:
362                         return Input.Keys.SLASH;
363                 case GLFW_KEY_MENU:
364                         return Input.Keys.MENU;
365                 case GLFW_KEY_RIGHT_SUPER:
366                         return Input.Keys.SYM;
367                 case GLFW_KEY_LEFT_SUPER:
368                         return Input.Keys.SYM;
369                 case GLFW_KEY_KP_EQUAL:
370                         return Input.Keys.EQUALS;
371                 case GLFW_KEY_EQUAL:
372                         return Input.Keys.EQUALS;
373                 case GLFW_KEY_KP_ENTER:
374                         return Input.Keys.ENTER;
375                 case GLFW_KEY_0:
376                         return Input.Keys.NUM_0;
377                 case GLFW_KEY_1:
378                         return Input.Keys.NUM_1;
379                 case GLFW_KEY_2:
380                         return Input.Keys.NUM_2;
381                 case GLFW_KEY_3:
382                         return Input.Keys.NUM_3;
383                 case GLFW_KEY_4:
384                         return Input.Keys.NUM_4;
385                 case GLFW_KEY_5:
386                         return Input.Keys.NUM_5;
387                 case GLFW_KEY_6:
388                         return Input.Keys.NUM_6;
389                 case GLFW_KEY_7:
390                         return Input.Keys.NUM_7;
391                 case GLFW_KEY_8:
392                         return Input.Keys.NUM_8;
393                 case GLFW_KEY_9:
394                         return Input.Keys.NUM_9;
395                 case GLFW_KEY_A:
396                         return Input.Keys.A;
397                 case GLFW_KEY_B:
398                         return Input.Keys.B;
399                 case GLFW_KEY_C:
400                         return Input.Keys.C;
401                 case GLFW_KEY_D:
402                         return Input.Keys.D;
403                 case GLFW_KEY_E:
404                         return Input.Keys.E;
405                 case GLFW_KEY_F:
406                         return Input.Keys.F;
407                 case GLFW_KEY_G:
408                         return Input.Keys.G;
409                 case GLFW_KEY_H:
410                         return Input.Keys.H;
411                 case GLFW_KEY_I:
412                         return Input.Keys.I;
413                 case GLFW_KEY_J:
414                         return Input.Keys.J;
415                 case GLFW_KEY_K:
416                         return Input.Keys.K;
417                 case GLFW_KEY_L:
418                         return Input.Keys.L;
419                 case GLFW_KEY_M:
420                         return Input.Keys.M;
421                 case GLFW_KEY_N:
422                         return Input.Keys.N;
423                 case GLFW_KEY_O:
424                         return Input.Keys.O;
425                 case GLFW_KEY_P:
426                         return Input.Keys.P;
427                 case GLFW_KEY_Q:
428                         return Input.Keys.Q;
429                 case GLFW_KEY_R:
430                         return Input.Keys.R;
431                 case GLFW_KEY_S:
432                         return Input.Keys.S;
433                 case GLFW_KEY_T:
434                         return Input.Keys.T;
435                 case GLFW_KEY_U:
436                         return Input.Keys.U;
437                 case GLFW_KEY_V:
438                         return Input.Keys.V;
439                 case GLFW_KEY_W:
440                         return Input.Keys.W;
441                 case GLFW_KEY_X:
442                         return Input.Keys.X;
443                 case GLFW_KEY_Y:
444                         return Input.Keys.Y;
445                 case GLFW_KEY_Z:
446                         return Input.Keys.Z;
447                 case GLFW_KEY_LALT:
448                         return Input.Keys.ALT_LEFT;
449                 case GLFW_KEY_RALT:
450                         return Input.Keys.ALT_RIGHT;
451                 case GLFW_KEY_BACKSLASH:
452                         return Input.Keys.BACKSLASH;
453                 case GLFW_KEY_COMMA:
454                         return Input.Keys.COMMA;
455                 case GLFW_KEY_DELETE:
456                         return Input.Keys.FORWARD_DEL;
457                 case GLFW_KEY_LEFT:
458                         return Input.Keys.DPAD_LEFT;
459                 case GLFW_KEY_RIGHT:
460                         return Input.Keys.DPAD_RIGHT;
461                 case GLFW_KEY_UP:
462                         return Input.Keys.DPAD_UP;
463                 case GLFW_KEY_DOWN:
464                         return Input.Keys.DPAD_DOWN;
465                 case GLFW_KEY_ENTER:
466                         return Input.Keys.ENTER;
467                 case GLFW_KEY_HOME:
468                         return Input.Keys.HOME;
469                 case GLFW_KEY_MINUS:
470                         return Input.Keys.MINUS;
471                 case GLFW_KEY_PERIOD:
472                         return Input.Keys.PERIOD;
473                 case GLFW_KEY_KP_ADD:
474                         return Input.Keys.PLUS;
475                 case GLFW_KEY_SEMICOLON:
476                         return Input.Keys.SEMICOLON;
477                 case GLFW_KEY_LSHIFT:
478                         return Input.Keys.SHIFT_LEFT;
479                 case GLFW_KEY_RSHIFT:
480                         return Input.Keys.SHIFT_RIGHT;
481                 case GLFW_KEY_SLASH:
482                         return Input.Keys.SLASH;
483                 case GLFW_KEY_SPACE:
484                         return Input.Keys.SPACE;
485                 case GLFW_KEY_TAB:
486                         return Input.Keys.TAB;
487                 case GLFW_KEY_LEFT_CONTROL:
488                         return Input.Keys.CONTROL_LEFT;
489                 case GLFW_KEY_RIGHT_CONTROL:
490                         return Input.Keys.CONTROL_RIGHT;
491                 case GLFW_KEY_ESCAPE:
492                         return Input.Keys.ESCAPE;
493                 case GLFW_KEY_END:
494                         return Input.Keys.END;
495                 case GLFW_KEY_INSERT:
496                         return Input.Keys.INSERT;
497                 case GLFW_KEY_BACKSPACE:
498                         return Input.Keys.DEL;
499                 case GLFW_KEY_KP_SUBTRACT:
500                         return Input.Keys.MINUS;
501                 case GLFW_KEY_APOSTROPHE:
502                         return Input.Keys.APOSTROPHE;
503                 case GLFW_KEY_F1:
504                         return Input.Keys.F1;
505                 case GLFW_KEY_F2:
506                         return Input.Keys.F2;
507                 case GLFW_KEY_F3:
508                         return Input.Keys.F3;
509                 case GLFW_KEY_F4:
510                         return Input.Keys.F4;
511                 case GLFW_KEY_F5:
512                         return Input.Keys.F5;
513                 case GLFW_KEY_F6:
514                         return Input.Keys.F6;
515                 case GLFW_KEY_F7:
516                         return Input.Keys.F7;
517                 case GLFW_KEY_F8:
518                         return Input.Keys.F8;
519                 case GLFW_KEY_F9:
520                         return Input.Keys.F9;
521                 case GLFW_KEY_F10:
522                         return Input.Keys.F10;
523                 case GLFW_KEY_F11:
524                         return Input.Keys.F11;
525                 case GLFW_KEY_F12:
526                         return Input.Keys.F12;
527                 case GLFW_KEY_KP_0:
528                         return Input.Keys.NUM_0;
529                 case GLFW_KEY_KP_1:
530                         return Input.Keys.NUM_1;
531                 case GLFW_KEY_KP_2:
532                         return Input.Keys.NUM_2;
533                 case GLFW_KEY_KP_3:
534                         return Input.Keys.NUM_3;
535                 case GLFW_KEY_KP_4:
536                         return Input.Keys.NUM_4;
537                 case GLFW_KEY_KP_5:
538                         return Input.Keys.NUM_5;
539                 case GLFW_KEY_KP_6:
540                         return Input.Keys.NUM_6;
541                 case GLFW_KEY_KP_7:
542                         return Input.Keys.NUM_7;
543                 case GLFW_KEY_KP_8:
544                         return Input.Keys.NUM_8;
545                 case GLFW_KEY_KP_9:
546                         return Input.Keys.NUM_9;
547                 default:
548                         return Input.Keys.UNKNOWN;
549                 }
550         }
551
552         static public int getJglfwKeyCode (int gdxKeyCode) {
553                 switch (gdxKeyCode) {
554                 case Input.Keys.LEFT_BRACKET:
555                         return GLFW_KEY_LEFT_BRACKET;
556                 case Input.Keys.RIGHT_BRACKET:
557                         return GLFW_KEY_RIGHT_BRACKET;
558                 case Input.Keys.GRAVE:
559                         return GLFW_KEY_GRAVE_ACCENT;
560                 case Input.Keys.STAR:
561                         return GLFW_KEY_KP_MULTIPLY;
562                 case Input.Keys.NUM:
563                         return GLFW_KEY_NUM_LOCK;
564                 case Input.Keys.EQUALS:
565                         return GLFW_KEY_MENU;
566                 case Input.Keys.MENU:
567                         return GLFW_KEY_MENU;
568                 case Input.Keys.SYM:
569                         return GLFW_KEY_LEFT_SUPER;
570                 case Input.Keys.NUM_0:
571                         return GLFW_KEY_0;
572                 case Input.Keys.NUM_1:
573                         return GLFW_KEY_1;
574                 case Input.Keys.NUM_2:
575                         return GLFW_KEY_2;
576                 case Input.Keys.NUM_3:
577                         return GLFW_KEY_3;
578                 case Input.Keys.NUM_4:
579                         return GLFW_KEY_4;
580                 case Input.Keys.NUM_5:
581                         return GLFW_KEY_5;
582                 case Input.Keys.NUM_6:
583                         return GLFW_KEY_6;
584                 case Input.Keys.NUM_7:
585                         return GLFW_KEY_7;
586                 case Input.Keys.NUM_8:
587                         return GLFW_KEY_8;
588                 case Input.Keys.NUM_9:
589                         return GLFW_KEY_9;
590                 case Input.Keys.A:
591                         return GLFW_KEY_A;
592                 case Input.Keys.B:
593                         return GLFW_KEY_B;
594                 case Input.Keys.C:
595                         return GLFW_KEY_C;
596                 case Input.Keys.D:
597                         return GLFW_KEY_D;
598                 case Input.Keys.E:
599                         return GLFW_KEY_E;
600                 case Input.Keys.F:
601                         return GLFW_KEY_F;
602                 case Input.Keys.G:
603                         return GLFW_KEY_G;
604                 case Input.Keys.H:
605                         return GLFW_KEY_H;
606                 case Input.Keys.I:
607                         return GLFW_KEY_I;
608                 case Input.Keys.J:
609                         return GLFW_KEY_J;
610                 case Input.Keys.K:
611                         return GLFW_KEY_K;
612                 case Input.Keys.L:
613                         return GLFW_KEY_L;
614                 case Input.Keys.M:
615                         return GLFW_KEY_M;
616                 case Input.Keys.N:
617                         return GLFW_KEY_N;
618                 case Input.Keys.O:
619                         return GLFW_KEY_O;
620                 case Input.Keys.P:
621                         return GLFW_KEY_P;
622                 case Input.Keys.Q:
623                         return GLFW_KEY_Q;
624                 case Input.Keys.R:
625                         return GLFW_KEY_R;
626                 case Input.Keys.S:
627                         return GLFW_KEY_S;
628                 case Input.Keys.T:
629                         return GLFW_KEY_T;
630                 case Input.Keys.U:
631                         return GLFW_KEY_U;
632                 case Input.Keys.V:
633                         return GLFW_KEY_V;
634                 case Input.Keys.W:
635                         return GLFW_KEY_W;
636                 case Input.Keys.X:
637                         return GLFW_KEY_X;
638                 case Input.Keys.Y:
639                         return GLFW_KEY_Y;
640                 case Input.Keys.Z:
641                         return GLFW_KEY_Z;
642                 case Input.Keys.ALT_LEFT:
643                         return GLFW_KEY_LALT;
644                 case Input.Keys.ALT_RIGHT:
645                         return GLFW_KEY_RALT;
646                 case Input.Keys.BACKSLASH:
647                         return GLFW_KEY_BACKSLASH;
648                 case Input.Keys.COMMA:
649                         return GLFW_KEY_COMMA;
650                 case Input.Keys.FORWARD_DEL:
651                         return GLFW_KEY_DELETE;
652                 case Input.Keys.DPAD_LEFT:
653                         return GLFW_KEY_LEFT;
654                 case Input.Keys.DPAD_RIGHT:
655                         return GLFW_KEY_RIGHT;
656                 case Input.Keys.DPAD_UP:
657                         return GLFW_KEY_UP;
658                 case Input.Keys.DPAD_DOWN:
659                         return GLFW_KEY_DOWN;
660                 case Input.Keys.ENTER:
661                         return GLFW_KEY_ENTER;
662                 case Input.Keys.HOME:
663                         return GLFW_KEY_HOME;
664                 case Input.Keys.MINUS:
665                         return GLFW_KEY_MINUS;
666                 case Input.Keys.PERIOD:
667                         return GLFW_KEY_PERIOD;
668                 case Input.Keys.PLUS:
669                         return GLFW_KEY_KP_ADD;
670                 case Input.Keys.SEMICOLON:
671                         return GLFW_KEY_SEMICOLON;
672                 case Input.Keys.SHIFT_LEFT:
673                         return GLFW_KEY_LSHIFT;
674                 case Input.Keys.SHIFT_RIGHT:
675                         return GLFW_KEY_RSHIFT;
676                 case Input.Keys.SLASH:
677                         return GLFW_KEY_SLASH;
678                 case Input.Keys.SPACE:
679                         return GLFW_KEY_SPACE;
680                 case Input.Keys.TAB:
681                         return GLFW_KEY_TAB;
682                 case Input.Keys.DEL:
683                         return GLFW_KEY_BACKSPACE;
684                 case Input.Keys.CONTROL_LEFT:
685                         return GLFW_KEY_LEFT_CONTROL;
686                 case Input.Keys.CONTROL_RIGHT:
687                         return GLFW_KEY_RIGHT_CONTROL;
688                 case Input.Keys.ESCAPE:
689                         return GLFW_KEY_ESCAPE;
690                 case Input.Keys.F1:
691                         return GLFW_KEY_F1;
692                 case Input.Keys.F2:
693                         return GLFW_KEY_F2;
694                 case Input.Keys.F3:
695                         return GLFW_KEY_F3;
696                 case Input.Keys.F4:
697                         return GLFW_KEY_F4;
698                 case Input.Keys.F5:
699                         return GLFW_KEY_F5;
700                 case Input.Keys.F6:
701                         return GLFW_KEY_F6;
702                 case Input.Keys.F7:
703                         return GLFW_KEY_F7;
704                 case Input.Keys.F8:
705                         return GLFW_KEY_F8;
706                 case Input.Keys.F9:
707                         return GLFW_KEY_F9;
708                 case Input.Keys.F10:
709                         return GLFW_KEY_F10;
710                 case Input.Keys.F11:
711                         return GLFW_KEY_F11;
712                 case Input.Keys.F12:
713                         return GLFW_KEY_F12;
714                 default:
715                         return 0;
716                 }
717         }
718
719         /** Receives GLFW input and calls InputProcessor methods.
720          * @author Nathan Sweet */
721         static class GlfwInputProcessor extends GlfwCallbackAdapter {
722                 private int mouseX, mouseY, mousePressed;
723                 private char lastCharacter;
724                 private InputProcessor processor;
725
726                 public GlfwInputProcessor (InputProcessor processor) {
727                         if (processor == null) throw new IllegalArgumentException("processor cannot be null.");
728                         this.processor = processor;
729                 }
730
731                 public void key (long window, int key, int action) {
732                         switch (action) {
733                         case GLFW_PRESS:
734
735                                 key = getGdxKeyCode(key);
736                                 processor.keyDown(key);
737
738                                 lastCharacter = 0;
739                                 char character = characterForKeyCode(key);
740                                 if (character != 0) character(window, character);
741                                 break;
742
743                         case GLFW_RELEASE:
744                                 processor.keyUp(getGdxKeyCode(key));
745                                 break;
746
747                         case GLFW_REPEAT:
748                                 if (lastCharacter != 0) processor.keyTyped(lastCharacter);
749                                 break;
750                         }
751                 }
752
753                 public void character (long window, char character) {
754                         lastCharacter = character;
755                         processor.keyTyped(character);
756                 }
757
758                 public void scroll (long window, double scrollX, double scrollY) {
759                         processor.scrolled((int)-Math.signum(scrollY));
760                 }
761
762                 public void mouseButton (long window, int button, boolean pressed) {
763                         if (pressed) {
764                                 mousePressed++;
765                                 processor.touchDown(mouseX, mouseY, 0, button);
766                         } else {
767                                 mousePressed = Math.max(0, mousePressed - 1);
768                                 processor.touchUp(mouseX, mouseY, 0, button);
769                         }
770                 }
771
772                 public void cursorPos (long window, int x, int y) {
773                         mouseX = x;
774                         mouseY = y;
775                         if (mousePressed > 0)
776                                 processor.touchDragged(x, y, 0);
777                         else
778                                 processor.mouseMoved(x, y);
779                 }
780         }
781 }