jborder.cpp
6.6 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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
/***************************************************************************
* Copyright (C) 2005 by Jeff Ferr *
* root@sat *
* *
* This program 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 2 of the License, or *
* (at your option) any later version. *
* *
* This program 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 this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include "Stdafx.h"
#include "jborder.h"
#include "jcomponent.h"
namespace jgui {
Border::Border():
jcommon::Object()
{
jcommon::Object::SetClassName("jgui::Border");
_is_visible = true;
_border_size = 2;
}
Border::~Border()
{
}
void Border::SetSize(int size)
{
if (size < 0) {
size = 0;
}
_border_size = size;
}
int Border::GetSize()
{
return _border_size;
}
void Border::SetVisible(bool b)
{
if (_is_visible == b) {
return;
}
_is_visible = b;
}
bool Border::IsVisible()
{
return _is_visible;
}
void Border::SetBorderType(jcomponent_border_t t)
{
_border_type = t;
}
jcomponent_border_t Border::GetBorderType()
{
return _border_type;
}
void Border::SetBorderColor(int red, int green, int blue, int alpha)
{
_border_color = Color(red, green, blue, alpha);
}
void Border::SetBorderFocusColor(int red, int green, int blue, int alpha)
{
_focus_border_color = Color(red, green , blue, alpha);
}
void Border::SetBorderColor(const Color &color)
{
_border_color = color;
}
void Border::SetBorderFocusColor(const Color &color)
{
_focus_border_color = color;
}
Color & Border::GetBorderColor()
{
return _border_color;
}
Color & Border::GetBorderFocusColor()
{
return _focus_border_color;
}
void Border::PaintBorderBackground(Component *c, Graphics *g)
{
int x = c->GetX(),
y = c->GetY(),
width = c->GetWidth(),
height = c->GetHeight();
if (_border_type == FLAT_BORDER) {
g->FillRectangle(x, y, width, height);
} else if (_border_type == LINE_BORDER) {
g->FillRectangle(x, y, width, height);
} else if (_border_type == GRADIENT_BORDER) {
g->FillRectangle(x, y, width, height);
} else if (_border_type == ROUND_BORDER) {
g->FillRoundRectangle(x, y, width-1, height-1);
} else if (_border_type == BEVEL_BORDER) {
g->FillBevelRectangle(x, y, width, height);
} else if (_border_type == DOWN_BEVEL_BORDER) {
g->FillBevelRectangle(x, y, width, height);
} else if (_border_type == ETCHED_BORDER) {
g->FillRectangle(x, y, width, height);
} else {
g->FillRectangle(x, y, width, height);
}
}
void Border::PaintBorder(Component *c, Graphics *g)
{
if (c == NULL || g == NULL) {
return;
}
if (_is_visible == false) {
return;
}
int xp = 0,
yp = 0,
wp = c->GetWidth()-1,
hp = c->GetHeight()-1,
size = _border_size;
int dr = _border_color.GetRed(),
dg = _border_color.GetGreen(),
db = _border_color.GetBlue(),
da = _border_color.GetAlpha();
int step = 0x20;
g->SetLineWidth(1);
if (c->HasFocus() == true) {
dr = _focus_border_color.GetRed();
dg = _focus_border_color.GetGreen();
db = _focus_border_color.GetBlue();
da = _focus_border_color.GetAlpha();
}
if (_border_type == FLAT_BORDER) {
g->SetColor(dr, dg, db, da);
for (int i=0; i<size && i<wp && i<hp; i++) {
g->DrawRectangle(xp+i, yp+i, wp-2*i, hp-2*i);
}
} else if (_border_type == LINE_BORDER) {
for (int i=0; i<size && i<wp && i<hp; i++) {
g->SetColor(dr+step, dg+step, db+step);
g->DrawLine(xp+i, yp+i, xp+wp-i, yp+i); //cima
g->SetColor(dr-step, dg-step, db-step);
g->DrawLine(xp+i, yp+hp-i, xp+wp-i, yp+hp-i); //baixo
}
for (int i=0; i<size && i<wp && i<hp; i++) {
g->SetColor(dr+step, dg+step, db+step);
g->DrawLine(xp+i, yp+i, xp+i, yp+hp-i); //esquerda
g->SetColor(dr-step, dg-step, db-step);
g->DrawLine(xp+wp-i, yp+i, xp+wp-i, yp+hp-i); //direita
}
} else if (_border_type == GRADIENT_BORDER) {
for (int i=0; i<size && i<wp && i<hp; i++) {
g->SetColor(dr+step*(size-i), dg+step*(size-i), db+step*(size-i));
g->DrawLine(xp+i, yp+i, xp+wp-i, yp+i); //cima
g->SetColor(dr-step*(size-i), dg-step*(size-i), db-step*(size-i));
g->DrawLine(xp+i, yp+hp-i, xp+wp-i, yp+hp-i); //baixo
}
for (int i=0; i<size && i<wp && i<hp; i++) {
g->SetColor(dr+step*(size-i), dg+step*(size-i), db+step*(size-i));
g->DrawLine(xp+i, yp+i, xp+i, yp+hp-i); //esquerda
g->SetColor(dr-step*(size-i), dg-step*(size-i), db-step*(size-i));
g->DrawLine(xp+wp-i, yp+i, xp+wp-i, yp+hp-i); //direita
}
} else if (_border_type == ROUND_BORDER) {
g->SetColor(dr, dg, db, da);
for (int i=0; i<size && i<wp && i<hp; i++) {
g->DrawRoundRectangle(xp+i, yp+i, wp-2*i, hp-2*i-1);
}
} else if (_border_type == BEVEL_BORDER) {
for (int i=0; i<size && i<wp && i<hp; i++) {
g->SetColor(dr, dg, db, da);
g->DrawBevelRectangle(i, i, c->GetWidth()-2*i, c->GetHeight()-2*i-1);
g->SetColor(0x00, 0x00, 0x00, 0xff);
g->DrawBevelRectangle(i+2, i+2, c->GetWidth()-2*(i+2), c->GetHeight()-2*(i+2)-1);
}
} else if (_border_type == DOWN_BEVEL_BORDER) {
for (int i=0; i<size && i<wp && i<hp; i++) {
g->SetColor(0x00, 0x00, 0x00, 0xff);
g->DrawBevelRectangle(i, i, c->GetWidth()-2*i, c->GetHeight()-2*i-1);
g->SetColor(dr, dg, db, da);
g->DrawBevelRectangle(i+2, i+2, c->GetWidth()-2*(i+2), c->GetHeight()-2*(i+2)-1);
}
} else if (_border_type == ETCHED_BORDER) {
for (int i=0; i<size && i<wp && i<hp; i++) {
g->SetColor(dr+step, dg+step, db+step, da);
g->DrawRectangle(xp+i, yp+i, wp-2*i, hp-2*i);
g->SetColor(0x00, 0x00, 0x00, 0xff);
g->DrawRectangle(xp+(i+2), yp+(i+2), wp-2*(i+2), hp-2*(i+2));
}
}
if (c->IsEnabled() == false) {
g->SetColor(0x00, 0x00, 0x00, 0x80);
g->FillRectangle(0, 0, c->GetWidth(), c->GetHeight());
}
}
}