Beispiel #1
0
	wxSize legendText::GetTextSize(const wxString& text)
	{
		wxBitmap bmp( 1, 1 );
		wxMemoryDC textDrawer(bmp);
		textDrawer.SetBrush( *wxGREEN_BRUSH );
		textDrawer.SetTextBackground(textBackground);
		textDrawer.SetTextForeground(textForeground);
		textDrawer.SetFont(textFont);
		wxSize sizeText;
		sizeText=textDrawer.GetTextExtent(text);
		return sizeText;
	}
Beispiel #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);	
	}
void CFontSizeTestControl::Draw(const TRect& aRect) const
	{
	CWindowGc& gc = SystemGc();
	gc.SetBrushColor(iBackgroundColor);
	
	// get the nearest font matching the desired height
	CFont* font = NULL;
	TFontSpec fontSpec;
	fontSpec.iTypeface.iName = KNokiaSeries60Font;
	fontSpec.iHeight = iFontSize;
	
	CWsScreenDevice* screen = CCoeEnv::Static()->ScreenDevice();
	ASSERT(screen->GetNearestFontToDesignHeightInPixels(font, fontSpec) == KErrNone);
	
	iBidiText->WrapText(aRect.Width() - ESideBearingsAllowance, *font, NULL, EMaximumTextLines);
	
	// it's recommended to create the text drawer in the actual draw function
    XCoeTextDrawer textDrawer(TextDrawer());
    textDrawer->SetMargins(iMargin);
    textDrawer->SetAlignment(TGulAlignment(EHCenterVCenter));
    textDrawer->SetTextColor(KRgbBlack);
    textDrawer->SetLineGapInPixels(EGapBetweenTextLines);
    textDrawer.SetClipRect(aRect);
    textDrawer.DrawText(gc, *iBidiText, aRect, *font);
    
    // Release font, otherwise there are problems deleting iScreen (still holds references)
    screen->ReleaseFont(font);
    	
	// Draw font 1 pixel larger or smaller next time.
	if (iIncreaseFontSize)
	    {
	    ++iFontSize;
	    }
	else
	    {
	    if (iFontSize > 1)
	        {
	        --iFontSize;
	        }
	    }
	}
Beispiel #4
0
//--------------------------------------------------------------------------------------------------
/// Set up camera/viewport and render
//--------------------------------------------------------------------------------------------------
void OverlayColorLegend::render(OpenGLContext* oglContext, const Vec2ui& position, const Vec2ui& size, bool software)
{   
    if (size.x() <= 0 || size.y() <= 0)
    {
        return;
    }

    Camera camera;
    camera.setViewport(position.x(), position.y(), size.x(), size.y());
    camera.setProjectionAsPixelExact2D();
    camera.setViewMatrix(Mat4d::IDENTITY);
    camera.applyOpenGL();
    camera.viewport()->applyOpenGL(oglContext, Viewport::CLEAR_DEPTH);

    // Get layout information
    // Todo: Cache this between renderings. Update only when needed.
    OverlayColorLegendLayoutInfo layout(position, size);
    layoutInfo(&layout);

    // Set up text drawer
    TextDrawer textDrawer(m_font.p());
    setupTextDrawer(&textDrawer, &layout);

    // Do the actual rendering
    if (software)
    {
        renderLegendImmediateMode(oglContext, &layout);
        textDrawer.renderSoftware(oglContext, camera);
    }
    else
    {
        const MatrixState matrixState(camera);
        renderLegend(oglContext, &layout, matrixState);
        textDrawer.render(oglContext, camera);
    }

    CVF_CHECK_OGL(oglContext);
}