Are there any way to update NSPanel content during dragging the panel ?

  • My custom NSView in a NSPanel shows some information depends on panel's position to the main window. I want  to update it during dragging the panel. I try [self setNeedsDisplay:YES] in mouseDragged: delegate, drawRect: called many times during dragging, but it will not appear on screen until mouse stop.
    I test it on Mac OS X 10.7 and want to support 10.6.

    Yoshiaki Katayanagi
    http://www.jizoh.jp/english.html
  • On May 2, 2012, at 5:59 PM, Yoshiaki Katayanagi wrote:

    > My custom NSView in a NSPanel shows some information depends on panel's position to the main window. I want  to update it during dragging the panel. I try [self setNeedsDisplay:YES] in mouseDragged: delegate

    -mouseDragged: is called after the mouse button is pressed *within your view* and the cursor moves. It has nothing to do with the window being dragged, since after all that’s a mouse-down in the title bar, not your view.

    In general views don’t care about and don’t get notified about window movement. You can listen to the NSWindowDidMoveNotification posted by the window, if you want to know about it.

    —Jens
  • Hi, Jens

    > -mouseDragged: is called after the mouse button is pressed *within your view* and the cursor moves. It has nothing to do with the window being dragged, since after all thatís a mouse-down in the title bar, not your view.
    >
    > In general views donít care about and donít get notified about window movement. You can listen to the NSWindowDidMoveNotification posted by the window, if you want to know about it.
    >
    > Jens

    Thanks Jens, but the panel is defined as HUD panel, and to drag it, user should press mouse button on my custom view as it has no title bar. I examined that mouseDragged: and drawRect are called actually.

    Yoshiaki Katayanagi
    http://www.jizoh.jp/english.html
  • > My custom NSView in a NSPanel shows some information depends on panel's position to the main window. I want  to update it during dragging the panel. I try [self setNeedsDisplay:YES] in mouseDragged: delegate, drawRect: called many times during dragging, but it will not appear on screen until mouse stop.
    > I test it on Mac OS X 10.7 and want to support 10.6.

      Found the solution. Simply, drag the panel by my self. Following code in the custom view do this.

    - (void)mouseDown:(NSEvent*)event {
        offset = [event locationInWindow];
    }

    - (void)mouseDragged:(NSEvent *)event {
        NSPoint location = [NSEvent mouseLocation];
        location.x -= offset;
        location.y -= offset;
        [[self window] setFrameOrigin:location];
        [self setNeedsDisplay:YES];
    }

    Thanks.

    Yoshiaki Katayanagi
    http://www.jizoh.jp/english.html
previous month may 2012 next month
MTWTFSS
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31      
Go to today