Jump to content
Sign in to follow this  
Guest wysspeter

GDI+ text in VC

Recommended Posts

Guest wysspeter

I designed a gauge using GDI+ to display text. The font size is calculated by the height of the rectangle.PELEMENT_STATIC_IMAGE pelement = (PELEMENT_STATIC_IMAGE)(pgauge->elements_list[0]->next_element[0]);PIXPOINT dim = pelement->image_data.final->dim;Font myFont(L"Lucida Console", 0.23*(float)dim.y);graphics.DrawString(string1,-1,&myFont,origin1,&format,&textBrush);This works fine in 2D panel, but in the VC the text seems to be stretched. The height of a character is ok, but it's too wide, so the text does not fit into the rectangle.Is there a possibility to reduce the width according to the width of the rectangle without reducing the font height?

Share this post


Link to post
Share on other sites
Guest qsysk

you need to call ScaleTransform Method of the graphics object prior the call to the DrawString Method call..Example:PELEMENT_STATIC_IMAGE pelement = (PELEMENT_STATIC_IMAGE)(pgauge->elements_list<0>->next_element<0>);PIXPOINT dim = pelement->image_data.final->dim;Font myFont(L"Lucida Console", 1);graphics.ScaleTransform(dim.x*dblWidth,dim.y*dblHeight);graphics.DrawString(string1,-1,&myFont,origin1,&format,&textBrush);You can play i little bit with dblWidth and dblHeight to find the desired values needed .. or you can use the following routine to draw a text in a pelement.VOID DrawString( PELEMENT_STATIC_IMAGE pelement, LPSTR szText, FLOAT x, FLOAT y, LPSTR szFont, FLOAT flScaleX, FLOAT flScaleY, Gdiplus::Color color, int FontStyle){ CA2W wszFontFamily(szFont); CA2W wszString(szText); Gdiplus::Font font(wszFontFamily,1,FontStyle); Gdiplus::PointF origin(0,0); Gdiplus::SolidBrush brush(color); Gdiplus::Graphics graphics(pelement->hdc); /*REMOVE THE NEXT LINE TO DISABLE ANTIALIAS*/ graphics.SetTextRenderingHint(Gdiplus::TextRenderingHintAntiAlias); graphics.TranslateTransform(x,y); graphics.ScaleTransform(flScaleX,flScaleY); graphics.DrawString(wszString,-1,&font,origin,&brush); graphics.ResetTransform();}How to call DrawString..VOID DrawTRInfo(PELEMENT_STATIC_IMAGE pelement){ /* size is relative to the size of the pelement so if the pelement is stretched the text is stretch too */ FLOAT pos_x=pelement->image_data.final->dim.x * 0.000; FLOAT pos_y=pelement->image_data.final->dim.y * 0.800; FLOAT scale_x=pelement->image_data.final->dim.x * 0.025; FLOAT scale_y=pelement->image_data.final->dim.y * 0.025; DrawString(pelement, "TERR", pos_x, pos_y, "Arial", scale_x, scale_y, Gdiplus::Color(0x52,0xCE,0xFF), Gdiplus::FontStyleBold ); };I Hope this would help

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Tom Allensworth,
    Founder of AVSIM Online


  • Flight Simulation's Premier Resource!

    AVSIM is a free service to the flight simulation community. AVSIM is staffed completely by volunteers and all funds donated to AVSIM go directly back to supporting the community. Your donation here helps to pay our bandwidth costs, emergency funding, and other general costs that crop up from time to time. Thank you for your support!

    Click here for more information and to see all donations year to date.
×
×
  • Create New...