forked from OpenXcom/OpenXcom
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFrame.cpp
More file actions
148 lines (133 loc) · 2.9 KB
/
Copy pathFrame.cpp
File metadata and controls
148 lines (133 loc) · 2.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/*
* Copyright 2010-2013 OpenXcom Developers.
*
* This file is part of OpenXcom.
*
* OpenXcom is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* OpenXcom is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenXcom. If not, see <http://www.gnu.org/licenses/>.
*/
#include "Frame.h"
namespace OpenXcom
{
/**
* Sets up a blank frame with the specified size and position.
* @param state Pointer to state the frame belongs to.
* @param width Width in pixels.
* @param height Height in pixels.
* @param x X position in pixels.
* @param y Y position in pixels.
* @param popup Popup animation.
*/
Frame::Frame(int width, int height, int x, int y) : Surface(width, height, x, y), _color(0), _bg(0), _thickness(5), _contrast(false)
{
}
/**
*
*/
Frame::~Frame()
{
}
/**
* Changes the color used to draw the shaded border.
* @param color Color value.
*/
void Frame::setColor(Uint8 color)
{
_color = color;
_redraw = true;
}
/**
* Returns the color used to draw the shaded border.
* @return Color value.
*/
Uint8 Frame::getColor() const
{
return _color;
}
/**
* Changes the color used to draw the background.
* @param bg Color value.
*/
void Frame::setBackground(Uint8 bg)
{
_bg = bg;
_redraw = true;
}
/**
* Returns the color used to draw the background.
* @return Color value.
*/
Uint8 Frame::getBackground() const
{
return _bg;
}
/**
* Enables/disables high contrast color. Mostly used for
* Battlescape UI.
* @param contrast High contrast setting.
*/
void Frame::setHighContrast(bool contrast)
{
_contrast = contrast;
_redraw = true;
}
/**
* Changes the thickness of the border to draw.
* @param thickness Thickness in pixels.
*/
void Frame::setThickness(int thickness)
{
_thickness = thickness;
_redraw = true;
}
/**
* Draws the bordered frame with a graphic background.
* The background never moves with the frame, it's
* always aligned to the top-left corner of the screen
* and cropped to fit the inside area.
*/
void Frame::draw()
{
Surface::draw();
SDL_Rect square;
square.x = 0;
square.w = getWidth();
square.y = 0;
square.h = getHeight();
int mul = 1;
if (_contrast)
{
mul = 2;
}
Uint8 color = _color + 3 * mul;
for (int i = 0; i < _thickness; ++i)
{
drawRect(&square, color);
if (i < _thickness / 2)
color -= 1 * mul;
else
color += 1 * mul;
square.x++;
square.y++;
if (square.w >= 2)
square.w -= 2;
else
square.w = 1;
if (square.h >= 2)
square.h -= 2;
else
square.h = 1;
}
drawRect(&square, _bg);
}
}