Cafu Engine
CompBasics.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_WINDOW_BASICS_HPP_INCLUDED
8 #define CAFU_GUISYS_COMPONENT_WINDOW_BASICS_HPP_INCLUDED
9 
10 #include "CompBase.hpp"
11 
12 
13 namespace cf
14 {
15  namespace GuiSys
16  {
17  /// This component adds the basics of the window (its name and the "is shown?" flag).
18  /// It is one of the components that is "fundamental" to a window (cf::GuiSys::IsFundamental() returns `true`).
19  /// Every window must have exactly one.
21  {
22  public:
23 
24  /// The constructor.
26 
27  /// The copy constructor.
28  /// @param Comp The component to create a copy of.
30 
31  /// Returns the name of the window.
32  const std::string& GetWindowName() const { return m_Name.Get(); }
33 
34  /// Returns `true` if the window is currently shown. Returns `false` if the window is currently hidden.
35  bool IsShown() const { return m_Show.Get(); }
36 
37  /// Sets a new name for the window.
38  /// Window names must be valid Lua script identifiers and unique among their siblings, and the method
39  /// modifies the given string as necessary. As a result, GetWindowName() can return a string that is
40  /// different from the string given to a preceeding call to SetWindowName().
41  void SetWindowName(const std::string& Name) { m_Name.Set(Name); }
42 
43  // Base class overrides.
44  ComponentBasicsT* Clone() const;
45  const char* GetName() const { return "Basics"; }
46 
47 
48  // The TypeSys related declarations for this class.
49  const cf::TypeSys::TypeInfoT* GetType() const { return &TypeInfo; }
50  static void* CreateInstance(const cf::TypeSys::CreateParamsT& Params);
51  static const cf::TypeSys::TypeInfoT TypeInfo;
52 
53 
54  protected:
55 
56  // The Lua API methods of this class.
57  static int toString(lua_State* LuaState);
58 
59  static const luaL_Reg MethodsList[]; ///< The list of Lua methods for this class.
60  static const char* DocClass;
61  static const cf::TypeSys::MethsDocT DocMethods[];
62  static const cf::TypeSys::MethsDocT DocCallbacks[];
63  static const cf::TypeSys::VarsDocT DocVars[];
64 
65 
66  private:
67 
68  /// A variable of type `std::string`, specifically for window names.
69  /// Window names must be valid Lua script identifiers and unique among their siblings.
70  class WindowNameT : public TypeSys::VarT<std::string>
71  {
72  public:
73 
74  WindowNameT(const char* Name, const std::string& Value, const char* Flags[], ComponentBasicsT& CompBasics);
75  WindowNameT(const WindowNameT& Var, ComponentBasicsT& CompBasics);
76 
77  // Base class overrides.
78  void Set(const std::string& v);
79 
80 
81  private:
82 
83  ComponentBasicsT& m_CompBasics; ///< The parent ComponentBasicsT that contains this variable.
84  };
85 
86  /// A variable of type `bool`, indicating whether this window is currently shown or hidden.
87  /// Besides keeping the boolean flag, this variable calls the `OnShow()` script callback whenever its value changes.
88  class WindowShowT : public TypeSys::VarT<bool>
89  {
90  public:
91 
92  WindowShowT(const char* Name, const bool& Value, const char* Flags[], ComponentBasicsT& CompBasics);
93  WindowShowT(const WindowShowT& Var, ComponentBasicsT& CompBasics);
94 
95  // Base class overrides.
96  void Set(const bool& v);
97 
98 
99  private:
100 
101  ComponentBasicsT& m_CompBasics; ///< The parent ComponentBasicsT that contains this variable.
102  };
103 
104 
105  WindowNameT m_Name; ///< The name of the window. Window names must be valid Lua script identifiers and unique among their siblings.
106  WindowShowT m_Show; ///< Is this window currently shown?
107  };
108  }
109 }
110 
111 #endif
const char * GetName() const
Returns the name of this component.
Definition: CompBasics.hpp:45
This component adds the basics of the window (its name and the "is shown?" flag). ...
Definition: CompBasics.hpp:20
static const luaL_Reg MethodsList[]
The list of Lua methods for this class.
Definition: CompBasics.hpp:59
void SetWindowName(const std::string &Name)
Sets a new name for the window.
Definition: CompBasics.hpp:41
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
ComponentBasicsT()
The constructor.
Definition: CompBasics.cpp:138
const std::string & GetWindowName() const
Returns the name of the window.
Definition: CompBasics.hpp:32
bool IsShown() const
Returns true if the window is currently shown. Returns false if the window is currently hidden...
Definition: CompBasics.hpp:35
ComponentBasicsT * Clone() const
The virtual copy constructor.
Definition: CompBasics.cpp:158
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