Sign in to follow this  
Guest

Syncronization, callbacks icons and mouse sound area

Recommended Posts

Problem: When the seatbelt switch is set to ON, the sound is played whereafter the switch returns to the OFF position. It should stay in the ON position, and when clicking in this area again, it should return to the OFF position (toggle function). How can this be solved without defining specific areas for OFF and ON?Fragments of the C code ("." marks cut-away areas):// mouse callbacks..BOOL FSAPI mouse_seatbelt_cb(PPIXPOINT, FLAGS32);// callbacks for the icons..FLOAT64 FSAPI seatbelt_cb(PELEMENT_ICON);.// main gauge callbackvoid FSAPI signs_cb(PGAUGEHDR, int, UINT32);.// local variableschar signs_gauge_name[] = GAUGE_NAME; extern PELEMENT_HEADER signs_list;extern MOUSERECT signs_mouse_rect[];..MFSSoundFileVars(seatbelt_sound, "SOUNDJS734DING.WAV"); ..MAKE_ICON( seatbelt_switch, BMP_SIGNS_SEATBELT_OFF, NULL, NULL, IMAGE_USE_ERASE | IMAGE_USE_TRANSPARENCY, 0, 124, 35, MODULE_VAR_NONE, seatbelt_cb, ICON_SWITCH_TYPE_SET_CUR_ICON, 2, 0, 0)// link the drawing elements to the backgroundPELEMENT_HEADER plist1[] = {.. &seatbelt_switch.header, NULL};// MOUSE SPECIFIC DEFINITIONS// --------------------------------------------------------------------------MOUSE_BEGIN(signs_mouse_rect, HELP_NONE, 0, 0).. MOUSE_CHILD_FUNCT(124, 35, 35, 43, CURSOR_HAND, MOUSE_LEFTSINGLE, mouse_seatbelt_cb)MOUSE_END// --------------------------------------------------------------------------// MOUSE CALLBACKS// --------------------------------------------------------------------------..BOOL FSAPI mouse_seatbelt_cb(PPIXPOINT relative_point, FLAGS32 mouse_flags) { // start or stop a looping sound buffer if (MFSSoundIsPlaying(seatbelt_sound)) MFSSoundStop(seatbelt_sound); else // specifying TRUE as the second parameter in the play function (macro) // makes the sound buffer loop forever or until the stop function // (macro) is called MFSSoundFilePlay(seatbelt_sound, FALSE); return FALSE;}// --------------------------------------------------------------------------// DRAWING ELEMENT CALLBACKS// --------------------------------------------------------------------------// icon callbacks..FLOAT64 FSAPI seatbelt_cb(PELEMENT_ICON pelement) { // the button shows "on" while the sound buffer is playing return MFSSoundIsPlaying(seatbelt_sound);}..// --------------------------------------------------------------------------// MAIN GAUGE CALLBACK// --------------------------------------------------------------------------void FSAPI signs_cb(PGAUGEHDR pgauge, int service_id, UINT32 extra_data) { switch(service_id) { case PANEL_SERVICE_POST_INSTALL: // sounds need to be registered before they can be played . MFSSoundFileRegister(seatbelt_sound); . case PANEL_SERVICE_PRE_KILL: // never forget to unregister the sounds . MFSSoundUnRegister(seatbelt_sound); . break; }}// --------------------------------------------------------------------------// CLEAN UP// --------------------------------------------------------------------------#undef GAUGE_NAME#undef GAUGEHDR_VAR_NAME#undef GAUGE_W(end of code)Best regardsJan Harry Sorensenwww.jspanels.com

Share this post


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

Hi Jan,declare a global integer variable, which value is initially 0 (OFF). In the icon callback, define the return value the same as the global variable (return [globalvariable]. As soon as you click on the area, the global variable is set to 1, and because the return value is now also 1, the second picture is displayed (ON). If you click again on the area, the value must again be 0.if ([globalvar] == 1) {[globalvar] = 0;} else {[globalvar] = 1; (maybe trigger sound here)}Enjoy!Greetings,Marcel Burrchief programmingbluesky software development

Share this post


Link to post
Share on other sites

Hi Marcel,Thanks for your help. I have tried to follow your advises, but must admit that this stuff is rather complicated (for me anyway!). The Visual C ++ (6.0) IDE settings:Category: Code GenerationProcessor: Blend*Use run-time library: Multithreaded DLLCalling covention: _cdecl*Struct member alignment: 8 bytes There are alltogether 4 switches where the two first has OFF/ON bitmaps (2):// --------------------------------------------------------------------------// DRAWING ELEMENTS DEFINITIONS// --------------------------------------------------------------------------MAKE_ICON( smokeoff_switch, BMP_SIGNS_NOSMOKING_OFF, NULL, NULL, IMAGE_USE_ERASE | IMAGE_USE_TRANSPARENCY, 0, 24, 35, MODULE_VAR_NONE, nosmoke_cb, ICON_SWITCH_TYPE_SET_CUR_ICON, 2, 0, 0)MAKE_ICON( seatbelt_switch, BMP_SIGNS_SEATBELT_OFF, NULL, NULL, IMAGE_USE_ERASE | IMAGE_USE_TRANSPARENCY, 0, 124, 35, MODULE_VAR_NONE, seatbelt_cb, ICON_SWITCH_TYPE_SET_CUR_ICON, 2, 0, 0)(/snip)The last two has only one bitmap, attendant and ground call buttons.I have further done the following:(snip)..// icons set to OFF or zero valueUINT32 smoke = 0;UINT32 seat = 0;..// --------------------------------------------------------------------------// DRAWING ELEMENT CALLBACKS// --------------------------------------------------------------------------// icon callbacksFLOAT64 FSAPI nosmoke_cb(PELEMENT_ICON pelement) { if (smoke == 1) { smoke = 0; } else { smoke = 1; } // you can check whether a sound buffer is currently playing return MFSSoundIsPlaying(nosmoke_sound);}FLOAT64 FSAPI seatbelt_cb(PELEMENT_ICON pelement) { if (seat == 1) { seat = 0; } else { seat = 1; } // the button shows "on" while the sound buffer is playing return MFSSoundIsPlaying(seatbelt_sound);}(/snip)Result: No change - i.e the switches returns to OFF after playing the sound. I also tried to add some if and else statements in the main gauge callback section, case PANEL_SERVICE_PRE_UPDATE:, but that did not do the trick either:(snip)..case PANEL_SERVICE_PRE_UPDATE: if (smoke == 0) { HIDE_IMAGE(pgauge->elements_list[0]->next_element[1]); } else if (smoke == 1) { SHOW_IMAGE(pgauge->elements_list[0]->next_element[1]); } if (seat == 0) { HIDE_IMAGE(pgauge->elements_list[0]->next_element[2]); } else if (seat == 1) { SHOW_IMAGE(pgauge->elements_list[0]->next_element[2]); } ..(end of code snippets)This had no effect other than that the seatbelt and attend switches where flickering all the time, but the sounds were there as "normal".Best regardsJan Harry Sorensenwww.jspanels.com

Share this post


Link to post
Share on other sites

Hi Jan,in the seatbelt_cb you wrote:------------if (seat == 1){seat = 0;}else{seat = 1;}// the button shows "on" while the sound buffer is playingreturn MFSSoundIsPlaying(seatbelt_sound);-----------this is nonsense! You already did that in the mouse callback!Delete all you wrote out of the callback and write: return seat; Thats it!If you want to know why, download the "Switch tutorial" of EasyGauge at www.bluesky-net.de There is the syntax explained.Greetings,Marcel Burrbluesky software

Share this post


Link to post
Share on other sites

Hi Marcel,I have studied the "Switch Tutorial" and compiled a new switch with sound in the EASYgauge program which worked :) Thereafter I corrected the following sections in signs.c:(code snippets)..// --------------------------------------------------------------------------// MOUSE CALLBACKS// --------------------------------------------------------------------------BOOL FSAPI mouse_nosmoke_cb(PPIXPOINT relative_point, FLAGS32 mouse_flags) { if ( smoke == 0 ) { smoke = 1 ; } else { smoke = 0 ; } MFSSoundFilePlay(nosmoke_sound, FALSE); return FALSE;}..// --------------------------------------------------------------------------// DRAWING ELEMENT CALLBACKS// --------------------------------------------------------------------------// icon callbacksFLOAT64 FSAPI nosmoke_cb(PELEMENT_ICON pelement) { return smoke;}..(end of code snippets)And NOW it works! Many thanks for your help :)Best regardsJan Harry Sorensenwww.jspanels.com

Share this post


Link to post
Share on other sites

Hi Jan,I am very happy that EasyGauge helped you.If you have any further questions, feel free to ask me!Greetings,Marcel Burrbluesky software development

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