cocoa - Copies of NSRects not displaying -


i trying make simple cocoa program. have little black box (a subclass of nsview drawing nsrect on screen) following mouse around. part have working. need is: when click mouse want leave "copy" of black box behind.

i have been trying work on 5 hours , have tried under sun. sure solution simple, guess missing grasping of fundamental concepts.

here have (a "stay" supposed copy stays behind):

@property nsmutablearray *stays;  ...  - (void) makestay {     if (!_stays)         _stays = [[nsmutablearray alloc]init];      nsvalue *newstay = [nsvalue valuewithrect:self.frame];     [_stays addobject:newstay]; }  ...   -(void)drawrect:(nsrect)rect {     [[nscolor blackcolor] set];     nsrectfill([self bounds]);      (int x = 0; x < _stays.count; x++) {         nsrectfill([_stays[x] rectvalue]);     } } 

any on how understand fundamentals of nsview work appreciated!

from code i'm guessing problem bounds.

it looks have nsview moving around screen - it's frame location in superview , saving in makestay.

in drawrect fill view's bounds - in view coordinates. try fill "stays", these in superview coordinates treated view coordinates , undoubtedly outside of bounds of view , clipped.

try instead having "board" view filling window, , box view subview of that. board view should keep , draw list of "stays", "box" view when clicked should add current frame board views list. stays in bounds of board.

hth.


Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -