Otclient  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 <framework/otml/otml.h>
27 #include <client/spritemanager.h>
28 
30  m_spriteId(0),
31  m_spriteColor(Color::white)
32 { }
33 
35 {
36  if((drawPane & Fw::ForegroundPane) == 0)
37  return;
38 
39  // draw style components in order
40  if(m_backgroundColor.aF() > Fw::MIN_ALPHA) {
41  Rect backgroundDestRect = m_rect;
44  }
45 
47 
48  if(m_spriteVisible && m_sprite) {
51  }
52 
56 }
57 
59 {
60  if(!g_sprites.isLoaded())
61  return;
62 
63  m_spriteId = id;
64  if(id == 0)
65  m_sprite = nullptr;
66  else {
67  ImagePtr image = g_sprites.getSpriteImage(id);
68  if(image)
69  m_sprite = new Texture(image);
70  else
71  m_sprite = nullptr;
72  }
73 }
74 
75 void UISprite::onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode)
76 {
77  UIWidget::onStyleApply(styleName, styleNode);
78 
79  for(const OTMLNodePtr& node : styleNode->children()) {
80  if(node->tag() == "sprite-id")
81  setSpriteId(node->value<int>());
82  else if(node->tag() == "sprite-visible")
83  setSpriteVisible(node->value<bool>());
84  else if(node->tag() == "sprite-color")
85  setSpriteColor(node->value<Color>());
86  }
87 }
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:1054
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:1461
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:170
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:58
UIWidget::drawBorder
void drawBorder(const Rect &screenCoords)
Definition: uiwidgetbasestyle.cpp:348
UISprite::m_sprite
TexturePtr m_sprite
Definition: uisprite.h:49
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
UISprite::onStyleApply
void onStyleApply(const std::string &styleName, const OTMLNodePtr &styleNode)
Definition: uisprite.cpp:75
Color::aF
float aF() const
Definition: color.h:49
UIWidget::drawIcon
void drawIcon(const Rect &screenCoords)
Definition: uiwidgetbasestyle.cpp:380
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
UISprite::drawSelf
void drawSelf(Fw::DrawPane drawPane)
Definition: uisprite.cpp:34