Add inertia to non-native Android scroller (Livecode) - scroll

Charles B posted an interesting alternative to the native scroller in Android using LiveCode. His code may be found here: Scrolling in iphone and android devices in LiveCode (and I'll reproduce his code at the bottom of this post)
It really does work; however, there is no inertia. In other words, when you remove your finger, the scrolling stops dead in its tracks. I'm wondering if an alteration to his code might provide some inertial scrolling - perhaps some sort of timer added to the mouseRelease or mouseUp handlers?
While I know this is not the official method provided by LiveCode (it's not a "native" scroller), it's certainly a snap to implement and, in fact, is the first example code that actually worked for me in terms of scrolling all the way to the end of my provided text. If I could add inertial scrolling, it would be awesome.
Thanks,
Barry
local allowMove
on mouseDown
put mouseH(),mouseV() into allowMove
end mouseDown
on mouseMove X,Y
if allowMove is not empty then
lock screen
if the hScrollbar of me then
set the hScroll of me to the hScroll of me + (item 1 of allowMove-X)
end if
if the vScrollbar of me then
set the vScroll of me to the vScroll of me + (item 2 of allowMove-Y)
end if
put X into item 1 of allowMove
put Y into item 2 of allowMove
unlock screen
end if
end mouseMove
on mouseUp
put empty into allowMove
end mouseUp
on mouseRelease
mouseUp
end mouseRelease

An inertia type effect can be achieve with some repeat loops in the mouseUp handler.
local allowMove, sScrollPos
on mouseDown
put mouseH(),mouseV() into allowMove
put the vScroll of me into sScrollPos
end mouseDown
on mouseMove X,Y
if allowMove is not empty then
lock screen
if the hScrollbar of me then
set the hScroll of me to the hScroll of me + (item 1 of allowMove-X)
end if
if the vScrollbar of me then
set the vScroll of me to the vScroll of me + (item 2 of allowMove-Y)
end if
put X into item 1 of allowMove
put Y into item 2 of allowMove
unlock screen
end if
end mouseMove
on mouseUp
put the vScroll of me into tVscroll
if tVscroll > sScrollPos then
put "down"
repeat with x = 1 to 20
set the vScroll of me to the vScroll of me + (20-x)
end repeat
end if
if tVscroll < sScrollPos then
put "up"
repeat with x = 1 to 20
set the vScroll of me to the vScroll of me - (20-x)
end repeat
end if
if tVscroll = sScrollPos then
put "same"
end if
put empty into allowMove
end mouseUp
on mouseRelease
mouseUp
end mouseRelease
Basically on the mouseUp, the vScroll of a field is being set to its vScorll +/- an ever decreasing valued defined in the various repeat loops.. I have also added a little bit of debugging that tells you if the scroll is up, down or stays the same.
The values in the repeat loop can be changed to give a more/less dramatic inertia effect

Related

How to create splash screen with animated .gif image?

I would like to know if there is any way that when opening my App, a splash screen with an animated GIF image is presented and soon after this screen closes and opens the main screen of the app, what I have done so far is what is in the gif below, but to work I need to use this display alert , or otherwise I don't see the progress bar being loaded, that is, it already opens in the second tab of my tab view.
Example of what I've done so far.
script AppDelegate
property parent : class "NSObject"
-- IBOutlets
property theWindow : missing value
property gifImg : missing value
property indicatorProgress : missing value
property myTabView : missing value
property myLabel : missing value
on applicationWillFinishLaunching_(aNotification)
myTabView's selectTabViewItemAtIndex:0
loadGifScreen()
end applicationWillFinishLaunching_
on applicationShouldTerminateAfterLastWindowClosed_(sender)
return true
end applicationShouldTerminate_
on loadGifScreen()
display alert "" giving up after 2
set c to 0
repeat 100 times
set c to c + 1
delay 0.04
tell indicatorProgress to setDoubleValue:c
if c > 99 then
exit repeat
end if
end repeat
myTabView's selectTabViewItemAtIndex:1
end loadGifScreen
end script

Excel - More efficient way to remove specific borders

How can I make the below code more efficient, at the moment it takes roughly 30 seconds to complete
The code will clear all cells within a selection which have a white background & then clear all diagonal borders within a selection.
With only the clear cells with white background code it finishes instantly but as soon as I added the remove borders code it became slow.
Sub ADULTClearOnly()
Set sh2 = ThisWorkbook.Worksheets("ADULT Sign On Sheet")
sh2.Select
Cells.Range("B1:F756").Select
For Each Cell In Selection
If Cell.Interior.Color = Excel.XlRgbColor.rgbWhite Then
Cell.Value = ""
End If
Next
Cells.Range("G1:AO757").Select
For Each Cell In Selection
If Cell.Borders(xlDiagonalUp).LineStyle = xlDiagonalUp Then
Cell.Borders(xlDiagonalUp).LineStyle = xlNone
End If
Next
End Sub
There are several issues in your code:
You don't need to, and should not Select to do these actions
Your logic is flawed: xlDiagonalUp is not a LineStyle
Because you are setting any Diagonal Up borders to none, you don't need to iterate the range, do it in one step
So, replace
Cells.Range("G1:AO757").Select
For Each Cell In Selection
If Cell.Borders(xlDiagonalUp).LineStyle = xlDiagonalUp Then
Cell.Borders(xlDiagonalUp).LineStyle = xlNone
End If
Next
with
sh2.Range("G1:AO757").Borders(xlDiagonalUp).LineStyle = xlNone
Similarly,
sh2.Select
Cells.Range("B1:F756").Select
For Each Cell In Selection
If Cell.Interior.Color = Excel.XlRgbColor.rgbWhite Then
Cell.Value = ""
End If
Next
can be reduced to
For Each Cell In sh2.Range("B1:F756")
If Cell.Interior.Color = Excel.XlRgbColor.rgbWhite Then
Cell.ClearContents
End If
Next

Fix multiple middle mouse click

Basically I have an issue where the middle mouse button when clicked does multiple very fast middle mouses. For example, if I open a link in a new tab with middle mouse it will open about 10 of that tab. I have tried all of the conventional methods to fix it, ie. driver fixes etc. What I want to try now is a bit of mouse debouncing with AHK (Auto Hot Key) for windows.
Essentially what I am thinking is to do this:
while (forever)
if( capture the middle mouse)
sleep 500 ms
mouse click
end
end
Can anyone give some advice with this approach?
Alternatively i thought about making a middle mouse hotkey:
$MButton::
Loop
{
sleep 500
if not GetKeyState("MButton", "P")
break ; Break out of the loop.
}
send {MButton}
return
Can anyone see any problems with this?
You can have a much simpler solution without a delay.
This will ignore middle click if the last click was 50 ms ago.
#Persistent
global pressed_g := 0
global delay_g := 50 ; delay in miliseconds, increase this value if your multiple click take longer than delay_g time
return
MButton::
if( pressed_g = 0 )
{
Send, {MButton}
tooltip,sent
pressed_g := 1
}
SetTimer, Countdown , Off
SetTimer, Countdown , -%delay_g%
return
Countdown:
pressed_g := 0
return
Could it be that you are looking for this? You press the MButton and while you keep the MButton pressed, the script will continue to fire MButton.
#Persistent
MButton::
while GetKeyState("MButton", "P") ; While the Middle Mouse button key is being held down
{
Send, {MButton}
}
return

Getting touch events when objects have an alpha of 0 In Corona SDK

If I wanted to have an invisible box, for example, how could I get touch events if it has an alpha of 0? Or is there another way to make an invisible box.
local function invisiblebuttontouch(event)
if event.phase == 'began' then
print (event.x..","..event.y)
end
end
button = display.newRect(1,1,300,300)
button:addEventListener("touch",invisiblebuttontouch)
button.alpha = 0
It never prints out the x and y, however if I don't set the alpha to 0, then it works fine.
You need to add this line to your code:
button.isHitTestable = true
Source: http://docs.coronalabs.com/api/type/DisplayObject/isHitTestable.html
it should be noted that no callback for a target will be fired if one of the parent groups are invisible disregarding isHittestable. Also setting isHittestable of the mother group won't change that.

How to position editbox's cursor in shoes?

Shoes is very handy GUI tool. I would like to do a search form so that a user is helped to navigate through larger texts for editing. For this I need to move the cursor within an editbox element.
Here you'll see my question in code:
Shoes.app do
stack do
p=para "After pressing 'search' a question will arise"
box=edit_box
box.text="One\nof\nthe\nmost\nstriking\ndifferences\nbetween\na\ncat\nand\na\nlie\nis\nthat\na\ncat\nhas\nonly\nnine lives."
flow :margin_top=>0.1 do
search=edit_line
button("search") do
pos=box.text.index search.text
y = box.text[0..pos].split.size-1 if pos
if not y.nil?
#For example if you searched "only" then
#cursor should jump/scroll to line 17.
#
#Anything there for cursor positioning,
#like: box.cursor=[0,y]
#
p.text="How can I move editbox's cursor in line #{y+1}?"
else
alert "'#{search.text}' not found"
end
end
end
end
end
Is there is any way to change cursor's position of an editbox? If not, do you know an alternative way of implementation?
Unfortunately, Shoes doesn't seem to provide any way to do that. These are the only methods defined on EditBox (it inherits from Native, which has several methods, but again, none to reposition the cursor).
rb_define_method(cEditBox, "text", CASTHOOK(shoes_edit_box_get_text), 0);
rb_define_method(cEditBox, "text=", CASTHOOK(shoes_edit_box_set_text), 1);
rb_define_method(cEditBox, "draw", CASTHOOK(shoes_edit_box_draw), 2);
rb_define_method(cEditBox, "change", CASTHOOK(shoes_control_change), -1);
http://github.com/why/shoes/blob/cea39a8bf9a5b7057b1824a9fab868d1f8609d69/shoes/ruby.c

Resources