Mercurial > projects > dstep
comparison dstep/appkit/NSColor.d @ 16:19885b43130e
Huge update, the bridge actually works now
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Sun, 03 Jan 2010 22:06:11 +0100 |
parents | |
children | b9de51448c6b |
comparison
equal
deleted
inserted
replaced
15:7ff919f595d5 | 16:19885b43130e |
---|---|
1 /** | |
2 * Copyright: Copyright (c) 2009 Jacob Carlborg. | |
3 * Authors: Jacob Carlborg | |
4 * Version: Initial created: Sep 24, 2009 | |
5 * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0) | |
6 */ | |
7 module dstep.appkit.NSColor; | |
8 | |
9 import dstep.appkit.AppKitDefines; | |
10 import dstep.appkit.NSCell; | |
11 import dstep.appkit.NSColorSpace; | |
12 import dstep.appkit.NSImage; | |
13 import dstep.appkit.NSPasteboard; | |
14 import dstep.applicationservices.coregraphics.CGBase; | |
15 import dstep.foundation.NSArray; | |
16 import dstep.foundation.NSCoder; | |
17 import dstep.foundation.NSDictionary; | |
18 import dstep.foundation.NSGeometry; | |
19 import dstep.foundation.NSObjCRuntime; | |
20 import dstep.foundation.NSObject; | |
21 import dstep.foundation.NSString; | |
22 import dstep.foundation.NSZone; | |
23 import dstep.objc.bridge.Bridge; | |
24 import dstep.objc.objc; | |
25 import dstep.quartzcore.CIColor; | |
26 | |
27 import bindings = dstep.appkit.NSColor_bindings; | |
28 | |
29 private | |
30 { | |
31 NSString NSSystemColorsDidChangeNotification_; | |
32 } | |
33 | |
34 NSString NSSystemColorsDidChangeNotification () | |
35 { | |
36 if (NSSystemColorsDidChangeNotification_) | |
37 return NSSystemColorsDidChangeNotification_; | |
38 | |
39 return NSSystemColorsDidChangeNotification_ = new NSString(bindings.NSSystemColorsDidChangeNotification); | |
40 } | |
41 | |
42 class NSColor : NSObject, INSCopying, INSCoding | |
43 { | |
44 mixin (ObjcWrap); | |
45 | |
46 this (NSCoder aDecoder) | |
47 { | |
48 super(typeof(this).alloc.initWithCoder(aDecoder).objcObject); | |
49 } | |
50 | |
51 void encodeWithCoder (NSCoder aCoder) | |
52 { | |
53 return invokeObjcSelf!(void, "encodeWithCoder:", NSCoder)(aCoder); | |
54 } | |
55 | |
56 typeof(this) initWithCoder (NSCoder aDecoder) | |
57 { | |
58 return invokeObjcSelf!(typeof(this), "initWithCoder:", NSCoder)(aDecoder); | |
59 } | |
60 | |
61 typeof(this) copyWithZone (NSZone* zone) | |
62 { | |
63 return invokeObjcSelf!(typeof(this), "copyWithZone:", NSZone*)(zone); | |
64 } | |
65 | |
66 static NSColor colorWithCalibratedWhite (CGFloat white, CGFloat alpha) | |
67 { | |
68 return invokeObjcSelfClass!(NSColor, "colorWithCalibratedWhite:alpha:", CGFloat, CGFloat)(white, alpha); | |
69 } | |
70 | |
71 static NSColor colorWithCalibratedHue (CGFloat hue, CGFloat saturation, CGFloat brightness, CGFloat alpha) | |
72 { | |
73 return invokeObjcSelfClass!(NSColor, "colorWithCalibratedHue:saturation:brightness:alpha:", CGFloat, CGFloat, CGFloat, CGFloat)(hue, saturation, brightness, alpha); | |
74 } | |
75 | |
76 static NSColor colorWithCalibratedRed (CGFloat red, CGFloat green, CGFloat blue, CGFloat alpha) | |
77 { | |
78 return invokeObjcSelfClass!(NSColor, "colorWithCalibratedRed:green:blue:alpha:", CGFloat, CGFloat, CGFloat, CGFloat)(red, green, blue, alpha); | |
79 } | |
80 | |
81 static NSColor colorWithDeviceWhite (CGFloat white, CGFloat alpha) | |
82 { | |
83 return invokeObjcSelfClass!(NSColor, "colorWithDeviceWhite:alpha:", CGFloat, CGFloat)(white, alpha); | |
84 } | |
85 | |
86 static NSColor colorWithDeviceHue (CGFloat hue, CGFloat saturation, CGFloat brightness, CGFloat alpha) | |
87 { | |
88 return invokeObjcSelfClass!(NSColor, "colorWithDeviceHue:saturation:brightness:alpha:", CGFloat, CGFloat, CGFloat, CGFloat)(hue, saturation, brightness, alpha); | |
89 } | |
90 | |
91 static NSColor colorWithDeviceRed (CGFloat red, CGFloat green, CGFloat blue, CGFloat alpha) | |
92 { | |
93 return invokeObjcSelfClass!(NSColor, "colorWithDeviceRed:green:blue:alpha:", CGFloat, CGFloat, CGFloat, CGFloat)(red, green, blue, alpha); | |
94 } | |
95 | |
96 static NSColor colorWithDeviceCyan (CGFloat cyan, CGFloat magenta, CGFloat yellow, CGFloat black, CGFloat alpha) | |
97 { | |
98 return invokeObjcSelfClass!(NSColor, "colorWithDeviceCyan:magenta:yellow:black:alpha:", CGFloat, CGFloat, CGFloat, CGFloat, CGFloat)(cyan, magenta, yellow, black, alpha); | |
99 } | |
100 | |
101 static NSColor colorWithCatalogName (NSString listName, NSString colorName) | |
102 { | |
103 return invokeObjcSelfClass!(NSColor, "colorWithCatalogName:colorName:", NSString, NSString)(listName, colorName); | |
104 } | |
105 | |
106 static NSColor colorWithColorSpace (NSColorSpace space, CGFloat* components, NSInteger numberOfComponents) | |
107 { | |
108 return invokeObjcSelfClass!(NSColor, "colorWithColorSpace:components:count:", NSColorSpace, CGFloat*, NSInteger)(space, components, numberOfComponents); | |
109 } | |
110 | |
111 static NSColor blackColor () | |
112 { | |
113 return invokeObjcSelfClass!(NSColor, "blackColor"); | |
114 } | |
115 | |
116 static NSColor darkGrayColor () | |
117 { | |
118 return invokeObjcSelfClass!(NSColor, "darkGrayColor"); | |
119 } | |
120 | |
121 static NSColor lightGrayColor () | |
122 { | |
123 return invokeObjcSelfClass!(NSColor, "lightGrayColor"); | |
124 } | |
125 | |
126 static NSColor whiteColor () | |
127 { | |
128 return invokeObjcSelfClass!(NSColor, "whiteColor"); | |
129 } | |
130 | |
131 static NSColor grayColor () | |
132 { | |
133 return invokeObjcSelfClass!(NSColor, "grayColor"); | |
134 } | |
135 | |
136 static NSColor redColor () | |
137 { | |
138 return invokeObjcSelfClass!(NSColor, "redColor"); | |
139 } | |
140 | |
141 static NSColor greenColor () | |
142 { | |
143 return invokeObjcSelfClass!(NSColor, "greenColor"); | |
144 } | |
145 | |
146 static NSColor blueColor () | |
147 { | |
148 return invokeObjcSelfClass!(NSColor, "blueColor"); | |
149 } | |
150 | |
151 static NSColor cyanColor () | |
152 { | |
153 return invokeObjcSelfClass!(NSColor, "cyanColor"); | |
154 } | |
155 | |
156 static NSColor yellowColor () | |
157 { | |
158 return invokeObjcSelfClass!(NSColor, "yellowColor"); | |
159 } | |
160 | |
161 static NSColor magentaColor () | |
162 { | |
163 return invokeObjcSelfClass!(NSColor, "magentaColor"); | |
164 } | |
165 | |
166 static NSColor orangeColor () | |
167 { | |
168 return invokeObjcSelfClass!(NSColor, "orangeColor"); | |
169 } | |
170 | |
171 static NSColor purpleColor () | |
172 { | |
173 return invokeObjcSelfClass!(NSColor, "purpleColor"); | |
174 } | |
175 | |
176 static NSColor brownColor () | |
177 { | |
178 return invokeObjcSelfClass!(NSColor, "brownColor"); | |
179 } | |
180 | |
181 static NSColor clearColor () | |
182 { | |
183 return invokeObjcSelfClass!(NSColor, "clearColor"); | |
184 } | |
185 | |
186 static NSColor controlShadowColor () | |
187 { | |
188 return invokeObjcSelfClass!(NSColor, "controlShadowColor"); | |
189 } | |
190 | |
191 static NSColor controlDarkShadowColor () | |
192 { | |
193 return invokeObjcSelfClass!(NSColor, "controlDarkShadowColor"); | |
194 } | |
195 | |
196 static NSColor controlColor () | |
197 { | |
198 return invokeObjcSelfClass!(NSColor, "controlColor"); | |
199 } | |
200 | |
201 static NSColor controlHighlightColor () | |
202 { | |
203 return invokeObjcSelfClass!(NSColor, "controlHighlightColor"); | |
204 } | |
205 | |
206 static NSColor controlLightHighlightColor () | |
207 { | |
208 return invokeObjcSelfClass!(NSColor, "controlLightHighlightColor"); | |
209 } | |
210 | |
211 static NSColor controlTextColor () | |
212 { | |
213 return invokeObjcSelfClass!(NSColor, "controlTextColor"); | |
214 } | |
215 | |
216 static NSColor controlBackgroundColor () | |
217 { | |
218 return invokeObjcSelfClass!(NSColor, "controlBackgroundColor"); | |
219 } | |
220 | |
221 static NSColor selectedControlColor () | |
222 { | |
223 return invokeObjcSelfClass!(NSColor, "selectedControlColor"); | |
224 } | |
225 | |
226 static NSColor secondarySelectedControlColor () | |
227 { | |
228 return invokeObjcSelfClass!(NSColor, "secondarySelectedControlColor"); | |
229 } | |
230 | |
231 static NSColor selectedControlTextColor () | |
232 { | |
233 return invokeObjcSelfClass!(NSColor, "selectedControlTextColor"); | |
234 } | |
235 | |
236 static NSColor disabledControlTextColor () | |
237 { | |
238 return invokeObjcSelfClass!(NSColor, "disabledControlTextColor"); | |
239 } | |
240 | |
241 static NSColor textColor () | |
242 { | |
243 return invokeObjcSelfClass!(NSColor, "textColor"); | |
244 } | |
245 | |
246 static NSColor textBackgroundColor () | |
247 { | |
248 return invokeObjcSelfClass!(NSColor, "textBackgroundColor"); | |
249 } | |
250 | |
251 static NSColor selectedTextColor () | |
252 { | |
253 return invokeObjcSelfClass!(NSColor, "selectedTextColor"); | |
254 } | |
255 | |
256 static NSColor selectedTextBackgroundColor () | |
257 { | |
258 return invokeObjcSelfClass!(NSColor, "selectedTextBackgroundColor"); | |
259 } | |
260 | |
261 static NSColor gridColor () | |
262 { | |
263 return invokeObjcSelfClass!(NSColor, "gridColor"); | |
264 } | |
265 | |
266 static NSColor keyboardFocusIndicatorColor () | |
267 { | |
268 return invokeObjcSelfClass!(NSColor, "keyboardFocusIndicatorColor"); | |
269 } | |
270 | |
271 static NSColor windowBackgroundColor () | |
272 { | |
273 return invokeObjcSelfClass!(NSColor, "windowBackgroundColor"); | |
274 } | |
275 | |
276 static NSColor scrollBarColor () | |
277 { | |
278 return invokeObjcSelfClass!(NSColor, "scrollBarColor"); | |
279 } | |
280 | |
281 static NSColor knobColor () | |
282 { | |
283 return invokeObjcSelfClass!(NSColor, "knobColor"); | |
284 } | |
285 | |
286 static NSColor selectedKnobColor () | |
287 { | |
288 return invokeObjcSelfClass!(NSColor, "selectedKnobColor"); | |
289 } | |
290 | |
291 static NSColor windowFrameColor () | |
292 { | |
293 return invokeObjcSelfClass!(NSColor, "windowFrameColor"); | |
294 } | |
295 | |
296 static NSColor windowFrameTextColor () | |
297 { | |
298 return invokeObjcSelfClass!(NSColor, "windowFrameTextColor"); | |
299 } | |
300 | |
301 static NSColor selectedMenuItemColor () | |
302 { | |
303 return invokeObjcSelfClass!(NSColor, "selectedMenuItemColor"); | |
304 } | |
305 | |
306 static NSColor selectedMenuItemTextColor () | |
307 { | |
308 return invokeObjcSelfClass!(NSColor, "selectedMenuItemTextColor"); | |
309 } | |
310 | |
311 static NSColor highlightColor () | |
312 { | |
313 return invokeObjcSelfClass!(NSColor, "highlightColor"); | |
314 } | |
315 | |
316 static NSColor shadowColor () | |
317 { | |
318 return invokeObjcSelfClass!(NSColor, "shadowColor"); | |
319 } | |
320 | |
321 static NSColor headerColor () | |
322 { | |
323 return invokeObjcSelfClass!(NSColor, "headerColor"); | |
324 } | |
325 | |
326 static NSColor headerTextColor () | |
327 { | |
328 return invokeObjcSelfClass!(NSColor, "headerTextColor"); | |
329 } | |
330 | |
331 static NSColor alternateSelectedControlColor () | |
332 { | |
333 return invokeObjcSelfClass!(NSColor, "alternateSelectedControlColor"); | |
334 } | |
335 | |
336 static NSColor alternateSelectedControlTextColor () | |
337 { | |
338 return invokeObjcSelfClass!(NSColor, "alternateSelectedControlTextColor"); | |
339 } | |
340 | |
341 static NSArray controlAlternatingRowBackgroundColors () | |
342 { | |
343 return invokeObjcSelfClass!(NSArray, "controlAlternatingRowBackgroundColors"); | |
344 } | |
345 | |
346 NSColor highlightWithLevel (CGFloat val) | |
347 { | |
348 id result = invokeObjcSelf!(id, "highlightWithLevel:", CGFloat)(val); | |
349 return result is this.objcObject ? this : (result !is null ? new NSColor(result) : null); | |
350 } | |
351 | |
352 NSColor shadowWithLevel (CGFloat val) | |
353 { | |
354 id result = invokeObjcSelf!(id, "shadowWithLevel:", CGFloat)(val); | |
355 return result is this.objcObject ? this : (result !is null ? new NSColor(result) : null); | |
356 } | |
357 | |
358 static NSColor colorForControlTint (uint controlTint) | |
359 { | |
360 return invokeObjcSelfClass!(NSColor, "colorForControlTint:", uint)(controlTint); | |
361 } | |
362 | |
363 static uint currentControlTint () | |
364 { | |
365 return invokeObjcSelfClass!(uint, "currentControlTint"); | |
366 } | |
367 | |
368 void set () | |
369 { | |
370 return invokeObjcSelf!(void, "set"); | |
371 } | |
372 | |
373 void setFill () | |
374 { | |
375 return invokeObjcSelf!(void, "setFill"); | |
376 } | |
377 | |
378 void setStroke () | |
379 { | |
380 return invokeObjcSelf!(void, "setStroke"); | |
381 } | |
382 | |
383 NSString colorSpaceName () | |
384 { | |
385 return invokeObjcSelf!(NSString, "colorSpaceName"); | |
386 } | |
387 | |
388 NSColor colorUsingColorSpaceName (NSString colorSpace) | |
389 { | |
390 id result = invokeObjcSelf!(id, "colorUsingColorSpaceName:", NSString)(colorSpace); | |
391 return result is this.objcObject ? this : (result !is null ? new NSColor(result) : null); | |
392 } | |
393 | |
394 NSColor colorUsingColorSpaceName (NSString colorSpace, NSDictionary deviceDescription) | |
395 { | |
396 id result = invokeObjcSelf!(id, "colorUsingColorSpaceName:device:", NSString, NSDictionary)(colorSpace, deviceDescription); | |
397 return result is this.objcObject ? this : (result !is null ? new NSColor(result) : null); | |
398 } | |
399 | |
400 NSColor colorUsingColorSpace (NSColorSpace space) | |
401 { | |
402 id result = invokeObjcSelf!(id, "colorUsingColorSpace:", NSColorSpace)(space); | |
403 return result is this.objcObject ? this : (result !is null ? new NSColor(result) : null); | |
404 } | |
405 | |
406 NSColor blendedColorWithFraction (CGFloat fraction, NSColor color) | |
407 { | |
408 id result = invokeObjcSelf!(id, "blendedColorWithFraction:ofColor:", CGFloat, NSColor)(fraction, color); | |
409 return result is this.objcObject ? this : (result !is null ? new NSColor(result) : null); | |
410 } | |
411 | |
412 NSColor colorWithAlphaComponent (CGFloat alpha) | |
413 { | |
414 id result = invokeObjcSelf!(id, "colorWithAlphaComponent:", CGFloat)(alpha); | |
415 return result is this.objcObject ? this : (result !is null ? new NSColor(result) : null); | |
416 } | |
417 | |
418 NSString catalogNameComponent () | |
419 { | |
420 return invokeObjcSelf!(NSString, "catalogNameComponent"); | |
421 } | |
422 | |
423 NSString colorNameComponent () | |
424 { | |
425 return invokeObjcSelf!(NSString, "colorNameComponent"); | |
426 } | |
427 | |
428 NSString localizedCatalogNameComponent () | |
429 { | |
430 return invokeObjcSelf!(NSString, "localizedCatalogNameComponent"); | |
431 } | |
432 | |
433 NSString localizedColorNameComponent () | |
434 { | |
435 return invokeObjcSelf!(NSString, "localizedColorNameComponent"); | |
436 } | |
437 | |
438 CGFloat redComponent () | |
439 { | |
440 return invokeObjcSelf!(CGFloat, "redComponent"); | |
441 } | |
442 | |
443 CGFloat greenComponent () | |
444 { | |
445 return invokeObjcSelf!(CGFloat, "greenComponent"); | |
446 } | |
447 | |
448 CGFloat blueComponent () | |
449 { | |
450 return invokeObjcSelf!(CGFloat, "blueComponent"); | |
451 } | |
452 | |
453 void getRed (CGFloat* red, CGFloat* green, CGFloat* blue, CGFloat* alpha) | |
454 { | |
455 return invokeObjcSelf!(void, "getRed:green:blue:alpha:", CGFloat*, CGFloat*, CGFloat*, CGFloat*)(red, green, blue, alpha); | |
456 } | |
457 | |
458 CGFloat hueComponent () | |
459 { | |
460 return invokeObjcSelf!(CGFloat, "hueComponent"); | |
461 } | |
462 | |
463 CGFloat saturationComponent () | |
464 { | |
465 return invokeObjcSelf!(CGFloat, "saturationComponent"); | |
466 } | |
467 | |
468 CGFloat brightnessComponent () | |
469 { | |
470 return invokeObjcSelf!(CGFloat, "brightnessComponent"); | |
471 } | |
472 | |
473 void getHue (CGFloat* hue, CGFloat* saturation, CGFloat* brightness, CGFloat* alpha) | |
474 { | |
475 return invokeObjcSelf!(void, "getHue:saturation:brightness:alpha:", CGFloat*, CGFloat*, CGFloat*, CGFloat*)(hue, saturation, brightness, alpha); | |
476 } | |
477 | |
478 CGFloat whiteComponent () | |
479 { | |
480 return invokeObjcSelf!(CGFloat, "whiteComponent"); | |
481 } | |
482 | |
483 void getWhite (CGFloat* white, CGFloat* alpha) | |
484 { | |
485 return invokeObjcSelf!(void, "getWhite:alpha:", CGFloat*, CGFloat*)(white, alpha); | |
486 } | |
487 | |
488 CGFloat cyanComponent () | |
489 { | |
490 return invokeObjcSelf!(CGFloat, "cyanComponent"); | |
491 } | |
492 | |
493 CGFloat magentaComponent () | |
494 { | |
495 return invokeObjcSelf!(CGFloat, "magentaComponent"); | |
496 } | |
497 | |
498 CGFloat yellowComponent () | |
499 { | |
500 return invokeObjcSelf!(CGFloat, "yellowComponent"); | |
501 } | |
502 | |
503 CGFloat blackComponent () | |
504 { | |
505 return invokeObjcSelf!(CGFloat, "blackComponent"); | |
506 } | |
507 | |
508 void getCyan (CGFloat* cyan, CGFloat* magenta, CGFloat* yellow, CGFloat* black, CGFloat* alpha) | |
509 { | |
510 return invokeObjcSelf!(void, "getCyan:magenta:yellow:black:alpha:", CGFloat*, CGFloat*, CGFloat*, CGFloat*, CGFloat*)(cyan, magenta, yellow, black, alpha); | |
511 } | |
512 | |
513 NSColorSpace colorSpace () | |
514 { | |
515 return invokeObjcSelf!(NSColorSpace, "colorSpace"); | |
516 } | |
517 | |
518 NSInteger numberOfComponents () | |
519 { | |
520 return invokeObjcSelf!(NSInteger, "numberOfComponents"); | |
521 } | |
522 | |
523 void getComponents (CGFloat* components) | |
524 { | |
525 return invokeObjcSelf!(void, "getComponents:", CGFloat*)(components); | |
526 } | |
527 | |
528 CGFloat alphaComponent () | |
529 { | |
530 return invokeObjcSelf!(CGFloat, "alphaComponent"); | |
531 } | |
532 | |
533 static NSColor colorFromPasteboard (NSPasteboard pasteBoard) | |
534 { | |
535 return invokeObjcSelfClass!(NSColor, "colorFromPasteboard:", NSPasteboard)(pasteBoard); | |
536 } | |
537 | |
538 void writeToPasteboard (NSPasteboard pasteBoard) | |
539 { | |
540 return invokeObjcSelf!(void, "writeToPasteboard:", NSPasteboard)(pasteBoard); | |
541 } | |
542 | |
543 static NSColor colorWithPatternImage (NSImage image) | |
544 { | |
545 return invokeObjcSelfClass!(NSColor, "colorWithPatternImage:", NSImage)(image); | |
546 } | |
547 | |
548 NSImage patternImage () | |
549 { | |
550 return invokeObjcSelf!(NSImage, "patternImage"); | |
551 } | |
552 | |
553 void drawSwatchInRect (NSRect rect) | |
554 { | |
555 return invokeObjcSelf!(void, "drawSwatchInRect:", NSRect)(rect); | |
556 } | |
557 | |
558 static void setIgnoresAlpha (bool flag) | |
559 { | |
560 return invokeObjcSelfClass!(void, "setIgnoresAlpha:", bool)(flag); | |
561 } | |
562 | |
563 static bool ignoresAlpha () | |
564 { | |
565 return invokeObjcSelfClass!(bool, "ignoresAlpha"); | |
566 } | |
567 | |
568 } | |
569 | |
570 const TNSAppKitColorExtensions = ` | |
571 | |
572 NSColor decodeNXColor () | |
573 { | |
574 return invokeObjcSelf!(NSColor, "decodeNXColor"); | |
575 } | |
576 | |
577 //mixin ObjcBindMethod!(decodeNXColor, "decodeNXColor"); | |
578 | |
579 `; | |
580 | |
581 const TNSAppKitAdditions = ` | |
582 | |
583 NSAppKitAdditions initWithColor (NSColor color) | |
584 { | |
585 id result = invokeObjcSelf!(id, "initWithColor:", NSColor)(color); | |
586 return result is this.objcObject ? this : (result !is null ? new NSAppKitAdditions(result) : null); | |
587 } | |
588 | |
589 this (NSColor color) | |
590 { | |
591 super(NSAppKitAdditions.alloc.initWithColor(color).objcObject); | |
592 } | |
593 | |
594 //mixin ObjcBindMethod!(initWithColor, "initWithColor:"); | |
595 | |
596 `; | |
597 |