SDK Question Pen and Brush definition in Orbiter 2010

Thorton

sense offender
Addon Developer
Joined
Mar 31, 2008
Messages
330
Reaction score
1
Points
0
Location
Tomsk
Hi

I'm trying to recompile my addons against new SDK and I have some problems with Pen and Brush.

Could someone help me with this functions?

Here is what I have how:
Code:
class SouyzTM: public VESSEL3 
{
	public:
				
	bla-bla-bla	

	private:
           
           oapi::Pen *Pen_white;
};

Code:
void SouyzTM::clbkPostCreation()
{
   .......
   Pen_white = oapiCreatePen (PS_SOLID, 1, RGB (100,100,100));
}

So when i use this construction all objects that i'm trying to draw are invisible, but if i remove it, they are visible again but with default HUD color.

Another problem, could anyone give an example that shows how to create a Brush? I've tried different ways, but always had errors during compilation.

Any suggestions?
Thanks!
 
Last edited:
Here's how I draw a filled rectangle for the FuelMFD ... full source here http://members.iinet.net.au/~trevorjohns/
Code:
    hNewBrush = CreateSolidBrush(BarColor);
    hOldBrush = (HBRUSH) SelectObject(hDC, hNewBrush);
    Rectangle(hDC, p.x, p.y+ch/2, p.x+BarLength, p.y+ch*2);
    SelectObject(hDC, hOldBrush);
    DeleteObject(hNewBrush);
 
Thanks, but as I understand it is not possible to use this construction for drawing HUD via Sketchpad.
 
this is my code if you can help:

Code:
[/COLOR]
[COLOR=#000][COLOR=red]Vessel.h[/COLOR][/COLOR]
[COLOR=#000][COLOR=black]public:[/COLOR][/COLOR]
[COLOR=#000]void clbkDrawHUD (int mode, const HUDPAINTSPEC *hps, HDC hDC);[/COLOR]
[COLOR=#000][/COLOR] 
[COLOR=#000]private:  [/COLOR]
[COLOR=#000]bla-bla-bla[/COLOR]
[COLOR=#000]);[/COLOR]
[COLOR=#000][/COLOR] 
[COLOR=#000]HINSTANCE hDLL;
HFONT hFont;
HPEN hPen;
HBRUSH hBrush;

Code:
[/COLOR]
[COLOR=#000][COLOR=red]Vessel.cpp[/COLOR][/COLOR]
[COLOR=#000]void  Vessel ::clbkDrawHUD (int mode, const HUDPAINTSPEC *hps, HDC hDC)
{
 // draw the default HUD
 VESSEL2::clbkDrawHUD (mode, hps, hDC);
 
 if ((engstart ==2) )
 {  SetTextAlign (hDC, TA_CENTER);
   TextOut (hDC, hps->CX, hps->H-60, "ENGINE ON", 10);
   SetTextAlign (hDC, TA_LEFT);
 }
 
 if ((engstart ==1)&& (fmod (oapiGetSimTime(), 1.0) < 0.5) )
 {  SetTextAlign (hDC, TA_CENTER);
   TextOut (hDC, hps->CX, hps->H-60, "ENGINE START", 12);
   SetTextAlign (hDC, TA_LEFT);
 }
 if ((engstart == 0) )
 {  SetTextAlign (hDC, TA_CENTER);
   TextOut (hDC, hps->CX, hps->H-60, "ENGINE OFF", 10);
   SetTextAlign (hDC, TA_LEFT);
 }
 
 if   (gear_status == DOOR_CLOSED || (gear_status >= DOOR_OPENING && fmod (oapiGetSimTime(), 1.0) < 0.5))
 {  SetTextAlign (hDC, TA_CENTER);
   TextOut (hDC, hps->CX, hps->H-94, "GEAR", 4);
   SetTextAlign (hDC, TA_LEFT);
 }
 
 if (gear_status == DOOR_CLOSED || (gear_status >= DOOR_OPENING ))
 {
  int d = hps->Markersize/2;
  int cx = hps->CX, cy = hps->CY;
  if (cx >= -d*3 && cx < hps->W+d*3 && cy >= d && cy < hps->H+d*5) {
   Rectangle (hDC, cx+d*-0.5, cy-d*6.0, cx+d*0.5, cy-d*7.5);
   Rectangle (hDC, cx+d*-4.0, cy-d*-7.0, cx+d*-3.0, cy-d*-8.5);
   Rectangle (hDC, cx+d*4.0, cy-d*-7.0, cx+d*3.0, cy-d*-8.5);
  }
 }
 
 }[/COLOR]
[COLOR=#000]DLLCLBK void InitModule (HINSTANCE hModule)
{
 // For ship's with panels and VC, the instance creation of the module
 // is quite important.
 hDLL = hModule;
 hFont = CreateFont (-15, 4, 0, 0, 150, 0, 0, 0, 0, 0, 0, 0, 0, "Arial");
 hPen = CreatePen (PS_SOLID, 3, RGB (120,120,120));
 hBrush = CreateSolidBrush (RGB(0,128,0));[/COLOR]
[COLOR=#000][/COLOR] 
[COLOR=#000]DLLCLBK void ExitModule (HINSTANCE hModule)
{
 // Don't forget to discard these resources after closing Orbiter. You
 // do not want all this cluttering up your memory when you go back
 // to MS Word and Excel after your lunch break!
 DeleteObject (hFont);
 DeleteObject (hPen);
 DeleteObject (hBrush);
 
}


}[/COLOR]
[COLOR=#000][/COLOR] 
[COLOR=#000]
 
This example won't work if you are using Sketchpad.
 
Is also not really important, since all examples are build on GDI and not VESSEL3 interfaces. I can take a look at the stuff, I know I made it work in the BlackDart during porting it to Orbiter 2010.

(VESSEL3 and GDI drawing doesn't work as well)
 
Yep, GDI doesnt works with Vessel3, maybe it is better does not change Vessel2 to Vessel3 and recompile project as is against new SDK?

BTW, Urwumpe, Happy Birthday!
 
Yep, GDI doesnt works with Vessel3, maybe it is better does not change Vessel2 to Vessel3 and recompile project as is against new SDK?

I don't think so, the advantages of the new Vessel Interface exceed the problems so far, at least for my projects. You need it for HUD painting, right? I'll look if there are differences, I used colors only for painting on surfaces.

BTW, Urwumpe, Happy Birthday!

Thank you! :cheers:
 
Hi,
this works for me. All inside the clbkDrawHUD section.

Code:
bool SolarSail::clbkDrawHUD (int mode, const HUDPAINTSPEC *hps, oapi::Sketchpad *skp)
{
 oapi::Pen *pen1;
 pen1 = oapiCreatePen(1,3,0x0033FFFF); // create Yellow Pen
 skp->SetPen(pen1);
 
 skp->Line(cx1,cy1,(cx1-dx),(cy1+dy));  // draw a line
 
 oapiReleasePen(pen1);                       // release Yellow pen
}

Haven't tried using a brush yet, though.

Cheers,
Brian
 
Thanks BrianJ!
It works, so i have only 1 problem left :) how is Brush suppose to created?

Very interesting that there are oapiCreatePen(), oapiCreateFont() functions, but i cant find oapiCreateBrush(). So I'm wondering, maybe Martin forgot to add it? ;)
 
Last edited:
Back
Top