페이지

2013년 12월 25일 수요일

CoreGraphics angle,clockwise direction

    //각도의 시작은 우측 수평선에서 시계방향으로 증가한다. 그런데, y 플립이기에 시계방향은 화면에서는 반시계방향이다.


    CGContextBeginPath(context);
    CGContextMoveToPoint(context, 0, 30);
    CGContextAddLineToPoint(context, 60, 30);
    CGContextAddArc(context, 60-15, 30, 15, radian(0), radian(45), false);
    CGContextAddLineToPoint(context, 60-15, 30);
    CGContextClosePath(context);

    CGContextDrawPath(context, kCGPathStroke);

2013년 2월 15일 금요일

Set up Mercurial Server on Mac OS X Server ( 10.7.5 Lion )



  • Install mercurial





after installing mercurial, type "python" and type "import mercurial" on terminal.

user$ python
Python 2.7.1 (r271:86832, Jun 25 2011, 05:09:01)
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import mercurial
>>>

if error, refer to http://mercurial.selenic.com/wiki/PublishingRepositories
(cf 3.1.1 Python and Mercurial )










  • Make hgweb script


make hgweb.cgi file in the path "/Volumes/works/hg".
and then add the following contents on it.
( in this guide, we assume that mercurial works are in the path "/Volumes/works/hg". so all config files might be there.)





#!/usr/bin/env python
#
# send python tracebacks to the browser if an error occurs:
import cgitb
cgitb.enable()

# An example CGI script to export multiple hgweb repos, edit as necessary

# adjust python path if not a system-wide install:
import sys
#input mercurial path
sys.path.insert(0, "/Library/python/2.7/site-packages/mercurial")
# enable importing on demand to reduce startup time
from mercurial import demandimport; demandimport.enable()
from mercurial.hgweb.hgwebdir_mod import hgwebdir
import mercurial.hgweb.wsgicgi as wsgicgi
application = hgwebdir('hgweb.config')
wsgicgi.launch(application)


  • hg init

type hg init command for repository.

hg init /volumes/works/hg/"repository name"

  • Make hgweb.config 



make hgweb.config file in the path "/Volumes/works/hg".
and then add the following contents on it.



#hgweb.config

[paths]
#project1 = /Volumes/works/hg/project1
#project2 = /Volumes/works/hg/project2
/ = /Volumes/works/hg/*

[web]
#visiting the given URL paths or including subrepositories
descend = True
allow_push = johnson
#allow_push = *
push_ssl = true
#for http://example.com/hg
baseurl = /hg
#for http://hg.example.com
#baseurl =


  • path

if you have only project1 repository, you can define repository's path as like

project1 = /Volumes/works/hg/project1

but, if you want to have multiple repositories, do it like this

/ = /Volumes/works/hg/*


so you can access all repositories under /Volumes/works/hg/

ex)
https://example.com/hg/project1
https://example.com/hg/project2
.... and so on.


  • allow_push

allow_push = johnson

this would allow pushing for johnson.

you can allow pushing for everyone as like this

allow_push = *


  • Defining User Credential

To make user id and password for mercurial, use htpasswd command.

htpasswd -c /Volumes/works/hg/hgusers johnson
(cf htpasswd )


and we have to change permission of repositories.


chown -R _www:_www /Volumes/works/hg
chmod -R g+rw /Volumes/works/hg
chmod -R g+x /Volumes/works/hg
chmod -R g+x /Volumes/works/hg/*
chmod -R g+x /Volumes/works/hg/*/.hg

_www is a group for apache web service.

  • Make httpd-hg.conf file

make httpd-hg.conf file in the path /Volumes/works/hg. and add the following text on it.


# Mercurial setting
ScriptAlias /hg "/volumes/works/hg/hgweb.cgi"

#restrict pushing to known users
<Location /hg>
#Require SSL authentication
SSLRequireSSL
AuthType Basic
AuthName "Mercurial repositories"
AuthUserFile /volumes/works/hg/hgusers
Require valid-user
</Location>



  • Setting Apache config file

add the following text on /etc/apache2/httpd.conf.

Include /Volumes/works/hg/httpd-hg.conf

and that's all.


if you want to know more or it doesn't work,
please refer to the link.
http://mercurial.selenic.com/wiki/PublishingRepositories









2013년 1월 20일 일요일

NSSet VS NSArray


  • NSSet
    • Primarily access items by comparison
    • Unordered
    • Does not allow duplicates
  • NSArray
    • Can access items by index
    • Ordered
    • Allows duplicates


2012년 11월 10일 토요일

Core Animation Programming Summary 2


Animation


The animation occurs automatically in a separate thread, without further interaction with your application.

Animation Classes and Timing

- CABasicAnimation
- CAKeyframeAnimation
- CATransition
- CAAnimationGroup

Implicit Animation

Implicitly animating multiple properties of multiple layers
theLayer.opacity = 0.0;
theLayer.zPosition = -100;


Explicit Animation


ex 1 
CABasicAnimation *theAnimation;
theAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"];
theAnimation.duration = 3.0;
theAnimation.repeatCount = 2;
theAnimation.autoreverse = YES;
theAnimation.fromValue = [NSNumber numberWithFloat:1.0];
theAnimation.toValue = [NSNumber numberWithFloat:0.0];
[theLayer addAnimation:theAnimation forKey:@"animateOpacity"];

ex 2

CIFileter *filter = [CIFilter filterWithName:@"CIBloom"];
[filter setDefaults];
[filter setValue:[NSNumber numberWithFloat:5.0] forKey:@"inputRadius"];
[filter setName:@"pulseFilter"];
[selectionLayer setFilters:[NSArray arrayWithObject:filter]];
CABasicAnimation* pulseAnimation = [CABasicAnimation animation];
pulseAnimation.keyPath = @"filters.pulseFilter.inputIntensity";
pulseAnimation.fromValue = [NSNumber numberWithFloat:0.0];
pulseAnimation.toValue = [NSNumber numberWithFloat:1.5];
pulseAnimation.duration = 1.0;
pulseAnimation.repeatCount = HUGE_VALF;
pulseAnimation.autoreverses = YES;
pulseAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
[selectionLayer addAnimation:pulseAnimation forKey:@"pulseAnimation"];


Starting and Stopping Explicit Animations

addAnimation:forKey:
removeAnimationForKey:
removeAllAnimations


Layer Actions


A Layer is responsible for mapping action identifiers to the appropriate action objects.
typically, action objects are an instance of a CAAnimation subclass, which implements the CAAction protocol.
When an instance of CAAnimation receives the runActionForKey:object:arguments: message it responds by adding itself to the layer's animations

The Role of Action Objects
?
Defined Search Pattern for Action Keys
?
Adopting the CAAction Protocol
?
- (void) runActionForKey:(NSString*)key
object:(id)anObject
arguments:(NSDictionary*)dict
{
[(CALayer*)anObject addAnimation:self forKey:key];
}


Overriding an Implied Animation


- (id<CAAction>)actionForLayer:(CALayer*)theLayer
forKey:(NSString*)theKey
{
CATransition *theAnimation = nil;
if ([theKey isEqualToString:@"contents"])
{
theAnimation = [[CATransition alloc] init];
theAnimation.duration = 1.0;
theAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
theAnimation.type = kCATransitionPush;
theAnimation.subtype = kCATransitionFromRight;
}
return theAnimation;
}



Implied animation for the sublayers property


NSMutableDictionary *customActions = [NSMutableDictionary dictionaryWithDictionary:[theLayer actions]];
//diable the animation for the sublayers property
[customActions setObject:[NSNull null] forKey:@"sublayers"];
theLayer.actions = customActions;



Transactions


Implicit transactions

theLayer.opacity = 0.0;
theLayer.zPosition = -200;
theLayer.position = CGPointMake(0.0, 0.0);

Explicit transactions

Explicit transactions are particularly useful when setting the properties of many layers at the same time (for example, while laying out multiple layers)

Temporarily disabling a layer's actions

[CATransaction begin];
[CATransaction setValue:(id)kCFBooleanTrue
forKey:kCATransactionDisableActions];
[aLayer removeFromSuperlayer];
[CATranscation commit];



Overriding the animation duration

[CATransaction begin];
[CATransaction setValue:[NSNumber numberWithFloat:10.0f]
forKey:kCATransactionAnimationDuration];
theLayer.zPosition = 200.0;
theLayer.opacity = 0.0;
[CATransaction commit];


Nesting explicit transactions

[CATransaction begin]; //outer transaction
//change the animation duration to 2 secs
[CATransaction setValue:[NSNumber numberWithFloat:2.0f]
forKey:kCATransactionAnimationDuration];
theLayer.position = CGPointMake(0.0, 0.0);
[CATransaction begin]; //inner transaction
[CATransaction setValue:[NSNumber numberWithFloat:5.0f]
forKey:kCATransactionAnimationDuration];
theLayer.zPosition = 200.0;
theLayer.opacity = 0.0;
[CATransaction commit]; //inner transaction
[CATransaction commit]; //outer transaction



Laying Out Core Animation Layers

Contraints Layout Manager

Default Value Support

+(id)defaultValueForKey:(NSString*) key
{
if ( [key isEqualToString:@"masksToBounds"] )
return [NSNumber numberWithBool:YES];
return [super defaultValueForKey:key];
}



myLayer.transform.rotation.x = 0; // this is wrong
[myLayer setValue:[NSNumber numberWithInt:0] forKeyPath:@"transform.rotation.x"];
//this is right.

2012년 11월 4일 일요일

Core Animation Programming Guide Summary


Core animation classes

- Layer classes that provide content for display
- Animation and timing classes
- Layout and constraint classes
- A transaction class that groups multiple layer changes into an atomic update

Layer classes

CALayer is the parent class for all types of Core animation layers.
CALayer diverges from the application kit and cocoa touch view classes in that it's not necessary to subclass CALayer in order to display content.

Animation and Timing Classes

CAAnimation adopts CAMediaTiming protocol which provides the simple duration,speed and repeat count for an animation.
and adopts CAAction protocol.

- CATransition
- CAAnimationGroup
- CAPropertyAnimation
- CABasicAnimation 
- CAKeyframeAnimation

Layout Manager Classes

- CAContraint

Transaction Management Classes


Core Animation Rendering Architecture
NSView,UIView are objects in the MVC pattern.
Core Animation Layers are model objects.
the actual display is not the layer's responsibility.

a presentation tree and a render tree.

layer-tree -> Presentation-tree -> Render-tree (Private)




Layer-tree Hierarchy


Displaying Layers in Views

[theView setLayer: theRootLayer];
[theView setWantsLayer:YES];

Adding,Removing Layers from a Hierarchy
while inserting,removing,replacing layers cause kCAOnOrderIn, kCAOnOrderOut, kCATransition triggered.

Repositioning and Resizing Layers
If a layer's needsDisplayOnBoundsChange property is YES, the layer's content is recached when the layer's bounds changes. this value is no by default.

Autoresizing Layers
CAAutoresizingMask

Clipping Sublayers
masksToBounds determines if sublayers are clipped to the parent.

Providing Layer Content

When using Cocoa views you must subclass NSVIew or UIView and implement drawRect: in order to display anything. However CALayer instances can often be used directly, without requiring subclassing. Because CALayer is a key-value coding compliant container class, that is you can store arbitrary values in any instance, subclassing can often be avoided entirely.

Providing CALayer Content

- Explicitly set the contents property of a layer instance using a CGImageRef that contains the content image.
- Specify a delegate that provides, or draws, the content.
- Subclass CALayer and override one of the display methods.

Setting the Contents Property
CALayer *theLayer;
theLayer = [CALayer layer];
theLayer.position = CGPointMake(50,50);
theLayer.bounds = CGRectMake(0,0,100,100);
theLayer.contents = theImage; //CGImageRef

Using a Delegate to Provide Content
displayLayer: or drawLayer:inContext: are called by sending it a setNeedsDisplay or setNeedsDisplayInRect: or needsDisplayOnBoundsChange = YES.

Subclassing is not required to store the state value, coz the CALayer instance acts as a key-value coding container.
- (void)displayLayer:(CALayer*)theLayer
{
if ([[theLayer valueForKey:@"state"] boolValue])
{
theLayer.contents = [someHelperObject loadStateYesImage];
}
else {
theLayer.contents = [someHelperObject loadStateNoImage];
}
}



if you must the layer's content rather than loading it from an image, use drawLayer:inContext:
- (void)drawLayer:(CALayer*)theLayer inContext:(CGContextRef)theContext
{
CGMutablePathRef thePath = CGPathCreateMutable();
CGPathMoveToPoint( thePath,NULL,15.0f,15.f);
CGPathAddCurveToPoint( thePath, NULL, 15.f,250.f,295.f,250.f,295.f,15.f );
CGContextBeginPath(theContext);
CGContextAddPath(theContext, thePath);
CGContextSetLineWidth( theContext, [[theLayer valueForKey:@"lineWidth"] floatValue]);
CGContextStokePath(theContext);
CFRelease(thePath);
}


Providing CALayer Content by Subclassing

using property rather than depending on the key-value coding container.
- (void)display{ if(self.state) { self.contents = [someHelperObject loadStateYesImage]; } else { self.contents = [someHelperObject loadStateNoImage]; }}
- (void)drawInContext:(CGContextRef)theContext{ CGMutablePathRef thePath = CGPathCreateMutable(); CGPathMoveToPoint(thePath,NULL,15.f,15.f); CGPathAddCurveToPoint(thePath,NULL,15.f,250.f,295.f,250.f,295.f,15.f); CGContextBeginPath(theContext); CGContextAddPath(theContext, thePath); CGContextSetLineWidth(theContext,self.lineWidth); CGContextSetStrokeColorWithColor(theContext, self.lineColor); CGContextStrokePath(theContext); CFRelease(thePath);}


Positioning Content Within a Layer

contentsGravity property allows you to position and scale the layer's contents image within the layer bounds. by default, the content image fills the layer's bounds entirely, ignoring the natural aspect ratio of the image.