Пример #1
0
HBITMAP Icon2Bitmap(HICON icon)
{
	assert(icon != 0);

	std::auto_ptr<Bitmap> tmpBitmap(Bitmap::FromHICON(icon));
	HBITMAP bmp = 0;

	tmpBitmap->GetHBITMAP(0, &bmp);
	return bmp;
}
Пример #2
0
	/*
	void legendText::DoAppendText(const wxString& text,int x,int y, bool overwrite,int maxLength)
	{
		//Todo utiliser uniquement l'espace nécessaire à la chaine de caractère
		wxMemoryDC textDrawer;
		textDrawer.SetBrush( *wxGREEN_BRUSH );
		textDrawer.SetTextBackground(textBackground);
		textDrawer.SetTextForeground(textForeground);
		textDrawer.SetFont(textFont);

		wxSize sizeText;
		if(maxLength==-1 || maxLength<text.size())
			sizeText=textDrawer.GetTextExtent(text);
		else
			sizeText=textDrawer.GetTextExtent(wxString("0",maxLength));		
		if(!foreground_tex)
		{
			legendObject::Init(sizeText.GetWidth(),sizeText.GetHeight());
		}

		unsigned char* color=new unsigned char[objConfig.width*objConfig.height*3];
		unsigned char* alpha=new unsigned char[objConfig.width*objConfig.height];
		memset(color,0,objConfig.width*objConfig.height*3);
		memset(alpha,255,objConfig.width*objConfig.height);

		wxImage emptyImage(objConfig.width,objConfig.height,color,alpha);

		wxBitmap tmpBitmap(emptyImage);
		textDrawer.SelectObject(tmpBitmap);
		if(textBackground.Alpha()==255)
			textDrawer.SetBackgroundMode(wxSOLID);
		else
			textDrawer.SetBackgroundMode(wxTRANSPARENT);
	
		textDrawer.DrawText(text,x,y);
		textDrawer.SelectObject(wxNullBitmap);
		wxImage imageTxt=tmpBitmap.ConvertToImage();
		CopyFont(imageTxt.GetData(),imageTxt.GetAlpha(),overwrite);	
	}
	*/
	void legendText::DoAppendText(const wxString& text,int x,int y, bool overwrite,int maxLength)
	{
		//Todo utiliser uniquement l'espace nécessaire à la chaine de caractère
        wxBitmap bmp(1,1);
		wxMemoryDC textDrawer(bmp);
		textDrawer.SetBrush( *wxGREEN_BRUSH );
		textDrawer.SetTextBackground(textBackground);
		textDrawer.SetTextForeground(textForeground);
		textDrawer.SetFont(textFont);

		wxSize sizeText;
		if(maxLength==-1 || maxLength<text.size())
		{
			sizeText=textDrawer.GetTextExtent(text);
		}else{
			sizeText=textDrawer.GetTextExtent(wxString("0").Pad(maxLength));
		}
		if(!foreground_tex)
		{
			legendObject::Init(sizeText.GetWidth(),sizeText.GetHeight());
		}

		unsigned char* color=new unsigned char[sizeText.GetWidth()*sizeText.GetHeight()*3];
		unsigned char* alpha=new unsigned char[sizeText.GetWidth()*sizeText.GetHeight()];
		memset(color,0,sizeText.GetWidth()*sizeText.GetHeight()*3);
		memset(alpha,255,sizeText.GetWidth()*sizeText.GetHeight());

		wxImage emptyImage(sizeText.GetWidth(),sizeText.GetHeight(),color,alpha);

		wxBitmap tmpBitmap(emptyImage);
		textDrawer.SelectObject(tmpBitmap);
		if(textBackground.Alpha()==255)
			textDrawer.SetBackgroundMode(wxSOLID);
		else
			textDrawer.SetBackgroundMode(wxTRANSPARENT);
	
		textDrawer.DrawText(text,0,0);
		textDrawer.SelectObject(wxNullBitmap);
		wxImage imageTxt=tmpBitmap.ConvertToImage();
		DoCopy(imageTxt.GetData(),imageTxt.GetAlpha(),sizeText.GetWidth(),sizeText.GetHeight(),overwrite,x,y);	
	}
Пример #3
0
void EDA_DRAW_PANEL::DrawGrid( wxDC* aDC )
{
    #define MIN_GRID_SIZE 10        // min grid size in pixels to allow drawing
    BASE_SCREEN* screen = GetScreen();
    wxRealPoint  gridSize;
    wxSize       screenSize;
    wxPoint      org;
    wxRealPoint  screenGridSize;

    /* The grid must be visible. this is possible only is grid value
     * and zoom value are sufficient
     */
    gridSize = screen->GetGridSize();
    screen->m_StartVisu = CalcUnscrolledPosition( wxPoint( 0, 0 ) );
    screenSize = GetClientSize();

    screenGridSize.x = aDC->LogicalToDeviceXRel( KiROUND( gridSize.x ) );
    screenGridSize.y = aDC->LogicalToDeviceYRel( KiROUND( gridSize.y ) );

    org = m_ClipBox.GetPosition();

    if( screenGridSize.x < MIN_GRID_SIZE || screenGridSize.y < MIN_GRID_SIZE )
    {
        screenGridSize.x *= 2.0;
        screenGridSize.y *= 2.0;
        gridSize.x *= 2.0;
        gridSize.y *= 2.0;
    }

    if( screenGridSize.x < MIN_GRID_SIZE || screenGridSize.y < MIN_GRID_SIZE )
        return;

    org = GetParent()->GetNearestGridPosition( org, &gridSize );

    // Setting the nearest grid position can select grid points outside the clip box.
    // Incrementing the start point by one grid step should prevent drawing grid points
    // outside the clip box.
    if( org.x < m_ClipBox.GetX() )
        org.x += KiROUND( gridSize.x );

    if( org.y < m_ClipBox.GetY() )
        org.y += KiROUND( gridSize.y );

#if ( defined( __WXMAC__ ) || 1 )
    // Use a pixel based draw to display grid.  There are a lot of calls, so the cost is
    // high and grid is slowly drawn on some platforms.  Please note that this should
    // always be enabled until the bitmap based solution below is fixed.
#ifndef __WXMAC__
    GRSetColorPen( aDC, GetParent()->GetGridColor() );
#else
    // On mac (Cocoa), a point isn't a pixel and being of size 1 don't survive to antialiasing
    GRSetColorPen( aDC, GetParent()->GetGridColor(), aDC->DeviceToLogicalXRel(2) );
#endif

    int xpos;
    double right = ( double ) m_ClipBox.GetRight();
    double bottom = ( double ) m_ClipBox.GetBottom();

    for( double x = (double) org.x; x <= right; x += gridSize.x )
    {
        xpos = KiROUND( x );

        for( double y = (double) org.y; y <= bottom; y += gridSize.y )
        {
            aDC->DrawPoint( xpos, KiROUND( y )  );
        }
    }
#else
    /* This is fast only if the Blit function is fast.  Not true on all platforms.
     *
     * A first grid column is drawn in a temporary bitmap, and after is duplicated using
     * the Blit function (copy from a screen area to an other screen area).
     */
    wxMemoryDC tmpDC;
    wxBitmap tmpBM( 1, aDC->LogicalToDeviceYRel( m_ClipBox.GetHeight() ) );
    tmpDC.SelectObject( tmpBM );
    tmpDC.SetLogicalFunction( wxCOPY );
    tmpDC.SetBackground( wxBrush( GetBackgroundColour() ) );
    tmpDC.Clear();
    tmpDC.SetPen( MakeColour( GetParent()->GetGridColor() ) );

    double usx, usy;
    int lox, loy, dox, doy;

    aDC->GetUserScale( &usx, &usy );
    aDC->GetLogicalOrigin( &lox, &loy );
    aDC->GetDeviceOrigin( &dox, &doy );

    // Create a dummy DC for coordinate translation because the actual DC scale and origin
    // must be reset in order to work correctly.
    wxBitmap tmpBitmap( 1, 1 );
    wxMemoryDC scaleDC( tmpBitmap );
    scaleDC.SetUserScale( usx, usy );
    scaleDC.SetLogicalOrigin( lox, loy );
    scaleDC.SetDeviceOrigin( dox, doy );

    double bottom = ( double ) m_ClipBox.GetBottom();

    // Draw a column of grid points.
    for( double y = (double) org.y; y <= bottom; y += gridSize.y )
    {
        tmpDC.DrawPoint( 0, scaleDC.LogicalToDeviceY( KiROUND( y ) ) );
    }

    // Reset the device context scale and origin and restore on exit.
    EDA_BLIT_NORMALIZER blitNorm( aDC );

    // Mask of everything but the grid points.
    tmpDC.SelectObject( wxNullBitmap );
    tmpBM.SetMask( new wxMask( tmpBM, GetBackgroundColour() ) );
    tmpDC.SelectObject( tmpBM );

    double right = m_ClipBox.GetRight();

    // Blit the column for each row of the damaged region.
    for( double x = (double) org.x; x <= right; x += gridSize.x )
    {
        aDC->Blit( scaleDC.LogicalToDeviceX( KiROUND( x ) ),
                   scaleDC.LogicalToDeviceY( m_ClipBox.GetY() ),
                   1, tmpBM.GetHeight(), &tmpDC, 0, 0, wxCOPY, true );
    }
#endif
}
Пример #4
0
void CPreview::DrawPreviewBitmap()
	{
	if(!bContinue) return;


	MaxX=width();
	MaxY=height();
	QPixmap tmpBitmap(MaxX, MaxY);
	QPainter DC(&tmpBitmap);
	QRect rc=rect();

	x1=4;
	x2=MaxX-4;
	y1=4;
	y2=MaxY-4;

	xw1=1;
	xw2=MaxX;
	yw1=0;
	yw2=MaxY;


    QBrush WhiteBrush(QColor(255,255,255));
    QBrush GrayBrush(QColor(192,192,192));
    QBrush BlueBrush(QColor(0,0,255));

    QPen WhitePen(QColor(255,255,255));
	QPen DarkPen(QColor(0,0,0));
    QPen BluePen(QColor(0,0,255));
    QPen YellowPen(QColor(255,255,0));
    QPen WhitePen2(QColor(255,255,255),2);
    QPen GrayPen2(QColor(128,128,128),2);


//********************************************************************
	DC.setPen(BluePen);
	DC.fillRect(rc, BlueBrush);
//	DC.SelectObject(CFont::FromHandle((HFONT)GetStockObject(ANSI_VAR_FONT)));


	int xl=(int)((pDisplay->t1 - pDisplay->tB1)*(x2-x1)/(pDisplay->tB2-pDisplay->tB1)+x1+0.5);
	int xr=(int)((pDisplay->t2 - pDisplay->tB1)*(x2-x1)/(pDisplay->tB2-pDisplay->tB1)+x1+0.5);

	DC.setPen(WhitePen2);

	DC.moveTo(xw1,MaxY-yw2);		
	DC.lineTo(xw2,MaxY-yw2);

	DC.moveTo(xw1,MaxY-yw2);		
	DC.lineTo(xw1,MaxY-yw1);

	DC.setPen(GrayPen2);

	DC.moveTo(xw2,MaxY-yw1);		
	DC.lineTo(xw2,MaxY-yw2);

	DC.moveTo(xw2,MaxY-yw1);		
	DC.lineTo(xw1,MaxY-yw1);

	DrawWaveform(DC);
	
	DC.setPen(WhitePen2);
	DC.moveTo(xl,MaxY-y1);		
	DC.lineTo(xr,MaxY-y1);
	DC.lineTo(xr,MaxY-y2);		
	DC.lineTo(xl,MaxY-y2);		
	DC.lineTo(xl,MaxY-y1);		


//********************************************************************

	ScreenBitmapCriticalSection.lock();
	Bitmap=tmpBitmap;
	bDrawBitmap=TRUE;
	ScreenBitmapCriticalSection.unlock();
	repaint(FALSE);
	}