## coordonates of point

Discussions related to Visual Prolog
marco62118
VIP Member
Posts: 88
Joined: 16 Feb 2011 19:21

### coordonates of point

Hello

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
Novice, very novice in Visual Prolog and even poorer in English

Harrison Pratt
VIP Member
Posts: 285
Joined: 5 Nov 2000 0:01
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
!.``````

Ferenc Nagy
VIP Member
Posts: 289
Joined: 24 Apr 2007 12:26

### Dialog unit coordinates or pixel coordinates?

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?
TIA, Regards,
Frank Nagy

Harrison Pratt
VIP Member
Posts: 285
Joined: 5 Nov 2000 0:01
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.

Paul Cerkez
VIP Member
Posts: 202
Joined: 6 Mar 2000 0:01
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.
AI Rules!
P.

Harrison Pratt
VIP Member
Posts: 285
Joined: 5 Nov 2000 0:01
It looks like there is this to get the color from a bitmap:

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

Harrison Pratt
VIP Member
Posts: 285
Joined: 5 Nov 2000 0:01
This idea from Stackoverflow:
1. Capture the screen to a bitmap
2. Read the pixel color in the bitmap.

http://stackoverflow.com/questions/1483 ... 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!

Ferenc Nagy
VIP Member
Posts: 289
Joined: 24 Apr 2007 12:26
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``````
TIA, Regards,
Frank Nagy

Gukalov
Active Member
Posts: 27
Joined: 5 Oct 2011 15:16
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.

Harrison Pratt
VIP Member
Posts: 285
Joined: 5 Nov 2000 0:01
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.``````

marco62118
VIP Member
Posts: 88
Joined: 16 Feb 2011 19:21
Hello

thank you "Harrison Pratt" I have not had time to thank you "PNT = pnt (X, Y)," suits me
Novice, very novice in Visual Prolog and even poorer in English