| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "embedders/openglui/emulator/emulator_embedder.h" | 5 #include "embedders/openglui/emulator/emulator_embedder.h" |
| 6 | 6 |
| 7 #include <string.h> | 7 #include <string.h> |
| 8 #include <sys/time.h> | 8 #include <sys/time.h> |
| 9 #include "embedders/openglui/common/canvas_context.h" | 9 #include "embedders/openglui/common/canvas_context.h" |
| 10 #include "embedders/openglui/common/context.h" | 10 #include "embedders/openglui/common/context.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 void reshape(int width, int height) { | 46 void reshape(int width, int height) { |
| 47 glViewport(0, 0, width, height); | 47 glViewport(0, 0, width, height); |
| 48 glMatrixMode(GL_PROJECTION); | 48 glMatrixMode(GL_PROJECTION); |
| 49 glLoadIdentity(); | 49 glLoadIdentity(); |
| 50 glOrtho(0, width, 0, height, -1, 1); | 50 glOrtho(0, width, 0, height, -1, 1); |
| 51 glMatrixMode(GL_MODELVIEW); | 51 glMatrixMode(GL_MODELVIEW); |
| 52 glutPostRedisplay(); | 52 glutPostRedisplay(); |
| 53 } | 53 } |
| 54 | 54 |
| 55 void keyboard(unsigned char key, int x, int y) { | 55 void keyboard(unsigned char key, int x, int y) { |
| 56 input_handler_ptr->OnKeyEvent(kKeyDown, time(0), 0, key, 0, 0); | 56 input_handler_ptr->OnKeyEvent(kKeyDown, time(0), key, false, false, false, 0); |
| 57 input_handler_ptr->OnKeyEvent(kKeyUp, time(0), 0, key, 0, 0); | 57 input_handler_ptr->OnKeyEvent(kKeyUp, time(0), key, false, false, false, 0); |
| 58 if (key == 27) { | 58 if (key == 27) { |
| 59 lifecycle_handler_ptr->Pause(); | 59 lifecycle_handler_ptr->Pause(); |
| 60 lifecycle_handler_ptr->Deactivate(); | 60 lifecycle_handler_ptr->Deactivate(); |
| 61 lifecycle_handler_ptr->FreeAllResources(); | 61 lifecycle_handler_ptr->FreeAllResources(); |
| 62 exit(0); | 62 exit(0); |
| 63 } else if (key == '0') { | 63 } else if (key == '0') { |
| 64 LOGI("Simulating suspend"); | 64 LOGI("Simulating suspend"); |
| 65 lifecycle_handler_ptr->Pause(); | 65 lifecycle_handler_ptr->Pause(); |
| 66 lifecycle_handler_ptr->Deactivate(); | 66 lifecycle_handler_ptr->Deactivate(); |
| 67 } else if (key == '1') { | 67 } else if (key == '1') { |
| 68 LOGI("Simulating resume"); | 68 LOGI("Simulating resume"); |
| 69 lifecycle_handler_ptr->Activate(); | 69 lifecycle_handler_ptr->Activate(); |
| 70 lifecycle_handler_ptr->Resume(); | 70 lifecycle_handler_ptr->Resume(); |
| 71 } else if (key == '+') { | 71 } else if (key == '+') { |
| 72 LOGI("Simulating focus gain"); | 72 LOGI("Simulating focus gain"); |
| 73 lifecycle_handler_ptr->Resume(); | 73 lifecycle_handler_ptr->Resume(); |
| 74 } else if (key == '-') { | 74 } else if (key == '-') { |
| 75 LOGI("Simulating focus loss"); | 75 LOGI("Simulating focus loss"); |
| 76 lifecycle_handler_ptr->Pause(); | 76 lifecycle_handler_ptr->Pause(); |
| 77 } | 77 } |
| 78 } | 78 } |
| 79 | 79 |
| 80 void mouse(int button, int state, int x, int y) { |
| 81 if (state == GLUT_UP) { |
| 82 input_handler_ptr->OnMotionEvent(kMotionUp, time(0), x, y); |
| 83 } else if (state == GLUT_DOWN) { |
| 84 input_handler_ptr->OnMotionEvent(kMotionDown, time(0), x, y); |
| 85 } |
| 86 } |
| 87 |
| 88 void motion(int x, int y) { |
| 89 input_handler_ptr->OnMotionEvent(kMotionMove, time(0), x, y); |
| 90 } |
| 91 |
| 80 DART_EXPORT void emulator_main(int argc, char** argv, const char* script) { | 92 DART_EXPORT void emulator_main(int argc, char** argv, const char* script) { |
| 81 EmulatorGraphicsHandler graphics_handler(argc, argv); | 93 EmulatorGraphicsHandler graphics_handler(argc, argv); |
| 82 if (argc > 0) { | 94 if (argc > 0) { |
| 83 int i = argc - 1; | 95 int i = argc - 1; |
| 84 size_t len = strlen(argv[i]); | 96 size_t len = strlen(argv[i]); |
| 85 if (len > 5 && strcmp(".dart", argv[i] + len - 5) == 0) { | 97 if (len > 5 && strcmp(".dart", argv[i] + len - 5) == 0) { |
| 86 script = argv[i]; | 98 script = argv[i]; |
| 87 } | 99 } |
| 88 } | 100 } |
| 89 VMGlue vm_glue(&graphics_handler, ".", "gl.dart", script); | 101 VMGlue vm_glue(&graphics_handler, ".", "gl.dart", script); |
| 90 InputHandler input_handler(&vm_glue); | 102 InputHandler input_handler(&vm_glue); |
| 91 input_handler_ptr = &input_handler; | 103 input_handler_ptr = &input_handler; |
| 92 SoundHandler sound_handler; | 104 SoundHandler sound_handler; |
| 93 Timer timer; | 105 Timer timer; |
| 94 Context app_context; | 106 Context app_context; |
| 95 app_context.graphics_handler = &graphics_handler; | 107 app_context.graphics_handler = &graphics_handler; |
| 96 app_context.input_handler = &input_handler; | 108 app_context.input_handler = &input_handler; |
| 97 app_context.sound_handler = &sound_handler; | 109 app_context.sound_handler = &sound_handler; |
| 98 app_context.timer = &timer; | 110 app_context.timer = &timer; |
| 99 app_context.vm_glue = &vm_glue; | 111 app_context.vm_glue = &vm_glue; |
| 100 DartHost host(&app_context); | 112 DartHost host(&app_context); |
| 101 lifecycle_handler_ptr = &host; | 113 lifecycle_handler_ptr = &host; |
| 102 glutReshapeFunc(reshape); | 114 glutReshapeFunc(reshape); |
| 103 glutDisplayFunc(display); | 115 glutDisplayFunc(display); |
| 104 glutKeyboardFunc(keyboard); | 116 glutKeyboardFunc(keyboard); |
| 117 glutMouseFunc(mouse); |
| 118 glutMotionFunc(motion); |
| 105 lifecycle_handler_ptr->OnStart(); | 119 lifecycle_handler_ptr->OnStart(); |
| 106 lifecycle_handler_ptr->Activate(); | 120 lifecycle_handler_ptr->Activate(); |
| 107 lifecycle_handler_ptr->Resume(); | 121 lifecycle_handler_ptr->Resume(); |
| 108 gettimeofday(&tvStart, NULL); | 122 gettimeofday(&tvStart, NULL); |
| 109 glutTimerFunc(1, tick, 0); | 123 glutTimerFunc(1, tick, 0); |
| 110 glutMainLoop(); | 124 glutMainLoop(); |
| 111 } | 125 } |
| 112 | 126 |
| OLD | NEW |