0

My NSRect is being drawn in BrightnessView.m and it is connected to the custom class of NSView on a xib called "brightness". PanelController is connected to another xib called "controller" and that is where the slider is with the action. Panel Controller.h cannot have an outlet to the BrightnessView because it is not connected to the same xib as the one with the view. Instead of an outlet would I need just a pointer to the brightness view or will this be able to work? I added a regular pointer but this wont work

//Panel Controller.h connected to files owner on xib "Controller"

#import "BrightnessView.h"

@interface PanelController : NSWindowController
{
   BrightnessView *_myBrightnessView;

}

@property (assign) BrightnessView *BrightnessView;

@end

//Panel Controller.m

@synthesize BrightnessView = _myBrightnessView;
- (IBAction)sliderChange:(id)sender;
{
       [_myBrightnessView.self setNeedsDisplay:YES];
}

//BrightnessView.m connected to the NSView on xib "Brightness"

- (void)drawRect:(NSRect)theRect
        {
            NSLog(@"the view is drawn");
            NSRect contentRect = NSInsetRect([self bounds], 0, 0);
            NSBezierPath *path = [NSBezierPath bezierPath];

            [path moveToPoint:NSMakePoint(_arrowX, NSMaxY(contentRect))];
            [path lineToPoint:NSMakePoint(_arrowX / 2, NSMaxY(contentRect))];
            [path lineToPoint:NSMakePoint(NSMaxX(contentRect), NSMaxY(contentRect))];

            NSPoint topRightCorner = NSMakePoint(NSMaxX(contentRect), NSMaxY(contentRect));
            [path curveToPoint:NSMakePoint(NSMaxX(contentRect), NSMaxY(contentRect))
                 controlPoint1:topRightCorner controlPoint2:topRightCorner];

            [path lineToPoint:NSMakePoint(NSMaxX(contentRect), NSMinY(contentRect))];

            NSPoint bottomRightCorner = NSMakePoint(NSMaxX(contentRect), NSMinY(contentRect));
            [path curveToPoint:NSMakePoint(NSMaxX(contentRect), NSMinY(contentRect))
                 controlPoint1:bottomRightCorner controlPoint2:bottomRightCorner];

            [path lineToPoint:NSMakePoint(NSMinX(contentRect), NSMinY(contentRect))];

            [path curveToPoint:NSMakePoint(NSMinX(contentRect), NSMinY(contentRect))
                 controlPoint1:contentRect.origin controlPoint2:contentRect.origin];

            [path lineToPoint:NSMakePoint(NSMinX(contentRect), NSMaxY(contentRect))];

            NSPoint topLeftCorner = NSMakePoint(NSMinX(contentRect), NSMaxY(contentRect));
            [path curveToPoint:NSMakePoint(NSMinX(contentRect), NSMaxY(contentRect))
                 controlPoint1:topLeftCorner controlPoint2:topLeftCorner];

            [path lineToPoint:NSMakePoint(_arrowX / 2, NSMaxY(contentRect))];
            [path closePath];

            [the_Color setFill];
            [path fill];

            [NSGraphicsContext saveGraphicsState];

            NSBezierPath *clip = [NSBezierPath bezierPathWithRect:[self bounds]];
            [clip appendBezierPath:path];
            [clip addClip];

            [NSGraphicsContext restoreGraphicsState];
        }


        - (void)setArrowX:(NSInteger)value
        {
            _arrowX = value;
        }

www.mediafire.com/?66q8jv3vly1cch4 is an example of this project and how it will not work.

Grant Wilkinson
  • 1,088
  • 1
  • 13
  • 38

1 Answers1

3

You are creating a new instance of BrightnessView every time the user moves the slider. That is wrong. You should be using your existing BrightnessView instance. Your PanelController needs a property or instance variable that points to the existing instance.

rob mayoff
  • 375,296
  • 67
  • 796
  • 848
  • I updated it to point but it still wont redraw. sorry Im new at objective-c – Grant Wilkinson Feb 20 '12 at 20:48
  • 2
    Is the `brightnessView` outlet hooked up? You should check by using `NSLog` in `sliderChange:`. – rob mayoff Feb 20 '12 at 20:53
  • i tried to simplify the code to put it into stacked but updated it to show why it really isint working. they are connected to separate xib's and I cant make an outlet from the panel controller to the brightnessView – Grant Wilkinson Feb 20 '12 at 21:09
  • would i have to make them into one xib or is there another way? – Grant Wilkinson Feb 20 '12 at 21:26
  • 1
    You can connect the property in code, but without seeing more of your code I can't help you. It sounds like you need to read some documentation or work through some tutorials to learn more of the basics of Cocoa programming. – rob mayoff Feb 20 '12 at 21:38