Scope
ScopeSliderCtrl.cpp
1 #include "stdafx.h"
2 #include "ScopeSliderCtrl.h"
3 #include "helpers/Helpers.h"
4 
5 namespace scope {
6  namespace gui {
7 
8 CScopeSliderCtrl::CScopeSliderCtrl(ScopeNumber<double>* _scopenum, const double& _increment, const bool& _connectback, const bool& _connectcontrolstate)
9  : created(false)
10  , scopenum(_scopenum)
11  , increment(_increment)
12  , scalefactor((increment!=0)?increment:(scopenum->ul()-scopenum->ll()) / 100)
13  , offset(scopenum->ll())
14  , rangehigh((increment!=0)?static_cast<int32_t>((scopenum->ul()-scopenum->ll())/increment):100)
15  , rangelow(0) {
16  if ( _connectback )
18  if ( _connectcontrolstate )
19  stateconnection = scopenum->ConnectState(std::bind(&CScopeSliderCtrl::SetState, this, std::placeholders::_1));
20 }
21 
23  valueconnection.disconnect();
24  stateconnection.disconnect();
25 }
26 
28  if ( SubclassWindow(hWnd) ) {
29  created = true;
30  SetRange(static_cast<int32_t>(rangelow), static_cast<int32_t>(rangehigh), TRUE);
31  if ( increment == 0 )
32  SetTicFreq(10); // if not incrementing have only 10 ticks (although we have values from 0...100)
33  UpdateControl();
34  return TRUE;
35  }
36  return FALSE;
37 }
38 
39 void CScopeSliderCtrl::OnScroll(UINT nSBCode, UINT nPos, CScrollBar pScrollBar) {
40  // adjust scopenum on dragging the slider
41  // nPos 0 at top, but bottom should be 0
42  if ( nSBCode == SB_THUMBPOSITION )
43  scopenum->Set(std::abs(static_cast<int32_t>(nPos)-rangehigh) * scalefactor + offset);
44  // and on clicking into trackbar
45  if ( (nSBCode == SB_PAGEUP) || (nSBCode == SB_PAGEDOWN) || (nSBCode == SB_PAGELEFT) || (nSBCode == SB_PAGERIGHT) )
46  scopenum->Set(std::abs(GetPos()-rangehigh) * scalefactor + offset);
47 }
48 
49 LRESULT CScopeSliderCtrl::OnKeyDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) {
50  switch (wParam) {
51  case VK_RETURN:
52  case VK_TAB:
53  ::PostMessage(GetParent(), WM_NEXTDLGCTL, shiftstate, 0L);
54  return FALSE;
55  case VK_SHIFT:
56  shiftstate = true;
57  }
58  return DefWindowProc(uMsg, wParam, lParam);
59 }
60 
61 LRESULT CScopeSliderCtrl::OnKeyUp(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) {
62  switch (wParam) {
63  case VK_SHIFT:
64  shiftstate = false;
65  }
66  return DefWindowProc(uMsg, wParam, lParam);
67 }
68 
69 LRESULT CScopeSliderCtrl::OnUpdateControl(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) {
70  // nPos 0 at top, but bottom should be 0
71  SetPos(round2i32(abs((scopenum->Value()-offset)/scalefactor-rangehigh)));
72  return 0;
73 }
74 
76  ::PostMessage(m_hWnd, WM_UPDATECONTROL, NULL, NULL);
77 }
78 
79 void CScopeSliderCtrl::SetState(const bool& state) {
80  if ( created )
81  EnableWindow(state);
82 }
83 
84 }
85 
86 }
void SetState(const bool &state)
Sets the enabled/disabled control state.
boost::signals2::connection ConnectGUI(signalchange_t::slot_type slot)
Connect signal to slot to GUI.
virtual T Set(const T &_v, const bool &_callguisignal=true, const bool &_callothersignal=true, const bool &_callatnochange=false)
Sets the value and calls both change signals if the value actually changed.
Definition: ScopeValue.h:67
boost::signals2::connection stateconnection
The connection object for the control state (connection to the scopenum rw state change) ...
bool created
true if window created
T Value() const
Definition: ScopeValue.h:46
* CScopeSliderCtrl(ScopeNumber< double > *_scopenum, const double &_increment=0, const bool &_connectback=false, const bool &_connectcontrolstate=false)
()
LRESULT OnKeyDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Switches to next control on return or tab and updates ScopeValue scope_val Also sets state of shift k...
LRESULT OnUpdateControl(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Worker for UpdateControl.
LRESULT OnKeyUp(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Resets state of shift key.
~CScopeSliderCtrl()
Disconnects everything.
const double offset
is ScopeNumber lower limit
This is the include file for standard system include files, or project specific include files that ar...
bool shiftstate
stores state of shift key
void OnScroll(UINT nSBCode, UINT nPos, CScrollBar pScrollBar)
Updates the ScopeNumber from the slider position.
const int32_t rangelow
lower end of the slider range, usually 0
boost::signals2::connection ConnectState(signalstate_t::slot_type slot)
Connect signal to slot for state changes.
const int32_t rangehigh
the upper end of the slider range (100 if not incrementing, otherwise range/increment) ...
const double scalefactor
scalefactor is increment or range/100 (if not incrementing)
void UpdateControl()
Updates the slider position from the ScopeNumber.
ScopeNumber< double > *const scopenum
Pointer to the underlying ScopeNumber.
Various helper functions and classes for Scope.
const double increment
if != 0, then scopenum can only be changed by multiples of increment and the slider should display ti...
boost::signals2::connection valueconnection
The connection object for the control state (connection to the scopenum value change) ...
BOOL AttachToDlgItem(HWND hWnd)
Attach the control to a dialog item and set range and tick frequency.