ManaPlus
cutinwindow.cpp
Go to the documentation of this file.
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 
25 
26 #include "configuration.h"
27 
28 #include "const/utils/timer.h"
29 
31 
32 #include "utils/delete2.h"
33 #include "utils/timer.h"
34 
35 #include "debug.h"
36 
38 
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);
51  enableVisibleSound(false);
52 }
53 
55 {
57 }
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)
75 }
76 
77 void CutInWindow::show(const std::string &name,
78  const CutInT cutin)
79 {
81  if (name.empty())
82  {
84  }
85  else
86  {
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)
96  else
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);
130  setPosition(x, y);
131  setCloseButton(showTitle);
132  setShowTitle(showTitle);
133  setSize(width, height);
136  }
137  }
138 }
139 
141 {
142  delete2(mImage)
144 }
145 
147 {
148  if (mImage != nullptr)
149  {
150  const int time = tick_time * MILLISECONDS_IN_A_TICK;
151  mImage->update(time);
152  }
153 }
int getHeight() const
int getWidth() const
static AnimatedSprite * load(const std::string &filename, const int variant)
bool update(const int time)
void drawRaw(Graphics *const graphics, const int posX, const int posY) const
std::string getStringValue(const std::string &key) const
void show(const std::string &name, const CutInT cutin)
Definition: cutinwindow.cpp:77
void draw(Graphics *const graphics)
Definition: cutinwindow.cpp:59
void draw2(Graphics *const graphics)
Definition: cutinwindow.cpp:71
int mOldTitleBarHeight
Definition: cutinwindow.h:57
AnimatedSprite * mImage
Definition: cutinwindow.h:56
void safeDraw(Graphics *const graphics)
Definition: cutinwindow.cpp:65
int mWidth
Definition: graphics.h:484
int mHeight
Definition: graphics.h:485
void setSize(const int width, const int height)
Definition: widget.cpp:367
virtual void requestMoveToTop()
Definition: widget.cpp:213
void setPosition(const int x, const int y)
Definition: widget.cpp:161
Definition: window.h:102
void safeDraw(Graphics *const graphics)
Definition: window.cpp:423
void setSaveVisible(const bool save)
Definition: window.h:300
void setResizable(const bool resize)
Definition: window.cpp:627
virtual void setVisible(Visible visible)
Definition: window.cpp:778
void setWindowName(const std::string &name)
Definition: window.h:355
unsigned int mTitleBarHeight
Definition: window.h:623
void enableVisibleSound(bool b)
Definition: window.h:481
void draw(Graphics *const graphics)
Definition: window.cpp:311
void setShowTitle(bool flag)
Definition: window.h:235
void setCloseButton(const bool flag)
Definition: window.cpp:749
int mPadding
Definition: window.h:618
void setDefaultVisible(const bool save)
Definition: window.h:288
Configuration paths
static const int MILLISECONDS_IN_A_TICK
Definition: timer.h:30
CutIn ::T CutInT
Definition: cutin.h:35
CutInWindow * cutInWindow
Definition: cutinwindow.cpp:37
#define delete2(var)
Definition: delete2.h:25
Graphics * mainGraphics
Definition: graphics.cpp:109
#define nullptr
Definition: localconsts.h:45
volatile int tick_time
Definition: timer.cpp:53
const bool Modal_false
Definition: modal.h:30
@ BottomLeft
Definition: cutin.h:29
@ Movable
Definition: cutin.h:32
@ BottomCenter
Definition: cutin.h:30
@ BottomRight
Definition: cutin.h:31
@ MovableClose
Definition: cutin.h:33
std::string pathJoin(std::string str1, const std::string &str2)
const bool Visible_false
Definition: visible.h:30
const bool Visible_true
Definition: visible.h:30