Livecode player: How to catch up a "dragStop" message - livecode

Within a player, I would like to allow the user to manually drag the boundaries of the selection (start time and end time).
I can use a dragStart message to catch if the user start to drag, but I can't get the final positions of the elements, because I don't know when the user stop to drag.
I have tried something like this:
on dragStart
repeat until the mouse is up
/*unfortunately, this part freeze the player*/
end repeat
put the timeScale of me into sr
put the endTime of me into endT
put endT/sr
end dragStart
But the player is frozen with the wait command. So the user can't move the boundaries, and I can't get the final position of the "endTime".
How to wait until the mouse is up, but without frozen the player?

There are many ways to get out of that blocking loop, waiting "with messages" or sending a message in time within a handler, which releases the engine during the interval. But the most basic might be something like this, if you will try an experiment. Make a button and a field on a new card. In the button script:
on dragStart
put the loc of me into line 1 of fld 1
end dragStart
on mouseMove
if the mouseLoc is within the rect of me and the mouse is down then
set the loc of me to the mouseLoc
end if
end mouseMove
on mouseup
put the loc of me into line 2 of fld 1
end mouse up
Now this is overdone, but at least shows how you can use small handlers to deal with small issues.

This could finally be achieved with a very simple code (as often with livecode):
on selectionchanged
put the timeScale of me into sr
put the endTime of me into endT
put endT/sr into fld 1
end selectionchanged

Related

UIViewPropertyAnimator position reset

I have a slight problem. I'm trying to create animated progress bar like Instagram does. It works correctly in all cases except when I want to present previous item. Breakpoints say that when I switch to previous item, UIViewPropertyAnimator position remains in .end state, so it immediately call its completion and switch "back" to next item. So my question is - when animator done its job, how to reset it's position back to .start and then switch next item?
The problem was related to previous called function. Before moving to the next or previous item I call function which should update all UIProgressView objects through for_in cycle. So when the previous item appeared on the screen, UIProgressView for this item was still .progress = 1.0, UIViewPropertyAnimator had nothing to do, so it called completion block and switch next item.
fillProgress(bars: currentStoryItem)
let duration = story.files[currentStoryItem].duration
DispatchQueue.main.asyncAfter(deadline: .now() + 0.01) {
self.progressBars[self.currentStoryItem].startFillingAnimation(with: duration)
}
asyncAfter saved my live)

How do I make an Excel ActiveX label to be transparent ... at runtime?

I want to put a transparent label on top of a sheet in Excel, so that I can take advantage of the MouseMove event of the label to "draw cells" (aka change their fill color and so on) by mouse click / drag / etc. - since I can't do that on the cells per se.
Now everything works just fine, except that I can't make the label transparent at runtime (aka in VBA) ... while by doing exactly the same thing in Design Mode works as expected. Specifically, I have the code (more or less):
Dim MapLabel As OLEObject
On Error Resume Next
Sheet2.OLEObjects("MapLabel").Delete
Set MapLabel = Sheet2.OLEObjects.Add("Forms.Label.1")
MapLabel.name = "MapLabel"
MapLabel.Placement = xlMoveAndSize
MapLabel.Object.Caption = ""
' Problem line below
MapLabel.Object.BackStyle = fmBackStyleTransparent
' Problem line above
MapLabel.Left = Sheet2.cells(2, 6).Left
MapLabel.Top = Sheet2.cells(2, 6).Top
MapLabel.Width = Sheet2.cells(2,6).Width * 10
MapLabel.Height = Sheet2.cells(2,6).Height * 10
So, in words, I first delete the label named 'MapLabel', then recreate it (the above code goes into a "init" Sub). All the code lines except the one marked produce the desired result. The marked one does set the BackStyle property of the label to fmBackStyleTransparent ... but it doesn't actually make the label transparent. This is frustrating, because it's the same approach that works flawlessly at design time!
Do you have a solution to this? I read about solving similar problems by declaring the label as MsForms.Label or as Control, but the sheet object doesn't have those properties, plus, there are far more label properties which can be set using the OLEObject than with the help of MsForms.Label or Control.
All you need to do after this line:
MapLabel.Object.BackStyle = fmBackStyleTransparent
put this line:
ActiveSheet.Shapes(MapLabel.Name).Fill.Transparency = 1
I hope I helped.
P.S. If you need explanation i will edit my answer.
I had the same problem as you but in Word. The solution for me was to do the following:
In design mode:
Right click on the object
Navigate to Switch to automatic form/Image > Wrapping > In front of the text
Add an empty picture to your label

How to limit the items in popup?

How to limit the items in the popup. "Sar" array contains lot of words, with respect to the selection. if my first popup contains 15 items and did the change. when going to the next popup, if it contains 10 items, the remains 5 items from the first also added to the second popup options.
How to kill that buffer in popup menu items? Iam using this code
global jar,myjar,sam,mySam,Dic,Sar
on mouseUp pMouseButton
put the selectedText of field "MytextField" into Ftext
if pMouseButton = 3 then
put the number of lines of (the keys of sam) into mySam
repeat with i = 1 to mySam
if sam[i] contains Ftext then
put sam[i] into Sar
split Sar by comma
end if
end repeat
put the text of button "M" into tText
put the number of words of (the keys of Sar) into mylength
repeat with x = 1 to mylength
put Sar[x] into line x of tText
end repeat
put mylength into kk---now iam using this code for delete the buffer
----repeat with j = kk to 100
---put "" into line j of tText
---end repeat
set the text of button "M" to tText
popup button "M" at the clickLoc
else
--popup button "M" at the clickLoc
-- do other stuff here
end if
end mouseUp
Is any option for limit the items in popup. Example:- if popup contains 15 items, i want to see only 10 items, remaining 5 could be see only clicking the bottom button in the popup
You are using globals which might not be what you want.
Try emptying the global with put empty into Sar before adding some new values or use locals which will be emptied after your code is done.

Image slide show on Livecode

I create 2 images for slide show but I have a problem. My problem is when the first image fade to the second image. The stack freeze. When image fade finish, the stack back to normal.
Code.
command aniFadehide curF
Switch noFa
case 1
lock screen for visual effect in rect (the rect of img 1 of grp curF)
show img 2 of grp curF
hide img 1 of grp curF
unlock screen with visual effect dissolve very fast
add 1 to noFa
break
case 2
lock screen for visual effect in rect (the rect of img 1 of grp curF)
show img 1 of grp curF
hide img 2 of grp curF
unlock screen with visual effect dissolve very fast
put 1 to noFa
break
end Switch
send "aniFadehide curF" to me in 3 secs
end aniFadehide
There are a few things I do before using visual effects. First, I always load QT by getting the QTVersion. This may no longer apply to LiveCode 7, unless you set the dontUseQT to false.
Second, I execute a visual effect invisible to make sure that I have the "freeze" behind me before I really need visual effects. E.g.
on openStack
lock screen for visual effect
// nothing here, but you can but something if you want
unlock screen with visual effect dissolve very fast
pass openStack
end openStack
This handler execute a visual effect, but because you don't go to a different card and don't show or hide controls, the use is just thinking that s/he waiting for the software to start up.
Next, you seem to have a little error in your script, as put 1 to noFashould be put 1 into noFa.
There may also be an issue with your global or local variables. So, I made a working script and will post it here. This script would run in a button.
global noFa
local lCounter
on mouseUp
put the pendingMessages into myMsgs
filter myMsgs with "*aniFadehide*"
repeat for each line myLine in myMsgs
cancel item 1 of myLine
end repeat
put 1 into noFa
put 0 into Counter
aniFadehide 1
end mouseUp
command aniFadehide curF
add 1 to lCounter
Switch noFa
case 1
lock screen for visual effect in rect (the rect of img 1 of grp curF)
show img 2 of grp curF
hide img 1 of grp curF
unlock screen with visual effect dissolve very fast
add 1 to noFa
break
case 2
lock screen for visual effect in rect (the rect of img 1 of grp curF)
show img 1 of grp curF
hide img 2 of grp curF
unlock screen with visual effect dissolve very fast
put 1 into noFa
break
end Switch
if lCounter < 10 then
send "aniFadehide curF" to me in 3 secs
end if
end aniFadehide

why check box does not move when stack is resized?

I made a stack that displays lines of text that change their width when the stack is resized.
The Category columns is changing its position on resizing but the check box does not.
What am I missing in the code? What changes have to be made?
See the code in the stack that can be downloaded here:
https://dl.dropboxusercontent.com/u/99863601/Data%20grid%20Form-variable%20line%20height%2Bcheckbox.zip
Thanks in advance.
keram
If I understand what you are trying to achieve here then in your LayoutControl handler make the following change:
-- put the rect of btn "btnCheck" of me into theFieldRect
-- put item 3 of pControlRect - 5 into item 3 of theFieldRect
-- set the rect of btn "btnCheck" of me to theFieldRect
set the left of btn "btnCheck" of me to the right of fld "cat" of me
However I think the resizing of the Cat field is wrong too. Try something like:
on LayoutControl pControlRect
set the right of btn "btnCheck" of me to item 3 of pControlRect-4
set the right of fld "Cat" of me to the left of btn "btnCheck" of me
get the rect of fld "Line" of me
put the left of fld "Cat" of me into item 3 of it
set the rect of fld "Line" of me to it
put the formattedHeight of fld "Line" of me + item 2 of it into item 4 of it
set the rect of fld "Line" of me to it
put item 4 of it into item 4 of pControlRect
set the rect of graphic "Background" of me to pControlRect
end LayoutControl
To edit the LayoutControl script you need to open the datagrid property inspector and click on the Row Behavior... button. This will present the script editor for the behavior of the row template.
Because the DataGrid doesn't have this feature. If you would use the Geometry manager, the GM propeties are not copied from the checkbox in the template to the checkboxes in the actual DG. So, the GM won't work. Perhaps you could write a script of your own that sets the right of all checkboxes to a position relative to the width of the card:
on resizeStack
lock screen
repeat with x = 1 to number of buttons
if the style of btn x is "checkbox" then
set the right of btn x to the width of this cd - 100
end if
end repeat
unlock screen
end resizeStack
Unfortunately, this doesn't work with the datagrid either, because the DG also does some (or a lot) resizing of its own.
It would be much easier to create your own.

Resources