ManaPlus
Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes
BasicContainer Class Reference

#include <basiccontainer.h>

Inheritance diagram for BasicContainer:
Widget WidgetDeathListener Widget2 BasicContainer2 DropDown ScrollArea Tab TabbedArea Container Window ChatTab ShortcutTab SkillTab SocialTab AttrDisplay CharacterDisplay CharacterViewBase DebugTab Desktop FlowContainer HorizontContainer InfoClanTab Pincode Popup RelationClanTab SetupTab SliderList StatsClanTab StatsPage StatsPageBasic VertContainer WidgetGroup WindowContainer WindowMenu BankWindow BuyDialog BuySellDialog ChangeEmailDialog ChangePasswordDialog CharCreateDialog CharSelectDialog ChatWindow ClanWindow ConfirmDialog ConnectionDialog CutInWindow DebugWindow DidYouKnowWindow EditDialog EditServerDialog EmoteWindow EquipmentWindow HelpWindow InventoryWindow ItemAmountWindow KillStats LoginDialog MailEditWindow MailViewWindow MailWindow Minimap MiniStatusWindow NpcDialog OkDialog OutfitWindow PincodeDialog QuestsWindow QuitDialog RegisterDialog SellDialog ServerDialog ServerInfoWindow SetupWindow ShopWindow ShortcutWindow SkillDialog SocialWindow StatusWindow TextCommandEditor TextDialog TextSelectDialog TradeWindow UpdaterWindow WhoIsOnline WorldSelectDialog BattleTab ChannelTab ClanTab EmulateGuildTab GmTab GuildTab LangTab PartyTab TradeTab WhisperTab SocialAttackTab SocialFriendsTab SocialGuildTab SocialGuildTab2 SocialNavigationTab SocialPartyTab SocialPickupTab SocialPlayersTab

Public Member Functions

 BasicContainer (const Widget2 *const widget)
 
 ~BasicContainer ()
 
void showWidgetPart (Widget *const widget, const Rect &area)
 
void moveToTop (Widget *const widget)
 
void moveToBottom (Widget *const widget)
 
Rect getChildrenArea ()
 
void focusNext ()
 
void focusPrevious ()
 
void logic ()
 
void setFocusHandler (FocusHandler *const focusHandler)
 
void setInternalFocusHandler (FocusHandler *const focusHandler)
 
WidgetgetWidgetAt (int x, int y)
 
void death (const Event &event)
 
WidgetfindFirstWidget (const std::set< Widget *> &list)
 
void add (Widget *const widget)
 
virtual void remove (Widget *const widget)
 
virtual void clear ()
 
- Public Member Functions inherited from Widget
 Widget (const Widget2 *const widget)
 
 ~Widget ()
 
virtual void draw (Graphics *const graphics)=0
 
virtual void safeDraw (Graphics *const graphics)=0
 
virtual void drawFrame (Graphics *graphics)
 
virtual void safeDrawFrame (Graphics *graphics)
 
void setFrameSize (const unsigned int frameSize)
 
unsigned int getFrameSize () const
 
WidgetgetParent () const
 
void setWidth (const int width)
 
int getWidth () const
 
void setHeight (const int height)
 
int getHeight () const
 
void setSize (const int width, const int height)
 
void setX (const int x)
 
int getX () const
 
void setY (const int y)
 
int getY () const
 
void setPosition (const int x, const int y)
 
void setDimension (const Rect &dimension)
 
const RectgetDimension () const
 
void setFocusable (const bool focusable)
 
bool isFocusable () const
 
virtual bool isFocused () const
 
void setEnabled (const bool enabled)
 
bool isEnabled () const
 
void setVisible (Visible visible)
 
bool isVisible () const
 
void setBaseColor (const Color &color)
 
const ColorgetBaseColor () const
 
void setForegroundColor (const Color &color)
 
const ColorgetForegroundColor () const
 
void setBackgroundColor (const Color &color)
 
const ColorgetBackgroundColor () const
 
virtual void requestFocus ()
 
virtual void requestMoveToTop ()
 
virtual void requestMoveToBottom ()
 
FocusHandlergetFocusHandler ()
 
void addActionListener (ActionListener *const actionListener)
 
void removeActionListener (ActionListener *const actionListener)
 
void addDeathListener (WidgetDeathListener *const deathListener)
 
void removeDeathListener (WidgetDeathListener *const deathListener)
 
void addMouseListener (MouseListener *const mouseListener)
 
void removeMouseListener (MouseListener *const mouseListener)
 
void addKeyListener (KeyListener *const keyListener)
 
void removeKeyListener (KeyListener *const keyListener)
 
void addFocusListener (FocusListener *const focusListener)
 
void removeFocusListener (FocusListener *const focusListener)
 
void addWidgetListener (WidgetListener *const widgetListener)
 
void removeWidgetListener (WidgetListener *const widgetListener)
 
void setActionEventId (const std::string &actionEventId)
 
const std::string & getActionEventId () const
 
virtual void getAbsolutePosition (int &x, int &y) const
 
virtual void setParent (Widget *parent)
 
FontgetFont () const
 
void setFont (Font *const font)
 
virtual void fontChanged ()
 
bool isTabInEnabled () const
 
void setTabInEnabled (const bool enabled)
 
bool isTabOutEnabled () const
 
void setTabOutEnabled (const bool enabled)
 
void requestModalFocus ()
 
virtual void requestModalMouseInputFocus ()
 
virtual void releaseModalFocus ()
 
virtual void releaseModalMouseInputFocus ()
 
virtual bool isModalFocused () const
 
virtual bool isModalMouseInputFocused () const
 
const std::list< MouseListener * > & getMouseListeners () const A_CONST
 
const std::list< KeyListener * > & getKeyListeners () const A_CONST
 
const std::list< FocusListener * > & getFocusListeners () const A_CONST
 
virtual FocusHandlergetInternalFocusHandler ()
 
void setInternalFocusHandler (FocusHandler *const internalFocusHandler)
 
void setId (const std::string &id)
 
const std::string & getId () const
 
virtual void showPart (const Rect &rectangle)
 
bool isAllowLogic () const
 
void setMouseConsume (const bool b)
 
bool isMouseConsume () const
 
void setRedraw (const bool b)
 
virtual bool isSelectable () const
 
void setSelectable (const bool selectable)
 
void windowResized ()
 
virtual void postInit ()
 
- Public Member Functions inherited from Widget2
virtual ~Widget2 ()
 
const ColorgetThemeColor (const ThemeColorIdT type, const unsigned int alpha) const A_INLINE
 
const ColorgetThemeCharColor (const signed char c, bool &valid) const A_INLINE
 
virtual void setWidget2 (const Widget2 *const widget)
 
void setPalette (int palette)
 
void checkPalette ()
 
void setForegroundColor2 (const Color &color)
 
WidgetgetWindow () const
 
virtual void setWindow (Widget *const window)
 
- Public Member Functions inherited from WidgetDeathListener
virtual ~WidgetDeathListener ()
 

Protected Types

typedef std::vector< Widget * > WidgetList
 
typedef WidgetList::iterator WidgetListIterator
 
typedef WidgetList::const_iterator WidgetListConstIterator
 
typedef WidgetList::reverse_iterator WidgetListReverseIterator
 
typedef WidgetList::const_reverse_iterator WidgetListCReverseIterator
 
- Protected Types inherited from Widget
typedef std::list< MouseListener * > MouseListenerList
 
typedef MouseListenerList::iterator MouseListenerIterator
 
typedef std::list< KeyListener * > KeyListenerList
 
typedef KeyListenerList::iterator KeyListenerIterator
 
typedef std::list< ActionListener * > ActionListenerList
 
typedef ActionListenerList::iterator ActionListenerIterator
 
typedef std::list< WidgetDeathListener * > WidgetDeathListenerList
 
typedef WidgetDeathListenerList::iterator WidgetDeathListenerIterator
 
typedef std::list< FocusListener * > FocusListenerList
 
typedef FocusListenerList::iterator FocusListenerIterator
 
typedef std::list< WidgetListener * > WidgetListenerList
 
typedef WidgetListenerList::iterator WidgetListenerIterator
 

Protected Member Functions

virtual void drawChildren (Graphics *const graphics)
 
virtual void safeDrawChildren (Graphics *const graphics)
 
virtual void logicChildren ()
 
- Protected Member Functions inherited from Widget
void distributeActionEvent ()
 
void distributeResizedEvent ()
 
void distributeMovedEvent ()
 
void distributeHiddenEvent ()
 
void distributeShownEvent ()
 
- Protected Member Functions inherited from Widget2
 Widget2 (const Widget2 *const widget)
 
- Protected Member Functions inherited from WidgetDeathListener
 WidgetDeathListener ()
 

Protected Attributes

WidgetList mWidgets
 
WidgetList mLogicWidgets
 
- Protected Attributes inherited from Widget
MouseListenerList mMouseListeners
 
KeyListenerList mKeyListeners
 
ActionListenerList mActionListeners
 
WidgetDeathListenerList mDeathListeners
 
FocusListenerList mFocusListeners
 
WidgetListenerList mWidgetListeners
 
Color mForegroundColor
 
Color mBackgroundColor
 
Color mBaseColor
 
Rect mDimension
 
std::string mActionEventId
 
std::string mId
 
FocusHandlermFocusHandler
 
FocusHandlermInternalFocusHandler
 
WidgetmParent
 
FontmCurrentFont
 
unsigned int mFrameSize
 
bool mFocusable
 
bool mTabIn
 
bool mTabOut
 
bool mEnabled
 
bool mAllowLogic
 
bool mMouseConsume
 
bool mRedraw
 
bool mSelectable
 
- Protected Attributes inherited from Widget2
int mPaletteOffset
 
WidgetmWindow
 
Color mForegroundColor2
 

Additional Inherited Members

- Static Public Member Functions inherited from Widget
static void setGlobalFont (Font *const font)
 
static FontgetGloablFont ()
 
static void cleanGlobalFont ()
 
static bool widgetExists (const Widget *const widget)
 
static void distributeWindowResizeEvent ()
 
static WidgetcallPostInit (Widget *const widget)
 
- Data Fields inherited from Widget
Visible mVisible
 
- Static Protected Attributes inherited from Widget
static FontmGlobalFont = 0
 

Detailed Description

A base class for containers. The class implements the most common things for a container. If you are implementing a container, consider inheriting from this class.

See also
Container

Definition at line 78 of file basiccontainer.h.

Member Typedef Documentation

◆ WidgetList

typedef std::vector<Widget *> BasicContainer::WidgetList
protected

Typedef.

Definition at line 183 of file basiccontainer.h.

◆ WidgetListConstIterator

typedef WidgetList::const_iterator BasicContainer::WidgetListConstIterator
protected

Typedef.

Definition at line 193 of file basiccontainer.h.

◆ WidgetListCReverseIterator

typedef WidgetList::const_reverse_iterator BasicContainer::WidgetListCReverseIterator
protected

Typedef.

Definition at line 203 of file basiccontainer.h.

◆ WidgetListIterator

typedef WidgetList::iterator BasicContainer::WidgetListIterator
protected

Typedef.

Definition at line 188 of file basiccontainer.h.

◆ WidgetListReverseIterator

typedef WidgetList::reverse_iterator BasicContainer::WidgetListReverseIterator
protected

Typedef.

Definition at line 198 of file basiccontainer.h.

Constructor & Destructor Documentation

◆ BasicContainer()

BasicContainer::BasicContainer ( const Widget2 *const  widget)
inlineexplicit

◆ ~BasicContainer()

BasicContainer::~BasicContainer ( )

Destructor

Definition at line 75 of file basiccontainer.cpp.

References clear().

Referenced by BasicContainer().

76 {
77  // +++ virtual method call
78  clear();
79 }
virtual void clear()

Member Function Documentation

◆ add()

void BasicContainer::add ( Widget *const  widget)

Adds a widget to the basic container.

Parameters
widgetThe widget to add.
See also
remove, clear

Definition at line 259 of file basiccontainer.cpp.

References Widget::getFocusHandler(), Widget::mInternalFocusHandler, mLogicWidgets, and mWidgets.

Referenced by BasicContainer2::add(), BasicContainer2::addXY(), BasicContainer(), TabbedArea::enableScrollButtons(), Tab::init(), TabbedArea::postInit(), and ScrollArea::setContent().

260 {
261  if (widget == nullptr)
262  return;
263  mWidgets.push_back(widget);
264  if (widget->isAllowLogic())
265  mLogicWidgets.push_back(widget);
266 
267  if (mInternalFocusHandler == nullptr)
268  widget->setFocusHandler(getFocusHandler());
269  else
271 
272  widget->setParent(this);
273  widget->addDeathListener(this);
274 }
FocusHandler * getFocusHandler()
Definition: widget.h:473
WidgetList mLogicWidgets
FocusHandler * mInternalFocusHandler
Definition: widget.h:1121
virtual void setParent(Widget *parent)
Definition: widget.h:625
WidgetList mWidgets
void addDeathListener(WidgetDeathListener *const deathListener)
Definition: widget.cpp:261
bool isAllowLogic() const
Definition: widget.h:932
virtual void setFocusHandler(FocusHandler *const focusHandler)
Definition: widget.cpp:237

◆ clear()

void BasicContainer::clear ( )
virtual

Clears the basic container from all widgets.

See also
remove, clear

Reimplemented in PopupMenu, TradeWindow, SetupTabScroll, MailWindow, VertContainer, HorizontContainer, and WidgetGroup.

Definition at line 302 of file basiccontainer.cpp.

References FOR_EACH, mLogicWidgets, mWidgets, and restrict.

Referenced by BasicContainer(), WidgetGroup::clear(), HorizontContainer::clear(), VertContainer::clear(), Window::clearLayout(), TabbedArea::removeTab(), ScrollArea::setContent(), and ~BasicContainer().

303 {
305  {
306  Widget *restrict const widget = *iter;
307  widget->setFocusHandler(nullptr);
308  widget->setWindow(nullptr);
309  widget->setParent(nullptr);
310  widget->removeDeathListener(this);
311  }
312 
313  mWidgets.clear();
314  mLogicWidgets.clear();
315 }
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
WidgetList::const_iterator WidgetListConstIterator
WidgetList mLogicWidgets
Definition: widget.h:97
#define restrict
Definition: localconsts.h:164
WidgetList mWidgets

◆ death()

void BasicContainer::death ( const Event event)
virtual

Called when a widget dies. It is used to be able to recieve a notification when a death of a widget occurs.

Parameters
eventThe event of the death.

Implements WidgetDeathListener.

Reimplemented in TabbedArea.

Definition at line 133 of file basiccontainer.cpp.

References AttributesEnum::find(), mLogicWidgets, and mWidgets.

Referenced by BasicContainer(), and TabbedArea::death().

134 {
135  const WidgetListIterator iter = std::find(mWidgets.begin(),
136  mWidgets.end(), event.getSource());
137  if (iter != mWidgets.end())
138  mWidgets.erase(iter);
139 
140  const WidgetListIterator iter2 = std::find(mLogicWidgets.begin(),
141  mLogicWidgets.end(), event.getSource());
142  if (iter2 != mLogicWidgets.end())
143  mLogicWidgets.erase(iter2);
144 }
WidgetList mLogicWidgets
bool find(const std::string &key)
WidgetList mWidgets
WidgetList::iterator WidgetListIterator

◆ drawChildren()

void BasicContainer::drawChildren ( Graphics *const  graphics)
protectedvirtual

Draws the children widgets of the basic container.

Parameters
graphicsA graphics object to draw with.

Reimplemented in WindowMenu.

Definition at line 317 of file basiccontainer.cpp.

References BLOCK_END, BLOCK_START, CAST_S32, FOR_EACH, getChildrenArea(), Rect::height, mWidgets, restrict, Visible_true, Rect::width, Rect::x, and Rect::y.

Referenced by BasicContainer(), ConnectionDialog::draw(), MiniStatusWindow::draw(), Popup::draw(), TabbedArea::draw(), Tab::draw(), Window::draw(), ScrollArea::draw(), BasicContainer2::draw(), and WindowMenu::drawChildren().

318 {
319  BLOCK_START("BasicContainer::drawChildren")
320  graphics->pushClipArea(getChildrenArea());
321 
323  {
324  Widget *restrict const widget = *iter;
325  if (widget->mVisible == Visible_true)
326  {
327  // If the widget has a frame,
328  // draw it before drawing the widget
329  if (widget->mFrameSize > 0)
330  {
331  Rect rec = widget->mDimension;
332  const int frame = CAST_S32(widget->mFrameSize);
333  const int frame2 = frame * 2;
334  rec.x -= frame;
335  rec.y -= frame;
336  rec.width += frame2;
337  rec.height += frame2;
338  graphics->pushClipArea(rec);
339  BLOCK_START("BasicContainer::drawChildren 1")
340  widget->drawFrame(graphics);
342  graphics->popClipArea();
343  }
344 
345  graphics->pushClipArea(widget->mDimension);
347  widget->draw(graphics);
349  graphics->popClipArea();
350  }
351  }
352 
353  graphics->popClipArea();
355 }
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
int width
Definition: rect.h:218
void popClipArea() restrict2 override final
const bool Visible_true
Definition: visible.h:29
virtual void draw(Graphics *const graphics)=0
WidgetList::const_iterator WidgetListConstIterator
void pushClipArea(const Rect &restrict area) restrict2 override final
Definition: rect.h:72
#define BLOCK_START(name)
Definition: perfomance.h:78
#define BLOCK_END(name)
Definition: perfomance.h:79
int x
Definition: rect.h:208
#define CAST_S32
Definition: cast.h:29
int y
Definition: rect.h:213
int height
Definition: rect.h:223
Definition: widget.h:97
virtual void drawChildren(Graphics *const graphics)
virtual void pushClipArea(const Rect &area)
Definition: graphics.cpp:676
#define restrict
Definition: localconsts.h:164
WidgetList mWidgets
virtual void drawFrame(Graphics *graphics)
Definition: widget.h:148
Rect mDimension
Definition: widget.h:1100

◆ findFirstWidget()

Widget * BasicContainer::findFirstWidget ( const std::set< Widget *> &  list)

Definition at line 443 of file basiccontainer.cpp.

References FOR_EACHR, and mWidgets.

Referenced by BasicContainer(), and InventoryWindow::getFirstVisible().

445 {
447  {
448  if (list.find(*iter) != list.end())
449  return *iter;
450  }
451  return nullptr;
452 }
#define FOR_EACHR(type, iter, array)
Definition: foreach.h:27
WidgetList::reverse_iterator WidgetListReverseIterator
WidgetList mWidgets

◆ focusNext()

void BasicContainer::focusNext ( )
virtual

Focuses the next widget in the widget.

See also
moveToBottom

Reimplemented from Widget.

Definition at line 151 of file basiccontainer.cpp.

References mWidgets.

Referenced by BasicContainer().

152 {
154 
155  for (it = mWidgets.begin(); it != mWidgets.end(); ++ it)
156  {
157  if ((*it)->isFocused())
158  break;
159  }
160 
161  const WidgetListConstIterator end = it;
162 
163  if (it == mWidgets.end())
164  it = mWidgets.begin();
165 
166  ++ it;
167 
168  for ( ; it != end; ++ it)
169  {
170  if (it == mWidgets.end())
171  it = mWidgets.begin();
172 
173  if ((*it)->isFocusable())
174  {
175  (*it)->requestFocus();
176  return;
177  }
178  }
179 }
WidgetList::const_iterator WidgetListConstIterator
WidgetList mWidgets

◆ focusPrevious()

void BasicContainer::focusPrevious ( )
virtual

Focuses the previous widget in the widget.

See also
moveToBottom

Reimplemented from Widget.

Definition at line 181 of file basiccontainer.cpp.

References mWidgets.

Referenced by BasicContainer().

182 {
184 
185  for (it = mWidgets.rbegin(); it != mWidgets.rend(); ++ it)
186  {
187  if ((*it)->isFocused())
188  break;
189  }
190 
191  const WidgetListReverseIterator end = it;
192 
193  ++ it;
194 
195  if (it == mWidgets.rend())
196  it = mWidgets.rbegin();
197 
198  for ( ; it != end; ++ it)
199  {
200  if (it == mWidgets.rend())
201  it = mWidgets.rbegin();
202 
203  if ((*it)->isFocusable())
204  {
205  (*it)->requestFocus();
206  return;
207  }
208  }
209 }
WidgetList::reverse_iterator WidgetListReverseIterator
WidgetList mWidgets

◆ getChildrenArea()

Rect BasicContainer::getChildrenArea ( )
virtual

Gets the area of the widget occupied by the widget's children. By default this method returns an empty rectangle as not all widgets are containers. If you want to make a container this method should return the area where the children resides. This method is used when drawing children of a widget when computing clip rectangles for the children.

An example of a widget that overloads this method is ScrollArea. A ScrollArea has a view of its contant and that view is the children area. The size of a ScrollArea's children area might vary depending on if the scroll bars of the ScrollArea is shown or not.

Returns
The area of the widget occupied by the widget's children.
See also
BasicContainer
BasicContainer::getChildrenArea
BasicContainer::drawChildren

Reimplemented from Widget.

Reimplemented in Window, ScrollArea, Popup, DropDown, and MiniStatusWindow.

Definition at line 146 of file basiccontainer.cpp.

References Rect::height, Widget::mDimension, and Rect::width.

Referenced by BasicContainer(), drawChildren(), getWidgetAt(), safeDrawChildren(), showWidgetPart(), and LayoutHelper::widgetResized().

147 {
148  return Rect(0, 0, mDimension.width, mDimension.height);
149 }
int width
Definition: rect.h:218
Definition: rect.h:72
int height
Definition: rect.h:223
Rect mDimension
Definition: widget.h:1100

◆ getWidgetAt()

Widget * BasicContainer::getWidgetAt ( int  x,
int  y 
)
virtual

Gets a widget from a certain position in the widget. This function is used to decide which gets mouse input, thus it can be overloaded to change that behaviour.

NOTE: This always returns NULL if the widget is not a container.

Parameters
xThe x coordinate of the widget to get.
yThe y coordinate of the widget to get.
Returns
The widget at the specified coodinate, NULL if no widget is found.

Reimplemented from Widget.

Reimplemented in ScrollArea.

Definition at line 211 of file basiccontainer.cpp.

References getChildrenArea(), Rect::isPointInRect(), mWidgets, restrict, x, Rect::x, y, and Rect::y.

Referenced by BasicContainer(), and TabbedArea::mousePressed().

212 {
213  const Rect r = getChildrenArea();
214 
215  if (!r.isPointInRect(x, y))
216  return nullptr;
217 
218  x -= r.x;
219  y -= r.y;
220 
221  for (WidgetListReverseIterator it = mWidgets.rbegin();
222  it != mWidgets.rend(); ++ it)
223  {
224  const Widget *restrict const widget = *it;
225  if (widget->isVisible() &&
226  widget->getDimension().isPointInRect(x, y))
227  {
228  return *it;
229  }
230  }
231 
232  return nullptr;
233 }
Definition: rect.h:72
bool isPointInRect(const int x_, const int y_) const
Definition: rect.h:196
int x
Definition: rect.h:208
WidgetList::reverse_iterator WidgetListReverseIterator
int y
Definition: rect.h:213
Definition: widget.h:97
#define restrict
Definition: localconsts.h:164
WidgetList mWidgets

◆ logic()

void BasicContainer::logic ( )
virtual

Called for all widgets in the gui each time Gui::logic is called. You can do logic stuff here like playing an animation.

See also
Gui::logic

Reimplemented from Widget.

Reimplemented in NpcDialog, TabbedArea, ScrollArea, UpdaterWindow, ServerDialog, CharCreateDialog, Viewport, Viewport, WhoIsOnline, MiniStatusWindow, CutInWindow, StatDebugTab, MapDebugTab, NetDebugTab, TargetDebugTab, and DebugTab.

Definition at line 235 of file basiccontainer.cpp.

References BLOCK_END, BLOCK_START, logicChildren(), Widget::mVisible, and Visible_false.

Referenced by ChatWindow::addTab(), BasicContainer(), Window::isMovable(), MiniStatusWindow::logic(), ServerDialog::logic(), NpcDialog::logic(), Window::resizeToContent(), BeingPopup::show(), and ClanWindow::slowLogic().

236 {
237  BLOCK_START("BasicContainer::logic")
239  {
240  BLOCK_END("BasicContainer::logic")
241  return;
242  }
243  logicChildren();
245 }
#define BLOCK_START(name)
Definition: perfomance.h:78
if(!vert) return
#define BLOCK_END(name)
Definition: perfomance.h:79
Visible mVisible
Definition: widget.h:962
const bool Visible_false
Definition: visible.h:29
virtual void logicChildren()

◆ logicChildren()

void BasicContainer::logicChildren ( )
protectedvirtual

◆ moveToBottom()

void BasicContainer::moveToBottom ( Widget *const  widget)
virtual

Moves a widget in this widget to the bottom of this widget. The moved widget will be drawn below all other widgets in this widget.

Parameters
widgetThe widget to move to the bottom.
See also
moveToTop

Reimplemented from Widget.

Definition at line 109 of file basiccontainer.cpp.

References AttributesEnum::find(), mLogicWidgets, mWidgets, and reportAlways.

Referenced by BasicContainer().

110 {
111  if (widget == nullptr)
112  {
113  reportAlways("BasicContainer::moveToBottom empty widget.");
114  return;
115  }
116  const WidgetListIterator iter = std::find(mWidgets.begin(),
117  mWidgets.end(), widget);
118  if (iter != mWidgets.end())
119  {
120  mWidgets.erase(iter);
121  mWidgets.insert(mWidgets.begin(), widget);
122  }
123 
124  const WidgetListIterator iter2 = std::find(mLogicWidgets.begin(),
125  mLogicWidgets.end(), widget);
126  if (iter2 != mLogicWidgets.end())
127  {
128  mLogicWidgets.erase(iter2);
129  mLogicWidgets.insert(mLogicWidgets.begin(), widget);
130  }
131 }
WidgetList mLogicWidgets
bool find(const std::string &key)
WidgetList mWidgets
#define reportAlways(...)
Definition: checkutils.h:252
WidgetList::iterator WidgetListIterator

◆ moveToTop()

void BasicContainer::moveToTop ( Widget *const  widget)
virtual

Moves a widget to the top of this widget. The moved widget will be drawn above all other widgets in this widget.

Parameters
widgetThe widget to move to the top.
See also
moveToBottom

Reimplemented from Widget.

Definition at line 81 of file basiccontainer.cpp.

References FOR_EACH, mLogicWidgets, mWidgets, and reportAlways.

Referenced by BasicContainer().

82 {
83  if (widget == nullptr)
84  {
85  reportAlways("BasicContainer::moveToTop empty widget.");
86  return;
87  }
88 
90  {
91  if (*iter == widget)
92  {
93  mWidgets.erase(iter);
94  mWidgets.push_back(widget);
95  break;
96  }
97  }
99  {
100  if (*iter == widget)
101  {
102  mLogicWidgets.erase(iter);
103  mLogicWidgets.push_back(widget);
104  return;
105  }
106  }
107 }
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
WidgetList mLogicWidgets
WidgetList mWidgets
#define reportAlways(...)
Definition: checkutils.h:252
WidgetList::iterator WidgetListIterator

◆ remove()

void BasicContainer::remove ( Widget *const  widget)
virtual

Removes a widget from the basic container.

Parameters
widgetThe widget to remove.
See also
add, clear

Definition at line 276 of file basiccontainer.cpp.

References FOR_EACH, mLogicWidgets, and mWidgets.

Referenced by TabbedArea::removeTab(), and TabbedArea::setSelectedTab().

277 {
278  if (widget == nullptr)
279  return;
281  {
282  if (*iter == widget)
283  {
284  mWidgets.erase(iter);
285  widget->setFocusHandler(nullptr);
286  widget->setWindow(nullptr);
287  widget->setParent(nullptr);
288  widget->removeDeathListener(this);
289  break;
290  }
291  }
293  {
294  if (*iter == widget)
295  {
296  mLogicWidgets.erase(iter);
297  return;
298  }
299  }
300 }
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
void removeDeathListener(WidgetDeathListener *const deathListener)
Definition: widget.cpp:266
WidgetList mLogicWidgets
virtual void setWindow(Widget *const window)
Definition: widget2.h:96
virtual void setParent(Widget *parent)
Definition: widget.h:625
WidgetList mWidgets
virtual void setFocusHandler(FocusHandler *const focusHandler)
Definition: widget.cpp:237
WidgetList::iterator WidgetListIterator

◆ safeDrawChildren()

void BasicContainer::safeDrawChildren ( Graphics *const  graphics)
protectedvirtual

Reimplemented in WindowMenu.

Definition at line 357 of file basiccontainer.cpp.

References BLOCK_END, BLOCK_START, CAST_S32, FOR_EACH, getChildrenArea(), Rect::height, mWidgets, restrict, Visible_true, Rect::width, Rect::x, and Rect::y.

Referenced by BasicContainer(), ConnectionDialog::safeDraw(), MiniStatusWindow::safeDraw(), Popup::safeDraw(), TabbedArea::safeDraw(), Tab::safeDraw(), Window::safeDraw(), ScrollArea::safeDraw(), BasicContainer2::safeDraw(), and WindowMenu::safeDrawChildren().

359 {
360  BLOCK_START("BasicContainer::drawChildren")
361  graphics->pushClipArea(getChildrenArea());
362 
364  {
365  Widget *restrict const widget = *iter;
366  if (widget->mVisible == Visible_true)
367  {
368  // If the widget has a frame,
369  // draw it before drawing the widget
370  if (widget->mFrameSize > 0)
371  {
372  Rect rec = widget->mDimension;
373  const int frame = CAST_S32(widget->mFrameSize);
374  const int frame2 = frame * 2;
375  rec.x -= frame;
376  rec.y -= frame;
377  rec.width += frame2;
378  rec.height += frame2;
379  graphics->pushClipArea(rec);
380  BLOCK_START("BasicContainer::drawChildren 1")
381  widget->safeDrawFrame(graphics);
383  graphics->popClipArea();
384  }
385 
386  graphics->pushClipArea(widget->mDimension);
388  widget->safeDraw(graphics);
390  graphics->popClipArea();
391  }
392  }
393 
394  graphics->popClipArea();
396 }
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
int width
Definition: rect.h:218
virtual void safeDrawFrame(Graphics *graphics)
Definition: widget.h:151
void popClipArea() restrict2 override final
const bool Visible_true
Definition: visible.h:29
WidgetList::const_iterator WidgetListConstIterator
void pushClipArea(const Rect &restrict area) restrict2 override final
Definition: rect.h:72
virtual void safeDraw(Graphics *const graphics)=0
#define BLOCK_START(name)
Definition: perfomance.h:78
#define BLOCK_END(name)
Definition: perfomance.h:79
int x
Definition: rect.h:208
#define CAST_S32
Definition: cast.h:29
int y
Definition: rect.h:213
int height
Definition: rect.h:223
Definition: widget.h:97
virtual void drawChildren(Graphics *const graphics)
virtual void pushClipArea(const Rect &area)
Definition: graphics.cpp:676
#define restrict
Definition: localconsts.h:164
WidgetList mWidgets
Rect mDimension
Definition: widget.h:1100

◆ setFocusHandler()

void BasicContainer::setFocusHandler ( FocusHandler *const  focusHandler)
virtual

Sets the focus handler to be used.

WARNING: This function is used internally and should not be called or overloaded unless you know what you are doing.

Parameters
focusHandlerThe focus handler to use.
See also
getFocusHandler

Reimplemented from Widget.

Definition at line 247 of file basiccontainer.cpp.

References FOR_EACH, Widget::mInternalFocusHandler, mWidgets, and Widget::setFocusHandler().

Referenced by BasicContainer().

249 {
250  Widget::setFocusHandler(focusHandler);
251 
252  if (mInternalFocusHandler != nullptr)
253  return;
254 
256  (*iter)->setFocusHandler(focusHandler);
257 }
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
WidgetList::const_iterator WidgetListConstIterator
FocusHandler * mInternalFocusHandler
Definition: widget.h:1121
WidgetList mWidgets
virtual void setFocusHandler(FocusHandler *const focusHandler)
Definition: widget.cpp:237

◆ setInternalFocusHandler()

void BasicContainer::setInternalFocusHandler ( FocusHandler *const  focusHandler)

Definition at line 430 of file basiccontainer.cpp.

References FOR_EACH, Widget::getFocusHandler(), Widget::mInternalFocusHandler, mWidgets, restrict, and Widget::setInternalFocusHandler().

Referenced by BasicContainer().

432 {
433  Widget::setInternalFocusHandler(focusHandler);
434 
435  FocusHandler *const restrict handler = mInternalFocusHandler != nullptr ?
438  {
439  (*iter)->setFocusHandler(handler);
440  }
441 }
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
WidgetList::const_iterator WidgetListConstIterator
FocusHandler * getFocusHandler()
Definition: widget.h:473
FocusHandler * mInternalFocusHandler
Definition: widget.h:1121
#define restrict
Definition: localconsts.h:164
WidgetList mWidgets
void setInternalFocusHandler(FocusHandler *const internalFocusHandler)
Definition: widget.cpp:460

◆ showWidgetPart()

void BasicContainer::showWidgetPart ( Widget *const  widget,
const Rect area 
)
virtual

Shows a certain part of a widget in the basic container. Used when widgets want a specific part to be visible in its parent. An example is a TextArea that wants a specific part of its text to be visible when a TextArea is a child of a ScrollArea.

Parameters
widgetThe widget whom wants a specific part of itself to be visible.
areaThe rectangle to be visible.

Reimplemented from Widget.

Reimplemented in ScrollArea.

Definition at line 406 of file basiccontainer.cpp.

References getChildrenArea(), Rect::height, Rect::width, x, and y.

Referenced by BasicContainer(), and ScrollArea::showWidgetPart().

408 {
409  if (widget == nullptr)
410  return;
411 
412  const Rect widgetArea = getChildrenArea();
413 
414  const int x = widget->mDimension.x;
415  const int y = widget->mDimension.y;
416  const int ax = area.x + x;
417  const int ay = area.y + y;
418 
419  if (ax < 0)
420  widget->setX(-area.x);
421  else if (ax + area.width > widgetArea.width)
422  widget->setX(widgetArea.width - area.x - area.width);
423 
424  if (ay < 0)
425  widget->setY(-area.y);
426  else if (ay + area.height > widgetArea.height)
427  widget->setY(widgetArea.height - area.y - area.height);
428 }
int width
Definition: rect.h:218
void setY(const int y)
Definition: widget.cpp:153
Definition: rect.h:72
int x
Definition: rect.h:208
void setX(const int x)
Definition: widget.cpp:146
int y
Definition: rect.h:213
int height
Definition: rect.h:223
Rect mDimension
Definition: widget.h:1100

Field Documentation

◆ mLogicWidgets

WidgetList BasicContainer::mLogicWidgets
protected

◆ mWidgets

WidgetList BasicContainer::mWidgets
protected

The documentation for this class was generated from the following files: