DO NOT REPLY TO THIS MESSAGE.  INSTEAD, POST ANY RESPONSES TO THE LINK BELOW.

[STR New]

Link: http://www.fltk.org/str.php?L2409
Version: 1.3-feature





Link: http://www.fltk.org/str.php?L2409
Version: 1.3-feature
/*
==============================================================================

    Modified Fl_Scroll test program for the Fast Light Tool Kit (FLTK).
    Version 2: dynamic loading and deleting of widgets

    compile and link with: fltk-config --compile scroll_2.cxx

    Use the "buttons" slider to adjust the number of buttons to test.
    Then click on the "create buttons" button.

    There are some interesting test cases:

    (1) click on "Fl_Scroll::clear" or "Fl_Group::clear" buttons, resp.,
    (2) click on any button within the Fl_Scroll group, or
    (3) move the focus to the "Fl_Group::clear" button (e.g. by pressing
        SHIFT/TAB multiple times), the move the mouse over the buttons
        w/o clicking, and then press <SPACE> to fire the "Fl_Group::clear"
        button.

    Watch the "time" display for each action. There can be really big
    differences from something like 0.05 seconds up to 5 seconds or more
    (maybe more than a minute on older hardware). Don't use too big numbers
    of buttons, if you're not sure with your hardware.

    There are also printf statements that show some progress information,
    but some Windows configurations may hide these (Cygwin and MinGW are
    known to work with stdout output, whereas VC does not!).

    Then, use the suggested patch and try again...

    Note: My tests, as of Aug 24, 2010, show delays of about 4 seconds with
    100,000 buttons with FLTK 1.3 (r 7687), but only about 0.04 seconds or
    less with the preliminary patch (Windows 7, Intel Core i5, 3.2 GHz).

==============================================================================
*/

#include <FL/Fl.H>
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Scroll.H>
#include <FL/Fl_Scrollbar.H>
#include <FL/Fl_Button.H>
#include <FL/Fl_Check_Button.H>
#include <FL/Fl_Value_Slider.H>
#include <FL/Fl_Output.H>
#include <FL/fl_ask.h>

#include <time.h>
#include <sys/timeb.h>
#include <stdio.h>

#include <string.h>
#include <stdio.h>

#include <Windows.h>

static char *mytime (double *secs)
{
  static char tbuf[40];
  struct timeb  ctime;
  struct tm     *lt;
  ftime (&ctime);
  lt = localtime (&ctime.time);
  sprintf (tbuf,"%2.2d:%2.2d:%2.2d.%3.3d",
                lt->tm_hour,
                lt->tm_min,
                lt->tm_sec,
                ctime.millitm);
  if (secs) { // return seconds and milliseconds
    *secs = (double)lt->tm_min*60.0 + (double)lt->tm_sec + 
((double)ctime.millitm)/1000.0;
  }
  return tbuf;
}

Fl_Scroll* thescroll = 0;
Fl_Scrollbar* hsb = 0;
Fl_Scrollbar* vsb = 0;
Fl_Value_Slider *numb = 0;
Fl_Check_Button *cq = 0;
Fl_Output *dtime = 0;

double start, end, delta;

static void set_time() {
  char buf[30];
  delta = end - start;
  if (delta<0) delta += 3600.0;
  sprintf (buf,"%5.3f sec.",delta);
  dtime->value(buf);
  printf ("--> delta time = %5.3f sec.\n",delta);
}

void clear_cb(Fl_Widget*, void* v);

void reset_cb(Fl_Widget*, void* v) {

  // printf ("reset_cb: %s - started,  
children=%6d\n",mytime(&start),thescroll->children());

  if (thescroll->children() > 2) {
    fl_alert("You must clear the scroll group first");
    return;
  }

  int nw = (int)numb->value();
  if (nw < 10 || nw > 100000) nw = 20000;
  Fl_Group *curr = Fl_Group::current();
  thescroll->begin();
  int n = 0;
  for (int y=0; y<(nw+99)/100; y++) for (int x=0; x<100; x++) {
    char buf[20]; sprintf(buf,"%d",n++);
    Fl_Button* b = new Fl_Button(x*60,y*20,60,20);
    b->copy_label(buf);
    b->color(n%128);
    b->labelcolor(FL_WHITE);
    b->callback(clear_cb,(void*)1);
    // b->when(FL_WHEN_CHANGED); // optional: callback on FL_PUSH event
    if (n > nw) break;
  }
  Fl_Group::current(curr);

  // printf ("reset_cb: %s - finished, 
children=%6d\n",mytime(&end),thescroll->children());
  // set_time();
}

void clear_cb(Fl_Widget* me, void* v) {

  printf ("\nclear_cb: %s (%p) [%s]\n",mytime(0),me,me->label());

  dtime->value("..."); dtime->redraw(); Fl::flush();

  int use_group = (int)v;

  if (cq->value()) {
    int i;
    for (i=0; i<99; i++)
      if (!Fl::readqueue()) break;
    printf ("Fl::readqueue() - flushed %d entries\n",i);
  }

  printf ("clear_cb: %s - started,  
children=%6d\n",mytime(&start),thescroll->children());

  if (use_group) {
    thescroll->remove(hsb);
    thescroll->remove(vsb);
    thescroll->Fl_Group::clear();
    thescroll->add(hsb);
    thescroll->add(vsb);
  } else {
    thescroll->clear();
  }
  printf ("clear_cb: %s - finished, 
children=%6d\n",mytime(&end),thescroll->children());
  set_time();
  if (thescroll->children()>2)
    printf ("child(2)->label = \"%s\"\n",thescroll->child(2)->label());
  thescroll->redraw();
  printf ("clear_cb(%p) --- DONE ---\n",me);
}

int main(int argc, char** argv) {

  setvbuf (stdout,NULL,_IONBF,0); // set stdout unbuffered (for Cygwin)
  Fl_Window window(600,420);
  Fl_Scroll scroll(0,0,600,300);
  thescroll = &scroll;
  hsb = &thescroll->hscrollbar;
  vsb = &thescroll->scrollbar;
  scroll.end();
  scroll.type(Fl_Scroll::BOTH);
  scroll.box(FL_DOWN_BOX);
  window.resizable(scroll);

  Fl_Button *clear0 = new Fl_Button (20,320,120,20,"Fl_Scroll::clear");
  clear0->callback(clear_cb,(void*)0);

  Fl_Button *clear1 = new Fl_Button (20,350,120,20,"Fl_Group::clear");
  clear1->callback(clear_cb,(void*)1);

  cq = new Fl_Check_Button (20,380,160,20,"clear Fl::readqueue");
  cq->value(0);

  dtime = new Fl_Output (200,350,80,20,"time:");
  dtime->value("");

  numb = new Fl_Value_Slider (380,320,200,25,"buttons:");
  numb->minimum(100);
  numb->maximum(100000);
  numb->step(100);
  numb->labelsize(16);
  numb->align(FL_ALIGN_LEFT);
  numb->type(FL_HORIZONTAL);
  numb->value(20000);

  Fl_Button *res = new Fl_Button (380,350,200,20,"create buttons");
  res->callback(reset_cb,(void*)0);

  window.end();

  // reset_cb(thescroll,(void*)0);              // add the buttons

  window.show(argc,argv);
  return Fl::run();
}
_______________________________________________
fltk-bugs mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-bugs

Reply via email to