Cafu Engine
CompText.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_HPP_INCLUDED
8 #define CAFU_GUISYS_COMPONENT_TEXT_HPP_INCLUDED
9 
10 #include "CompBase.hpp"
11 
12 
13 namespace cf
14 {
15  class TrueTypeFontT;
16 
17 
18  namespace GuiSys
19  {
20  /// This components adds text to its window.
22  {
23  public:
24 
25  /// A variable of type std::string, specifically for font names. It updates the related
26  /// font instance in the parent ComponentTextT whenever a new font name is set.
27  class VarFontNameT : public TypeSys::VarT<std::string>
28  {
29  public:
30 
31  VarFontNameT(const char* Name, const std::string& Value, const char* Flags[], ComponentTextT& CompText);
32  VarFontNameT(const VarFontNameT& Var, ComponentTextT& CompText);
33 
34  // Base class overrides.
35  void Set(const std::string& v);
36  void GetChoices(ArrayT<std::string>& Strings, ArrayT<std::string>& Values) const;
37 
38 
39  private:
40 
41  ComponentTextT& m_CompText; ///< The parent ComponentTextT that contains this variable.
42  };
43 
44 
45  /// A variable of type int, specifically for horizontal alignments of text.
46  class VarTextAlignHorT : public TypeSys::VarT<int>
47  {
48  public:
49 
50  enum { LEFT = -1, CENTER, RIGHT };
51 
52  VarTextAlignHorT(const char* Name, const int& Value, const char* Flags[]=NULL);
53 
54  // Base class overrides.
55  void GetChoices(ArrayT<std::string>& Strings, ArrayT<int>& Values) const;
56  };
57 
58 
59  /// A variable of type int, specifically for vertical alignments of text.
60  class VarTextAlignVerT : public TypeSys::VarT<int>
61  {
62  public:
63 
64  enum { TOP = -1, MIDDLE, BOTTOM };
65 
66  VarTextAlignVerT(const char* Name, const int& Value, const char* Flags[]=NULL);
67 
68  // Base class overrides.
69  void GetChoices(ArrayT<std::string>& Strings, ArrayT<int>& Values) const;
70  };
71 
72 
73  /// The constructor.
75 
76  /// The copy constructor.
77  /// @param Comp The component to create a copy of.
78  ComponentTextT(const ComponentTextT& Comp);
79 
80  /// This method sets this components text value.
81  /// Other C++ code (especially other components) would normally have to use `GetMemberVars().Find("Text")`
82  /// to set this components text value. This auxiliary method makes the task much easier.
83  void SetText(const std::string& t) { m_Text.Set(t); }
84 
85  /// This method appends the given text to the components text value.
86  void AppendText(const std::string& t) { m_Text.Set(m_Text.Get() + t); }
87 
88  // Base class overrides.
89  ComponentTextT* Clone() const;
90  const char* GetName() const { return "Text"; }
91  void UpdateDependencies(WindowT* Window);
92  void Render() const;
93 
94 
95  // The TypeSys related declarations for this class.
96  const cf::TypeSys::TypeInfoT* GetType() const { return &TypeInfo; }
97  static void* CreateInstance(const cf::TypeSys::CreateParamsT& Params);
98  static const cf::TypeSys::TypeInfoT TypeInfo;
99 
100 
101  protected:
102 
103  // The Lua API methods of this class.
104  static int toString(lua_State* LuaState);
105 
106  static const luaL_Reg MethodsList[]; ///< The list of Lua methods for this class.
107  static const char* DocClass;
108  static const cf::TypeSys::MethsDocT DocMethods[];
109  static const cf::TypeSys::VarsDocT DocVars[];
110 
111 
112  private:
113 
114  friend class ComponentListBoxT;
115  friend class ComponentTextEditT;
116 
117  void FillMemberVars(); ///< A helper method for the constructors.
118 
119  TypeSys::VarT<std::string> m_Text; ///< The text to show in this window.
120  VarFontNameT m_FontName; ///< The name of the font.
121  TrueTypeFontT* m_FontInst; ///< The font instance used to render text in this window.
122  TypeSys::VarT<float> m_Scale; ///< The scale that is applied for rendering the text.
123  TypeSys::VarT<Vector2fT> m_Padding; ///< Padding between text and window rectangle.
124  TypeSys::VarT<Vector3fT> m_Color; ///< The text color.
125  TypeSys::VarT<float> m_Alpha; ///< The alpha component of the color.
126  VarTextAlignHorT m_AlignHor; ///< How the text is aligned horizontally (left, center, right).
127  VarTextAlignVerT m_AlignVer; ///< How the text is aligned vertically (top, middle, bottom).
128  };
129  }
130 }
131 
132 #endif
void Set(const std::string &v)
Sets the value of this variable to the given value v.
Definition: CompText.cpp:59
const char * GetName() const
Returns the name of this component.
Definition: CompText.hpp:90
With this component, the user can edit the text in a sibling text component.
Definition: CompTextEdit.hpp:23
This components turns its window into a list-box control.
Definition: CompListBox.hpp:23
ComponentTextT * Clone() const
The virtual copy constructor.
Definition: CompText.cpp:265
void UpdateDependencies(WindowT *Window)
This method is called whenever something "external" to this component has changed: ...
Definition: CompText.cpp:271
A variable of type std::string, specifically for font names.
Definition: CompText.hpp:27
A variable of type int, specifically for horizontal alignments of text.
Definition: CompText.hpp:46
ComponentTextT()
The constructor.
Definition: CompText.cpp:217
This is a "wrapper" around a normal C++ variable.
Definition: SetCompVar.hpp:15
void SetText(const std::string &t)
This method sets this components text value.
Definition: CompText.hpp:83
This is the base class for the components that a window is composed/aggregated of.
Definition: CompBase.hpp:51
This components adds text to its window.
Definition: CompText.hpp:21
void AppendText(const std::string &t)
This method appends the given text to the components text value.
Definition: CompText.hpp:86
void GetChoices(ArrayT< std::string > &Strings, ArrayT< int > &Values) const
This method returns a list of acceptable input values for this variable, along with a string represen...
Definition: CompText.cpp:161
This class represents a window of the GuiSys.
Definition: Window.hpp:54
A class for rendering fonts that have been created with the Cafu MakeFont tool.
Definition: FontTT.hpp:22
void Render() const
This method implements the graphical output of this component.
Definition: CompText.cpp:311
static const luaL_Reg MethodsList[]
The list of Lua methods for this class.
Definition: CompText.hpp:106
A variable of type int, specifically for vertical alignments of text.
Definition: CompText.hpp:60
void GetChoices(ArrayT< std::string > &Strings, ArrayT< std::string > &Values) const
This method returns a list of acceptable input values for this variable, along with a string represen...
Definition: CompText.cpp:75
void GetChoices(ArrayT< std::string > &Strings, ArrayT< int > &Values) const
This method returns a list of acceptable input values for this variable, along with a string represen...
Definition: CompText.cpp:179
virtual void Set(const T &v)
Sets the value of this variable to the given value v.
Definition: Variables.hpp:189
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
const T & Get() const
Returns the value of this variable.
Definition: Variables.hpp:182
Definition: TypeSys.hpp:68