Tuesday, July 22, 2014

#1 2012-02-05 08:32:16 pm

chumponimys
Member
Registered: 2011-08-05
Posts: 59

Making Scrolling Text in NSTextField Label

Hi Community,
I'm working on a program, and I need to create an NSTextField Label that will have text scrolling across it (much like the texts on this page). Currently I'm calling on a function and then just appending the characters one by one to the NSTextView backwards with a .04 second delay (I use Shane's doEventFetch function to update the NSTextField). However, this is buggy as some characters will append faster than others. Is there any easier way to go about doing this? Here's the code I have so far (the Label's value is bound to the variable theDow):

   

Applescript:

on test_(sender)
       set theString to "THIS IS A TEST "
       set backwardsString to {}
       set theChars to characters of theString
       set theNum to number of items of theString
       repeat theNum times
           set end of backwardsString to item theNum of theChars
           set theNum to theNum - 1
       end repeat
       set backwardsString to backwardsString as string
       set my theDow to ""
       set theNum to 0
       repeat
           if continueDow then
               repeat with i in characters of backwardsString
                   set my theDow to i & theDow
                   do shell script "sleep .04"
                   doEventFetch()
               end repeat
               if theNum < 5 then
                   set theNum to theNum + 1
               else
                   set theDow to characters 1 through 78 of theDow
               end if
           else
               exit repeat
           end if
       end repeat
   end test_

Last edited by chumponimys (2012-02-05 08:32:31 pm)

Offline

 

#2 2012-02-05 09:58:00 pm

Shane Stanley
Member
From: Australia
Registered: 2002-12-07
Posts: 3520

Re: Making Scrolling Text in NSTextField Label

Your best bet is probably an animation. The easiest way would be to resize your field, So you might start of with a marrow field set with Text Direction Right to Left, and then use something like:


Applescript:

       tell current application's NSAnimationContext to beginGrouping()
       tell current application's NSAnimationContext's currentContext() to setDuration_(2)
       textField's animator()'s setFrameSize_({width:400, height:17})
       tell current application's NSAnimationContext to endGrouping()

The grouping code is for setting the duration; the main thin is that instead of setting the size of the text field, you set the size of the text field's animator.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

#3 2012-02-05 11:15:43 pm

chumponimys
Member
Registered: 2011-08-05
Posts: 59

Re: Making Scrolling Text in NSTextField Label

Oh wow, I was unaware that you could do Animations in ASOC, that's pretty amazing. It'll be a little bit painful making the text seem as if it's constantly looping across the screen, but the animation is definitely going to look a million times better than just appending text. Thank you so much!

By the way, just for future projects, what are the other animator functions you can use with an NSTextField other than "setFrameSize:"?

Last edited by chumponimys (2012-02-05 11:17:19 pm)

Offline

 

#4 2012-02-05 11:50:04 pm

Shane Stanley
Member
From: Australia
Registered: 2002-12-07
Posts: 3520

Re: Making Scrolling Text in NSTextField Label

chumponimys wrote:

Oh wow, I was unaware that you could do Animations in ASOC, that's pretty amazing. It'll be a little bit painful making the text seem as if it's constantly looping across the screen, but the animation is definitely going to look a million times better than just appending text. Thank you so much!

I suspect getting a repeating animation will be a bit more couple than using animator -- you will possibly have to use NSViewAnimation.

By the way, just for future projects, what are the other animator functions you can use with an NSTextField other than "setFrameSize:"?

"properties of the types float, double, NSPoint, NSSize, or NSRect are animatable using the proxy returned the NSAnimatablePropertyContainer method animator"


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

#5 2012-02-11 08:12:02 pm

chumponimys
Member
Registered: 2011-08-05
Posts: 59

Re: Making Scrolling Text in NSTextField Label

I've decided to stick with constantly editing the Label. I decided to switch to using an NSLoop and change the font, both of which had a huge impact and are making it run a lot more smoothly. Thank you so much for your help!

Offline

 

#6 2012-02-11 09:24:21 pm

Shane Stanley
Member
From: Australia
Registered: 2002-12-07
Posts: 3520

Re: Making Scrolling Text in NSTextField Label

NSLoop?


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

Board footer

Powered by FluxBB

[ Generated in 0.144 seconds, 10 queries executed ]

RSS (new topics) RSS (active topics)