• Which the release of FS2020 we see an explosition of activity on the forun and of course we are very happy to see this. But having all questions about FS2020 in one forum becomes a bit messy. So therefore we would like to ask you all to use the following guidelines when posting your questions:

    • Tag FS2020 specific questions with the MSFS2020 tag.
    • Questions about making 3D assets can be posted in the 3D asset design forum. Either post them in the subforum of the modelling tool you use or in the general forum if they are general.
    • Questions about aircraft design can be posted in the Aircraft design forum
    • Questions about airport design can be posted in the FS2020 airport design forum. Once airport development tools have been updated for FS2020 you can post tool speciifc questions in the subforums of those tools as well of course.
    • Questions about terrain design can be posted in the FS2020 terrain design forum.
    • Questions about SimConnect can be posted in the SimConnect forum.

    Any other question that is not specific to an aspect of development or tool can be posted in the General chat forum.

    By following these guidelines we make sure that the forums remain easy to read for everybody and also that the right people can find your post to answer it.

Gdi+ pfd

Messages
95
Country
malta
Dear All,
I intend to start a new project, which is a 320 PFD using GDI+. I know GDI+ only a bit so I was going to ask you.

How can, for example, a speed tape be done?

In XML and normal C/C++, you use the masks to hide the area but how can it be done in GDI+ ?

Regards
 
I'd suggest that you download and examine my GDI+ Project Template:
https://files.secureserver.net/0sHeElqPojuq8Z

There are some examples there that illustrate the methods. In practice, it is very similar to the XML techniques for "vector drawing" where you specify a shape (such as a rectangle) of w,h size at x,y screen coordinates.
 
Hello Bill,

Thanks for that, in fact, I was the one who asked for it some weeks ago by e-mail. I already did this:
Oh, I didn't notice that you were the one who'd written earlier. Nicely done on what you've got so far! :D

Here is an example of a 'compass strip' using the SetClip and ResetClip methods:
Code:
path.AddRectangle (RectF (54,267, 194,39));
graphics.SetClip (&path);
graphics.FillRectangle (&darkbrownBrush,  54, 267, 194, 39);

// In order to make compass drawing logic relatively simply mathematically,
// we are going to draw the compass with degree zero being at the left margin
// of the compass strip (which is xPixel 54), but then use TranslateTransform to "shift"
// the compass strip so that the desired value is in the MIDDLE of the compass strip.
// Remember, the compass strip is 194 xPixels wide, so the center is at xPixel 98.

// wcompass is the compass degrees
xAdjust = ((xpixelsPerDegree * wcompass) - 98)*-1; // -1 reverses movement

graphics.TranslateTransform(xAdjust,0); // translate everything to the middle of the compass strip.
WCHAR* hsinr;
bool drawText;
// Compass Ledger Lines 
LongTickMark = true;
RectF clipRectF;
stringFormat.SetAlignment(StringAlignmentCenter);
for (int i=-390; i<390; i+=5)
{
	switch (INT(i))
	{
	case -390:
		hsinr = L"33";
		drawText = TRUE;
		break;
	case -360:
		hsinr = L"N";
		drawText = TRUE;
		break;
	case -330:
		hsinr = L"03";
		drawText = TRUE;
		break;
	case -300:
		hsinr = L"06";
		drawText = TRUE;
		break;
	case -270:
		hsinr = L"E";
		drawText = TRUE;
		break;
	case -240:
		hsinr = L"12";
		drawText = TRUE;
		break;
	case -210:
		hsinr = L"15";
		drawText = TRUE;
		break;
	case -180:
		hsinr = L"S";
		drawText = TRUE;
		break;
	case -150:
		hsinr = L"21";
		drawText = TRUE;
		break;
	case -120:
		hsinr = L"24";
		drawText = TRUE;
		break;
	case -90:
		hsinr = L"W";
		drawText = TRUE;
		break;
	case -60:
		hsinr = L"30";
		drawText = TRUE;
		break;
	case -30:
		hsinr = L"33";
		drawText = TRUE;
		break;
	case 0:
		hsinr = L"N";
		drawText = TRUE;
		break;
	case 30:
		hsinr = L"03";
		drawText = TRUE;
		break;
	case 60:
		hsinr = L"06";
		drawText = TRUE;
		break;
	case 90:
		hsinr = L"E";
		drawText = TRUE;
		break;
	case 120:
		hsinr = L"12";
		drawText = TRUE;
		break;
	case 150:
		hsinr = L"15";
		drawText = TRUE;
		break;
	case 180:
		hsinr = L"S";
		drawText = TRUE;
		break;
	case 210:
		hsinr = L"21";
		drawText = TRUE;
		break;
	case 240:
		hsinr = L"24";
		drawText = TRUE;
		break;
	case 270:
		hsinr = L"W";
		drawText = TRUE;
		break;
	case 300:
		hsinr = L"30";
		drawText = TRUE;
		break;
	case 330:
		hsinr = L"33";
		drawText = TRUE;
		break;
	case 360:
		hsinr = L"N";
		drawText = TRUE;
		break;
	case 390: 
		hsinr = L"03"; 
		drawText = TRUE;
		break;
	default:
		drawText = FALSE;
		break;
	}

	if (LongTickMark == false || drawText == true)
	{ 
                   graphics.FillRectangle(&whiteBrush,(INT)(54+(xpixelsPerDegree * i)-2), 270, 4, 10); // short tickmark 
                   if (drawText == TRUE) 
                   { 
                        xPos = 54+(xpixelsPerDegree * i); 
                        clipRectF = RectF(xPos-20, 273, 40, 40); 
                        graphics.DrawString(hsinr,-1,&Arial28,PointF((INT)(54+(xpixelsPerDegree*i)), 277),&stringFormat,&whiteBrush); 
                   } 
	} 
	else
                   graphics.FillRectangle(&whiteBrush, (INT)(54+(xpixelsPerDegree * i)-2), 270, 4, 20); // long tickmark

	if (LongTickMark == true)
	    LongTickMark = false;
	else
	    LongTickMark = true;

}
graphics.ResetClip ();
ResetTransform (graphics);
path.Reset ();
 
Last edited:
Just so you are aware though, if you want to clip a irregular shape (not a rectangle) I think you can use a region. Im not sure how to set one up (i never used it in GDI+ and I have now switched to Direct2D) but it shouldnt be too hard.
 
Thanks Bill, will give it a good look.

Regards
Oh yes, just in case you are wondering why I am drawing the compass strip to 390º...

Keep in mind that we need to draw the strip such that when at the extreme end, there's still some "strip" showing to the left or right of the center index line... :D
 
Just on a side note Bill, you could always set the loop length to purely the number of text/tick marks, multiply the value by 30, and add it to your starting value, and use swprintf to convert the resulting value into text in far fewer lines of code :) .
 
Just on a side note Bill, you could always set the loop length to purely the number of text/tick marks, multiply the value by 30, and add it to your starting value, and use swprintf to convert the resulting value into text in far fewer lines of code :) .
True enough. I tend to be more of a "belt and suspenders" type of programmer though. Brute force! :scratchch
 
Back
Top