-
Notifications
You must be signed in to change notification settings - Fork 1
/
Led.cpp
99 lines (74 loc) · 3.6 KB
/
Led.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
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
97
98
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include <memory>
#include "Led.h"
using std::unique_ptr;
//---------------------------------------------------------------------------
#pragma package(smart_init)
namespace SclLedCtrl {
//---------------------------------------------------------------------------
using Gdiplus::GdiplusStartup;
using Gdiplus::GdiplusShutdown;
GdiPlusSessionManager::GdiPlusSessionManager()
{
GdiplusStartup( &gdiplusToken_, &gdiplusStartupInput_, NULL );
}
//---------------------------------------------------------------------------
GdiPlusSessionManager::~GdiPlusSessionManager() /* throw() */
{
try {
GdiplusShutdown( gdiplusToken_ );
}
catch ( ... ) {
}
}
//---------------------------------------------------------------------------
Led::Led( float Size )
: size_( Size )
{
glowCurvePoints_.reserve( 13 );
glowCurvePoints_.push_back( Gdiplus::PointF( size_ * 0.4274 , size_ * 0.428250455 ) );
glowCurvePoints_.push_back( Gdiplus::PointF( size_ * 0.520608636 , size_ * 0.335055 ) );
glowCurvePoints_.push_back( Gdiplus::PointF( size_ * 0.542190455 , size_ * 0.205563182 ) );
glowCurvePoints_.push_back( Gdiplus::PointF( size_ * 0.475615 , size_ * 0.138987727 ) );
glowCurvePoints_.push_back( Gdiplus::PointF( size_ * 0.409039545 , size_ * 0.072412273 ) );
glowCurvePoints_.push_back( Gdiplus::PointF( size_ * 0.279547727 , size_ * 0.093994091 ) );
glowCurvePoints_.push_back( Gdiplus::PointF( size_ * 0.186352273 , size_ * 0.187202727 ) );
glowCurvePoints_.push_back( Gdiplus::PointF( size_ * 0.093144091 , size_ * 0.280398182 ) );
glowCurvePoints_.push_back( Gdiplus::PointF( size_ * 0.071561818 , size_ * 0.409889545 ) );
glowCurvePoints_.push_back( Gdiplus::PointF( size_ * 0.138137273 , size_ * 0.476465455 ) );
glowCurvePoints_.push_back( Gdiplus::PointF( size_ * 0.204713182 , size_ * 0.543040909 ) );
glowCurvePoints_.push_back( Gdiplus::PointF( size_ * 0.334204545 , size_ * 0.521458636 ) );
glowCurvePoints_.push_back( Gdiplus::PointF( size_ * 0.4274 , size_ * 0.428250455 ) );
}
//---------------------------------------------------------------------------
void Led::Draw( Gdiplus::Graphics& Canvas, Gdiplus::Color Color,
Gdiplus::PointF Offset, Gdiplus::Color RingColor,
float RingSize ) const
{
const float RingSize2 = RingSize * 2;
Gdiplus::Bitmap Bmp( size_ + RingSize2, size_ + RingSize2 );
unique_ptr<Gdiplus::Graphics> g( Gdiplus::Graphics::FromImage( &Bmp ) );
g->SetSmoothingMode( Canvas.GetSmoothingMode() );
Gdiplus::RectF Rect( 0, 0, size_, size_ );
g->TranslateTransform( RingSize, RingSize );
Gdiplus::SolidBrush const BkBrush( Gdiplus::Color::Black );
Gdiplus::SolidBrush const ClBrush = Color;
g->FillEllipse( &BkBrush, Rect );
g->FillEllipse( &ClBrush, Rect );
Gdiplus::GraphicsPath GlowBezierPath;
GlowBezierPath.AddBeziers( &glowCurvePoints_[0], glowCurvePoints_.size() );
Gdiplus::LinearGradientBrush GlowLinearGradientBrush(
Gdiplus::PointF( size_ * 0.2, size_ * 0.2 ),
Gdiplus::PointF( size_ * 0.45, size_ * 0.45 ),
Gdiplus::Color( 255, 255, 255, 255 ),
Gdiplus::Color( 0, 255, 255, 255 )
);
g->FillPath( &GlowLinearGradientBrush, &GlowBezierPath );
Gdiplus::Pen const RingPen( RingColor, RingSize );
g->DrawEllipse( &RingPen, Rect );
Canvas.DrawImage( &Bmp, Offset.X, Offset.Y );
}
//---------------------------------------------------------------------------
} // End of namespace SclLedCtrl