• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How can I implement labels without the overhead of an NSTextField?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How can I implement labels without the overhead of an NSTextField?


  • Subject: Re: How can I implement labels without the overhead of an NSTextField?
  • From: Henry McGilton <email@hidden>
  • Date: Mon, 13 Dec 2004 08:35:55 -0800


On Dec 13, 2004, at 6:03 AM, Guy English wrote:

On Mon, 13 Dec 2004 07:37:37 +0000, email@hidden
<email@hidden>
Okay, I will do as you wish. I picked up a copy of "Cocoa Programming" from the
bookstore and am reading chapter 14 and others. I will report back when I have either
found a way to solve my problem or given up.
Cool - it's a good book and will help a lot.

If your labels change infrequently and are arranged in an aritrary
layout (not column and rows) you may want to simply throw a little
memory at the problem. You could make a bitmap (NSImage) big enough to
hold all the labels, draw them into that (using NSAttributedString
drawAtPoint: ) then scroll around this big bitmap. It'll be much
faster and probably a less time consuming optimization than doing the
glyph drawing yourself.

Maybe that'll help a little.

I just performed a simple experiment . . .

Using Interface Builder, I created a window that contains a
custom view named  RandomLabelsView.  I made  RandomLabelsView
a subview of a regular old NSScrollView.

RandomLabelsView  inits itself by loading up a three+ megabyte
image as a background image, and then goes on to generate one
thousand random strings (for labels).

In the  drawRect  method of  RandomLabelsView  I make a
background buffer (NSImage) the same size as the bounds of
RandomLabelsView on the first time that  drawRect  is called.
That first time, I draw the background image into the
background buffer, and then I draw the thousand strings at
random placements all over the background buffer, by locking
and unlocking focus on the background buffer.  I draw the
strings by using the NSString addition method
drawAtPoint:  withAttributes:

Then I draw the background buffer into the  RandomLabelsView
itself.  On all subsequent invocations of  drawRect, only the
background buffer is drawn into the  RandomLabelsView.

Performance is perfectly acceptable at the user level.
Both the 3484 x 2452 image and the thousand strings
scroll smoothly and with no apparent jerkiness.

Rendering time for the large background image and the
thousand strings is about two seconds on a 1.4GHz G4.
So you would expect to see the two second hit on the
first time through, and any time the view changes its size.

The code is available for inspection if anybody wants to
look at it --- it's somewhat crude as it's a first
approximation.

Anyway, the moral of the story is to use buffering for drawing
in views, rather than using Interface Builder as a page layout
application.

    Cheers,
		........  Henry

===============================+============================
  Henry McGilton, Boulevardier |    Trilithon Software
   Objective-C/Java Composer   |     Seroia Research
-------------------------------+----------------------------
  mailto:email@hidden   |   http://www.trilithon.com
                               |
===============================+============================

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: How can I implement labels without the overhead of an NSTextField?
      • From: Guy English <email@hidden>
References: 
 >RE: How can I implement labels without the overhead of an NSTextField? (From: email@hidden)
 >Re: How can I implement labels without the overhead of an NSTextField? (From: Guy English <email@hidden>)

  • Prev by Date: Best way to email html?
  • Next by Date: Re: c++ exceptions causing abort
  • Previous by thread: Re: How can I implement labels without the overhead of an NSTextField?
  • Next by thread: Re: How can I implement labels without the overhead of an NSTextField?
  • Index(es):
    • Date
    • Thread