home *** CD-ROM | disk | FTP | other *** search
/ OpenGL Superbible (2nd Edition) / OpenGL SuperBible e2.iso / tools / FLTK-1.0.6 / test / cursor.cxx < prev    next >
Encoding:
C/C++ Source or Header  |  1999-01-07  |  4.9 KB  |  164 lines

  1. //
  2. // "$Id: cursor.cxx,v 1.4 1999/01/07 19:17:52 mike Exp $"
  3. //
  4. // Cursor test program for the Fast Light Tool Kit (FLTK).
  5. //
  6. // Copyright 1998-1999 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.
  12. //
  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.
  17. //
  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.
  22. //
  23. // Please report all bugs and problems to "fltk-bugs@easysw.com".
  24. //
  25.  
  26. #include <FL/Fl.H>
  27. #include <FL/Fl_Window.H>
  28. #include <FL/Fl_Hor_Value_Slider.H>
  29. #include <FL/Fl_Choice.H>
  30. #include <FL/fl_draw.H>
  31. #include <FL/Fl_Box.H>
  32.  
  33. Fl_Color fg = FL_BLACK;
  34. Fl_Color bg = FL_WHITE;
  35. Fl_Cursor cursor = FL_CURSOR_DEFAULT;
  36.  
  37. Fl_Hor_Value_Slider *cursor_slider;
  38.  
  39. void choice_cb(Fl_Widget *, void *v) {
  40.   cursor = (Fl_Cursor)(int)v;
  41.   cursor_slider->value(cursor);
  42.   fl_cursor(cursor,fg,bg);
  43. }
  44.  
  45. Fl_Menu_Item choices[] = {
  46.   {"FL_CURSOR_DEFAULT",0,choice_cb,(void*)FL_CURSOR_DEFAULT},
  47.   {"FL_CURSOR_ARROW",0,choice_cb,(void*)FL_CURSOR_ARROW},
  48.   {"FL_CURSOR_CROSS",0,choice_cb,(void*)FL_CURSOR_CROSS},
  49.   {"FL_CURSOR_WAIT",0,choice_cb,(void*)FL_CURSOR_WAIT},
  50.   {"FL_CURSOR_INSERT",0,choice_cb,(void*)FL_CURSOR_INSERT},
  51.   {"FL_CURSOR_HAND",0,choice_cb,(void*)FL_CURSOR_HAND},
  52.   {"FL_CURSOR_HELP",0,choice_cb,(void*)FL_CURSOR_HELP},
  53.   {"FL_CURSOR_MOVE",0,choice_cb,(void*)FL_CURSOR_MOVE},
  54.   {"FL_CURSOR_NS",0,choice_cb,(void*)FL_CURSOR_NS},
  55.   {"FL_CURSOR_WE",0,choice_cb,(void*)FL_CURSOR_WE},
  56.   {"FL_CURSOR_NWSE",0,choice_cb,(void*)FL_CURSOR_NWSE},
  57.   {"FL_CURSOR_NESW",0,choice_cb,(void*)FL_CURSOR_NESW},
  58.   {"FL_CURSOR_NONE",0,choice_cb,(void*)FL_CURSOR_NONE},
  59. #if 0
  60.   {"FL_CURSOR_N",0,choice_cb,(void*)FL_CURSOR_N},
  61.   {"FL_CURSOR_NE",0,choice_cb,(void*)FL_CURSOR_NE},
  62.   {"FL_CURSOR_E",0,choice_cb,(void*)FL_CURSOR_E},
  63.   {"FL_CURSOR_SE",0,choice_cb,(void*)FL_CURSOR_SE},
  64.   {"FL_CURSOR_S",0,choice_cb,(void*)FL_CURSOR_S},
  65.   {"FL_CURSOR_SW",0,choice_cb,(void*)FL_CURSOR_SW},
  66.   {"FL_CURSOR_W",0,choice_cb,(void*)FL_CURSOR_W},
  67.   {"FL_CURSOR_NW",0,choice_cb,(void*)FL_CURSOR_NW},
  68. #endif
  69.   {0}
  70. };
  71.  
  72. void setcursor(Fl_Widget *o, void *) {
  73.   Fl_Hor_Value_Slider *slider = (Fl_Hor_Value_Slider *)o;
  74.   cursor = Fl_Cursor((int)slider->value());
  75.   fl_cursor(cursor,fg,bg);
  76. }
  77.  
  78. void setfg(Fl_Widget *o, void *) {
  79.   Fl_Hor_Value_Slider *slider = (Fl_Hor_Value_Slider *)o;
  80.   fg = Fl_Color((int)slider->value());
  81.   fl_cursor(cursor,fg,bg);
  82. }
  83.  
  84. void setbg(Fl_Widget *o, void *) {
  85.   Fl_Hor_Value_Slider *slider = (Fl_Hor_Value_Slider *)o;
  86.   bg = Fl_Color((int)slider->value());
  87.   fl_cursor(cursor,fg,bg);
  88. }
  89.  
  90. // draw the label without any ^C or \nnn conversions:
  91. class CharBox : public Fl_Box {
  92.   void draw() {
  93.     fl_font(FL_FREE_FONT,14);
  94.     fl_draw(label(), x()+w()/2, y()+h()/2);
  95.   }
  96. public:
  97.   CharBox(int X, int Y, int W, int H, const char* L) : Fl_Box(X,Y,W,H,L) {}
  98. };
  99.  
  100. int main(int argc, char **argv) {
  101.   Fl_Window window(400,300);
  102.  
  103.   Fl_Choice choice(80,100,200,25,"Cursor:");
  104.   choice.menu(choices);
  105.   choice.callback(choice_cb);
  106.   choice.when(FL_WHEN_RELEASE|FL_WHEN_NOT_CHANGED);
  107.  
  108.   Fl_Hor_Value_Slider slider1(80,180,310,30,"Cursor:");
  109.   cursor_slider = &slider1;
  110.   slider1.align(FL_ALIGN_LEFT);
  111.   slider1.step(1);
  112.   slider1.precision(0);
  113.   slider1.bounds(0,100);
  114.   slider1.value(0);
  115.   slider1.callback(setcursor);
  116.   slider1.value(cursor);
  117.  
  118.   Fl_Hor_Value_Slider slider2(80,220,310,30,"fgcolor:");
  119.   slider2.align(FL_ALIGN_LEFT);
  120.   slider2.step(1);
  121.   slider2.precision(0);
  122.   slider2.bounds(0,255);
  123.   slider2.value(0);
  124.   slider2.callback(setfg);
  125.   slider2.value(fg);
  126.  
  127.   Fl_Hor_Value_Slider slider3(80,260,310,30,"bgcolor:");
  128.   slider3.align(FL_ALIGN_LEFT);
  129.   slider3.step(1);
  130.   slider3.precision(0);
  131.   slider3.bounds(0,255);
  132.   slider3.value(0);
  133.   slider3.callback(setbg);
  134.   slider3.value(bg);
  135.  
  136. #if 0
  137.   // draw the manual's diagram of cursors...
  138.   window.size(400,800);
  139.   int y = 300;
  140.   Fl::set_font(FL_FREE_FONT, "cursor");
  141.   char buf[100]; char *p = buf;
  142.   for (Fl_Menu* m = choices; m->label(); m++) {
  143.     Fl_Box* b = new Fl_Box(35,y,150,25,m->label());
  144.     b->align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE);
  145.     int n = (int)(m->argument());
  146.     if (n == FL_CURSOR_NONE) break;
  147.     if (n == FL_CURSOR_DEFAULT) n = FL_CURSOR_ARROW;
  148.     p[0] = (char)((n-1)*2);
  149.     p[1] = 0;
  150.     b = new CharBox(15,y,20,20,p); p+=2;
  151.     y += 25;
  152.   }
  153. #endif
  154.  
  155.   window.resizable(window);
  156.   window.end();
  157.   window.show(argc,argv);
  158.   return Fl::run();
  159. }
  160.  
  161. //
  162. // End of "$Id: cursor.cxx,v 1.4 1999/01/07 19:17:52 mike Exp $".
  163. //
  164.