Recent

Author Topic: Getting absolute coordinates  (Read 13537 times)

vgoudreault

  • New Member
  • *
  • Posts: 11
Getting absolute coordinates
« on: September 19, 2010, 09:01:03 pm »
I am looking for a way to obtain the X and Y coordinate of a mouse/pointer location.
The Event list does contain a few functions, like OnMouseMove that pass on a X and Y coordinate, but those are relative to the widget for which the OnMouseMove procedure is defined. One can assume that there is some mechanism where the X and Y coordinate in the overall display is obtained, which then gets offset to the running application window, which then gets offset again to the reference location of the widget that has focus. Obtaining the overall position would then require having an active OnMouseMove procedure for every single component, with lots of back-offset calculation to get the original, overall X and Y coordinates of the screen (or the current application window).
Is there some resources that return the overall X and Y coordinates (which must exist somewhere) of the mouse? And are there procedures that allow querying the current value of the pixel, and even to dynamically alter it?
I am developing for Win32 and WinCE, if that matters.

Thanks for any clue.


Vincent G

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4459
  • I like bugs.
Re: Getting absolute coordinates
« Reply #1 on: September 19, 2010, 10:59:29 pm »
TControl has at least these methods:

    function  ScreenToClient(const APoint: TPoint): TPoint;
    function  ClientToScreen(const APoint: TPoint): TPoint;
    function  ScreenToControl(const APoint: TPoint): TPoint;
    function  ControlToScreen(const APoint: TPoint): TPoint;

Juha
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

vgoudreault

  • New Member
  • *
  • Posts: 11
Re: Getting absolute coordinates
« Reply #2 on: September 20, 2010, 03:27:37 am »
Thanks. That is a very good start.

Using

  glopos:=Panel2.ClientToScreen(Point (X,Y));
  locpos:=Form1.ScreenToClient(glopos);   

where X and Y are the current position passed on as arguments to the Panel2MouseMove procedure, I have that "glopos" set to the coordinate for the overall computer screen, and "locpos" would be the coordinate in the application window.

Now, there is the other half of the problem that I want to figure out. If the mouse moves to a daughter widget to Panel2, Panel2MouseMove is not called anymore. Same thing if the pointer moves outside of Panel2 altogether (I will neglect the pathological case where the mouse pointed is continually pressed while moving in and out of elements). One could always define a ...MouseMove for each and every graphical element, but that would be top heavy.
Is there some sort of overall procedure that would be called all the time, i.e. getting some sort of access to the procedure that tracks the mouse location and is at the root of the process that determines that the pointer has just left Panel1 and entered Panel2?


Vincent G


JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4459
  • I like bugs.
Re: Getting absolute coordinates
« Reply #3 on: September 20, 2010, 08:58:54 am »
What do you want to do with the coordinates?
If your widgets are "normal" GUI elements then you can add OnMouseMove handlers in code by iterating all of them.
If you make some kind of drawing program then you should draw graphics on a backround (canvas) and use its events.

Juha
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

vgoudreault

  • New Member
  • *
  • Posts: 11
Re: Getting absolute coordinates
« Reply #4 on: September 21, 2010, 04:45:41 am »


Well, that is the point. One of the application I developed is extremely rich in terms of widgets, and enabling a mouse position for each individual ones would be very repetitive, unless there would be a way to track the current active widget and pass its value on so that one could write

  glopos:=widget.ClientToScreen(Point (X,Y));
  locpos:=Form1.ScreenToClient(glopos);

which would allow all the OnMouseMove event to be associated with a single generic and universal procedure.

I dare assume that all those switching between the various procedure would be some sort of a burden on the system, with it having to track all those events.

I figure, if I get down to the most basic unit, the system mouse tracking, I could build a code that bypasses most of the individual events (sort of like the various widgets inheriting the TForm mouse position) and have a more effective code. One of my main target platform are smartphones/pocketpc, and they do not have all the excess poser of desktop computers, so every little bit may help. On such machines, the mouse does not ' move'  it jumps to where one taps with the stylus/finger, unless it is dragged around.

TCanvas is a interesting tool, which I am now exploring. I will have to resolve and investigate the possibility of working with multiple canvas units, blinking them on and off (visibility) as well as having it share real estate with pop-up/context dependent widgets.

I suppose the next step is to move to LazRGBGraphics and OpenGL. I still have a lot to explore.


Vincent G




felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3538
Re: Getting absolute coordinates
« Reply #5 on: September 21, 2010, 08:17:50 am »
I suppose the next step is to move to LazRGBGraphics and OpenGL. I still have a lot to explore.

I would recommend using TLazIntfImage instead of LazRGBGraphics. AFAIK no one maintains LazRGBGraphics at the moment and it also depends on a per platform implementation.

TLazIntfImage is just as powerful, maintained and works in all Lazarus platforms.

vgoudreault

  • New Member
  • *
  • Posts: 11
Re: Getting absolute coordinates
« Reply #6 on: September 22, 2010, 03:09:51 am »

Thanks for the tip.

Does the mention of TLazIntfImage in http://wiki.freepascal.org/Components_and_Code_examples while it is not in the 'graphic articles' list supposed to imply that it is already included in the distribution and that it is not a component to be added?

Actually, the one thing advanced environment like Lazarus need is some sort of 'flow chart' explorer information page, which would have entries like "do you want to develop 3D graphics?' and would have a recommended course of action on what modules to add or use, with the pros and cons of each -- including their availability on each platform. That would help new comers like myself.


Vincent G




 

TinyPortal © 2005-2018