Here is a good start for you Tk Patio/Office layout designer. You will find that collision detection or "snap to grid" will be difficult.

Here is a start for collision detection, but it may be a dead end.

#!/usr/bin/perl use warnings; use strict; use Tk; my $dx; my $dy; my $mw = MainWindow->new; $mw->geometry("700x600"); my $canvas = $mw->Canvas(-width => 700, -height => 565, -bg => 'black', -borderwidth => 3, -relief => 'sunken', )->pack; my $closebutton = $mw->Button(-text => 'Exit', -command => sub{Tk::exi +t(0)}) ->pack; my $dr = $canvas->createPolygon(0, 20, 50, 20, 50, 75, 0,75, -fill => 'red', -tags => ['move','red','paver'], ); my $db = $canvas->createPolygon(70, 20, 150,20, 150, 75, 70 , 75, -fill => 'blue', -tags => ['move','blue','paver'], ); my $dg = $canvas->createPolygon(200, 20, 250,20, 250, 75, -fill => 'green', -tags => ['move','green','paver'], ); my $dp = $canvas->createPolygon(300, 20, 350,20, 350, 75, -fill => 'purple', -tags => ['move','purple','paver'], ); $canvas->bind('move', '<1>', sub {&mobileStart();}); $canvas->bind('move', '<B1-Motion>', sub {&mobileMove();}); $canvas->bind('move', '<ButtonRelease-1>', sub {&mobileStop();}); MainLoop; sub mobileStart { my $ev = $canvas->XEvent; ($dx, $dy) = (0 - $ev->x, 0 - $ev->y); $canvas->raise('current'); # print "START MOVE-> $dx $dy\n"; } sub mobileMove { my $ev = $canvas->XEvent; # $canvas->bind('current', '<Leave>', sub {&mobileStop();}); + my @coords_in = $canvas->coords('current'); # print "@coords_in\n"; $canvas->move('current', $ev->x + $dx, $ev->y +$dy); ($dx, $dy) = (0 - $ev->x, 0 - $ev->y); # print "MOVING-> $dx $dy\n"; my @coords = $canvas->coords('current'); #print "@coords\n"; my (@olaps) = $canvas->find('overlapping', $coords[0],$coords[1] +,$coords[4],$coords[5], ); foreach my $id(@olaps){ print $canvas->gettags($id),"\t"; } print "@olaps\n"; print "\n"; if(scalar @olaps > 1){ # Redraw the rect $canvas->coords('current', @coords_in); } } sub mobileStop{ &mobileMove; }

I'm not really a human, but I play one on earth CandyGram for Mongo

In reply to Re: Slecting and placing 'groups' on a TK canvas by zentara
in thread Slecting and placing 'groups' on a TK canvas by merrymonk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.