Advanced Question Drawing on a texture in VC

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
7,322
Reaction score
1,554
Points
203
Location
Dallas, TX
Thanks. I got it to work.

Working on another part the elevator trim. So I have it draw a rectangle it is the center.
I have it get the elevator trim. But it seems this value is 0-1. So do I get negative trim?

On drawing the trim bar I guess I need to adjust the y values.

Code:
void RANGER1::RedrawPanel_Fuelstatus(SURFHANDLE surf, int part)

{
	//SURFHANDLE const tex3 = oapiGetTextureHandle(meshhg_VC,5 );
	char cbuf[20];
	HDC hDC = oapiGetDC(surf);




	double level = GetThrusterLevel(th_main[0]);
	double level2 = GetPropellantMass(tank);
	double level3 = GetThrusterLevel(th_hover[0]);
	double trim = GetControlSurfaceLevel(AIRCTRL_ELEVATORTRIM);


	SelectObject(hDC, g_Param.hBrush[4]);//green box
	Rectangle(hDC, 150, 144, (int)(150 + level * (351 - 150)), 187);//thrust

	Rectangle(hDC, 150, 217, (int)(150 + level3 * (350 - 150)), 260);//thrust


	Rectangle(hDC, 152, 70, (int)(152.0 + (level2 / 52)), 108);  //fuel


	Rectangle(hDC, 312, 343, 333, 349);  //TRIM

	SelectObject(hDC, g_Param.hFont[3]);
	SetTextColor(hDC, RGB(0, 153, 0));
	SetTextAlign(hDC, TA_LEFT);
	SetBkMode(hDC, TRANSPARENT);

	sprintf(cbuf, "%0.1f", trim);
	TextOut(hDC, 390, 325, cbuf, strlen(cbuf));






	oapiReleaseDC(surf, hDC);


}


Also can you display text? Like it you had a box for Gear. And you want if Gear up then show "GEAR up"
 
Last edited:

marcogavazzeni

Addon Developer
Addon Developer
Joined
Jan 5, 2009
Messages
217
Reaction score
0
Points
16
Location
Near Verona
Website
orbiteritalia.forumotion.com
I have it get the elevator trim. But it seems this value is 0-1. So do I get negative trim?

I'm not sure that works GetTrimScale ()


Or as an alternative
double trim = (GetControlSurfaceLevel(AIRCTRL_ELEVATORTRIM)-0.5);

Also can you display text? Like it you had a box for Gear. And you want if Gear up then show "GEAR up"

Code:
if (gear_status == DOOR_CLOSED) {
			sprintf (cbuf, "GEAR up", 7);
			TextOut (hDC, 18, 10, cbuf, strlen (cbuf));
}
if (gear_status == DOOR_OPEN) {
			sprintf (cbuf, "GEAR down", 9);
			TextOut (hDC, 18, 10, cbuf, strlen (cbuf));
}
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
7,322
Reaction score
1,554
Points
203
Location
Dallas, TX
Well I am going to try to do it differently since our displays move. Looking at the Shuttle A code

Right now all I want is the nav lights. So I made a test mesh with the texture applied.

But now when I turn the VC on I get a ctd.

Code:
bool TESTVC::clbkLoadPanel(int id)
{
	//static MFDSPEC mfds_left = { { 66, 84, 326, 344 }, 6, 6, 31, 38 };
	//static MFDSPEC mfds_right = { { 828, 84, 1088, 344 }, 6, 6, 31, 38 };
	ReleaseSurfaces();

	HBITMAP hBmp = LoadBitmap(g_Param.hDLL, MAKEINTRESOURCE(IDB_PANEL1 ));

	switch (id) {
	case 0: // main panel
		oapiRegisterPanelBackground(hBmp, PANEL_ATTACH_BOTTOM | PANEL_MOVEOUT_BOTTOM, 0xffffff);
		oapiSetPanelNeighbours(-1, -1, 1, -1);
		//oapiRegisterMFD(MFD_LEFT, mfds_left);
		//oapiRegisterMFD(MFD_RIGHT, mfds_right);
		oapiRegisterPanelArea(AID_NAVMODE, _R(112, 17, 374, 48), PANEL_REDRAW_USER, PANEL_MOUSE_LBDOWN, PANEL_MAP_BACKGROUND);
		break;

		InitPanel(id);
		return hBmp != NULL;
	}
}

this is the line the debugger ends on:
oapiRegisterPanelArea(AID_NAVMODE, _R(112, 17, 374, 48), PANEL_REDRAW_USER, PANEL_MOUSE_LBDOWN, PANEL_MAP_BACKGROUND);




> TESTVCPANEL.dll!TESTVC::clbkLoadPanel(int id) Line 137 C++



I see nothing when I switch. In my thinking it doesn't know the panel is IDB_PANEL1.. here the texture is id'ed though

Code:
bool TESTVC::clbkLoadVC(int id) { // ID is the Preset Camera Position
	{
		
		ReleaseSurfaces();

		switch (id) {
		case 0:

			//SURFHANDLE tex1 = oapiGetTextureHandle(vcmesh_tpl, 10); //engine thrust tex

			SURFHANDLE tex1 = oapiGetTextureHandle(meshhg_VC, 1); //navmode tex
			oapiVCRegisterArea(AID_NAVMODE, _R(0, 0, 262, 32), PANEL_REDRAW_MOUSE | PANEL_REDRAW_USER, PANEL_MOUSE_LBDOWN, PANEL_MAP_BACKGROUND, tex1);
			oapiVCSetAreaClickmode_Quadrilateral(AID_NAVMODE,
				_V(-0.843884764f, 2.123497933f, 16.36420527f),
				_V(-0.689299533f, 2.129213263f, 16.35194677f),
				_V(-0.843884764f, 2.106857749f, 16.35644716f),
				_V(-0.689299533f, 2.112573079f, 16.34418865f));

		



		};

		InitPanel(-1);// VC is -1
		return true;
	}
	
	

}


---------- Post added 05-30-16 at 06:24 AM ---------- Previous post was 05-29-16 at 02:58 PM ----------

Here is the mesh info:
Code:
MSHX1
GROUPS  1
LABEL mesh01
MATERIAL 1
TEXTURE 1
GEOM 4 2 ;Group 0 (mesh01) SHUTTLEA/panel1.dds background
 8.978517 -4.60155  14.00024  0  0 -1  .999924  1
-8.080483 -4.60155  14.00024  0  0 -1  .000076  1
-8.080483  4.60155  14.00024  0  0 -1  .000076  0
 8.978517  4.60155  14.00024  0  0 -1  .999924  0
 0  1  2
 0  2  3
MATERIALS 1
background
MATERIAL background
 .878431  .878431  .878431  1
 .878431  .878431  .878431  1
 1  1  1  1  20
 0  0  0  1
TEXTURES 1
SHUTTLEA/panel1.dds

not sure how the background panel is id'ed.
 
Last edited:

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
36,873
Reaction score
1,533
Points
203
Location
Langendernbach
LoadPanel is for the old Panel code, not for the VC.
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
7,322
Reaction score
1,554
Points
203
Location
Dallas, TX
Thanks. I see the vc mesh. But no clickable area yet.

I calculated this for my mesh.
Code:
void TESTVC::clbkNavMode(int mode, bool active)
{
oapiTriggerRedrawArea(0, 0, AID_NAVMODE);
}
void TESTVC::RedrawPanel_Navmode(SURFHANDLE surf)
{
    for (DWORD i = NAVMODE_KILLROT; i < NAVMODE_HOLDALT; i++)
    if (GetNavmodeState(i))
        oapiBlt(surf, srf[0], (6 - i) * 44, 0, (i - 1) * 42, 0, 42, 31);
}


bool TESTVC::clbkLoadGenericCockpit() {
    //viewController->HandleLoadGC();
    return true;
}

bool TESTVC::clbkLoadVC(int id) { // ID is the Preset Camera Position
    {
        
        ReleaseSurfaces();

        switch (id) {
        case 0:

            //SURFHANDLE tex1 = oapiGetTextureHandle(vcmesh_tpl, 10); //engine thrust tex

            SURFHANDLE tex1 = oapiGetTextureHandle(vcmesh_tpl, 1); //navmode tex
            oapiVCRegisterArea(AID_NAVMODE, _R(0, 0, 262, 32), PANEL_REDRAW_MOUSE | PANEL_REDRAW_USER, PANEL_MOUSE_LBDOWN, PANEL_MAP_BACKGROUND, tex1);
            oapiVCSetAreaClickmode_Quadrilateral(AID_NAVMODE,
                _V(6.5391f, 4.1944, 14),
                _V(2.4322f, 4.1944, 14),
                _V(6.4754, 3.985, 14),
                _V(2.464, 3.985, 14));

        



        };

    //    InitPanel(-1);// VC is -1
        return true;
    }
    
    

}

bool TESTVC::HandleLoadVC(UINT const id)
{
    
    

    return true;
}

bool TESTVC::clbkVCMouseEvent(int id, int event, VECTOR3 &p)
{
    static int ctrl = 3;


    switch (id) {

    case AID_NAVMODE:
    {
                        ctrl = (int)(p.x*262.0f);
                        if ((ctrl % 44) < 42) {
                            ToggleNavmode(6 - ctrl / 44);
                            //    oapiTriggerPanelRedrawArea (0, AID_NAVMODE);
                            return true;
                        }
                        break;
    }
        return false;
    }
}


bool TESTVC::VCMouseEvent(int const id, int const event, SURFHANDLE surf)
{
    switch (id) {

    case AID_NAVMODE:
        RedrawPanel_Navmode(surf);
        return true;
    }

    return false; // We must return false, as we didn't processed the event!
}



bool TESTVC::clbkVCRedrawEvent(int id, int event, SURFHANDLE surf) {
    bool result = false;


    result = result || VCRedrawEvent(id, event, surf);
    


    return result;
}

bool TESTVC::VCRedrawEvent(int const id, int const event, SURFHANDLE const surf) {
    return false;
}



void TESTVC::DefineAnimations()
{

}


---------- Post added at 05:46 PM ---------- Previous post was at 07:21 AM ----------

Ok. I when back with the Shuttle A vc mesh and get clickable area. next is to get the texture to change.

in am running the debugger. I can click in the area where the Nav buttons are. It triggers a break and goes to
Code:
case AID_NAVMODE:
        ctrl = (int)(p.x*262.0f);
        if ((ctrl % 44) < 42) {
            ToggleNavmode(6 - ctrl / 44);
            //    oapiTriggerPanelRedrawArea (0, AID_NAVMODE);
            return true;
        }
        break;
then to here:
Code:
void TESTVC::clbkNavMode(int mode, bool active)
{
oapiTriggerRedrawArea(0, 0, AID_NAVMODE);
}
I can see the Navmode change.

But it never goes here to where the texture is changed?
Code:
void TESTVC::RedrawPanel_Navmode(SURFHANDLE surf)
{
    for (DWORD i = NAVMODE_KILLROT; i < NAVMODE_HOLDALT; i++)
    if (GetNavmodeState(i))
        oapiBlt(surf, srf[2], (6 - i) * 44, 0, (i - 1) * 42, 0, 42, 31);
}
 
Last edited:

GLS

Well-known member
Orbiter Contributor
Addon Developer
Joined
Mar 22, 2008
Messages
5,001
Reaction score
1,633
Points
188
p.x and p.y are the coordinates horizontal and vertical of where the user clicked, inside the rectangle that you defined. Those coordinates will be a number between 0 and 1, where the 0 is the left edge of the click area and 1 is the right edge (for the horizontal coordinate). This way you can tell where the user clicked.
You should checkout the API_Reference.pdf in the orbitersdk/doc folder, that contains info about what each Orbiter function does.
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
7,322
Reaction score
1,554
Points
203
Location
Dallas, TX
Thanks. Yes I figured that out I didn't have this:
Code:
bool TESTVC::clbkVCMouseEvent(int id, int event, VECTOR3 &p)

So I can hit the clickable area. just can't get to the change the texture.

Code:
void TESTVC::RedrawPanel_Navmode(SURFHANDLE surf)
{
	for (DWORD i = NAVMODE_KILLROT; i < NAVMODE_HOLDALT; i++)
	if (GetNavmodeState(i))
		oapiBlt(surf, srf[2], (6 - i) * 44, 0, (i - 1) * 42, 0, 42, 31);
}


---------- Post added at 06:23 PM ---------- Previous post was at 06:13 PM ----------

I added this: goes there but no texture change:
Code:
bool TESTVC::clbkVCRedrawEvent(int id, int event, SURFHANDLE surf)
{

	switch (id) {

	case AID_NAVMODE:
		RedrawPanel_Navmode(surf);
		return true;


	}
	return false;
};
srf[2] = oapiCreateSurface(LOADBMP(IDB_BUTTON1));

Not sure why it doesn't change. Not sure how it knows that IDB_BUTTON1 is the bitmap button1?

---------- Post added at 07:50 PM ---------- Previous post was at 06:23 PM ----------

yes. It works. I needed to add the resource files. Now to adapter it to mine.
THAnks
 
Last edited:

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
7,322
Reaction score
1,554
Points
203
Location
Dallas, TX
Back to drawing on a texture. To help with the fps. We have set the draw part only when changes occur in thrust level and fuel amount. BUT it seems only one mainly the thrust bar shows up something the fuel bar shows up.

One thought was the painting overlapped. But that is not the case. the math is correct also.

poststep to trigger if change:
Code:
fuel_percent = int(100 * (GetFuelMass()) / (FUELMASS));

	if (fuel_percent != fuel_percent_last_redraw){
		fuel_percent_last_redraw = fuel_percent;
			oapiVCTriggerRedrawArea(-1, AID_FUELSTATUS);
	}
	current_thrust_level = GetThrusterLevel(th_main[0]);

	if (current_thrust_level != thrust_last_drawn){
		thrust_last_drawn = current_thrust_level;
		oapiVCTriggerRedrawArea(-1, AID_THRUSTSTATUS);
	}

Code:
void TESTVC::RedrawPanel_Fuelstatus(SURFHANDLE surf, int part)

{
	//SURFHANDLE const tex3 = oapiGetTextureHandle(meshhg_VC,5 );
	char cbuf[20];
	HDC hDC = oapiGetDC(surf);



	
	level2 = GetPropellantMass(tank);

	SelectObject(hDC, g_Param.hBrush[3]);//green box

	level3 = ((level2 / FUELMASS)*237);
	Rectangle(hDC, 110, 34, (int)(110.0 + level3), 75);  //fuel





	oapiReleaseDC(surf, hDC);


}

void TESTVC::RedrawPanel_Thruststatus(SURFHANDLE surf, int part)

{
	//SURFHANDLE const tex3 = oapiGetTextureHandle(meshhg_VC,5 );
	char cbuf[20];
	HDC hDC = oapiGetDC(surf);




	level = GetThrusterLevel(th_main[0]);
	//double level2 = GetPropellantMass(tank);

	SelectObject(hDC, g_Param.hBrush[3]);//green box
	Rectangle(hDC, 114, 111, (int)(114 + level * (346 - 114)), 160);//thrust
	//Rectangle(hDC, 110, 34, (int)((110.0 - level2 / FUELMASS)*3.2), 75);  //fuel





	oapiReleaseDC(surf, hDC);


}

Code:
bool TESTVC::clbkLoadVC(int id) { // ID is the Preset Camera Position
	SURFHANDLE const tex3 = oapiGetTextureHandle(meshhg_VC, TEX_TESTVCPANELENDURANCE_ENDURANCEVC2E);


	viewController->HandleLoadVC(id);
mfdController->HandleLoadVC(id);	
	oapiVCRegisterArea(AID_FUELSTATUS, _R(0, 0, 512, 512), PANEL_REDRAW_USER, PANEL_MOUSE_IGNORE, PANEL_MAP_BACKGROUND, tex3);
	oapiVCRegisterArea(AID_THRUSTSTATUS, _R(0, 0, 512, 512), PANEL_REDRAW_USER, PANEL_MOUSE_IGNORE, PANEL_MAP_BACKGROUND, tex3);
	//oapiVCRegisterArea(AID_PODSTATUS, _R(0, 0, 512, 512), PANEL_REDRAW_USER, PANEL_MOUSE_IGNORE, PANEL_MAP_BACKGROUND, tex3);

	return HandleLoadVC(id);
}

Code:
bool TESTVC::clbkVCRedrawEvent(int id, int event, SURFHANDLE surf) {
	bool result = false;
	result = result || mfdController->HandleRedrawEvent(id, event, surf);


	result = result || VCRedrawEvent(id, event, surf);


	{

		switch (id) {
		case AID_FUELSTATUS:
			RedrawPanel_Fuelstatus(surf, id - AID_FUELSTATUS);
		//	sprintf(oapiDebugString(), "Fuel %f", fuel_percent);
			return true;
	
		
		case AID_THRUSTSTATUS:
			RedrawPanel_Thruststatus(surf, id - AID_THRUSTSTATUS);
		
			return true;
	
	
		case AID_PODSTATUS:
			RedrawPanel_Podstatus(surf, id - AID_PODSTATUS);

			return true;
		}
		//	return false;



	}
	return result;
}
 

Attachments

  • endurancevc2E.jpg
    endurancevc2E.jpg
    40 KB · Views: 8

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
7,322
Reaction score
1,554
Points
203
Location
Dallas, TX
I solved this. I combined all 3 redraw events into 1 big one.
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
7,322
Reaction score
1,554
Points
203
Location
Dallas, TX
Not sure. It did it in regular graphics also. To me it was it was like painting the bar and then the other bar blocked it out and then it painted it. So by putting all 3 in 1 redraw it only saw 1.

On the other panel project I think I am going to use the animated button feature. I think the move the texture might be above my pay scale:)
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
36,873
Reaction score
1,533
Points
203
Location
Langendernbach
Not sure. It did it in regular graphics also. To me it was it was like painting the bar and then the other bar blocked it out and then it painted it. So by putting all 3 in 1 redraw it only saw 1.

On the other panel project I think I am going to use the animated button feature. I think the move the texture might be above my pay scale:)

Well, never say never. :lol:
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
7,322
Reaction score
1,554
Points
203
Location
Dallas, TX
Well with the moving vc I think there will be a lot of parent/child. If we go with the mesh button then we can click on the mesh. I think with the panel not sure if the values would follow the animation. Not to mention I haven't figure how to change the texture
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
7,322
Reaction score
1,554
Points
203
Location
Dallas, TX
ok. I have 2 issues. 1 trying to get the text in the correct spot. 2 the bars.

This is what the texture looks like:
rangerfrontdisplay6.bmp

then on the vc mesh:
RANGERCENTERSCREENMESH.jpg


but in play I get:
rangercenterscreenissue.jpg


and this is where the text is mapped on the texture:

rangerfrontdisplay6ISSUE.jpg



and the code:
Code:
void RANGER::RedrawPanel_CENTERFuelstatus(SURFHANDLE surf, int part)

{

    char cbuf[20];
    HDC hDC = oapiGetDC(surf);
    double level2 = GetPropellantMass(tank1);

    double level4 = GetPropellantMass(tank2);//hover
    double level5 = GetPropellantMass(tank3);//rcs


    //double level = GetThrusterLevel(th_main[0]);
//    double level2 = GetPropellantMass(tank);
    //double level3 = GetThrusterLevel(th_hover[0]);


    SelectObject(hDC, g_Param.hBrush[4]);//green box
    //Rectangle(hDC, 150, 144, (int)(150 + level * (351 - 150)), 187);//thrust

    //Rectangle(hDC, 150, 217, (int)(150 + level3 * (350 - 150)), 260);//thrust


    Rectangle(hDC, 131, 325, 174, (int)(455 - (level2 )));  //fuel
   
    Rectangle(hDC, 241, 325, 284, (int)(455 - (level4 )));  //fuel

    Rectangle(hDC, 350, 325, 394, (int)(455 - (level5 )));  //rscfuel


    SetTextColor(hDC, RGB(0, 153, 0));
    SetTextAlign(hDC, TA_LEFT);
    SetBkMode(hDC, TRANSPARENT);

    SelectObject(hDC, g_Param.hFont[1]);
    sprintf(cbuf, "%0.1f", level2 );
    TextOut(hDC, 130, 474, cbuf, strlen(cbuf));
   

    sprintf(cbuf, "%0.1f", level4);
    TextOut(hDC, 244,474, cbuf, strlen(cbuf));
   

    sprintf(cbuf, "%0.1f", level5);
    TextOut(hDC, 352, 474, cbuf, strlen(cbuf));
   

   
    SelectObject(hDC, g_Param.hFont[3]);

    if (GEAR_status == GEAR_UP) {
        sprintf(cbuf, "GEAR UP", 7);
        TextOut(hDC, 250, 100, cbuf, strlen(cbuf));
        //TextOut(hDC, 400, 100, cbuf, strlen(cbuf));
        TextOut(hDC, 50, 300, cbuf, strlen(cbuf));
    }
    if (GEAR_status == GEAR_DOWN) {
        sprintf(cbuf, "GEAR DOWN", 9);
        TextOut(hDC, 50, 172, cbuf, strlen(cbuf));
    }




    oapiReleaseDC(surf, hDC);
}
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
7,322
Reaction score
1,554
Points
203
Location
Dallas, TX
Well the text out for the levels are ok. It is the text out for the gear. I can get the left side but not the right
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
36,873
Reaction score
1,533
Points
203
Location
Langendernbach
455 is the lower right corner (y) value

And level2 the propellant mass of a logical propellant resource, measured in kg.

If level2 bigger than 455 kg, the coordinate is negative, if it is bigger than 455 - 325 = 120 kg, it is drawn upwards.

What you really want is 455 - level2 * constant, with that constant being

constant = (455 - 325) / MaxPropellantMass;

(BTW, I recommend defining the top and bottom coordinates of your painting as constants, so you only need to define them once and can avoid typing them all the time. )
 
Top