Otclient 1.0  14/8/2020
uisprite.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010-2020 OTClient <https://github.com/edubart/otclient>
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to deal
6  * in the Software without restriction, including without limitation the rights
7  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  * copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20  * THE SOFTWARE.
21  */
22 
23 #include "uisprite.h"
24 #include <client/spritemanager.h>
27 #include <framework/otml/otml.h>
28 
30  m_spriteId(0),
31  m_spriteColor(Color::white)
32 {
33 }
34 
36 {
37  if((drawPane & Fw::ForegroundPane) == 0)
38  return;
39 
40  // draw style components in order
41  if(m_backgroundColor.aF() > Fw::MIN_ALPHA) {
42  Rect backgroundDestRect = m_rect;
45  }
46 
48 
49  if(m_spriteVisible && m_sprite) {
52  }
53 
57 }
58 
60 {
61  if(!g_sprites.isLoaded())
62  return;
63 
64  m_spriteId = id;
65  if(id == 0)
66  m_sprite = nullptr;
67  else {
68  const ImagePtr image = g_sprites.getSpriteImage(id);
69  if(image)
70  m_sprite = new Texture(image);
71  else
72  m_sprite = nullptr;
73  }
74 }
75 
76 void UISprite::onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode)
77 {
78  UIWidget::onStyleApply(styleName, styleNode);
79 
80  for(const OTMLNodePtr& node : styleNode->children()) {
81  if(node->tag() == "sprite-id")
82  setSpriteId(node->value<int>());
83  else if(node->tag() == "sprite-visible")
84  setSpriteVisible(node->value<bool>());
85  else if(node->tag() == "sprite-color")
86  setSpriteColor(node->value<Color>());
87  }
88 }
Painter::setColor
virtual void setColor(const Color &color)
Definition: painter.h:77
EdgeGroup::right
T right
Definition: uiwidget.h:41
UIWidget::getPaddingRect
Rect getPaddingRect()
Definition: uiwidget.cpp:1061
graphics.h
Color
Definition: color.h:32
otml.h
TRect< int >
UIWidget::onStyleApply
virtual void onStyleApply(const std::string &styleName, const OTMLNodePtr &styleNode)
Definition: uiwidget.cpp:1480
uisprite.h
Texture
Definition: texture.h:28
EdgeGroup::top
T top
Definition: uiwidget.h:40
UIWidget::m_borderWidth
EdgeGroup< int > m_borderWidth
Definition: uiwidget.h:290
texturemanager.h
UISprite::setSpriteVisible
void setSpriteVisible(bool visible)
Definition: uisprite.h:42
OTMLNode::children
OTMLNodeList children()
Definition: otmlnode.cpp:171
SpriteManager::getSpriteImage
ImagePtr getSpriteImage(int id)
Definition: spritemanager.cpp:127
UIWidget::m_rect
Rect m_rect
Definition: uiwidget.h:62
UISprite::setSpriteId
void setSpriteId(int id)
Definition: uisprite.cpp:59
UIWidget::drawBorder
void drawBorder(const Rect &screenCoords)
Definition: uiwidgetbasestyle.cpp:348
UISprite::m_sprite
TexturePtr m_sprite
Definition: uisprite.h:49
UISprite::drawSelf
void drawSelf(Fw::DrawPane drawPane) override
Definition: uisprite.cpp:35
UISprite::m_spriteColor
Color m_spriteColor
Definition: uisprite.h:51
UISprite::m_spriteVisible
stdext::boolean< true > m_spriteVisible
Definition: uisprite.h:53
TRect::expand
void expand(T top, T right, T bottom, T left)
Definition: rect.h:95
g_sprites
SpriteManager g_sprites
Definition: spritemanager.cpp:29
spritemanager.h
UISprite::UISprite
UISprite()
Definition: uisprite.cpp:29
Color::aF
float aF() const
Definition: color.h:49
UIWidget::drawIcon
void drawIcon(const Rect &screenCoords)
Definition: uiwidgetbasestyle.cpp:380
UISprite::onStyleApply
void onStyleApply(const std::string &styleName, const OTMLNodePtr &styleNode) override
Definition: uisprite.cpp:76
UIWidget::drawImage
void drawImage(const Rect &screenCoords)
Definition: uiwidgetimage.cpp:78
UIWidget::m_backgroundColor
Color m_backgroundColor
Definition: uiwidget.h:282
Fw::DrawPane
DrawPane
Definition: const.h:285
stdext::shared_object_ptr
Definition: shared_object.h:39
SpriteManager::isLoaded
bool isLoaded()
Definition: spritemanager.h:51
Fw::ForegroundPane
@ ForegroundPane
Definition: const.h:286
g_painter
Painter * g_painter
Definition: painter.cpp:28
UISprite::setSpriteColor
void setSpriteColor(Color color)
Definition: uisprite.h:39
EdgeGroup::bottom
T bottom
Definition: uiwidget.h:42
EdgeGroup::left
T left
Definition: uiwidget.h:43
UISprite::m_spriteId
uint16 m_spriteId
Definition: uisprite.h:50
UIWidget::drawText
void drawText(const Rect &screenCoords)
Definition: uiwidgettext.cpp:83
Painter::drawTexturedRect
virtual void drawTexturedRect(const Rect &dest, const TexturePtr &texture, const Rect &src)=0
UIWidget::drawBackground
void drawBackground(const Rect &screenCoords)
Definition: uiwidgetbasestyle.cpp:336