Skip to content
View in the app

A better way to browse. Learn more.

The AVSIM Community

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Grabbing mouse co-ordinates on a gauge

Featured Replies

  • Commercial Member

Someone has actually managed to persuade me to look again at FS... :) but I'm finding that quite a bit of my old sd2gau tutorials is now completely out of date. I've caught up with a lot of it and added some new stuff, but one area that I specifically need no longer works. Does anyone know how to grab the mouse cursor co-ordinates from a gauge? Getting cursor co-ordinates for the entire panel is dead easy but equally useless :/ and using the method that I detailed in sd2gau for FS2K and FS2K2 simply crashes FS9. I want to rotate an ASI speedbug by dragging the mouse and I need to check that the left button down action is within the bounding box defined by the size and position of the speedbug bitmap before moving the bug.-Dai

Dai,I have the code at home and will post it later this evening; that is, if Arne or Bill don't beat me to it...Doug

Nice to see hear from you again!FS has overloaded the PPIXPOINT argument of a mouse callback quite heavily try e.g:#define GAUGEHDR_FOR_MOUSE_CALLBACK(PIXPOINT) ((PIXPOINT) ? ((PGAUGEHDR)(((PMOUSECALLBACK)(PIXPOINT))->user_data)) : NULL)#define PMOUSERECT_FOR_MOUSE_CALLBACK(PIXPOINT) ((PIXPOINT) ? ((PMOUSERECT)(((PMOUSECALLBACK)(PIXPOINT))->mouse)) : NULL)...BOOL FSAPI set_cursorpos(PPIXPOINT arg1, FLAGS32 mouse_flags){ MOUSERECT *pmouse_rect = PMOUSERECT_FOR_MOUSE_CALLBACK(arg1); if(arg1!=NULL && pmouse_rect!=NULL) { //do something with arg1->x and pmouse_rect->relative_box.size_x // arg1->y and pmouse_rect->relative_box.size_y } return FALSE;}You can even get the GAUGEHDR with GAUGEHDR_FOR_MOUSE_CALLBACK. Both macros might not be in the original form any more.

Dai,This seemed to work for me:SINT32 mouse_x, mouse_y;SINT32 size_y, size_x;void FSAPI gauge_callback_function(PGAUGEHDR pgauge, int service_id, UINT32 extra_data){switch(service_id){case PANEL_SERVICE_PRE_DRAW:/*Vertical size of gauge; could also be referenced here as pgauge->size.y*/size_y = pgauge->mouse_rect->relative_box.size_y;break;}}BOOL FSAPI mouse_click( PPIXPOINT relative_point, FLAGS32 mouse_flags){// Position of mouse relative to the upper left corner of the gauge mouse_x = relative_point->x; mouse_y = relative_point->y; return FALSE;}MOUSE_BEGIN(Mouse_Display_mouse_rect,0,0,0) MOUSE_CHILD_FUNCT(0,0,40,46,CURSOR_HAND,MOUSE_LEFTSINGLE | MOUSE_LEFTDRAG,mouse_click)MOUSE_ENDFLOAT64 FSAPI callback3( PELEMENT_STRING pelement){/*Vertical position of the mouse click or drag.Will need to restrict values based on minimum of 0 and maximum of pelement->gauge_header->size.y*/sprintf(pelement->string,"%d",mouse_y);return 0;}FLOAT64 FSAPI callback2( PELEMENT_STRING pelement){//Vertical size of the gaugesprintf(pelement->string,"%d",size_y);return 0;}MAKE_STRING(String3,NULL,NULL,IMAGE_USE_ERASE | IMAGE_USE_TRANSPARENCY | BIT7,0,2,22,40,16,10,MODULE_VAR_NONE,MODULE_VAR_NONE,MODULE_VAR_NONE,RGB(255,255,255),RGB(0,0,0),RGB(0,0,0),GAUGE_FONT_DEFAULT3,GAUGE_WEIGHT_DEFAULT3,GAUGE_CHARSET3,0,0,NULL,callback3)PELEMENT_HEADER ElementList2[] = {&String3.header,NULL};MAKE_STRING(String2,&ElementList2,NULL,IMAGE_USE_ERASE | IMAGE_USE_TRANSPARENCY | BIT7,0,2,2,40,16,10,MODULE_VAR_NONE,MODULE_VAR_NONE,MODULE_VAR_NONE,RGB(255,255,255),RGB(0,0,0),RGB(0,0,0),GAUGE_FONT_DEFAULT2,GAUGE_WEIGHT_DEFAULT2,GAUGE_CHARSET2,0,0,NULL,callback2)PELEMENT_HEADER ElementList3[] = {&String2.header,NULL};MAKE_STATIC(Static1,Rec0,&ElementList3,NULL,IMAGE_USE_ERASE | IMAGE_USE_TRANSPARENCY | BIT7,0,0,0)PELEMENT_HEADER Mouse_Display_list = &Static1.header;Doug

  • Author
  • Moderator

LOL! Doug, you just beat me to the punch... :)I was fixing to post pretty much the same thing regarding these two flags:relative_point->xrelative_point->yUsed here in a simple throttle mouse callback to drag the lever:BOOL FSAPI THROT_mouse_cb( PPIXPOINT relative_point, FLAGS32 mouse_flags){thrust_pos = ( 196 - relative_point->y ) * 83.591836 ; trigger_key_event (KEY_THROTTLE1_SET,thrust_pos) ; return FALSE;}*NOTE: 196 is the total pix of vertical movement & 83.591836 is the scalar used to calculate pixel offset from max THROTTLE1 value.

Fr. Bill    

AOPA Member: 07141481 AARP Member: 3209010556


     Avsim Board of Directors | Avsim Forums Moderator
  • Author
  • Moderator

No problem, Dai! Your tutorial(s) have been a great help for a countless number of folks who'd otherwise would've been left staring at the lame excuse for an SDK thinking "Huh??" :)My first calculus professor was a retired mining engineer who undoubtedly knew the subject with alacrity, but lamentably lacked the skills to teach anyone how to find their own arse with two hands and a flashlight! Although I passed the semester (barely!), I deliberately repeated the class the following semester with another professor who actually knew how to teach... ;)It's not really that difficult to teach well, it all comes down to using relevant examples and speaking (writing) clearly, building up concepts methodically, and making sure not to "assume" too much! :-beerchug

Fr. Bill    

AOPA Member: 07141481 AARP Member: 3209010556


     Avsim Board of Directors | Avsim Forums Moderator

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.