Blame test/navigation.cxx

Packit 328d5c
//
Packit 328d5c
// "$Id: navigation.cxx 8864 2011-07-19 04:49:30Z greg.ercolano $"
Packit 328d5c
//
Packit 328d5c
// Navigation test program for the Fast Light Tool Kit (FLTK).
Packit 328d5c
//
Packit 328d5c
// Silly test of navigation keys. This is not a recommended method of
Packit 328d5c
// laying out your panels!
Packit 328d5c
//
Packit 328d5c
// Copyright 1998-2010 by Bill Spitzak and others.
Packit 328d5c
//
Packit 328d5c
// This library is free software. Distribution and use rights are outlined in
Packit 328d5c
// the file "COPYING" which should have been included with this file.  If this
Packit 328d5c
// file is missing or damaged, see the license at:
Packit 328d5c
//
Packit 328d5c
//     http://www.fltk.org/COPYING.php
Packit 328d5c
//
Packit 328d5c
// Please report all bugs and problems on the following page:
Packit 328d5c
//
Packit 328d5c
//     http://www.fltk.org/str.php
Packit 328d5c
//
Packit 328d5c
Packit 328d5c
#include <stdio.h>
Packit 328d5c
#include <stdlib.h>
Packit 328d5c
#include <FL/Fl.H>
Packit 328d5c
#include <FL/Fl_Window.H>
Packit 328d5c
#include <FL/Fl_Input.H>
Packit 328d5c
#include <FL/Fl_Light_Button.H>
Packit 328d5c
Packit 328d5c
#define WIDTH 600
Packit 328d5c
#define HEIGHT 300
Packit 328d5c
#define GRID 25
Packit 328d5c
Packit 328d5c
void ToggleArrowFocus_CB(Fl_Widget *w, void*) {
Packit 328d5c
  Fl_Light_Button *b = (Fl_Light_Button*)w;
Packit 328d5c
  Fl::option(Fl::OPTION_ARROW_FOCUS, b->value() ? true : false);
Packit 328d5c
}
Packit 328d5c
int main(int argc, char **argv) {
Packit 328d5c
  if (argc > 1) srand(atoi(argv[1]));
Packit 328d5c
  Fl_Window window(WIDTH,HEIGHT+40,argv[0]);
Packit 328d5c
    // Include a toggle button to control arrow focus
Packit 328d5c
    Fl_Light_Button arrowfocus_butt(10,HEIGHT+10,130,20," Arrow Focus");
Packit 328d5c
    arrowfocus_butt.callback(ToggleArrowFocus_CB);
Packit 328d5c
    arrowfocus_butt.value(Fl::option(Fl::OPTION_ARROW_FOCUS) ? 1 : 0);	// use default
Packit 328d5c
    arrowfocus_butt.tooltip("Control horizontal arrow key focus navigation behavior.\n"
Packit 328d5c
                            "e.g. Fl::OPTION_ARROW_FOCUS");
Packit 328d5c
  window.end(); // don't auto-add children
Packit 328d5c
  for (int i = 0; i<10000; i++) {
Packit 328d5c
    // make up a random size of widget:
Packit 328d5c
    int x = rand()%(WIDTH/GRID+1) * GRID;
Packit 328d5c
    int y = rand()%(HEIGHT/GRID+1) * GRID;
Packit 328d5c
    int w = rand()%(WIDTH/GRID+1) * GRID;
Packit 328d5c
    if (w < x) {w = x-w; x-=w;} else {w = w-x;}
Packit 328d5c
    int h = rand()%(HEIGHT/GRID+1) * GRID;
Packit 328d5c
    if (h < y) {h = y-h; y-=h;} else {h = h-y;}
Packit 328d5c
    if (w < GRID || h < GRID || w < h) continue;
Packit 328d5c
    // find where to insert it and see if it intersects something:
Packit 328d5c
    Fl_Widget *j = 0;
Packit 328d5c
    int n; for (n=0; n < window.children(); n++) {
Packit 328d5c
      Fl_Widget *o = window.child(n);
Packit 328d5c
      if (x<o->x()+o->w() && x+w>o->x() &&
Packit 328d5c
	  y<o->y()+o->h() && y+h>o->y()) break;
Packit 328d5c
      if ( !j && ( y<o->y() || (y==o->y() && x<o->x()) ) ) j = o;
Packit 328d5c
    }
Packit 328d5c
    // skip if intersection:
Packit 328d5c
    if (n < window.children()) continue;
Packit 328d5c
    window.insert(*(new Fl_Input(x,y,w,h)),j);
Packit 328d5c
  }
Packit 328d5c
  window.show(argc, argv);
Packit 328d5c
  return Fl::run();
Packit 328d5c
}
Packit 328d5c
Packit 328d5c
//
Packit 328d5c
// End of "$Id: navigation.cxx 8864 2011-07-19 04:49:30Z greg.ercolano $".
Packit 328d5c
//