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)
virtual void setSkin (const Widget2 *const widget, Skin *const skin)
- 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
int mImageOffsetX
int mImageOffsetY
int mTextOffsetX
int mTextOffsetY
- 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 41 of file shortcutcontainer.h.

Constructor & Destructor Documentation

◆ ~ShortcutContainer()

ShortcutContainer::~ShortcutContainer ( )


Definition at line 84 of file shortcutcontainer.cpp.

85 {
86  if (mBackgroundImg != nullptr)
87  {
88  mBackgroundImg->decRef();
89  mBackgroundImg = nullptr;
90  }
92  if (gui != nullptr)
93  gui->removeDragged(this);
96 }
void removeDragged(const Widget *const widget)
Definition: gui.cpp:1162
ImageCollection * mVertexes
#define delete2(var)
Definition: delete2.h:25
Gui * gui
Definition: gui.cpp:111

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

◆ ShortcutContainer()

ShortcutContainer::ShortcutContainer ( Widget2 *const  widget)

Constructor. Initializes the shortcut container.

Definition at line 43 of file shortcutcontainer.cpp.

43  :
44  Widget(widget),
46  MouseListener(),
47  mBackgroundImg(nullptr),
48  mSkin(nullptr),
49  mMaxItems(0),
50  mBoxWidth(1),
51  mBoxHeight(1),
52  mGridWidth(1),
53  mGridHeight(1),
54  mImageOffsetX(2),
55  mImageOffsetY(2),
56  mTextOffsetX(2),
57  mTextOffsetY(2),
59 {
60  mAllowLogic = false;
62  addMouseListener(this);
63  addWidgetListener(this);
66  mForegroundColor2 = getThemeColor(ThemeColorId::TEXT_OUTLINE, 255U);
69  "item_shortcut_background.xml", "background.xml");
71  if (mBackgroundImg != nullptr)
72  {
73  mBackgroundImg->setAlpha(settings.guiAlpha);
74  mBoxHeight = mBackgroundImg->getHeight();
75  mBoxWidth = mBackgroundImg->getWidth();
76  }
77  else
78  {
79  mBoxHeight = 1;
80  mBoxWidth = 1;
81  }
82 }
float guiAlpha
Definition: settings.h:131
static Image * getImageFromThemeXml(const std::string &name, const std::string &name2)
Definition: theme.cpp:926
Color mForegroundColor2
Definition: widget2.h:113
const Color & getThemeColor(const ThemeColorIdT type, const unsigned int alpha) const A_INLINE
Definition: widget2.h:45
Color mForegroundColor
Definition: widget.h:1086
Widget(const Widget2 *const widget)
Definition: widget.cpp:85
bool mAllowLogic
Definition: widget.h:1160
void addMouseListener(MouseListener *const mouseListener)
Definition: widget.cpp:292
void addWidgetListener(WidgetListener *const widgetListener)
Definition: widget.cpp:302
Settings settings
Definition: settings.cpp:32

References Widget::addMouseListener(), Widget::addWidgetListener(), Theme::getImageFromThemeXml(), Widget2::getThemeColor(), Settings::guiAlpha, Widget::mAllowLogic, mBackgroundImg, mBoxHeight, mBoxWidth, Widget::mForegroundColor, Widget2::mForegroundColor2, settings, and QuestType::TEXT.

Member Function Documentation

◆ drawBackground()

void ShortcutContainer::drawBackground ( Graphics *const  g)

Definition at line 131 of file shortcutcontainer.cpp.

132 {
133  if (mBackgroundImg != nullptr)
134  {
135  if (mRedraw)
136  {
137  mRedraw = false;
138  mVertexes->clear();
139  for (unsigned i = 0; i < mMaxItems; i ++)
140  {
142  (i % mGridWidth) * mBoxWidth,
143  (i / mGridWidth) * mBoxHeight);
144  }
145  g->finalize(mVertexes);
146  }
148  }
149 }
virtual void drawTileCollection(const ImageCollection *const vertCol)=0
virtual void calcTileCollection(ImageCollection *const vertCol, const Image *const image, int x, int y)=0
virtual void finalize(ImageCollection *const col)
Definition: graphics.h:465
bool mRedraw
Definition: widget.h:1164

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

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

◆ getBoxHeight()

int ShortcutContainer::getBoxHeight ( ) const

Definition at line 88 of file shortcutcontainer.h.

89  { return mBoxHeight; }

References mBoxHeight.

Referenced by ShortcutWindow::ShortcutWindow().

◆ getBoxWidth()

int ShortcutContainer::getBoxWidth ( ) const

Definition at line 85 of file shortcutcontainer.h.

86  { return mBoxWidth; }

References mBoxWidth.

Referenced by ShortcutWindow::ShortcutWindow().

◆ 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 114 of file shortcutcontainer.cpp.

116 {
117  const Rect tRect = Rect(0, 0,
120  int index = ((pointY / mBoxHeight) * mGridWidth) + pointX / mBoxWidth;
122  if (!tRect.isPointInRect(pointX, pointY) ||
123  index >= CAST_S32(mMaxItems) || index < 0)
124  {
125  index = -1;
126  }
128  return index;
129 }
#define CAST_S32
Definition: cast.h:30
Definition: rect.h:74
bool isPointInRect(const int x_, const int y_) const
Definition: rect.h:197

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

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

◆ getMaxItems()

int ShortcutContainer::getMaxItems ( ) const

Definition at line 82 of file shortcutcontainer.h.

83  { return mMaxItems; }

References mMaxItems.

Referenced by ShortcutWindow::ShortcutWindow().

◆ mouseDragged()

void ShortcutContainer::mouseDragged ( MouseEvent event)

Handles mouse when dragged.

Reimplemented from MouseListener.

Reimplemented in VirtShortcutContainer, and SpellShortcutContainer.

Definition at line 64 of file shortcutcontainer.h.

65  {
66  }

◆ mousePressed()

void ShortcutContainer::mousePressed ( MouseEvent event)

Handles mouse when pressed.

Reimplemented from MouseListener.

Reimplemented in VirtShortcutContainer, and SpellShortcutContainer.

Definition at line 71 of file shortcutcontainer.h.

72  {
73  }

◆ mouseReleased()

void ShortcutContainer::mouseReleased ( MouseEvent event)

Handles mouse release.

Reimplemented from MouseListener.

Reimplemented in VirtShortcutContainer, and SpellShortcutContainer.

Definition at line 78 of file shortcutcontainer.h.

79  {
80  }

◆ safeDrawBackground()

void ShortcutContainer::safeDrawBackground ( Graphics *const  g)

Definition at line 151 of file shortcutcontainer.cpp.

152 {
153  if (mBackgroundImg != nullptr)
154  {
155  for (unsigned i = 0; i < mMaxItems; i ++)
156  {
158  (i / mGridWidth) * mBoxHeight);
159  }
160  }
161 }
virtual void drawImage(const Image *const image, int dstX, int dstY)=0

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

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

◆ setSkin()

void ShortcutContainer::setSkin ( const Widget2 *const  widget,
Skin *const  skin 

Reimplemented in VirtShortcutContainer, SpellShortcutContainer, ItemShortcutContainer, and EmoteShortcutContainer.

Definition at line 168 of file shortcutcontainer.cpp.

170 {
171  setWidget2(widget);
172  mSkin = skin;
173  if (mSkin)
174  {
175  mImageOffsetX = mSkin->getOption("imageOffsetX", 2);
176  mImageOffsetY = mSkin->getOption("imageOffsetY", 2);
177  mTextOffsetX = mSkin->getOption("textOffsetX", 2);
178  mTextOffsetY = mSkin->getOption("textOffsetY", 2);
179  }
180 }
int getOption(const std::string &name) const
Definition: skin.h:106
virtual void setWidget2(const Widget2 *const widget)
Definition: widget2.h:64

References Skin::getOption(), mImageOffsetX, mImageOffsetY, mSkin, mTextOffsetX, mTextOffsetY, and Widget2::setWidget2().

Referenced by ShortcutWindow::addTab(), EmoteShortcutContainer::setSkin(), ItemShortcutContainer::setSkin(), SpellShortcutContainer::setSkin(), and VirtShortcutContainer::setSkin().

◆ widgetMoved()

void ShortcutContainer::widgetMoved ( const Event event)

Invoked when a widget is moved.

eventDescribes the event.

Reimplemented from WidgetListener.

Definition at line 163 of file shortcutcontainer.cpp.

164 {
165  mRedraw = true;
166 }

References Widget::mRedraw.

◆ 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 98 of file shortcutcontainer.cpp.

99 {
102  if (mGridWidth < 1)
103  mGridWidth = 1;
107  if (mMaxItems % mGridWidth != 0 || mGridHeight < 1)
108  ++mGridHeight;
111  mRedraw = true;
112 }
#define CAST_U32
Definition: cast.h:31
int width
Definition: rect.h:219
Rect mDimension
Definition: widget.h:1101
void setHeight(const int height)
Definition: widget.cpp:140

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

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 122 of file shortcutcontainer.h.

Referenced by getIndexFromGrid(), and widgetResized().

◆ mGridWidth

int ShortcutContainer::mGridWidth

◆ mImageOffsetX

int ShortcutContainer::mImageOffsetX

◆ mImageOffsetY

int ShortcutContainer::mImageOffsetY

◆ mMaxItems

unsigned ShortcutContainer::mMaxItems

◆ mSkin

Skin* ShortcutContainer::mSkin

Definition at line 115 of file shortcutcontainer.h.

Referenced by ItemShortcutContainer::setSkin(), and setSkin().

◆ mTextOffsetX

int ShortcutContainer::mTextOffsetX

◆ mTextOffsetY

int ShortcutContainer::mTextOffsetY

◆ mVertexes

ImageCollection* ShortcutContainer::mVertexes

Definition at line 127 of file shortcutcontainer.h.

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

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