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 setWidget2 (const Widget2 *const widget)
 
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
 
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
 
unsigned mMaxItems
 
int mBoxWidth
 
int mBoxHeight
 
int mGridWidth
 
int mGridHeight
 
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.

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

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)
unsigned int getSpellsCount() const A_CONST
SpellShortcut * 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 66 of file spellshortcutcontainer.cpp.

References BLOCK_END, BLOCK_START, ShortcutContainer::drawBackground(), Graphics::drawImage(), Graphics::drawRectangle(), Font::drawString(), ServerCommandType::font, 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::mMaxItems, Image::setAlpha(), Graphics::setColor(), settings, spellManager, and spellShortcut.

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

◆ getItemByIndex()

int SpellShortcutContainer::getItemByIndex ( const int  index) const

Definition at line 367 of file spellshortcutcontainer.cpp.

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

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

368 {
369  return spellShortcut->getItem(
370  (mNumber * SPELL_SHORTCUT_ITEMS) + index);
371 }
int getItem(const size_t index) const
Definition: spellshortcut.h:78
const unsigned int SPELL_SHORTCUT_ITEMS
Definition: spells.h:28
SpellShortcut * spellShortcut

◆ mouseDragged()

void SpellShortcutContainer::mouseDragged ( MouseEvent event)
virtual

Handles mouse when dragged.

Reimplemented from ShortcutContainer.

Definition at line 186 of file spellshortcutcontainer.cpp.

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

187 {
188  if (event.getButton() == MouseButton::LEFT)
189  {
190  if (dragDrop.isEmpty() && mSpellClicked)
191  {
192  mSpellClicked = false;
193  const int index = getIndexFromGrid(event.getX(), event.getY());
194 
195  if (index == -1)
196  return;
197 
198  const int itemId = getItemByIndex(index);
199  if (itemId < 0)
200  return;
201  event.consume();
202  TextCommand *const spell = spellManager->getSpell(itemId);
203  if (spell != nullptr)
204  {
206  dragDrop.setItem(spell->getId() + SPELL_MIN_ID);
207  }
208  else
209  {
210  dragDrop.clear();
211  mSpellClicked = false;
212  }
213  }
214  }
215 }
SpellManager * spellManager
void clear()
Definition: dragdrop.h:182
MouseButtonT getButton() const
Definition: mouseevent.h:115
DragDrop dragDrop
bool isEmpty() const
Definition: dragdrop.h:195
int getIndexFromGrid(const int pointX, const int pointY) const
const int SPELL_MIN_ID
Definition: spells.h:27
TextCommand * getSpell(const int spellId) const
void setItem(const int item)
Definition: dragdrop.h:237
int getX() const
Definition: mouseevent.h:126
int getItemByIndex(const int index) const
int getId() const
Definition: textcommand.h:94
void dragCommand(const TextCommand *const command, const DragDropSourceT source, const int tag)
Definition: dragdrop.h:116

◆ 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 355 of file spellshortcutcontainer.cpp.

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

356 {
357  if (spellPopup != nullptr)
359 }
void setVisible(Visible visible)
Definition: widget.cpp:224
SpellPopup * spellPopup
Definition: spellpopup.cpp:34
const bool Visible_false
Definition: visible.h:29

◆ 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 327 of file spellshortcutcontainer.cpp.

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

328 {
329  if (spellPopup == nullptr ||
330  spellShortcut == nullptr ||
331  spellManager == nullptr)
332  {
333  return;
334  }
335 
336  const int index = getIndexFromGrid(event.getX(), event.getY());
337 
338  if (index == -1)
339  return;
340 
341  const int itemId = getItemByIndex(index);
343  const TextCommand *const spell = spellManager->getSpell(itemId);
344  if ((spell != nullptr) && !spell->isEmpty())
345  {
346  spellPopup->setItem(spell);
348  }
349  else
350  {
352  }
353 }
SpellManager * spellManager
void setVisible(Visible visible)
Definition: widget.cpp:224
int mMouseX
Definition: viewport.h:153
SpellPopup * spellPopup
Definition: spellpopup.cpp:34
int getIndexFromGrid(const int pointX, const int pointY) const
TextCommand * getSpell(const int spellId) const
const bool Visible_false
Definition: visible.h:29
void setItem(const TextCommand *const spell)
Definition: spellpopup.cpp:63
void view(const int x, const int y)
Definition: spellpopup.cpp:91
int mMouseY
Definition: viewport.h:154
bool isEmpty() const
Definition: textcommand.h:153
int getX() const
Definition: mouseevent.h:126
int getItemByIndex(const int index) const
SpellShortcut * spellShortcut
Viewport * viewport
Definition: viewport.cpp:35

◆ mousePressed()

void SpellShortcutContainer::mousePressed ( MouseEvent event)
virtual

Handles mouse when pressed.

Reimplemented from ShortcutContainer.

Definition at line 217 of file spellshortcutcontainer.cpp.

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

218 {
219  const int index = getIndexFromGrid(event.getX(), event.getY());
220 
221  if (index == -1)
222  return;
223 
224  const MouseButtonT eventButton = event.getButton();
225  if (eventButton == MouseButton::LEFT)
226  {
227  const int itemId = getItemByIndex(index);
228  if (itemId > 0)
229  mSpellClicked = true;
230  event.consume();
231  }
232  else if (eventButton == MouseButton::MIDDLE)
233  {
234  if ((spellShortcut == nullptr) || (spellManager == nullptr))
235  return;
236 
237  event.consume();
238  const int itemId = getItemByIndex(index);
239  spellManager->invoke(itemId);
240  }
241 }
SpellManager * spellManager
int getIndexFromGrid(const int pointX, const int pointY) const
void invoke(const int spellId) const
int getX() const
Definition: mouseevent.h:126
int getItemByIndex(const int index) const
MouseButton ::T MouseButtonT
Definition: mousebutton.h:77
SpellShortcut * spellShortcut

◆ mouseReleased()

void SpellShortcutContainer::mouseReleased ( MouseEvent event)
virtual

Handles mouse release.

Reimplemented from ShortcutContainer.

Definition at line 243 of file spellshortcutcontainer.cpp.

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(), TextCommand::isEmpty(), DragDrop::isEmpty(), itemShortcut, itemShortcutWindow, MouseButton::LEFT, Viewport::mMouseX, Viewport::mMouseY, mNumber, mSpellClicked, popupMenu, MouseButton::RIGHT, SpellManager::save(), SpellShortcut::setItemSelected(), ItemShortcut::setItemSelected(), SHORTCUT_TABS, PopupMenu::showSpellPopup(), SPELL_MIN_ID, SPELL_SHORTCUT_ITEMS, spellManager, DragDropSource::Spells, spellShortcut, SpellManager::swap(), and viewport.

244 {
245  if ((spellShortcut == nullptr) || (spellManager == nullptr))
246  return;
247 
248  const int index = getIndexFromGrid(event.getX(), event.getY());
249 
250  if (index == -1)
251  {
252  dragDrop.clear();
253  return;
254  }
255 
256  const int itemId = getItemByIndex(index);
257  const MouseButtonT eventButton = event.getButton();
258 
259  if (eventButton == MouseButton::LEFT)
260  {
261  mSpellClicked = false;
262 
263  if (itemId < 0)
264  return;
265 
266  const int selectedId = spellShortcut->getSelectedItem();
267  event.consume();
268 
269  if (!dragDrop.isEmpty())
270  {
272  {
273  const int oldIndex = dragDrop.getTag();
274  const int idx = mNumber * SPELL_SHORTCUT_ITEMS;
275  spellManager->swap(idx + index, idx + oldIndex);
276  spellManager->save();
277  dragDrop.clear();
278  dragDrop.deselect();
279  }
280  }
281  else
282  {
283  if (selectedId != itemId)
284  {
285  const TextCommand *const
286  spell = spellManager->getSpell(itemId);
287  if ((spell != nullptr) && !spell->isEmpty())
288  {
289  const int num = itemShortcutWindow->getTabIndex();
290  if (num >= 0 && num < CAST_S32(SHORTCUT_TABS)
291  && (itemShortcut[num] != nullptr))
292  {
294  spell->getId() + SPELL_MIN_ID);
295  }
297  }
298  }
299  else
300  {
301  const int num = itemShortcutWindow->getTabIndex();
302  if (num >= 0 && num < CAST_S32(SHORTCUT_TABS)
303  && (itemShortcut[num] != nullptr))
304  {
305  itemShortcut[num]->setItemSelected(-1);
306  }
308  }
309  }
310  }
311  else if (eventButton == MouseButton::RIGHT)
312  {
313  TextCommand *spell = nullptr;
314  if (itemId >= 0)
315  spell = spellManager->getSpell(itemId);
316 
317  if ((spell != nullptr) && (popupMenu != nullptr))
318  {
320  viewport->mMouseY,
321  spell);
322  }
323  }
324 }
void setItemSelected(const int itemId)
Definition: itemshortcut.h:125
int getTag() const
Definition: dragdrop.h:234
void swap(const int id1, const int id2)
SpellManager * spellManager
void clear()
Definition: dragdrop.h:182
void save() const
DragDrop dragDrop
int mMouseX
Definition: viewport.h:153
bool isEmpty() const
Definition: dragdrop.h:195
int getIndexFromGrid(const int pointX, const int pointY) const
const int SPELL_MIN_ID
Definition: spells.h:27
TextCommand * getSpell(const int spellId) const
#define CAST_S32
Definition: cast.h:29
int getTabIndex() const
PopupMenu * popupMenu
Definition: popupmenu.cpp:102
const unsigned int SPELL_SHORTCUT_ITEMS
Definition: spells.h:28
int getSelectedItem() const
Definition: spellshortcut.h:70
void deselect()
Definition: dragdrop.h:212
ShortcutWindow * itemShortcutWindow
void setItemSelected(const int itemId)
Definition: spellshortcut.h:58
const unsigned int SHORTCUT_TABS
Definition: itemshortcut.h:27
ItemShortcut * itemShortcut[SHORTCUT_TABS]
int mMouseY
Definition: viewport.h:154
bool isEmpty() const
Definition: textcommand.h:153
int getX() const
Definition: mouseevent.h:126
int getItemByIndex(const int index) const
DragDropSourceT getSource() const
Definition: dragdrop.h:83
int getId() const
Definition: textcommand.h:94
MouseButton ::T MouseButtonT
Definition: mousebutton.h:77
void showSpellPopup(const int x, const int y, TextCommand *const cmd)
Definition: popupmenu.cpp:886
SpellShortcut * spellShortcut
Viewport * viewport
Definition: viewport.cpp:35

◆ safeDraw()

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

Implements Widget.

Definition at line 126 of file spellshortcutcontainer.cpp.

References BLOCK_END, BLOCK_START, Graphics::drawImage(), Graphics::drawRectangle(), Font::drawString(), ServerCommandType::font, 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::mMaxItems, ShortcutContainer::safeDrawBackground(), Image::setAlpha(), Graphics::setColor(), settings, spellManager, and spellShortcut.

127 {
128  if (spellShortcut == nullptr)
129  return;
130 
131  BLOCK_START("SpellShortcutContainer::draw")
132  if (settings.guiAlpha != mAlpha)
133  {
134  mAlpha = settings.guiAlpha;
135  if (mBackgroundImg != nullptr)
136  mBackgroundImg->setAlpha(mAlpha);
137  }
138 
139  Font *const font = getFont();
140 
141  const int selectedId = spellShortcut->getSelectedItem();
142  graphics->setColor(mForegroundColor);
143  safeDrawBackground(graphics);
144 
145  // +++ in future need reorder images and string drawing.
146  for (unsigned i = 0; i < mMaxItems; i++)
147  {
148  const int itemX = (i % mGridWidth) * mBoxWidth;
149  const int itemY = (i / mGridWidth) * mBoxHeight;
150 
151  const int itemId = getItemByIndex(i);
152  if (selectedId >= 0 && itemId == selectedId)
153  {
154  graphics->drawRectangle(Rect(itemX + 1, itemY + 1,
155  mBoxWidth - 1, mBoxHeight - 1));
156  }
157 
158  if (spellManager == nullptr)
159  continue;
160 
161  const TextCommand *const spell = spellManager->getSpell(itemId);
162  if (spell != nullptr)
163  {
164  if (!spell->isEmpty())
165  {
166  Image *const image = spell->getImage();
167 
168  if (image != nullptr)
169  {
170  image->setAlpha(1.0F);
171  graphics->drawImage(image, itemX, itemY);
172  }
173  }
174 
175  font->drawString(graphics,
178  spell->getSymbol(),
179  itemX + 2, itemY + mBoxHeight / 2);
180  }
181  }
182 
183  BLOCK_END("SpellShortcutContainer::draw")
184 }
Font * getFont() const
Definition: widget.cpp:330
Definition: font.h:88
SpellManager * spellManager
Definition: rect.h:72
#define BLOCK_START(name)
Definition: perfomance.h:78
if(!vert) return
#define BLOCK_END(name)
Definition: perfomance.h:79
Color mForegroundColor
Definition: widget.h:1085
virtual void drawRectangle(const Rect &rectangle)=0
Settings settings
Definition: settings.cpp:31
virtual void setAlpha(const float alpha)
Definition: image.cpp:285
TextCommand * getSpell(const int spellId) const
virtual void setColor(const Color &color)
Definition: graphics.h:319
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 getSelectedItem() const
Definition: spellshortcut.h:70
Color mForegroundColor2
Definition: widget2.h:112
virtual void drawImage(const Image *const image, int dstX, int dstY)=0
std::string getSymbol() const
Definition: textcommand.h:91
Definition: image.h:61
void safeDrawBackground(Graphics *const g)
bool isEmpty() const
Definition: textcommand.h:153
int getItemByIndex(const int index) const
float guiAlpha
Definition: settings.h:129
SpellShortcut * spellShortcut
Image * getImage() const
Definition: textcommand.h:156

◆ setWidget2()

void SpellShortcutContainer::setWidget2 ( const Widget2 *const  widget)
virtual

Reimplemented from Widget2.

Definition at line 59 of file spellshortcutcontainer.cpp.

References Widget2::getThemeColor(), Widget::mForegroundColor, Widget2::mForegroundColor2, Widget2::setWidget2(), ThemeColorId::TEXT, and ThemeColorId::TEXT_OUTLINE.

60 {
61  Widget2::setWidget2(widget);
64 }
virtual void setWidget2(const Widget2 *const widget)
Definition: widget2.h:63
Color mForegroundColor
Definition: widget.h:1085
Color mForegroundColor2
Definition: widget2.h:112
const Color & getThemeColor(const ThemeColorIdT type, const unsigned int alpha) const A_INLINE
Definition: widget2.h:44

◆ 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 361 of file spellshortcutcontainer.cpp.

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

362 {
363  if (spellPopup != nullptr)
365 }
void setVisible(Visible visible)
Definition: widget.cpp:224
SpellPopup * spellPopup
Definition: spellpopup.cpp:34
const bool Visible_false
Definition: visible.h:29

Field Documentation

◆ mNumber

unsigned int SpellShortcutContainer::mNumber
private

Definition at line 82 of file spellshortcutcontainer.h.

Referenced by getItemByIndex(), and mouseReleased().

◆ mSpellClicked

bool SpellShortcutContainer::mSpellClicked
private

Definition at line 83 of file spellshortcutcontainer.h.

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


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