Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5992907
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:35:58+00:00 2026-05-22T23:35:58+00:00

The following code is supposed to draw a rectangle on the mapWindow NSView. There

  • 0

The following code is supposed to draw a rectangle on the mapWindow NSView. There is another file for my program that uses the NSView window; hence why I want to have a new window. However, the rectangle does not display. Any help would be appreciated.

@interface mapWindow : NSView {@private NSView* theMapWindow;}

- (void)drawRect:(int)pointx: (int)pointy;

@property (assign) IBOutlet NSView* theMapWindow;

@end

@implementation mapWindow
@synthesize theMapWindow;
- (void)mouseDown:(NSEvent *)event 
{
    NSPoint point = [event locationInWindow];
    //NSLog( @"mouseDown location: (%f,%f)", (float) point.x, (float) point.y);
    [self drawRect:point.x:point.y];
}

- (void)drawRect:(int)pointx: (int)pointy
{
    NSLog(@"Drawing point at (%d, %d)",pointx, pointy);
    NSPoint origin = { pointx,pointy };

    NSRect rect;
    rect.origin = origin;
    rect.size.width  = 128;
    rect.size.height = 128;

    NSBezierPath * path;
    path = [NSBezierPath bezierPathWithRect:rect];

    [path setLineWidth:4];

    [[NSColor whiteColor] set];
    [path fill];

    [[NSColor grayColor] set]; 
    [path stroke];

    [theMapWindow setNeedsDisplayInRect:rect];
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T23:35:59+00:00Added an answer on May 22, 2026 at 11:35 pm

    NSView‘s drawRect: method is called on your behalf; you should use it to your drawing, as described in Drawing View Content.

    @interface mapWindow : NSView {
    
    @private
       NSView* theMapWindow;
       NSPoint drawPoint;
    }
    
    // - (void)drawRect:(int)pointx: (int)pointy;
    
    @property (assign) IBOutlet NSView* theMapWindow;
    @property (assign) NSPoint drawPoint;
    
    @end
    

    —

    @implementation mapWindow
    
    @synthesize theMapWindow, drawPoint;
    
    - (void)mouseDown:(NSEvent *)event 
    {
        NSPoint point = [event locationInWindow];
        NSLog(@"[%@ %@] mouseDown location == %@",
                  NSStringFromClass([self class]),
                  NSStringFromSelector(_cmd),
                  NSStringFromPoint(point));
    
        [self setDrawPoint:point];
    
        [self setNeedsDisplay:YES];
    
        //NSLog( @"mouseDown location: (%f,%f)", (float) point.x, (float) point.y);
        //[self drawRect:point.x:point.y];
    }
    
    - (void)drawRect:(NSRect)frame {
        NSLog(@"Drawing point at %@", NSStringFromPoint(drawPoint));
        NSRect drawFrame = NSMakeRect(point.x, point.y, 128.0, 128.0);
        [NSBezierPath setDefaultLineWidth:4];
        [[NSColor whiteColor] set];
        [NSBezierPath fillRect:drawFrame];
        [[NSColor grayColor] set]; 
        [NSBezierPath strokeRect:drawFrame];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

the following code is supposed to replace the system color that's used for window
Given the following code (it's supposed to write helloworld in a helloworld file, and
I expected the following code to print 8, 111 and 999. I supposed that
The following code supposed to read a file containing a set of molecular structures,
Background I have the following code that is supposed to refresh data when a
I'm new to C++ and inherited the following code that is supposed to transform
I am creating a SMS app the following code is supposed to: check if
The following code gives an error when it's supposed to output just std::endl :
I have the following code, which is supposed to try to parse a given
The following code is supposed to perform an AJAX request after the page loads,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.