ページ

2008年4月23日水曜日

RubberBand(その8)枠の移動

このエントリーをブックマークに追加 このエントリーを含むはてなブックマーク

枠をドラッグして移動できるようにする。

これは簡単にできる。

 if (NSPointInRect(cp, _rect)) {
dx = _rect.origin.x - cp.x;
dy = _rect.origin.y - cp.y;
while ([event type] != NSLeftMouseUp) {
event = [[self window] nextEventMatchingMask:(NSLeftMouseDraggedMask | NSLeftMouseUpMask)];
cp = [self convertPoint:[event locationInWindow] fromView:nil];
_rect.origin.x = cp.x + dx;
_rect.origin.y = cp.y + dy;

[self setNeedsDisplay:YES];
}
}


ソース:RubberBand-5.zip