青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

逛奔的蝸牛

我不聰明,但我會很努力

   ::  :: 新隨筆 ::  ::  :: 管理 ::
Learn Quartz

Introduction to Quartz

Quartz is at the center of all graphics in Cocoa. It provides basic graphics data structures and drawing routines, as well Mac OS X's window server.

This beginner-level tutorial introduces basic Cocoa graphics concepts: rectangles, points, colors, and coordinate systems. 

This tutorial is written and illustrated by Scott Stevenson
 
Copyright © 2006 Scott Stevenson

Rectangles and Points

All drawing in Quartz involves rectangles. In Cocoa, you use the NSRectstruct to describe a rectangle's location and dimensions: 

(Rects don't automatically draw themselves. These are just diagrams to go with the examples.)
 
typedef struct { NSPoint origin; NSSize size; } NSRect; // make a rect at (0,0) which is 20x20 NSRect myRect; myRect.origin.x = 0; myRect.origin.y = 0; myRect.size.width = 20; myRect.size.height = 20;
 
The origin field is the "anchor point" of the rect, where the drawing starts. A point is described by NSPoint, which has x and y coordinates:
 
typedef struct { float x; float y; } NSPoint; // make three points on the canvas NSPoint point1; point1.x = 4; point1.y = 11; NSPoint point2; point2.x = 12; point2.y = 21; NSPoint point3; point3.x = 19; point3.y = 8;
 
The size field of a rect is an NSSize, which holds a width and a height. There's no way to depict an instance of NSSize, it has to be part of a rect to be useful.
 
typedef struct { float width; float height; } NSSize;
Much of 2D drawing in Cocoa is based on these three structs. Remember these are not Objective-C classes. You can't call methods on them directly, but there are functions that go with them. 

All measurements in Quartz are float values, which gives you finer control of drawing than integer-based coordinates.

Convenience Functions

Cocoa has a number of functions for creating geometry structs. Most of them are listed in Foundation's NSGeometry.h file.
 
// make a point at coordinate 20,20 NSPoint newPoint = NSMakePoint ( 20, 20 ); // make a size of 100 wide x 100 high NSSize newSize = NSMakeSize ( 100, 100 ); // use the previous point and size to make a rect NSRect newRect = NSMakeRect ( newPoint.x, newPoint.y, newSize.width, newSize.height ); // also can just do this NSRect newRect = NSMakeRect ( 20, 20, 100, 100 );
Using these functions instead of creating the structs manually makes the code a bit more obvious and makes searching easier.
 

Coordinates in Quartz

The drawing area of a view in Cocoa is treated as a rect. Quartz calls this drawing area the "bounds." An NSPoint can represent any location in the view bounds. 

The standard Quartz coordinate system is based on PDF model, which means drawing in a view starts in the bottom-left. This is what you see in geometry textbooks. 

Sometimes it's easier to write drawing code if the origin is in the top-left. This is how things work in web page design, for example. Quartz calls this a flipped coordinate system.
 
You can easily convert points between standard and flipped views using NSView's convertPoint:fromView: and convertPoint:toView: methods.

Rects as Objects

Because they're not objects, you can't store the geometry structs in an NSArray, NSDictionary, or NSSet directly, but you can wrap them in anNSValue object:
 
NSRect newRect = NSMakeRect ( 20, 20, 100, 100 ); NSValue * rectObject = [NSValue valueWithRect: newRect]; NSMutableArray * myArray = [NSMutableArray array]; [myArray addObject: rectObject]; NSRect originalRect = [[myArray objectAtIndex: 0] rectValue];
NSValue has similar methods for NSPoint and NSSize. You can also log information about rects using the NSStringFromRect function:
 
NSRect newRect = NSMakeRect ( 20, 20, 100, 100 ); NSLog (@"%@", NSStringFromRect( newRect ));
Another function, NSRectFromString takes a properly-formatted rect description and returns an NSRect. Both sets of functions also exist for NSPoint and NSSize.

Derived Rects

Cocoa provides functions to create new rects based on existing ones. Here's how to make a rect which has the same dimensions as the original, but is shifted down and to the right (offset).
 
// create a rect, then get the 5x5 offset NSRect rect1; rect1.origin.x = 0; rect1.origin.y = 0; rect1.size.width = 30; rect1.size.height = 25; NSRect rect2; rect2 = NSOffsetRect ( rect1, 5, 5 );
 
You can use negative values for the offset if you want to move in the opposite directions. 

Here's how to get the intersection area of two rects:
 
// get the common area between two rects NSRect rect1; rect1.origin.x = 0; rect1.origin.y = 0; rect1.size.width = 30; rect1.size.height = 25; NSRect rect2; rect2 = NSOffsetRect ( rect1, 5, 5 ); NSRect rect3; rect3 = NSIntersectionRect ( rect1, rect2 );
 
Here's how to create a rect which encloses two other rects (a union).
 
// get a combination of two rects NSRect rect1; rect1.origin.x = 0; rect1.origin.y = 0; rect1.size.width = 30; rect1.size.height = 25; NSRect rect2; rect2 = NSOffsetRect ( rect1, 5, 5 ); NSRect rect3; rect3 = NSUnionRect ( rect1, rect2 );
 
An inset rect is helpful if you want to create a outer boundry, then create a rect for the content inside:
 
// get a contracted version of a rect NSRect rect1; rect1.origin.x = 0; rect1.origin.y = 0; rect1.size.width = 30; rect1.size.height = 25; NSRect rect2; rect2 = NSInsetRect ( rect1, 5, 5 );
 

Comparing Rects and Points

Foundation provides a group of functions to check the equality of points and rects, as well as functions to see if points and rects are inside in other rects.
 
NSRect rect1; rect1.origin.x = 0; rect1.origin.y = 0; rect1.size.width = 30; rect1.size.height = 25; NSPoint point1 = NSMakePoint ( 8,21 ); BOOL isInRect; isInRect = NSPointInRect ( point1, rect1 );
 
Below is a table of the most useful comparison functions. All of these functions return a YES or NO value. 

Comparison Functions
NSEqualRects Are rects identical?
NSEqualPoints Are points identical?
NSEqualSizes Are sizes identical?
NSContainsRect Does the first rect contain the other?
NSIntersectsRect Do the rects at least partially overlap?
NSPointInRect Is the point inside the rect?
NSMouseInRect Is the mouse cursor in this rect?
NSIsEmptyRect Is the rect empty (no area)?


These functions are listed in Foundation's NSGeometry.h file.

Drawing

NSRects and NSPoints only describe geometry, they don't actually do drawing. Let's look at some primitive drawing functions in Cocoa's NSGraphics.h file.
 
NSColor * gray = [NSColor grayColor]; NSColor * white = [NSColor whiteColor]; // fill background [gray set]; NSRectFill ( [self bounds] ); // fill target rect NSRect rect1 = NSMakeRect ( 21,21,210,210 ); [white set]; NSRectFill ( rect1 );
 
The example above uses NSColor. When you call the -set method on a color object, Quartz uses it for all drawing until you set a new one. 

Here's how to draw a border around a rect:
 
NSColor * gray = [NSColor grayColor]; NSColor * white = [NSColor whiteColor]; // fill background [gray set]; NSRectFill ( [self bounds] ); // draw a border around target rect NSRect rect1 = NSMakeRect ( 21,21,210,210 ); [white set]; NSFrameRectWithWidth ( rect1, 1 );
 
You can also call NSFrameRect if you just want to use the default line width.
 

Drawing Groups

It's often faster to draw an array of rects all at once instead of calling NSRectFill for each one individually. 

Below is a more involved example which builds C-style arrays of NSRects and NSColors, then passes both to NSRectFillListWithColors.
 
// setup basics [[NSColor grayColor] set]; NSRectFill ( [self bounds] ); int count = 12; NSRect startingRect = NSMakeRect ( 21,21,50,50 ); // create arrays of rects and colors NSRect rectArray [count]; NSColor * colorArray[count]; rectArray [0] = startingRect; colorArray[0] = [NSColor redColor]; // populate arrays int i; NSRect oneRect = rectArray[0]; for ( i = 1; i < count; i++ ) { // move 100 pixels to the right oneRect.origin.x += 100; // if the right edge doesn't fit, move down 100 pixels if ( NSMaxX (oneRect) > NSMaxX ([self bounds]) ) { oneRect.origin.x = startingRect.origin.x; oneRect.origin.y += 100; } rectArray [i] = oneRect; // increment color colorArray[i] = [NSColor colorWithCalibratedHue: (i*0.04) saturation: 1 brightness: 0.9 alpha: 1]; } // use rect and color arrays to fill NSRectFillListWithColors ( rectArray, colorArray, count ); // draw a 2 pixel border around each rect [[NSColor whiteColor] set]; for ( i = 0; i < count; i++) { NSFrameRectWithWidth ( rectArray[i], 2 ); }
 
This example also uses the function NSMaxX to get the maximum x-axis value of the rect (right edge). If it's outside of the view bounds, we move down to the next row.
 

Wrap Up

We've covered basic Quartz concepts here. The next tutorial will dig into intermediate topics. You can download the final example here: 

IntroToQuartz Xcode 2.4 Project (52k) 

Love it? Suggestions? Send feedback on this tutorial. 

For further reading, check out Cocoa Graphics Part II
 
Copyright © 2004-2006 Scott Stevenson
Made with TextMate
Cocoa Dev Central is a servicemark of Tree House Ideas
Site design © 2004-2006 Scott Stevenson
From: http://www.cocoadevcentral.com/d/intro_to_quartz/
@import url(http://m.shnenglu.com/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);
posted on 2011-12-02 00:15 逛奔的蝸牛 閱讀(694) 評論(0)  編輯 收藏 引用 所屬分類: Cocoa
青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            国产欧美日韩免费| 激情综合网激情| 亚洲在线成人| 一区二区激情小说| 在线一区二区视频| 中文高清一区| 亚洲在线视频免费观看| 一区二区成人精品| 亚洲无线视频| 亚洲综合首页| 欧美在线亚洲综合一区| 久久久福利视频| 另类亚洲自拍| 欧美剧在线免费观看网站| 欧美日本三级| 欧美视频在线观看视频极品| 国产精品乱子乱xxxx| 国产香蕉97碰碰久久人人| 伊人成综合网伊人222| 亚洲精品久久| 亚洲欧美激情视频在线观看一区二区三区| 亚洲一区三区电影在线观看| 欧美一二区视频| 欧美成人午夜视频| 免费视频一区| 日韩午夜剧场| 久久综合图片| 亚洲精品乱码久久久久| 91久久精品www人人做人人爽 | 亚洲专区在线| 久久久综合网站| 亚洲黄色一区二区三区| 亚洲一级网站| 免费成人性网站| 国产精品美女一区二区在线观看 | 99re66热这里只有精品3直播| 亚洲午夜精品久久| 久久综合成人精品亚洲另类欧美| 亚洲国产1区| 亚洲欧美中文字幕| 欧美日韩三级一区二区| 永久免费毛片在线播放不卡| 一级成人国产| 欧美91大片| 羞羞色国产精品| 欧美日韩一区二区高清| 亚洲国产成人精品视频| 欧美在现视频| 一区二区三区精品视频在线观看| 美女精品网站| 红桃视频国产一区| 久久成人这里只有精品| 99国产麻豆精品| 欧美精品在线免费观看| 在线看片成人| 久久久亚洲欧洲日产国码αv| 日韩一级黄色大片| 欧美欧美天天天天操| 亚洲黄色影院| 你懂的国产精品永久在线| 午夜精品影院在线观看| 欧美性猛交xxxx免费看久久久| 亚洲精品一二| 亚洲国产精品久久人人爱蜜臀 | 亚洲视频你懂的| 亚洲美女av网站| 欧美激情一区二区三区全黄| 亚洲国内自拍| 欧美激情中文字幕一区二区| 久久综合九色九九| 亚洲电影免费观看高清完整版| 久久伊人精品天天| 久久精品一本久久99精品| 久久综合狠狠| 亚洲精品视频啊美女在线直播| 欧美电影免费网站| 欧美成人一区在线| 蜜臀a∨国产成人精品| 欧美日韩一区自拍| 亚洲一区欧美二区| 亚洲免费影视第一页| 国产女主播一区二区| 久久精品久久99精品久久| 欧美一区二区三区四区夜夜大片| 国产日韩欧美综合一区| 久久综合色一综合色88| 欧美成人免费在线观看| 一区二区国产精品| 亚洲综合不卡| 韩日精品在线| 亚洲人成免费| 国产精品婷婷午夜在线观看| 久久久久久久久岛国免费| 噜噜噜躁狠狠躁狠狠精品视频| 亚洲精品女av网站| 一区二区三区日韩精品视频| 国产日产精品一区二区三区四区的观看方式 | 亚洲精品偷拍| 国产精品网曝门| 噜噜噜噜噜久久久久久91| 欧美大片免费看| 亚洲欧美日韩在线观看a三区| 久久av红桃一区二区小说| 最新日韩在线| 毛片精品免费在线观看| 欧美日本久久| 久久人人爽人人爽| 欧美日本亚洲韩国国产| 久久精品国产亚洲a| 欧美激情麻豆| 久久人人97超碰精品888| 欧美日韩视频不卡| 美女福利精品视频| 国产精品一区二区在线观看网站| 欧美高清在线精品一区| 国产欧美亚洲视频| 日韩视频三区| 亚洲人成7777| 久久激情久久| 午夜一区二区三区在线观看| 女人香蕉久久**毛片精品| 欧美在线免费播放| 欧美日韩中字| 亚洲黄色精品| 亚洲国产成人精品久久| 欧美一区二视频| 一区二区三区欧美在线| 免费不卡在线观看| 玖玖玖国产精品| 国产欧美亚洲一区| 亚洲无亚洲人成网站77777 | 亚洲高清一二三区| 久久国产精品72免费观看| 亚洲欧美日本视频在线观看| 欧美电影在线播放| 欧美91福利在线观看| 国内成人自拍视频| 亚洲国产一区二区三区在线播| 日韩视频在线观看一区二区| 国产一区二区三区成人欧美日韩在线观看| 亚洲精品视频在线看| 亚洲欧洲日产国产综合网| 久久久精品久久久久| 久久亚洲美女| 一区在线免费| 久久频这里精品99香蕉| 久久久亚洲国产天美传媒修理工| 国产乱码精品一区二区三区av| 亚洲午夜成aⅴ人片| 亚洲欧洲av一区二区| 国产精品视频yy9099| 亚洲一区二区在线视频 | 国产精品人成在线观看免费| 日韩系列在线| 亚洲午夜激情免费视频| 欧美三级视频在线| 99re6热在线精品视频播放速度| 99在线热播精品免费| 欧美日韩激情网| 亚洲视频一区二区免费在线观看| 亚洲欧美日韩一区二区在线 | 亚洲欧美在线aaa| 久久精品亚洲乱码伦伦中文 | 午夜欧美大尺度福利影院在线看| 国产精品一卡| 欧美在线日韩精品| 欧美国产日本| 亚洲在线成人| 狠狠色丁香婷综合久久| 欧美国产综合| 亚洲综合精品| 欧美aa国产视频| 中文欧美日韩| 国产一区二区三区久久悠悠色av| 开心色5月久久精品| 在线视频欧美精品| 美女精品在线| 亚洲欧美成人一区二区在线电影| 国产亚洲成精品久久| 欧美激情一区二区三区四区| 亚洲欧美久久久久一区二区三区| 男同欧美伦乱| 性做久久久久久久免费看| 亚洲国产成人不卡| 国产麻豆综合| 欧美日韩国产成人| 久久黄色级2电影| 国产精品99久久久久久人| 麻豆精品在线播放| 亚洲欧美日韩视频一区| 亚洲激情黄色| 国产日本欧美一区二区| 欧美日韩国产高清| 久久久水蜜桃| 亚洲精品视频在线观看免费| 另类综合日韩欧美亚洲| 9久草视频在线视频精品| 在线国产日韩| 国产精品老牛| 欧美肥婆在线|