Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Mac > Mac Programmer Help > Re: Scrolling t...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 5 Topic 3678 of 3836
Post > Topic >>

Re: Scrolling text like a stock ticker

by David Phillip Oster <oster@[EMAIL PROTECTED] > Mar 29, 2008 at 11:27 AM

In article 
<79d3e4eb-b1f1-4fc9-ac43-d1da8b39c4ea@[EMAIL PROTECTED]
>,
 flopbucket <flopbucket@[EMAIL PROTECTED]
> wrote:

> I'm an experienced C++ developer but new to Mac OS X.  I am familiar
> with basic Cocoa development, Objective-C, etc.
> 
> I want to write a small app that open a window and at the bottom has a
> scrolling text area, like a stock ticker.  As new data arrives, I want
> it to smoothly scroll in from the right, causing text at the extreme
> left to scroll out of the window.  Normal "ticker" type stuff.
> 
> Being new to Mac OS, I'm not exactly sure how best to go about this.
> Especially about getting the letters to smoothly scroll in (i.e. not
> whole letter at a time).  Do I draw to an offscreen bitmap and copy
> part of it to the window for display?
> 
> If anyone has any ideas on how to go about this it'd be greatly
> appreciated.  I don't mind reading and doing the hard work of course,
> I'm just not sure what way you would do this in Cocoa.

Text is complicated. There are Unicode and kerning rules that will have 
you tearing your hair. Better just to re-use the existing Cocoa cl***** 
for drawing scrolling text.

For you, I've built a simple working model of the ticker tape view you 
asked for here: http://www.TurboZen.com/sourcecode/Ticker.zip

It is built out of an NSTextView, with the following tricks:
The animation is driven by a timer, that fires 60 times a second, 
executing this:

- (void)step:(NSTimer *)timer {
  mOffset -= 2; // pixels per tick
  [self setTextContainerInset:NSMakeSize(mOffset, 0)];
  [self setNeedsDisplay:YES];
}


Limitations: 

* the timer is created scheduled, on the runloop in the default mode. To 
get the ticker to work while the user is tracking a menu or a control, 
you need to add the timer to the other runloop modes.

* I didn't add any API to set the font attributes, such as color of the 
appended text.

* A real program would use the NSTextContainer owned by the NSTextView 
to measure the pixels in the string prefix, delete the prefix, and reset 
the container offset, so you wouldn't waste storage storing dead history 
in the prefix of the string of the NSTextStorage.


(If you are new to Cocoa, you may miss that much of the creation and 
wiring up of the objects in a program is specified in Interface Builder, 
in the .nib file. That is how the AppDelegate and gets created and how 
it gets a pointer to the TickerView.)

See 
file:///Developer/ADC%20Reference%20Library/do***entation/Cocoa/Conceptua
l/TextArchitecture/index.html for more information.

-- 
David Phillip Oster
 




 5 Posts in Topic:
Scrolling text like a stock ticker
flopbucket <flopbucket  2008-03-28 16:05:31 
Re: Scrolling text like a stock ticker
David Phillip Oster <o  2008-03-29 11:27:50 
Re: Scrolling text like a stock ticker
flopbucket <flopbucket  2008-03-30 08:35:26 
Re: Scrolling text like a stock ticker
David Phillip Oster <o  2008-03-30 08:52:01 
Re: Scrolling text like a stock ticker
Simon Slavin <slavins.  2008-03-30 19:58:40 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Aug 29 14:23:37 CDT 2008.