Professional Web Applications Themes

Drawing in the right window (and not in the panel) - Mac Programming

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 ...

  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. #2

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

    In <clund-B256AC.21390203082003amstwist00.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]matttidbits.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

  3. #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 doentation.

    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

  4. #4

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

    In article <3F2DFE4D.8D2EEC80nospam.idiom.com>,
    "John C. Randolph" <jcrnospam.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 doentation.
    > 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

  5. #5

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

    In article <clund-8A6CA2.10125204082003amstwist00.chello.com>, C Lund
    <clundNOSPAMnotam02.no> wrote:
    > In article <clund-A9EFD8.09444004082003amstwist00.chello.com>,
    > C Lund <clundNOSPAMnotam02.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

  6. #6

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

    In <blackgold-0408031510540001rledet.wacom.com> Raleigh Ledet wrote:
    > In article <clund-8A6CA2.10125204082003amstwist00.chello.com>, C Lund
    > <clundNOSPAMnotam02.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]matttidbits.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

  7. #7

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

    C Lund wrote:
    >
    > In article <clund-A9EFD8.09444004082003amstwist00.chello.com>,
    > C Lund <clundNOSPAMnotam02.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

Similar Threads

  1. Combine Spry Tabbed Panel and Spry HTML Panel
    By Fishbine in forum Macromedia Exchange Dreamweaver Extensions
    Replies: 1
    Last Post: December 4th, 06:08 PM
  2. New Window Target doesn't open a new window inContribute but does in Firefox
    By toddtemple2 in forum Macromedia Contribute General Discussion
    Replies: 1
    Last Post: January 8th, 08:36 PM
  3. hide and slide the panel out of window
    By drkshih in forum Macromedia Flex General Discussion
    Replies: 3
    Last Post: July 13th, 04:39 PM
  4. Child window property window.opener null after postback
    By MrFez in forum ASP.NET Security
    Replies: 1
    Last Post: April 28th, 06:43 PM
  5. Drawing in Flex? Drawing and AS for custom compon
    By yoway in forum Macromedia Flex General Discussion
    Replies: 0
    Last Post: April 18th, 10:19 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not 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