GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/gui/windows/cutinwindow.cpp Lines: 13 64 20.3 %
Date: 2018-07-14 Branches: 6 45 13.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-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
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
1
CutInWindow::CutInWindow() :
39
    Window("", Modal_false, nullptr, "cutin.xml"),
40
    mImage(nullptr),
41

7
    mOldTitleBarHeight(mTitleBarHeight)
42
{
43
4
    setWindowName("CutIn");
44
45
2
    setShowTitle(false);
46
1
    setResizable(false);
47
2
    setDefaultVisible(false);
48
2
    setSaveVisible(false);
49
1
    setVisible(Visible_false);
50
2
    enableVisibleSound(false);
51
1
}
52
53
3
CutInWindow::~CutInWindow()
54
{
55
1
    delete2(mImage);
56
2
}
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"), name).append(".xml"),
88
            0);
89
        if (mImage != nullptr)
90
        {
91
            mImage->update(1);
92
            const bool showTitle = (cutin == CutIn::MovableClose);
93
            if (showTitle)
94
                mTitleBarHeight = mOldTitleBarHeight;
95
            else
96
                mTitleBarHeight = mPadding;
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);
128
            setVisible(Visible_true);
129
            setPosition(x, y);
130
            setCloseButton(showTitle);
131
            setShowTitle(showTitle);
132
            setSize(width, height);
133
            setVisible(Visible_true);
134
            requestMoveToTop();
135
        }
136
    }
137
}
138
139
void CutInWindow::hide()
140
{
141
    delete2(mImage);
142
    setVisible(Visible_false);
143
}
144
145
void CutInWindow::logic()
146
{
147
    if (mImage != nullptr)
148
    {
149
        const int time = tick_time * MILLISECONDS_IN_A_TICK;
150
        mImage->update(time);
151
    }
152
}