ManaPlus
Public Member Functions | Private Attributes
PlayerBox Class Reference

#include <playerbox.h>

Inheritance diagram for PlayerBox:
Widget MouseListener Widget2

Public Member Functions

 PlayerBox (Widget2 *const widget, Being *const being, const std::string &skin, const std::string &selectedSkin)
 
 PlayerBox (Widget2 *const widget, const std::string &skin, const std::string &selectedSkin)
 
 ~PlayerBox ()
 
void init (std::string name, std::string selectedName)
 
void setPlayer (Being *being)
 
void draw (Graphics *const graphics)
 
void safeDraw (Graphics *const graphics)
 
void drawFrame (Graphics *const graphics)
 
void safeDrawFrame (Graphics *const graphics)
 
BeinggetBeing ()
 
void setSelected (bool b)
 
void mouseReleased (MouseEvent &event)
 
- Public Member Functions inherited from Widget
 Widget (const Widget2 *const widget)
 
 ~Widget ()
 
void setFrameSize (const unsigned int frameSize)
 
unsigned int getFrameSize () const
 
virtual void logic ()
 
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 ()
 
virtual void setFocusHandler (FocusHandler *const focusHandler)
 
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
 
virtual WidgetgetWidgetAt (int x, int y)
 
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 Rect getChildrenArea ()
 
virtual FocusHandlergetInternalFocusHandler ()
 
void setInternalFocusHandler (FocusHandler *const internalFocusHandler)
 
virtual void moveToTop (Widget *widget)
 
virtual void moveToBottom (Widget *widget)
 
virtual void focusNext ()
 
virtual void focusPrevious ()
 
virtual void showWidgetPart (Widget *const widget, const Rect &area)
 
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 MouseListener
virtual ~MouseListener ()
 
virtual void mouseEntered (MouseEvent &event)
 
virtual void mouseExited (MouseEvent &event)
 
virtual void mousePressed (MouseEvent &event)
 
virtual void mouseClicked (MouseEvent &event)
 
virtual void mouseWheelMovedUp (MouseEvent &event)
 
virtual void mouseWheelMovedDown (MouseEvent &event)
 
virtual void mouseMoved (MouseEvent &event)
 
virtual void mouseDragged (MouseEvent &event)
 

Private Attributes

BeingmBeing
 
float mAlpha
 
ImageRect mBackground
 
ImageRect mSelectedBackground
 
SkinmSkin
 
SkinmSelectedSkin
 
int mOffsetX
 
int mOffsetY
 
bool mDrawBackground
 
bool mSelected
 

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
 
- 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 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 MouseListener
 MouseListener ()
 
- 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
 
- Static Protected Attributes inherited from Widget
static FontmGlobalFont = 0
 

Detailed Description

A box showing a player character.

Definition at line 42 of file playerbox.h.

Constructor & Destructor Documentation

◆ PlayerBox() [1/2]

PlayerBox::PlayerBox ( Widget2 *const  widget,
Being *const  being,
const std::string &  skin,
const std::string &  selectedSkin 
)

Constructor. Takes the initial player character that this box should display, which defaults to NULL.

Definition at line 38 of file playerbox.cpp.

References init().

41  :
42  Widget(widget),
43  MouseListener(),
44  mBeing(being),
45  mAlpha(1.0),
46  mBackground(),
48  mSkin(nullptr),
49  mSelectedSkin(nullptr),
50  mOffsetX(-mapTileSize / 2),
52  mDrawBackground(false),
53  mSelected(false)
54 {
55  init(skin, selectedSkin);
56 }
int mOffsetY
Definition: playerbox.h:107
bool mDrawBackground
Definition: playerbox.h:108
bool mSelected
Definition: playerbox.h:109
ImageRect mBackground
Definition: playerbox.h:102
float mAlpha
Definition: playerbox.h:101
int mOffsetX
Definition: playerbox.h:106
Widget(const Widget2 *const widget)
Definition: widget.cpp:84
Being * mBeing
Definition: playerbox.h:100
Skin * mSkin
Definition: playerbox.h:104
Skin * mSelectedSkin
Definition: playerbox.h:105
static const int mapTileSize
Definition: map.h:26
void init(std::string name, std::string selectedName)
Definition: playerbox.cpp:87
ImageRect mSelectedBackground
Definition: playerbox.h:103

◆ PlayerBox() [2/2]

PlayerBox::PlayerBox ( Widget2 *const  widget,
const std::string &  skin,
const std::string &  selectedSkin 
)

Definition at line 58 of file playerbox.cpp.

References init().

60  :
61  Widget(widget),
62  MouseListener(),
63  mBeing(nullptr),
64  mAlpha(1.0),
65  mBackground(),
67  mSkin(nullptr),
68  mSelectedSkin(nullptr),
69  mOffsetX(-mapTileSize / 2),
71  mDrawBackground(false),
72  mSelected(false)
73 {
74  init(skin, selectedSkin);
75 }
int mOffsetY
Definition: playerbox.h:107
bool mDrawBackground
Definition: playerbox.h:108
bool mSelected
Definition: playerbox.h:109
ImageRect mBackground
Definition: playerbox.h:102
float mAlpha
Definition: playerbox.h:101
int mOffsetX
Definition: playerbox.h:106
Widget(const Widget2 *const widget)
Definition: widget.cpp:84
Being * mBeing
Definition: playerbox.h:100
Skin * mSkin
Definition: playerbox.h:104
Skin * mSelectedSkin
Definition: playerbox.h:105
static const int mapTileSize
Definition: map.h:26
void init(std::string name, std::string selectedName)
Definition: playerbox.cpp:87
ImageRect mSelectedBackground
Definition: playerbox.h:103

◆ ~PlayerBox()

PlayerBox::~PlayerBox ( )

Destructor.

Definition at line 77 of file playerbox.cpp.

References gui, mBackground, mBeing, mSelectedBackground, Gui::removeDragged(), and Theme::unloadRect().

78 {
79  if (gui != nullptr)
80  gui->removeDragged(this);
81 
84  mBeing = nullptr;
85 }
Gui * gui
Definition: gui.cpp:110
ImageRect mBackground
Definition: playerbox.h:102
Being * mBeing
Definition: playerbox.h:100
void removeDragged(const Widget *const widget)
Definition: gui.cpp:1160
ImageRect mSelectedBackground
Definition: playerbox.h:103
static void unloadRect(const ImageRect &rect, const int start, const int end)
Definition: theme.cpp:1124

Member Function Documentation

◆ draw()

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

Draws the scroll area.

Implements Widget.

Definition at line 126 of file playerbox.cpp.

References BLOCK_END, BLOCK_START, Being::drawBasic(), ImageRect::grid, Settings::guiAlpha, Rect::height, mAlpha, mBackground, mBeing, Widget::mDimension, Widget::mFrameSize, mOffsetX, mOffsetY, Image::setAlpha(), settings, Rect::width, x, and y.

Referenced by safeDraw(), and setPlayer().

127 {
128  BLOCK_START("PlayerBox::draw")
129  if (mBeing != nullptr)
130  {
131  const int bs = mFrameSize;
132  const int x = mDimension.width / 2 + bs + mOffsetX;
133  const int y = mDimension.height - bs + mOffsetY;
134  mBeing->drawBasic(graphics, x, y);
135  }
136 
137  if (settings.guiAlpha != mAlpha)
138  {
139  const float alpha = settings.guiAlpha;
140  for (int a = 0; a < 9; a++)
141  {
142  if (mBackground.grid[a] != nullptr)
143  mBackground.grid[a]->setAlpha(alpha);
144  }
145  }
146  BLOCK_END("PlayerBox::draw")
147 }
int width
Definition: rect.h:218
int mOffsetY
Definition: playerbox.h:107
#define BLOCK_START(name)
Definition: perfomance.h:78
void drawBasic(Graphics *const graphics, const int x, const int y) const
Definition: being.cpp:3906
ImageRect mBackground
Definition: playerbox.h:102
float mAlpha
Definition: playerbox.h:101
if(!vert) return
#define BLOCK_END(name)
Definition: perfomance.h:79
int mOffsetX
Definition: playerbox.h:106
Settings settings
Definition: settings.cpp:31
virtual void setAlpha(const float alpha)
Definition: image.cpp:285
Image * grid[9]
Definition: imagerect.h:41
unsigned int mFrameSize
Definition: widget.h:1137
int height
Definition: rect.h:223
Being * mBeing
Definition: playerbox.h:100
float guiAlpha
Definition: settings.h:129
Rect mDimension
Definition: widget.h:1100

◆ drawFrame()

void PlayerBox::drawFrame ( Graphics *const  graphics)
virtual

Draws the background and border of the scroll area.

Reimplemented from Widget.

Definition at line 154 of file playerbox.cpp.

References BLOCK_END, BLOCK_START, Graphics::drawImageRect(), Rect::height, mBackground, Widget::mDimension, mDrawBackground, Widget::mFrameSize, mSelected, mSelectedBackground, and Rect::width.

Referenced by setPlayer().

155 {
156  BLOCK_START("PlayerBox::drawFrame")
158  {
159  const int bs = mFrameSize * 2;
160  const int w = mDimension.width + bs;
161  const int h = mDimension.height + bs;
162 
163  if (!mSelected)
164  graphics->drawImageRect(0, 0, w, h, mBackground);
165  else
166  graphics->drawImageRect(0, 0, w, h, mSelectedBackground);
167  }
168  BLOCK_END("PlayerBox::drawFrame")
169 }
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
bool mDrawBackground
Definition: playerbox.h:108
#define BLOCK_START(name)
Definition: perfomance.h:78
bool mSelected
Definition: playerbox.h:109
ImageRect mBackground
Definition: playerbox.h:102
if(!vert) return
#define BLOCK_END(name)
Definition: perfomance.h:79
unsigned int mFrameSize
Definition: widget.h:1137
int height
Definition: rect.h:223
ImageRect mSelectedBackground
Definition: playerbox.h:103
Rect mDimension
Definition: widget.h:1100

◆ getBeing()

Being* PlayerBox::getBeing ( )
inline

Definition at line 91 of file playerbox.h.

References mBeing.

Referenced by NpcDialog::setAvatarAction(), NpcDialog::setAvatarDirection(), and NpcDialog::~NpcDialog().

92  { return mBeing; }
Being * mBeing
Definition: playerbox.h:100

◆ init()

void PlayerBox::init ( std::string  name,
std::string  selectedName 
)

Definition at line 87 of file playerbox.cpp.

References Widget::addMouseListener(), Skin::getOption(), ImageRect::grid, Theme::loadSkinRect(), Widget::mAllowLogic, mapTileSize, mBackground, mDrawBackground, Widget::mFrameSize, mOffsetX, mOffsetY, mSelectedBackground, mSelectedSkin, mSkin, Widget::setFrameSize(), and theme.

Referenced by PlayerBox().

88 {
89  mAllowLogic = false;
90  setFrameSize(2);
91  addMouseListener(this);
92 
93  if (theme != nullptr)
94  {
95  if (name.empty())
96  name = "playerbox.xml";
98  name,
99  "playerbox_background.xml",
100  0,
101  8);
102  if (mSkin != nullptr)
103  {
104  mDrawBackground = (mSkin->getOption("drawbackground") != 0);
105  mOffsetX = mSkin->getOption("offsetX", -mapTileSize / 2);
106  mOffsetY = mSkin->getOption("offsetY", -mapTileSize);
107  mFrameSize = mSkin->getOption("frameSize", 2);
108  }
109  if (selectedName.empty())
110  selectedName = "playerboxselected.xml";
112  selectedName,
113  "playerbox_background.xml",
114  0,
115  8);
116  }
117  else
118  {
119  for (int f = 0; f < 9; f ++)
120  mBackground.grid[f] = nullptr;
121  for (int f = 0; f < 9; f ++)
122  mSelectedBackground.grid[f] = nullptr;
123  }
124 }
int mOffsetY
Definition: playerbox.h:107
bool mDrawBackground
Definition: playerbox.h:108
ImageRect mBackground
Definition: playerbox.h:102
int mOffsetX
Definition: playerbox.h:106
int getOption(const std::string &name) const
Definition: skin.h:105
Image * grid[9]
Definition: imagerect.h:41
Skin * loadSkinRect(ImageRect &image, const std::string &name, const std::string &name2, const int start, const int end)
Definition: theme.cpp:1109
unsigned int mFrameSize
Definition: widget.h:1137
void setFrameSize(const unsigned int frameSize)
Definition: widget.h:167
bool mAllowLogic
Definition: widget.h:1159
void addMouseListener(MouseListener *const mouseListener)
Definition: widget.cpp:291
Skin * mSkin
Definition: playerbox.h:104
Theme * theme
Definition: theme.cpp:61
Skin * mSelectedSkin
Definition: playerbox.h:105
static const int mapTileSize
Definition: map.h:26
ImageRect mSelectedBackground
Definition: playerbox.h:103

◆ mouseReleased()

void PlayerBox::mouseReleased ( MouseEvent event)
virtual

Called when a mouse button has been released on the widget area.

Parameters
eventDescribes the event.

Reimplemented from MouseListener.

Definition at line 188 of file playerbox.cpp.

References Widget::distributeActionEvent(), MouseEvent::getButton(), MouseButton::LEFT, and Widget::mActionEventId.

Referenced by setSelected().

189 {
190  if (event.getButton() == MouseButton::LEFT)
191  {
192  if (!mActionEventId.empty())
194  event.consume();
195  }
196 }
MouseButtonT getButton() const
Definition: mouseevent.h:115
void distributeActionEvent()
Definition: widget.cpp:492
std::string mActionEventId
Definition: widget.h:1105

◆ safeDraw()

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

Implements Widget.

Definition at line 149 of file playerbox.cpp.

References draw().

Referenced by setPlayer().

150 {
151  PlayerBox::draw(graphics);
152 }
void draw(Graphics *const graphics)
Definition: playerbox.cpp:126

◆ safeDrawFrame()

void PlayerBox::safeDrawFrame ( Graphics *const  graphics)
virtual

Reimplemented from Widget.

Definition at line 171 of file playerbox.cpp.

References BLOCK_END, BLOCK_START, Graphics::drawImageRect(), Rect::height, mBackground, Widget::mDimension, mDrawBackground, Widget::mFrameSize, mSelected, mSelectedBackground, and Rect::width.

Referenced by setPlayer().

172 {
173  BLOCK_START("PlayerBox::drawFrame")
175  {
176  const int bs = mFrameSize * 2;
177  const int w = mDimension.width + bs;
178  const int h = mDimension.height + bs;
179 
180  if (!mSelected)
181  graphics->drawImageRect(0, 0, w, h, mBackground);
182  else
183  graphics->drawImageRect(0, 0, w, h, mSelectedBackground);
184  }
185  BLOCK_END("PlayerBox::drawFrame")
186 }
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
bool mDrawBackground
Definition: playerbox.h:108
#define BLOCK_START(name)
Definition: perfomance.h:78
bool mSelected
Definition: playerbox.h:109
ImageRect mBackground
Definition: playerbox.h:102
if(!vert) return
#define BLOCK_END(name)
Definition: perfomance.h:79
unsigned int mFrameSize
Definition: widget.h:1137
int height
Definition: rect.h:223
ImageRect mSelectedBackground
Definition: playerbox.h:103
Rect mDimension
Definition: widget.h:1100

◆ setPlayer()

void PlayerBox::setPlayer ( Being being)
inline

Sets a new player character to be displayed by this box. Setting the player to NULL causes the box not to draw any character.

Definition at line 73 of file playerbox.h.

References A_NONNULL, draw(), drawFrame(), mBeing, safeDraw(), and safeDrawFrame().

Referenced by EquipmentWindow::EquipmentWindow(), EquipmentWindow::setBeing(), CharacterDisplay::setCharacter(), and NpcDialog::showAvatar().

74  { mBeing = being; }
Being * mBeing
Definition: playerbox.h:100

◆ setSelected()

void PlayerBox::setSelected ( bool  b)
inline

Definition at line 94 of file playerbox.h.

References mouseReleased(), and mSelected.

95  { mSelected = b; }
bool mSelected
Definition: playerbox.h:109

Field Documentation

◆ mAlpha

float PlayerBox::mAlpha
private

Definition at line 101 of file playerbox.h.

Referenced by draw().

◆ mBackground

ImageRect PlayerBox::mBackground
private

Definition at line 102 of file playerbox.h.

Referenced by draw(), drawFrame(), init(), safeDrawFrame(), and ~PlayerBox().

◆ mBeing

Being* PlayerBox::mBeing
private

Definition at line 100 of file playerbox.h.

Referenced by draw(), getBeing(), setPlayer(), and ~PlayerBox().

◆ mDrawBackground

bool PlayerBox::mDrawBackground
private

Definition at line 108 of file playerbox.h.

Referenced by drawFrame(), init(), and safeDrawFrame().

◆ mOffsetX

int PlayerBox::mOffsetX
private

Definition at line 106 of file playerbox.h.

Referenced by draw(), and init().

◆ mOffsetY

int PlayerBox::mOffsetY
private

Definition at line 107 of file playerbox.h.

Referenced by draw(), and init().

◆ mSelected

bool PlayerBox::mSelected
private

Definition at line 109 of file playerbox.h.

Referenced by drawFrame(), safeDrawFrame(), and setSelected().

◆ mSelectedBackground

ImageRect PlayerBox::mSelectedBackground
private

Definition at line 103 of file playerbox.h.

Referenced by drawFrame(), init(), safeDrawFrame(), and ~PlayerBox().

◆ mSelectedSkin

Skin* PlayerBox::mSelectedSkin
private

Definition at line 105 of file playerbox.h.

Referenced by init().

◆ mSkin

Skin* PlayerBox::mSkin
private

Definition at line 104 of file playerbox.h.

Referenced by init().


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