April 02, 2020, 07:26:06 am


IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!

19b. Drawing the Background

Started by LarryMc, September 11, 2011, 04:16:23 pm

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.


Part B

The preceding is all we can draw without knowing the type of gage the user wants.  Therefore it is necessary for us to configure each of our instances of the control with the following code:

Code Select
ConfigGageRLM(main,ROUND270B,"Fuel Qty","lbs.",0,100,0,10,1000,1)
ConfigGageRLM(main,ROUND270T,"#1 Oil Temp","degF",0,100,0,15,20,2)
ConfigGageRLM(main,ROUND270L,"Inlet Flow","gpm",0,100,0,8,100,3 )
ConfigGageRLM(main,ROUND270R,"Manifold Press",chr$(34)+"Hg",0,100,0,5,0, 4 )
ConfigGageRLM(main,ROUND360SGL,"Fuel Qty","lbs.",0,10,0,0,1000, 5 )
ConfigGageRLM(main,ROUND360DBL,"Inlet Flow","gpm",0,10,0,0,100, 6 )
ConfigGageRLM(main,ROUND2PENV,"Battery","amps",0,100,-2,13,10, 7 )
ConfigGageRLM(main,ROUND2PENH,"Manifold Press",chr$(34)+"Hg",0,100,0,5,0, 8 )
ConfigGageRLM(main,ROUNDCLOCK12,"Local","",0,0,0,0,0, 9 )
ConfigGageRLM(main,ROUNDCLOCK24,"Local","",0,0,0,0,0, 10 )

The above code is placed in Section 5 of CCT_test.iwb.

Returning to the GageDrawbackground subroutine we will next create a pen to use for the rest of the background drawing using the following code:

Code Select
if #g_dat.nGageColor =RGBA(140,140,140,255)

We have the IF statement because our background can be one of two colors and we will need to adjust the line drawing colors accordingly.  And, since we created a pen we know we have to delete it so we will add that command toward the end of our subroutine, as shown:

Code Select

We'll next draw the arc/circle that our tic marks will be attached to. All but two types use the same center and radius for the drawing. So the first thing we will do is construct a SELECT block to identify those two exceptions.

Code Select
select #g_dat.sStyle




We'll handle the default condition first since it will address 8 of our 10 types. The default case is changed to look like this:

Code Select
   GdipDrawArc(pGraphics,pPen,16, 16, 168, 168,#g_dat.nAngleStart,#g_dat.nAngleEnd-#g_dat.nAngleStart)

Next we'll address the ROUND2PENV type gage by adding the following code:

Code Select
'left side
GdipDrawArc(pGraphics,pPen, -352, -100, 440, 400,#g_dat.nAngleStart,#g_dat.nAngleEnd-#g_dat.nAngleStart)
'right side
GdipDrawArc(pGraphics,pPen,112, -100, 440, 400,#g_dat.nAngleStart,#g_dat.nAngleEnd-#g_dat.nAngleStart)

The reader might notice the odd numbers being used, considering we're drawing to a rectangle 200 x 200 pixels with the top left corner being 0,0.  In order to get the arc to look like we want we have to tell the GdipDrawArc function that the arc is in a much larger rectangle and shift if left or right, as appropriate. (There was a lot of trial and error to get the look and position we wanted.)

The ROUND2PENH type gauge uses the same sort of structure, shown below:

Code Select
'top side
GdipDrawArc(pGraphics,pPen, -100, -352, 400, 440,#g_dat.nAngleStart,#g_dat.nAngleEnd-#g_dat.nAngleStart)
'bottom side
GdipDrawArc(pGraphics,pPen, -100, 112, 400, 440,#g_dat.nAngleStart,#g_dat.nAngleEnd-#g_dat.nAngleStart)


Coming Next - Drawing the Background - Part C
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library