GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/gui/windows/cutinwindow.cpp Lines: 13 67 19.4 %
Date: 2017-11-29 Branches: 7 49 14.3 %

Line Branch Exec Source
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-2017  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
23
#include "gui/windows/cutinwindow.h"
24
25
#include "configuration.h"
26
27
#include "const/utils/timer.h"
28
29
#include "resources/sprite/animatedsprite.h"
30
31
#include "utils/delete2.h"
32
#include "utils/timer.h"
33
34
#include "debug.h"
35
36
CutInWindow *cutInWindow = nullptr;
37
38
2
CutInWindow::CutInWindow() :
39
    Window("", Modal_false, nullptr, "cutin.xml"),
40
    mImage(nullptr),
41

14
    mOldTitleBarHeight(mTitleBarHeight)
42
{
43
10
    setWindowName("CutIn");
44
45
4
    setShowTitle(false);
46
2
    setResizable(false);
47
4
    setDefaultVisible(false);
48
4
    setSaveVisible(false);
49
2
    setVisible(Visible_false);
50
4
    enableVisibleSound(false);
51
2
}
52
53
6
CutInWindow::~CutInWindow()
54
{
55
2
    delete2(mImage);
56
4
}
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)
73
        mImage->drawRaw(graphics, mPadding, mTitleBarHeight);
74
}
75
76
void CutInWindow::show(const std::string &name,
77
                       const CutInT cutin)
78
{
79
    delete2(mImage);
80
    if (name.empty())
81
    {
82
        setVisible(Visible_false);
83
    }
84
    else
85
    {
86
        mImage = AnimatedSprite::load(
87
            pathJoin(paths.getStringValue("cutInsDir"),
88
            name).append(
89
            ".xml"));
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
}