diff options
| author | Matthias Melcher <fltk@matthiasm.com> | 2018-03-03 14:05:18 +0000 |
|---|---|---|
| committer | Matthias Melcher <fltk@matthiasm.com> | 2018-03-03 14:05:18 +0000 |
| commit | 6ba638f5d6bbc27657ae8e21ad4996c60015d634 (patch) | |
| tree | bebc7a244940208188db5fc0f46a47d524c00272 /src/drivers/Android | |
| parent | 8bb4ab025d455f0d5bcaf8ae196f1651dc489028 (diff) | |
Android: need more source files
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.4@12705 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src/drivers/Android')
| -rw-r--r-- | src/drivers/Android/Fl_Android_Application.cpp | 5 | ||||
| -rw-r--r-- | src/drivers/Android/Fl_Android_Application.h | 8 | ||||
| -rw-r--r-- | src/drivers/Android/Fl_Android_Screen_Driver.H | 8 | ||||
| -rw-r--r-- | src/drivers/Android/Fl_Android_Screen_Driver.cxx | 124 |
4 files changed, 132 insertions, 13 deletions
diff --git a/src/drivers/Android/Fl_Android_Application.cpp b/src/drivers/Android/Fl_Android_Application.cpp new file mode 100644 index 000000000..5ab0c7993 --- /dev/null +++ b/src/drivers/Android/Fl_Android_Application.cpp @@ -0,0 +1,5 @@ +// +// Created by Matthias Melcher on 3/3/18. +// + +#include "Fl_Android_Application.h" diff --git a/src/drivers/Android/Fl_Android_Application.h b/src/drivers/Android/Fl_Android_Application.h new file mode 100644 index 000000000..7e7cba5aa --- /dev/null +++ b/src/drivers/Android/Fl_Android_Application.h @@ -0,0 +1,8 @@ +// +// Created by Matthias Melcher on 3/3/18. +// + +#ifndef HELLOANDROID_FL_ANDROID_APPLICATION_H +#define HELLOANDROID_FL_ANDROID_APPLICATION_H + +#endif //HELLOANDROID_FL_ANDROID_APPLICATION_H diff --git a/src/drivers/Android/Fl_Android_Screen_Driver.H b/src/drivers/Android/Fl_Android_Screen_Driver.H index ecbd87716..45f1ebee6 100644 --- a/src/drivers/Android/Fl_Android_Screen_Driver.H +++ b/src/drivers/Android/Fl_Android_Screen_Driver.H @@ -28,11 +28,17 @@ #include <FL/Fl_Screen_Driver.H> //#include <windows.h> +extern void (*fl_unlock_function)(); +extern void (*fl_lock_function)(); + + class Fl_Window; class FL_EXPORT Fl_Android_Screen_Driver : public Fl_Screen_Driver { +private: + int handle_queued_events(double time_to_wait); #if 0 @@ -74,7 +80,9 @@ public: virtual void beep(int type); // --- global events virtual void flush(); +#endif virtual double wait(double time_to_wait); +#if 0 virtual int ready(); virtual void grab(Fl_Window* win); // --- global colors diff --git a/src/drivers/Android/Fl_Android_Screen_Driver.cxx b/src/drivers/Android/Fl_Android_Screen_Driver.cxx index c8428a5f9..618718902 100644 --- a/src/drivers/Android/Fl_Android_Screen_Driver.cxx +++ b/src/drivers/Android/Fl_Android_Screen_Driver.cxx @@ -27,6 +27,20 @@ #include <FL/fl_ask.H> #include <stdio.h> +#include <android/log.h> + +#define LOG_TAG "FLTK" +#define LOGI(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__) +#define LOGW(...) __android_log_print(ANDROID_LOG_WARN,LOG_TAG,__VA_ARGS__) +#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__) +#define LOGV(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__) + +static struct android_app* gAndroidApp = 0L; + +static void nothing() {} +void (*fl_unlock_function)() = nothing; +void (*fl_lock_function)() = nothing; + #if 0 // these are set by Fl::args() and override any system colors: from Fl_get_system_colors.cxx @@ -53,6 +67,102 @@ Fl_Screen_Driver *Fl_Screen_Driver::newScreenDriver() return new Fl_Android_Screen_Driver(); } +int Fl_Android_Screen_Driver::handle_queued_events(double time_to_wait) +{ +/* + int ALooper_pollAll ( int timeoutMillis, + int * outFd, + int * outEvents, + void ** outData + ) + + struct engine engine; + + memset(&engine, 0, sizeof(engine)); + state->userData = &engine; + state->onAppCmd = engine_handle_cmd; + state->onInputEvent = engine_handle_input; + engine.app = state; + + struct timespec now; + clock_gettime(CLOCK_MONOTONIC, &now); + start_ms = (((int64_t)now.tv_sec)*1000000000LL + now.tv_nsec)/1000000; + + win = new Fl_Window(10, 10, 600, 400, "Hallo"); + btn = new Fl_Button(190, 200, 280, 35, "Hello, Android!"); + win->show(); + + + // loop waiting for stuff to do. + + while (1) { + // Read all pending events. + int ident; + int events; + struct android_poll_source* source; + + // If not animating, we will block forever waiting for events. + // If animating, we loop until all events are read, then continue + // to draw the next frame of animation. + while ((ident=ALooper_pollAll(engine.animating ? 0 : -1, NULL, &events, + (void**)&source)) >= 0) { + + // Process this event. + if (source != NULL) { + source->process(state, source); + } + + // Check if we are exiting. + if (state->destroyRequested != 0) { + LOGI("Engine thread destroy requested!"); + engine_term_display(&engine); + return; + } + } + + if (engine.animating) { + engine_draw_frame(&engine); + } + } + */ + return -1; +} + + +double Fl_Android_Screen_Driver::wait(double time_to_wait) +{ + Fl::run_checks(); + static int in_idle = 0; + if (Fl::idle) { + if (!in_idle) { + in_idle = 1; + Fl::idle(); + in_idle = 0; + } + // the idle function may turn off idle, we can then wait: + if (Fl::idle) time_to_wait = 0.0; + } + + if (time_to_wait==0.0) { + // if there is no wait time, handle the event and show the results right away + fl_unlock_function(); + handle_queued_events(time_to_wait); + fl_lock_function(); + Fl::flush(); + } else { + // if there is wait time, show the pending changes and then handle the events + Fl::flush(); + if (Fl::idle && !in_idle) // 'idle' may have been set within flush() + time_to_wait = 0.0; + fl_unlock_function(); + handle_queued_events(time_to_wait); + fl_lock_function(); + } + + return 0.0; // FIXME: return the remaining time to reach 'time_to_wait' +} + + #if 0 int Fl_WinAPI_Screen_Driver::visual(int flags) @@ -682,19 +792,6 @@ int Fl_WinAPI_Screen_Driver::screen_num_unscaled(int x, int y) #include <unistd.h> #include <sys/resource.h> -//#include "android_native_app_glue.h" -#include <android/log.h> - -#define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, "threaded_app", __VA_ARGS__)) -#define LOGE(...) ((void)__android_log_print(ANDROID_LOG_ERROR, "threaded_app", __VA_ARGS__)) - -/* For debug builds, always enable the debug traces in this library */ -#ifndef NDEBUG -# define LOGV(...) ((void)__android_log_print(ANDROID_LOG_VERBOSE, "threaded_app", __VA_ARGS__)) -#else -# define LOGV(...) ((void)0) -#endif - static void free_saved_state(struct android_app* android_app) { pthread_mutex_lock(&android_app->mutex); if (android_app->savedState != NULL) { @@ -902,6 +999,7 @@ static void* android_app_entry(void* param) { static struct android_app* android_app_create(ANativeActivity* activity, void* savedState, size_t savedStateSize) { struct android_app* android_app = (struct android_app*)malloc(sizeof(struct android_app)); + gAndroidApp = android_app; memset(android_app, 0, sizeof(struct android_app)); android_app->activity = activity; |
