How to copy backgroundPattern of a graphic ?

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: 475
Joined: Mon May 28, 2007 10:12 am
Location: France
Contact:

How to copy backgroundPattern of a graphic ?

Post by Zax » Wed Apr 10, 2024 12:47 pm

Hello

How can I copy the backgroundPattern from one graphic control to another?

Here is how I populate the backgroundPattern of a first graphic with an image:

Code: Select all

set the backGroundPattern of graphic "Graphic1" to (the id of last image)
delete last image
I would now a second graphic to have the same backgroundPattern as the first, even though the source image has been deleted.
I tried, without success:

Code: Select all

set the backgroundPattern of graphic "Graphic2" to the backgroundPattern of graphic "Graphic1"

Klaus
Posts: 13831
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: How to copy backgroundPattern of a graphic ?

Post by Klaus » Wed Apr 10, 2024 1:07 pm

Bonjour Zax,

this is not possible!

It is just like the icon of a button, which is also the id of an image.
If you delete the image, close the stack and reopen it, the icon of the button is gone!

Same for a bgpattern, the image is neccessary for the pattern as some kind of "reference".
Means no image, no bgpattern!


Best

Klaus

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

Re: How to copy backgroundPattern of a graphic ?

Post by Zax » Wed Apr 10, 2024 1:11 pm

Klaus wrote:
Wed Apr 10, 2024 1:07 pm
this is not possible!
Merci Klaus :)

(I must say that I still preferred the time when you answered me "It's possible, it's Livecode!" :twisted: )

Klaus
Posts: 13831
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: How to copy backgroundPattern of a graphic ?

Post by Klaus » Wed Apr 10, 2024 1:41 pm

Maybe next time... :-D

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

Re: How to copy backgroundPattern of a graphic ?

Post by richmond62 » Wed Apr 10, 2024 1:50 pm

Try this:

Code: Select all

on mouseUp
   set the backGroundPattern of grc "rp2" to the backGroundPattern of grc "rp1"
end mouseUp
Of course IF you have deleted the source image (erm, why?) you'll have to do something more sneaky:

Code: Select all

on mouseUp
   import snapshot from grc "rp1"
   set the name of the last image to "xxx"
   set the backGroundPattern of grc "rp3" to id of img "xxx"
end mouseUp
Last edited by richmond62 on Wed Apr 10, 2024 1:55 pm, edited 1 time in total.

Klaus
Posts: 13831
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: How to copy backgroundPattern of a graphic ?

Post by Klaus » Wed Apr 10, 2024 1:52 pm

richmond62 wrote:
Wed Apr 10, 2024 1:50 pm
Try this:

Code: Select all

on mouseUp
   set the backGroundPattern of grc "rp2" to the backGroundPattern of grc "rp1"
end mouseUp
We have been there already... 8)

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

Re: How to copy backgroundPattern of a graphic ?

Post by richmond62 » Wed Apr 10, 2024 1:56 pm

Read the second bit of my posting. 8)

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

Re: How to copy backgroundPattern of a graphic ?

Post by Zax » Wed Apr 10, 2024 2:04 pm

Thank you richmond62.

BTW, my script deletes the "last image" because, when in development time, I didn't want to store lots a temporary images in my stack.

Klaus
Posts: 13831
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: How to copy backgroundPattern of a graphic ?

Post by Klaus » Wed Apr 10, 2024 2:07 pm

richmond62 wrote:
Wed Apr 10, 2024 1:56 pm
Read the second bit of my posting. 8)
That came later than my posting, Sir! 8)

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

Re: How to copy backgroundPattern of a graphic ?

Post by richmond62 » Wed Apr 10, 2024 2:33 pm

Your 'problem' Klaus, is that you were too quick off the mark, and I had to stir some food I was cooking between the 2 parts of my message.
--
Here's your punishment: 8)


Spinach Toran


SERVES 2
450 g/| Ib fresh spinach
4 tbsp oil
I small onion, finely chopped
I green chilli, chopped
75 g/3 oz tomatoes, peeled and chopped
75 g/3 oz grated or desiccated coconut
salt

1 Wash the spinach, discard any discoloured leaves and tough stalks, and shake dry. Chop as finely as possible and leave in a colander to drain.
2 Heat the oil in a pan and gently fry the onion and green chilli until the onion is transparent.
3 Add the spinach and tomato, cover tightly and cook on a low heat for 4-5 minutes, shaking the pan occasionally, until the spinach has collapsed.
4 Stir in the coconut and add salt to taste.

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”