Create a button's icon with a part of a big image? - Beleaguered Castle
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Re: Create a button's icon with a part of a big image?
Well, in my specific case, the mouseControl is useless, as it always returns the dragged card.
I used richmond's solution with the mouseLoc and it works.
I used richmond's solution with the mouseLoc and it works.
-
- Livecode Opensource Backer
- Posts: 9359
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Create a button's icon with a part of a big image?
I realised that the targets did NOT "unflush" blue if one moused over them with the 'card' and then moused out of them again, so
here is a modified version that sorts that out:
- -
here is a modified version that sorts that out:
- -
Code: Select all
on mouseDown
grab me
set the coloroverlay["opacity"] of grc "Target 1" to "0"
set the coloroverlay["opacity"] of grc "Target 2" to "0"
end mouseDown
on mouseMove
if the mouseLoc is within the rect of grc "Target 1" then
set the coloroverlay["opacity"] of grc "Target 2" to "0"
set the coloroverlay["color"] of grc "Target 1" to blue
set the coloroverlay["opacity"] of grc "Target 1" to "100"
else
set the coloroverlay["opacity"] of grc "Target 1" to "0"
end if
if the mouseLoc is within the rect of grc "Target 2" then
set the coloroverlay["opacity"] of grc "Target 1" to "0"
set the coloroverlay["color"] of grc "Target 2" to blue
set the coloroverlay["opacity"] of grc "Target 2" to "100"
else
set the coloroverlay["opacity"] of grc "Target 2" to "0"
end if
end mouseMove
on mouseUp
if the mouseLoc is within the rect of grc "Target 1" then
set the coloroverlay["color"] of grc "Target 1" to blue
set the coloroverlay["opacity"] of grc "Target 1" to "100"
set the loc of me to the loc of grc "Target 1"
end if
if the mouseLoc is within the rect of grc "Target 2" then
set the coloroverlay["color"] of grc "Target 2" to blue
set the coloroverlay["opacity"] of grc "Target 2" to "100"
set the loc of me to the loc of grc "Target 2"
end if
end mouseUp
- Attachments
-
- split targets 2.livecode.zip
- Stack.
- (36.36 KiB) Downloaded 65 times
-
- VIP Livecode Opensource Backer
- Posts: 3999
- Joined: Sun Jan 07, 2007 9:12 pm
- Location: Bochum, Germany
Re: Create a button's icon with a part of a big image?
How about:
Kind regards
Bernd
Code: Select all
on mouseDown
grab me
set the coloroverlay["opacity"] of grc "Target 1" to "0"
set the coloroverlay["opacity"] of grc "Target 2" to "0"
end mouseDown
on mouseMove
if the loc of grc "Target 1" is within the rect of me then
set the coloroverlay["opacity"] of grc "Target 2" to "0"
set the coloroverlay["color"] of grc "Target 1" to blue
set the coloroverlay["opacity"] of grc "Target 1" to "100"
else
set the coloroverlay["opacity"] of grc "Target 1" to "0"
end if
if the loc of grc "Target 2" is within the rect of me then
set the coloroverlay["opacity"] of grc "Target 1" to "0"
set the coloroverlay["color"] of grc "Target 2" to blue
set the coloroverlay["opacity"] of grc "Target 2" to "100"
else
set the coloroverlay["opacity"] of grc "Target 2" to "0"
end if
end mouseMove
on mouseUp
if the loc of grc "Target 1" is within the rect of me then
set the coloroverlay["color"] of grc "Target 1" to blue
set the coloroverlay["opacity"] of grc "Target 1" to "100"
set the loc of me to the loc of grc "Target 1"
end if
if the loc of grc "Target 2" is within the rect of me then
set the coloroverlay["color"] of grc "Target 2" to blue
set the coloroverlay["opacity"] of grc "Target 2" to "100"
set the loc of me to the loc of grc "Target 2"
end if
end mouseUp
Bernd
-
- Livecode Opensource Backer
- Posts: 9359
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Create a button's icon with a part of a big image?
As the target's rect is bigger than that of the 'card' I am not sure how that would work.
-
- VIP Livecode Opensource Backer
- Posts: 3999
- Joined: Sun Jan 07, 2007 9:12 pm
- Location: Bochum, Germany
Re: Create a button's icon with a part of a big image?
Richmond,
The advantage of taking the loc of the target as reference is that it does not matter where the user "grabs" the card. Imagine the user grabs the card at the bottom of the card. The mouseLoc would have to go a long way to be within the rect of the target. etc.
The proof is in the pudding.
Try it and complain...
Kind regards
Bernd
The advantage of taking the loc of the target as reference is that it does not matter where the user "grabs" the card. Imagine the user grabs the card at the bottom of the card. The mouseLoc would have to go a long way to be within the rect of the target. etc.
The proof is in the pudding.
Try it and complain...
Kind regards
Bernd
-
- Livecode Opensource Backer
- Posts: 9359
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Create a button's icon with a part of a big image?
Why bother when what I have works?Try it and complain...
-
- VIP Livecode Opensource Backer
- Posts: 7229
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: Create a button's icon with a part of a big image?
Right, I was mis-remembering how my card games work. I took a look at my (very old) scripts and I see I was using mouseloc as well. I didn't use the grab command, I tracked the mouseloc with mousemove and compared that to a list of valid drop rectangles in a script local. Because it's all in memory, it's very fast.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
Re: Create a button's icon with a part of a big image?
Interesting. At this time, I only have a list of valid drop object's name in memory. It seems fast enough on a 2011 MacBook Pro but the app is far to be finished.
-
- VIP Livecode Opensource Backer
- Posts: 7229
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: Create a button's icon with a part of a big image?
I think looking up the object rects as you go would be fine on today's computers. I wrote my first card game more than 15 years ago.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
-
- Livecode Opensource Backer
- Posts: 9359
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Create a button's icon with a part of a big image?
Looking up the object rects on a 2006 iMac running 10.7.5
(LC 8.1.10) seems perfectly acceptable speedwise: especially if one runs a loop with sequentially named targets . . .
Chopping up tomatoes for the vegetable drier right now,
but, possibly later, I'll knock up a wee demo.
(LC 8.1.10) seems perfectly acceptable speedwise: especially if one runs a loop with sequentially named targets . . .
Chopping up tomatoes for the vegetable drier right now,
but, possibly later, I'll knock up a wee demo.
Re: Create a button's icon with a part of a big image?
Right now, trying to deal with the cards dimensions when the board needs to be resized... I suppose I will have to resize all images one by one and the calculation is not simple
-
- Livecode Opensource Backer
- Posts: 9359
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Create a button's icon with a part of a big image?
-
- Attachments
-
- Multiple Targets.livecode.zip
- Stack.
- (64.6 KiB) Downloaded 73 times
-
- Livecode Opensource Backer
- Posts: 9359
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Create a button's icon with a part of a big image?
1. the SIZE.Right now, trying to deal with the cards dimensions when the board needs to be resized...
2. the POSITION.
- -
Please note that each of the vector images has 2 custom properties . . .
-
- Attachments
-
- MIGRAINE.livecode.zip
- Stack.
- (49.39 KiB) Downloaded 78 times
-
- Livecode Opensource Backer
- Posts: 9359
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Create a button's icon with a part of a big image?
Of course you could use the Geometry Manager:
https://lessons.livecode.com/m/4071/l/1 ... k%20resize.
https://livecode.fandom.com/wiki/Geometry_manager
Personally I have found it almost impossible to use, that is why I'd far rather "roll my own."
https://lessons.livecode.com/m/4071/l/1 ... k%20resize.
https://livecode.fandom.com/wiki/Geometry_manager
Personally I have found it almost impossible to use, that is why I'd far rather "roll my own."
Re: Create a button's icon with a part of a big image?
i often use both the GM and the resizeStack handler - typically i pick a key control that would dictate the size to the rest of the other controls resize/reposition all other controls relative to that - and because i'm lazy i usually resize the key control with the GM...
just remember to call revUpdateGeometry at the start of the resizeStack handler to ensure the GM updates at the right time...
just remember to call revUpdateGeometry at the start of the resizeStack handler to ensure the GM updates at the right time...