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
|
#include <precomp.h>
#include "xuiprogressgrid.h"
#include <tataki/canvas/ifc_canvas.h>
#include <bfc/string/stringdict.h>
#include <api/core/api_core.h>
#define ProgressGrid_TIMER_POS 1
#define PROGRESSGRID_INTERVAL 500
#ifndef _WASABIRUNTIME
BEGIN_SERVICES(ProgressGrid_Svc);
DECLARE_SERVICE(XuiObjectCreator<ProgressGridXuiSvc>);
END_SERVICES(ProgressGrid_Svc, _ProgressGrid_Svc);
#ifdef _X86_
extern "C" { int _link_ProgressGridXuiSvc; }
#else
extern "C" { int __link_ProgressGridXuiSvc; }
#endif
#endif
BEGIN_STRINGDICTIONARY(_pgorientationvalues)
SDI(L"top", PROGRESSGRID_TOP);
SDI(L"left", PROGRESSGRID_LEFT);
SDI(L"right", PROGRESSGRID_RIGHT);
SDI(L"bottom", PROGRESSGRID_BOTTOM);
END_STRINGDICTIONARY(_pgorientationvalues, pgorientationvalues)
// -----------------------------------------------------------------------
const wchar_t ProgressGridXuiObjectStr[] = L"ProgressGrid"; // xml tag
char ProgressGridXuiSvcName[] = "ProgressGrid xui object";
XMLParamPair ProgressGrid::params[] = {
{ PROGRESSGRID_SETORIENTATION, L"ORIENTATION"},
{ PROGRESSGRID_SETINTERVAL, L"INTERVAL"},
};
// -----------------------------------------------------------------------
ProgressGrid::ProgressGrid() {
myxuihandle = newXuiHandle();
CreateXMLParameters(myxuihandle);
orientation = PROGRESSGRID_RIGHT;
progress = 0;
started = 0;
update_interval = PROGRESSGRID_INTERVAL;
}
void ProgressGrid::CreateXMLParameters(int master_handle)
{
//PROGRESSGRID_PARENT::CreateXMLParameters(master_handle);
int numParams = sizeof(params) / sizeof(params[0]);
hintNumberOfParams(myxuihandle, numParams);
for (int i = 0;i < numParams;i++)
addParam(myxuihandle, params[i], XUI_ATTRIBUTE_IMPLIED);
}
// -----------------------------------------------------------------------
ProgressGrid::~ProgressGrid() {
killTimer(ProgressGrid_TIMER_POS);
WASABI_API_MEDIACORE->core_delCallback(0, this);
}
// -----------------------------------------------------------------------
int ProgressGrid::setXuiParam(int xuihandle, int xmlattributeid, const wchar_t *xmlattributename, const wchar_t *value) {
if (xuihandle != myxuihandle)
return PROGRESSGRID_PARENT::setXuiParam(xuihandle, xmlattributeid, xmlattributename, value);
switch (xmlattributeid) {
case PROGRESSGRID_SETORIENTATION:
setOrientation(value);
break;
case PROGRESSGRID_SETINTERVAL:
if ((update_interval = WTOI(value)) <= 20)
update_interval = PROGRESSGRID_INTERVAL;
break;
default:
return 0;
}
return 1;
}
// -----------------------------------------------------------------------
void ProgressGrid::setOrientation(const wchar_t *or) {
int a = pgorientationvalues.getId(or);
if (orientation == a) return;
orientation = a;
invalidate();
}
// -----------------------------------------------------------------------
void ProgressGrid::getGridRect(RECT *r) {
RECT cr;
getClientRect(&cr);
float p = started ? progress : 0.0f;
int height = (int)((float)(cr.bottom - cr.top) * p);
int width = (int)((float)(cr.right - cr.left) * p);
switch (orientation) {
case PROGRESSGRID_LEFT: cr.left = cr.right - width; break;
case PROGRESSGRID_TOP: cr.top = cr.bottom - height; break;
case PROGRESSGRID_RIGHT: cr.right = cr.left + width; break;
case PROGRESSGRID_BOTTOM: cr.bottom = cr.top + height; break;
}
*r = cr;
}
// -----------------------------------------------------------------------
int ProgressGrid::onInit() {
PROGRESSGRID_PARENT::onInit();
timerCallback(ProgressGrid_TIMER_POS);
setTimer(ProgressGrid_TIMER_POS, update_interval);
WASABI_API_MEDIACORE->core_addCallback(0, this);
if (WASABI_API_MEDIACORE->core_getStatus(0) != 0) started = 1; else started = 0;
return 1;
}
// -----------------------------------------------------------------------
int ProgressGrid::corecb_onSeeked(int newpos) {
if(!started) corecb_onStarted();
int len = WASABI_API_MEDIACORE->core_getLength(0);
if (newpos == -1 || len <= 0) setProgress(0);
else setProgress(((float)newpos/(float)len));
return 0;
}
// -----------------------------------------------------------------------
int ProgressGrid::corecb_onStarted() {
started = 1;
invalidate();
return 0;
}
// -----------------------------------------------------------------------
int ProgressGrid::corecb_onStopped() {
started = 0;
progress = 0.0f;
invalidate();
return 0;
}
void ProgressGrid::setProgress(float p) {
if (progress == p) return;
progress = p;
invalidate();
}
void ProgressGrid::timerCallback(int id) {
switch (id) {
case ProgressGrid_TIMER_POS: {
int playpos = WASABI_API_MEDIACORE->core_getPosition(0);
corecb_onSeeked(playpos);
}
break;
default:
PROGRESSGRID_PARENT::timerCallback(id);
}
}
|