• 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.

Simple C++ switch

Messages
76
I use a ton of very simple 2 position switches. In the old days of FSX
if (underway_switch_sw == 1) {
SHOW_LISTELEMENT(pgauge->elements_list[0], 2);
HIDE_LISTELEMENT(pgauge->elements_list[0], 1);
}

this would work to switch the visuals of the switch. But there is no SHOW_LISTELEMENT in P3D.
The only thing I can find that's close is:
HIDE_IMAGE(underway_switch_plist1[0]);
SHOW_IMAGE(underway_switch_plist2[0]);

But these two functions want an element - whatever type that is (I haven't a clue). I've tried using just about anything the compiler wouldn't complain about. The only example I've found is from the SDK:
if(gs_var.var_value.n == 0)
{
HIDE_IMAGE((&gs_slider));
HIDE_IMAGE((&gs_background));
}

But there is no clue as to what gs_slider or gs_background are. Any help greatly appreciated!
 
You could try instead of using the SHOW/HIDE LISTELEMENT. Change your object from STATIC ELEMENT to ICON.

Cheers

Mauricio
 
The best place for the SHOW_IMAGE and HIDE_IMAGE macros is in the callback function for the element in question.
Something like this:

double FSAPI callback5( PELEMENT_ICON pelement)
{
if ( active == 0 ) { HIDE_IMAGE(pelement) ; }
else { SHOW_IMAGE(pelement) ; }
return pelement->source_var.var_value.n;
}
 
Without going into too much boring detail below is, I think, the relevant code.
A couple of things to note: First - I can change the appearance of the switch when you switch to the panel that it is on at first, but it will not change after the first time. I can set it to on, off, or both visually. Second I know the code for the Show/Hide Image is being executed because I put print statement in both side of the switch update (callback). Any idea why the image refuses to change?

GAUGE_CALLBACK underway_switch_update;
GAUGE_HEADER_FS700(GAUGE_W, underway_switch_gauge_name, &underway_switch_list, underway_switch_mouse_rect,underway_switch_update, 0,0,0 );



MOUSE_BEGIN(underway_switch_mouse_rect, 0, 0, 0)
MOUSE_CHILD_FUNCT(0, 0, 50, 75, CURSOR_CROSSHAIR, MOUSE_LEFTSINGLE, underway_switch_mcb)​
MOUSE_END


MAKE_ICON(underway_switch_off_icon,
PANEL_UNDERWAY_SW_OFF,
NULL,
NULL,
IMAGE_USE_TRANSPARENCY | IMAGE_USE_ERASE,
0,
0, 0,
MODULE_VAR_NONE, NULL,
ICON_SWITCH_TYPE_SET_CUR_ICON,
1, //1 original
0,
0)​
PELEMENT_HEADER underway_switch_plist1[] = {&underway_switch_off_icon.header,NULL};

MAKE_ICON(underway_switch_on_icon,
PANEL_UNDERWAY_SW_ON,
underway_switch_plist1,
NULL,
IMAGE_USE_TRANSPARENCY | IMAGE_USE_ERASE,
0,
0, 0,
MODULE_VAR_NONE, NULL,
ICON_SWITCH_TYPE_SET_CUR_ICON,
1, //1 original
0,
0)​

PELEMENT_HEADER underway_switch_plist2[] = { &underway_switch_on_icon.header,NULL };


MAKE_STATIC ( underway_switch_off_static,
PANEL_UNDERWAY_SW_OFF, //PANEL_SW_BG, //PANEL_UNDERWAY_SW_OFF, //PANEL_UNDERWAY_SW_OFF, //PANEL_SW_BG, //LAUNCH_LIGHT_ON_BMP, //PANEL_UNDERWAY_SW_OFF,
underway_switch_plist2,
NULL,
IMAGE_USE_TRANSPARENCY, // | IMAGE_USE_ERASE, //erase | transparent,
0,
0,0 )​

PELEMENT_HEADER underway_switch_list = &underway_switch_off_static.header;

void FSAPI underway_switch_update(PGAUGEHDR pgauge, SINT32 service_id, UINT_PTR extra_data) {
if (underway_switch_sw == 1) {
HIDE_IMAGE((&underway_switch_off_icon));
SHOW_IMAGE((&underway_switch_on_icon));​
} else {
HIDE_IMAGE((&underway_switch_on_icon));
SHOW_IMAGE((&underway_switch_off_icon));​
}​
}
 
If you #define PANEL_UNDERWAY_SW_OFF and PANEL_UNDERWAY_SW_ON with consecutive resource numbers, you can do this and the work will be done for you by the callback function:

FLOAT64 FSAPI switch0_icon_cb( PELEMENT_ICON pelement)
{
return (FLOAT64)underway_switch_sw;
}

MAKE_ICON(underway_switch_off_icon,PANEL_UNDERWAY_SW_OFF,NULL,NULL,IMAGE_USE_ERASE | IMAGE_USE_TRANSPARENCY ,0,0,0,MODULE_VAR_NONE,
switch0_icon_cb,ICON_SWITCH_TYPE_STEP_TO,
2,0,0)

PELEMENT_HEADER underway_switch_plist1[] = {&underway_switch_off_icon.header,NULL};

MAKE_STATIC ( underway_switch_off_static,
PANEL_UNDERWAY_SW_OFF, //PANEL_SW_BG, //PANEL_UNDERWAY_SW_OFF, //PANEL_UNDERWAY_SW_OFF, //PANEL_SW_BG, //LAUNCH_LIGHT_ON_BMP, //PANEL_UNDERWAY_SW_OFF,
underway_switch_plist1,
NULL,
IMAGE_USE_TRANSPARENCY, // | IMAGE_USE_ERASE, //erase | transparent,
0,
0,0 )

PELEMENT_HEADER underway_switch_list = &underway_switch_off_static.header;
 
Wow! What an idiot! I tried using a multi switch, but somehow I missed that the MAKE_ICON had a separate callback. Jeeze - 5 days wasted. Well not really, I learned more than I cared to about ICONs. In your earlier post I was like "What - how do you return a float from a void callback? And only one argument?" Now I see it. Thank you so very much! Now I can get on with the FSX to P3dv4 conversion.

SOLVED!
 
Back
Top