aboutsummaryrefslogtreecommitdiff
path: root/Src/Wasabi/api/skin/widgets/wa2/xuiwa2slider.cpp
blob: d4799a069b17f220b90ffeed4ac44763fd8cc584 (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
#include <precomp.h>

#include "xuiwa2slider.h"
#include <tataki/canvas/canvas.h>
#include <tataki/bitmap/bitmap.h>
#include <api/core/api_core.h>

#define WA2SLIDER_SEEK_INTERVAL 500

const wchar_t Wa2SliderXuiObjectStr[] = L"images"; // This is the xml tag
char Wa2SliderXuiSvcName[] = "Images XuiObject Service";

XMLParamPair Wa2Slider::params[] =
    {
        {WA2SLIDER_IMAGES, L"IMAGES"},
        {WA2SLIDER_IMAGESSPACING, L"IMAGESSPACING"},
        {WA2SLIDER_SOURCE, L"SOURCE"},
    };

Wa2Slider::Wa2Slider()
		: started(false)
{
	realpos = 0;
	imagesBitmap = 0;
	spacing = 0;
	action = ACT_NONE;

	xuihandle = newXuiHandle();
	CreateXMLParameters(xuihandle);	
}

void Wa2Slider::CreateXMLParameters(int master_handle)
{
	//WA2SLIDER_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);
}

Wa2Slider::~Wa2Slider()
{
	killTimer(Wa2Slider_TIMER_POS);
	WASABI_API_MEDIACORE->core_delCallback(0, this);
	delete(imagesBitmap);
}

int Wa2Slider::setXuiParam(int _xuihandle, int xmlattributeid, const wchar_t *xmlattributename, const wchar_t *value)
{
	if (xuihandle == _xuihandle)
	{
		switch (xmlattributeid)
		{
		case WA2SLIDER_IMAGES: images = value; return 1;
		case WA2SLIDER_IMAGESSPACING: spacing = WTOI(value); return 1;
		case WA2SLIDER_SOURCE:
			if (!_wcsicmp(value, L"volume")) action = ACT_VOLUME;
			if (!_wcsicmp(value, L"balance")) action = ACT_BALANCE;
			if (!_wcsicmp(value, L"seek")) action = ACT_SEEK;
			return 1;
		}
	}
	return WA2SLIDER_PARENT::setXuiParam(_xuihandle, xmlattributeid, xmlattributename, value);
}

int Wa2Slider::onInit()
{
	WA2SLIDER_PARENT::onInit();

	imagesBitmap = new SkinBitmap(images);

	if (action == ACT_VOLUME)
		corecb_onVolumeChange(WASABI_API_MEDIACORE->core_getVolume(0));
	if (action == ACT_BALANCE)
		corecb_onPanChange(WASABI_API_MEDIACORE->core_getPan(0));
	if (action == ACT_SEEK)
	{
		corecb_onSeeked(WASABI_API_MEDIACORE->core_getPosition(0));
		started = (WASABI_API_MEDIACORE->core_getStatus(0) != 0);
		setTimer(Wa2Slider_TIMER_POS, WA2SLIDER_SEEK_INTERVAL);
	}

	WASABI_API_MEDIACORE->core_addCallback(0, this);

	return 0;
}

int Wa2Slider::onPaint(Canvas *canvas)
{
	if (imagesBitmap->getHeight() && spacing)
	{
		RECT r, r2;
		getClientRect(&r2);
		int nb = (imagesBitmap->getHeight() / spacing) - 1;
		int which = 0;
		switch (action)
		{
		case ACT_BALANCE:
			{
				int p = realpos;
				int f = 32768; //FULL/2;
				if (p > f)
				{
					which = (realpos - f) * nb / f;
				}
				else if (p < f)
				{
					which = (f - realpos) * nb / f;
				}
				else which = 0;
			}
			break;
		case ACT_SEEK:
			if (!started)
				which = 0;
			else
				which = realpos * nb / 65536;
			break;
		case ACT_VOLUME:
			which = realpos * nb / 65536;
			break;
		}

		r.left = 0;
		r.top = which * spacing;
		r.bottom = which * spacing + (r2.bottom - r2.top);
		r.right = r2.right - r2.left;
		imagesBitmap->blitToRect(canvas, &r, &r2);
	}
	return WA2SLIDER_PARENT::onPaint(canvas);
}

int Wa2Slider::corecb_onVolumeChange(int newvol)
{
	if (action != ACT_VOLUME) return 0;
	realpos = (int)(((double)newvol * 65535.f) / 255.f);
	invalidate();
	return 0;
}

int Wa2Slider::corecb_onPanChange(int newpan)
{
	if (action != ACT_BALANCE) return 0;

	realpos = (int)(((double)(newpan + 127) * 65535.f) / 255.f);
invalidate();
	return 0;
}

int Wa2Slider::corecb_onSeeked(int newpos)
{
	if (action != ACT_SEEK) return 0;

	int len = WASABI_API_MEDIACORE->core_getLength(0);

	realpos = (int)(((float)(newpos) * 65535.f) / (float)len);
invalidate();
	return 0;
}

int Wa2Slider::corecb_onStarted()
{
	started = true;
	corecb_onSeeked(0);
	invalidate();
	return 0;
}

int Wa2Slider::corecb_onStopped()
{
	started = false;
	corecb_onSeeked(0);
	invalidate();
	return 0;
}
void Wa2Slider::timerCallback(int id)
{
	switch (id)
	{
	case Wa2Slider_TIMER_POS:
		corecb_onSeeked(WASABI_API_MEDIACORE->core_getPosition(0));
		break;
	default:
		WA2SLIDER_PARENT::timerCallback(id);
	}
}