Drawing in the right window (and not in the panel)

Ask a Question related to Mac Programming, Design and Development.

  1. #1

    Default Drawing in the right window (and not in the panel)

    I'm working on an app that starts with one panel open, and no windows.
    The panel resides in the Nib file, while the windows are created by code.

    In the header:

    IBOutlet NSWindow *controlPanel; //this panel is tagged as a utility
    panel
    NSRect contentRect;
    NSWindow *fontWindow;
    FontMatrix *fontView;

    And the method that creates the window is:

    contentRect.origin.x = 40;
    contentRect.origin.y = 400;
    contentRect.size.height = 128;
    contentRect.size.width = 128;

    fontWindow = [[NSWindow alloc] initWithContentRect: contentRect
    styleMask: NSTitledWindowMask
    backing: NSBackingStoreBuffered
    defer: NO];
    [fontWindow setTitle:@"128x128"];
    [fontWindow orderFrontRegardless]; //the window won't show without
    this
    fontView = [[FontMatrix alloc] initWithFrame:[fontWindow frame]];

    [fontView drawRect:[fontView bounds]]; //all drawRect is supposed to
    do is color the view black.

    What the app is supposed to do is start with the control panel open and
    no visible windows. Menu selections should open windows and fill them
    with whatever I feel like putting in drawRect.

    What happens is that selecting a menu item only gives me an empty
    window. If I click on the window, a portion of the panel corresponding
    to the size of the window goes black.

    What's wrong is:

    1) I have to click on the new before any drawing takes place.
    2) The drawing takes place in the panel instead of the window.

    Any idea what I'm doing wrong?

    --
    C Lund, [url]www.notam02.no/~clund[/url]
    C Lund Guest

  2. Similar Questions and Discussions

    1. Combine Spry Tabbed Panel and Spry HTML Panel
      I would like to maintain the presentation of the tabbed panel and utilize its ability to load content from a Spry Dataset, but I would also like to...
    2. hide and slide the panel out of window
      Hi, I try to create a panel which has a handler that slides open the panel from the right edge of the window when clicked and slide hide the...
    3. Child window property window.opener null after postback
      I have an webform from which I open a child window to display a calendar. When a date is selected in the calendar window it attempts to set the...
    4. Drawing in Flex? Drawing and AS for custom compon
      Hey Peter, I just went to your site to check out your flex prototypes. They're pretty nice. I'm currently looking into developing something...
    5. dlopen is failing on Window XP works great on Window 2000
      Michael Davis <mdavis@sevasoftware.com> writes: Check the permission of the so file: $ ls -l...
  3. #2

    Default Re: Drawing in the right window (and not in the panel)

    In <clund-B256AC.21390203082003@amstwist00.chello.com> C Lund wrote:
    > contentRect.origin.x = 40;
    > contentRect.origin.y = 400;
    > contentRect.size.height = 128;
    > contentRect.size.width = 128;
    >
    > fontWindow = [[NSWindow alloc] initWithContentRect: contentRect
    > styleMask: NSTitledWindowMask
    > backing: NSBackingStoreBuffered
    > defer: NO];
    > [fontWindow setTitle:@"128x128"];
    > [fontWindow orderFrontRegardless]; //the window won't show without
    > this
    > fontView = [[FontMatrix alloc] initWithFrame:[fontWindow frame]];
    >
    > [fontView drawRect:[fontView bounds]];
    How to draw in a window: In PB, make an NSView subclass. Drag the header
    file into IB. In IB, make a custom NSView and drag it into a window. Set
    its class to the NSView subclass. Do your drawing in the NSView
    subclass's drawRect override. m.

    --
    matt neuburg, phd = [email]matt@tidbits.com[/email], [url]http://www.tidbits.com/matt[/url]
    REALbasic: The Definitive Guide! 2nd edition!
    [url]http://www.amazon.com/exec/obidos/ASIN/0596001770/somethingsbymatt[/url]
    Subscribe to TidBITS. It's free and smart.
    matt neuburg Guest

  4. #3

    Default Re: Drawing in the right window (and not in the panel)

    C Lund wrote:
    >
    > I'm working on an app that starts with one panel open, and no windows.
    > The panel resides in the Nib file, while the windows are created by code.
    >
    > In the header:
    >
    > IBOutlet NSWindow *controlPanel; //this panel is tagged as a utility
    > panel
    > NSRect contentRect;
    > NSWindow *fontWindow;
    > FontMatrix *fontView;
    >
    > And the method that creates the window is:
    >
    > contentRect.origin.x = 40;
    > contentRect.origin.y = 400;
    > contentRect.size.height = 128;
    > contentRect.size.width = 128;
    >
    > fontWindow = [[NSWindow alloc] initWithContentRect: contentRect
    > styleMask: NSTitledWindowMask
    > backing: NSBackingStoreBuffered
    > defer: NO];
    > [fontWindow setTitle:@"128x128"];
    > [fontWindow orderFrontRegardless]; //the window won't show without
    > this
    > fontView = [[FontMatrix alloc] initWithFrame:[fontWindow frame]];
    >
    > [fontView drawRect:[fontView bounds]]; //all drawRect is supposed to
    > do is color the view black.
    >
    > What the app is supposed to do is start with the control panel open and
    > no visible windows. Menu selections should open windows and fill them
    > with whatever I feel like putting in drawRect.
    >
    > What happens is that selecting a menu item only gives me an empty
    > window. If I click on the window, a portion of the panel corresponding
    > to the size of the window goes black.
    >
    > What's wrong is:
    >
    > 1) I have to click on the new before any drawing takes place.
    > 2) The drawing takes place in the panel instead of the window.
    >
    > Any idea what I'm doing wrong?
    In order:

    1) I don't see you putting the fontView into the fontWindow. See
    -setContentView: and -addSubView: in the NSWindow documentation.

    2) You're building a window and a view programmatically, instead of
    just creating them in the Interface Builder, like any other Cocoa
    developer would.

    Is there some reason why you want to do this the hard way?

    -jcr
    John C. Randolph Guest

  5. #4

    Default Re: Drawing in the right window (and not in the panel)

    In article <3F2DFE4D.8D2EEC80@nospam.idiom.com>,
    "John C. Randolph" <jcr@nospam.idiom.com> wrote:
    > > What's wrong is:
    > >
    > > 1) I have to click on the new before any drawing takes place.
    > > 2) The drawing takes place in the panel instead of the window.
    >
    > > Any idea what I'm doing wrong?
    > In order:
    > 1) I don't see you putting the fontView into the fontWindow. See
    > -setContentView: and -addSubView: in the NSWindow documentation.
    > 2) You're building a window and a view programmatically, instead of
    > just creating them in the Interface Builder, like any other Cocoa
    > developer would.
    > Is there some reason why you want to do this the hard way?
    I want the window+view to be resizeable via the menu. However, I forgot
    about the setFrame:display method so I tried doing it programmatically.

    Having fixed that, I now have a window+view in the Nib file that resizes
    arbitrarily via the menu plus a panel for the controls, and the app
    draws to the view without having to click in the frame. That solves #1.

    However; #2 is still a problem since the drawing now takes place not
    only where intended, but also in the area around the buttons and sliders
    and so on in the panel.
    > -jcr
    --
    C Lund, [url]www.notam02.no/~clund[/url]
    C Lund Guest

  6. #5

    Default Re: Drawing in the right window (and not in the panel)

    In article <clund-8A6CA2.10125204082003@amstwist00.chello.com>, C Lund
    <clund@NOSPAMnotam02.no> wrote:
    > In article <clund-A9EFD8.09444004082003@amstwist00.chello.com>,
    > C Lund <clund@NOSPAMnotam02.no> wrote:
    >
    > > However; #2 is still a problem since the drawing now takes place not
    > > only where intended, but also in the area around the buttons and sliders
    > > and so on in the panel.
    >
    > Turns out this was caused by a superfluous drawRect call. Problem
    > solved. B)
    >
    > (wonder why that caused stuff to be drawn in the wrong window though)
    You where manually calling drawRect if I recall correctly. drawRect
    assumes that the proper CGContext, grafPort, etc... drawable port is set
    and locked in place. You where not handeling the setup required by
    drawRect.

    The easiest thing to do is call [myView setNeedsDisplay:YES]; on the view
    you want to call DrawRect on. If you are not in some special loop,
    drawRect will be called for you on the normal event chain. Usually, this
    is fast enough. UMMV.

    -raleigh


    -----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
    [url]http://www.newsfeeds.com[/url] - The #1 Newsgroup Service in the World!
    -----== Over 80,000 Newsgroups - 16 Different Servers! =-----
    Raleigh Ledet Guest

  7. #6

    Default Re: Drawing in the right window (and not in the panel)

    In <blackgold-0408031510540001@rledet.wacom.com> Raleigh Ledet wrote:
    > In article <clund-8A6CA2.10125204082003@amstwist00.chello.com>, C Lund
    > <clund@NOSPAMnotam02.no> wrote:
    >
    > You where manually calling drawRect if I recall correctly. drawRect
    > assumes that the proper CGContext, grafPort, etc... drawable port is
    > set and locked in place. You where not handeling the setup required by
    > drawRect.
    And that is why I said to use the drawRect inside the NSView subclass.
    That way you are guaranteed that everything is ready for you to draw
    right here, in this NSView. m.

    --
    matt neuburg, phd = [email]matt@tidbits.com[/email], [url]http://www.tidbits.com/matt[/url]
    REALbasic: The Definitive Guide! 2nd edition!
    [url]http://www.amazon.com/exec/obidos/ASIN/0596001770/somethingsbymatt[/url]
    Subscribe to TidBITS. It's free and smart.
    matt neuburg Guest

  8. #7

    Default Re: Drawing in the right window (and not in the panel)

    C Lund wrote:
    >
    > In article <clund-A9EFD8.09444004082003@amstwist00.chello.com>,
    > C Lund <clund@NOSPAMnotam02.no> wrote:
    >
    > > However; #2 is still a problem since the drawing now takes place not
    > > only where intended, but also in the area around the buttons and sliders
    > > and so on in the panel.
    >
    > Turns out this was caused by a superfluous drawRect call. Problem
    > solved. B)
    >
    > (wonder why that caused stuff to be drawn in the wrong window though)
    You shouldn't need to call -drawRect: yourself at all. When you know
    that a view needs updating, call -setNeedsDisplay: or
    -setNeedsDisplayInRect:, and let the framework take care of sending
    -drawRect: messages to the view hierarchy.

    -jcr
    John C. Randolph Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139