Cafu Engine
CompListBox.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_LISTBOX_HPP_INCLUDED
8 #define CAFU_GUISYS_COMPONENT_LISTBOX_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 turns its window into a list-box control.
21  /// It requires that in the same window a text component is available where the aspects of text rendering are
22  /// configured (but that normally has empty text contents itself).
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  ComponentListBoxT* Clone() const;
36  const char* GetName() const { return "ListBox"; }
37  void UpdateDependencies(WindowT* Window);
38  void Render() const;
39  bool OnInputEvent(const CaKeyboardEventT& KE);
40  bool OnInputEvent(const CaMouseEventT& ME, float PosX, float PosY);
41 
42 
43  // The TypeSys related declarations for this class.
44  const cf::TypeSys::TypeInfoT* GetType() const { return &TypeInfo; }
45  static void* CreateInstance(const cf::TypeSys::CreateParamsT& Params);
46  static const cf::TypeSys::TypeInfoT TypeInfo;
47 
48 
49  protected:
50 
51  // The Lua API methods of this class.
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  IntrusivePtrT<ComponentTextT> m_TextComp; ///< The sibling text component from which we take the text settings.
65  TypeSys::VarArrayT<std::string> m_Items; ///< The list of available items.
66  TypeSys::VarT<unsigned int> m_Selection; ///< The index number of the currently selected item, where 1 corresponds to the first item (as per Lua convention). Use 0 for "no selection".
67  TypeSys::VarT<Vector3fT> m_BgColorOdd; ///< The background color for odd rows.
68  TypeSys::VarT<float> m_BgAlphaOdd; ///< The background alpha for odd rows.
69  TypeSys::VarT<Vector3fT> m_BgColorEven; ///< The background color for even rows.
70  TypeSys::VarT<float> m_BgAlphaEven; ///< The background alpha for even rows.
71  TypeSys::VarT<Vector3fT> m_BgColorSel; ///< The background color for selected rows.
72  TypeSys::VarT<float> m_BgAlphaSel; ///< The background alpha for selected rows.
73  TypeSys::VarT<Vector3fT> m_TextColorSel; ///< The foreground color for selected rows.
74  TypeSys::VarT<float> m_TextAlphaSel; ///< The foreground alpha for selected rows.
75  };
76  }
77 }
78 
79 #endif
This class implements smart (reference-counted) pointers.
Definition: Pointer.hpp:43
This components turns its window into a list-box control.
Definition: CompListBox.hpp:23
bool OnInputEvent(const CaKeyboardEventT &KE)
This method handles keyboard input events.
Definition: CompListBox.cpp:249
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
ComponentListBoxT()
The constructor.
Definition: CompListBox.cpp:66
static const luaL_Reg MethodsList[]
The list of Lua methods for this class.
Definition: CompListBox.hpp:55
void Render() const
This method implements the graphical output of this component.
Definition: CompListBox.cpp:143
This struct describes a keyboard event.
Definition: OpenGLWindow.hpp:20
const char * GetName() const
Returns the name of this component.
Definition: CompListBox.hpp:36
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
void UpdateDependencies(WindowT *Window)
This method is called whenever something "external" to this component has changed: ...
Definition: CompListBox.cpp:126
Definition: TypeSys.hpp:68
ComponentListBoxT * Clone() const
The virtual copy constructor.
Definition: CompListBox.cpp:120