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

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
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 inherited from Widget
static FontmGlobalFont = 0

Detailed Description

Definition at line 33 of file emotepage.h.

Constructor & Destructor Documentation

◆ EmotePage()

EmotePage::EmotePage ( const Widget2 *const  widget)

Definition at line 42 of file emotepage.cpp.

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

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

◆ ~EmotePage()

EmotePage::~EmotePage ( )

Definition at line 56 of file emotepage.cpp.

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

57 {
58  if (mEmotes != nullptr)
59  {
60  mEmotes->decRef();
61  mEmotes = nullptr;
62  }
64 }
virtual void decRef()
Definition: resource.cpp:49
#define delete2(var)
Definition: delete2.h:24
ImageSet * mEmotes
Definition: emotepage.h:62
ImageCollection * mVertexes
Definition: emotepage.h:63

Member Function Documentation

◆ draw()

void EmotePage::draw ( Graphics *const  graphics)

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.

graphicsaA graphics object to draw with.

Implements Widget.

Definition at line 66 of file emotepage.cpp.

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.

67 {
68  BLOCK_START("EmotePage::draw")
70  if (mRedraw)
71  {
72  if (mEmotes == nullptr)
73  return;
75  const STD_VECTOR<Image*> &images = mEmotes->getImages();
77  const unsigned int width = mDimension.width;
78  unsigned int x = 0;
79  unsigned int y = 0;
81  mRedraw = false;
82  mVertexes->clear();
83  FOR_EACH (STD_VECTOR<Image*>::const_iterator, it, images)
84  {
85  const Image *const image = *it;
86  if (image != nullptr)
87  {
88  graphics->calcTileCollection(mVertexes, image, x, y);
89  x += emoteWidth;
90  if (x + emoteWidth > width)
91  {
92  x = 0;
93  y += emoteHeight;
94  }
95  }
96  }
97  graphics->finalize(mVertexes);
98  }
99  graphics->drawTileCollection(mVertexes);
101  BLOCK_END("EmotePage::draw")
102 }
const std::vector< Image * > & getImages() const
Definition: imageset.h:87
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
int width
Definition: rect.h:218
virtual void drawTileCollection(const ImageCollection *const vertCol)=0
#define BLOCK_START(name)
Definition: perfomance.h:78
if(!vert) return
#define BLOCK_END(name)
Definition: perfomance.h:79
virtual void finalize(ImageCollection *const col)
Definition: graphics.h:464
ImageSet * mEmotes
Definition: emotepage.h:62
bool mRedraw
Definition: widget.h:1163
ImageCollection * mVertexes
Definition: emotepage.h:63
Definition: image.h:61
virtual void calcTileCollection(ImageCollection *const vertCol, const Image *const image, int x, int y)=0
const unsigned int emoteHeight
Definition: emotepage.cpp:39
Rect mDimension
Definition: widget.h:1100

◆ getIndexFromGrid()

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

Definition at line 142 of file emotepage.cpp.

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

Referenced by mousePressed().

143 {
144  const int width = mDimension.width;
145  if (x < 0 || x > width || y < 0 || y > mDimension.height)
146  return -1;
147  const int cols = width / emoteWidth;
148  const int index = (y / emoteHeight) * cols + (x / emoteWidth);
149  if (index >= CAST_S32(mEmotes->size()))
150  return -1;
151  return index;
152 }
int width
Definition: rect.h:218
#define CAST_S32
Definition: cast.h:29
ImageSet * mEmotes
Definition: emotepage.h:62
size_type size() const
Definition: imageset.h:72
int height
Definition: rect.h:223
const unsigned int emoteHeight
Definition: emotepage.cpp:39
Rect mDimension
Definition: widget.h:1100

◆ getSelectedIndex()

int EmotePage::getSelectedIndex ( ) const

Definition at line 58 of file emotepage.h.

References mSelectedIndex.

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

59  { return mSelectedIndex; }
int mSelectedIndex
Definition: emotepage.h:64

◆ mousePressed()

void EmotePage::mousePressed ( MouseEvent event)

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.

eventDescribes the event.

Reimplemented from MouseListener.

Definition at line 135 of file emotepage.cpp.

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

136 {
137  mSelectedIndex = getIndexFromGrid(event.getX(), event.getY());
138  event.consume();
140 }
int getIndexFromGrid(const int x, const int y) const
Definition: emotepage.cpp:142
void distributeActionEvent()
Definition: widget.cpp:492
int mSelectedIndex
Definition: emotepage.h:64
int getX() const
Definition: mouseevent.h:126

◆ resetAction()

void EmotePage::resetAction ( )

Definition at line 154 of file emotepage.cpp.

References mSelectedIndex.

Referenced by EmoteWindow::clearEmote().

155 {
156  mSelectedIndex = -1;
157 }
int mSelectedIndex
Definition: emotepage.h:64

◆ safeDraw()

void EmotePage::safeDraw ( Graphics *const  graphics)

Implements Widget.

Definition at line 104 of file emotepage.cpp.

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.

105 {
106  BLOCK_START("EmotePage::safeDraw")
108  if (mEmotes == nullptr)
109  return;
111  const STD_VECTOR<Image*> &images = mEmotes->getImages();
113  const unsigned int width = mDimension.width;
114  unsigned int x = 0;
115  unsigned int y = 0;
117  FOR_EACH (STD_VECTOR<Image*>::const_iterator, it, images)
118  {
119  const Image *const image = *it;
120  if (image != nullptr)
121  {
122  graphics->drawImage(image, x, y);
123  x += emoteWidth;
124  if (x + emoteWidth > width)
125  {
126  x = 0;
127  y += emoteHeight;
128  }
129  }
130  }
132  BLOCK_END("EmotePage::safeDraw")
133 }
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
#define BLOCK_START(name)
Definition: perfomance.h:78
if(!vert) return
#define BLOCK_END(name)
Definition: perfomance.h:79
#define STD_VECTOR
Definition: vector.h:29
ImageSet * mEmotes
Definition: emotepage.h:62
virtual void drawImage(const Image *const image, int dstX, int dstY)=0
Definition: image.h:61
const unsigned int emoteHeight
Definition: emotepage.cpp:39
Rect mDimension
Definition: widget.h:1100

◆ widgetMoved()

void EmotePage::widgetMoved ( const Event event)

Invoked when a widget is moved.

eventDescribes the event.

Reimplemented from WidgetListener.

Definition at line 164 of file emotepage.cpp.

References Widget::mRedraw.

165 {
166  mRedraw = true;
167 }
bool mRedraw
Definition: widget.h:1163

◆ widgetResized()

void EmotePage::widgetResized ( const Event event)

Invoked when a widget changes its size.

eventDescribes the event.

Reimplemented from WidgetListener.

Definition at line 159 of file emotepage.cpp.

References Widget::mRedraw.

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

160 {
161  mRedraw = true;
162 }
bool mRedraw
Definition: widget.h:1163

Field Documentation

◆ mEmotes

ImageSet* EmotePage::mEmotes

Definition at line 62 of file emotepage.h.

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

◆ mSelectedIndex

int EmotePage::mSelectedIndex

Definition at line 64 of file emotepage.h.

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

◆ mVertexes

ImageCollection* EmotePage::mVertexes

Definition at line 63 of file emotepage.h.

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

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