On Tue, 1 Dec 2009 03:35:57 +0200, Henri H?kkinen <hen...@henuxsoft.com>
said:
>Hello.
>
>I'm trying to implement my custom NSView derived class to draw a chessboard
with chess pieces on it. I'm using Core Animation's CALayer classes since I want
to use animation with other effects later on.
>
>Currently I have have Board and Piece classes, which both derive from CALayer.
Board overrides resizeWithSuperlayerSize which resizes bounds to always keep the
layer's aspect ratio fixed (since chessboards are always square) and it's
position centered relative to the superlayer's frame, and in drawInContext I
draw the chess squares with two alternating colors. Piece class likewise
overrides drawInContext to draw NSImage on it, which represents piece's vector
image loaded from a PDF file. Board layer is added as a sublayer of the NSView's
root layer and Piece layers are added as a sublayer of the Board layer and so
forth.
>
>My problem now is, however, that I am not sure how do I keep the position and
size of a Piece layer fixed to a specific square in the Board layer. Board's
bounding rectangle can be any size and it changes dynamically as the view gets
resized. Piece layer does not know it's square coordinates on the chessboard,
except by the bounds rectangle.

Maybe I'm misunderstanding, but it seems to me from what you say that the
Board knows how the chessboard is laid out, and it knows where each Piece
is, so it knows which "square" a given Piece is in. So as the Board redraws
/ resizes, it redraws the squares and resizes / repositions each Piece
accordingly. (Or if you want each Piece to resize / reposition itself,
provide a method so that it can ask the Board where it needs to be.)

m.

-- 
matt neuburg, phd = m...@tidbits.com, <http://www.tidbits.com/matt/>
A fool + a tool + an autorelease pool = cool!
AppleScript: the Definitive Guide - Second Edition!
http://www.tidbits.com/matt/default.html#applescriptthings



_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to