Beispiel #1
0
int wxImageList::Add( const wxBitmap &bitmap )
{
    wxASSERT_MSG( (bitmap.GetScaledWidth() >= m_width && bitmap.GetScaledHeight() == m_height)
                  || (m_width == 0 && m_height == 0),
                  wxT("invalid bitmap size in wxImageList: this might work ")
                  wxT("on this platform but definitely won't under Windows.") );

    // Mimic behaviour of Windows ImageList_Add that automatically breaks up the added
    // bitmap into sub-images of the correct size
    if (m_width > 0 && bitmap.GetScaledWidth() > m_width && bitmap.GetScaledHeight() >= m_height)
    {
        int numImages = bitmap.GetScaledWidth() / m_width;
        for (int subIndex = 0; subIndex < numImages; subIndex++)
        {
            wxRect rect(m_width * subIndex, 0, m_width, m_height);
            wxBitmap tmpBmp = bitmap.GetSubBitmap(rect);
            m_images.Append( new wxBitmap(tmpBmp) );
        }
    }
    else
    {
        m_images.Append( new wxBitmap(bitmap) );
    }

    if (m_width == 0 && m_height == 0)
    {
        m_width = bitmap.GetScaledWidth();
        m_height = bitmap.GetScaledHeight();
    }

    return m_images.GetCount() - 1;
}
Beispiel #2
0
void osm_pi::DoDrawBitmap( const wxBitmap &bitmap, wxCoord x, wxCoord y, bool usemask )
{

    if ( m_pdc ) {
        wxLogMessage (_T("OSM_PI: DoDrawBitmap %i,%i"),x,y);
            m_pdc->DrawBitmap( bitmap, x, y, usemask );
    } else {
        wxLogMessage (_T("OSM_PI: DoDrawBitmapGL %i,%i"),x,y);
        // GL doesn't draw anything if x<0 || y<0 so we must crop image first
        wxBitmap bmp;
        if ( x < 0 || y < 0 ) {
              int dx = (x < 0 ? -x : 0);
              int dy = (y < 0 ? -y : 0);
              int w = bitmap.GetWidth()-dx;
              int h = bitmap.GetHeight()-dy;
              /* picture is out of viewport */
              if ( w <= 0 || h <= 0 )
                    return;
              wxBitmap newBitmap = bitmap.GetSubBitmap( wxRect( dx, dy, w, h ) );
              x += dx;
              y += dy;
              bmp = newBitmap;
        } else {
              bmp = bitmap;
        }
        wxImage image = bmp.ConvertToImage();
        int w = image.GetWidth(), h = image.GetHeight();

        if ( usemask ) {
              unsigned char *d = image.GetData();
              unsigned char *a = image.GetAlpha();

              unsigned char mr, mg, mb;
              if( !image.GetOrFindMaskColour( &mr, &mg, &mb ) && !a )
                    printf("trying to use mask to draw a bitmap without alpha or mask\n");

              unsigned char *e = new unsigned char[4*w*h];
              //               int w = image.GetWidth(), h = image.GetHeight();
              int sb = w*h;
              unsigned char r, g, b;
              for ( int i=0 ; i<sb ; i++ ) {
                    r = d[i*3 + 0];
                    g = d[i*3 + 1];
                    b = d[i*3 + 2];

                    e[i*4 + 0] = r;
                    e[i*4 + 1] = g;
                    e[i*4 + 2] = b;

                    e[i*4 + 3] = a ? a[i] :
                    ((r==mr)&&(g==mg)&&(b==mb) ? 0 : 255);
              }

              glColor4f( 1, 1, 1, 1 );
              glEnable( GL_BLEND );
              glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
              glRasterPos2i( x, y );
              glPixelZoom( 1, -1 );
              glDrawPixels( w, h, GL_RGBA, GL_UNSIGNED_BYTE, e );
              glPixelZoom( 1, 1 );
              glDisable( GL_BLEND );
              free( e );
        } else {
              glRasterPos2i( x, y );
              glPixelZoom( 1, -1 ); /* draw data from top to bottom */
              glDrawPixels( w, h, GL_RGB, GL_UNSIGNED_BYTE, image.GetData() );
              glPixelZoom( 1, 1 );
        }
    }
}
Beispiel #3
0
void ocpnDC::DrawBitmap( const wxBitmap &bitmap, wxCoord x, wxCoord y, bool usemask )
{
    wxBitmap bmp;
    if( x < 0 || y < 0 ) {
        int dx = ( x < 0 ? -x : 0 );
        int dy = ( y < 0 ? -y : 0 );
        int w = bitmap.GetWidth() - dx;
        int h = bitmap.GetHeight() - dy;
        /* picture is out of viewport */
        if( w <= 0 || h <= 0 ) return;
        wxBitmap newBitmap = bitmap.GetSubBitmap( wxRect( dx, dy, w, h ) );
        x += dx;
        y += dy;
        bmp = newBitmap;
    } else {
        bmp = bitmap;
    }
    if( dc ) dc->DrawBitmap( bmp, x, y, usemask );
    else {
        wxImage image = bmp.ConvertToImage();
        int w = image.GetWidth(), h = image.GetHeight();

        if( usemask ) {
            unsigned char *d = image.GetData();
            unsigned char *a = image.GetAlpha();

            unsigned char mr, mg, mb;
            if( !image.GetOrFindMaskColour( &mr, &mg, &mb ) && !a ) printf(
                    "trying to use mask to draw a bitmap without alpha or mask\n" );

            unsigned char *e = new unsigned char[4 * w * h];
//               int w = image.GetWidth(), h = image.GetHeight();
            {
                for( int y = 0; y < h; y++ )
                    for( int x = 0; x < w; x++ ) {
                        unsigned char r, g, b;
                        int off = ( y * image.GetWidth() + x );
                        r = d[off * 3 + 0];
                        g = d[off * 3 + 1];
                        b = d[off * 3 + 2];

                        e[off * 4 + 0] = r;
                        e[off * 4 + 1] = g;
                        e[off * 4 + 2] = b;

                        e[off * 4 + 3] =
                                a ? a[off] : ( ( r == mr ) && ( g == mg ) && ( b == mb ) ? 0 : 255 );
                    }
            }

            glColor4f( 1, 1, 1, 1 );
            GLDrawBlendData( x, y, w, h, GL_RGBA, e );
            delete[] ( e );
        } else {
            glRasterPos2i( x, y );
            glPixelZoom( 1, -1 ); /* draw data from top to bottom */
            glDrawPixels( w, h, GL_RGB, GL_UNSIGNED_BYTE, image.GetData() );
            glPixelZoom( 1, 1 );
        }
    }
}
void wxSpeedButton::SplitGlyphs(const wxBitmap &inBitmap, int inCount) {
int         n;
int         bw,bh;
int         sw,sh;
wxRect      rr;
wxImage     img;
wxBitmap    *bmp;

// no images yet

    mGlyphUp       = wxNullBitmap;
    mGlyphDown     = wxNullBitmap;
    mGlyphDisabled = wxNullBitmap;

// if no bitmap, then we are done

    if (! inBitmap.Ok()) return;

// size of the bitmap

    bw = inBitmap.GetWidth();
    bh = inBitmap.GetHeight();
    if ((bw <= 0) || (bh <= 0)) return;

// determine the number of images in the source bitmap
// if inCount > 0, then that is the count specified by the user
// else, count number of square sub-images

    if      (inCount > 0) n = inCount;
    else if (bw >= bh)    n = (int) bw / bh;
    else                  n = (int) bh / bw;

// extract sub-images, either vertically or horizontally

    if (n == 1) {
        mGlyphUp   = inBitmap;
        mGlyphDown = inBitmap;

        img = inBitmap.ConvertToImage();
        img = img.ConvertToGreyscale();
        bmp = new wxBitmap(img);
        mGlyphDisabled = *bmp;
    }
    else if ((n == 2) && (bw >= bh)) {
        sw = (int) bw / n;
        sh = bh;

        rr.SetX(0);
        rr.SetY(0);
        rr.SetWidth(sw);
        rr.SetHeight(sh);
        mGlyphUp = inBitmap.GetSubBitmap(rr);
        mGlyphDown = inBitmap.GetSubBitmap(rr);
        rr.SetX(sw);
        mGlyphDisabled = inBitmap.GetSubBitmap(rr);
    }
    else if ((n == 2) && (bh > bw)) {
        sw = bw;
        sh = (int) bh / n;

        rr.SetX(0);
        rr.SetY(0);
        rr.SetWidth(sw);
        rr.SetHeight(sh);
        mGlyphUp = inBitmap.GetSubBitmap(rr);
        mGlyphDown = inBitmap.GetSubBitmap(rr);
        rr.SetY(sh);
        mGlyphDisabled = inBitmap.GetSubBitmap(rr);
    }
    else if ((n >= 3) && (bw >= bh)) {
        sw = (int) bw / n;
        sh = bh;

        rr.SetX(0);
        rr.SetY(0);
        rr.SetWidth(sw);
        rr.SetHeight(sh);
        mGlyphUp = inBitmap.GetSubBitmap(rr);
        rr.SetX(sw);
        mGlyphDown = inBitmap.GetSubBitmap(rr);
        rr.SetX(sw+sw);
        mGlyphDisabled = inBitmap.GetSubBitmap(rr);
    }
    else { // (n >= 3) && (bh > bw)
        sw = bw;
        sh = (int) bh / n;

        rr.SetX(0);
        rr.SetY(0);
        rr.SetWidth(sw);
        rr.SetHeight(sh);
        mGlyphUp = inBitmap.GetSubBitmap(rr);
        rr.SetY(sh);
        mGlyphDown = inBitmap.GetSubBitmap(rr);
        rr.SetY(sh+sh);;
        mGlyphDisabled = inBitmap.GetSubBitmap(rr);
    };

// make them all transparent

    MakeTransparent(mGlyphUp);
    MakeTransparent(mGlyphDown);
    MakeTransparent(mGlyphDisabled);
}