bool CRoundSliderCtrl::SetKnob(const CPoint& pt) { const int nMin = GetRangeMin(); const int nMax = GetRangeMax()+1; CSize szDelta = pt - m_ptCenter; if(m_bInverted) szDelta.cx *= -1; double dNewPos = 0.0; if(szDelta.cx != 0) { dNewPos = 90.0 - atan(-(double)szDelta.cy / (double)szDelta.cx) * 180.0 / pi; } if(((szDelta.cx == 0) && (szDelta.cy >= 0)) || (szDelta.cx < 0)) { dNewPos += 180.0; } dNewPos -= m_nZero; while(dNewPos < 0.0) dNewPos += 360.0; while(dNewPos >= 360.0) dNewPos -= 360.0; const int nNewPos = nMin + (int)(dNewPos*(nMax-nMin)/360.0); const bool bChanged = (nNewPos != GetPos()); if(bChanged) { SetPos(nNewPos); } return bChanged; }
void CSliderCtrlEx::SetRangeMax(int nMax, BOOL bRedraw) { int h = GetRangeMax(); if (nMax < h) clearColors(); CSliderCtrl::SetRangeMax(nMax, bRedraw); }
void CRoundSliderCtrl::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) { const int nMin = GetRangeMin(); const int nMax = GetRangeMax()+1; switch(nChar) { case VK_LEFT: case VK_UP: { int nNewPos = GetPos()-GetLineSize(); while(nNewPos < nMin) nNewPos += (nMax - nMin); SetPos(nNewPos); RedrawWindow(); PostMessageToParent(TB_LINEUP); } break; case VK_RIGHT: case VK_DOWN: { int nNewPos = GetPos()+GetLineSize(); while(nNewPos >= nMax) nNewPos -= (nMax - nMin); SetPos(nNewPos); RedrawWindow(); PostMessageToParent(TB_LINEDOWN); } break; case VK_PRIOR: { int nNewPos = GetPos()-GetPageSize(); while(nNewPos < nMin) nNewPos += (nMax - nMin); SetPos(nNewPos); RedrawWindow(); PostMessageToParent(TB_PAGEUP); } break; case VK_NEXT: { int nNewPos = GetPos()+GetPageSize(); while(nNewPos >= nMax) nNewPos -= (nMax - nMin); SetPos(nNewPos); RedrawWindow(); PostMessageToParent(TB_PAGEDOWN); } break; case VK_HOME: case VK_END: // Do nothing (ignore keystroke) break; default: CSliderCtrl::OnKeyDown(nChar, nRepCnt, nFlags); } }
void CmusikTrackCtrl::DrawChannel( CDC* pDC, const CRect& rect, BOOL bHoriz ) { CRect rcChannel = rect; if ( bHoriz ) { rcChannel.top += 1; rcChannel.bottom += 1; rcChannel.InflateRect( 0, 1, 0, 1 ); } else { rcChannel.left += 1; rcChannel.right += 1; rcChannel.InflateRect( 1, 0, 1, 0 ); } CMemDC pMemDC( pDC, &rcChannel ); pMemDC.FillSolidRect( rcChannel, m_Prefs->MUSIK_COLOR_BTNHILIGHT ); pMemDC.Draw3dRect( rcChannel, m_Prefs->MUSIK_COLOR_BTNSHADOW, m_Prefs->MUSIK_COLOR_BTNHILIGHT ); int nMax = GetRangeMax(); int nPos = GetPos(); float fPercent = (float)GetPos() / (float)GetRangeMax(); if ( bHoriz ) { float fWidth = ( (float)rcChannel.Width() * fPercent ) + 1; pMemDC->FillSolidRect( CRect( rcChannel.left + 1, rcChannel.top + 1, rcChannel.left + (int)fWidth, rcChannel.bottom - 1 ), m_Prefs->MUSIK_COLOR_ACTIVECAPTION ); } else { float fHeight = ( (float)rcChannel.Height() * fPercent ) + 1; pMemDC->FillSolidRect( CRect( rcChannel.left + 1, rcChannel.top + (int)fHeight, rcChannel.right - 1, rcChannel.bottom - 1 ), m_Prefs->MUSIK_COLOR_ACTIVECAPTION ); } Invalidate( false ); }
void MFCQuaRotor::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) { int nMin = GetRangeMin(); int nMax = GetRangeMax()+1; switch(nChar) { case VK_LEFT: { case VK_DOWN: PixelDelta(-1, 1); RedrawRotor(); } break; case VK_RIGHT: case VK_UP: { PixelDelta(+1, 1); RedrawRotor(); } break; case VK_PRIOR: { SetFloatValue(fMid); SendVCMsg(); RedrawRotor(); } break; case VK_HOME: { SetFloatValue(fMin); SendVCMsg(); RedrawRotor(); } break; case VK_END: { SetFloatValue(fMax); SendVCMsg(); RedrawRotor(); } break; default: CSliderCtrl::OnKeyDown(nChar, nRepCnt, nFlags); } }
void CRoundSliderCtrl::OnPaint() { const int nMin = GetRangeMin(); const int nMax = GetRangeMax()+1; const bool bDisabled = !IsWindowEnabled(); CPaintDC dc(this); // device context for painting #ifdef USE_MEM_DC CMemDC pDC(&dc); #else CDC* pDC = &dc; #endif int nRadius = m_nRadius; // Draw (clear) the background CRect rc; GetClientRect(rc); pDC->SelectStockObject(NULL_BRUSH); pDC->SelectStockObject(NULL_PEN); pDC->FillSolidRect(rc, ::GetSysColor(COLOR_BTNFACE)); // Draw the sliders channel if(!m_bDrawRadioButton) { DrawCircle(pDC, m_ptCenter, nRadius--, ::GetSysColor(COLOR_3DDKSHADOW), ::GetSysColor(COLOR_3DHIGHLIGHT)); DrawCircle(pDC, m_ptCenter, nRadius, ::GetSysColor(COLOR_3DSHADOW), ::GetSysColor(COLOR_3DLIGHT)); } int nPos = (((GetPos()-nMin)*360/(nMax-nMin)) + m_nZero + 360) % 360; if(m_bInverted) nPos = 360-nPos; const double dPos = ((double)(nPos))*pi/180.0; CPoint ptKnobCenter; #pragma warning(disable:4244) // Disable warning "Converting 'double' to 'int', possible loss of data" if(m_bDrawRadioButton) { ptKnobCenter = CPoint(m_ptCenter.x + (nRadius-m_nKnobRadius) * sin(dPos), m_ptCenter.y - (nRadius-m_nKnobRadius) * cos(dPos)); } else { ptKnobCenter = CPoint(m_ptCenter.x + (nRadius) * sin(dPos), m_ptCenter.y - (nRadius) * cos(dPos)); } #pragma warning(default:4244) m_ptKnobCenter = ptKnobCenter; if(m_bDrawRadioButton) { nRadius += 2; } else { nRadius -= 2; } if(!bDisabled) { CBrush* pOldBrush = pDC->SelectObject(CBrush::FromHandle(m_hDialBrush)); pDC->Ellipse(m_ptCenter.x - nRadius + 1, m_ptCenter.y - nRadius + 1, m_ptCenter.x + nRadius + 1, m_ptCenter.y + nRadius + 1); pDC->SelectObject(pOldBrush); } DrawCircle(pDC, m_ptCenter, nRadius--, ::GetSysColor(COLOR_3DHIGHLIGHT), ::GetSysColor(COLOR_3DDKSHADOW)); DrawCircle(pDC, m_ptCenter, nRadius--, ::GetSysColor(COLOR_3DLIGHT), ::GetSysColor(COLOR_3DSHADOW)); // Draw the knob int nKnobRadius = m_nKnobRadius; if(m_bDrawRadioButton) { nKnobRadius *= 4; nKnobRadius /= 5; } const CRect rcKnob(ptKnobCenter.x - nKnobRadius + 2, ptKnobCenter.y - nKnobRadius + 2, ptKnobCenter.x + nKnobRadius, ptKnobCenter.y + nKnobRadius); CRgn rgnKnob; rgnKnob.CreateEllipticRgnIndirect(rcKnob); if(bDisabled) { pDC->FillRgn(&rgnKnob, CBrush::FromHandle(::GetSysColorBrush(COLOR_BTNFACE))); } else { pDC->FillRgn(&rgnKnob, CBrush::FromHandle(m_hKnobBrush)); } rgnKnob.DeleteObject(); if(m_bDrawRadioButton || m_bDragging) { DrawCircle(pDC, ptKnobCenter, --nKnobRadius, ::GetSysColor(COLOR_3DDKSHADOW), ::GetSysColor(COLOR_3DHIGHLIGHT)); DrawCircle(pDC, ptKnobCenter, --nKnobRadius, ::GetSysColor(COLOR_3DSHADOW), ::GetSysColor(COLOR_3DLIGHT)); } else { DrawCircle(pDC, ptKnobCenter, --nKnobRadius, ::GetSysColor(COLOR_3DHIGHLIGHT), ::GetSysColor(COLOR_3DDKSHADOW)); DrawCircle(pDC, ptKnobCenter, --nKnobRadius, ::GetSysColor(COLOR_3DLIGHT), ::GetSysColor(COLOR_3DSHADOW)); } // Draw the focus circle on the inside of the knob if(!m_bDrawRadioButton && (GetFocus() == this)) { DrawCircle(pDC, ptKnobCenter, nKnobRadius-2, RGB(0, 0, 0), TRUE); } // Draw the text const CString strFormattedText = OnFormatText(); if(!strFormattedText.IsEmpty()) { CFont* pOldFont = pDC->SelectObject(&m_font); const CSize szExtent = pDC->GetTextExtent(strFormattedText); const CPoint ptText = CPoint(m_ptCenter.x - szExtent.cx/2, m_ptCenter.y - szExtent.cy/2); const int nOldTextColor = pDC->SetTextColor(m_crText); pDC->SetBkMode(TRANSPARENT); if(bDisabled) { pDC->DrawState(ptText, szExtent, strFormattedText, DSS_DISABLED, TRUE, 0, (HBRUSH)NULL); } else { pDC->TextOut(ptText.x, ptText.y, strFormattedText); } // Clean up pDC->SelectObject(pOldFont); pDC->SetTextColor(nOldTextColor); } // Don't call CSliderCtrl::OnPaint() }
void CSliderCtrl::GetRange(int& nMin, int& nMax) { ASSERT(::IsWindow(m_hWnd)); nMin = GetRangeMin(); nMax = GetRangeMax(); }
void CmusikTrackCtrl::SetPosFromMouse() { CPoint pos; GetCursorPos( &pos ); ScreenToClient( &pos ); CRect rcClient; GetClientRect( &rcClient ); // vertical if ( GetStyle() & TBS_VERT ) { if ( pos.y >= rcClient.bottom && GetPos() != GetRangeMax() ) { SetPos( GetRangeMax() ); m_LastPos = GetRangeMax(); OnPosChanged(); return; } else if ( pos.y <= rcClient.top && GetPos() != GetRangeMin() ) { SetPos( GetRangeMin() ); m_LastPos = GetRangeMin(); OnPosChanged(); return; } else { int nLoc = rcClient.Height() - pos.y; float fRatio = (float)nLoc / rcClient.Height(); float nPos = (float)fRatio * (float)GetRangeMax(); int nFinal = GetRangeMax() - (int)nPos; if ( nFinal != m_LastPos ) { SetPos( nFinal ); m_LastPos = nFinal; OnPosChanged(); } return; } } // horizontal else { if ( pos.x >= rcClient.right && GetPos() != GetRangeMax() ) { SetPos( GetRangeMax() ); m_LastPos = GetRangeMax(); OnPosChanged(); return; } else if ( pos.x <= rcClient.left && GetPos() != GetRangeMin() ) { SetPos( GetRangeMin() ); m_LastPos = GetRangeMin(); OnPosChanged(); return; } else { int nLoc = rcClient.Width() - pos.x; float fRatio = (float)nLoc / rcClient.Width(); float nPos = (float)fRatio * (float)GetRangeMax(); int nFinal = GetRangeMax() - (int)nPos; if ( nFinal != m_LastPos ) { SetPos( nFinal ); m_LastPos = nFinal; OnPosChanged(); } return; } } }
void CColorSlide::GetRange(int& nMin, int& nMax) const { ASSERT(::IsWindow(m_hWnd)); nMin = GetRangeMin(); nMax = GetRangeMax(); }
double CEditSliderCtrl::GetValNorm() const { return(Norm(m_Val) / GetRangeMax()); }
void CEditSliderCtrl::SetValNorm(double Val) { SetVal(Denorm(Val * GetRangeMax())); }