uiprogressrect.cpp

main 97 lines · 3.9 KB Raw
Alex Alex Commit Client Upload Part 2 19/10/2026 00:06
1/*
2 * Copyright (c) 2010-2017 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 "uiprogressrect.h"
24#include <framework/otml/otml.h>
25#include <framework/graphics/graphics.h>
26#include <framework/graphics/fontmanager.h>
27
28UIProgressRect::UIProgressRect()
29{
30 m_percent = 0;
31}
32
33void UIProgressRect::drawSelf(Fw::DrawPane drawPane)
34{
35 if(drawPane != Fw::ForegroundPane)
36 return;
37
38 // todo: check +1 to right/bottom
39 // todo: add smooth
40 Rect drawRect = getPaddingRect();
41
42 // 0% - 12.5% (12.5)
43 // triangle from top center, to top right (var x)
44 if(m_percent < 12.5) {
45 Point var = Point(std::max<int>(m_percent - 0.0, 0.0) * (drawRect.right() - drawRect.horizontalCenter()) / 12.5, 0);
46 g_drawQueue->addFilledTriangle(drawRect.center(), drawRect.topRight() + Point(1,0), drawRect.topCenter() + var, m_backgroundColor);
47 }
48
49 // 12.5% - 37.5% (25)
50 // triangle from top right to bottom right (var y)
51 if(m_percent < 37.5) {
52 Point var = Point(0, std::max<int>(m_percent - 12.5, 0.0) * (drawRect.bottom() - drawRect.top()) / 25.0);
53 g_drawQueue->addFilledTriangle(drawRect.center(), drawRect.bottomRight() + Point(1,1), drawRect.topRight() + var + Point(1,0), m_backgroundColor);
54 }
55
56 // 37.5% - 62.5% (25)
57 // triangle from bottom right to bottom left (var x)
58 if(m_percent < 62.5) {
59 Point var = Point(std::max<int>(m_percent - 37.5, 0.0) * (drawRect.right() - drawRect.left()) / 25.0, 0);
60 g_drawQueue->addFilledTriangle(drawRect.center(), drawRect.bottomLeft() + Point(0,1), drawRect.bottomRight() - var + Point(1,1), m_backgroundColor);
61 }
62
63 // 62.5% - 87.5% (25)
64 // triangle from bottom left to top left
65 if(m_percent < 87.5) {
66 Point var = Point(0, std::max<int>(m_percent - 62.5, 0.0) * (drawRect.bottom() - drawRect.top()) / 25.0);
67 g_drawQueue->addFilledTriangle(drawRect.center(), drawRect.topLeft(), drawRect.bottomLeft() - var + Point(0,1), m_backgroundColor);
68 }
69
70 // 87.5% - 100% (12.5)
71 // triangle from top left to top center
72 if(m_percent < 100) {
73 Point var = Point(std::max<int>(m_percent - 87.5, 0.0) * (drawRect.horizontalCenter() - drawRect.left()) / 12.5, 0);
74 g_drawQueue->addFilledTriangle(drawRect.center(), drawRect.topCenter(), drawRect.topLeft() + var, m_backgroundColor);
75 }
76
77 drawImage(m_rect);
78 drawBorder(m_rect);
79 drawIcon(m_rect);
80 drawText(m_rect);
81}
82
83void UIProgressRect::setPercent(float percent)
84{
85 m_percent = stdext::clamp<float>((double)percent, 0.0, 100.0);
86}
87
88void UIProgressRect::onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode)
89{
90 UIWidget::onStyleApply(styleName, styleNode);
91
92 for(const OTMLNodePtr& node : styleNode->children()) {
93 if(node->tag() == "percent")
94 setPercent(node->value<float>());
95 }
96}
97
Top