Debian Codegraph @

protolib/examples/juce/juceProtoExample/Source/ivoxActivityComponent.cpp

raw
1 /*
2 ==============================================================================
3
4 IvoxActivityComponent.cpp
5 Created: 29 May 2018 10:14:27pm
6 Author: adamson
7
8 ==============================================================================
9 */
10
11 #include "../JuceLibraryCode/JuceHeader.h"
12 #include "IvoxActivityComponent.h"
13 #include "protoDebug.h"
14
15 //==============================================================================
16 IvoxActivityComponent::IvoxActivityComponent()
17 : activity_status(DEAD), is_animated(true),
18 bg_colour(Colours::grey)
19 {
20 // This done simply for temporary array initialization
21 const Colour blueShades[5] =
22 {
23 Colour(0xff3838ff),
24 Colour(0xff7171ff),
25 Colour(0xff7171ff),
26 Colour(0xffaaaaff),
27 Colour (0xffe3e3ff)
28 };
29 memcpy(blue_shades, blueShades, sizeof(blueShades));
30 // Convert blueShades[] to grayscale values
31 for (int i = 0; i < 5; i++)
32 {
33 grey_shades[i] = Colour::greyLevel(blueShades[i].getPerceivedBrightness());
34 dead_shades[i] = grey_shades[i].brighter();
35 }
36
37 setFramesPerSecond(10);
38 setVisible(true);
39 setSize(128, 128);
40 }
41
42 IvoxActivityComponent::~IvoxActivityComponent()
43 {
44 }
45
46 void IvoxActivityComponent::SetStatus(Status status, bool animate)
47 {
48 is_animated = animate;
49 if (animate && (PLAY == status))
50 setFramesPerSecond(10);
51 else
52 setFramesPerSecond(1);
53 activity_status = status;
54 repaint();
55 } // end IvoxActivityComponent::SetStatus()
56
57 void IvoxActivityComponent::paint(Graphics& g)
58 {
59 // Fill background
60 g.fillAll(Colour(bg_colour));
61 // Draw 'speaker' circle
62 // 'diameter' is min(width, height)
63 float diameter = (getWidth() < getHeight() ? getWidth() : getHeight());
64 float radius = diameter / 2.0;
65 // 'c' is the centre point
66 Point<float> c(getWidth()/2.0, getHeight()/2.0);
67 // Set 'speaker' background gradient per 'activity_status'
68 Colour* shade;
69 if (activity_status > IDLE)
70 shade = blue_shades;
71 else if (activity_status > DEAD)
72 shade = grey_shades;
73 else
74 shade = dead_shades;
75 ColourGradient gradient(shade[0], c.x, c.y,
76 shade[4], c.x, c.y + radius, true);
77 gradient.addColour(0.25, shade[1]);
78 gradient.addColour(0.50, shade[2]);
79 gradient.addColour(0.75, shade[3]);
80 g.setGradientFill(gradient);
81
82 g.fillEllipse (c.x - radius, c.y - radius, diameter, diameter);
83
84 if (PLAY == activity_status)
85 {
86 g.setColour(blue_shades[0]);
87 float rscale = 1.0;
88 if (is_animated)
89 rscale = ((float)abs(getFrameCounter() % 20 - 10)) / 10.0;
90 // Draw 5 concentric circles as 'speaker' coil
91 for (unsigned int i = 0; i < 5; i++)
92 {
93 float s = ((float)(i+1)) / 10.0;
94 float r = 2.0*s*rscale*radius;
95 double d = 2.0*r;
96 g.drawEllipse(c.x - r, c.y - r, d, d, 1.0);
97 }
98 }
99 } // end IvoxActivityComponent::paint()
100
101 void IvoxActivityComponent::resized()
102 {
103 // This method is where you should set the bounds of any child
104 // components that your component contains..
105
106 }