GUI
EditBox.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017 by Maciej Wiecierzewski
3  */
4 
5 #ifndef EDITBOX_H
6 #define EDITBOX_H
7 
8 #include <string>
9 
10 #include "keycodes.h"
11 #include "Widget.h"
12 #include "Handle.h"
13 #include "Scrollbar.h"
14 
15 namespace gui
16 {
17 
18 class GUISystem;
19 
21 
22 class EditBox : public Widget
23 {
24  public:
25  EditBox(GUISystem *guiSystem, int x, int y, int w, int h);
26  virtual ~EditBox() {};
27 
28  void render(Renderer *renderer);
29  void keyChar(int unichar);
30  void keyDown(int keyCode);
31 
32  void setMultiline();
33  void setText(const std::string &text);
34  std::string getText();
35 
36  protected:
41 
43 
44  private:
45  void updateScrollbars();
46  void getCursorXY(Renderer *renderer, int& cursorX, int& cursorY);
47  void findCursorLine();
48  void countLines();
49 
52 
53  std::string text;
54  unsigned int cursorPos;
55  unsigned int cursorLine;
56  int lines;
57  float lineHeight;
58  bool multiline;
59  bool vScroll;
60  bool hScroll;
61 
62  friend class GUISystem;
63 };
64 
65 }
66 #endif // EDITBOX_H