📄 win32.cpp
字号:
// draw the text, image and the focus around them (if necessary) wxRect rectLabel( REVERSE_FOR_VERTICAL(rect.x,rect.y), REVERSE_FOR_VERTICAL(rect.width,rect.height) ); rectLabel.Deflate(1, 1); if ( isVertical ) { // draw it horizontally into memory and rotate for screen wxMemoryDC dcMem; wxBitmap bitmapRotated, bitmapMem( rectLabel.x + rectLabel.width, rectLabel.y + rectLabel.height ); dcMem.SelectObject(bitmapMem); dcMem.SetBackground(dc.GetBackground()); dcMem.SetFont(dc.GetFont()); dcMem.SetTextForeground(dc.GetTextForeground()); dcMem.Clear(); bitmapRotated =#if wxUSE_IMAGE wxBitmap( wxImage( bitmap.ConvertToImage() ).Rotate90(dir==wxLEFT) )#else bitmap#endif // wxUSE_IMAGE ; DrawButtonLabel(dcMem, label, bitmapRotated, rectLabel, flags, wxALIGN_CENTRE, indexAccel); dcMem.SelectObject(wxNullBitmap); bitmapMem = bitmapMem.GetSubBitmap(rectLabel);#if wxUSE_IMAGE bitmapMem = wxBitmap(wxImage(bitmapMem.ConvertToImage()).Rotate90(dir==wxRIGHT));#endif // wxUSE_IMAGE dc.DrawBitmap(bitmapMem, rectLabel.y, rectLabel.x, false); } else { DrawButtonLabel(dc, label, bitmap, rectLabel, flags, wxALIGN_CENTRE, indexAccel); } // now draw the tab border itself (maybe use DrawRoundedRectangle()?) static const wxCoord CUTOFF = 2; // radius of the rounded corner wxCoord x = SELECT_FOR_VERTICAL(rect.x,rect.y), y = SELECT_FOR_VERTICAL(rect.y,rect.x), x2 = SELECT_FOR_VERTICAL(rect.GetRight(),rect.GetBottom()), y2 = SELECT_FOR_VERTICAL(rect.GetBottom(),rect.GetRight()); // FIXME: all this code will break if the tab indent or the border width, // it is tied to the fact that both of them are equal to 2 switch ( dir ) { default: // default is top case wxLEFT: // left orientation looks like top but IsVertical makes x and y reversed case wxTOP: // top is not vertical so use coordinates in written order dc.SetPen(m_penHighlight); dc.DrawLine(REVERSE_FOR_VERTICAL(x, y2), REVERSE_FOR_VERTICAL(x, y + CUTOFF)); dc.DrawLine(REVERSE_FOR_VERTICAL(x, y + CUTOFF), REVERSE_FOR_VERTICAL(x + CUTOFF, y)); dc.DrawLine(REVERSE_FOR_VERTICAL(x + CUTOFF, y), REVERSE_FOR_VERTICAL(x2 - CUTOFF + 1, y)); dc.SetPen(m_penBlack); dc.DrawLine(REVERSE_FOR_VERTICAL(x2, y2), REVERSE_FOR_VERTICAL(x2, y + CUTOFF)); dc.DrawLine(REVERSE_FOR_VERTICAL(x2, y + CUTOFF), REVERSE_FOR_VERTICAL(x2 - CUTOFF, y)); dc.SetPen(m_penDarkGrey); dc.DrawLine(REVERSE_FOR_VERTICAL(x2 - 1, y2), REVERSE_FOR_VERTICAL(x2 - 1, y + CUTOFF - 1)); if ( flags & wxCONTROL_SELECTED ) { dc.SetPen(m_penLightGrey); // overwrite the part of the border below this tab dc.DrawLine(REVERSE_FOR_VERTICAL(x + 1, y2 + 1), REVERSE_FOR_VERTICAL(x2 - 1, y2 + 1)); // and the shadow of the tab to the left of us dc.DrawLine(REVERSE_FOR_VERTICAL(x + 1, y + CUTOFF + 1), REVERSE_FOR_VERTICAL(x + 1, y2 + 1)); } break; case wxRIGHT: // right orientation looks like bottom but IsVertical makes x and y reversed case wxBOTTOM: // bottom is not vertical so use coordinates in written order dc.SetPen(m_penHighlight); // we need to continue one pixel further to overwrite the corner of // the border for the selected tab dc.DrawLine(REVERSE_FOR_VERTICAL(x, y - (flags & wxCONTROL_SELECTED ? 1 : 0)), REVERSE_FOR_VERTICAL(x, y2 - CUTOFF)); dc.DrawLine(REVERSE_FOR_VERTICAL(x, y2 - CUTOFF), REVERSE_FOR_VERTICAL(x + CUTOFF, y2)); dc.SetPen(m_penBlack); dc.DrawLine(REVERSE_FOR_VERTICAL(x + CUTOFF, y2), REVERSE_FOR_VERTICAL(x2 - CUTOFF + 1, y2)); dc.DrawLine(REVERSE_FOR_VERTICAL(x2, y), REVERSE_FOR_VERTICAL(x2, y2 - CUTOFF)); dc.DrawLine(REVERSE_FOR_VERTICAL(x2, y2 - CUTOFF), REVERSE_FOR_VERTICAL(x2 - CUTOFF, y2)); dc.SetPen(m_penDarkGrey); dc.DrawLine(REVERSE_FOR_VERTICAL(x + CUTOFF, y2 - 1), REVERSE_FOR_VERTICAL(x2 - CUTOFF + 1, y2 - 1)); dc.DrawLine(REVERSE_FOR_VERTICAL(x2 - 1, y), REVERSE_FOR_VERTICAL(x2 - 1, y2 - CUTOFF + 1)); if ( flags & wxCONTROL_SELECTED ) { dc.SetPen(m_penLightGrey); // overwrite the part of the (double!) border above this tab dc.DrawLine(REVERSE_FOR_VERTICAL(x + 1, y - 1), REVERSE_FOR_VERTICAL(x2 - 1, y - 1)); dc.DrawLine(REVERSE_FOR_VERTICAL(x + 1, y - 2), REVERSE_FOR_VERTICAL(x2 - 1, y - 2)); // and the shadow of the tab to the left of us dc.DrawLine(REVERSE_FOR_VERTICAL(x + 1, y2 - CUTOFF), REVERSE_FOR_VERTICAL(x + 1, y - 1)); } break; } #undef SELECT_FOR_VERTICAL #undef REVERSE_FOR_VERTICAL}#endif // wxUSE_NOTEBOOK#if wxUSE_SLIDER// ----------------------------------------------------------------------------// slider// ----------------------------------------------------------------------------wxSizewxWin32Renderer::GetSliderThumbSize(const wxRect& WXUNUSED(rect), int lenThumb, wxOrientation orient) const{ wxSize size; wxCoord width = wxMax (lenThumb, SLIDER_THUMB_LENGTH) / 2; wxCoord height = wxMax (lenThumb, SLIDER_THUMB_LENGTH); if (orient == wxHORIZONTAL) { size.x = width; size.y = height; } else { // == wxVERTICAL size.x = height; size.y = width; } return size;}wxRect wxWin32Renderer::GetSliderShaftRect(const wxRect& rectOrig, int lenThumb, wxOrientation orient, long style) const{ bool transpose = (orient == wxVERTICAL); bool left = ((style & wxSL_AUTOTICKS) != 0) & (((style & wxSL_TOP) != 0) & !transpose | ((style & wxSL_LEFT) != 0) & transpose | ((style & wxSL_BOTH) != 0)); bool right = ((style & wxSL_AUTOTICKS) != 0) & (((style & wxSL_BOTTOM) != 0) & !transpose | ((style & wxSL_RIGHT) != 0) & transpose | ((style & wxSL_BOTH) != 0)); wxRect rect = rectOrig; wxSize sizeThumb = GetSliderThumbSize (rect, lenThumb, orient); if (orient == wxHORIZONTAL) { rect.x += SLIDER_MARGIN; if (left & right) { rect.y += wxMax ((rect.height - 2*BORDER_THICKNESS) / 2, sizeThumb.y/2); } else if (left) { rect.y += wxMax ((rect.height - 2*BORDER_THICKNESS - sizeThumb.y/2), sizeThumb.y/2); } else { rect.y += sizeThumb.y/2; } rect.width -= 2*SLIDER_MARGIN; rect.height = 2*BORDER_THICKNESS; } else { // == wxVERTICAL rect.y += SLIDER_MARGIN; if (left & right) { rect.x += wxMax ((rect.width - 2*BORDER_THICKNESS) / 2, sizeThumb.x/2); } else if (left) { rect.x += wxMax ((rect.width - 2*BORDER_THICKNESS - sizeThumb.x/2), sizeThumb.x/2); } else { rect.x += sizeThumb.x/2; } rect.width = 2*BORDER_THICKNESS; rect.height -= 2*SLIDER_MARGIN; } return rect;}void wxWin32Renderer::DrawSliderShaft(wxDC& dc, const wxRect& rectOrig, int lenThumb, wxOrientation orient, int flags, long style, wxRect *rectShaft){ /* show shaft geometry shaft +-------------+ | | | XXX | <-- x1 | XXX | | XXX | | XXX | | XXX | <-- x2 | | +-------------+ ^ ^ | | y1 y2 */ if (flags & wxCONTROL_FOCUSED) { DrawFocusRect(dc, rectOrig); } wxRect rect = GetSliderShaftRect(rectOrig, lenThumb, orient, style); if (rectShaft) *rectShaft = rect; DrawSunkenBorder(dc, &rect);}void wxWin32Renderer::DrawSliderThumb(wxDC& dc, const wxRect& rect, wxOrientation orient, int flags, long style){ /* show thumb geometry H <--- y1 H H B H H B H H B <--- y3 H D B H D B H D B H D B where H is highlight colour H D B D dark grey H D B B black H D B H D B H D B <--- y4 H D B H D B B <--- y2 ^ ^ ^ | | | x1 x3 x2 The interior of this shape is filled with the hatched brush if the thumb is pressed. */ DrawBackground(dc, wxNullColour, rect, flags); bool transpose = (orient == wxVERTICAL); bool left = ((style & wxSL_AUTOTICKS) != 0) & (((style & wxSL_TOP) != 0) & !transpose | ((style & wxSL_LEFT) != 0) & transpose) & ((style & wxSL_BOTH) == 0); bool right = ((style & wxSL_AUTOTICKS) != 0) & (((style & wxSL_BOTTOM) != 0) & !transpose | ((style & wxSL_RIGHT) != 0) & transpose) & ((style & wxSL_BOTH) == 0); wxCoord sizeArrow = (transpose ? rect.height : rect.width) / 2; wxCoord c = ((transpose ? rect.height : rect.width) - 2*sizeArrow); wxCoord x1, x2, x3, y1, y2, y3, y4; x1 = (transpose ? rect.y : rect.x); x2 = (transpose ? rect.GetBottom() : rect.GetRight()); x3 = (x1-1+c) + sizeArrow; y1 = (transpose ? rect.x : rect.y); y2 = (transpose ? rect.GetRight() : rect.GetBottom()); y3 = (left ? (y1-1+c) + sizeArrow : y1); y4 = (right ? (y2+1-c) - sizeArrow : y2); dc.SetPen(m_penBlack); if (left) { DrawLine(dc, x3+1-c, y1, x2, y3, transpose); } DrawLine(dc, x2, y3, x2, y4, transpose); if (right) { DrawLine(dc, x3+1-c, y2, x2, y4, transpose); } else { DrawLine(dc, x1, y2, x2, y2, transpose); } dc.SetPen(m_penDarkGrey); DrawLine(dc, x2-1, y3+1, x2-1, y4-1, transpose); if (right) { DrawLine(dc, x3+1-c, y2-1, x2-1, y4, transpose); } else { DrawLine(dc, x1+1, y2-1, x2-1, y2-1, transpose); } dc.SetPen(m_penHighlight); if (left) { DrawLine(dc, x1, y3, x3, y1, transpose); DrawLine(dc, x3+1-c, y1+1, x2-1, y3, transpose); } else { DrawLine(dc, x1, y1, x2, y1, transpose); } DrawLine(dc, x1, y3, x1, y4, transpose); if (right) { DrawLine(dc, x1, y4, x3+c, y2+c, transpose); } if (flags & wxCONTROL_PRESSED) { // TODO: MSW fills the entire area inside, not just the rect wxRect rectInt = rect; if ( transpose ) { rectInt.SetLeft(y3); rectInt.SetRight(y4); } else { rectInt.SetTop(y3); rectInt.SetBottom(y4); } rectInt.Deflate(2);#if !defined(__WXMGL__) static const char *stipple_xpm[] = { /* columns rows colors chars-per-pixel */ "2 2 2 1", " c None", "w c white", /* pixels */ "w ", " w", };#else // VS: MGL can only do 8x8 stipple brushes static const char *stipple_xpm[] = { /* columns rows colors chars-per-pixel */ "8 8 2 1", " c None", "w c white", /* pixels */ "w w w w ", " w w w w", "w w w w ", " w w w w", "w w w w ", " w w w w", "w w w w ", " w w w w", };#endif dc.SetBrush(wxBrush(stipple_xpm)); dc.SetTextForeground(wxSCHEME_COLOUR(m_scheme, SHADOW_HIGHLIGHT)); dc.SetTextBackground(wxSCHEME_COLOUR(m_scheme, CONTROL)); dc.SetPen(*wxTRANSPARENT_PEN); dc.DrawRectangle(rectInt); }}void wxWin32Renderer::DrawSliderTicks(wxDC& dc, const wxRect& rect, int lenThumb, wxOrientation orient, int start, int end, int step, int WXUNUSED(flags), long style){ /* show ticks geometry left right ticks shaft ticks ---- XX ---- <-- x1 ---- XX ---- ---- XX ---- ---- XX ---- <-- x2 ^ ^ ^ ^ | | | | y3 y1 y2 y4 */ // empty slider? if (end == start) return; bool transpose = (orient == wxVERTICAL); bool left = ((style & wxSL_AUTOTICKS) != 0) & (((style & wxSL_TOP) != 0) & !transpose | ((style & wxSL_LEFT) != 0) & transpose | ((style & wxSL_BOTH) != 0)); bool right = ((style & wxSL_AUTOTICKS) != 0) & (((style & wxSL_BOTTOM) != 0) & !transpose | ((style &
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -