2010-01-23 19:44:49 +00:00
|
|
|
/**********************************************************************
|
|
|
|
|
|
|
|
Audacity: A Digital Audio Editor
|
|
|
|
|
|
|
|
AColor.h
|
|
|
|
|
|
|
|
Dominic Mazzoni
|
|
|
|
|
|
|
|
Manages color brushes and pens and provides utility
|
|
|
|
drawing functions
|
|
|
|
|
|
|
|
**********************************************************************/
|
|
|
|
|
|
|
|
#ifndef __AUDACITY_COLOR__
|
|
|
|
#define __AUDACITY_COLOR__
|
|
|
|
|
2016-05-03 13:57:06 +00:00
|
|
|
#include "MemoryX.h"
|
2010-01-23 19:44:49 +00:00
|
|
|
#include <wx/brush.h>
|
2018-11-14 18:50:12 +00:00
|
|
|
#include <wx/pen.h> // member variable
|
2010-01-23 19:44:49 +00:00
|
|
|
|
|
|
|
class wxDC;
|
|
|
|
class wxRect;
|
|
|
|
|
2017-11-09 18:32:29 +00:00
|
|
|
/// Used to restore pen, brush and logical-op in a DC back to what they were.
|
2016-05-03 13:57:06 +00:00
|
|
|
struct DCUnchanger {
|
|
|
|
public:
|
|
|
|
DCUnchanger() {}
|
|
|
|
|
|
|
|
DCUnchanger(const wxBrush &brush_, const wxPen &pen_, long logicalOperation_)
|
|
|
|
: brush(brush_), pen(pen_), logicalOperation(logicalOperation_)
|
|
|
|
{}
|
|
|
|
|
|
|
|
void operator () (wxDC *pDC) const;
|
|
|
|
|
|
|
|
wxBrush brush {};
|
|
|
|
wxPen pen {};
|
|
|
|
long logicalOperation {};
|
|
|
|
};
|
|
|
|
|
2017-11-09 18:32:29 +00:00
|
|
|
/// Makes temporary drawing context changes that you back out of, RAII style
|
|
|
|
// It's like wxDCPenChanger, etc., but simple and general
|
2016-05-03 13:57:06 +00:00
|
|
|
class ADCChanger : public std::unique_ptr<wxDC, ::DCUnchanger>
|
|
|
|
{
|
|
|
|
using Base = std::unique_ptr<wxDC, ::DCUnchanger>;
|
|
|
|
public:
|
|
|
|
ADCChanger() : Base{} {}
|
|
|
|
ADCChanger(wxDC *pDC);
|
|
|
|
};
|
|
|
|
|
2010-01-23 19:44:49 +00:00
|
|
|
class AColor {
|
|
|
|
public:
|
2014-10-18 14:19:38 +00:00
|
|
|
|
|
|
|
enum ColorGradientChoice {
|
|
|
|
ColorGradientUnselected = 0,
|
|
|
|
ColorGradientTimeSelected,
|
|
|
|
ColorGradientTimeAndFrequencySelected,
|
2014-10-22 21:06:15 +00:00
|
|
|
ColorGradientEdge,
|
2014-10-18 14:19:38 +00:00
|
|
|
|
|
|
|
ColorGradientTotal // keep me last
|
|
|
|
};
|
|
|
|
|
2010-01-23 19:44:49 +00:00
|
|
|
static void Init();
|
|
|
|
static void ReInit();
|
|
|
|
|
|
|
|
static void Arrow(wxDC & dc, wxCoord x, wxCoord y, int width, bool down = true);
|
Fix cross-platform one-pixel differences in line drawing...
... Make all line drawing go through our AColor which wraps the wxDC
line-drawing functions.
Despite what wxWidgets documentation says, the functions still don't
consistently include the first point and omit the last point of a line. I
observed inclusion of both on Mac, while on Windows, omission sometimes of the
first point instead of the last.
Discrepancies could be observed in 2.3.0 between Windows and Mac, using the
Window magnifier or command+alt+ +, zooming in closely on the ends of the
shadow lines below and right of tracks, or at the bottom-right corners of the
bevels drawn around vertical rulers.
So where there is an observable one-pixel difference of drawing between
platforms, there is the question, which was the intent when the drawing code
was written? Should the coordinates be corrected by one or not?
I reviewed each case and used my judgment.
Most of the calls are in drawing rulers. Major tick lines were drawn five
pixels long, and minor, three, on Mac. I keep this behavior, but you might
argue for making them four and two.
On the other hand the drawing of ruler grid lines, which you can see in
the equalization and frequency analysis windows, did need a one-pixel correction
to avoid straying out of bounds.
2018-11-17 14:25:26 +00:00
|
|
|
|
|
|
|
// Draw a line, INCLUSIVE of both endpoints
|
|
|
|
// (unlike what wxDC::DrawLine() documentation specifies)
|
2010-01-23 19:44:49 +00:00
|
|
|
static void Line(wxDC & dc, wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2);
|
Fix cross-platform one-pixel differences in line drawing...
... Make all line drawing go through our AColor which wraps the wxDC
line-drawing functions.
Despite what wxWidgets documentation says, the functions still don't
consistently include the first point and omit the last point of a line. I
observed inclusion of both on Mac, while on Windows, omission sometimes of the
first point instead of the last.
Discrepancies could be observed in 2.3.0 between Windows and Mac, using the
Window magnifier or command+alt+ +, zooming in closely on the ends of the
shadow lines below and right of tracks, or at the bottom-right corners of the
bevels drawn around vertical rulers.
So where there is an observable one-pixel difference of drawing between
platforms, there is the question, which was the intent when the drawing code
was written? Should the coordinates be corrected by one or not?
I reviewed each case and used my judgment.
Most of the calls are in drawing rulers. Major tick lines were drawn five
pixels long, and minor, three, on Mac. I keep this behavior, but you might
argue for making them four and two.
On the other hand the drawing of ruler grid lines, which you can see in
the equalization and frequency analysis windows, did need a one-pixel correction
to avoid straying out of bounds.
2018-11-17 14:25:26 +00:00
|
|
|
|
|
|
|
// Draw lines, INCLUSIVE of all endpoints
|
|
|
|
static void Lines(wxDC &dc, size_t nPoints, const wxPoint points[]);
|
|
|
|
|
2010-01-23 19:44:49 +00:00
|
|
|
static void DrawFocus(wxDC & dc, wxRect & r);
|
2016-04-30 17:48:04 +00:00
|
|
|
static void Bevel(wxDC & dc, bool up, const wxRect & r);
|
2017-07-09 16:24:07 +00:00
|
|
|
static void Bevel2
|
|
|
|
(wxDC & dc, bool up, const wxRect & r, bool bSel=false, bool bHighlight = false);
|
2017-06-22 02:34:26 +00:00
|
|
|
static void BevelTrackInfo(wxDC & dc, bool up, const wxRect & r, bool highlight = false);
|
2010-01-23 19:44:49 +00:00
|
|
|
static wxColour Blend(const wxColour & c1, const wxColour & c2);
|
|
|
|
|
2019-03-29 22:06:03 +00:00
|
|
|
static void UseThemeColour( wxDC * dc, int iBrush, int iPen=-1, int alpha = 255 );
|
2010-01-23 19:44:49 +00:00
|
|
|
static void TrackPanelBackground(wxDC * dc, bool selected);
|
|
|
|
|
2017-06-22 02:34:26 +00:00
|
|
|
static void Light(wxDC * dc, bool selected, bool highlight = false);
|
2010-03-09 04:59:26 +00:00
|
|
|
static void Medium(wxDC * dc, bool selected);
|
|
|
|
static void MediumTrackInfo(wxDC * dc, bool selected);
|
2017-06-22 02:34:26 +00:00
|
|
|
static void Dark(wxDC * dc, bool selected, bool highlight = false);
|
2010-01-23 19:44:49 +00:00
|
|
|
|
|
|
|
static void CursorColor(wxDC * dc);
|
|
|
|
static void IndicatorColor(wxDC * dc, bool bIsNotRecording);
|
|
|
|
static void PlayRegionColor(wxDC * dc, bool locked);
|
|
|
|
|
|
|
|
static void Mute(wxDC * dc, bool on, bool selected, bool soloing);
|
|
|
|
static void Solo(wxDC * dc, bool on, bool selected);
|
|
|
|
|
2017-05-31 15:04:59 +00:00
|
|
|
// In all of these, channel is 1-indexed (1 through 16); if out of bounds
|
|
|
|
// (either due to being explicitly set to 0 or due to an allegro file with
|
|
|
|
// more than 16 channels) a gray color is returned.
|
|
|
|
|
2010-01-23 19:44:49 +00:00
|
|
|
static void MIDIChannel(wxDC * dc, int channel /* 1 - 16 */ );
|
|
|
|
static void LightMIDIChannel(wxDC * dc, int channel /* 1 - 16 */ );
|
|
|
|
static void DarkMIDIChannel(wxDC * dc, int channel /* 1 - 16 */ );
|
|
|
|
|
|
|
|
static void TrackFocusPen(wxDC * dc, int level /* 0 - 2 */);
|
|
|
|
static void SnapGuidePen(wxDC * dc);
|
|
|
|
|
2010-09-13 01:31:54 +00:00
|
|
|
static void PreComputeGradient();
|
|
|
|
|
2010-01-23 19:44:49 +00:00
|
|
|
// Member variables
|
|
|
|
|
|
|
|
static wxBrush lightBrush[2];
|
2010-03-09 04:59:26 +00:00
|
|
|
static wxBrush mediumBrush[2];
|
2010-01-23 19:44:49 +00:00
|
|
|
static wxBrush darkBrush[2];
|
|
|
|
static wxPen lightPen[2];
|
2010-03-09 04:59:26 +00:00
|
|
|
static wxPen mediumPen[2];
|
2010-01-23 19:44:49 +00:00
|
|
|
static wxPen darkPen[2];
|
|
|
|
|
|
|
|
static wxPen cursorPen;
|
|
|
|
static wxPen indicatorPen[2];
|
|
|
|
static wxBrush indicatorBrush[2];
|
|
|
|
static wxPen playRegionPen[2];
|
|
|
|
static wxBrush playRegionBrush[2];
|
|
|
|
|
|
|
|
static wxBrush muteBrush[2];
|
|
|
|
static wxBrush soloBrush;
|
|
|
|
|
|
|
|
static wxPen clippingPen;
|
|
|
|
|
|
|
|
static wxPen envelopePen;
|
|
|
|
static wxPen WideEnvelopePen;
|
|
|
|
static wxBrush envelopeBrush;
|
|
|
|
|
|
|
|
static wxBrush labelTextNormalBrush;
|
|
|
|
static wxBrush labelTextEditBrush;
|
|
|
|
static wxBrush labelUnselectedBrush;
|
|
|
|
static wxBrush labelSelectedBrush;
|
2010-08-11 22:47:26 +00:00
|
|
|
static wxBrush labelSyncLockSelBrush;
|
2010-01-23 19:44:49 +00:00
|
|
|
static wxPen labelUnselectedPen;
|
|
|
|
static wxPen labelSelectedPen;
|
2010-08-11 22:47:26 +00:00
|
|
|
static wxPen labelSyncLockSelPen;
|
2010-01-23 19:44:49 +00:00
|
|
|
static wxPen labelSurroundPen;
|
|
|
|
|
|
|
|
static wxPen trackFocusPens[3];
|
|
|
|
static wxPen snapGuidePen;
|
|
|
|
|
2015-08-09 11:03:42 +00:00
|
|
|
static wxPen tooltipPen;
|
2010-01-23 19:44:49 +00:00
|
|
|
static wxBrush tooltipBrush;
|
|
|
|
|
2010-09-13 01:31:54 +00:00
|
|
|
static bool gradient_inited;
|
|
|
|
static const int gradientSteps = 512;
|
2014-10-18 14:19:38 +00:00
|
|
|
static unsigned char gradient_pre[ColorGradientTotal][2][gradientSteps][3];
|
2010-09-13 01:31:54 +00:00
|
|
|
|
2017-06-22 02:34:26 +00:00
|
|
|
// For experiments in mouse-over highlighting only
|
|
|
|
static wxPen uglyPen;
|
|
|
|
static wxBrush uglyBrush;
|
|
|
|
|
2010-01-23 19:44:49 +00:00
|
|
|
private:
|
|
|
|
static wxPen sparePen;
|
|
|
|
static wxBrush spareBrush;
|
|
|
|
static bool inited;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2010-09-13 01:31:54 +00:00
|
|
|
inline void GetColorGradient(float value,
|
2014-10-18 14:19:38 +00:00
|
|
|
AColor::ColorGradientChoice selected,
|
2010-09-13 01:31:54 +00:00
|
|
|
bool grayscale,
|
2016-09-20 11:15:18 +00:00
|
|
|
unsigned char * __restrict red,
|
|
|
|
unsigned char * __restrict green,
|
|
|
|
unsigned char * __restrict blue) {
|
2010-09-13 01:31:54 +00:00
|
|
|
|
|
|
|
int idx = value * (AColor::gradientSteps - 1);
|
2011-07-06 09:49:59 +00:00
|
|
|
|
|
|
|
*red = AColor::gradient_pre[selected][grayscale][idx][0];
|
|
|
|
*green = AColor::gradient_pre[selected][grayscale][idx][1];
|
2014-06-03 20:30:19 +00:00
|
|
|
*blue = AColor::gradient_pre[selected][grayscale][idx][2];
|
2010-09-13 01:31:54 +00:00
|
|
|
}
|
2010-01-23 19:44:49 +00:00
|
|
|
|
|
|
|
#endif
|