ManaPlus
Public Member Functions | Private Member Functions | Private Attributes
Desktop Class Reference

#include <desktop.h>

Inheritance diagram for Desktop:
Container LinkHandler WidgetListener BasicContainer2 BasicContainer Widget WidgetDeathListener Widget2

Public Member Functions

 Desktop (const Widget2 *const widget)
 
 ~Desktop ()
 
void reloadWallpaper ()
 
void widgetResized (const Event &event)
 
void draw (Graphics *const graphics)
 
void safeDraw (Graphics *const graphics)
 
void postInit ()
 
void handleLink (const std::string &link, MouseEvent *event)
 
- Public Member Functions inherited from Container
 Container (const Widget2 *const widget)
 
 ~Container ()
 
bool safeRemove (Widget *const widget)
 
void removeControls ()
 
- Public Member Functions inherited from BasicContainer2
 BasicContainer2 (const Widget2 *const widget)
 
 ~BasicContainer2 ()
 
void setOpaque (Opaque opaque)
 
bool isOpaque () const
 
virtual void add (Widget *const widget)
 
void addXY (Widget *const widget, const int x, const int y)
 
- Public Member Functions inherited from BasicContainer
 BasicContainer (const Widget2 *const widget)
 
 ~BasicContainer ()
 
void showWidgetPart (Widget *const widget, const Rect &area)
 
void moveToTop (Widget *const widget)
 
void moveToBottom (Widget *const widget)
 
Rect getChildrenArea ()
 
void focusNext ()
 
void focusPrevious ()
 
void logic ()
 
void setFocusHandler (FocusHandler *const focusHandler)
 
void setInternalFocusHandler (FocusHandler *const focusHandler)
 
WidgetgetWidgetAt (int x, int y)
 
void death (const Event &event)
 
WidgetfindFirstWidget (const std::set< Widget *> &list)
 
void add (Widget *const widget)
 
virtual void remove (Widget *const widget)
 
virtual void clear ()
 
- 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
 
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 ()
 
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
 
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 FocusHandlergetInternalFocusHandler ()
 
void setInternalFocusHandler (FocusHandler *const internalFocusHandler)
 
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 ()
 
- 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 WidgetDeathListener
virtual ~WidgetDeathListener ()
 
- Public Member Functions inherited from LinkHandler
 LinkHandler ()
 
virtual ~LinkHandler ()
 
- Public Member Functions inherited from WidgetListener
virtual ~WidgetListener ()
 
virtual void widgetMoved (const Event &event)
 
virtual void widgetHidden (const Event &event)
 
virtual void widgetShown (const Event &event)
 

Private Member Functions

void setBestFittingWallpaper ()
 

Private Attributes

ImagemWallpaper
 
StaticBrowserBoxmVersionLabel
 
SkinmSkin
 
Color mBackgroundGrayColor
 
bool mShowBackground
 

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 BasicContainer
typedef std::vector< Widget * > WidgetList
 
typedef WidgetList::iterator WidgetListIterator
 
typedef WidgetList::const_iterator WidgetListConstIterator
 
typedef WidgetList::reverse_iterator WidgetListReverseIterator
 
typedef WidgetList::const_reverse_iterator WidgetListCReverseIterator
 
- 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 BasicContainer
virtual void drawChildren (Graphics *const graphics)
 
virtual void safeDrawChildren (Graphics *const graphics)
 
virtual void logicChildren ()
 
- 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 WidgetDeathListener
 WidgetDeathListener ()
 
- Protected Member Functions inherited from WidgetListener
 WidgetListener ()
 
- Protected Attributes inherited from BasicContainer2
Opaque mOpaque
 
- Protected Attributes inherited from BasicContainer
WidgetList mWidgets
 
WidgetList mLogicWidgets
 
- 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

Desktop widget, for drawing a background image and color.

It picks the best fitting background image. If the image doesn't fit, a background color is drawn and the image is centered.

When the desktop widget is resized, the background image is automatically updated.

The desktop also displays the client version in the top-right corner.

Definition at line 50 of file desktop.h.

Constructor & Destructor Documentation

◆ Desktop()

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

Definition at line 50 of file desktop.cpp.

References StaticBrowserBox::addRow(), Widget::addWidgetListener(), ThemeColorId::BACKGROUND, branding, FULL_VERSION, Skin::getOption(), Widget2::getThemeColor(), Theme::getThemePath(), ConfigurationObject::getValue(), Theme::load(), Wallpaper::loadWallpapers(), Widget::mBackgroundColor, mShowBackground, mSkin, mVersionLabel, StaticBrowserBox::setLinkHandler(), strprintf(), theme, and StaticBrowserBox::updateHeight().

50  :
51  Container(widget),
52  LinkHandler(),
54  mWallpaper(nullptr),
56  "browserbox.xml")),
57  mSkin(nullptr),
59  mShowBackground(true)
60 {
62 
63  addWidgetListener(this);
64 
66 
67  if (theme != nullptr)
68  {
69  mSkin = theme->load("desktop.xml",
70  "",
71  true,
73  }
74 
75  if (mSkin != nullptr)
76  mShowBackground = (mSkin->getOption("showBackground") != 0);
77 
78  const std::string appName = branding.getValue("appName", std::string());
79  if (appName.empty())
80  {
82  false);
83  }
84  else
85  {
87  appName.c_str()),
88  false);
89  }
90  mVersionLabel->addRow("copyright",
91  "(C) ManaPlus developers, http://manaplus.org");
94 }
Configuration branding
bool mShowBackground
Definition: desktop.h:83
Skin * mSkin
Definition: desktop.h:81
static std::string getThemePath()
Definition: theme.h:66
Skin * load(const std::string &filename, const std::string &filename2, const bool full, const std::string &defaultPath)
Definition: theme.cpp:178
Color mBackgroundGrayColor
Definition: desktop.h:82
int getOption(const std::string &name) const
Definition: skin.h:105
Container(const Widget2 *const widget)
Definition: container.cpp:29
void setLinkHandler(LinkHandler *linkHandler)
Color mBackgroundColor
Definition: widget.h:1090
std::string strprintf(const char *const format,...)
Definition: stringutils.cpp:99
static void loadWallpapers()
Definition: wallpaper.cpp:87
const bool Opaque_false
Definition: opaque.h:29
#define FULL_VERSION
Definition: main.h:163
void addWidgetListener(WidgetListener *const widgetListener)
Definition: widget.cpp:301
std::string getValue(const std::string &key, const std::string &deflt) const
Theme * theme
Definition: theme.cpp:61
Image * mWallpaper
Definition: desktop.h:79
const Color & getThemeColor(const ThemeColorIdT type, const unsigned int alpha) const A_INLINE
Definition: widget2.h:44
StaticBrowserBox * mVersionLabel
Definition: desktop.h:80
void addRow(const std::string &row, const bool atTop)

◆ ~Desktop()

Desktop::~Desktop ( )

Definition at line 96 of file desktop.cpp.

References Image::decRef(), mSkin, mWallpaper, theme, and Theme::unload().

97 {
98  if (mWallpaper != nullptr)
99  {
100  mWallpaper->decRef();
101  mWallpaper = nullptr;
102  }
103  if (theme != nullptr)
104  theme->unload(mSkin);
105 }
void unload(Skin *const skin)
Definition: theme.cpp:249
Skin * mSkin
Definition: desktop.h:81
Theme * theme
Definition: theme.cpp:61
Image * mWallpaper
Definition: desktop.h:79
void decRef()
Definition: image.cpp:522

Member Function Documentation

◆ draw()

void Desktop::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.

Reimplemented from BasicContainer2.

Definition at line 134 of file desktop.cpp.

References BLOCK_END, BLOCK_START, BasicContainer2::draw(), Graphics::drawImage(), Graphics::drawRescaledImage(), Graphics::fillRectangle(), Image::getHeight(), Image::getWidth(), GLDEBUG_END, GLDEBUG_START, Rect::height, imageHelper, mBackgroundGrayColor, Widget::mDimension, mWallpaper, RENDER_SOFTWARE, Graphics::setColor(), ImageHelper::useOpenGL(), and Rect::width.

Referenced by safeDraw().

135 {
136  BLOCK_START("Desktop::draw")
138 
139  const Rect &rect = mDimension;
140  const int width = rect.width;
141  const int height = rect.height;
142  if (mWallpaper != nullptr)
143  {
144  const int wallpWidth = mWallpaper->getWidth();
145  const int wallpHeight = mWallpaper->getHeight();
146 
147  if (width > wallpWidth || height > wallpHeight)
148  {
149  graphics->setColor(mBackgroundGrayColor);
150  graphics->fillRectangle(Rect(0, 0, width, height));
151  }
152 
154  {
155  graphics->drawImage(mWallpaper,
156  (width - wallpWidth) / 2,
157  (height - wallpHeight) / 2);
158  }
159  else
160  {
161  graphics->drawRescaledImage(mWallpaper, 0, 0, width, height);
162  }
163  }
164  else
165  {
166  graphics->setColor(mBackgroundGrayColor);
167  graphics->fillRectangle(Rect(0, 0, width, height));
168  }
169 
170  Container::draw(graphics);
171  GLDEBUG_END()
173 }
virtual RenderType useOpenGL() const
Definition: imagehelper.h:106
ImageHelper * imageHelper
Definition: imagehelper.cpp:43
Definition: rect.h:72
#define BLOCK_START(name)
Definition: perfomance.h:78
#define GLDEBUG_START(text)
Definition: opengldebug.h:34
if(!vert) return
#define BLOCK_END(name)
Definition: perfomance.h:79
Color mBackgroundGrayColor
Definition: desktop.h:82
void draw(Graphics *const graphics)
virtual void setColor(const Color &color)
Definition: graphics.h:319
virtual void drawRescaledImage(const Image *const image, int dstX, int dstY, const int desiredWidth, const int desiredHeight)=0
virtual void fillRectangle(const Rect &rectangle)=0
virtual void drawImage(const Image *const image, int dstX, int dstY)=0
Image * mWallpaper
Definition: desktop.h:79
void draw(Graphics *const graphics)
Definition: desktop.cpp:134
int getWidth() const A_INLINE
Definition: image.h:116
Rect mDimension
Definition: widget.h:1100
#define GLDEBUG_END()
Definition: opengldebug.h:35
int getHeight() const A_INLINE
Definition: image.h:122

◆ handleLink()

void Desktop::handleLink ( const std::string &  link,
MouseEvent event 
)
virtual

Implements LinkHandler.

Definition at line 232 of file desktop.cpp.

References InputManager::executeAction(), inputManager, and InputAction::WINDOW_ABOUT.

233 {
234  if (link == "copyright")
236 }
InputManager inputManager
void executeAction(const InputActionT keyNum)

◆ postInit()

void Desktop::postInit ( )
virtual

Reimplemented from Widget.

Definition at line 107 of file desktop.cpp.

References BasicContainer2::addXY(), Skin::getOption(), mSkin, and mVersionLabel.

108 {
109  if (mSkin != nullptr)
110  {
112  mSkin->getOption("versionX", 25),
113  mSkin->getOption("versionY", 2));
114  }
115  else
116  {
117  addXY(mVersionLabel, 25, 2);
118  }
119 }
Skin * mSkin
Definition: desktop.h:81
void addXY(Widget *const widget, const int x, const int y)
int getOption(const std::string &name) const
Definition: skin.h:105
StaticBrowserBox * mVersionLabel
Definition: desktop.h:80

◆ reloadWallpaper()

void Desktop::reloadWallpaper ( )

Has to be called after updates have been loaded.

Definition at line 121 of file desktop.cpp.

References Wallpaper::loadWallpapers(), and setBestFittingWallpaper().

Referenced by ServerDialog::connectToSelectedServer(), Client::gameExec(), and Client::loadData().

122 {
125 }
void setBestFittingWallpaper()
Definition: desktop.cpp:180
static void loadWallpapers()
Definition: wallpaper.cpp:87

◆ safeDraw()

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

Reimplemented from BasicContainer2.

Definition at line 175 of file desktop.cpp.

References draw().

176 {
177  Desktop::draw(graphics);
178 }
void draw(Graphics *const graphics)
Definition: desktop.cpp:134

◆ setBestFittingWallpaper()

void Desktop::setBestFittingWallpaper ( )
private

Definition at line 180 of file desktop.cpp.

References config, ResourceManager::decRefDelete(), Configuration::getBoolValue(), Image::getHeight(), Widget::getHeight(), Theme::getImageFromTheme(), Loader::getRescaled(), Wallpaper::getWallpaper(), Image::getWidth(), Widget::getWidth(), Rect::height, imageHelper, Logger::log(), logger, Widget::mDimension, mShowBackground, mWallpaper, RENDER_SOFTWARE, ImageHelper::useOpenGL(), and Rect::width.

Referenced by reloadWallpaper(), and widgetResized().

181 {
182  if (!mShowBackground || !config.getBoolValue("showBackground"))
183  return;
184 
185  const std::string wallpaperName =
187 
188  Image *const nWallPaper = Theme::getImageFromTheme(wallpaperName);
189 
190  if (nWallPaper != nullptr)
191  {
192  if (mWallpaper != nullptr)
193  {
195  mWallpaper = nullptr;
196  }
197 
198  const Rect &rect = mDimension;
199  const int width = rect.width;
200  const int height = rect.height;
201 
203  (nWallPaper->getWidth() != width ||
204  nWallPaper->getHeight() != height))
205  {
206  // We rescale to obtain a fullscreen wallpaper...
207  Image *const newRsclWlPpr = Loader::getRescaled(
208  nWallPaper, width, height);
209 
210  if (newRsclWlPpr != nullptr)
211  {
212  ResourceManager::decRefDelete(nWallPaper);
213  // We replace the resource in the resource manager
214  mWallpaper = newRsclWlPpr;
215  }
216  else
217  {
218  mWallpaper = nWallPaper;
219  }
220  }
221  else
222  {
223  mWallpaper = nWallPaper;
224  }
225  }
226  else
227  {
228  logger->log("Couldn't load %s as wallpaper", wallpaperName.c_str());
229  }
230 }
virtual RenderType useOpenGL() const
Definition: imagehelper.h:106
int width
Definition: rect.h:218
int getWidth() const
Definition: widget.h:220
ImageHelper * imageHelper
Definition: imagehelper.cpp:43
Definition: rect.h:72
bool mShowBackground
Definition: desktop.h:83
Configuration config
Logger * logger
Definition: logger.cpp:88
bool getBoolValue(const std::string &key) const
static Image * getImageFromTheme(const std::string &path)
Definition: theme.cpp:654
int height
Definition: rect.h:223
Image * mWallpaper
Definition: desktop.h:79
Definition: image.h:61
int getHeight() const
Definition: widget.h:239
int getWidth() const A_INLINE
Definition: image.h:116
void decRefDelete(Resource *const res)
void log(const char *const log_text,...)
Definition: logger.cpp:264
Rect mDimension
Definition: widget.h:1100
static std::string getWallpaper(const int width, const int height)
Definition: wallpaper.cpp:136
Image * getRescaled(const Image *const image, const int width, const int height)
int getHeight() const A_INLINE
Definition: image.h:122

◆ widgetResized()

void Desktop::widgetResized ( const Event event)
virtual

Invoked when a widget changes its size.

Parameters
eventDescribes the event.

Reimplemented from WidgetListener.

Definition at line 127 of file desktop.cpp.

References Widget::getHeight(), Widget::getWidth(), mVersionLabel, setBestFittingWallpaper(), Widget::setSize(), and StaticBrowserBox::updateHeight().

128 {
132 }
void setSize(const int width, const int height)
Definition: widget.cpp:366
int getWidth() const
Definition: widget.h:220
void setBestFittingWallpaper()
Definition: desktop.cpp:180
int getHeight() const
Definition: widget.h:239
StaticBrowserBox * mVersionLabel
Definition: desktop.h:80

Field Documentation

◆ mBackgroundGrayColor

Color Desktop::mBackgroundGrayColor
private

Definition at line 82 of file desktop.h.

Referenced by draw().

◆ mShowBackground

bool Desktop::mShowBackground
private

Definition at line 83 of file desktop.h.

Referenced by Desktop(), and setBestFittingWallpaper().

◆ mSkin

Skin* Desktop::mSkin
private

Definition at line 81 of file desktop.h.

Referenced by Desktop(), postInit(), and ~Desktop().

◆ mVersionLabel

StaticBrowserBox* Desktop::mVersionLabel
private

Definition at line 80 of file desktop.h.

Referenced by Desktop(), postInit(), and widgetResized().

◆ mWallpaper

Image* Desktop::mWallpaper
private

Definition at line 79 of file desktop.h.

Referenced by draw(), setBestFittingWallpaper(), and ~Desktop().


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