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-2018 The ManaPlus Developers
6  *
7  * This file is part of The ManaPlus Client.
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <http://www.gnu.org/licenses/>.
21  */
22 
24 
25 #include "configuration.h"
26 
27 #include "const/utils/timer.h"
28 
30 
31 #include "utils/delete2.h"
32 #include "utils/timer.h"
33 
34 #include "debug.h"
35 
37 
39  Window("", Modal_false, nullptr, "cutin.xml"),
40  mImage(nullptr),
41  mOldTitleBarHeight(mTitleBarHeight)
42 {
43  setWindowName("CutIn");
44 
45  setShowTitle(false);
46  setResizable(false);
47  setDefaultVisible(false);
48  setSaveVisible(false);
50  enableVisibleSound(false);
51 }
52 
54 {
55  delete2(mImage);
56 }
57 
58 void CutInWindow::draw(Graphics *const graphics)
59 {
60  Window::draw(graphics);
61  draw2(graphics);
62 }
63 
64 void CutInWindow::safeDraw(Graphics *const graphics)
65 {
66  Window::safeDraw(graphics);
67  draw2(graphics);
68 }
69 
70 void CutInWindow::draw2(Graphics *const graphics)
71 {
72  if (mImage != nullptr)
74 }
75 
76 void CutInWindow::show(const std::string &name,
77  const CutInT cutin)
78 {
79  delete2(mImage);
80  if (name.empty())
81  {
83  }
84  else
85  {
87  pathJoin(paths.getStringValue("cutInsDir"), name).append(".xml"),
88  0);
89  if (mImage != nullptr)
90  {
91  mImage->update(1);
92  const bool showTitle = (cutin == CutIn::MovableClose);
93  if (showTitle)
95  else
97  const int width = mImage->getWidth() + 2 * mPadding;
98  const int height = mImage->getHeight() + mTitleBarHeight
99  + mPadding;
100 
101  const int screenWidth = mainGraphics->mWidth;
102  const int screenHeight = mainGraphics->mHeight;
103 
104  if (width * 2 > screenWidth ||
105  height * 2 > screenHeight)
106  {
107  return;
108  }
109  const int padding = 100;
110  int x = 0;
111  const int y = screenHeight - height - padding;
112  switch (cutin)
113  {
114  case CutIn::BottomRight:
115  x = screenWidth - width - padding;
116  break;
117  case CutIn::BottomCenter:
118  case CutIn::Movable:
119  case CutIn::MovableClose:
120  x = (screenWidth - width) / 2;
121  break;
122  case CutIn::BottomLeft:
123  default:
124  x = padding;
125  break;
126  }
127  setCloseButton(false);
129  setPosition(x, y);
130  setCloseButton(showTitle);
131  setShowTitle(showTitle);
132  setSize(width, height);
135  }
136  }
137 }
138 
140 {
141  delete2(mImage);
143 }
144 
146 {
147  if (mImage != nullptr)
148  {
149  const int time = tick_time * MILLISECONDS_IN_A_TICK;
150  mImage->update(time);
151  }
152 }
void setSize(const int width, const int height)
Definition: widget.cpp:366
std::string getStringValue(const std::string &key) const
void setDefaultVisible(const bool save)
Definition: window.h:287
void show(const std::string &name, const CutInT cutin)
Definition: cutinwindow.cpp:76
volatile int tick_time
Definition: timer.cpp:52
int mPadding
Definition: window.h:617
const bool Visible_true
Definition: visible.h:29
int mOldTitleBarHeight
Definition: cutinwindow.h:56
std::string pathJoin(std::string str1, const std::string &str2)
virtual void requestMoveToTop()
Definition: widget.cpp:212
Definition: window.h:98
int mWidth
Definition: graphics.h:483
void setShowTitle(bool flag)
Definition: window.h:234
#define delete2(var)
Definition: delete2.h:24
static AnimatedSprite * load(const std::string &filename, const int variant)
CutIn ::T CutInT
Definition: cutin.h:34
int getHeight() const
const bool Visible_false
Definition: visible.h:29
void draw(Graphics *const graphics)
Definition: window.cpp:310
#define nullptr
Definition: localconsts.h:44
Graphics * mainGraphics
Definition: graphics.cpp:108
static const int MILLISECONDS_IN_A_TICK
Definition: timer.h:29
void draw(Graphics *const graphics)
Definition: cutinwindow.cpp:58
void setPosition(const int x, const int y)
Definition: widget.cpp:160
void setCloseButton(const bool flag)
Definition: window.cpp:748
void safeDraw(Graphics *const graphics)
Definition: cutinwindow.cpp:64
int mHeight
Definition: graphics.h:484
void drawRaw(Graphics *const graphics, const int posX, const int posY) const
AnimatedSprite * mImage
Definition: cutinwindow.h:55
void enableVisibleSound(bool b)
Definition: window.h:480
void setSaveVisible(const bool save)
Definition: window.h:299
Configuration paths
virtual void setVisible(Visible visible)
Definition: window.cpp:777
int getWidth() const
void setResizable(const bool resize)
Definition: window.cpp:626
void draw2(Graphics *const graphics)
Definition: cutinwindow.cpp:70
bool update(const int time)
unsigned int mTitleBarHeight
Definition: window.h:622
void safeDraw(Graphics *const graphics)
Definition: window.cpp:422
CutInWindow * cutInWindow
Definition: cutinwindow.cpp:36
void setWindowName(const std::string &name)
Definition: window.h:354