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.

145 lines
4.0KB

  1. //
  2. // "$Id: scroll.cxx 7978 2010-12-08 14:00:35Z AlbrechtS $"
  3. //
  4. // Fl_Scroll 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_Scroll.H>
  30. #include <FL/Fl_Light_Button.H>
  31. #include <FL/Fl_Choice.H>
  32. #include <FL/Fl_Box.H>
  33. #include <string.h>
  34. #include <stdio.h>
  35. #include <FL/fl_draw.H>
  36. #include <FL/math.h>
  37. class Drawing : public Fl_Widget {
  38. void draw();
  39. public:
  40. Drawing(int X,int Y,int W,int H,const char* L) : Fl_Widget(X,Y,W,H,L) {
  41. align(FL_ALIGN_TOP);
  42. box(FL_FLAT_BOX);
  43. color(FL_WHITE);
  44. }
  45. };
  46. void Drawing::draw() {
  47. draw_box();
  48. fl_push_matrix();
  49. fl_translate(x()+w()/2, y()+h()/2);
  50. fl_scale(w()/2, h()/2);
  51. fl_color(FL_BLACK);
  52. for (int i = 0; i < 20; i++) {
  53. for (int j = i+1; j < 20; j++) {
  54. fl_begin_line();
  55. fl_vertex(cos(M_PI*i/10+.1), sin(M_PI*i/10+.1));
  56. fl_vertex(cos(M_PI*j/10+.1), sin(M_PI*j/10+.1));
  57. fl_end_line();
  58. }
  59. }
  60. fl_pop_matrix();
  61. }
  62. Fl_Scroll* thescroll;
  63. void box_cb(Fl_Widget* o, void*) {
  64. thescroll->box(((Fl_Button*)o)->value() ? FL_DOWN_FRAME : FL_NO_BOX);
  65. thescroll->redraw();
  66. }
  67. void type_cb(Fl_Widget*, void* v) {
  68. thescroll->type((uchar)((fl_intptr_t)v));
  69. thescroll->redraw();
  70. }
  71. Fl_Menu_Item choices[] = {
  72. {"0", 0, type_cb, (void*)0},
  73. {"HORIZONTAL", 0, type_cb, (void*)Fl_Scroll::HORIZONTAL},
  74. {"VERTICAL", 0, type_cb, (void*)Fl_Scroll::VERTICAL},
  75. {"BOTH", 0, type_cb, (void*)Fl_Scroll::BOTH},
  76. {"HORIZONTAL_ALWAYS", 0, type_cb, (void*)Fl_Scroll::HORIZONTAL_ALWAYS},
  77. {"VERTICAL_ALWAYS", 0, type_cb, (void*)Fl_Scroll::VERTICAL_ALWAYS},
  78. {"BOTH_ALWAYS", 0, type_cb, (void*)Fl_Scroll::BOTH_ALWAYS},
  79. {0}
  80. };
  81. void align_cb(Fl_Widget*, void* v) {
  82. thescroll->scrollbar.align((uchar)((fl_intptr_t)v));
  83. thescroll->redraw();
  84. }
  85. Fl_Menu_Item align_choices[] = {
  86. {"left+top", 0, align_cb, (void*)(FL_ALIGN_LEFT+FL_ALIGN_TOP)},
  87. {"left+bottom", 0, align_cb, (void*)(FL_ALIGN_LEFT+FL_ALIGN_BOTTOM)},
  88. {"right+top", 0, align_cb, (void*)(FL_ALIGN_RIGHT+FL_ALIGN_TOP)},
  89. {"right+bottom", 0, align_cb, (void*)(FL_ALIGN_RIGHT+FL_ALIGN_BOTTOM)},
  90. {0}
  91. };
  92. int main(int argc, char** argv) {
  93. Fl_Window window(5*75,400);
  94. window.box(FL_NO_BOX);
  95. Fl_Scroll scroll(0,0,5*75,300);
  96. int n = 0;
  97. for (int y=0; y<16; y++) for (int x=0; x<5; x++) {
  98. char buf[20]; sprintf(buf,"%d",n++);
  99. Fl_Button* b = new Fl_Button(x*75,y*25+(y>=8?5*75:0),75,25);
  100. b->copy_label(buf);
  101. b->color(n);
  102. b->labelcolor(FL_WHITE);
  103. }
  104. Drawing drawing(0,8*25,5*75,5*75,0);
  105. scroll.end();
  106. window.resizable(scroll);
  107. Fl_Box box(0,300,5*75,window.h()-300); // gray area below the scroll
  108. box.box(FL_FLAT_BOX);
  109. Fl_Light_Button but1(150, 310, 200, 25, "box");
  110. but1.callback(box_cb);
  111. Fl_Choice choice(150, 335, 200, 25, "type():");
  112. choice.menu(choices);
  113. choice.value(3);
  114. Fl_Choice achoice(150, 360, 200, 25, "scrollbar.align():");
  115. achoice.menu(align_choices);
  116. achoice.value(3);
  117. thescroll = &scroll;
  118. //scroll.box(FL_DOWN_BOX);
  119. //scroll.type(Fl_Scroll::VERTICAL);
  120. window.end();
  121. window.show(argc,argv);
  122. return Fl::run();
  123. }
  124. //
  125. // End of "$Id: scroll.cxx 7978 2010-12-08 14:00:35Z AlbrechtS $".
  126. //