Flu_Dual_Progress_Meter.H 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. // $Id: Flu_Dual_Progress_Meter.h,v 1.6 2003/08/20 16:29:41 jbryan Exp $
  2. /***************************************************************
  3. * FLU - FLTK Utility Widgets
  4. * Copyright (C) 2002 Ohio Supercomputer Center, Ohio State University
  5. *
  6. * This file and its content is protected by a software license.
  7. * You should have received a copy of this license with this file.
  8. * If not, please contact the Ohio Supercomputer Center immediately:
  9. * Attn: Jason Bryan Re: FLU 1224 Kinnear Rd, Columbus, Ohio 43212
  10. *
  11. ***************************************************************/
  12. #ifndef _FLU_DUAL_PROGRESS_METER_H
  13. #define _FLU_DUAL_PROGRESS_METER_H
  14. #include <stdio.h>
  15. /* fltk includes */
  16. #include <FL/Fl.H>
  17. #include <FL/Fl_Double_Window.H>
  18. #include <FL/Fl_Slider.H>
  19. #include <FL/Fl_Button.H>
  20. #include "FLU/Flu_Label.H"
  21. #include "FLU/Flu_Enumerations.H"
  22. //! This class provides a simple meter showing both current and total progress that also provides canceling behavior
  23. class FLU_EXPORT Flu_Dual_Progress_Meter
  24. {
  25. public:
  26. //! Constructor which makes the progress meter with the title \b t
  27. Flu_Dual_Progress_Meter( const char* t = NULL );
  28. //! Default destructor
  29. virtual ~Flu_Dual_Progress_Meter();
  30. //! Set the title of the progress meter to \b t
  31. inline void setTitle( const char* t )
  32. { if( window ) window->label( t ); }
  33. //! \return the title of this meter
  34. inline const char* getTitle() const
  35. { if( window ) return window->label(); else return ""; }
  36. //! Convenience routine combining setCurrentLabel() and setTotalLabel()
  37. inline void setLabel( const char* current, const char* total )
  38. { if( currentLabel ) currentLabel->label( current ); if( totalLabel ) totalLabel->label( total ); }
  39. //! Set the "current" label displayed during the operation
  40. inline void setCurrentLabel( const char* l )
  41. { if( currentLabel ) currentLabel->label( l ); }
  42. //! Set the "total" label displayed during the operation
  43. inline void setTotalLabel( const char* l )
  44. { if( totalLabel ) totalLabel->label( l ); }
  45. //! Get the label for the current progress
  46. inline const char* getCurrentLabel() const
  47. { if( currentLabel ) return currentLabel->label(); else return ""; }
  48. //! Get the label for the total progress
  49. inline const char* getTotalLabel() const
  50. { if( totalLabel ) return totalLabel->label(); else return ""; }
  51. //! Set the color of the progress bar
  52. /*! Default is FL_BLUE */
  53. inline void setColor( Fl_Color c )
  54. { if( currentSlider ) currentSlider->selection_color( c );if( totalSlider ) totalSlider->selection_color( c ); }
  55. //! \return the current color of the progress bar
  56. inline Fl_Color getColor() const
  57. { if( currentSlider ) return currentSlider->selection_color(); else return FL_BLUE; }
  58. //! Convenience routine combining setCurrentValue() and setTotalValue()
  59. inline bool setValue( float currentVal, float totalVal )
  60. { bool b = setCurrentValue(currentVal) | setTotalValue(totalVal); return b; }
  61. //! Set the value of the current progress bar. \b v should be on [0,1]
  62. /*! \return \c true if the cancel button has been pressed */
  63. bool setCurrentValue( float v );
  64. //! Set the value of the total progress bar. \b v should be on [0,1]
  65. /*! \return \c true if the cancel button has been pressed */
  66. bool setTotalValue( float v );
  67. //! This function can be registered to update the progress bar
  68. inline static void currentValueCallback( float v, void *arg )
  69. { ((Flu_Dual_Progress_Meter*)arg)->setCurrentValue( v ); }
  70. //! This function can be registered to update the progress bar
  71. inline static void totalValueCallbackd( double v, void *arg )
  72. { ((Flu_Dual_Progress_Meter*)arg)->setTotalValue( (float)v ); }
  73. //! \return the current value of the progress bar, on [0,1]
  74. inline float getCurrentValue() const
  75. { if( currentSlider ) return currentSlider->value(); else return 0.0f; }
  76. //! \return the current value of the progress bar, on [0,1]
  77. inline float getTotalValue() const
  78. { if( totalSlider ) return totalSlider->value(); else return 0.0f; }
  79. //! Show the meter. If \b cancelBtnVisible is \c true, then the "Cancel" button will be shown
  80. void show( bool cancelBtnVisible = false );
  81. //! Hide the meter
  82. inline void hide()
  83. { if( window ) window->hide(); Fl::flush(); }
  84. //! \return \c true if the meter is shown, \c false otherwise
  85. inline bool shown() const
  86. { if( window ) return window->shown(); else return false; }
  87. //! Set the function that will be called when the "Cancel" button is pressed
  88. inline void cancelCallback( void (*cb)(void*), void* cbd = NULL )
  89. { _cancelCB = cb; _cancelCBD = cbd; }
  90. protected:
  91. private:
  92. void (*_cancelCB)(void*);
  93. void* _cancelCBD;
  94. bool _cancelled;
  95. static void _onCancelCB( Fl_Widget* w, void* arg )
  96. { ((Flu_Dual_Progress_Meter*)arg)->onCancel(); }
  97. void onCancel()
  98. { _cancelled = true; if( _cancelCB ) _cancelCB( _cancelCBD ); }
  99. Fl_Double_Window* window;
  100. Fl_Slider *currentSlider, *totalSlider;
  101. Fl_Button* cancel;
  102. Flu_Label *currentLabel, *totalLabel;
  103. };
  104. #endif