📄 gtk.cpp
字号:
if ( border != wxBORDER_NONE )
{
if ( flags & wxCONTROL_FOCUSED )
{
DrawRect(dc, &rect, m_penBlack);
DrawAntiShadedRect(dc, &rect, m_penDarkGrey, m_penHighlight);
}
else // !focused
{
DrawAntiShadedRect(dc, &rect, m_penDarkGrey, m_penHighlight);
DrawAntiShadedRect(dc, &rect, m_penBlack, m_penHighlight);
}
}
if ( rectIn )
*rectIn = rect;
}
void wxGTKRenderer::DrawButtonBorder(wxDC& dc,
const wxRect& rectTotal,
int flags,
wxRect *rectIn)
{
wxRect rect = rectTotal;
if ( flags & wxCONTROL_PRESSED )
{
// button pressed: draw a black border around it and an inward shade
DrawRect(dc, &rect, m_penBlack);
for ( size_t width = 0; width < BORDER_THICKNESS; width++ )
{
DrawAntiShadedRect(dc, &rect, m_penDarkGrey, m_penHighlight);
DrawAntiShadedRect(dc, &rect, m_penBlack, m_penDarkGrey);
}
}
else
{
// button not pressed
if ( flags & wxCONTROL_ISDEFAULT )
{
// TODO
}
if ( flags & wxCONTROL_FOCUSED )
{
// button is currently default: add an extra border around it
DrawRect(dc, &rect, m_penBlack);
}
// now draw a normal button
for ( size_t width = 0; width < BORDER_THICKNESS; width++ )
{
DrawShadedRect(dc, &rect, m_penHighlight, m_penBlack);
DrawAntiShadedRect(dc, &rect,
wxPen(GetBackgroundColour(flags), 0, wxSOLID),
m_penDarkGrey);
}
}
if ( rectIn )
{
*rectIn = rect;
}
}
// ----------------------------------------------------------------------------
// lines and frames
// ----------------------------------------------------------------------------
void wxGTKRenderer::DrawHorizontalLine(wxDC& dc,
wxCoord y, wxCoord x1, wxCoord x2)
{
dc.SetPen(m_penDarkGrey);
dc.DrawLine(x1, y, x2 + 1, y);
dc.SetPen(m_penHighlight);
y++;
dc.DrawLine(x1, y, x2 + 1, y);
}
void wxGTKRenderer::DrawVerticalLine(wxDC& dc,
wxCoord x, wxCoord y1, wxCoord y2)
{
dc.SetPen(m_penDarkGrey);
dc.DrawLine(x, y1, x, y2 + 1);
dc.SetPen(m_penHighlight);
x++;
dc.DrawLine(x, y1, x, y2 + 1);
}
void wxGTKRenderer::DrawFrame(wxDC& dc,
const wxString& label,
const wxRect& rect,
int flags,
int alignment,
int indexAccel)
{
wxCoord height = 0; // of the label
wxRect rectFrame = rect;
if ( !label.empty() )
{
// the text should touch the top border of the rect, so the frame
// itself should be lower
dc.GetTextExtent(label, NULL, &height);
rectFrame.y += height / 2;
rectFrame.height -= height / 2;
// TODO: the +4 should be customizable
wxRect rectText;
rectText.x = rectFrame.x + 4;
rectText.y = rect.y;
rectText.width = rectFrame.width - 8;
rectText.height = height;
wxRect rectLabel;
DrawLabel(dc, label, rectText, flags, alignment, indexAccel, &rectLabel);
rectLabel.x -= 1;
rectLabel.width += 2;
StandardDrawFrame(dc, rectFrame, rectLabel);
// GTK+ does it like this
dc.SetPen(m_penHighlight);
dc.DrawPoint(rectText.x, rectFrame.y);
dc.DrawPoint(rectText.x + rectLabel.width - 3, rectFrame.y);
}
else
{
// just draw the complete frame
DrawShadedRect(dc, &rectFrame, m_penDarkGrey, m_penHighlight);
DrawShadedRect(dc, &rectFrame, m_penHighlight, m_penDarkGrey);
}
}
// ----------------------------------------------------------------------------
// label
// ----------------------------------------------------------------------------
void wxGTKRenderer::DrawLabel(wxDC& dc,
const wxString& label,
const wxRect& rect,
int flags,
int alignment,
int indexAccel,
wxRect *rectBounds)
{
DrawButtonLabel(dc, label, wxNullBitmap, rect, flags,
alignment, indexAccel, rectBounds);
}
void wxGTKRenderer::DrawButtonLabel(wxDC& dc,
const wxString& label,
const wxBitmap& image,
const wxRect& rect,
int flags,
int alignment,
int indexAccel,
wxRect *rectBounds)
{
if ( flags & wxCONTROL_DISABLED )
{
// make the text grey and draw a shade for it
dc.SetTextForeground(*wxWHITE); // FIXME hardcoded colour
wxRect rectShadow = rect;
rectShadow.x++;
rectShadow.y++;
dc.DrawLabel(label, rectShadow, alignment, indexAccel);
dc.SetTextForeground(wxSCHEME_COLOUR(m_scheme, CONTROL_TEXT_DISABLED));
}
else
{
dc.SetTextForeground(wxSCHEME_COLOUR(m_scheme, CONTROL_TEXT));
}
dc.DrawLabel(label, image, rect, alignment, indexAccel, rectBounds);
}
void wxGTKRenderer::DrawItem(wxDC& dc,
const wxString& label,
const wxRect& rect,
int flags)
{
wxLogTrace(_T("listbox"), _T("drawing item '%s' at (%d, %d)-(%d, %d)"),
label.c_str(),
rect.x, rect.y,
rect.x + rect.width, rect.y + rect.height);
wxColour colFg;
if ( flags & wxCONTROL_SELECTED )
{
dc.SetBrush(wxBrush(wxSCHEME_COLOUR(m_scheme, HIGHLIGHT), wxSOLID));
dc.SetPen(*wxTRANSPARENT_PEN);
dc.DrawRectangle(rect);
colFg = dc.GetTextForeground();
dc.SetTextForeground(wxSCHEME_COLOUR(m_scheme, HIGHLIGHT_TEXT));
}
if ( flags & wxCONTROL_FOCUSED )
{
dc.SetBrush(*wxTRANSPARENT_BRUSH);
wxRect rectFocus = rect;
DrawRect(dc, &rectFocus, m_penBlack);
}
wxRect rectText = rect;
rectText.x += 2;
rectText.y++;
dc.DrawLabel(label, wxNullBitmap, rectText);
if ( flags & wxCONTROL_SELECTED )
{
dc.SetBackgroundMode(wxTRANSPARENT);
}
// restore the text colour
if ( colFg.Ok() )
{
dc.SetTextForeground(colFg);
}
}
void wxGTKRenderer::DrawCheckItem(wxDC& dc,
const wxString& label,
const wxBitmap& bitmap,
const wxRect& rect,
int flags)
{
wxRect rectBitmap = rect;
rectBitmap.x -= 1;
rectBitmap.width = GetCheckBitmapSize().x;
// never draw the focus rect around the check indicators here
DrawCheckButton(dc, wxEmptyString, bitmap, rectBitmap, flags & ~wxCONTROL_FOCUSED);
wxRect rectLabel = rect;
wxCoord shift = rectBitmap.width + 2*GetCheckItemMargin();
rectLabel.x += shift;
rectLabel.width -= shift;
DrawItem(dc, label, rectLabel, flags);
}
// ----------------------------------------------------------------------------
// check/radion buttons
// ----------------------------------------------------------------------------
void wxGTKRenderer::DrawUndeterminedBitmap(wxDC& dc,
const wxRect& rectTotal,
bool isPressed)
{
// FIXME: For sure it is not GTK look but it is better than nothing.
// Show me correct look and I will immediatelly make it better (ABX)
wxRect rect = rectTotal;
wxColour col1, col2;
if ( isPressed )
{
col1 = wxSCHEME_COLOUR(m_scheme, SHADOW_DARK);
col2 = wxSCHEME_COLOUR(m_scheme, CONTROL_PRESSED);
}
else
{
col1 = wxSCHEME_COLOUR(m_scheme, SHADOW_DARK);
col2 = wxSCHEME_COLOUR(m_scheme, SHADOW_IN);
}
dc.SetPen(*wxTRANSPARENT_PEN);
dc.SetBrush(wxBrush(col1, wxSOLID));
dc.DrawRectangle(rect);
rect.Deflate(1);
dc.SetBrush(wxBrush(col2, wxSOLID));
dc.DrawRectangle(rect);
}
void wxGTKRenderer::DrawUncheckBitmap(wxDC& dc,
const wxRect& rectTotal,
bool isPressed)
{
wxRect rect = rectTotal;
DrawAntiRaisedBorder(dc, &rect);
wxColour col = wxSCHEME_COLOUR(m_scheme, SHADOW_IN);
dc.SetPen(wxPen(col, 0, wxSOLID));
dc.DrawPoint(rect.GetRight() - 1, rect.GetBottom() - 1);
if ( isPressed )
col = wxSCHEME_COLOUR(m_scheme, CONTROL_PRESSED);
//else: it is SHADOW_IN, leave as is
dc.SetPen(*wxTRANSPARENT_PEN);
dc.SetBrush(wxBrush(col, wxSOLID));
dc.DrawRectangle(rect);
}
void wxGTKRenderer::DrawCheckBitmap(wxDC& dc, const wxRect& rectTotal)
{
wxRect rect = rectTotal;
DrawAntiShadedRect(dc, &rect, m_penDarkGrey, m_penHighlight);
DrawShadedRect(dc, &rect, m_penBlack, m_penLightGrey);
dc.SetPen(*wxTRANSPARENT_PEN);
dc.SetBrush(wxBrush(wxSCHEME_COLOUR(m_scheme, CONTROL_PRESSED), wxSOLID));
dc.DrawRectangle(rect);
}
void wxGTKRenderer::DrawRadioBitmap(wxDC& dc,
const wxRect& rect,
int flags)
{
wxCoord x = rect.x,
y = rect.y,
xRight = rect.GetRight(),
yBottom = rect.GetBottom();
wxCoord yMid = (y + yBottom) / 2;
// this looks ugly when the background colour of the control is not the
// same ours - radiobox is not transparent as it should be
#if 0
// first fill the middle: as FloodFill() is not implemented on all
// platforms, this is the only thing to do
wxColour colBg = flags & wxCONTROL_CURRENT
? wxSCHEME_COLOUR(m_scheme, CONTROL_CURRENT)
: wxSCHEME_COLOUR(m_scheme, SHADOW_IN);
dc.SetBrush(wxBrush(colBg, wxSOLID));
dc.SetPen(*wxTRANSPARENT_PEN);
dc.DrawRectangle(rect);
#endif // 0
// then draw the upper half
dc.SetPen(flags & wxCONTROL_CHECKED ? m_penDarkGrey : m_penHighlight);
DrawUpZag(dc, x, xRight, yMid, y);
DrawUpZag(dc, x + 1, xRight - 1, yMid, y + 1);
bool drawIt = true;
if ( flags & wxCONTROL_CHECKED )
dc.SetPen(m_penBlack);
else if ( flags & wxCONTROL_PRESSED )
dc.SetPen(wxPen(wxSCHEME_COLOUR(m_scheme, CONTROL_PRESSED), 0, wxSOLID));
else // unchecked and unpressed
drawIt = false;
if ( drawIt )
DrawUpZag(dc, x + 2, xRight - 2, yMid, y + 2);
// and then the lower one
dc.SetPen(flags & wxCONTROL_CHECKED ? m_penHighlight : m_penBlack);
DrawDownZag(dc, x, xRight, yMid, yBottom);
if ( !(flags & wxCONTROL_CHECKED) )
dc.SetPen(m_penDarkGrey);
DrawDownZag(dc, x + 1, xRight - 1, yMid, yBottom - 1);
if ( !(flags & wxCONTROL_CHECKED) )
drawIt = true; // with the same pen
else if ( flags & wxCONTROL_PRESSED )
{
dc.SetPen(wxPen(wxSCHEME_COLOUR(m_scheme, CONTROL_PRESSED), 0, wxSOLID));
drawIt = true;
}
else // checked and unpressed
drawIt = false;
if ( drawIt )
DrawDownZag(dc, x + 2, xRight - 2, yMid, yBottom - 2);
}
void wxGTKRenderer::DrawUpZag(wxDC& dc,
wxCoord x1,
wxCoord x2,
wxCoord y1,
wxCoord y2)
{
wxCoord xMid = (x1 + x2) / 2;
dc.DrawLine(x1, y1, xMid, y2);
dc.DrawLine(xMid, y2, x2 + 1, y1 + 1);
}
void wxGTKRenderer::DrawDownZag(wxDC& dc,
wxCoord x1,
wxCoord x2,
wxCoord y1,
wxCoord y2)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -