bool ASSISTANT::Oval::ContainsPoint(Gdiplus::PointF &ptMouse) { if (!visible) return false; CRect rcObject; GetBoundingBox(rcObject); CRgn rgnElliptic; double dMaxDistance = (double)lineWidth / 2 + 0.5; BOOL bRet = TRUE; if (IsFilled()) { CRgn rgnElliptic; bRet = rgnElliptic.CreateEllipticRgnIndirect(rcObject); if (!bRet) return false; if (rgnElliptic.PtInRegion((int)ptMouse.X, (int)ptMouse.Y)) return true; } else { CRect rcOutside = rcObject; rcOutside.InflateRect(dMaxDistance, dMaxDistance, dMaxDistance, dMaxDistance); bRet = rgnElliptic.CreateEllipticRgnIndirect(rcOutside); if (!bRet) return false; CRgn rgnElliptic2; CRect rcInside = rcObject; rcInside.DeflateRect(dMaxDistance, dMaxDistance, dMaxDistance, dMaxDistance); bRet = rgnElliptic2.CreateEllipticRgnIndirect(rcInside); if (!bRet) return false; rgnElliptic.CombineRgn(&rgnElliptic, &rgnElliptic2, RGN_DIFF); if (rgnElliptic.PtInRegion((int)ptMouse.X, (int)ptMouse.Y)) return true; } return false; }
void Tree::display(CPaintDC& dc, int x, int y, int age) { CBrush brushGreen(RGB(0, 255, 0)); int d = 20 + (age/2); CRect rcEllipse(CPoint(x, y), CSize(d, d)); CRgn rgnEllipse; rgnEllipse.CreateEllipticRgnIndirect(&rcEllipse); dc.FillRgn(&rgnEllipse, &brushGreen); }
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() }
// rect must be in logical coordinates BOOL CDrawRect::Intersects(const CRect& rect) { ASSERT_VALID(this); CRect rectT = rect; rectT.NormalizeRect(); CRect fixed = m_position; fixed.NormalizeRect(); if ((rectT & fixed).IsRectEmpty()) return FALSE; CRgn rgn; switch (m_nShape) { case rectangle: case text: return TRUE; case roundRectangle: rgn.CreateRoundRectRgn(fixed.left, fixed.top, fixed.right, fixed.bottom, m_roundness.x, m_roundness.y); break; case ellipse: rgn.CreateEllipticRgnIndirect(fixed); break; case line: { int x = (m_logpen.lopnWidth.x + 5) / 2; int y = (m_logpen.lopnWidth.y + 5) / 2; POINT points[4]; points[0].x = fixed.left; points[0].y = fixed.top; points[1].x = fixed.left; points[1].y = fixed.top; points[2].x = fixed.right; points[2].y = fixed.bottom; points[3].x = fixed.right; points[3].y = fixed.bottom; if (fixed.left < fixed.right) { points[0].x -= x; points[1].x += x; points[2].x += x; points[3].x -= x; } else { points[0].x += x; points[1].x -= x; points[2].x -= x; points[3].x += x; } if (fixed.top < fixed.bottom) { points[0].y -= y; points[1].y += y; points[2].y += y; points[3].y -= y; } else { points[0].y += y; points[1].y -= y; points[2].y -= y; points[3].y += y; } rgn.CreatePolygonRgn(points, 4, ALTERNATE); } break; } return rgn.RectInRegion(fixed); }