X
PrevPrev Go to previous topic
NextNext Go to next topic
Last Post 09 Mar 2006 01:26 PM by  anon
how can I continuously print out the coordinates, data of the cursor when the mouse is moving
 1 Replies
Sort:
You are not authorized to post a reply.
Author Messages

anon



New Member


Posts:
New Member


--
09 Mar 2006 01:26 PM
    I am new to this forum so, first of all, hello to everyone and thanks in advance for the help. I'm truly a beginner in IDL so I suspect my problem should have a simple answer, be patient in case this is true... I'm writing a simple program which should plot together the coordinates, data of the cursor when the mouse is moving. My problem is, I was planning to use cursor for this, but the CURSOR procedure does not seem to work continuously, that is to say, the CURSOR procedure does not print out the coordinates, data of the cursor if the mouse is moving and some key does not be depressed. So: I may be doing something wrong, and CURSOR is supposed to work continuously. Or, there is some other method to grab the position of the cursor continuously. I spent some time looking in the documentation and on internet, with no success. Or, there's not a way to do it, which would seem truly weird to me... Thanks CHEN shao-hui

    Deleted User



    New Member


    Posts:
    New Member


    --
    09 Mar 2006 01:26 PM
    CURSOR is a very simple "one-time event handler" function that IDL created for a very limited purpose- providing on a direct graphics window the coordinates where a user presses a button. For the functionality you want, where the display of coordinates should update dynamically as a mouse "drags", IDL programmers need to learn some basic IDL Widget code. The place to learn this is in 'Online Help -> Contents tab page -> Programmer's Guides -> Building IDL Applications -> Part IV: Creating Graphical User Interfaces in IDL' This sample code below gives you a taste of what is involved in widget programming, using your cursor coordinates example: PRO ex_display_mouse_location_event, event ; Handle only draw widget events if tag_names(event, /STRUCTURE_NAME) ne 'WIDGET_DRAW' then return widget_control, event.top, GET_UVALUE=info ; Handle motion events only if button is pressed while dragging switch event.type of 0: begin ; button press if event.press eq 1 then *info.buttonPressed = 1 break end 1: begin ; button release - clear the label text widget_control, info.wLabel, SET_VALUE=info.defaultLabelText *info.buttonPressed = 0 return end 2: break ; motion event else: begin ; all other events widget_control, info.wLabel, SET_VALUE=info.defaultLabelText *info.buttonPressed = 0 return end endswitch ; Process events not processed in switch statement above if *info.buttonPressed ne 1 then return ; If mouse not pressed, don't process ; If mouse moves off draw window, then clear label text if event.x lt 0 or event.x gt 359 or event.y lt 0 or event.y gt 359 then begin widget_control, info.wLabel, SET_VALUE=info.defaultLabelText return endif statusMsg = 'Value at [' + strtrim(event.x, 2) + ',' + strtrim(event.y, 2) + $ '] = ' + strtrim(info.data[event.x, event.y], 2) widget_control, info.wLabel, SET_VALUE=statusMsg END PRO ex_display_mouse_location tlb = widget_base(/COLUMN, TITLE='Cursor Coordinate Displayer') wDraw = widget_draw(tlb, XSIZE=360, YSIZE=360, /BUTTON_EVENTS, /MOTION_EVENTS) instructionMsg = 'Hold button down and drag on image ...' wLabel = widget_label(tlb, XSIZE=360, /SUNKEN_FRAME, VALUE=instructionMsg) widget_control, tlb, /REALIZE ; Draw some example data on the draw widget window data = dist(360) widget_control, wDraw, GET_VALUE=winID wset, winID tv, data ; Method for passing variables and handles to event handler code: info = {wDraw:wDraw, wLabel:wLabel, data:data, buttonPressed:ptr_new(0), $ defaultLabelText:instructionMsg} widget_control, tlb, SET_UVALUE=info ; Method for accessing event handler xmanager, 'ex_display_mouse_location', tlb END
    You are not authorized to post a reply.