mouse cursor / object position

This forum is for eXpress++ general support.
Post Reply
Message
Author
Zdeno Bielik
Posts: 147
Joined: Thu Jan 28, 2010 9:24 am
Location: Nitra, Slovakia
Contact:

mouse cursor / object position

#1 Post by Zdeno Bielik »

Hi Roger,

one customer asked from me solution for task like this:
I need to know object, over which just mouse is while user move mouse’s cursor or cursor stops over any object – e.g. it is over green arrow or over yellow star...
The problem is I cannot put each ones objects on dcstatic area, but I can only put one whole image(see attached example) on dcstatic object.
Do you have idea how to solve this?

TIA & Regards
Zdeno
Attachments
rd-example.png
rd-example.png (15.13 KiB) Viewed 5909 times

User avatar
rdonnay
Site Admin
Posts: 4734
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: mouse cursor / object position

#2 Post by rdonnay »

I would probably approach such a project with a simple solution, making the assumption that each object occupies a rectangular area of the screen, even if it does not look rectangular.

In other words, I would determine the rectangular coordinates that would best define the object on the screen.

Examples ;
1. The upper-left object ( the right-pointing arrow ) occupies the rectangular coordinates from 40, 20 to 380, 80.
2. The upper-middle object ( the star ) occupies the rectangular coordinates from 395,17 to 488,100.
3. The pentagon occupies the rectangular coordinates from 508, 49 to 648,172.

There are 13 total objects, so I would create a multi-dimensional array of 13 elements.
It would look like this:

Code: Select all

aObjects := { ;
   { 40,20,380,80,'Right pointing arrow' }, ;
   { 395,17,488,100,'Star' }, ;
   { 508,49,648,172,'Pentagon' }, ;
   .... }
I would then use the :motion callback slot of the static object to call a function every time the mouse is moved.

Code: Select all

@ .. DCSTATIC oStatic TYPE XBPSTATIC_TYPE_BITMAP CAPTION 'Objects.Bmp' ;
      EVAL {|o|o:motion := {|aMousePos|DisplayObjectName( aMousePos, aObjects, oObjectName )}

@ .. DCSTATIC oObjectName TYPE XBPSTATIC_TYPE_TEXT ...

* ------------

STATIC FUNCTION DisplayObjectName( aMousePos, aObjects, oObjectName )

nObject := FindObject( aMousePos, aObjects )

IF nObject > 0
  oObjectName:setCaption( aObjects[nObject,5] )
ELSE
  oObjectName:setCaption( '' )
ENDIF

RETURN nil

* ------------

STATIC FUNCTION FindObject( aMousePos, aObjects ) 

LOCAL i, nObject := 0

FOR i := 1 TO Len(aObjects)

  IF aMousePos[1] >= aObjects[i,1] .AND. aMousePos[1] <= aObjects[i,3] .AND. ;
     aMousePos[2] >= aObjects[i,2] .AND. aMousePos[2] <= aObjects[i,4]
    nObject := i
    EXIT
  ENDIF

NEXT[

RETURN nObject
This is a rather simplistic approach but it may satisfy the needs of your customer.
The eXpress train is coming - and it has more cars.

Zdeno Bielik
Posts: 147
Joined: Thu Jan 28, 2010 9:24 am
Location: Nitra, Slovakia
Contact:

Re: mouse cursor / object position

#3 Post by Zdeno Bielik »

Roger,

thank you for example, it works great!

Zdeno

Post Reply