-
Notifications
You must be signed in to change notification settings - Fork 1
/
led.cpp
executable file
·105 lines (90 loc) · 2.28 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
99
100
101
102
103
104
105
/////////////////////////////////////////////////////////////////////////////
// Name: led.cpp
// Purpose:
// Author: Joachim Buermann
// Id: $Id$
// Copyright: (c) 2001 Joachim Buermann
/////////////////////////////////////////////////////////////////////////////
#include "led.h"
#include "leds.xpm"
#include <wx/dcmemory.h>
#include <wx/settings.h>
BEGIN_EVENT_TABLE(awxLed, wxWindow)
EVT_ERASE_BACKGROUND(awxLed::OnErase)
EVT_PAINT(awxLed::OnPaint)
EVT_SIZE(awxLed::OnSizeEvent)
END_EVENT_TABLE()
awxLed::awxLed(wxWindow* parent,
wxWindowID id,
const wxPoint& pos,
const wxSize& size,
awxLedColour color) :
wxWindow(parent,id,pos,size,wxNO_FULL_REPAINT_ON_RESIZE)
{
m_state = awxLED_OFF;
m_bitmap = new wxBitmap(16,16);
m_timer = NULL;
m_blink = 0;
m_x = m_y = 0;
m_icons[awxLED_OFF] = new wxIcon(led_off_xpm);
m_icons[awxLED_ON] = NULL;
SetColour(color);
m_timer = new BlinkTimer(this);
};
awxLed::~awxLed()
{
if(m_timer) {
m_timer->Stop();
delete m_timer;
}
delete m_bitmap;
delete m_icons[awxLED_OFF];
delete m_icons[awxLED_ON];
};
void awxLed::Blink()
{
m_blink ^= 1;
Redraw();
};
void awxLed::DrawOnBitmap()
{
wxSize s = GetClientSize();
if((m_bitmap->GetWidth() != s.GetWidth()) ||
(m_bitmap->GetHeight() != s.GetHeight())) {
m_bitmap->Create(s.x,s.y);
}
wxMemoryDC dc;
dc.SelectObject(*m_bitmap);
wxBrush brush(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE),
wxSOLID);
dc.SetBackground(brush);
dc.Clear();
if(m_state == awxLED_BLINK) dc.DrawIcon(*m_icons[m_blink],m_x,m_y);
else dc.DrawIcon(*m_icons[m_state & 1],m_x,m_y);
dc.SelectObject(wxNullBitmap);
};
void awxLed::SetColour(awxLedColour color)
{
if(m_icons[awxLED_ON]) delete m_icons[awxLED_ON];
switch(color) {
case awxLED_GREEN:
m_icons[awxLED_ON] = new wxIcon(led_green_xpm);
break;
case awxLED_YELLOW:
m_icons[awxLED_ON] = new wxIcon(led_yellow_xpm);
break;
default:
m_icons[awxLED_ON] = new wxIcon(led_red_xpm);
}
};
void awxLed::SetState(awxLedState state)
{
m_state = state;
if(m_timer->IsRunning()) {
m_timer->Stop();
}
if(m_state == awxLED_BLINK) {
m_timer->Start(500);
}
Redraw();
};