aboutsummaryrefslogtreecommitdiff
path: root/Src/Wasabi/api/skin/widgets/textbase.cpp
blob: 5fb32e7af646886bae075c9ef2fa6b2ab4a9a26a (plain) (blame)
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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
#include <precomp.h>
#include <api.h>
#include "textbase.h"
#include <api/skin/skinparse.h>
#include <api/skin/skinelem.h>
#include <api/service/svcs/svc_action.h>
#include <api/script/vcpu.h>

#define COLORMODE_RGB 0
#define COLORMODE_SKINCOLOR 1

XMLParamPair TextBase::params[] =
{
	{TEXTBASE_RCLICKPARAM, L"RCLICKPARAM"},
	{TEXTBASE_DBLCLICKPARAM, L"DBLCLICKPARAM"},
	{TEXTBASE_SETALIGN, L"ALIGN"},
	{TEXTBASE_SETALTANTIALIAS, L"ALTANTIALIAS"},
	{TEXTBASE_SETALTBOLD, L"ALTBOLD"},
	{TEXTBASE_SETALTCOLOR, L"ALTCOLOR"},
	{TEXTBASE_SETALTFONT, L"ALTFONT"},
	{TEXTBASE_SETALTFONTSIZE, L"ALTFONTSIZE"},
	{TEXTBASE_SETALTITALIC, L"ALTITALIC"},
	{TEXTBASE_SETANTIALIAS, L"ANTIALIAS"},
	{TEXTBASE_SETBOLD, L"BOLD"},
	{TEXTBASE_SETCOLOR, L"COLOR"},
	{TEXTBASE_SETDBLCLKACTION, L"DBLCLICKACTION"},
	{TEXTBASE_SETFONT, L"FONT"},
	{TEXTBASE_SETFONTSIZE, L"FONTSIZE"},
	{TEXTBASE_SETITALIC, L"ITALIC"},
	{TEXTBASE_SETLPADDING, L"LEFTPADDING"},
	{TEXTBASE_SETRCLKACTION, L"RIGHTCLICKACTION"},
	{TEXTBASE_SETRPADDING, L"RIGHTPADDING"},
};

TextBase::TextBase()
{
	color[0].setColorGroup(L"Text");
	color[1].setColorGroup(L"Text");
	color[0].setColor(RGB(255, 255, 255));
	color[1].setColor(RGB(255, 255, 255));

	color_mode[0] = COLORMODE_RGB;
	color_mode[1] = COLORMODE_RGB;

	fontsize[0] = fontsize[1] = 14;

	font[0] = wasabi_default_fontnameW;
	font[1] = wasabi_default_fontnameW;

	bold[0] = 0;
	bold[1] = 0;

	italic[0] = 0;
	italic[1] = 0;

	antialias[0] = 1;
	antialias[1] = 1;

	align = ALIGN_LEFT;

	lpadding = rpadding = 0;

	grab = 0;

	/* register XML parameters */
	xuihandle = newXuiHandle();
	CreateXMLParameters(xuihandle);	
}

void TextBase::CreateXMLParameters(int master_handle)
{
	//TEXTBASE_PARENT::CreateXMLParameters(master_handle);
	int numParams = sizeof(params) / sizeof(params[0]);
	hintNumberOfParams(xuihandle, numParams);
	for (int i = 0;i < numParams;i++)
		addParam(xuihandle, params[i], XUI_ATTRIBUTE_IMPLIED);
}

TextBase::~TextBase()
{
	WASABI_API_SYSCB->syscb_deregisterCallback(static_cast<SkinCallbackI*>(this));
}

int TextBase::onInit()
{
	TEXTBASE_PARENT::onInit();
	WASABI_API_SYSCB->syscb_registerCallback(static_cast<SkinCallbackI*>(this));
	return 1;
}

int TextBase::skincb_onColorThemeChanged(const wchar_t *newcolortheme)
{
	invalidateTextBuffer();
	return 0;
}


ARGB32 TextBase::GetColor(int alt)
{
	if (alt < 0 || alt > 1) alt = 0;
	if (color_mode[alt] == COLORMODE_SKINCOLOR)
		return scolor[alt];
	return color[alt].getColor();
}

void TextBase::SetTextColor(ARGB32 c, int alt)
{
	if (alt < 0 || alt > 1) alt = 0;
	color_mode[alt] = COLORMODE_RGB;
	color[alt].setColor(c);
	invalidateTextBuffer();
	if (alt == 0) SetTextColor(c, 1);
}

void TextBase::SetFontSize(const wchar_t *strvalue, int alt)
{
	if (alt < 0 || alt > 1) alt = 0;
	if (!strvalue || !*strvalue) return ;
	if (*strvalue == '+')
		fontsize[alt] += WTOI(strvalue + 1);
	else if (*strvalue == '-')
		fontsize[alt] -= WTOI(strvalue + 1);
	else if (*strvalue == '*')
		fontsize[alt] *= WTOI(strvalue + 1);
	else if (*strvalue == '/')
		fontsize[alt] /= WTOI(strvalue + 1);
	else
		fontsize[alt] = WTOI(strvalue);
	invalidateTextBuffer();
	if (alt == 0) SetFontSize(strvalue, 1);
}

void TextBase::GetFontInfo(Wasabi::FontInfo *_font, int alt)
{
	_font->opaque=false;
	_font->color = GetColor(alt);
	_font->pointSize = fontsize[alt];
	_font->face = font[alt];
	_font->bold = bold[alt];
	_font->italic = !!italic[alt];
	_font->antialias = antialias[alt];
	_font->alignFlags = align;
}

void TextBase::SetFont(const wchar_t *name, int alt)
{
	if (alt < 0 || alt > 1) alt = 0;
	font[alt] = name;
	invalidateTextBuffer();
	if (alt == 0) SetFont(name, 1);
}

void TextBase::SetAntialias(int a, int alt)
{
	antialias[alt] = a;
	if (alt==0)
		antialias[1] = antialias[0];
	invalidateTextBuffer();
}

void TextBase::SetFontAlign(int al)
{
	align = al;
	invalidateTextBuffer();

}

int TextBase::setXuiParam(int _xuihandle, int attrid, const wchar_t *name, const wchar_t *strval)
{
	if (xuihandle != _xuihandle) return TEXTBASE_PARENT::setXuiParam(_xuihandle, attrid, name, strval);
	switch (attrid)
	{
	case TEXTBASE_SETCOLOR:
		if (WASABI_API_PALETTE->getColorElementRef(strval))
		{
			color_mode[0] = COLORMODE_SKINCOLOR;
			scolor[0] = strval;
			color_mode[1] = COLORMODE_SKINCOLOR;
			scolor[1] = strval;
		}
		else
			SetTextColor(SkinParser::parseColor(strval), 0);
		break;

	case TEXTBASE_SETALTCOLOR:
		if (WASABI_API_PALETTE->getColorElementRef(strval))
		{
			color_mode[1] = COLORMODE_SKINCOLOR;
			scolor[1] = strval;
		}
		else
			SetTextColor(SkinParser::parseColor(strval), 1);
		break;

	case TEXTBASE_SETFONTSIZE:
		SetFontSize(strval);
		break;

	case TEXTBASE_SETFONT:
		SetFont(strval);
		break;

	case TEXTBASE_SETALTFONT:
		SetFont(strval, 1);
		break;

	case TEXTBASE_SETALTFONTSIZE:
		SetFontSize(strval, 1);
		break;

	case TEXTBASE_SETBOLD:
		bold[0] = WTOI(strval);
		bold[1] = bold[0];
		break;

	case TEXTBASE_SETALTBOLD:
		bold[1] = WTOI(strval);
		break;

	case TEXTBASE_SETITALIC:
		italic[0] = WTOI(strval);
		italic[1] = italic[0];
		break;

	case TEXTBASE_SETALTITALIC:
		italic[1] = WTOI(strval);
		break;

	case TEXTBASE_SETANTIALIAS:
		SetAntialias(WTOI(strval));
		invalidateTextBuffer();
		break;

	case TEXTBASE_SETALTANTIALIAS:
		SetAntialias(WTOI(strval), 1);
		invalidateTextBuffer();
		break;

	case TEXTBASE_SETDBLCLKACTION:
		dblClickAction = strval;
		break;

	case TEXTBASE_DBLCLICKPARAM:
		setDblClickParam(strval);
		break;

	case TEXTBASE_RCLICKPARAM:
		setRClickParam(strval);
		break;

	case TEXTBASE_SETRCLKACTION:
		rClickAction = strval;
		break;

	case TEXTBASE_SETALIGN:
		SetFontAlign(SkinParser::getAlign(strval));
		break;

	case TEXTBASE_SETLPADDING:
		lpadding = WTOI(strval);
		break;
	case TEXTBASE_SETRPADDING:
		rpadding = WTOI(strval);
		break;


	default:
		return 0;
	}
	return 1;
}

void TextBase::setDblClickParam(const wchar_t *p) 
{
	dblclickparam=p;
}

const wchar_t *TextBase::getDblClickParam() 
{
	return dblclickparam;
}

void TextBase::setRClickParam(const wchar_t *p) 
{
	rclickparam=p;
}

const wchar_t *TextBase::getRClickParam() 
{
	return rclickparam;
}

int TextBase::onLeftButtonDblClk(int x, int y)
{
	TEXTBASE_PARENT::onLeftButtonDblClk(x, y);
	int r = 1;
	grab = 0;
	if (!dblClickAction.isempty() && !VCPU::getComplete())
	{
#ifdef WASABI_COMPILE_WNDMGR
		const wchar_t *toCheck = L"SWITCH;";
		if (!_wcsnicmp(dblClickAction, toCheck, 7))
		{
			onLeftButtonUp(x, y);
			getGuiObject()->guiobject_getParentGroup()->getParentContainer()->switchToLayout(dblClickAction.getValue() + 7);
		}
		else
		{
#endif
			svc_action *act = ActionEnum(dblClickAction).getNext();
			if (act)
			{
				int _x = x;
				int _y = y;
				clientToScreen(&_x, &_y);
				act->onAction(dblClickAction, getDblClickParam(), _x, _y, NULL, 0, this);
				SvcEnum::release(act);
			}
#ifdef WASABI_COMPILE_WNDMGR

		}
#endif

	}
	return r;
}


int TextBase::onRightButtonDown(int x, int y)
{
	TEXTBASE_PARENT::onRightButtonDown(x, y);
	if (!rClickAction.isempty())
	{
		svc_action *act = ActionEnum(rClickAction).getNext();
		if (act)
		{
			int _x = x;
			int _y = y;
			clientToScreen(&_x, &_y);
			act->onAction(rClickAction, getRClickParam(), _x, _y, NULL, 0, this);
			SvcEnum::release(act);
		}
	}
	return 1;
}