Coming out of Brush Mode by clicking another button

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
KingCode
Posts: 9
Joined: Wed Feb 05, 2014 5:34 pm

Coming out of Brush Mode by clicking another button

Post by KingCode » Mon Feb 10, 2014 7:55 pm

Another issue I can't solve, I am in brush mode and I have another button that allows you to come out of brush mode and back into browse mode

choose browse tool

However, the button does not seem to work and stays in brush mode. Because this is for a touch device, I can't use a space bar or enter key to come back out.

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

Re: Coming out of Brush Mode by clicking another button

Post by dunbarx » Mon Feb 10, 2014 8:07 pm

Hi again.

Same sort of thing, you have to monitor other LC processes to get out of these things. Put this in the card script:

Code: Select all

on mouseMove
   if the mouseLoc is within the rect of btn "yourButton" and the mouse is down then choose browse tool
end mouseMove
Should work.

Craig Newman

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7312
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Coming out of Brush Mode by clicking another button

Post by jacque » Tue Feb 11, 2014 6:48 pm

Does mouseMove (or touchMove) get sent if the user isn't dragging their finger across the screen? That is, is it sent if the user only taps? I can't remember. If so, then that would be handy in more cases than just this one.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Klaus
Posts: 13977
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Coming out of Brush Mode by clicking another button

Post by Klaus » Wed Feb 12, 2014 1:03 pm

Does mouseMove (or touchMove) get sent if the user isn't dragging their finger across the screen?
No, if the finger is not on the screen, then there is no TOUCH that could be evaluated!
And since there is no MOUSE, "mousemove" will also no get sent!

I Just made a small test (on Mac) with a paint tool/brush:
1. "mousemove" will be sent UNLESS the mouse is DOWN = actually painting!
When mouse is DOWN, there is no mousemove message!
2. "mouseenter", "mouseup" etc. doe NOT work with a paint tool active!
I find this strange to say the least...

All this makes it a bit complicated to control painting on mobile, on the desktop
you can get away with an extra PALETTE window for switching tools.

Any idea how this should work on mobile?

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4102
Joined: Sun Jan 07, 2007 9:12 pm

Re: Coming out of Brush Mode by clicking another button

Post by bn » Wed Feb 12, 2014 1:59 pm

Hi Klaus,
Any idea how this should work on mobile?
Actually it should work as on the desktop:
make a card and an image "myImage" on the card
set the script of the card to

Code: Select all

local sLastLoc

on mouseDown
   put the clickloc into sLastLoc
   if not (sLastLoc is within the rect of image "myImage") then exit mouseDown
   set the pencolor to any item of "red,blue,green,black" 
   set the linesize to 2
   choose  curve tool
   send "doMove" to me in 10 millisec
end mouseDown

on doMove
   if the mouse is up then 
      choose the browse tool
      exit doMove
   else
      lock screen
      put the mouseloc into tLoc
      if sLastLoc is within the rect of image "myImage" And tLoc is within the rect of image "myImage" then
         drag from sLastLoc to tLoc
         put tLoc into sLastLoc
      end if
      unlock screen
      send "doMove" to me in 1 millisec
   end if
end doMove
not tested on mobile

Kind regards
Bernd


Edit: improved code a bit

rmuzzini
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 63
Joined: Mon Oct 08, 2012 11:30 am

Re: Coming out of Brush Mode by clicking another button

Post by rmuzzini » Thu May 22, 2014 1:28 pm

Klaus wrote:
Does mouseMove (or touchMove) get sent if the user isn't dragging their finger across the screen?
No, if the finger is not on the screen, then there is no TOUCH that could be evaluated!
And since there is no MOUSE, "mousemove" will also no get sent!

I Just made a small test (on Mac) with a paint tool/brush:
1. "mousemove" will be sent UNLESS the mouse is DOWN = actually painting!
When mouse is DOWN, there is no mousemove message!
2. "mouseenter", "mouseup" etc. doe NOT work with a paint tool active!
I find this strange to say the least...

All this makes it a bit complicated to control painting on mobile, on the desktop
you can get away with an extra PALETTE window for switching tools.

Any idea how this should work on mobile?
hi, klaus.
i'm developing a multiplatform app (desktop/mobile) in which user has to use brush/bucket/eraser tool over an image.
and i'm now facing exactly the same issue you described.
i was pretty sure to have found a solution, using the mousemove event to get the "mouse" position (over the image to be painted or not), but, after deeper tests i have to admit my solution is buggy on mobile platform, 'cause of the fancy "mousemove" event.
so, i came here to seek for a solution from masters.
did you get yours, in the meanwhile?
:)

rmuzzini
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 63
Joined: Mon Oct 08, 2012 11:30 am

Re: Coming out of Brush Mode by clicking another button

Post by rmuzzini » Thu May 22, 2014 1:54 pm

wait… i didn't read with attention last bernd 's post, which offers a nice solution, it seems.

so, probably, something like this could work with brush/eraser:

Code: Select all

    local sLastLoc

    on mouseDown
       put the clickloc into sLastLoc
       if not (sLastLoc is within the rect of image "myImage") OR (the pTool of me is empty) then exit mouseDown //or whatever else, like "dragPictureOverTheScreen", for example
       choose (the pTool of me)
       send "doMove" to me in 10 millisec
    end mouseDown

    on doMove
       if the mouse is up then
          choose the browse tool        
          exit doMove
       else
          lock screen
          put the mouseloc into tLoc
          if sLastLoc is within the rect of image "myImage" And tLoc is within the rect of image "myImage" then
             drag from sLastLoc to tLoc
             put tLoc into sLastLoc
          end if
          unlock screen
          send "doMove" to me in 1 millisec
       end if
    end doMove

//button doBrush script
on mouseUp
	if the hilite of me then
		set the pTool of this cd to empty
	else
		set the pTool of this cd to "brush tool"
	end if
	set the hilite of me to not(the hilite of me)
end mouseUp

but for bucket? i'll do some more tests.

rmuzzini
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 63
Joined: Mon Oct 08, 2012 11:30 am

Re: Coming out of Brush Mode by clicking another button

Post by rmuzzini » Fri May 23, 2014 11:48 am

bernd, you're a genius.

following your tips, it works like a charm now. both on desktop and mobile.

for anyone interested i paste here an example of the working code.

Code: Select all

//card script
local sLastLoc
on mouseDown
   put the clickloc into sLastLoc
   if not (sLastLoc is within the rect of image "picture") OR (the pTool of me is empty) then exit mouseDown //or whatever else, like "dragPictureAroundTheScreen", for example
   choose (the pTool of me)
   send "doMove" to me in 10 millisec
end mouseDown

on doMove
   if the mouse is up then
      choose the browse tool
      exit doMove
   else
      lock screen
      put the mouseloc into tLoc
      if sLastLoc is within the rect of image "picture" AND tLoc is within the rect of image "picture" then
         drag from sLastLoc to tLoc
         put tLoc into sLastLoc
      end if
      unlock screen
      send "doMove" to me in 1 millisec
   end if
end doMove

command resetHilite
   unhilite btn "brush"
   unhilite btn "eraser"
   unhilite btn "bucket"
   unhilite btn "marker"
   if there is a group "brush_marker" then
      lock screen
      ungroup group "brush_marker"
      set  the selected of img "brush_img" to false
      set  the selected of img "marker_img" to false
      unlock screen
   end if
end resetHilite
/******************************/
//button doBrushTool script
on mouseDown
   put the hilite of me into tActive
   resetHilite
   if tActive then
      set the pTool of this cd to empty
   else
      set the brush to 2
      set the brushColor to (random(255),random(255),random(255))
      relayer img "marker_img" after img "picture" //marker_img is an empty img with blend = 50. brush "marker" paints here
      relayer img "brush_img" after img "marker_img" //brush_img is an empty img. brush paints here
      set the pTool of this cd to "brush tool"
   end if
   set the hilite of me to not(tActive)
end mouseDown
/******************************/
//button doMarkerTool script
on mouseDown
   put the hilite of me into tActive
   resetHilite
   if tActive then
      set the pTool of this cd to empty
   else
      set the brush to 2
      set the brushColor to (random(255),random(255),random(255))
      relayer img "brush_img" after img "picture" //brush_img is an empty img. brush paints here
      relayer img "marker_img" after img "brush_img" //marker_img is an empty img with blend = 50. brush "marker" paints here
      set the pTool of this cd to "brush tool"
   end if
   set the hilite of me to not(tActive)
end mouseDown
/******************************/
//button doBucketTool script
on mouseDown
   put the hilite of me into tActive
   resetHilite
   if tActive then
      set the pTool of this cd to empty
   else
      set the brushColor to (random(255),random(255),random(255))
      group img "brush_img" and img "marker_img"
      set the name of last group to "brush_marker" //so that bucket paints directly on picture
      relayer grp "brush_marker" after img "picture" 
      set the pTool of this cd to "bucket tool"
   end if
   set the hilite of me to not(tActive)
end mouseDown
/******************************/
//button doEraserTool script
on mouseDown
   put the hilite of me into tActive
   resetHilite
   if tActive then
      set the pTool of this cd to empty
   else
      set the eraser to 2
      set the pTool of this cd to "eraser tool" //in this example it erases the front-most layer, i.e. the layer of the last tool used between brush and marker
   end if
   set the hilite of me to not(tActive)
end mouseDown

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4102
Joined: Sun Jan 07, 2007 9:12 pm

Re: Coming out of Brush Mode by clicking another button

Post by bn » Fri May 23, 2014 11:59 am

Hi,

glad you got it working.
bernd, you're a genius
I wouldn't go that far.... :) just ask people who know me a little better, or better yet don't ask them :wink:

Kind regards
Bernd

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”