A few questions relative to custom views

Discussion in 'Mac Programming' started by phjo, Apr 2, 2008.

  1. phjo macrumors regular

    Jan 8, 2008

    I am in the process of writing a (simple) library for scientific 2D plotting (I am not satisfied with whatever I found so far for cocoa/objective-c, and I miss the QwtPlot library I used several times in the past, but I don't miss C++ that much...)

    Project is moving along quite well so far, with performance living up to the best expectations (plots with millions points won't be a problem) so the time I put this online for anyone to use is maybe not that far away.

    I need help though, and have a few questions :

    - the application Grapher provided by apple (under Utilities) has two modes for mouse actions which involves selection of part of the view, with a semi-transparent rectangle following the selection.

    How would you do that ? I know how to receive and follow mouse events, that is not the problem (well, not the main problem there), but I don't know how to draw this semi-transparent without having to draw again the view behind it afterwards...

    - Right now, my view is configured to move the graph when clicking on the graph and moving with button pressed (such as Grapher does when the Hand button is activated)

    It works just fine in regular window, but when I activate the Textured flag of the window, then I have to double-click in the view for the view to receive the mouse event. If I don't, a click everywhere in the window containing the view allows one to move the window, which is not what I want...

    It must be something about firstResponder, but I couldn't find out what.

    - another question : I suppose Apple wouldn't sue me for parsing the Grapher directory and borrowing there a few icons (the mouse, the hand and the zoom+ and zoom- buttons...) but maybe would you know a place to download free icons of that nature ?

  2. kainjow Moderator emeritus


    Jun 15, 2000
    I'm not an expert on efficient CoreGraphics drawing, but you could try using a subview, although that might cause the main view to draw again. You could also have your main view draw not into the view directly, but into a separate graphics context, and then draw that context onto the screen, which might be more efficient if you're not changing your main view very often. This might make it more efficient when drawing the selection rect.

    I created a sample app a while go that shows a way to use the selection rectangle. You can check it out via a 'svn co http://kaincode.googlecode.com/svn/trunk/selectionview/'

    I'm not sure if this would solve it offhand, but you could look into NSView's mouseDownCanMoveWindow method.
  3. phjo thread starter macrumors regular

    Jan 8, 2008
    A few things to try indeed, although right now I am not so sure how to do it, but it certainly gives me some directions to look for in documentation !

    As concerns the sample app selectionview I downloaded, the [self setNeedsDisplay] are precisely what I want to avoid... My hope is that by drawing some kind of a frameless semi-transparent window, I can rely on the window manager to buffer the window so that the drawRect: method is not called everytime...

    Right on the point ! It looks like it has to do with the opacity of the view, which is different on a textured window (transparent by default I guess in this case...)

    So reimplementing this method to return NO solves the problem I complained about.



Share This Page