示例#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 HTMLButcherMaskAreaEditDialog::OnSelectColor(ButcherImageViewColorEvent &event)
{
    if (ButcherOptions::GetEditMode(GetProject()->GetOptions())>=ButcherOptions::EM_NORMAL)
    {

        int cid=ID_PROC_HOVERCOLOR;
        if (event.GetSelect()==ButcherImageViewColorEvent::CS_SELECT ||
                event.GetSelect()==ButcherImageViewColorEvent::CS_CONFIRM)
        {
            cid=ID_PROC_SELCOLOR;

            if (ButcherOptions::GetEditMode(GetProject()->GetOptions())>=ButcherOptions::EM_NORMAL)
            {
                if (event.GetSelect()==ButcherImageViewColorEvent::CS_CONFIRM)
                {
                    wxColourPickerCtrl *bgcolorctrl=(wxColourPickerCtrl*)FindWindow(ID_BGCOLOR);
                    bgcolorctrl->SetColour(event.GetColor());
                }
            }
        }
        wxTextCtrl *ct=(wxTextCtrl*)FindWindow(cid);

        // 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(~event.GetColor().Red(), ~event.GetColor().Green(), ~event.GetColor().Blue());

        ct->SetForegroundColour(colFg);
        ct->SetBackgroundColour(event.GetColor());
        ct->SetValue(event.GetColor().GetAsString(wxC2S_HTML_SYNTAX));

        //SetTitle(event.GetColor().GetAsString(wxC2S_HTML_SYNTAX));
    }
    event.Skip();
}