OSDN Git Service

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