-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvumeter.cpp
53 lines (42 loc) · 1.08 KB
/
vumeter.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
#include "vumeter.h"
#include <string.h>
/*
** VUMeter
*/
VUMeter::VUMeter(Scrob* pParent, const Rect& r)
: Scrob(pParent, r)
{
Create(pParent, r);
}
bool VUMeter::Create(Scrob *pParent, const Rect& r)
{
if (!Scrob::Create(pParent, r))
return false;
m_nPercentage = 60;
memset(m_History, 0, sizeof(char)*15);
m_nHistoryPos = 0;
return true;
}
void VUMeter::Draw()
{
dt.SetCurrentObject(this);
dt.DrawRect(Rect(0, 0, m_Rect.Width(), m_Rect.Height()), 3);
int x = m_nPercentage * (m_Rect.Width()-2) / 100;
dt.FillRect(Rect(1, 1, x+1, m_Rect.Height()-1), 2);
dt.FillRect(Rect(x+1, 1, m_Rect.Width()-1, m_Rect.Height()-1), 1);
int percent_max=0;
for (int i=0; i<30; i++)
if (m_History[i] > percent_max)
percent_max = m_History[i];
x = percent_max * (m_Rect.Width()-2) / 100;
dt.FillRect(Rect(x+1, 1, x+2, m_Rect.Height()-1), 3);
}
void VUMeter::SetPercentage(int percent)
{
if (percent > 100) percent = 100;
if (percent < 0) percent = 0;
m_nPercentage=percent;
m_History[m_nHistoryPos] = percent;
m_nHistoryPos = (m_nHistoryPos+1)%30;
SetDirty();
}