00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef _FLU_PROGRESS_METER_H
00017 #define _FLU_PROGRESS_METER_H
00018
00019 #include <stdio.h>
00020
00021
00022 #include <FL/Fl.H>
00023 #include <FL/Fl_Double_Window.H>
00024 #include <FL/Fl_Button.H>
00025
00026 #include "FLU/Flu_Label.h"
00027 #include "FLU/Flu_Progress.h"
00028 #include "FLU/Flu_Enumerations.h"
00029
00030 #ifdef WIN32
00031 #include <winsock.h>
00032 #include <time.h>
00033 #else
00034 #include <sys/time.h>
00035 #endif
00036
00038 class FLU_EXPORT Flu_Progress_Meter : public Fl_Double_Window
00039 {
00040
00041 public:
00042
00044 Flu_Progress_Meter( const char* t = NULL );
00045
00047 virtual ~Flu_Progress_Meter();
00048
00050 inline void title( const char* t )
00051 { Fl_Double_Window::label( t ); }
00052
00054 inline const char* title() const
00055 { return Fl_Double_Window::label(); }
00056
00058 inline void label( const char* l )
00059 { if( _label ) _label->label( l ); }
00060
00062 inline const char* label() const
00063 { if( _label ) return _label->label(); else return ""; }
00064
00066 inline void cancel_label( const char *l )
00067 { if( l && _cancel ) _cancel->label( l ); }
00068
00070 inline void color( Fl_Color c )
00071 { if( _progress ) _progress->selection_color( c ); }
00072
00074 inline Fl_Color color() const
00075 { if( _progress ) return _progress->selection_color(); else return FL_BLUE; }
00076
00078
00085
00086
00087 bool value( float v );
00088
00090 inline float value() const
00091 { if( _progress ) return _progress->value(); else return 0.0f; }
00092
00094 inline static void value_callback( float v, void *arg )
00095 { ((Flu_Progress_Meter*)arg)->value( v ); }
00096
00098 inline static void value_callbackd( double v, void *arg )
00099 { ((Flu_Progress_Meter*)arg)->value( (float)v ); }
00100
00102 inline static bool cvalue_callback( float v, void *arg )
00103 { return ((Flu_Progress_Meter*)arg)->value( v ); }
00104
00106 inline static bool cvalue_callbackd( double v, void *arg )
00107 { return ((Flu_Progress_Meter*)arg)->value( (float)v ); }
00108
00110 inline void show_completion_time( bool b )
00111 { _showETC = b; }
00112
00114 inline bool show_completion_time() const
00115 { return _showETC; }
00116
00117
00118 inline float elapsed_time() const
00119 { return (float)elapsed; }
00120
00121
00122 inline float remaining_time() const
00123 { return (float)remaining; }
00124
00126 void show( bool withCancelButton = false );
00127
00129 void reset();
00130
00132 inline void do_cancel()
00133 { onCancel(); }
00134
00136 void hide();
00137
00139 inline void cancel_callback( void (*cb)(void*), void* cbd = NULL )
00140 { _cancelCB = cb; _cancelCBD = cbd; }
00141
00142 protected:
00143
00144 private:
00145
00146 #ifdef WIN32
00147 inline void gettimeofday( struct timeval *t, void* )
00148 {
00149 t->tv_sec = 0;
00150 t->tv_usec = clock();
00151 }
00152 #endif
00153
00154 timeval startT, deltaT;
00155 double elapsed, remaining;
00156
00157 inline static void _secondTimerCB( void *arg )
00158 { ((Flu_Progress_Meter*)arg)->secondTimerCB(); }
00159 void secondTimerCB( bool repeatTimer = true );
00160
00161 void (*_cancelCB)(void*);
00162 void* _cancelCBD;
00163 bool _cancelled, _showETC;
00164
00165 static void _onCancelCB( Fl_Widget* w, void* arg )
00166 { ((Flu_Progress_Meter*)arg)->onCancel(); }
00167 void onCancel()
00168 { _cancelled = true; if( _cancelCB ) _cancelCB( _cancelCBD ); }
00169
00170 Flu_Progress* _progress;
00171 Fl_Button* _cancel;
00172 Flu_Label *_label, *_etc;
00173
00174 };
00175
00176 #endif