SDL Window Engine  20200905
swe_wingui_input.h
1 /***************************************************************************
2  * Copyright (C) 2017 by SWE team <sdl.window.engine@gmail.com> *
3  * *
4  * Part of the SWE: SDL Window Engine: *
5  * https://github.com/AndreyBarmaley/sdl-window-engine *
6  * *
7  * This program is free software; you can redistribute it and/or modify *
8  * it under the terms of the GNU General Public License as published by *
9  * the Free Software Foundation; either version 3 of the License, or *
10  * (at your option) any later version. *
11  * *
12  * This program is distributed in the hope that it will be useful, *
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15  * GNU General Public License for more details. *
16  * *
17  * You should have received a copy of the GNU General Public License *
18  * along with this program; if not, write to the *
19  * Free Software Foundation, Inc., *
20  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
21  ***************************************************************************/
22 
23 #ifndef _SWE_GUI_INPUT_
24 #define _SWE_GUI_INPUT_
25 
26 #include "swe_wingui.h"
27 
29 namespace SWE
30 {
31  // LineEdit emit signals: LineEditTextChanged, LineEditCursorChanged, LineEditReturnPressed
32  class LineEdit : public WindowToolTipArea
33  {
34  std::string content;
35  int curpos;
36 
37  protected:
38  bool mouseClickEvent(const ButtonsEvent &) override;
39  bool keyPressEvent(const KeySym &) override;
40  bool textInputEvent(const std::string &) override;
41 
42  virtual const FontRender & fontRender(void) const;
43 
44  public:
45  LineEdit(Window*);
46  LineEdit(const Size &, Window*);
47  LineEdit(const Point &, const Size &, Window*);
48  LineEdit(const Point &, const Size &, const std::string &, Window*);
49 
50  int cursorPosition(void) const;
51  int cursorPositionAt(const Point &) const;
52  void clear(void);
53  void setCursorPosition(int);
54  void setText(const std::string &);
55 
56  const std::string & text(void) const;
57 
58  void renderLineEdit(const Color & textColor, const Color & cursorColor, int cursorHeight, int cursorOffset);
59  void renderWindow(void) override;
60 
61  virtual void cursorPositionChanged(int oldpos, int newpos);
62  virtual void textChanged(const std::string & text);
63  virtual void returnPressed(void) {}
64 
65  const char* className(void) const override { return "SWE::LineEdit"; }
66 #ifdef SWE_WITH_JSON
67  JsonObject toJson(void) const override
68  {
69  JsonObject res = WindowToolTipArea::toJson();
70  res.addInteger("curpos", curpos);
71  res.addString("text", content);
72  return res;
73  }
74 #endif
75  };
76 
77 } // SWE
78 #endif
const char * className(void) const override
идентификацинная метка класса
Definition: swe_wingui_input.h:65
пространство SWE.
Definition: swe_binarybuf.cpp:30
event класс кнопки мыши (с состояниями press, release)
Definition: swe_events.h:159
Definition: swe_wingui.h:31
класс точки с двумя координатами
Definition: swe_rect.h:72
Definition: swe_inputs_keys.h:245
Definition: swe_wingui_input.h:32
класс цвета
Definition: swe_colors.h:65
базовый класс шрифта
Definition: swe_fontset.h:151
класс двухмерной размерности
Definition: swe_rect.h:36
базовый класс графических объектов сцены DisplayScene.
Definition: swe_window.h:57