Discussions related to Visual Prolog
marco62118
Posts: 9
Joined: 16 Feb 2011 19:21

coordonates of point

Unread post by marco62118 »

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: 439
Joined: 5 Nov 2000 0:01

Unread post 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         !.
User avatar
Ferenc Nagy
VIP Member
Posts: 215
Joined: 24 Apr 2007 12:26

Dialog unit coordinates or pixel coordinates?

Unread post 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?
TIA, Regards,
Frank Nagy
Harrison Pratt
VIP Member
Posts: 439
Joined: 5 Nov 2000 0:01

Unread post 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.
Paul Cerkez
VIP Member
Posts: 106
Joined: 6 Mar 2000 0:01

Unread post 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.
AI Rules!
P.
Harrison Pratt
VIP Member
Posts: 439
Joined: 5 Nov 2000 0:01

Unread post by Harrison Pratt »

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: 439
Joined: 5 Nov 2000 0:01

Unread post by Harrison Pratt »

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!
User avatar
Ferenc Nagy
VIP Member
Posts: 215
Joined: 24 Apr 2007 12:26

Unread post 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
TIA, Regards,
Frank Nagy
User avatar
Gukalov
VIP Member
Posts: 62
Joined: 5 Oct 2011 15:16

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

Unread post 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.
marco62118
Posts: 9
Joined: 16 Feb 2011 19:21

Unread post by marco62118 »

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
Post Reply