• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
[Newbie] Who's changing my radius?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Newbie] Who's changing my radius?


  • Subject: [Newbie] Who's changing my radius?
  • From: Malte <email@hidden>
  • Date: Sat, 5 Jun 2004 15:46:00 +0200

Hello Gurus, Wizards and Masters of the Art.

I apologize for asking something this trivial but i have fiddled around
for about two hours now and can't find the source of the failure.

A quick summary of the situation:
I have hacked in the "tutorial project" from a (so far) very excellent
book from a renowned publisher with an irish sounding name. :)
The goal is a little application, where you can click somewhere in a
custom made view and a little dot appears.
You should be able to change the size (radius) and color of the dot
with a slider (NSSlider) respectively a color well (NSColorWell).

My problem is this:
When i move the slider, the correct action is being invoked and i can
see the result being displayed in my log (i've inserted
NSLog(@"Messages"); all over the place).

However, then i click somewhere in my custom view but instead of being
able to marvel at a dot of the just-set-size another dot of the initial
size appears (in this case radius = 5.0;).

Apparently something is somewhere changing the radius back to the value
it has been initialized with and i can absolutely not find out where.
Since i am *t h e* programming/obj.c/cocoa newbie my possibilites to
track this down are severely limited.

I hope one of you can help me with this ridiculous situation.

Thanks!

-malte

Here's the header and implementation file of my custom-view:
(the nib file is merely a window with my custom-view, a slider
underneath and a color well in the corner. i believe everything (the
outlets and actions) is setup and connected correctly since the NSLog
messages print their log message whenever i change i.e. the slider.)

/* DotView */

#import <Cocoa/Cocoa.h>

@interface DotView : NSView
{
IBOutlet NSColorWell *colorWell;
IBOutlet NSSlider *slider;

NSPoint center;
NSColor * color;
float radius;
}

- (IBAction)setColor:(id)sender;
- (IBAction)setRadius:(id)sender;
@end

#import "DotView.h"

@implementation DotView

- (id)initWithFrame:(NSRect)frameRect
{
NSLog(@"initWithFrame");
self = [super initWithFrame:frameRect];
center.x = 50.0;
center.y = 50.0;
radius = 5.0;
color = [[NSColor redColor] retain];

return self;
}

- (void)awakeFromNib
{
NSLog(@"awakeFromNib");
[colorWell setColor:color];
[slider setFloatValue:radius];
}

- (void)dealloc
{
NSLog(@"dealloc");
[color release];
[super dealloc];
}

- (void)drawRect:(NSRect)rect
{
NSLog(@"drawRect");
NSRect dotRect;

[[NSColor whiteColor] set];
NSRectFill([self bounds]);

dotRect.origin.x = center.x - radius;
dotRect.origin.y = center.y - radius;

NSLog(@"Drawing with radius: %f", radius);
dotRect.size.width = 2 * radius;
dotRect.size.height = 2 * radius;

[color set];

[[NSBezierPath bezierPathWithOvalInRect:dotRect] fill];
}

- (BOOL)isOpaque
{
NSLog(@"isOpaque");
return YES;
}

- (void)mouseDown:(NSEvent *)event
{
NSLog(@"mouseDown --> radius: %f", radius); //RADIUS IS BACK TO 5 !!!!
NSPoint eventLocation = [event locationInWindow];
center = [self convertPoint:eventLocation fromView:nil];
[self setNeedsDisplay:YES];
}

- (IBAction)setColor:(id)sender
{
NSLog(@"setColor");
NSColor * newColor = [sender color];
[newColor retain];
[color release];
color = newColor;
[self setNeedsDisplay:YES];
}

- (IBAction)setRadius:(id)sender
{
NSLog(@"setRadius");
NSLog(@"slider changed to: %f", [sender floatValue]); //correctly
displaying the slider value
radius = [sender floatValue];
NSLog(@"new radius: %f", radius);//equivalent to the [sender
floatValue] from above -> assignment successful!
[self setNeedsDisplay:YES];
}


@end

/
************************************************************************
*******************/

--
mindprobe.net
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


  • Follow-Ups:
    • Re: [Newbie] Who's changing my radius?
      • From: Malte <email@hidden>
  • Prev by Date: More on NSTask and output to NSTextView
  • Next by Date: Re: Is that really a bug at all? (was: Re: Ugly bug in Foundation, beware!)
  • Previous by thread: Re: More on NSTask and output to NSTextView
  • Next by thread: Re: [Newbie] Who's changing my radius?
  • Index(es):
    • Date
    • Thread