You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

166 lines
4.9KB

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