Re: Basic: How to go about implementing such a view?
Re: Basic: How to go about implementing such a view?
- Subject: Re: Basic: How to go about implementing such a view?
- From: Fritz Anderson <email@hidden>
- Date: Mon, 5 Jan 2009 13:04:55 -0600
I'm responding off the top of my head, so take all of this as just my
first, instinctual approach.
On 30 Dec 2008, at 10:35 PM, Matt Rajca wrote:
I am trying to figure out how to implement a 'Piano Roll' view in
Cocoa. Attached is a screenshot of what I'm trying to accomplish.
Disregard the keyboard on the left of the window and let's just
focus on the area with the colorful rectangles, symbolizing notes.
1. When drawing the light and dark grey rows which make up a
background, should I just use a loop with Quartz 2D/Cocoa Drawing
calls?
I'd think in terms of "cells." Just let your view have a "drawCell"
method that takes the datum, location, and background, and draws for
just that datum: It draws a cell within the larger view. Loop through
the data, subtracting cell.size.height from cell.origin.y at each step.
See the NSTableDataSource documentation for an example of how a
controller delegate can supply the data for each row, without your
view having to know anything about your model*. All you'd have to do
is keep a reference to the data source.
==
* This is a bit hollow, since your cell-drawing code has to reference
the properties unique to your model, but you get the idea.
==
So, yes, a loop of Quartz or Cocoa drawing calls.
2. When drawing the vertical lines, should I just use a loop with
Quartz 2D/Cocoa Drawing calls?
I'd have the view draw the lines after it's looped through the cells.
Again, yes, a loop of +[NSBezierPath strokeLineFromPoint:toPoint:].
3. Should I put the notes (colorful rectangles) each in a separate
view (or Core Animation layer), or is it effective to just draw them
directly in the main view (same view in which the rows are drawn)? I
am eventually going to want to resize them and change their position
by dragging them around.
I haven't seen anything that requires Core Animation. A view for each
row is possible, but I think it's much too heavyweight, and
complicates the geometry and drawing those lines over everything.
For dragging, lock drawing focus on an NSImage, draw the cell into it,
and feed the image to the view's
dragImage:at:offset:event:pasteboard:source:slideBack:
4. How would I go about changing the view's width as more notes
(rectangles) are added to the view? When enclosed in a NSScrollView,
would manipulating the width of the view also hide/show the
horizontal scrollbar appropriately?
As notes are added, change the view's frame to match. The NSScrollView
mechanism will handle the rest.
— F
--
Fritz Anderson -- Xcode 3 Unleashed: Now in its second printing -- <http://x3u.manoverboard.org/
>
_______________________________________________
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