LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

move graph cursor with mouse

I am using 6.0 and I would like to create a graph with 2 plotlines and have a mouse move a freeform cursor without dragging with a button.
 
I am using GetRelativeMouseState() to obtain the mouse position inside the graph. I would like to know how to translate that into the graph cursor's position. The y-axis dynamically changes so I can't use an easy static workaround. How can I do this? thx
0 Kudos
Message 1 of 12
(5,171 Views)
Hi sergsergserg,

Are you trying to update the cursor position as the mouse hovers over the graph without clicking any mouse button?

Regards,
0 Kudos
Message 2 of 12
(5,135 Views)
Correct.
 
I would like to show a cursor (vertical line so only X-axis will change)  that follows the mouse cursor when it is over the graph control.
 
I use: GetRelativeMouseState (panelGraph, PANELBIG_GRAPHBIG, &x, &y, NULL, NULL, NULL);
to get the mouse position.
 
Then I use: GetCtrlAttribute (panelGraph, PANELBIG_GRAPHBIG,ATTR_PLOT_AREA_WIDTH, &pWidth);
to get the width of the plot.
 
I use these 2 positions to find out which x-axis index position to attach the vertical line cursor to.
 
It does a 'decent' job of following the mouse cursor, but totally breaks down if zooming is used as it will only work if the autozoom is on.
 
Thx,
 
Jason
0 Kudos
Message 3 of 12
(5,116 Views)
Hi sergsergserg,

There are few things you need to do in order to accomplish this.
First, you need to listen for the mouse move event on the graph. You are probably already doing this but here is how:

EnableExtendedMouseEvents (panelHandle, PANEL_GRAPH, .1);

Next, you must modify the graph callback to handle the event and update the graph cursor location. Notice the call to GetGraphCoordsFromPoint. This function will compute the graph coordinates of the point returned from GetRelativeMouseState. The return value will be 0 if the point is not within the graph's plot area. If this is the case, then you do not want to update the cursor position (without this you will receive an error when zooming is enabled). Another thing to consider is the plot area left/top offset. You must offset the values returned from GetRelativeMouseState because they are relative to the graph control's edge, rather than the edge of the plot area in the graph. I tried with little success to use the values returned from GetCtrlAttribute (commented out below) so I had to specify an offset manually. This was reported to R&D (# 45LDIIZL) for further investigation.

int CVICALLBACK GraphCallback (int panel, int control, int event,
        void *callbackData, int eventData1, int eventData2)
{
    int xCoordinate, yCoordinate, leftButtonDown, rightButtonDown, keyModifiers;
    int plotAreaLeftOffset, plotAreaTopOffset;

    double xCursor, yCursor;
   
    switch (event)
    {
        case EVENT_MOUSE_MOVE:
           
            GetRelativeMouseState (panelHandle, PANEL_GRAPH,
                &xCoordinate, &yCoordinate,
                &leftButtonDown, &rightButtonDown,
                &keyModifiers);
           
            plotAreaLeftOffset = 19;
            plotAreaTopOffset = 38;
           
            //GetCtrlAttribute (panelHandle, PANEL_GRAPH, ATTR_PLOT_AREA_LEFT, &plotAreaLeftOffset);
            //GetCtrlAttribute (panelHandle, PANEL_GRAPH, ATTR_PLOT_AREA_TOP, &plotAreaTopOffset);
           
            if (GetGraphCoordsFromPoint (panelHandle, PANEL_GRAPH,
                MakePoint (xCoordinate + plotAreaLeftOffset, yCoordinate + plotAreaTopOffset),
                &xCursor, &yCursor))
            {
                SetGraphCursor (panelHandle, PANEL_GRAPH, 1, xCursor, yCursor);
            }
            break;
    }
    return 0;
}

I was able to implement this method successfully on my system (CVI 8.1) with zooming enabled.
Message 4 of 12
(5,075 Views)
James,

ATTR_PLOT_AREA_LEFT and ATTR_PLOT_AREA_TOP were only introduced in CVI 7.0, so they wouldn't be available to sergsergserg. The only workaround would be for sergsergserg to download the latest runtime engine (link below), and then use the IDs of those attributes (1129 and 1128, respectively) and hope for the best.

Here's the CVI 8.1 RTE: http://digital.ni.com/softlib.nsf/websearch/F1C03164F065432586256EEC005EBA87?opendocument&node=132060_US

It's probably best to try this in a test machine first, since installing the CVI 8.1 RTE will remove the 6.0 RTE. It should be backwards compatible, but it makes sense to test it first.

Luis
Message 5 of 12
(5,067 Views)
A few of my problems has been because it is 6.0 and I have run into solutions, but they seem to be for newer versions.
 
Is 'EnableExtendedMouseEvents (panelHandle, PANEL_GRAPH, .1);' usable in 6.0?
 
I have tried to use this before, but get a 'missing prototype' error and cannot find the function in the help list. Do I need to include a windows header file? If so which one. Thx for ur help so far.
 
-Jason
0 Kudos
Message 6 of 12
(5,053 Views)
Correction:
 
Copying and pasting the line wasn't working, and I verified I had the 'toolbox.h' was there.
 
Adding it in using the menus (same exact code as copy/paste) then prompted me to add toolbox.h
 
So that part is solved.
0 Kudos
Message 7 of 12
(5,042 Views)
Hi Jason,

At this point I am unsure if your question has been fully answered. Please understand that it is our official policy to support two major revisions back. Consequently, my resources are limited in terms of anwering every question specifically related to 6.0. However, after looking into EnableExtendedMouseEvents further, it seems as though this method is obsolete. The function help suggests listening for EVENT_MOUSE_POINTER_MOVE, so this may be a viable option for you.

Regards,
0 Kudos
Message 8 of 12
(5,025 Views)
The reason for starting this thread is to really figure out a solution for converting the relativemousestate positioning which is in pixels to something I can translate onto a cursor, which is an index of the plot points. Then using the cursor's location to output the plot's data at that index. Unfortunately all the functions I am finding seem to be for 7.1+ versions.
 
Thx for the continued interest.
Jason
0 Kudos
Message 9 of 12
(5,021 Views)
You can use EnableExtendedMouseEvents in CVI 6.0. The function is available in the Programmer's Toolbox. To use the Programmer's Toolbox in CVI 6.0, you need to add toolslib\toolbox\toolbox.fp to your project.

As James pointed out, that function is now obsolete, but that's only in CVI 8.1, when some additional UI events were added to the UI Library which made extended mouse events unnecessary.

Luis
0 Kudos
Message 10 of 12
(5,008 Views)