Using Brush Tool

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
gsillevis
Posts: 40
Joined: Tue Oct 13, 2020 10:55 pm

Using Brush Tool

Post by gsillevis » Sat Nov 14, 2020 12:22 pm

Hello!

I'm trying to add a brush tool to my stack. I can't figure out how to control what image it draws on. I want it to draw on image 'paper.png' but it keeps drawing on an image behind it. Does anyone know how to fix this?

Thank you!

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

Re: Using Brush Tool

Post by jmburnod » Sat Nov 14, 2020 1:12 pm

Hi gsillevis ,
Is your image 'paper.png' referenced from an external file "'paper.png'" ?
Best regards
Jean-Marc
https://alternatic.ch

gsillevis
Posts: 40
Joined: Tue Oct 13, 2020 10:55 pm

Re: Using Brush Tool

Post by gsillevis » Sat Nov 14, 2020 1:15 pm

Yes, it is an imported control

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

Re: Using Brush Tool

Post by jmburnod » Sat Nov 14, 2020 2:24 pm

Yes, it is an imported control
Yes but i think that is a referenced control (your image have a filename9
To draw on image you have to import your image not referenced (import as control)
MenuImportControl.png
MenuImportControl.png (27.55 KiB) Viewed 5113 times
https://alternatic.ch

gsillevis
Posts: 40
Joined: Tue Oct 13, 2020 10:55 pm

Re: Using Brush Tool

Post by gsillevis » Sat Nov 14, 2020 2:26 pm

It is not a referenced control, it is imported.

It is inside a group, though. When I moved it out of the group, it suddenly works better.

gsillevis
Posts: 40
Joined: Tue Oct 13, 2020 10:55 pm

Re: Using Brush Tool

Post by gsillevis » Sat Nov 14, 2020 2:45 pm

I'm making a game and I want players to be able to turn on a drawing layer (by clicking the Pencil On button at top right)

While I am able to get the new layers to appear (by turning on visible of a group called " Paper") the brush tool prefers to draw on the layers below it
Attachments
Untitled-1.jpg

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

Re: Using Brush Tool

Post by jmburnod » Sat Nov 14, 2020 4:17 pm

Just an idea...
Is it possible in your context to export snapshot to a variable from rect of image paper.png and set the text of image paper.png to content of variable ?
Be careful, if your image paper.png has been resized, the rect of image paper.png keep rect of snapshot.
https://alternatic.ch

gsillevis
Posts: 40
Joined: Tue Oct 13, 2020 10:55 pm

Re: Using Brush Tool

Post by gsillevis » Sat Nov 14, 2020 4:20 pm

I ended up using this code:

Code: Select all

on mouseup
   
   
   if there is no image "Paper.png" then
      copy image "CleanPaper.png" of card "Menu Page" to this card
      set the name of image "CleanPaper.png" to "Paper.png"
      set layer of image "Paper.png" to top
      
   end if
   set blendlevel of image "Paper.png" to 50
   set visible of image "Paper.png" to true
   
   
   set visible of button "Clear image" to true
   set visible of button "Close pencil" to true
   
   set layer of group GUI to top
   
   
   
   
   
   
end mouseup

And it works great.

Unfortunately I only realised too late that the Brush tool doesn't work in HTML5 (which is what I'm building this for)...

But at least I learned some new things along the way!

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

Re: Using Brush Tool

Post by jmburnod » Sat Nov 14, 2020 4:42 pm

I tested what i described above and it works.
Know the name of target image will be next step (mouseenter is not sent when brush tool s selected.
Fortunately, mousemove is sent and we can get the mouseloc on mousemove. Then a simple loop can return the name of target image if the mouseloc is within the rect of an image.

Code: Select all

on doSetTextImg pImg -- pImg = image name
   put the rect of img pImg into tRect
   export snapshot from rect tRect of this cd to tDataImg as PNG
   set the text of img seymaz to tDataImg
   delete last img -- image created when you paint
end doSetTextImg
Jean-Marc
https://alternatic.ch

Post Reply