Sign in to follow this  
n4gix

Newbie MAKE_STRING question

Recommended Posts

Hi,I'm just starting a gauge project in FS2004 for the first time. I'm needing a debug tool and am planning to use MAKE_STRING to display certain variables to the screen during the coarse of a flight. I know my code is running fine but the MAKE_STRING macro does not display anything on the screen. I use the PANEL_SERVICE_PRE_DRAW callback to call a routine that contains MAKE_STRING. Here is the relevant code I am using:#define GAUGE_CHARSET DEFAULT_CHARSET#define GAUGE_FONT_DEFAULT "Courier New"#define GAUGE_WEIGHT_DEFAULT FW_NORMAL void testredraw(){ MAKE_STRING( update_code, NULL, NULL, IMAGE_USE_ERASE | IMAGE_USE_BRIGHT | IMAGE_USE_TRANSPARENCY, 0, 28, 9, 60, 29, 30, TOTAL_AIR_TEMP, DISPLAY_UNITS, MODULE_VAR_NONE, RGB(0,255,0), RGB(255,0,0), RGB(0,0,255), GAUGE_FONT_DEFAULT, GAUGE_WEIGHT_DEFAULT, GAUGE_CHARSET, 0, DT_CENTER | DT_VCENTER | DT_SINGLELINE, NULL, NULL) PELEMENT_HEADER update_code_list[] ={&update_code.header,NULL}; }When I call this testredraw() routine should it not be drawing these system variable to the screen?Thanks,Magma

Share this post


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

You'll also need a MAKE_STATIC background to display the string on - all gauges have to have a MAKE_STATIC macro as the last item in the gauge macro stack. There's nothing to stop the background from being completely transparent so that the string acts like a HUD; in fact I have a hud-type debug gauge that outputs ten variables (plus other info) at any one time.If you haven't already got it, I think that reading sd2gau18.zip may be a great help.-Dai

Share this post


Link to post
Share on other sites

Yes I already have a background image and it is showing up just fine. Here is the MAKE_STATIC code:MAKE_STATIC(test_background,BMP_SMALL_test,NULL,NULL,IMAGE_USE_TRANSPARENCY,0,0,0);PELEMENT_HEADER test_Small = &test_background.header;I know my testredraw() routine is being called, but nothing is being displayed. Can you see anything I'm doing wrong? Thanks,Magma

Share this post


Link to post
Share on other sites

If that is all of your MAKE_STRING code then it looks like the callback routine that actually writes the information to the screen is missing. What you actually put into the callback routine depends on the data you are trying to display (string, integer etc). I really would download sd2gau18.zip and read the tutorial because I go into a lot of detail as to how all of the macros work. There is a lot of sample code included with it, all of which came from my own experience when I started programming gauges back in FS98 days. I know the learning curve you're going through.... I've been there :)-Dai

Share this post


Link to post
Share on other sites

And Dai, I can't imagine what the learning curve would have been like for me withut your awesome tutorials. It's great to see you back around these parts.CheersBob ScottATP IMEL Gulfstream II-III-IV-V L-300Santiago de Chile

Share this post


Link to post
Share on other sites

>And Dai, I can't imagine what the learning curve would have>been like for me withut your awesome tutorials. It's great to>see you back around these parts.>>Cheers>>Bob Scott>ATP IMEL Gulfstream II-III-IV-V L-300>Santiago de Chile>I'd like to second those thanks. The MS SDK has more holes than swiss cheese. Dai's tutorial is a Gauge designers Bible!!Thanks for putting in the effort to share it with us Dai!!RegardsJim

Share this post


Link to post
Share on other sites

As has been pointed out, you don't provide the actual callback for the MAKE_STRING macro...The more important question might be, why are you putting the macro in the PRE_DRAW case anyway?The entire gauge is nothing but a gigantic callback to begin with that executes the loop at 18/sec. Placing the macro in the case switch simply adds a level of obscurity that's totally unnecessary. ;)I prefer using a more structured layout whereby the code is logically structured... One such layout is based loosely on the format generated by Easy Gauge:Gauge Header InformationVariable DeclarationsModule DeclarationsGauge CallbackCase Switch StructureFailure DeclarationsMouse CallbacksMouse MacrosGauge Element CallbacksGauge Element MacrosThe major advantage of this type structure is that all of the Gauge Element Macros are listed in top-to-bottom order, which makes the logical flow of the linked list crystal clear with zero ambiguity... ;)

Share this post


Link to post
Share on other sites

I'm just going through a bit of a learning curve, and the fog is beginning to lift. sd2gau18.zip totally helped. I can see what you mean by "the entire gauge is nothing but a gigantic callback to begin with". You define certain parameters in the macro and also declare your callback routine. Then write your code in the callback routine...correct? I think I understand but I'm still having problems with this small chunk of code. My MAKE_STRING callback is still not being called for some reason. Here is the code:#include "..incgauges.h"#include #include "test.h"//#include #define GAUGE_NAME "Test0"#define GAUGEHDR_VAR_NAME gaugehdr_test#define GAUGE_W 100#define GAUGE_CHARSET DEFAULT_CHARSET#define GAUGE_FONT_DEFAULT "Courier New"#define GAUGE_WEIGHT_DEFAULT FW_NORMALextern PELEMENT_HEADER test_Small;STRING_UPDATE_CALLBACK update_callback;char test_gauge_name[] = GAUGE_NAME;GAUGE_HEADER_FS700(GAUGE_W, test_gauge_name, &test_Small, NULL, NULL, 0, 0, 0);MAKE_STATIC(test_background,BMP_SMALL_test,NULL,NULL,IMAGE_USE_TRANSPARENCY,0,0,0);MAKE_STRING(update_code,NULL,NULL,IMAGE_USE_ERASE | IMAGE_USE_BRIGHT , 0,50, 50,60, 29,30,CLOCK_SECOND ,MODULE_VAR_NONE ,MODULE_VAR_NONE ,RGB(0,255,0),RGB(0,0,0), RGB(92,92,92),GAUGE_FONT_DEFAULT,GAUGE_WEIGHT_DEFAULT,GAUGE_CHARSET,0,DT_CENTER | DT_VCENTER | DT_SINGLELINE, NULL,update_callback)PELEMENT_HEADER update_code_list[] ={&update_code.header,NULL};PELEMENT_HEADER test_Small = &test_background.header;FLOAT64 FSAPI update_callback(PELEMENT_STRING pelement ){ FLOAT64 val=pelement->source_var[0].var_value.n; val = !val; wsprintf(pelement->string, "%3d", (UINT32)val); return val;}void FSAPI ModuleInit(void){}void FSAPI ModuleDeinit(void){}GAUGE_TABLE_BEGIN() GAUGE_TABLE_ENTRY(&gaugehdr_BLD) GAUGE_TABLE_END()I'm trying to use the CLOCK_SECOND token variable to trigger my update_callback routine once every second. Is this the right approach or do I still have some learning curve to go?Magma

Share this post


Link to post
Share on other sites

The update_callback routine will automatically be called every 18th of a second.Your code is drawing a background referenced by BMP_SMALL_test, it is then placing a text box on it at the coordinates (50,50),the text box will be 60px wide and 29px high,it will then allow you to write up to 30 characters to this box.Because your textbox is 60px wide and you have told it that you want to write 30 characters in it it will only assign 2 pxs per characterYour update_callback will examine the value of CLOCK_SECONDS every 18th of a second.val=!val is an 'unrecognised' C routine (well I've never seen or used it) so will probably assign the value 0 to val.wsprintf(pelement->string, "%3d",(UINT32)val);This will print the value of val in the first 3 chracter spaces of the text box.If your code compiles... all it will do is print a zero, which you probably won't be able to see because its only 2pxs wideChange your code from ... 0,50,50,60,29,30 .... to... 0,50,50,60,29,3 .....Also remove the line val=!val;This should then display the value of CLOCK_SECONDS and you should see it count from 0 to 59RegardsJim

Share this post


Link to post
Share on other sites

Thanks Jim,I tried as you suggested but without success. Still nothing shows up when I run FS. I'm pretty sure that my update_callback routine is never being called by FS. I know this because I can put a routine inside of update_callback that is suppose to paint text to the screen using HDC and hBrush but nothing happens like it does when I set up a callback function through GAUGE_HEADER_FS700 macro. That works fine. So I don't know where the problem is and why my callback routine is never getting called. Am I suppose to export the function in my .h header file or .rc? Magma

Share this post


Link to post
Share on other sites

MagmaChangeGAUGE_TABLE_BEGIN() GAUGE_TABLE_ENTRY(&gaugehdr_BLD) GAUGE_TABLE_END()To:GAUGE_TABLE_BEGIN() GAUGE_TABLE_ENTRY(&gaugehdr_test) GAUGE_TABLE_END()RegardsJim

Share this post


Link to post
Share on other sites

Good eye Jim, but it has already been changed. I had changed some of the names to "test" in order to protect the proprietary project. Guess I missed one when I posted. So anyways it still doesn't work. I've looked at other sample code and it doesn't look like I'm doing anything wrong. It must be something silly I'm not doing.Magma

Share this post


Link to post
Share on other sites

The 'next_element' item in the static macro has to indicate the string. Try this:MAKE_STRING(update_code,NULL,NULL,IMAGE_USE_ERASE | IMAGE_USE_BRIGHT , 0,50, 50,60, 29,30,CLOCK_SECOND ,MODULE_VAR_NONE ,MODULE_VAR_NONE ,RGB(0,255,0),RGB0,0,0),RGB(92,92,92),GAUGE_FONT_DEFAULT,GAUGE_WEIGHT_DEFAULT,GAUGE_CHARSET,0,DT_CENTER | DT_VCENTER | DT_SINGLELINE, NULL,update_callback)PELEMENT_HEADER update_code_list[] = {&update_code.header,NULL};MAKE_STATIC( test_background, BMP_SMALL_test, &update_code_list, NULL, IMAGE_USE_TRANSPARENCY, 0, 0, 0 );PELEMENT_HEADER test_Small = &test_background.header;Doug

Share this post


Link to post
Share on other sites

Yep, Doug's found itMAKE_STATIC( test_background, BMP_SMALL_test, &update_code_list,Goes back to Bill's point about being methodical in your layout. I always put every element on a new line like this:MAKE_STATIC( test_background, BMP_SMALL_test, &update_code_list, NULL, IMAGE_USE_TRANSPARENCY, 0, 0,0 .....................(but keep coordnates together)makes it so much easier to de-bugRegardsJim

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