April 19, 2024, 04:24:42 AM

News:

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.

LarryMc

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:

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:

penwidth=4
if #g_dat.nGageColor =RGBA(140,140,140,255)
GdipCreatePen1(RGBA(255,255,255,255),penwidth,UnitPixel,&pPen)
else
GdipCreatePen1(RGBA(100,100,100,255),penwidth,UnitPixel,&pPen)
endif


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:

....
GdipDeletePen(pPen)
....


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.

select #g_dat.sStyle
case ROUND2PENV

case ROUND2PENH

default

endselect


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:

default
   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:

...
case ROUND2PENV
'left side
#g_dat.nAngleStart=20
#g_dat.nAngleEnd=-20
GdipDrawArc(pGraphics,pPen, -352, -100, 440, 400,#g_dat.nAngleStart,#g_dat.nAngleEnd-#g_dat.nAngleStart)
'right side
#g_dat.nAngleStart=160
#g_dat.nAngleEnd=200
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:

...
case ROUND2PENH
'top side
#g_dat.nAngleStart=-250
#g_dat.nAngleEnd=-290
GdipDrawArc(pGraphics,pPen, -100, -352, 400, 440,#g_dat.nAngleStart,#g_dat.nAngleEnd-#g_dat.nAngleStart)
'bottom side
#g_dat.nAngleStart=250
#g_dat.nAngleEnd=290
GdipDrawArc(pGraphics,pPen, -100, 112, 400, 440,#g_dat.nAngleStart,#g_dat.nAngleEnd-#g_dat.nAngleStart)
...


_________________________________

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