Re: Line-Mouse widget tool [message #43256 is a reply to message #43234] |
Tue, 29 March 2005 14:42  |
Robert Barnett
Messages: 70 Registered: May 2004
|
Member |
|
|
David,
I render a direct graphics plot onto a widget_draw.
How do you transform a mouse click event which is specified in pixels to
data-space when using direct graphics? I can compute it from the
xmargin, ymargin, xtick_get, ytick_get, xsize and ysize. But, surely
there must be an easier way?
Here is an excerpt from my code:
; ev - The event struct
; draw_id - The Widget_Draw
; return_kewyords - Keywords returned from plot
xcharsize = 6.0
ycharsize = 10.0
geometry = widget_info(self.draw_id, /geometry)
; Calculate the corresponding x,y value coordinate on the plot
evx = ev.x - xmargin[0] * xcharsize
evy = ev.y - ymargin[0] * ycharsize
evwidth = geometry.xsize - total(xmargin) * xcharsize
evheight = geometry.ysize - total(ymargin) * ycharsize
xtickget = *return_keywords.xtick_get
ytickget = *return_keywords.ytick_get
xmaxtick = N_ELEMENTS(xtickget) - 1
ymaxtick = N_ELEMENTS(ytickget) - 1
x = xtickget[0] + (xtickget[xmaxtick] - xtickget[0]) * evx / evwidth
y = ytickget[0] + (ytickget[ymaxtick] - ytickget[0]) * evy / evheight
return, [x, y]
David Fanning wrote:
> Howard S. Cohl writes:
>
>
>> Oh, one more thing, if it's not too difficult, is to build into the
>> widget the capability to use curved line segments (splines, or polynomials
>> perhaps) as well as straight lines and be able to output either the
>> equation of the curve or output a the numerical set of N values for the
>> curved line segment.
>>
>
> Oh, well, a little more than an hour, then. :-)
>
> Cheers,
>
> David
>
>
--
nrb@
Robbie Barnett
imag
Research Assistant
wsahs
Nuclear Medicine & Ultrasound
nsw
Westmead Hospital
gov
Sydney Australia
au
+61 2 9845 7223
|
|
|