Exemplo n.º 1
0
void CPanelPreferences::OnEraseBackground( wxEraseEvent& event ) {
    CSkinSimple* pSkinSimple = wxGetApp().GetSkinManager()->GetSimple();

    wxASSERT(pSkinSimple);
    wxASSERT(wxDynamicCast(pSkinSimple, CSkinSimple));

    wxMemoryDC memDC;
    wxCoord w, h, x, y;

    // Get the desired background bitmap
    wxBitmap bmp(*pSkinSimple->GetDialogBackgroundImage()->GetBitmap());

    // Dialog dimensions
    wxSize sz = GetClientSize();

    // Create a buffered device context to reduce flicker
    wxBufferedDC dc(event.GetDC(), sz, wxBUFFER_CLIENT_AREA);

    // bitmap dimensions
    w = bmp.GetWidth();
    h = bmp.GetHeight();

#if TEST_BACKGROUND_WITH_MAGENTA_FILL
    // Fill the dialog with a magenta color so people can detect when something
    //   is wrong
    dc.SetBrush(wxBrush(wxColour(255,0,255)));
    dc.SetPen(wxPen(wxColour(255,0,255)));
    dc.DrawRectangle(0, 0, sz.GetWidth(), sz.GetHeight());
#else
    wxColour bgColor(*pSkinSimple->GetDialogBackgroundImage()->GetBackgroundColor());
    SetBackgroundColour(bgColor);
#endif

    // Is the bitmap smaller than the window?
    if ( (w < sz.x) || (h < sz.y) ) {
        // Check to see if they need to be rescaled to fit in the window
        wxImage img = bmp.ConvertToImage();
        img.Rescale((int) sz.x, (int) sz.y);

        // Draw our cool background (centered)
        dc.DrawBitmap(wxBitmap(img), 0, 0);
    } else {
        // Snag the center of the bitmap and use it
        //   for the background image
        x = wxMax(0, (w - sz.x)/2);
        y = wxMax(0, (h - sz.y)/2);

        // Select the desired bitmap into the memory DC so we can take
        //   the center chunk of it.
        memDC.SelectObject(bmp);

        // Draw the center chunk on the window
        dc.Blit(0, 0, w, h, &memDC, x, y, wxCOPY);

        // Drop the bitmap
        memDC.SelectObject(wxNullBitmap);
    }
}
Exemplo n.º 2
0
void CPanelPreferences::OnEraseBackground( wxEraseEvent& event ) {
    if (!m_backgroundBitmap) {
        MakeBackgroundBitmap();
    }
    // Create a buffered device context to reduce flicker
    wxSize sz = GetClientSize();
    wxBufferedDC dc(event.GetDC(), sz, wxBUFFER_CLIENT_AREA);

#if TEST_BACKGROUND_WITH_MAGENTA_FILL
    // Fill the dialog with a magenta color so people can detect when something
    //   is wrong
    dc.SetBrush(wxBrush(wxColour(255,0,255)));
    dc.SetPen(wxPen(wxColour(255,0,255)));
    dc.DrawRectangle(0, 0, sz.GetWidth(), sz.GetHeight());
#else
    CSkinSimple* pSkinSimple = wxGetApp().GetSkinManager()->GetSimple();
    
    wxASSERT(pSkinSimple);
    wxASSERT(wxDynamicCast(pSkinSimple, CSkinSimple));

    wxColour bgColor(*pSkinSimple->GetDialogBackgroundImage()->GetBackgroundColor());
    SetBackgroundColour(bgColor);
#endif

    if (m_backgroundBitmap->IsOk()) {
       dc.DrawBitmap(*m_backgroundBitmap, 0, 0);
    }
}
Exemplo n.º 3
0
void CPanelPreferences::MakeBackgroundBitmap() {
    CSkinSimple* pSkinSimple = wxGetApp().GetSkinManager()->GetSimple();
    
    wxASSERT(pSkinSimple);
    wxASSERT(wxDynamicCast(pSkinSimple, CSkinSimple));

    wxMemoryDC memDC;
    wxCoord w, h, x, y;

    // Get the desired background bitmap
    wxBitmap bmp(*pSkinSimple->GetDialogBackgroundImage()->GetBitmap());

    // Dialog dimensions
    wxSize sz = GetClientSize();

    m_backgroundBitmap = new wxBitmap(sz);
    wxMemoryDC dc(*m_backgroundBitmap);

    // bitmap dimensions
    w = bmp.GetWidth();
    h = bmp.GetHeight();

    // Is the bitmap smaller than the window?
    if ( (w < sz.x) || (h < sz.y) ) {
        // Check to see if they need to be rescaled to fit in the window
        wxImage img = bmp.ConvertToImage();
        img.Rescale((int) sz.x, (int) sz.y);

        // Draw our cool background (enlarged and centered)
        dc.DrawBitmap(wxBitmap(img), 0, 0);
    } else {
        switch(pSkinSimple->GetDialogBackgroundImage()->GetHorizontalAnchor()) {
        case BKGD_ANCHOR_HORIZ_LEFT:
        default:
            x = 0;
            break;
        case BKGD_ANCHOR_HORIZ_CENTER:
            x = (w - sz.x) / 2;
            break;
        case BKGD_ANCHOR_HORIZ_RIGHT:
            x = w - sz.x;
            break;
        }

        switch(pSkinSimple->GetDialogBackgroundImage()->GetVerticalAnchor()) {
        case BKGD_ANCHOR_VERT_TOP:
        default:
            y = 0;
            break;
        case BKGD_ANCHOR_VERT_CENTER:
            y = (h - sz.y) /2;
            break;
        case BKGD_ANCHOR_VERT_BOTTOM:
            y = h - sz.y;
            break;
        }

        // Select the desired bitmap into the memory DC so we can take
        //   the desired chunk of it.
        memDC.SelectObject(bmp);

        // Draw the desired chunk on the window
        dc.Blit(0, 0, sz.x, sz.y, &memDC, x, y, wxCOPY);

        // Drop the bitmap
        memDC.SelectObject(wxNullBitmap);
    }
}