Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes
ShortcutContainer Class Reference

#include <shortcutcontainer.h>

Inheritance diagram for ShortcutContainer:
Widget WidgetListener MouseListener Widget2 EmoteShortcutContainer ItemShortcutContainer SpellShortcutContainer VirtShortcutContainer

Public Member Functions

 ~ShortcutContainer ()
void widgetResized (const Event &event)
void widgetMoved (const Event &event)
void mouseDragged (MouseEvent &event)
void mousePressed (MouseEvent &event)
void mouseReleased (MouseEvent &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 draw (Graphics *const graphics)=0
virtual void safeDraw (Graphics *const graphics)=0
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 widgetHidden (const Event &event)
virtual void widgetShown (const Event &event)
- Public Member Functions inherited from MouseListener
virtual ~MouseListener ()
virtual void mouseEntered (MouseEvent &event)
virtual void mouseExited (MouseEvent &event)
virtual void mouseClicked (MouseEvent &event)
virtual void mouseWheelMovedUp (MouseEvent &event)
virtual void mouseWheelMovedDown (MouseEvent &event)
virtual void mouseMoved (MouseEvent &event)

Protected Member Functions

 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

unsigned mMaxItems
int mBoxWidth
int mBoxHeight
int mGridWidth
int mGridHeight
- 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

static float mAlpha = 1.0
- Static Protected Attributes inherited from Widget
static FontmGlobalFont = 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

Detailed Description

A generic shortcut container.

Definition at line 39 of file shortcutcontainer.h.

Constructor & Destructor Documentation

◆ ~ShortcutContainer()

ShortcutContainer::~ShortcutContainer ( )


Definition at line 77 of file shortcutcontainer.cpp.

References Image::decRef(), delete2, gui, mBackgroundImg, mVertexes, and Gui::removeDragged().

78 {
79  if (mBackgroundImg != nullptr)
80  {
82  mBackgroundImg = nullptr;
83  }
85  if (gui != nullptr)
86  gui->removeDragged(this);
89 }
ImageCollection * mVertexes
Gui * gui
Definition: gui.cpp:110
#define delete2(var)
Definition: delete2.h:24
void removeDragged(const Widget *const widget)
Definition: gui.cpp:1160
void decRef()
Definition: image.cpp:521

◆ ShortcutContainer()

ShortcutContainer::ShortcutContainer ( Widget2 *const  widget)

Constructor. Initializes the shortcut container.

Definition at line 41 of file shortcutcontainer.cpp.

References Widget::addMouseListener(), Widget::addWidgetListener(), Image::getHeight(), Theme::getImageFromThemeXml(), Widget2::getThemeColor(), Image::getWidth(), Settings::guiAlpha, Widget::mAllowLogic, mBackgroundImg, mBoxHeight, mBoxWidth, Widget::mForegroundColor, Widget2::mForegroundColor2, Image::setAlpha(), settings, ThemeColorId::TEXT, and ThemeColorId::TEXT_OUTLINE.

Referenced by getBoxHeight().

41  :
42  Widget(widget),
44  MouseListener(),
45  mBackgroundImg(nullptr),
46  mMaxItems(0),
47  mBoxWidth(1),
48  mBoxHeight(1),
49  mGridWidth(1),
50  mGridHeight(1),
52 {
53  mAllowLogic = false;
55  addMouseListener(this);
56  addWidgetListener(this);
62  "item_shortcut_background.xml", "background.xml");
64  if (mBackgroundImg != nullptr)
65  {
69  }
70  else
71  {
72  mBoxHeight = 1;
73  mBoxWidth = 1;
74  }
75 }
ImageCollection * mVertexes
static Image * getImageFromThemeXml(const std::string &name, const std::string &name2)
Definition: theme.cpp:1135
Color mForegroundColor
Definition: widget.h:1085
Settings settings
Definition: settings.cpp:31
virtual void setAlpha(const float alpha)
Definition: image.cpp:285
Widget(const Widget2 *const widget)
Definition: widget.cpp:84
bool mAllowLogic
Definition: widget.h:1159
void addMouseListener(MouseListener *const mouseListener)
Definition: widget.cpp:291
void addWidgetListener(WidgetListener *const widgetListener)
Definition: widget.cpp:301
Color mForegroundColor2
Definition: widget2.h:112
int getWidth() const A_INLINE
Definition: image.h:116
const Color & getThemeColor(const ThemeColorIdT type, const unsigned int alpha) const A_INLINE
Definition: widget2.h:44
float guiAlpha
Definition: settings.h:129
int getHeight() const A_INLINE
Definition: image.h:122

Member Function Documentation

◆ drawBackground()

void ShortcutContainer::drawBackground ( Graphics *const  g)

Definition at line 124 of file shortcutcontainer.cpp.

References Graphics::calcTileCollection(), ImageCollection::clear(), Graphics::drawTileCollection(), Graphics::finalize(), mBackgroundImg, mBoxHeight, mBoxWidth, mGridWidth, mMaxItems, Widget::mRedraw, and mVertexes.

Referenced by EmoteShortcutContainer::draw(), ItemShortcutContainer::draw(), SpellShortcutContainer::draw(), VirtShortcutContainer::draw(), and getBoxHeight().

125 {
126  if (mBackgroundImg != nullptr)
127  {
128  if (mRedraw)
129  {
130  mRedraw = false;
131  mVertexes->clear();
132  for (unsigned i = 0; i < mMaxItems; i ++)
133  {
135  (i % mGridWidth) * mBoxWidth,
136  (i / mGridWidth) * mBoxHeight);
137  }
138  g->finalize(mVertexes);
139  }
141  }
142 }
virtual void drawTileCollection(const ImageCollection *const vertCol)=0
ImageCollection * mVertexes
virtual void finalize(ImageCollection *const col)
Definition: graphics.h:464
bool mRedraw
Definition: widget.h:1163
virtual void calcTileCollection(ImageCollection *const vertCol, const Image *const image, int x, int y)=0

◆ getBoxHeight()

int ShortcutContainer::getBoxHeight ( ) const

◆ getBoxWidth()

int ShortcutContainer::getBoxWidth ( ) const

Definition at line 83 of file shortcutcontainer.h.

References mBoxWidth.

Referenced by ShortcutWindow::ShortcutWindow().

84  { return mBoxWidth; }

◆ getIndexFromGrid()

int ShortcutContainer::getIndexFromGrid ( const int  pointX,
const int  pointY 
) const

Gets the index from the grid provided the point is in an item box.

pointXX coordinate of the point.
pointYY coordinate of the point.
index on success, -1 on failure.

Definition at line 107 of file shortcutcontainer.cpp.

References CAST_S32, Rect::isPointInRect(), mBoxHeight, mBoxWidth, mGridHeight, mGridWidth, and mMaxItems.

Referenced by getBoxHeight(), ItemShortcutContainer::mouseDragged(), SpellShortcutContainer::mouseDragged(), VirtShortcutContainer::mouseDragged(), EmoteShortcutContainer::mouseMoved(), ItemShortcutContainer::mouseMoved(), SpellShortcutContainer::mouseMoved(), VirtShortcutContainer::mouseMoved(), SpellShortcutContainer::mousePressed(), ItemShortcutContainer::mousePressed(), VirtShortcutContainer::mousePressed(), EmoteShortcutContainer::mousePressed(), ItemShortcutContainer::mouseReleased(), SpellShortcutContainer::mouseReleased(), VirtShortcutContainer::mouseReleased(), and EmoteShortcutContainer::mouseReleased().

109 {
110  const Rect tRect = Rect(0, 0,
113  int index = ((pointY / mBoxHeight) * mGridWidth) + pointX / mBoxWidth;
115  if (!tRect.isPointInRect(pointX, pointY) ||
116  index >= CAST_S32(mMaxItems) || index < 0)
117  {
118  index = -1;
119  }
121  return index;
122 }
Definition: rect.h:72
bool isPointInRect(const int x_, const int y_) const
Definition: rect.h:196
#define CAST_S32
Definition: cast.h:29

◆ getMaxItems()

int ShortcutContainer::getMaxItems ( ) const

Definition at line 80 of file shortcutcontainer.h.

References mMaxItems.

Referenced by ShortcutWindow::ShortcutWindow().

81  { return mMaxItems; }

◆ mouseDragged()

void ShortcutContainer::mouseDragged ( MouseEvent event)

Handles mouse when dragged.

Reimplemented from MouseListener.

Reimplemented in VirtShortcutContainer, and SpellShortcutContainer.

Definition at line 62 of file shortcutcontainer.h.

63  {
64  }

◆ mousePressed()

void ShortcutContainer::mousePressed ( MouseEvent event)

Handles mouse when pressed.

Reimplemented from MouseListener.

Reimplemented in VirtShortcutContainer, and SpellShortcutContainer.

Definition at line 69 of file shortcutcontainer.h.

70  {
71  }

◆ mouseReleased()

void ShortcutContainer::mouseReleased ( MouseEvent event)

Handles mouse release.

Reimplemented from MouseListener.

Reimplemented in VirtShortcutContainer, and SpellShortcutContainer.

Definition at line 76 of file shortcutcontainer.h.

77  {
78  }

◆ safeDrawBackground()

void ShortcutContainer::safeDrawBackground ( Graphics *const  g)

Definition at line 144 of file shortcutcontainer.cpp.

References Graphics::drawImage(), mBackgroundImg, mBoxHeight, mBoxWidth, mGridWidth, and mMaxItems.

Referenced by getBoxHeight(), SpellShortcutContainer::safeDraw(), ItemShortcutContainer::safeDraw(), EmoteShortcutContainer::safeDraw(), and VirtShortcutContainer::safeDraw().

145 {
146  if (mBackgroundImg != nullptr)
147  {
148  for (unsigned i = 0; i < mMaxItems; i ++)
149  {
151  (i / mGridWidth) * mBoxHeight);
152  }
153  }
154 }
virtual void drawImage(const Image *const image, int dstX, int dstY)=0

◆ widgetMoved()

void ShortcutContainer::widgetMoved ( const Event event)

Invoked when a widget is moved.

eventDescribes the event.

Reimplemented from WidgetListener.

Definition at line 156 of file shortcutcontainer.cpp.

References Widget::mRedraw.

157 {
158  mRedraw = true;
159 }
bool mRedraw
Definition: widget.h:1163

◆ widgetResized()

void ShortcutContainer::widgetResized ( const Event event)

Invoked when a widget changes its size. This is used to determine the new height of the container.

Reimplemented from WidgetListener.

Definition at line 91 of file shortcutcontainer.cpp.

References CAST_U32, mBoxHeight, mBoxWidth, Widget::mDimension, mGridHeight, mGridWidth, mMaxItems, Widget::mRedraw, Widget::setHeight(), and Rect::width.

92 {
95  if (mGridWidth < 1)
96  mGridWidth = 1;
100  if (mMaxItems % mGridWidth != 0 || mGridHeight < 1)
101  ++mGridHeight;
104  mRedraw = true;
105 }
#define CAST_U32
Definition: cast.h:30
int width
Definition: rect.h:218
void setHeight(const int height)
Definition: widget.cpp:139
bool mRedraw
Definition: widget.h:1163
Rect mDimension
Definition: widget.h:1100

Field Documentation

◆ mAlpha

float ShortcutContainer::mAlpha = 1.0

◆ mBackgroundImg

Image* ShortcutContainer::mBackgroundImg

◆ mBoxHeight

int ShortcutContainer::mBoxHeight

◆ mBoxWidth

int ShortcutContainer::mBoxWidth

◆ mGridHeight

int ShortcutContainer::mGridHeight

Definition at line 116 of file shortcutcontainer.h.

Referenced by getIndexFromGrid(), and widgetResized().

◆ mGridWidth

int ShortcutContainer::mGridWidth

◆ mMaxItems

unsigned ShortcutContainer::mMaxItems

◆ mVertexes

ImageCollection* ShortcutContainer::mVertexes

Definition at line 117 of file shortcutcontainer.h.

Referenced by drawBackground(), and ~ShortcutContainer().

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