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.

84 lines
3.0KB

  1. //
  2. // "$Id: navigation.cxx 8090 2010-12-21 02:37:41Z greg.ercolano $"
  3. //
  4. // Navigation test program for the Fast Light Tool Kit (FLTK).
  5. //
  6. // Silly test of navigation keys. This is not a recommended method of
  7. // laying out your panels!
  8. //
  9. // Copyright 1998-2010 by Bill Spitzak and others.
  10. //
  11. // This library is free software; you can redistribute it and/or
  12. // modify it under the terms of the GNU Library General Public
  13. // License as published by the Free Software Foundation; either
  14. // version 2 of the License, or (at your option) any later version.
  15. //
  16. // This library is distributed in the hope that it will be useful,
  17. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  19. // Library General Public License for more details.
  20. //
  21. // You should have received a copy of the GNU Library General Public
  22. // License along with this library; if not, write to the Free Software
  23. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  24. // USA.
  25. //
  26. // Please report all bugs and problems on the following page:
  27. //
  28. // http://www.fltk.org/str.php
  29. //
  30. #include <stdio.h>
  31. #include <stdlib.h>
  32. #include <FL/Fl.H>
  33. #include <FL/Fl_Window.H>
  34. #include <FL/Fl_Input.H>
  35. #include <FL/Fl_Light_Button.H>
  36. #define WIDTH 600
  37. #define HEIGHT 300
  38. #define GRID 25
  39. void ToggleArrowFocus_CB(Fl_Widget *w, void*) {
  40. Fl_Light_Button *b = (Fl_Light_Button*)w;
  41. Fl::option(Fl::OPTION_ARROW_FOCUS, b->value() ? true : false);
  42. }
  43. int main(int argc, char **argv) {
  44. if (argc > 1) srand(atoi(argv[1]));
  45. Fl_Window window(WIDTH,HEIGHT+40,argv[0]);
  46. // Include a toggle button to control arrow focus
  47. Fl_Light_Button arrowfocus_butt(10,HEIGHT+10,130,20," Arrow Focus");
  48. arrowfocus_butt.callback(ToggleArrowFocus_CB);
  49. arrowfocus_butt.value(Fl::option(Fl::OPTION_ARROW_FOCUS) ? 1 : 0); // use default
  50. arrowfocus_butt.tooltip("Control horizontal arrow key focus navigation behavior.\n"
  51. "e.g. Fl::OPTION_ARROW_FOCUS");
  52. window.end(); // don't auto-add children
  53. for (int i = 0; i<10000; i++) {
  54. // make up a random size of widget:
  55. int x = rand()%(WIDTH/GRID+1) * GRID;
  56. int y = rand()%(HEIGHT/GRID+1) * GRID;
  57. int w = rand()%(WIDTH/GRID+1) * GRID;
  58. if (w < x) {w = x-w; x-=w;} else {w = w-x;}
  59. int h = rand()%(HEIGHT/GRID+1) * GRID;
  60. if (h < y) {h = y-h; y-=h;} else {h = h-y;}
  61. if (w < GRID || h < GRID || w < h) continue;
  62. // find where to insert it and see if it intersects something:
  63. Fl_Widget *j = 0;
  64. int n; for (n=0; n < window.children(); n++) {
  65. Fl_Widget *o = window.child(n);
  66. if (x<o->x()+o->w() && x+w>o->x() &&
  67. y<o->y()+o->h() && y+h>o->y()) break;
  68. if ( !j && ( y<o->y() || (y==o->y() && x<o->x()) ) ) j = o;
  69. }
  70. // skip if intersection:
  71. if (n < window.children()) continue;
  72. window.insert(*(new Fl_Input(x,y,w,h)),j);
  73. }
  74. window.show(argc, argv);
  75. return Fl::run();
  76. }
  77. //
  78. // End of "$Id: navigation.cxx 8090 2010-12-21 02:37:41Z greg.ercolano $".
  79. //