Use cairo to draw everything.
[ntk.git] / test / cursor.cxx
blobefc693a54f20c30afb5f122a83d1b4059670fabd
1 //
2 // "$Id: cursor.cxx 7978 2010-12-08 14:00:35Z AlbrechtS $"
3 //
4 // Cursor test program for the Fast Light Tool Kit (FLTK).
5 //
6 // Copyright 1998-2010 by Bill Spitzak and others.
7 //
8 // This library is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU Library General Public
10 // License as published by the Free Software Foundation; either
11 // version 2 of the License, or (at your option) any later version.
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Library General Public License for more details.
18 // You should have received a copy of the GNU Library General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
21 // USA.
23 // Please report all bugs and problems on the following page:
25 // http://www.fltk.org/str.php
28 #include <FL/Fl.H>
29 #include <FL/Fl_Double_Window.H>
30 #include <FL/Fl_Hor_Value_Slider.H>
31 #include <FL/Fl_Choice.H>
32 #include <FL/fl_draw.H>
33 #include <FL/Fl_Box.H>
35 Fl_Color fg = FL_BLACK;
36 Fl_Color bg = FL_WHITE;
37 Fl_Cursor cursor = FL_CURSOR_DEFAULT;
39 Fl_Hor_Value_Slider *cursor_slider;
41 void choice_cb(Fl_Widget *, void *v) {
42 cursor = (Fl_Cursor)(fl_intptr_t)v;
43 cursor_slider->value(cursor);
44 fl_cursor(cursor,fg,bg);
47 Fl_Menu_Item choices[] = {
48 {"FL_CURSOR_DEFAULT",0,choice_cb,(void*)FL_CURSOR_DEFAULT},
49 {"FL_CURSOR_ARROW",0,choice_cb,(void*)FL_CURSOR_ARROW},
50 {"FL_CURSOR_CROSS",0,choice_cb,(void*)FL_CURSOR_CROSS},
51 {"FL_CURSOR_WAIT",0,choice_cb,(void*)FL_CURSOR_WAIT},
52 {"FL_CURSOR_INSERT",0,choice_cb,(void*)FL_CURSOR_INSERT},
53 {"FL_CURSOR_HAND",0,choice_cb,(void*)FL_CURSOR_HAND},
54 {"FL_CURSOR_HELP",0,choice_cb,(void*)FL_CURSOR_HELP},
55 {"FL_CURSOR_MOVE",0,choice_cb,(void*)FL_CURSOR_MOVE},
56 {"FL_CURSOR_NS",0,choice_cb,(void*)FL_CURSOR_NS},
57 {"FL_CURSOR_WE",0,choice_cb,(void*)FL_CURSOR_WE},
58 {"FL_CURSOR_NWSE",0,choice_cb,(void*)FL_CURSOR_NWSE},
59 {"FL_CURSOR_NESW",0,choice_cb,(void*)FL_CURSOR_NESW},
60 {"FL_CURSOR_NONE",0,choice_cb,(void*)FL_CURSOR_NONE},
61 #if 0
62 {"FL_CURSOR_N",0,choice_cb,(void*)FL_CURSOR_N},
63 {"FL_CURSOR_NE",0,choice_cb,(void*)FL_CURSOR_NE},
64 {"FL_CURSOR_E",0,choice_cb,(void*)FL_CURSOR_E},
65 {"FL_CURSOR_SE",0,choice_cb,(void*)FL_CURSOR_SE},
66 {"FL_CURSOR_S",0,choice_cb,(void*)FL_CURSOR_S},
67 {"FL_CURSOR_SW",0,choice_cb,(void*)FL_CURSOR_SW},
68 {"FL_CURSOR_W",0,choice_cb,(void*)FL_CURSOR_W},
69 {"FL_CURSOR_NW",0,choice_cb,(void*)FL_CURSOR_NW},
70 #endif
71 {0}
74 void setcursor(Fl_Widget *o, void *) {
75 Fl_Hor_Value_Slider *slider = (Fl_Hor_Value_Slider *)o;
76 cursor = Fl_Cursor((int)slider->value());
77 fl_cursor(cursor,fg,bg);
80 void setfg(Fl_Widget *o, void *) {
81 Fl_Hor_Value_Slider *slider = (Fl_Hor_Value_Slider *)o;
82 fg = Fl_Color((int)slider->value());
83 fl_cursor(cursor,fg,bg);
86 void setbg(Fl_Widget *o, void *) {
87 Fl_Hor_Value_Slider *slider = (Fl_Hor_Value_Slider *)o;
88 bg = Fl_Color((int)slider->value());
89 fl_cursor(cursor,fg,bg);
92 // draw the label without any ^C or \nnn conversions:
93 class CharBox : public Fl_Box {
94 void draw() {
95 fl_font(FL_FREE_FONT,14);
96 fl_draw(label(), x()+w()/2, y()+h()/2);
98 public:
99 CharBox(int X, int Y, int W, int H, const char* L) : Fl_Box(X,Y,W,H,L) {}
102 int main(int argc, char **argv) {
103 Fl_Double_Window window(400,300);
105 Fl_Choice choice(80,100,200,25,"Cursor:");
106 choice.menu(choices);
107 choice.callback(choice_cb);
108 choice.when(FL_WHEN_RELEASE|FL_WHEN_NOT_CHANGED);
110 Fl_Hor_Value_Slider slider1(80,180,310,30,"Cursor:");
111 cursor_slider = &slider1;
112 slider1.align(FL_ALIGN_LEFT);
113 slider1.step(1);
114 slider1.precision(0);
115 slider1.bounds(0,100);
116 slider1.value(0);
117 slider1.callback(setcursor);
118 slider1.value(cursor);
120 Fl_Hor_Value_Slider slider2(80,220,310,30,"fgcolor:");
121 slider2.align(FL_ALIGN_LEFT);
122 slider2.step(1);
123 slider2.precision(0);
124 slider2.bounds(0,255);
125 slider2.value(0);
126 slider2.callback(setfg);
127 slider2.value(fg);
129 Fl_Hor_Value_Slider slider3(80,260,310,30,"bgcolor:");
130 slider3.align(FL_ALIGN_LEFT);
131 slider3.step(1);
132 slider3.precision(0);
133 slider3.bounds(0,255);
134 slider3.value(0);
135 slider3.callback(setbg);
136 slider3.value(bg);
138 #if 0
139 // draw the manual's diagram of cursors...
140 window.size(400,800);
141 int y = 300;
142 Fl::set_font(FL_FREE_FONT, "cursor");
143 char buf[100]; char *p = buf;
144 for (Fl_Menu* m = choices; m->label(); m++) {
145 Fl_Box* b = new Fl_Box(35,y,150,25,m->label());
146 b->align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE);
147 int n = (int)(m->argument());
148 if (n == FL_CURSOR_NONE) break;
149 if (n == FL_CURSOR_DEFAULT) n = FL_CURSOR_ARROW;
150 p[0] = (char)((n-1)*2);
151 p[1] = 0;
152 b = new CharBox(15,y,20,20,p); p+=2;
153 y += 25;
155 #endif
157 window.resizable(window);
158 window.end();
159 window.show(argc,argv);
160 return Fl::run();
164 // End of "$Id: cursor.cxx 7978 2010-12-08 14:00:35Z AlbrechtS $".