Cafu Engine
CompChoice.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_CHOICE_HPP_INCLUDED
8 #define CAFU_GUISYS_COMPONENT_CHOICE_HPP_INCLUDED
9 
10 #include "CompBase.hpp"
11 
12 
13 namespace cf
14 {
15  namespace GuiSys
16  {
17  class ComponentTextT;
18 
19 
20  /// This components add the behaviour of a choice field to its window.
21  /// It requires that the window also has a text component, whose value it updates according to user
22  /// interaction to one of the available choices.
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  ComponentChoiceT* Clone() const;
36  const char* GetName() const { return "Choice"; }
37  void UpdateDependencies(WindowT* Window);
38  void OnPostLoad(bool OnlyStatic);
39  bool OnInputEvent(const CaKeyboardEventT& KE);
40  bool OnInputEvent(const CaMouseEventT& ME, float PosX, float PosY);
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 Set(lua_State* LuaState);
52  static int GetSelItem(lua_State* LuaState);
53  static int toString(lua_State* LuaState);
54 
55  static const luaL_Reg MethodsList[]; ///< The list of Lua methods for this class.
56  static const char* DocClass;
57  static const cf::TypeSys::MethsDocT DocMethods[];
58  static const cf::TypeSys::MethsDocT DocCallbacks[];
59  static const cf::TypeSys::VarsDocT DocVars[];
60 
61 
62  private:
63 
64  void Sync(); ///< Sets the text component to the currently selected choice.
65 
66  IntrusivePtrT<ComponentTextT> m_TextComp; ///< The sibling text component whose value we're updating.
67  TypeSys::VarArrayT<std::string> m_Choices; ///< The list of available choices.
68  TypeSys::VarT<unsigned int> m_Selection; ///< The index number of the currently selected choice, where 1 corresponds to the first choice (as per Lua convention). Use 0 for "no selection".
69  };
70  }
71 }
72 
73 #endif
void UpdateDependencies(WindowT *Window)
This method is called whenever something "external" to this component has changed: ...
Definition: CompChoice.cpp:67
static const luaL_Reg MethodsList[]
The list of Lua methods for this class.
Definition: CompChoice.hpp:55
This class implements smart (reference-counted) pointers.
Definition: Pointer.hpp:43
void OnPostLoad(bool OnlyStatic)
This method is called after all windows and their components have been loaded.
Definition: CompChoice.cpp:84
This components add the behaviour of a choice field to its window.
Definition: CompChoice.hpp:23
bool OnInputEvent(const CaKeyboardEventT &KE)
This method handles keyboard input events.
Definition: CompChoice.cpp:90
This struct describes a mouse event.
Definition: OpenGLWindow.hpp:185
This is the base class for the components that a window is composed/aggregated of.
Definition: CompBase.hpp:51
ComponentChoiceT()
The constructor.
Definition: CompChoice.cpp:39
const char * GetName() const
Returns the name of this component.
Definition: CompChoice.hpp:36
This struct describes a keyboard event.
Definition: OpenGLWindow.hpp:20
This class represents a window of the GuiSys.
Definition: Window.hpp:54
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
ComponentChoiceT * Clone() const
The virtual copy constructor.
Definition: CompChoice.cpp:61