summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGreg Ercolano <erco@seriss.com>2012-02-29 05:37:30 +0000
committerGreg Ercolano <erco@seriss.com>2012-02-29 05:37:30 +0000
commita9397d9ca82cf6b6339771f489ee566ea77fe64c (patch)
treebe7f5fed6d862d79756b5bd77b41e8d2272f6926
parent04c4df7be6fa6a9b91fd2928b434c87a217f65d4 (diff)
Added progress bar widget demo.
Nabbed from Greg's cheat sheet, with his permission. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@9255 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
-rw-r--r--examples/Makefile1
-rw-r--r--examples/progress-simple.cxx78
2 files changed, 79 insertions, 0 deletions
diff --git a/examples/Makefile b/examples/Makefile
index 250b951d5..2e8d35767 100644
--- a/examples/Makefile
+++ b/examples/Makefile
@@ -11,6 +11,7 @@ ALL = howto-add_fd-and-popen$(EXEEXT) \
howto-text-over-image-button$(EXEEXT) \
menubar-add$(EXEEXT) \
nativefilechooser-simple-app$(EXEEXT) \
+ progress-simple$(EXEEXT) \
table-as-container$(EXEEXT) \
table-simple$(EXEEXT) \
table-sort$(EXEEXT) \
diff --git a/examples/progress-simple.cxx b/examples/progress-simple.cxx
new file mode 100644
index 000000000..9b831957f
--- /dev/null
+++ b/examples/progress-simple.cxx
@@ -0,0 +1,78 @@
+#include <stdio.h>
+#include <FL/Fl.H>
+#include <FL/Fl_Window.H>
+#include <FL/Fl_Button.H>
+#include <FL/Fl_Progress.H>
+
+//
+// "$Id$"
+//
+// Demonstrate using the Fl_Progress widget in an application - erco 05/02/2005
+//
+// Copyright 2005,2012 Greg Ercolano.
+// Copyright 1998-2012 by Bill Spitzak and others.
+//
+// This library is free software. Distribution and use rights are outlined in
+// the file "COPYING" which should have been included with this file. If this
+// file is missing or damaged, see the license at:
+//
+// http://www.fltk.org/COPYING.php
+//
+// Please report all bugs and problems on the following page:
+//
+// http://www.fltk.org/str.php
+//
+
+#ifdef _WIN32
+// WINDOWS
+#include <windows.h>
+#define usleep(v) Sleep(v/1000)
+#else
+// UNIX
+#include <unistd.h> // usleep
+#endif
+
+// Button callback
+void butt_cb(Fl_Widget *butt, void *data) {
+
+ // Deactivate the button
+ butt->deactivate(); // prevent button from being pressed again
+ Fl::check(); // give fltk some cpu to gray out button
+ // Make the progress bar
+ Fl_Window *w = (Fl_Window*)data; // access parent window
+ w->begin(); // add progress bar to it..
+ Fl_Progress *progress = new Fl_Progress(10,50,200,30);
+ progress->minimum(0); // set progress range to be 0.0 ~ 1.0
+ progress->maximum(1);
+ progress->color(0x88888800); // background color
+ progress->selection_color(0x4444ff00); // progress bar color
+ progress->labelcolor(FL_WHITE); // percent text color
+ w->end(); // end adding to window
+ // Computation loop..
+ for ( int t=1; t<=500; t++ ) {
+ progress->value(t/500.0); // update progress bar with 0.0 ~ 1.0 value
+ char percent[10];
+ sprintf(percent, "%d%%", int((t/500.0)*100.0));
+ progress->label(percent); // update progress bar's label
+ Fl::check(); // give fltk some cpu to update the screen
+ usleep(1000); // 'your stuff' that's compute intensive
+ }
+ // Cleanup
+ w->remove(progress); // remove progress bar from window
+ delete(progress); // deallocate it
+ butt->activate(); // reactivate button
+ w->redraw(); // tell window to redraw now that progress removed
+}
+// Main
+int main() {
+ Fl_Window win(220,90);
+ Fl_Button butt(10,10,100,25,"Press");
+ butt.callback(butt_cb, &win);
+ win.resizable(win);
+ win.show();
+ return(Fl::run());
+}
+
+//
+// End of "$Id$".
+//