Skip to content

Commit

Permalink
Android: Made Fl_Rect virtual. Maybe a bad idea?
Browse files Browse the repository at this point in the history
Also, added rectangular clipping which works.
Expanding now to a more complex clipping scheme to make multiple
windows work.

git-svn-id: file:///fltk/svn/fltk/branches/branch-1.4@12739 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
  • Loading branch information
Matthias Melcher committed Mar 11, 2018
1 parent 0b1fd7e commit 88ce4ae
Show file tree
Hide file tree
Showing 8 changed files with 268 additions and 111 deletions.
6 changes: 4 additions & 2 deletions FL/Fl_Rect.H
Expand Up @@ -60,14 +60,16 @@ public:
Fl_Rect (const Fl_Widget* const widget)
: x_(widget->x()), y_(widget->y()), w_(widget->w()), h_(widget->h()) {}

virtual ~Fl_Rect() { }

/** Return 1 if the rectangle is empty, width or height are 0 */
int is_empty() { return (w_<=0)||(h_<=0); }

/** Set the position and size */
void set(int x, int y, int w, int h) { x_=x; y_=y; w_=w; h_=h; }
virtual void set(int x, int y, int w, int h) { x_=x; y_=y; w_=w; h_=h; }

/** Clone another rectangle */
void set(Fl_Rect *r) { x_=r->x_; y_=r->y_; w_=r->w_; h_=r->h_; }
virtual void set(Fl_Rect *r) { x_=r->x_; y_=r->y_; w_=r->w_; h_=r->h_; }

/** return 0 if the rectangles are different, or 1 if they are the same */
int equals(int x, int y, int w, int h) { return ( (x_==x) && (y_==y) && (w_==w) && (h_==h) ); }
Expand Down
29 changes: 18 additions & 11 deletions ide/AndroidStudio3/app/src/main/cpp/HelloAndroid.cxx
Expand Up @@ -21,35 +21,42 @@
#include <FL/Enumerations.H>
#include <FL/fl_draw.H>

Fl_Window *win;

Fl_Window *win, *win2, *win3;
Fl_Button *btn;


class MyButton : public Fl_Button
{
public:
MyButton(int x, int y, int w, int h, const char *l) : Fl_Button(x, y, w, h, l) { }
void draw() {
fl_push_clip(x(), y(), w()/2, h()/2);
fl_push_clip(x(), y(), w()*2/3, h()*2/3);
Fl_Button::draw();
fl_pop_clip();
}
};

int h(void*, void*)
{
Fl_Android_Application::log_w("App global event %p", Fl::event());
return 0;
}

int main(int argc, char **argv)
{
Fl::add_system_handler(h, 0);
win = new Fl_Window(10, 10, 600, 400, "Hallo");
btn = new MyButton(190, 200, 280, 35, "Hello, Android!");
win2 = new Fl_Window(100, 50, 150, 200, "on bottom");
win2->color(FL_BLUE);
win2->end();
win2->show();

win = new Fl_Window(50, 150, 500, 400, "Hallo");
btn = new MyButton((win->w()-280)/2, 200, 280, 35, "Hello, Android!");
btn->color(FL_LIGHT2);
win->show(argc, argv);

/*
win3 = new Fl_Window(300, 50, 150, 200, "on top");
win3->color(FL_RED);
win3->end();
win3->show();
*/
Fl::run();

return 0;
}

35 changes: 16 additions & 19 deletions src/drivers/Android/Fl_Android_Application.cxx
Expand Up @@ -36,11 +36,9 @@

#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 const char *LOG_TAG = "FLTK";


// The ANativeActivity object instance that this app is running in.
ANativeActivity *Fl_Android_Application::pActivity = 0L;
Expand Down Expand Up @@ -175,7 +173,7 @@ int8_t Fl_Android_Application::read_cmd()
}
return cmd;
} else {
LOGE("No data on command pipe!");
log_e("No data on command pipe!");
}
return -1;
}
Expand All @@ -187,7 +185,7 @@ void Fl_Android_Application::print_cur_config()
AConfiguration_getLanguage(pConfig, lang);
AConfiguration_getCountry(pConfig, country);

LOGV("Config: mcc=%d mnc=%d lang=%c%c cnt=%c%c orien=%d touch=%d dens=%d "
log_v("Config: mcc=%d mnc=%d lang=%c%c cnt=%c%c orien=%d touch=%d dens=%d "
"keys=%d nav=%d keysHid=%d navHid=%d sdk=%d size=%d long=%d "
"modetype=%d modenight=%d",
AConfiguration_getMcc(pConfig),
Expand Down Expand Up @@ -216,14 +214,14 @@ void Fl_Android_Application::pre_exec_cmd(int8_t cmd)
{
switch (cmd) {
case APP_CMD_INPUT_CHANGED:
LOGV("APP_CMD_INPUT_CHANGED\n");
log_v("APP_CMD_INPUT_CHANGED\n");
pthread_mutex_lock(&pMutex);
if (pInputQueue != NULL) {
AInputQueue_detachLooper(pInputQueue);
}
pInputQueue = pPendingInputQueue;
if (pInputQueue != NULL) {
LOGV("Attaching input queue to looper");
log_v("Attaching input queue to looper");
AInputQueue_attachLooper(pInputQueue,
pMsgPipeLooper, LOOPER_ID_INPUT, NULL,
&pInputPollSource);
Expand All @@ -233,7 +231,7 @@ void Fl_Android_Application::pre_exec_cmd(int8_t cmd)
break;

case APP_CMD_INIT_WINDOW:
LOGV("APP_CMD_INIT_WINDOW\n");
log_v("APP_CMD_INIT_WINDOW\n");
// tell the main thread that we received the window handle
pthread_mutex_lock(&pMutex);
pNativeWindow = pPendingWindow;
Expand All @@ -250,30 +248,30 @@ void Fl_Android_Application::pre_exec_cmd(int8_t cmd)
break;

case APP_CMD_TERM_WINDOW:
LOGV("APP_CMD_TERM_WINDOW\n");
log_v("APP_CMD_TERM_WINDOW\n");
pthread_cond_broadcast(&pCond);
break;

case APP_CMD_RESUME:
case APP_CMD_START:
case APP_CMD_PAUSE:
case APP_CMD_STOP:
LOGV("activityState=%d\n", cmd);
log_v("activityState=%d\n", cmd);
pthread_mutex_lock(&pMutex);
pActivityState = cmd;
pthread_cond_broadcast(&pCond);
pthread_mutex_unlock(&pMutex);
break;

case APP_CMD_CONFIG_CHANGED:
LOGV("APP_CMD_CONFIG_CHANGED\n");
log_v("APP_CMD_CONFIG_CHANGED\n");
AConfiguration_fromAssetManager(pConfig,
pActivity->assetManager);
print_cur_config();
break;

case APP_CMD_DESTROY:
LOGV("APP_CMD_DESTROY\n");
log_v("APP_CMD_DESTROY\n");
pDestroyRequested = 1;
// FIXME: see Fl::program_should_quit()
break;
Expand All @@ -292,15 +290,15 @@ void Fl_Android_Application::post_exec_cmd(int8_t cmd)
{
switch (cmd) {
case APP_CMD_TERM_WINDOW:
LOGV("APP_CMD_TERM_WINDOW\n");
log_v("APP_CMD_TERM_WINDOW\n");
pthread_mutex_lock(&pMutex);
pNativeWindow = NULL;
pthread_cond_broadcast(&pCond);
pthread_mutex_unlock(&pMutex);
break;

case APP_CMD_SAVE_STATE:
LOGV("APP_CMD_SAVE_STATE\n");
log_v("APP_CMD_SAVE_STATE\n");
pthread_mutex_lock(&pMutex);
pStateSaved = 1;
pthread_cond_broadcast(&pCond);
Expand Down Expand Up @@ -334,7 +332,6 @@ void Fl_Android_Application::process_input(struct android_poll_source* source)
{
AInputEvent* event = NULL;
while (AInputQueue_getEvent(pInputQueue, &event) >= 0) {
//LOGV("New input event: type=%d\n", AInputEvent_getType(event));
if (AInputQueue_preDispatchEvent(pInputQueue, event)) {
continue;
}
Expand Down Expand Up @@ -502,7 +499,7 @@ bool Fl_Android_Application::screen_is_locked()
void Fl_Android_Activity::write_cmd(int8_t cmd)
{
if (write(pMsgWritePipe, &cmd, sizeof(cmd)) != sizeof(cmd)) {
LOGE("Failure writing android_app cmd: %s\n", strerror(errno));
log_e("Failure writing android_app cmd: %s\n", strerror(errno));
}
}

Expand Down Expand Up @@ -756,7 +753,7 @@ void Fl_Android_Activity::create(ANativeActivity* activity, void* savedState,

int msgpipe[2];
if (pipe(msgpipe)) {
LOGE("could not create pipe: %s", strerror(errno));
log_e("could not create pipe: %s", strerror(errno));
return;
}
pMsgReadPipe = msgpipe[0];
Expand Down
27 changes: 24 additions & 3 deletions src/drivers/Android/Fl_Android_Graphics_Driver.H
Expand Up @@ -30,6 +30,9 @@
#include <limits.h>


class Fl_Android_Window_Driver;


/**
* The Fl_Rect_Region is based on Fl_Rect with additional functionality for clipping.
*/
Expand All @@ -52,6 +55,8 @@ public:
*/
Fl_Rect_Region(int x, int y, int w, int h) : Fl_Rect(x, y, w, h) {}
int intersect_with(Fl_Rect_Region *r);
virtual void print();

static int min(int a, int b) { return (a<b) ? a : b; }
static int max(int a, int b) { return (a>b) ? a : b; }
};
Expand Down Expand Up @@ -79,10 +84,16 @@ public:
Fl_Complex_Region() : Fl_Rect_Region(), pSubregion(0L), pNext(0L) { }
Fl_Complex_Region(int x, int y, int w, int h) : Fl_Rect_Region(x, y, w, h), pSubregion(0L), pNext(0L) { }
~Fl_Complex_Region();
void set(Fl_Rect *rect);
virtual void set(int x, int y, int w, int h);
virtual void set(Fl_Rect *rect);
void subtract(Fl_Rect*);
void intersect(Fl_Rect*);
void clone(Fl_Complex_Region*);
char is_simple() { return pSubregion==0; }
char is_complex() { return pSubregion!=0; }
void print();
protected:
void print_data(int indent);
Fl_Complex_Region *pSubregion;
Fl_Complex_Region *pNext;
};
Expand Down Expand Up @@ -112,7 +123,8 @@ protected:
POINT *p;
#endif
public:
Fl_Android_Graphics_Driver() : pWindowRegion(0L) {}
Fl_Android_Graphics_Driver();
~Fl_Android_Graphics_Driver();
#if 0
Fl_GDI_Graphics_Driver() {mask_bitmap_ = NULL; gc_ = NULL; p_size = 0; p = NULL; depth = -1; origins = NULL;}
virtual ~Fl_GDI_Graphics_Driver() { if (p) free(p); delete[] origins;}
Expand Down Expand Up @@ -190,7 +202,6 @@ protected:
void restore_clip();
void clip_region(Fl_Region r);
Fl_Region clip_region();
Fl_Rect_Region *pWindowRegion;
#if 0
virtual Fl_Region scale_clip(float f);
// --- implementation is in src/fl_vertex.cxx which includes src/cfg_gfx/xxx_rect.cxx
Expand Down Expand Up @@ -227,6 +238,16 @@ protected:

#endif

int render_letter(int xx, int yy, uint32_t c);
void make_current(Fl_Window*);

int32_t pStride;
uint16_t *pBits;

// Fl_Rect_Region pScreenRegion;
Fl_Rect_Region *pWindowRegion;
Fl_Complex_Region *pDesktopRegion;
Fl_Complex_Region *pClippingRegion;
};


Expand Down

0 comments on commit 88ce4ae

Please sign in to comment.