Tools & Drawing inside image

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Ron Zellner
Posts: 106
Joined: Wed May 31, 2006 9:56 pm
Contact:

Tools & Drawing inside image

Post by Ron Zellner » Wed May 27, 2009 11:47 pm

Is there an example out there for this? I want to provide buttons for selecting the pencil, brush, or eraser tool. Then the user selects and draws inside the rectangle of an image. But I want the tool to switch to browse when the cursor exits the image so other options can be accessed, and back to the selected tool on re-entering the image. I have some examples working but would like to see if there are other approaches to this.

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Tools & Drawing inside image

Post by jmburnod » Thu May 28, 2009 8:39 am

Hi Ron,

I think the best way is a toolPaint substack you open as palette

All the best

Jean-Marc

grc
Posts: 13
Joined: Thu Apr 23, 2009 9:21 am

Post by grc » Thu May 28, 2009 9:51 am

Hi

I think this is what you mean.

In the image script write:

Code: Select all

on mouseLeave # mouseLeave is sent when the mouse leaves the area where the image is
   choose browse tool
end mouseLeave
In the buttons' script write:

Code: Select all

on mouseUp
choose paint tool # or whatever tool you want
end mouseUp
grc

Janschenkel
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 977
Joined: Sat Apr 08, 2006 7:47 am
Contact:

Post by Janschenkel » Thu May 28, 2009 7:57 pm

Make a separate stack, and add a series of buttons to it to switch the current tool, and then the user can draw in the actual drawing stack.
To switch to the rectangular selection tool, use the script

Code: Select all

on mouseUp
  choose select tool
end mouseUp
To switch to he spray can, use the script

Code: Select all

on mouseUp
  choose spray can tool
end mouseUp
See the choose command and tool global property entries in the Revolution dictionary for a full list.

HTH,

Jan Schenkel.
Quartam Reports & PDF Library for LiveCode
www.quartam.com

Ron Zellner
Posts: 106
Joined: Wed May 31, 2006 9:56 pm
Contact:

Browse/Pointer

Post by Ron Zellner » Thu May 28, 2009 9:00 pm

Those basic commands make sense, but I have a problem when I am developing and I pass over the image it puts me into browse rather than pointer mode. Also, selecting & unselecting the image triggers the script. The commands on mouseLeave and on mouseEnter also seem to be dependent on whether there is content drawn at the point where the mouse is located, e.g. MouseEnter and mouseLeave messages are sent as I go over parts in the drawing with the browse tool.
I also want to automatically go back to the previously selected tool when the users return to the drawing image, so they do not need to reselect the tool. So this almost works:

Code: Select all

on mouseLeave # mouseLeave is sent when the mouse leaves the area where the image is
   global CurrentToolUse
   put word one of the tool into CurrentToolUse
   choose browse tool 
end mouseLeave

on mouseEnter
  global CurrentToolUse
 choose CurrentToolUse Tool
end mouseEnter
But the brush tool doesn't return until the cursor passes over a part of the actual drawing, not when it enters the image bounds.
I can then change the selection tool command to:

Code: Select all

 global CurrentToolUse
   put "pencil" into CurrentToolUse
But, it still doesn't change until it crosses a piece of the drawing content. It seems like once you draw inside an image, only the actual drawing part can be used to select the image. Is there a way around that?
-----------------
I just tried filling the image with a very light gray ( "#FEFEFE") and then using a brush of that color as an eraser tool. That seems to work fine. The tools change as soon as they enter the image. It still looks OK.
---------------------
I had been using this sort of command for selection buttons:

Code: Select all

on mouseUp
     set the uCurrentDrawingTool of group 1 to "pencil"
 end mouseUp
And this in the Group: (there are reasons it is more complicated, for example, I need to track and record the time in each tool)

Code: Select all

global gNextCheckMouseWithinMsgID

on checkMouseWithin
   if (the mouseLoc is within the rect of me and the uCurrentDrawingTool of me is not "") then  
      choose (the uCurrentDrawingTool of me) tool
   else
      choose browse tool
   end if
      
   send "checkMouseWithin" to me in 100 millisecs
   put the result into gNextCheckMouseWithinMsgID
end checkMouseWithin
I also have a script that makes a png file of the user's drawing image every 5 seconds and I get an occasional crash that I think relates to its working on such things in the background. Also, seems to happen when the user is making a rapid drawing stroke and continues moving beyond the drawing image rectangle edges.

I was just wondering if there were a different technique that I might consider.

Post Reply