<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Th30z - Coding on the Fly &#187; NSView</title>
	<atom:link href="http://th30z.netsons.org/tag/nsview/feed/" rel="self" type="application/rss+xml" />
	<link>http://th30z.netsons.org</link>
	<description>Matteo Bertozzi, Objective-C, Cocoa, C, C++, Qt4, iPhone, Mac OS X, Open Moko, Matteo Bertozzi Development</description>
	<lastBuildDate>Sun, 22 Nov 2009 09:47:19 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Cocoa: Drag &amp; Drop</title>
		<link>http://th30z.netsons.org/2009/02/cocoa-drag-drop/</link>
		<comments>http://th30z.netsons.org/2009/02/cocoa-drag-drop/#comments</comments>
		<pubDate>Sat, 28 Feb 2009 10:58:37 +0000</pubDate>
		<dc:creator>Matteo Bertozzi</dc:creator>
				<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[Drag & Drop]]></category>
		<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[NSView]]></category>

		<guid isPermaLink="false">http://th30z.netsons.org/?p=554</guid>
		<description><![CDATA[Today a simple example of Drag &#38; Drop with Cocoa and NSView. The screenshot below shows two groups. In the first one, you can drop the photos on your filesystem, taken from Desktop or Finder. In the second group, you can only drop the first group image.

You can find the source code here: Drag &#38; [...]]]></description>
			<content:encoded><![CDATA[<p>Today a simple example of Drag &amp; Drop with Cocoa and NSView. The screenshot below shows two groups. In the first one, you can drop the photos on your filesystem, taken from Desktop or Finder. In the second group, you can only drop the first group image.</p>
<p><a href="http://th30z.netsons.org/wp-content/uploads/cocoa-draganddrop.png"><img class="aligncenter size-medium wp-image-555" title="Cocoa Drag &amp; Drop Test App" src="http://th30z.netsons.org/wp-content/uploads/cocoa-draganddrop-350x175.png" alt="Cocoa Drag &amp; Drop Test App" width="350" height="175" /></a></p>
<p>You can find the source code here: <a href="http://th30z.netsons.org/wp-content/uploads/cocoa-draganddroptest.zip">Drag &amp; Drop Test Source Code</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://th30z.netsons.org/2009/02/cocoa-drag-drop/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Cocoa: VBox View and NSScrollView</title>
		<link>http://th30z.netsons.org/2008/11/cocoa-vbox-view-and-nsscrollview/</link>
		<comments>http://th30z.netsons.org/2008/11/cocoa-vbox-view-and-nsscrollview/#comments</comments>
		<pubDate>Sun, 16 Nov 2008 09:19:11 +0000</pubDate>
		<dc:creator>Matteo Bertozzi</dc:creator>
				<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[NSScrollView]]></category>
		<category><![CDATA[NSView]]></category>

		<guid isPermaLink="false">http://th30z.netsons.org/?p=299</guid>
		<description><![CDATA[Following the post of yesterday, today I&#8217;ve implemented a simple VBoxView (Vertical Box Layout) that allow you to lines up NSViews vertically.
br />
Here you can find the example Source Code.
]]></description>
			<content:encoded><![CDATA[<p>Following the post of yesterday, today I&#8217;ve implemented a simple VBoxView (Vertical Box Layout) that allow you to lines up NSViews vertically.<br />
<div id="attachment_300" class="wp-caption aligncenter" style="width: 567px"><a href="http://th30z.netsons.org/wp-content/uploads/cocoascrollablensview.png"><img src="http://th30z.netsons.org/wp-content/uploads/cocoascrollablensview.png" alt="Cocoa Scrollable NSViews VBox" title="Cocoa Scrollable NSViews VBox" width="557" height="329" class="size-full wp-image-300" /></a><p class="wp-caption-text">Cocoa Scrollable NSViews VBox</p></div><br />
Here you can find the example <a href="http://th30z.netsons.org/wp-content/uploads/cocoavboxscrollview.zip">Source Code</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://th30z.netsons.org/2008/11/cocoa-vbox-view-and-nsscrollview/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Cocoa: Drawing Images, Texts and Shadows</title>
		<link>http://th30z.netsons.org/2008/11/cocoa-drawing-images-texts-and-shadows/</link>
		<comments>http://th30z.netsons.org/2008/11/cocoa-drawing-images-texts-and-shadows/#comments</comments>
		<pubDate>Sat, 15 Nov 2008 10:23:17 +0000</pubDate>
		<dc:creator>Matteo Bertozzi</dc:creator>
				<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[NSView]]></category>

		<guid isPermaLink="false">http://th30z.netsons.org/?p=286</guid>
		<description><![CDATA[Today I&#8217;m playing a bit with Quartz and Cocoa Drawing system (that is based on Quartz).
I&#8217;ve made a simple example that you can see below where I&#8217;ve used custom NSView that draws an Image and a Bezier Path with some text inside, and around the Bezier Path there&#8217;s a Shadow.
&#8230;And this is the drawRect method [...]]]></description>
			<content:encoded><![CDATA[<p>Today I&#8217;m playing a bit with Quartz and Cocoa Drawing system (that is based on Quartz).</p>
<p>I&#8217;ve made a simple example that you can see below where I&#8217;ve used custom NSView that draws an Image and a Bezier Path with some text inside, and around the Bezier Path there&#8217;s a Shadow.</p>
<div id="attachment_287" class="wp-caption aligncenter" style="width: 577px"><a href="http://th30z.netsons.org/wp-content/uploads/cocoansviewdrawings.png"><img src="http://th30z.netsons.org/wp-content/uploads/cocoansviewdrawings.png" alt="Cocoa Drawing Example" title="Cocoa Drawing Example" width="567" height="243" class="size-full wp-image-287" /></a><p class="wp-caption-text">Cocoa Drawing Example</p></div>
<p>&#8230;And this is the drawRect method source code of the custom NSView.</p>
<pre>
- (void)drawRect:(NSRect)frameRect {
  [NSGraphicsContext saveGraphicsState];

  [[NSColor colorWithCalibratedRed:0.64 green:0.66 blue:0.71 alpha:1.0] set];
  NSRectFill(frameRect);

  /* Draw Shadow */
  NSShadow *shadow = [[NSShadow alloc] init];
  [shadow setShadowColor:[[NSColor blackColor] colorWithAlphaComponent:0.5]];
  [shadow setShadowOffset:NSMakeSize(4.0, -4.0)];
  [shadow setShadowBlurRadius:3.0];
  [shadow set];

  /* Draw Control */
  NSRect myRect = NSMakeRect(80, 50, frameRect.size.width - 120, 60);
  NSBezierPath *path = [NSBezierPath bezierPath];
  [path setLineJoinStyle:NSRoundLineJoinStyle];
  [path appendBezierPathWithRoundedRect:myRect xRadius:8.0 yRadius:8.0];    

  [path moveToPoint:NSMakePoint(80, 75)];
  [path lineToPoint:NSMakePoint(65, 85)];
  [path lineToPoint:NSMakePoint(80, 95)];

  NSColor *startingColor = [NSColor colorWithCalibratedRed:0.90
                                             green:0.92 blue:0.85 alpha:1.0];
  NSColor *endingColor = [NSColor colorWithCalibratedRed:0.81
                                           green:0.83 blue:0.76 alpha:1.0];
  NSGradient *gradient = [[[NSGradient alloc] initWithStartingColor:startingColor
                                 endingColor:endingColor] autorelease];
  [path fill];
  [gradient drawInBezierPath:path angle:90];

  [NSGraphicsContext restoreGraphicsState];

  [shadow release];

  NSImage *image = [NSImage imageNamed:NSImageNameUser];
  [image drawInRect:NSMakeRect(15, 50, 50, 50) fromRect:NSZeroRect
                operation:NSCompositeSourceOver fraction:1.0];

  NSString *string = [NSString stringWithString:@"Text\nMore Text"];
  [string drawInRect:NSMakeRect(90, 60, frameRect.size.width - 140, 45)
                        withAttributes:nil];
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://th30z.netsons.org/2008/11/cocoa-drawing-images-texts-and-shadows/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cocoa: Filterbar Control</title>
		<link>http://th30z.netsons.org/2008/11/cocoa-filterbar-control/</link>
		<comments>http://th30z.netsons.org/2008/11/cocoa-filterbar-control/#comments</comments>
		<pubDate>Sun, 09 Nov 2008 19:30:10 +0000</pubDate>
		<dc:creator>Matteo Bertozzi</dc:creator>
				<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[NSView]]></category>

		<guid isPermaLink="false">http://th30z.netsons.org/?p=273</guid>
		<description><![CDATA[This morning I&#8217;ve created this FilterBar (take a look at the picture below). You can add custom NSView and you can manage you groups with delegates.
Below, I&#8217;ve added a movie&#8230; but it doesn&#8217;t [sizeToFit] the page&#8230; so here is the link of Cocoa Filterbar Demo. And here you can find the Cocoa Filterbar Souce.

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_cocoafilterbardemo_1374049199"
			class="flashmovie"
			width="400"
			height="100%">
	<param name="movie" value="http://th30z.netsons.org/wp-content/uploads/cocoafilterbardemo.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://th30z.netsons.org/wp-content/uploads/cocoafilterbardemo.swf"
			name="fm_cocoafilterbardemo_1374049199"
			width="400"
			height="100%">
	<!--<![endif]-->
		
	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>]]></description>
			<content:encoded><![CDATA[<p>This morning I&#8217;ve created this <strong>FilterBar</strong> (take a look at the picture below). You can add custom NSView and you can manage you groups with delegates.</p>
<div id="attachment_274" class="wp-caption aligncenter" style="width: 510px"><a href="http://th30z.netsons.org/wp-content/uploads/cocoafilterbardemo.png"><img class="size-full wp-image-274" title="Cocoa Filterbar Demo" src="http://th30z.netsons.org/wp-content/uploads/cocoafilterbardemo.png" alt="Cocoa Filterbar Demo" width="500" height="134" /></a><p class="wp-caption-text">Cocoa Filterbar Demo</p></div>
<p>Below, I&#8217;ve added a movie&#8230; but it doesn&#8217;t [sizeToFit] the page&#8230; so here is the link of <a href="http://th30z.netsons.org/wp-content/uploads/cocoafilterbardemo.swf">Cocoa Filterbar Demo</a>. And here you can find the <a href="http://th30z.netsons.org/wp-content/uploads/cocoafilterbar.zip">Cocoa Filterbar Souce</a>.</p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_cocoafilterbardemo_1439686354"
			class="flashmovie"
			width="100%"
			height="100%">
	<param name="movie" value="http://th30z.netsons.org/wp-content/uploads/cocoafilterbardemo.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://th30z.netsons.org/wp-content/uploads/cocoafilterbardemo.swf"
			name="fm_cocoafilterbardemo_1439686354"
			width="100%"
			height="100%">
	<!--<![endif]-->
		
	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
]]></content:encoded>
			<wfw:commentRss>http://th30z.netsons.org/2008/11/cocoa-filterbar-control/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cocoa: Horizontal Box</title>
		<link>http://th30z.netsons.org/2008/11/cocoa-horizontal-box/</link>
		<comments>http://th30z.netsons.org/2008/11/cocoa-horizontal-box/#comments</comments>
		<pubDate>Sat, 08 Nov 2008 17:43:24 +0000</pubDate>
		<dc:creator>Matteo Bertozzi</dc:creator>
				<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[NSView]]></category>

		<guid isPermaLink="false">http://th30z.netsons.org/?p=264</guid>
		<description><![CDATA[It&#8217;s a couple of days that I&#8217;m searching for something like QHBoxLayout (Qt Horizonal Box Layout) in Cocoa. There&#8217;s NSMatrix that do something like this&#8230; but it uses NSCell and it sets the same size for all the cells, so this is not what I want. My solution is a simple NSView subclass&#8230;

This is the [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s a couple of days that I&#8217;m searching for something like QHBoxLayout (Qt Horizonal Box Layout) in Cocoa. There&#8217;s <em>NSMatrix</em> that do something like this&#8230; but it uses <em>NSCell</em> and it sets the same size for all the cells, so this is not what I want. My solution is a simple <em>NSView subclass</em>&#8230;</p>
<div id="attachment_265" class="wp-caption aligncenter" style="width: 510px"><a href="http://th30z.netsons.org/wp-content/uploads/testcocoahbox.png"><img class="size-full wp-image-265" title="Cocoa Horizontal Box" src="http://th30z.netsons.org/wp-content/uploads/testcocoahbox.png" alt="Example: Cocoa Horizontal Box" width="500" height="185" /></a><p class="wp-caption-text">Example: Cocoa Horizontal Box</p></div>
<p><span id="more-264"></span><br />
This is the HBox Source&#8230;</p>
<pre>@interface HBox : NSView {
    NSUInteger hspace;
}

@property (readwrite, assign) NSUInteger space;

- (id)initWithFrame:(NSRect)frameRect;

- (void)clearItems;

- (void)addItem:(NSControl *)itemView;
- (void)removeItemAtIndex:(NSUInteger)index;

- (void)moveItem:(NSView *)view space:(NSInteger)space;
- (void)moveItems:(NSInteger) space fromIndex:(NSUInteger)index;
@end</pre>
<pre>@implementation HBox

@synthesize space = hspace;

- (id)initWithFrame:(NSRect)frameRect {
    if ((self = [super initWithFrame:frameRect])) {
        hspace = 4;
    }
    return self;
}

- (void)dealloc {
    [super dealloc];
}

- (void)clearItems {
    NSArray *subviewArray = [self subviews];
    NSUInteger subviewCount = [subviewArray count];

    while (subviewCount-- &gt; 0) {
        NSView *view = [subviewArray objectAtIndex:0];
        [view removeFromSuperview];
        [view release];
    }

    [self setNeedsDisplay:YES];
}

- (void)removeItemAtIndex:(NSUInteger)index {
    NSView *view = [[self subviews] objectAtIndex:index];
    int viewWidth = -1 * [view frame].size.width - hspace;
    [view removeFromSuperview];
    [view release];

    [self moveItems:viewWidth fromIndex:index];
    [self setNeedsDisplay:YES];
}

- (void)moveItem:(NSView *)view space:(NSInteger)space {
    NSRect rect = [view frame];
    rect.origin.x += space;
    [view setFrame:rect];
}

- (void)moveItems:(NSInteger) space fromIndex:(NSUInteger)index {
    NSArray *subviewArray = [self subviews];
    NSUInteger subviewCount = [subviewArray count];

    for (; index &lt; subviewCount; ++index)
        [self moveItem:[subviewArray objectAtIndex:index] space:space];
}

- (void)addItem:(NSControl *)itemView {
    [itemView sizeToFit];

    NSRect itemFrame = [itemView frame];
    NSView *lastView = [[self subviews] lastObject];
    if (lastView != nil) {
        itemFrame.origin.x = [lastView frame].origin.x +
                             [lastView frame].size.width +
                             hspace;
    } else {
        itemFrame.origin.x = [self bounds].origin.x + hspace;
    }
    itemFrame.origin.y = [self bounds].origin.y;
    [itemView setFrame:itemFrame];

    [self addSubview:itemView];
    [self setNeedsDisplay:YES];
}

@end</pre>
<p>And This is a simple &#8220;Main&#8221; to test the HBox.</p>
<pre>
- (NSTextField *)createTextField:(NSString *)text {
    NSTextField *field = [[NSTextField alloc] init];
    [field setStringValue:text];
    return [field retain];
}

- (NSButton *)createButton:(NSString *)caption {
    NSButton *button = [[NSButton alloc] init];
    [button setBezelStyle:NSRecessedBezelStyle];
    [button setButtonType:NSPushOnPushOffButton];
    [[button cell] setHighlightsBy:(NSCellIsBordered | NSCellIsInsetButton)];
    [button setShowsBorderOnlyWhileMouseInside:YES];
    [button setButtonType:NSOnOffButton];
    [button setTitle:caption];

    return [button retain];
}

- (void)awakeFromNib {
    [box addItem:[self createTextField:@"Label 1"]];
    [box addItem:[self createButton:@"Button 1"]];
    [box removeItemAtIndex:0];
    [box addItem:[self createTextField:@"Label 2"]];
    [box addItem:[self createButton:@"Say"]];
}
</pre>
<p>Download Here the <a href='http://th30z.netsons.org/wp-content/uploads/testcocoahbox.zip'>Test Cocoa HBox Source</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://th30z.netsons.org/2008/11/cocoa-horizontal-box/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cocoa: Image Pattern as NSView Background</title>
		<link>http://th30z.netsons.org/2008/10/cocoa-image-pattern-as-nswindow-background/</link>
		<comments>http://th30z.netsons.org/2008/10/cocoa-image-pattern-as-nswindow-background/#comments</comments>
		<pubDate>Sat, 25 Oct 2008 15:11:46 +0000</pubDate>
		<dc:creator>Matteo Bertozzi</dc:creator>
				<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[NSView]]></category>

		<guid isPermaLink="false">http://th30z.netsons.org/?p=216</guid>
		<description><![CDATA[I Really like Apple Mail Note Editor, and today I&#8217;ve tried to do something like notes of Mail.app
Mail uses html and css loaded into a WebView (WebKit) to render the background of the window. I&#8217;ve used a simple NSView, I&#8217;ve Inherited from it and I&#8217;ve added a couple of feature to render an image as background [...]]]></description>
			<content:encoded><![CDATA[<p>I Really like Apple Mail Note Editor, and today I&#8217;ve tried to do something like notes of Mail.app</p>
<p>Mail uses html and css loaded into a WebView (WebKit) to render the background of the window. I&#8217;ve used a simple NSView, I&#8217;ve Inherited from it and I&#8217;ve added a couple of feature to render an image as background pattern. Below you can see the result and here you can <a href="http://th30z.netsons.org/wp-content/uploads/cocoa-winbgimg.zip">Download the Source</a>.</p>
<div id="attachment_215" class="wp-caption aligncenter" style="width: 443px"><a href="http://th30z.netsons.org/wp-content/uploads/cocoawindowbgimage.png"><img class="size-full wp-image-215" title="NSWindow with Image Pattern as Background" src="http://th30z.netsons.org/wp-content/uploads/cocoawindowbgimage.png" alt="NSWindow with Image Pattern as Background" width="433" height="298" /></a><p class="wp-caption-text">NSWindow with Image Pattern as Background</p></div>
]]></content:encoded>
			<wfw:commentRss>http://th30z.netsons.org/2008/10/cocoa-image-pattern-as-nswindow-background/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
