-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathMyParamDisplay.cpp
More file actions
96 lines (85 loc) · 2.42 KB
/
MyParamDisplay.cpp
File metadata and controls
96 lines (85 loc) · 2.42 KB
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
/*
* MyParamDisplay.cpp
* C700
*
* Created by osoumen on 12/10/05.
* Copyright 2012 __MyCompanyName__. All rights reserved.
*
*/
#include "MyParamDisplay.h"
#include <stdio.h>
#include <cmath>
//------------------------------------------------------------------------
CMyParamDisplay::CMyParamDisplay(const CRect& size, long tag, float valueMultipler, char *unitStr, CBitmap* background, const long style)
: CParamDisplay(size, background, style)
, mValueMultipler(valueMultipler)
{
setTag(tag);
if (valueMultipler == 0)
{
mValueMultipler = 1;
}
if ( unitStr && unitStr[0] != '0')
{
strncpy(mUnitStr, unitStr, UNITSTR_LEN-1);
}
else
{
mUnitStr[0] = 0;
}
setStringConvert(stringConvert, this);
}
//------------------------------------------------------------------------
CMyParamDisplay::~CMyParamDisplay()
{
}
//------------------------------------------------------------------------
void CMyParamDisplay::stringConvert(float value, char *string, void *userData)
{
CMyParamDisplay *This = static_cast<CMyParamDisplay*>(userData);
if (This->mValueMultipler < 1) {
float floatValue = value * This->mValueMultipler;
sprintf(string, "%.1f%s", floatValue, This->mUnitStr);
}
else {
int intValue = roundf(value * This->mValueMultipler);
sprintf(string, "%d%s", intValue, This->mUnitStr);
}
}
//------------------------------------------------------------------------
CMouseEventResult CMyParamDisplay::onMouseDown (CPoint& where, const long& buttons)
{
if (!(buttons & kLButton))
return kMouseEventNotHandled;
mInitialPos = where;
mInitialValue = value;
beginEdit ();
if (checkDefaultValue (buttons))
{
endEdit ();
return kMouseDownEventHandledButDontNeedMovedOrUpEvents;
}
if (buttons & kShift)
return kMouseEventHandled;
return onMouseMoved (where, buttons);
}
//------------------------------------------------------------------------
CMouseEventResult CMyParamDisplay::onMouseUp (CPoint& where, const long& buttons)
{
endEdit ();
return kMouseEventHandled;
}
//------------------------------------------------------------------------
CMouseEventResult CMyParamDisplay::onMouseMoved (CPoint& where, const long& buttons)
{
if (buttons & kLButton)
{
value = (int)(mInitialValue - (float)(where.v - mInitialPos.v)/3);
bounceValue ();
if (isDirty () && listener)
listener->valueChanged (this);
if (isDirty ())
invalid ();
}
return kMouseEventHandled;
}