📄 renderer.cpp
字号:
wxPageContainer *pc = static_cast<wxPageContainer*>( pageContainer ); wxPen pen = (tabIdx == pc->GetSelection()) ? wxPen( pc->GetBorderColour() ) : wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE)); if(tabIdx == pc->GetSelection()) { int posy = pc->HasFlag(wxFNB_BOTTOM) ? 2 : VERTICAL_BORDER_PADDING; int th = tabHeight - 5; wxRect rect(posx, posy, tabWidth, th); wxColour col2 = (pc->HasFlag( wxFNB_BOTTOM ) ) ? pc->GetGradientColourTo() : pc->GetGradientColourFrom(); wxColour col1 = (pc->HasFlag( wxFNB_BOTTOM ) ) ? pc->GetGradientColourFrom() : pc->GetGradientColourTo(); PaintStraightGradientBox(dc, rect, col1, col2); dc.SetBrush(*wxTRANSPARENT_BRUSH); dc.SetPen(pen); dc.DrawRectangle(rect); // erase the bottom/top line of the rectangle dc.SetPen( wxPen( pc->GetGradientColourFrom() ) ); if(pc->HasFlag(wxFNB_BOTTOM)) dc.DrawLine(rect.x, 2, rect.x + rect.width, 2); else dc.DrawLine(rect.x, rect.y + rect.height - 1, rect.x + rect.width, rect.y + rect.height - 1); } else { // We dont draw a rectangle for non selected tabs, but only // vertical line on the left dc.SetPen(borderPen); dc.DrawLine(posx + tabWidth, VERTICAL_BORDER_PADDING + 3, posx + tabWidth, tabHeight - 4); } // ----------------------------------- // Text and image drawing // ----------------------------------- // Text drawing offset from the left border of the // rectangle int textOffset; // The width of the images are 16 pixels int padding = static_cast<wxFlatNotebook*>( pc->GetParent() )->GetPadding(); bool hasImage = pc->GetPageInfoVector()[tabIdx].GetImageIndex() != -1; int imageYCoord = pc->HasFlag(wxFNB_BOTTOM) ? 6 : 8; hasImage ? textOffset = padding * 2 + 16 : textOffset = padding ; if(tabIdx != pc->GetSelection()) { // Set the text background to be like the vertical lines dc.SetTextForeground(pc->GetNonoActiveTextColor()); } if(hasImage) { int imageXOffset = textOffset - 16 - padding; dc.DrawBitmap((*pc->GetImageList())[pc->GetPageInfoVector()[tabIdx].GetImageIndex()], posx + imageXOffset, imageYCoord, true); } dc.DrawText(pc->GetPageText(tabIdx), posx + textOffset, imageYCoord); // draw 'x' on tab (if enabled) if(pc->HasFlag(wxFNB_X_ON_TAB) && tabIdx == pc->GetSelection()) { int textWidth, textHeight; dc.GetTextExtent(pc->GetPageText(tabIdx), &textWidth, &textHeight); int tabCloseButtonXCoord = posx + textOffset + textWidth + 1; // take a bitmap from the position of the 'x' button (the x on tab button) // this bitmap will be used later to delete old buttons int tabCloseButtonYCoord = imageYCoord; wxRect x_rect(tabCloseButtonXCoord, tabCloseButtonYCoord, 16, 16); GetBitmap(dc, x_rect, m_tabXBgBmp); // Draw the tab DrawTabX(pc, dc, x_rect, tabIdx, btnStatus); }}//------------------------------------------------------------------// Visual studio 2005 (VS8)//------------------------------------------------------------------void wxFNBRendererVC8::DrawTabs(wxWindow *pageContainer, wxDC &dc, wxEvent &event){ wxPageContainer *pc = static_cast<wxPageContainer*>( pageContainer );#ifndef __WXMAC__ // Works well on MSW & GTK, however this lines should be skipped on MAC if(pc->GetPageInfoVector().empty() || pc->m_nFrom >= (int)pc->GetPageInfoVector().GetCount()) { pc->Hide(); event.Skip(); return; }#endif // Get the text hight int tabHeight = CalcTabHeight( pageContainer ); // Set the font for measuring the tab height wxFont normalFont = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); wxFont boldFont = normalFont; boldFont.SetWeight(wxFONTWEIGHT_BOLD); // Calculate the number of rows required for drawing the tabs wxRect rect = pc->GetClientRect(); // Set the maximum client size#ifdef __WXMAC__ pc->SetSizeHints(wxSize(GetButtonsAreaLength( pc ), tabHeight));#endif wxPen borderPen = wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNSHADOW)); /// Create brushes wxBrush backBrush; backBrush = wxBrush(pc->m_tabAreaColor); wxBrush noselBrush = wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE)); wxBrush selBrush = wxBrush(pc->m_activeTabColor); wxSize size = pc->GetSize(); // Background dc.SetTextBackground(pc->GetBackgroundColour()); dc.SetTextForeground(pc->m_activeTextColor); // If border style is set, set the pen to be border pen if( pc->HasFlag(wxFNB_TABS_BORDER_SIMPLE) ) dc.SetPen(borderPen); else dc.SetPen(*wxTRANSPARENT_PEN); int lightFactor = pc->HasFlag(wxFNB_BACKGROUND_GRADIENT) ? 70 : 0; /// For VC8 style, we color the tab area in gradient coloring PaintStraightGradientBox(dc, pc->GetClientRect(), pc->m_tabAreaColor, LightColour(pc->m_tabAreaColor, lightFactor)); dc.SetBrush(*wxTRANSPARENT_BRUSH); dc.DrawRectangle(0, 0, size.x, size.y); // Take 3 bitmaps for the background for the buttons { wxMemoryDC mem_dc; wxRect rect; //--------------------------------------- // X button //--------------------------------------- rect = wxRect(GetXPos( pc ), 6, 16, 14); mem_dc.SelectObject(m_xBgBmp); mem_dc.Blit(0, 0, rect.width, rect.height, &dc, rect.x, rect.y); mem_dc.SelectObject(wxNullBitmap); //--------------------------------------- // Right button //--------------------------------------- rect = wxRect(GetRightButtonPos( pc ), 6, 16, 14); mem_dc.SelectObject(m_rightBgBmp); mem_dc.Blit(0, 0, rect.width, rect.height, &dc, rect.x, rect.y); mem_dc.SelectObject(wxNullBitmap); //--------------------------------------- // Left button //--------------------------------------- rect = wxRect(GetLeftButtonPos( pc ), 6, 16, 14); mem_dc.SelectObject(m_leftBgBmp); mem_dc.Blit(0, 0, rect.width, rect.height, &dc, rect.x, rect.y); mem_dc.SelectObject(wxNullBitmap); } // We always draw the bottom/upper line of the tabs // regradless the style dc.SetPen(borderPen); DrawTabsLine(pc, dc); // Restore the pen dc.SetPen(borderPen); // Draw labels dc.SetFont(boldFont); int posx; int i = 0, cur = 0; // Update all the tabs from 0 to 'pc->m_nFrom' to be non visible for(i=0; i<pc->m_nFrom; i++) { pc->GetPageInfoVector()[i].SetPosition(wxPoint(-1, -1)); pc->GetPageInfoVector()[i].GetRegion().Clear(); } // Draw the visible tabs, in VC8 style, we draw them from right to left std::vector<wxRect> vTabsInfo; NumberTabsCanFit(pc, vTabsInfo); int activeTabPosx(0); int activeTabWidth(0); int activeTabHeight(0); for(cur=(int)vTabsInfo.size() - 1; cur>=0; cur--) { /// 'i' points to the index of the currently drawn tab /// in pc->GetPageInfoVector() vector i = pc->m_nFrom + cur; dc.SetPen(borderPen); dc.SetBrush((i==pc->GetSelection()) ? selBrush : noselBrush); // Now set the font to the correct font dc.SetFont((i==pc->GetSelection()) ? boldFont : normalFont); // Add the padding to the tab width // Tab width: // +-----------------------------------------------------------+ // | PADDING | IMG | IMG_PADDING | TEXT | PADDING | x |PADDING | // +-----------------------------------------------------------+ int tabWidth = CalcTabWidth( pageContainer, i, tabHeight ); posx = vTabsInfo[cur].x; // By default we clean the tab region // incase we use the VC8 style which requires // the region, it will be filled by the function // drawVc8Tab pc->GetPageInfoVector()[i].GetRegion().Clear(); // Clean the 'x' buttn on the tab // 'Clean' rectanlge is a rectangle with width or height // with values lower than or equal to 0 pc->GetPageInfoVector()[i].GetXRect().SetSize(wxSize(-1, -1)); // Draw the tab // Incase we are drawing the active tab // we need to redraw so it will appear on top // of all other tabs // when using the vc8 style, we keep the position of the active tab so we will draw it again later if( i == pc->GetSelection() && pc->HasFlag( wxFNB_VC8 ) ) { activeTabPosx = posx; activeTabWidth = tabWidth; activeTabHeight = tabHeight; } else { DrawTab(pc, dc, posx, i, tabWidth, tabHeight, pc->m_nTabXButtonStatus); } // Restore the text forground dc.SetTextForeground(pc->m_activeTextColor); // Update the tab position & size pc->GetPageInfoVector()[i].SetPosition(wxPoint(posx, VERTICAL_BORDER_PADDING)); pc->GetPageInfoVector()[i].SetSize(wxSize(tabWidth, tabHeight)); } // Incase we are in VC8 style, redraw the active tab (incase it is visible) if(pc->GetSelection() >= pc->m_nFrom && pc->GetSelection()< pc->m_nFrom + (int)vTabsInfo.size() ) { DrawTab(pc, dc, activeTabPosx, pc->GetSelection(), activeTabWidth, activeTabHeight, pc->m_nTabXButtonStatus); } // Update all tabs that can not fit into the screen as non-visible int xx; for(xx = pc->m_nFrom + (int)vTabsInfo.size(); xx<(int)pc->GetPageInfoVector().size(); xx++) { pc->GetPageInfoVector()[xx].SetPosition(wxPoint(-1, -1)); pc->GetPageInfoVector()[xx].GetRegion().Clear(); } // Draw the left/right/close buttons // Left arrow DrawLeftArrow(pc, dc); DrawRightArrow(pc, dc); DrawX(pc, dc); DrawDropDownArrow(pc, dc);}void wxFNBRendererVC8::DrawTab(wxWindow* pageContainer, wxDC &dc, const int &posx, const int &tabIdx, const int &tabWidth, const int &tabHeight, const int btnStatus){ // Fancy tabs - like with VC71 but with the following differences: // - The Selected tab is colored with gradient color wxPageContainer *pc = static_cast<wxPageContainer*>( pageContainer ); wxPen borderPen = wxPen( pc->GetBorderColour() ); wxPoint tabPoints[8]; // If we draw the first tab or the active tab, // we draw a full tab, else we draw a truncated tab // // X(2) X(3) // X(1) X(4) // // X(5) // // X(0),(7) X(6) // // tabPoints[0].x = pc->HasFlag( wxFNB_BOTTOM ) ? posx : posx + m_factor; tabPoints[0].y = pc->HasFlag( wxFNB_BOTTOM ) ? 2 : tabHeight - 3; tabPoints[1].x = tabPoints[0].x + tabHeight - VERTICAL_BORDER_PADDING - 3 - m_factor; tabPoints[1].y = pc->HasFlag( wxFNB_BOTTOM ) ? tabHeight - (VERTICAL_BORDER_PADDING+2) : (VERTICAL_BORDER_PADDING+2); tabPoints[2].x = tabPoints[1].x + 4; tabPoints[2].y = pc->HasFlag( wxFNB_BOTTOM ) ? tabHeight - VERTICAL_BORDER_PADDING : VERTICAL_BORDER_PADDING; tabPoints[3].x = tabPoints[2].x + tabWidth - 2; tabPoints[3].y = pc->HasFlag( wxFNB_BOTTOM ) ? tabHeight - VERTICAL_BORDER_PADDING : VERTICAL_BORDER_PADDING; tabPoints[4].x = tabPoints[3].x + 1; tabPoints[4].y = pc->HasFlag( wxFNB_BOTTOM ) ? tabPoints[3].y - 1 : tabPoints[3].y + 1; tabPoints[5].x = tabPoints[4].x + 1; tabPoints[5].y = pc->HasFlag( wxFNB_BOTTOM ) ? (tabPoints[4].y - 1 ): tabPoints[4].y + 1; tabPoints[6].x = tabPoints[2].x + tabWidth; tabPoints[6].y = tabPoints[0].y; tabPoints[7].x = tabPoints[0].x; tabPoints[7].y = tabPoints[0].y; pc->GetPageInfoVector()[tabIdx].SetRegion(8, tabPoints); // Draw the polygon wxBrush br = dc.GetBrush(); dc.SetBrush(wxBrush(tabIdx == pc->GetSelection() ? pc->GetActiveTabColour() : pc->GetGradientColourTo() )); dc.SetPen(wxPen(tabIdx == pc->GetSelection() ? wxSystemSettings::GetColour(wxSYS_COLOUR_BTNSHADOW) : pc->GetBorderColour())); dc.DrawPolygon(8, tabPoints); // Restore the brush dc.SetBrush(br); wxRect rect = pc->GetClientRect();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -