Scope
ScopeLEDCtrl.cpp
1 #include "stdafx.h"
2 #include "ScopeLEDCtrl.h"
3 #include "resource.h"
4 #include "helpers/helpers.h"
5 
6 namespace scope {
7 
8 namespace gui {
9 
10 CImageList CScopeLEDCtrl::imagegreen;
11 CImageList CScopeLEDCtrl::imagered;
13 
14 CScopeLEDCtrl::CScopeLEDCtrl(ScopeNumber<bool>* _scopebool, const uint32_t& _style)
15  : scopebool(_scopebool)
16  , style(_style) {
17  // Create imagelists (only once)
18  if ( imagegreen.IsNull() ) {
19  CIcon icon;
20  icon.LoadIconWithScaleDown(IDI_LED_GREEN, 18, 18);
21  imagegreen.Create(18, 18, ILC_COLOR32, 0, 2);
22  imagegreen.AddIcon(icon);
23  }
24  if ( imagered.IsNull() ) {
25  CIcon icon;
26  icon.LoadIconWithScaleDown(IDI_LED_RED, 18, 18);
27  imagered.Create(18, 18, ILC_COLOR32, 0, 2);
28  imagered.AddIcon(icon);
29  }
30  if ( imagewarning.IsNull() ) {
31  CIcon icon;
32  icon.LoadIconWithScaleDown(IDI_LED_WARNING, 18, 18);
33  imagewarning.Create(18, 18, ILC_COLOR32, 0, 2);
34  imagewarning.AddIcon(icon);
35  }
37 }
38 
40  valueconnection.disconnect();
41 }
42 
44  if ( scopebool->Value() )
45  SetTrue();
46  else
47  SetFalse();
48 }
49 
51  if ( SubclassWindow(hWnd) ) {
52  UpdateControl();
53  return true;
54  }
55  return false;
56 }
57 
58 void CScopeLEDCtrl::DoPaint(CDCHandle dc) {
59  RECT rc;
60  GetClientRect(&rc);
61  dc.FillRect(&rc, (HBRUSH)(COLOR_BTNFACE));
62  // call inherited DoPaint()
63  CBitmapButtonImpl<CScopeLEDCtrl>::DoPaint(dc);
64 }
65 
67  if ( style == SCOPELED_OKONTRUE )
68  SetImageList(imagegreen);
69  if ( style == SCOPELED_WARNINGONTRUE )
70  SetImageList(imagewarning);
71  SetImages(0);
72  // Force drawing update
73  if ( IsWindow() )
74  Invalidate();
75 }
76 
78  if ( style == SCOPELED_OKONTRUE )
79  SetImageList(imagered);
80  if ( style == SCOPELED_WARNINGONTRUE )
81  SetImageList(imagegreen);
82  SetImages(0);
83  // Force drawing update
84  if ( IsWindow() )
85  Invalidate();
86 }
87 
88 }
89 
90 }
void DoPaint(CDCHandle dc)
override of CBitmapButtonImpl DoPaint() in CBmpBtn class to erase background (otherwise weird overlay...
boost::signals2::connection ConnectGUI(signalchange_t::slot_type slot)
Connect signal to slot to GUI.
static CImageList imagewarning
image for warning LED
Definition: ScopeLEDCtrl.h:34
T Value() const
Definition: ScopeValue.h:46
void SetFalse()
Sets LED to false.
bool AttachToDlgItem(HWND hWnd)
Attach the control to a dialog item.
boost::signals2::connection valueconnection
The connection object for the control state (connection to the scopenum value change) ...
Definition: ScopeLEDCtrl.h:20
This is the include file for standard system include files, or project specific include files that ar...
CScopeLEDCtrl(ScopeNumber< bool > *_scopebool, const uint32_t &_style=SCOPELED_WARNINGONTRUE)
Gets a pointer to the ScopeNumber and connects.
static CImageList imagered
image for red LED
Definition: ScopeLEDCtrl.h:31
void UpdateControl()
Sets LED according to value of scopebool.
Various helper functions and classes for Scope.
void SetTrue()
Sets LED to true.
~CScopeLEDCtrl()
Disconnects.
ScopeNumber< bool > *const scopebool
pointer to underlying ScopeNumber
Definition: ScopeLEDCtrl.h:17
static CImageList imagegreen
image for green LED
Definition: ScopeLEDCtrl.h:28
const uint32_t style
the LED style
Definition: ScopeLEDCtrl.h:25