📄 renderer.cpp
字号:
mem_dc.SelectObject(bmp); mem_dc.Blit(0, 0, rect.width, rect.height, &dc, rect.x, rect.y); mem_dc.SelectObject(wxNullBitmap);}wxColor wxFNBRenderer::RandomColor(){ int r, g, b; r = rand() % 256; // Random value betweem 0-255 g = rand() % 256; // Random value betweem 0-255 b = rand() % 256; // Random value betweem 0-255 return wxColor(r, g, b);}wxColor wxFNBRenderer::LightColour(const wxColour& color, int percent){ int rd, gd, bd, high = 0; wxColor end_color = wxT("WHITE"); rd = end_color.Red() - color.Red(); gd = end_color.Green() - color.Green(); bd = end_color.Blue() - color.Blue(); high = 100; // We take the percent way of the color from color --> white int i = percent; int r = color.Red() + ((i*rd*100)/high)/100; int g = color.Green() + ((i*gd*100)/high)/100; int b = color.Blue() + ((i*bd*100)/high)/100; return wxColor(r, g, b);}void wxFNBRenderer::DrawTabsLine(wxWindow* pageContainer, wxDC& dc){ wxPageContainer *pc = static_cast<wxPageContainer*>( pageContainer ); wxRect clntRect = pc->GetClientRect(); wxRect clientRect, clientRect2, clientRect3; clientRect3 = wxRect(0, 0, clntRect.width, clntRect.height); if(pc->HasFlag(wxFNB_BOTTOM)) { clientRect = wxRect(0, 2, clntRect.width, clntRect.height - 2); clientRect2 = wxRect(0, 1, clntRect.width, clntRect.height - 1); } else { clientRect = wxRect(0, 0, clntRect.width, clntRect.height - 2); clientRect2 = wxRect(0, 0, clntRect.width, clntRect.height - 1); } dc.SetBrush(*wxTRANSPARENT_BRUSH); dc.SetPen( wxPen(pc->GetSingleLineBorderColor()) ); dc.DrawRectangle(clientRect2); dc.DrawRectangle(clientRect3); dc.SetPen(wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNSHADOW))); dc.DrawRectangle(clientRect); if( !pc->HasFlag(wxFNB_TABS_BORDER_SIMPLE) ) { dc.SetPen(wxPen( pc->HasFlag( wxFNB_VC71) ? wxColour(247, 243, 233) : pc->m_tabAreaColor)); dc.DrawLine(0, 0, 0, clientRect.height+1); if(pc->HasFlag(wxFNB_BOTTOM)) { dc.DrawLine(0, clientRect.height+1, clientRect.width, clientRect.height+1); } else dc.DrawLine(0, 0, clientRect.width, 0); dc.DrawLine(clientRect.width - 1, 0, clientRect.width - 1, clientRect.height+1); }}int wxFNBRenderer::CalcTabWidth(wxWindow *pageContainer, int tabIdx, int tabHeight){ wxPageContainer *pc = static_cast<wxPageContainer*>( pageContainer ); int tabWidth, shapePoints(0), width, pom; wxMemoryDC dc; // bitmap must be set before it can be used for anything wxBitmap bmp(10, 10); dc.SelectObject(bmp); wxFont normalFont = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); wxFont boldFont(normalFont); boldFont.SetWeight(wxFONTWEIGHT_BOLD); if( pc->IsDefaultTabs() ) shapePoints = (int)(tabHeight*tan((double)pc->GetPageInfoVector()[tabIdx].GetTabAngle()/180.0*M_PI)); if(pc->GetSelection() == tabIdx) dc.SetFont(boldFont); else dc.SetFont(normalFont); dc.GetTextExtent(pc->GetPageText(tabIdx), &width, &pom); // Set a minimum size to a tab if(width < 20) width = 20; tabWidth = ((wxFlatNotebook *)pc->m_pParent)->GetPadding() * 2 + width; /// Style to add a small 'x' button on the top right /// of the tab if(pc->HasFlag(wxFNB_X_ON_TAB) && tabIdx == pc->GetSelection()) { int spacer = 9; if( pc->HasFlag(wxFNB_VC8) ) spacer = 4; tabWidth += ((wxFlatNotebook *)pc->m_pParent)->GetPadding() + spacer; } if( pc->IsDefaultTabs() ) // Default style tabWidth += 2 * shapePoints; bool hasImage = (pc->m_ImageList != NULL && pc->GetPageInfoVector()[tabIdx].GetImageIndex() != -1); // For VC71 style, we only add the icon size (16 pixels) if(hasImage) { if( ! pc->IsDefaultTabs() ) tabWidth += (16 + ((wxFlatNotebook*)pc->m_pParent)->GetPadding()); else // Default style tabWidth += (16 + ((wxFlatNotebook*)pc->m_pParent)->GetPadding()) + shapePoints / 2; } return tabWidth;}void wxFNBRenderer::NumberTabsCanFit(wxWindow *pageContainer, std::vector<wxRect> &vTabInfo, int from){ wxPageContainer *pc = static_cast<wxPageContainer*>( pageContainer ); int tabHeight, clientWidth; wxRect rect = pc->GetClientRect(); clientWidth = rect.width; /// Empty results vTabInfo.clear(); tabHeight = CalcTabHeight( pageContainer ); // The drawing starts from posx int posx = ((wxFlatNotebook *)pc->m_pParent)->GetPadding(); if( from < 0 ) from = pc->m_nFrom; for(int i = from; i<(int)pc->GetPageInfoVector().GetCount(); i++) { int tabWidth = CalcTabWidth( pageContainer, i, tabHeight ); if(posx + tabWidth + GetButtonsAreaLength( pc ) >= clientWidth) break; /// Add a result to the returned vector wxRect tabRect(posx, VERTICAL_BORDER_PADDING, tabWidth , tabHeight); vTabInfo.push_back(tabRect); /// Advance posx posx += tabWidth + wxFNB_HEIGHT_SPACER; }}void wxFNBRenderer::DrawDragHint(wxWindow *pageContainer, int tabIdx){ wxUnusedVar( pageContainer ); wxUnusedVar( tabIdx );}int wxFNBRenderer::CalcTabHeight(wxWindow *pageContainer){ int tabHeight; wxMemoryDC dc; wxUnusedVar( pageContainer ); wxBitmap bmp(10, 10); dc.SelectObject(bmp); // For GTK it seems that we must do this steps in order // for the tabs will get the proper height on initialization // on MSW, preforming these steps yields wierd results wxFont normalFont = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); wxFont boldFont = normalFont; boldFont.SetWeight(wxFONTWEIGHT_BOLD);#ifdef __WXGTK__ dc.SetFont( boldFont );#endif static int height(-1); static int width(-1); if( height == -1 && width == -1 ) { wxString stam = wxT("Tp"); // Temp data to get the text height; dc.GetTextExtent(stam, &width, &height); } tabHeight = height + wxFNB_HEIGHT_SPACER; // We use 8 pixels as padding#ifdef __WXGTK__ // On GTK the tabs are should be larger tabHeight += 6;#endif return tabHeight;}void wxFNBRenderer::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); long style = pc->GetParent()->GetWindowStyleFlag(); // Calculate the number of rows required for drawing the tabs wxRect rect = pc->GetClientRect(); int clientWidth = rect.width; // Set the maximum client size#ifdef __WXMAC__ pc->SetSizeHints(wxSize(GetButtonsAreaLength( pc ), tabHeight));#endif wxPen borderPen = wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNSHADOW)); wxBrush backBrush; if(style & wxFNB_VC71) backBrush = wxBrush(wxColour(247, 243, 233)); else 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((style & wxFNB_VC71 ? wxColour(247, 243, 233) : pc->GetBackgroundColour())); dc.SetTextForeground(pc->m_activeTextColor); dc.SetBrush(backBrush); // If border style is set, set the pen to be border pen if(pc->HasFlag(wxFNB_TABS_BORDER_SIMPLE)) dc.SetPen(borderPen); else { wxColor colr = pc->HasFlag( wxFNB_VC71 ) ? wxColour(247, 243, 233) : pc->GetBackgroundColour(); dc.SetPen( wxPen(colr) ); } 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); if(pc->HasFlag( wxFNB_VC71 )) { int greyLineYVal = pc->HasFlag( wxFNB_BOTTOM ) ? 0 : size.y - 2; int whiteLineYVal = pc->HasFlag( wxFNB_BOTTOM ) ? 3 : size.y - 3; wxPen pen = wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE)); dc.SetPen(pen); // Draw thik grey line between the windows area and // the tab area int num = 0; for(; num<3; num++) dc.DrawLine(0, greyLineYVal + num, size.x, greyLineYVal + num); wxPen wbPen = pc->HasFlag(wxFNB_BOTTOM) ? *wxBLACK_PEN : *wxWHITE_PEN; dc.SetPen( wbPen ); dc.DrawLine(1, whiteLineYVal, size.x - 1, whiteLineYVal); // Restore the pen dc.SetPen(borderPen); }#ifdef __WXMAC__ // On MAC, Add these lines so the tab background gets painted if(pc->GetPageInfoVector().empty() || pc->m_nFrom >= (int)pc->GetPageInfoVector().GetCount()) { pc->Hide(); return; }#endif // Draw labels wxFont normalFont = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); wxFont boldFont = normalFont; boldFont.SetWeight(wxFONTWEIGHT_BOLD); dc.SetFont(boldFont);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -