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
|
#include "precomp.h"
#include "textbar.h"
#include <bfc/ifc_canvas.h>
#include <bfc/string/string.h>
#include <bfc/skinclr.h>
#include <bfc/autobitmap.h>
#include <common/checkwnd.h>
static SkinColor bgcolor("wasabi.textBar.background", "Text backgrounds");
static SkinColor fgcolor("wasabi.textBar.text");
TextBar::TextBar() {
size = 16;
usebt = 0;
alignment = TEXTALIGN_LEFT; //set default alignment
checkwndtarget = NULL;
textshadowed = 1; // display a shadow of the text in bgcolor. default: on
textoutlined = 0; // draw an outline of the text in bgcolor. default: off
drawbox = 0; // draw a box of bgcolor the size of the boundsrect. default: off
// bgbitmap = "studio.textBar.background";
}
int TextBar::onLeftButtonDown(int x, int y) {
TEXTBAR_PARENT::onLeftButtonDown(x, y);
if (checkwndtarget) checkwndtarget->toggle();
return 1;
}
void TextBar::setUseBaseTexture(int u) {
usebt = u;
invalidate();
}
int TextBar::onPaint(Canvas *canvas) {
RECT r;
PaintCanvas paintcanvas;
if (canvas == NULL) {
if (!paintcanvas.beginPaint(this)) return 0;
canvas = &paintcanvas;
}
TEXTBAR_PARENT::onPaint(canvas);
getClientRect(&r);
if (!usebt) {
if (drawbox) {
canvas->fillRect(&r, bgcolor);
}
/*
if (bgbitmap.getBitmap()->isInvalid())
canvas->fillRect(&r, bgcolor);
else {
RECT br;
br.left = 0;
br.top = 0;
br.right = bgbitmap.getWidth();
br.bottom = bgbitmap.getHeight();
bgbitmap.getBitmap()->blitToRect(canvas, &br, &r, 255);
}
*/
} else
renderBaseTexture(canvas, r);
const char *name = getName();
if (name != NULL) {
canvas->setTextOpaque(FALSE);
canvas->pushTextSize(size);
int w, h;
canvas->getTextExtent(name, &w, &h);
int y = (r.bottom-r.top - h) / 2;
// int x = centered ? (r.right-r.left - w) / 2 : TEXTBAR_LEFTMARGIN; //teh old code
int x = 0;
switch (alignment) {
default:
case TEXTALIGN_LEFT: x = TEXTBAR_LEFTMARGIN; break;
case TEXTALIGN_CENTER: x = (r.right-r.left - w) / 2; break;
case TEXTALIGN_RIGHT: x = (r.right-r.left - w); break;
}
if (!drawbox && textoutlined) {
canvas->setTextColor(bgcolor);
canvas->textOut(r.left+x+1, r.top+y+1, getName());
canvas->setTextColor(bgcolor);
canvas->textOut(r.left+x+1, r.top+y-1, getName());
canvas->setTextColor(bgcolor);
canvas->textOut(r.left+x-1, r.top+y+1, getName());
canvas->setTextColor(bgcolor);
canvas->textOut(r.left+x-1, r.top+y-1, getName());
} else if (!drawbox && textshadowed) {
canvas->setTextColor(bgcolor);
canvas->textOut(r.left+x+1, r.top+y+1, getName());
}
canvas->setTextColor(fgcolor);
canvas->textOut(r.left+x, r.top+y, getName());
canvas->popTextSize();
}
return 1;
}
int TextBar::setTextSize(int newsize) {
if (newsize < 1 || newsize > 72) return 0;
size = newsize;
invalidate();
return 1;
}
int TextBar::setInt(int i) {
setName(StringPrintf(i));
invalidate();
return 1;
}
void TextBar::onSetName() {
TEXTBAR_PARENT::onSetName();
invalidate();
}
int TextBar::getTextWidth() {
if (!getName()) return 0;
BltCanvas *c = new BltCanvas(10, 10);
c->pushTextSize(size);
int r = c->getTextWidth(getName());
c->popTextSize();
delete c;
return r+4;
}
int TextBar::getTextHeight() {
return size;
}
void TextBar::setAlign(TextAlign align) {
if (alignment != align) {
alignment = align;
invalidate();
}
}
TextAlign TextBar::getAlign() {
return alignment;
}
|