Flu_Float_Input.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. public:
  23. //! Normal FLTK widget constructor
  24. Flu_Float_Input( int X,int Y,int W,int H,const char *l = 0 );
  25. //! Default destructor
  26. ~Flu_Float_Input();
  27. //! Set the format to use when printing the value into the input area. Only the pointer to \b f is copied. Default is "%g"
  28. inline void format( const char *f )
  29. { _format = f; }
  30. //! Get the format to use when printing the value into the input area.
  31. inline const char *format() const
  32. { return _format; }
  33. //! \return the value of the widget as a float
  34. inline float fvalue() const { return atof( value() ); }
  35. //! Set the value of the widget as a float using the given \c printf style format string
  36. inline void fvalue( float v, const char *format = 0 )
  37. { char buf[32]; sprintf(buf,format?format:_format,v); value(buf); }
  38. private:
  39. const char *_format;
  40. };
  41. #endif