ManaPlus
Public Member Functions | Private Attributes
SpellShortcutContainer Class Reference

#include <spellshortcutcontainer.h>

Inheritance diagram for SpellShortcutContainer:
ShortcutContainer Widget WidgetListener MouseListener Widget2

Public Member Functions

 SpellShortcutContainer (Widget2 *const widget, const unsigned number)
 
 ~SpellShortcutContainer ()
 
void draw (Graphics *const graphics)
 
void safeDraw (Graphics *const graphics)
 
void mouseDragged (MouseEvent &event)
 
void mousePressed (MouseEvent &event)
 
void mouseReleased (MouseEvent &event)
 
void widgetHidden (const Event &event)
 
void mouseExited (MouseEvent &event)
 
void mouseMoved (MouseEvent &event)
 
void setSkin (const Widget2 *const widget, Skin *const skin)
 
int getItemByIndex (const int index) const
 
- Public Member Functions inherited from ShortcutContainer
 ~ShortcutContainer ()
 
void widgetResized (const Event &event)
 
void widgetMoved (const Event &event)
 
int getMaxItems () const
 
int getBoxWidth () const
 
int getBoxHeight () const
 
void drawBackground (Graphics *const g)
 
void safeDrawBackground (Graphics *const g)
 
- 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 WidgetListener
virtual ~WidgetListener ()
 
virtual void widgetShown (const Event &event)
 
- 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

unsigned int mNumber
 
bool mSpellClicked
 

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 ShortcutContainer
 ShortcutContainer (Widget2 *const widget)
 
int getIndexFromGrid (const int pointX, const int pointY) const
 
- 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 WidgetListener
 WidgetListener ()
 
- Protected Member Functions inherited from MouseListener
 MouseListener ()
 
- Protected Attributes inherited from ShortcutContainer
ImagemBackgroundImg
 
SkinmSkin
 
unsigned mMaxItems
 
int mBoxWidth
 
int mBoxHeight
 
int mGridWidth
 
int mGridHeight
 
int mImageOffsetX
 
int mImageOffsetY
 
int mTextOffsetX
 
int mTextOffsetY
 
ImageCollectionmVertexes
 
- 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 ShortcutContainer
static float mAlpha = 1.0
 
- Static Protected Attributes inherited from Widget
static FontmGlobalFont = 0
 

Detailed Description

An item shortcut container. Used to quickly use items.

Definition at line 33 of file spellshortcutcontainer.h.

Constructor & Destructor Documentation

◆ SpellShortcutContainer()

SpellShortcutContainer::SpellShortcutContainer ( Widget2 *const  widget,
const unsigned  number 
)

Constructor. Initializes the graphic.

Definition at line 43 of file spellshortcutcontainer.cpp.

44  :
45  ShortcutContainer(widget),
46  mNumber(number),
47  mSpellClicked(false)
48 {
49  if (spellShortcut != nullptr)
51  else
52  mMaxItems = 0;
53 }
ShortcutContainer(Widget2 *const widget)
static unsigned int getSpellsCount()
SpellShortcut * spellShortcut

References SpellShortcut::getSpellsCount(), ShortcutContainer::mMaxItems, and spellShortcut.

◆ ~SpellShortcutContainer()

SpellShortcutContainer::~SpellShortcutContainer ( )

Destructor.

Definition at line 55 of file spellshortcutcontainer.cpp.

56 {
57 }

Member Function Documentation

◆ draw()

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

Draws the items.

Implements Widget.

Definition at line 67 of file spellshortcutcontainer.cpp.

68 {
69  if (spellShortcut == nullptr)
70  return;
71 
72  BLOCK_START("SpellShortcutContainer::draw")
73  if (settings.guiAlpha != mAlpha)
74  {
76  if (mBackgroundImg != nullptr)
77  mBackgroundImg->setAlpha(mAlpha);
78  }
79 
80  Font *const font = getFont();
81 
82  const int selectedId = spellShortcut->getSelectedItem();
83  graphics->setColor(mForegroundColor);
84  drawBackground(graphics);
85 
86  // +++ in future need reorder images and string drawing.
87  for (unsigned i = 0; i < mMaxItems; i++)
88  {
89  const int itemX = (i % mGridWidth) * mBoxWidth;
90  const int itemY = (i / mGridWidth) * mBoxHeight;
91 
92  const int itemId = getItemByIndex(i);
93  if (selectedId >= 0 && itemId == selectedId)
94  {
95  graphics->drawRectangle(Rect(itemX + 1, itemY + 1,
96  mBoxWidth - 1, mBoxHeight - 1));
97  }
98 
99  if (spellManager == nullptr)
100  continue;
101 
102  const TextCommand *const spell = spellManager->getSpell(itemId);
103  if (spell != nullptr)
104  {
105  if (!spell->isEmpty())
106  {
107  Image *const image = spell->getImage();
108 
109  if (image != nullptr)
110  {
111  image->setAlpha(1.0F);
112  graphics->drawImage(image,
113  itemX + mImageOffsetX,
114  itemY + mImageOffsetY);
115  }
116  }
117 
118  font->drawString(graphics,
121  spell->getSymbol(),
122  itemX + mTextOffsetX,
123  itemY + mTextOffsetY);
124  }
125  }
126 
127  BLOCK_END("SpellShortcutContainer::draw")
128 }
Definition: font.h:90
void drawString(Graphics *const graphics, Color col, const Color &col2, const std::string &text, const int x, const int y)
Definition: font.cpp:254
virtual void drawImage(const Image *const image, int dstX, int dstY)=0
virtual void setColor(const Color &color)
Definition: graphics.h:320
virtual void drawRectangle(const Rect &rectangle)=0
Definition: rect.h:74
float guiAlpha
Definition: settings.h:131
void drawBackground(Graphics *const g)
TextCommand * getSpell(const int spellId) const
int getItemByIndex(const int index) const
int getSelectedItem() const
Definition: spellshortcut.h:70
bool isEmpty() const
Definition: textcommand.h:153
std::string getSymbol() const
Definition: textcommand.h:91
Image * getImage() const
Definition: textcommand.h:156
Color mForegroundColor2
Definition: widget2.h:113
Color mForegroundColor
Definition: widget.h:1086
Font * getFont() const
Definition: widget.cpp:331
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
SpellManager * spellManager

References BLOCK_END, BLOCK_START, ShortcutContainer::drawBackground(), Graphics::drawImage(), Graphics::drawRectangle(), Font::drawString(), Widget::getFont(), TextCommand::getImage(), getItemByIndex(), SpellShortcut::getSelectedItem(), SpellManager::getSpell(), TextCommand::getSymbol(), Settings::guiAlpha, TextCommand::isEmpty(), ShortcutContainer::mAlpha, ShortcutContainer::mBackgroundImg, ShortcutContainer::mBoxHeight, ShortcutContainer::mBoxWidth, Widget::mForegroundColor, Widget2::mForegroundColor2, ShortcutContainer::mGridWidth, ShortcutContainer::mImageOffsetX, ShortcutContainer::mImageOffsetY, ShortcutContainer::mMaxItems, ShortcutContainer::mTextOffsetX, ShortcutContainer::mTextOffsetY, Graphics::setColor(), settings, spellManager, and spellShortcut.

◆ getItemByIndex()

int SpellShortcutContainer::getItemByIndex ( const int  index) const

Definition at line 374 of file spellshortcutcontainer.cpp.

375 {
376  return spellShortcut->getItem(
377  (mNumber * SPELL_SHORTCUT_ITEMS) + index);
378 }
int getItem(const size_t index) const
Definition: spellshortcut.h:78
const unsigned int SPELL_SHORTCUT_ITEMS
Definition: spells.h:28

References SpellShortcut::getItem(), mNumber, SPELL_SHORTCUT_ITEMS, and spellShortcut.

Referenced by draw(), mouseDragged(), mouseMoved(), mousePressed(), mouseReleased(), and safeDraw().

◆ mouseDragged()

void SpellShortcutContainer::mouseDragged ( MouseEvent event)
virtual

Handles mouse when dragged.

Reimplemented from ShortcutContainer.

Definition at line 193 of file spellshortcutcontainer.cpp.

194 {
195  if (event.getButton() == MouseButton::LEFT)
196  {
197  if (dragDrop.isEmpty() && mSpellClicked)
198  {
199  mSpellClicked = false;
200  const int index = getIndexFromGrid(event.getX(), event.getY());
201 
202  if (index == -1)
203  return;
204 
205  const int itemId = getItemByIndex(index);
206  if (itemId < 0)
207  return;
208  event.consume();
209  TextCommand *const spell = spellManager->getSpell(itemId);
210  if (spell != nullptr)
211  {
213  dragDrop.setItem(spell->getId() + SPELL_MIN_ID);
214  }
215  else
216  {
217  dragDrop.clear();
218  mSpellClicked = false;
219  }
220  }
221  }
222 }
void setItem(const int item)
Definition: dragdrop.h:238
void dragCommand(const TextCommand *const command, const DragDropSourceT source, const int tag)
Definition: dragdrop.h:117
bool isEmpty() const
Definition: dragdrop.h:196
void clear()
Definition: dragdrop.h:183
MouseButtonT getButton() const
Definition: mouseevent.h:116
int getX() const
Definition: mouseevent.h:127
int getY() const
Definition: mouseevent.h:138
int getIndexFromGrid(const int pointX, const int pointY) const
int getId() const
Definition: textcommand.h:94
DragDrop dragDrop
const int SPELL_MIN_ID
Definition: spells.h:27

References DragDrop::clear(), DragDrop::dragCommand(), dragDrop, MouseEvent::getButton(), TextCommand::getId(), ShortcutContainer::getIndexFromGrid(), getItemByIndex(), SpellManager::getSpell(), MouseEvent::getX(), MouseEvent::getY(), DragDrop::isEmpty(), MouseButton::LEFT, mSpellClicked, DragDrop::setItem(), SPELL_MIN_ID, spellManager, and DragDropSource::Spells.

◆ mouseExited()

void SpellShortcutContainer::mouseExited ( MouseEvent event)
virtual

Called when the mouse has exited the widget area.

Parameters
eventDescribes the event.

Reimplemented from MouseListener.

Definition at line 362 of file spellshortcutcontainer.cpp.

363 {
364  if (spellPopup != nullptr)
366 }
void setVisible(Visible visible)
Definition: widget.cpp:225
SpellPopup * spellPopup
Definition: spellpopup.cpp:34
const bool Visible_false
Definition: visible.h:30

References Widget::setVisible(), spellPopup, and Visible_false.

◆ mouseMoved()

void SpellShortcutContainer::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 334 of file spellshortcutcontainer.cpp.

335 {
336  if (spellPopup == nullptr ||
337  spellShortcut == nullptr ||
338  spellManager == nullptr)
339  {
340  return;
341  }
342 
343  const int index = getIndexFromGrid(event.getX(), event.getY());
344 
345  if (index == -1)
346  return;
347 
348  const int itemId = getItemByIndex(index);
350  const TextCommand *const spell = spellManager->getSpell(itemId);
351  if ((spell != nullptr) && !spell->isEmpty())
352  {
353  spellPopup->setItem(spell);
355  }
356  else
357  {
359  }
360 }
void view(const int x, const int y)
Definition: spellpopup.cpp:91
void setItem(const TextCommand *const spell)
Definition: spellpopup.cpp:63
int mMouseX
Definition: viewport.h:154
int mMouseY
Definition: viewport.h:155
Viewport * viewport
Definition: viewport.cpp:36

References ShortcutContainer::getIndexFromGrid(), getItemByIndex(), SpellManager::getSpell(), MouseEvent::getX(), MouseEvent::getY(), TextCommand::isEmpty(), Viewport::mMouseX, Viewport::mMouseY, SpellPopup::setItem(), Widget::setVisible(), spellManager, spellPopup, spellShortcut, SpellPopup::view(), viewport, and Visible_false.

◆ mousePressed()

void SpellShortcutContainer::mousePressed ( MouseEvent event)
virtual

Handles mouse when pressed.

Reimplemented from ShortcutContainer.

Definition at line 224 of file spellshortcutcontainer.cpp.

225 {
226  const int index = getIndexFromGrid(event.getX(), event.getY());
227 
228  if (index == -1)
229  return;
230 
231  const MouseButtonT eventButton = event.getButton();
232  if (eventButton == MouseButton::LEFT)
233  {
234  const int itemId = getItemByIndex(index);
235  if (itemId > 0)
236  mSpellClicked = true;
237  event.consume();
238  }
239  else if (eventButton == MouseButton::MIDDLE)
240  {
241  if ((spellShortcut == nullptr) || (spellManager == nullptr))
242  return;
243 
244  event.consume();
245  const int itemId = getItemByIndex(index);
246  spellManager->invoke(itemId);
247  }
248 }
void invoke(const int spellId) const
MouseButton ::T MouseButtonT
Definition: mousebutton.h:78

References ShortcutContainer::getIndexFromGrid(), getItemByIndex(), MouseEvent::getX(), MouseEvent::getY(), SpellManager::invoke(), MouseButton::LEFT, MouseButton::MIDDLE, mSpellClicked, spellManager, and spellShortcut.

◆ mouseReleased()

void SpellShortcutContainer::mouseReleased ( MouseEvent event)
virtual

Handles mouse release.

Reimplemented from ShortcutContainer.

Definition at line 250 of file spellshortcutcontainer.cpp.

251 {
252  if ((spellShortcut == nullptr) || (spellManager == nullptr))
253  return;
254 
255  const int index = getIndexFromGrid(event.getX(), event.getY());
256 
257  if (index == -1)
258  {
259  dragDrop.clear();
260  return;
261  }
262 
263  const int itemId = getItemByIndex(index);
264  const MouseButtonT eventButton = event.getButton();
265 
266  if (eventButton == MouseButton::LEFT)
267  {
268  mSpellClicked = false;
269 
270  if (itemId < 0)
271  return;
272 
273  const int selectedId = spellShortcut->getSelectedItem();
274  event.consume();
275 
276  if (!dragDrop.isEmpty())
277  {
279  {
280  const int oldIndex = dragDrop.getTag();
281  const int idx = mNumber * SPELL_SHORTCUT_ITEMS;
282  spellManager->swap(idx + index, idx + oldIndex);
283  spellManager->save();
284  dragDrop.clear();
285  dragDrop.deselect();
286  }
287  }
288  else
289  {
290  if (selectedId != itemId)
291  {
292  const TextCommand *const
293  spell = spellManager->getSpell(itemId);
294  if ((spell != nullptr) && !spell->isEmpty())
295  {
296  const int num = itemShortcutWindow->getTabIndex();
297  if (num >= 0 && num < CAST_S32(SHORTCUT_TABS)
298  && (itemShortcut[num] != nullptr))
299  {
301  spell->getId() + SPELL_MIN_ID);
302  }
304  }
305  }
306  else
307  {
308  const int num = itemShortcutWindow->getTabIndex();
309  if (num >= 0 && num < CAST_S32(SHORTCUT_TABS)
310  && (itemShortcut[num] != nullptr))
311  {
312  itemShortcut[num]->setItemSelected(-1);
313  }
315  }
316  }
317  }
318  else if (eventButton == MouseButton::RIGHT)
319  {
320  TextCommand *spell = nullptr;
321  if (itemId >= 0)
322  spell = spellManager->getSpell(itemId);
323 
324  if ((spell != nullptr) && (popupMenu != nullptr))
325  {
327  viewport->mMouseY,
328  spell);
329  }
330  }
331 }
#define CAST_S32
Definition: cast.h:30
DragDropSourceT getSource() const
Definition: dragdrop.h:84
void deselect()
Definition: dragdrop.h:213
int getTag() const
Definition: dragdrop.h:235
void setItemSelected(const int itemId)
Definition: itemshortcut.h:126
void showSpellPopup(const int x, const int y, TextCommand *const cmd)
Definition: popupmenu.cpp:887
int getTabIndex() const
void swap(const int id1, const int id2)
void save() const
void setItemSelected(const int itemId)
Definition: spellshortcut.h:58
const unsigned int SHORTCUT_TABS
Definition: itemshortcut.h:28
ItemShortcut * itemShortcut[SHORTCUT_TABS]
PopupMenu * popupMenu
Definition: popupmenu.cpp:103
ShortcutWindow * itemShortcutWindow

References CAST_S32, DragDrop::clear(), DragDrop::deselect(), dragDrop, TextCommand::getId(), ShortcutContainer::getIndexFromGrid(), getItemByIndex(), SpellShortcut::getSelectedItem(), DragDrop::getSource(), SpellManager::getSpell(), ShortcutWindow::getTabIndex(), DragDrop::getTag(), MouseEvent::getX(), MouseEvent::getY(), DragDrop::isEmpty(), TextCommand::isEmpty(), itemShortcut, itemShortcutWindow, MouseButton::LEFT, Viewport::mMouseX, Viewport::mMouseY, mNumber, mSpellClicked, popupMenu, MouseButton::RIGHT, SpellManager::save(), ItemShortcut::setItemSelected(), SpellShortcut::setItemSelected(), SHORTCUT_TABS, PopupMenu::showSpellPopup(), SPELL_MIN_ID, SPELL_SHORTCUT_ITEMS, spellManager, DragDropSource::Spells, spellShortcut, SpellManager::swap(), and viewport.

◆ safeDraw()

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

Implements Widget.

Definition at line 130 of file spellshortcutcontainer.cpp.

131 {
132  if (spellShortcut == nullptr)
133  return;
134 
135  BLOCK_START("SpellShortcutContainer::draw")
136  if (settings.guiAlpha != mAlpha)
137  {
139  if (mBackgroundImg != nullptr)
140  mBackgroundImg->setAlpha(mAlpha);
141  }
142 
143  Font *const font = getFont();
144 
145  const int selectedId = spellShortcut->getSelectedItem();
146  graphics->setColor(mForegroundColor);
147  safeDrawBackground(graphics);
148 
149  // +++ in future need reorder images and string drawing.
150  for (unsigned i = 0; i < mMaxItems; i++)
151  {
152  const int itemX = (i % mGridWidth) * mBoxWidth;
153  const int itemY = (i / mGridWidth) * mBoxHeight;
154 
155  const int itemId = getItemByIndex(i);
156  if (selectedId >= 0 && itemId == selectedId)
157  {
158  graphics->drawRectangle(Rect(itemX + 1, itemY + 1,
159  mBoxWidth - 1, mBoxHeight - 1));
160  }
161 
162  if (spellManager == nullptr)
163  continue;
164 
165  const TextCommand *const spell = spellManager->getSpell(itemId);
166  if (spell != nullptr)
167  {
168  if (!spell->isEmpty())
169  {
170  Image *const image = spell->getImage();
171 
172  if (image != nullptr)
173  {
174  image->setAlpha(1.0F);
175  graphics->drawImage(image,
176  itemX + mImageOffsetX,
177  itemY + mImageOffsetY);
178  }
179  }
180 
181  font->drawString(graphics,
184  spell->getSymbol(),
185  itemX + mTextOffsetX,
186  itemY + mTextOffsetY);
187  }
188  }
189 
190  BLOCK_END("SpellShortcutContainer::draw")
191 }
void safeDrawBackground(Graphics *const g)

References BLOCK_END, BLOCK_START, Graphics::drawImage(), Graphics::drawRectangle(), Font::drawString(), Widget::getFont(), TextCommand::getImage(), getItemByIndex(), SpellShortcut::getSelectedItem(), SpellManager::getSpell(), TextCommand::getSymbol(), Settings::guiAlpha, TextCommand::isEmpty(), ShortcutContainer::mAlpha, ShortcutContainer::mBackgroundImg, ShortcutContainer::mBoxHeight, ShortcutContainer::mBoxWidth, Widget::mForegroundColor, Widget2::mForegroundColor2, ShortcutContainer::mGridWidth, ShortcutContainer::mImageOffsetX, ShortcutContainer::mImageOffsetY, ShortcutContainer::mMaxItems, ShortcutContainer::mTextOffsetX, ShortcutContainer::mTextOffsetY, ShortcutContainer::safeDrawBackground(), Graphics::setColor(), settings, spellManager, and spellShortcut.

◆ setSkin()

void SpellShortcutContainer::setSkin ( const Widget2 *const  widget,
Skin *const  skin 
)
virtual

Reimplemented from ShortcutContainer.

Definition at line 59 of file spellshortcutcontainer.cpp.

61 {
62  ShortcutContainer::setSkin(widget, skin);
64  mForegroundColor2 = getThemeColor(ThemeColorId::TEXT_OUTLINE, 255U);
65 }
virtual void setSkin(const Widget2 *const widget, Skin *const skin)
const Color & getThemeColor(const ThemeColorIdT type, const unsigned int alpha) const A_INLINE
Definition: widget2.h:45

References Widget2::getThemeColor(), Widget::mForegroundColor, Widget2::mForegroundColor2, ShortcutContainer::setSkin(), and QuestType::TEXT.

◆ widgetHidden()

void SpellShortcutContainer::widgetHidden ( const Event event)
virtual

Invoked when a widget is hidden, i.e it's set to be not visible.

Parameters
eventDescribes the event.

Reimplemented from WidgetListener.

Definition at line 368 of file spellshortcutcontainer.cpp.

369 {
370  if (spellPopup != nullptr)
372 }

References Widget::setVisible(), spellPopup, and Visible_false.

Field Documentation

◆ mNumber

unsigned int SpellShortcutContainer::mNumber
private

Definition at line 83 of file spellshortcutcontainer.h.

Referenced by getItemByIndex(), and mouseReleased().

◆ mSpellClicked

bool SpellShortcutContainer::mSpellClicked
private

Definition at line 84 of file spellshortcutcontainer.h.

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


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