C++ Question Need Help with MFD Buttons

Altair Aerospace

Addon Developer
Addon Developer
Joined
Nov 12, 2011
Messages
17
Reaction score
0
Points
0
Location
Catania
Website
orbiteritalia.forumotion.com
Hi guys i need an help or hint with my MFD Button on VC. I don't understand how to make this work on my dll

I have declared this on my .h file

Code:
	//identificatore tasti

#define AID_PWR			0001	// MFD 'Power' button
#define AID_SEL			0002	// MFD 'Select' button
#define AID_MNU			0003	// MFD 'Menu' button



	// MFD buttons (relative to MFD)
	const VECTOR3 MFD_BUTTON_POS[3] = {		
		{0.236,0.595,6.4}, { 0.236,0.795,9.8}, { 0.236,0.995,9.8} };

Difference beetwen first and all the other buttons is just a test to see if i need the offset that also the VC camera has (both not working)

in my cpp i have this

Code:
bool Altairsm::clbkLoadVC(int id)
{
	VECTOR3 MFD_buttons[3];

.....
.....



switch (id) {
	case 0: // pilota

oapiVCRegisterMFD(MFD_RIGHT, &mfd);
		oapiVCRegisterMFD(MFD_LEFT, &mfd2);
		


		oapiVCRegisterArea(AID_PWR, _R(0, 0, 0, 0), PANEL_REDRAW_NEVER, PANEL_MOUSE_LBDOWN, PANEL_MAP_NONE, NULL);
		oapiVCSetAreaClickmode_Spherical(AID_PWR, MFD_buttons[1], 0.01);

		oapiVCRegisterArea(AID_SEL, _R(0, 0, 0, 0), PANEL_REDRAW_NEVER, PANEL_MOUSE_LBDOWN, PANEL_MAP_NONE, NULL);
		oapiVCSetAreaClickmode_Spherical(AID_SEL, MFD_buttons[2], 0.01);

		oapiVCRegisterArea(AID_MNU, _R(0, 0, 0, 0), PANEL_REDRAW_NEVER, PANEL_MOUSE_LBDOWN, PANEL_MAP_NONE, NULL);
		oapiVCSetAreaClickmode_Spherical(AID_MNU, MFD_buttons[3], 0.01);

...

I don't understand what i must declare in

Code:
void Altairsm::RegisterActiveAreas(VECTOR3 ofs)
{

}

bool Altairsm::clbkVCMouseEvent(int id, int event, VECTOR3 &p)
{
	switch (id) {
	case AID_SEL: {
		oapiSendMFDKey(MFD_LEFT, OAPI_KEY_F2);

	}return true;


	case AID_PWR: {
		oapiSendMFDKey(MFD_LEFT, OAPI_KEY_ESCAPE);
	}
	}
	return true;
} 

bool Altairsm::clbkVCRedrawEvent(int id, int event, SURFHANDLE surf)
{
	return false;
}

thanks to anyone that want to share with me the solution of the problem
 
Last edited:

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,636
Reaction score
2,613
Points
203
Location
Dallas, TX
It shows but but can't press the buttons? I will look at my code but not sure about the definintion of the buttons 0,0,0,0?
 

Altair Aerospace

Addon Developer
Addon Developer
Joined
Nov 12, 2011
Messages
17
Reaction score
0
Points
0
Location
Catania
Website
orbiteritalia.forumotion.com
there is no visual trasformation after pressing, but the action (for expl) power on/off of the mfd not working

---------- Post added 27-03-19 at 01:26 ---------- Previous post was 26-03-19 at 20:28 ----------

Still not working, i think that the problem is on that code

Code:
bool Altairsm::clbkVCMouseEvent(int id, int event, VECTOR3 &p)
{
	switch (id) {
	case AID_SEL: {
		oapiSendMFDKey(MFD_LEFT, OAPI_KEY_F2);

	}return true;


	case AID_PWR: {
		oapiSendMFDKey(MFD_LEFT, OAPI_KEY_ESCAPE);
	}
	}
	return true;
}
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,636
Reaction score
2,613
Points
203
Location
Dallas, TX
So this is what I have for the Shuttle
Code:
// --------------------------------------------------------------
// Respond to MFD mode change
// --------------------------------------------------------------
void Atlantis::clbkMFDMode (int mfd, int mode)
{
	oapiVCTriggerRedrawArea (-1, AID_CDR1_BUTTONS+mfd-MFD_LEFT);
}




void Atlantis::RegisterVC_CdrMFD ()
{
	// activate MFD function buttons
	oapiVCSetAreaClickmode_Quadrilateral(AID_CDR1_BUTTONS, _V(-0.9239, 2.0091, 14.65), _V(-0.7448, 2.0091, 14.65), _V(-0.9239, 1.9881, 14.65), _V(-0.7448, 1.9881, 14.65));
	oapiVCSetAreaClickmode_Quadrilateral(AID_CDR2_BUTTONS, _V(-0.6546, 2.0091, 14.65), _V(-0.4736, 2.0091, 14.65), _V(-0.6546, 1.9881, 14.65), _V(-0.4736, 1.9881, 14.65));

    // D. Beachy: register+activate MFD power buttons
    const double powerButtonRadius = 0.0075; // radius of power button on each MFD
	oapiVCRegisterArea (AID_CDR1_PWR, PANEL_REDRAW_NEVER, PANEL_MOUSE_LBDOWN|PANEL_MOUSE_ONREPLAY);
	oapiVCRegisterArea (AID_CDR2_PWR, PANEL_REDRAW_NEVER, PANEL_MOUSE_LBDOWN|PANEL_MOUSE_ONREPLAY);
	oapiVCSetAreaClickmode_Spherical(AID_CDR1_PWR, _V(-0.952, 2.0107, 14.65), powerButtonRadius);
	oapiVCSetAreaClickmode_Spherical(AID_CDR2_PWR, _V(-0.680, 2.0107, 14.65), powerButtonRadius);

	// register+activate MFD brightness buttons
	oapiVCRegisterArea (AID_CDR1_BRT, PANEL_REDRAW_NEVER, PANEL_MOUSE_LBDOWN|PANEL_MOUSE_LBPRESSED|PANEL_MOUSE_ONREPLAY);
	oapiVCRegisterArea (AID_CDR2_BRT, PANEL_REDRAW_NEVER, PANEL_MOUSE_LBDOWN|PANEL_MOUSE_LBPRESSED|PANEL_MOUSE_ONREPLAY);
	oapiVCSetAreaClickmode_Quadrilateral(AID_CDR1_BRT, _V(-0.729, 2.0221, 14.649), _V(-0.714, 2.0221, 14.649), _V(-0.729, 2.0063, 14.645), _V(-0.714, 2.0063, 14.645));
	oapiVCSetAreaClickmode_Quadrilateral(AID_CDR2_BRT, _V(-0.459, 2.0221, 14.649), _V(-0.444, 2.0221, 14.649), _V(-0.459, 2.0063, 14.645), _V(-0.444, 2.0063, 14.645));
}

Code:
// --------------------------------------------------------------
// Respond to virtual cockpit mouse event
// --------------------------------------------------------------
bool Atlantis::clbkVCMouseEvent (int id, int event, VECTOR3 &p)
{
	static bool counting = false;
	static double t0 = 0.0;

	switch (id) {
	// handle MFD selection buttons
	case AID_CDR1_BUTTONS:
	case AID_CDR2_BUTTONS:
	case AID_PLT1_BUTTONS:
	case AID_PLT2_BUTTONS:
	case AID_MFD1_BUTTONS:
	case AID_MFD2_BUTTONS:
	case AID_MFD3_BUTTONS:
	case AID_MFD4_BUTTONS: 
	case AID_MFD5_BUTTONS:
	case AID_MFDA_BUTTONS: {
		int mfd = id-AID_CDR1_BUTTONS+MFD_LEFT;
		int bt = (int)(p.x*5.99);
		if (bt < 5) oapiProcessMFDButton (mfd, bt, event);
		else {
			if (event & PANEL_MOUSE_LBDOWN) {
				t0 = oapiGetSysTime();
				counting = true;
			} else if ((event & PANEL_MOUSE_LBUP) && counting) {
				oapiSendMFDKey (mfd, OAPI_KEY_F2);
				counting = false;
			} else if ((event & PANEL_MOUSE_LBPRESSED) && counting && (oapiGetSysTime()-t0 >= 1.0)) {
				oapiSendMFDKey (mfd, OAPI_KEY_F1);
				counting = false;
			}
		}
		} return true;

    // D. Beachy: handle power buttons
    case AID_CDR1_PWR:
    case AID_CDR2_PWR:
	case AID_PLT1_PWR:
	case AID_PLT2_PWR:
    case AID_MFD1_PWR:
    case AID_MFD2_PWR:
    case AID_MFD3_PWR:
	case AID_MFD4_PWR: 
	case AID_MFD5_PWR:
	case AID_MFDA_PWR: {
        int mfd = id - AID_CDR1_PWR+MFD_LEFT;
        oapiSendMFDKey(mfd, OAPI_KEY_ESCAPE);
        } return true;
              
	// handle MFD brightness buttons
	case AID_CDR1_BRT:
	case AID_CDR2_BRT:
	case AID_PLT1_BRT:
	case AID_PLT2_BRT:
	case AID_MFD1_BRT:
	case AID_MFD2_BRT:
	case AID_MFD3_BRT: 
	case AID_MFD4_BRT: 
	case AID_MFD5_BRT:
	case AID_MFDA_BRT: {
		static double t0, brt0;
		static bool up;
		int mfd = id-AID_CDR1_BRT;
		if (event & PANEL_MOUSE_LBDOWN) {
			up = (p.x >= 0.5);
			t0 = oapiGetSysTime();
			brt0 = mfdbright[mfd];
		} else if (event & PANEL_MOUSE_LBPRESSED) {
			double dt = oapiGetSysTime()-t0;
			double brt, dbrt = dt * 0.2;
			if (up) brt = min (1.0, brt0 + dbrt);
			else    brt = max (0.25, brt0 - dbrt);
			mfdbright[mfd] = brt;
			if (vis) {
				MATERIAL mat;
				memset (&mat, 0, sizeof(MATERIAL));
				mat.emissive.r = mat.emissive.g = mat.emissive.b = (float)brt;
				mat.emissive.a = 1.0f;
				DEVMESHHANDLE hMesh = GetDevMesh (vis, mesh_vc);
				oapiSetMaterial (hMesh, 17+mfd, &mat);
			}
		}
		} return false;

	// handle panel R13L events (payload bay operations)
	case AID_R13L:
		return plop->VCMouseEvent (id, event, p);
	}
	return false;
}
Code:
bool Atlantis::clbkVCRedrawEvent (int id, int event, SURFHANDLE surf)
{
	switch (id) {
	case AID_CDR1_BUTTONS:
	case AID_CDR2_BUTTONS:
	case AID_PLT1_BUTTONS:
	case AID_PLT2_BUTTONS:
	case AID_MFD1_BUTTONS:
	case AID_MFD2_BUTTONS:
	case AID_MFD3_BUTTONS:
	case AID_MFD4_BUTTONS: 
	case AID_MFD5_BUTTONS:
	case AID_MFDA_BUTTONS: {
		int mfd = id-AID_CDR1_BUTTONS+MFD_LEFT;
		RedrawPanel_MFDButton (surf, mfd);
		} return true;
	default:
		if (id >= AID_R13L_MIN && id <= AID_R13L_MAX)
			return plop->VCRedrawEvent (id, event, surf);
		break;
	}
	return false;
}
 

martins

Orbiter Founder
Orbiter Founder
Joined
Mar 31, 2008
Messages
2,448
Reaction score
462
Points
83
Website
orbit.medphys.ucl.ac.uk
Code:
bool Altairsm::clbkLoadVC(int id)
{
	VECTOR3 MFD_buttons[3];

.....
.....



switch (id) {
	case 0: // pilota

oapiVCRegisterMFD(MFD_RIGHT, &mfd);
		oapiVCRegisterMFD(MFD_LEFT, &mfd2);
		


		oapiVCRegisterArea(AID_PWR, _R(0, 0, 0, 0), PANEL_REDRAW_NEVER, PANEL_MOUSE_LBDOWN, PANEL_MAP_NONE, NULL);
		oapiVCSetAreaClickmode_Spherical(AID_PWR, MFD_buttons[1], 0.01);

		oapiVCRegisterArea(AID_SEL, _R(0, 0, 0, 0), PANEL_REDRAW_NEVER, PANEL_MOUSE_LBDOWN, PANEL_MAP_NONE, NULL);
		oapiVCSetAreaClickmode_Spherical(AID_SEL, MFD_buttons[2], 0.01);

		oapiVCRegisterArea(AID_MNU, _R(0, 0, 0, 0), PANEL_REDRAW_NEVER, PANEL_MOUSE_LBDOWN, PANEL_MAP_NONE, NULL);
		oapiVCSetAreaClickmode_Spherical(AID_MNU, MFD_buttons[3], 0.01);

...

You declare (and use) variable MFD_buttons, but you never define it, unless that bit was omitted from the code snippet. Also what is the difference between MFD_buttons and MFD_BUTTON_POS? Finally, you address MFD_buttons with indices 1-3, but the valid range is 0-2.

If you drop a breakpoint in clbkVCMouseEvent, is it ever called? If not, it indicates that the mouse-sensitive region is not correctly defined.
 
Top