Hi, I’m trying to learn some basic ways of making your own graphics
views and though I see one way of completing this first mini-project,
I’m wondering if people have any alternate ideas for solutions as mine
seems both memory and CPU intensive. Basically I want a panel of a
fixed width and height that displays values such that a new value is
added on the the right of the current values and if there are more
values the pixel width on the panel, the lefthand value is removed and
every value is adjusted to the left one value. My plan is to have each
value represented by a black pixel and the background would be white,
I want no anti-aliasing and the values aren’t meant to look
contiguous.
As I see it the two most ideal solutions for the "move everything
left" part would be to either be able to move all the retained
graphics left one pixel and at the right "uncovered" pixel, cover it
with the new value, or else do something similar, only with the
numeric array that the values are based on (I don’t care to retain any
data besides for its usefulness in this functionality). Perhaps I
could make the subclass of NSView 1 pixel wider than as shown in the
ScrollView (or ClipView?) and each time a new value is added, scroll
left one pixel and…(??) remove that pixel and add the width back to
the right side of the NSView subclass? Hmm… It seems to me, also,
the NSBezierPath isn’t really the type of object that I should use for
this type of graphics. I don’t want the leftmost pixel to connect to
the rightmost (this isn’t a polygon) and I don’t even want the black
dots to look like they’re supposed to be a line or a path – they’re
representative of distinct, noncontiguous values. However, I see no
other options in the Cocoa libraries for how to draw to a subclass of
NSView besides using one or many NSBezierPaths (I’m of course, not
claiming they aren’t there but I can’t find them in Apple’s docs).
Even if I have to blank out the NSView and go through a for loop and
say drawPixel(currentXValue, myValueArray[y]), as long as it isn’t too
CPU intensive, doesn’t have tremendous lag (some is fine), doesn’t
have antialiasing or look contiguous I’d be happy. It’s seems to me
that there must be other people around who just want to paint dots at
specific, distinct and noncontiguous points in their Cocoa code, so
what do they do?
Thanks,
Ben
p.s. I make the disclaimer that this post may be caused by me missing
a simple or easy to find solution but given the late hour I’ve done my
best for tonight.