Prompting A User For a Canvas Click

Ryan Burnside pixeloutlaw at gmail.com
Fri Dec 11 16:36:04 UTC 2020


Thanks for your assistance cage - this should give me something to 
tinker with!


On 12/10/2020 4:08 AM, cage wrote:
> On Wed, Dec 09, 2020 at 03:38:03PM -0700, Ryan Burnside wrote:
>> Hello cage,
> Hi!
>
>> Thanks for the reply.
> You're welcome!  I am always  happy to discuss programming  with other
> lispers! :)
>
>> Your code did demonstrate the general idea if I was collecting from a field.
>> But as this is a CAD program (think drafting) it's important that the user
>> be able to pick points of interest from a main canvas.
>> As important that the canvas cursor can "snap" to points of interest such as
>> endpoints intersections etc. (I'll handle that myself).
> I wrote  a (unfortunately  never released)  software -many  years ago-
> that vaguely remember me what you  want to accomplish.  I had a canvas
> and a set of buttons next to  the former. Each button allowed the user
> to draw a  shape (nothing too complicated: box, circle  a bezier arrow
> and a  few more). If an  user would wants  to draw a bezier  they just
> have to press  the corresponding button (to enter in  "bezier mode" so
> to  say) and  press four  times the  mouse button  on the  canvas; the
> program collected the points calculated the  bezier and drawn a set of
> segments and an arrow head on the last ends.
>
> I am not sure that this workflow  fits into your program but all i did
> was forget about  a main loop and  just let the user  events drive the
> process. I waited for <1> (i  mean, mouse click) event (event bound to
> the  canvas) checked  the drawing  mode (box,  bezier etc.)   and acts
> following the mode (collect two point [one more events] for a box -the
> diagonal- or for a segment and so on). Once got all the data needed to
> draw the program updated the canvas with actual drawing.
>
> I  even draw  a little  placeholder for  each collected  point in  the
> canvas for each of this events.
>
> There was also  interactions that allowed to move control  points of a
> shape (in this case i waited for <Button1-Motion> event).
>
> You can even  tag canvas items (the shapes) and  bind different custom
> events to each one, see:
>
> https://www.autistici.org/interzona/lisp.html#orge51c1f0
>
> If  this is  -with  good approximation-  what  you want  to  do i  can
> guarantee is doable with ltk. :)
>
>> Here is a diagram if it helps...
>> https://i.imgur.com/5uxY7Tq.png
> Looking  to the  diagram  i started  to  think that  if  you call  the
> procedure 'draw-foo' inside  the function bound to a  canvas event you
> get more or less  what i described above, but i  could easily be wrong,
> as usual! :)
>
> Inside the event function you can  even run another toplevel (modal if
> needed and hijack completely the input system)  as i did in the code i
> wrote before.
>
>> Hopefully this is possible!
> I also hope it was! :)
>
> Bye!!!
> C.
>




More information about the ltk-user mailing list