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

Zax
Posts: 457
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 » Sun Aug 07, 2022 10:16 am

Many thanks richmond and jeff, it's really christmas before christmas :D :D :D

I'll have to look at your respective codes and try to understand this SVG stuff, but I think I will have no more excuses not to finish this project !

richmond62
Livecode Opensource Backer
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?

Post by richmond62 » Sun Aug 07, 2022 11:52 am

Personally I would favour SVG vector files (but, obviously NOT ones like the ones I found with embedded fonty bits) if I wanted to scale things.

As I generally develop for desktop delivery where scaling is a non-event, I have "had a thing" about PNG images after I got fed up with the GIF format.

Zax
Posts: 457
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 » Sun Aug 07, 2022 12:33 pm

richmond, a question about "moving the queen":

Your script uses grab command, which is fine, but I would like a visual effect (maybe with overlay property) when the dragged card intersects a valid rectangle (the green area in your example stack).
So I tried to replace grab command with:

Code: Select all

on mouseStillDown
   --grab me
   set loc of me to the mouseLoc
  focusControl "btn1", intersect(me, btn "btn1", 3)
end mouseStillDown

on mouseUp
   focusControl "btn1", false
end mouseUp

on focusControl controlName, bool
   if (bool) then
      set the colorOverlay["color"] of btn controlName to yellow
      set the colorOverlay["opacity"] of btn controlName to 60
   else
      --set the colorOverlay["color"] of btn controlName to white
      set the colorOverlay["opacity"] of btn controlName to 0
   end if
end focusControl
It works with the mouvement is *very* jerky :(

richmond62
Livecode Opensource Backer
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?

Post by richmond62 » Sun Aug 07, 2022 1:12 pm

Here's a thought:
-
SShot 2022-08-07 at 15.11.16.png
Attachments
Card Target 2.livecode.zip
Stack.
(95.33 KiB) Downloaded 60 times

Zax
Posts: 457
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 » Sun Aug 07, 2022 2:15 pm

Great! :D
I modified your script in order to have what I wanted:

Code: Select all

on mouseDown
   grab me
end mouseDown

on mouseMove
   if intersect(img "QUEEN", grc "cPLACE", 3) then
      set the coloroverlay["color"] of me to white
      set the coloroverlay["opacity"] of me to "100"
   end if
end mouseMove

on mouseUp
   if intersect(img "QUEEN", grc "cPLACE", 3) then
      set the loc of img "QUEEN" to the loc of grc "cPLACE" ----------- FINAL POSITION HERE
   else
      set the coloroverlay["opacity"] of img "QUEEN" to "0"
      move img "QUEEN" to 113, 151
   end if
end mouseUp

jmk_phd
Posts: 213
Joined: Sat Apr 15, 2017 8:29 pm

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

Post by jmk_phd » Mon Aug 08, 2022 3:43 am

stam --

You wrote:
Personally I would favour SVG vector files ... if I wanted to scale things. As I generally develop for desktop delivery where scaling is a non-event, I have "had a thing" about PNG images after I got fed up with the GIF format.
Isn't there an important exception to scaling being a "non-event" for desktop delivery? Namely, accommodating Retina/high-rez screens for desktops/laptops.

About a decade ago I had to convert my vector graphics to 300ppi PNGs because at the time LC didn't do SVG. Not ideal, but "good enough" -- that is, until I ran my app on a Retina Mac. Ugly! So with SVG now available in LC, I redrew all 237 images as SVGs. Tedious and time-consuming, but these look noticeably better on my standard-rez screens and terrific on the Retina screens. (As a bonus, it's reduced the size of my app quite a bit.)

I've seen SVGs characterized as "future-proof," inasmuch as we know that -- sooner or later -- there will be super-high-rez screens. So I look at it as an investment in the future.

jeff k

richmond62
Livecode Opensource Backer
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?

Post by richmond62 » Mon Aug 08, 2022 6:41 am

Of course, Jeff, you are quite right.

And to that end it would behoove LC to improve SVG
import so 'fonty bits' are imported successfully as well as the pictorial components.

GIMP manages that without a hitch . . .

stam
Posts: 2679
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

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

Post by stam » Mon Aug 08, 2022 10:06 am

jmk_phd wrote:
Mon Aug 08, 2022 3:43 am
stam --

You wrote:
Personally I would favour SVG vector files ... if I wanted to scale things. As I generally develop for desktop delivery where scaling is a non-event, I have "had a thing" about PNG images after I got fed up with the GIF format.
Isn't there an important exception to scaling being a "non-event" for desktop delivery? Namely, accommodating Retina/high-rez screens for desktops/laptops.

About a decade ago I had to convert my vector graphics to 300ppi PNGs because at the time LC didn't do SVG. Not ideal, but "good enough" -- that is, until I ran my app on a Retina Mac. Ugly! So with SVG now available in LC, I redrew all 237 images as SVGs. Tedious and time-consuming, but these look noticeably better on my standard-rez screens and terrific on the Retina screens. (As a bonus, it's reduced the size of my app quite a bit.)

I've seen SVGs characterized as "future-proof," inasmuch as we know that -- sooner or later -- there will be super-high-rez screens. So I look at it as an investment in the future.

jeff k
Jeff, I’m pretty sure I said nothing of the sort… are you sure you weren’t responding to Richmond?

If quoting people it may be best to include the reference to the post to avoid any confusion….

Best regards
Stam

richmond62
Livecode Opensource Backer
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?

Post by richmond62 » Mon Aug 08, 2022 10:33 am

Yes, he was replying to me, as it was me he was quoting.

That is why I replied to him. 8)

stam
Posts: 2679
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

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

Post by stam » Mon Aug 08, 2022 12:00 pm

Thanks Richmond.

It struck me as odd as even though I’m writing stuff for desktop, I’m very definitely catering for scaling.

My users are on windows 10 on a variety of machines which not only have vastly different resolutions but also different “magnifications” - yes, very unhelpfully, win10 offers both a resolution and a magnification setting, which even in the same machine may change significantly, as many have work laptops that dock into a 27’ screen and both of these settings change. Some users prefer full-screen while others do not. Some set the resolution extremely low as the like things “big”.

Safe to say this takes a big chunk of time for me and I would definitely not say that scaling on desktop is a non-event! ;)

jmk_phd
Posts: 213
Joined: Sat Apr 15, 2017 8:29 pm

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

Post by jmk_phd » Mon Aug 08, 2022 3:55 pm

My deepest apologies to stam for the misattribution. :oops:

jeff k

stam
Posts: 2679
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

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

Post by stam » Mon Aug 08, 2022 3:58 pm

no worries, just led to a lot of head scratching, but Richmond cleared that up ;)

Zax
Posts: 457
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 1:30 pm

I don't think I will be able to complete this project because I have a big problem with the order of the elements: I forgot that the number of a control cann't be set by script :(

Desired board after the cards have just been dealt (found on the net):
net.jpg

My board after the cards have just been dealt:
lc.jpg

I could find a solution for the distribution of the cards during a new game but the order problem will stay each time a card is manually moved: only the cards at the bottom of each column can be moved, they must be in the foreground (above all others). When a card is moved, it will risk "sliding" below another when it should remain in the foreground (until it is possibly covered by a future move).

Anyway, it allowed me to discover SVG images, and I confirm that it is the right choice for this kind of project which requires a change in image dimensions.
Thanks again for your help.

richmond62
Livecode Opensource Backer
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?

Post by richmond62 » Tue Aug 09, 2022 1:54 pm

the order problem will stay each time a card is manually moved: only the cards at the bottom of each column can be moved, they must be in the foreground (above all others). When a card is moved, it will risk "sliding" below another when it should remain in the foreground (until it is possibly covered by a future move).
That all seems very mysterious.
-
layers.jpg
-
https://www.dropbox.com/s/fozn5ubfufyn4 ... e.zip?dl=0

bn
VIP Livecode Opensource Backer
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?

Post by bn » Tue Aug 09, 2022 3:40 pm

Zax wrote:
Tue Aug 09, 2022 1:30 pm
I don't think I will be able to complete this project because I have a big problem with the order of the elements: I forgot that the number of a control cann't be set by script :(
Have you looked at the layer of an object? You can relayer the objects. It is a bit more difficult if the objects are within groups.
Changing the layer of an objects will also affect its number.

If you set two objects to the same number the other object with the same number will change its number.

Also look at set the layer of object to top/bottom

Similar what Richmond did in very basic form in his stack.

Kind regards
Bernd

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”