• 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
Subclassing NSMatrix to tile with hexagons
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Subclassing NSMatrix to tile with hexagons


  • Subject: Subclassing NSMatrix to tile with hexagons
  • From: Matthew Anderson <email@hidden>
  • Date: Sun, 8 Feb 2009 16:03:38 -0600

Hello All --

I'm trying to subclass NSMatrix to lay cells out in a hexagonal tiling
instead of a proper grid (as a foundation for a game with a
hexagonally tiled board).  It seemed an appropriate base class, as I
still index cell locations with rows and columns.  Cells are
constrained to be of a particular shape, and every other column is
offset half a cell height. I hope that's clear, but see [1] for more
info on what I mean.

[1] http://www.gamedev.net/reference/articles/article1800.asp

Anyway, I thought I might be able to get away with overriding as little as:
- drawCellAtRow:column:
- cellFrameAtRow:column:
- getRow:column:forPoint:
- setCellSize:
- setIntercellSpacing:

and then for drawing giving the target cell the outer bounding rect of
a regular hexagon with that width (which overlaps with the bounding
rects of the adjacent columns) if it responds YES to a selector
"isHexShaped" or the largest rect possible inside the hexagon if it
doesn't respond in that fashion.

It doesn't seem to work though.  Problems are:
- "drawCellAtRow:column:" doesn't seem to ever get called unless I
call it myself while overriding "drawRect:"
- "cellFrameAtRow:column:" only gets called when you click on the view
- "getRow:column:forPoint:" isn't getting called either by the super's
"mouseDown:" to identify which cell was clicked on

I've poured over docs, googled, and experimented.  No joy yet.

Is there something that one can hook into to reposition the cells such
that the superclass's "drawRect:" and picking code do something
sensible, or would all that have to be re-implemented?

Would cocoa-wisdom greater than I've acquired thusfar suggest a
different base class that might meet my needs better than NSMatrix?

Note, I'm somewhat new to Cocoa (though I've read fully through half a
dozen apple cocoa guides and worked through 90% of the 3rd ed
Hillegass book), but not to programming.

Thanks a lot!
Matt Anderson
_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:

This email sent to email@hidden

  • Prev by Date: Re: NSScrollView: is setting the document view size supported?
  • Next by Date: Why its necessary to include .dylib file to project as well as to /usr/local/lib?
  • Previous by thread: Re: FSExchangeObjects / FSReplaceObject
  • Next by thread: Why its necessary to include .dylib file to project as well as to /usr/local/lib?
  • Index(es):
    • Date
    • Thread