Jump to content
Sign in to follow this  
n4gix

GDI+ String Making...

Recommended Posts

The following will draw the desired text in the proper location on the background bitmap, and will scale when the gauge is resized...However, undocking the window and resizing the window causes the text to disappear. Can anyone tell me how to either (a) force a redraw of the strings, or (:( where I should place the code to prevent this from happening?////////////////////////////////////case PANEL_SERVICE_PRE_DRAW: { PELEMENT_STATIC_IMAGE pelement = (PELEMENT_STATIC_IMAGE)(pgauge->elements_list[0]->next_element[0]); if (pelement) { HDC hdc = pelement->hdc; PIXPOINT dim = pelement->image_data.final->dim; if (hdc) { Graphics graphics(hdc); graphics.SetSmoothingMode(SmoothingModeAntiAlias); SolidBrush whiteBrush(Color(255, (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); } SET_OFF_SCREEN (pelement); } }


Fr. Bill    

AOPA Member: 07141481 AARP Member: 3209010556


     Avsim Board of Directors | Avsim Forums Moderator

Share this post


Link to post
Share on other sites

Bill,PANEL_SERVICE_PRE_INITIALIZE and PANEL_SERVICE_PRE_GENERATE both get executed on a dock/undock and on a resize. For that matter, so do POST_INITIALIZE and POST_GENERATE.Try calling your draw routines from one of those cases as well.Or, have you got something in PRE_INITIALIZE that is killing your string?Doug

Share this post


Link to post
Share on other sites

>Bill,>>PANEL_SERVICE_PRE_INITIALIZE and PANEL_SERVICE_PRE_GENERATE>both get executed on a dock/undock and on a resize. For that>matter, so do POST_INITIALIZE and POST_GENERATE.>Try calling your draw routines from one of those cases as>well.>Or, have you got something in PRE_INITIALIZE that is killing>your string?Actually, at the moment there is nothing in the PRE_INITIALIZE section... ;)I'm working on a "learning gauge" trying to wrap my head around GDI+ DrawString and so forth. ;)So far, XML's "scheme" is far easier and less problematic... ;)I'll try ploping the code into the PRE_INITIALIZE case and see what happens... Thanks!


Fr. Bill    

AOPA Member: 07141481 AARP Member: 3209010556


     Avsim Board of Directors | Avsim Forums Moderator

Share this post


Link to post
Share on other sites

Hello Bill,I'm sorry, I didn't answer your email, no time yet ;-)But I think I have the answer to your question:I disagree with what Doug said. In my gauges, I also ignore the PANEL_SERVICE_PRE_INITIALIZE and PANEL_SERVICE_PRE_GENERATE events, and everything works fine, even when the gauges are undocked and resized.Now you may ask: what is the difference between our gauges, which makes my gauges work and not yours !!The answer is because I have coded my gauges so that when a gauge is undocked, the original gauge in the main panel does NOT draw any more. Basically, I did this to improve performance, thinking it is not necessary to draw the same gauge twice. THe consequence of this drawing mode is that the gauge draws only once, with a well-known size.The problem of your gauge is that the same gauge is designed to draw twice with 2 different displays, and 2 different sizes. As the gauges are DLLs, they share the same memory space, so the value of the variables are the same for both displays, even if it the same gauge!!I am 99% sure this is the cause of the problem.Eric

Share this post


Link to post
Share on other sites

They say a picture is worth a thousand words, so perhaps a picture of what I'm trying to accomplish will make things more clear.The GMA340 in the middle is entirely XML vector drawn. The only bitmap in the entire gauge is the background image. All text uses the XML version of DrawString, and the AOM indicator lights are vector drawn graphic boxes, with DrawString labels. One of the major "features" is that the level of label illumination is continuously variable with a rotary knob on the a/c's electrical panel.The top GMA340 is a partial reproduction with just several text labels created using the "traditional" MAKE_STRING callbacks.The lower GMA340 is my initial attempt at "translating" the XML version using the GDI+ DrawString method. I'm not going to bother with more than one "button" until I've solved display and resizing issues.The specific problem I've asked about in this thread is that once "undocked" (as these three in the window are), any attempt to "resize the undocked window" is causing the "MKR MUTE" DrawString to disappear and not get redrawn.http://forums.avsim.net/user_files/117104.jpg


Fr. Bill    

AOPA Member: 07141481 AARP Member: 3209010556


     Avsim Board of Directors | Avsim Forums Moderator

Share this post


Link to post
Share on other sites

Just to put a "period" on this thread, Chris K. was kind enough to provide the simple, yet elegant solution...In the PANEL_SERVICE_PRE_KILL routine, you have to use: if(init){GdiplusShutdown(gdiplusToken);init = false;} so that after a resize or undock or full screen/window toggle it can initialize again.This works, of course, because I used a similar routine to start Gdiplus to begin with:void FSAPI PFDCallBack ( PGAUGEHDR pgauge, SINT32 service_id, UINT32 extra_data ){ if(!init) { GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL); init = true;}I only had the GdiplusShutdown(gdiplusToken); in the PRE_KILL section initially, so it would never "restart."Thanks everyone for your kind suggestions... ;)


Fr. Bill    

AOPA Member: 07141481 AARP Member: 3209010556


     Avsim Board of Directors | Avsim Forums Moderator

Share this post


Link to post
Share on other sites
Guest _ak

In this case why not just add strings to bitmaps?

Share this post


Link to post
Share on other sites

>In this case why not just add strings to bitmaps?The rationale for this was covered in another thread, but to recapitulate briefly, using conventional MAKE_STRINGs would require a total of 33 MAKE_STRING entries and associated callbacks.Worse, since I need the "backlighted text" to be a softer white, that would double the number of MAKE_STRING entries and callbacks.More importantly, you cannot use a MAKE_STRING to create the Garmin "name Logo."Finally, it is an excellent excuse for me to buckle down and learn how to use new techniques! ;)


Fr. Bill    

AOPA Member: 07141481 AARP Member: 3209010556


     Avsim Board of Directors | Avsim Forums Moderator

Share this post


Link to post
Share on other sites
Guest _ak

I would use MAKE_ICON there with strings made in Photoshop :) Even if there is 33 icons, not so much really :)I trying minimize GDI+ usage to save FPS

Share this post


Link to post
Share on other sites

>I would use MAKE_ICON there with strings made in Photoshop :)>Even if there is 33 icons, not so much really :)>I trying minimize GDI+ usage to save FPSMany people complain endlessly about "blurry text" on panels and gauge subpanels.I'd rather avoid those complaints by offering crisy, legible text for them to read. ;)


Fr. Bill    

AOPA Member: 07141481 AARP Member: 3209010556


     Avsim Board of Directors | Avsim Forums Moderator

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...