Sign in to follow this  
Guest dko60202

Writing "Strings" in C

Recommended Posts

Are there any alternatives to the MAKE_STRING callback method for inserting strings in C?I'd like to "label" a gauge bezel without having to write 60 MAKE_STRING functions.There are 30 text labels needed, and the "night version" needs to be RGB 180,180,180 (softer white), so that means 60 bloody callbacks! :(

Share this post


Link to post
Share on other sites
Help AVSIM continue to serve you!
Please donate today!

Bill,I used this function to toggle the pink night lighting on or off:FLOAT64 FSAPI callback2( PELEMENT_STRING pelement){ if ( i != lights_now ) { if ( i == 1 ) { LUMINOUS_IMAGE(pelement->gauge_header->elements_list[0]); LUMINOUS_IMAGE(pelement->gauge_header->elements_list[0]->next_element[0]); REDRAW_IMAGE( pelement->gauge_header->elements_list[0] ); } else if ( i == 0 ) { DELUMINOUS_IMAGE(pelement->gauge_header->elements_list[0]); DELUMINOUS_IMAGE(pelement->gauge_header->elements_list[0]->next_element[0]); REDRAW_IMAGE( pelement->gauge_header->elements_list[0] ); } lights_now = i; } sprintf(pelement->string,"%05.0f", (( 39.37 / 12. ) * pelement->source_var[0].var_value.n)); return 0;}Replace the LUMINOUS_IMAGE and DELUMINOUS_IMAGE statements with pelement->fg_color = RGB(255, 255, 255); and pelement->fg_color = RGB(180, 180, 180);and you should be back down to 30 callbacks.Doug

Share this post


Link to post
Share on other sites

The only solution I know is to create a DIB section and use the GDI text drawing functions to draw any text you wish, with any color.It is much easier than the MAKE_STRING macro...Eric

Share this post


Link to post
Share on other sites

>The only solution I know is to create a DIB section and use>the GDI text drawing functions to draw any text you wish, with>any color.>It is much easier than the MAKE_STRING macro...Eric,I tried but failed miserably after spending several hours at it... Do you have a simple, one string example you could share? ;)

Share this post


Link to post
Share on other sites

Bill,Please send me an email (marciano.eric@free.fr) and we will work it out together ;-)Eric

Share this post


Link to post
Share on other sites

>Bill,>>Please send me an email (marciano.eric@free.fr) and we will>work it out together ;-)TIA, message sent!

Share this post


Link to post
Share on other sites

>>Bill,>>>>Please send me an email (marciano.eric@free.fr) and we will>>work it out together ;-)>>TIA, message sent!...and NEVER replied to... ;(

Share this post


Link to post
Share on other sites

There is no difference from drawing any graphics with GDI+The rules are:1) ensure your bitmap is recorded as owner draw (see example in SDK)2) extract the GDI graphics object from the callback (also in example)3) use any string function from GDI+ to draw the string onto the bitmapYou can set aliasing, select the font with a GDI+ font object, and use any of the GDI+ calls for special effects.Tips and tricks you can use with strings rendered as GDI+ over the MAKESTRING macro:a) setup a color transform matrix (allows you to "dim" the display"):( to help with FPS, pre-draw "canned", officialy called "cached" strings so you don't have to draw them all the time. Create bitmaps in memory and draw on them. Once they are created, you can just blit (copy) the images which is a lot faster than drawing from scratch. Just remember that if the user changes resolution and/or lighting in the panel, watch out for side effects (solution, trap these events).c) use sprintf to create any complex string you want - the formatting capabilities of sprintf are amazing).A word of warning: GDI+ impacts frame rates quite a bit, and you may want to refresh the display only so often (I usually do this once per second, or once every 18 callback).Hope this helps,Etienne

Share this post


Link to post
Share on other sites

Hello Bill,I feel confused because I know I never answered your e-mail, and I apologize for this. Nevertheless, I answered a post explaining a lot of things about string display, where I was also apologizing for not answering your e-mail.I thought it was this thread, but it appears to be another one, and I made a confusion between the two. Sorry for this...In other words, I thought you had read my answer about this problem. If not, I will answer your e-mail soon to give you more info.Please let me know.Eric

Share this post


Link to post
Share on other sites

>3) use any string function from GDI+ to draw the string onto>the bitmapActually, I have made some progress with this, but what is more than a bit frustrating is that none of the examples given in "Graphics Programming with GDI+" by Mahesh Chand seem to work. This book is part of the "Microsoft .NET Development Series," hence my consternation... :(Graphics graphics(hdc); graphics.SetTextRenderingHint(TextRenderingHintAntiAlias);SolidBrush whiteBrush(Color((255*trans)/100, (255*brt)/100, (255*brt)/100, (255*brt)/100));FontFamily Arial(L"Arial");Font TempTitles(&Arial, 0.085*dim.y, FontStyleBold, UnitPixel);PointF pointF(0.158*dim.x, 0.176*dim.y);graphics.DrawString(L"MKR", -1, &TempTitles, pointF, &whiteBrush);PointF pointF1(0.15*dim.x, 0.245*dim.y);graphics.DrawString(L"MUTE", -1, &TempTitles, pointF1, &whiteBrush);Using "trans" I can control the opacity.Using "brt" I can control the brightness w/o changing the color.The above code works, but according to the reference book I have been attempting to use, this should work, but it does not:SolidBrush solidBrush = new SolidBrush(Color.FromArgb(255, 0, 0, 255));nor does this work:Font verdanaFont = new Font( "Verdana", 10);

Share this post


Link to post
Share on other sites

>In other words, I thought you had read my answer about this>problem. If not, I will answer your e-mail soon to give you>more info.>Please let me know.Eric, as I recall, I sent you some valuable information in "exchange" for some "tutoring assistance." Hence my concern.

Share this post


Link to post
Share on other sites

>Actually, I have made some progress with this, but what is>more than a bit frustrating is that none of the examples given>in "Graphics Programming with GDI+" by Mahesh Chand seem to>work. This book is part of the "Microsoft .NET Development>Series," hence my consternation... :(Bill, I just received my copy of the Chand book yesterday. I know little about this, but the examples in the book all use the .NET "managed" code framework and "Windows Forms and Controls", which I think account for the differences, if you're coding "native" (unmanaged), like I am (I'm using the freebie VC++ command line tools.) I can't do a g.Dispose() either, for example...I think that "Windows Forms" consist of additional .dlls that provide the extra functions...I don't know if the answer is to try and configure for managed code and "Windows Forms", or just stick with the GDI+ reference in the MS SDK documentation, but I'm going with the latter for now.Douglas

Share this post


Link to post
Share on other sites

>I don't know if the answer is to try and configure for managed>code and "Windows Forms", or just stick with the GDI+>reference in the MS SDK documentation, but I'm going with the>latter for now.Hmmm, you may be on to something there. In that case, the Chand book has now become an expensive paperweight, at leastinsofar as gauge work goes.Looking at the top of page 5 I read, "Managed GDI+ classes are defined in System.Drawing and its subnamespaces and reside in the System.Drawing.dll and System.Drawing.dll assemblies."On page 6, I read, "In this book we will be using GDI+ through the namespaces provided by the .NET framework library."Should I ever branch out into writing "stand alone stuff" then it may prove a useful resource... ;)

Share this post


Link to post
Share on other sites

Hello my dear namesake, *:-*I am interested about how you dim those displays... I am not sure what a matrix actually is (not gotten that far in maths class yet, but should not take longer than ten months from now... ;)), but probably you can expand a bit on your method.Thanks in advance. :-hahEtienne :-wave

Share this post


Link to post
Share on other sites

One way to dim the display is to render the same exact image in GDI+, but using a color transform to brighten or darken the image.The easiest way to do this in GDI+ is to use a color transformation matrix.Example:Graphics* pgCanvas = NULL; // graphics contextbmpImage = new Bitmap(width, height); // render in memorypgCanvas = Graphics::FromImage(bmpImage); // the drawing contextfloat rscale, bscale, gscale;GetColorScale(&rscale,&bscale,&gscale); // current color scale factor (a routine you write)ImageAttributes m_imAtt;ColorMatrix colorMatrix = { rscale, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, gscale, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, bscale, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}; m_imAtt.SetColorMatrix(&colorMatrix,ColorMatrixFlagsDefault,ColorAdjustTypeBitmap); pgCanvas->DrawImage(bmpImage,rect,0,0,width,height,UnitPixel,&m_imAtt);Hope this helps,Etienne

Share this post


Link to post
Share on other sites

You can also scale the alpha in the same transform matrix (row 4, col 4).Problem is, this scales in rgb-space, which can cause undesirable color shifts. To properly dim a color (other than white/gray), it should be converted to HSB or HLS color-space, where you can scale a single value (Brightness or Luminence) and convert back to rgb.Douglas

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