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 51 of file desktop.h.

Constructor & Destructor Documentation

◆ Desktop()

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

Definition at line 51 of file desktop.cpp.

51  :
52  Container(widget),
53  LinkHandler(),
55  mWallpaper(nullptr),
57  "browserbox.xml")),
58  mSkin(nullptr),
59  mBackgroundGrayColor(getThemeColor(ThemeColorId::BACKGROUND_GRAY, 255U)),
60  mShowBackground(true)
61 {
63 
64  addWidgetListener(this);
65 
67 
68  if (theme != nullptr)
69  {
70  mSkin = theme->load("desktop.xml",
71  "",
72  true,
74  }
75 
76  if (mSkin != nullptr)
77  mShowBackground = (mSkin->getOption("showBackground") != 0);
78 
79  const std::string appName = branding.getValue("appName", std::string());
80  if (appName.empty())
81  {
83  false);
84  }
85  else
86  {
88  appName.c_str()),
89  false);
90  }
91  mVersionLabel->addRow("copyright",
92  "(C) ManaPlus developers, http://manaplus.org");
95 }
std::string getValue(const std::string &key, const std::string &deflt) const
Container(const Widget2 *const widget)
Definition: container.cpp:30
StaticBrowserBox * mVersionLabel
Definition: desktop.h:81
Color mBackgroundGrayColor
Definition: desktop.h:83
bool mShowBackground
Definition: desktop.h:84
Skin * mSkin
Definition: desktop.h:82
Image * mWallpaper
Definition: desktop.h:80
int getOption(const std::string &name) const
Definition: skin.h:106
void addRow(const std::string &row, const bool atTop)
void setLinkHandler(LinkHandler *linkHandler)
static std::string getThemePath()
Definition: theme.h:67
Skin * load(const std::string &filename, const std::string &filename2, const bool full, const std::string &defaultPath)
Definition: theme.cpp:179
static void loadWallpapers()
Definition: wallpaper.cpp:88
const Color & getThemeColor(const ThemeColorIdT type, const unsigned int alpha) const A_INLINE
Definition: widget2.h:45
Color mBackgroundColor
Definition: widget.h:1091
void addWidgetListener(WidgetListener *const widgetListener)
Definition: widget.cpp:302
Configuration branding
#define FULL_VERSION
Definition: main.h:164
const bool Opaque_false
Definition: opaque.h:30
std::string strprintf(const char *const format,...)
Theme * theme
Definition: theme.cpp:62

References StaticBrowserBox::addRow(), Widget::addWidgetListener(), LinkHighlightMode::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().

◆ ~Desktop()

Desktop::~Desktop ( )

Definition at line 97 of file desktop.cpp.

98 {
99  if (mWallpaper != nullptr)
100  {
101  mWallpaper->decRef();
102  mWallpaper = nullptr;
103  }
104  if (theme != nullptr)
105  theme->unload(mSkin);
106 }
void unload(Skin *const skin)
Definition: theme.cpp:250

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

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 135 of file desktop.cpp.

136 {
137  BLOCK_START("Desktop::draw")
139 
140  const Rect &rect = mDimension;
141  const int width = rect.width;
142  const int height = rect.height;
143  if (mWallpaper != nullptr)
144  {
145  const int wallpWidth = mWallpaper->getWidth();
146  const int wallpHeight = mWallpaper->getHeight();
147 
148  if (width > wallpWidth || height > wallpHeight)
149  {
150  graphics->setColor(mBackgroundGrayColor);
151  graphics->fillRectangle(Rect(0, 0, width, height));
152  }
153 
155  {
156  graphics->drawImage(mWallpaper,
157  (width - wallpWidth) / 2,
158  (height - wallpHeight) / 2);
159  }
160  else
161  {
162  graphics->drawRescaledImage(mWallpaper, 0, 0, width, height);
163  }
164  }
165  else
166  {
167  graphics->setColor(mBackgroundGrayColor);
168  graphics->fillRectangle(Rect(0, 0, width, height));
169  }
170 
171  Container::draw(graphics);
172  GLDEBUG_END()
174 }
void draw(Graphics *const graphics)
void draw(Graphics *const graphics)
Definition: desktop.cpp:135
virtual void drawImage(const Image *const image, int dstX, int dstY)=0
virtual void fillRectangle(const Rect &rectangle)=0
virtual void setColor(const Color &color)
Definition: graphics.h:320
virtual void drawRescaledImage(const Image *const image, int dstX, int dstY, const int desiredWidth, const int desiredHeight)=0
virtual RenderType useOpenGL() const
Definition: imagehelper.h:107
Definition: rect.h:74
Rect mDimension
Definition: widget.h:1101
if(!vert) return
ImageHelper * imageHelper
Definition: imagehelper.cpp:44
#define GLDEBUG_START(text)
Definition: opengldebug.h:35
#define GLDEBUG_END()
Definition: opengldebug.h:36
#define BLOCK_END(name)
Definition: perfomance.h:80
#define BLOCK_START(name)
Definition: perfomance.h:79
@ RENDER_SOFTWARE
Definition: rendertype.h:27

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

Referenced by safeDraw().

◆ handleLink()

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

Implements LinkHandler.

Definition at line 233 of file desktop.cpp.

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

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

◆ postInit()

void Desktop::postInit ( )
virtual

Reimplemented from Widget.

Definition at line 108 of file desktop.cpp.

109 {
110  if (mSkin != nullptr)
111  {
113  mSkin->getOption("versionX", 25),
114  mSkin->getOption("versionY", 2));
115  }
116  else
117  {
118  addXY(mVersionLabel, 25, 2);
119  }
120 }
void addXY(Widget *const widget, const int x, const int y)

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

◆ reloadWallpaper()

void Desktop::reloadWallpaper ( )

Has to be called after updates have been loaded.

Definition at line 122 of file desktop.cpp.

123 {
126 }
void setBestFittingWallpaper()
Definition: desktop.cpp:181

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

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

◆ safeDraw()

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

Reimplemented from BasicContainer2.

Definition at line 176 of file desktop.cpp.

177 {
178  Desktop::draw(graphics);
179 }

References draw().

◆ setBestFittingWallpaper()

void Desktop::setBestFittingWallpaper ( )
private

Definition at line 181 of file desktop.cpp.

182 {
183  if (!mShowBackground || !config.getBoolValue("showBackground"))
184  return;
185 
186  const std::string wallpaperName =
188 
189  Image *const nWallPaper = Theme::getImageFromTheme(wallpaperName);
190 
191  if (nWallPaper != nullptr)
192  {
193  if (mWallpaper != nullptr)
194  {
196  mWallpaper = nullptr;
197  }
198 
199  const Rect &rect = mDimension;
200  const int width = rect.width;
201  const int height = rect.height;
202 
204  (nWallPaper->getWidth() != width ||
205  nWallPaper->getHeight() != height))
206  {
207  // We rescale to obtain a fullscreen wallpaper...
208  Image *const newRsclWlPpr = Loader::getRescaled(
209  nWallPaper, width, height);
210 
211  if (newRsclWlPpr != nullptr)
212  {
213  ResourceManager::decRefDelete(nWallPaper);
214  // We replace the resource in the resource manager
215  mWallpaper = newRsclWlPpr;
216  }
217  else
218  {
219  mWallpaper = nWallPaper;
220  }
221  }
222  else
223  {
224  mWallpaper = nWallPaper;
225  }
226  }
227  else
228  {
229  logger->log("Couldn't load %s as wallpaper", wallpaperName.c_str());
230  }
231 }
bool getBoolValue(const std::string &key) const
void log(const char *const log_text,...)
Definition: logger.cpp:269
int width
Definition: rect.h:219
int height
Definition: rect.h:224
static Image * getImageFromTheme(const std::string &path)
Definition: theme.cpp:655
static std::string getWallpaper(const int width, const int height)
Definition: wallpaper.cpp:137
int getHeight() const
Definition: widget.h:240
int getWidth() const
Definition: widget.h:221
Configuration config
Logger * logger
Definition: logger.cpp:89
Image * getRescaled(const Image *const image, const int width, const int height)
void decRefDelete(Resource *const res)

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

Referenced by reloadWallpaper(), and widgetResized().

◆ 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 128 of file desktop.cpp.

129 {
133 }
void setSize(const int width, const int height)
Definition: widget.cpp:367

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

Field Documentation

◆ mBackgroundGrayColor

Color Desktop::mBackgroundGrayColor
private

Definition at line 83 of file desktop.h.

Referenced by draw().

◆ mShowBackground

bool Desktop::mShowBackground
private

Definition at line 84 of file desktop.h.

Referenced by Desktop(), and setBestFittingWallpaper().

◆ mSkin

Skin* Desktop::mSkin
private

Definition at line 82 of file desktop.h.

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

◆ mVersionLabel

StaticBrowserBox* Desktop::mVersionLabel
private

Definition at line 81 of file desktop.h.

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

◆ mWallpaper

Image* Desktop::mWallpaper
private

Definition at line 80 of file desktop.h.

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


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