void SurfaceImpl::RectangleDraw(PRectangle rc, ColourAllocated fore, ColourAllocated back) { PenColour(fore); BrushColour(back); hdc->DrawRectangle(wxRectFromPRectangle(rc)); }
// Draw all tabs void wxTabView::Draw(wxDC& dc) { // Don't draw anything if there are no tabs. if (GetNumberOfTabs() == 0) return; // Draw top margin area (beneath tabs and above view area) if (GetTabStyle() & wxTAB_STYLE_COLOUR_INTERIOR) { dc.SetPen(*wxTRANSPARENT_PEN); if(GetBackgroundBrush()) dc.SetBrush(*GetBackgroundBrush()); // Add 1 because the pen is transparent. Under Motif, may be different. dc.DrawRectangle( m_tabViewRect.x, (m_tabViewRect.y - m_topMargin), (m_tabViewRect.width + 1), (m_topMargin + 1) ); } // Draw layers in reverse order wxTabLayerList::compatibility_iterator node = m_layers.GetLast(); while (node) { wxTabLayer *layer = (wxTabLayer *)node->GetData(); wxList::compatibility_iterator node2 = layer->GetFirst(); while (node2) { wxTabControl *control = (wxTabControl *)node2->GetData(); control->OnDraw(dc, (!node2->GetNext())); node2 = node2->GetNext(); } node = node->GetPrevious(); } #ifndef wxUSE_NEW_METHOD if (GetTabStyle() & wxTAB_STYLE_DRAW_BOX) { dc.SetPen(* GetShadowPen()); // Draw bottom line dc.DrawLine( (GetViewRect().x + 1), (GetViewRect().y + GetViewRect().height), (GetViewRect().x + GetViewRect().width + 1), (GetViewRect().y + GetViewRect().height) ); // Draw right line dc.DrawLine( (GetViewRect().x + GetViewRect().width), (GetViewRect().y - GetTopMargin() + 1), (GetViewRect().x + GetViewRect().width), (GetViewRect().y + GetViewRect().height) ); dc.SetPen(* wxBLACK_PEN); // Draw bottom line dc.DrawLine( (GetViewRect().x), (GetViewRect().y + GetViewRect().height + 1), #if defined(__WXMOTIF__) (GetViewRect().x + GetViewRect().width + 1), #else (GetViewRect().x + GetViewRect().width + 2), #endif (GetViewRect().y + GetViewRect().height + 1) ); // Draw right line dc.DrawLine( (GetViewRect().x + GetViewRect().width + 1), (GetViewRect().y - GetTopMargin()), (GetViewRect().x + GetViewRect().width + 1), (GetViewRect().y + GetViewRect().height + 1) ); } #endif }
void EDA_DOCKART::DrawBorder( wxDC& aDC, wxWindow* aWindow, const wxRect& aRect, wxAuiPaneInfo& aPane ) { const wxRect& r = aRect; aDC.SetPen( m_borderPen ); aDC.SetBrush( *wxTRANSPARENT_BRUSH ); // notebooks draw the border themselves, so they can use native rendering (e.g. tabartgtk) wxAuiTabArt* art = nullptr; wxAuiNotebook* nb = wxDynamicCast( aWindow, wxAuiNotebook ); if( nb ) art = nb->GetArtProvider(); if( art ) { art->DrawBorder( aDC, aWindow, r ); } else if( aPane.name == "DrawFrame" || aPane.name == "DrawFrameGal" ) { // We don't want to re-write the layout manager, so we give the canvas a single-pixel // border and then fill in the top and left with the canvas background colour. // // This achieves a right-bottom-bordered canvas, which works reasonably well with // wxWidgets right-bottom bordered toolbars. //wxWindow* window = reinterpret_cast<wxWindow*>( m_frame->GetCanvas() ); //wxSize scrollbarSize = window->GetSize() - window->GetClientSize(); // Not sure why it takes a pen twice as wide as the border to fill it in, but it does. #if 0 int borderWidth = GetMetric( wxAUI_DOCKART_PANE_BORDER_SIZE ) * 2; int borderAdjust = borderWidth; aDC.SetPen( wxPen( m_frame->GetDrawBgColor().ToColour(), borderWidth ) ); // Yes, this leaves me scratching my head too. if( m_frame->IsType( FRAME_PCB ) || m_frame->IsType( FRAME_PCB_MODULE_EDITOR ) || m_frame->IsType( FRAME_PCB_MODULE_VIEWER ) || m_frame->IsType( FRAME_PCB_MODULE_VIEWER_MODAL ) || m_frame->IsType( FRAME_GERBER ) ) { borderAdjust += 1; } // left aDC.DrawLine( r.x + 1, r.y, r.x + 1, r.y + r.height - borderAdjust - scrollbarSize.y ); // top aDC.DrawLine( r.x + 1, r.y, r.x + r.width - borderAdjust - scrollbarSize.x, r.y ); aDC.SetPen( m_borderPen ); // finish off bottom of left side (at end of scrollbar) aDC.DrawLine( r.x, r.y + r.height - 1 - scrollbarSize.y, r.x, r.y + r.height - 1 ); // right aDC.DrawLine( r.x + r.width, r.y, r.x + r.width, r.y + r.height - 1 ); // bottom aDC.DrawLine( r.x, r.y + r.height - 1, r.x + r.width - 1, r.y + r.height - 1 ); #endif } else { aDC.DrawRectangle( r ); } }
void wxCustomButton::Paint( wxDC &dc ) { #if (wxMINOR_VERSION<8) dc.BeginDrawing(); #endif int w, h; GetSize(&w,&h); wxColour foreColour = GetForegroundColour(); wxColour backColour = GetBackgroundColour(); if (m_focused) { backColour.Set( wxMin(backColour.Red() + 20, 255), wxMin(backColour.Green() + 20, 255), wxMin(backColour.Blue() + 20, 255) ); } wxBitmap bitmap; if (IsEnabled()) { if (GetValue() && m_bmpSelected.Ok()) bitmap = m_bmpSelected; else if (m_focused && m_bmpFocus.Ok()) bitmap = m_bmpFocus; else if (m_bmpLabel.Ok()) bitmap = m_bmpLabel; } else { // try to create disabled if it doesn't exist if (!m_bmpDisabled.Ok() && m_bmpLabel.Ok()) m_bmpDisabled = CreateBitmapDisabled(m_bmpLabel); if (m_bmpDisabled.Ok()) bitmap = m_bmpDisabled; else if (m_bmpLabel.Ok()) bitmap = m_bmpLabel; foreColour = wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT); } wxBrush brush(backColour, wxSOLID); dc.SetBackground(brush); dc.SetBrush(brush); dc.SetPen(*wxTRANSPARENT_PEN); dc.DrawRectangle(0, 0, w, h); if (bitmap.Ok()) dc.DrawBitmap(bitmap, m_bitmapPos.x, m_bitmapPos.y, TRUE ); if (!GetLabel().IsEmpty()) { dc.SetFont(GetFont()); dc.SetTextBackground(backColour); dc.SetTextForeground(foreColour); dc.DrawText(GetLabel(), m_labelPos.x, m_labelPos.y); } if (GetValue()) // draw sunken border { dc.SetPen(*wxGREY_PEN); dc.DrawLine(0,h-1,0,0); dc.DrawLine(0,0,w,0); dc.SetPen(*wxWHITE_PEN); dc.DrawLine(w-1,1,w-1,h-1); dc.DrawLine(w-1,h-1,0,h-1); dc.SetPen(*wxBLACK_PEN); dc.DrawLine(1,h-2,1,1); dc.DrawLine(1,1,w-1,1); } else if (((m_button_style & wxCUSTBUT_FLAT) == 0) || m_focused) // draw raised border { dc.SetPen(*wxWHITE_PEN); dc.DrawLine(0,h-2,0,0); dc.DrawLine(0,0,w-1,0); dc.SetPen(*wxBLACK_PEN); dc.DrawLine(w-1,0,w-1,h-1); dc.DrawLine(w-1,h-1,-1,h-1); dc.SetPen(*wxGREY_PEN); dc.DrawLine(2,h-2,w-2,h-2); dc.DrawLine(w-2,h-2,w-2,1); } dc.SetBackground(wxNullBrush); dc.SetBrush(wxNullBrush); dc.SetPen(wxNullPen); #if (wxMINOR_VERSION<8) dc.EndDrawing(); #endif }
void CLMainAuiTBArt::DrawButton(wxDC& dc, wxWindow* wnd, const wxAuiToolBarItem& item, const wxRect& rect) { wxAuiDefaultToolBarArt::DrawButton(dc, wnd, item, rect); #if 0 // if(!DrawingUtils::IsThemeDark()) { // wxAuiDefaultToolBarArt::DrawButton(dc, wnd, item, rect); // return; // } int textWidth = 0, textHeight = 0; if(m_flags & wxAUI_TB_TEXT) { dc.SetFont(m_font); int tx, ty; dc.GetTextExtent(wxT("ABCDHgj"), &tx, &textHeight); textWidth = 0; dc.GetTextExtent(item.GetLabel(), &textWidth, &ty); } int bmpX = 0, bmpY = 0; int textX = 0, textY = 0; if(m_textOrientation == wxAUI_TBTOOL_TEXT_BOTTOM) { bmpX = rect.x + (rect.width / 2) - (item.GetBitmap().GetWidth() / 2); bmpY = rect.y + ((rect.height - textHeight) / 2) - (item.GetBitmap().GetHeight() / 2); textX = rect.x + (rect.width / 2) - (textWidth / 2) + 1; textY = rect.y + rect.height - textHeight - 1; } else if(m_textOrientation == wxAUI_TBTOOL_TEXT_RIGHT) { bmpX = rect.x + 3; bmpY = rect.y + (rect.height / 2) - (item.GetBitmap().GetHeight() / 2); textX = bmpX + 3 + item.GetBitmap().GetWidth(); textY = rect.y + (rect.height / 2) - (textHeight / 2); } if(!(item.GetState() & wxAUI_BUTTON_STATE_DISABLED)) { if(item.GetState() & wxAUI_BUTTON_STATE_PRESSED) { dc.SetPen(wxPen(m_highlightColour)); dc.SetBrush(wxBrush(m_highlightColour.ChangeLightness(150))); dc.DrawRectangle(rect); } else if((item.GetState() & wxAUI_BUTTON_STATE_HOVER) || item.IsSticky()) { dc.SetPen(wxPen(m_highlightColour)); dc.SetBrush(wxBrush(m_highlightColour.ChangeLightness(170))); // draw an even lighter background for checked item hovers (since // the hover background is the same color as the check background) if(item.GetState() & wxAUI_BUTTON_STATE_CHECKED) dc.SetBrush(wxBrush(m_highlightColour.ChangeLightness(180))); dc.DrawRectangle(rect); } else if(item.GetState() & wxAUI_BUTTON_STATE_CHECKED) { // it's important to put this code in an else statement after the // hover, otherwise hovers won't draw properly for checked items dc.SetPen(wxPen(m_highlightColour)); dc.SetBrush(wxBrush(m_highlightColour.ChangeLightness(170))); dc.DrawRectangle(rect); } } wxBitmap bmp; if(item.GetState() & wxAUI_BUTTON_STATE_DISABLED) { bmp = CreateDisabledBitmap(item.GetBitmap()); } else bmp = item.GetBitmap(); if(bmp.IsOk()) dc.DrawBitmap(bmp, bmpX, bmpY, true); // set the item's text color based on if it is disabled dc.SetTextForeground(*wxBLACK); if(item.GetState() & wxAUI_BUTTON_STATE_DISABLED) dc.SetTextForeground(DISABLED_TEXT_COLOR); if((m_flags & wxAUI_TB_TEXT) && !item.GetLabel().empty()) { dc.DrawText(item.GetLabel(), textX, textY); } #endif }
void wxCustomButton::Paint( wxDC &dc ) { int w, h; GetSize(&w,&h); wxColour foreColour = GetForegroundColour(); wxColour backColour = GetBackgroundColour(); if (m_focused) { backColour.Set( wxMin(backColour.Red() + 20, 255), wxMin(backColour.Green() + 20, 255), wxMin(backColour.Blue() + 20, 255) ); } wxBitmap bitmap; if (IsEnabled()) { if (GetValue() && m_bmpSelected.Ok()) bitmap = m_bmpSelected; else if (m_focused && m_bmpFocus.Ok()) bitmap = m_bmpFocus; else if (m_bmpLabel.Ok()) bitmap = m_bmpLabel; } else { // try to create disabled if it doesn't exist if (!m_bmpDisabled.Ok() && m_bmpLabel.Ok()) m_bmpDisabled = CreateBitmapDisabled(m_bmpLabel); if (m_bmpDisabled.Ok()) bitmap = m_bmpDisabled; else if (m_bmpLabel.Ok()) bitmap = m_bmpLabel; foreColour = wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT); } #if wxCHECK_VERSION(2, 8, 0) // wxCONTROL_DISABLED //flags may have the wxCONTROL_PRESSED, wxCONTROL_CURRENT or wxCONTROL_ISDEFAULT int ren_flags = 0; if (GetValue()) ren_flags |= wxCONTROL_PRESSED; if (m_focused) ren_flags |= wxCONTROL_CURRENT; if (!IsEnabled()) ren_flags |= wxCONTROL_DISABLED; wxRendererNative::Get().DrawPushButton(this, dc, wxRect(0, 0, w, h), ren_flags); #else wxBrush brush(backColour, wxSOLID); dc.SetBackground(brush); dc.SetBrush(brush); dc.SetPen(*wxTRANSPARENT_PEN); dc.DrawRectangle(0, 0, w, h); #endif // !wxCHECK_VERSION(2, 8, 0) if (bitmap.Ok()) dc.DrawBitmap(bitmap, m_bitmapPos.x, m_bitmapPos.y, true ); if (!GetLabel().IsEmpty()) { dc.SetFont(GetFont()); dc.SetTextBackground(backColour); dc.SetTextForeground(foreColour); dc.DrawText(GetLabel(), m_labelPos.x, m_labelPos.y); } #if !wxCHECK_VERSION(2, 8, 0) if (GetValue()) // draw sunken border { dc.SetPen(*wxGREY_PEN); dc.DrawLine(0,h-1,0,0); dc.DrawLine(0,0,w,0); dc.SetPen(*wxWHITE_PEN); dc.DrawLine(w-1,1,w-1,h-1); dc.DrawLine(w-1,h-1,0,h-1); dc.SetPen(*wxBLACK_PEN); dc.DrawLine(1,h-2,1,1); dc.DrawLine(1,1,w-1,1); } else if (((m_button_style & wxCUSTBUT_FLAT) == 0) || m_focused) // draw raised border { dc.SetPen(*wxWHITE_PEN); dc.DrawLine(0,h-2,0,0); dc.DrawLine(0,0,w-1,0); dc.SetPen(*wxBLACK_PEN); dc.DrawLine(w-1,0,w-1,h-1); dc.DrawLine(w-1,h-1,-1,h-1); dc.SetPen(*wxGREY_PEN); dc.DrawLine(2,h-2,w-2,h-2); dc.DrawLine(w-2,h-2,w-2,1); } #endif // !wxCHECK_VERSION(2, 8, 0) dc.SetBackground(wxNullBrush); dc.SetBrush(wxNullBrush); dc.SetPen(wxNullPen); }
// // Draw the grabber // void Grabber::DrawGrabber( wxDC & dc ) { wxRect r = GetRect(); // PaintDC positions are relative to the grabber, not the parent window. // So use 0,0 as origin for draw, so that the grabber draws right if // positioned in its parent at some non zero position. r.SetPosition( wxPoint(0,0) ); int y, left, right, top, bottom; #ifndef EXPERIMENTAL_THEMING AColor::Medium(&dc, mOver ); dc.DrawRectangle(r); // HACK: We used a wider rectangle to also cover one pixel of space just to the right. if( mAsSpacer ) r.width -= 1; #else // Paint the background if( mOver ) { AColor::Medium(&dc, mOver ); dc.DrawRectangle(r); } else { // Get colour from parent... // when parent colour changes, child colour might not! wxBrush brush( GetParent()->GetBackgroundColour() ); dc.SetBrush( brush ); dc.DrawRectangle(r); } #endif #ifndef __WXMAC__ // Add a box r.width -= 1; r.height -= 1; AColor::Bevel(dc, !mPressed, r); r.width += 1; r.height += 1; #endif // No bumps in a spacer grabber. if( mAsSpacer ) return; // Calculate the bump rectangle r.Deflate(3, 3); if ((r.GetHeight() % 4) < 2) { r.Offset(0, 1); } // Cache left = r.GetLeft(); right = r.GetRight(); top = r.GetTop(); bottom = r.GetBottom(); // Draw the raised bumps if (mPressed) { AColor::Dark(&dc, false); } else { AColor::Light(&dc, false); } for (y = top; y < bottom; y += 4) { AColor::Line(dc, left, y, right, y); } // Draw the pushed bumps if (mPressed) { AColor::Light(&dc, false); } else { AColor::Dark(&dc, false); } for (y = top + 1; y <= bottom; y += 4) { AColor::Line(dc, left, y, right, y); } }
void LabelTrack::Draw(wxDC & dc, wxRect & r, double h, double pps, double sel0, double sel1) { double right = h + r.width / pps; double dsel0 = sel0; if (dsel0 < h) dsel0 = h; if (dsel0 > right) dsel0 = right; double dsel1 = sel1; if (dsel1 < h) dsel1 = h; if (dsel1 > right) dsel1 = right; wxRect before = r; before.width = int ((dsel0 - h) * pps); dc.SetBrush(mUnselectedBrush); dc.SetPen(mUnselectedPen); dc.DrawRectangle(before); wxRect selr = r; selr.x += before.width; selr.width = int ((dsel1 - dsel0) * pps); dc.SetBrush(mSelectedBrush); dc.SetPen(mSelectedPen); dc.DrawRectangle(selr); wxRect after = r; after.x += (before.width + selr.width); after.width -= (before.width + selr.width); if (after.x < r.x) { after.width -= (r.x - after.x); after.x = r.x; } dc.SetBrush(mUnselectedBrush); dc.SetPen(mUnselectedPen); dc.DrawRectangle(after); dc.SetBrush(mFlagBrush); dc.SetPen(mFlagPen); int nextx = 0; for (int i = 0; i < (int)mLabels.Count(); i++) { int x = r.x + (int) ((mLabels[i]->t - h) * pps); int y = r.y; int height = r.height; if (x >= r.x && x < r.x + r.width) { if (x < nextx && i != mSelIndex) { // Draw flag obscured by the previous label dc.DrawLine(x, y, x, y + 2); dc.DrawLine(x, y + height - 2, x, y + height); mLabels[i]->width = 0; } else { // Draw the flag and label wxPoint tri[3]; tri[0].x = x; tri[0].y = y; tri[1].x = x - 8; tri[1].y = y + 4; tri[2].x = x; tri[2].y = y + 8; if (mSelIndex == i) dc.SetBrush(*wxWHITE_BRUSH); dc.DrawPolygon(3, tri); if (mSelIndex == i) dc.SetBrush(mFlagBrush); dc.DrawLine(x, y, x, y + height); dc.SetTextForeground(wxColour(204, 0, 0)); #ifdef __WXMAC__ long textWidth, textHeight; #else int textWidth, textHeight; #endif dc.GetTextExtent(mLabels[i]->title, &textWidth, &textHeight); dc.DrawText(mLabels[i]->title, x + 4, y + 4); if (i == mSelIndex) { wxRect outline; outline.x = x + 2; outline.y = y + 2; outline.width = textWidth + 4; outline.height = height - 4; dc.SetBrush(*wxTRANSPARENT_BRUSH); dc.DrawRectangle(outline); dc.SetBrush(mFlagBrush); } mLabels[i]->width = textWidth + 8; nextx = x + textWidth + 8; } } } }
void clRowEntry::Render(wxWindow* win, wxDC& dc, const clColours& c, int row_index, clSearchText* searcher) { wxUnusedVar(searcher); wxRect rowRect = GetItemRect(); bool zebraColouring = (m_tree->HasStyle(wxTR_ROW_LINES) || m_tree->HasStyle(wxDV_ROW_LINES)); bool even_row = ((row_index % 2) == 0); // Define the clipping region bool hasHeader = (m_tree->GetHeader() && !m_tree->GetHeader()->empty()); // Not cell related clColours colours = c; if(zebraColouring) { // Set Zebra colouring, only if no user colour was provided for the given line colours.SetItemBgColour(even_row ? c.GetAlternateColour() : c.GetBgColour()); } // Override default item bg colour with the user's one if(GetBgColour().IsOk()) { colours.SetItemBgColour(GetBgColour()); } wxRect selectionRect = rowRect; wxPoint deviceOrigin = dc.GetDeviceOrigin(); selectionRect.SetX(-deviceOrigin.x); if(IsSelected()) { DrawSimpleSelection(win, dc, selectionRect, colours); } else if(IsHovered()) { dc.SetPen(colours.GetHoverBgColour()); dc.SetBrush(colours.GetHoverBgColour()); dc.DrawRectangle(selectionRect); } else if(colours.GetItemBgColour().IsOk()) { dc.SetBrush(colours.GetItemBgColour()); dc.SetPen(colours.GetItemBgColour()); dc.DrawRectangle(selectionRect); } // Per cell drawings for(size_t i = 0; i < m_cells.size(); ++i) { bool last_cell = (i == (m_cells.size() - 1)); colours = c; // reset the colours wxFont f = clScrolledPanel::GetDefaultFont(); clCellValue& cell = GetColumn(i); if(cell.GetFont().IsOk()) { f = cell.GetFont(); } if(cell.GetTextColour().IsOk()) { colours.SetItemTextColour(cell.GetTextColour()); } if(cell.GetBgColour().IsOk()) { colours.SetItemBgColour(cell.GetBgColour()); } dc.SetFont(f); wxColour buttonColour = IsSelected() ? colours.GetSelbuttonColour() : colours.GetButtonColour(); wxRect cellRect = GetCellRect(i); // We use a helper class to clip the drawings this ensures that if we exit the scope // the clipping region is restored properly clClipperHelper clipper(dc); if(hasHeader) { clipper.Clip(cellRect); } int textXOffset = cellRect.GetX(); if((i == 0) && !IsListItem()) { // The expand button is only make sense for the first cell if(HasChildren()) { wxRect buttonRect = GetButtonRect(); buttonRect.Deflate(1); textXOffset += buttonRect.GetWidth(); if(m_tree->IsNativeTheme() && !IS_OSX) { int flags = wxCONTROL_CURRENT; if(IsExpanded()) { flags |= wxCONTROL_EXPANDED; } int button_width = wxSystemSettings::GetMetric(wxSYS_SMALLICON_X); wxRect modButtonRect = buttonRect; modButtonRect.SetWidth(button_width); modButtonRect.SetHeight(button_width); modButtonRect = modButtonRect.CenterIn(buttonRect); wxRendererNative::Get().DrawTreeItemButton(win, dc, modButtonRect, flags); } else { wxRect buttonRect = GetButtonRect(); if(textXOffset >= cellRect.GetWidth()) { // if we cant draw the button (off screen etc) SetRects(GetItemRect(), wxRect()); continue; } buttonRect.Deflate((buttonRect.GetWidth() / 3), (buttonRect.GetHeight() / 3)); wxRect tribtn = buttonRect; dc.SetPen(wxPen(buttonColour, 2)); if(IsExpanded()) { tribtn.SetHeight(tribtn.GetHeight() - tribtn.GetHeight() / 2); tribtn = tribtn.CenterIn(buttonRect); wxPoint middleLeft = wxPoint((tribtn.GetLeft() + tribtn.GetWidth() / 2), tribtn.GetBottom()); dc.DrawLine(tribtn.GetTopLeft(), middleLeft); dc.DrawLine(tribtn.GetTopRight(), middleLeft); } else { tribtn.SetWidth(tribtn.GetWidth() - tribtn.GetWidth() / 2); tribtn = tribtn.CenterIn(buttonRect); wxPoint middleLeft = wxPoint(tribtn.GetRight(), (tribtn.GetY() + (tribtn.GetHeight() / 2))); wxPoint p1 = tribtn.GetTopLeft(); wxPoint p2 = tribtn.GetBottomLeft(); dc.DrawLine(p1, middleLeft); dc.DrawLine(middleLeft, p2); } } } else { wxRect buttonRect(rowRect); buttonRect.SetWidth(rowRect.GetHeight()); buttonRect.Deflate(1); textXOffset += buttonRect.GetWidth(); if(textXOffset >= cellRect.GetWidth()) { SetRects(GetItemRect(), wxRect()); continue; } } } int itemIndent = IsListItem() ? clHeaderItem::X_SPACER : (GetIndentsCount() * m_tree->GetIndent()); int bitmapIndex = cell.GetBitmapIndex(); if(IsExpanded() && HasChildren() && cell.GetBitmapSelectedIndex() != wxNOT_FOUND) { bitmapIndex = cell.GetBitmapSelectedIndex(); } // Draw checkbox if(cell.IsBool()) { // Render the checkbox textXOffset += X_SPACER; int checkboxSize = GetCheckBoxWidth(win); wxRect checkboxRect = wxRect(textXOffset, rowRect.GetY(), checkboxSize, checkboxSize); checkboxRect = checkboxRect.CenterIn(rowRect, wxVERTICAL); dc.SetPen(colours.GetItemTextColour()); RenderCheckBox(win, dc, colours, checkboxRect, cell.GetValueBool()); cell.SetCheckboxRect(checkboxRect); textXOffset += checkboxRect.GetWidth(); textXOffset += X_SPACER; } else { cell.SetCheckboxRect(wxRect()); // clear the checkbox rect } // Draw the bitmap if(bitmapIndex != wxNOT_FOUND) { const wxBitmap& bmp = m_tree->GetBitmap(bitmapIndex); if(bmp.IsOk()) { textXOffset += IsListItem() ? 0 : X_SPACER; int bitmapY = rowRect.GetY() + ((rowRect.GetHeight() - bmp.GetScaledHeight()) / 2); // if((textXOffset + bmp.GetScaledWidth()) >= cellRect.GetWidth()) { continue; } dc.DrawBitmap(bmp, itemIndent + textXOffset, bitmapY, true); textXOffset += bmp.GetScaledWidth(); textXOffset += X_SPACER; } } // Draw the text wxRect textRect(dc.GetTextExtent(cell.GetValueString())); textRect = textRect.CenterIn(rowRect, wxVERTICAL); int textY = textRect.GetY(); int textX = (i == 0 ? itemIndent : clHeaderItem::X_SPACER) + textXOffset; RenderText(win, dc, colours, cell.GetValueString(), textX, textY, i); textXOffset += textRect.GetWidth(); textXOffset += X_SPACER; if(cell.IsChoice()) { // draw the drop down arrow. Make it aligned to the right wxRect dropDownRect(cellRect.GetTopRight().x - rowRect.GetHeight(), rowRect.GetY(), rowRect.GetHeight(), rowRect.GetHeight()); dropDownRect = dropDownRect.CenterIn(rowRect, wxVERTICAL); DrawingUtils::DrawDropDownArrow(win, dc, dropDownRect, wxNullColour); // Keep the rect to test clicks cell.SetDropDownRect(dropDownRect); textXOffset += dropDownRect.GetWidth(); textXOffset += X_SPACER; // Draw a separator line between the drop down arrow and the rest of the cell content dropDownRect.Deflate(3); dropDownRect = dropDownRect.CenterIn(rowRect, wxVERTICAL); dc.SetPen(wxPen(colours.GetHeaderVBorderColour(), 1, PEN_STYLE)); dc.DrawLine(dropDownRect.GetTopLeft(), dropDownRect.GetBottomLeft()); } else { cell.SetDropDownRect(wxRect()); } if(!last_cell) { cellRect.SetHeight(rowRect.GetHeight()); dc.SetPen(wxPen(colours.GetHeaderVBorderColour(), 1, PEN_STYLE)); dc.DrawLine(cellRect.GetTopRight(), cellRect.GetBottomRight()); } } }
void MyDayInfoPlot::DrawPricePlot(wxDC&dc){ TotalDayInfoStru MyDays[TOTAY_DAYS_MYDAYINFO]; double MaxSz,MinSz,MaxSh,MinSh,MaxTotal,MinTotal,MaxDelta,MinDelta; MaxSz=MinSz=MaxSh=MinSh=MaxTotal=MinTotal=MaxDelta=MinDelta=0; for (int tidx=0;tidx<TOTAY_DAYS_MYDAYINFO;tidx++){ MyDays[tidx].Valid=false; } wxString keyPath=WStockConfig::GetMyDayInfoPath(); wxFileName keyf(keyPath); keyf.MakeAbsolute(); xmlDocPtr doc=NULL; if (keyf.FileExists()){ //Load Stocks Name From file doc = xmlParseFile((const char*)keyf.GetFullPath().mb_str()); } //If Load Fail, Create the Xml Memory if (doc==NULL){ dc.DrawText(_("No Info File Found!"),10,10); return; } for (xmlNodePtr node=doc->children->children;node;node=node->next){ if (xmlStrcmp(node->name,(const xmlChar*)"DayInfo")==0){ wxString Date(wxConvUTF8.cMB2WC( (char*)xmlGetProp(node, (const xmlChar*)"Date")),*wxConvCurrent); wxString Sz(wxConvUTF8.cMB2WC( (char*)xmlGetProp(node, (const xmlChar*)"ShenZhen")),*wxConvCurrent); wxString Sh(wxConvUTF8.cMB2WC( (char*)xmlGetProp(node, (const xmlChar*)"ShangHai")),*wxConvCurrent); wxString Total(wxConvUTF8.cMB2WC( (char*)xmlGetProp(node, (const xmlChar*)"Total")),*wxConvCurrent); wxString Delta(wxConvUTF8.cMB2WC( (char*)xmlGetProp(node, (const xmlChar*)"TodayEarning")),*wxConvCurrent); wxDateTime date; date.ParseDate(Date); int idx=(wxDateTime::Today()-date).GetDays(); if (idx<TOTAY_DAYS_MYDAYINFO){ Sz.ToDouble(&MyDays[idx].sz); Sh.ToDouble(&MyDays[idx].sh); Total.ToDouble(&MyDays[idx].total); Delta.ToDouble(&MyDays[idx].delta); MyDays[idx].Valid = true; MyDays[idx].date = date; } } } int i; for (i=0;i<TOTAY_DAYS_MYDAYINFO;i++){ if (MyDays[i].Valid){ if (MyDays[i].sz>MaxSz) MaxSz = MyDays[i].sz; if (MyDays[i].sz<MinSz) MinSz = MyDays[i].sz; if (MyDays[i].sh>MaxSh) MaxSh = MyDays[i].sh; if (MyDays[i].sh<MinSh) MinSh = MyDays[i].sh; if (MyDays[i].total>MaxTotal) MaxTotal = MyDays[i].total; if (MyDays[i].total<MinTotal) MinTotal = MyDays[i].total; if (MyDays[i].delta>MaxDelta) MaxDelta = MyDays[i].delta; if (MyDays[i].delta<MinDelta) MinDelta = MyDays[i].delta; } } dc.SetPen(wxPen(*wxBLACK,3)); int XStart=100,YStart=10,YFree=60; int TotalY=dc.GetSize().y-30-YFree; int XTotal = dc.GetSize().x-110; float TotalDelta=0; if (MinDelta<0) TotalDelta = MaxTotal - MinDelta+YFree; else TotalDelta = MaxTotal+YFree; if (TotalDelta<0.0003) TotalDelta = 1; int ZeroY = (int)(double)(TotalY/TotalDelta * MaxTotal + YStart); dc.DrawLine(XStart,YStart,XStart,YStart + TotalY + YFree); dc.DrawLine(XStart-10,ZeroY,XStart+XTotal,ZeroY); for (i=0;i<TOTAY_DAYS_MYDAYINFO;i++){ if (MyDays[i].Valid){ int MyTotalY=(int)(double)(ZeroY - TotalY/TotalDelta * MyDays[i].total); int MyDeltaY=(int)(double)(ZeroY - TotalY/TotalDelta * MyDays[i].delta); dc.SetBrush(*wxBLACK_BRUSH); dc.DrawRectangle(XStart+(i+1)*(XTotal / (TOTAY_DAYS_MYDAYINFO + 1)) - 5,MyTotalY,10,Abs(ZeroY-MyTotalY)); dc.SetBrush(*wxGREEN_BRUSH); dc.DrawRectangle(XStart+(i+1)*(XTotal / (TOTAY_DAYS_MYDAYINFO + 1)) - 5,MyDeltaY,10,Abs(ZeroY-MyDeltaY)); //wxLogMessage(wxT("Draw Rect at:%d %d %d %d"),(int)(XStart+(i+1)*(XTotal / (TOTAY_DAYS_MYDAYINFO + 1)) - 5), //MyDeltaY,10,Abs(ZeroY-MyDeltaY)); dc.DrawText(MyDays[i].date.FormatISODate(),XStart+(i+1)*(XTotal / (TOTAY_DAYS_MYDAYINFO + 1))-30,YStart+TotalY); } } }
void FillAreaDraw::Draw(wxDC &dc, wxRect rc) { dc.SetPen(m_borderPen); dc.SetBrush(m_fillBrush); dc.DrawRectangle(rc); }
void TGraphScale::drawit ( wxDC &dc , wxRect &r , wxRect &inner ) { wxRect ir = CalcInternalRect ( r ) ; int border = 2 ; if ( horizontal ) { if ( ir.x < inner.x ) ir.x = inner.x ; while ( ir.GetRight() > inner.GetRight() ) ir.width-- ; outline = ir ; ir.height -= border*2 ; ir.y += border ; } else { if ( ir.y < inner.y ) ir.y = inner.y ; while ( ir.GetBottom() > inner.GetBottom() ) ir.height-- ; outline = ir ; ir.width -= border*2 ; ir.x += border ; } // Selected? Draw nice background! if ( selected ) { dc.SetPen ( *MYPEN ( TGraphDisplay::prettyColor ) ) ; dc.SetBrush ( *MYBRUSH ( TGraphDisplay::prettyColor ) ) ; dc.DrawRectangle ( outline ) ; dc.SetBrush ( *wxTRANSPARENT_BRUSH ) ; } // Calculate major and minor units float multiplier = 10 ; //( unit == _T("s") ) ? 6 : 10 ; float factor = 1 ; while ( factor <= max ) factor *= multiplier ; float f2 = top - bottom ; while ( factor >= f2 ) factor /= multiplier ; float major = factor ; float minor = major / 5 ; // Draw scale dc.SetFont ( *MYFONT ( 8 , wxMODERN , wxNORMAL , wxNORMAL ) ) ; dc.SetTextForeground ( col ) ; dc.SetPen ( *MYPEN ( col ) ) ; float p = 0 ; while ( p > bottom ) p -= minor ; while ( p < bottom ) p += minor ; if ( p != bottom ) p -= minor ; while ( p <= top ) { wxString label ; /* if ( unit == _T("s") ) label = wxString::Format ( _T("%d:%2d") , p / 60 , ((int)p) % 60 ) ; else */label = wxString::Format ( _T("%f") , p ) ; DrawMark ( dc , p , ir , label , ( p - ((int)(p/major))*major ) == 0 ) ; p += minor ; } // Draw "backline" and name/unit wxString text = name ; if ( !unit.IsEmpty() ) text += _T(" [") + unit + _T("]") ; int tw , th ; dc.GetTextExtent ( text , &tw , &th ) ; if ( horizontal ) { if ( left ) { dc.DrawLine ( ir.x , ir.y , ir.GetRight() , ir.y ) ; dc.DrawText ( text , ir.x , ir.y ) ; } else { dc.DrawLine ( ir.x , ir.GetBottom() , ir.GetRight() , ir.GetBottom() ) ; dc.DrawText ( text , ir.x , ir.GetBottom() - th ) ; } if ( show_mark ) { int c = GetRealCoord ( GetVirtualCoordinate ( mark , inner ) , inner ) ; dc.SetPen ( *wxRED_PEN ) ; dc.DrawLine ( c , ir.GetTop() , c , ir.GetBottom() ) ; } } else { if ( left ) { dc.DrawLine ( ir.x , ir.y , ir.x , ir.GetBottom() ) ; dc.DrawRotatedText ( text , ir.x + 2 , ir.GetBottom() , 90 ) ; } else { dc.DrawLine ( ir.GetRight() , ir.y , ir.GetRight() , ir.GetBottom() ) ; dc.DrawRotatedText ( text , ir.GetRight()-th , ir.GetBottom() , 90 ) ; } if ( show_mark ) { int c = GetRealCoord ( GetVirtualCoordinate ( mark , inner ) , inner ) ; dc.SetPen ( *wxRED_PEN ) ; dc.DrawLine ( ir.GetLeft() , c , ir.GetRight() , c ) ; } } last_inner = inner ; show_mark = false ; }
void clAuiDockArt::DrawCaption(wxDC& dc, wxWindow* window, const wxString& text, const wxRect& rect, wxAuiPaneInfo& pane) { wxRect tmpRect(wxPoint(0, 0), rect.GetSize()); // Hackishly prevent assertions on linux if(tmpRect.GetHeight() == 0) tmpRect.SetHeight(1); if(tmpRect.GetWidth() == 0) tmpRect.SetWidth(1); #ifdef __WXOSX__ tmpRect = rect; window->PrepareDC(dc); // Prepare the colours wxColour bgColour, penColour, textColour; textColour = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT); bgColour = DrawingUtils::DarkColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE), 2.0); ; // Same as the notebook background colour penColour = wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW); penColour = bgColour; wxFont f = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); dc.SetFont(f); dc.SetPen(penColour); dc.SetBrush(bgColour); dc.DrawRectangle(tmpRect); // Fill the caption to look like OSX caption wxColour topColour("#d3d2d3"); wxColour bottomColour("#e8e8e8"); dc.GradientFillLinear(tmpRect, topColour, bottomColour, wxNORTH); dc.SetPen(penColour); dc.SetBrush(*wxTRANSPARENT_BRUSH); dc.DrawRectangle(tmpRect); int caption_offset = 0; if(pane.icon.IsOk()) { DrawIcon(dc, tmpRect, pane); caption_offset += pane.icon.GetWidth() + 3; } else { caption_offset = 3; } dc.SetTextForeground(textColour); wxCoord w, h; dc.GetTextExtent(wxT("ABCDEFHXfgkj"), &w, &h); wxRect clip_rect = tmpRect; clip_rect.width -= 3; // text offset clip_rect.width -= 2; // button padding if(pane.HasCloseButton()) clip_rect.width -= m_buttonSize; if(pane.HasPinButton()) clip_rect.width -= m_buttonSize; if(pane.HasMaximizeButton()) clip_rect.width -= m_buttonSize; wxString draw_text = wxAuiChopText(dc, text, clip_rect.width); wxSize textSize = dc.GetTextExtent(draw_text); dc.SetTextForeground(textColour); dc.DrawText(draw_text, tmpRect.x + 3 + caption_offset, tmpRect.y + ((tmpRect.height - textSize.y) / 2)); #else wxBitmap bmp(tmpRect.GetSize()); { wxMemoryDC memDc; memDc.SelectObject(bmp); wxGCDC gdc; wxDC* pDC = NULL; if(!DrawingUtils::GetGCDC(memDc, gdc)) { pDC = &memDc; } else { pDC = &gdc; } // Prepare the colours wxColour bgColour, penColour, textColour; textColour = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT); bgColour = DrawingUtils::DarkColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE), 2.0); ; // Same as the notebook background colour penColour = wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW); penColour = bgColour; wxFont f = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); pDC->SetFont(f); pDC->SetPen(penColour); pDC->SetBrush(bgColour); pDC->DrawRectangle(tmpRect); pDC->SetPen(penColour); pDC->SetBrush(*wxTRANSPARENT_BRUSH); pDC->DrawRectangle(tmpRect); int caption_offset = 0; if(pane.icon.IsOk()) { DrawIcon(gdc, tmpRect, pane); caption_offset += pane.icon.GetWidth() + 3; } else { caption_offset = 3; } pDC->SetTextForeground(textColour); wxCoord w, h; pDC->GetTextExtent(wxT("ABCDEFHXfgkj"), &w, &h); wxRect clip_rect = tmpRect; clip_rect.width -= 3; // text offset clip_rect.width -= 2; // button padding if(pane.HasCloseButton()) clip_rect.width -= m_buttonSize; if(pane.HasPinButton()) clip_rect.width -= m_buttonSize; if(pane.HasMaximizeButton()) clip_rect.width -= m_buttonSize; wxString draw_text = wxAuiChopText(gdc, text, clip_rect.width); wxSize textSize = pDC->GetTextExtent(draw_text); pDC->SetTextForeground(textColour); pDC->DrawText(draw_text, tmpRect.x + 3 + caption_offset, tmpRect.y + ((tmpRect.height - textSize.y) / 2)); memDc.SelectObject(wxNullBitmap); } dc.DrawBitmap(bmp, rect.x, rect.y, true); #endif }
void SurfaceImpl::FillRectangle(PRectangle rc, ColourAllocated back) { BrushColour(back); hdc->SetPen(*wxTRANSPARENT_PEN); hdc->DrawRectangle(wxRectFromPRectangle(rc)); }
void CParameter::DrawFore(wxDC& dc, wxRect& rc) { m_iSamplesPerPixel = m_pTracks->GetSamplesPerPixel(); if(m_fMax == 0.f) return; m_fScale = (float)rc.GetHeight() / (float)(m_fMax - m_fMin); int start = m_pRegion->GetStartPos(); int end = m_pRegion->GetEndPos(); int offset = m_pRegion->GetStartOffset(); int top = rc.GetTop(); int bottom = rc.GetTop() + rc.GetHeight(); int left = rc.GetX() + 1; int right = left + rc.GetWidth() - 1; float value = 0.f; int prevX = left; int prevY = bottom; int pos = m_bAfterTrack ? 0 : start; bool bLoaded = false; bool bDrawCircle = true; if(!m_pInput->GetParamAt(pos, m_index, &value)) { pos = m_pInput->GetPrevOffset(pos); bDrawCircle = false; } else bLoaded = true; wxPen oldpen = dc.GetPen(); wxColor color = m_color; if( IsSelected() ) color.Set(255-color.Red(), 255-color.Green(), 255-color.Blue()); dc.SetPen( wxPen(color) ); do { if(m_pInput->GetParamAt(pos, m_index, &value)) { bLoaded = true; int x = pos; int y = (int)((float)bottom - (value * m_fScale)); if(y>top && y<bottom) { if(m_bAfterTrack && offset>=0) x += start - offset; x /= m_iSamplesPerPixel; if(x <= left) prevX = left; else if(x >= right) y = prevY; else { dc.DrawLine(prevX, prevY, x, prevY); // Horizontal line dc.DrawLine(x, prevY, x, y); // Vertical line if( bDrawCircle ) { if(m_pSelectedPoint && m_pSelectedPoint->m_offset==pos && m_pSelectedPoint->m_value==value) { dc.DrawRectangle(x-3, y-3, 6, 6); // Selected parameter } else dc.DrawCircle(x, y, 3); // Parameter } prevX = x; } bDrawCircle = true; prevY = y; } } pos = m_pInput->GetNextOffset(pos); } while ( pos>0 && pos<end && prevX<right ); if(bLoaded && prevX<right) // there have been parameters! dc.DrawLine(prevX, prevY, right, prevY); dc.SetPen(oldpen); }
int NoteTrack::DrawLabelControls(wxDC & dc, wxRect & r) { int wid = 23; int ht = 16; if (r.height < ht * 4) { return r.y + 5 + ht * 4; } int x = r.x + (r.width / 2 - wid * 2) + 2; int y = r.y + 5; wxRect box; for (int row = 0; row < 4; row++) { for (int col = 0; col < 4; col++) { // chanName is the "external" channel number (1-16) // used by AColor and button labels int chanName = row * 4 + col + 1; box.x = x + col * wid; box.y = y + row * ht; box.width = wid; box.height = ht; if (IsVisibleChan(chanName - 1)) { AColor::MIDIChannel(&dc, chanName); dc.DrawRectangle(box); // two choices: channel is enabled (to see and play) when button is in // "up" position (original Audacity style) or in "down" position // #define CHANNEL_ON_IS_DOWN 1 #if CHANNEL_ON_IS_DOWN AColor::DarkMIDIChannel(&dc, chanName); #else AColor::LightMIDIChannel(&dc, chanName); #endif AColor::Line(dc, box.x, box.y, box.x + box.width - 1, box.y); AColor::Line(dc, box.x, box.y, box.x, box.y + box.height - 1); #if CHANNEL_ON_IS_DOWN AColor::LightMIDIChannel(&dc, chanName); #else AColor::DarkMIDIChannel(&dc, chanName); #endif AColor::Line(dc, box.x + box.width - 1, box.y, box.x + box.width - 1, box.y + box.height - 1); AColor::Line(dc, box.x, box.y + box.height - 1, box.x + box.width - 1, box.y + box.height - 1); } else { AColor::MIDIChannel(&dc, 0); dc.DrawRectangle(box); #if CHANNEL_ON_IS_DOWN AColor::LightMIDIChannel(&dc, 0); #else AColor::DarkMIDIChannel(&dc, 0); #endif AColor::Line(dc, box.x, box.y, box.x + box.width - 1, box.y); AColor::Line(dc, box.x, box.y, box.x, box.y + box.height - 1); #if CHANNEL_ON_IS_DOWN AColor::DarkMIDIChannel(&dc, 0); #else AColor::LightMIDIChannel(&dc, 0); #endif AColor::Line(dc, box.x + box.width - 1, box.y, box.x + box.width - 1, box.y + box.height - 1); AColor::Line(dc, box.x, box.y + box.height - 1, box.x + box.width - 1, box.y + box.height - 1); } wxString t; wxCoord w; wxCoord h; t.Printf(wxT("%d"), chanName); dc.GetTextExtent(t, &w, &h); dc.DrawText(t, box.x + (box.width - w) / 2, box.y + (box.height - h) / 2); } } AColor::MIDIChannel(&dc, 0); // always return with gray color selected return box.GetBottom(); }
void MyApp::Draw(wxDC&dc) { // This routine just draws a bunch of random stuff on the screen so that we // can check that different types of object are being drawn consistently // between the screen image, the print preview image (at various zoom // levels), and the printed page. dc.SetBackground(*wxWHITE_BRUSH); // dc.Clear(); dc.SetFont(m_testFont); // dc.SetBackgroundMode(wxTRANSPARENT); dc.SetPen(*wxBLACK_PEN); dc.SetBrush(*wxLIGHT_GREY_BRUSH); dc.DrawRectangle(0, 0, 230, 350); dc.DrawLine(0, 0, 229, 349); dc.DrawLine(229, 0, 0, 349); dc.SetBrush(*wxTRANSPARENT_BRUSH); dc.SetBrush(*wxCYAN_BRUSH); dc.SetPen(*wxRED_PEN); dc.DrawRoundedRectangle(0, 20, 200, 80, 20); dc.DrawText( wxT("Rectangle 200 by 80"), 40, 40); dc.SetPen( wxPen(*wxBLACK, 0, wxPENSTYLE_DOT_DASH) ); dc.DrawEllipse(50, 140, 100, 50); dc.SetPen(*wxRED_PEN); dc.DrawText( wxT("Test message: this is in 10 point text"), 10, 180); #if wxUSE_UNICODE const char *test = "Hebrew שלום -- Japanese (日本語)"; wxString tmp = wxConvUTF8.cMB2WC( test ); dc.DrawText( tmp, 10, 200 ); #endif wxPoint points[5]; points[0].x = 0; points[0].y = 0; points[1].x = 20; points[1].y = 0; points[2].x = 20; points[2].y = 20; points[3].x = 10; points[3].y = 20; points[4].x = 10; points[4].y = -20; dc.DrawPolygon( 5, points, 20, 250, wxODDEVEN_RULE ); dc.DrawPolygon( 5, points, 50, 250, wxWINDING_RULE ); dc.DrawEllipticArc( 80, 250, 60, 30, 0.0, 270.0 ); points[0].x = 150; points[0].y = 250; points[1].x = 180; points[1].y = 250; points[2].x = 180; points[2].y = 220; points[3].x = 200; points[3].y = 220; dc.DrawSpline( 4, points ); dc.DrawArc( 20,10, 10,10, 25,40 ); wxString str; int i = 0; str.Printf( wxT("---- Text at angle %d ----"), i ); dc.DrawRotatedText( str, 100, 300, i ); i = m_angle; str.Printf( wxT("---- Text at angle %d ----"), i ); dc.DrawRotatedText( str, 100, 300, i ); wxIcon my_icon = wxICON(sample); dc.DrawIcon( my_icon, 100, 100); if (m_bitmap.IsOk()) dc.DrawBitmap( m_bitmap, 10, 10 ); #if wxUSE_GRAPHICS_CONTEXT wxGraphicsContext *gc = NULL; wxPrinterDC *printer_dc = wxDynamicCast( &dc, wxPrinterDC ); if (printer_dc) gc = wxGraphicsContext::Create( *printer_dc ); wxWindowDC *window_dc = wxDynamicCast( &dc, wxWindowDC ); if (window_dc) gc = wxGraphicsContext::Create( *window_dc ); #ifdef __WXMSW__ wxEnhMetaFileDC *emf_dc = wxDynamicCast( &dc, wxEnhMetaFileDC ); if (emf_dc) gc = wxGraphicsContext::Create( *emf_dc ); #endif if (gc) { // make a path that contains a circle and some lines, centered at 100,100 gc->SetPen( *wxRED_PEN ); wxGraphicsPath path = gc->CreatePath(); path.AddCircle( 50.0, 50.0, 50.0 ); path.MoveToPoint(0.0, 50.0); path.AddLineToPoint(100.0, 50.0); path.MoveToPoint(50.0, 0.0); path.AddLineToPoint(50.0, 100.0 ); path.CloseSubpath(); path.AddRectangle(25.0, 25.0, 50.0, 50.0); gc->StrokePath(path); // draw some text wxString text("Text by wxGraphicsContext"); gc->SetFont( m_testFont, *wxBLACK ); gc->DrawText(text, 25.0, 60.0); // draw rectangle around the text double w, h, d, el; gc->GetTextExtent(text, &w, &h, &d, &el); gc->SetPen( *wxBLACK_PEN ); gc->DrawRectangle(25.0, 60.0, w, h); delete gc; } #endif }
bool SjOscStar::Draw(wxDC& dc, const wxSize& clientSize, double rot, wxPen& pen, wxBrush& brush) { double xfloat, yfloat; int x, y, hh, vv; int d, intensity; m_z -= 2; if( m_z < -63 ) { m_z = STAR_DEPTH; m_doDraw = !m_exitRequest; } hh = (m_x*64)/(64+m_z); vv = (m_y*64)/(64+m_z); // check position x = hh + 500; y = vv + 500; if( x < -300 || x > 1300 || y < -300 || y > 1300 ) { m_z = STAR_DEPTH; m_doDraw = !m_exitRequest; hh = (m_x*64)/(64+m_z); vv = (m_y*64)/(64+m_z); } // calculate position xfloat = (hh*cos(rot))-(vv*sin(rot)); yfloat = (hh*sin(rot))+(vv*cos(rot)); x = (int)xfloat + 500; y = (int)yfloat + 500; // use star? if( !m_doDraw ) { if( m_exitRequest || x < 450 || x > 550 || y < 450 || y > 550 ) { return FALSE; } else { m_doDraw = TRUE; } } // map star position to client size, keep aspect ratio d = clientSize.x; if( clientSize.y > d ) { d = clientSize.y; } if( d == 0 ) { d = 10; } x = (x * d) / 1000 - (d-clientSize.x)/2; y = (y * d) / 1000 - (d-clientSize.y)/2; // calculate size d = (STAR_DEPTH-m_z) / (38400/d); if( d == 0 ) d = 1; // calculate light intensity intensity = STAR_DEPTH-m_z; intensity = 55 + ((intensity * 200) / STAR_DEPTH); //if( intensity < light ) intensity = light + 10; if( intensity < 0 ) intensity = 0; if( intensity > 255 ) intensity = 255; // draw star if( d==1 ) { pen.SetColour(intensity, intensity, intensity); dc.SetPen(pen); dc.DrawPoint(x, y); } else { dc.SetPen(*wxTRANSPARENT_PEN); brush.SetColour(intensity, intensity, intensity); dc.SetBrush(brush); dc.DrawRectangle(x, y, d, d); } return TRUE; }
void PlotXY::OnDraw(wxDC& dc) { agw::PlotLua* pl = plotLua_.get(); std::vector<agw::PlotLayer_sptr>& layers = pl->layers_; if (layers.size() == 0) return; int xv, yv; GetVirtualSize(&xv, &yv); PixelWorld& pw = pl->world_; pw.calc(xv,yv); pw.calcScales(layers); wxBrush backBrush(pw.backColor_); dc.SetBackground(backBrush); dc.DrawRectangle(0,0,xv,yv); wxPen axePen(pw.axisColor_); auto savePen = dc.GetPen(); dc.SetPen(axePen); auto xright = pw.left_ + pw.xspan_; auto xbottom = pw.top_ + pw.yspan_; if (pw.leftFrame_) dc.DrawLine(pw.left_, pw.top_,pw.left_, xbottom); if (pw.topFrame_) dc.DrawLine(pw.left_, pw.top_, xright, pw.top_); if (pw.rightFrame_) dc.DrawLine(xright, pw.top_,xright, xbottom); if (pw.bottomFrame_) dc.DrawLine(xright, xbottom, pw.left_, xbottom); pw.yScale_.renderDC(dc,pw); // bottom axis, pw.xScale_.renderDC(dc,pw); auto it = layers.begin(); auto fin = layers.end(); for( ; it != fin; it++) { PlotLayer* p = it->get(); if (p->isVisible()) p->renderDC(dc, pw); } dc.SetPen(savePen); std::vector<PlotLayer_sptr>& text = pl->text_.labels_; it = text.begin(); fin = text.end(); for( ; it != fin; it++) { PlotLayer* p = it->get(); p->setPlot(plotLua_); if (p->isVisible()) p->renderDC(dc, pw); } PlotLayer* p = pl->text_.legend_.get(); if (p && p->isVisible()) { p->setPlot(plotLua_); p->renderDC(dc, pw); } }
void clAuiTabArt::DrawTab(wxDC& dc, wxWindow* wnd, const wxAuiNotebookPage& page, const wxRect& in_rect, int close_button_state, wxRect* out_tab_rect, wxRect* out_button_rect, int* x_extent) { wxCoord normal_textx, normal_texty; wxCoord selected_textx, selected_texty; wxCoord texty; // if the caption is empty, measure some temporary text wxString caption = page.caption; if (caption.empty()) caption = wxT("Xj"); dc.SetFont(m_selected_font); dc.GetTextExtent(caption, &selected_textx, &selected_texty); dc.SetFont(m_normal_font); dc.GetTextExtent(caption, &normal_textx, &normal_texty); // figure out the size of the tab wxSize tab_size = GetTabSize(dc, wnd, page.caption, page.bitmap, page.active, close_button_state, x_extent); wxCoord tab_height = m_tab_ctrl_height - 3; wxCoord tab_width = tab_size.x; wxCoord tab_x = in_rect.x; wxCoord tab_y = in_rect.y + in_rect.height - tab_height; caption = page.caption; // select pen, brush and font for the tab to be drawn if (page.active) { dc.SetFont(m_selected_font); texty = selected_texty; } else { dc.SetFont(m_normal_font); texty = normal_texty; } // create points that will make the tab outline int clip_width = tab_width; if (tab_x + clip_width > in_rect.x + in_rect.width) clip_width = (in_rect.x + in_rect.width) - tab_x; // since the above code above doesn't play well with WXDFB or WXCOCOA, // we'll just use a rectangle for the clipping region for now -- dc.SetClippingRegion(tab_x, tab_y, clip_width+1, tab_height-3); wxPoint border_points[6]; if (m_flags &wxAUI_NB_BOTTOM) { border_points[0] = wxPoint(tab_x, tab_y); border_points[1] = wxPoint(tab_x, tab_y+tab_height-6); border_points[2] = wxPoint(tab_x, tab_y+tab_height-4); border_points[3] = wxPoint(tab_x+tab_width, tab_y+tab_height-4); border_points[4] = wxPoint(tab_x+tab_width, tab_y+tab_height-6); border_points[5] = wxPoint(tab_x+tab_width, tab_y); } else { //if (m_flags & wxAUI_NB_TOP) {} if(page.active == false) { tab_height -= 2; tab_y += 2; } border_points[0] = wxPoint(tab_x, tab_y+tab_height-4); border_points[1] = wxPoint(tab_x, tab_y+2); border_points[2] = wxPoint(tab_x, tab_y); border_points[3] = wxPoint(tab_x+tab_width, tab_y); border_points[4] = wxPoint(tab_x+tab_width, tab_y+2); border_points[5] = wxPoint(tab_x+tab_width, tab_y+tab_height-4); } // TODO: else if (m_flags &wxAUI_NB_LEFT) {} // TODO: else if (m_flags &wxAUI_NB_RIGHT) {} int drawn_tab_yoff = border_points[1].y; int drawn_tab_height = border_points[0].y - border_points[1].y; if (page.active) { // draw active tab // draw base background color wxRect r(tab_x, tab_y, tab_width, tab_height); dc.SetPen(m_base_colour_pen); dc.SetBrush(m_base_colour_brush); dc.DrawRectangle(r.x, r.y+1, r.width-1, r.height-4); // this white helps fill out the gradient at the top of the tab dc.SetPen(m_base_colour); dc.SetBrush(m_base_colour); dc.DrawRectangle(r.x, r.y+1, r.width-1, r.height-4); // these two points help the rounded corners appear more antialiased dc.SetPen(m_base_colour_pen); dc.DrawPoint(r.x+2, r.y+1); dc.DrawPoint(r.x+r.width-2, r.y+1); // set rectangle down a bit for gradient drawing r.height -= 1; r.y += 1; r.width -= 2; r.x += 1; // draw gradient background wxColor top_color = m_base_colour_4; wxColor bottom_color = m_bottom_rect_colour; dc.GradientFillLinear(r, bottom_color, top_color, m_flags & wxAUI_NB_BOTTOM ? wxSOUTH : wxNORTH); } else { // draw inactive tab wxRect r(tab_x, tab_y, tab_width, tab_height-2); // start the gradent up a bit and leave the inside border inset // by a pixel for a 3D look. Only the top half of the inactive // tab will have a slight gradient r.x += 1; r.y++; r.width -= 1; r.height /= 2; // r.height; // -- draw top gradient fill for glossy look wxColor top_color = m_shade_colour; wxColor bottom_color = m_shade_colour; dc.GradientFillLinear(r, bottom_color, top_color, wxNORTH); r.y += r.height; r.y--; // -- draw bottom fill for glossy look top_color = m_shade_colour; bottom_color = m_shade_colour; dc.GradientFillLinear(r, top_color, bottom_color, wxSOUTH); } // draw tab outline dc.SetPen(m_border_pen); dc.SetBrush(*wxTRANSPARENT_BRUSH); dc.DrawPolygon(WXSIZEOF(border_points), border_points); // there are two horizontal grey lines at the bottom of the tab control, // this gets rid of the top one of those lines in the tab control if (page.active) { //if (m_flags &wxAUI_NB_BOTTOM) // dc.SetPen(wxPen(wxColour(wxAuiStepColour(m_base_colour, 170)))); // TODO: else if (m_flags &wxAUI_NB_LEFT) {} // TODO: else if (m_flags &wxAUI_NB_RIGHT) {} //else //for wxAUI_NB_TOP dc.SetPen(m_bottom_rect_colour); dc.DrawLine(border_points[0].x+1, border_points[0].y, border_points[5].x, border_points[5].y); } int text_offset = tab_x + 8; int close_button_width = 0; if (close_button_state != wxAUI_BUTTON_STATE_HIDDEN) { close_button_width = m_active_close_bmp.GetWidth() + 4; } int bitmap_offset = 0; if (page.bitmap.IsOk()) { bitmap_offset = tab_x + 8; // draw bitmap dc.DrawBitmap(page.bitmap, bitmap_offset, drawn_tab_yoff + (drawn_tab_height/2) - (page.bitmap.GetHeight()/2), true); text_offset = bitmap_offset + page.bitmap.GetWidth(); text_offset += 3; // bitmap padding } else { text_offset = tab_x + 8; } wxString draw_text = wxAuiChopText(dc, caption, tab_width - (text_offset-tab_x) - close_button_width); // draw tab text dc.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT) ); dc.DrawText(draw_text, text_offset, drawn_tab_yoff + (drawn_tab_height)/2 - (texty/2) - 1); // draw close button if necessary if (close_button_state != wxAUI_BUTTON_STATE_HIDDEN) { wxBitmap bmp = m_disabled_close_bmp; if (close_button_state == wxAUI_BUTTON_STATE_HOVER || close_button_state == wxAUI_BUTTON_STATE_PRESSED) { bmp = m_active_close_bmp; } wxRect rect(tab_x + tab_width - close_button_width - 1, tab_y + (tab_height/2) - (bmp.GetHeight()/2), close_button_width, tab_height); IndentPressedBitmap(&rect, close_button_state); dc.DrawBitmap(bmp, rect.x, rect.y-1, true); *out_button_rect = rect; } *out_tab_rect = wxRect(tab_x, tab_y, tab_width, tab_height); #ifndef __WXMAC__ // draw focus rectangle if (page.active && (wnd->FindFocus() == wnd)) { wxRect focusRectText(text_offset, (drawn_tab_yoff + (drawn_tab_height)/2 - (texty/2) - 1), selected_textx, selected_texty); wxRect focusRect; wxRect focusRectBitmap; if (page.bitmap.IsOk()) focusRectBitmap = wxRect(bitmap_offset, drawn_tab_yoff + (drawn_tab_height/2) - (page.bitmap.GetHeight()/2), page.bitmap.GetWidth(), page.bitmap.GetHeight()); if (page.bitmap.IsOk() && draw_text.IsEmpty()) focusRect = focusRectBitmap; else if (!page.bitmap.IsOk() && !draw_text.IsEmpty()) focusRect = focusRectText; else if (page.bitmap.IsOk() && !draw_text.IsEmpty()) focusRect = focusRectText.Union(focusRectBitmap); focusRect.Inflate(2, 2); } #endif dc.DestroyClippingRegion(); }
void CtrlRegisterList::OnDraw(wxDC& dc) { wxFont font = pxGetFixedFont(8); font.SetPixelSize(wxSize(charWidth,rowHeight-2)); dc.SetFont(font); refreshChangedRegs(); wxColor colorChanged = wxColor(0xFF0000FF); wxColor colorUnchanged = wxColor(0xFF004000); wxColor colorNormal = wxColor(0xFF600000); int startRow; GetViewStart(nullptr,&startRow); int endRow = startRow + ceil(float(GetClientSize().y) / rowHeight); // draw categories int width = GetClientSize().x; if (startRow == 0) { int piece = width /cpu->getRegisterCategoryCount(); for (int i = 0; i < cpu->getRegisterCategoryCount(); i++) { const char* name = cpu->getRegisterCategoryName(i); int x = i*piece; if (i == category) { dc.SetBrush(wxBrush(wxColor(0xFF70FF70))); dc.SetPen(wxPen(wxColor(0xFF000000))); } else { dc.SetBrush(wxBrush(wxColor(0xFFFFEFE8))); dc.SetPen(wxPen(wxColor(0xFF000000))); } if (i == cpu->getRegisterCategoryCount()-1) piece += width-piece*cpu->getRegisterCategoryCount()-1; dc.DrawRectangle(x,0,piece+1,rowHeight); // center text x += (piece-strlen(name)*charWidth)/2; dc.DrawText(wxString(name,wxConvUTF8),x,2); } } // skip the tab row startRow = std::max<int>(0,startRow-1); endRow = std::min<int>(cpu->getRegisterCount(category)-1,endRow-1); int nameStart = 17; int valueStart = startPositions[category]; ChangedReg* changedRegs = changedCategories[category]; int registerBits = cpu->getRegisterSize(category); DebugInterface::RegisterType type = cpu->getRegisterType(category); for (int i = startRow; i <= endRow; i++) { int x = valueStart; int y = rowHeight*(i+1); wxColor backgroundColor; if (currentRows[category] == i) backgroundColor = wxColor(0xFFFFCFC8); else if (i % 2) backgroundColor = wxColor(237, 242, 255, 255); else backgroundColor = wxColor(0xFFFFFFFF); dc.SetBrush(backgroundColor); dc.SetPen(backgroundColor); dc.DrawRectangle(0, y, width, rowHeight); const char* name = cpu->getRegisterName(category,i); dc.SetTextForeground(colorNormal); dc.DrawText(wxString(name,wxConvUTF8),nameStart,y+2); u128 value = cpu->getRegister(category,i); ChangedReg& changed = changedRegs[i]; switch (type) { case DebugInterface::NORMAL: // display them in 32 bit parts switch (registerBits) { case 128: { int startIndex = std::min<int>(3, maxBits / 32 - 1); if (resolvePointerStrings && cpu->isAlive()) { char *strval = cpu->stringFromPointer(value._u32[0]); if (strval) { static wxColor clr = wxColor(0xFF228822); dc.SetTextForeground(clr); dc.DrawText(wxString(strval), width - (32 * charWidth + 12), y + 2); startIndex = 0; } } int actualX = width-4-(startIndex+1)*(8*charWidth+2); x = std::max<int>(actualX,x); if (startIndex != 3) { bool c = false; for (int i = 3; i > startIndex; i--) c = c || changed.changed[i]; if (c) { dc.SetTextForeground(colorChanged); dc.DrawText(L"+",x-charWidth,y+2); } } for (int i = startIndex; i >= 0; i--) { if (changed.changed[i]) dc.SetTextForeground(colorChanged); else dc.SetTextForeground(colorUnchanged); drawU32Text(dc,value._u32[i],x,y+2); x += charWidth*8+2; } break; } case 64: { if (maxBits < 64 && changed.changed[1]) { dc.SetTextForeground(colorChanged); dc.DrawText(L"+",x-charWidth,y+2); } for (int i = 1; i >= 0; i--) { if (changed.changed[i]) dc.SetTextForeground(colorChanged); else dc.SetTextForeground(colorUnchanged); drawU32Text(dc,value._u32[i],x,y+2); x += charWidth*8+2; } break; } case 32: { if (changed.changed[0]) dc.SetTextForeground(colorChanged); else dc.SetTextForeground(colorUnchanged); drawU32Text(dc,value._u32[0],x,y+2); break; } } break; case DebugInterface::SPECIAL: // let debug interface format them and just display them { if (changed.changed[0] || changed.changed[1] || changed.changed[2] || changed.changed[3]) dc.SetTextForeground(colorChanged); else dc.SetTextForeground(colorUnchanged); dc.DrawText(cpu->getRegisterString(category,i),x,y+2); break; } } } }
void ChipPackage::DrawPins(wxDC& dc, const wxPoint& pt, unsigned int PackageLen, unsigned int FirstPin, unsigned int LastPin, int flags, wxDirection dir) { wxASSERT_MSG(LastPin>FirstPin, "invalid pin indexes"); // NOTE: inside this function context // pin number == the index of the pin (e.g. "1", "2", etc) // pin name == pin label == the name of the pin signal (e.g. "VCC", "GND" etc) // pin == pin rectangle // some drawing constants: const unsigned int PinCount = LastPin - FirstPin; // pin height is calculated imposing that // 1) PinCount*PinH + (PinCount+1)*PinSpacing = PackageLen // 2) PinSpacing = PinH/2 // solving for PinH yields: unsigned int PinH = (unsigned int)floor(2*PackageLen/(3.0*PinCount+1)); unsigned int PinW = (unsigned int)1.5*PinH; const unsigned int PinSpacing = (const unsigned int)floor(PinH/2.0); // the error which force us to have a "pin y offset" is caused by rounding // in the calculation of PinH: const int PinOffset = (PackageLen - (PinCount*PinH + (PinCount+1)*PinSpacing))/2; wxASSERT(PinOffset>=0); if (int(PinH*0.8) == 0) return; // this happens for very small package sizes; // the check avoids an assertion failure from wxFont ctor // select a font suitable for the PinH we have computed above: int fSize = int(PinH*0.8); if(fSize>12)fSize=12; wxFont fnt(wxSize(0,fSize), wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD); dc.SetFont(fnt); const unsigned int PinNumberW = 2*dc.GetCharWidth(); const unsigned int PinNumberH = dc.GetCharHeight(); bool invertOrder = (flags & DRAWPIN_INVERTED_ORDER) != 0; unsigned int start = invertOrder ? LastPin-1 : FirstPin; unsigned int end = invertOrder ? FirstPin-1 : LastPin; int inc = invertOrder ? -1 : +1; if (dir == wxLEFT || dir == wxRIGHT) { unsigned int PinX = (dir == wxLEFT) ? pt.x-PinW+1 : pt.x-1; unsigned int PinY = pt.y + PinOffset + PinSpacing; unsigned int PinNumberX = (dir == wxLEFT) ? pt.x+PinSpacing : pt.x-PinNumberW-PinSpacing; if (flags & DRAWPIN_NUMBERS_INSIDE_PINS) PinNumberX = PinX + (PinW-PinNumberW)/2; // draw the pins organizing them in a vertical column for (unsigned int i=start; i != end; i+=inc) { unsigned int PinNumberY = PinY + (PinH-PinNumberH)/2; unsigned int pinLabelX = (dir == wxLEFT) ? PinX-PinSpacing-dc.GetTextExtent(PinNames[i]).GetWidth() : PinX+PinW+PinSpacing; unsigned int pinLabelY = PinNumberY; // draw the pin rect dc.DrawRectangle(PinX, PinY, PinW, PinH); // print the pin number dc.SetTextForeground(IsICSPPin(i) ? *wxRED : *wxBLACK); dc.DrawText(wxString::Format(("%d"), i+1), PinNumberX, PinNumberY); // print the pin name dc.DrawText(PinNames[i], pinLabelX, pinLabelY); PinY += PinH+PinSpacing; } } else if (dir == wxTOP || dir == wxBOTTOM) { SWAP(PinH, PinW, unsigned int); // in this case the PackageLen is the number of horizontal pixels available // for drawing the pin strip; thus we want to compute PinW and set PinH // VERY IMPORTANT: the code below is the dual of the code for wxLEFT|wxRIGHT case! // If you change something here, you may want to change it also // above, with the appropriate differences // NOTE: remember however that the text is drawn rotated by 90 degrees unsigned int PinX = pt.x + PinOffset + PinSpacing; unsigned int PinY = (dir == wxTOP) ? pt.y-PinH+1 : pt.y-1; unsigned int PinNumberY = (dir == wxTOP) ? pt.y+PinSpacing : pt.y-PinNumberH-PinSpacing; if (flags & DRAWPIN_NUMBERS_INSIDE_PINS) PinNumberY = PinY + (PinH-PinNumberW)/2; // draw the pins organizing them in a horizontal column for (unsigned int i=start; i != end; i+=inc) { unsigned int PinNumberX = PinX + PinNumberH + (PinW-PinNumberH)/2; unsigned int pinLabelX = PinNumberX; unsigned int pinLabelY = (dir == wxTOP) ? PinY-PinSpacing-dc.GetTextExtent(PinNames[i]).GetWidth() : PinY+PinH+PinSpacing; // draw the pin rect dc.DrawRectangle(PinX, PinY, PinW, PinH); // print the pin number dc.SetTextForeground(IsICSPPin(i) ? *wxRED : *wxBLACK); dc.DrawRotatedText(wxString::Format(("%d"), i+1), PinNumberX, PinNumberY, -90); // print the pin name dc.DrawRotatedText(PinNames[i], pinLabelX, pinLabelY, -90); PinX += PinW+PinSpacing; } } else wxLogWarning(_("Invalid direction")); }
void CLMainAuiTBArt::DrawDropDownButton(wxDC& dc, wxWindow* wnd, const wxAuiToolBarItem& item, const wxRect& rect) { wxAuiDefaultToolBarArt::DrawDropDownButton(dc, wnd, item, rect); #if 0 // Dark theme int textWidth = 0, textHeight = 0, textX = 0, textY = 0; int bmpX = 0, bmpY = 0, dropBmpX = 0, dropBmpY = 0; wxRect buttonRect = wxRect(rect.x, rect.y, rect.width - BUTTON_DROPDOWN_WIDTH, rect.height); wxRect dropDownRect = wxRect(rect.x + rect.width - BUTTON_DROPDOWN_WIDTH - 1, rect.y, BUTTON_DROPDOWN_WIDTH + 1, rect.height); if(m_flags & wxAUI_TB_TEXT) { dc.SetFont(m_font); int tx, ty; if(m_flags & wxAUI_TB_TEXT) { dc.GetTextExtent(wxT("ABCDHgj"), &tx, &textHeight); textWidth = 0; } dc.GetTextExtent(item.GetLabel(), &textWidth, &ty); } dropBmpX = dropDownRect.x + (dropDownRect.width / 2) - (m_buttonDropDownBmp.GetWidth() / 2); dropBmpY = dropDownRect.y + (dropDownRect.height / 2) - (m_buttonDropDownBmp.GetHeight() / 2); if(m_textOrientation == wxAUI_TBTOOL_TEXT_BOTTOM) { bmpX = buttonRect.x + (buttonRect.width / 2) - (item.GetBitmap().GetWidth() / 2); bmpY = buttonRect.y + ((buttonRect.height - textHeight) / 2) - (item.GetBitmap().GetHeight() / 2); textX = rect.x + (rect.width / 2) - (textWidth / 2) + 1; textY = rect.y + rect.height - textHeight - 1; } else if(m_textOrientation == wxAUI_TBTOOL_TEXT_RIGHT) { bmpX = rect.x + 3; bmpY = rect.y + (rect.height / 2) - (item.GetBitmap().GetHeight() / 2); textX = bmpX + 3 + item.GetBitmap().GetWidth(); textY = rect.y + (rect.height / 2) - (textHeight / 2); } if(item.GetState() & wxAUI_BUTTON_STATE_PRESSED) { dc.SetPen(wxPen(m_highlightColour)); dc.SetBrush(wxBrush(m_highlightColour.ChangeLightness(140))); dc.DrawRectangle(buttonRect); dc.SetBrush(wxBrush(m_highlightColour.ChangeLightness(170))); dc.DrawRectangle(dropDownRect); } else if(item.GetState() & wxAUI_BUTTON_STATE_HOVER || item.IsSticky()) { dc.SetPen(wxPen(m_highlightColour)); dc.SetBrush(wxBrush(m_highlightColour.ChangeLightness(170))); dc.DrawRectangle(buttonRect); dc.DrawRectangle(dropDownRect); } else if(item.GetState() & wxAUI_BUTTON_STATE_CHECKED) { // Notice that this branch must come after the hover one to ensure the // correct appearance when the mouse hovers over a checked item.m_ dc.SetPen(wxPen(m_highlightColour)); dc.SetBrush(wxBrush(m_highlightColour.ChangeLightness(170))); dc.DrawRectangle(buttonRect); dc.DrawRectangle(dropDownRect); } wxBitmap bmp; wxBitmap dropbmp; if(item.GetState() & wxAUI_BUTTON_STATE_DISABLED) { bmp = CreateDisabledBitmap(item.GetBitmap()); dropbmp = m_disabledButtonDropDownBmp; } else { bmp = item.GetBitmap(); dropbmp = m_buttonDropDownBmp; } if(!bmp.IsOk()) return; dc.DrawBitmap(bmp, bmpX, bmpY, true); dc.DrawBitmap(dropbmp, dropBmpX, dropBmpY, true); // set the item's text color based on if it is disabled dc.SetTextForeground(*wxBLACK); if(item.GetState() & wxAUI_BUTTON_STATE_DISABLED) dc.SetTextForeground(DISABLED_TEXT_COLOR); if((m_flags & wxAUI_TB_TEXT) && !item.GetLabel().empty()) { dc.DrawText(item.GetLabel(), textX, textY); } #endif }
void ChipPackage::Draw(wxDC& dc, const wxSize& sz, const wxString& chipModel) { // set some GUI objects common to all packages-drawing code dc.SetPen(*wxBLACK_PEN); switch (Type) { case PDIP: case SOIC: case SSOP: { // some drawing constants: // in these package types, pins are organized in two columns: const unsigned int PinPerSide = GetPinCount()/2; if ((GetPinCount()%2) != 0) { wxLogWarning(_("Invalid odd pin count: %d"), GetPinCount()); return; } // choose reasonable package width&height to // - make best use of the available space // - avoid drawing package excessively big const unsigned int BoxW = sz.GetWidth()/3; const unsigned int BoxH = (unsigned int)((double)sz.GetHeight()*0.8); const unsigned int BoxX = (sz.GetWidth()-BoxW)/2; const unsigned int BoxY = (sz.GetHeight()-BoxH)/2; const unsigned int R = BoxW/6; if (int(BoxW/8) == 0) return; // this happens for very small package sizes; // the check avoids an assertion failure from wxFont ctor later // draw the PIC package box dc.DrawRectangle(BoxX, BoxY, BoxW, BoxH); dc.DrawArc(sz.GetWidth()/2-R, BoxY + 1, sz.GetWidth()/2+R, BoxY + 1, sz.GetWidth()/2, BoxY + 1); dc.SetFont(wxFont(wxSize(0, BoxW/8), wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD)); const wxSize& nameSz = dc.GetTextExtent(chipModel); dc.DrawRotatedText(chipModel, (sz.GetWidth() + nameSz.GetHeight())/2, (sz.GetHeight() - nameSz.GetWidth())/2, -90); // draw the pins DrawPins(dc, wxPoint(BoxX, BoxY), BoxH, 0, PinPerSide, 0, wxLEFT); DrawPins(dc, wxPoint(BoxX+BoxW, BoxY), BoxH, PinPerSide, GetPinCount(), DRAWPIN_INVERTED_ORDER, wxRIGHT); } break; case MQFP: case TQFP: case PLCC: case QFN: { // some drawing constants: // in these package types, pins are organized in two columns: const unsigned int PinPerSide = GetPinCount()/4; if ((GetPinCount()%4) != 0) { wxLogWarning(_("Invalid pin count: %d"), GetPinCount()); return; } // choose reasonable package width&height to // - make best use of the available space // - avoid drawing package excessively big const unsigned int BoxL = max(sz.GetWidth()/2,80); const unsigned int BoxX = (sz.GetWidth()-BoxL)/2; const unsigned int BoxY = (sz.GetHeight()-BoxL)/2; const unsigned int R = BoxL/10; if (int(BoxL/10) == 0) return; // this happens for very small package sizes; // the check avoids an assertion failure from wxFont ctor later // draw the PIC package box dc.DrawRectangle(BoxX, BoxY, BoxL, BoxL); dc.DrawCircle(BoxX+int(R*1.3), BoxY+int(R*1.3), R/2); // draw the name of the PIC model in the centre of the box dc.SetFont(wxFont(wxSize(0, BoxL/10), wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD)); const wxSize& nameSz = dc.GetTextExtent(chipModel); dc.DrawText(chipModel, (sz.GetWidth() - nameSz.GetWidth())/2, (sz.GetHeight() - nameSz.GetHeight())/2); // draw the pins DrawPins(dc, wxPoint(BoxX, BoxY), BoxL, 0, PinPerSide, DRAWPIN_NUMBERS_INSIDE_PINS, wxLEFT); DrawPins(dc, wxPoint(BoxX, BoxY+BoxL), BoxL, PinPerSide, PinPerSide*2, DRAWPIN_NUMBERS_INSIDE_PINS, wxBOTTOM); DrawPins(dc, wxPoint(BoxX+BoxL, BoxY), BoxL, PinPerSide*2, PinPerSide*3, DRAWPIN_INVERTED_ORDER|DRAWPIN_NUMBERS_INSIDE_PINS, wxRIGHT); DrawPins(dc, wxPoint(BoxX, BoxY), BoxL, PinPerSide*3, PinPerSide*4, DRAWPIN_INVERTED_ORDER|DRAWPIN_NUMBERS_INSIDE_PINS, wxTOP); } break; default: break; } }
void wxTabControl::OnDraw(wxDC& dc, bool lastInRow) { // Old, but in some ways better (drawing opaque tabs) #ifndef wxUSE_NEW_METHOD if (!m_view) return; // Top-left of tab view area int viewX = m_view->GetViewRect().x; int viewY = m_view->GetViewRect().y; // Top-left of tab control int tabX = GetX() + viewX; int tabY = GetY() + viewY; int tabHeightInc = 0; if (m_isSelected) { tabHeightInc = (m_view->GetTabSelectionHeight() - m_view->GetTabHeight()); tabY -= tabHeightInc; } dc.SetPen(*wxTRANSPARENT_PEN); // Draw grey background if (m_view->GetTabStyle() & wxTAB_STYLE_COLOUR_INTERIOR) { if(m_view->GetBackgroundBrush()) dc.SetBrush(*m_view->GetBackgroundBrush()); // Add 1 because the pen is transparent. Under Motif, may be different. #ifdef __WXMOTIF__ dc.DrawRectangle(tabX, tabY, (GetWidth()+1), (GetHeight() + tabHeightInc)); #else dc.DrawRectangle(tabX, tabY, (GetWidth()+1), (GetHeight() + 1 + tabHeightInc)); #endif } // Draw highlight and shadow dc.SetPen(*m_view->GetHighlightPen()); // Calculate the top of the tab beneath. It's the height of the tab, MINUS // a bit if the tab below happens to be selected. Check. wxTabControl *tabBeneath = NULL; int subtractThis = 0; if (GetColPosition() > 0) tabBeneath = m_view->FindTabControlForPosition(GetColPosition() - 1, GetRowPosition()); if (tabBeneath && tabBeneath->IsSelected()) subtractThis = (m_view->GetTabSelectionHeight() - m_view->GetTabHeight()); // Vertical highlight: if first tab, draw to bottom of view if (tabX == m_view->GetViewRect().x && (m_view->GetTabStyle() & wxTAB_STYLE_DRAW_BOX)) dc.DrawLine(tabX, tabY, tabX, (m_view->GetViewRect().y + m_view->GetViewRect().height)); else if (tabX == m_view->GetViewRect().x) // Not box drawing, just to top of view. dc.DrawLine(tabX, tabY, tabX, (m_view->GetViewRect().y)); else dc.DrawLine(tabX, tabY, tabX, (tabY + GetHeight() + tabHeightInc - subtractThis)); dc.DrawLine(tabX, tabY, (tabX + GetWidth()), tabY); dc.SetPen(*m_view->GetShadowPen()); // Test if we're outside the right-hand edge of the view area if (((tabX + GetWidth()) >= m_view->GetViewRect().x + m_view->GetViewRect().width) && (m_view->GetTabStyle() & wxTAB_STYLE_DRAW_BOX)) { int bottomY = m_view->GetViewRect().y + m_view->GetViewRect().height + GetY() + m_view->GetTabHeight() + m_view->GetTopMargin(); // Add a tab height since we wish to draw to the bottom of the view. dc.DrawLine((tabX + GetWidth()), tabY, (tabX + GetWidth()), bottomY); // Calculate the far-right of the view, since we don't wish to // draw inside that int rightOfView = m_view->GetViewRect().x + m_view->GetViewRect().width + 1; // Draw the horizontal bit to connect to the view rectangle dc.DrawLine((wxMax((tabX + GetWidth() - m_view->GetHorizontalTabOffset()), rightOfView)), (bottomY-1), (tabX + GetWidth()), (bottomY-1)); // Draw black line to emphasize shadow dc.SetPen(*wxBLACK_PEN); dc.DrawLine((tabX + GetWidth() + 1), (tabY+1), (tabX + GetWidth() + 1), bottomY); // Draw the horizontal bit to connect to the view rectangle dc.DrawLine((wxMax((tabX + GetWidth() - m_view->GetHorizontalTabOffset()), rightOfView)), (bottomY), (tabX + GetWidth() + 1), (bottomY)); } else { if (lastInRow) { // 25/5/97 UNLESS it's less than the max number of positions in this row int topY = m_view->GetViewRect().y - m_view->GetTopMargin(); int maxPositions = ((wxTabLayer *)m_view->GetLayers().Item(0)->GetData())->GetCount(); // Only down to the bottom of the tab, not to the top of the view if ( GetRowPosition() < (maxPositions - 1) ) topY = tabY + GetHeight() + tabHeightInc; #ifdef __WXMOTIF__ topY -= 1; #endif // Shadow dc.DrawLine((tabX + GetWidth()), tabY, (tabX + GetWidth()), topY); // Draw black line to emphasize shadow dc.SetPen(*wxBLACK_PEN); dc.DrawLine((tabX + GetWidth() + 1), (tabY+1), (tabX + GetWidth() + 1), topY); } else { // Calculate the top of the tab beneath. It's the height of the tab, MINUS // a bit if the tab below (and next col along) happens to be selected. Check. wxTabControl *tabBeneath = NULL; int subtractThis = 0; if (GetColPosition() > 0) tabBeneath = m_view->FindTabControlForPosition(GetColPosition() - 1, GetRowPosition() + 1); if (tabBeneath && tabBeneath->IsSelected()) subtractThis = (m_view->GetTabSelectionHeight() - m_view->GetTabHeight()); #ifdef __WXMOTIF__ subtractThis += 1; #endif // Draw only to next tab down. dc.DrawLine((tabX + GetWidth()), tabY, (tabX + GetWidth()), (tabY + GetHeight() + tabHeightInc - subtractThis)); // Draw black line to emphasize shadow dc.SetPen(*wxBLACK_PEN); dc.DrawLine((tabX + GetWidth() + 1), (tabY+1), (tabX + GetWidth() + 1), (tabY + GetHeight() + tabHeightInc - subtractThis)); } } // Draw centered text int textY = tabY + m_view->GetVerticalTabTextSpacing() + tabHeightInc; if (m_isSelected) dc.SetFont(* m_view->GetSelectedTabFont()); else dc.SetFont(* GetFont()); wxColour col(m_view->GetTextColour()); dc.SetTextForeground(col); dc.SetBackgroundMode(wxTRANSPARENT); wxCoord textWidth, textHeight; dc.GetTextExtent(GetLabel(), &textWidth, &textHeight); int textX = (int)(tabX + (GetWidth() - textWidth)/2.0); if (textX < (tabX + 2)) textX = (tabX + 2); dc.SetClippingRegion(tabX, tabY, GetWidth(), GetHeight()); dc.DrawText(GetLabel(), textX, textY); dc.DestroyClippingRegion(); if (m_isSelected) { dc.SetPen(*m_view->GetHighlightPen()); // Draw white highlight from the tab's left side to the left hand edge of the view dc.DrawLine(m_view->GetViewRect().x, (tabY + GetHeight() + tabHeightInc), tabX, (tabY + GetHeight() + tabHeightInc)); // Draw white highlight from the tab's right side to the right hand edge of the view dc.DrawLine((tabX + GetWidth()), (tabY + GetHeight() + tabHeightInc), m_view->GetViewRect().x + m_view->GetViewRect().width, (tabY + GetHeight() + tabHeightInc)); } #else // New HEL version with rounder tabs if (!m_view) return; int tabInc = 0; if (m_isSelected) { tabInc = m_view->GetTabSelectionHeight() - m_view->GetTabHeight(); } int tabLeft = GetX() + m_view->GetViewRect().x; int tabTop = GetY() + m_view->GetViewRect().y - tabInc; int tabRight = tabLeft + m_view->GetTabWidth(); int left = m_view->GetViewRect().x; int top = tabTop + m_view->GetTabHeight() + tabInc; int right = left + m_view->GetViewRect().width; int bottom = top + m_view->GetViewRect().height; if (m_isSelected) { // TAB is selected - draw TAB and the View's full outline dc.SetPen(*(m_view->GetHighlightPen())); wxPoint pnts[10]; int n = 0; pnts[n].x = left; pnts[n++].y = bottom; pnts[n].x = left; pnts[n++].y = top; pnts[n].x = tabLeft; pnts[n++].y = top; pnts[n].x = tabLeft; pnts[n++].y = tabTop + 2; pnts[n].x = tabLeft + 2; pnts[n++].y = tabTop; pnts[n].x = tabRight - 1; pnts[n++].y = tabTop; dc.DrawLines(n, pnts); if (!lastInRow) { dc.DrawLine( (tabRight + 2), top, right, top ); } dc.SetPen(*(m_view->GetShadowPen())); dc.DrawLine( tabRight, tabTop + 2, tabRight, top ); dc.DrawLine( right, top, right, bottom ); dc.DrawLine( right, bottom, left, bottom ); dc.SetPen(*wxBLACK_PEN); dc.DrawPoint( tabRight, tabTop + 1 ); dc.DrawPoint( tabRight + 1, tabTop + 2 ); if (lastInRow) { dc.DrawLine( tabRight + 1, bottom, tabRight + 1, tabTop + 1 ); } else { dc.DrawLine( tabRight + 1, tabTop + 2, tabRight + 1, top ); dc.DrawLine( right + 1, top, right + 1, bottom + 1 ); } dc.DrawLine( right + 1, bottom + 1, left + 1, bottom + 1 ); } else { // TAB is not selected - just draw TAB outline and RH edge // if the TAB is the last in the row int maxPositions = ((wxTabLayer*)m_view->GetLayers().Item(0)->GetData())->GetCount(); wxTabControl* tabBelow = 0; wxTabControl* tabBelowRight = 0; if (GetColPosition() > 0) { tabBelow = m_view->FindTabControlForPosition( GetColPosition() - 1, GetRowPosition() ); } if (!lastInRow && GetColPosition() > 0) { tabBelowRight = m_view->FindTabControlForPosition( GetColPosition() - 1, GetRowPosition() + 1 ); } float raisedTop = top - m_view->GetTabSelectionHeight() + m_view->GetTabHeight(); dc.SetPen(*(m_view->GetHighlightPen())); wxPoint pnts[10]; int n = 0; pnts[n].x = tabLeft; if (tabBelow && tabBelow->IsSelected()) { pnts[n++].y = (long)raisedTop; } else { pnts[n++].y = top; } pnts[n].x = tabLeft; pnts[n++].y = tabTop + 2; pnts[n].x = tabLeft + 2; pnts[n++].y = tabTop; pnts[n].x = tabRight - 1; pnts[n++].y = tabTop; dc.DrawLines(n, pnts); dc.SetPen(*(m_view->GetShadowPen())); if (GetRowPosition() >= maxPositions - 1) { dc.DrawLine( tabRight, (tabTop + 2), tabRight, bottom ); dc.DrawLine( tabRight, bottom, (tabRight - m_view->GetHorizontalTabOffset()), bottom ); } else { if (tabBelowRight && tabBelowRight->IsSelected()) { dc.DrawLine( tabRight, (long)raisedTop, tabRight, tabTop + 1 ); } else { dc.DrawLine( tabRight, top - 1, tabRight, tabTop + 1 ); } } dc.SetPen(*wxBLACK_PEN); dc.DrawPoint( tabRight, tabTop + 1 ); dc.DrawPoint( tabRight + 1, tabTop + 2 ); if (GetRowPosition() >= maxPositions - 1) { // draw right hand edge to bottom of view dc.DrawLine( tabRight + 1, bottom + 1, tabRight + 1, tabTop + 2 ); dc.DrawLine( tabRight + 1, bottom + 1, (tabRight - m_view->GetHorizontalTabOffset()), bottom + 1 ); } else { // draw right hand edge of TAB if (tabBelowRight && tabBelowRight->IsSelected()) { dc.DrawLine( tabRight + 1, (long)(raisedTop - 1), tabRight + 1, tabTop + 2 ); } else { dc.DrawLine( tabRight + 1, top - 1, tabRight + 1, tabTop + 2 ); } } } // Draw centered text dc.SetPen(*wxBLACK_PEN); if (m_isSelected) { dc.SetFont(*(m_view->GetSelectedTabFont())); } else { dc.SetFont(*(GetFont())); } wxColour col(m_view->GetTextColour()); dc.SetTextForeground(col); dc.SetBackgroundMode(wxTRANSPARENT); long textWidth, textHeight; dc.GetTextExtent(GetLabel(), &textWidth, &textHeight); float textX = (tabLeft + tabRight - textWidth) / 2; float textY = (tabInc + tabTop + m_view->GetVerticalTabTextSpacing()); dc.DrawText(GetLabel(), (long)textX, (long)textY); #endif }
static void DrawCenteredRectangle(wxDC &dc, int x, int y, int w, int h) { x -= w / 2; y -= h / 2; dc.DrawRectangle(x, y, w, h); }
void SjCoverBrowser::DoPaint(wxDC& dc) { long x, y, w, h; #define SPACE_BRUSH g_mainFrame->m_workspaceColours[SJ_COLOUR_NORMAL].bgBrush // reset required and waiting images g_mainFrame->m_imgThread->RequireStart(m_window); // draw stuff very left (does not scroll) dc.SetPen(*wxTRANSPARENT_PEN); dc.SetBrush(SPACE_BRUSH); dc.DrawRectangle(0, 0, SPACE_LEFT, m_window->m_clientH); dc.SetClippingRegion(wxRect(0, 0, SPACE_LEFT-SEL_BORDER_W, m_window->m_clientH)); w = m_fontHeight - 4; h = m_fontHeight - 4; x = (SPACE_LEFT-w) / 2; y = SPACE_TOP + 2; dc.SetPen(g_mainFrame->m_workspaceColours[SJ_COLOUR_TITLE1].fgPen); SjTools::DrawIcon(dc, wxRect(x, y, w, h), (m_flags&SJ_BROWSER_VIEW_COVER)? SJ_DRAWICON_TRIANGLE_DOWN : SJ_DRAWICON_TRIANGLE_RIGHT); if( g_mainFrame->m_libraryModule ) m_window->DrawUpText(dc, g_mainFrame->m_libraryModule->GetUpText(), 0, SPACE_TOP+m_fontHeight, SPACE_LEFT, m_window->m_clientH-(SPACE_TOP+m_fontHeight)); dc.DestroyClippingRegion(); // draw space atop of all covers long currY = -m_scrollY; dc.SetBrush(SPACE_BRUSH); dc.SetPen(*wxTRANSPARENT_PEN); dc.DrawRectangle(SPACE_LEFT, currY, m_window->m_clientW, g_mainFrame->m_currColumnYSpace); // go through all cover rows int coverIndex = 0; currY += g_mainFrame->m_currColumnYSpace; for( int yIndex = 0; yIndex < m_coversYCount+ADD_ROWS/*try two rows more*/; yIndex++ ) { // go through all cover columns long currX = SPACE_LEFT; for( int xIndex = 0; xIndex < m_coversXCount; xIndex++ ) { bool selectCover = false, coverDrawn = false, borderBottom = true; if( coverIndex < m_allocatedCoverCount ) { SjCol* cover = m_allocatedCover[coverIndex++]; if( cover && cover->m_rowCount>0 && cover->m_rows[0]->m_roughType==SJ_RRTYPE_COVER ) { SjImgThreadObj* cachedImg = m_window->RequireImage(cover->m_rows[0]->m_textm); // cachedImg may be NULL, but this is okay for PaintCover() and for ReleaseImage() m_window->PaintCover(dc, cachedImg, currX, currY); g_mainFrame->m_imgThread->ReleaseImage(m_window, cachedImg); coverDrawn = true; selectCover = cover->FindFirstSelectedRow()!=NULL; // draw text below cover if( m_flags&SJ_BROWSER_VIEW_COVER ) { // get text wxString texts[2]; int trackCount = 0; for( int r = 0; r < cover->m_rowCount; r++ ) { SjRow* row = cover->m_rows[r]; if( row ) { if( row->m_roughType == SJ_RRTYPE_TITLE1 || row->m_roughType == SJ_RRTYPE_TITLE2 ) { if( texts[0].IsEmpty() ) texts[0] = row->m_textm; else texts[1] = row->m_textm; } else if( row->m_roughType == SJ_RRTYPE_NORMAL ) { trackCount ++; } } } if( texts[0].IsEmpty() ) { texts[0].Printf(_("%s tracks"), SjTools::FormatNumber(trackCount).c_str()); } // draw text for( int i=0; i<m_linesBelowCover; i++ ) { wxRect drawRect(currX, currY+g_mainFrame->m_currCoverHeight+m_fontHeight*i, g_mainFrame->m_currCoverWidth, m_fontHeight); SjSkinColour* bgcolour = &g_mainFrame->m_workspaceColours[selectCover? SJ_COLOUR_SELECTIONODD : SJ_COLOUR_NORMAL]; SjSkinColour* fgcolour = &g_mainFrame->m_workspaceColours[selectCover? SJ_COLOUR_SELECTIONODD : (i==0?SJ_COLOUR_TITLE1:SJ_COLOUR_TITLE2)]; wxFont* stdFont = i==0? &g_mainFrame->m_currBoldFont : &g_mainFrame->m_currStdFont; wxFont* smallFont = i==0? &g_mainFrame->m_currSmallBoldFont : &g_mainFrame->m_currSmallFont; dc.SetPen(*wxTRANSPARENT_PEN); dc.SetBrush(bgcolour->bgBrush); dc.DrawRectangle(drawRect); dc.SetTextBackground(fgcolour->bgColour); dc.SetTextForeground(fgcolour->fgColour); g_tools->DrawSingleLineText(dc, texts[i], drawRect, *stdFont, *smallFont, NULL, fgcolour->hiColour); if( selectCover ) borderBottom = false; } } } } if( !coverDrawn ) { // draw space instead of cover (normally this happens if this are the last covers) dc.SetPen(*wxTRANSPARENT_PEN); dc.SetBrush(g_mainFrame->m_workspaceColours[SJ_COLOUR_NORMAL].bgBrush); dc.DrawRectangle(currX-SEL_BORDER_W, currY-SEL_BORDER_W, g_mainFrame->m_currCoverWidth+SEL_BORDER_W*2, m_coverNTitleHeight+SEL_BORDER_W*2); } else { // draw the (selection) border SjSkinColour* colour = &g_mainFrame->m_workspaceColours[selectCover? SJ_COLOUR_SELECTIONODD : SJ_COLOUR_NORMAL]; dc.SetPen(colour->bgPen); dc.SetBrush(*wxTRANSPARENT_BRUSH); for( int i = 1; i <= SEL_BORDER_W; i++ ) { dc.DrawRectangle(currX-i, currY-i, g_mainFrame->m_currCoverWidth+i*2, m_coverNTitleHeight+i*(borderBottom?2:1)); if( !borderBottom ) { dc.SetPen(g_mainFrame->m_workspaceColours[SJ_COLOUR_NORMAL].bgPen); y = currY+m_coverNTitleHeight+i-1; dc.DrawLine(currX-SEL_BORDER_W, y, currX+g_mainFrame->m_currCoverWidth+SEL_BORDER_W, y); dc.SetPen(colour->bgPen); } } } // draw space aright of the cover x = currX+g_mainFrame->m_currCoverWidth+SEL_BORDER_W; y = currY-SEL_BORDER_W; h = m_coverNTitleHeight+SEL_BORDER_W*2; w = m_coverXSpace-SEL_BORDER_W*2; if( xIndex == m_coversXCount-1 ) w = m_window->m_clientW-(currX+g_mainFrame->m_currCoverWidth+SEL_BORDER_W); if( w > 0 ) { dc.SetPen(*wxTRANSPARENT_PEN); dc.SetBrush(SPACE_BRUSH); dc.DrawRectangle(x, y, w, h); } // next cover in row currX += g_mainFrame->m_currCoverWidth+m_coverXSpace; } // draw space below this cover row x = SPACE_LEFT-SEL_BORDER_W; y = currY+m_coverNTitleHeight+SEL_BORDER_W; w = m_window->m_clientW-x; h = g_mainFrame->m_currColumnYSpace-SEL_BORDER_W*2; if( yIndex == (m_coversYCount-1)+ADD_ROWS /*we've added 2 in the for() loop, so no -1 here*/ ) h = m_window->m_clientH-(currY+m_coverNTitleHeight+SEL_BORDER_W); if( h > 0 ) { dc.SetPen(*wxTRANSPARENT_PEN); dc.SetBrush(SPACE_BRUSH); dc.DrawRectangle(x, y, w, h); } // next row currY += m_coverNTitleHeight+g_mainFrame->m_currColumnYSpace; } // free all images that are no longer required but still waiting g_mainFrame->m_imgThread->RequireEnd(m_window); }
static void DrawControlGroupBox(wxDC &dc, ControlGroupBox *g) { switch (g->control_group->type) { case GROUP_TYPE_TILT : case GROUP_TYPE_STICK : case GROUP_TYPE_CURSOR : { // this is starting to be a mess combining all these in one case double x = 0, y = 0, z = 0; switch (g->control_group->type) { case GROUP_TYPE_STICK : ((ControllerEmu::AnalogStick*)g->control_group)->GetState(&x, &y); break; case GROUP_TYPE_TILT : ((ControllerEmu::Tilt*)g->control_group)->GetState(&x, &y); break; case GROUP_TYPE_CURSOR : ((ControllerEmu::Cursor*)g->control_group)->GetState(&x, &y, &z); break; } // ir cursor forward movement if (GROUP_TYPE_CURSOR == g->control_group->type) { if (z) { dc.SetPen(*wxRED_PEN); dc.SetBrush(*wxRED_BRUSH); } else { dc.SetPen(*wxGREY_PEN); dc.SetBrush(*wxGREY_BRUSH); } dc.DrawRectangle(0, 31 - z*31, 64, 2); } // octagon for visual aid for diagonal adjustment dc.SetPen(*wxLIGHT_GREY_PEN); dc.SetBrush(*wxWHITE_BRUSH); if (GROUP_TYPE_STICK == g->control_group->type) { // outline and fill colors wxBrush LightGrayBrush("#dddddd"); wxPen LightGrayPen("#bfbfbf"); dc.SetBrush(LightGrayBrush); dc.SetPen(LightGrayPen); // polygon offset float max , diagonal , box = 64 , d_of = box / 256.0 , x_of = box / 2.0; if (g->control_group->name == "Main Stick") { max = (87.0f / 127.0f) * 100; diagonal = (55.0f / 127.0f) * 100.0; } else if (g->control_group->name == "C-Stick") { max = (74.0f / 127.0f) * 100; diagonal = (46.0f / 127.0f) * 100; } else { max = (82.0f / 127.0f) * 100; diagonal = (58.0f / 127.0f) * 100; } // polygon corners wxPoint Points[8]; Points[0].x = (int)(0.0 * d_of + x_of); Points[0].y = (int)(max * d_of + x_of); Points[1].x = (int)(diagonal * d_of + x_of); Points[1].y = (int)(diagonal * d_of + x_of); Points[2].x = (int)(max * d_of + x_of); Points[2].y = (int)(0.0 * d_of + x_of); Points[3].x = (int)(diagonal * d_of + x_of); Points[3].y = (int)(-diagonal * d_of + x_of); Points[4].x = (int)(0.0 * d_of + x_of); Points[4].y = (int)(-max * d_of + x_of); Points[5].x = (int)(-diagonal * d_of + x_of); Points[5].y = (int)(-diagonal * d_of + x_of); Points[6].x = (int)(-max * d_of + x_of); Points[6].y = (int)(0.0 * d_of + x_of); Points[7].x = (int)(-diagonal * d_of + x_of); Points[7].y = (int)(diagonal * d_of + x_of); // draw polygon dc.DrawPolygon(8, Points); } else { dc.DrawRectangle(16, 16, 32, 32); } if (GROUP_TYPE_CURSOR != g->control_group->type) { // deadzone circle dc.SetBrush(*wxLIGHT_GREY_BRUSH); dc.DrawCircle(32, 32, g->control_group->settings[SETTING_DEADZONE]->value * 32); } // raw dot { float xx, yy; xx = g->control_group->controls[3]->control_ref->State(); xx -= g->control_group->controls[2]->control_ref->State(); yy = g->control_group->controls[1]->control_ref->State(); yy -= g->control_group->controls[0]->control_ref->State(); dc.SetPen(*wxGREY_PEN); dc.SetBrush(*wxGREY_BRUSH); DrawCoordinate(dc, xx, yy); } // adjusted dot if (x != 0 && y != 0) { dc.SetPen(*wxRED_PEN); dc.SetBrush(*wxRED_BRUSH); // XXX: The adjusted values flip the Y axis to be in the format // the Wii expects. Should this be in WiimoteEmu.cpp instead? DrawCoordinate(dc, x, -y); } } break; case GROUP_TYPE_FORCE : { double raw_dot[3]; double adj_dot[3]; const float deadzone = g->control_group->settings[0]->value; // adjusted ((ControllerEmu::Force*)g->control_group)->GetState(adj_dot); // raw for (unsigned int i=0; i<3; ++i) { raw_dot[i] = (g->control_group->controls[i*2 + 1]->control_ref->State() - g->control_group->controls[i*2]->control_ref->State()); } // deadzone rect for forward/backward visual dc.SetBrush(*wxLIGHT_GREY_BRUSH); dc.SetPen(*wxLIGHT_GREY_PEN); int deadzone_height = deadzone * VIS_BITMAP_SIZE; DrawCenteredRectangle(dc, 0, VIS_BITMAP_SIZE / 2, VIS_BITMAP_SIZE, deadzone_height); #define LINE_HEIGHT 2 int line_y; // raw forward/background line dc.SetPen(*wxGREY_PEN); dc.SetBrush(*wxGREY_BRUSH); line_y = VIS_COORD(raw_dot[2]); DrawCenteredRectangle(dc, VIS_BITMAP_SIZE / 2, line_y, VIS_BITMAP_SIZE, LINE_HEIGHT); // adjusted forward/background line if (adj_dot[2] != 0.0) { dc.SetPen(*wxRED_PEN); dc.SetBrush(*wxRED_BRUSH); line_y = VIS_COORD(adj_dot[2]); DrawCenteredRectangle(dc, VIS_BITMAP_SIZE / 2, line_y, VIS_BITMAP_SIZE, LINE_HEIGHT); } #define DEADZONE_RECT_SIZE 32 // empty deadzone square dc.SetBrush(*wxWHITE_BRUSH); dc.SetPen(*wxLIGHT_GREY_PEN); DrawCenteredRectangle(dc, VIS_BITMAP_SIZE / 2, VIS_BITMAP_SIZE / 2, DEADZONE_RECT_SIZE, DEADZONE_RECT_SIZE); // deadzone square dc.SetBrush(*wxLIGHT_GREY_BRUSH); int dz_size = (deadzone * DEADZONE_RECT_SIZE); DrawCenteredRectangle(dc, VIS_BITMAP_SIZE / 2, VIS_BITMAP_SIZE / 2, dz_size, dz_size); // raw dot dc.SetPen(*wxGREY_PEN); dc.SetBrush(*wxGREY_BRUSH); DrawCoordinate(dc, raw_dot[1], raw_dot[0]); // adjusted dot if (adj_dot[1] != 0 && adj_dot[0] != 0) { dc.SetPen(*wxRED_PEN); dc.SetBrush(*wxRED_BRUSH); DrawCoordinate(dc, adj_dot[1], adj_dot[0]); } } break; case GROUP_TYPE_BUTTONS : { const unsigned int button_count = ((unsigned int)g->control_group->controls.size()); // draw the shit dc.SetPen(*wxGREY_PEN); unsigned int * const bitmasks = new unsigned int[ button_count ]; for (unsigned int n = 0; n<button_count; ++n) bitmasks[n] = (1 << n); unsigned int buttons = 0; ((ControllerEmu::Buttons*)g->control_group)->GetState(&buttons, bitmasks); for (unsigned int n = 0; n<button_count; ++n) { if (buttons & bitmasks[n]) { dc.SetBrush(*wxRED_BRUSH); } else { unsigned char amt = 255 - g->control_group->controls[n]->control_ref->State() * 128; dc.SetBrush(wxBrush(wxColour(amt, amt, amt))); } dc.DrawRectangle(n * 12, 0, 14, 12); // text const std::string name = g->control_group->controls[n]->name; // bit of hax so ZL, ZR show up as L, R dc.DrawText(StrToWxStr(std::string(1, (name[1] && name[1] < 'a') ? name[1] : name[0])), n*12 + 2, 1); } delete[] bitmasks; } break; case GROUP_TYPE_TRIGGERS : { const unsigned int trigger_count = ((unsigned int)(g->control_group->controls.size())); // draw the shit dc.SetPen(*wxGREY_PEN); ControlState deadzone = g->control_group->settings[0]->value; double* const trigs = new double[trigger_count]; ((ControllerEmu::Triggers*)g->control_group)->GetState(trigs); for (unsigned int n = 0; n < trigger_count; ++n) { ControlState trig_r = g->control_group->controls[n]->control_ref->State(); // outline dc.SetPen(*wxGREY_PEN); dc.SetBrush(*wxWHITE_BRUSH); dc.DrawRectangle(0, n*12, 64, 14); // raw dc.SetBrush(*wxGREY_BRUSH); dc.DrawRectangle(0, n*12, trig_r*64, 14); // deadzone affected dc.SetBrush(*wxRED_BRUSH); dc.DrawRectangle(0, n*12, trigs[n]*64, 14); // text dc.DrawText(StrToWxStr(g->control_group->controls[n]->name), 3, n*12 + 1); } delete[] trigs; // deadzone box dc.SetPen(*wxLIGHT_GREY_PEN); dc.SetBrush(*wxTRANSPARENT_BRUSH); dc.DrawRectangle(0, 0, deadzone*64, trigger_count*14); } break; case GROUP_TYPE_MIXED_TRIGGERS : { const unsigned int trigger_count = ((unsigned int)(g->control_group->controls.size() / 2)); // draw the shit dc.SetPen(*wxGREY_PEN); ControlState thresh = g->control_group->settings[0]->value; for (unsigned int n = 0; n < trigger_count; ++n) { dc.SetBrush(*wxRED_BRUSH); ControlState trig_d = g->control_group->controls[n]->control_ref->State(); ControlState trig_a = trig_d > thresh ? 1 : g->control_group->controls[n+trigger_count]->control_ref->State(); dc.DrawRectangle(0, n*12, 64+20, 14); if (trig_d <= thresh) dc.SetBrush(*wxWHITE_BRUSH); dc.DrawRectangle(trig_a*64, n*12, 64+20, 14); dc.DrawRectangle(64, n*12, 32, 14); // text dc.DrawText(StrToWxStr(g->control_group->controls[n+trigger_count]->name), 3, n*12 + 1); dc.DrawText(StrToWxStr(std::string(1, g->control_group->controls[n]->name[0])), 64 + 3, n*12 + 1); } // threshold box dc.SetPen(*wxLIGHT_GREY_PEN); dc.SetBrush(*wxTRANSPARENT_BRUSH); dc.DrawRectangle(thresh*64, 0, 128, trigger_count*14); } break; case GROUP_TYPE_SLIDER: { const ControlState deadzone = g->control_group->settings[0]->value; ControlState state = g->control_group->controls[1]->control_ref->State() - g->control_group->controls[0]->control_ref->State(); dc.SetPen(*wxGREY_PEN); dc.SetBrush(*wxGREY_BRUSH); dc.DrawRectangle(31 + state * 30, 0, 2, 14); double adj_state; ((ControllerEmu::Slider*)g->control_group)->GetState(&adj_state); if (state) { dc.SetPen(*wxRED_PEN); dc.SetBrush(*wxRED_BRUSH); dc.DrawRectangle(31 + adj_state * 30, 0, 2, 14); } // deadzone box dc.SetPen(*wxLIGHT_GREY_PEN); dc.SetBrush(*wxTRANSPARENT_BRUSH); dc.DrawRectangle(32 - deadzone * 32, 0, deadzone * 64, 14); } break; default: break; } }
//------------------------------------------------------------------------------ // custom renderer //------------------------------------------------------------------------------ void CustomRenderer::Draw(wxGrid& grid, wxGridCellAttr& attr, wxDC& dc, const wxRect& rect, int row, int col, bool isSelected) { dc.SetPen(wxPen(attr.GetBackgroundColour(), 1)); dc.SetBrush(wxBrush( attr.GetBackgroundColour(), wxBRUSHSTYLE_SOLID )); dc.DrawRectangle( rect ); if( m_IsDigit || m_dDir == GRIB_NOTDEF ) { //digital format wxString text(wxEmptyString); if( m_dDir != GRIB_NOTDEF ) text.Printf(_T("%03d\u00B0"), (int)m_dDir); dc.DrawLabel(text, rect, wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL); } else { //graphical format double si = sin( (m_dDir - 90) * M_PI / 180. ); double co = cos( (m_dDir - 90) * M_PI / 180. ); int i = rect.GetTopLeft().x + (rect.GetWidth() / 2); int j = rect.GetTopLeft().y + (rect.GetHeight() / 2); int arrowSize = rect.GetHeight() - 3; int dec = -arrowSize / 2; #if wxUSE_GRAPHICS_CONTEXT wxGraphicsContext *gdc; wxClientDC *cdc = new wxClientDC(wxDynamicCast( &grid, wxWindow)); cdc = wxDynamicCast(&dc, wxClientDC); if( cdc ) { gdc = wxGraphicsContext::Create(*cdc); #ifdef __WXGTK__ /*platforms don't manage the same way the gdc origin for linux, we have to re-compute the good one. To DO : verify it works on all other plateforms (done for MSW*/ bool vis = false; int r = 0; for( int c = 0; c < grid.GetNumberCols(); c++){ for(r = 0; r < grid.GetNumberRows(); r++) { if(grid.IsVisible(r, c)){ //find the first row/col vis = true; i -= (c * grid.GetColSize(0)); j -= (r * grid.GetRowHeight(0)); break; } } if(vis) break; } #endif gdc->SetPen(wxPen(attr.GetTextColour(), 3)); gdc->SetBrush(wxBrush( attr.GetBackgroundColour(), wxBRUSHSTYLE_SOLID )); double ii, jj, kk, ll; GetArrowsPoints( si, co, i, j, dec, 0, dec + arrowSize, 0, ii, jj, kk, ll ); gdc->StrokeLine( ii, jj, kk, ll ); GetArrowsPoints( si, co, i, j, dec - 3, 0, dec + 5, 3, ii, jj, kk, ll ); gdc->StrokeLine( ii, jj, kk, ll ); GetArrowsPoints( si, co, i, j, dec - 3, 0, dec + 5, -3, ii, jj, kk, ll ); gdc->StrokeLine( ii, jj, kk, ll ); delete gdc; } else #endif { dc.SetPen(wxPen(attr.GetTextColour(), 3)); double ii, jj, kk, ll; GetArrowsPoints( si, co, i, j, dec, 0, dec + arrowSize, 0, ii, jj, kk, ll ); dc.DrawLine( (int)ii, (int)jj, (int)kk, (int)ll ); GetArrowsPoints( si, co, i, j, dec - 3, 0, dec + 5, 3, ii, jj, kk, ll ); dc.DrawLine( (int)ii, (int)jj, (int)kk, (int)ll ); GetArrowsPoints( si, co, i, j, dec - 3, 0, dec + 5, -3, ii, jj, kk, ll ); dc.DrawLine( (int)ii, (int)jj, (int)kk, (int)ll ); } } }
// draw focus background on area in a way typical on platform void wxComboCtrl::PrepareBackground( wxDC& dc, const wxRect& rect, int flags ) const { #if wxUSE_UXTHEME wxUxThemeHandle hTheme(this, L"COMBOBOX"); #endif wxSize sz = GetClientSize(); bool isEnabled; bool doDrawFocusRect; // also selected // For smaller size control (and for disabled background) use less spacing int focusSpacingX; int focusSpacingY; if ( !(flags & wxCONTROL_ISSUBMENU) ) { // Drawing control isEnabled = IsThisEnabled(); doDrawFocusRect = ShouldDrawFocus(); #if wxUSE_UXTHEME // Windows-style: for smaller size control (and for disabled background) use less spacing if ( hTheme ) { // WinXP Theme focusSpacingX = isEnabled ? 2 : 1; focusSpacingY = sz.y > (GetCharHeight()+2) && isEnabled ? 2 : 1; } else #endif { // Classic Theme if ( isEnabled ) { focusSpacingX = 1; focusSpacingY = 1; } else { focusSpacingX = 0; focusSpacingY = 0; } } } else { // Drawing a list item isEnabled = true; // they are never disabled doDrawFocusRect = flags & wxCONTROL_SELECTED ? true : false; focusSpacingX = 0; focusSpacingY = 0; } // Set the background sub-rectangle for selection, disabled etc wxRect selRect(rect); selRect.y += focusSpacingY; selRect.height -= (focusSpacingY*2); int wcp = 0; if ( !(flags & wxCONTROL_ISSUBMENU) ) wcp += m_widthCustomPaint; selRect.x += wcp + focusSpacingX; selRect.width -= wcp + (focusSpacingX*2); wxColour fgCol; wxColour bgCol; bool doDrawDottedEdge = false; bool doDrawSelRect = true; // TODO: doDrawDottedEdge = true when focus has arrived to control via tab. // (and other cases which are not that apparent). if ( isEnabled ) { // If popup is hidden and this control is focused, // then draw the focus-indicator (selbgcolor background etc.). if ( doDrawFocusRect ) { // NB: We can't really use XP visual styles to get TMT_TEXTCOLOR since // it is not properly defined for combo boxes. Instead, they expect // you to use DrawThemeText. // // Here is, however, sample code how to get theme colours: // // COLORREF cref; // theme->GetThemeColor(hTheme,EP_EDITTEXT,ETS_NORMAL,TMT_TEXTCOLOR,&cref); // dc.SetTextForeground( wxRGBToColour(cref) ); if ( (m_iFlags & wxCC_FULL_BUTTON) && !(flags & wxCONTROL_ISSUBMENU) ) { // Vista style read-only combo fgCol = GetForegroundColour(); bgCol = GetBackgroundColour(); doDrawSelRect = false; doDrawDottedEdge = true; } else { fgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT); bgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT); } } else { fgCol = GetForegroundColour(); bgCol = GetBackgroundColour(); doDrawSelRect = false; } } else { fgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT); bgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE); } dc.SetTextForeground(fgCol); dc.SetBrush(bgCol); if ( doDrawSelRect ) { dc.SetPen(bgCol); dc.DrawRectangle(selRect); } if ( doDrawDottedEdge ) wxMSWDrawFocusRect(dc, selRect); // Don't clip exactly to the selection rectangle so we can draw // to the non-selected area in front of it. wxRect clipRect(rect.x,rect.y, (selRect.x+selRect.width)-rect.x-1,rect.height); dc.SetClippingRegion(clipRect); }