ManaPlus
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

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

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

Constructor & Destructor Documentation

◆ ~ShortcutContainer()

ShortcutContainer::~ShortcutContainer ( )

Destructor.

Definition at line 83 of file shortcutcontainer.cpp.

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

84 {
85  if (mBackgroundImg != nullptr)
86  {
88  mBackgroundImg = nullptr;
89  }
90 
91  if (gui != nullptr)
92  gui->removeDragged(this);
93 
95 }
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:522

◆ ShortcutContainer()

ShortcutContainer::ShortcutContainer ( Widget2 *const  widget)
explicitprotected

Constructor. Initializes the shortcut container.

Definition at line 42 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().

42  :
43  Widget(widget),
45  MouseListener(),
46  mBackgroundImg(nullptr),
47  mSkin(nullptr),
48  mMaxItems(0),
49  mBoxWidth(1),
50  mBoxHeight(1),
51  mGridWidth(1),
52  mGridHeight(1),
53  mImageOffsetX(2),
54  mImageOffsetY(2),
55  mTextOffsetX(2),
56  mTextOffsetY(2),
58 {
59  mAllowLogic = false;
60 
61  addMouseListener(this);
62  addWidgetListener(this);
63 
66 
68  "item_shortcut_background.xml", "background.xml");
69 
70  if (mBackgroundImg != nullptr)
71  {
75  }
76  else
77  {
78  mBoxHeight = 1;
79  mBoxWidth = 1;
80  }
81 }
ImageCollection * mVertexes
static Image * getImageFromThemeXml(const std::string &name, const std::string &name2)
Definition: theme.cpp:925
Color mForegroundColor
Definition: widget.h:1085
Settings settings
Definition: settings.cpp:31
virtual void setAlpha(const float alpha)
Definition: image.cpp:286
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 130 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().

131 {
132  if (mBackgroundImg != nullptr)
133  {
134  if (mRedraw)
135  {
136  mRedraw = false;
137  mVertexes->clear();
138  for (unsigned i = 0; i < mMaxItems; i ++)
139  {
141  (i % mGridWidth) * mBoxWidth,
142  (i / mGridWidth) * mBoxHeight);
143  }
144  g->finalize(mVertexes);
145  }
147  }
148 }
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
inline

◆ getBoxWidth()

int ShortcutContainer::getBoxWidth ( ) const
inline

Definition at line 84 of file shortcutcontainer.h.

References mBoxWidth.

Referenced by ShortcutWindow::ShortcutWindow().

85  { return mBoxWidth; }

◆ getIndexFromGrid()

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

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

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

Definition at line 113 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().

115 {
116  const Rect tRect = Rect(0, 0,
118 
119  int index = ((pointY / mBoxHeight) * mGridWidth) + pointX / mBoxWidth;
120 
121  if (!tRect.isPointInRect(pointX, pointY) ||
122  index >= CAST_S32(mMaxItems) || index < 0)
123  {
124  index = -1;
125  }
126 
127  return index;
128 }
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
inline

Definition at line 81 of file shortcutcontainer.h.

References mMaxItems.

Referenced by ShortcutWindow::ShortcutWindow().

82  { return mMaxItems; }

◆ mouseDragged()

void ShortcutContainer::mouseDragged ( MouseEvent event)
inlinevirtual

Handles mouse when dragged.

Reimplemented from MouseListener.

Reimplemented in VirtShortcutContainer, and SpellShortcutContainer.

Definition at line 63 of file shortcutcontainer.h.

64  {
65  }

◆ mousePressed()

void ShortcutContainer::mousePressed ( MouseEvent event)
inlinevirtual

Handles mouse when pressed.

Reimplemented from MouseListener.

Reimplemented in VirtShortcutContainer, and SpellShortcutContainer.

Definition at line 70 of file shortcutcontainer.h.

71  {
72  }

◆ mouseReleased()

void ShortcutContainer::mouseReleased ( MouseEvent event)
inlinevirtual

Handles mouse release.

Reimplemented from MouseListener.

Reimplemented in VirtShortcutContainer, and SpellShortcutContainer.

Definition at line 77 of file shortcutcontainer.h.

78  {
79  }

◆ safeDrawBackground()

void ShortcutContainer::safeDrawBackground ( Graphics *const  g)

Definition at line 150 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().

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

◆ setSkin()

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

Reimplemented in EmoteShortcutContainer, VirtShortcutContainer, ItemShortcutContainer, and SpellShortcutContainer.

Definition at line 167 of file shortcutcontainer.cpp.

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

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

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

◆ widgetMoved()

void ShortcutContainer::widgetMoved ( const Event event)
virtual

Invoked when a widget is moved.

Parameters
eventDescribes the event.

Reimplemented from WidgetListener.

Definition at line 162 of file shortcutcontainer.cpp.

References Widget::mRedraw.

163 {
164  mRedraw = true;
165 }
bool mRedraw
Definition: widget.h:1163

◆ widgetResized()

void ShortcutContainer::widgetResized ( const Event event)
virtual

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

Reimplemented from WidgetListener.

Definition at line 97 of file shortcutcontainer.cpp.

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

98 {
100 
101  if (mGridWidth < 1)
102  mGridWidth = 1;
103 
105 
106  if (mMaxItems % mGridWidth != 0 || mGridHeight < 1)
107  ++mGridHeight;
108 
110  mRedraw = true;
111 }
#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
staticprotected

◆ mBackgroundImg

Image* ShortcutContainer::mBackgroundImg
protected

◆ mBoxHeight

int ShortcutContainer::mBoxHeight
protected

◆ mBoxWidth

int ShortcutContainer::mBoxWidth
protected

◆ mGridHeight

int ShortcutContainer::mGridHeight
protected

Definition at line 121 of file shortcutcontainer.h.

Referenced by getIndexFromGrid(), and widgetResized().

◆ mGridWidth

int ShortcutContainer::mGridWidth
protected

◆ mImageOffsetX

int ShortcutContainer::mImageOffsetX
protected

◆ mImageOffsetY

int ShortcutContainer::mImageOffsetY
protected

◆ mMaxItems

unsigned ShortcutContainer::mMaxItems
protected

◆ mSkin

Skin* ShortcutContainer::mSkin
protected

Definition at line 114 of file shortcutcontainer.h.

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

◆ mTextOffsetX

int ShortcutContainer::mTextOffsetX
protected

◆ mTextOffsetY

int ShortcutContainer::mTextOffsetY
protected

◆ mVertexes

ImageCollection* ShortcutContainer::mVertexes
protected

Definition at line 126 of file shortcutcontainer.h.

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


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