-
Notifications
You must be signed in to change notification settings - Fork 1
/
Controls.cpp
executable file
·459 lines (391 loc) · 10.2 KB
/
Controls.cpp
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
/*
This is my "standard" controls library.
CDisplay
The program display (program number and name, boot message)
CFader
Drawbars
CCircDisplay
The knobs with integrated number display
CTab
Tabs to click on...
*/
#include "Controls.h"
#include "resource.h"
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <ctype.h>
CDisplay::CDisplay(CRect &size, CControlListener *listener, int tag, CBitmap *background) : CControl(size, listener, tag, background)
{
my_listener=listener;
my_tag=tag;
bg=background;
top=size.top;
bottom=size.bottom;
left=size.left;
right=size.right;
first=1;
line1[0]=0;
line2[0]=0;
line3[0]=0;
line4[0]=0;
value=0;
last_value=-2;
linevalue=-1;
my_drawcontext=NULL;
}
int32_t CDisplay::getTag() const
{
return(my_tag);
}
void CDisplay::draw(CDrawContext *pContext)
{
/*
last_value=value;
my_drawcontext=pContext;
if(first==1)
{
// oc=new COffscreenContext(getFrame(),right-left,bottom-top,kBlackCColor);
first=0;
}
CRect rect(0,0,right-left,bottom-top);
bg->draw(oc,rect,CPoint(left,top));
oc->setFont(kNormalFontVerySmall);
{
CColor mc={255,236,200,0};
oc->setFontColor(mc);
oc->setLineWidth(1);
oc->setFrameColor(mc);
mc.red=126;
mc.green=210;
mc.blue=204;
oc->setFillColor(mc);
}
oc->drawString(line1,CRect(2,0,right-left,10),false,kLeftText);
oc->drawString(line2,CRect(2,10,right-left,10+10),false,kLeftText);
oc->drawString(line3,CRect(2,20,right-left,20+10),false,kLeftText);
oc->drawString(line4,CRect(2,30,right-left,30+10),false,kLeftText);
if(linevalue>=0)
{
oc->drawRect(CRect(2,42,right-left-2,48));
oc->fillRect(CRect(3,43,4+(int)((right-left-7)*linevalue),47));
}
oc->copyFrom(pContext,CRect(left,top,right,bottom),CPoint(0,0));
*/
pContext->setFont(kNormalFontVerySmall);
CRect rect(size.left, size.top-30, size.right, size.bottom);
pContext->drawString(line1, rect, kLeftText);
pContext->drawString(line2, CRect(size.left, size.top-10, size.right, size.bottom), kLeftText);
pContext->drawString(line3, CRect(size.left, size.top+10, size.right, size.bottom), kLeftText);
pContext->drawString(line4, CRect(size.left, size.top+30, size.right, size.bottom), kLeftText);
}
void CDisplay::setline(float value)
{
linevalue=value;
this->setDirty();
}
void CDisplay::setstring(int line, char *string)
{
if(line==1)
strncpy(line1,string,sizeof(line1));
else if(line==2)
strncpy(line2,string,sizeof(line2));
else if(line==3)
strncpy(line3,string,sizeof(line3));
else if(line==4)
strncpy(line4,string,sizeof(line4));
this->setDirty();
}
void CDisplay::setValue(float value)
{
this->value=value;
}
float CDisplay::getValue() const
{
return(value);
}
CDisplay::~CDisplay()
{
// if(oc!=NULL)
// delete oc;
}
CFader::CFader(CRect &size, CControlListener *listener, int tag, CBitmap *bitmap, CBitmap *background, int handleheight) : CControl (size, listener, tag, background)
{
my_listener=listener;
first=1;
top=size.top;
left=size.left;
bottom=size.bottom;
right=size.right;
width=bitmap->getWidth();
height=bitmap->getHeight();
my_tag=tag;
my_bm=bitmap;
my_bg=background;
my_handleheight=handleheight;
value=0;
last_value=-2;
m_xStart = 0;
m_mouseDown = false;
}
int32_t CFader::getTag() const
{
return(my_tag);
}
void CFader::draw(CDrawContext *pContext)
{
/*
last_value=value;
int pos=int((1-value)*(height-my_handleheight));
if(first==1)
{
oc=new COffscreenContext(getFrame(),right-left,bottom-top,kBlackCColor);
first=0;
}
CRect rect(0,0,width,height);
my_bm->draw(oc,rect,CPoint(0,pos));
rect(0,height-pos,width,height);
my_bg->draw(oc,rect,CPoint(left,bottom-pos));
rect(left,top,right,bottom);
oc->copyFrom(pContext,rect,CPoint(0,0));
*/
last_value=value;
int pos=int((1-value)*(height-my_handleheight));
CRect rect(left,top,right,bottom);
if (my_bm)
my_bm->draw((pContext), rect, CPoint(0,pos));
}
CMouseEventResult CFader::onMouseDown (CPoint& where, const CButtonState& buttons)
{
m_mouseDown = true;
float pos = where.y - this->top;
value = pos / (this->bottom - this->top);
beginEdit();
valueChanged();
invalid();
endEdit();
return kMouseEventHandled;
}
//------------------------------------------------------------------------
CMouseEventResult CFader::onMouseMoved (CPoint& where, const CButtonState& buttons)
{
if (!m_mouseDown)
return kMouseEventHandled;
float pos = where.y - this->top;
value = pos / (this->bottom - this->top);
if (value < 0)
value = 0.f;
if (value > 1)
value = 1.f;
beginEdit();
valueChanged();
invalid();
endEdit();
return kMouseEventHandled;
}
//------------------------------------------------------------------------
CMouseEventResult CFader::onMouseUp (CPoint& where, const CButtonState& buttons)
{
invalid();
m_mouseDown = false;
return kMouseEventHandled;
}
//------------------------------------------------------------------------
void CFader::setValue(float value)
{
this->value=value;
}
float CFader::getValue() const
{
return(value);
}
CFader::~CFader()
{
// if(oc!=NULL)
// delete oc;
}
CCircDisplay::CCircDisplay(CRect &size, CControlListener *listener, int tag, CBitmap *bitmap, CBitmap *digits, CBitmap *background) : CControl (size, listener, tag, background)
{
my_listener=listener;
first=1;
stringConvert=NULL;
top=size.top;
left=size.left;
width=bitmap->getWidth();
totalheight=bitmap->getHeight();
numofbm=int(totalheight/width);
my_tag=tag;
my_bm=bitmap;
my_digits=digits;
my_bg=background;
digitwidth=digits->getWidth();
digitheight=digits->getHeight()/12;
value=0;
last_value=-2;
m_leftPosXClick = 0;
m_mouseDown = false;
}
void CCircDisplay::setStringConvert (void (*convert) (float value, char *string))
{
stringConvert = convert;
}
int32_t CCircDisplay::getTag() const
{
return(my_tag);
}
void CCircDisplay::setValue(float value)
{
this->value=value;
}
float CCircDisplay::getValue() const
{
return(value);
}
CCircDisplay::~CCircDisplay()
{
// if(oc!=NULL)
// delete oc;
}
void CCircDisplay::draw(CDrawContext *pContext)
{
/*
char t[16];
unsigned int x;
int y=0,z;
if(first==1)
{
oc=new COffscreenContext(getFrame(),width,width,kBlackCColor);
first=0;
}
last_value=value;
if(stringConvert)
stringConvert(value,t);
else
sprintf(t,"%3d%",int(100*value+.001f));
CRect rect(0,0,width,width);
my_bg->draw(oc,rect,CPoint(left,top));
my_bm->drawTransparent(oc,rect,CPoint(0,int(value*(numofbm-1))*width));
for(x=0;x<strlen(t);x++)
{
if(t[x]=='.')
{
int a;
if(y>=digitwidth)
a=y-digitwidth;
rect(12+a,19,12+a+digitwidth,19+digitheight);
my_digits->drawTransparent(oc,rect,CPoint(0,10*digitheight));
continue;
}
else if(t[x]==' ')
{
y+=digitwidth;
continue;
}
else if(t[x]=='%')
z=11*digitheight;
else if(!isdigit(t[x]))
continue;
else
z=digitheight*(t[x]-'0');
rect(12+y,18,12+y+digitwidth,18+digitheight);
my_digits->drawTransparent(oc,rect,CPoint(0,z));
y+=digitwidth;
}
oc->copyFrom(pContext,CRect(left,top,left+width,top+width),CPoint(0,0));
*/
char t[16];
unsigned int x;
int y=0,z;
last_value=value;
if(stringConvert)
stringConvert(value,t);
else
sprintf(t,"%3d%",int(100*value+.001f));
//CRect rect(0,0,width,width);
CRect rect(left,top,size.right,size.bottom);
my_bg->draw(pContext,rect,CPoint(left,top));
my_bm->draw(pContext,rect,CPoint(0,int(value*(numofbm-1))*width), 0.3f);
pContext->setFont(kNormalFontVerySmall);
pContext->drawString(t,rect);
}
CMouseEventResult CCircDisplay::onMouseDown (CPoint& where, const CButtonState& buttons)
{
m_mouseDown = true;
float pos = where.y - this->top;
m_leftPosXClick = pos;
beginEdit();
valueChanged();
invalid();
endEdit();
return kMouseEventHandled;
}
//------------------------------------------------------------------------
CMouseEventResult CCircDisplay::onMouseMoved (CPoint& where, const CButtonState& buttons)
{
if (!m_mouseDown)
return kMouseEventHandled;
float pos = where.y - this->top;
float offset= m_leftPosXClick - pos;
if(offset < 0)
value -= 0.02f;
if (offset>0)
value += 0.02f;
if (value < 0)
value = 0.f;
if (value > 1)
value = 1.f;
beginEdit();
valueChanged();
invalid();
endEdit();
m_leftPosXClick = pos;
return kMouseEventHandled;
}
//------------------------------------------------------------------------
CMouseEventResult CCircDisplay::onMouseUp (CPoint& where, const CButtonState& buttons)
{
invalid();
m_mouseDown = false;
return kMouseEventHandled;
}
//------------------------------------------------------------------------
CTextSplash::CTextSplash(CRect &size,CControlListener *listener, int tag, CBitmap *background, CRect &toDisplay, CPoint &offset) : CSplashScreen(size,listener,tag,background,toDisplay,offset)
{
}
void CTextSplash::draw(CDrawContext *pContext)
{
if (value && getBackground())
{
getBackground()->draw (pContext, toDisplay, offset);
pContext->setFont(kNormalFontSmaller);
{
int x;
CColor mc={0,0,0,0};
pContext->setFontColor(mc);
for(x=0;x<100;x++)
{
pContext->drawString(text[x],CRect(size.left+158, size.top+x*10, size.right+250, size.bottom+10+x*10),kLeftText);
}
}
}
}
CTab::CTab(CRect &size,CControlListener *listener,int tag,CBitmap *bm) : CControl(size, listener, tag, bm)
{
}
CTab::~CTab()
{
}
void CTab::draw(CDrawContext *pContext)
{
}
CMouseEventResult CTab::onMouseDown (CPoint& where, const CButtonState& buttons)
{
beginEdit();
VSTGUIEditorInterface * editor = getEditor();
setValue(1);
valueChanged();
invalid();
endEdit();
return kMouseEventHandled;
}