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
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
|
#include <precomp.h>
#include "wa2songticker.h"
#include <api.h>
#include <tataki/color/skinclr.h>
#include <api/core/api_core.h>
#include <api/application/api_application.h>
#include <wasabicfg.h>
#include "wa2frontend.h"
#include <api/skin/skinelem.h>
#include <api/skin/skinparse.h>
#include <api/config/items/attribs.h>
#include <api/config/api_config.h>
// {9149C445-3C30-4e04-8433-5A518ED0FDDE}
static const GUID uioptions_guid =
{ 0x9149c445, 0x3c30, 0x4e04, { 0x84, 0x33, 0x5a, 0x51, 0x8e, 0xd0, 0xfd, 0xde } };
// {280876CF-48C0-40bc-8E86-73CE6BB462E5}
static const GUID options_guid =
{ 0x280876cf, 0x48c0, 0x40bc, { 0x8e, 0x86, 0x73, 0xce, 0x6b, 0xb4, 0x62, 0xe5 } };
const wchar_t songtickerXuiObjectStr[] = L"SongTicker"; // This is the xml tag
char songtickerXuiSvcName[] = "Song Ticker XUI object"; // this is the name of the xuiservice
BEGIN_SERVICES(wa2SongTicker_Svcs);
DECLARE_SERVICE(XuiObjectCreator<SongTickerXuiSvc>);
END_SERVICES(wa2SongTicker_Svcs, _wa2SongTicker_Svcs);
#ifdef _X86_
extern "C"
{
int _link_wa2SongTicker_Svcs;
}
#else
extern "C"
{
int __link_wa2SongTicker_Svcs;
}
#endif
extern _float cfg_uioptions_textspeed;
extern _int cfg_uioptions_textincrement;
#define TIMER_SONGTICKER_SCROLL 0x777
//#define SONGTICKER_SCROLL_MS 200 // TODO: make adjustable (api_config, xml param, maki script object)
#define SONGTICKER_INCREMENT_PIXELS (cfg_uioptions_textincrement) // TODO: make adjustable?
#define SONGTICKER_SCROLL_MS ((13.0f*(float)cfg_uioptions_textincrement)/cfg_uioptions_textspeed)
#define SONGTICKER_SCROLL_ONE_PIXEL_MS (13.0f/cfg_uioptions_textspeed)
#define SONGTICKER_SKIP_MS 2000 // TODO: make adjustable
XMLParamPair SongTicker::params[] =
{
{SONGTICKER_TICKER, L"TICKER"},
};
SongTicker::SongTicker()
{
WASABI_API_MEDIACORE->core_addCallback(0, this);
song_title[0]=0;
song_length=-1;
position=0;
tickerMode=TICKER_SCROLL;
ticker_direction=1;
skipTimers=0;
grab_x = 0;
last_tick = Wasabi::Std::getTickCount();
buffer_hw_valid=false;
textW=0;
/* register XML parameters */
xuihandle = newXuiHandle();
CreateXMLParameters(xuihandle);
CfgItem *ci=WASABI_API_CONFIG->config_getCfgItemByGuid(uioptions_guid);
if (ci)
{
viewer_addViewItem(ci->getDependencyPtr());
}
ci=WASABI_API_CONFIG->config_getCfgItemByGuid(options_guid);
if (ci)
{
viewer_addViewItem(ci->getDependencyPtr());
}
}
void SongTicker::CreateXMLParameters(int master_handle)
{
//SONGTICKER_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);
}
SongTicker::~SongTicker()
{
WASABI_API_MEDIACORE->core_delCallback(0, this);
// TODO: benski> is this the right place for this?
killTimer(TIMER_SONGTICKER_SCROLL);
}
int SongTicker::onResize()
{
killTimer(TIMER_SONGTICKER_SCROLL);
buffer_hw_valid=false;
invalidateBuffer();
return SONGTICKER_PARENT::onResize();
}
int SongTicker::onInit()
{
int r = SONGTICKER_PARENT::onInit();
BuildTitle();
return r;
}
int SongTicker::corecb_onTitleChange(const wchar_t *title)
{
BuildTitle();
return 1;
}
int SongTicker::corecb_onLengthChange(int newlength)
{
song_length = newlength;
return 1;
}
void SongTicker::BuildTitle()
{
killTimer(TIMER_SONGTICKER_SCROLL);
const wchar_t *curFilename = wa2.GetCurrentFile();
if (curFilename && *curFilename)
{
wa2.GetFileInfo(curFilename, song_title, 1024, &song_length);
WASABI_API_MEDIACORE->core_setTitle(song_title);
}
else
{
song_title[0]=0;
song_length=-1;
}
if (!song_title[0] || ((unsigned long)song_title < 65536))
{
display = WASABI_API_APP->main_getVersionString();
}
else
{
// TODO: use TimeFmt:: to format the time
if (song_length >= 0)
display.printf(L"%s (%d:%02d)",song_title,song_length/60,song_length%60);
else
display.printf(L"%s",song_title);
}
rotatingDisplay.printf(L"%s *** %s", display, display);
TextInfoCanvas c(this);
Wasabi::FontInfo fontInfo;
GetFontInfo(&fontInfo);
width_of_str_padded = c.getTextWidth(display, &fontInfo) + lpadding - rpadding;
width_of_str = c.getTextWidth(rotatingDisplay, &fontInfo) - c.getTextWidth(display, &fontInfo);
buffer_hw_valid=false;
invalidateBuffer();
}
int SongTicker::onBufferPaint(BltCanvas *canvas, int w, int h)
{
SONGTICKER_PARENT::onBufferPaint(canvas, w, h);
// TODO: benski> need to optimize this :)
RECT r = {0,0,w,h};
canvas->fillRect(&r, RGB(0, 0, 0));
getClientRect(&r);
Wasabi::FontInfo fontInfo;
GetFontInfo(&fontInfo);
/*
if (tickerMode == TICKER_OFF)
{
lpadding=min(lpadding, w);
w=max(w-lpadding+rpadding, 0);
canvas->textOut(lpadding, 0, w, h, display, &fontInfo);
return 1;
}
*/
const int textAreaWidth = r.right - r.left;
StringW *whichString = &display;
if (width_of_str_padded > textAreaWidth) // too big to fit?
{
switch (tickerMode)
{
case TICKER_OFF:
{
int extra = width_of_str_padded - textAreaWidth;
if (position>extra)
position=extra;
if (position<0)
position=0;
}
break;
case TICKER_SCROLL:
{
// make sure our position isn't out of bounds
while (position < 0)
position += width_of_str;
position %= (width_of_str);
whichString = &rotatingDisplay;
skipTimers=0;
setTimer(TIMER_SONGTICKER_SCROLL, (int)SONGTICKER_SCROLL_MS);
}
break;
case TICKER_BOUNCE:
{
int extra = width_of_str_padded- textAreaWidth;
if (position < 0)
{
position=0;
ticker_direction=1;
skipTimers=(int)(SONGTICKER_SKIP_MS/SONGTICKER_SCROLL_MS);
}
if (position>=extra)
{
position=extra-1;
ticker_direction=-1;
skipTimers=(int)(SONGTICKER_SKIP_MS/SONGTICKER_SCROLL_MS);
}
if (position < 0)
position=0;
setTimer(TIMER_SONGTICKER_SCROLL, (int)SONGTICKER_SCROLL_MS);
}
break;
}
}
else // if there's enough room, just draw the string as-is
{
position=0;
}
int x =min(lpadding, w);
w=max(w-x+rpadding, 0);
canvas->textOut(lpadding, 0, w, h, whichString->getValueSafe(), &fontInfo);
return 1;
}
void SongTicker::timerCallback(int id)
{
if (id == TIMER_SONGTICKER_SCROLL && !grab)
{
uint32_t this_tick = Wasabi::Std::getTickCount();
if (TICKER_OFF == tickerMode)
{
killTimer(TIMER_SONGTICKER_SCROLL);
return;
}
if (skipTimers)
{
last_tick=this_tick;
skipTimers--;
return;
}
int numTicks=SONGTICKER_INCREMENT_PIXELS;
if (this_tick > last_tick) // make sure we havn't wrapped around
{
numTicks = (int)((this_tick - last_tick) / SONGTICKER_SCROLL_ONE_PIXEL_MS);
last_tick += (uint32_t)(numTicks * SONGTICKER_SCROLL_ONE_PIXEL_MS); // we do this instead of last_tick = this_tick, so we get some error shaping
}
else
last_tick=this_tick;
// move the ticker
position+=(ticker_direction*numTicks);
// ask to be redrawn
if (numTicks)
invalidate();
}
else
SONGTICKER_PARENT::timerCallback(id);
}
void SongTicker::getBufferPaintSource(RECT *r)
{
if (r)
{
RECT cr;
getClientRect(&cr);
const int textAreaWidth = cr.right - cr.left;
if (width_of_str_padded > textAreaWidth) // too big to fit?
{
switch (tickerMode)
{
case TICKER_OFF:
{
int extra = width_of_str_padded- textAreaWidth;
if (position>extra)
position=extra;
if (position<0)
position=0;
}
break;
case TICKER_SCROLL:
{
// make sure our position isn't out of bounds
while (position < 0)
position += width_of_str;
position %= (width_of_str);
}
break;
case TICKER_BOUNCE:
{
int extra = width_of_str_padded - textAreaWidth;
if (position>=extra)
{
position=extra-1;
ticker_direction=-1;
skipTimers=(int)(SONGTICKER_SKIP_MS/SONGTICKER_SCROLL_MS);
}
if (position < 0)
{
position=0;
ticker_direction=1;
skipTimers=(int)(SONGTICKER_SKIP_MS/SONGTICKER_SCROLL_MS);
}
}
break;
}
}
else
{
position=0;
}
r->left = position;
r->right = cr.right - cr.left + position;
r->top = 0;
r->bottom = cr.bottom - cr.top;
}
}
void SongTicker::getBufferPaintSize(int *w, int *h)
{
RECT r;
getClientRect(&r);
int _w = r.right - r.left;
int _h = r.bottom - r.top;
if (!buffer_hw_valid)
{
const int textAreaWidth = r.right - r.left;
StringW *whichString = &display;
if (width_of_str_padded > textAreaWidth && tickerMode == TICKER_SCROLL) // too big to fit?
{
whichString = &rotatingDisplay;
buffer_hw_valid=false;
}
TextInfoCanvas canvas(this);
Wasabi::FontInfo fontInfo;
GetFontInfo(&fontInfo);
textW = canvas.getTextWidth(whichString->getValueSafe(), &fontInfo);
//int textH = canvas.getTextHeight(whichString->getValueSafe(), &fontInfo);
textW = textW + lpadding - rpadding;
buffer_hw_valid=true;
}
*w = max(_w, textW);
*h = _h;//max(_h, textH);
}
int SongTicker::setXuiParam(int _xuihandle, int attrid, const wchar_t *name, const wchar_t *strval)
{
if (xuihandle != _xuihandle) return SONGTICKER_PARENT::setXuiParam(_xuihandle, attrid, name, strval);
switch (attrid)
{
case SONGTICKER_TICKER:
if (!WCSICMP(strval, L"bounce"))
tickerMode=TICKER_BOUNCE;
else if (!WCSICMP(strval, L"scroll"))
{
tickerMode=TICKER_SCROLL;
ticker_direction=1;
}
else if (!WCSICMP(strval, L"off"))
{
tickerMode=TICKER_OFF;
position=0;
killTimer(TIMER_SONGTICKER_SCROLL);
}
buffer_hw_valid=false;
invalidateBuffer();
break;
default:
return 0;
}
return 1;
}
int SongTicker::onAction(const wchar_t *action, const wchar_t *param, int x, int y, intptr_t p1, intptr_t p2, void *data, size_t datalen, ifc_window *source)
{
int r = SONGTICKER_PARENT::onAction(action, param, x, y, p1, p2, data, datalen, source);
if(!WCSICMP(action, L"rebuildtitle"))
BuildTitle();
return r;
}
int SongTicker::viewer_onEvent(api_dependent *item, const GUID *classguid, int event, intptr_t param, void *ptr, size_t ptrlen)
{
if (*classguid == *CfgItem::depend_getClassGuid())
{
if (event==CfgItem::Event_ATTRIBUTE_CHANGED)
{
CfgItem *ci = (CfgItem *)item->dependent_getInterface(CfgItem::depend_getClassGuid());
if (ci->getGuid() == uioptions_guid
&& ptr && (WCSCASEEQLSAFE((const wchar_t *)ptr, L"Text Ticker Speed") || WCSCASEEQLSAFE((const wchar_t *)ptr, L"Text Ticker Increment")))
{
BuildTitle();
}
}
}
return 1;
}
int SongTicker::onLeftButtonDown(int x, int y)
{
if (!SONGTICKER_PARENT::onLeftButtonDown(x, y))
{
grab = 0;
return 0;
}
grab = 1;
grab_x = x + position;
// onMouseMove(x,y);
return 1;
}
int SongTicker::onMouseMove(int x, int y)
{
if (!SONGTICKER_PARENT::onMouseMove(x, y))
{
grab = 0;
}
//POINT pos = {x, y};
//clientToScreen(&pos);
if (!grab) return 1;
position = grab_x - x;
// this forces us to calculate wraparound for position
RECT dummy;
getBufferPaintSource(&dummy);
invalidate();
return 1;
}
int SongTicker::onLeftButtonUp(int x, int y)
{
if (!SONGTICKER_PARENT::onLeftButtonUp(x, y))
{
grab = 0;
return 0;
}
grab = 0;
return 1;
}
|