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
CutInWindow()39 CutInWindow::CutInWindow() :
40 Window("", Modal_false, nullptr, "cutin.xml"),
41 mImage(nullptr),
42 mOldTitleBarHeight(mTitleBarHeight)
43 {
44 setWindowName("CutIn");
45
46 setShowTitle(false);
47 setResizable(false);
48 setDefaultVisible(false);
49 setSaveVisible(false);
50 setVisible(Visible_false);
51 enableVisibleSound(false);
52 }
53
~CutInWindow()54 CutInWindow::~CutInWindow()
55 {
56 delete2(mImage)
57 }
58
draw(Graphics * const graphics)59 void CutInWindow::draw(Graphics *const graphics)
60 {
61 Window::draw(graphics);
62 draw2(graphics);
63 }
64
safeDraw(Graphics * const graphics)65 void CutInWindow::safeDraw(Graphics *const graphics)
66 {
67 Window::safeDraw(graphics);
68 draw2(graphics);
69 }
70
draw2(Graphics * const graphics)71 void CutInWindow::draw2(Graphics *const graphics)
72 {
73 if (mImage != nullptr)
74 mImage->drawRaw(graphics, mPadding, mTitleBarHeight);
75 }
76
show(const std::string & name,const CutInT cutin)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
hide()140 void CutInWindow::hide()
141 {
142 delete2(mImage)
143 setVisible(Visible_false);
144 }
145
logic()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 }
154