Archived

This topic is now archived and is closed to further replies.

misho_TerraBuilder

Hiding/Showing Gauge Images

Recommended Posts

I'm trying to conditionally show and hide gauge image lements, namely an indicator and a background. I'm using the HIDE_IMAGE() and SHOW_IMAGE() macros, but I'm having problems hiding the background of the gauge. I can hide the indicator element of the gauge by specifying the callback function and using the "pelement" parameter as an argument to HIDE_IMAGE(). However, MAKE_STATIC doesn't allow for a callback, so it is rather ambiguous how to use the macros to hide and show the background... For example, in the following simple code:char cs_gauge_name[] = GAUGE_NAME; extern PELEMENT_HEADER cs_list; extern MOUSERECT cs_mouse_rect[]; GAUGE_HEADER_FS700(GAUGE_W, cs_gauge_name, &cs_list, cs_mouse_rect, 0, 0, 0, 0); MAKE_SLIDER ( cs_slider_rudder, BMP_CS_SMALL_RUDDER, NULL, 0, IMAGE_USE_ERASE | IMAGE_USE_TRANSPARENCY, 0, 94, 83, RUDDER_DEFLECTION, NULL, 80, MODULE_VAR_NONE, NULL, 0 ) PELEMENT_HEADER cs_sliders_list[] = { &cs_slider_rudder.header, NULL }; MAKE_STATIC ( cs_background, BMP_CS_SMALL_BACKGROUND, &cs_sliders_list, NULL, IMAGE_USE_TRANSPARENCY, 0, 0,0 ) PELEMENT_HEADER cs_list = &cs_background.header; MOUSE_BEGIN( cs_mouse_rect, HELP_NONE, 0, 0 ) MOUSE_PARENT( 60,78,76,16, HELPID_GAUGE_YAW_TRIM ) MOUSE_END #undef GAUGE_NAME #undef GAUGEHDR_VAR_NAME #undef GAUGE_W I'd like to hide both "cs_slider_rudder" and "cs_background" using the HIDE_IMAGE() and SHOW_IMAGE() macros. How is this done?

Share this post


Link to post
Share on other sites
Help AVSIM continue to serve you!
Please donate today!

The short answer is that you cannot...The only real option is to use a completely transparent bitmap for the background, then create a single image MAKE_ICON for the actual background image...Then you can use the SHOW_ELEMENT(pelement); and HIDE_IMAGE(pelement); macros.

Share this post


Link to post
Share on other sites

Thanks Bill! That's what I thought, but I thought I check with the forum to see if I'm not seeing something. What confused me is the following code snippet from the ESP SDK documentation (it is on-line, and I'm using it as a reference since it seems to be identical to FSX SDK):MODULE_VAR gs_var = {VOR1_GS_FLAG}; Void update_routine() { lookup_var(&gs_var); if(gs_var.var_value.n == 0) { HIDE_IMAGE((&gs_slider)); HIDE_IMAGE((&gs_background)); } else { SHOW_IMAGE((&gs_slider)); SHOW_IMAGE((&gs_background)); } 'Include other update code} This clearly shows a gauge that has a slider and a background, and pointers to both that are being used in the HIDE/SHOW calls. I'd love to know how to get &gs_slider and &gs_background. Any thoughts on this?

Share this post


Link to post
Share on other sites

I'm sorry... that's where in the documentation?

Share this post


Link to post
Share on other sites

As I mentioned, this is in ESP Documentation under "Programming C++ Gauges", which is available on-line in its entirety:http://msdn.microsoft.com/en-us/library/cc526958.aspxSearch for HIDE_IMAGE. I am using ESP documentation as it seems to be identical to FSX SDK, and available on-line, in case I don't have my dev system with me :)I apologize if I refered to something which is ESP-specific... I'll check if this is the case with the FSX SDK when I get to my dev system.

Share this post


Link to post
Share on other sites

Oh, it's not ESP specific... it's just a rather bad example to draw upon.The example you chose is for the "lookup_var" function. It's being used in a default C-style void function. It is not actually any type of gauge element callback routine.The only way to hide static elements is from within the gauge's main callback routine.

Share this post


Link to post
Share on other sites

Yup, I know it is the example of the "lookup_var" usage, but it still shows what appears to be showing and hiding of the slider and its background. "lookup_var" is only used to determine the visibility state. Is this then an arbitrary piece of code that would actually never work in a real app, and author just wrote this to illustrate the point?So then, how can I hide a static element? Statics don't allow for callback routines, so how are they referenced in SHOW_IMAGE() macro? Can you give me a short code snippet using the code from my original post? Also, what is the "gauge's main callback routine"? From what I've seen so far, each gauge element has its own callback routine (except STATIC) - there are no "main" callbacks for the whole gauge.Alternatively, Bill suggested that gauge backgrounds can be declared as MAKE_ICON (which allows callback function), rather than MAKE_STATIC, and thus allowing for the access to pelement through the callback. I'll give that a try tonight...Thanks,

Share this post


Link to post
Share on other sites

There are indeed callbacks for the primary gauge.I suggest you review the declaration of the macro for defining a gauge header. It has a place to pass a callback routine.GAUGE_HEADER_FS700(panel_width, panel_gauge_name, &panel_list, panel_mouse_rect, panel_gaugecall, 0, 0, 0);There's an example of the gauge header being defined via the macro. This macro is for the FS700 version of the header... but it still illustrates. As for Bill's suggestion... keep in mind ALL gauges MUST start with a static image as the base element. No exceptions.

Share this post


Link to post
Share on other sites

Actually, you can SHOW, HIDE, LIGHT and DARKEN from nearly anywhere in the main gauge, by simply referencing the elements_list.Many gauge authors (such as Dai Griffiths) actually prefer to do so rather than doing it pelement by pelement... ;)For example://If the VOR is within range if (vor2_sig > 0) {//If the VOR is a VORLOC then display the VORLOC symbol if (VorType(vor2_code,VOR_CODE_IS_LOCALIZER)) { SHOW_LISTELEMENT(pgauge->elements_list[0],24); HIDE_LISTELEMENT(pgauge->elements_list[0],23); HIDE_LISTELEMENT(pgauge->elements_list[0],22); HIDE_LISTELEMENT(pgauge->elements_list[0],21); } else...Of course, this does not apply to your actual question, which as I said before requires that you use a transparent bitmap for the STATIC, and then code a single bitmap MAKE_ICON callback for the real 'static background bitmap' so you can then SHOW or HIDE it... ;)

Share this post


Link to post
Share on other sites

Thanks, Bill and Ed! Bill, the code you pasted above makes sense except for the SHOW_LISTELEMENT macro - I get an undefined on it...must be something extra defined in the "new" gauges.h file. I am working with a stock FS2004 setup. Nevertheless, I have figured it out, with one wrinkle outstanding. I have set up my gauge with a MAKE_STATIC background (with transparent bitmap) and a MAKE_ICON member for gauge panel, working as a 2-position switch. On top of that, I have a MAKE_SLIDER element that is moving along the scale drawn in the MAKE_ICON bitmap. Then, I defined a gauge callback (thanks Ed!) that looks like this:static void FSAPI callBack(PGAUGEHDR pgauge, int service_id, UINT32 extra_data){ if(bShow) { SHOW_IMAGE_TREE(pgauge->elements_list[0]); } else { HIDE_IMAGE_TREE(pgauge->elements_list[0]); }}This basically does exactly what I wanted it to (without the need of element callbacks), except for one nagging thing: The MAKE_SLIDER bitmap, when it is hidden, is replaced by a "ghost" artifact bitmap, in the same position and size as the slider, but it looks as if it is carved out of its background, MAKE_ICON bitmap. Is there something I'm missing? Why is this little piece left behind? Is there something I need to call, akin to "Invalidate region"? I tried a few different ways of doing the same thing, including individual calls to SHOW_IMAGE on all 3 elements, and breaking down to callbacks in the MAKE_SLIDER and MAKE_ICON elements, all with the same artifact left behind...Thanks in advance,

Share this post


Link to post
Share on other sites

Oops! Actually, I use Dai's modified fsxgauges_sp2.h instead of the default SDK's gauges.h file. Dai has added quite a few new macros to make life simpler, along with incorporating quite a few 'fixes' to errors in the default gauges.h file supplied. Arne Bartels' contributions over the past decade are also included.You may find this in Dai's excellent BOOK sd2gau27.zip here in AVSIM's library...As for the 'ghost image,' you may need to force an OFF SCREEN to refresh the display...SET_OFFSCREEN_LISTELEMENTAnyway, here are a few of the macros Dai includes://////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// macros to add/remove_imagedata_to_listelement//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////#define HIDE_LISTELEMENT( pelement , pos_element ) add_imagedata_to_listelement( pelement , pos_element , IMAGE_HIDDEN )#define SHOW_LISTELEMENT( pelement , pos_element ) remove_imagedata_from_listelement( pelement , pos_element , IMAGE_HIDDEN )#define REDRAW_LISTELEMENT( pelement , pos_element ) remove_imagedata_from_listelement( pelement , pos_element , IMAGE_ON_SCREEN )#define LIGHT_LISTELEMENT(pelement,pos_element) add_imagedata_to_listelement( pelement , pos_element , IMAGE_USE_BRIGHT )#define DARKEN_LISTELEMENT(pelement,pos_element) remove_imagedata_from_listelement( pelement , pos_element , IMAGE_USE_BRIGHT )#define LIGHT_LISTELEMENT(pelement,pos_element) add_imagedata_to_listelement( pelement , pos_element , IMAGE_USE_BRIGHT )#define DARKEN_LISTELEMENT(pelement,pos_element) remove_imagedata_from_listelement( pelement , pos_element , IMAGE_USE_BRIGHT )#define LUMINOUS_LISTELEMENT(pelement,pos_element)add_imagedata_to_listelement(pelement,pos_element,IMAGE_USE_LUMINOUS )#define DELUMINOUS_LISTELEMENT(pelement,pos_element)remove_imagedata_from_listelement(pelement,pos_element,IMAGE_USE_LUMINOUS )#define SET_OFFSCREEN_LISTELEMENT(pelement,pos_element)add_imagedata_to_listelement(pelement,pos_element,IMAGE_ON_SCREEN)#define SET_ONSCREEN_LISTELEMENT(pelement,pos_element)remove_imagedata_to_listelement(pelement,pos_element,IMAGE_ON_SCREEN)

Share this post


Link to post
Share on other sites

hmmm okay - as I mentioned before, this is a FS2004 gauge, so I might not be able to use these extensions...I'll test out the OFF_SCREEN macro to see if that takes care of it...

Share this post


Link to post
Share on other sites

Hi MishoAll of Arne's and my additional macros are all backwards-compatible as far as FS2000. If you are programming for FS9, #include my fsxgauges_sp2.h file but keep a copy of the FS9 gauges.h file handy and use only the key_events etc. that are in the FS9 gauges.h file. This way you will get the convenience of the additional macros without the inconvenience of accidently calling an fsx/sp1/sp2-only event. In sd2gau27 I also finally got around to listing the additional macros - should have done that a long time ago. They're in the section called 'Additional Macros' near the end.-Dai

Share this post


Link to post
Share on other sites

Hi Dai!Thanks for the info - I'll keep that in mind! Last night I implemented latest suggestions from Bill and Ed and now my gauge is finally working as advertised! I noticed a few forehead slappers I did ( I was calling hiding/showing in every cycle) but now that's been adressed and the gauge is behaving as it should! Thanks everyone!

Share this post


Link to post
Share on other sites