Page 1 of 1

coordonates of point

Posted: 9 Jan 2016 18:25
by marco62118

how to retrieve the x, y coordinates of a point?

I saw but I do not know how to apply

Code: Select all

vpiDomains::pnt=pnt(integer X, integer Y)

thank you

Posted: 10 Jan 2016 4:29
by Harrison Pratt
Take a look at the Mouse___Listeners in the Events properties of the form that the mouse is in.

A little example:

Code: Select all

predicates     onMouseUp : window::mouseUpListener. % <== predicate for MouseUpListener event in Form clauses     onMouseUp(_Source, PNT, _ShiftControlAlt, _Button) :-           PNT = pnt(X,Y),         % do something with X and Y here         !.

Dialog unit coordinates or pixel coordinates?

Posted: 11 Jan 2016 13:34
by Ferenc Nagy
Are the above coordinates passed to the mouse event listener measured in dialog units or pixels?
Their automatically generated code uses dialog base units when the controls of a form or dialog are created.
Let me suppose I have bitmap control like the Russian flag, and a mouse down listener delegated to it. How can I decide whether the user has clicked on its red, blue or white stripe? (I presume that the 3 stripes have equal height.)
Which is the simplest way of coordinate transformation?

Let the position and the size of the flag XD,YD, WD, HD in d.b.u.
Which are the rectangle coordinates in pixels RED_RCT, BLUE_RCT, WHITE_RCT, respectively?

Posted: 12 Jan 2016 4:35
by Harrison Pratt
The PNT is returned expressed in logical pixels, i.e., pnt( PixelX, PixelY ). One way to approach the flag problem is to map out the flag as a series of rectangles of known color and test to see which rectangle contains PNT.

Code: Select all

gui_native::ptInRect/3-> ptInRect : (     vpiDomains::rct Rect,     integer PointX,     integer PointY)     -> booleanInt Result     language apicall.
I don't know if there is a way to determine the color of a given pixel.

Posted: 12 Jan 2016 13:06
by Paul Cerkez
Not sure about in VIP 7.5 but I could swear there used to be a clause to get the color directly from the pnt(X,Y).

don't remember exactly but it was something like:
Color = Win_GetPixel(Win, pnt(X, Y))

you provided the window handle and the coordinates and then retrieved the color. It's been quite a while (maybe as far back as VIP 5.x) but I used to use this a lot in determining where the user was on the screen based on the color at the mouse down to execute specific actions.

Posted: 12 Jan 2016 21:01
by Harrison Pratt
It looks like there is this to get the color from a bitmap:

getPixel : ( integer X, integer Y) -> color Color.

Posted: 12 Jan 2016 21:11
by Harrison Pratt
This idea from Stackoverflow:
1. Capture the screen to a bitmap
2. Read the pixel color in the bitmap. ... reen-pixel

There are several "solutions" to this question, most of which seem to use this strategy. I guess it's not a bad approach since most applications wouldn't require polling a pixel (or pixels) for a change in color, which would require recapturing the screen image bitmap.

Search Google for "c# windows get color of pixel on screen" for many similar approaches.

Disclaimer: I have not tried any of these notions!

Posted: 13 Jan 2016 8:34
by Ferenc Nagy
Let me return to my problem:
The dialog editor uses dialog base units in order to easy fit the texts of the controls if the programmer changes the dialog font face or size.
If I know well these integer coordinates appear in the lines creating controls of the generatedInitialize() procedures as rct(LDBU, TDBU, RDBU, BDBU).

However, the mouse event handlers use click positions measured in pixels.

Let the rectangle of the flag FLAGRECTDBU=rct(LDBU, TDBU, RDBU, BDBU) in dialog base units.
The corresponding rectangle in pixels FLAGRECTPIX=Rrct(LPIX, TPIX, RPIX, BPIX).

Which is the simplest way of the transformation dbuToPix(rct FLAGRECTDBU [in], rct FLAGRECTPIX [out]) ?

So if the mouse in clicked at pnt(XCLICK, YCLICK) which is inside the rectangle rct(LPIX, TPIX, RPIX, BPIX) then we are within flag.
The stripes of the Russian flag are horizontal and have equal heights. [Unlike the stripes of the Spanish flag where the ratio is 1:2:1]. This simplifies our task after the rectPntInside call.

Code: Select all

dbuToPix(FLAGRECTDBU,FLAGRECTPIX), rectPntInside(rct(LPIX, TPIX, RPIX, BPIX),pnt(XCLICK, YCLICK)), if YCLICK<(TPIX*2+BPIX) div 3 then     Color=color_white elseif if YCLICK>(TPIX+BPIX*2) div 3 then     Color=color_red else     Color = color_blue end if

Posted: 13 Jan 2016 11:03
by Gukalov
The stripes of the Russian flag are horizontal and have equal heights.
Stupid way may be, but works - just make 3 imaleControls (for 3 colors). And forget about coordinates - click happens on certain control with certain color.

P.S. setUnit(pixelUnit) - you can aplay it in dialog constructor and averything will work in pixel coordinates only. But it can "brakes" coordinates/sizes.

Posted: 13 Jan 2016 13:16
by Harrison Pratt
Frank, have you looked at this:

Code: Select all

vpi::getBaseUnits/2   getBaseUnits : (     integer DlgBaseWidth [out],     integer DlgBaseHeigth [out])     language c.   Returns the pixel equivalents of the horizontal (width) and vertical (height) dialog base units.

Posted: 13 Jan 2016 17:18
by marco62118

thank you "Harrison Pratt" I have not had time to thank you "PNT = pnt (X, Y)," suits me