2013년 7월 21일 일요일

마우스 이벤트 처리

1. 왼쪽 마우스 버튼 처리

- (void) mouseDown:(NSEvent *)theEvent
{
    NSPoint mouseLocationWindow = [theEvent locationInWindow];
    NSPoint mouseLocationView   = [self convertPoint:mouseLocationWindow fromView:nil];

    m_pImage->OnLButtonDown(CPoint(mouseLocationView.x, mouseLocationView.y));
    
    [self setNeedsDisplay:YES];
}

- (void) mouseUp:(NSEvent *)theEvent
{
    NSPoint mouseLocationWindow = [theEvent locationInWindow];
    NSPoint mouseLocationView   = [self convertPoint:mouseLocationWindow fromView:nil];

    m_pImage->OnLButtonUp(CPoint(mouseLocationView.x, mouseLocationView.y));

    [self setNeedsDisplay:YES];
}

- (void) mouseDragged:(NSEvent *)theEvent
{
    NSPoint mouseLocationWindow = [theEvent locationInWindow];
    NSPoint mouseLocationView   = [self convertPoint:mouseLocationWindow fromView:nil];
    
    m_pImage->OnMouseMove(CPoint(mouseLocationView.x, mouseLocationView.y));

    [self setNeedsDisplay:YES];
}

2. 오른쪽 마우스 버튼 처리

- (void) rightMouseDown:(NSEvent *)theEvent
{
    NSPoint mouseLocationWindow = [theEvent locationInWindow];
    NSPoint mouseLocationView   = [self convertPoint:mouseLocationWindow fromView:nil];

    m_pImage->OnRButtonDown(CPoint(mouseLocationView.x, mouseLocationView.y));

    [self setNeedsDisplay:YES];
}


- (void) rightMouseDragged:(NSEvent *)theEvent
{
    NSPoint mouseLocationWindow = [theEvent locationInWindow];
    NSPoint mouseLocationView   = [self convertPoint:mouseLocationWindow fromView:nil];
    
    m_pImage->OnMouseMove(CPoint(mouseLocationView.x, mouseLocationView.y));
    
    [self setNeedsDisplay:YES];    
}

- (void) rightMouseUp:(NSEvent *)theEvent
{
    NSPoint mouseLocationWindow = [theEvent locationInWindow];
    NSPoint mouseLocationView   = [self convertPoint:mouseLocationWindow fromView:nil];
    
    m_pImage->OnRButtonUp(CPoint(mouseLocationView.x, mouseLocationView.y));
    
    [self setNeedsDisplay:YES];
}

댓글 없음:

댓글 쓰기