SuperTuxKart
Loading...
Searching...
No Matches
abstract_top_level_container.hpp
1// SuperTuxKart - a fun racing game with go-kart
2//
3// Copyright (C) 2009-2015 Marianne Gagnon
4//
5// This program is free software; you can redistribute it and/or
6// modify it under the terms of the GNU General Public License
7// as published by the Free Software Foundation; either version 3
8// of the License, or (at your option) any later version.
9//
10// This program is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with this program; if not, write to the Free Software
17// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
19#ifndef __TOP_LEVEL_CONT_HPP__
20#define __TOP_LEVEL_CONT_HPP__
21
22
23#include "guiengine/widget.hpp"
24#include "utils/log.hpp"
25#include "utils/ptr_vector.hpp"
26
27#include <cstring> // for NULL
28#include <typeinfo> // for typeid
29
30
31namespace GUIEngine
32{
33 class Widget;
34
43 {
44 protected:
47
55
63
65 Widget* parent=NULL);
66
67 public:
70
71 virtual int getWidth() = 0;
72 virtual int getHeight() = 0;
73
75 Widget* getWidget(const char* name);
76
78 Widget* getWidget(const int id);
79
85 template <typename T>
86 T* getWidget(const char* name)
87 {
88 Widget* out = getWidget(name);
89 T* outCasted = dynamic_cast<T*>( out );
90 if (out != NULL && outCasted == NULL)
91 Log::fatal("Screen::getWidget", "Widget '%s' of type '%s'"
92 "cannot be casted to requested type '%s'!\n", name,
93 typeid(*out).name(), typeid(T).name());
94 return outCasted;
95 }
96
97 static Widget* getWidget(const char* name,
98 PtrVector<Widget>* within_vector);
99 static Widget* getWidget(const int id,
100 PtrVector<Widget>* within_vector);
101
102 Widget* getFirstWidget(PtrVector<Widget>* within_vector=NULL);
103 Widget* getLastWidget(PtrVector<Widget>* within_vector=NULL);
104
105 void elementsWereDeleted(PtrVector<Widget>* within_vector = NULL);
106
107 bool isMyChild(Widget* widget) const;
108 virtual bool enableScreenPadding() const { return true; }
109 }; // AbstractTopLevelContainer
110
111} // namespace GUIEngine
112
113#endif
Represents a GUI widgets container.
Definition: abstract_top_level_container.hpp:43
void addWidgetsRecursively(PtrVector< Widget > &widgets, Widget *parent=NULL)
This function adds a list of widgets recursively, effectively creating the hierarchy of widgets.
Definition: abstract_top_level_container.cpp:52
Widget * getLastWidget(PtrVector< Widget > *within_vector=NULL)
This function returns the last widget found in within_vector.
Definition: abstract_top_level_container.cpp:253
T * getWidget(const char *name)
This function searches and returns a widget by name, cast as specified type, if that widget is found ...
Definition: abstract_top_level_container.hpp:86
Widget * m_first_widget
AbstractTopLevelContainer is generally able to determine its first widget just fine,...
Definition: abstract_top_level_container.hpp:54
PtrVector< Widget, HOLD > m_widgets
the widgets in this screen
Definition: abstract_top_level_container.hpp:46
Widget * m_last_widget
AbstractTopLevelContainer is generally able to determine its last widget just fine,...
Definition: abstract_top_level_container.hpp:62
Widget * getWidget(const char *name)
This function returns a widget by name if that widget is found.
Definition: abstract_top_level_container.cpp:136
void elementsWereDeleted(PtrVector< Widget > *within_vector=NULL)
This function is called when screen is removed.
Definition: abstract_top_level_container.cpp:295
bool isMyChild(Widget *widget) const
This function checks if a widget is a child of the container.
Definition: abstract_top_level_container.cpp:126
Widget * getFirstWidget(PtrVector< Widget > *within_vector=NULL)
This function returns the first widget found in within_vector.
Definition: abstract_top_level_container.cpp:213
The nearly-abstract base of all widgets (not fully abstract since a bare Widget can be created for th...
Definition: widget.hpp:143
Definition: ptr_vector.hpp:44
Contains all GUI engine related classes and functions.
Definition: abstract_state_manager.hpp:33