Flu_Float_Input.H 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // $Id: Flu_Float_Input.h,v 1.10 2004/03/29 23:13:19 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_FLOAT_INPUT_H
  13. #define _FLU_FLOAT_INPUT_H
  14. #include <FL/Fl_Float_Input.H>
  15. #include <stdlib.h>
  16. #include <string.h>
  17. #include <stdio.h>
  18. #include "FLU/Flu_Enumerations.H"
  19. //! This class simply extends Fl_Float_Input to allow getting/setting the widget value as floats instead of just strings
  20. class FLU_EXPORT Flu_Float_Input : public Fl_Float_Input
  21. {
  22. DECLARE_CLASS_CHEAP_RTTI_2(Flu_Float_Input, Fl_Float_Input)
  23. public:
  24. //! Normal FLTK widget constructor
  25. Flu_Float_Input( int X,int Y,int W,int H,const char *l = 0 );
  26. //! Default destructor
  27. ~Flu_Float_Input();
  28. //! Set the format to use when printing the value into the input area. Only the pointer to \b f is copied. Default is "%g"
  29. inline void format( const char *f )
  30. { _format = f; }
  31. //! Get the format to use when printing the value into the input area.
  32. inline const char *format() const
  33. { return _format; }
  34. //! \return the value of the widget as a float
  35. inline float fvalue() const { return atof( value() ); }
  36. //! Set the value of the widget as a float using the given \c printf style format string
  37. inline void fvalue( float v, const char *format = 0 )
  38. { char buf[32]; sprintf(buf,format?format:_format,v); value(buf); }
  39. private:
  40. const char *_format;
  41. };
  42. #endif