1 |
|
|
/* |
2 |
|
|
* The ManaPlus Client |
3 |
|
|
* Copyright (C) 2004-2009 The Mana World Development Team |
4 |
|
|
* Copyright (C) 2009-2010 The Mana Developers |
5 |
|
|
* Copyright (C) 2011-2019 The ManaPlus Developers |
6 |
|
|
* Copyright (C) 2019-2021 Andrei Karas |
7 |
|
|
* |
8 |
|
|
* This file is part of The ManaPlus Client. |
9 |
|
|
* |
10 |
|
|
* This program is free software; you can redistribute it and/or modify |
11 |
|
|
* it under the terms of the GNU General Public License as published by |
12 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
13 |
|
|
* any later version. |
14 |
|
|
* |
15 |
|
|
* This program is distributed in the hope that it will be useful, |
16 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18 |
|
|
* GNU General Public License for more details. |
19 |
|
|
* |
20 |
|
|
* You should have received a copy of the GNU General Public License |
21 |
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
22 |
|
|
*/ |
23 |
|
|
|
24 |
|
|
#include "gui/windows/cutinwindow.h" |
25 |
|
|
|
26 |
|
|
#include "configuration.h" |
27 |
|
|
|
28 |
|
|
#include "const/utils/timer.h" |
29 |
|
|
|
30 |
|
|
#include "resources/sprite/animatedsprite.h" |
31 |
|
|
|
32 |
|
|
#include "utils/delete2.h" |
33 |
|
|
#include "utils/timer.h" |
34 |
|
|
|
35 |
|
|
#include "debug.h" |
36 |
|
|
|
37 |
|
|
CutInWindow *cutInWindow = nullptr; |
38 |
|
|
|
39 |
|
1 |
CutInWindow::CutInWindow() : |
40 |
|
|
Window("", Modal_false, nullptr, "cutin.xml"), |
41 |
|
|
mImage(nullptr), |
42 |
✓✗✓✗
|
7 |
mOldTitleBarHeight(mTitleBarHeight) |
43 |
|
|
{ |
44 |
✓✗ |
4 |
setWindowName("CutIn"); |
45 |
|
|
|
46 |
|
2 |
setShowTitle(false); |
47 |
✓✗ |
1 |
setResizable(false); |
48 |
|
2 |
setDefaultVisible(false); |
49 |
|
2 |
setSaveVisible(false); |
50 |
✓✗ |
1 |
setVisible(Visible_false); |
51 |
|
2 |
enableVisibleSound(false); |
52 |
|
1 |
} |
53 |
|
|
|
54 |
|
3 |
CutInWindow::~CutInWindow() |
55 |
|
|
{ |
56 |
✗✓ |
1 |
delete2(mImage) |
57 |
|
2 |
} |
58 |
|
|
|
59 |
|
|
void CutInWindow::draw(Graphics *const graphics) |
60 |
|
|
{ |
61 |
|
|
Window::draw(graphics); |
62 |
|
|
draw2(graphics); |
63 |
|
|
} |
64 |
|
|
|
65 |
|
|
void CutInWindow::safeDraw(Graphics *const graphics) |
66 |
|
|
{ |
67 |
|
|
Window::safeDraw(graphics); |
68 |
|
|
draw2(graphics); |
69 |
|
|
} |
70 |
|
|
|
71 |
|
|
void CutInWindow::draw2(Graphics *const graphics) |
72 |
|
|
{ |
73 |
|
|
if (mImage != nullptr) |
74 |
|
|
mImage->drawRaw(graphics, mPadding, mTitleBarHeight); |
75 |
|
|
} |
76 |
|
|
|
77 |
|
|
void CutInWindow::show(const std::string &name, |
78 |
|
|
const CutInT cutin) |
79 |
|
|
{ |
80 |
|
|
delete2(mImage) |
81 |
|
|
if (name.empty()) |
82 |
|
|
{ |
83 |
|
|
setVisible(Visible_false); |
84 |
|
|
} |
85 |
|
|
else |
86 |
|
|
{ |
87 |
|
|
mImage = AnimatedSprite::load( |
88 |
|
|
pathJoin(paths.getStringValue("cutInsDir"), name).append(".xml"), |
89 |
|
|
0); |
90 |
|
|
if (mImage != nullptr) |
91 |
|
|
{ |
92 |
|
|
mImage->update(1); |
93 |
|
|
const bool showTitle = (cutin == CutIn::MovableClose); |
94 |
|
|
if (showTitle) |
95 |
|
|
mTitleBarHeight = mOldTitleBarHeight; |
96 |
|
|
else |
97 |
|
|
mTitleBarHeight = mPadding; |
98 |
|
|
const int width = mImage->getWidth() + 2 * mPadding; |
99 |
|
|
const int height = mImage->getHeight() + mTitleBarHeight |
100 |
|
|
+ mPadding; |
101 |
|
|
|
102 |
|
|
const int screenWidth = mainGraphics->mWidth; |
103 |
|
|
const int screenHeight = mainGraphics->mHeight; |
104 |
|
|
|
105 |
|
|
if (width * 2 > screenWidth || |
106 |
|
|
height * 2 > screenHeight) |
107 |
|
|
{ |
108 |
|
|
return; |
109 |
|
|
} |
110 |
|
|
const int padding = 100; |
111 |
|
|
int x = 0; |
112 |
|
|
const int y = screenHeight - height - padding; |
113 |
|
|
switch (cutin) |
114 |
|
|
{ |
115 |
|
|
case CutIn::BottomRight: |
116 |
|
|
x = screenWidth - width - padding; |
117 |
|
|
break; |
118 |
|
|
case CutIn::BottomCenter: |
119 |
|
|
case CutIn::Movable: |
120 |
|
|
case CutIn::MovableClose: |
121 |
|
|
x = (screenWidth - width) / 2; |
122 |
|
|
break; |
123 |
|
|
case CutIn::BottomLeft: |
124 |
|
|
default: |
125 |
|
|
x = padding; |
126 |
|
|
break; |
127 |
|
|
} |
128 |
|
|
setCloseButton(false); |
129 |
|
|
setVisible(Visible_true); |
130 |
|
|
setPosition(x, y); |
131 |
|
|
setCloseButton(showTitle); |
132 |
|
|
setShowTitle(showTitle); |
133 |
|
|
setSize(width, height); |
134 |
|
|
setVisible(Visible_true); |
135 |
|
|
requestMoveToTop(); |
136 |
|
|
} |
137 |
|
|
} |
138 |
|
|
} |
139 |
|
|
|
140 |
|
|
void CutInWindow::hide() |
141 |
|
|
{ |
142 |
|
|
delete2(mImage) |
143 |
|
|
setVisible(Visible_false); |
144 |
|
|
} |
145 |
|
|
|
146 |
|
|
void CutInWindow::logic() |
147 |
|
|
{ |
148 |
|
|
if (mImage != nullptr) |
149 |
|
|
{ |
150 |
|
|
const int time = tick_time * MILLISECONDS_IN_A_TICK; |
151 |
|
|
mImage->update(time); |
152 |
|
|
} |
153 |
|
|
} |