[racket] plot pixel position

From: Neil Toronto (neil.toronto at gmail.com)
Date: Wed Apr 16 12:04:09 EDT 2014

I don't know under what circumstances the paint events should be 
coalesced, nor why it's not happening here. But here's an evil hack you 
can use in your class definition to get around the problem:

   (define refresh? #f)

   ;; 20hz timer to check the refresh? flag
   (define refresh-timer
     (make-object timer%
       (λ () (when refresh?
               (send this refresh)
               (set! refresh? #f)))
       50))

Instead of (send this refresh) you'd use (set! refresh? #t).

I think this hack stops working well when the plots start taking longer 
than 50ms to generate. The plot snips have some way to get around this 
that I can't remember, and also render on another thread to keep the GUI 
responsive. IIRC, the logic is tricky and hard to get right, so you 
might want to look into how those are implemented.

Neil ⊥

On 04/15/2014 12:59 PM, David Vanderson wrote:
> Sorry for the delay.  I hacked together something that lets you drag
> points around on a plot (attached).
>
> Is there a way to access area's plot->dc?  For this example I wanted to
> ask if the mouse was within 2 pixels of any point.
>
> When dragging the point around on the plot, it looks like I'm seeing
> multiple repaints queueing up.  It's especially bad on Linux where I can
> move the mouse a bunch and then watch all the repaints happen over the
> next few seconds.  I'm trying to figure out if this can be improved.
>
> Question for GUI experts: Is there a reason why multiple repaint
> requests in the queue should not be coalesced into a single paint?
>
> Thanks,
> Dave
>
> On 04/01/2014 05:41 PM, Neil Toronto wrote:
>> On 04/01/2014 02:17 PM, David Vanderson wrote:
>>> Plot is fantastic - thanks so much!
>>>
>>> Is there a way to hook into the interactive features of plot so, for
>>> instance, the user could click to add data or drag data points around?
>>>
>>> I'm using plot/dc to draw onto a canvas, and I'd be more than happy just
>>> to be able to ask a plot to translate a pixel position to the
>>> corresponding axes' positions.  I know that plot does this for the
>>> zooming feature, but is there a way for external code to do it?
>>
>> There's not an easy way right now.
>>
>> If you don't mind copying code, you can take some from `plot/dc' here:
>>
>>     pkgs/plot-pkgs/plot-lib/plot/private/no-gui/plot2d.rkt
>>
>> The main thing you need is access to the `area' object, which has a
>> public `dc->plot' method that translates device context coordinates
>> into plot coordinates. I'm sorry it's not easier. :/
>>
>> It will be someday, I promise! I've lately decided that "2D and 3D
>> games that use Plot to render scenes" will be two of my main test
>> cases. Games are the most interactive uses I can think of, and they
>> need to be fast, so that should cover pretty much everyone's
>> interactivity needs.
>>
>> Neil ⊥
>>
>>
>


Posted on the users mailing list.