RE: [Newbie] Creating a timeline view
RE: [Newbie] Creating a timeline view
- Subject: RE: [Newbie] Creating a timeline view
- From: Keith Blount <email@hidden>
- Date: Wed, 1 Mar 2006 11:58:48 -0800 (PST)
Depending on how complicated you want the view to be,
creating your own custom time-line view will not be
trivial, especially if you are very new to Cocoa (as
you indicate in your message). If you haven't done so
already, I recommend you work through a book such as
Aaron Hillegass's Cocoa Programming For Mac OS X,
which covers such things as creating a custom view
with drag and drop.
Assuming you have already done all that, here is the
way I would go about it (I recently did something
similar when I implemented an Index Card view which
allows the user to arrange and edit index cards on a
corkboard):
1) Have a really good look at how NSTableView and
NSOutlineView work. These will be good models for what
you want to do.
2) Create your own NSView subclass (TimeLineView or
some such). In all likelihood, you will generally want
this to be placed inside a scroll view so that the
user can scroll across the time line.
3) Have your TimeLineView depend on a data source
(like NSTableView) for all its data (like I say, study
NSTableView for this part), and for validating drag
and drop. This will ensure it is flexible and
reusable, and that your view is separated from your
model and controller.
4) You could either have your TimeLineView draw
everything (in -drawRect:, of course) - the lines
along with the boxes of info on top of them (this is
how I do things in my own view, for various reasons -
or you could subclass NSCell to draw the boxes and
only draw the lines in your TimeLineView (NSTableView
uses NSCells to draw its text and controls, but draws
the grid and background itself).
5) You will need to implement your own equivalent of
-tile, in which you lay out all of your boxes and
ensure they don't (and can't) overlap.
6) You will override -mouseDown:, -mouseUp:,
-mouseDragged: etc to check for clicks on your items
and for updating dragging indicators within the view
(such as the black lines that appear when you drag
inside NSTableView).
7) If you want to edit the boxes of data, you could
use the window's field editor whenever the user
double-clicks inside a box area (I keep a C array of
NSRects of all my index cards for this purpose and for
drawing).
8) Override all the NSResponder methods you want to
support for keyboard navigation etc.
Essentially, you are going to have to do the whole
thing yourself, as none of the framework views are
really suitable for modification as a time-line view
(I'm sure someone will correct me if I am grossly
mistaken here, but certainly, none spring to mind).
Sorry this is all so vague - the trouble is that it's
a big undertaking and will take a lot of work, though
I'm sure it will be worth it.
Good luck and all the best,
Keith
--- ORIGINAL MESSAGE ---
I'm about to start a new Cocoa app, which will be
time-line based. A
bit
like the timeline in FinalCut etc.
I'm pretty new to Cocoa so before I start I thought
I'd seek the advice
of
the list.
What would be the best way to implement a timeline
view?
My app requires any number of 'tracks' in the time
line, and the user
can
drop things onto the tracks, then shift them left and
right (backwards
and
forwards in time really).
The user should be able to grab any object on any
track and drag it
around
both left and right along the track, and up and down
tracks.
What would be the best way to handle the user
interface for this type
of
thing? Should I use a ListView with a subclassed
CustomView in each
row?
Then draw each track in a CustomView? How about the
objects on the
tracks,
they will not all be aligned, but none can overlap.
Should I subclass
NSButton and handle the dragging by moving it within
the custom view?
Of
course the time line needs to be able to scroll too.
(ie be wider than
the
view).
I've had a read through "Introduction to Drawing and
Views Programming
Topics for Cocoa" on the ADC site, but obviously it's
not specific to
this
idea.
Any ideas or pointers would be thankfully received.
-Kenny
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.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