From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabWindows/CVI User Group Documents

cancel
Showing results for 
Search instead for 
Did you mean: 

LabWindows/CVI Tip: Little known Rectangle and Point Coordinate functions

No need to write your own coordinate functions! Take a closer look at built-in CVI functions that compare point coordinates to the location of a rectangle area. Such functions are useful when locating mouse clicks on the front panel.

A great example that demonstrates the usefulness of this function is the Colview.cws example. This code shows how to use the Table control in an interactive way, by clicking on the table's column label will sort the list contents using that column as a key. The RectContainsPoint function helps us determine where the mouse click occurred, specifically which column label is clicked by the user.

colviewexample.png

Here is the Code snippet that uses RectContainsPoint to determins the column label clicked on.

colviewcode.png

All Rectangle and Point functions can be found in the User Interface Library as seen below.

libtree Rect functions.png

Below is a further description of the RectContainsPoint function taken from CVI Help.

RectContainsPoint

int RectContainsPoint (Rect rect, Point point);

Purpose

Returns 1 if the specified rectangle encloses the point you specify. The function returns 0 otherwise.

The rectangle is considered to enclose the point if the point is in the interior of the rectangle or on its frame.

Parameters

Input
NameTypeDescription
rectRectThe location and size of a rectangle.
pointPointThe location of the center of the rectangle.

Return Value

NameTypeDescription
containsPointintIndicates if rect contains point.

CodeDescription
1point is in the interior or on the frame of the rectangle specified by rect.
0point is outside the frame of the rectangle specified by rect.

Refer to userint\colview.cws for an example of using the RectContainsPoint function.

Did you find this tip useful? Rate this document or add a comment below.

National Instruments
Comments
ASIC_LabRat
Member
Member
on

Can this be used to identify(and select) a point on a graph plot?

nickb
Active Participant
Active Participant
on

Hmmm... While these functions may be helpful for that, in general, the best approach is to create a cursor that snaps to a point (VAL_SNAP_TO_POINT).  You can make the cursor transparent if you'd like.  Then, when you want to select a point, you click on the graph, move the cursor to the click location (SetGraphCursor), and then determine which point the cursor is on (GetGraphCursorIndex).

Contributors