Cocoa:[システムコントロール再描画チュートリアル]:NSWindowの再描画

11299 ワード

Cocoa:[システムコントロール再描画チュートリアル]:NSWindowの再描画
NSWindow         ,   。Panel    HUD   , window  ,  window panel titile   
, HUDWindow , window titlebar , button
resize , window sheet ……    sheet window , window titlebar ~
NSWindow Texture , , 。 window , NSView content , , window 。
apple ~ class-dump ~
NSWindow.h , NSView , 。 window 。

, NSWindow , window , (
NSWindow closebutton , button NSButton,
NSThemeButton? )。
+(Class)frameViewClassForStyleMask:(unsigned int)styleMask

とても怪しいです.そしてdumpから出てきたクラスにはNSThemeFrameというクラスの方法があります.それを見て、ははは、発見しましたね.windowに関する描画方法ばかりです.だから次のことは簡単です.クラス継承NSThemeFrameを書きます.
#import <Cocoa/Cocoa.h>
#import "NSThemeFrame.h"
@interface KAThemeFrame : NSThemeFrame
{
}
@end

では、どのような関数を書き換える必要がありますか~私たちの目標はTitleBarを再描画することです.具体的なフォームの内容は再描画する必要はありません.どうせNSViewが上に上書きされるので、一つの方法で十分です.くだらないことは言わないで、コードをつけます.
#import "KAThemeFrame.h"
 
@implementation KAThemeFrame
 
- (id)contentFill
{
// This color is used only when dragging.
// Please don't try to modify the value.
return [NSColor colorWithCalibratedWhite:.13 alpha:1];
}
 
- (id)frameColor
{
return [NSColor redColor];
}
 
- (void)_drawTitleBar:(NSRect)rect
{
NSRect titleRect = [self titlebarRect];
 
// Panel style
if([self _isUtility])
{
KAGradient *titleGradient = [KAGradient gradientWithStartingColor: [NSColor colorWithCalibratedRed:0.423f green:0.423f blue:0.423f alpha:1.0]
endingColor: [NSColor colorWithCalibratedRed:0.365f green:0.365f blue:0.365f alpha:1.0]];
[titleGradient drawInRect:titleRect angle:-90];
}
// Window style
else
{
float radius = 4;
NSBezierPath *borderPath = [NSBezierPath bezierPathWithRoundedRect:titleRect cornerRadius:radius inCorners:(OSTopLeftCorner | OSTopRightCorner)];
NSBezierPath *titlebarPath = [NSBezierPath bezierPathWithRoundedRect:NSInsetRect(titleRect, 1, 1) cornerRadius:radius-1 inCorners:(OSTopLeftCorner | OSTopRightCorner)];
 
KAGradient *titleGradient = [KAGradient gradientWithStartingColor: [NSColor colorWithCalibratedRed:0.423f green:0.423f blue:0.423f alpha:1.0]
endingColor: [NSColor colorWithCalibratedRed:0.365f green:0.365f blue:0.365f alpha:1.0]];
KAGradient *borderGradient = [KAGradient gradientWithStartingColor: [NSColor colorWithCalibratedRed:0.423f green:0.423f blue:0.423f alpha:1.0]
endingColor: [NSColor colorWithCalibratedRed:0.365f green:0.365f blue:0.365f alpha:1.0]];
 
 
[[NSColor clearColor] set];
NSRectFill(titleRect);
 
[borderGradient drawInBezierPath:borderPath angle:-90];
[titleGradient drawInBezierPath:titlebarPath angle:-90];
 
}
[self _drawTitleStringIn:[self _titlebarTitleRect] withColor:[NSColor colorWithDeviceWhite:.75 alpha:1]];

    :http://www.cocoachina.com/macdev/cocoa/2010/0122/352.html


@import url(http://www.cppblog.com/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);