2 // "$Id: navigation.cxx 8090 2010-12-21 02:37:41Z greg.ercolano $"
4 // Navigation test program for the Fast Light Tool Kit (FLTK).
6 // Silly test of navigation keys. This is not a recommended method of
7 // laying out your panels!
9 // Copyright 1998-2010 by Bill Spitzak and others.
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.
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.
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
26 // Please report all bugs and problems on the following page:
28 // http://www.fltk.org/str.php
34 #include <FL/Fl_Window.H>
35 #include <FL/Fl_Input.H>
36 #include <FL/Fl_Light_Button.H>
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);
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:
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
;
73 // skip if intersection:
74 if (n
< window
.children()) continue;
75 window
.insert(*(new Fl_Input(x
,y
,w
,h
)),j
);
77 window
.show(argc
, argv
);
82 // End of "$Id: navigation.cxx 8090 2010-12-21 02:37:41Z greg.ercolano $".