Otclient  14/8/2020
statictext.h
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 #ifndef STATICTEXT_H
24 #define STATICTEXT_H
25 
26 #include "thing.h"
28 #include <framework/core/timer.h>
29 
30 // @bindclass
31 class StaticText : public Thing
32 {
33 public:
34  StaticText();
35 
36  void drawText(const Point& dest, const Rect& parentRect);
37 
38  std::string getName() { return m_name; }
39  Otc::MessageMode getMessageMode() { return m_mode; }
40  std::string getFirstMessage() { return m_messages[0].first; }
41 
42  bool isYell() { return m_mode == Otc::MessageYell || m_mode == Otc::MessageMonsterYell || m_mode == Otc::MessageBarkLoud; }
43 
44  void setText(const std::string& text);
45  void setFont(const std::string& fontName);
46  bool addMessage(const std::string& name, Otc::MessageMode mode, const std::string& text);
47 
48  StaticTextPtr asStaticText() { return static_self_cast<StaticText>(); }
49  bool isStaticText() { return true; }
50 
51  void setColor(const Color& color) { m_color = color; }
52  Color getColor() { return m_color; }
53 
54 private:
55  void update();
56  void scheduleUpdate();
57  void compose();
58 
60  std::deque<std::pair<std::string, ticks_t>> m_messages;
61  std::string m_name;
62  Otc::MessageMode m_mode;
63  Color m_color;
64  CachedText m_cachedText;
65  ScheduledEventPtr m_updateEvent;
66 };
67 
68 #endif
StaticText::getFirstMessage
std::string getFirstMessage()
Definition: statictext.h:40
Color
Definition: color.h:32
StaticText::getColor
Color getColor()
Definition: statictext.h:52
StaticText::setText
void setText(const std::string &text)
Definition: statictext.cpp:57
TRect< int >
CachedText
Definition: cachedtext.h:29
StaticText::addMessage
bool addMessage(const std::string &name, Otc::MessageMode mode, const std::string &text)
Definition: statictext.cpp:62
StaticText::asStaticText
StaticTextPtr asStaticText()
Definition: statictext.h:48
StaticText
Definition: statictext.h:31
cachedtext.h
stdext::boolean< false >
Thing
Definition: thing.h:33
Otc::MessageYell
@ MessageYell
Definition: const.h:290
StaticText::isStaticText
bool isStaticText()
Definition: statictext.h:49
StaticText::isYell
bool isYell()
Definition: statictext.h:42
Otc::MessageMode
MessageMode
Definition: const.h:286
timer.h
Otc::MessageBarkLoud
@ MessageBarkLoud
Definition: const.h:322
StaticText::StaticText
StaticText()
Definition: statictext.cpp:30
StaticText::drawText
void drawText(const Point &dest, const Rect &parentRect)
Definition: statictext.cpp:38
stdext::shared_object_ptr
Definition: shared_object.h:39
StaticText::getMessageMode
Otc::MessageMode getMessageMode()
Definition: statictext.h:39
thing.h
TPoint< int >
StaticText::setFont
void setFont(const std::string &fontName)
Definition: statictext.cpp:52
Otc::MessageMonsterYell
@ MessageMonsterYell
Definition: const.h:332
StaticText::getName
std::string getName()
Definition: statictext.h:38
StaticText::setColor
void setColor(const Color &color)
Definition: statictext.h:51