setting backgound image (as a decoration)

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

chris25
Posts: 354
Joined: Tue Oct 08, 2013 9:32 pm

setting backgound image (as a decoration)

Post by chris25 » Thu Nov 07, 2013 10:41 pm

I can not actually find this anywhere to be honest with you, the complicated stuff is easy to look up, but the simpler stuff is so elusive. I simply want my background image (it fills the app) to appear on every card. Now If I were creating new cards then the property inspector would take care of this with setting the background and share attributes, unfortunately it does not work with an established stack with multiple cards. How do you do this?

Chris

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

Re: setting backgound image (as a decoration)

Post by dunbarx » Thu Nov 07, 2013 10:51 pm

HI.

I wrote a tool to "place" an object on every card. This will set its backgroundBehavior to "true" so that on subsequent created cards it will automatically appear. Look up "place" in the dictionary. You should write this for yourself as well. It comes in handy.

No question it is easier if this sort of thing is anticipated in advance. But that is not always possible. Do pay attention to the layer of the new gadget, since you said it will cover the whole card you will also want to have it back in the layer order, not in front, where it might obscure other stuff.

Craig

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am

Re: setting backgound image (as a decoration)

Post by Dixie » Thu Nov 07, 2013 10:54 pm

Chris...
Make a button on the first card of your stack... choose the grc that you wish to use as a background... in this example I use grc "background" which is on the first card...

Code: Select all

on mouseUp
   lock screen
   push this card
   copy grc "background" of this card
   
   repeat with count = 2 to the number of cds of this stack
      go card count
      paste
      set the layer of the last grc of this card to 1
   end repeat
   
   pop card
end mouseUp
Dixie

chris25
Posts: 354
Joined: Tue Oct 08, 2013 9:32 pm

Re: setting backgound image (as a decoration)

Post by chris25 » Thu Nov 07, 2013 11:04 pm

Craig that is excellent I will get right on this - Big thanks. Dixie, I will do your thing as well, always nice to see what happens. I am experimenting with writing some code so that I can offer the user a choice of skins, in this case keeping it simple with just backgound adjustments so that the user can flip through his or her preferences for appearance. Just another exercise I dreamed up. As a side not I found all those tutorials from a conference in USA back in 2005, hosted by Jacque absolutely fantastic. I have learned an incredible amount in a few days by going through those well presented stacks, 2005? do not seem to be out dated despite being 8 years old. Pity there aren't anymore from previous years, are these conferences held every year? I can not find anymore.
Kindest regards
chris

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

Re: setting backgound image (as a decoration)

Post by dunbarx » Thu Nov 07, 2013 11:07 pm

Well, Dixie has given you much instruction.

But it is useful to know about the workings of this sort of thing. The script you have copies the grc onto each card. But if you make a new card, and you said you will, you will have to do it again. By "placing" you will create a group with its backGroundBehavior set to "true", will still get them on each card (or onto any set of cards you wish) as Dixie's script provides, but also from then on any new card you make will automatically contain it as well.

Lots of ways to do stuff, and there are nuances to each. You should play with both...

Craig

chris25
Posts: 354
Joined: Tue Oct 08, 2013 9:32 pm

Re: setting backgound image (as a decoration)

Post by chris25 » Thu Nov 07, 2013 11:31 pm

Hallo well Dixie's methode worked a treat, just changed grc to img and then hid the button (had to of course make the initial image a group otherwise it does not work. Big thanks Dixie. But dear Craig, your method seems a bit bewildering at the moment. I of course read the Place in the dictionary, then realized after trying various syntaxes and sticking it on different cards that I actually have no idea what to do with it. Can you perhaps start me off, I mean I would think that the command goes on the first card, set the image to group, write out: place backgound "image name" into this card? But this does not make sense.

place group "Navigation" onto card "Navy" -- group is on current card
place background 1 onto this card -- group may be on any card

Not a lot here in the dictionary to go on really, you said you wrote a tool? I really do not know where to start on this one.
regards
chris


Edit: After 45 minutes - I give up! Not a lot further I can take this on so little information from the dictionary and nothing discovered in resources either.

Properties in inspector relating to background also changed as many times...

Place backgound 'groupname" onto this card
Place groupname onto this card
place background 1 onto this card (renamed background)
place background "imagename" onto this card

What exactly is there left to do??

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

Re: setting backgound image (as a decoration)

Post by dunbarx » Fri Nov 08, 2013 12:58 am

Chris.

Make a new stack. Make three additional cards. Go back to card 1 and create a button. Group that button.

Navigate through the four cards (go next card). You will see your button only on the first card.

Now, go back to card 1, and in the message box, write:

Place group 1 onto card 3.

Navigate again. You will see the button on card 1 and 3. Check out its properties in the inspector. You will see its backgroundBehavior is now "true".

Quick homework:

1- Make a field on card 1. Make a new button also on card 1 that has a handler in its script that places that field onto ALL cards.
2- In the stack script, write a handler that lets you know which card you are on when you navigate, putting the info into the field
3- Make new cards. Check out your work.

Craig

chris25
Posts: 354
Joined: Tue Oct 08, 2013 9:32 pm

Re: setting backgound image (as a decoration)

Post by chris25 » Fri Nov 08, 2013 12:23 pm

place group 1 onto card 3 in the message box? Granted, this works….But What is the point in having it in the message box when it does not work in the actual stack or card as a script?

I see no connection at all between the above xercise and the the second one? That little homework exercise left me with the same reasons as to why I even first posted this question - I am no closer to understanding the solution by doing the message box thing, and that exercise leaves me asking the same flipping questions all over again - believe me I have spent enough time examinig what is going wrong and I am really fed up with it. sorry craig - many things I learn in livecode are coming together and making sense, some new things now 100 times more complicated than this I am not having such infuriating frustration with. The reason? Because some simple actions in livecode are rather complex in their workings - a background is a bloody backgound, and putting it on ALL cards at any time in a software process SHOULD NOT BE THIS RIDICILOUSLY COMPLEX A PROCEDRE - yes I am going nuts with it. At the least ithere should be a straightforward tutorial, why make the learning process so painful there is no need for it. I take apart what I am told, I don't just repeat verbatim without understanding, I have no time for copying other peoples' work, but I like to see the answer in order to understand the problem in the first place.

I have done my best here - as for the script handler in the stack, well I went through all sorts of ideas from using me and target, to trying to find an example script, but that all failed. The stupid Irony of all this is that your idea is much better than Dixies for the reasons you mentioned I was looking forward to actually making sometool - Oh just use the place command and all will be fine....Ugh :evil: Dixies method may have more writing and procedure but I actually understand it. :!: and can even remember it without looking at it again.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

Re: setting backgound image (as a decoration)

Post by dunbarx » Fri Nov 08, 2013 3:16 pm

Chris.

You never thought of simply making a button and putting that single line in a mouseUp handler? I only suggested the msg box because it was convenient. If you did not, then you are still not quite at the point where you can integrate what you know with what is open to you in LiveCode, a toolbox full of tools. It is NOT a package of stand-alone gadgetry that you pick and choose, and simply run.

In the stack script:

Code: Select all

on openCard
put the number of this card into fld "yourCardNumberField"
end openCard
Every time you navigate to a new card, the "openCard" message is sent by the engine. This is trapped in the stack script, which is above all the cards in the hierarchy, and the single line is executed. "this card" is the current one, since it is opened after the message is sent, and therefore the number indicates the card you are looking at.

As for the placing of a backGround on some or all cards, why do you see this as a horrible burden? Could there be a command that does this automatically? Likely not, as you would have to pass perhaps hundreds or thousands of parameters to such a command:

superPlace tBackGround, cd 1,cd 3,cd 66,cd 4567 | all

Do you see? This has to be written by the author, implemented as a handler. You can always write such a thing and store it in a backscript or the stack script as a library that you keep forever

You are frustrated because you believe you ought to be able to assimilate a great deal of knowledge very quickly, We have spoken about this before. I think you are progressing quite well, You think you are stuck in a mire of unclear, inadequate and overwhelming information.

We are both correct. Once again, this is not about learning to program your remote. Would you think that reading a college level chemistry textbook would be somehow more likely to teach you the heart of that subject in a few weeks or months

I wonder if you will be around in a year. I hope so. Maybe you respond better to concrete examples rather than my smug-ass homework assignments. I apologize. I will try to provide those more often, and see if that helps you better.

Homework. Write a "superPlace" library handler that... Oops. sorry.

Craig

chris25
Posts: 354
Joined: Tue Oct 08, 2013 9:32 pm

Re: setting backgound image (as a decoration)

Post by chris25 » Fri Nov 08, 2013 4:49 pm

Hi Craig, firstly I will be around in two years, secondly I do appreciate that this is essentially a programming environment and not a drag drop macdonalds take away code your beefburger.

One of the first things I tried was to put that handler into the mouse button, this was the first thing I tried. As you can see I replicated what I did.

The second thing is this: superPlace tBackGround, cd 1,cd 3,cd 66,cd 4567 | all
I looked up superplace? Was this humour? I can not find it in the dictionary. It's not the language or livecode that I am having difficulty with, it's the spaghetti like approach to its tutorials and indexes. And then when you want to find out something often you do not know How to ask the question, in Chemistry I look up its name because I know its name exists even though I do not understand it, in chemistry I look up parameters because I know from inherited learning that these parameters must exist (for example what dilution do I need for such and such - I am aware of the word dilution), So when I look up background, because I have learned that livecode uses friendly language, I can not find the logical progression between setting a background on one card to setting it on multiple cards and things start to get painfully difficult. I can not simply look up background and start reading pages of examples and variations and how it should be used, this latter process is the ideal learning method. Try looking up background in Python, I think you will find all the information in one place with exhaustive explanations as to Why this should be done in this way and what Not to do.

I have learned quite some stuff but only where there are exhaustive explanations written by people who teach, and by seeing things done. Dixies example makes sense, why? because there is a logical sequence and I see what is happening. It worked. I still can not place my image on every card after the cards are already there, I can place my image on every card BEFORE I make the cards, I can place my buttons on every card, I can place text files on every card, but I can not place a background image on every card.

On the arrow example it placed it on card 2 and then came up with an error.

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am

Re: setting backgound image (as a decoration)

Post by Dixie » Fri Nov 08, 2013 6:24 pm

Chris…

I too hope that you are around in two years time… Whether you are using liveCode or not !…:-)

To clear this up… I have attached another stack for you to look at. Open the stack, it contains 7 cards… run throughout the stack with the arrowKeys… you will notice that cards 2 to 7 do not have a background on them…

Now using the button on the first card (we went through this earlier) the background will now be placed on each of the cards that exist in the stack if it is not already on them… Once you have the background on all the cards delete the button on the first card…

Now make a new card…:-) I have put a handler in the stack script that will ask if you want the background, that appears on all the other cards, to appear on this new card as well… the choice is yours.. ‘Yes’ or ‘No’…

Remember that if you are at the first card and make a new card, the new card will appear immediately after the first card, so if you want to ‘add’ the new card after the last card in your stack… first go to the last card before you make a new card.
Attachments
backgroundsContinued.livecode.zip
(1.91 KiB) Downloaded 197 times

chris25
Posts: 354
Joined: Tue Oct 08, 2013 9:32 pm

Re: setting backgound image (as a decoration)

Post by chris25 » Fri Nov 08, 2013 7:04 pm

Hallo Dixie, I used this method when you first gave it to me. And it works great. Besides all that, I am grateful for this stack because there is a little extra here which actually I can learn from and experiment by introducing a few other things and see what happens. So this stack is by no means wasted - big thankyou I see that you have put quite some time into the explanations as well.

As for dear old Craig (well he might be younger that that), I feel I have exhausted him. It is Only the Place command, AFTER the cards are created that still eludes me. As I said I can place background controls and images after the card is created using the place command from the option menu. I can also script the necessities to get the same objects throughout cards BEFORE the cards are created. So there it is - and my own frustrations are due to the intensity to which I push myself not just to 'Know' but to ' Understand' and that works against me you know, but I can't help it, that's how I have always been unfortunately.

Well that's new - I never knew that you could simply put a made-up variable name between a mouse up handler and close it. then begin a new mouseUp with that variable - Now THAT is totally new... and exciting.

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7393
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: setting backgound image (as a decoration)

Post by jacque » Fri Nov 08, 2013 9:49 pm

One more thing while you're absorbing all this. Dixie's script makes a copy of the graphic (or image in your case) and pastes it onto every card. That means you'll have as many copies of the image as you have cards that use it. If you ever decide to change the image, or add a script to it, or anything else, you will have to make the same change on every card.

Shared groups avoid this problem by storing only a single copy in the stack and just drawing it on every card it's placed on. This keeps stacks size smaller and also helps considerably if you want to edit the contents later. You only need to change the original, and every card the group is placed on will automatically show the changes. This is usually the preferred method.

Use duplicate objects when they need to be slightly different on each card. Use a shared, placed group when the object(s) should always be the same on every card.

There's another method no one has mentioned yet. You can set the background pattern of a card, or of a whole stack. This method also uses only a single image (it only works with images, not graphics or anything else. Patterns must be images.) If you set the pattern of a card, it will only show on that card. If you set it on the whole stack, every card in the stack will show it (unless you also set it on a card; the card's pattern will override the stack's pattern.)

To do this, import the image, note its ID, and hide it. To show it on every card in the stack:

Code: Select all

set the backgroundPattern of this stack to <ID number>
To show it on only a single card:

Code: Select all

set the backgroundPattern of this card to <ID number>
Since this only has to be done once during development, typing the command into the message box is easier than creating a button with a script that you need to hide or delete when you're done. The message box is very useful for these types of one-off commands that you only execute once during development.

The limitations of using backgroundPattern: if your image is smaller than the card, it will tile. This is both a blessing and a curse. If you are using a seamless tiled image it looks great and you can resize the stack and the background will grow/shrink and always look good. But if you are using a photo or a non-tiled image, small cards will crop the image and big cards will repeat it -- which looks odd. The method depands on your stack and the image you choose.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7393
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: setting backgound image (as a decoration)

Post by jacque » Fri Nov 08, 2013 9:51 pm

Oh, and if you try this and don't like it, you can remove the pattern this way:

Code: Select all

set the backgroundPattern of this stack to empty
Sustitute "card" for "stack" if that's where you put it.

EDIT: I just remembered you won't need the message box -- you can set the background pattern in the stack or card property inspector. That's probably easier. My old habits die hard. I'm a devoted message box user.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

chris25
Posts: 354
Joined: Tue Oct 08, 2013 9:32 pm

Re: setting backgound image (as a decoration)

Post by chris25 » Fri Nov 08, 2013 10:04 pm

Jacque, thankyou for your additions. And appreciated some of the turorials that you gave in conference 2005. The stacks were quite enlightening and very well presented.

Post Reply