Scripted painting in an image in a group

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
PlaidFlannel
Posts: 43
Joined: Fri Aug 21, 2020 7:06 pm

Scripted painting in an image in a group

Post by PlaidFlannel » Thu Feb 18, 2021 5:58 pm

In my stack, I use scripted painting tools to create the contents of three nonoverlapping image objects.

This works, but there are some complications that raise some questions.

1. LiveCode will only allow painting into the image that is in the top layer. So to control which of my image objects gets the paint, my scripts always set the layer of the target image to "top" before painting, and then return the image to its previous layer after painting. This works.

Code: Select all

put the layer of image "Canvas1" into tSavedLayer
set the layer of image "Canvas1" to top
-- invoke the paint tools
set the layer of image "Canvas1" to tSavedLayer
This process certainly could be simplified if LiveCode were to add a new "paintTarget" property. Then I could do something like this:

Code: Select all

set the paintTarget to image "Canvas1"
-- invoke the paint tools
set the paintTarget to image "Canvas2"
-- invoke the paint tools again
set the paintTarget to empty -- return to LiveCode default behavior
A question for forum members with knowledge of the internals of LiveCode: is such a change likely to be straightforward, or would it be difficult?

2. When the image is large, I put it in a group with a vertical scrollbar. Apparently, there are some behind-the-scenes constraints on the layers of groups and their objects. In particular, an attempt to move a grouped image object to the top layer fails at runtime.

My current workaround is to have my painting scripts first ungroup the scrolling group, move the image object to the top layer, paint into it, then select that object and the other objects that were also previously in the group, and then group the selectedObject. In the one case I have tried, this seems to work. Note that it does not seem to be necessary to return the image object to its previous layer before regrouping.

However, if my group object has properties, including a script, are they always preserved across this ungroup/group action? Again, in the one case I have tried, this seems to work.

But if I do the task in two steps, and I look at the Project Browser between the steps, the group object does not appear. Is it somehow "remembered" so that the next group command brings it back, with all its properties and its script intact?

Is this always the case with an ungroup/group sequence, whether scripted or manual? For example, if I create a group containing, say, radio buttons, give that group object some properties and a script, later change my mind and ungroup, and then group a different set of objects, do I get a new group object or the old "remembered" group object?

My concern is that there might be situations where ungrouping and regrouping would affect the layering of objects, resulting in objects that were previously visible becoming hidden by the new group.

More generally, is there a simpler approach that would facilitate painting into a large image object that is inside a scrolling group?

Thanks for your help.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10043
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Scripted painting in an image in a group

Post by FourthWorld » Thu Feb 18, 2021 6:16 pm

The relayerGroupedControls may be what you're looking for you simplify that relayering.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

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

Re: Scripted painting in an image in a group

Post by Klaus » Thu Feb 18, 2021 6:52 pm

Hi PlaidFlannel,

1. sorry, no idea...
2. to change the layer of an object inside of a group you
a. have first to:
...

Code: Select all

set the relayerGroupedControls of grp "your group here" to TRUE
set the layer of img "you image 1" to X
## where X is the new layer
set the layer of...

## Done:
set the relayerGroupedControls of grp "your group here" to FALSE
...
or
b. use the -> relayer command

I would probably just copy the image into an empty image object which is NOT part of the group,
so no need to mess with the layers, do you painting stuff and then put it back into the image inside of the group.

Code: Select all

...
put img "the one inside of the group you want to paint on" into img "the image on top of all objects"
## do your paint stuff
put img "the image on top of all objectss" into img "the one inside of the group you want to paint on"
hide img "the image on top of all objects"
## Or just delete it and create a new one whenever you need it.
...
Best

Klaus

PlaidFlannel
Posts: 43
Joined: Fri Aug 21, 2020 7:06 pm

Re: Scripted painting in an image in a group

Post by PlaidFlannel » Thu Feb 18, 2021 7:56 pm

Thanks for the quick replies. As a LiveCode beginner, I was unaware of the relayering capabilities of a group.

It also never occurred to me that moving the contents of an image to another image could be scripted just like moving the contents of a field to another field. Sometimes the obvious has to be pointed out in order to become obvious.

These suggestions certain point the way to almost trivial solutions to all my issues. I'll be interested in seeing if moving images of about two million pixels around has any impact on the perceived performance of my application.

Post Reply