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

float mAlpha
ImageRect mBackground
ImageRect mSelectedBackground
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
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
Color mForegroundColor2
- Static Protected Attributes inherited from Widget
static FontmGlobalFont = 0

Detailed Description

A box showing a player character.

Definition at line 43 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 39 of file playerbox.cpp.

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

References init().

◆ PlayerBox() [2/2]

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

Definition at line 59 of file playerbox.cpp.

61  :
62  Widget(widget),
63  MouseListener(),
64  mBeing(nullptr),
65  mAlpha(1.0),
66  mBackground(),
68  mSkin(nullptr),
69  mSelectedSkin(nullptr),
70  mOffsetX(-mapTileSize / 2),
72  mDrawBackground(false),
73  mSelected(false)
74 {
75  init(skin, selectedSkin);
76 }

References init().

◆ ~PlayerBox()

PlayerBox::~PlayerBox ( )


Definition at line 78 of file playerbox.cpp.

79 {
80  if (gui != nullptr)
81  gui->removeDragged(this);
85  mBeing = nullptr;
86 }
void removeDragged(const Widget *const widget)
Definition: gui.cpp:1162
static void unloadRect(const ImageRect &rect, const int start, const int end)
Definition: theme.cpp:915
Gui * gui
Definition: gui.cpp:111

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

Member Function Documentation

◆ draw()

void PlayerBox::draw ( Graphics *const  graphics)

Draws the scroll area.

Implements Widget.

Definition at line 127 of file playerbox.cpp.

128 {
129  BLOCK_START("PlayerBox::draw")
130  if (mBeing != nullptr)
131  {
132  const int bs = mFrameSize;
133  const int x = mDimension.width / 2 + bs + mOffsetX;
134  const int y = mDimension.height - bs + mOffsetY;
135  mBeing->drawBasic(graphics, x, y);
136  }
138  if (settings.guiAlpha != mAlpha)
139  {
140  const float alpha = settings.guiAlpha;
141  for (int a = 0; a < 9; a++)
142  {
143  if (mBackground.grid[a] != nullptr)
144  mBackground.grid[a]->setAlpha(alpha);
145  }
146  }
147  BLOCK_END("PlayerBox::draw")
148 }
void drawBasic(Graphics *const graphics, const int x, const int y) const
Definition: being.cpp:3930
Image * grid[9]
Definition: imagerect.h:42
int width
Definition: rect.h:219
int height
Definition: rect.h:224
float guiAlpha
Definition: settings.h:131
Rect mDimension
Definition: widget.h:1101
unsigned int mFrameSize
Definition: widget.h:1138
if(!vert) return
#define BLOCK_END(name)
Definition: perfomance.h:80
#define BLOCK_START(name)
Definition: perfomance.h:79
Settings settings
Definition: settings.cpp:32

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

Referenced by safeDraw().

◆ drawFrame()

void PlayerBox::drawFrame ( Graphics *const  graphics)

Draws the background and border of the scroll area.

Reimplemented from Widget.

Definition at line 155 of file playerbox.cpp.

156 {
157  BLOCK_START("PlayerBox::drawFrame")
159  {
160  const int bs = mFrameSize * 2;
161  const int w = mDimension.width + bs;
162  const int h = mDimension.height + bs;
164  if (!mSelected)
165  graphics->drawImageRect(0, 0, w, h, mBackground);
166  else
167  graphics->drawImageRect(0, 0, w, h, mSelectedBackground);
168  }
169  BLOCK_END("PlayerBox::drawFrame")
170 }
virtual void drawImageRect(const int x, const int y, const int w, const int h, const ImageRect &imgRect)=0

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

◆ getBeing()

Being* PlayerBox::getBeing ( )

Definition at line 92 of file playerbox.h.

93  { return mBeing; }

References mBeing.

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

◆ init()

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

Definition at line 88 of file playerbox.cpp.

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

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().

◆ mouseReleased()

void PlayerBox::mouseReleased ( MouseEvent event)

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

eventDescribes the event.

Reimplemented from MouseListener.

Definition at line 189 of file playerbox.cpp.

190 {
191  if (event.getButton() == MouseButton::LEFT)
192  {
193  if (!mActionEventId.empty())
195  event.consume();
196  }
197 }
MouseButtonT getButton() const
Definition: mouseevent.h:116
void distributeActionEvent()
Definition: widget.cpp:493
std::string mActionEventId
Definition: widget.h:1106

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

◆ safeDraw()

void PlayerBox::safeDraw ( Graphics *const  graphics)

Implements Widget.

Definition at line 150 of file playerbox.cpp.

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

References draw().

◆ safeDrawFrame()

void PlayerBox::safeDrawFrame ( Graphics *const  graphics)

Reimplemented from Widget.

Definition at line 172 of file playerbox.cpp.

173 {
174  BLOCK_START("PlayerBox::drawFrame")
176  {
177  const int bs = mFrameSize * 2;
178  const int w = mDimension.width + bs;
179  const int h = mDimension.height + bs;
181  if (!mSelected)
182  graphics->drawImageRect(0, 0, w, h, mBackground);
183  else
184  graphics->drawImageRect(0, 0, w, h, mSelectedBackground);
185  }
186  BLOCK_END("PlayerBox::drawFrame")
187 }

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

◆ setPlayer()

void PlayerBox::setPlayer ( Being being)

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 74 of file playerbox.h.

75  { mBeing = being; }

References mBeing.

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

◆ setSelected()

void PlayerBox::setSelected ( bool  b)

Definition at line 95 of file playerbox.h.

96  { mSelected = b; }

References mSelected.

Referenced by CharacterDisplay::setSelect().

Field Documentation

◆ mAlpha

float PlayerBox::mAlpha

Definition at line 102 of file playerbox.h.

Referenced by draw().

◆ mBackground

ImageRect PlayerBox::mBackground

Definition at line 103 of file playerbox.h.

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

◆ mBeing

Being* PlayerBox::mBeing

Definition at line 101 of file playerbox.h.

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

◆ mDrawBackground

bool PlayerBox::mDrawBackground

Definition at line 109 of file playerbox.h.

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

◆ mOffsetX

int PlayerBox::mOffsetX

Definition at line 107 of file playerbox.h.

Referenced by draw(), and init().

◆ mOffsetY

int PlayerBox::mOffsetY

Definition at line 108 of file playerbox.h.

Referenced by draw(), and init().

◆ mSelected

bool PlayerBox::mSelected

Definition at line 110 of file playerbox.h.

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

◆ mSelectedBackground

ImageRect PlayerBox::mSelectedBackground

Definition at line 104 of file playerbox.h.

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

◆ mSelectedSkin

Skin* PlayerBox::mSelectedSkin

Definition at line 106 of file playerbox.h.

Referenced by init().

◆ mSkin

Skin* PlayerBox::mSkin

Definition at line 105 of file playerbox.h.

Referenced by init().

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