Help with NSButton event

Discussion in 'Mac Programming' started by kev786, Jan 5, 2010.

  1. kev786 macrumors newbie

    Joined:
    Jan 5, 2010
    #1
    Hi,
    I have a problem: I want to place a NSButton with type of "Recessed Button" on NSView and part of button should be on view and another part should be outside of this view
    That's ok, but when cursor of mouse move inside button and outside view, button receive event about this.
    What need to do for this event do not send to button when cursor move outside my view ?
    Thanks
     
  2. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    You could try overriding hitTest: in a subclass of NSButton and return nil if the point doesn't lie within the view (see convertPoint:toView:). I'm not even sure if that'd work.
     
  3. kev786 thread starter macrumors newbie

    Joined:
    Jan 5, 2010
    #3
    Thanks for the answer, but when I clicked on the button - that's ok, problem is appear when I moved cursor on the Recessed Button and not clicked.
    Because it's Recessed - it light when cursor place inside button and fade when cursor place outside.
    hitTest send when mouse click, but not when mouse moved

    I try override mouseEntered: and mouseExited: events, but it's not help me
     
  4. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #4
    Maybe try subclassing NSButtonCell and play around with the various mouse handling methods in NSCell (look at the Tracking the Mouse section for NSCell's documentation).
     
  5. Sydde macrumors 68020

    Sydde

    Joined:
    Aug 17, 2009
    #5
    You could subclass NSButton and override the -mouseMoved: method or subclass the cell and override -setState:

    The latter might be a little more work because you would have to handle -setState: for when the button is clicked.
     
  6. kev786 thread starter macrumors newbie

    Joined:
    Jan 5, 2010
    #6
    I'm trying it, but no effect ((( I try override functions in NSButtonCell and override functions in NSButton , but it's not help me ((
    Functions mouseMoved: is ignored when I override it
    setState: ignored when mouse moved over button, it's send when clicked on button

    I think that if replace options in NSTrackingArea for NSButton it will be help me
    In Debugger I saw that default options is 4225 - I think that it's NSTrackingMouseEnteredAndExited|NSTrackingActiveAlways|NSTrackingAssumeInside
    I want replace it to NSTrackingMouseEnteredAndExited|NSTrackingActiveAlways|NSTrackingInVisibleRect
    But if I do it in awakeFromNib function and add breakpoint in drawRect: -- it have first value. Somewhere value overwrite before drawRect:

    Code:
     //MyButton.mm
     - (void)awakeFromNib
     {
     NSArray *a = [self trackingAreas];
     NSTrackingArea * t = [[NSTrackingArea alloc] initWithRect:(NSRect){0, 0, 100, 50} 
     options:NSTrackingMouseEnteredAndExited|NSTrackingActiveAlways|NSTrackingInVisibleRect
     owner:self 
     userInfo:nil];
     [self removeTrackingArea:[a objectAtIndex:0]];
     [self addTrackingArea:t];
     [t release];
     
     }
     
     - (void)drawRect:(NSRect)aRect
     {
     NSArray *a = [self trackingAreas];
     NSTrackingArea *t1 = [a objectAtIndex:0]; //always first value !!!
     
     [super drawRect: aRect];
     }
     
     
     
  7. kev786 thread starter macrumors newbie

    Joined:
    Jan 5, 2010
  8. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #8
    Why do you want a button to overlap other views in the first place? Can you possibly post a screenshot of what you're doing? You might be better off creating one big view that tracks the mouse and draws all the controls yourself. A button that only tracks the mouse on part of itself seems like an awkward UI.
     
  9. kev786 thread starter macrumors newbie

    Joined:
    Jan 5, 2010
    #9
    I try to use NSViewCollection for displaying items like iTunes , when mouse move over some item it will be highlighted. If I place in representation view Recessed Button - this effect work, problem appear when content scrolling and some row with items appear not all
     
  10. rossipoo macrumors regular

    Joined:
    Jun 7, 2009
    #10
    Move the button to the ContentView or another view that is big enough. In Interface Builder, you may have to position it manually since dragging the button with the mouse automatically places it inside the top most view.
     
  11. Sydde macrumors 68020

    Sydde

    Joined:
    Aug 17, 2009
    #11
    Seems like it could be as simple as overlaying part of the button with a transparent custom view when necessary to cature the troublesome mouse movements and prevent them from getting to the button.
     
  12. kev786 thread starter macrumors newbie

    Joined:
    Jan 5, 2010
    #12
    It's not help me to ((

    I attached little demo project. Maybe Recessed Button replace on the some view, but how ? Maybe exist different way to do this ? I want make interface like iTunes when on the item highlighted info icon
     

    Attached Files:

    • test.zip
      File size:
      59.2 KB
      Views:
      68
    • 1.png
      1.png
      File size:
      18.8 KB
      Views:
      41
    • 2.png
      2.png
      File size:
      15.5 KB
      Views:
      51
    • 3.png
      3.png
      File size:
      16 KB
      Views:
      35

Share This Page