Jump to content
Sign in to follow this  
badderjet

"NEW" C++ Technique for Dynamic Tooltips

Recommended Posts

Guest Patrick_Waugh

[h3]The Old Way[/h3]After actually having truely learned C++, I've been slowly looking more deeply at the many little hints the gauges.h offers us on how to really do things.When making on/off switches, I often want a dynamic tooltip like "Switch: ON".So, I might do this:[PRE]static PCSTRINGZ FSAPI GetState(FLOAT64 number, ID id, PCSTRINGZ string, MODULE_VAR *source_var, PGAUGEHDR gauge){ if (source_var->var_value.n) { return "Starter: ON"; } else { return "Starter: OFF"; }}MOUSE_TOOLTIP_ARGS (Switch_Args) MOUSE_TOOLTIP_ARG(GENERAL_ENGINE1_STARTER, 1, NULL, NULL, value_table, NULL, NULL, GetState)MOUSE_TOOLTIP_ARGS_ENDMOUSE_BEGIN(Switch_rect, HELP_NONE, 0, 0) MOUSE_TOOLTIP_TEXT_STRING ("Switch: %1!s!", Switch_Args) MOUSE_CHILD_FUNCT(10, 10, 21, 21, CURSOR_GRAB, MOUSE_LEFTSINGLE | MOUSE_LEFTRELEASE, Switch_mcb)MOUSE_ENDGAUGE_HEADER_FS700(GAUGE_W, Switch_gauge_name, &switch_list, switch_rect, Switch_cb, 0, 0, 0);[/PRE]You'll note that above I've made GetState return a string, and therefore have made it the STRING_CALLBACK parameter in the MOUSE_TOOLTIP_ARG macro.However, I have always been not quiet happy with it as I am forced to sort of convert the FLOAT64 to a Boolean.[br][h3]And now for something completely different...[/h3]While looking more closely at the MOUSE_TOOLTIP_ARG macro I became curious about the STRING_TABLE parameter. How was this used?The relavent portion of the macro substitution is this: (STRING_TABLE), sizeof(STRING_TABLE)/sizeof(MOUSE_ARG_STRING_MAP),and made me realize that it was a user defined table (array) of MOUSE_ARG_STRING_MAPs!Just above the macro in gauges.h you'll see:[PRE] typedef struct { SINT32 source; PSTRINGZ value; } MOUSE_ARG_STRING_MAP;[/PRE]and tells us that an "entry" is a number that identifies a string. It is defined very much like the FAILURE_RECORD like so:[PRE] MOUSE_ARG_STRING_MAP value_table[] = { { 0, "OFF" }, { 1, "ON" } };[/PRE]My table has only two entries, 0="OFF", 1="ON".GetState can now just return a FLOAT64 like this:[PRE] static FLOAT64 FSAPI GetState(FLOAT64 number, ID id, PCSTRINGZ string, MODULE_VAR *source_var, PGAUGEHDR gauge) { return source_var->var_value.n; }[/PRE]And you then add the STRING_TABLE to the macro and put GetState back in the NUMERIC_CALLBACK parameter like so: MOUSE_TOOLTIP_ARG(GENERAL_ENGINE1_STARTER, 1, NULL, NULL, value_table, GetState, NULL, NULL)and voila! The translation is done by the STRING_TABLE!!!! :-beerchug

Share this post


Link to post
Share on other sites

Hi... looking good, thanks a ton! :-hahHey regarding the failure records, do you know a way to determine something has actually failed...!? I can't seem to retrieve e. g. if NAV1 or NAV2 has failed. There are PP_... TokenVars but they seem to differ from what can be failed in the Failure Dialog of FS.Thanks,Etienne :-wave

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