trash bin like feature

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

demolken
Posts: 3
Joined: Wed Mar 06, 2013 8:10 pm

trash bin like feature

Post by demolken » Wed Mar 06, 2013 8:16 pm

I've been trying to implement a recycle bin like feature. I've been trying to do this by detecting if there are images within a field however, i cant seem to work out the problems.

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

Re: trash bin like feature

Post by Klaus » Wed Mar 06, 2013 9:02 pm

Hi demolken,

I don't have the slightest idea what you are talking about resp. what you are trying to achieve!?


Best

Klaus

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Re: trash bin like feature

Post by mwieder » Wed Mar 06, 2013 11:30 pm

Klaus- not to worry. I think it's just another spam message.

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

Re: trash bin like feature

Post by dunbarx » Thu Mar 07, 2013 2:40 am

This seems like a reasonable request, and a reasonable approach to finding a solution, detecting whether one object is within the rect of another.

Only a single post, but why think it is bogus? If spam, it is very well done in a LC context. We need the algorithms that produced it.

So Demolken, are you for real?

Craig Newman

demolken
Posts: 3
Joined: Wed Mar 06, 2013 8:10 pm

Re: trash bin like feature

Post by demolken » Fri Mar 08, 2013 8:25 pm

yes i'm real. Sorry for the difficult explanation but craig seems to have answered my question. Thank you

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

Re: trash bin like feature

Post by Klaus » Fri Mar 08, 2013 9:20 pm

Hi Demolken,

AHA! :D

OK, welcome to the forum!


Best

Klaus

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Re: trash bin like feature

Post by mwieder » Fri Mar 08, 2013 9:23 pm

Yay! on all counts. :D

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

Re: trash bin like feature

Post by dunbarx » Fri Mar 08, 2013 9:38 pm

Goodie.

And Demolken, since you appear to be well on your way with the "within" function, which pertains to objects, do also look at the "is within" operator, which is similar, but pertains to points.

If you intend to animate your trashcan gizmo, please demonstrate it here.

Craig Newman

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

Re: trash bin like feature

Post by dunbarx » Fri Mar 08, 2013 10:17 pm

I was thinking about this, and thought I was presumptuous

I made two buttons. In the script of the first one (the button to be trashed) I put:

Code: Select all

on mouseMove
   if the mouse is down then  set  the loc of me to  the mouseLoc
end mouseMove

on mouseup
   if the loc of me is within the rect of btn "trashCan" then put random(99)
end mouseup
This uses the "is within" operator as opposed to the "within" function that I assumed earlier. You may be well ahead of this already.

Craig Newman

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

Re: trash bin like feature

Post by Klaus » Sat Mar 09, 2013 11:28 am

Hi friends,

watch out!

Code: Select all

on mouseMove
   if the mouse is down then  set  the loc of me to  the mouseLoc
end mouseMove
"Polling" the mouse in this way is SIN and will lead to eternal damnation:
http://www.hyperactivesw.com/resources_polling.html :D

Best do this instead "on mousemove":

Code: Select all

on mousedown
  grab me
end mousedown
Best

Klaus

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

Re: trash bin like feature

Post by dunbarx » Sat Mar 09, 2013 6:11 pm

Klaus.

Yep, grab is better. More relaxing to the engine.

But polling, when an action is wholly dedicated to a particular task, does not seem to me to be so dastardly. Certainly if any other task at all might be running at the same time, or might be called or invoked during that action, then a "send in time" or somesuch is proper.

Still does not mean that "grab" is not better.

Craig

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

Re: trash bin like feature

Post by jacque » Sat Mar 09, 2013 7:42 pm

dunbarx wrote: But polling, when an action is wholly dedicated to a particular task, does not seem to me to be so dastardly. Certainly if any other task at all might be running at the same time, or might be called or invoked during that action, then a "send in time" or somesuch is proper.
If it only involved LiveCode itself then you're right. The problem is, though, that it stops the whole computer. All background tasks in all open apps, including the OS, are suspended or at least greatly slowed down. Dr Raney's pet peeve with this (he was the original damnation-caster) was that every other app came to a halt while the tight polling loop used almost 100% of the CPU.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

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

Re: trash bin like feature

Post by dunbarx » Sat Mar 09, 2013 9:58 pm

Jacque.

I watched the "Activity Monitor" while this was running:

Code: Select all

on mouseMove
   if the mouse is down then set the loc of me to the mouseLoc
end mouseMove
I could be completely misreading this application, but whereas when nothing was going on in LC, CPU usage was about 17%. During the actual mouseMove action, activity dropped to about 10%, and sometimes lower. In other words, to free up the CPU, run a CPU intensive process.

About the same response using "grab", by the way.

Macbook Air, 1.86 GHz.

Craig

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: trash bin like feature

Post by sturgis » Sat Mar 09, 2013 10:11 pm

Based on the linked page, checking things in the mousemove is the "recommended" method. The linked page rather says the following is bad.

Code: Select all

repeat until the mouse is up
  set the loc of btn "dragBtn" to the mouseLoc
end repeat

This isn't polling, its just a message being handled and should work great.

Code: Select all

on mouseMove
   if the mouse is down then  set  the loc of me to  the mouseLoc
end mouseMove

Newbie4
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 332
Joined: Sun Apr 15, 2012 1:17 am
Contact:

Re: trash bin like feature

Post by Newbie4 » Sun Mar 10, 2013 5:45 pm

Does it matter if you use the "intersect" function, "is within" or the "within" function for testing if the object is in the trashcan?
Cyril Pruszko
https://sites.google.com/a/pgcps.org/livecode/
https://sites.google.com/a/setonhs.org/app-and-game-workshop/home
https://learntolivecode.com/

Post Reply