ManaPlus
Public Member Functions | Private Attributes | Static Private Attributes
SkillRectangleListBox Class Reference

#include <skillrectanglelistbox.h>

Inheritance diagram for SkillRectangleListBox:
Widget MouseListener Widget2

Public Member Functions

 SkillRectangleListBox (const Widget2 *const widget, SkillModel *const model)
 
 ~SkillRectangleListBox ()
 
SkillInfogetSelectedInfo () const
 
void draw (Graphics *const graphics)
 
void safeDraw (Graphics *const graphics)
 
const SkillInfogetSkillByEvent (const MouseEvent &event) const
 
int getSelectionByEvent (const MouseEvent &event) const
 
void mouseMoved (MouseEvent &event)
 
void mouseDragged (MouseEvent &event)
 
void mousePressed (MouseEvent &event)
 
void mouseReleased (MouseEvent &event)
 
void mouseExited (MouseEvent &event)
 
void updateAlpha ()
 
void setSelected (const int selected)
 
- 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
 
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 mouseClicked (MouseEvent &event)
 
virtual void mouseWheelMovedUp (MouseEvent &event)
 
virtual void mouseWheelMovedDown (MouseEvent &event)
 

Private Attributes

Color mHighlightColor
 
Color mTextColor
 
Color mTextColor2
 
Color mCooldownColor
 
Color mForegroundSelectedColor
 
Color mForegroundSelectedColor2
 
SkillModelmModel
 
SkinmSkin
 
int mSelected
 
int mPadding
 
int mBoxWidth
 
int mBoxHeight
 
int mIconXOffset
 
int mIconYOffset
 
int mTextXOffset
 
int mTextYOffset
 
bool mSkillClicked
 

Static Private Attributes

static float mAlpha = 1.0
 

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

Definition at line 47 of file skillrectanglelistbox.h.

Constructor & Destructor Documentation

◆ SkillRectangleListBox()

SkillRectangleListBox::SkillRectangleListBox ( const Widget2 *const  widget,
SkillModel *const  model 
)
inline

Definition at line 51 of file skillrectanglelistbox.h.

References A_DELETE_COPY, Widget::addMouseListener(), ServerCommandType::font, Widget::getFont(), Font::getHeight(), SkillModel::getNumberOfElements(), Skin::getOption(), Skin::getPadding(), SkillModel::getSkillAt(), Theme::getThemePath(), Font::getWidth(), Theme::load(), mBoxHeight, mBoxWidth, mIconXOffset, mIconYOffset, mPadding, mSkin, mTextXOffset, mTextYOffset, Widget::setHeight(), Widget::setWidth(), theme, SkillInfo::x, and SkillInfo::y.

52  :
53  Widget(widget),
54  MouseListener(),
63  mModel(model),
64  mSkin(nullptr),
65  mSelected(-1),
66  mPadding(2),
67  mBoxWidth(80),
68  mBoxHeight(70),
69  mIconXOffset(24),
70  mIconYOffset(10),
71  mTextXOffset(0),
72  mTextYOffset(44),
73  mSkillClicked(false)
74  {
75  if (theme != nullptr)
76  {
77  mSkin = theme->load("skillrectanglelistbox.xml",
78  "listbox.xml",
79  true,
81  }
82 
83  if (mSkin != nullptr)
84  {
86  mBoxWidth = mSkin->getOption("boxWidth", 80);
87  mBoxHeight = mSkin->getOption("boxHeight", 70);
88  mIconXOffset = mSkin->getOption("iconXOffset", 24);
89  mIconYOffset = mSkin->getOption("iconYOffset", 10);
90  mTextXOffset = mSkin->getOption("textXOffset", 0);
91  mTextYOffset = mSkin->getOption("textYOffset", 44);
92  }
93  Font *const font = getFont();
94  int minWidth = font->getWidth("Lvl: 10/10") + mTextXOffset + 2;
95  int minHeight = font->getHeight() + mTextYOffset + 2;
96  if (mBoxWidth < minWidth)
97  mBoxWidth = minWidth;
98  if (mBoxHeight < minHeight)
99  mBoxHeight = minHeight;
100  int maxX = 0;
101  int maxY = 0;
102  for (int i = 0;
103  i < model->getNumberOfElements();
104  ++i)
105  {
106  SkillInfo *const e = model->getSkillAt(i);
107  if (e != nullptr)
108  {
109  if (e->x > maxX)
110  maxX = e->x;
111  if (e->y > maxY)
112  maxY = e->y;
113  }
114  }
115  maxX ++;
116  maxY ++;
117  setWidth(maxX * mBoxWidth);
118  setHeight(maxY * mBoxHeight);
119  addMouseListener(this);
120  }
SkillInfo * getSkillAt(const int i) const
Definition: skillmodel.cpp:38
Font * getFont() const
Definition: widget.cpp:330
void setWidth(const int width)
Definition: widget.cpp:132
Definition: font.h:88
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 getOption(const std::string &name) const
Definition: skin.h:105
int getPadding() const
Definition: skin.h:99
int getNumberOfElements()
Definition: skillmodel.h:45
Widget(const Widget2 *const widget)
Definition: widget.cpp:84
void addMouseListener(MouseListener *const mouseListener)
Definition: widget.cpp:291
void setHeight(const int height)
Definition: widget.cpp:139
Theme * theme
Definition: theme.cpp:61
int getWidth(const std::string &text) const
Definition: font.cpp:333
const Color & getThemeColor(const ThemeColorIdT type, const unsigned int alpha) const A_INLINE
Definition: widget2.h:44
int getHeight() const
Definition: font.cpp:361

◆ ~SkillRectangleListBox()

SkillRectangleListBox::~SkillRectangleListBox ( )
inline

Definition at line 124 of file skillrectanglelistbox.h.

References delete2, and mModel.

125  {
126  delete2(mModel)
127  }
#define delete2(var)
Definition: delete2.h:24

Member Function Documentation

◆ draw()

void SkillRectangleListBox::draw ( Graphics *const  graphics)
inlinevirtual

Draws the widget. It is called by the parent widget when it is time for the widget to draw itself. The graphics object is set up so that all drawing is relative to the widget, i.e coordinate (0,0) is the top left corner of the widget. It is not possible to draw outside of a widget's dimension.

Parameters
graphicsaA graphics object to draw with.

Implements Widget.

Definition at line 143 of file skillrectanglelistbox.h.

References Color::a, CAST_S32, data, SkillInfo::data, Font::drawString(), ServerCommandType::font, Widget::getFont(), SkillModel::getNumberOfElements(), SkillModel::getSkillAt(), Font::getWidth(), SkillData::icon, mAlpha, mBoxHeight, mBoxWidth, mForegroundSelectedColor, mHighlightColor, mIconXOffset, mIconYOffset, mModel, ServerCommandType::model, mPadding, mSelected, mTextColor, mTextColor2, mTextXOffset, mTextYOffset, Widget::setHeight(), Widget::setWidth(), SkillInfo::skillLevel, SkillInfo::skillLevelWidth, updateAlpha(), x, SkillInfo::x, y, and SkillInfo::y.

Referenced by safeDraw().

144  {
145  if (mModel == nullptr)
146  return;
147 
148  SkillModel *const model = mModel;
149  updateAlpha();
150 
151  int maxX = 0;
152  int maxY = 0;
153  mHighlightColor.a = CAST_S32(mAlpha * 255.0F);
154  graphics->setColor(mHighlightColor);
155  Font *const font = getFont();
156  if (mSelected >= 0)
157  {
158  SkillInfo *const e = model->getSkillAt(mSelected);
159  if (e != nullptr)
160  {
161  const int x = e->x * mBoxWidth + mPadding;
162  const int y = e->y * mBoxHeight + mPadding;
163 
164  graphics->fillRectangle(Rect(x, y,
166 
167  const int xOffset = (mBoxWidth -
168  font->getWidth(e->skillLevel)) / 2;
169  font->drawString(graphics,
172  e->skillLevel,
173  x + mTextXOffset + xOffset,
174  y + mTextYOffset);
175  }
176  }
177 
178  // +++ need split drawing icons and text
179  for (int i = 0;
180  i < model->getNumberOfElements();
181  ++i)
182  {
183  SkillInfo *const e = model->getSkillAt(i);
184  if (e != nullptr)
185  {
186  if (e->x > maxX)
187  maxX = e->x;
188  if (e->y > maxY)
189  maxY = e->y;
190  const SkillData *const data = e->data;
191  const int x = e->x * mBoxWidth + mPadding;
192  const int y = e->y * mBoxHeight + mPadding;
193 
194  graphics->drawImage(data->icon,
195  x + mIconXOffset,
196  y + mIconYOffset);
197 
198  if (i != mSelected)
199  {
200  const int width1 = font->getWidth(e->skillLevel);
201  const int xOffset = (mBoxWidth -
202  width1) / 2;
203  font->drawString(graphics,
204  mTextColor,
205  mTextColor2,
206  e->skillLevel,
207  x + mTextXOffset + xOffset,
208  y + mTextYOffset);
209  if (e->skillLevelWidth < 0)
210  {
211  // Add one for padding
212  e->skillLevelWidth = width1 + 1;
213  }
214  }
215  else
216  {
217  if (e->skillLevelWidth < 0)
218  {
219  // Add one for padding
220  e->skillLevelWidth = font->getWidth(
221  e->skillLevel) + 1;
222  }
223  }
224  }
225  }
226  maxX ++;
227  maxY ++;
228  setWidth(maxX * mBoxWidth);
229  setHeight(maxY * mBoxHeight);
230  }
SkillInfo * getSkillAt(const int i) const
Definition: skillmodel.cpp:38
Font * getFont() const
Definition: widget.cpp:330
void setWidth(const int width)
Definition: widget.cpp:132
Definition: font.h:88
unsigned int a
Definition: color.h:250
Definition: rect.h:72
Image * icon
Definition: skilldata.h:46
SkillData * data
Definition: skillinfo.h:62
virtual void setColor(const Color &color)
Definition: graphics.h:319
#define CAST_S32
Definition: cast.h:29
uint32_t data
void drawString(Graphics *const graphics, Color col, const Color &col2, const std::string &text, const int x, const int y)
Definition: font.cpp:253
int getNumberOfElements()
Definition: skillmodel.h:45
std::string skillLevel
Definition: skillinfo.h:51
void setHeight(const int height)
Definition: widget.cpp:139
virtual void fillRectangle(const Rect &rectangle)=0
virtual void drawImage(const Image *const image, int dstX, int dstY)=0
int getWidth(const std::string &text) const
Definition: font.cpp:333
int skillLevelWidth
Definition: skillinfo.h:67

◆ getSelectedInfo()

SkillInfo* SkillRectangleListBox::getSelectedInfo ( ) const
inline

Definition at line 129 of file skillrectanglelistbox.h.

References SkillModel::getNumberOfElements(), SkillModel::getSkillAt(), mModel, and mSelected.

Referenced by SkillTab::getSelectedInfo().

130  {
131  if (mModel == nullptr)
132  return nullptr;
133  const int selected = mSelected;
134  if (selected < 0 ||
135  selected > mModel->getNumberOfElements())
136  {
137  return nullptr;
138  }
139 
140  return mModel->getSkillAt(selected);
141  }
SkillInfo * getSkillAt(const int i) const
Definition: skillmodel.cpp:38
int getNumberOfElements()
Definition: skillmodel.h:45

◆ getSelectionByEvent()

int SkillRectangleListBox::getSelectionByEvent ( const MouseEvent event) const
inline

Definition at line 257 of file skillrectanglelistbox.h.

References SkillModel::getNumberOfElements(), SkillModel::getSkillAt(), mBoxHeight, mBoxWidth, mModel, mPadding, SkillInfo::x, and SkillInfo::y.

Referenced by mouseDragged(), and mouseReleased().

258  {
259  if (mModel == nullptr)
260  return -1;
261  const int posX = (event.getX() - mPadding) / mBoxWidth;
262  const int posY = (event.getY() - mPadding) / mBoxHeight;
263  for (int i = 0;
265  ++i)
266  {
267  SkillInfo *const e = mModel->getSkillAt(i);
268  if (e != nullptr)
269  {
270  if (posX == e->x && posY == e->y)
271  return i;
272  }
273  }
274  return -1;
275  }
SkillInfo * getSkillAt(const int i) const
Definition: skillmodel.cpp:38
int getNumberOfElements()
Definition: skillmodel.h:45

◆ getSkillByEvent()

const SkillInfo* SkillRectangleListBox::getSkillByEvent ( const MouseEvent event) const
inline

Definition at line 237 of file skillrectanglelistbox.h.

References SkillModel::getNumberOfElements(), SkillModel::getSkillAt(), mBoxHeight, mBoxWidth, mModel, mPadding, SkillInfo::x, and SkillInfo::y.

Referenced by mouseDragged(), mouseMoved(), and mousePressed().

238  {
239  if (mModel == nullptr)
240  return nullptr;
241  const int posX = (event.getX() - mPadding) / mBoxWidth;
242  const int posY = (event.getY() - mPadding) / mBoxHeight;
243  for (int i = 0;
245  ++i)
246  {
247  SkillInfo *const e = mModel->getSkillAt(i);
248  if (e != nullptr)
249  {
250  if (posX == e->x && posY == e->y)
251  return e;
252  }
253  }
254  return nullptr;
255  }
SkillInfo * getSkillAt(const int i) const
Definition: skillmodel.cpp:38
int getNumberOfElements()
Definition: skillmodel.h:45

◆ mouseDragged()

void SkillRectangleListBox::mouseDragged ( MouseEvent event)
inlinevirtual

Called when the mouse has moved and the mouse has previously been pressed on the widget.

Parameters
eventDescribes the event.

Reimplemented from MouseListener.

Definition at line 294 of file skillrectanglelistbox.h.

References dragDrop, DragDrop::dragSkill(), getSelectionByEvent(), getSkillByEvent(), SkillInfo::id, DragDrop::isEmpty(), MouseButton::LEFT, mSkillClicked, DragDrop::setItem(), DragDrop::setItemData(), setSelected(), Actions::skill(), SKILL_MIN_ID, DragDropSource::Skills, and SkillInfo::toDataStr().

295  {
296  if (event.getButton() != MouseButton::LEFT)
297  return;
298  setSelected(std::max(0, getSelectionByEvent(event)));
299 
300  if (dragDrop.isEmpty())
301  {
302  if (mSkillClicked)
303  {
304  mSkillClicked = false;
305  const SkillInfo *const skill = getSkillByEvent(event);
306  if (skill == nullptr)
307  return;
309  dragDrop.setItem(skill->id + SKILL_MIN_ID);
310  dragDrop.setItemData(skill->toDataStr());
311  }
312  }
313  }
unsigned int id
Definition: skillinfo.h:68
bool skill(InputEvent &event)
Definition: commands.cpp:96
MouseButtonT getButton() const
Definition: mouseevent.h:115
DragDrop dragDrop
bool isEmpty() const
Definition: dragdrop.h:195
const int SKILL_MIN_ID
Definition: skill.h:24
void setSelected(const int selected)
std::string toDataStr() const
Definition: skillinfo.cpp:198
void setItemData(const std::string &data)
Definition: dragdrop.h:77
void dragSkill(const SkillInfo *const info, const DragDropSourceT source, const int tag)
Definition: dragdrop.h:151
void setItem(const int item)
Definition: dragdrop.h:237
const SkillInfo * getSkillByEvent(const MouseEvent &event) const
int getSelectionByEvent(const MouseEvent &event) const

◆ mouseExited()

void SkillRectangleListBox::mouseExited ( MouseEvent event)
inlinevirtual

Called when the mouse has exited the widget area.

Parameters
eventDescribes the event.

Reimplemented from MouseListener.

Definition at line 366 of file skillrectanglelistbox.h.

References Popup::hide(), and skillPopup.

367  {
368  skillPopup->hide();
369  }
SkillPopup * skillPopup
Definition: skillpopup.cpp:41
void hide()
Definition: popup.cpp:264

◆ mouseMoved()

void SkillRectangleListBox::mouseMoved ( MouseEvent event)
inlinevirtual

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 277 of file skillrectanglelistbox.h.

References SkillInfo::customCastType, SkillInfo::customOffsetX, SkillInfo::customOffsetY, SkillInfo::customSelectedLevel, dragDrop, getSkillByEvent(), DragDrop::isEmpty(), Viewport::mMouseX, Viewport::mMouseY, Popup::position(), SkillPopup::show(), Actions::skill(), skillPopup, and viewport.

278  {
279  if ((viewport == nullptr) || !dragDrop.isEmpty())
280  return;
281 
282  const SkillInfo *const skill = getSkillByEvent(event);
283  if (skill == nullptr)
284  return;
285  skillPopup->show(skill,
286  skill->customSelectedLevel,
287  skill->customCastType,
288  skill->customOffsetX,
289  skill->customOffsetY);
291  viewport->mMouseY);
292  }
bool skill(InputEvent &event)
Definition: commands.cpp:96
SkillPopup * skillPopup
Definition: skillpopup.cpp:41
CastTypeT customCastType
Definition: skillinfo.h:78
DragDrop dragDrop
int mMouseX
Definition: viewport.h:153
bool isEmpty() const
Definition: dragdrop.h:195
int customOffsetY
Definition: skillinfo.h:66
void show(const SkillInfo *const skill, const int level, const CastTypeT type, const int offsetX, const int offsetY)
Definition: skillpopup.cpp:105
void position(const int x, const int y)
Definition: popup.cpp:234
int customOffsetX
Definition: skillinfo.h:65
int customSelectedLevel
Definition: skillinfo.h:64
const SkillInfo * getSkillByEvent(const MouseEvent &event) const
int mMouseY
Definition: viewport.h:154
Viewport * viewport
Definition: viewport.cpp:35

◆ mousePressed()

void SkillRectangleListBox::mousePressed ( MouseEvent event)
inlinevirtual

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

NOTE: A mouse press is NOT equal to a mouse click. Use mouseClickMessage to check for mouse clicks.

Parameters
eventDescribes the event.

Reimplemented from MouseListener.

Definition at line 315 of file skillrectanglelistbox.h.

References ServerCommandType::font, Widget::getFont(), Font::getHeight(), SkillModel::getSkillAt(), getSkillByEvent(), Popup::hide(), MouseButton::LEFT, mBoxHeight, mBoxWidth, mModel, ServerCommandType::model, mPadding, mSelected, mSkillClicked, mTextXOffset, mTextYOffset, popupMenu, MouseButton::RIGHT, PopupMenu::showSkillLevelPopup(), PopupMenu::showSkillPopup(), Actions::skill(), skillPopup, x, SkillInfo::x, y, and SkillInfo::y.

316  {
317  const MouseButtonT button = event.getButton();
318  if (button == MouseButton::LEFT ||
319  button == MouseButton::RIGHT)
320  {
321  const SkillInfo *const skill = getSkillByEvent(event);
322  if (skill == nullptr)
323  return;
324  event.consume();
325  mSkillClicked = true;
326  SkillModel *const model = mModel;
327  if ((model != nullptr) &&
328  mSelected >= 0 &&
329  model->getSkillAt(mSelected) == skill)
330  {
331  skillPopup->hide();
332 
333  const int x = skill->x * mBoxWidth + mPadding;
334  const int y = skill->y * mBoxHeight + mPadding;
335  Font *const font = getFont();
336  const int height = font->getHeight();
337  const int eventX = event.getX();
338  const int eventY = event.getY() - mTextYOffset;
339  if (button == MouseButton::LEFT)
340  {
341  if (eventX >= x + mTextXOffset &&
342  eventX <= x + mBoxWidth - mTextXOffset &&
343  eventY >= y &&
344  eventY <= y + height)
345  {
347  }
348  }
349  else if (button == MouseButton::RIGHT)
350  {
351  popupMenu->showSkillPopup(skill);
352  }
353  }
354  }
355  }
SkillInfo * getSkillAt(const int i) const
Definition: skillmodel.cpp:38
Font * getFont() const
Definition: widget.cpp:330
bool skill(InputEvent &event)
Definition: commands.cpp:96
Definition: font.h:88
SkillPopup * skillPopup
Definition: skillpopup.cpp:41
void showSkillPopup(const SkillInfo *const info)
Definition: popupmenu.cpp:2263
void hide()
Definition: popup.cpp:264
PopupMenu * popupMenu
Definition: popupmenu.cpp:102
void showSkillLevelPopup(const SkillInfo *const info)
Definition: popupmenu.cpp:2356
const SkillInfo * getSkillByEvent(const MouseEvent &event) const
int getHeight() const
Definition: font.cpp:361
MouseButton ::T MouseButtonT
Definition: mousebutton.h:77

◆ mouseReleased()

void SkillRectangleListBox::mouseReleased ( MouseEvent event)
inlinevirtual

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

Parameters
eventDescribes the event.

Reimplemented from MouseListener.

Definition at line 357 of file skillrectanglelistbox.h.

References Widget::distributeActionEvent(), getSelectionByEvent(), MouseButton::LEFT, and setSelected().

358  {
359  if (event.getButton() == MouseButton::LEFT)
360  {
361  setSelected(std::max(0, getSelectionByEvent(event)));
363  }
364  }
MouseButtonT getButton() const
Definition: mouseevent.h:115
void setSelected(const int selected)
void distributeActionEvent()
Definition: widget.cpp:492
int getSelectionByEvent(const MouseEvent &event) const

◆ safeDraw()

void SkillRectangleListBox::safeDraw ( Graphics *const  graphics)
inlinevirtual

Implements Widget.

Definition at line 232 of file skillrectanglelistbox.h.

References draw().

233  {
234  SkillRectangleListBox::draw(graphics);
235  }
void draw(Graphics *const graphics)

◆ setSelected()

void SkillRectangleListBox::setSelected ( const int  selected)
inline

Definition at line 380 of file skillrectanglelistbox.h.

References SkillModel::getNumberOfElements(), mModel, and mSelected.

Referenced by mouseDragged(), and mouseReleased().

381  {
382  if (mModel == nullptr)
383  {
384  mSelected = -1;
385  }
386  else
387  {
388  if (selected < 0)
389  mSelected = -1;
390  else if (selected >= mModel->getNumberOfElements())
392  else
393  mSelected = selected;
394  }
395  }
int getNumberOfElements()
Definition: skillmodel.h:45

◆ updateAlpha()

void SkillRectangleListBox::updateAlpha ( )
inline

Definition at line 371 of file skillrectanglelistbox.h.

References Theme::getMinimumOpacity(), Settings::guiAlpha, mAlpha, settings, and theme.

Referenced by draw().

372  {
373  const float alpha = std::max(settings.guiAlpha,
375 
376  if (mAlpha != alpha)
377  mAlpha = alpha;
378  }
float getMinimumOpacity() const
Definition: theme.h:123
Settings settings
Definition: settings.cpp:31
Theme * theme
Definition: theme.cpp:61
float guiAlpha
Definition: settings.h:129

Field Documentation

◆ mAlpha

float SkillRectangleListBox::mAlpha = 1.0
staticprivate

Definition at line 415 of file skillrectanglelistbox.h.

Referenced by draw(), and updateAlpha().

◆ mBoxHeight

int SkillRectangleListBox::mBoxHeight
private

◆ mBoxWidth

int SkillRectangleListBox::mBoxWidth
private

◆ mCooldownColor

Color SkillRectangleListBox::mCooldownColor
private

Definition at line 401 of file skillrectanglelistbox.h.

◆ mForegroundSelectedColor

Color SkillRectangleListBox::mForegroundSelectedColor
private

Definition at line 402 of file skillrectanglelistbox.h.

Referenced by draw().

◆ mForegroundSelectedColor2

Color SkillRectangleListBox::mForegroundSelectedColor2
private

Definition at line 403 of file skillrectanglelistbox.h.

◆ mHighlightColor

Color SkillRectangleListBox::mHighlightColor
private

Definition at line 398 of file skillrectanglelistbox.h.

Referenced by draw().

◆ mIconXOffset

int SkillRectangleListBox::mIconXOffset
private

Definition at line 410 of file skillrectanglelistbox.h.

Referenced by draw(), and SkillRectangleListBox().

◆ mIconYOffset

int SkillRectangleListBox::mIconYOffset
private

Definition at line 411 of file skillrectanglelistbox.h.

Referenced by draw(), and SkillRectangleListBox().

◆ mModel

SkillModel* SkillRectangleListBox::mModel
private

◆ mPadding

int SkillRectangleListBox::mPadding
private

◆ mSelected

int SkillRectangleListBox::mSelected
private

Definition at line 406 of file skillrectanglelistbox.h.

Referenced by draw(), getSelectedInfo(), mousePressed(), and setSelected().

◆ mSkillClicked

bool SkillRectangleListBox::mSkillClicked
private

Definition at line 414 of file skillrectanglelistbox.h.

Referenced by mouseDragged(), and mousePressed().

◆ mSkin

Skin* SkillRectangleListBox::mSkin
private

Definition at line 405 of file skillrectanglelistbox.h.

Referenced by SkillRectangleListBox().

◆ mTextColor

Color SkillRectangleListBox::mTextColor
private

Definition at line 399 of file skillrectanglelistbox.h.

Referenced by draw().

◆ mTextColor2

Color SkillRectangleListBox::mTextColor2
private

Definition at line 400 of file skillrectanglelistbox.h.

Referenced by draw().

◆ mTextXOffset

int SkillRectangleListBox::mTextXOffset
private

Definition at line 412 of file skillrectanglelistbox.h.

Referenced by draw(), mousePressed(), and SkillRectangleListBox().

◆ mTextYOffset

int SkillRectangleListBox::mTextYOffset
private

Definition at line 413 of file skillrectanglelistbox.h.

Referenced by draw(), mousePressed(), and SkillRectangleListBox().


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