Search Results

Search found 12 results on 1 pages for 'nsbezierpath'.

Page 1/1 | 1 

  • NSBezierPath with transparent fill

    - by nosedive25
    I've got a NSBezierPath that needs to have a semi-transparent fill. When I fill it with a solid color, I get the expected result. However, when filled with a semi-transparent color I get a path with a rounded stroke but an odd, rectangular fill. It looks like: Instead of filling the entire area, I get a filled rectangle inside the stoke with a small, unfilled boarder. I set up my path as follows: NSBezierPath *menuItem = [NSBezierPath bezierPathWithRoundedRect:menuItemRect xRadius:3 yRadius:3] [menuItem setLineWidth:4.0]; [menuItem setLineJoinStyle:NSRoundLineJoinStyle]; [[NSColor whiteColor] set]; [menuItem stroke]; [[NSColor colorWithCalibratedRed:0.000 green:0.000 blue:0.000 alpha:0.500] set]; [menuItem fill]; If anyones got any ideas, that would be great. Thanks

    Read the article

  • Any simple way to "resize" an NSBezierPath?

    - by d11wtq
    I have an NSBezierPath that I'm filling and stroking. I'd like to add some inner glow to the path (a light stroke, just inside of the outer stroke), and the thing that comes to mind is to use the same path shrunk by 1 pixel (the size of the line that is already )stroked. Is there a way to do this? Alternatively, is there some sort of pattern I can use when applying both a border (stroke) and a glow to a bezier path? Example, the (extremely subtle) inner glow on the Google Chrome tabs:

    Read the article

  • appendBezierPathWithGlyph fails in [NSBezierPath currentPoint]

    - by anton-schwitzgäbele
    Has anybody an idea in which case this can happen? GDB output: 0 .. 8: kill, abort, objc_exception_throw etc. 9: 0x00007fff87ea21f4 in +[NSException raise:format:] () 10: 0x00007fff8694e9e2 in -[NSBezierPath currentPoint] () 11: 0x00007fff869e3b3b in __NSAppendBezierPathWithGlyphs () 12: 0x00007fff869e5baf in -[NSBezierPath appendBezierPathWithGlyphs:count:inFont:]() 13: 0x00007fff869e2e2d in -[NSBezierPath appendBezierPathWithGlyph:inFont:] ()

    Read the article

  • Does strokeRect: of NSBezierPath always draw a transparent rect? (Cocoa OSX)

    - by Michael Minerva
    I am trying to make a custom selection box for an image view I created and I am trying to use strokeRect: from NSBezierPath but it always seems to be transparent. Called the method set to set the color the blackColor and then also tried using olorWithDeviceRed:green:blue:alpha: but no matter what I have tried the rectangle created always seems to be transparent. Is there a better method to use to draw an empty rectangle?

    Read the article

  • Making a Grid in an NSView

    - by Hooligancat
    I currently have an NSView that draws a grid pattern (essentially a guide of horizontal and vertical lines) with the idea being that a user can change the spacing of the grid and the color of the grid. The purpose of the grid is to act as a guideline for the user when lining up objects. Everything works just fine with one exception. When I resize the NSWindow by dragging the resize handle, if my grid spacing is particularly small (say 10 pixels). the drag resize becomes lethargic in nature. My drawRect code for the grid is as follows: -(void)drawRect:(NSRect)dirtyRect { NSRect thisViewSize = [self bounds]; // Set the line color [[NSColor colorWithDeviceRed:0 green:(255/255.0) blue:(255/255.0) alpha:1] set]; // Draw the vertical lines first NSBezierPath * verticalLinePath = [NSBezierPath bezierPath]; int gridWidth = thisViewSize.size.width; int gridHeight = thisViewSize.size.height; int i; while (i < gridWidth) { i = i + [self currentSpacing]; NSPoint startPoint = {i,0}; NSPoint endPoint = {i, gridHeight}; [verticalLinePath setLineWidth:1]; [verticalLinePath moveToPoint:startPoint]; [verticalLinePath lineToPoint:endPoint]; [verticalLinePath stroke]; } // Draw the horizontal lines NSBezierPath * horizontalLinePath = [NSBezierPath bezierPath]; i = 0; while (i < gridHeight) { i = i + [self currentSpacing]; NSPoint startPoint = {0,i}; NSPoint endPoint = {gridWidth, i}; [horizontalLinePath setLineWidth:1]; [horizontalLinePath moveToPoint:startPoint]; [horizontalLinePath lineToPoint:endPoint]; [horizontalLinePath stroke]; } } I suspect this is entirely to do with the way that I am drawing the grid and am open to suggestions on how I might better go about it. I can see where the inefficiency is coming in, drag-resizing the NSWindow is constantly calling the drawRect in this view as it resizes, and the closer the grid, the more calculations per pixel drag of the parent window. I was thinking of hiding the view on the resize of the window, but it doesn't feel as dynamic. I want the user experience to be very smooth without any perceived delay or flickering. Does anyone have any ideas on a better or more efficient method to drawing the grid? All help, as always, very much appreciated.

    Read the article

  • NSUndoManager won't undo editing of a NSMutableDictionary

    - by xon1c
    Hi, I'm experiencing problems with the undo operation. The following code won't undo an removeObjectForKey: operation but the redo operation setObject:ForKey: works. - (void) insertIntoDictionary:(NSBezierPath *)thePath { [[[window undoManager] prepareWithInvocationTarget:self] removeFromDictionary:thePath]; if(![[window undoManager] isUndoing]) [[window undoManager] setActionName:@"Save Path"]; NSLog(@"Object id is: %d and Key id is: %d", [currentPath objectAtIndex:0], thePath); [colorsForPaths setObject:[currentPath objectAtIndex:0] forKey:thePath]; } - (void) removeFromDictionary:(NSBezierPath *)thePath { [[[window undoManager] prepareWithInvocationTarget:self] insertIntoDictionary:thePath]; if(![[window undoManager] isUndoing]) [[window undoManager] setActionName:@"Delete Path"]; NSLog(@"Object id is: %d and Key id is: %d", [[colorsForPaths allKeys] objectAtIndex:0], thePath); [colorsForPaths removeObjectForKey:thePath]; } The output on the console looks like: // Before setObject:ForKey: Object id is: 1184384 and Key id is: 1530016 // Before removeObjectForKey: UNDO Object id is: 2413664 and Key id is: 1530016 I don't get why the Object id is different although the Key id remains the same. Is there some special undo/redo handling of NSMutableDictionary objects? thx xonic

    Read the article

  • Draw an Inset NSShadow and Inset Stroke

    - by Alexsander Akers
    I have an NSBezierPath and I want to draw in inset shadow (similar to Photoshop) inside the path. Is there anyway to do this? Also, I know you can -stroke paths, but can you stroke inside a path (similar to Stroke Inside in Photoshop)? Update This is the code I'm using. The first part makes a white shadow downwards. The second part draws the gray gradient. The third part draws the black inset shadow. Assume path is an NSBezierPath instance and that clr(...) returns an NSColor from a hex string. NSShadow * shadow = [NSShadow new]; [shadow setShadowColor: [NSColor colorWithDeviceWhite: 1.0f alpha: 0.5f]]; [shadow setShadowBlurRadius: 0.0f]; [shadow setShadowOffset: NSMakeSize(0, 1)]; [shadow set]; [shadow release]; NSGradient * gradient = [[NSGradient alloc] initWithColorsAndLocations: clr(@"#262729"), 0.0f, clr(@"#37383a"), 0.43f, clr(@"#37383a"), 1.0f, nil]; [gradient drawInBezierPath: path angle: 90.0f]; [gradient release]; [NSGraphicsContext saveGraphicsState]; [path setClip]; shadow = [NSShadow new]; [shadow setShadowColor: [NSColor redColor]]; [shadow setShadowBlurRadius: 0.0f]; [shadow setShadowOffset: NSMakeSize(0, -1)]; [shadow set]; [shadow release]; [path stroke]; [NSGraphicsContext restoreGraphicsState]; Here you can see a gradient fill, a white drop shadow downwards, and a black inner shadow downwards.

    Read the article

  • Optimize a views drawing code

    - by xon1c
    Hi, in a simple drawing application I have a model which has a NSMutableArray curvedPaths holding all the lines the user has drawn. A line itself is also a NSMutableArray, containing the point objects. As I draw curved NSBezier paths, my point array has the following structure: linePoint, controlPoint, controlPoint, linePoint, controlPoint, controlPoint, etc... I thought having one array holding all the points plus control points would be more efficient than dealing with 2 or 3 different arrays. Obviously my view draws the paths it gets from the model, which leads to the actual question: Is there a way to optimize the following code (inside the view's drawRect method) in terms of speed? int lineCount = [[model curvedPaths] count]; // Go through paths for (int i=0; i < lineCount; i++) { // Get the Color NSColor *theColor = [model getColorOfPath:[[model curvedPaths] objectAtIndex:i]]; // Get the points NSArray *thePoints = [model getPointsOfPath:[[model curvedPaths] objectAtIndex:i]]; // Create a new path for performance reasons NSBezierPath *path = [[NSBezierPath alloc] init]; // Set the color [theColor set]; // Move to first point without drawing [path moveToPoint:[[thePoints objectAtIndex:0] myNSPoint]]; int pointCount = [thePoints count] - 3; // Go through points for (int j=0; j < pointCount; j+=3) { [path curveToPoint:[[thePoints objectAtIndex:j+3] myNSPoint] controlPoint1:[[thePoints objectAtIndex:j+1] myNSPoint] controlPoint2:[[thePoints objectAtIndex:j+2] myNSPoint]]; } // Draw the path [path stroke]; // Bye stuff [path release]; [theColor release]; } Thanks, xonic

    Read the article

  • OSX: Programmatically added subviews not responding to mouse down events

    - by BigCola
    I have 3 subclasses: a Block class, a Row class and a Table class. All are subclasses of NSView. I have a Table added with IB which programmatically displays 8 rows, each of which displays 8 blocks. I overrode the mouseDown: method in Block to change the background color to red, but it doesn't work. Still if I add a block directly on top of the Table with IB it does work so I can't understand why it won't work in the first case. Here's the implementation code for Block and Row (Table's implementation works the same way as Row's): //block.m - (void)drawRect:(NSRect)dirtyRect { [color set]; [NSBezierPath fillRect:dirtyRect]; } -(void)mouseDown:(NSEvent *)theEvent { color = [NSColor redColor]; checked = YES; [self setNeedsDisplay:YES]; } //row.m - (void)drawRect:(NSRect)dirtyRect { [[NSColor blueColor] set]; [NSBezierPath fillRect:dirtyRect]; int x; for(x=0; x<8; x++){ int margin = x*2; NSRect rect = NSMakeRect(0, 50*x+margin, 50, 50); Block *block = [[Block alloc] initWithFrame:rect]; [self addSubview:block]; } }

    Read the article

  • CGGradient in an CGPath

    - by catlan
    Is it possible to draw a gradient in a path on the iPhone? I'm looking for a replacement of the mac os x method -drawInBezierPath:(NSBezierPath *)path relativeCenterPosition:(NSPoint)relativeCenterPosition of NSGradient.

    Read the article

  • Subview of custom NSView is resizing itself to fit within its superview

    - by Jonathan Patt
    I have a custom NSView which contains a subview—for the purposes of solving this issue, the top level view is simply acting as a container and automatically resizes to fit within the window. Its subview draws a rectangle 10 pixels inset from the edge of the window, except for the bottom, which should get clipped by the window until it's resized to show the entire rectangle. It does not, however, behave as I intend, and instead shrinks the height of the rectangle when its superview has a smaller height than it does. How do I avoid this and have it stay at its proper height and instead get clipped when the superview is smaller? The parent view's implementation code is: - (id)initWithFrame:(NSRect)frameRect { self = [super initWithFrame:frameRect]; if (self) { subView = [[SubView alloc] initWithFrame:frameRect]; } return self; } - (void)drawRect:(NSRect)dirtyRect { [[NSColor grayColor] set]; [subView setFrame:NSMakeRect(10, 10, dirtyRect.size.width - 20, 500)]; [self addSubview:subView]; } - (BOOL)isFlipped { return YES; } And the subview is just: - (void)drawRect:(NSRect)dirtyRect { [[NSColor blackColor] set]; [NSBezierPath strokeRect:dirtyRect]; } - (BOOL)isFlipped { return YES; }

    Read the article

  • Implementations details of drag and drop of file path in cocoa.

    - by foo
    Hi, I'm trying to get a part of my window to react to drag and drop. In this case to copy the file path to the file being dropped on the view. I have looked over some documentation but I still have some problems to see exactly where I should implement my methods for drag and drop. I have seen some examples but almost all of them assumes that I want to drop an image on the view. I'm pretty new to cocoa and Xcode so, I have some problems with seeing the exact relation between interface builder and the generated code. I have created a subclass to NSView, called drop zone like this: #import <Cocoa/Cocoa.h> @interface dropZone : NSView { } @end I then use an NSRect to color it grey like this: #import "dropZone.h" @implementation dropZone - (void)drawRect:(NSRect)rect { NSRect bounds = [self bounds]; [[NSColor grayColor] set]; [NSBezierPath fillRect:bounds]; } @end I then drag this class to my window in interface builder. But I will need to implement the registerForDraggingTypes method, but where? I have also seen a convenience method in the Apple docs for file paths like this: dragFile:fromRect:slideBack:event: that might work.

    Read the article

1