ManaPlus
Public Member Functions | Private Attributes
EmotePage Class Reference

#include <emotepage.h>

Inheritance diagram for EmotePage:
Widget MouseListener WidgetListener Widget2

Public Member Functions

 EmotePage (const Widget2 *const widget)
 
 ~EmotePage ()
 
void draw (Graphics *const graphics)
 
void safeDraw (Graphics *const graphics)
 
void mousePressed (MouseEvent &event)
 
int getIndexFromGrid (const int x, const int y) const
 
void widgetResized (const Event &event)
 
void widgetMoved (const Event &event)
 
void resetAction ()
 
int getSelectedIndex () const
 
- 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 MouseListener
virtual ~MouseListener ()
 
virtual void mouseEntered (MouseEvent &event)
 
virtual void mouseExited (MouseEvent &event)
 
virtual void mouseReleased (MouseEvent &event)
 
virtual void mouseClicked (MouseEvent &event)
 
virtual void mouseWheelMovedUp (MouseEvent &event)
 
virtual void mouseWheelMovedDown (MouseEvent &event)
 
virtual void mouseMoved (MouseEvent &event)
 
virtual void mouseDragged (MouseEvent &event)
 
- Public Member Functions inherited from WidgetListener
virtual ~WidgetListener ()
 
virtual void widgetHidden (const Event &event)
 
virtual void widgetShown (const Event &event)
 

Private Attributes

ImageSetmEmotes
 
ImageCollectionmVertexes
 
int mSelectedIndex
 

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 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 MouseListener
 MouseListener ()
 
- Protected Member Functions inherited from WidgetListener
 WidgetListener ()
 
- 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 Widget
static FontmGlobalFont = 0
 

Detailed Description

Definition at line 34 of file emotepage.h.

Constructor & Destructor Documentation

◆ EmotePage()

EmotePage::EmotePage ( const Widget2 *const  widget)
explicit

Definition at line 43 of file emotepage.cpp.

43  :
44  Widget(widget),
45  MouseListener(),
48  "graphics/sprites/chatemotes.png", emoteWidth, emoteHeight)),
50  mSelectedIndex(-1)
51 {
52  addMouseListener(this);
53  addWidgetListener(this);
54  mAllowLogic = false;
55 }
int mSelectedIndex
Definition: emotepage.h:65
ImageCollection * mVertexes
Definition: emotepage.h:64
ImageSet * mEmotes
Definition: emotepage.h:63
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
ImageSet * getImageSet(const std::string &imagePath, const int w, const int h)
const unsigned int emoteHeight
Definition: emotepage.cpp:40

References Widget::addMouseListener(), Widget::addWidgetListener(), and Widget::mAllowLogic.

◆ ~EmotePage()

EmotePage::~EmotePage ( )

Definition at line 57 of file emotepage.cpp.

58 {
59  if (mEmotes != nullptr)
60  {
61  mEmotes->decRef();
62  mEmotes = nullptr;
63  }
65 }
virtual void decRef()
Definition: resource.cpp:50
#define delete2(var)
Definition: delete2.h:25

References Resource::decRef(), delete2, mEmotes, and mVertexes.

Member Function Documentation

◆ draw()

void EmotePage::draw ( Graphics *const  graphics)
virtual

Draws the widget. It is called by the parent widget when it is time for the widget to draw itself. The graphics object is set up so that all drawing is relative to the widget, i.e coordinate (0,0) is the top left corner of the widget. It is not possible to draw outside of a widget's dimension.

Parameters
graphicsaA graphics object to draw with.

Implements Widget.

Definition at line 67 of file emotepage.cpp.

68 {
69  BLOCK_START("EmotePage::draw")
70 
71  if (mRedraw)
72  {
73  if (mEmotes == nullptr)
74  return;
75 
76  const STD_VECTOR<Image*> &images = mEmotes->getImages();
77 
78  const unsigned int width = mDimension.width;
79  unsigned int x = 0;
80  unsigned int y = 0;
81 
82  mRedraw = false;
83  mVertexes->clear();
84  FOR_EACH (STD_VECTOR<Image*>::const_iterator, it, images)
85  {
86  const Image *const image = *it;
87  if (image != nullptr)
88  {
89  graphics->calcTileCollection(mVertexes, image, x, y);
90  x += emoteWidth;
91  if (x + emoteWidth > width)
92  {
93  x = 0;
94  y += emoteHeight;
95  }
96  }
97  }
98  graphics->finalize(mVertexes);
99  }
100  graphics->drawTileCollection(mVertexes);
101 
102  BLOCK_END("EmotePage::draw")
103 }
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
const std::vector< Image * > & getImages() const
Definition: imageset.h:88
int width
Definition: rect.h:219
Rect mDimension
Definition: widget.h:1101
bool mRedraw
Definition: widget.h:1164
#define FOR_EACH(type, iter, array)
Definition: foreach.h:25
if(!vert) return
#define BLOCK_END(name)
Definition: perfomance.h:80
#define BLOCK_START(name)
Definition: perfomance.h:79

References BLOCK_END, BLOCK_START, Graphics::calcTileCollection(), ImageCollection::clear(), Graphics::drawTileCollection(), anonymous_namespace{emotepage.cpp}::emoteHeight, anonymous_namespace{emotepage.cpp}::emoteWidth, Graphics::finalize(), FOR_EACH, ImageSet::getImages(), Widget::mDimension, mEmotes, Widget::mRedraw, mVertexes, Rect::width, x, and y.

◆ getIndexFromGrid()

int EmotePage::getIndexFromGrid ( const int  x,
const int  y 
) const

Definition at line 143 of file emotepage.cpp.

144 {
145  const int width = mDimension.width;
146  if (x < 0 || x > width || y < 0 || y > mDimension.height)
147  return -1;
148  const int cols = width / emoteWidth;
149  const int index = (y / emoteHeight) * cols + (x / emoteWidth);
150  if (index >= CAST_S32(mEmotes->size()))
151  return -1;
152  return index;
153 }
#define CAST_S32
Definition: cast.h:30
size_type size() const
Definition: imageset.h:73
int height
Definition: rect.h:224

References CAST_S32, anonymous_namespace{emotepage.cpp}::emoteHeight, anonymous_namespace{emotepage.cpp}::emoteWidth, Rect::height, Widget::mDimension, mEmotes, ImageSet::size(), Rect::width, x, and y.

Referenced by mousePressed().

◆ getSelectedIndex()

int EmotePage::getSelectedIndex ( ) const
inline

Definition at line 59 of file emotepage.h.

60  { return mSelectedIndex; }

References mSelectedIndex.

Referenced by EmoteWindow::clearEmote(), and EmoteWindow::getSelectedEmote().

◆ mousePressed()

void EmotePage::mousePressed ( MouseEvent event)
virtual

Called when a mouse button has been pressed on the widget area.

NOTE: A mouse press is NOT equal to a mouse click. Use mouseClickMessage to check for mouse clicks.

Parameters
eventDescribes the event.

Reimplemented from MouseListener.

Definition at line 136 of file emotepage.cpp.

137 {
138  mSelectedIndex = getIndexFromGrid(event.getX(), event.getY());
139  event.consume();
141 }
int getIndexFromGrid(const int x, const int y) const
Definition: emotepage.cpp:143
int getX() const
Definition: mouseevent.h:127
int getY() const
Definition: mouseevent.h:138
void distributeActionEvent()
Definition: widget.cpp:493

References Widget::distributeActionEvent(), getIndexFromGrid(), MouseEvent::getX(), MouseEvent::getY(), and mSelectedIndex.

◆ resetAction()

void EmotePage::resetAction ( )

Definition at line 155 of file emotepage.cpp.

156 {
157  mSelectedIndex = -1;
158 }

References mSelectedIndex.

Referenced by EmoteWindow::clearEmote().

◆ safeDraw()

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

Implements Widget.

Definition at line 105 of file emotepage.cpp.

106 {
107  BLOCK_START("EmotePage::safeDraw")
108 
109  if (mEmotes == nullptr)
110  return;
111 
112  const STD_VECTOR<Image*> &images = mEmotes->getImages();
113 
114  const unsigned int width = mDimension.width;
115  unsigned int x = 0;
116  unsigned int y = 0;
117 
118  FOR_EACH (STD_VECTOR<Image*>::const_iterator, it, images)
119  {
120  const Image *const image = *it;
121  if (image != nullptr)
122  {
123  graphics->drawImage(image, x, y);
124  x += emoteWidth;
125  if (x + emoteWidth > width)
126  {
127  x = 0;
128  y += emoteHeight;
129  }
130  }
131  }
132 
133  BLOCK_END("EmotePage::safeDraw")
134 }
virtual void drawImage(const Image *const image, int dstX, int dstY)=0
#define STD_VECTOR
Definition: vector.h:30

References BLOCK_END, BLOCK_START, Graphics::drawImage(), anonymous_namespace{emotepage.cpp}::emoteHeight, anonymous_namespace{emotepage.cpp}::emoteWidth, FOR_EACH, ImageSet::getImages(), Widget::mDimension, mEmotes, Rect::width, x, and y.

◆ widgetMoved()

void EmotePage::widgetMoved ( const Event event)
virtual

Invoked when a widget is moved.

Parameters
eventDescribes the event.

Reimplemented from WidgetListener.

Definition at line 165 of file emotepage.cpp.

166 {
167  mRedraw = true;
168 }

References Widget::mRedraw.

◆ widgetResized()

void EmotePage::widgetResized ( const Event event)
virtual

Invoked when a widget changes its size.

Parameters
eventDescribes the event.

Reimplemented from WidgetListener.

Definition at line 160 of file emotepage.cpp.

161 {
162  mRedraw = true;
163 }

References Widget::mRedraw.

Referenced by EmoteWindow::widgetMoved(), and EmoteWindow::widgetResized().

Field Documentation

◆ mEmotes

ImageSet* EmotePage::mEmotes
private

Definition at line 63 of file emotepage.h.

Referenced by draw(), getIndexFromGrid(), safeDraw(), and ~EmotePage().

◆ mSelectedIndex

int EmotePage::mSelectedIndex
private

Definition at line 65 of file emotepage.h.

Referenced by getSelectedIndex(), mousePressed(), and resetAction().

◆ mVertexes

ImageCollection* EmotePage::mVertexes
private

Definition at line 64 of file emotepage.h.

Referenced by draw(), and ~EmotePage().


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