1 | // |
---|
2 | // "$Id: navigation.cxx 8090 2010-12-21 02:37:41Z greg.ercolano $" |
---|
3 | // |
---|
4 | // Navigation test program for the Fast Light Tool Kit (FLTK). |
---|
5 | // |
---|
6 | // Silly test of navigation keys. This is not a recommended method of |
---|
7 | // laying out your panels! |
---|
8 | // |
---|
9 | // Copyright 1998-2010 by Bill Spitzak and others. |
---|
10 | // |
---|
11 | // This library is free software; you can redistribute it and/or |
---|
12 | // modify it under the terms of the GNU Library General Public |
---|
13 | // License as published by the Free Software Foundation; either |
---|
14 | // version 2 of the License, or (at your option) any later version. |
---|
15 | // |
---|
16 | // This library is distributed in the hope that it will be useful, |
---|
17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
19 | // Library General Public License for more details. |
---|
20 | // |
---|
21 | // You should have received a copy of the GNU Library General Public |
---|
22 | // License along with this library; if not, write to the Free Software |
---|
23 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
---|
24 | // USA. |
---|
25 | // |
---|
26 | // Please report all bugs and problems on the following page: |
---|
27 | // |
---|
28 | // http://www.fltk.org/str.php |
---|
29 | // |
---|
30 | |
---|
31 | #include <stdio.h> |
---|
32 | #include <stdlib.h> |
---|
33 | #include <FL/Fl.H> |
---|
34 | #include <FL/Fl_Window.H> |
---|
35 | #include <FL/Fl_Input.H> |
---|
36 | #include <FL/Fl_Light_Button.H> |
---|
37 | |
---|
38 | #define WIDTH 600 |
---|
39 | #define HEIGHT 300 |
---|
40 | #define GRID 25 |
---|
41 | |
---|
42 | void ToggleArrowFocus_CB(Fl_Widget *w, void*) { |
---|
43 | Fl_Light_Button *b = (Fl_Light_Button*)w; |
---|
44 | Fl::option(Fl::OPTION_ARROW_FOCUS, b->value() ? true : false); |
---|
45 | } |
---|
46 | int main(int argc, char **argv) { |
---|
47 | if (argc > 1) srand(atoi(argv[1])); |
---|
48 | Fl_Window window(WIDTH,HEIGHT+40,argv[0]); |
---|
49 | // Include a toggle button to control arrow focus |
---|
50 | Fl_Light_Button arrowfocus_butt(10,HEIGHT+10,130,20," Arrow Focus"); |
---|
51 | arrowfocus_butt.callback(ToggleArrowFocus_CB); |
---|
52 | arrowfocus_butt.value(Fl::option(Fl::OPTION_ARROW_FOCUS) ? 1 : 0); // use default |
---|
53 | arrowfocus_butt.tooltip("Control horizontal arrow key focus navigation behavior.\n" |
---|
54 | "e.g. Fl::OPTION_ARROW_FOCUS"); |
---|
55 | window.end(); // don't auto-add children |
---|
56 | for (int i = 0; i<10000; i++) { |
---|
57 | // make up a random size of widget: |
---|
58 | int x = rand()%(WIDTH/GRID+1) * GRID; |
---|
59 | int y = rand()%(HEIGHT/GRID+1) * GRID; |
---|
60 | int w = rand()%(WIDTH/GRID+1) * GRID; |
---|
61 | if (w < x) {w = x-w; x-=w;} else {w = w-x;} |
---|
62 | int h = rand()%(HEIGHT/GRID+1) * GRID; |
---|
63 | if (h < y) {h = y-h; y-=h;} else {h = h-y;} |
---|
64 | if (w < GRID || h < GRID || w < h) continue; |
---|
65 | // find where to insert it and see if it intersects something: |
---|
66 | Fl_Widget *j = 0; |
---|
67 | int n; for (n=0; n < window.children(); n++) { |
---|
68 | Fl_Widget *o = window.child(n); |
---|
69 | if (x<o->x()+o->w() && x+w>o->x() && |
---|
70 | y<o->y()+o->h() && y+h>o->y()) break; |
---|
71 | if ( !j && ( y<o->y() || (y==o->y() && x<o->x()) ) ) j = o; |
---|
72 | } |
---|
73 | // skip if intersection: |
---|
74 | if (n < window.children()) continue; |
---|
75 | window.insert(*(new Fl_Input(x,y,w,h)),j); |
---|
76 | } |
---|
77 | window.show(argc, argv); |
---|
78 | return Fl::run(); |
---|
79 | } |
---|
80 | |
---|
81 | // |
---|
82 | // End of "$Id: navigation.cxx 8090 2010-12-21 02:37:41Z greg.ercolano $". |
---|
83 | // |
---|