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.

189 lines
5.3KB

  1. //
  2. // "$Id: label.cxx 7903 2010-11-28 21:06:39Z matt $"
  3. //
  4. // Label 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_Box.H>
  30. #include <FL/Fl_Hor_Value_Slider.H>
  31. #include <FL/Fl_Toggle_Button.H>
  32. #include <FL/Fl_Input.H>
  33. #include <FL/Fl_Choice.H>
  34. #include <FL/Fl_Pixmap.H>
  35. #include <FL/fl_draw.H>
  36. #include "pixmaps/blast.xpm"
  37. Fl_Toggle_Button *imageb, *imageovertextb, *imagenexttotextb, *imagebackdropb;
  38. Fl_Toggle_Button *leftb,*rightb,*topb,*bottomb,*insideb,*clipb,*wrapb;
  39. Fl_Box *text;
  40. Fl_Input *input;
  41. Fl_Hor_Value_Slider *fonts;
  42. Fl_Hor_Value_Slider *sizes;
  43. Fl_Double_Window *window;
  44. Fl_Pixmap *img;
  45. void button_cb(Fl_Widget *,void *) {
  46. int i = 0;
  47. if (leftb->value()) i |= FL_ALIGN_LEFT;
  48. if (rightb->value()) i |= FL_ALIGN_RIGHT;
  49. if (topb->value()) i |= FL_ALIGN_TOP;
  50. if (bottomb->value()) i |= FL_ALIGN_BOTTOM;
  51. if (insideb->value()) i |= FL_ALIGN_INSIDE;
  52. if (clipb->value()) i |= FL_ALIGN_CLIP;
  53. if (wrapb->value()) i |= FL_ALIGN_WRAP;
  54. if (imageovertextb->value()) i |= FL_ALIGN_TEXT_OVER_IMAGE;
  55. if (imagenexttotextb->value()) i |= FL_ALIGN_IMAGE_NEXT_TO_TEXT;
  56. if (imagebackdropb->value()) i |= FL_ALIGN_IMAGE_BACKDROP;
  57. text->align(i);
  58. window->redraw();
  59. }
  60. void image_cb(Fl_Widget *,void *) {
  61. if (imageb->value())
  62. text->image(img);
  63. else
  64. text->image(0);
  65. window->redraw();
  66. }
  67. void font_cb(Fl_Widget *,void *) {
  68. text->labelfont(int(fonts->value()));
  69. window->redraw();
  70. }
  71. void size_cb(Fl_Widget *,void *) {
  72. text->labelsize(int(sizes->value()));
  73. window->redraw();
  74. }
  75. void input_cb(Fl_Widget *,void *) {
  76. text->label(input->value());
  77. window->redraw();
  78. }
  79. void normal_cb(Fl_Widget *,void *) {
  80. text->labeltype(FL_NORMAL_LABEL);
  81. window->redraw();
  82. }
  83. void symbol_cb(Fl_Widget *,void *) {
  84. text->labeltype(FL_SYMBOL_LABEL);
  85. if (input->value()[0] != '@') {
  86. input->static_value("@->");
  87. text->label("@->");
  88. }
  89. window->redraw();
  90. }
  91. void shadow_cb(Fl_Widget *,void *) {
  92. text->labeltype(FL_SHADOW_LABEL);
  93. window->redraw();
  94. }
  95. void embossed_cb(Fl_Widget *,void *) {
  96. text->labeltype(FL_EMBOSSED_LABEL);
  97. window->redraw();
  98. }
  99. void engraved_cb(Fl_Widget *,void *) {
  100. text->labeltype(FL_ENGRAVED_LABEL);
  101. window->redraw();
  102. }
  103. Fl_Menu_Item choices[] = {
  104. {"FL_NORMAL_LABEL",0,normal_cb},
  105. {"FL_SYMBOL_LABEL",0,symbol_cb},
  106. {"FL_SHADOW_LABEL",0,shadow_cb},
  107. {"FL_ENGRAVED_LABEL",0,engraved_cb},
  108. {"FL_EMBOSSED_LABEL",0,embossed_cb},
  109. {0}};
  110. int main(int argc, char **argv) {
  111. img = new Fl_Pixmap(blast_xpm);
  112. window = new Fl_Double_Window(400,400);
  113. input = new Fl_Input(50,375,350,25);
  114. input->static_value("The quick brown fox jumped over the lazy dog.");
  115. input->when(FL_WHEN_CHANGED);
  116. input->callback(input_cb);
  117. sizes= new Fl_Hor_Value_Slider(50,350,350,25,"Size:");
  118. sizes->align(FL_ALIGN_LEFT);
  119. sizes->bounds(1,64);
  120. sizes->step(1);
  121. sizes->value(14);
  122. sizes->callback(size_cb);
  123. fonts=new Fl_Hor_Value_Slider(50,325,350,25,"Font:");
  124. fonts->align(FL_ALIGN_LEFT);
  125. fonts->bounds(0,15);
  126. fonts->step(1);
  127. fonts->value(0);
  128. fonts->callback(font_cb);
  129. Fl_Group *g = new Fl_Group(50,275,350,50);
  130. imageb = new Fl_Toggle_Button(50,275,50,25,"image");
  131. imageb->callback(image_cb);
  132. imageovertextb = new Fl_Toggle_Button(100,275,50,25,"I - T");
  133. imageovertextb->callback(button_cb);
  134. imagenexttotextb = new Fl_Toggle_Button(150,275,50,25,"I | T");
  135. imagenexttotextb->callback(button_cb);
  136. imagebackdropb = new Fl_Toggle_Button(200,275,50,25,"back");
  137. imagebackdropb->callback(button_cb);
  138. leftb = new Fl_Toggle_Button(50,300,50,25,"left");
  139. leftb->callback(button_cb);
  140. rightb = new Fl_Toggle_Button(100,300,50,25,"right");
  141. rightb->callback(button_cb);
  142. topb = new Fl_Toggle_Button(150,300,50,25,"top");
  143. topb->callback(button_cb);
  144. bottomb = new Fl_Toggle_Button(200,300,50,25,"bottom");
  145. bottomb->callback(button_cb);
  146. insideb = new Fl_Toggle_Button(250,300,50,25,"inside");
  147. insideb->callback(button_cb);
  148. wrapb = new Fl_Toggle_Button(300,300,50,25,"wrap");
  149. wrapb->callback(button_cb);
  150. clipb = new Fl_Toggle_Button(350,300,50,25,"clip");
  151. clipb->callback(button_cb);
  152. g->resizable(insideb);
  153. g->end();
  154. Fl_Choice *c = new Fl_Choice(50,250,200,25);
  155. c->menu(choices);
  156. text= new Fl_Box(FL_FRAME_BOX,100,75,200,100,input->value());
  157. text->align(FL_ALIGN_CENTER);
  158. window->resizable(text);
  159. window->end();
  160. window->show(argc,argv);
  161. return Fl::run();
  162. }
  163. //
  164. // End of "$Id: label.cxx 7903 2010-11-28 21:06:39Z matt $".
  165. //