////////////////////////////////////////////////////////////////////////////////
// GLLineEdit.h
// Copyright Bjoern Ganster 2007-2010
////////////////////////////////////////////////////////////////////////////////

#ifndef GLLineEdit__H
#define GLLineEdit__H

#include "GLWindow.h"
#include "BGCPString.h"

////////////////////////////////////////////////////////////////////////////////
// Base class for a button

class GLLineEdit: public GLWindow {
public:
   Color textColor;

   // Constructor
   GLLineEdit (GLWindow* _parent = NULL, int _left = 0, int _top = 0, 
             int _width = 0, int _height = 0);

   // Destructor
   virtual ~GLLineEdit();

   // Text access
   const BGCPString& getText () const
   { return text; }
   void setText (const BGCPString& newText)
   { text = newText; }

   // Set text to numerical values
   void setDouble (double newVal)
   { text = BGCPString::fromDouble (newVal); }
   void setInt (int newVal)
   { text = BGCPString::fromInt(newVal); }

   // Try to interpret text as numerical values
   bool getDouble (double& value) const;

   template <typename T>
   bool getInt (T& value) const
   {
       value = (T)text.toInt();
       return true;
   }

   // Render
   virtual void render(int x, int y, int w, int h) OVERRIDE;

   // Keyboard events
   void keypressed (BGKey key, bool shiftHeld, bool ctrlHeld, bool down, bool repeat) OVERRIDE;

   // Button state changed over a window: returns child that was clicked
   GLWindow* buttonStateChanged (int button, bool down, int /*x*/, int /*y*/) OVERRIDE;

   void mouseMoved (int /*x*/, int /*y*/) OVERRIDE;

   // Event: widget looses focus
   void loseFocus () OVERRIDE;

protected:
   BGCPString text;
   int cursorPos;
};

#endif
