virtual bool Render(wxRect cell, wxDC *dc, int state) { wxVariant v; GetValue(v); wxString str = v.GetString(); str.Trim(); wxPoint pt = cell.GetTopLeft(); wxFont f = m_font; bool isSelected = false; //state & wxDATAVIEW_CELL_SELECTED; if ( str.StartsWith(ERROR_MARKER, &str) ) { if ( !isSelected ) { dc->SetTextForeground( m_errFgColor ); } } else if( str.StartsWith(WARNING_MARKER, &str) ) { if ( !isSelected ) { dc->SetTextForeground( m_warnFgColor ); } } else if ( str.StartsWith(SUMMARY_MARKER, &str) ) { f.SetWeight(wxFONTWEIGHT_BOLD); } else if( str.StartsWith(wxT("----")) ) { f.SetStyle(wxFONTSTYLE_ITALIC); if ( !isSelected ) dc->SetTextForeground(m_greyColor); } else if(str.Contains(wxT("Entering directory")) || str.Contains(wxT("Leaving directory"))) { f.SetStyle(wxFONTSTYLE_ITALIC); if ( !isSelected ) dc->SetTextForeground(m_greyColor); } if(str.StartsWith(SUMMARY_MARKER_ERROR, &str)) { dc->DrawBitmap(m_errorBmp, pt); pt.x += m_errorBmp.GetWidth() + 2; str.Prepend(wxT(": ")); } else if( str.StartsWith(SUMMARY_MARKER_WARNING, &str)) { dc->DrawBitmap(m_warningBmp, pt); pt.x += m_warningBmp.GetWidth() + 2; str.Prepend(wxT(": ")); } else if(str.StartsWith(SUMMARY_MARKER_SUCCESS, &str)) { dc->DrawBitmap(m_successBmp, pt); pt.x += m_successBmp.GetWidth() + 2; str.Prepend(wxT(": ")); } dc->SetFont(f); if ( (str.length() * m_charWidth) > BUILD_PANE_WIDTH ) { size_t newWidth = (BUILD_PANE_WIDTH / m_charWidth) - 1; str = str.Mid(0, newWidth); } dc->DrawText(str, pt); return true; }
//--------------------------------------------------------- void CVIEW_ScatterPlot::_Draw_Image(wxDC &dc, wxRect r) { CSG_Colors *pColors = m_Options("DENSITY_PAL")->asColors(); wxImage Image(r.GetWidth(), r.GetHeight()); double dCount = (pColors->Get_Count() - 2.0) / log(1.0 + m_Count.Get_Max()); double dx = (m_Count.Get_NX() - 1.0) / (double)r.GetWidth (); double dy = (m_Count.Get_NY() - 1.0) / (double)r.GetHeight(); //----------------------------------------------------- #pragma omp parallel for for(int y=Image.GetHeight()-1; y>=0; y--) { double Count; double ix = 0.0; double iy = m_Count.Get_NY() - 1 - y * dy; for(int x=0; x<Image.GetWidth(); x++, ix+=dx) { int i = m_Count.Get_Value(ix, iy, Count) && Count > 0.0 ? (int)(log(1.0 + Count) * dCount) : 0; Image.SetRGB(x, y, pColors->Get_Red(i), pColors->Get_Green(i), pColors->Get_Blue(i)); } } dc.DrawBitmap(wxBitmap(Image), r.GetTopLeft()); }
bool Render(wxRect rect, wxDC* dc, int state) { bool ret = true; wxString preview = Hit.Preview; // we want to trim the leading whitespace so that the // preview text is aligned left; however trimming the // leading spaces means that we need to account for the // number of spaces we trimmed so that we split // the before/after hit string correctly size_t spaceCount = 0; for (; spaceCount < preview.length(); ++spaceCount) { if (preview[spaceCount] != ' ' && preview[spaceCount] != '\t' && preview[spaceCount] != '\v' && preview[spaceCount] != '\r' && preview[spaceCount] != '\n') { break; } } preview.Trim(false); // break the preview into before/during/after hit. // taking into account the spaces that were trimmed // from the beginning of the string wxString beforeHit = preview.Mid(0, Hit.LineOffset - spaceCount); wxString hit = preview.Mid(Hit.LineOffset - spaceCount, Hit.MatchLength); wxString afterHit = preview.Mid(Hit.LineOffset + Hit.MatchLength - spaceCount); wxSize sizeBeforeHit = GetTextExtent(beforeHit); wxSize sizeHit = GetTextExtent(hit); wxPoint posBeforeHit = rect.GetTopLeft(); wxPoint posHit = rect.GetTopLeft(); posHit.x += sizeBeforeHit.GetWidth(); wxPoint posAfterHit = rect.GetTopLeft(); posAfterHit.x += sizeBeforeHit.GetWidth() + sizeHit.GetWidth(); dc->DrawText(beforeHit, posBeforeHit); dc->SetBackgroundMode(wxSOLID); dc->SetTextBackground(*wxYELLOW); dc->DrawText(hit, posHit); dc->SetBackgroundMode(wxTRANSPARENT); dc->DrawText(afterHit, posAfterHit); return ret; }
/********************************************************************************************* > virtual BOOL CRenderWnd::Create(const wxRect& rect, wxWindow* parent, UINT32 id) Author: Justin_Flude (Xara Group Ltd) <*****@*****.**> Created: ages ago Inputs: Windows instance-style flags; a rectangle describing the position of the scroller; a pointer to its parent window; a child window numeric identifier Outputs: - Returns: TRUE if the window is successfully created. Purpose: Registers a new window class with the operating system, which accepts double clicks, is byte-aligned in video RAM and is responsible for drawing is own backgrounds. Errors: - Scope: Public SeeAlso: CCamView::OnCreate() **********************************************************************************************/ BOOL CRenderWnd::Create(const wxRect& rect, wxWindow *pParent, UINT32 id) { BOOL ok=wxWindow::Create(pParent, id, rect.GetTopLeft(), rect.GetSize(), wxNO_FULL_REPAINT_ON_RESIZE); SetExtraStyle(wxWS_EX_PROCESS_IDLE); #if defined(__WXGTK__) ::SetDoubleBuffer(this, m_DoubleBuffer); #endif return ok; }
void clTabRendererCurved::DrawBottomRect( clTabInfo::Ptr_t activeTab, const wxRect& clientRect, wxDC& dc, const clTabColours& colours, size_t style) { #ifdef __WXOSX__ if(!IS_VERTICAL_TABS(style)) { wxPoint pt1, pt2; dc.SetPen(colours.activeTabBgColour); if(style & kNotebook_BottomTabs) { // bottom tabs pt1 = clientRect.GetTopLeft(); pt2 = clientRect.GetTopRight(); DRAW_LINE(pt1, pt2); } else { // Top tabs pt1 = clientRect.GetBottomLeft(); pt2 = clientRect.GetBottomRight(); pt1.y -= 1; pt2.y -= 1; DRAW_LINE(pt1, pt2); } } #else if(!IS_VERTICAL_TABS(style)) { wxPoint pt1, pt2; dc.SetPen(colours.activeTabPenColour); if(style & kNotebook_BottomTabs) { // bottom tabs pt1 = clientRect.GetTopLeft(); pt2 = clientRect.GetTopRight(); DRAW_LINE(pt1, pt2); } else { // Top tabs pt1 = clientRect.GetBottomLeft(); pt2 = clientRect.GetBottomRight(); DRAW_LINE(pt1, pt2); } } #endif }
virtual bool Render(wxRect cell, wxDC* dc, int state) { wxVariant v; GetValue(v); wxString str = v.GetString(); str.Trim(); wxPoint pt = cell.GetTopLeft(); wxFont f = m_font; dc->SetFont(f); dc->DrawText(str, pt); return true; }
void DisplayVariableDlg::DoAdjustPosition() { if ( m_keepCurrentPosition ) { // Reset the flag m_keepCurrentPosition = false; Move(s_Rect.GetTopLeft()); s_Rect = wxRect(); return; } Move( ::wxGetMousePosition() ); }
void wxCustomStatusBarArt::DrawFieldSeparator(wxDC& dc, const wxRect& fieldRect) { // draw border line dc.SetPen(GetPenColour()); wxPoint bottomPt, topPt; topPt = fieldRect.GetTopLeft(); topPt.y += 2; bottomPt = fieldRect.GetBottomLeft(); bottomPt.y += 1; dc.DrawLine(topPt, bottomPt); }
void SkinRegion::Stroke(wxDC& dc, wxGraphicsContext* gc, const wxRect& rect, int /*n*/) { if (!has_border) return; int penw = border.GetWidth() / 2.0f; wxRect r(rect); r.Deflate(penw, penw); //border.SetCap(wxCAP_PROJECTING); if (rounded) { bool needsDelete = false; if (!gc) { gc = wxGraphicsContext::Create((wxWindowDC&)dc); needsDelete = true; } gc->SetBrush(*wxTRANSPARENT_BRUSH); gc->SetPen(border); gc->DrawRoundedRectangle(rect.x, rect.y, rect.width, rect.height, rounded * .97); rect.Inflate(penw, penw); if (needsDelete) delete gc; } else { dc.SetPen(border); int offset = (int)(border.GetWidth() % 2 == 0); wxPoint x(offset, 0); wxPoint y(0, offset); dc.DrawLine(rect.GetTopLeft(), rect.GetBottomLeft() + y); dc.DrawLine(rect.GetBottomLeft() + y, rect.GetBottomRight() + y + x); dc.DrawLine(rect.GetBottomRight() + y + x, rect.GetTopRight() + x); dc.DrawLine(rect.GetTopRight() + x, rect.GetTopLeft()); } }
void wxImageComboBox::OnDrawItem (wxDC &dc, const wxRect &rect, int item, int flags) const { if ( item == wxNOT_FOUND ) return; const ImageHandle& image = images[item]; wxBitmap* bmp = ConvertImageToBitmap( image.Resolve(), "" ); if( !bmp ) return; dc.DrawBitmap( *bmp, rect.GetTopLeft() ); delete bmp; }
wxSize CDragBar::GetInvalidatedIconRange(const wxRect& rect) { switch(m_orientation) { case wxHORIZONTAL: { int first = FindToolFromCoords(rect.GetTopLeft()); if (first == -1) first = FindToolFromCoords(rect.GetTopLeft() + wxSize(m_margins.GetWidth(), 0)); int last = FindToolFromCoords(rect.GetTopRight()); if (last == -1) { last = FindToolFromCoords(rect.GetTopRight() - wxSize(m_margins.GetWidth(), 0)); if (last == -1) last = static_cast<int>(m_items.size() - 1); } return wxSize(first, last); } case wxVERTICAL: { int first = FindToolFromCoords(rect.GetTopLeft()); if (first == -1) first = FindToolFromCoords(rect.GetTopLeft() + wxSize(0, m_margins.GetHeight())); int last = FindToolFromCoords(rect.GetBottomLeft()); if (last == -1) { last = FindToolFromCoords(rect.GetBottomLeft() - wxSize(0, m_margins.GetHeight())); if (last == -1) last = static_cast<int>(m_items.size() - 1); } return wxSize(first, last); } default: wxFAIL_MSG(wxT("m_orientation not initialized correctly")); return wxSize(0, 0); } }
void Canvas::overdraw_rectangle(wxRect rect, wxDC *dc) { wxRect edges[4]; wxSize hor(rect.GetWidth(), 1), ver(1, rect.GetHeight()); edges[0] = wxRect( rect.GetTopLeft(), hor ); edges[1] = wxRect( rect.GetTopLeft(), ver ); edges[2] = wxRect( rect.GetTopRight(), ver ); edges[3] = wxRect( rect.GetBottomLeft(), hor ); for (int i = 0; i < 4; i++) { dc->DrawBitmap( zoomed_bitmap_for_canvas_region( edges[i] ), edges[i].GetTopLeft() ); } }
void wxImageComboBox::OnDrawBackground (wxDC &dc, const wxRect &rect, int item, int flags) const { if ( item == wxNOT_FOUND ) return; const ImageHandle& image = images[item]; wxBitmap* bmp = ConvertImageToBitmap( image.Resolve(), "" ); if( !bmp ) return; dc.DrawBitmap( *bmp, rect.GetTopLeft() ); if( flags & wxODCB_PAINTING_SELECTED ) dc.DrawRectangle( rect ); delete bmp; }
wxPoint GetWindowOriginSoThatItFits(int display, const wxRect& windowRect) { wxPoint pos = windowRect.GetTopLeft(); wxRect desktop = wxDisplay(display).GetClientArea(); if (!desktop.Contains(windowRect)) { if (pos.x < desktop.x) pos.x = desktop.x; if (pos.y < desktop.y) pos.y = desktop.y; wxPoint bottomRightDiff = windowRect.GetBottomRight() - desktop.GetBottomRight(); if (bottomRightDiff.x > 0) pos.x -= bottomRightDiff.x; if (bottomRightDiff.y > 0) pos.y -= bottomRightDiff.y; } return pos; }
void clTabRendererClassic::FinaliseBackground(wxWindow* parent, wxDC& dc, const wxRect& clientRect, const clTabColours& colours, size_t style) { wxUnusedVar(parent); clTabColours c = colours; if(DrawingUtils::IsDark(c.activeTabBgColour)) { InitDarkColours(c, c.activeTabBgColour); } else { InitLightColours(c, c.activeTabBgColour); } dc.SetPen(c.activeTabPenColour); if(style & kNotebook_BottomTabs) { dc.DrawLine(clientRect.GetTopLeft(), clientRect.GetTopRight()); } else { dc.DrawLine(clientRect.GetBottomLeft(), clientRect.GetBottomRight()); } }
BOOL CScrollerCorner::Create(LPCTSTR, LPCTSTR, DWORD style, const wxRect& rect, wxWindow* pParent, UINT32 id) { return wxWindow::Create( pParent, id, rect.GetTopLeft(), rect.GetSize(), style ); /* return CWnd::Create(AfxRegisterWndClass( CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS, 0, HBRUSH(COLOR_SCROLLBAR + 1), 0), "", style | WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE, rect, parent, id, ctxt); */ }
void Canvas::zoom_to( wxRect rect ) { wxSize window_size = wxWindow::GetClientSize(); float ratio = std::max( float(rect.GetWidth()) / window_size.GetWidth(), float(rect.GetHeight()) / window_size.GetHeight() ); int zoom; if ( ratio < 1 ) { /* Zoom in. */ zoom = round( 1 / ratio ) - 1; } else { /* Zoom out. */ zoom = - round( ratio ); } zoom = std::max( -16, std::min( zoom, 16 ) ); wxPoint sumPoint = (rect.GetTopLeft() + rect.GetBottomRight()); wxPoint centerPoint( sumPoint.x/2, sumPoint.y/2); set_zoom( zoom, centerPoint ); }
void clAuiDockArt::DrawPaneButton( wxDC& dc, wxWindow* window, int button, int button_state, const wxRect& _rect, wxAuiPaneInfo& pane) { int xx = _rect.GetTopLeft().x + ((_rect.GetWidth() - AUI_BUTTON_SIZE) / 2); int yy = _rect.GetTopLeft().y + ((_rect.GetHeight() - AUI_BUTTON_SIZE) / 2); switch(button) { case wxAUI_BUTTON_CLOSE: dc.DrawBitmap(m_dockCloseBmp, xx, yy); break; case wxAUI_BUTTON_MAXIMIZE_RESTORE: if(pane.IsMaximized()) { dc.DrawBitmap(m_dockMinimizeBmp, xx, yy); } else { dc.DrawBitmap(m_dockExpandeBmp, xx, yy); } break; case wxAUI_BUTTON_PIN: dc.DrawBitmap(m_dockMoreBmp, xx, yy); break; default: wxAuiDefaultDockArt::DrawPaneButton(dc, window, button, button_state, _rect, pane); 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 ); } } }
void clAuiMainNotebookTabArt::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) { if(in_rect.GetHeight() == 0) return; // Tabs are not visible int curx = 0; wxGCDC gdc; if(!DrawingUtils::GetGCDC(dc, gdc)) return; wxColour penColour = page.active ? m_activeTabPenColour : m_penColour; wxGraphicsPath path = gdc.GetGraphicsContext()->CreatePath(); gdc.SetPen(penColour); wxSize sz = GetTabSize(gdc, wnd, page.caption, page.bitmap, page.active, close_button_state, x_extent); wxRect rr(in_rect.GetTopLeft(), sz); rr.y += TAB_Y_OFFSET; rr.width -= 1; #ifndef __WXMAC__ if(page.active) { rr.y -= 2; rr.height += 2; } #endif #ifndef __WXGTK__ rr.height += 4; #endif /// the tab start position (x) curx = rr.x + 7; // Set clipping region int clip_width = rr.width; if(rr.x + clip_width > in_rect.x + in_rect.width) clip_width = (in_rect.x + in_rect.width) - rr.x; gdc.SetClippingRegion(rr.x, rr.y, clip_width, rr.height); gdc.SetBrush(m_bgColour); gdc.SetPen(penColour); if(page.active) { gdc.SetBrush(m_activeTabBgColour); path.AddRoundedRectangle(rr.x, rr.y, rr.width - 1, rr.height, m_tabRadius); gdc.GetGraphicsContext()->FillPath(path); gdc.GetGraphicsContext()->StrokePath(path); } else { wxGraphicsPath outerPath = gdc.GetGraphicsContext()->CreatePath(); gdc.SetPen(penColour); outerPath.AddRoundedRectangle(rr.x, rr.y, rr.width - 1, rr.height, m_tabRadius); gdc.GetGraphicsContext()->StrokePath(outerPath); gdc.SetPen(m_innerPenColour); path.AddRoundedRectangle(rr.x + 1, rr.y + 1, rr.width - 3, rr.height - 1, m_tabRadius); gdc.GetGraphicsContext()->StrokePath(path); gdc.SetBrush(m_tabBgColour); gdc.GetGraphicsContext()->StrokePath(path); gdc.GetGraphicsContext()->FillPath(path); gdc.SetPen(penColour); } if(!page.active) { // Draw a line at the bottom rect gdc.SetPen(m_activeTabPenColour); gdc.DrawLine(in_rect.GetBottomLeft(), in_rect.GetBottomRight()); } wxString caption = page.caption; if(caption.IsEmpty()) { caption = "Tp"; } wxFont fnt = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); gdc.SetFont(fnt); wxSize ext = gdc.GetTextExtent(caption); if(caption == "Tp") caption.Clear(); /// Draw the bitmap if(page.bitmap.IsOk()) { int bmpy = (rr.y + (rr.height - page.bitmap.GetHeight()) / 2) - TAB_Y_OFFSET + BMP_Y_SPACER; gdc.GetGraphicsContext()->DrawBitmap(page.bitmap, curx, bmpy, page.bitmap.GetWidth(), page.bitmap.GetHeight()); curx += page.bitmap.GetWidth(); curx += 3; } /// Draw the text wxColour textColour = page.active ? m_activeTabTextColour : m_tabTextColour; gdc.SetTextForeground(textColour); wxDouble textYOffCorrd = (rr.y + (rr.height - ext.y) / 2) - TAB_Y_OFFSET + TEXT_Y_SPACER; gdc.GetGraphicsContext()->DrawText(page.caption, curx, textYOffCorrd); // advance the X offset curx += ext.x; curx += 3; /// Draw the X button on the tab if(close_button_state != wxAUI_BUTTON_STATE_HIDDEN) { curx += 1; wxBitmap xBmp = m_bmpClose; switch(close_button_state) { case wxAUI_BUTTON_STATE_HOVER: xBmp = m_bmpCloseHover; break; case wxAUI_BUTTON_STATE_PRESSED: xBmp = m_bmpClosePressed; break; } int btny = (rr.y + (rr.height - x_button_height) / 2) - TAB_Y_OFFSET + BMP_Y_SPACER; gdc.GetGraphicsContext()->DrawBitmap(xBmp, curx, btny, x_button_height, x_button_height); *out_button_rect = wxRect(curx, btny, x_button_height, x_button_height); curx += x_button_height; } *out_tab_rect = rr; gdc.DestroyClippingRegion(); }
void clAuiMainNotebookTabArt::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) { int curx = 0; wxGCDC gdc; if(!DrawingUtils::GetGCDC(dc, gdc)) return; wxColour penColour = page.active ? m_activeTabPenColour : m_penColour; wxGraphicsPath path = gdc.GetGraphicsContext()->CreatePath(); gdc.SetPen(penColour); wxSize sz = GetTabSize(gdc, wnd, page.caption, page.bitmap, page.active, close_button_state, x_extent); wxRect rr(in_rect.GetTopLeft(), sz); rr.y += TAB_Y_OFFSET; rr.width -= 1; #ifndef __WXMAC__ if(page.active) { rr.y -= 2; rr.height += 2; } #endif #ifdef __WXGTK__ rr.height += TAB_HEIGHT_SPACER; #else rr.height += 4; #endif /// the tab start position (x) curx = rr.x + 7; // Set clipping region int clip_width = rr.width; if(rr.x + clip_width > in_rect.x + in_rect.width) clip_width = (in_rect.x + in_rect.width) - rr.x; gdc.SetClippingRegion(rr.x, rr.y, clip_width, rr.height); gdc.SetBrush(m_bgColour); gdc.SetPen(penColour); if(page.active) { gdc.SetBrush(m_activeTabBgColour); path.AddRoundedRectangle(rr.x, rr.y, rr.width - 1, rr.height, TAB_RADIUS); gdc.GetGraphicsContext()->FillPath(path); gdc.GetGraphicsContext()->StrokePath(path); } else { wxGraphicsPath outerPath = gdc.GetGraphicsContext()->CreatePath(); gdc.SetPen(penColour); outerPath.AddRoundedRectangle(rr.x, rr.y, rr.width - 1, rr.height, TAB_RADIUS); gdc.GetGraphicsContext()->StrokePath(outerPath); gdc.SetPen(m_innerPenColour); path.AddRoundedRectangle(rr.x + 1, rr.y + 1, rr.width - 3, rr.height - 1, TAB_RADIUS); gdc.GetGraphicsContext()->StrokePath(path); gdc.SetBrush(m_tabBgColour); gdc.GetGraphicsContext()->StrokePath(path); gdc.GetGraphicsContext()->FillPath(path); gdc.SetPen(penColour); } if(!page.active) { // Draw a line at the bottom rect gdc.SetPen(m_activeTabPenColour); gdc.DrawLine(in_rect.GetBottomLeft(), in_rect.GetBottomRight()); } wxString caption = page.caption; if(caption.IsEmpty()) { caption = "Tp"; } wxFont fnt = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); if(page.active) { fnt.SetWeight(wxFONTWEIGHT_BOLD); } gdc.SetFont(fnt); wxSize ext = gdc.GetTextExtent(caption); if(caption == "Tp") caption.Clear(); /// Draw the bitmap if(page.bitmap.IsOk()) { int bmpy = (rr.y + (rr.height - page.bitmap.GetHeight()) / 2) - TAB_Y_OFFSET; gdc.GetGraphicsContext()->DrawBitmap(page.bitmap, curx, bmpy, page.bitmap.GetWidth(), page.bitmap.GetHeight()); curx += page.bitmap.GetWidth(); curx += 3; } /// Draw the text wxColour textColour = page.active ? m_activeTabTextColour : m_tabTextColour; gdc.SetTextForeground(textColour); gdc.GetGraphicsContext()->DrawText( page.caption, curx, (rr.y + (rr.height - ext.y) / 2) - TAB_Y_OFFSET + TEXT_Y_SPACER); // advance the X offset curx += ext.x; curx += 3; /// Draw the X button on the tab if(close_button_state != wxAUI_BUTTON_STATE_HIDDEN) { int btny = (rr.y + (rr.height / 2)) - TAB_Y_OFFSET + TEXT_Y_SPACER; if(close_button_state == wxAUI_BUTTON_STATE_PRESSED) { curx += 1; btny += 1; } /// Defines the rectangle surrounding the X button wxRect xRect = wxRect(curx, btny - X_RADIUS, X_DIAMETER, X_DIAMETER); *out_button_rect = xRect; /// Defines the 'x' inside the circle wxPoint circleCenter(curx + X_RADIUS, btny); wxDouble xx_width = ::sqrt(::pow(X_DIAMETER, 2.0) / 2.0); wxDouble x_square = (circleCenter.x - (xx_width / 2.0)); wxDouble y_square = (circleCenter.y - (xx_width / 2.0)); wxPoint2DDouble ptXTopLeft(x_square, y_square); wxRect2DDouble insideRect(ptXTopLeft.m_x, ptXTopLeft.m_y, xx_width, xx_width); insideRect.Inset(1.0, 1.0); // Shrink it by 1 pixle /// Draw the 'x' itself wxGraphicsPath xpath = gdc.GetGraphicsContext()->CreatePath(); xpath.MoveToPoint(insideRect.GetLeftTop()); xpath.AddLineToPoint(insideRect.GetRightBottom()); xpath.MoveToPoint(insideRect.GetRightTop()); xpath.AddLineToPoint(insideRect.GetLeftBottom()); gdc.SetPen(wxPen(textColour, 1)); gdc.GetGraphicsContext()->StrokePath(xpath); curx += X_DIAMETER; } *out_tab_rect = rr; gdc.DestroyClippingRegion(); }
void clAuiGlossyTabArt::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) { wxColour bgColour = wxColour(EditorConfigST::Get()->GetCurrentOutputviewBgColour()); wxColour penColour; wxColour textColour; bool isBgColourDark = DrawingUtils::IsDark(bgColour); if ( isBgColourDark ) { penColour = DrawingUtils::LightColour(bgColour, 4.0); } else { bgColour = *wxWHITE; penColour = wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW); } textColour = EditorConfigST::Get()->GetCurrentOutputviewFgColour(); int curx = 0; // Allow the plugins to override the default colours clColourEvent colourEvent( wxEVT_COLOUR_TAB ); colourEvent.SetIsActiveTab( page.active ); colourEvent.SetPage( page.window ); if ( EventNotifier::Get()->ProcessEvent( colourEvent ) ) { bgColour = colourEvent.GetBgColour(); textColour = colourEvent.GetFgColour(); } // Allow the plugins to override the border colour wxColour originalPenColour = penColour; clColourEvent borderColourEvent( wxEVT_GET_TAB_BORDER_COLOUR ); if ( EventNotifier::Get()->ProcessEvent( borderColourEvent ) ) { penColour = borderColourEvent.GetBorderColour(); } wxGCDC gdc; if ( !DrawingUtils::GetGCDC(dc, gdc) ) return; m_penColour = penColour; wxGraphicsPath path = gdc.GetGraphicsContext()->CreatePath(); gdc.SetPen( penColour ); wxSize sz = GetTabSize(gdc, wnd, page.caption, page.bitmap, page.active, close_button_state, x_extent); wxRect rr (in_rect.GetTopLeft(), sz); rr.y += TAB_Y_OFFSET; rr.width -= 1; #ifndef __WXMAC__ if ( page.active ) { rr.y -= 2; rr.height += 2; } #endif #ifdef __WXGTK__ rr.height += TAB_HEIGHT_SPACER; #else rr.height += 4; #endif /// the tab start position (x) curx = rr.x + 7; // Set clipping region int clip_width = rr.width; if (rr.x + clip_width > in_rect.x + in_rect.width) clip_width = (in_rect.x + in_rect.width) - rr.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 -- gdc.SetClippingRegion(rr.x, rr.y, clip_width, rr.height); gdc.SetBrush( bgColour ); gdc.SetPen( penColour ); if ( page.active ) { path.AddRoundedRectangle(rr.x, rr.y, rr.width-1, rr.height, 6.5); gdc.GetGraphicsContext()->FillPath( path ); gdc.GetGraphicsContext()->StrokePath( path ); } else { if ( !m_bgColour.IsOk() ) { wxColour b, p; DoGetTabAreaBackgroundColour(b, p); m_bgColour = b; } DoDrawInactiveTabSeparator(gdc, rr); } if ( !page.active ) { // Draw a line at the bottom rect gdc.SetPen(penColour); gdc.DrawLine(in_rect.GetBottomLeft(), in_rect.GetBottomRight()); } wxString caption = page.caption; if ( caption.IsEmpty() ) { caption = "Tp"; } wxFont fnt = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); if ( page.active ) { fnt.SetWeight(wxFONTWEIGHT_BOLD); } gdc.SetFont( fnt ); wxSize ext = gdc.GetTextExtent( caption ); if ( caption == "Tp" ) caption.Clear(); /// Draw the bitmap if ( page.bitmap.IsOk() ) { int bmpy = (rr.y + (rr.height - page.bitmap.GetHeight())/2)-TAB_Y_OFFSET; gdc.GetGraphicsContext()->DrawBitmap( page.bitmap, curx, bmpy, page.bitmap.GetWidth(), page.bitmap.GetHeight()); curx += page.bitmap.GetWidth(); curx += 3; } /// Draw the text gdc.SetTextForeground( textColour ); gdc.GetGraphicsContext()->DrawText( page.caption, curx, (rr.y + (rr.height - ext.y)/2)-TAB_Y_OFFSET+TEXT_Y_SPACER); // advance the X offset curx += ext.x; curx += 3; /// Draw the X button on the tab if ( close_button_state != wxAUI_BUTTON_STATE_HIDDEN ) { int btny = (rr.y + (rr.height/2))-TAB_Y_OFFSET+TEXT_Y_SPACER; if ( close_button_state == wxAUI_BUTTON_STATE_PRESSED ) { curx += 1; btny += 1; } /// Defines the rectangle surrounding the X button wxRect xRect = wxRect(curx, btny - X_RADIUS, X_DIAMETER, X_DIAMETER); *out_button_rect = xRect; /// Defines the 'x' inside the circle wxPoint circleCenter( curx + X_RADIUS, btny); wxDouble xx_width = ::sqrt( ::pow(X_DIAMETER, 2.0) /2.0 ); wxDouble x_square = (circleCenter.x - (xx_width/2.0)); wxDouble y_square = (circleCenter.y - (xx_width/2.0)); wxPoint2DDouble ptXTopLeft(x_square, y_square); wxRect2DDouble insideRect(ptXTopLeft.m_x, ptXTopLeft.m_y, xx_width, xx_width); insideRect.Inset(1.0 , 1.0); // Shrink it by 1 pixle /// Draw the 'x' itself wxGraphicsPath xpath = gdc.GetGraphicsContext()->CreatePath(); xpath.MoveToPoint( insideRect.GetLeftTop() ); xpath.AddLineToPoint( insideRect.GetRightBottom()); xpath.MoveToPoint( insideRect.GetRightTop() ); xpath.AddLineToPoint( insideRect.GetLeftBottom() ); gdc.SetPen( wxPen(textColour, 1) ); gdc.GetGraphicsContext()->StrokePath( xpath ); curx += X_DIAMETER; } *out_tab_rect = rr; gdc.DestroyClippingRegion(); }
// draw the continuity starting at a specific offset void DrawCont(wxDC& dc, const CC_textline_list& print_continuity, const wxRect& bounding, bool landscape) { SaveAndRestore_DeviceOrigin orig_dev(dc); SaveAndRestore_UserScale orig_scale(dc); SaveAndRestore_TextForeground orig_text(dc); SaveAndRestore_Font orig_font(dc); #if DEBUG dc.DrawRectangle(bounding); #endif dc.SetTextForeground(*wxBLACK); int pageMiddle = (bounding.GetWidth()/2); size_t numLines = 0; for (auto text = print_continuity.begin(); text != print_continuity.end(); ++text) { if (text->GetOnSheet()) { ++numLines; } } int font_size = ((bounding.GetBottom() - bounding.GetTop()) - (numLines - 1)*2)/(numLines ? numLines : 1); //font size, we scale to be no more than 256 pixels. font_size = std::min(font_size, 10); wxFont *contPlainFont = wxTheFontList->FindOrCreateFont(font_size, wxMODERN, wxNORMAL, wxNORMAL); wxFont *contBoldFont = wxTheFontList->FindOrCreateFont(font_size, wxMODERN, wxNORMAL, wxBOLD); wxFont *contItalFont = wxTheFontList->FindOrCreateFont(font_size, wxMODERN, wxITALIC, wxNORMAL); wxFont *contBoldItalFont = wxTheFontList->FindOrCreateFont(font_size, wxMODERN, wxITALIC, wxBOLD); dc.SetFont(*contPlainFont); const wxCoord maxtexth = contPlainFont->GetPointSize()+2; float y = bounding.GetTop(); const wxCoord charWidth = dc.GetCharWidth(); for (auto& cont : print_continuity) { float x = bounding.GetLeft(); // Determine how to center the text if (cont.GetCenter()) { x += pageMiddle; auto chunks = cont.GetChunks(); for (auto& c : chunks) { bool do_tab = false; switch (c.font) { case PSFONT_SYMBOL: { wxCoord textw, texth; dc.GetTextExtent(wxT("O"), &textw, &texth); x += textw * c.text.length(); } break; case PSFONT_NORM: dc.SetFont(*contPlainFont); break; case PSFONT_BOLD: dc.SetFont(*contBoldFont); break; case PSFONT_ITAL: dc.SetFont(*contItalFont); break; case PSFONT_BOLDITAL: dc.SetFont(*contBoldItalFont); break; case PSFONT_TAB: do_tab = true; break; } if (!do_tab && (c.font != PSFONT_SYMBOL)) { wxCoord textw, texth; dc.GetTextExtent(c.text, &textw, &texth); x -= textw/2; } } } // now draw the text unsigned tabnum = 0; auto chunks = cont.GetChunks(); for (auto& c : chunks) { bool do_tab = false; switch (c.font) { case PSFONT_NORM: case PSFONT_SYMBOL: dc.SetFont(*contPlainFont); break; case PSFONT_BOLD: dc.SetFont(*contBoldFont); break; case PSFONT_ITAL: dc.SetFont(*contItalFont); break; case PSFONT_BOLDITAL: dc.SetFont(*contBoldItalFont); break; case PSFONT_TAB: { tabnum++; wxCoord textw = bounding.GetLeft() + charWidth * TabStops(tabnum, landscape); if (textw >= x) x = textw; else x += charWidth; do_tab = true; } break; default: break; } if (c.font == PSFONT_SYMBOL) { wxCoord textw, texth, textd; dc.GetTextExtent(wxT("O"), &textw, &texth, &textd); const float d = textw; const float top_y = y + texth - textd - textw; for (std::string::const_iterator s = c.text.begin(); s != c.text.end(); s++) { { dc.SetPen(*wxBLACK_PEN); SYMBOL_TYPE sym = (SYMBOL_TYPE)(*s - 'A'); switch (sym) { case SYMBOL_SOL: case SYMBOL_SOLBKSL: case SYMBOL_SOLSL: case SYMBOL_SOLX: dc.SetBrush(*wxBLACK_BRUSH); break; default: dc.SetBrush(*wxTRANSPARENT_BRUSH); } dc.DrawEllipse(x, top_y, d, d); switch (sym) { case SYMBOL_SL: case SYMBOL_X: case SYMBOL_SOLSL: case SYMBOL_SOLX: dc.DrawLine(x-1, top_y + d+1, x + d+1, top_y-1); break; default: break; } switch (sym) { case SYMBOL_BKSL: case SYMBOL_X: case SYMBOL_SOLBKSL: case SYMBOL_SOLX: dc.DrawLine(x-1, top_y-1, x + d+1, top_y + d+1); break; default: break; } } x += d; } } else { if (!do_tab) { wxCoord textw, texth; dc.GetTextExtent(c.text, &textw, &texth); dc.DrawText(c.text, x, y); x += textw; } } } y += maxtexth; } #if DEBUG char buffer[100]; snprintf(buffer, sizeof(buffer), "TopLeft %d, %d", bounding.GetTopLeft().x, bounding.GetTopLeft().y); dc.DrawText(buffer, bounding.GetTopLeft()); snprintf(buffer, sizeof(buffer), "BottomRight %d, %d", bounding.GetBottomRight().x, bounding.GetBottomRight().y); dc.DrawText(buffer, bounding.GetBottomRight()); #endif }
bool wxRect::Contains(const wxRect& rect) const { return Contains(rect.GetTopLeft()) && Contains(rect.GetBottomRight()); }