void DrawSplit(const raytrace::CKDNode* pNode) { // No children, no split. if (!pNode->GetLeftChild()) return; AABB oBox = pNode->GetBounds(); size_t iSplitAxis = pNode->GetSplitAxis(); float flSplitPos = pNode->GetSplitPos(); // Construct four points that are the corners or a rectangle representing this portal split. Vector v0 = oBox.m_vecMins; v0[iSplitAxis] = flSplitPos; Vector v1 = v0; v1[(iSplitAxis+1)%3] = oBox.m_vecMaxs[(iSplitAxis+1)%3]; Vector v2 = v0; v2[(iSplitAxis+1)%3] = oBox.m_vecMaxs[(iSplitAxis+1)%3]; v2[(iSplitAxis+2)%3] = oBox.m_vecMaxs[(iSplitAxis+2)%3]; Vector v3 = v0; v3[(iSplitAxis+2)%3] = oBox.m_vecMaxs[(iSplitAxis+2)%3]; SMAKWindow()->AddDebugLine(v0, v1); SMAKWindow()->AddDebugLine(v1, v2); SMAKWindow()->AddDebugLine(v2, v3); SMAKWindow()->AddDebugLine(v3, v0); if (pNode->GetLeftChild()) DrawSplit(pNode->GetLeftChild()); if (pNode->GetRightChild()) DrawSplit(pNode->GetRightChild()); }
void StatusView::Draw(BRect update) { SetDrawingMode(B_OP_COPY); SetHighColor(tint_color(LowColor(), B_DARKEN_2_TINT)); StrokeLine(BPoint(update.left, Bounds().top), BPoint(update.right, Bounds().top)); #ifdef __HAIKU__ BRect rect(Bounds()); rect.top++; be_control_look->DrawMenuBarBackground(this, rect, update, LowColor()); #else SetHighColor(255, 255, 255, 255); StrokeLine(BPoint(update.left, Bounds().top + 1), BPoint(update.right, Bounds().top + 1)); #endif float width(5.0); font_height fh; GetFontHeight(&fh); SetDrawingMode(B_OP_OVER); SetHighColor(tint_color(LowColor(), 1.7)); for (int32 i = 0; i < items.CountItems(); ++i) { if (i) { DrawSplit(width += 3); width += 5; } StatusItem* item(ItemAt(i)); if (item->label.Length()) { DrawString(item->label.String(), BPoint(width, fh.ascent + fh.leading + 2)); } if (item->alignment == STATUS_ALIGN_RIGHT) width = item->frame.right - StringWidth(item->value.String()); else width = item->frame.left; DrawString(item->value.String(), BPoint(width, fh.ascent + fh.leading + 2)); width = item->frame.right; } }
//============================================================================= void CXButtonXP::DrawItem(LPDRAWITEMSTRUCT lpDIS) //============================================================================= { CDC *pDC = CDC::FromHandle(lpDIS->hDC); CRect rectItem = lpDIS->rcItem; // set up for double buffering CDC memDC; memDC.CreateCompatibleDC(pDC); CBitmap bmp; bmp.CreateCompatibleBitmap(pDC, rectItem.Width(), rectItem.Height()); CBitmap *pOldBitmap = memDC.SelectObject(&bmp); // initialize dc from existing dc memDC.BitBlt(0, 0, rectItem.Width(), rectItem.Height(), pDC, 0, 0, SRCCOPY); memDC.SetBkMode(TRANSPARENT); if (m_bFirstTime) { // open theme for Button m_bFirstTime = FALSE; if (ThemeHelper.IsThemeLibAvailable()) { if (m_hTheme) ThemeHelper.CloseThemeData(m_hTheme); m_hTheme = NULL; if (m_bDrawToolbar) { m_hTheme = ThemeHelper.OpenThemeData(m_hWnd, _T("Toolbar")); } else { m_hTheme = ThemeHelper.OpenThemeData(m_hWnd, _T("Button")); } } SaveParentBackground(); } CFont *pFont = GetParent()->GetFont(); if (pFont) memDC.SelectObject(pFont); // button state // get the button's title CString strTitle = _T(""); GetWindowText(strTitle); BOOL bHasText = !strTitle.IsEmpty(); BOOL bIsFocused = lpDIS->itemState & ODS_FOCUS; BOOL bIsDisabled = lpDIS->itemState & ODS_DISABLED; BOOL bDrawFocusRect = !(lpDIS->itemState & ODS_NOFOCUSRECT); BOOL bIsPressed = lpDIS->itemState & ODS_SELECTED; BOOL bIsDefault = IsDefault(); BOOL bIsThemed = IsThemed(); BOOL bCustomColors = (m_crBackground != XBUTTONXP_NO_COLOR) || (m_crText != XBUTTONXP_NO_COLOR); if (bCustomColors) { bIsThemed = FALSE; } if (m_bIsToggle) { if (m_bLButtonDown && !m_bMouseOverButton) { // left mouse button is down outside button bIsPressed = !m_bToggled; } else { bIsPressed = m_bToggled; } } if (m_bDrawToolbar) { // restore parent window bits memDC.BitBlt(0, 0, m_rectButton.Width(), m_rectButton.Height(), &m_dcParent, 0, 0, SRCCOPY); bIsFocused = FALSE; bIsDefault = FALSE; } if (bIsThemed) { DWORD state = bIsPressed ? PBS_PRESSED : PBS_NORMAL; if (bIsDisabled) { state = PBS_DISABLED; } else if (state == PBS_NORMAL) { if (bIsFocused || bIsDefault) { state = PBS_DEFAULTED; } if (m_bMouseOverButton) state = PBS_HOT; } ThemeHelper.DrawThemeParentBackground(m_hWnd, memDC.m_hDC, &rectItem); ThemeHelper.DrawThemeBackground(m_hTheme, memDC.m_hDC, BP_PUSHBUTTON, state, &rectItem, NULL); } else // not themed { CBrush brBackground; if (m_crBackground == XBUTTONXP_NO_COLOR) brBackground.CreateSolidBrush(GetSysColor(COLOR_BTNFACE)); else brBackground.CreateSolidBrush(m_crBackground); if (!m_bDrawToolbar || bCustomColors) { // fill in background, if custom color or not toolbar CRect rectClient(rectItem); InflateRect(&rectClient, -1, -1); memDC.FillRect(&rectClient, &brBackground); } if (bIsFocused || bIsDefault) { if (!m_bIsToggle || !bIsPressed) { CBrush brush(RGB(0,0,0)); memDC.FrameRect(&rectItem, &brush); } InflateRect(&rectItem, -1, -1); } // draw the traditional pushbutton edge if (bIsPressed) { memDC.DrawEdge(&rectItem, EDGE_SUNKEN, BF_RECT); } else if (!m_bDrawToolbar) { memDC.DrawEdge(&rectItem, EDGE_RAISED, BF_RECT); } } CRect rectDraw = lpDIS->rcItem; // draw the icon DrawIcon(&memDC, bHasText, rectItem, rectDraw, bIsPressed, bIsThemed, bIsDisabled); // draw the button title (if any) if (bHasText) { DrawText(&memDC, strTitle, rectDraw, bIsPressed, bIsThemed, bIsDisabled); } // draw the focus rect if (bIsFocused && bDrawFocusRect) { CRect rectFocus = rectItem; if (m_pDropDownMenu) rectFocus.right = rectFocus.right - MENUBTN_WIDTH + 1; if (!bIsThemed && bIsPressed) rectFocus.OffsetRect(1, 1); rectFocus.InflateRect(-3, -3); memDC.DrawFocusRect(&rectFocus); } if (m_pDropDownMenu) { DrawSplit(&memDC, rectItem, bIsPressed, bIsThemed, bIsDisabled); DrawArrow(&memDC, rectItem, bIsPressed, bIsThemed, bIsDisabled); } // end double buffering pDC->BitBlt(0, 0, rectItem.Width(), rectItem.Height(), &memDC, 0, 0, SRCCOPY); // swap back the original bitmap if (pOldBitmap) memDC.SelectObject(pOldBitmap); if (bmp.GetSafeHandle()) bmp.DeleteObject(); memDC.DeleteDC(); }