Jump to content
Sign in to follow this  
anthony31

Can you check if a 2D popup window is visible?

Recommended Posts

Hello againI am making a gauge (in XML) and I would like to be able to check if it is visible as a 2D popup. The problem is that the gauge also appears in the virtual cockpit so using the <update hidden="no"> command won't work as From a brief read of the SDK it appears that C gauges can use the is_panel_window_visible_ident function. It would be really nice if there was a similar function in XML but if there is I can't find it which is why I am asking the question.It may be that I have to write a C gauge just to check the panel window is visible and then transfer that value back to xml.Thanks in advance for any info.


www.antsairplanes.com

Share this post


Link to post
Share on other sites
It may be that I have to write a C gauge just to check the panel window is visible and then transfer that value back to xml.
In fact, Doug Dawson created such a gauge a few years back, named dsd_window_status.gau (freeware).I don't think he uploaded it publically, but you can find a version of it (for FSX) in my groundhandling addon rcbgh50a.zipI use it frequently to monitor the state of a (visible or invisible) 2D-window, in order to keep it forced open after view changes.Rob

Share this post


Link to post
Share on other sites

Thanks for the reply Rob.It looks like I will have to go down the C route. I'll download your ground handling gauge so I can get a feel for how it should work.


www.antsairplanes.com

Share this post


Link to post
Share on other sites
In fact, Doug Dawson created such a gauge a few years back, named dsd_window_status.gau (freeware).I don't think he uploaded it publically, but you can find a version of it (for FSX) in my groundhandling addon rcbgh50a.zipI use it frequently to monitor the state of a (visible or invisible) 2D-window, in order to keep it forced open after view changes.Rob
Thanks to the OP for asking! Thanks to Rob for the heads up!Rob, What is the output of Doug's Gauge?From perusing your .xml, can I assume it gives an L:Var output directly related to the window ID# in the panel.cfg? Thanks...Don

Share this post


Link to post
Share on other sites
Thanks to the OP for asking! Thanks to Rob for the heads up!Rob, What is the output of Doug's Gauge?From perusing your .xml, can I assume it gives an L:Var output directly related to the window ID# in the panel.cfg? Thanks...Don
Yes, correct.
You define the 2D-window with:"ident" (>L:window_id_00, enum)and read the open/closed status with(L:window_status_00, bool)This allows you to handle max. 100 windows (_00 upto _99)

Note: There's no configuration file, so make sure the gauge is only defined once in the panel.cfg to avoid conflicts.Rob

Share this post


Link to post
Share on other sites

Just as a heads up for FSX: if you need any gauge to load first and be seen globally, place it in the last [VCockpitnn] section. FSX loads the panel.cfg from the bottom up... ;)


Fr. Bill    

AOPA Member: 07141481 AARP Member: 3209010556


     Avsim Board of Directors | Avsim Forums Moderator

Share this post


Link to post
Share on other sites

Well, after messing about with C I've got a gauge that displays if a particular window is open or not and it works quite well.This simple line checks if window ident 15532 is open and returns 1 into panel_ident if it is or 0 if it ain't

panel_ident=is_panel_window_visible_ident(15532);

My problem now is transferring that information back into an XML L: variable.Here is Dai Griffiths advice on how to do it: "To reverse the procedure and write to the XML variables, use the following piece of code. execute_calculator_code("(>K:<kvar>)", NULL, &return_value, NULL); "So this is what I did:

[font="Courier New"][size="2"][font="Courier New"][size="2"][font="Courier New"][size="2"][font="Courier New"][size="2"]panel_ident=is_panel_window_visible_ident(15532);panel_ident2=panel_ident;execute_calculator_code([/size][/font][/size][/font][font="Courier New"][size="2"][color="#a31515"][font="Courier New"][size="2"][color="#a31515"][font="Courier New"][size="2"][color="#a31515"]"(>L:Transfer, number)"[/color][/size][/font][/color][/size][/font][/color][/size][/font][font="Courier New"][size="2"][font="Courier New"][size="2"], NULL, &panel_ident, NULL); [/size][/font][/size][/font][/size][/font][/size][/font]

I'm copying panel_ident into panel_ident2 so I can print out panel_ident2 in the C gauge to check things are working. Also using the execute_calculator_code resets panel_ident to zero (which is supposed to indicate a successful transfer)Checking L:Transfer though in my XML gauge shows it as zero. Hmmm, obviously something I am missing.If anyone has any ideas on how to get the panel_ident value into L:Transfer it would be the missing piece in the puzzle.Thanks.


www.antsairplanes.com

Share this post


Link to post
Share on other sites

Sorry about all the font troubles in the previous reply :)I think I have worked it out. I think the process of posting the question got my brain working in a different way and I was able to figure out where I was going wrong.here is what I have now and it seems to be working (although there are some things I really need to change)panel_ident=is_panel_window_visible_ident(15532);panel_ident2=panel_ident;if ( panel_ident == 1 ){execute_calculator_code("1 (>L:Transfer, number)", NULL, &panel_ident, NULL); }else{execute_calculator_code("0 (>L:Transfer, number)", NULL, &panel_ident, NULL); }panel_ident holds either 0 or 1 depending if window 15532 is closed or openpanel_ident2 is just a temp holding spot which I should delete.the if statement checks if panel_ident is true ie the window is open and writes 1 into L:transferthe else statement writes in 0 to L:transfer indicating the window is closed.I should also change the &panel_ident values in both execute_calculator_code lines.When I write something neater I will post it here again.


www.antsairplanes.com

Share this post


Link to post
Share on other sites

First of all, you can't use forum formatting codes in a {code} box... It just messes up the display... ;)Second, that technique only works for triggering a command (K:ommand)...To properly set an XML L:var from C requires a different technique. Here's how I would set the (L:PitotCover,enum) variable from my C variable pitot_cover:

double	pitot_cover = 0 ;  // create a C variableID pitot_cover_id;   // create an ID name		case PANEL_SERVICE_POST_INSTALL:			register_named_variable ( "PitotCover" );  // register the name of the L:var		break;           // Now we need to check the L:var for updating, then we "set" the value equal to our C variable by casting it as a (FLOAT64)		case PANEL_SERVICE_PRE_UPDATE:			pitot_cover_id = check_named_variable ( "PitotCover" ) ;				set_named_variable_value ( pitot_cover_id, (FLOAT64)pitot_cover ) ;		break;

Okay, I see the revised method you posted. You can use either one, but I'd suggest passing the panel_ident number instead of a binary value, since it would be more flexible! ;)


Fr. Bill    

AOPA Member: 07141481 AARP Member: 3209010556


     Avsim Board of Directors | Avsim Forums Moderator

Share this post


Link to post
Share on other sites

Thanks BillMy problem now is getting this all into a simple gauge.What I started with is the SDK.temperature gauge and the code I made sits in one of the functions that the MAKE_STRING macro calls.I need to get it out of that macro and into something that just runs. Looks like I need to do some research on PANEL_SERVICE commands.Did I mention this is the first ever C gauge I have made that actually works? :) So, I know nothing and I'm really trying to learn a lot of stuff real quick.I've contacted Doug Dawson and he was kind enough to send me his gauge so I will have a look at that and see what I can learn.


www.antsairplanes.com

Share this post


Link to post
Share on other sites

As promised here is the final code of the gauge. I've commented the hell out of it because in 6 months time I will probably come back to it and need to know what I did (so I don't have to relearn everything from scratch).It's written as a subgauge of a multi gauge (just like in the SDK examples) so you would need to set up the main source file, header file and resource file appropriately. Most of the gauge is just setting the gauge up so that it works in FSX. There are only a handful of lines that actually send the panel information. I'm also not so sure that this is the best way to write the gauge. I'm just a beginner so I'm certainly no guru.I spent quite a bit of time trying to figure this all out so if this example saves someone else a bit of time or helps them understand the dark mystical art of C++ FS gauges then that would be a good thing.

 // Set up gauge header. The Gauge name is PanelCheckchar panelcheck_gauge_name[]  = GAUGE_NAME;extern PELEMENT_HEADER  panelcheck_list;// extern MOUSERECT   panelcheck_mouse_rect[]; // No mouse rect needed for this gauge so commented outGAUGE_CALLBACK     panelcheckcall; // Calls the Main procedure that does all the workGAUGE_HEADER_FS700(GAUGE_W, panelcheck_gauge_name, &panelcheck_list, NULL, panelcheckcall, 0, 0, 0);// Changes to the usual header//   Inserted NULL as we don't have the Mouserect//   Inserted panelcheckcall which seems to be needed for the Gauge_Callback int panel_ident; // Variable that holds the result of the window visible check. Could have made this a local var in the panelcheckcall but I didn't// Main procedure that does all the workvoid FSAPI panelcheckcall(PGAUGEHDR pgauge, int service_id, UINT32 extra_data){   int return_value=0; // Holds the return value from execute_calculator_code. Nothing else is done with this var  // Now we use a case statement to check the service_id and put our code into the PANEL_SERVICE_PRE_UPDATE so that it executes every tick  switch(service_id) { case PANEL_SERVICE_PRE_UPDATE:  // This is where we put all the logic (everything else is just setting up the gauge to actually work)  // This is the logic I used but you can do any sort of processing you need to return the results you need  // Writes the status of panel 15532 (change this to the panel ID you need) into panel_ident. 1 if the window is open, 0 if it is closed.  panel_ident=is_panel_window_visible_ident(15532);  // Now we check the result (a smarter person would skip writing into panel_ident and just check is_panel_window_visible_ident directly)  if ( panel_ident == 1 )   // Panel is visible so set transfer to 0. Value is set to 0 and not 1 as it removes   // the need for the XML gauge to be dependant upon the C gauge working.   // If the C gauge is not working the transfer value will still be 0 and the XML will still work.   {    execute_calculator_code("0 (>L:EKP_Visible2D, number)", NULL, &return_value, NULL);    }  else   // Panel is not visible so set transfer to 1   {    execute_calculator_code("1 (>L:EKP_Visible2D, number)", NULL, &return_value, NULL);    }  break;  } }// It seems we need a background image in every gauge we make so here is a blank one with NULL instead of a BMP referenceMAKE_STATIC( panelcheck_background, NULL, NULL, NULL, IMAGE_USE_ERASE | IMAGE_USE_TRANSPARENCY, 0, 0,0)PELEMENT_HEADER  panelcheck_list = &panelcheck_background.header;/////////////////////////////////////////////////////////////////////////////// Not sure if these undef are needed but they were in the original SDK.temperature gauge so I left them in here.#undef GAUGE_NAME#undef GAUGEHDR_VAR_NAME#undef GAUGE_W

 


www.antsairplanes.com

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Tom Allensworth,
    Founder of AVSIM Online


  • Flight Simulation's Premier Resource!

    AVSIM is a free service to the flight simulation community. AVSIM is staffed completely by volunteers and all funds donated to AVSIM go directly back to supporting the community. Your donation here helps to pay our bandwidth costs, emergency funding, and other general costs that crop up from time to time. Thank you for your support!

    Click here for more information and to see all donations year to date.
×
×
  • Create New...