Create a button's icon with a part of a big image? - Beleaguered Castle

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

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7237
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?

Post by jacque » Tue Aug 09, 2022 3:46 pm

I forgot that the number of a control cann't be set by script :(
Layer is synonymous with number and you can set it in script. To make it easier, you can also use the reserved word "top" to set the layer of the control to the highest number available. That's what I did in my old Klondike game.

Code: Select all

set the layer of <control> to top
Oops, I see Bernd beat me to it.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Zax
Posts: 469
Joined: Mon May 28, 2007 10:12 am
Location: France
Contact:

Re: Create a button's icon with a part of a big image?

Post by Zax » Tue Aug 09, 2022 3:52 pm

Thanks again all! :D :D :D
Very nice demo stack, richmond.

Keep you informed (... about my next problem :wink: )

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9386
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Create a button's icon with a part of a big image?

Post by richmond62 » Tue Aug 09, 2022 9:37 pm

... about my next problem
If your next problem is as easily sorted out as the recent ones that's OK with me.

Anything more complicated you should look to Klaus or Jacque. 8)

Zax
Posts: 469
Joined: Mon May 28, 2007 10:12 am
Location: France
Contact:

Re: Create a button's icon with a part of a big image?

Post by Zax » Wed Aug 10, 2022 10:57 am

richmond62 wrote:
Tue Aug 09, 2022 9:37 pm
If your next problem is as easily sorted out as the recent ones that's OK with me.
I don't know, you tell me ;)

I'm using:

Code: Select all

intersect(draggedImg, targetImg, "pixels")
to hilite the image target but in some cases, dragged image intersects 2 possible targets.
lc.jpg

In the case shown of the screenshot, one can't know on which target the dragged image will be dropped on mouseOut event but *we hope* the correct target will be the Queen of Diamonds... So my question is: is there a way to restrain the "hot" rectangle of the dragged image?
I think I could do that without intersect function and create my own function, maybe using centerRect() but I'm afraid the card mouvement will be jerky, due to calculation loop.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9386
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Create a button's icon with a part of a big image?

Post by richmond62 » Wed Aug 10, 2022 11:12 am

I have NEVER heard of mouseOut . . . 8)
-
SShot 2022-08-10 at 13.18.22.png
-
Obviously if your drop targets are so near to each other that 2 intersect
signals fire at the same time you are going to be in the treacle.
-
treacle.jpg
treacle.jpg (7.1 KiB) Viewed 6253 times
-
Solution #1:

Make sure your drop targets are a sufficient distance apart that that doesn't happen.

Although, frankly, looking at your last screenshot that is going to look unpleasant.

Solution #2:

Do NOT use intersect, but use mouseLoc instead:

Code: Select all

on mouseDown
   grab me
end mouseDown

on mouseUp
   if the mouseLoc is within the rect of grc "Target 1" then
      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 loc of me to the loc of grc "Target 2"
   end if
end mouseUp
As a footnote to using mouseLoc , it is important that end-users do NOT
drink 3 double vodkas before playing as their aim may be a bit shoogly. :P
Attachments
split targets.livecode.zip
Stack.
(36.2 KiB) Downloaded 53 times

Zax
Posts: 469
Joined: Mon May 28, 2007 10:12 am
Location: France
Contact:

Re: Create a button's icon with a part of a big image?

Post by Zax » Wed Aug 10, 2022 1:13 pm

Great, once again :D
richmond62 wrote:
Wed Aug 10, 2022 11:12 am
As a footnote to using mouseLoc , it is important that end-users do NOT
drink 3 double vodkas before playing as their aim may be a bit shoogly. :P
Well, make it Suntory Time !
images.jpg
images.jpg (4.45 KiB) Viewed 6238 times

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9386
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Create a button's icon with a part of a big image?

Post by richmond62 » Wed Aug 10, 2022 1:15 pm

I really ought NOT to be chewing Purslane from the garden . . . :shock:

What a horrible dream I had last night: I was playing Pope Joan with Auld Clootie:
-
popeJoan.jpg
-
https://en.wikipedia.org/wiki/Pope_Joan_(card_game)
-
clootie.jpg
clootie.jpg (11.16 KiB) Viewed 6238 times
-
AND . . . as the say (quite literally in this case) "the Devil is in the detail" . . .
-
4corners.jpg
-
Of course the "other devil" is being limited to 3 attachments to each posting . . . :D
Last edited by richmond62 on Wed Aug 10, 2022 1:23 pm, edited 1 time in total.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9386
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Create a button's icon with a part of a big image?

Post by richmond62 » Wed Aug 10, 2022 1:16 pm

As a Scot, I am not overly keen on Japanese whisky, and as a poor Scotsman,
I drink . . . Jim Beam. :?

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9386
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Create a button's icon with a part of a big image?

Post by richmond62 » Wed Aug 10, 2022 1:18 pm

So, what with Auld Clootie and myself . . .

. . . Oh, and he was not prepared to offer me a million bucks for my Devawriter Pro he did NOT get my soul . . . 8)
-
Orpheus.jpg
-
https://youtu.be/JUpZ1Npj23M
Attachments
4 corners.livecode.zip
Stack.
(88.63 KiB) Downloaded 50 times

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9386
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Create a button's icon with a part of a big image?

Post by richmond62 » Wed Aug 10, 2022 2:55 pm

MrP.jpg
Original image
MrP.jpg (33.95 KiB) Viewed 6209 times
-
If you are going to rotate images using angle it is important NOT to lock them
as they then will be distorted.
-
SShot 2022-08-10 at 16.53.10.png
Distorted
SShot 2022-08-10 at 16.53.10.png (32.86 KiB) Viewed 6209 times
-
If you are going to rotate images using rotate just DO NOT as you get something that looks like a goat
has been nibbling round the edges.
-
SShot 2022-08-10 at 16.54.45.png
Chewed.
SShot 2022-08-10 at 16.54.45.png (50.27 KiB) Viewed 6209 times

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7237
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?

Post by jacque » Wed Aug 10, 2022 6:02 pm

So my question is: is there a way to restrain the "hot" rectangle of the dragged image?
Instead of intersect, use "the mousecontrol" which returns the control under the mouse pointer. That way only one control will hilite and users will quickly learn how far to drag before they see it light up.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9386
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Create a button's icon with a part of a big image?

Post by richmond62 » Wed Aug 10, 2022 8:16 pm

mouseControl

hey-ho:

If I have a 'card' containing this sort of code"

Code: Select all

on mouseDown
   grab me
end mouseDown

on mouseUp
  put the mouseControl
  on mouseUp


Every time I release the mouse what will be returned is the number of the 'card' and NOT
any target it is intersecting with . . .

So the ONLY way this is going to be of use is if the script can in some way hilight the target.
Last edited by richmond62 on Wed Aug 10, 2022 8:34 pm, edited 2 times in total.

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

Re: Create a button's icon with a part of a big image?

Post by bn » Wed Aug 10, 2022 8:21 pm

richmond62 wrote:
Wed Aug 10, 2022 8:16 pm
Every time I release the mouse what will be returned is the number of the 'card' and NOT
any target it is intersecting with . . .
Try

Code: Select all

on mouseDown
   grab me
end mouseDown

on mouseUp
   put the long name of the mouseControl
end mouseUp
What does it say?

Kind regards
Bernd

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9386
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Create a button's icon with a part of a big image?

Post by richmond62 » Wed Aug 10, 2022 8:33 pm

SShot 2022-08-10 at 22.32.10.png
-

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"
   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"
   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.33 KiB) Downloaded 45 times

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9386
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Create a button's icon with a part of a big image?

Post by richmond62 » Wed Aug 10, 2022 8:38 pm

What does it say?
Nothing of any obvious value as it still returns the name of the top image and NOT the drop target.
-
SShot 2022-08-10 at 22.37.12.png

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”