Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

major refactoring -> readability + extensibility #42

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 0 additions & 18 deletions Classes/OMColorFrameView.h

This file was deleted.

30 changes: 0 additions & 30 deletions Classes/OMColorFrameView.m

This file was deleted.

86 changes: 37 additions & 49 deletions Classes/OMColorHelper.h
Original file line number Diff line number Diff line change
@@ -1,64 +1,52 @@
//
// OMColorHelper.h
// OMColorHelper
//
// Created by Ole Zorn on 09/07/12.
//
//

#import <Foundation/Foundation.h>
#import <AppKit/AppKit.h>
// OMColorHelper.h OMColorHelper Created by Ole Zorn on 09/07/12.

@import AppKit;

typedef NS_ENUM(int, OMColorType) {

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]
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]

} OMColorType;
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]
OMColorType6DigitHex, // #ffffff
OMColorType3DigitHex // #fff

};

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

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

@class OMColorFrameView, OMPlainColorWell;
@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;
}
@interface OMColorHelper : NSObject

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

- (void) dismissColorWell;
- (void) activateColorHighlighting;
- (void) deactivateColorHighlighting;

- (NSColor*) colorInText:(NSString*)x selectedRange:(NSRange)r
type:(OMColorType*)t matchedRange:(NSRangePointer)m;

@property (nonatomic, strong) OMPlainColorWell *colorWell;
@property (nonatomic, strong) OMColorFrameView *colorFrameView;
@property (nonatomic, strong) NSTextView *textView;
@property (nonatomic, assign) NSRange selectedColorRange;
@property (nonatomic, assign) OMColorType selectedColorType;
- (NSString*) colorStringForColor:(NSColor*)c withType:(OMColorType)t;

- (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;
- (double)dividedValue:(double)value withDivisorRange:(NSRange)divisorRange inString:(NSString *)text;
- (double) dividedValue:(double)v withDivisorRange:(NSRange)r inString:(NSString *)text;

@end
Loading