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.

240 lines
7.8KB

  1. //
  2. // "$Id: forms.cxx 7903 2010-11-28 21:06:39Z matt $"
  3. //
  4. // Another forms demo for the Fast Light Tool Kit (FLTK).
  5. //
  6. // This is an XForms program with very few changes.
  7. // Search for "fltk" to find all changes necessary to port to fltk.
  8. //
  9. // This demo show the different boxtypes. Note that some
  10. // boxtypes are not appropriate for some objects
  11. //
  12. // Copyright 1998-2010 by Bill Spitzak and others.
  13. //
  14. // This library is free software; you can redistribute it and/or
  15. // modify it under the terms of the GNU Library General Public
  16. // License as published by the Free Software Foundation; either
  17. // version 2 of the License, or (at your option) any later version.
  18. //
  19. // This library is distributed in the hope that it will be useful,
  20. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  22. // Library General Public License for more details.
  23. //
  24. // You should have received a copy of the GNU Library General Public
  25. // License along with this library; if not, write to the Free Software
  26. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  27. // USA.
  28. //
  29. // Please report all bugs and problems on the following page:
  30. //
  31. // http://www.fltk.org/str.php
  32. //
  33. #include <FL/forms.H> // changed for fltk
  34. static int border = 1; // changed from FL_TRANSIENT for fltk
  35. // (this is so the close box and Esc work to close the window)
  36. typedef struct { int val; const char *name; } VN_struct;
  37. #define VN(a) {a,#a}
  38. // static VN_struct gmode[] =
  39. // {
  40. // VN(StaticGray), VN(GrayScale), VN(StaticColor),
  41. // VN(PseudoColor), VN(TrueColor), VN(DirectColor),
  42. // };
  43. static VN_struct btypes[]=
  44. {
  45. {FL_NO_BOX,"no box"},
  46. {FL_UP_BOX, "up box"},
  47. {FL_DOWN_BOX,"down box"},
  48. {FL_BORDER_BOX,"border box"},
  49. {FL_SHADOW_BOX,"shadow box"},
  50. {FL_FLAT_BOX,"flat box"},
  51. {FL_FRAME_BOX,"frame box"},
  52. {FL_EMBOSSED_BOX,"embossed box"},
  53. {FL_ROUNDED_BOX,"rounded box"},
  54. {FL_RFLAT_BOX,"rflat box"},
  55. {FL_RSHADOW_BOX,"rshadow box"}, // renamed for fltk
  56. {FL_OVAL_BOX,"oval box"},
  57. {FL_ROUNDED3D_UPBOX,"rounded3d upbox"},
  58. {FL_ROUNDED3D_DOWNBOX,"rounded3d downbox"},
  59. {FL_OVAL3D_UPBOX,"oval3d upbox"},
  60. {FL_OVAL3D_DOWNBOX,"oval3d downbox"},
  61. {FL_PLASTIC_UP_BOX,"plastic upbox"},
  62. {FL_PLASTIC_DOWN_BOX,"plastic downbox"},
  63. {FL_GTK_UP_BOX,"GTK up box"},
  64. {FL_GTK_ROUND_UP_BOX,"GTK round up box"},
  65. /* sentinel */
  66. {-1}
  67. };
  68. #include "pixmaps/srs.xbm"
  69. /*************** Callback **********************/
  70. FL_FORM *form;
  71. Fl_Widget *tobj[18], *exitob, *btypeob, *modeob;
  72. void
  73. boxtype_cb (Fl_Widget * ob, long)
  74. {
  75. int i, req_bt = fl_get_choice(ob) - 1;
  76. static int lastbt = -1;
  77. if(lastbt != req_bt)
  78. {
  79. fl_freeze_form (form);
  80. fl_redraw_form (form);
  81. for (i = 0; i < 18; i++)
  82. fl_set_object_boxtype (tobj[i], (Fl_Boxtype)btypes[req_bt].val);
  83. fl_unfreeze_form (form);
  84. lastbt = req_bt;
  85. fl_redraw_form(form); // added for fltk
  86. }
  87. }
  88. void
  89. mode_cb (Fl_Widget *, long)
  90. {
  91. // static int lval = -1;
  92. // int val = fl_get_choice (ob) -1;
  93. // int db = 0;
  94. // if (val == lval || val < 0)
  95. // return;
  96. // fl_hide_form (form);
  97. // if (!fl_mode_capable (gmode[val].val, 0))
  98. // {
  99. // fl_set_choice(ob, lval);
  100. // val = lval;
  101. // }
  102. // fl_set_graphics_mode (gmode[val].val, db);
  103. // fl_show_form (form, FL_PLACE_GEOMETRY, border, "Box types");
  104. // lval = val;
  105. }
  106. /*************** Creation Routines *********************/
  107. void
  108. create_form_form (void)
  109. {
  110. Fl_Widget *obj;
  111. form = fl_bgn_form(FL_NO_BOX, 720, 520);
  112. obj = fl_add_box(FL_UP_BOX, 0, 0, 720, 520, "");
  113. fl_set_object_color(obj, FL_BLUE, FL_COL1);
  114. obj = fl_add_box(FL_DOWN_BOX, 10, 90, 700, 420, "");
  115. fl_set_object_color(obj, FL_COL1, FL_COL1);
  116. obj = fl_add_box(FL_DOWN_BOX, 10, 10, 700, 70, "");
  117. fl_set_object_color(obj, FL_SLATEBLUE, FL_COL1);
  118. tobj[0] = obj = fl_add_box(FL_UP_BOX, 30, 110, 110, 110, "Box");
  119. tobj[1] = obj = fl_add_text(FL_NORMAL_TEXT, 30, 240, 110, 30, "Text");
  120. tobj[2] = obj = fl_add_bitmap(FL_NORMAL_BITMAP, 40, 280, 90, 80, "Bitmap");
  121. fl_set_object_lcol(obj, FL_BLUE);
  122. tobj[3] = obj = fl_add_chart(FL_BAR_CHART, 160, 110, 160, 110, "Chart");
  123. tobj[4] = obj = fl_add_clock(FL_ANALOG_CLOCK, 40, 390, 90, 90, "Clock");
  124. //fl_set_object_dblbuffer(tobj[4],1); // removed for fltk
  125. tobj[5]=obj=fl_add_button(FL_NORMAL_BUTTON, 340, 110, 120, 30, "Button");
  126. tobj[6]=obj=fl_add_lightbutton(FL_PUSH_BUTTON,340,150,120,30,"Lightbutton");
  127. tobj[7]=obj=fl_add_roundbutton(FL_PUSH_BUTTON,340,190,120,30,"Roundbutton");
  128. tobj[8]=obj=fl_add_slider(FL_VERT_SLIDER, 160, 250, 40, 230, "Slider");
  129. tobj[9]=obj=fl_add_valslider(FL_VERT_SLIDER, 220, 250, 40, 230, "Valslider");
  130. tobj[10]=obj=fl_add_dial (FL_LINE_DIAL, 280, 250, 100, 100, "Dial");
  131. tobj[11]=obj=fl_add_positioner(FL_NORMAL_POSITIONER,280,380,150,100, "Positioner");
  132. tobj[12]=obj=fl_add_counter (FL_NORMAL_COUNTER,480,110,210,30, "Counter");
  133. tobj[13]=obj=fl_add_input (FL_NORMAL_INPUT, 520,170,170,30, "Input");
  134. tobj[14]=obj=fl_add_menu (FL_PUSH_MENU, 400, 240, 100, 30, "Menu");
  135. tobj[15]=obj=fl_add_choice (FL_NORMAL_CHOICE, 580, 250, 110, 30, "Choice");
  136. tobj[16]=obj=fl_add_timer (FL_VALUE_TIMER, 580, 210, 110, 30, "Timer");
  137. //fl_set_object_dblbuffer(tobj[16], 1); // removed for fltk
  138. tobj[17]=obj=fl_add_browser (FL_NORMAL_BROWSER,450,300,240, 180, "Browser");
  139. exitob=obj= fl_add_button (FL_NORMAL_BUTTON, 590, 30, 100, 30, "Exit");
  140. btypeob=obj= fl_add_choice (FL_NORMAL_CHOICE,110,30, 130, 30, "Boxtype");
  141. fl_set_object_callback (obj, boxtype_cb, 0);
  142. modeob = obj=fl_add_choice(FL_NORMAL_CHOICE,370,30,130,30,"Graphics mode");
  143. fl_set_object_callback (obj, mode_cb, 0);
  144. fl_end_form ();
  145. }
  146. /*---------------------------------------*/
  147. void
  148. create_the_forms (void)
  149. {
  150. create_form_form ();
  151. }
  152. /*************** Main Routine ***********************/
  153. const char *browserlines[] = {
  154. " ", "@C1@c@l@bObjects Demo", " ",
  155. "This demo shows you all", "objects that currently",
  156. "exist in the Forms Library.", " ",
  157. "You can change the boxtype", "of the different objects",
  158. "using the buttons at the", "top of the form. Note that",
  159. "some combinations might not", "look too good. Also realize",
  160. "that for all object classes", "many different types are",
  161. "available with different", "behaviour.", " ",
  162. "With this demo you can also", "see the effect of the drawing",
  163. "mode on the appearance of the","objects.",
  164. 0
  165. };
  166. int
  167. main (int argc, char *argv[])
  168. {
  169. FL_COLOR c = FL_BLACK;
  170. const char **p;
  171. VN_struct *vn;
  172. fl_initialize(&argc, argv, "FormDemo", 0, 0);
  173. create_the_forms ();
  174. fl_set_bitmap_data (tobj[2], sorceress_width, sorceress_height, sorceress_bits);
  175. fl_add_chart_value (tobj[3], 15, "item 1", c++);
  176. fl_add_chart_value (tobj[3], 5, "item 2", c++);
  177. fl_add_chart_value (tobj[3], -10, "item 3", c++);
  178. fl_add_chart_value (tobj[3], 25, "item 4", c++);
  179. fl_set_menu (tobj[14], "item 1|item 2|item 3|item 4|item 5");
  180. fl_addto_choice (tobj[15], "item 1");
  181. fl_addto_choice (tobj[15], "item 2");
  182. fl_addto_choice (tobj[15], "item 3");
  183. fl_addto_choice (tobj[15], "item 4");
  184. fl_addto_choice (tobj[15], "item 5");
  185. fl_set_timer (tobj[16], 1000.0);
  186. for ( p = browserlines; *p; p++)
  187. fl_add_browser_line (tobj[17], *p);
  188. for ( vn = btypes; vn->val >= 0; vn++)
  189. fl_addto_choice(btypeob, vn->name);
  190. // {
  191. // int i;
  192. // VN_struct *g = gmode, *gs = g + sizeof (gmode) / sizeof (gmode[0]);
  193. // for (i = 1; g < gs; g++, i++)
  194. // {
  195. // fl_addto_choice (modeob, g->name);
  196. // if(!fl_mode_capable(g->val, 0))
  197. // fl_set_choice_item_mode(modeob, i, FL_PUP_GRAY);
  198. // }
  199. // }
  200. // fl_set_choice (modeob, fl_vmode+1);
  201. fl_show_form (form, FL_PLACE_MOUSE, border, "Box types");
  202. while (fl_do_forms () != exitob)
  203. ;
  204. return 0;
  205. }
  206. //
  207. // End of "$Id: forms.cxx 7903 2010-11-28 21:06:39Z matt $".
  208. //