Create a button's icon with a part of a big image? - Beleaguered Castle
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
-
- Livecode Opensource Backer
- Posts: 9388
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Create a button's icon with a part of a big image?
I am very glad, Zak, that someone can help
you with the GM, because I cannot.
you with the GM, because I cannot.
Re: Create a button's icon with a part of a big image?
I also never find a way to use the GM so I usually prefer to write my own script to change objects size and position on resizeStack handler.richmond62 wrote: ↑Fri Aug 12, 2022 3:17 pmPersonally I have found it almost impossible to use, that is why I'd far rather "roll my own."
My actual problem is that I have 52 SVG picts to move and resize. The operation takes so long it reminds me of an old 68k Mac
Re: Create a button's icon with a part of a big image?
With so many objects I would probably not use the GM for all of these as there are pitfalls and it would be super-tedious. It may be possible to do this with the new responsive layout, but I really can’t get that to work yet…
If you number the cards sequentially (don’t use actual numbers, but something like card1, card2 etc) you can easily construct code to position and resize all cards relative to an anchor card in the on resizeStack handler (well, relatively easily anyway!). How you resize the anchor card is up to you, whether by GM or not is not the difficult bit.
If you mean the resizing & repositioning of your cards is slow, perhaps post your code here as others. May be able to help you optimise it.
Re: Create a button's icon with a part of a big image?
To be more accurate, I encounter 2 problems:
1 - automatic resize
When a column contains more than a certain amount of cards, the entire board must be reduced, in order to have enough space to place other cards at the bottom of this column.
2 - manual resize : when the user resize the stack's window.
This event is obviously handled with resizeStack
In both case, I have to calculate the new position of the columns top card and loop over all cards to change their height, width and location.
This loop is very simple, it's something like:
And yes, the resizing and repositioning of the cards is slow on my old machine.
In the case#2, when the user resize the stack's window, is there a way to lock the screen, or the process, in order to not trigger the resizing and repositioning until the user releases the mouse? With resizeStack, the resizing is a live process (which is very cool in most of the cases) but it's awful in my case
1 - automatic resize
When a column contains more than a certain amount of cards, the entire board must be reduced, in order to have enough space to place other cards at the bottom of this column.
2 - manual resize : when the user resize the stack's window.
This event is obviously handled with resizeStack
In both case, I have to calculate the new position of the columns top card and loop over all cards to change their height, width and location.
This loop is very simple, it's something like:
Code: Select all
put item row of BCA_CARDS[col] into cardName // BCA_CARDS is a global containing all the cards name
set the height of img cardName to gArrDimsCard["height"]
set the width of img cardName to gArrDimsCard["width"]
set topLeft of img cardName to (coordH & "," & coordV)
add offsetPx to coordV
In the case#2, when the user resize the stack's window, is there a way to lock the screen, or the process, in order to not trigger the resizing and repositioning until the user releases the mouse? With resizeStack, the resizing is a live process (which is very cool in most of the cases) but it's awful in my case
-
- Livecode Opensource Backer
- Posts: 9388
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Create a button's icon with a part of a big image?
There is nothing stopping you moving the resizeStack code to
inside a mouseUp.
BUT, there will be no continuous resizing.
inside a mouseUp.
BUT, there will be no continuous resizing.
-
- VIP Livecode Opensource Backer
- Posts: 4003
- Joined: Sun Jan 07, 2007 9:12 pm
- Location: Bochum, Germany
Re: Create a button's icon with a part of a big image?
Hi Zax,
Kind regards
Bernd
Could you try to define the final rect of the resized card in code and set the image cardName to that rect instead of setting height, setting width and setting topLeft. It should reduce the time a bit because LC does not have to recalculate the image as often. And I assume that you have a lockscreen/unlock screen wrapper for your resizing.put item row of BCA_CARDS[col] into cardName // BCA_CARDS is a global containing all the cards name
set the height of img cardName to gArrDimsCard["height"]
set the width of img cardName to gArrDimsCard["width"]
set topLeft of img cardName to (coordH & "," & coordV)
add offsetPx to coordV
Kind regards
Bernd
-
- VIP Livecode Opensource Backer
- Posts: 4003
- Joined: Sun Jan 07, 2007 9:12 pm
- Location: Bochum, Germany
Re: Create a button's icon with a part of a big image?
Hi Zax,
as far a resizing after the final resize is concerned the only hack I came up with is to test for "the mouse is not down" as shown in this small example stack
EDIT: the uploaded stack in this post is changed after I found a flaw in it. Please use this version.
Kind regards
Bernd
as far a resizing after the final resize is concerned the only hack I came up with is to test for "the mouse is not down" as shown in this small example stack
EDIT: the uploaded stack in this post is changed after I found a flaw in it. Please use this version.
Kind regards
Bernd
Last edited by bn on Mon Aug 15, 2022 8:08 am, edited 1 time in total.
-
- Livecode Opensource Backer
- Posts: 9388
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Create a button's icon with a part of a big image?
Are you wanting to resize your game:
1. So it fits the screens of phones & tablets?
2. So that users on computers can do daft things?
If #1 the place to put the code is in an openStack command.
1. So it fits the screens of phones & tablets?
2. So that users on computers can do daft things?
If #1 the place to put the code is in an openStack command.
Re: Create a button's icon with a part of a big image?
Great x2 Bernd
My original resize cards script took 1800 ms
When using rectangle, 910 ms
And finally, with lock screen, 95 ms!
Also, you example stack is perfect.
richmond, I don't understand when you say "there will be no continuous resizing". If I don't use Bernd's trick, resizing is continuous until the mouse is up.
My original resize cards script took 1800 ms
When using rectangle, 910 ms
And finally, with lock screen, 95 ms!
Also, you example stack is perfect.
richmond, I don't understand when you say "there will be no continuous resizing". If I don't use Bernd's trick, resizing is continuous until the mouse is up.
-
- Livecode Opensource Backer
- Posts: 9388
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Create a button's icon with a part of a big image?
I meant there would not be continuous resizing if you removed your resize script from inside a mouseMove command and placed it inside a mouseUp command.
lockScreen is going to speed things up as the computer is not going to have to pump out continuous screen redraws.
lockScreen is going to speed things up as the computer is not going to have to pump out continuous screen redraws.
Re: Create a button's icon with a part of a big image?
OK, maybe I wasn't very accurate. I was talking about the built-in resize ability: when a stack is resizable and the user resizes the stack's window by dragging the bottomRight corner of the window.richmond62 wrote: ↑Sat Aug 13, 2022 11:31 amI meant there would not be continuous resizing if you removed your resize script from inside a mouseMove command and placed it inside a mouseUp command.
Anyhow, all is working fine now (I'm now working on the history and saved games... more questions to come soon ).
-
- VIP Livecode Opensource Backer
- Posts: 4003
- Joined: Sun Jan 07, 2007 9:12 pm
- Location: Bochum, Germany
Re: Create a button's icon with a part of a big image?
Hello all,
Please be aware that the 'Resize after Mouse is up" stack I posted in this thread has a flaw that made it send too many messages after resize stopped.
Here is a version that sends only one message after manually resizing a stack.
Kind regards
Bernd
Please be aware that the 'Resize after Mouse is up" stack I posted in this thread has a flaw that made it send too many messages after resize stopped.
Here is a version that sends only one message after manually resizing a stack.
Kind regards
Bernd
Re: Create a button's icon with a part of a big image?
Thanks Bernd for this fix.
I also tried with lock messages and it seems OK, though in my script, pNewWidth and pNewHeight values seems wrong to calculate the new dimensions of controls.
I also tried with lock messages and it seems OK, though in my script, pNewWidth and pNewHeight values seems wrong to calculate the new dimensions of controls.
Code: Select all
on resizeStack pNewWidth, pNewHeight, pOldWidth, pOldHeight
lock messages
send "resizeControls pNewWidth, pNewHeight" to me in 1 milliseconds
end resizeStack
on resizeControls pNewWidth, pNewHeight
// pNewWidth, pNewHeight --> wrong values ???
beep
put 10 into tMargins
put tMargins & comma & the bottom of btn "BtnReset" + tMargins & comma & the width of this stack - tMargins & comma & the height of this stack - tMargins into tRect
set the rect of fld 1 to tRect
end resizeControls
-
- VIP Livecode Opensource Backer
- Posts: 4003
- Joined: Sun Jan 07, 2007 9:12 pm
- Location: Bochum, Germany
Re: Create a button's icon with a part of a big image?
Hi Zax,
That is interesting. Apparently your "lock messages" kicks in after the first round of "resizeStack" and is only sent once at the first round. And it is only sent after the last "resizeStack" finished.
You can see this if you change in "resizeStack"
and in "resizeControls"
This behavior is atypical because in "normal" LC handlers if you lock messages send in time is sent anyways, apparently not within "resizeStack"
For me the "resizeStack" message is a strange message because it used to be that you could easily crash LC if you did something "resizeStack" did not like.
Mark Waddingham fixed at some point those crashes but "resizeStack" is still a bit different from normal messages.
If you add a "unlock messages" at the end of the "resizeStack" handler you get the "resizeControls" on every "resizeStack" event but also after the last "resizeStack" has ended.
In short: I would not use your solution because I am superstitious and I consider it an "off-label" use and the behavior might change without notice. I recomment you stick to the convoluted solution I propose which is in line of what you can expect.
(Unless Mark Waddingham sanctions your solution)
Kind regards
Bernd
That is interesting. Apparently your "lock messages" kicks in after the first round of "resizeStack" and is only sent once at the first round. And it is only sent after the last "resizeStack" finished.
You can see this if you change in "resizeStack"
Code: Select all
send "resizeControls pNewWidth, pNewHeight, pOldWidth, pOldHeight" to me in 1 milliseconds
Code: Select all
on resizeControls pNewWidth, pNewHeight, pOldWidth, pOldHeight
put "resizeControls --> new :" && pNewWidth && "x" && pNewHeight & " Old: " & pOldWidth && "x" && pOldHeight & "( stack :" && the width of this stack && "x" && \
the height of this stack && ")" & cr after fld 1 /////
For me the "resizeStack" message is a strange message because it used to be that you could easily crash LC if you did something "resizeStack" did not like.
Mark Waddingham fixed at some point those crashes but "resizeStack" is still a bit different from normal messages.
If you add a "unlock messages" at the end of the "resizeStack" handler you get the "resizeControls" on every "resizeStack" event but also after the last "resizeStack" has ended.
In short: I would not use your solution because I am superstitious and I consider it an "off-label" use and the behavior might change without notice. I recomment you stick to the convoluted solution I propose which is in line of what you can expect.
(Unless Mark Waddingham sanctions your solution)
Kind regards
Bernd
-
- Livecode Opensource Backer
- Posts: 9388
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Create a button's icon with a part of a big image?
'Off-line', 'In-line', somewhere kinky wiggling off into the dark recesses of a forest . . .
. . . personally, if it works, and you annotate it adequately
so you have chance of understanding it in 10-15 years time
when you need to modify it, whether 1, 2 or 3 should not really matter.
. . . personally, if it works, and you annotate it adequately
so you have chance of understanding it in 10-15 years time
when you need to modify it, whether 1, 2 or 3 should not really matter.