Esempio n. 1
0
void wxGenericColourButton::UpdateColour()
{
    if ( !m_colour.Ok() )
    {
#if wxCLRBTN_USES_BMP_BUTTON
        wxBitmap empty(1,1);
        SetBitmapLabel(empty);
#else
        if ( HasFlag(wxCLRP_SHOW_LABEL) )
            SetLabel(wxEmptyString);
#endif
        return;
    }

    // some combinations of the fg/bg colours may be unreadable, so we invert
    // the colour to make sure fg colour is different enough from m_colour
    wxColour colFg(~m_colour.Red(), ~m_colour.Green(), ~m_colour.Blue());

#if wxCLRBTN_USES_BMP_BUTTON
    wxSize sz = GetSize();
    sz.x -= 2*GetMarginX();
    sz.y -= 2*GetMarginY();

    wxPoint topleft;
    
    if ( sz.x < 1 )
        sz.x = 1;
    else
    if ( sz.y < 1 )
        sz.y = 1;
    
    wxBitmap bmp(sz.x, sz.y);
    {
        wxMemoryDC memdc(bmp);
        memdc.SetPen(colFg);
        memdc.SetBrush(m_colour);
        memdc.DrawRectangle(topleft,sz);
        if ( HasFlag(wxCLRP_SHOW_LABEL) )
        {
            int x, y, leading, desc;
            wxString label = m_colour.GetAsString(wxC2S_HTML_SYNTAX);
            memdc.GetTextExtent(label,&x,&y,&desc,&leading);
            if ( x <= sz.x && y <= sz.y )
            {
                topleft.x += (sz.x-x)/2;
                topleft.y += (sz.y-y)/2;
                memdc.SetTextForeground(colFg);
                memdc.DrawText(label,topleft);
            }
        }
    }
    SetBitmapLabel(bmp);
#else
    SetForegroundColour(colFg);
    SetBackgroundColour(m_colour);

    if ( HasFlag(wxCLRP_SHOW_LABEL) )
        SetLabel(m_colour.GetAsString(wxC2S_HTML_SYNTAX));
#endif
}
void ctlColourPicker::UpdateColour()
{
    if (!m_colour_clr.IsOk())
    {
        wxBitmap empty(1,1);
        SetBitmapLabel(empty);
        return;
    }

    wxSize sz = GetSize();
    sz.x -= 2*GetMarginX();
    sz.y -= 2*GetMarginY();

    wxPoint topleft;
    if ( sz.x < 1 )
        sz.x = 1;
    else
        if ( sz.y < 1 )
             sz.y = 1;
    wxBitmap bmp(sz.x, sz.y);

    wxMemoryDC dc(bmp);
    dc.SetBrush(wxBrush(m_colour_clr));
    dc.DrawRectangle(topleft,sz);

    ((wxBitmapButton *)this)->SetBitmapLabel(bmp);
}