Mercurial > projects > dstep
comparison dstep/appkit/NSGraphicsContext.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.NSGraphicsContext; | |
8 | |
9 import dstep.appkit.AppKitDefines; | |
10 import dstep.appkit.NSBitmapImageRep; | |
11 import dstep.appkit.NSGraphics; | |
12 import dstep.appkit.NSWindow; | |
13 import dstep.foundation.NSDictionary; | |
14 import dstep.foundation.NSGeometry; | |
15 import dstep.foundation.NSObjCRuntime; | |
16 import dstep.foundation.NSObject; | |
17 import dstep.foundation.NSString; | |
18 import dstep.objc.bridge.Bridge; | |
19 import dstep.objc.objc; | |
20 import dstep.quartzcore.CIContext; | |
21 | |
22 import bindings = dstep.appkit.NSGraphicsContext_bindings; | |
23 | |
24 typedef NSUInteger NSImageInterpolation; | |
25 typedef NSInteger NSColorRenderingIntent; | |
26 | |
27 private | |
28 { | |
29 NSString NSGraphicsContextDestinationAttributeName_; | |
30 NSString NSGraphicsContextRepresentationFormatAttributeName_; | |
31 NSString NSGraphicsContextPSFormat_; | |
32 NSString NSGraphicsContextPDFFormat_; | |
33 } | |
34 | |
35 NSString NSGraphicsContextDestinationAttributeName () | |
36 { | |
37 if (NSGraphicsContextDestinationAttributeName_) | |
38 return NSGraphicsContextDestinationAttributeName_; | |
39 | |
40 return NSGraphicsContextDestinationAttributeName_ = new NSString(bindings.NSGraphicsContextDestinationAttributeName); | |
41 } | |
42 | |
43 NSString NSGraphicsContextRepresentationFormatAttributeName () | |
44 { | |
45 if (NSGraphicsContextRepresentationFormatAttributeName_) | |
46 return NSGraphicsContextRepresentationFormatAttributeName_; | |
47 | |
48 return NSGraphicsContextRepresentationFormatAttributeName_ = new NSString(bindings.NSGraphicsContextRepresentationFormatAttributeName); | |
49 } | |
50 | |
51 NSString NSGraphicsContextPSFormat () | |
52 { | |
53 if (NSGraphicsContextPSFormat_) | |
54 return NSGraphicsContextPSFormat_; | |
55 | |
56 return NSGraphicsContextPSFormat_ = new NSString(bindings.NSGraphicsContextPSFormat); | |
57 } | |
58 | |
59 NSString NSGraphicsContextPDFFormat () | |
60 { | |
61 if (NSGraphicsContextPDFFormat_) | |
62 return NSGraphicsContextPDFFormat_; | |
63 | |
64 return NSGraphicsContextPDFFormat_ = new NSString(bindings.NSGraphicsContextPDFFormat); | |
65 } | |
66 | |
67 enum | |
68 { | |
69 NSImageInterpolationDefault, | |
70 NSImageInterpolationNone, | |
71 NSImageInterpolationLow, | |
72 NSImageInterpolationHigh | |
73 } | |
74 | |
75 enum | |
76 { | |
77 NSColorRenderingIntentDefault, | |
78 NSColorRenderingIntentAbsoluteColorimetric, | |
79 NSColorRenderingIntentRelativeColorimetric, | |
80 NSColorRenderingIntentPerceptual, | |
81 NSColorRenderingIntentSaturation | |
82 } | |
83 | |
84 const TNSQuartzCoreAdditions = ` | |
85 | |
86 CIContext CIContext_ () | |
87 { | |
88 return invokeObjcSelf!(CIContext, "CIContext"); | |
89 } | |
90 | |
91 //mixin ObjcBindMethod!(CIContext_, "CIContext"); | |
92 | |
93 `; | |
94 | |
95 const TNSGraphicsContext_RenderingOptions = ` | |
96 | |
97 void setShouldAntialias (bool antialias) | |
98 { | |
99 return invokeObjcSelf!(void, "setShouldAntialias:", bool)(antialias); | |
100 } | |
101 | |
102 bool shouldAntialias () | |
103 { | |
104 return invokeObjcSelf!(bool, "shouldAntialias"); | |
105 } | |
106 | |
107 void setImageInterpolation (uint interpolation) | |
108 { | |
109 return invokeObjcSelf!(void, "setImageInterpolation:", uint)(interpolation); | |
110 } | |
111 | |
112 uint imageInterpolation () | |
113 { | |
114 return invokeObjcSelf!(uint, "imageInterpolation"); | |
115 } | |
116 | |
117 void setPatternPhase (NSPoint phase) | |
118 { | |
119 return invokeObjcSelf!(void, "setPatternPhase:", NSPoint)(phase); | |
120 } | |
121 | |
122 NSPoint patternPhase () | |
123 { | |
124 return invokeObjcSelf!(NSPoint, "patternPhase"); | |
125 } | |
126 | |
127 void setCompositingOperation (uint operation) | |
128 { | |
129 return invokeObjcSelf!(void, "setCompositingOperation:", uint)(operation); | |
130 } | |
131 | |
132 uint compositingOperation () | |
133 { | |
134 return invokeObjcSelf!(uint, "compositingOperation"); | |
135 } | |
136 | |
137 int colorRenderingIntent () | |
138 { | |
139 return invokeObjcSelf!(int, "colorRenderingIntent"); | |
140 } | |
141 | |
142 void setColorRenderingIntent (int renderingIntent) | |
143 { | |
144 return invokeObjcSelf!(void, "setColorRenderingIntent:", int)(renderingIntent); | |
145 } | |
146 | |
147 //mixin ObjcBindMethod!(setShouldAntialias, "setShouldAntialias:"); | |
148 //mixin ObjcBindMethod!(shouldAntialias, "shouldAntialias"); | |
149 //mixin ObjcBindMethod!(setImageInterpolation, "setImageInterpolation:"); | |
150 //mixin ObjcBindMethod!(imageInterpolation, "imageInterpolation"); | |
151 //mixin ObjcBindMethod!(setPatternPhase, "setPatternPhase:"); | |
152 //mixin ObjcBindMethod!(patternPhase, "patternPhase"); | |
153 //mixin ObjcBindMethod!(setCompositingOperation, "setCompositingOperation:"); | |
154 //mixin ObjcBindMethod!(compositingOperation, "compositingOperation"); | |
155 //mixin ObjcBindMethod!(colorRenderingIntent, "colorRenderingIntent"); | |
156 //mixin ObjcBindMethod!(setColorRenderingIntent, "setColorRenderingIntent:"); | |
157 | |
158 `; | |
159 | |
160 class NSGraphicsContext : NSObject | |
161 { | |
162 mixin (ObjcWrap); | |
163 | |
164 static NSGraphicsContext graphicsContextWithAttributes (NSDictionary attributes) | |
165 { | |
166 return invokeObjcSelfClass!(NSGraphicsContext, "graphicsContextWithAttributes:", NSDictionary)(attributes); | |
167 } | |
168 | |
169 static NSGraphicsContext graphicsContextWithWindow (NSWindow window) | |
170 { | |
171 return invokeObjcSelfClass!(NSGraphicsContext, "graphicsContextWithWindow:", NSWindow)(window); | |
172 } | |
173 | |
174 static NSGraphicsContext graphicsContextWithBitmapImageRep (NSBitmapImageRep bitmapRep) | |
175 { | |
176 return invokeObjcSelfClass!(NSGraphicsContext, "graphicsContextWithBitmapImageRep:", NSBitmapImageRep)(bitmapRep); | |
177 } | |
178 | |
179 static NSGraphicsContext graphicsContextWithGraphicsPort (void* graphicsPort, bool initialFlippedState) | |
180 { | |
181 return invokeObjcSelfClass!(NSGraphicsContext, "graphicsContextWithGraphicsPort:flipped:", void*, bool)(graphicsPort, initialFlippedState); | |
182 } | |
183 | |
184 static NSGraphicsContext currentContext () | |
185 { | |
186 return invokeObjcSelfClass!(NSGraphicsContext, "currentContext"); | |
187 } | |
188 | |
189 static void setCurrentContext (NSGraphicsContext context) | |
190 { | |
191 return invokeObjcSelfClass!(void, "setCurrentContext:", NSGraphicsContext)(context); | |
192 } | |
193 | |
194 static bool currentContextDrawingToScreen () | |
195 { | |
196 return invokeObjcSelfClass!(bool, "currentContextDrawingToScreen"); | |
197 } | |
198 | |
199 static void saveGraphicsState_static () | |
200 { | |
201 return invokeObjcSelfClass!(void, "saveGraphicsState"); | |
202 } | |
203 | |
204 static void restoreGraphicsState_static () | |
205 { | |
206 return invokeObjcSelfClass!(void, "restoreGraphicsState"); | |
207 } | |
208 | |
209 static void setGraphicsState (NSInteger gState) | |
210 { | |
211 return invokeObjcSelfClass!(void, "setGraphicsState:", NSInteger)(gState); | |
212 } | |
213 | |
214 NSDictionary attributes () | |
215 { | |
216 return invokeObjcSelf!(NSDictionary, "attributes"); | |
217 } | |
218 | |
219 bool isDrawingToScreen () | |
220 { | |
221 return invokeObjcSelf!(bool, "isDrawingToScreen"); | |
222 } | |
223 | |
224 void saveGraphicsState () | |
225 { | |
226 return invokeObjcSelf!(void, "saveGraphicsState"); | |
227 } | |
228 | |
229 void restoreGraphicsState () | |
230 { | |
231 return invokeObjcSelf!(void, "restoreGraphicsState"); | |
232 } | |
233 | |
234 void flushGraphics () | |
235 { | |
236 return invokeObjcSelf!(void, "flushGraphics"); | |
237 } | |
238 | |
239 Object focusStack () | |
240 { | |
241 return invokeObjcSelf!(Object, "focusStack"); | |
242 } | |
243 | |
244 void setFocusStack (Object stack) | |
245 { | |
246 return invokeObjcSelf!(void, "setFocusStack:", Object)(stack); | |
247 } | |
248 | |
249 void* graphicsPort () | |
250 { | |
251 return invokeObjcSelf!(void*, "graphicsPort"); | |
252 } | |
253 | |
254 bool isFlipped () | |
255 { | |
256 return invokeObjcSelf!(bool, "isFlipped"); | |
257 } | |
258 | |
259 // NSQuartzCoreAdditions | |
260 CIContext CIContext_ () | |
261 { | |
262 return invokeObjcSelf!(CIContext, "CIContext"); | |
263 } | |
264 | |
265 // NSGraphicsContext_RenderingOptions | |
266 void setShouldAntialias (bool antialias) | |
267 { | |
268 return invokeObjcSelf!(void, "setShouldAntialias:", bool)(antialias); | |
269 } | |
270 | |
271 bool shouldAntialias () | |
272 { | |
273 return invokeObjcSelf!(bool, "shouldAntialias"); | |
274 } | |
275 | |
276 void setImageInterpolation (uint interpolation) | |
277 { | |
278 return invokeObjcSelf!(void, "setImageInterpolation:", uint)(interpolation); | |
279 } | |
280 | |
281 uint imageInterpolation () | |
282 { | |
283 return invokeObjcSelf!(uint, "imageInterpolation"); | |
284 } | |
285 | |
286 void setPatternPhase (NSPoint phase) | |
287 { | |
288 return invokeObjcSelf!(void, "setPatternPhase:", NSPoint)(phase); | |
289 } | |
290 | |
291 NSPoint patternPhase () | |
292 { | |
293 return invokeObjcSelf!(NSPoint, "patternPhase"); | |
294 } | |
295 | |
296 void setCompositingOperation (uint operation) | |
297 { | |
298 return invokeObjcSelf!(void, "setCompositingOperation:", uint)(operation); | |
299 } | |
300 | |
301 uint compositingOperation () | |
302 { | |
303 return invokeObjcSelf!(uint, "compositingOperation"); | |
304 } | |
305 | |
306 int colorRenderingIntent () | |
307 { | |
308 return invokeObjcSelf!(int, "colorRenderingIntent"); | |
309 } | |
310 | |
311 void setColorRenderingIntent (int renderingIntent) | |
312 { | |
313 return invokeObjcSelf!(void, "setColorRenderingIntent:", int)(renderingIntent); | |
314 } | |
315 } |