- extern float mnit_zoom;
-
- int mnit_orientation_changed;
- float mnit_zoom;
- int mnit_animating = 0;
-
- /* This is confusing; the type come from android_native_app_glue.h
- and so identifies the java part of the app */
- struct android_app *mnit_java_app;
-
- /* This is the pure Nit App */
- App nit_app;
-
- /* The main of the Nit application, compiled somewhere else */
- extern int main(int, char**);
-
- /* Wraps App_full_frame() and check for orientation. */
- void mnit_frame();
-
- void mnit_term_display()
- {
- // At this point we have nothing to do
- }
-
- /* Handle inputs from the Android platform and sort them before
- sending them in the Nit App */
- static int32_t mnit_handle_input(struct android_app* app, AInputEvent* event) {
- LOGI("handle input %i", (int)pthread_self());
- if (AInputEvent_getType(event) == AINPUT_EVENT_TYPE_KEY) {
- LOGI("key");
- return App_extern_input_key(nit_app, event);
- }
- else if (AInputEvent_getType(event) == AINPUT_EVENT_TYPE_MOTION) {
- LOGI("motion");
- return App_extern_input_motion(nit_app, event);
- }
-
- return 0;
- }
-
- static void mnit_handle_cmd(struct android_app* app, int32_t cmd) {
-
- mnit_java_app = app;
- AConfiguration_setOrientation(mnit_java_app->config, ACONFIGURATION_ORIENTATION_LAND);
- LOGI("cmd %i", (int)pthread_self());
-
- switch (cmd) {
- case APP_CMD_SAVE_STATE:
- LOGI ("save state");
- mnit_java_app->savedStateSize = 1;
- mnit_java_app->savedState = malloc(1);
- App_save(nit_app);
- break;
-
- case APP_CMD_INIT_WINDOW:
- LOGI ("init window");
- if (mnit_java_app->window != NULL) {
- LOGI("init window in");
- App_init_window(nit_app);
- mnit_frame();
- mnit_animating = 1;
- }
- break;
-
- case APP_CMD_TERM_WINDOW:
- LOGI ("term window");
- mnit_term_display();
- App_term_window(nit_app);
- break;
-
- case APP_CMD_GAINED_FOCUS:
- LOGI ("gain foc");
- mnit_animating = 1;
- App_gained_focus(nit_app);
- LOGI ("gain foc 1");
- break;
-
- case APP_CMD_LOST_FOCUS:
- LOGI ("lost foc");
- mnit_animating = 0;
- App_lost_focus(nit_app);
- mnit_frame();
- break;
-
- case APP_CMD_PAUSE:
- LOGI ("app pause");
- App_pause(nit_app);
- break;
-
- /*
- case APP_CMD_STOP:
- LOGI ("app stop");
- App_stop(nit_app);
- break;
-
- case APP_CMD_DESTROY:
- LOGI ("app destrop");
- App_destroy(nit_app);
- break;
-
- case APP_CMD_START:
- LOGI ("app start");
- App_start(nit_app);
- break;
- */
-
- case APP_CMD_RESUME:
- LOGI ("app resume");
- App_resume(nit_app);
- break;
-
- case APP_CMD_LOW_MEMORY:
- LOGI ("app low mem");
- break;
-
- case APP_CMD_CONFIG_CHANGED:
- LOGI ("app cmd conf ch");
- break;
-
- case APP_CMD_INPUT_CHANGED:
- LOGI ("app cmd in ch");
- break;
-
- case APP_CMD_WINDOW_RESIZED:
- mnit_orientation_changed = 1;
- LOGI ("app win res");
- break;
-
- case APP_CMD_WINDOW_REDRAW_NEEDED:
- LOGI ("app win redraw needed");
- break;
-
- case APP_CMD_CONTENT_RECT_CHANGED:
- LOGI ("app content rect ch");
- break;
- }
- }
-
- void android_main(struct android_app* app)
- {
- mnit_java_app = app;
-
- app_dummy();
-
- main(0, NULL);
- }
-
- void mnit_frame()
- {
- if (mnit_display == EGL_NO_DISPLAY) {
- LOGI("no frame");
- return;
- }
-
- if (mnit_orientation_changed)
- {
- mnit_orientation_changed = 0;
-
- if (mnit_surface != EGL_NO_SURFACE) {
- eglDestroySurface(mnit_display, mnit_surface);
- }
- EGLSurface surface = eglCreateWindowSurface(mnit_display, mnit_config, mnit_java_app->window, NULL);
-
- if (eglMakeCurrent(mnit_display, surface, surface, mnit_context) == EGL_FALSE) {
- LOGW("Unable to eglMakeCurrent");
- }
-
- eglQuerySurface(mnit_display, surface, EGL_WIDTH, &mnit_width);
- eglQuerySurface(mnit_display, surface, EGL_HEIGHT, &mnit_height);
-
- mnit_surface = surface;
-
- glViewport(0, 0, mnit_width, mnit_height);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glOrthof(0.0f, mnit_width, mnit_height, 0.0f, 0.0f, 1.0f);
- glMatrixMode(GL_MODELVIEW);
- }
-
- LOGI("frame");
-
- glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
- glClear(GL_COLOR_BUFFER_BIT); // | GL_DEPTH_BUFFER_BIT);
-
- App_full_frame(nit_app);
-
- LOGI("frame b");
- }