Drawing help

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
Matt9537
Posts: 8
Joined: Tue Oct 02, 2007 4:41 pm

Drawing help

Post by Matt9537 » Thu Oct 09, 2008 12:56 pm

After reading a previous post I have learnt how the user can draw shapes in a picture field using the following code:

Code: Select all

on mouseUp
choose pencil tool 
set the pencolor to "black" 
end mouseUp
I have assigned the code to a button. However, once the button is clicked the cursor will always be a pencil tool and you cannot select another button on the stack.

I have also tried using the 'Mouseenter' and 'Mouseexit' on the image to change the tools from the pencil tool to a cursor...but no success.

So, how would I be able to get the user to draw an image and be able to use buttons (say to change the pen colour or something?)

Klaus
Posts: 13824
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Post by Klaus » Thu Oct 09, 2008 1:12 pm

Hi Matt,

the only soluton is to create a palette window with your "tools", just like in the Rev IDE.

Once you have set another "tool", no "mouse" events are being sent, that's why you got stuck with the pencil tool.


Best

Klaus

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3999
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Post by bn » Thu Oct 09, 2008 1:40 pm

Hi Matt,

depending on what you want you probably have a image object to which you paint. You could set the script of the image object to

Code: Select all

on mouseLeave
    choose browse tool
end mouseLeave
That way you choose the pencil tool (or whatever) with your button, paint in the image, as soon as you move out of the image the cursor reverts to the browse tool.

This may or may not be what you want, give it a try.

cheers

bernd

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3999
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Post by bn » Thu Oct 09, 2008 1:48 pm

Hi Matt,

as an aside: a button with

Code: Select all

on mouseUp 
    set the text of image "myImage" to ""
end mouseUp
erases the image. It took me a while to pick that up, so it might be handy
regards
bernd

Klaus
Posts: 13824
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Post by Klaus » Thu Oct 09, 2008 1:50 pm

Or simply (a little less semantically challenging) ;-)
...
put empty into img "your_image"
...

Matt9537
Posts: 8
Joined: Tue Oct 02, 2007 4:41 pm

Post by Matt9537 » Thu Oct 09, 2008 2:50 pm

Klaus wrote:Or simply (a little less semantically challenging) ;-)
...
put empty into img "your_image"
...
Thanks BN for the prompt help and thanks Klaus! Havent had a chance to try it yet - maybe tomorrow.

I was actually going to ask how you would delete an image....so thanks for that!

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3999
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Post by bn » Thu Oct 09, 2008 7:24 pm

Hi Klaus,
Or simply (a little less semantically challenging)
...
put empty into img "your_image"
...
how easy, thank you,
somehow the "semantic challenges" seem to attract me :) isn't the "semantic challenge" what makes a 'real' programming language? :wink:
cheers
bernd

Matt9537
Posts: 8
Joined: Tue Oct 02, 2007 4:41 pm

Post by Matt9537 » Fri Oct 10, 2008 9:45 am

Hi Bn and Klaus (again)

The script works perfectly! However, after a good hour of trying, reading manuals and searching the forum...can anyone tell me how I could export the image drawn in the image area as a picture file? Such as a .jpg or a .bmp or something?

(on a mac BTW)

Klaus
Posts: 13824
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Post by Klaus » Fri Oct 10, 2008 9:58 am

Hi Matt,

you can export images and screenshots in PNG, GIF or JPG format.

Please check these terms in the docs:
export
export snapshot
jpegquality

As always, it's pretty easy :-)

Code: Select all

...
export img "my wonderful image" to file "path/to/file.jpg" as JPEG
...
Best

Klaus

Dondi
Posts: 18
Joined: Fri Apr 10, 2009 2:40 am

Post by Dondi » Sun Jun 07, 2009 4:11 pm

Klaus wrote:Hi Matt,

the only soluton is to create a palette window with your "tools", just like in the Rev IDE. ...

Klaus
Hi Klaus, can you elaborate on implementation of the palette? I tried implementing this approach by placing the "canvas" on a card in the mainstack and the palette on a card on a substack.

However, the create graphics command places the selected tool on the palette card and I can't figure out how to specify that the graphic should be created on the "canvas" on the mainstack. Any ideas on how to remedy this?

Klaus
Posts: 13824
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Post by Klaus » Mon Jun 08, 2009 5:43 pm

Hi Dondi,

I was referring to PAINT tools which will only work sufficiently in a palette!

You can "set the defaultstack" first before creating graphics:
...
set the defaultstack to "stack where the graphic should appear"
create graphic "new_graphic1"
...

Is that what you wanted to know?


Best

Klaus

Dondi
Posts: 18
Joined: Fri Apr 10, 2009 2:40 am

Post by Dondi » Fri Jun 12, 2009 11:15 pm

Thanks Klaus. I am using vector objects on an image object used as a canvas. I will try your defaultstack suggestion and see where it leads.

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”