예제 #1
0
void wxFlatButton::OnPaint(wxPaintEvent& event)
{
    wxUnusedVar(event);
    wxAutoBufferedPaintDC paintDC(this);
    wxGCDC gdc;
    GetGCDC(paintDC, gdc);

    wxRect clientRect = GetClientRect();
    // Draw the background
    gdc.SetPen(GetBarBgColour(m_theme));
    gdc.SetBrush(GetBarBgColour(m_theme));
    gdc.DrawRectangle(clientRect);

    switch(m_state) {
    case kStateHover: {
        if(!IsChecked()) {
            // Hover
            gdc.SetBrush(GetBgHoverColour());
            gdc.SetPen(m_penHoverOuterColour);
            gdc.DrawRoundedRectangle(clientRect, BTN_RADIUS);

            clientRect.Deflate(1);
            gdc.SetBrush(*wxTRANSPARENT_BRUSH);
            gdc.SetPen(m_penHoverColourInner);
            gdc.DrawRoundedRectangle(clientRect, BTN_RADIUS);

            // gdc.SetPen(m_penHoverColourInner);
            // gdc.DrawLine(clientRect.GetBottomLeft(), clientRect.GetTopLeft());
            // gdc.DrawLine(clientRect.GetTopLeft(), clientRect.GetTopRight());
            //
            // gdc.SetPen(m_penHoverOuterColour);
            // gdc.DrawLine(clientRect.GetTopRight(), clientRect.GetBottomRight());
            // gdc.DrawLine(clientRect.GetBottomRight(), clientRect.GetBottomLeft());
        }
        break;
    }
    case kStateNormal: {
        // do nothing
        gdc.SetBrush(GetBgColour());
        gdc.SetPen(GetPenNormalColour());
        gdc.DrawRoundedRectangle(clientRect, BTN_RADIUS);
        break;
    }
    case kStatePressed: {
        // Pressed
        gdc.SetBrush(GetBgPressedColour());
        gdc.SetPen(GetPenPressedColour());
        gdc.DrawRoundedRectangle(clientRect, BTN_RADIUS);

        // gdc.SetBrush(GetBgPressedColour());
        // gdc.DrawRectangle(clientRect);
        //
        // gdc.SetPen(m_penHoverOuterColour);
        // gdc.DrawLine(clientRect.GetBottomLeft(), clientRect.GetTopLeft());
        // gdc.DrawLine(clientRect.GetTopLeft(), clientRect.GetTopRight());
        //
        // gdc.SetPen(m_penHoverColourInner);
        // gdc.DrawLine(clientRect.GetTopRight(), clientRect.GetBottomRight());
        // gdc.DrawLine(clientRect.GetBottomRight(), clientRect.GetBottomLeft());
        break;
    }
    }

    // Draw text
    gdc.SetFont(GetTextFont());
    if(!IsEnabled()) {
        gdc.SetTextForeground(GetTextColourDisabled());
        gdc.DrawLabel(
            m_text, m_bmpDisabled, clientRect, wxALIGN_CENTER_VERTICAL | wxALIGN_CENTER_HORIZONTAL, m_accelIndex);
    } else {
        gdc.SetTextForeground(GetTextColour());
        gdc.DrawLabel(m_text, m_bmp, clientRect, wxALIGN_CENTER_VERTICAL | wxALIGN_CENTER_HORIZONTAL, m_accelIndex);
    }
}
예제 #2
0
void wxFlatButton::OnPaint(wxPaintEvent& event)
{
    wxUnusedVar(event);
    wxAutoBufferedPaintDC paintDC(this);
    PrepareDC(paintDC);

    wxGCDC gdc;
    GetGCDC(paintDC, gdc);

    wxRect clientRect = GetClientRect();
    // Draw the background
    gdc.SetPen(GetBarBgColour(m_theme));
    gdc.SetBrush(GetBarBgColour(m_theme));
    gdc.DrawRectangle(clientRect);

    switch(m_state) {
    case kStateHover: {
        // do nothing
        gdc.SetBrush(GetBgColour());
        gdc.SetPen(GetPenNormalColour());
        gdc.DrawRoundedRectangle(clientRect, BTN_RADIUS);
        break;
    }
    case kStateNormal: {
        break;
    }
    case kStatePressed: {
        // Pressed
        gdc.SetBrush(GetBgPressedColour());
        gdc.SetPen(GetPenPressedColour());
        gdc.DrawRoundedRectangle(clientRect, BTN_RADIUS);
        break;
    }
    }

    // Draw text
    gdc.SetFont(GetTextFont());
    wxColour textColour = IsEnabled() ? GetTextColour() : GetTextColourDisabled();
    wxBitmap bmp = IsEnabled() ? m_bmp : m_bmpDisabled;

    wxCoord textY;
    wxCoord bmpY;

    wxCoord totalLen = 0;
    const int spacer = 2;
    if(bmp.IsOk()) {
        // we got a bitmap
        totalLen += bmp.GetScaledWidth();
    }

    wxSize textSize;
    if(!m_text.IsEmpty()) {
        textSize = gdc.GetTextExtent(m_text);
        totalLen += spacer;
        totalLen += textSize.x;
    }

    wxCoord offset = (clientRect.GetWidth() - totalLen) / 2;
    bmpY = (clientRect.GetHeight() - bmp.GetScaledHeight()) / 2;
    textY = (clientRect.GetHeight() - textSize.y) / 2;
    if(bmp.IsOk()) {
        gdc.DrawBitmap(bmp, offset, bmpY);
        offset += bmp.GetScaledWidth();
        offset += spacer;
    }

    if(!m_text.IsEmpty()) {
        gdc.DrawText(m_text, offset, textY);
        offset += textSize.x;
        offset += spacer;
    }
}