# screen possition

## Recommended Posts

Hi All

does any one know how to get the screen or window possiton of a fe node or element?

##### Share on other sites

Hi

To clarify the question, I want to return the screen (pixel) coordinates of a node/element in the current screen view?

##### Share on other sites

Hi there

I think this is similar to my question:

Maybe one should call the support to get an answer ...

Greetings

Thomas

##### Share on other sites

Called the support - got no answer - but a colleague at work found out ...

Here is the solution:

`# getScreenPosOfNode --##       Delivers the screen position of a node \$nodeID. A node at the lower left#       corner of the viewport gives (0/0) - at the upper right corner (1/1).## Arguments:#       nodeID   node number to retrieve screen position for## Results:#       Returns a list of 2 values: relative x- and relative y-screen-positionproc getScreenPosOfNode {nodeID} {    set P [join [hm_nodevalue \$nodeID]] ;# real world coords in global coord sys    set view [join [hm_getcurrentview]]    # extract transformation matrix T    set T [list [lrange \$view 0 2] [lrange \$view 4 6] [lrange \$view 8 10]]    set v [lrange \$view 12 14] ;# translation vector v    foreach {minx miny maxx maxy} [join [hm_getviewport]] {}    # rotational transformation: real world coords to screen coords (P-->P_)    set P_ {}    for {set row 0} {\$row < 3} {incr row} {        set coord_ 0        for {set col 0} {\$col < 3} {incr col} {            set coord_ [expr {\$coord_+[lindex \$T \$col \$row]*[lindex \$P \$col]}]        }        lappend P_ \$coord_    }    # add translation (P_-->P_canvas)    set Px_canvas [expr {[lindex \$P_ 0]+[lindex \$v 0]}]    set Py_canvas [expr {[lindex \$P_ 1]+[lindex \$v 1]}]    # compute relative screen position    set Canvas_DeltaX [expr {\$maxx-\$minx}]    set Canvas_DeltaY [expr {\$maxy-\$miny}]    set P_relX [expr {(\$Px_canvas-\$minx)/double(\$Canvas_DeltaX)}]    set P_relY [expr {(\$Py_canvas-\$miny)/double(\$Canvas_DeltaY)}]    return [list \$P_relX \$P_relY]}`

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

You are posting as a guest. If you have an account, please sign in.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.