ManaPlus
Public Member Functions | Static Public Member Functions | Protected Attributes | Private Attributes

#include <popup.h>

Inheritance diagram for Popup:
Container MouseListener WidgetListener BasicContainer2 BasicContainer Widget WidgetDeathListener Widget2 BeingPopup ItemPopup PopupList PopupMenu SkillPopup SpeechBubble SpellPopup StatusPopup TextBoxPopup TextPopup

Public Member Functions

 Popup (const std::string &name, std::string skin)
 
 ~Popup ()
 
void draw (Graphics *const graphics)
 
void safeDraw (Graphics *const graphics)
 
void setContentSize (int width, int height)
 
void setLocationRelativeTo (const Widget *const widget)
 
void mouseMoved (MouseEvent &event)
 
void setMinWidth (const int width)
 
int getMinWidth () const
 
void setMinHeight (const int height)
 
int getMinHeight () const
 
void setMaxWidth (const int width)
 
int getMaxWidth () const
 
void setMaxHeight (const int height)
 
int getMaxHeight () const
 
int getPadding () const
 
void setPadding (int padding)
 
void setPopupName (const std::string &name)
 
const std::string & getPopupName () const
 
void scheduleDelete ()
 
Rect getChildrenArea ()
 
void position (const int x, const int y)
 
void hide ()
 
void widgetResized (const Event &event)
 
void widgetMoved (const Event &event)
 
bool isPopupVisible () const
 
void postInit ()
 
- Public Member Functions inherited from Container
 Container (const Widget2 *const widget)
 
 ~Container ()
 
bool safeRemove (Widget *const widget)
 
void removeControls ()
 
- Public Member Functions inherited from BasicContainer2
 BasicContainer2 (const Widget2 *const widget)
 
 ~BasicContainer2 ()
 
void setOpaque (Opaque opaque)
 
bool isOpaque () const
 
virtual void add (Widget *const widget)
 
void addXY (Widget *const widget, const int x, const int y)
 
- Public Member Functions inherited from BasicContainer
 BasicContainer (const Widget2 *const widget)
 
 ~BasicContainer ()
 
void showWidgetPart (Widget *const widget, const Rect &area)
 
void moveToTop (Widget *const widget)
 
void moveToBottom (Widget *const widget)
 
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 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 ()
 
- 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 ()
 
- Public Member Functions inherited from MouseListener
virtual ~MouseListener ()
 
virtual void mouseEntered (MouseEvent &event)
 
virtual void mouseExited (MouseEvent &event)
 
virtual void mousePressed (MouseEvent &event)
 
virtual void mouseReleased (MouseEvent &event)
 
virtual void mouseClicked (MouseEvent &event)
 
virtual void mouseWheelMovedUp (MouseEvent &event)
 
virtual void mouseWheelMovedDown (MouseEvent &event)
 
virtual void mouseDragged (MouseEvent &event)
 
- Public Member Functions inherited from WidgetListener
virtual ~WidgetListener ()
 
virtual void widgetHidden (const Event &event)
 
virtual void widgetShown (const Event &event)
 

Static Public Member Functions

static void setWindowContainer (WindowContainer *const windowContainer)
 
- 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)
 

Protected Attributes

int mPadding
 
SkinmSkin
 
- Protected Attributes inherited from BasicContainer2
Opaque mOpaque
 
- Protected Attributes inherited from BasicContainer
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
 

Private Attributes

std::string mPopupName
 
ImageCollectionmVertexes
 
int mMinWidth
 
int mMinHeight
 
int mMaxWidth
 
int mMaxHeight
 
bool mInit
 

Additional Inherited Members

- Data Fields inherited from Widget
Visible mVisible
 
- Protected Types inherited from BasicContainer
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 inherited from BasicContainer
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 Member Functions inherited from MouseListener
 MouseListener ()
 
- Protected Member Functions inherited from WidgetListener
 WidgetListener ()
 
- Static Protected Attributes inherited from Widget
static FontmGlobalFont = 0
 

Detailed Description

A light version of the Window class. Particularly suited for popup type functionality that doesn't need to be resized or moved around by the mouse once created, but only needs to display some simple content, like a static message.

Popups, in general, shouldn't also need to update their content once created, although this is not an explicit requirement to use the popup class.

Definition at line 48 of file popup.h.

Constructor & Destructor Documentation

◆ Popup()

Popup::Popup ( const std::string &  name,
std::string  skin 
)

Constructor. Initializes the title to the given text and hooks itself into the popup container.

Parameters
nameA human readable name for the popup. Only useful for debugging purposes.
skinThe location where the Popup's skin XML can be found.

Definition at line 39 of file popup.cpp.

References BasicContainer2::add(), Widget::addWidgetListener(), Skin::getOption(), Skin::getPadding(), Theme::getThemePath(), Theme::load(), Logger::log(), logger, mSkin, Widget2::mWindow, setPadding(), Widget2::setPalette(), Widget::setVisible(), theme, Visible_false, and windowContainer.

40  :
41  Container(nullptr),
42  MouseListener(),
44  mPadding(3),
45  mSkin(nullptr),
46  mPopupName(name),
48  mMinWidth(100),
49  mMinHeight(40),
52  mInit(false)
53 {
54  logger->log("Popup::Popup(\"%s\")", name.c_str());
55 
56  mWindow = this;
57 
58  addWidgetListener(this);
59 
60  if (skin.empty())
61  skin = "popup.xml";
62 
63  if (theme != nullptr)
64  {
65  mSkin = theme->load(skin,
66  "popup.xml",
67  true,
69  if (mSkin != nullptr)
70  {
72  setPalette(mSkin->getOption("palette"));
73  }
74  }
75 
76  if (windowContainer != nullptr)
77  windowContainer->add(this);
78 
79  // Popups are invisible by default
81 }
WindowContainer * windowContainer
void setVisible(Visible visible)
Definition: widget.cpp:224
int mWidth
Definition: graphics.h:483
static std::string getThemePath()
Definition: theme.h:66
Skin * load(const std::string &filename, const std::string &filename2, const bool full, const std::string &defaultPath)
Definition: theme.cpp:178
int mPadding
Definition: popup.h:180
int getOption(const std::string &name) const
Definition: skin.h:105
Container(const Widget2 *const widget)
Definition: container.cpp:29
Logger * logger
Definition: logger.cpp:88
int getPadding() const
Definition: skin.h:99
int mMaxHeight
Definition: popup.h:189
int mMaxWidth
Definition: popup.h:188
const bool Visible_false
Definition: visible.h:29
Widget * mWindow
Definition: widget2.h:111
virtual void add(Widget *const widget)
Graphics * mainGraphics
Definition: graphics.cpp:108
int mMinWidth
Definition: popup.h:186
bool mInit
Definition: popup.h:190
int mMinHeight
Definition: popup.h:187
int mHeight
Definition: graphics.h:484
std::string mPopupName
Definition: popup.h:184
void addWidgetListener(WidgetListener *const widgetListener)
Definition: widget.cpp:301
Theme * theme
Definition: theme.cpp:61
ImageCollection * mVertexes
Definition: popup.h:185
void log(const char *const log_text,...)
Definition: logger.cpp:264
void setPadding(int padding)
Definition: popup.h:137
Skin * mSkin
Definition: popup.h:181
void setPalette(int palette)
Definition: widget2.h:68

◆ ~Popup()

Popup::~Popup ( )

Destructor. Deletes all the added widgets.

Definition at line 83 of file popup.cpp.

References delete2, Logger::log(), logger, mInit, mPopupName, mSkin, mVertexes, theme, and Theme::unload().

84 {
85  logger->log("Popup::~Popup(\"%s\")", mPopupName.c_str());
86 
88 
89  if (mSkin != nullptr)
90  {
91  if (theme != nullptr)
92  theme->unload(mSkin);
93  mSkin = nullptr;
94  }
95 
96  if (!mInit)
97  {
98  logger->log("error: Popup created without calling postInit(): "
99  + mPopupName);
100  }
101 }
void unload(Skin *const skin)
Definition: theme.cpp:249
#define delete2(var)
Definition: delete2.h:24
Logger * logger
Definition: logger.cpp:88
bool mInit
Definition: popup.h:190
std::string mPopupName
Definition: popup.h:184
Theme * theme
Definition: theme.cpp:61
ImageCollection * mVertexes
Definition: popup.h:185
void log(const char *const log_text,...)
Definition: logger.cpp:264
Skin * mSkin
Definition: popup.h:181

Member Function Documentation

◆ draw()

void Popup::draw ( Graphics *const  graphics)
virtual

Draws the popup.

Reimplemented from BasicContainer2.

Definition at line 108 of file popup.cpp.

References BLOCK_END, BLOCK_START, Graphics::calcWindow(), ImageCollection::clear(), BasicContainer::drawChildren(), Graphics::drawTileCollection(), Graphics::finalize(), Skin::getBorder(), Rect::height, Widget::mDimension, Widget::mRedraw, mSkin, mVertexes, and Rect::width.

109 {
110  BLOCK_START("Popup::draw")
111 
112  if (mSkin != nullptr)
113  {
114  if (mRedraw)
115  {
116  mRedraw = false;
117  mVertexes->clear();
118  graphics->calcWindow(mVertexes,
119  0, 0,
121  mSkin->getBorder());
122  }
123  // need cache or remove calc call.
124  graphics->finalize(mVertexes);
125  graphics->drawTileCollection(mVertexes);
126  }
127 
128  drawChildren(graphics);
129  BLOCK_END("Popup::draw")
130 }
int width
Definition: rect.h:218
virtual void drawTileCollection(const ImageCollection *const vertCol)=0
#define BLOCK_START(name)
Definition: perfomance.h:78
if(!vert) return
#define BLOCK_END(name)
Definition: perfomance.h:79
virtual void finalize(ImageCollection *const col)
Definition: graphics.h:464
const ImageRect & getBorder() const
Definition: skin.h:67
int height
Definition: rect.h:223
virtual void drawChildren(Graphics *const graphics)
bool mRedraw
Definition: widget.h:1163
ImageCollection * mVertexes
Definition: popup.h:185
Rect mDimension
Definition: widget.h:1100
Skin * mSkin
Definition: popup.h:181
virtual void calcWindow(ImageCollection *const vertCol, const int x, const int y, const int w, const int h, const ImageRect &imgRect)=0

◆ getChildrenArea()

Rect Popup::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 BasicContainer.

Definition at line 147 of file popup.cpp.

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

Referenced by getPopupName().

148 {
149  const int pad2 = mPadding * 2;
150  return Rect(mPadding, mPadding,
151  mDimension.width - pad2, mDimension.height - pad2);
152 }
int width
Definition: rect.h:218
Definition: rect.h:72
int mPadding
Definition: popup.h:180
int height
Definition: rect.h:223
Rect mDimension
Definition: widget.h:1100

◆ getMaxHeight()

int Popup::getMaxHeight ( ) const
inline

Definition at line 124 of file popup.h.

References mMaxHeight.

125  { return mMaxHeight; }
int mMaxHeight
Definition: popup.h:189

◆ getMaxWidth()

int Popup::getMaxWidth ( ) const
inline

Definition at line 116 of file popup.h.

References mMaxWidth, and setMaxHeight().

117  { return mMaxWidth; }
int mMaxWidth
Definition: popup.h:188

◆ getMinHeight()

int Popup::getMinHeight ( ) const
inline

Definition at line 108 of file popup.h.

References mMinHeight, and setMaxWidth().

109  { return mMinHeight; }
int mMinHeight
Definition: popup.h:187

◆ getMinWidth()

int Popup::getMinWidth ( ) const
inline

Definition at line 100 of file popup.h.

References mMinWidth, and setMinHeight().

101  { return mMinWidth; }
int mMinWidth
Definition: popup.h:186

◆ getPadding()

int Popup::getPadding ( ) const
inline

Gets the padding of the popup. The padding is the distance between the popup border and the content.

Returns
The padding of the popup.
See also
setPadding

Definition at line 134 of file popup.h.

References mPadding.

Referenced by DropDown::dropDown().

135  { return mPadding; }
int mPadding
Definition: popup.h:180

◆ getPopupName()

const std::string& Popup::getPopupName ( ) const
inline

Definition at line 146 of file popup.h.

References getChildrenArea(), hide(), mPopupName, position(), scheduleDelete(), widgetMoved(), widgetResized(), x, and y.

147  { return mPopupName; }
std::string mPopupName
Definition: popup.h:184

◆ hide()

void Popup::hide ( )

◆ isPopupVisible()

bool Popup::isPopupVisible ( ) const
inline

◆ mouseMoved()

void Popup::mouseMoved ( MouseEvent event)
virtual

Called when the mouse has moved in the widget area and no mouse button has been pressed (i.e no widget is being dragged).

Parameters
eventDescribes the event.

Reimplemented from MouseListener.

Definition at line 252 of file popup.cpp.

References PopupManager::hideBeingPopup(), PopupManager::hideTextPopup(), Widget::mRedraw, and popupManager.

Referenced by TextBoxPopup::mouseMoved(), SpellPopup::mouseMoved(), SkillPopup::mouseMoved(), ItemPopup::mouseMoved(), and TextPopup::mouseMoved().

253 {
254  if (popupManager != nullptr)
255  {
258  }
259  mRedraw = true;
260 }
PopupManager * popupManager
static void hideTextPopup()
static void hideBeingPopup()
bool mRedraw
Definition: widget.h:1163

◆ position()

void Popup::position ( const int  x,
const int  y 
)

Sets the location to display the popup. Tries to horizontally center the popup and provide a vertical buffer between the given point and the popup. Prevents the popup from extending off-screen, if possible.

Definition at line 232 of file popup.cpp.

References Rect::height, mainGraphics, Widget::mDimension, Graphics::mHeight, Widget::mRedraw, Graphics::mWidth, Widget::requestMoveToTop(), Widget::setPosition(), Widget::setVisible(), Visible_true, and Rect::width.

Referenced by getPopupName(), ItemLinkHandler::handleItemLink(), ItemAmountWindow::mouseMoved(), ItemShortcutContainer::mouseMoved(), VirtShortcutContainer::mouseMoved(), ShopListBox::mouseMoved(), ItemContainer::mouseMoved(), EquipmentWindow::mouseMoved(), SkillListBox::mouseMoved(), SkillRectangleListBox::mouseMoved(), and BeingPopup::show().

233 {
234  const int distance = 20;
235 
236  const int width = mDimension.width;
237  const int height = mDimension.height;
238  int posX = std::max(0, x - width / 2);
239  int posY = y + distance;
240 
241  if (posX + width > mainGraphics->mWidth)
242  posX = mainGraphics->mWidth - width;
243  if (posY + height > mainGraphics->mHeight)
244  posY = y - height - distance;
245 
246  setPosition(posX, posY);
249  mRedraw = true;
250 }
int width
Definition: rect.h:218
const bool Visible_true
Definition: visible.h:29
void setVisible(Visible visible)
Definition: widget.cpp:224
virtual void requestMoveToTop()
Definition: widget.cpp:212
int mWidth
Definition: graphics.h:483
Graphics * mainGraphics
Definition: graphics.cpp:108
void setPosition(const int x, const int y)
Definition: widget.cpp:160
int height
Definition: rect.h:223
int mHeight
Definition: graphics.h:484
bool mRedraw
Definition: widget.h:1163
Rect mDimension
Definition: widget.h:1100

◆ postInit()

void Popup::postInit ( )
inlinevirtual

◆ safeDraw()

void Popup::safeDraw ( Graphics *const  graphics)
virtual

Reimplemented from BasicContainer2.

Definition at line 132 of file popup.cpp.

References BLOCK_END, BLOCK_START, Graphics::drawImageRect(), Skin::getBorder(), Rect::height, Widget::mDimension, mSkin, BasicContainer::safeDrawChildren(), and Rect::width.

133 {
134  BLOCK_START("Popup::safeDraw")
135 
136  if (mSkin != nullptr)
137  {
138  graphics->drawImageRect(0, 0,
140  mSkin->getBorder());
141  }
142 
143  safeDrawChildren(graphics);
144  BLOCK_END("Popup::safeDraw")
145 }
int width
Definition: rect.h:218
virtual void drawImageRect(const int x, const int y, const int w, const int h, const ImageRect &imgRect)=0
#define BLOCK_START(name)
Definition: perfomance.h:78
if(!vert) return
#define BLOCK_END(name)
Definition: perfomance.h:79
const ImageRect & getBorder() const
Definition: skin.h:67
int height
Definition: rect.h:223
Rect mDimension
Definition: widget.h:1100
virtual void safeDrawChildren(Graphics *const graphics)
Skin * mSkin
Definition: popup.h:181

◆ scheduleDelete()

void Popup::scheduleDelete ( )

Schedule this popup for deletion. It will be deleted at the start of the next logic update.

Definition at line 227 of file popup.cpp.

References WindowContainer::scheduleDelete(), and windowContainer.

Referenced by getPopupName().

228 {
230 }
void scheduleDelete(Widget *const widget)
WindowContainer * windowContainer

◆ setContentSize()

void Popup::setContentSize ( int  width,
int  height 
)

Sets the size of this popup.

Definition at line 154 of file popup.cpp.

References mMaxHeight, mMaxWidth, mMinHeight, mMinWidth, mPadding, Widget::mRedraw, and Widget::setSize().

Referenced by SpellPopup::setItem(), ItemPopup::setItem(), SpeechBubble::setText(), BeingPopup::show(), PopupList::show(), TextBoxPopup::show(), SkillPopup::show(), PopupMenu::showPopup(), and SpeechBubble::SpeechBubble().

155 {
156  const int pad2 = mPadding * 2;
157  width += pad2;
158  height += pad2;
159 
160  if (mMinWidth > width)
161  width = mMinWidth;
162  else if (mMaxWidth < width)
163  width = mMaxWidth;
164  if (mMinHeight > height)
165  height = mMinHeight;
166  else if (mMaxHeight < height)
167  height = mMaxHeight;
168 
169  setSize(width, height);
170  mRedraw = true;
171 }
void setSize(const int width, const int height)
Definition: widget.cpp:366
int mPadding
Definition: popup.h:180
int mMaxHeight
Definition: popup.h:189
int mMaxWidth
Definition: popup.h:188
int mMinWidth
Definition: popup.h:186
int mMinHeight
Definition: popup.h:187
bool mRedraw
Definition: widget.h:1163

◆ setLocationRelativeTo()

void Popup::setLocationRelativeTo ( const Widget *const  widget)

Sets the location relative to the given widget.

Definition at line 173 of file popup.cpp.

References Widget::getAbsolutePosition(), Widget::getHeight(), Widget::getWidth(), Rect::height, Widget::mDimension, Widget::mRedraw, Widget::setPosition(), Rect::width, x, Rect::x, y, and Rect::y.

174 {
175  if (widget == nullptr)
176  return;
177 
178  int wx, wy;
179  int x, y;
180 
181  widget->getAbsolutePosition(wx, wy);
182  getAbsolutePosition(x, y);
183 
184  setPosition(mDimension.x + (wx + (widget->getWidth()
185  - mDimension.width) / 2 - x),
186  mDimension.y + (wy + (widget->getHeight()
187  - mDimension.height) / 2 - y));
188  mRedraw = true;
189 }
int width
Definition: rect.h:218
int getWidth() const
Definition: widget.h:220
int x
Definition: rect.h:208
int y
Definition: rect.h:213
void setPosition(const int x, const int y)
Definition: widget.cpp:160
int height
Definition: rect.h:223
virtual void getAbsolutePosition(int &x, int &y) const
Definition: widget.cpp:311
bool mRedraw
Definition: widget.h:1163
int getHeight() const
Definition: widget.h:239
Rect mDimension
Definition: widget.h:1100

◆ setMaxHeight()

void Popup::setMaxHeight ( const int  height)

Sets the minimum height of the popup.

Definition at line 222 of file popup.cpp.

References mMaxHeight.

Referenced by getMaxWidth().

223 {
224  mMaxHeight = height;
225 }
int mMaxHeight
Definition: popup.h:189

◆ setMaxWidth()

void Popup::setMaxWidth ( const int  width)

Sets the maximum width of the popup.

Definition at line 217 of file popup.cpp.

References mMaxWidth.

Referenced by getMinHeight().

218 {
219  mMaxWidth = width;
220 }
int mMaxWidth
Definition: popup.h:188

◆ setMinHeight()

void Popup::setMinHeight ( const int  height)

Sets the minimum height of the popup.

Definition at line 204 of file popup.cpp.

References Skin::getMinHeight(), mMinHeight, and mSkin.

Referenced by BeingPopup::BeingPopup(), getMinWidth(), TextBoxPopup::postInit(), and SpeechBubble::SpeechBubble().

205 {
206  if (mSkin != nullptr)
207  {
208  mMinHeight = height > mSkin->getMinHeight() ?
209  height : mSkin->getMinHeight();
210  }
211  else
212  {
213  mMinHeight = height;
214  }
215 }
int getMinHeight() const
Definition: skin.cpp:141
int mMinHeight
Definition: popup.h:187
Skin * mSkin
Definition: popup.h:181

◆ setMinWidth()

void Popup::setMinWidth ( const int  width)

Sets the minimum width of the popup.

Definition at line 191 of file popup.cpp.

References Skin::getMinWidth(), mMinWidth, and mSkin.

Referenced by SpeechBubble::SpeechBubble().

192 {
193  if (mSkin != nullptr)
194  {
195  mMinWidth = width > mSkin->getMinWidth()
196  ? width : mSkin->getMinWidth();
197  }
198  else
199  {
200  mMinWidth = width;
201  }
202 }
int mMinWidth
Definition: popup.h:186
Skin * mSkin
Definition: popup.h:181
int getMinWidth() const
Definition: skin.cpp:128

◆ setPadding()

void Popup::setPadding ( int  padding)
inline

Definition at line 137 of file popup.h.

References mPadding.

Referenced by Popup().

138  { mPadding = padding; }
int mPadding
Definition: popup.h:180

◆ setPopupName()

void Popup::setPopupName ( const std::string &  name)
inline

Sets the name of the popup. This is only useful for debug purposes.

Definition at line 143 of file popup.h.

References mPopupName.

144  { mPopupName = name; }
std::string mPopupName
Definition: popup.h:184

◆ setWindowContainer()

void Popup::setWindowContainer ( WindowContainer *const  windowContainer)
static

Sets the window container to be used by new popups.

Definition at line 103 of file popup.cpp.

References windowContainer.

104 {
105  windowContainer = wc;
106 }

◆ widgetMoved()

void Popup::widgetMoved ( const Event event)
virtual

Invoked when a widget is moved.

Parameters
eventDescribes the event.

Reimplemented from WidgetListener.

Definition at line 273 of file popup.cpp.

References Widget::mRedraw.

Referenced by getPopupName().

274 {
275  mRedraw = true;
276 }
bool mRedraw
Definition: widget.h:1163

◆ widgetResized()

void Popup::widgetResized ( const Event event)
virtual

Invoked when a widget changes its size.

Parameters
eventDescribes the event.

Reimplemented from WidgetListener.

Reimplemented in PopupList.

Definition at line 268 of file popup.cpp.

References Widget::mRedraw.

Referenced by getPopupName(), and PopupList::widgetResized().

269 {
270  mRedraw = true;
271 }
bool mRedraw
Definition: widget.h:1163

Field Documentation

◆ mInit

bool Popup::mInit
private

Definition at line 190 of file popup.h.

Referenced by postInit(), and ~Popup().

◆ mMaxHeight

int Popup::mMaxHeight
private

Maximum popup height

Definition at line 189 of file popup.h.

Referenced by getMaxHeight(), setContentSize(), and setMaxHeight().

◆ mMaxWidth

int Popup::mMaxWidth
private

Maximum popup width

Definition at line 188 of file popup.h.

Referenced by getMaxWidth(), setContentSize(), and setMaxWidth().

◆ mMinHeight

int Popup::mMinHeight
private

Minimum popup height

Definition at line 187 of file popup.h.

Referenced by getMinHeight(), setContentSize(), and setMinHeight().

◆ mMinWidth

int Popup::mMinWidth
private

Minimum popup width

Definition at line 186 of file popup.h.

Referenced by getMinWidth(), setContentSize(), and setMinWidth().

◆ mPadding

int Popup::mPadding
protected

◆ mPopupName

std::string Popup::mPopupName
private

Name of the popup

Definition at line 184 of file popup.h.

Referenced by getPopupName(), setPopupName(), and ~Popup().

◆ mSkin

Skin* Popup::mSkin
protected

Skin in use by this popup

Definition at line 181 of file popup.h.

Referenced by draw(), Popup(), safeDraw(), setMinHeight(), setMinWidth(), and ~Popup().

◆ mVertexes

ImageCollection* Popup::mVertexes
private

Definition at line 185 of file popup.h.

Referenced by draw(), and ~Popup().


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