ManaPlus
Public Member Functions | Private Attributes

#include <icon.h>

Inheritance diagram for Icon:
Widget Widget2

Public Member Functions

 Icon (const Widget2 *const widget, const std::string &filename, const AutoRelease autoRelease)
 
 Icon (const Widget2 *const widget, Image *const image, const AutoRelease autoRelease)
 
 ~Icon ()
 
ImagegetImage () const
 
void setImage (Image *const image)
 
void draw (Graphics *const g)
 
void safeDraw (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)
 

Private Attributes

ImagemImage
 
AutoRelease mAutoRelease
 

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 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

An icon.

Definition at line 39 of file icon.h.

Constructor & Destructor Documentation

◆ Icon() [1/2]

Icon::Icon ( const Widget2 *const  widget,
const std::string &  filename,
const AutoRelease  autoRelease 
)

Constructor.

Definition at line 35 of file icon.cpp.

References Widget::mAllowLogic, Image::mBounds, mImage, and Widget::setSize().

37  :
38  Widget(widget),
39  mImage(Loader::getImage(file)),
40  mAutoRelease(autoRelease)
41 {
42  if (mImage != nullptr)
43  {
44  const SDL_Rect &bounds = mImage->mBounds;
45  setSize(bounds.w, bounds.h);
46  }
47  mAllowLogic = false;
48 }
void setSize(const int width, const int height)
Definition: widget.cpp:366
Image * mImage
Definition: icon.h:79
Image * getImage(const std::string &idPath)
Definition: imageloader.cpp:85
Widget(const Widget2 *const widget)
Definition: widget.cpp:84
bool mAllowLogic
Definition: widget.h:1159
AutoRelease mAutoRelease
Definition: icon.h:80
SDL_Rect mBounds
Definition: image.h:210

◆ Icon() [2/2]

Icon::Icon ( const Widget2 *const  widget,
Image *const  image,
const AutoRelease  autoRelease 
)

Constructor, uses an existing Image.

Definition at line 50 of file icon.cpp.

References Widget::mAllowLogic, Image::mBounds, mImage, and Widget::setSize().

52  :
53  Widget(widget),
54  mImage(image),
55  mAutoRelease(autoRelease)
56 {
57  if (mImage != nullptr)
58  {
59  const SDL_Rect &bounds = mImage->mBounds;
60  setSize(bounds.w, bounds.h);
61  }
62  mAllowLogic = false;
63 }
void setSize(const int width, const int height)
Definition: widget.cpp:366
Image * mImage
Definition: icon.h:79
Widget(const Widget2 *const widget)
Definition: widget.cpp:84
bool mAllowLogic
Definition: widget.h:1159
AutoRelease mAutoRelease
Definition: icon.h:80
SDL_Rect mBounds
Definition: image.h:210

◆ ~Icon()

Icon::~Icon ( )

Definition at line 65 of file icon.cpp.

References AutoRelease_true, Image::decRef(), gui, mAutoRelease, mImage, and Gui::removeDragged().

66 {
67  if (gui != nullptr)
68  gui->removeDragged(this);
69  if ((mImage != nullptr) && mAutoRelease == AutoRelease_true)
70  mImage->decRef();
71 }
Gui * gui
Definition: gui.cpp:110
Image * mImage
Definition: icon.h:79
void removeDragged(const Widget *const widget)
Definition: gui.cpp:1160
const bool AutoRelease_true
Definition: autorelease.h:29
AutoRelease mAutoRelease
Definition: icon.h:80
void decRef()
Definition: image.cpp:522

Member Function Documentation

◆ draw()

void Icon::draw ( Graphics *const  g)
virtual

Draws the Icon.

Implements Widget.

Definition at line 83 of file icon.cpp.

References BLOCK_END, BLOCK_START, Graphics::drawImage(), Rect::height, Image::mBounds, Widget::mDimension, mImage, and Rect::width.

Referenced by getImage().

84 {
85  BLOCK_START("Icon::draw")
86  if (mImage != nullptr)
87  {
88  graphics->drawImage(mImage,
89  (mDimension.width - mImage->mBounds.w) / 2,
90  (mDimension.height - mImage->mBounds.h) / 2);
91  }
92  BLOCK_END("Icon::draw")
93 }
int width
Definition: rect.h:218
Image * mImage
Definition: icon.h:79
#define BLOCK_START(name)
Definition: perfomance.h:78
if(!vert) return
#define BLOCK_END(name)
Definition: perfomance.h:79
int height
Definition: rect.h:223
SDL_Rect mBounds
Definition: image.h:210
Rect mDimension
Definition: widget.h:1100

◆ getImage()

Image* Icon::getImage ( ) const
inline

Gets the current Image.

Definition at line 63 of file icon.h.

References A_NONNULL, draw(), mImage, safeDraw(), and setImage().

Referenced by ItemPopup::setItem(), and ItemPopup::~ItemPopup().

64  { return mImage; }
Image * mImage
Definition: icon.h:79

◆ safeDraw()

void Icon::safeDraw ( Graphics *const  g)
virtual

Implements Widget.

Definition at line 95 of file icon.cpp.

References BLOCK_END, BLOCK_START, Graphics::drawImage(), Rect::height, Image::mBounds, Widget::mDimension, mImage, and Rect::width.

Referenced by getImage().

96 {
97  BLOCK_START("Icon::draw")
98  if (mImage != nullptr)
99  {
100  graphics->drawImage(mImage,
101  (mDimension.width - mImage->mBounds.w) / 2,
102  (mDimension.height - mImage->mBounds.h) / 2);
103  }
104  BLOCK_END("Icon::draw")
105 }
int width
Definition: rect.h:218
Image * mImage
Definition: icon.h:79
#define BLOCK_START(name)
Definition: perfomance.h:78
if(!vert) return
#define BLOCK_END(name)
Definition: perfomance.h:79
int height
Definition: rect.h:223
SDL_Rect mBounds
Definition: image.h:210
Rect mDimension
Definition: widget.h:1100

◆ setImage()

void Icon::setImage ( Image *const  image)

Sets the image to display.

Definition at line 73 of file icon.cpp.

References Image::mBounds, mImage, and Widget::setSize().

Referenced by ItemAmountWindow::action(), getImage(), and ItemPopup::setItem().

74 {
75  mImage = image;
76  if (mImage != nullptr)
77  {
78  const SDL_Rect &bounds = mImage->mBounds;
79  setSize(bounds.w, bounds.h);
80  }
81 }
void setSize(const int width, const int height)
Definition: widget.cpp:366
Image * mImage
Definition: icon.h:79
SDL_Rect mBounds
Definition: image.h:210

Field Documentation

◆ mAutoRelease

AutoRelease Icon::mAutoRelease
private

Definition at line 80 of file icon.h.

Referenced by ~Icon().

◆ mImage

Image* Icon::mImage
private

Definition at line 79 of file icon.h.

Referenced by draw(), getImage(), Icon(), safeDraw(), setImage(), and ~Icon().


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