-
Notifications
You must be signed in to change notification settings - Fork 1
/
led.h
executable file
·94 lines (86 loc) · 1.97 KB
/
led.h
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
/////////////////////////////////////////////////////////////////////////////
// Name: led.h
// Purpose:
// Author: Joachim Buermann
// Id: $Id$
// Copyright: (c) 2001 Joachim Buermann
/////////////////////////////////////////////////////////////////////////////
#ifndef __LED_H
#define __LED_H
#include <wx/icon.h>
#include <wx/dcclient.h>
#include <wx/bitmap.h>
#include <wx/timer.h>
#include <wx/window.h>
enum awxLedState {
awxLED_OFF = 0,
awxLED_ON,
awxLED_BLINK
};
enum awxLedColour {
awxLED_LUCID = 0,
awxLED_RED,
awxLED_GREEN,
awxLED_YELLOW
};
class BlinkTimer;
class awxLed : public wxWindow
{
protected:
// bitmap for double buffering
wxBitmap* m_bitmap;
wxIcon* m_icons[2];
awxLedState m_state;
BlinkTimer* m_timer;
int m_blink;
int m_x;
int m_y;
protected:
// protected member functions
void DrawOnBitmap();
public:
awxLed(wxWindow* parent,
wxWindowID id,
const wxPoint& pos = wxPoint(0,0),
const wxSize& size = wxSize(16,16),
// red LED is default
awxLedColour color = awxLED_RED);
~awxLed();
void Blink();
void OnErase(wxEraseEvent& WXUNUSED(erase)) {
Redraw();
};
void OnPaint(wxPaintEvent& WXUNUSED(event)) {
wxPaintDC dc(this);
dc.DrawBitmap(*m_bitmap,0,0,false);
};
void OnSizeEvent(wxSizeEvent& event) {
wxSize size = event.GetSize();
m_x = (size.GetX() - m_icons[0]->GetWidth()) >> 1;
m_y = (size.GetY() - m_icons[0]->GetHeight()) >> 1;
if(m_x < 0) m_x = 0;
if(m_y < 0) m_y = 0;
DrawOnBitmap();
};
void Redraw() {
wxClientDC dc(this);
DrawOnBitmap();
dc.DrawBitmap(*m_bitmap,0,0,false);
};
void SetColour(awxLedColour color);
void SetState(awxLedState state);
DECLARE_EVENT_TABLE()
};
class BlinkTimer : public wxTimer
{
protected:
awxLed* m_led;
public:
BlinkTimer(awxLed *led) : wxTimer() {
m_led = led;
};
void Notify() {
m_led->Blink();
};
};
#endif