Android: roughly fixed Fl::grab() to make menus easier to navigate

git-svn-id: file:///fltk/svn/fltk/branches/branch-1.4@12960 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
Matthias Melcher 2018-06-21 18:14:13 +00:00
parent 448cf77855
commit 7617a46b26
3 changed files with 141 additions and 68 deletions

View File

@ -17,81 +17,121 @@
#if 1
#include <FL/Fl.H>
#include <FL/Fl_Value_Input.H> // necessary for bug in mingw32?
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Scroll.H>
#include <FL/Fl_Light_Button.H>
#include <FL/Fl_Choice.H>
#include <FL/Fl_Box.H>
#include <FL/Fl_Hor_Value_Slider.H>
#include <FL/Fl_Toggle_Button.H>
#include <FL/Fl_Input.H>
#include <string.h>
#include <stdio.h>
#include <FL/fl_draw.H>
#include <FL/Fl_Output.H>
#include <FL/Fl_Multiline_Output.H>
#include <FL/math.h>
Fl_Output *text;
Fl_Multiline_Output *text2;
Fl_Input *input;
Fl_Value_Slider *fonts;
Fl_Value_Slider *sizes;
Fl_Double_Window *window;
class Drawing : public Fl_Widget {
void draw();
public:
Drawing(int X,int Y,int W,int H,const char* L) : Fl_Widget(X,Y,W,H,L) {
align(FL_ALIGN_TOP);
box(FL_FLAT_BOX);
color(FL_WHITE);
}
};
void font_cb(Fl_Widget *,void *) {
text->textfont(int(fonts->value()));
text->redraw();
text2->textfont(int(fonts->value()));
text2->redraw();
void Drawing::draw() {
draw_box();
fl_push_matrix();
fl_translate(x()+w()/2, y()+h()/2);
fl_scale(w()/2, h()/2);
fl_color(FL_BLACK);
for (int i = 0; i < 20; i++) {
for (int j = i+1; j < 20; j++) {
fl_begin_line();
fl_vertex(cos(M_PI*i/10+.1), sin(M_PI*i/10+.1));
fl_vertex(cos(M_PI*j/10+.1), sin(M_PI*j/10+.1));
fl_end_line();
}
}
fl_pop_matrix();
}
void size_cb(Fl_Widget *,void *) {
text->textsize(int(sizes->value()));
text->redraw();
text2->textsize(int(sizes->value()));
text2->redraw();
Fl_Scroll* thescroll;
void box_cb(Fl_Widget* o, void*) {
thescroll->box(((Fl_Button*)o)->value() ? FL_DOWN_FRAME : FL_NO_BOX);
thescroll->redraw();
}
void input_cb(Fl_Widget *,void *) {
text->value(input->value());
text2->value(input->value());
void type_cb(Fl_Widget*, void* v) {
thescroll->type((uchar)((fl_intptr_t)v));
thescroll->redraw();
}
Fl_Menu_Item choices[] = {
{"0", 0, type_cb, (void*)0},
{"HORIZONTAL", 0, type_cb, (void*)Fl_Scroll::HORIZONTAL},
{"VERTICAL", 0, type_cb, (void*)Fl_Scroll::VERTICAL},
{"BOTH", 0, type_cb, (void*)Fl_Scroll::BOTH},
{"HORIZONTAL_ALWAYS", 0, type_cb, (void*)Fl_Scroll::HORIZONTAL_ALWAYS},
{"VERTICAL_ALWAYS", 0, type_cb, (void*)Fl_Scroll::VERTICAL_ALWAYS},
{"BOTH_ALWAYS", 0, type_cb, (void*)Fl_Scroll::BOTH_ALWAYS},
{0}
};
void align_cb(Fl_Widget*, void* v) {
thescroll->scrollbar.align((uchar)((fl_intptr_t)v));
thescroll->redraw();
}
Fl_Menu_Item align_choices[] = {
{"left+top", 0, align_cb, (void*)(FL_ALIGN_LEFT+FL_ALIGN_TOP)},
{"left+bottom", 0, align_cb, (void*)(FL_ALIGN_LEFT+FL_ALIGN_BOTTOM)},
{"right+top", 0, align_cb, (void*)(FL_ALIGN_RIGHT+FL_ALIGN_TOP)},
{"right+bottom", 0, align_cb, (void*)(FL_ALIGN_RIGHT+FL_ALIGN_BOTTOM)},
{0}
};
int main(int argc, char** argv) {
window = new Fl_Double_Window(400,400);
Fl_Window window(5*75,400);
window.box(FL_NO_BOX);
Fl_Scroll scroll(0,0,5*75,300);
input = new Fl_Input(50,375,350,25);
input->static_value("The quick brown fox\njumped over\nthe lazy dog.");
input->when(FL_WHEN_CHANGED);
input->callback(input_cb);
int n = 0;
for (int y=0; y<16; y++) for (int x=0; x<5; x++) {
char buf[20]; sprintf(buf,"%d",n++);
Fl_Button* b = new Fl_Button(x*75,y*25+(y>=8?5*75:0),75,25);
b->copy_label(buf);
b->color(n);
b->labelcolor(FL_WHITE);
}
Drawing drawing(0,8*25,5*75,5*75,0);
scroll.end();
window.resizable(scroll);
sizes = new Fl_Hor_Value_Slider(50,350,350,25,"Size");
sizes->align(FL_ALIGN_LEFT);
sizes->bounds(1,64);
sizes->step(1);
sizes->value(14);
sizes->callback(size_cb);
Fl_Box box(0,300,5*75,window.h()-300); // gray area below the scroll
box.box(FL_FLAT_BOX);
fonts = new Fl_Hor_Value_Slider(50,325,350,25,"Font");
fonts->align(FL_ALIGN_LEFT);
fonts->bounds(0,15);
fonts->step(1);
fonts->value(0);
fonts->callback(font_cb);
Fl_Light_Button but1(150, 310, 200, 25, "box");
but1.callback(box_cb);
text2 = new Fl_Multiline_Output(100,150,200,100,"Fl_Multiline_Output");
text2->value(input->value());
text2->align(FL_ALIGN_BOTTOM);
text2->tooltip("This is an Fl_Multiline_Output widget.");
window->resizable(text2);
Fl_Choice choice(150, 335, 200, 25, "type():");
choice.menu(choices);
choice.value(3);
text = new Fl_Output(100,90,200,30,"Fl_Output");
text->value(input->value());
text->align(FL_ALIGN_BOTTOM);
text->tooltip("This is an Fl_Output widget.");
Fl_Choice achoice(150, 360, 200, 25, "scrollbar.align():");
achoice.menu(align_choices);
achoice.value(3);
window->end();
window->show(argc,argv);
thescroll = &scroll;
//scroll.box(FL_DOWN_BOX);
//scroll.type(Fl_Scroll::VERTICAL);
window.end();
window.show(argc,argv);
return Fl::run();
}
#else
#include <src/drivers/Android/Fl_Android_Application.H>
@ -226,6 +266,7 @@ int xmain(int argc, char **argv)
- scrolling if implemented as a complete redraw. Must implement real scrolling
- the 'hotspot' idea to position dialogs under the mouse cursor makes little sense on touch screen devices
- fix screen when keyboard pops up in front of the text cursor or input field (temporarily shift up?)
- ending 'message' will not quit the app right away, but wait for some timeout
test/CubeMain.cxx
@ -234,14 +275,10 @@ test/CubeView.cxx
test/list_visuals.cxx
test/mandelbrot.cxx
test/animated.cxx
test/menubar.cxx
test/message.cxx
test/bitmap.cxx
test/native-filechooser.cxx
test/blocks.cxx
test/navigation.cxx
test/offscreen.cxx
test/browser.cxx
test/overlay.cxx
test/cairo_test.cxx
test/pixmap.cxx
@ -298,7 +335,19 @@ test/input_choice.cxx
test/utf8.cxx
test/keyboard.cxx
test/windowfocus.cxx
test/browser.cxx
* test/scroll.cxx : - works ok
- some dirt when a popup draws over another menu button!?
- on touch-screens, menuitem should be selected when released
- on touch-screens, scroll groups should scroll on multitouch, or when not causing any other action
* test/bitmap.cxx : + 'bitmap' works
* test/message.cxx : - 'message' mostly works
- when ending the app, it will not close right away but instead hang around for a few seconds
* test/menubar.cxx : - 'menubar' mostly works including unicode
! pressing 'button' will hang the app
- shortcut modifiers don't work
- right-click does not work (should this be emulated via click-and-hold?)
* test/output.cxx : + 'output' works
* test/ask.cxx : + 'ask' works
* test/button.cxx : + 'button' works, including beep

View File

@ -101,15 +101,19 @@ public:
virtual int visual(int flags);
// --- screen configuration
virtual void init();
virtual int x();
virtual int y();
virtual int w();
virtual int h();
virtual void screen_xywh(int &X, int &Y, int &W, int &H, int n);
#endif
virtual int x() override { return 0; } // FIXME:
virtual int y() override { return 0; } // FIXME:
virtual int w() override { return 600; } // FIXME:
virtual int h() override { return 800; } // FIXME:
virtual void screen_xywh(int &X, int &Y, int &W, int &H, int n) override
{ X = 0; Y = 0; W = 600; H = 800; } // FIXME:
#if 0
virtual void screen_dpi(float &h, float &v, int n=0);
int screen_num_unscaled(int x, int y);
virtual void screen_work_area(int &X, int &Y, int &W, int &H, int n);
#endif
virtual void screen_work_area(int &X, int &Y, int &W, int &H, int n) override
{ X = 0; Y = 0; W = 600; H = 800; } // FIXME:
// --- audible output
virtual void beep(int type) override;
// --- global events
@ -117,7 +121,9 @@ public:
virtual double wait(double time_to_wait) override;
#if 0
virtual int ready();
virtual void grab(Fl_Window* win);
#endif
virtual void grab(Fl_Window* win) override;
#if 0
// --- global colors
virtual void get_system_colors();
virtual const char *get_system_scheme();

View File

@ -147,15 +147,17 @@ int Fl_Android_Screen_Driver::handle_mouse_event(AInputQueue *queue, AInputEvent
if (AMotionEvent_getAction(event) == AMOTION_EVENT_ACTION_DOWN) {
AInputQueue_finishEvent(queue, event, 1);
Fl::e_is_click = 1;
Fl_Android_Application::log_i("Mouse push %x %d at %d, %d", win, Fl::event_button(), Fl::event_x(), Fl::event_y());
if (win) Fl::handle(FL_PUSH, win); // do NOT send a push event into the "Desktop"
Fl_Android_Application::log_i("Mouse push %d at %d, %d", Fl::event_button(), Fl::event_x(), Fl::event_y());
} else if (AMotionEvent_getAction(event) == AMOTION_EVENT_ACTION_MOVE) {
AInputQueue_finishEvent(queue, event, 1);
Fl::handle(FL_DRAG, win);
Fl_Android_Application::log_i("Mouse drag %x %d at %d, %d", win, Fl::event_button(), Fl::event_x(), Fl::event_y());
if (win) Fl::handle(FL_DRAG, win);
} else if (AMotionEvent_getAction(event) == AMOTION_EVENT_ACTION_UP) {
AInputQueue_finishEvent(queue, event, 1);
Fl::e_state = 0;
Fl::handle(FL_RELEASE, win);
Fl_Android_Application::log_i("Mouse release %x %d at %d, %d", win, Fl::event_button(), Fl::event_x(), Fl::event_y());
if (win) Fl::handle(FL_RELEASE, win);
} else {
AInputQueue_finishEvent(queue, event, 0);
}
@ -504,6 +506,22 @@ int Fl_Android_Screen_Driver::get_mouse(int &x, int &y)
return 1;
}
void Fl_Android_Screen_Driver::grab(Fl_Window* win)
{
if (win) {
if (!Fl::grab_) {
// TODO: will we need to fix any focus and/or direct the input stream to a window
}
Fl::grab_ = win;
} else {
if (Fl::grab_) {
Fl::grab_ = 0;
}
}
}
//
// End of "$Id$".
//