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

Post Reply
Zax
Posts: 519
Joined: Mon May 28, 2007 10:12 am
Contact:

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

Post by Zax » Thu Aug 18, 2022 7:15 am

Is there a way to import as control by script?
If I use the menu File -> Image as Control -> Image File, .svg file are imported without any problem. But I'm unable to import the same .svg file with the import command :(

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10090
Joined: Fri Feb 19, 2010 10:17 am

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

Post by richmond62 » Thu Aug 18, 2022 8:14 am

Mmmm . . .
-
SShot 2022-08-18 at 10.12.04.png
-
C'est un crôt . . . :?

Code: Select all

on mouseUp
   answer file "Select image:"
   if the result is not cancel then
      set the lockscreen to true
      import paint from file it
      set the name of the last control to "XYZ"
      wait 5 ticks
      set the lockscreen to false
   end if
end mouseUp
Ce code fonctionne avec les images PNG! Et des JPGs, GIFs et (possiblement) BMPs.

Le problème réside dans le mot 'paint'. Les images SVGs n'ont pas 'paint', ils ont des lignes.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10090
Joined: Fri Feb 19, 2010 10:17 am

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

Post by richmond62 » Thu Aug 18, 2022 8:39 am

SShot 2022-08-18 at 10.37.09.png
-

Code: Select all

on mouseup
   answer file "select an SVG image"
   put it into XYZ
   create image
   put it into ABC
   set the text of ABC to drawingSvgCompileFile(XYZ)
end mouseup
This is SLOW, so wait. 8)
Attachments
Import SVG.livecode.zip
Stack.
(858 Bytes) Downloaded 133 times

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10090
Joined: Fri Feb 19, 2010 10:17 am

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

Post by richmond62 » Thu Aug 18, 2022 8:44 am

SShot 2022-08-18 at 10.39.52.png
-
And how the !@#$%^&*( did Richmond know what to look for in the Dictionary?

Café ! Tu peux dormir quand tu es mort ! :D

OBVIOUSLY this will NOT import SVG images that contain font components successfully.

stam
Posts: 3064
Joined: Sun Jun 04, 2006 9:39 pm

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

Post by stam » Thu Aug 18, 2022 10:18 am

That is a very interesting command Richmond, thank you for highlighting it...

This could be very useful for my own purposes, but I'm slightly concerned about the disclaimer at the end of the API:
Note: The drawing binary format is not currently considered stable and is subject to change until the end of the RC cycle for 9. At present it is advised that SVG files be compiled as needed when developing in the IDE, and then compiled ahead-of-time when building a standalone.
And of course, i'd have to remember to include XML for the standalone ;)

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10090
Joined: Fri Feb 19, 2010 10:17 am

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

Post by richmond62 » Thu Aug 18, 2022 10:26 am

What Zak has not told us is whether he wants to use this in a standalone, or simply
for his own uses in the IDE.

Oh, and THIS is from LC 10 DP-4, so I would not hold my breath:
-
SShot 2022-08-18 at 12.24.44.png
-
Oh, and as my licence [very kindly supplied by LiveCode for educational purposes] is going 'poof' in 2 weeks time,
I. at least, am "learning to live with" Livecode 9.6.3. Community, at least until someone somewhere manages to
produce a 'continuation' Open Source version, or LiveCode themselves offer a 'RevMedia reborn' version.

My stack works with LC 10-dp 4:
-
SShot 2022-08-18 at 12.32.53.png

Zax
Posts: 519
Joined: Mon May 28, 2007 10:12 am
Contact:

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

Post by Zax » Thu Aug 18, 2022 10:36 am

Merci beaucoup richmond :) Une fois de plus, vous êtes d'une aide précieuse !

It works great. I looked at the Dictionnary before posting but didn't find this command.
I made a loop based on your script to import all .svg files in a folder an dit works great :)

I'm using LC 9.6.8 with a License (don't remember which one, it's a kind of "middle" licence: not the biggest but one I paid).
I'm planning to build a standalone.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10090
Joined: Fri Feb 19, 2010 10:17 am

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

Post by richmond62 » Thu Aug 18, 2022 10:40 am

1. Open the Dictionary.

2. Search for 'SVG':
-
SShot 2022-08-18 at 12.39.20.png
-
Ce n'est pas difficile. 8)

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10090
Joined: Fri Feb 19, 2010 10:17 am

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

Post by richmond62 » Thu Aug 18, 2022 10:42 am

I made a loop based on your script to import all .svg files in a folder an dit works great
?:
-
SShot 2022-08-18 at 12.41.59.png

Zax
Posts: 519
Joined: Mon May 28, 2007 10:12 am
Contact:

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

Post by Zax » Thu Aug 18, 2022 10:49 am

richmond62 wrote:
Thu Aug 18, 2022 10:40 am
1. Open the Dictionary.
2. Search for 'SVG':
I searched "image" :(

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10090
Joined: Fri Feb 19, 2010 10:17 am

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

Post by richmond62 » Thu Aug 18, 2022 10:58 am

I searched "image"
I, first of all, looked at the image stuff, and then realised that an SVG file does not contain 'paint'.

That is why, earlier on, I tried a standard import image script and ended up looking un peu fou. :?

SVGs are Vector Images, and as a result, are treated differently.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10090
Joined: Fri Feb 19, 2010 10:17 am

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

Post by richmond62 » Thu Aug 18, 2022 12:03 pm

"To use this function in a standalone, you must include the XML extension."

It would be just great if someone could explain how to do that . . .
-
SShot 2022-08-18 at 14.02.23.png
-
?

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

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

Post by Klaus » Thu Aug 18, 2022 12:29 pm

Hi Richmond,

I think they mean the "SVG Icon Drawing Library", which has a separate entry in the list of Inclusions.


Best

Klaus

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10090
Joined: Fri Feb 19, 2010 10:17 am

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

Post by richmond62 » Thu Aug 18, 2022 12:40 pm

Thank you very much, Klaus, for
the help. 8)

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10090
Joined: Fri Feb 19, 2010 10:17 am

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

Post by richmond62 » Thu Aug 18, 2022 12:58 pm

Oh, wait a big fat moment . . .

SVG icons are one thing,

and importing SVG images might be another.

Post Reply