Skip to content

Instantly share code, notes, and snippets.

@nickjs
Created October 16, 2008 19:46
Show Gist options
  • Save nickjs/17240 to your computer and use it in GitHub Desktop.
Save nickjs/17240 to your computer and use it in GitHub Desktop.
@implementation LEStickyNote : CPView
{
CPTextField _label;
id mouseDownPoint;
}
+ (id)stickyWithStringValue:(CPString)stringValue
{
return [[LEStickyNote alloc] initWithStringValue:stringValue];
}
- (id)initWithStringValue:(CPString)stringValue
{
self = [[CPView alloc] initWithFrame:CGRectMake(0,0,225,206)];
if(self)
{
[self setBackgroundColor:[CPColor colorWithPatternImage:[CPImage imageWithContentsOfFile:@"Resources/Layout/Sticky.png" size:CGSizeMake(225,206)]]];
_label = [[CPTextField alloc] initWithFrame:CGRectMake(25,15,170,200)];
[_label setStringValue:stringValue];
[_label setFont:[CPFont fontWithName:@"Marker Felt" size:16.0]];
[_label setLineBreakMode:CPLineBreakByWordWrapping];
[_label setAlignment:CPCenterTextAlignment];
// [self addSubview:_label];
}
return self;
}
- (void)mouseDown:(CPEvent)event
{
console.log('Mouse Down')
mouseDownPoint = [self convertPoint:[event locationInWindow] fromView:nil];
}
- (void)mouseUp:(CPEvent)event
{
console.log('Mouse Up')
}
- (void)mouseDragged:(CPEvent)event
{
var newPoint = [event locationInWindow];
newPoint.x -= mouseDownPoint.x;
newPoint.y -= mouseDownPoint.y;
[self setFrameOrigin:newPoint];
}
- (void)setStringValue:(CPString)stringValue
{
[_label setStringValue:stringValue];
}
- (CPString)stringValue
{
return [_label stringValue];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment