Jump to content
Sign in to follow this  
n4gix

Grabbing mouse co-ordinates on a gauge

Recommended Posts

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites
Guest bartels

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.

Share this post


Link to post
Share on other sites

Many thanks Arne; that makes sense.Doug: If your code is slightly different, please post it anyway. This will all go into an updated sd2gau tutorial.-Dai

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

Bill/DougMany thanks for your input. IIRC correctly I've overlooked the use of mouse dragging in the sd2gau tutorials; something that I need to correct and a throttle example seems the perfect way to do it.-Dai

Share this post


Link to post
Share on other sites

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

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