Drawing with spray can

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

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
marcelloe
Posts: 140
Joined: Thu Oct 17, 2013 2:26 pm

Drawing with spray can

Post by marcelloe » Tue Oct 29, 2013 3:09 pm

I am very new to LC and programming in general. I want to create a drawing program for my son. I want to use the spray can tool to paint with. I am not sure where to start. Any help would be much appreciated.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10058
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Drawing with spray can

Post by FourthWorld » Tue Oct 29, 2013 3:18 pm

See the "choose" command and the "tool" global property in the Dictionary.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

marcelloe
Posts: 140
Joined: Thu Oct 17, 2013 2:26 pm

Re: Drawing with spray can

Post by marcelloe » Tue Oct 29, 2013 3:24 pm

I want to put the tools in the same stack as the drawing area.

Also, I have looked in the dictionary at choose and tools global, but when I set it up I get a blank image. If i don't select a tool I can draw just fine. Also, i have noticed that once I select a tool the run mode goes back to edit mode. I am at a loss.

Thanks in advance

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10058
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Drawing with spray can

Post by FourthWorld » Tue Oct 29, 2013 3:41 pm

Currently tool modes in LC are global, and will affect the content region of all toplevel windows. There's a request open for allowing tool modes to be limited to groups, which would do what you want - feel free to add your comments there so the team can better evaluate the level of interest in this in the community:

http://quality.runrev.com/show_bug.cgi?id=623
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

marcelloe
Posts: 140
Joined: Thu Oct 17, 2013 2:26 pm

Re: Drawing with spray can

Post by marcelloe » Tue Oct 29, 2013 3:50 pm

Would I put the global handler in the mouseUp? I saw other projects that use buttons to use the pencil tool and eraser. I can't figure out how they scripted the buttons. Here is the stack I am reffering too.
Attachments
drawBook.zip
(3.13 KiB) Downloaded 341 times

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10354
Joined: Wed May 06, 2009 2:28 pm

Re: Drawing with spray can

Post by dunbarx » Tue Oct 29, 2013 4:58 pm

Hi.

You must learn to walk before you can run. Your project, though, is perfect for learning. As a start, make a new stack and a button. As Richard points out, put this into the button script:

Code: Select all

on mouseUp
   choose spray can tool
end mouseUp
You will have to select a fill color, and other painting attributes. Can you do this? Can you make your own tools (as buttons) and place then on top of your stack, so you don't need the tools palette? These tools can be, for a start, a way to select those attributes you will need to paint.

Write back with your progress and complaints.

Craig Newman

marcelloe
Posts: 140
Joined: Thu Oct 17, 2013 2:26 pm

Re: Drawing with spray can

Post by marcelloe » Tue Oct 29, 2013 5:12 pm

I have created paint color buttons and a button to select different sizes. They work great. I have put the selected code into the mouseUp handler. When I try to select the tool in run mode it doesn't work and I can't go back to the default brush tool. All the buttons for the tools are on the main stack.

What I don't understand is creating tool buttons on a separate stack and being able to select the tool from the main stack. I theory I understand how it is suppose to work, but I am missing a piece somewhere.

Thanks for your help

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10354
Joined: Wed May 06, 2009 2:28 pm

Re: Drawing with spray can

Post by dunbarx » Tue Oct 29, 2013 11:44 pm

Hmmm.

If you create a separate stack with a button that chooses the spray paint tool, then that tool will persist when you click on another stack. It will persist, in fact, until another tool is explicitly chosen.

Can you give us a step by step procedure where your method is failing?

Craig

marcelloe
Posts: 140
Joined: Thu Oct 17, 2013 2:26 pm

Re: Drawing with spray can

Post by marcelloe » Wed Oct 30, 2013 1:35 pm

I can't picture how the second stack with the buttons will work with the main stack. I would really like to have the buttons on the main stack for easy use.

I can script the code for the buttons, but I am getting hung up on the code for the drawing area. I think that is the main issue right now. I am missing how to put the select tool to draw in the drawing area.

Thanks

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10058
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Drawing with spray can

Post by FourthWorld » Wed Oct 30, 2013 3:01 pm

marcelloe wrote:I can't picture how the second stack with the buttons will work with the main stack. I would really like to have the buttons on the main stack for easy use.
I think the key here is Craig's suggestion, "You must learn to walk before you can run."

Right now LC makes it relatively easy to use tool modes if you have all stacks that won't be affected by the tools in a mode other than toplevel (such as palette or modeless). LC's IDE provides a good example of this, as do many drawing/painting programs that use tool palettes.

As I noted above, the challenge with the design you're looking for is that tool mode in LC are currently global in scope - they will affect the entire content region of all toplevel stacks.

It's possible to work around this, but it will require a bit of work and some experimentation. So to first get you familiar with the basics of working with tool modes, try Craig's suggestion of implementing that as a palette just to get you started.

Once that's working well and you feel confident with what you've learned, the next steps would be:

1. Make an empty image object as the recipient for the paint. This will prevent LC from creating a new image, as it would normally do when using the paint tools, but automatically-crreated images will be the full size of the card, overlapping your other controls, which is not what you want.

2. You may want to put that image object within a group so it can scroll if the stack is resized smaller than the full size of the image. This would require adding a resizeStack handler to the card or stack script to handle the resizing of the group.

3. Track the mouse and change the tool to the browse tool whenever it leaves the image.

4. The controls which set the tool mode ("brush", "line" etc) will need to store their mode somewhere so it can be restored when the mouse returns to the image - a custom property of the image, card, or stack would do.

5. When the mouse returns to the image area you'll want to set the tool back to the choden painting tool.

6. It may also be a good idea to set the cantSelect property of all controls outside of the image to true, to minimze inappropriate interactions with them. Note that this will prevent you from selecting them with the pointer tool in the IDE, however, so you'll want to do that late in the process if at all.

As you can see, there's a bit to it, but it's doable. I would strongly support Craig's suggestion of first putting the controls in a palette to make sure you're confident with the basics, and only then dive into these further enhancements to pursue the design you're looking for.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Post Reply