ManaPlus
Public Member Functions | Private Attributes
EmoteShortcutContainer Class Reference

#include <emoteshortcutcontainer.h>

Inheritance diagram for EmoteShortcutContainer:
ShortcutContainer Widget WidgetListener MouseListener Widget2

Public Member Functions

 EmoteShortcutContainer (Widget2 *const widget)
 
 ~EmoteShortcutContainer ()
 
void draw (Graphics *graphics)
 
void safeDraw (Graphics *graphics)
 
void mouseDragged (MouseEvent &event)
 
void mousePressed (MouseEvent &event)
 
void mouseReleased (MouseEvent &event)
 
void mouseMoved (MouseEvent &event)
 
void mouseExited (MouseEvent &event)
 
void widgetHidden (const Event &event)
 
void setSkin (const Widget2 *const widget, Skin *const skin)
 
- Public Member Functions inherited from ShortcutContainer
 ~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 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

std::vector< const EmoteSprite * > mEmoteImg
 
bool mEmoteClicked
 
unsigned char mEmoteMoved
 

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 emote shortcut container. Used to quickly use emoticons.

Definition at line 35 of file emoteshortcutcontainer.h.

Constructor & Destructor Documentation

◆ EmoteShortcutContainer()

EmoteShortcutContainer::EmoteShortcutContainer ( Widget2 *const  widget)
explicit

Constructor. Initializes the graphic.

Definition at line 54 of file emoteshortcutcontainer.cpp.

55  :
56  ShortcutContainer(widget),
57  mEmoteImg(),
58  mEmoteClicked(false),
59  mEmoteMoved(0)
60 {
61  if (mBackgroundImg != nullptr)
62  mBackgroundImg->setAlpha(settings.guiAlpha);
63 
64  // Setup emote sprites
65  for (int i = 0; i <= EmoteDB::getLast(); i++)
66  {
67  const EmoteSprite *const sprite = EmoteDB::getSprite(i, true);
68  if ((sprite != nullptr) && (sprite->sprite != nullptr))
69  mEmoteImg.push_back(sprite);
70  }
71 
73 }
std::vector< const EmoteSprite * > mEmoteImg
float guiAlpha
Definition: settings.h:131
ShortcutContainer(Widget2 *const widget)
static const int MAX_ITEMS
const int & getLast() A_CONST
Definition: emotedb.cpp:301
const EmoteSprite * getSprite(const int id, const bool allowNull)
Definition: emotedb.cpp:292
Settings settings
Definition: settings.cpp:32
const AnimatedSprite * sprite
Definition: emotesprite.h:42

References EmoteDB::getLast(), EmoteDB::getSprite(), Settings::guiAlpha, MAX_ITEMS, ShortcutContainer::mBackgroundImg, mEmoteImg, ShortcutContainer::mMaxItems, settings, and EmoteSprite::sprite.

◆ ~EmoteShortcutContainer()

EmoteShortcutContainer::~EmoteShortcutContainer ( )

Destructor.

Definition at line 75 of file emoteshortcutcontainer.cpp.

76 {
77 }

Member Function Documentation

◆ draw()

void EmoteShortcutContainer::draw ( Graphics graphics)
virtual

Draws the items.

Implements Widget.

Definition at line 87 of file emoteshortcutcontainer.cpp.

88 {
89  if (emoteShortcut == nullptr)
90  return;
91 
92  BLOCK_START("EmoteShortcutContainer::draw")
93  if (settings.guiAlpha != mAlpha)
94  {
95  if (mBackgroundImg != nullptr)
96  mBackgroundImg->setAlpha(mAlpha);
98  }
99 
100  Font *const font = getFont();
101  drawBackground(graphics);
102 
103  unsigned sz = CAST_U32(mEmoteImg.size());
104  if (sz > mMaxItems)
105  sz = mMaxItems;
106  for (unsigned i = 0; i < sz; i++)
107  {
108  const EmoteSprite *restrict const emoteImg = mEmoteImg[i];
109  if (emoteImg != nullptr)
110  {
111  const AnimatedSprite *restrict const sprite = emoteImg->sprite;
112  if (sprite != nullptr)
113  {
114  sprite->draw(graphics,
117  }
118  }
119  }
120  for (unsigned i = 0; i < mMaxItems; i++)
121  {
122  const int emoteX = (i % mGridWidth) * mBoxWidth;
123  const int emoteY = (i / mGridWidth) * mBoxHeight;
124 
125  // Draw emote keyboard shortcut.
126  const std::string key = inputManager.getKeyValueString(
128 
129  font->drawString(graphics,
132  key,
133  emoteX + mTextOffsetX,
134  emoteY + mTextOffsetY);
135  }
136 
137  BLOCK_END("EmoteShortcutContainer::draw")
138 }
#define CAST_U32
Definition: cast.h:31
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
std::string getKeyValueString(const InputActionT index) const
void drawBackground(Graphics *const g)
Color mForegroundColor2
Definition: widget2.h:113
Color mForegroundColor
Definition: widget.h:1086
Font * getFont() const
Definition: widget.cpp:331
EmoteShortcut * emoteShortcut
if(!vert) return
InputManager inputManager
#define restrict
Definition: localconsts.h:165
#define BLOCK_END(name)
Definition: perfomance.h:80
#define BLOCK_START(name)
Definition: perfomance.h:79

References BLOCK_END, BLOCK_START, CAST_U32, Font::drawString(), InputAction::EMOTE_1, emoteShortcut, InputManager::getKeyValueString(), Settings::guiAlpha, inputManager, restrict, and settings.

◆ mouseDragged()

void EmoteShortcutContainer::mouseDragged ( MouseEvent event)
virtual

Handles mouse when dragged.

Reimplemented from MouseListener.

Definition at line 193 of file emoteshortcutcontainer.cpp.

195 {
196 }

◆ mouseExited()

void EmoteShortcutContainer::mouseExited ( MouseEvent event)
virtual

Called when the mouse has exited the widget area.

Parameters
eventDescribes the event.

Reimplemented from MouseListener.

Definition at line 288 of file emoteshortcutcontainer.cpp.

290 {
291  if (textPopup != nullptr)
293 }
void setVisible(Visible visible)
Definition: widget.cpp:225
TextPopup * textPopup
Definition: textpopup.cpp:33
const bool Visible_false
Definition: visible.h:30

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

◆ mouseMoved()

void EmoteShortcutContainer::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 268 of file emoteshortcutcontainer.cpp.

269 {
270  if ((emoteShortcut == nullptr) || (textPopup == nullptr))
271  return;
272 
273  const int index = getIndexFromGrid(event.getX(), event.getY());
274 
275  if (index == -1)
276  return;
277 
279 
280  if (CAST_SIZE(index) < mEmoteImg.size() && (mEmoteImg[index] != nullptr))
281  {
282  const EmoteSprite *restrict const sprite = mEmoteImg[index];
284  strprintf("%s, %d", sprite->name.c_str(), sprite->id));
285  }
286 }
#define CAST_SIZE
Definition: cast.h:34
int getX() const
Definition: mouseevent.h:127
int getY() const
Definition: mouseevent.h:138
int getIndexFromGrid(const int pointX, const int pointY) const
void show(const int x, const int y, const std::string &str1)
Definition: textpopup.h:57
int mMouseX
Definition: viewport.h:154
int mMouseY
Definition: viewport.h:155
Viewport * viewport
Definition: viewport.cpp:36
std::string strprintf(const char *const format,...)

References CAST_SIZE, emoteShortcut, Viewport::mMouseX, Viewport::mMouseY, restrict, Widget::setVisible(), TextPopup::show(), strprintf(), textPopup, viewport, and Visible_false.

◆ mousePressed()

void EmoteShortcutContainer::mousePressed ( MouseEvent event)
virtual

Handles mouse when pressed.

Reimplemented from MouseListener.

Definition at line 198 of file emoteshortcutcontainer.cpp.

199 {
200  if (event.isConsumed())
201  return;
202 
203  if (event.getButton() == MouseButton::LEFT)
204  {
205  if (emoteShortcut == nullptr)
206  return;
207 
208  const int index = getIndexFromGrid(event.getX(), event.getY());
209 
210  if (index == -1)
211  return;
212 
213  event.consume();
214  // Stores the selected emote if there is one.
216  {
217  emoteShortcut->setEmote(index);
219  }
220  else if (emoteShortcut->getEmote(index) != 0U)
221  {
222  mEmoteClicked = true;
223  }
224  }
225  else if (event.getButton() == MouseButton::RIGHT)
226  {
227  if (popupMenu != nullptr)
228  {
229  event.consume();
231  }
232  }
233 }
void setEmoteSelected(const unsigned char emoteId)
Definition: emoteshortcut.h:98
bool isEmoteSelected() const
unsigned char getEmote(const size_t index) const
Definition: emoteshortcut.h:60
void setEmote(const size_t index)
Definition: emoteshortcut.h:80
bool isConsumed() const
MouseButtonT getButton() const
Definition: mouseevent.h:116
void showEmoteType()
Definition: popupmenu.cpp:1215
PopupMenu * popupMenu
Definition: popupmenu.cpp:103

References emoteShortcut, EmoteShortcut::getEmote(), EmoteShortcut::isEmoteSelected(), MouseButton::LEFT, popupMenu, MouseButton::RIGHT, EmoteShortcut::setEmote(), EmoteShortcut::setEmoteSelected(), and PopupMenu::showEmoteType().

◆ mouseReleased()

void EmoteShortcutContainer::mouseReleased ( MouseEvent event)
virtual

Handles mouse release.

Reimplemented from MouseListener.

Definition at line 235 of file emoteshortcutcontainer.cpp.

237 {
238  if (emoteShortcut == nullptr)
239  return;
240 
241  if (event.getButton() == MouseButton::LEFT)
242  {
243  const int index = getIndexFromGrid(event.getX(), event.getY());
244 
247 
248  if (index == -1)
249  {
250  mEmoteMoved = 0;
251  return;
252  }
253 
254  if (mEmoteMoved != 0U)
255  {
257  mEmoteMoved = 0;
258  }
259  else if ((emoteShortcut->getEmote(index) != 0U) && mEmoteClicked)
260  {
261  emoteShortcut->useEmote(index + 1);
262  }
263 
264  mEmoteClicked = false;
265  }
266 }
void setEmotes(const size_t index, const unsigned char emoteId)
Definition: emoteshortcut.h:89
void useEmote(const size_t index) const

References emoteShortcut, EmoteShortcut::getEmote(), EmoteShortcut::isEmoteSelected(), MouseButton::LEFT, EmoteShortcut::setEmotes(), EmoteShortcut::setEmoteSelected(), and EmoteShortcut::useEmote().

◆ safeDraw()

void EmoteShortcutContainer::safeDraw ( Graphics graphics)
virtual

Implements Widget.

Definition at line 140 of file emoteshortcutcontainer.cpp.

141 {
142  if (emoteShortcut == nullptr)
143  return;
144 
145  BLOCK_START("EmoteShortcutContainer::draw")
146  if (settings.guiAlpha != mAlpha)
147  {
148  if (mBackgroundImg != nullptr)
149  mBackgroundImg->setAlpha(mAlpha);
151  }
152 
153  Font *const font = getFont();
154  safeDrawBackground(graphics);
155 
156  unsigned sz = CAST_U32(mEmoteImg.size());
157  if (sz > mMaxItems)
158  sz = mMaxItems;
159  for (unsigned i = 0; i < sz; i++)
160  {
161  const EmoteSprite *restrict const emoteImg = mEmoteImg[i];
162  if (emoteImg != nullptr)
163  {
164  const AnimatedSprite *restrict const sprite = emoteImg->sprite;
165  if (sprite != nullptr)
166  {
167  sprite->draw(graphics,
170  }
171  }
172  }
173  for (unsigned i = 0; i < mMaxItems; i++)
174  {
175  const int emoteX = (i % mGridWidth) * mBoxWidth;
176  const int emoteY = (i / mGridWidth) * mBoxHeight;
177 
178  // Draw emote keyboard shortcut.
179  const std::string key = inputManager.getKeyValueString(
181 
182  font->drawString(graphics,
185  key,
186  emoteX + mTextOffsetX,
187  emoteY + mTextOffsetY);
188  }
189 
190  BLOCK_END("EmoteShortcutContainer::draw")
191 }
void safeDrawBackground(Graphics *const g)

References BLOCK_END, BLOCK_START, CAST_U32, Font::drawString(), InputAction::EMOTE_1, emoteShortcut, InputManager::getKeyValueString(), Settings::guiAlpha, inputManager, restrict, and settings.

◆ setSkin()

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

Reimplemented from ShortcutContainer.

Definition at line 79 of file emoteshortcutcontainer.cpp.

81 {
82  ShortcutContainer::setSkin(widget, skin);
84  mForegroundColor2 = getThemeColor(ThemeColorId::TEXT_OUTLINE, 255U);
85 }
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 EmoteShortcutContainer::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 295 of file emoteshortcutcontainer.cpp.

297 {
298  if (textPopup != nullptr)
300 }

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

Field Documentation

◆ mEmoteClicked

bool EmoteShortcutContainer::mEmoteClicked
private

Definition at line 89 of file emoteshortcutcontainer.h.

◆ mEmoteImg

std::vector<const EmoteSprite*> EmoteShortcutContainer::mEmoteImg
private

Definition at line 87 of file emoteshortcutcontainer.h.

Referenced by EmoteShortcutContainer().

◆ mEmoteMoved

unsigned char EmoteShortcutContainer::mEmoteMoved
private

Definition at line 90 of file emoteshortcutcontainer.h.


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