Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Ole Zorn committed Sep 8, 2012
0 parents commit 86b6745
Show file tree
Hide file tree
Showing 10 changed files with 926 additions and 0 deletions.
14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
build
*.xcodeproj/*.pbxuser
*.xcodeproj/*.perspectivev3
*.xcodeproj/xcuserdata
.DS_Store
.swp
~.nib
.pbxuser
.perspective
*.perspectivev3
*.mode1v3
*.xcworkspacedata
*.xcuserstate
*xcuserdata*
18 changes: 18 additions & 0 deletions Classes/OMColorFrameView.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// OMColorFrameView.h
// OMColorHelper
//
// Created by Ole Zorn on 09/07/12.
//
//

#import <Cocoa/Cocoa.h>

@interface OMColorFrameView : NSView {

NSColor *_color;
}

@property (nonatomic, retain) NSColor *color;

@end
36 changes: 36 additions & 0 deletions Classes/OMColorFrameView.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// OMColorFrameView.m
// OMColorHelper
//
// Created by Ole Zorn on 09/07/12.
//
//

#import "OMColorFrameView.h"

@implementation OMColorFrameView

@synthesize color=_color;

- (void)drawRect:(NSRect)dirtyRect
{
[self.color setStroke];
[NSBezierPath strokeRect:NSInsetRect(self.bounds, 0.5, 0.5)];
}

- (void)setColor:(NSColor *)color
{
if (color != _color) {
[_color release];
_color = [color retain];
[self setNeedsDisplay:YES];
}
}

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

@end
63 changes: 63 additions & 0 deletions Classes/OMColorHelper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
//
// OMColorHelper.h
// OMColorHelper
//
// Created by Ole Zorn on 09/07/12.
//
//

#import <Foundation/Foundation.h>
#import <AppKit/AppKit.h>

typedef enum OMColorType {
OMColorTypeNone = 0,

OMColorTypeUIRGBA, //[UIColor colorWithRed:1.0 green:0.0 blue:0.0 alpha:1.0]
OMColorTypeUIRGBAInit, //[[UIColor alloc] initWithRed:1.0 green:0.0 blue:0.0 alpha:1.0]
OMColorTypeUIWhite, //[UIColor colorWithWhite:0.5 alpha:1.0]
OMColorTypeUIWhiteInit, //[[UIColor alloc] initWithWhite:0.5 alpha:1.0]
OMColorTypeUIConstant, //[UIColor redColor]

OMColorTypeNSRGBACalibrated, //[NSColor colorWithCalibratedRed:1.0 green:0.0 blue:0.0 alpha:1.0]
OMColorTypeNSRGBADevice, //[NSColor colorWithDeviceRed:1.0 green:0.0 blue:0.0 alpha:1.0]
OMColorTypeNSWhiteCalibrated, //[NSColor colorWithCalibratedWhite:0.5 alpha:1.0]
OMColorTypeNSWhiteDevice, //[NSColor colorWithDeviceWhite:0.5 alpha:1.0]
OMColorTypeNSConstant, //[NSColor redColor]

} OMColorType;

BOOL OMColorTypeIsNSColor(OMColorType colorType) { return colorType >= OMColorTypeNSRGBACalibrated; }

//TODO: Maybe support HSB and CMYK color types...

@class OMColorFrameView, OMPlainColorWell;

@interface OMColorHelper : NSObject {

OMPlainColorWell *_colorWell;
OMColorFrameView *_colorFrameView;
NSRange _selectedColorRange;
OMColorType _selectedColorType;
NSTextView *_textView;
NSDictionary *_constantColorsByName;

NSRegularExpression *_rgbaUIColorRegex;
NSRegularExpression *_rgbaNSColorRegex;
NSRegularExpression *_whiteNSColorRegex;
NSRegularExpression *_whiteUIColorRegex;
NSRegularExpression *_constantColorRegex;
}

@property (nonatomic, retain) OMPlainColorWell *colorWell;
@property (nonatomic, retain) OMColorFrameView *colorFrameView;
@property (nonatomic, retain) NSTextView *textView;
@property (nonatomic, assign) NSRange selectedColorRange;
@property (nonatomic, assign) OMColorType selectedColorType;

- (void)dismissColorWell;
- (void)activateColorHighlighting;
- (void)deactivateColorHighlighting;
- (NSColor *)colorInText:(NSString *)text selectedRange:(NSRange)selectedRange type:(OMColorType *)type matchedRange:(NSRangePointer)matchedRange;
- (NSString *)colorStringForColor:(NSColor *)color withType:(OMColorType)colorType;

@end
Loading

0 comments on commit 86b6745

Please sign in to comment.