Cafu Engine
CompTextEdit.hpp
1 /*
2 Cafu Engine, http://www.cafu.de/
3 Copyright (c) Carsten Fuchs and other contributors.
4 This project is licensed under the terms of the MIT license.
5 */
6 
7 #ifndef CAFU_GUISYS_COMPONENT_TEXT_EDIT_HPP_INCLUDED
8 #define CAFU_GUISYS_COMPONENT_TEXT_EDIT_HPP_INCLUDED
9 
10 #include "CompBase.hpp"
11 
12 
13 namespace cf
14 {
15  namespace GuiSys
16  {
17  class ComponentTextT;
18 
19 
20  /// With this component, the user can edit the text in a sibling text component.
21  /// The component requires that the window also has a text component, whose value it updates according to
22  /// user edits.
24  {
25  public:
26 
27  /// The constructor.
29 
30  /// The copy constructor.
31  /// @param Comp The component to create a copy of.
33 
34  // Base class overrides.
35  ComponentTextEditT* Clone() const;
36  const char* GetName() const { return "TextEdit"; }
37  void UpdateDependencies(WindowT* Window);
38  void Render() const;
39  bool OnInputEvent(const CaKeyboardEventT& KE);
40  void OnClockTickEvent(float t);
41 
42  // The TypeSys related declarations for this class.
43  const cf::TypeSys::TypeInfoT* GetType() const { return &TypeInfo; }
44  static void* CreateInstance(const cf::TypeSys::CreateParamsT& Params);
45  static const cf::TypeSys::TypeInfoT TypeInfo;
46 
47 
48  protected:
49 
50  // The Lua API methods of this class.
51  static int SetText(lua_State* LuaState);
52  static int toString(lua_State* LuaState);
53 
54  static const luaL_Reg MethodsList[]; ///< The list of Lua methods for this class.
55  static const char* DocClass;
56  static const cf::TypeSys::MethsDocT DocMethods[];
57  static const cf::TypeSys::VarsDocT DocVars[];
58 
59 
60  private:
61 
62  /// A variable of type int, specifically for the cursor type, "|" vs. "_".
63  class VarCursorTypeT : public TypeSys::VarT<int>
64  {
65  public:
66 
67  VarCursorTypeT(const char* Name, const int& Value, const char* Flags[]=NULL);
68 
69  // Base class overrides.
70  void GetChoices(ArrayT<std::string>& Strings, ArrayT<int>& Values) const;
71  };
72 
73 
74  IntrusivePtrT<ComponentTextT> m_TextComp; ///< The sibling text component whose value we're editing.
75  float m_CursorTime; ///< The current time in the cursor blink cycle.
76 
77  TypeSys::VarT<unsigned int> m_CursorPos; ///< The character position of the text cursor in the text. Valid values are 0 to Text.length().
78  VarCursorTypeT m_CursorType; ///< The type of the text cursor. 0 is a vertical bar cursor '|', 1 is an underline cursor '_'. Any other values default to the '|' cursor type.
79  TypeSys::VarT<float> m_CursorRate; ///< The rate in seconds at which the text cursor completes one blink cycle (on/off).
80  TypeSys::VarT<Vector3fT> m_CursorColor; ///< The color of the text cursor.
81  TypeSys::VarT<float> m_CursorAlpha; ///< The alpha component of the color.
82  };
83  }
84 }
85 
86 #endif
With this component, the user can edit the text in a sibling text component.
Definition: CompTextEdit.hpp:23
ComponentTextEditT * Clone() const
The virtual copy constructor.
Definition: CompTextEdit.cpp:107
This class implements smart (reference-counted) pointers.
Definition: Pointer.hpp:43
void UpdateDependencies(WindowT *Window)
This method is called whenever something "external" to this component has changed: ...
Definition: CompTextEdit.cpp:113
This is a "wrapper" around a normal C++ variable.
Definition: SetCompVar.hpp:15
This is the base class for the components that a window is composed/aggregated of.
Definition: CompBase.hpp:51
void OnClockTickEvent(float t)
This method handles clock-tick events.
Definition: CompTextEdit.cpp:308
ComponentTextEditT()
The constructor.
Definition: CompTextEdit.cpp:71
This struct describes a keyboard event.
Definition: OpenGLWindow.hpp:20
This class represents a window of the GuiSys.
Definition: Window.hpp:54
bool OnInputEvent(const CaKeyboardEventT &KE)
This method handles keyboard input events.
Definition: CompTextEdit.cpp:225
const char * GetName() const
Returns the name of this component.
Definition: CompTextEdit.hpp:36
static const luaL_Reg MethodsList[]
The list of Lua methods for this class.
Definition: CompTextEdit.hpp:54
void Render() const
This method implements the graphical output of this component.
Definition: CompTextEdit.cpp:132
Definition: TypeSys.hpp:52
Definition: TypeSys.hpp:57
This class keeps type information (about an entity class that occurs in the game).
Definition: TypeSys.hpp:79
Definition: TypeSys.hpp:68