Audacity 3.2.0
ClipIndicatorPanel.cpp
Go to the documentation of this file.
1/* SPDX-License-Identifier: GPL-2.0-or-later */
2/*!********************************************************************
3
4 Audacity: A Digital Audio Editor
5
6 ClipIndicatorPanel.cpp
7
8 Matthieu Hodgkinson
9
10**********************************************************************/
11#include "ClipIndicatorPanel.h"
12#include "AudioIO.h"
14#include <wx/dcclient.h>
15
16BEGIN_EVENT_TABLE(ClipIndicatorPanel, wxPanelWrapper)
19
20ClipIndicatorPanel::ClipIndicatorPanel(wxWindow* parent, int id)
21 : wxPanelWrapper { parent, id }
22 , mPlaybackStartStopSubscription { AudioIO::Get()->Subscribe(
23 [this](const AudioIOEvent& evt) {
24 if (evt.type == AudioIOEvent::PLAYBACK && evt.on)
25 Reset();
26 }) }
27{
28}
29
31{
32 mClipping = true;
33 Refresh();
34}
35
37{
38 mClipping = false;
39 Refresh();
40}
41
42void ClipIndicatorPanel::OnPaint(wxPaintEvent& evt)
43{
44 using namespace DynamicRangeProcessorPanel;
45
46 wxPaintDC dc { this };
47 const auto color = mClipping ? *wxRED : *wxLIGHT_GREY;
48 dc.SetBrush(color);
49 dc.SetPen(lineColor);
50 auto rect = GetPanelRect(*this);
51 dc.DrawRoundedRectangle(rect, 2);
52
53 // This is supposed to be a LED. Add a little shine.
54 dc.SetBrush(GetColorMix(*wxWHITE, color, 0.5));
55 dc.SetPen(*wxTRANSPARENT_PEN);
56 dc.DrawRoundedRectangle(rect.Deflate(2), 2);
57}
END_EVENT_TABLE()
static AudioIO * Get()
Definition: AudioIO.cpp:126
void OnPaint(wxPaintEvent &evt)
Subscription Subscribe(Callback callback)
Connect a callback to the Publisher; later-connected are called earlier.
Definition: Observer.h:199
wxColor GetColorMix(const wxColor &a, const wxColor &b, double aWeight)
wxRect GetPanelRect(const wxPanelWrapper &panel)
bool on
Definition: AudioIO.h:68
enum AudioIOEvent::Type type