• 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: Re: Pictures as characters
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Re: Pictures as characters


  • Subject: Re: Re: Pictures as characters
  • From: Guy English <email@hidden>
  • Date: Fri, 21 Jan 2005 11:51:24 -0500

fromRect is just the coords of the bitmap image you want to read from.
So if you've got a grid your rect calculation is:

frameRect = NSMakeRect( x * gridSize.width, y * gridSize.height, 32, 32 );

So map an index to a grid coord and get the resulting frame from your image:

- (NSRect) frameRectForIndex: (unichar) index
{
    unsigned numberOfGridsWide;
    unsigned x;
    unsigned y;

    numberOfGridsWide = [image size].width / gridSize.width;
    y = (index / numberOfGridsWide );
    x = (index % numberOfGridsWide );

    frameRect = NSMakeRect( x * gridSize.width, y * gridSize.height,
gridSize.width, gridSize.height );

    return frameRect;
}

Now you can write a function that'll take in a string and turn it into
frame rects:

- (unsigned) writeFrameRectsForString: (NSString*) string intoBuffer:
(NSRect*) rects numberOfElements: (unsigned) numberOfRects
{
    unsigned i;
    unsigned count;

    count = min( numberOfRects, [string length] );

    for ( i = 0; i < count; i++ )
    {
        unichar character;

        character = [string characterAtIndex: i];
        // you'll want to do some mapping here ...
        // like map a character to the glyph index you want it to be
represented by
        rects[i] = [self frameRectForIndex: character];
    }

    return i;
}

That function writes out an array of frame rects for the given string
and returns the number it actually wrote. Call it like this:

NSRect *rects = malloc( sizeof( NSRect * [string length] ) );
if ( rects )
{
    [self writeFrameRectsForString: string toBuffer: rects
numberOfElements: [string length];
    // draw the the frame rects to the screen from your image ...
    free( rects );
}


That should help. Don't trust the code too much - it's writen in a web
browser. And sorry if it's over the top - I'm waiting on a *long*
compile. :)

Guy


On Fri, 21 Jan 2005 16:46:08 +0100, Peter Karlsson <email@hidden> wrote:
> That sounds interesting, do you have any sample code to get me started? I
> know how to load the image, just need a little help with the fromRect code.
>
> Peter
>
> Ursprungligt meddelande
>
> > Assuming you're using the images as characters for a more graphical
> > font effect (the sort of effect you can't get just by changing font),
> > one simple method is to create an array of NSImages to store all your
> > characters in, load them all in at the start of the app and use
> > NSImage's drawAtPoint method to draw the required images across a
> > single view.
> >
> > A slightly more optimal method would be to draw all your characters in
> > a single image, in rows (a single row if all you need are A-Z, or a
> > grid of 128 characters if you're doing a full ASCII set). Load this in
> > as an NSImage on initialisation. You can then use the fromRect:
> > parameter of drawAtPoint to target the character to draw from within
> > the source image. You should end up with a graphical text method that
> > lets you draw a string of text in any view if you work on it :)
> >
> > _____________________________
> > Aaron Fothergill   :  MD / Lead Coder
> > Strange Flavour Ltd
> > email@hidden
> > http://www.strangeflavour.com
> >
> >
> > On 21 Jan 2005, at 14:19, Peter Karlsson wrote:
> >
> > > Dear list!
> > >
> > > I have 32 NSImageView's in my app, located as a row. I take a 32
> > > character
> > > NSString and convert the first char to a ascii filename (for example A
> > > =
> > > 65.tif) and load a picture in the first NSImageView. The 32
> > > NSImageView's
> > > is called view1Outlet, view2Outlet and so on. This is a lot of work. Is
> > > there another and better way to use pictures as characters?
> > >
> > > Best regards Peter
> > >
> > >  _______________________________________________
> > > 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
> > >
> >
> >
>
>  _______________________________________________
> 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
>
 _______________________________________________
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

References: 
 >RE: Re: Pictures as characters (From: "Peter Karlsson" <email@hidden>)

  • Prev by Date: CFSocket event handler accessing GUI variables
  • Next by Date: Re: Why do "loose" nibs take precedence over nibs in .lproj?
  • Previous by thread: RE: Re: Pictures as characters
  • Next by thread: RE: Re: Pictures as characters
  • Index(es):
    • Date
    • Thread