summaryrefslogtreecommitdiff
path: root/src/interface/Textbox.h
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2012-11-17 19:44:09 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2012-11-17 19:44:09 (GMT)
commit058a2edd75debbd0297f92572316daa704bd379f (patch)
treead303f091f9a08b209b91eb34a9fcad996a3de69 /src/interface/Textbox.h
parente3594aba9e05c6865d396418c028049cda92c2f3 (diff)
parent7a21ae192fe19868539956f3fe28e62b2c7c4429 (diff)
downloadpowder-058a2edd75debbd0297f92572316daa704bd379f.zip
powder-058a2edd75debbd0297f92572316daa704bd379f.tar.gz
Merge branch 'master' of github.com:FacialTurd/PowderToypp
Diffstat (limited to 'src/interface/Textbox.h')
-rw-r--r--src/interface/Textbox.h108
1 files changed, 108 insertions, 0 deletions
diff --git a/src/interface/Textbox.h b/src/interface/Textbox.h
new file mode 100644
index 0000000..7d06111
--- /dev/null
+++ b/src/interface/Textbox.h
@@ -0,0 +1,108 @@
+#ifndef TEXTBOX_H
+#define TEXTBOX_H
+
+#include <string>
+
+#include "Label.h"
+#include "Misc.h"
+
+namespace ui
+{
+class Textbox;
+class TextboxAction
+{
+public:
+ virtual void TextChangedCallback(ui::Textbox * sender) {}
+ virtual ~TextboxAction() {}
+};
+
+class Textbox : public Label
+{
+ friend class TextboxAction;
+public:
+ bool ReadOnly;
+ enum ValidInput { All, Numeric, Number };
+ Textbox(Point position, Point size, std::string textboxText = "", std::string textboxPlaceholder = "");
+ virtual ~Textbox();
+
+ virtual void SetText(std::string text);
+ virtual std::string GetText();
+
+ virtual void SetPlaceholder(std::string text);
+
+ void SetBorder(bool border) { this->border = border; };
+ void SetHidden(bool hidden);
+ bool GetHidden() { return masked; }
+ void SetActionCallback(TextboxAction * action) { actionCallback = action; }
+
+ void SetLimit(size_t limit);
+ size_t GetLimit();
+
+ ValidInput GetInputType();
+ void SetInputType(ValidInput input);
+
+ //Determines if the given character is valid given the input type
+ bool CharacterValid(Uint16 character);
+
+ virtual void Tick(float dt);
+ virtual void OnContextMenuAction(int item);
+ virtual void OnMouseClick(int x, int y, unsigned button);
+ virtual void OnMouseUp(int x, int y, unsigned button);
+ virtual void OnMouseMoved(int localx, int localy, int dx, int dy);
+ virtual void OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt);
+ virtual void OnVKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt);
+ virtual void OnKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt);
+ virtual void Draw(const Point& screenPos);
+
+protected:
+ ValidInput inputType;
+ size_t limit;
+ int repeatTime;
+ int keyDown;
+ Uint16 characterDown;
+ bool mouseDown;
+ bool masked, border;
+ int cursor, cursorPositionX, cursorPositionY;
+ TextboxAction *actionCallback;
+ std::string backingText;
+ std::string placeHolder;
+
+ virtual void selectAll();
+ virtual void cutSelection();
+ virtual void pasteIntoSelection();
+};
+
+/*class Textbox : public Component
+{
+ friend class TextboxAction;
+protected:
+ std::string text;
+ std::string displayText;
+ int cursor, cursorPosition;
+ TextboxAction *actionCallback;
+ bool masked;
+ bool border;
+public:
+ Textbox(Point position, Point size, std::string textboxText);
+ virtual ~Textbox();
+
+ virtual void SetText(std::string text);
+ virtual void SetDisplayText(std::string text);
+ std::string GetText();
+ void SetActionCallback(TextboxAction * action) { actionCallback = action; }
+ virtual void OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt);
+
+ void SetHidden(bool hidden) { masked = hidden; }
+ bool GetHidden() { return masked; }
+
+ void SetBorder(bool border) {this->border = border;}
+
+ void TextPosition();
+
+ virtual void Draw(const Point& screenPos);
+};
+}*/
+}
+
+
+#endif // TEXTBOX_H