|
1 /******************************************************************************* |
|
2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. This program and the accompanying materials |
|
4 * are made available under the terms of the Eclipse Public License v1.0 |
|
5 * which accompanies this distribution, and is available at |
|
6 * http://www.eclipse.org/legal/epl-v10.html |
|
7 * |
|
8 * Contributors: |
|
9 * Nokia Corporation - initial implementation |
|
10 *******************************************************************************/ |
|
11 package org.eclipse.swt.internal.qt.graphics; |
|
12 import java.util.Vector; |
|
13 |
|
14 import org.eclipse.swt.widgets.Internal_PackageSupport; |
|
15 import org.eclipse.swt.widgets.Widget; |
|
16 |
|
17 public final class GraphicsContext { |
|
18 |
|
19 // These must be in sync with graphics.h |
|
20 |
|
21 // Rectangle index |
|
22 /** |
|
23 * Rectangle data array's <code>x</code> index |
|
24 * @see #getClip |
|
25 * @see #getTextBoundingBox |
|
26 */ |
|
27 public final static int RECT_X = 0; |
|
28 |
|
29 /** |
|
30 * Rectangle data array's <code>y</code> index |
|
31 * @see #getClip |
|
32 * @see #getTextBoundingBox |
|
33 */ |
|
34 public final static int RECT_Y = 1; |
|
35 |
|
36 /** |
|
37 * Rectangle data array's <code>width</code> index |
|
38 * @see #getClip |
|
39 * @see #getTextBoundingBox |
|
40 */ |
|
41 public final static int RECT_WIDTH = 2; |
|
42 |
|
43 /** |
|
44 * Rectangle data array's <code>height</code> index |
|
45 * @see #getClip |
|
46 * @see #getTextBoundingBox |
|
47 */ |
|
48 public final static int RECT_HEIGHT = 3; |
|
49 |
|
50 // Blending modes |
|
51 /** |
|
52 * Constant for Source blending mode. The destination's color and |
|
53 * alpha values are replaced with those of source. |
|
54 */ |
|
55 public static final int BLENDING_MODE_SRC = 10; |
|
56 |
|
57 /** |
|
58 * Constant for Source over blending mode. The source is composed over destination. |
|
59 */ |
|
60 public static final int BLENDING_MODE_SRC_OVER = 11; |
|
61 |
|
62 /** |
|
63 * Constant for XOR blending mode. The resulting color in the destination is |
|
64 * the exclusive or of the color values in the source and the destination. |
|
65 */ |
|
66 public static final int BLENDING_MODE_XOR = 12; |
|
67 |
|
68 // Stroke styles |
|
69 /** |
|
70 * Stroke style is not set. |
|
71 */ |
|
72 public static final int STROKE_NO = 0; |
|
73 |
|
74 /** |
|
75 * Solid stroke. |
|
76 */ |
|
77 public static final int STROKE_SOLID = 1; |
|
78 |
|
79 /** |
|
80 * Dotted stroke |
|
81 */ |
|
82 public static final int STROKE_DOT = 2; |
|
83 |
|
84 /** |
|
85 * Dash stroke |
|
86 */ |
|
87 public static final int STROKE_DASH = 3; |
|
88 |
|
89 /** |
|
90 * Dash-dot stroke |
|
91 */ |
|
92 public static final int STROKE_DASH_DOT = 4; |
|
93 |
|
94 /** |
|
95 * Dash-dot-dot stroke |
|
96 */ |
|
97 public static final int STROKE_DASH_DOT_DOT = 5; |
|
98 |
|
99 // Text flags |
|
100 /** |
|
101 * One line. Whitespaces are threated as spaces. |
|
102 * NOTE: TEXT_SINGLE_LINE and TEXT_WORD_WRAP cannot be combined. |
|
103 * @see TEXT_WORD_WRAP |
|
104 */ |
|
105 public static final int TEXT_SINGLE_LINE = 0x0100; |
|
106 |
|
107 /** |
|
108 * Prints outside of the given bounds if needed |
|
109 */ |
|
110 public static final int TEXT_DONT_CLIP = 0x0200; |
|
111 |
|
112 /** |
|
113 * Expand tabs |
|
114 */ |
|
115 public static final int TEXT_EXPAND_TABS = 0x0400; |
|
116 |
|
117 /** |
|
118 * Underline the mnemonic character |
|
119 */ |
|
120 public static final int TEXT_SHOW_MNEMONIC = 0x0800; |
|
121 |
|
122 /** |
|
123 * Breaks lines at appropriate points |
|
124 * NOTE: TEXT_SINGLE_LINE and TEXT_WORD_WRAP cannot be combined. |
|
125 * @see TEXT_SINGLE_LINE |
|
126 */ |
|
127 public static final int TEXT_WORD_WRAP = 0x1000; |
|
128 |
|
129 /** |
|
130 * Breaks lines anywhere, even within words. |
|
131 */ |
|
132 public static final int TEXT_WRAP_ANYWHERE = 0x2000; |
|
133 |
|
134 /** |
|
135 * Same as OS_TEXT_SHOW_MNEMONIC but no underlines. |
|
136 * @see OS_TEXT_SHOW_MNEMONIC |
|
137 */ |
|
138 public static final int TEXT_HIDE_MNEMONIC = 0x8000; |
|
139 |
|
140 /** |
|
141 * Behaves like a "hidden" text - not printed. |
|
142 */ |
|
143 public static final int TEXT_DONT_PRINT = 0x4000; |
|
144 |
|
145 /** |
|
146 * Trailing whitespace not deleted automatically. |
|
147 */ |
|
148 public static final int TEXT_INCLUDE_TRAILING_SPACES = 0x08000000; |
|
149 |
|
150 /** |
|
151 * Ensures that text lines are justified. |
|
152 */ |
|
153 public static final int TEXT_JUSTIFICATIONFORCED = 0x10000; |
|
154 |
|
155 // Alignment flags |
|
156 /** |
|
157 * Aligns with the left edge. |
|
158 */ |
|
159 public static final int ALIGNMENT_LEFT = 0x0001; |
|
160 |
|
161 /** |
|
162 * Aligns with the right edge. |
|
163 */ |
|
164 public static final int ALIGNMENT_RIGHT = 0x0002; |
|
165 |
|
166 /** |
|
167 * Centers horizontally in the available space. |
|
168 */ |
|
169 public static final int ALIGNMENT_HCENTER = 0x0004; |
|
170 |
|
171 /** |
|
172 * Justifies the text in the available space. |
|
173 */ |
|
174 public static final int ALIGNMENT_JUSTIFY = 0x0008; |
|
175 |
|
176 /** |
|
177 * Aligns with the top. |
|
178 */ |
|
179 public static final int ALIGNMENT_TOP = 0x0020; |
|
180 |
|
181 /** |
|
182 * Aligns with the bottom. |
|
183 */ |
|
184 public static final int ALIGNMENT_BOTTOM = 0x0040; |
|
185 |
|
186 /** |
|
187 * Centers vertically in the available space. |
|
188 */ |
|
189 public static final int ALIGNMENT_VCENTER = 0x0080; |
|
190 |
|
191 // package constants |
|
192 |
|
193 /** |
|
194 * Specifies no target |
|
195 */ |
|
196 static final int TARGET_NONE = 0; |
|
197 |
|
198 /** |
|
199 * Specifies native target type QWidget. |
|
200 */ |
|
201 static final int TARGET_WIDGET = 1; |
|
202 |
|
203 /** |
|
204 * Specifies native target type Image. |
|
205 */ |
|
206 static final int TARGET_IMAGE = 2; |
|
207 |
|
208 /** |
|
209 * Specifies native target type Buffer. |
|
210 */ |
|
211 static final int TARGET_NATIVE_COMMAND_BUFFER = 3; |
|
212 |
|
213 /** |
|
214 * Specifies Java command buffer target |
|
215 */ |
|
216 static final int TARGET_WINDOWSURFACE = 4; |
|
217 /** |
|
218 * Specifies Java command buffer target, not valid in native target types |
|
219 */ |
|
220 static final int TARGET_JAVA_COMMAND_BUFFER = 5; |
|
221 |
|
222 /** |
|
223 * Native peer handle |
|
224 */ |
|
225 int handle = -1; |
|
226 |
|
227 |
|
228 /** |
|
229 * private members |
|
230 */ |
|
231 private boolean disposed; |
|
232 private RenderingTarget targetData = null; |
|
233 |
|
234 /** |
|
235 * Constructor |
|
236 */ |
|
237 public GraphicsContext() { |
|
238 Utils.validateUiThread(); |
|
239 handle = OS.graphicsContext_init(); |
|
240 targetData = new RenderingTarget(); |
|
241 disposed = false; |
|
242 } |
|
243 |
|
244 /** |
|
245 * Gets the windowsurface of currently bound target. |
|
246 * Windowsurface is the surface where external graphics APIs can render, e.g m2g and m3g. |
|
247 * @return windowSurface if currently bound target has one, otherwise null |
|
248 */ |
|
249 public WindowSurface getWindowSurface() { |
|
250 checkState(); |
|
251 |
|
252 // buffers don't have a window surface |
|
253 |
|
254 if ((targetData.type == TARGET_NATIVE_COMMAND_BUFFER) ||(targetData.type == TARGET_JAVA_COMMAND_BUFFER) ) { |
|
255 return null; |
|
256 } |
|
257 |
|
258 // Get the current target that is bound |
|
259 Object target = targetData.target; |
|
260 |
|
261 // Only shells have window surface so figure out if target is shell, |
|
262 // and if not get the shell of child widget |
|
263 if (targetData.type == TARGET_WIDGET) { |
|
264 if (!(target instanceof org.eclipse.swt.widgets.Shell)) { |
|
265 target = ((org.eclipse.swt.widgets.Control)target).getShell(); |
|
266 } |
|
267 } |
|
268 SurfaceCache cache = SurfaceCache.getInstance(); |
|
269 |
|
270 // check surface cache for existing windowsurface for current target |
|
271 WindowSurface surface = cache.getSurface(target); |
|
272 |
|
273 // If not found in cache we need to create new one |
|
274 // and store that to cache for future use |
|
275 if (surface == null) { |
|
276 surface = new WindowSurface(OS.graphicsContext_get_windowsurface(handle)); |
|
277 if (targetData.type == TARGET_WIDGET) { |
|
278 // Add to cache and let it add dispose listener for automatic cleanup |
|
279 cache.addSurface(surface, target, true); |
|
280 } else { |
|
281 // Image associated entry's are deleted when Image dispose is called |
|
282 cache.addSurface(surface, target, false); |
|
283 } |
|
284 return surface; |
|
285 } else { |
|
286 return surface; |
|
287 } |
|
288 } |
|
289 |
|
290 void bindTarget(java.lang.Object target, int type, int handle, int bufferFlushTargetHandle) { |
|
291 Utils.validateUiThread(); |
|
292 // validate state |
|
293 if(disposed) { |
|
294 throw new IllegalStateException("GraphicsContext already disposed"); |
|
295 } |
|
296 if (isActive()) { |
|
297 throw new IllegalStateException("Already bound to target: " + targetData.target); |
|
298 } |
|
299 |
|
300 // Reset iTarget before setting new target |
|
301 targetData.reset(); |
|
302 |
|
303 // call for actual bind, this may throw an exception |
|
304 // especially when trying to bind a target which has been bound already |
|
305 // this is skipped if target is java command buffer |
|
306 if (type != TARGET_JAVA_COMMAND_BUFFER) { |
|
307 doBind(handle, type, target, bufferFlushTargetHandle); |
|
308 } else { |
|
309 if(((JavaCommandBuffer)target).isBound()) { |
|
310 throw new IllegalStateException("Target already bound by other gc instance"); |
|
311 } |
|
312 targetData.commandBuffer = (JavaCommandBuffer)target; |
|
313 targetData.isJavaCommandBuffer = true; |
|
314 } |
|
315 |
|
316 // store target |
|
317 targetData.handle = handle; |
|
318 targetData.type = type; |
|
319 targetData.target = target; |
|
320 |
|
321 // If target is Image, inform that it is being bound. |
|
322 // this is needed in case image is disposed before |
|
323 // releaseTarget() is called |
|
324 if(type == TARGET_IMAGE) { |
|
325 ((org.eclipse.swt.internal.qt.graphics.Image)target).notifyBind(this); |
|
326 } |
|
327 } |
|
328 |
|
329 /** |
|
330 * Binds given SWT Control as the rendering target of this GraphicsContext. |
|
331 * |
|
332 * @param target SWT Control |
|
333 * |
|
334 * @throws java.lang.IllegalStateException if this GraphicsContext already has a rendering target |
|
335 * @throws java.lang.IllegalStateException if given target is already bound by some other GC instance |
|
336 * @throws java.lang.IllegalStateException if GraphicsContext has already been disposed |
|
337 * @throws java.lang.NullPointerException if given target is null |
|
338 * @throws java.lang.IllegalArgumentException if given target cannot be bound |
|
339 * @throws java.lang.IllegalArgumentException if given target is already disposed |
|
340 */ |
|
341 public void bindTarget(org.eclipse.swt.widgets.Control target) { |
|
342 if(target == null) { |
|
343 throw new NullPointerException("target is null"); |
|
344 } |
|
345 if(target.isDisposed()) |
|
346 throw new IllegalArgumentException("Target already disposed"); |
|
347 bindTarget(target, TARGET_WIDGET, handle(target), 0); |
|
348 } |
|
349 |
|
350 /** |
|
351 * Binds given SWT Display as the rendering target of this GraphicsContext. |
|
352 * |
|
353 * @param target SWT Display |
|
354 * |
|
355 * @throws java.lang.IllegalStateException if this GraphicsContext already has a rendering target |
|
356 * @throws java.lang.IllegalStateException if given target is already bound by some other GC instance |
|
357 * @throws java.lang.IllegalStateException if GraphicsContext has already been disposed |
|
358 * @throws java.lang.NullPointerException if given target is null |
|
359 * @throws java.lang.IllegalArgumentException if given target cannot be bound |
|
360 * @throws java.lang.IllegalArgumentException if given target is already disposed |
|
361 */ |
|
362 public void bindTarget(org.eclipse.swt.widgets.Display target) { |
|
363 if(target == null) { |
|
364 throw new NullPointerException("target is null"); |
|
365 } |
|
366 if(target.isDisposed()) |
|
367 throw new IllegalArgumentException("Target already disposed"); |
|
368 int handle = org.eclipse.swt.internal.qt.OS.QApplication_desktop(); |
|
369 bindTarget(target, TARGET_WIDGET, handle, 0); |
|
370 } |
|
371 |
|
372 /** |
|
373 * Binds given org.eclipse.swt.internal.qt.graphics.Image as the rendering target of this GraphicsContext. |
|
374 * |
|
375 * @param target The image |
|
376 * |
|
377 * @throws java.lang.IllegalStateException if this GraphicsContext already has a rendering target |
|
378 * @throws java.lang.IllegalStateException if given target is already bound by some other GC instance |
|
379 * @throws java.lang.IllegalStateException if GraphicsContext has already been disposed |
|
380 * @throws java.lang.NullPointerException if given target is null |
|
381 * @throws java.lang.IllegalArgumentException if given target cannot be bound |
|
382 * @throws java.lang.IllegalArgumentException if given target is already disposed |
|
383 */ |
|
384 public void bindTarget(org.eclipse.swt.internal.qt.graphics.Image target) { |
|
385 if(target == null) { |
|
386 throw new NullPointerException("target is null"); |
|
387 } |
|
388 if(target.isDisposed()) |
|
389 throw new IllegalArgumentException("Target already disposed"); |
|
390 bindTarget(target, TARGET_IMAGE, target.handle, 0); |
|
391 } |
|
392 |
|
393 /** |
|
394 * Binds given org.eclipse.swt.internal.qt.graphics.Buffer as the rendering target of this GraphicsContext. |
|
395 * |
|
396 * @param target The buffer |
|
397 * @param flushTargetHandle The actual target where the buffer will be flushed to |
|
398 * |
|
399 * @throws java.lang.IllegalStateException if this GraphicsContext already has a rendering target |
|
400 * @throws java.lang.IllegalStateException if given target is already bound by some other GC instance |
|
401 * @throws java.lang.IllegalStateException if CraphicsContext has already been disposed |
|
402 * @throws java.lang.NullPointerException if given target is null |
|
403 * @throws java.lang.NullPointerException if given flushTarget is null |
|
404 * @throws java.lang.IllegalArgumentException if given target cannot be bound |
|
405 * @throws java.lang.IllegalArgumentException if given target is already disposed |
|
406 */ |
|
407 public void bindTarget(org.eclipse.swt.internal.qt.graphics.NativeCommandBuffer target, org.eclipse.swt.widgets.Control flushTarget) { |
|
408 if(target == null) { |
|
409 throw new NullPointerException("target is null"); |
|
410 } |
|
411 if(flushTarget == null) { |
|
412 throw new NullPointerException("flushTarget is null"); |
|
413 } |
|
414 if(target.isDisposed()) |
|
415 throw new IllegalArgumentException("Target already disposed"); |
|
416 if(flushTarget.isDisposed()) |
|
417 throw new IllegalArgumentException("Buffer flush target already disposed"); |
|
418 bindTarget(target, TARGET_NATIVE_COMMAND_BUFFER, target.handle, handle(flushTarget)); |
|
419 } |
|
420 |
|
421 |
|
422 /** |
|
423 * Binds given org.eclipse.swt.internal.qt.graphics.CommandBuffer as the rendering target of this GraphicsContext. |
|
424 * When JavaCommandBuffer is set as rendering target only one way methods, i.e. draw and setters are supported. |
|
425 * See JavaCommanduffer implementation for details of what operations are supported. |
|
426 * |
|
427 * @param target The buffer where commands are recorded |
|
428 * @throws java.lang.IllegalStateException if this GraphicsContext already has a rendering target |
|
429 * @throws java.lang.IllegalStateException if given target is already bound by some other GC instance |
|
430 * @throws java.lang.IllegalStateException if CraphicsContext has already been disposed |
|
431 * @throws java.lang.NullPointerException if given target is null |
|
432 */ |
|
433 public void bindTarget(org.eclipse.swt.internal.qt.graphics.JavaCommandBuffer target) { |
|
434 if(target == null) |
|
435 throw new NullPointerException("target is null"); |
|
436 bindTarget(target, TARGET_JAVA_COMMAND_BUFFER, 0, 0); |
|
437 } |
|
438 |
|
439 |
|
440 /** |
|
441 * Don't use. This is here only for testing purposes. |
|
442 * @deprecated Buffer flush target must be given be given when binding to a buffer. |
|
443 * @see bindTarget(org.eclipse.swt.internal.qt.graphics.Buffer target, org.eclipse.swt.widgets.Control flushTarget) |
|
444 */ |
|
445 public void bindTarget(org.eclipse.swt.internal.qt.graphics.NativeCommandBuffer target) { |
|
446 if(target == null) { |
|
447 throw new NullPointerException("Target is null"); |
|
448 } |
|
449 if(target.isDisposed()) { |
|
450 throw new IllegalArgumentException("target already disposed"); |
|
451 } |
|
452 bindTarget(target, TARGET_NATIVE_COMMAND_BUFFER, target.handle, 0); |
|
453 } |
|
454 |
|
455 /** |
|
456 * Binds given org.eclipse.swt.internal.qt.graphics.WindowSurface as the rendering target of this GraphicsContext. |
|
457 * |
|
458 * @param target The WindowSurface instance to be bound |
|
459 * @throws java.lang.IllegalStateException if this GraphicsContext already has a rendering target |
|
460 * @throws java.lang.IllegalStateException if given target is already bound by some other GC instance |
|
461 * @throws java.lang.IllegalStateException if CraphicsContext has already been disposed |
|
462 * @throws java.lang.NullPointerException if given target is null |
|
463 * @throws java.lang.IllegalArgumentException if given target is already disposed |
|
464 */ |
|
465 public void bindTarget(org.eclipse.swt.internal.qt.graphics.WindowSurface target) { |
|
466 if(target == null) { |
|
467 throw new NullPointerException("target is null"); |
|
468 } |
|
469 if(target.isDisposed()) { |
|
470 throw new IllegalArgumentException("target already disposed"); |
|
471 } |
|
472 bindTarget(target, TARGET_WINDOWSURFACE, target.handle, 0); |
|
473 } |
|
474 |
|
475 /** |
|
476 * Get target to which current GraphicsContext is bound to |
|
477 * |
|
478 * @return Object to which GraphicsContext is bound to or null if there is no target |
|
479 */ |
|
480 public Object getBoundTarget() { |
|
481 checkState(); |
|
482 return targetData.target; |
|
483 } |
|
484 |
|
485 /** |
|
486 * Flushes all pending draw operations and releases current rending target. |
|
487 * If no target is bound, request is silently ingored. |
|
488 */ |
|
489 public void releaseTarget() { |
|
490 Utils.validateUiThread(); |
|
491 if (disposed) { |
|
492 throw new IllegalStateException("GraphicsContext already disposed"); |
|
493 } |
|
494 |
|
495 if (targetData.target != null) { |
|
496 // In case of java command buffer no native calls needed |
|
497 if (targetData.type == TARGET_JAVA_COMMAND_BUFFER) { |
|
498 targetData.commandBuffer.release(); |
|
499 targetData.reset(); |
|
500 return; |
|
501 } |
|
502 // call native release |
|
503 OS.graphicsContext_releaseTarget(handle); |
|
504 |
|
505 // if target is Image notify about release |
|
506 if(targetData.type == TARGET_IMAGE) { |
|
507 ((org.eclipse.swt.internal.qt.graphics.Image)targetData.target).notifyRelease(); |
|
508 } |
|
509 // reset target data |
|
510 targetData.reset(); |
|
511 } else { |
|
512 //ignore, i.e. no need to throw an exception |
|
513 } |
|
514 } |
|
515 |
|
516 /** |
|
517 * Checks if target is already bound by some other gc instance and does |
|
518 * native bind operation. |
|
519 * |
|
520 * @param gc The GraphicsContext doing the binding |
|
521 * @throws IllegalStateException if target is found in the list before adding it, |
|
522 * i.e. it is already being painted by some other gc. |
|
523 */ |
|
524 private void doBind(int targetHandle, int targetType, java.lang.Object target, int bufferFlushTargetHandle) { |
|
525 // call native bind. In case this fails the native peer throws an exception |
|
526 // and resets state automatically, i.e. there no need to rewind from here |
|
527 OS.graphicsContext_bindTarget(handle, targetHandle, targetType, bufferFlushTargetHandle); |
|
528 } |
|
529 |
|
530 /** |
|
531 * Renders all draw commands stored in given buffer to currently bound target. |
|
532 * |
|
533 * @param buffer The buffer to be processed |
|
534 * @throws NullPointerException If buffer is null |
|
535 * @throws IllegalArgumentException If buffer has been already disposed |
|
536 */ |
|
537 public void render(NativeCommandBuffer buffer) { |
|
538 checkState(); |
|
539 if(buffer == null) { |
|
540 throw new NullPointerException("buffer is null"); |
|
541 } |
|
542 if(buffer.isDisposed()) { |
|
543 throw new IllegalArgumentException("buffer already disposed"); |
|
544 } |
|
545 OS.graphicsContext_render(handle, buffer.handle); |
|
546 } |
|
547 |
|
548 /** |
|
549 * Renders all draw commands stored in given CommandBuffer to currently bound target. |
|
550 * Note that JavaCommandBuffer can be rendered only once as some of the large data objects placed in |
|
551 * the buffer are freed right after they have been processed. |
|
552 * |
|
553 * @param buffer The CommandBuffer to be processed |
|
554 * @throws NullPointerException If CommandBuffer is null |
|
555 */ |
|
556 public void render(JavaCommandBuffer buffer) { |
|
557 checkState(); |
|
558 if(buffer == null) { |
|
559 throw new NullPointerException("buffer is null"); |
|
560 } |
|
561 // if buffer does not contain data do nothing |
|
562 if(buffer.containsData()) { |
|
563 processBuffer(buffer); |
|
564 } |
|
565 } |
|
566 |
|
567 /** |
|
568 * Copies rectangular area from currently bound target to given image target. |
|
569 * The copy rectangle top left corned is defined by x and y and bottom right corner |
|
570 * by image width and height. |
|
571 * |
|
572 * @param target The image to copy into |
|
573 * @param x The x coordinate of top left corner copy area |
|
574 * @param y The y coordinate of top left corner copy area |
|
575 * @throws NullPointerException if Image target is null |
|
576 * @throws IllegalStateException if no target is bound |
|
577 */ |
|
578 public void copyArea(Image target, int x, int y) { |
|
579 checkState(); |
|
580 if (target == null) { |
|
581 throw new NullPointerException("Target image is null"); |
|
582 } |
|
583 if(targetData.isJavaCommandBuffer) { |
|
584 targetData.commandBuffer.copyArea(target, x, y); |
|
585 } else { |
|
586 OS.graphicsContext_copyArea(handle, target.handle, x, y); |
|
587 } |
|
588 } |
|
589 |
|
590 /** |
|
591 * Copies rectangular area within currently bound target from source |
|
592 * location to destination location. |
|
593 * |
|
594 * @param srcX The top left x coordinate of source rectangle |
|
595 * @param srcY The top left y coordinate of source rectangle |
|
596 * @param width The width of source rectangle |
|
597 * @param height The height of source rectangle |
|
598 * @param destX The top left x coordinate for the copy |
|
599 * @param destY The top left y coordinate for the copy |
|
600 * @throws IllegalStateException if no target is bound |
|
601 */ |
|
602 public void copyArea(int srcX, int srcY, int width, int height, int destX, int destY) { |
|
603 copyArea(srcX, srcY, width, height, destX, destY, false); |
|
604 } |
|
605 |
|
606 /** |
|
607 * Copies rectangular area within currently bound target from source |
|
608 * location to destination location. |
|
609 * |
|
610 * @param srcX The top left x coordinate of source rectangle |
|
611 * @param srcY The top left y coordinate of source rectangle |
|
612 * @param width The width of source rectangle |
|
613 * @param height The height of source rectangle |
|
614 * @param destX The top left x coordinate for the copy |
|
615 * @param destY The top left y coordinate for the copy |
|
616 * @param paint If to generate paint events for the new and obscured areas |
|
617 * @throws IllegalStateException if no target is bound |
|
618 */ |
|
619 public void copyArea(int srcX, int srcY, int width, int height, int destX, int destY, boolean paint) { |
|
620 checkState(); |
|
621 |
|
622 if(width <= 0 || height <= 0) { |
|
623 return; |
|
624 } |
|
625 if(targetData.isJavaCommandBuffer) { |
|
626 targetData.commandBuffer.copyArea(srcX, srcY, width, height, destX, destY, paint); |
|
627 } else { |
|
628 OS.graphicsContext_copyArea(handle, srcX, srcY, width, height, destX, destY, paint); |
|
629 } |
|
630 } |
|
631 |
|
632 /** |
|
633 * Draws outline of elliptical arc within specified rectangle using foreground color. |
|
634 * Arc is drawn counterclockwise. |
|
635 * |
|
636 * @param x The x coordinate of top left corner of arc rectangle |
|
637 * @param y The y coordinate of top left corner of arc rectangle |
|
638 * @param width The width of arc rectangle |
|
639 * @param height The height of arc rectangle |
|
640 * @param startAngle The starting angle for arc |
|
641 * @param arcAngle The span angle for arc |
|
642 * @throws IllegalStateException if no target is bound |
|
643 */ |
|
644 public void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle) { |
|
645 checkState(); |
|
646 |
|
647 if(width <= 0 || height <= 0) { |
|
648 return; |
|
649 } |
|
650 if(targetData.isJavaCommandBuffer) { |
|
651 targetData.commandBuffer.drawArc(x, y, width, height, startAngle, arcAngle); |
|
652 } else { |
|
653 OS.graphicsContext_drawArc(handle, x, y, width, height, startAngle, arcAngle); |
|
654 } |
|
655 } |
|
656 |
|
657 /** |
|
658 * Draws an ellipse specified by rectangle using foreground color. |
|
659 * |
|
660 * @param x The x coordinate of top left corner of ellipse rectangle |
|
661 * @param y The y coordinate of top left corner of ellipse rectangle |
|
662 * @param width The width of ellipse rectangle |
|
663 * @param height The height of ellipse rectangle |
|
664 * @throws IllegalStateException if no target is bound |
|
665 */ |
|
666 public void drawEllipse(int x, int y, int width, int height) { |
|
667 checkState(); |
|
668 |
|
669 if(width <= 0 || height <= 0) { |
|
670 return; |
|
671 } |
|
672 if(targetData.isJavaCommandBuffer) { |
|
673 targetData.commandBuffer.drawEllipse(x, y, width, height); |
|
674 } else { |
|
675 OS.graphicsContext_drawEllipse(handle, x, y, width, height); |
|
676 } |
|
677 } |
|
678 |
|
679 public void drawFocus(int x, int y, int width, int height) { |
|
680 checkState(); |
|
681 |
|
682 if(width <= 0 || height <= 0) { |
|
683 return; |
|
684 } |
|
685 if(targetData.isJavaCommandBuffer) { |
|
686 targetData.commandBuffer.drawFocus(x, y, width, height); |
|
687 } else { |
|
688 OS.graphicsContext_drawFocus(handle, x, y, width, height); |
|
689 } |
|
690 } |
|
691 |
|
692 /** |
|
693 * Draws given image to specified location. |
|
694 * |
|
695 * @param img The image to draw |
|
696 * @param x The x coordinate of top left corner where to draw image |
|
697 * @param y The y coordinate of top left corner where to draw image |
|
698 * @throws NullPointerException if Image is null |
|
699 * @throws IllegalStateException if no target is bound |
|
700 */ |
|
701 public void drawImage(Image img, int x, int y) { |
|
702 checkState(); |
|
703 if (img == null) { |
|
704 throw new NullPointerException("Image is null"); |
|
705 } |
|
706 if(targetData.isJavaCommandBuffer) { |
|
707 targetData.commandBuffer.drawImage(img, x, y); |
|
708 } else { |
|
709 OS.graphicsContext_drawImage(handle, img.handle, x, y); |
|
710 } |
|
711 } |
|
712 |
|
713 /** |
|
714 * Draws given image to specified location. |
|
715 * |
|
716 * @param img The image to draw |
|
717 * @param tx The top-left x coordinate in image that is to be drawn onto |
|
718 * @param ty The top-left y coordinate in image that is to be drawn onto |
|
719 * @param tw The width of the image that is to be drawn onto. |
|
720 * @param th The heigth of the image that is to be drawn onto. |
|
721 * @param sx The top-left x coordinate in image that is to be drawn |
|
722 * @param sy The top-left y coordinate in image that is to be drawn |
|
723 * @param sw The width of the image that is to be drawn. |
|
724 * @param sh The heigth of the image that is to be drawn. |
|
725 * @throws NullPointerException if Image is null |
|
726 * @throws IllegalStateException if no target is bound |
|
727 */ |
|
728 public void drawImage(Image img, |
|
729 int tx, int ty, int tw, int th, |
|
730 int sx, int sy, int sw, int sh) { |
|
731 checkState(); |
|
732 if (img == null) { |
|
733 throw new NullPointerException("Image is null"); |
|
734 } |
|
735 if(targetData.isJavaCommandBuffer) { |
|
736 targetData.commandBuffer.drawImage(img, tx, ty, tw, th, sx, sy, sw, sh, Image.TRANS_NONE); |
|
737 } else { |
|
738 OS.graphicsContext_drawImage(handle, img.handle, tx, ty, tw, th, sx, sy, sw, sh, Image.TRANS_NONE); |
|
739 } |
|
740 } |
|
741 |
|
742 /** |
|
743 * Draws given image to specified location. |
|
744 * |
|
745 * @param img The image to draw |
|
746 * @param tx The top-left x coordinate in image that is to be drawn onto |
|
747 * @param ty The top-left y coordinate in image that is to be drawn onto |
|
748 * @param tw The width of the image that is to be drawn onto. |
|
749 * @param th The heigth of the image that is to be drawn onto. |
|
750 * @param sx The top-left x coordinate in image that is to be drawn |
|
751 * @param sy The top-left y coordinate in image that is to be drawn |
|
752 * @param sw The width of the image that is to be drawn. |
|
753 * @param sh The heigth of the image that is to be drawn. |
|
754 * @param manipulation transformation to be applied to region to be drawn, one of Image.TRANS_* definitions |
|
755 * @throws NullPointerException if Image is null |
|
756 * @throws IllegalArgumentException if manipulation is invalid |
|
757 * @throws IllegalStateException if no target is bound |
|
758 */ |
|
759 public void drawImage(Image img, |
|
760 int tx, int ty, int tw, int th, |
|
761 int sx, int sy, int sw, int sh, int manipulation) { |
|
762 checkState(); |
|
763 if (img == null) { |
|
764 throw new NullPointerException("Image is null"); |
|
765 } |
|
766 if (!isManipulationValid(manipulation)) { |
|
767 throw new IllegalArgumentException("Invalid manipulation"); |
|
768 } |
|
769 if(targetData.isJavaCommandBuffer) { |
|
770 targetData.commandBuffer.drawImage(img, tx, ty, tw, th, sx, sy, sw, sh, manipulation); |
|
771 } else { |
|
772 OS.graphicsContext_drawImage(handle, img.handle, tx, ty, tw, th, sx, sy, sw, sh, manipulation); |
|
773 } |
|
774 } |
|
775 |
|
776 /** |
|
777 * Draws a line between defined points using foreground color. |
|
778 * |
|
779 * @param x1 The x coordinate of staring point |
|
780 * @param y1 The y coordinate of staring point |
|
781 * @param x2 The x coordinate of ending point |
|
782 * @param y2 The y coordinate of ending point |
|
783 * @throws IllegalStateException if no target is bound |
|
784 */ |
|
785 public void drawLine(int x1, int y1, int x2, int y2) { |
|
786 checkState(); |
|
787 if(targetData.isJavaCommandBuffer) { |
|
788 targetData.commandBuffer.drawLine(x1, y1, x2, y2); |
|
789 } else { |
|
790 OS.graphicsContext_drawLine(handle, x1, y1, x2, y2); |
|
791 } |
|
792 } |
|
793 |
|
794 /** |
|
795 * Draws a point to specified location using foreground color. |
|
796 * |
|
797 * @param x The x coordinate to draw the point |
|
798 * @param y The y coordinate to draw the point |
|
799 * @throws IllegalStateException if no target is bound |
|
800 */ |
|
801 public void drawPoint(int x, int y) { |
|
802 checkState(); |
|
803 if(targetData.isJavaCommandBuffer) { |
|
804 targetData.commandBuffer.drawPoint(x, y); |
|
805 } else { |
|
806 OS.graphicsContext_drawPoint(handle, x, y); |
|
807 } |
|
808 } |
|
809 |
|
810 /** |
|
811 * Draws a closed polygon which is defined integer array of coorinates, using foreground color. |
|
812 * Lines are drawn between each consecutive x,y pairs and between first and last point. |
|
813 * |
|
814 * @param pointArray An array alternating x and y values which are the verices of the polygon |
|
815 * @throws NullPointerException if <code>pointArray</code> is null |
|
816 * @throws IllegalStateException if no target is bound |
|
817 */ |
|
818 public void drawPolygon(int[] pointArray) { |
|
819 checkState(); |
|
820 if (pointArray == null) { |
|
821 throw new NullPointerException("pointaArray is null"); |
|
822 } |
|
823 if(targetData.isJavaCommandBuffer) { |
|
824 targetData.commandBuffer.drawPolygon(pointArray); |
|
825 } else { |
|
826 OS.graphicsContext_drawPolygon(handle, pointArray); |
|
827 } |
|
828 } |
|
829 |
|
830 /** |
|
831 * Draws polyline which is defined integer array of coorinates, using foreground color. |
|
832 * Lines are drawn between each consecutive x,y pairs, but not between first and last coordinate. |
|
833 * |
|
834 * @param pointArray An array alternating x and y values which are the corners of the polyline |
|
835 * @throws NullPointerException if <code>pointArray</code> is null |
|
836 * @throws IllegalStateException if no target is bound |
|
837 */ |
|
838 public void drawPolyline(int[] pointArray) { |
|
839 checkState(); |
|
840 if (pointArray == null) { |
|
841 throw new NullPointerException("pointaArray is null"); |
|
842 } |
|
843 if(targetData.isJavaCommandBuffer) { |
|
844 targetData.commandBuffer.drawPolyline(pointArray); |
|
845 } else { |
|
846 OS.graphicsContext_drawPolyline(handle, pointArray); |
|
847 } |
|
848 } |
|
849 |
|
850 /** |
|
851 * Draws outline rectangle specified by the arguments using foreground color. |
|
852 * |
|
853 * @param x The x coordinate of top left corner of rectangle |
|
854 * @param y The y coordinate of top left corner of rectangle |
|
855 * @param width The width of rectangle |
|
856 * @param height The height of rectangle |
|
857 * @throws IllegalStateException if no target is bound |
|
858 */ |
|
859 public void drawRect(int x, int y, int width, int height) { |
|
860 checkState(); |
|
861 |
|
862 if(width <= 0 || height <= 0) { |
|
863 return; |
|
864 } |
|
865 if(targetData.isJavaCommandBuffer) { |
|
866 targetData.commandBuffer.drawRect(x, y, width, height); |
|
867 } else { |
|
868 OS.graphicsContext_drawRect(handle, x, y, width, height); |
|
869 } |
|
870 } |
|
871 |
|
872 /** |
|
873 * Draws a series of RGB+transparency values to specified region |
|
874 * |
|
875 * Scanlength can be negative which results in reading <code>rgbData</code> array in reverse direction |
|
876 * |
|
877 * @param rgbData an array or ARGB values in format #AARRGGBB |
|
878 * @param offset the array index of the first ARGB value |
|
879 * @param scanlenght the relative arra offset between consecutive rows in the <code>rgbData</code> array |
|
880 * @param x the horizontal location of the region to be rendered |
|
881 * @param y the vertical location of the region to be rendered |
|
882 * @param width the width of the region to be rendered |
|
883 * @param height the height of the region to be rendered |
|
884 * @param processAlpha <code>true</code> if <code>rgbData</code> has an alpha channel, <code>false</code> if all pixels are fully opaque |
|
885 * @param manipulation transformation to be applied, one of Image.TRANS_* definitions |
|
886 * @throws NullPointerException if <code>rgbData</code> is null |
|
887 * @throws IllegalArgumentException if manipulation is invalid |
|
888 * @throws ArrayIndexOutOfBoundsException if operation will attempt to access elements outside the range of <code>rgbData</code> array |
|
889 * @throws IllegalStateException if no target is bound |
|
890 */ |
|
891 public void drawRGB(int[] rgbData, int offset, int scanlength, int x, int y, int width, int height, boolean processAlpha, int manipulation) { |
|
892 checkState(); |
|
893 if(rgbData == null) { |
|
894 throw new NullPointerException("rgbData is null"); |
|
895 } |
|
896 // check most obvious cases where we end up outside array bounds and abort |
|
897 // native peer will throw also exception if operation goes outside of array bounds |
|
898 if((offset < 0) || (rgbData.length < offset + width) ) { |
|
899 throw new ArrayIndexOutOfBoundsException(); |
|
900 } |
|
901 if (!isManipulationValid(manipulation)) { |
|
902 throw new IllegalArgumentException("Invalid manipulation"); |
|
903 } |
|
904 if(scanlength == 0) { |
|
905 return; |
|
906 } |
|
907 if(width <= 0 || height <= 0) { |
|
908 return; |
|
909 } |
|
910 if(Math.abs(scanlength) < width) { |
|
911 return; |
|
912 } |
|
913 if(targetData.isJavaCommandBuffer) { |
|
914 targetData.commandBuffer.drawRGB(rgbData, offset, scanlength, x, y, width, height, processAlpha, manipulation); |
|
915 } else { |
|
916 OS.graphicsContext_drawRGB(handle, rgbData, offset, scanlength, x, y, width, height, processAlpha, manipulation); |
|
917 } |
|
918 } |
|
919 |
|
920 /** |
|
921 * Draws a series of RGB+transparency values to specified region |
|
922 * |
|
923 * Scanlength can be negative which results in reading <code>rgbData</code> array in reverse direction |
|
924 * |
|
925 * @param rgbData an array or ARGB values in format #AARRGGBB |
|
926 * @param offset the array index of the first ARGB value |
|
927 * @param scanlenght the relative arra offset between consecutive rows in the <code>rgbData</code> array |
|
928 * @param x the horizontal location of the region to be rendered |
|
929 * @param y the vertical location of the region to be rendered |
|
930 * @param width the width of the region to be rendered |
|
931 * @param height the height of the region to be rendered |
|
932 * @param processAlpha <code>true</code> if <code>rgbData</code> has an alpha channel, <code>false</code> if all pixels are fully opaque |
|
933 * @throws NullPointerException if <code>rgbData</code> is null |
|
934 * @throws ArrayIndexOutOfBoundsException if operation will attempt to access elements outside the range of <code>rgbData</code> array |
|
935 * @throws IllegalStateException if no target is bound |
|
936 */ |
|
937 public void drawRGB(int[] rgbData, int offset, int scanlength, int x, int y, int width, int height, boolean processAlpha) { |
|
938 checkState(); |
|
939 drawRGB(rgbData, offset, scanlength, x, y, width, height, processAlpha, Image.TRANS_NONE); |
|
940 } |
|
941 |
|
942 /** |
|
943 * Draws a series of RGB+transparency values to specified region |
|
944 * |
|
945 * Scanlength can be negative which results in reading <code>rgbData</code> array in reverse direction |
|
946 * |
|
947 * @param rgbData an array or RGB values in format 1 bit per pixel |
|
948 * @param transparencyMask an array of mask values |
|
949 * @param offset the array index of the first ARGB value |
|
950 * @param scanlenght the relative arra offset between consecutive rows in the <code>rgbData</code> array |
|
951 * @param x the horizontal location of the region to be rendered |
|
952 * @param y the vertical location of the region to be rendered |
|
953 * @param width the width of the region to be rendered |
|
954 * @param height the height of the region to be rendered |
|
955 * @param manipulation transformation to be applied, one of Image.TRANS_* definitions |
|
956 * @throws NullPointerException if <code>rgbData</code> is null |
|
957 * @throws IllegalArgumentException if manipulation is invalid |
|
958 * @throws ArrayIndexOutOfBoundsException if operation will attempt to access elemens outside the range of <code>rgbData</code> array |
|
959 * @throws IllegalStateException if no target is bound |
|
960 */ |
|
961 public void drawRGB(byte[] rgbData, byte[] transparencyMask,int offset, int scanlength, int x, int y, int width, int height, int manipulation, int format) { |
|
962 checkState(); |
|
963 if(rgbData == null) { |
|
964 throw new NullPointerException("rgbData is null"); |
|
965 } |
|
966 // check most obvious cases where we end up outside array bounds and abort |
|
967 // native peer will throw also exception if operation goes outside of array bounds |
|
968 if((offset < 0) || (rgbData.length < offset + width) ) { |
|
969 throw new ArrayIndexOutOfBoundsException(); |
|
970 } |
|
971 if (!isManipulationValid(manipulation)) { |
|
972 throw new IllegalArgumentException("Invalid manipulation"); |
|
973 } |
|
974 |
|
975 if(scanlength == 0) { |
|
976 return; |
|
977 } |
|
978 if(width <= 0 || height <= 0) { |
|
979 return; |
|
980 } |
|
981 if(Math.abs(scanlength) < width) { |
|
982 return; |
|
983 } |
|
984 if(targetData.isJavaCommandBuffer) { |
|
985 targetData.commandBuffer.drawRGB(rgbData, transparencyMask, offset, scanlength, x, y, width, height, manipulation, format); |
|
986 } else { |
|
987 OS.graphicsContext_drawRGB(handle, rgbData, transparencyMask, offset, scanlength, x, y, width, height, manipulation, format); |
|
988 } |
|
989 } |
|
990 |
|
991 |
|
992 /** |
|
993 * Draws a series of RGB+transparency values to specified region |
|
994 * |
|
995 * Scanlength can be negative which results in reading <code>rgbData</code> array in reverse direction |
|
996 * |
|
997 * @param rgbData an array or ARGB values in format #AARRGGBB |
|
998 * @param offset the array index of the first ARGB value |
|
999 * @param scanlenght the relative arra offset between consecutive rows in the <code>rgbData</code> array |
|
1000 * @param x the horizontal location of the region to be rendered |
|
1001 * @param y the vertical location of the region to be rendered |
|
1002 * @param width the width of the region to be rendered |
|
1003 * @param height the height of the region to be rendered |
|
1004 * @param processAlpha <code>true</code> if <code>rgbData</code> has an alpha channel, <code>false</code> if all pixels are fully opaque |
|
1005 * @param manipulation transformation to be applied, one of Image.TRANS_* definitions |
|
1006 * @throws NullPointerException if <code>rgbData</code> is null |
|
1007 * @throws IllegalArgumentException if manipulation is invalid |
|
1008 * @throws ArrayIndexOutOfBoundsException if operation will attempt to access elemens outside the range of <code>rgbData</code> array |
|
1009 * @throws IllegalStateException if no target is bound |
|
1010 */ |
|
1011 public void drawRGB(short[] rgbData, int offset, int scanlength, int x, int y, int width, int height, boolean processAlpha, int manipulation, int format) { |
|
1012 checkState(); |
|
1013 if(rgbData == null) { |
|
1014 throw new NullPointerException("rgbData is null"); |
|
1015 } |
|
1016 // check most obvious cases where we end up outside array bounds and abort |
|
1017 // native peer will throw also exception if operation goes outside of array bounds |
|
1018 if((offset < 0) || (rgbData.length < offset + width) ) { |
|
1019 throw new ArrayIndexOutOfBoundsException(); |
|
1020 } |
|
1021 if (!isManipulationValid(manipulation)) { |
|
1022 throw new IllegalArgumentException("Invalid manipulation"); |
|
1023 } |
|
1024 if(scanlength == 0) { |
|
1025 return; |
|
1026 } |
|
1027 if(width <= 0 || height <= 0) { |
|
1028 return; |
|
1029 } |
|
1030 if(Math.abs(scanlength) < width) { |
|
1031 return; |
|
1032 } |
|
1033 if(targetData.isJavaCommandBuffer) { |
|
1034 targetData.commandBuffer.drawRGB(rgbData, offset, scanlength, x, y, width, height, processAlpha, manipulation, format); |
|
1035 } else { |
|
1036 OS.graphicsContext_drawRGB(handle, rgbData, offset, scanlength, x, y, width, height, processAlpha, manipulation, format); |
|
1037 } |
|
1038 } |
|
1039 /** |
|
1040 * Draws outline round-cornered rectangle specified by the arguments using foreground color. |
|
1041 * |
|
1042 * @param x The x coordinate of top left corner of rectangle |
|
1043 * @param y The y coordinate of top left corner of rectangle |
|
1044 * @param width The width of rectangle |
|
1045 * @param height The height of rectangle |
|
1046 * @param arcWidth The width of the rectangle corner arc |
|
1047 * @param arcHeight The heiht of the rectangle corner arc |
|
1048 * @throws IllegalStateException if no target is bound |
|
1049 */ |
|
1050 public void drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) { |
|
1051 checkState(); |
|
1052 if(width <= 0 || height <= 0) { |
|
1053 return; |
|
1054 } |
|
1055 if(targetData.isJavaCommandBuffer) { |
|
1056 targetData.commandBuffer.drawRoundRect(x, y, width, height, arcWidth, arcHeight); |
|
1057 } else { |
|
1058 OS.graphicsContext_drawRoundRect(handle, x, y, width, height, arcWidth, arcHeight); |
|
1059 } |
|
1060 } |
|
1061 |
|
1062 /** |
|
1063 * Draws the given string to specified location using the current font and foreground color. |
|
1064 * Note: no tab expansion or carriage return processing will be performed. |
|
1065 * |
|
1066 * @param string The string to draw |
|
1067 * @param x The x coordinate of top left corner of rectangular are where the string is drawn |
|
1068 * @param y The y coordinate of top left corner of rectangular are where the string is drawn |
|
1069 * @param sTransparent If true the background will be transparent, otherwise it will be opaque |
|
1070 * @throws IllegalStateException if no target is bound |
|
1071 */ |
|
1072 // TODO version for drawing bounding box (eSWT) |
|
1073 public void drawString(String string, int x, int y, boolean isTransparent) { |
|
1074 checkState(); |
|
1075 drawString( |
|
1076 string, |
|
1077 x, |
|
1078 y, |
|
1079 0, |
|
1080 0, |
|
1081 (GraphicsContext.ALIGNMENT_LEFT | GraphicsContext.ALIGNMENT_TOP), |
|
1082 GraphicsContext.TEXT_SINGLE_LINE, |
|
1083 isTransparent); |
|
1084 } |
|
1085 |
|
1086 /** |
|
1087 * Draws the given string to specified location using the current font and foreground color. |
|
1088 * <code>alignments</code> and <code>flags</code> can be combined by |
|
1089 * using the bit-wise or operation. |
|
1090 * |
|
1091 * @param string The string to draw |
|
1092 * @param x The x coordinate of top left corner of rectangular are where the string is drawn |
|
1093 * @param y The y coordinate of top left corner of rectangular are where the string is drawn |
|
1094 * @param width The width of rectangular are where the string is drawn. |
|
1095 * If 0 then the width is calculated based on the given <code>string</code>, <code>alignments</code> and <code>flags</code>. |
|
1096 * @param height The height of rectangular are where the string is drawn. |
|
1097 * If 0 then the height is calculated based on the given <code>text</code>, <code>alignments</code> and <code>flags</code>. |
|
1098 * @param alingments Alingments: |
|
1099 * <ul> |
|
1100 * <li>ALIGNMENT_LEFT - Aligns with the left edge</li> |
|
1101 * <li>ALIGNMENT_RIGHT - Aligns with the right edge</li> |
|
1102 * <li>ALIGNMENT_HCENTER - Centers horizontally in the available space</li> |
|
1103 * <li>ALIGNMENT_TOP - Aligns with the top</li> |
|
1104 * <li>ALIGNMENT_BOTTOM - Aligns with the bottom</li> |
|
1105 * <li>ALIGNMENT_VCENTER - Centers vertically in the available space</li> |
|
1106 * </ul> |
|
1107 * @param flags Flags: |
|
1108 * <ul> |
|
1109 * <li>TEXT_SINGLE_LINE - One line. Whitespaces are threated as spaces</li> |
|
1110 * <li>TEXT_DONT_CLIP - Prints outside of the given bounds if needed</li> |
|
1111 * <li>TEXT_EXPAND_TABS - Expand tabs</li> |
|
1112 * <li>TEXT_SHOW_MNEMONIC - Underline the mnemonic character</li> |
|
1113 * <li>TEXT_WORD_WRAP - Breaks lines at appropriate points</li> |
|
1114 * <li>TEXT_WRAP_ANYWHERE - Breaks lines anywhere, even within words</li> |
|
1115 * <li>TEXT_DONT_PRINT - Behaves like a "hidden" text, not printed</li> |
|
1116 * <li>TEXT_INCLUDE_TAILING_SPACES - Trailing whitespace not deleted automatically</li> |
|
1117 * <li>TEXT_JUSTIFICATIONFORCED - Ensures that text lines are justified</li> |
|
1118 * </ul> |
|
1119 */ |
|
1120 public void drawString( |
|
1121 String string, int x, int y, int width, int height, int alignments, int flags, boolean isTransparent) { |
|
1122 checkState(); |
|
1123 |
|
1124 if (string == null) { |
|
1125 throw new NullPointerException("string is null"); |
|
1126 } |
|
1127 if( (flags & TEXT_DONT_PRINT)== TEXT_DONT_PRINT) |
|
1128 { // nothing should be drawn |
|
1129 return; |
|
1130 } |
|
1131 if(targetData.isJavaCommandBuffer) { |
|
1132 targetData.commandBuffer.drawString(string, x, y, width, height, alignments, flags, isTransparent); |
|
1133 } else { |
|
1134 OS.graphicsContext_drawString(handle, string, x, y, width, height, alignments, flags, isTransparent); |
|
1135 } |
|
1136 } |
|
1137 |
|
1138 /** |
|
1139 * Fill interior of circular or elliptical arc within specified rectangular area, using background color. |
|
1140 * |
|
1141 * @param x The x coordinate of top left corner of arc rectangle |
|
1142 * @param y The y coordinate of top left corner of arc rectangle |
|
1143 * @param width The width of arc rectangle |
|
1144 * @param height The height of arc rectangle |
|
1145 * @param startAngle The starting angle for arc |
|
1146 * @param arcAngle The span angle for arc |
|
1147 * @throws IllegalStateException if no target is bound |
|
1148 */ |
|
1149 public void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle) { |
|
1150 checkState(); |
|
1151 if(width <= 0 || height <= 0) { |
|
1152 return; |
|
1153 } |
|
1154 if(targetData.isJavaCommandBuffer) { |
|
1155 targetData.commandBuffer.fillArc(x, y, width, height, startAngle, arcAngle); |
|
1156 } else { |
|
1157 OS.graphicsContext_fillArc(handle, x, y, width, height, startAngle, arcAngle); |
|
1158 } |
|
1159 } |
|
1160 |
|
1161 /** |
|
1162 * Fills interior of an ellipse/oval within specified rectangular area, using background color. |
|
1163 * |
|
1164 * @param x The x coordinate of top left corner of ellipse rectangle |
|
1165 * @param y The y coordinate of top left corner of ellipse rectangle |
|
1166 * @param width The width of ellipse rectangle |
|
1167 * @param height The height of ellipse rectangle |
|
1168 * @throws IllegalStateException if no target is bound |
|
1169 */ |
|
1170 public void fillEllipse(int x, int y, int width, int height) { |
|
1171 checkState(); |
|
1172 if(width <= 0 || height <= 0) { |
|
1173 return; |
|
1174 } |
|
1175 if(targetData.isJavaCommandBuffer) { |
|
1176 targetData.commandBuffer.fillEllipse(x, y, width, height); |
|
1177 } else { |
|
1178 OS.graphicsContext_fillEllipse(handle, x, y, width, height); |
|
1179 } |
|
1180 } |
|
1181 |
|
1182 /** |
|
1183 * Fills interior of specified rectangle with a gradient sweeping from left to right or top to bottom |
|
1184 * from foregroundcolor to backgroundcolor or from backgroundcolor to foregroundcolor depending on <code>swapColors</code>. |
|
1185 * |
|
1186 * @param x The x coordinate of top left corner of rectangle |
|
1187 * @param y The y coordinate of top left corner of rectangle |
|
1188 * @param width The width of rectangle |
|
1189 * @param height The height of rectangle |
|
1190 * @param vertical if true sweeps from top to bottom, else sweeps from left to right |
|
1191 * @param swapColors if true sweep is performed from background color to foreground color, else from foreground color to background color |
|
1192 * @throws IllegalStateException if no target is bound |
|
1193 */ |
|
1194 public void fillGradientRect(int x, int y, int width, int height, boolean vertical, boolean swapColors) { |
|
1195 checkState(); |
|
1196 if(width <= 0 || height <= 0) { |
|
1197 return; |
|
1198 } |
|
1199 if(targetData.isJavaCommandBuffer) { |
|
1200 targetData.commandBuffer.fillGradientRect(x, y, width, height, vertical, swapColors); |
|
1201 } else { |
|
1202 OS.graphicsContext_fillGradientRect(handle, x, y, width, height, vertical, swapColors); |
|
1203 } |
|
1204 } |
|
1205 |
|
1206 /** |
|
1207 * Fills interior of closed polygon which is specified by array of integer coordinates, |
|
1208 * using background color. Lines are drawn between each consecutive x,y pairs and between first and last point. |
|
1209 * |
|
1210 * @param pointArray An array alternating x and y values which are the verices of the polygon |
|
1211 * @throws NullPointerException if <code>pointArray</code> is null |
|
1212 * @throws IllegalStateException if no target is bound |
|
1213 */ |
|
1214 public void fillPolygon(int[] pointArray) { |
|
1215 checkState(); |
|
1216 if (pointArray == null) { |
|
1217 throw new NullPointerException("pointaArray is null"); |
|
1218 } |
|
1219 if(targetData.isJavaCommandBuffer) { |
|
1220 targetData.commandBuffer.fillPolygon(pointArray); |
|
1221 } else { |
|
1222 OS.graphicsContext_fillPolygon(handle, pointArray); |
|
1223 } |
|
1224 } |
|
1225 |
|
1226 /** |
|
1227 * Fills interior of the specified rectangle, using background color. |
|
1228 * |
|
1229 * @param x The x coordinate of top left corner of rectangle |
|
1230 * @param y The y coordinate of top left corner of rectangle |
|
1231 * @param width The width of rectangle |
|
1232 * @param height The height of rectangle |
|
1233 * @throws IllegalStateException if no target is bound |
|
1234 */ |
|
1235 public void fillRect(int x, int y, int width, int height) { |
|
1236 checkState(); |
|
1237 if(width <= 0 || height <= 0) { |
|
1238 return; |
|
1239 } |
|
1240 if(targetData.isJavaCommandBuffer) { |
|
1241 targetData.commandBuffer.fillRect(x, y, width, height); |
|
1242 } else { |
|
1243 OS.graphicsContext_fillRect(handle, x, y, width, height); |
|
1244 } |
|
1245 } |
|
1246 |
|
1247 /** |
|
1248 * Fills interior of round-cornered rectangle, using background color. |
|
1249 * |
|
1250 * @param x The x coordinate of top left corner of rectangle |
|
1251 * @param y The y coordinate of top left corner of rectangle |
|
1252 * @param width The width of rectangle |
|
1253 * @param height The height of rectangle |
|
1254 * @param arcWidth The width of the rectangle corner arc |
|
1255 * @param arcHeight The heiht of the rectangle corner arc |
|
1256 * @throws IllegalStateException if no target is bound |
|
1257 */ |
|
1258 public void fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) { |
|
1259 checkState(); |
|
1260 |
|
1261 if(width <= 0 || height <= 0) { |
|
1262 return; |
|
1263 } |
|
1264 if(targetData.isJavaCommandBuffer) { |
|
1265 targetData.commandBuffer.fillRoundRectangle(x, y, width, height, arcWidth, arcHeight); |
|
1266 } else { |
|
1267 OS.graphicsContext_fillRoundRect(handle, x, y, width, height, arcWidth, arcHeight); |
|
1268 } |
|
1269 } |
|
1270 |
|
1271 /** |
|
1272 * Get the advance width of the specified character in the font which is |
|
1273 * currently selected into the receiver. |
|
1274 * @param ch The character to be measured |
|
1275 * @return The distance in the x direction to move past the character before painting the next |
|
1276 */ |
|
1277 public int getAdvancedCharacterWidth(char ch) { |
|
1278 checkState(); |
|
1279 if(targetData.isJavaCommandBuffer) { |
|
1280 return targetData.commandBuffer.getAdvancedCharacterWidth(ch, true); |
|
1281 } else { |
|
1282 return OS.graphicsContext_getCharacterWidth(handle, ch, true); |
|
1283 } |
|
1284 } |
|
1285 |
|
1286 /** |
|
1287 * Get the advance width of the specified character in the font which is |
|
1288 * currently selected into the receiver. |
|
1289 * The width is defined as the space taken up by the actual character, |
|
1290 * not including the leading and tailing whitespace or overhang. |
|
1291 * |
|
1292 * @param ch The character to be measured |
|
1293 * @return The width of the character |
|
1294 */ |
|
1295 public int getCharacterWidth(char ch) { |
|
1296 checkState(); |
|
1297 if(targetData.isJavaCommandBuffer) { |
|
1298 return targetData.commandBuffer.getAdvancedCharacterWidth(ch, true); |
|
1299 } else { |
|
1300 return OS.graphicsContext_getCharacterWidth(handle, ch, false); |
|
1301 } |
|
1302 } |
|
1303 |
|
1304 /** |
|
1305 * Gets the <code>FontMetrics</code> data. |
|
1306 * |
|
1307 * Values are stored in the data array as follows: |
|
1308 * <ul> |
|
1309 * <li>data[0] = ASCENT |
|
1310 * <li>data[1] = AVERAGE CHAR WIDTH |
|
1311 * <li>data[2] = DESCENT |
|
1312 * <li>data[3] = HEIGHT |
|
1313 * <li>data[4] = LEADING |
|
1314 * </ul> |
|
1315 * @param data The integer array where to copy <code>FontMetrics</code> data. |
|
1316 * @param fontHandle If not zero then Fontmetrics data will be based on it |
|
1317 * otherwise data is based on the font which is currently selected into the receiver. |
|
1318 * @throws NullPointerException if data is null |
|
1319 * @throws IllegalStateException if no target is bound |
|
1320 */ |
|
1321 |
|
1322 public void getFontMetricsData(int[] data, int fontHandle) { |
|
1323 getFontMetricsData(data, fontHandle, true); |
|
1324 } |
|
1325 |
|
1326 public void getFontMetricsData(int[] data, int fontHandle, boolean check) { |
|
1327 if (check) checkState(); |
|
1328 if (data == null) { |
|
1329 throw new NullPointerException("data is null"); |
|
1330 } |
|
1331 if(targetData.isJavaCommandBuffer) { |
|
1332 targetData.commandBuffer.getFontMetricsData(data, fontHandle); |
|
1333 } else { |
|
1334 OS.graphicsContext_getFontMetricsData(handle, data, fontHandle); |
|
1335 } |
|
1336 } |
|
1337 |
|
1338 /** |
|
1339 * Gets the alpha component of the background color. |
|
1340 * |
|
1341 * @return The alpha value (0-255) |
|
1342 * @throws IllegalStateException if no target is bound |
|
1343 */ |
|
1344 public int getBackgroundAlpha() { |
|
1345 checkState(); |
|
1346 if(targetData.isJavaCommandBuffer) { |
|
1347 return targetData.commandBuffer.getBackgroundAlpha(); |
|
1348 } else { |
|
1349 return OS.graphicsContext_getBackgroundAlpha(handle); |
|
1350 } |
|
1351 } |
|
1352 |
|
1353 /** |
|
1354 * Gets current background color in argb format. |
|
1355 * |
|
1356 * @return Interger containing current color in #AARRGGBB format |
|
1357 * @throws IllegalStateException if no target is bound |
|
1358 */ |
|
1359 public int getBackgroundColor() { |
|
1360 checkState(); |
|
1361 if(targetData.isJavaCommandBuffer) { |
|
1362 return targetData.commandBuffer.getBackgroundColor(); |
|
1363 } else { |
|
1364 return OS.graphicsContext_getBackgroundColor(handle); |
|
1365 } |
|
1366 } |
|
1367 |
|
1368 /** |
|
1369 * Gets current blending mode. |
|
1370 * Default blending mode is SRC_OVER. |
|
1371 * |
|
1372 * @return blending mode |
|
1373 * @throws IllegalStateException if no target is bound |
|
1374 */ |
|
1375 public int getBlendingMode() { |
|
1376 checkState(); |
|
1377 if(targetData.isJavaCommandBuffer) { |
|
1378 return targetData.commandBuffer.getBlendingMode(); |
|
1379 } else { |
|
1380 return OS.graphicsContext_getBlendingMode(handle); |
|
1381 } |
|
1382 } |
|
1383 |
|
1384 /** |
|
1385 * Gets the current clip rectangle. Retrieved clip is copied in given integer array which |
|
1386 * must have at least size of 4, in order to populate all clip values. |
|
1387 * |
|
1388 * Values are stored in clip array as follows: |
|
1389 * <ul> |
|
1390 * <li>clip[RECT_X] - the x coordinate of clip</li> |
|
1391 * <li>clip[RECT_Y] - the y coordinate of clip |
|
1392 * <li>clip[RECT_WIDTH] - the width of clip |
|
1393 * <li>clip[RECT_HEIGHT] - the height of clip |
|
1394 * </ul> |
|
1395 * @param clip The integer array where to copy clip data |
|
1396 * @throws NullPointerException if clip is null |
|
1397 * @throws IllegalArgumentException if clip.length < 4 |
|
1398 * @throws IllegalStateException if no target is bound |
|
1399 */ |
|
1400 |
|
1401 public void getClip(int[] clip) { |
|
1402 checkState(); |
|
1403 if (clip == null) { |
|
1404 throw new NullPointerException("clip is null"); |
|
1405 } |
|
1406 if (clip.length < 4 ) { |
|
1407 throw new IllegalArgumentException("clip array size is < 4"); |
|
1408 } |
|
1409 if(targetData.isJavaCommandBuffer) { |
|
1410 targetData.commandBuffer.getClip(clip); |
|
1411 } else { |
|
1412 OS.graphicsContext_getClip(handle, clip); |
|
1413 } |
|
1414 } |
|
1415 |
|
1416 /** |
|
1417 * Gets the alpha component of the foreground color. |
|
1418 * |
|
1419 * @return The alpha value (0-255) |
|
1420 * @throws IllegalStateException if no target is bound |
|
1421 */ |
|
1422 public int getForegroundAlpha() { |
|
1423 checkState(); |
|
1424 if(targetData.isJavaCommandBuffer) { |
|
1425 return targetData.commandBuffer.getForegroundAlpha(); |
|
1426 } else { |
|
1427 return OS.graphicsContext_getForegroundAlpha(handle); |
|
1428 } |
|
1429 } |
|
1430 |
|
1431 /** |
|
1432 * Gets current foreground color in argb format. |
|
1433 * |
|
1434 * @return Integer containing current color in #AARRGGBB format |
|
1435 * @throws IllegalStateException if no target is bound |
|
1436 */ |
|
1437 public int getForegroundColor() { |
|
1438 checkState(); |
|
1439 if(targetData.isJavaCommandBuffer) { |
|
1440 return targetData.commandBuffer.getForegroundColor(); |
|
1441 } else { |
|
1442 return OS.graphicsContext_getForegroundColor(handle); |
|
1443 } |
|
1444 } |
|
1445 |
|
1446 /** |
|
1447 * @see #getTextBoundingBox() |
|
1448 */ |
|
1449 public void getTextBoundingBox( |
|
1450 int[] boundingBox, String string, int alignments, int flags) { |
|
1451 getTextBoundingBox(boundingBox, string, alignments, flags, 0, 0, 0, 0); |
|
1452 } |
|
1453 |
|
1454 /** |
|
1455 * Returns a bounding box required by the given <code>string</code> when it is |
|
1456 * drawn inside the given rectangle (<code>rectX</code>, <code>rectY</code>, |
|
1457 * <code>rectWidth</code>, <code>rectHeight</code>) with the given <code>flags</code> |
|
1458 * and <code>alignments</code> using the currently set font. |
|
1459 * If the text does not fit within the given rectangle then the required bounding box |
|
1460 * is returned. |
|
1461 * |
|
1462 * @param boundingBox The integer array where to copy bounding box data. |
|
1463 * Result is stored in the array as follows: |
|
1464 * <ul> |
|
1465 * <li>boundingBox[RECT_X] - top-left x of the text bounding box</li> |
|
1466 * <li>boundingBox[RECT_Y] - top-left y of the text bounding box</li> |
|
1467 * <li>boundingBox[RECT_WIDTH] - the width of the text bounding box</li> |
|
1468 * <li>boundingBox[RECT_HEIGHT] - the height of the text bounding box</li> |
|
1469 * </ul> |
|
1470 * @param string The string |
|
1471 * @param alignments Alignments @see #drawString() |
|
1472 * @param flags Flags @see #drawString() |
|
1473 * @param rectX Drawing rectangle's top-left x coordinate. |
|
1474 * @param rectY Drawing rectangle's top-left y coordinate. |
|
1475 * @param rectWidth Drawing rectangle width. |
|
1476 * @param rectHeight Drawing rectangle height. |
|
1477 * @throws NullPointerException if <code>boundingBox</code> is null |
|
1478 * @throws NullPointerException if <code>string</code> is null |
|
1479 * @throws IllegalArgumentException if <code>boundingBox</code>.length < 4 |
|
1480 * @throws IllegalStateException if no target is bound |
|
1481 */ |
|
1482 public void getTextBoundingBox( |
|
1483 int[] boundingBox, String string, int alignments, int flags, |
|
1484 int rectX, int rectY, int rectWidth, int rectHeight) { |
|
1485 checkState(); |
|
1486 if (boundingBox == null) { |
|
1487 throw new NullPointerException("boundingBox is null"); |
|
1488 } |
|
1489 if (string == null) { |
|
1490 throw new NullPointerException("string is null"); |
|
1491 } |
|
1492 if (boundingBox.length < 4 ) { |
|
1493 throw new IllegalArgumentException("boundingBox size must not be < 4"); |
|
1494 } |
|
1495 if(targetData.isJavaCommandBuffer) { |
|
1496 targetData.commandBuffer.getTextBoundingBox(boundingBox, string, alignments, flags, rectX, rectY, rectWidth, rectHeight); |
|
1497 } else { |
|
1498 OS.graphicsContext_getTextBoundingBox( |
|
1499 handle, boundingBox, string, alignments, flags, rectX, rectY, rectWidth, rectHeight); |
|
1500 } |
|
1501 } |
|
1502 |
|
1503 /** |
|
1504 * Gets the stroke width in pixels. |
|
1505 * |
|
1506 * @return stroke width in pixels |
|
1507 * @throws IllegalStateException if no target is bound |
|
1508 */ |
|
1509 public int getStrokeWidth() { |
|
1510 checkState(); |
|
1511 if(targetData.isJavaCommandBuffer) { |
|
1512 return targetData.commandBuffer.getStrokeWidth(); |
|
1513 } else { |
|
1514 return OS.graphicsContext_getStrokeWidth(handle); |
|
1515 } |
|
1516 } |
|
1517 |
|
1518 /** |
|
1519 * Gets current stroke style, which will be one of the constants: |
|
1520 * <ul> |
|
1521 * <li>STROKE_NO: Stroke is not used</li> |
|
1522 * <li>STROKE_SOLID: Plain line style</li> |
|
1523 * <li>STROKE_DASH: Line contains dashes separated by a few pixels</li> |
|
1524 * <li>STROKE_DOT: Line contains dots separated by a few pixels</li> |
|
1525 * <li>STROKE_DASH_DOT: Dot-dash line type</li> |
|
1526 * <li>STROKE_DASH_DOT_DOT: Dash-dot-dot line type</li> |
|
1527 * </ul> |
|
1528 * |
|
1529 * @return The style used for strokes |
|
1530 * @throws IllegalStateException if no target is bound |
|
1531 */ |
|
1532 public int getStrokeStyle() { |
|
1533 checkState(); |
|
1534 if(targetData.isJavaCommandBuffer) { |
|
1535 return targetData.commandBuffer.getStrokeStyle(); |
|
1536 } else { |
|
1537 return OS.graphicsContext_getStrokeStyle(handle); |
|
1538 } |
|
1539 } |
|
1540 |
|
1541 /** |
|
1542 * Gets the x coorinate of translated origin |
|
1543 * @return the x coorinate of origin |
|
1544 */ |
|
1545 public int getTranslateX() { |
|
1546 checkState(); |
|
1547 if(targetData.isJavaCommandBuffer) { |
|
1548 return targetData.commandBuffer.getTranslateX(); |
|
1549 } else { |
|
1550 return OS.graphicsContext_getTranslateX(handle); |
|
1551 } |
|
1552 } |
|
1553 |
|
1554 /** |
|
1555 * Gets the y coorinate of translated origin |
|
1556 * @return the y coorinate of origin |
|
1557 */ |
|
1558 public int getTranslateY() { |
|
1559 checkState(); |
|
1560 if(targetData.isJavaCommandBuffer) { |
|
1561 return targetData.commandBuffer.getTranslateY(); |
|
1562 } else { |
|
1563 return OS.graphicsContext_getTranslateY(handle); |
|
1564 } |
|
1565 } |
|
1566 |
|
1567 /** |
|
1568 * Sets alpha component value for background color |
|
1569 * |
|
1570 * @param alpha The alpha value to be set in range 0-255 |
|
1571 * @throws IllegalArgumentException if alpha is not in range of 0-255 |
|
1572 * @throws IllegalStateException if no target is bound |
|
1573 */ |
|
1574 public void setBackgroundAlpha(int alpha) { |
|
1575 checkState(); |
|
1576 if (alpha < 0 || alpha > 255 ) { |
|
1577 throw new IllegalArgumentException("alpha is not in range 0-255"); |
|
1578 } |
|
1579 if(targetData.isJavaCommandBuffer) { |
|
1580 targetData.commandBuffer.setBackgroundAlpha(alpha); |
|
1581 } else { |
|
1582 OS.graphicsContext_setBackgroundAlpha(handle, alpha); |
|
1583 } |
|
1584 } |
|
1585 |
|
1586 /** |
|
1587 * Sets the background color. |
|
1588 * The background color is used for fill operations and as the background color when text is drawn |
|
1589 * |
|
1590 * @param argb The color and alpha to be set in 32-bit format #AARRGGBB |
|
1591 * @throws IllegalStateException if no target is bound |
|
1592 */ |
|
1593 public void setBackgroundColor(int argb, boolean updateAlpha) { |
|
1594 checkState(); |
|
1595 if(targetData.isJavaCommandBuffer) { |
|
1596 targetData.commandBuffer.setBackgroundColor(argb, updateAlpha); |
|
1597 } else { |
|
1598 OS.graphicsContext_setBackgroundColor(handle, argb, updateAlpha); |
|
1599 } |
|
1600 } |
|
1601 |
|
1602 /** |
|
1603 * Sets the background color. |
|
1604 * The background color is used for fill operations and as the background color when text is drawn |
|
1605 * |
|
1606 * @param red The red component of the color being set in range 0-255 |
|
1607 * @param green The green component of the color being set in range 0-255 |
|
1608 * @param blue The blue component of the color being set in range 0-255 |
|
1609 * @throws IllegalArgumentException if red, green or blue is not in range of 0-255 |
|
1610 * @throws IllegalStateException if no target is bound |
|
1611 */ |
|
1612 public void setBackgroundColor(int red, int green, int blue) { |
|
1613 checkState(); |
|
1614 |
|
1615 if (red < 0 || red > 255 || |
|
1616 green < 0 || green > 255 || |
|
1617 blue < 0 || blue > 255 ) { |
|
1618 throw new IllegalArgumentException(); |
|
1619 } |
|
1620 if(targetData.isJavaCommandBuffer) { |
|
1621 targetData.commandBuffer.setBackgroundColor((0xff000000 | (red << 16) | (green << 8) | blue), false); |
|
1622 } else { |
|
1623 OS.graphicsContext_setBackgroundColor(handle, (0xff000000 | (red << 16) | (green << 8) | blue), false); |
|
1624 } |
|
1625 } |
|
1626 |
|
1627 /** |
|
1628 * Sets the background color. |
|
1629 * The background color is used for fill operations and as the background color when text is drawn |
|
1630 * |
|
1631 * @param alpha The alpha component of the color being set in range 0-255 |
|
1632 * @param red The red component of the color being set in range 0-255 |
|
1633 * @param green The green component of the color being set in range 0-255 |
|
1634 * @param blue The blue component of the color being set in range 0-255 |
|
1635 * @throws IllegalArgumentException if alpha, red, green or blue is not in range of 0-255 |
|
1636 * @throws IllegalStateException if no target is bound |
|
1637 */ |
|
1638 public void setBackgroundColor(int alpha, int red, int green, int blue) { |
|
1639 checkState(); |
|
1640 |
|
1641 if (alpha < 0 || alpha > 255 || |
|
1642 red < 0 || red > 255 || |
|
1643 green < 0 || green > 255 || |
|
1644 blue < 0 || blue > 255 ) { |
|
1645 throw new IllegalArgumentException(); |
|
1646 } |
|
1647 if(targetData.isJavaCommandBuffer) { |
|
1648 targetData.commandBuffer.setBackgroundColor(((alpha << 24) | (red << 16) | (green << 8) | blue), true); |
|
1649 } else { |
|
1650 OS.graphicsContext_setBackgroundColor(handle,((alpha << 24) | (red << 16) | (green << 8) | blue), true); |
|
1651 } |
|
1652 } |
|
1653 |
|
1654 /** |
|
1655 * Sets blending mode. The blending mode dictates how rendered pixels are combined with the destination pixels. |
|
1656 * The default blending mode is BLENDING_MODE_SRC_OVER, i.e. if not other mode is set using this method. |
|
1657 * |
|
1658 * If the bound target does not have and alpha channel the set mode has no effect. |
|
1659 * |
|
1660 * @param mode The blending mode to be set, one of BLENDING_MODE_SRC, BLENDING_MODE_SRC_OVER or BLENDING_MODE_XOR |
|
1661 * @throws IllegalArgumentException if mode is not one of listed above |
|
1662 * @throws IllegalStateException if no target is bound |
|
1663 */ |
|
1664 public void setBlendingMode(int mode) { |
|
1665 checkState(); |
|
1666 if ( mode != BLENDING_MODE_SRC && |
|
1667 mode != BLENDING_MODE_SRC_OVER && |
|
1668 mode != BLENDING_MODE_XOR) { |
|
1669 throw new IllegalArgumentException("Illegal blending mode"); |
|
1670 } |
|
1671 if(targetData.isJavaCommandBuffer) { |
|
1672 targetData.commandBuffer.setBlendingMode(mode); |
|
1673 } else { |
|
1674 OS.graphicsContext_setBlendingMode(handle, mode); |
|
1675 } |
|
1676 } |
|
1677 |
|
1678 /** |
|
1679 * Returns if clipped or not. |
|
1680 * @return True if clipping region is set, and false otherwise |
|
1681 */ |
|
1682 public boolean hasClipping() { |
|
1683 checkState(); |
|
1684 if(targetData.isJavaCommandBuffer) { |
|
1685 return targetData.commandBuffer.hasClipping(); |
|
1686 } else { |
|
1687 return OS.graphicsContext_hasClipping(handle); |
|
1688 } |
|
1689 } |
|
1690 |
|
1691 /** |
|
1692 * Reset clipping region. |
|
1693 */ |
|
1694 public void cancelClipping() { |
|
1695 checkState(); |
|
1696 if(targetData.isJavaCommandBuffer) { |
|
1697 targetData.commandBuffer.cancelClipping(); |
|
1698 } else { |
|
1699 OS.graphicsContext_cancelClipping(handle); |
|
1700 } |
|
1701 } |
|
1702 |
|
1703 /** |
|
1704 * Sets the clip rectangle where draw operations will take affect. |
|
1705 * Rendering operations have no effect outside of the clipping area. |
|
1706 * |
|
1707 * If intersects is set as true then the clip area is set to area where the current and given |
|
1708 * clip rectangle intersect, i.e. where they overlap. |
|
1709 * |
|
1710 * If width or height is negative request is silently ignored. |
|
1711 * |
|
1712 * @param x The x coordinate for the clip area |
|
1713 * @param y The y coordinate for the clip area |
|
1714 * @param width The width of the clip area |
|
1715 * @param height The height of the clip area |
|
1716 * @param intersects if true clip is set as interscetion of current and given clip rectangle, |
|
1717 * otherwise the clip is set as specified |
|
1718 * @throws IllegalStateException if no target is bound |
|
1719 */ |
|
1720 public void setClip(int x, int y, int width, int height, boolean intersects) { |
|
1721 checkState(); |
|
1722 |
|
1723 if(width < 0 || height < 0) { |
|
1724 return; |
|
1725 } |
|
1726 if(targetData.isJavaCommandBuffer) { |
|
1727 targetData.commandBuffer.setClip(x, y, width, height, intersects); |
|
1728 } else { |
|
1729 OS.graphicsContext_setClip(handle, x, y, width, height, intersects); |
|
1730 } |
|
1731 } |
|
1732 |
|
1733 /** |
|
1734 * Sets font which is used in drawString. |
|
1735 * |
|
1736 * @param fontHandle The handle of native QFont |
|
1737 */ |
|
1738 public void setFont(int fontHandle) { |
|
1739 checkState(); |
|
1740 if(targetData.isJavaCommandBuffer) { |
|
1741 targetData.commandBuffer.setFont(fontHandle); |
|
1742 } else { |
|
1743 OS.graphicsContext_setFont(handle, fontHandle); |
|
1744 } |
|
1745 } |
|
1746 |
|
1747 /** |
|
1748 * Sets alpha component value for foreground color |
|
1749 * |
|
1750 * @param alpha The alpha value to be set in range 0-255 |
|
1751 * @throws IllegalArgumentException if alpha is not in range of 0-255 |
|
1752 * @throws IllegalStateException if no target is bound |
|
1753 */ |
|
1754 public void setForegroundAlpha(int alpha) { |
|
1755 checkState(); |
|
1756 if (alpha < 0 || alpha > 255 ) { |
|
1757 throw new IllegalArgumentException("alpha is not in range 0-255"); |
|
1758 } |
|
1759 if(targetData.isJavaCommandBuffer) { |
|
1760 targetData.commandBuffer.setForegroundAlpha(alpha); |
|
1761 } else { |
|
1762 OS.graphicsContext_setForegroundAlpha(handle, alpha); |
|
1763 } |
|
1764 } |
|
1765 |
|
1766 /** |
|
1767 * Sets the foreground color. |
|
1768 * TThe foreground color is used for non fill primitives. |
|
1769 * |
|
1770 * @param argb The color and alpha to be set in 32-bit format #AARRGGBB |
|
1771 * @throws IllegalStateException if no target is bound |
|
1772 */ |
|
1773 public void setForegroundColor(int argb, boolean updateAlpha) { |
|
1774 checkState(); |
|
1775 if(targetData.isJavaCommandBuffer) { |
|
1776 targetData.commandBuffer.setForegroundColor(argb, updateAlpha); |
|
1777 } else { |
|
1778 OS.graphicsContext_setForegroundColor(handle, argb, updateAlpha); |
|
1779 } |
|
1780 } |
|
1781 /** |
|
1782 * Sets the foreground color. |
|
1783 * The foreground color is used for non fill primitives. |
|
1784 * |
|
1785 * @param red The red component of the color being set in range 0-255 |
|
1786 * @param green The green component of the color being set in range 0-255 |
|
1787 * @param blue The blue component of the color being set in range 0-255 |
|
1788 * @throws IllegalArgumentException if red, green or blue is not in range of 0-255 |
|
1789 * @throws IllegalStateException if no target is bound |
|
1790 */ |
|
1791 public void setForegroundColor(int red, int green, int blue) { |
|
1792 checkState(); |
|
1793 |
|
1794 if (red < 0 || red > 255 || |
|
1795 green < 0 || green > 255 || |
|
1796 blue < 0 || blue > 255 ) { |
|
1797 throw new IllegalArgumentException(); |
|
1798 } |
|
1799 if(targetData.isJavaCommandBuffer) { |
|
1800 targetData.commandBuffer.setForegroundColor((0xff000000 | (red << 16) | (green << 8) | blue), false); |
|
1801 } else { |
|
1802 OS.graphicsContext_setForegroundColor(handle, (0xff000000 | (red << 16) | (green << 8) | blue), false); |
|
1803 } |
|
1804 } |
|
1805 |
|
1806 /** |
|
1807 * Sets the foreground color. |
|
1808 * The foreground color is used for non fill primitives. |
|
1809 * |
|
1810 * @param alpha The alpha component of the color being set in range 0-255 |
|
1811 * @param red The red component of the color being set in range 0-255 |
|
1812 * @param green The green component of the color being set in range 0-255 |
|
1813 * @param blue The blue component of the color being set in range 0-255 |
|
1814 * @throws IllegalArgumentException if alpha, red, green or blue is not in range of 0-255 |
|
1815 * @throws IllegalStateException if no target is bound |
|
1816 */ |
|
1817 public void setForegroundColor(int alpha, int red, int green, int blue) { |
|
1818 checkState(); |
|
1819 |
|
1820 if (alpha < 0 || alpha > 255 || |
|
1821 red < 0 || red > 255 || |
|
1822 green < 0 || green > 255 || |
|
1823 blue < 0 || blue > 255 ) { |
|
1824 throw new IllegalArgumentException(); |
|
1825 } |
|
1826 if(targetData.isJavaCommandBuffer) { |
|
1827 targetData.commandBuffer.setForegroundColor(((alpha << 24) | (red << 16) | (green << 8) | blue), true); |
|
1828 } else { |
|
1829 OS.graphicsContext_setForegroundColor(handle,((alpha << 24) | (red << 16) | (green << 8) | blue), true); |
|
1830 } |
|
1831 } |
|
1832 |
|
1833 /** |
|
1834 * Sets the stroke style, which is one of STROKE_SOLID, STROKE_DOT, STROKE_DASH, |
|
1835 * STROKE_DASHDOT or STROKE_DASHDOTDOT. |
|
1836 * |
|
1837 * @param style The style to be set |
|
1838 * @throws IllegalArgumentException if style is not one of listed above |
|
1839 * @throws IllegalStateException if no target is bound |
|
1840 */ |
|
1841 public void setStrokeStyle(int style) { |
|
1842 checkState(); |
|
1843 |
|
1844 if (style != STROKE_SOLID && |
|
1845 style != STROKE_DOT && |
|
1846 style != STROKE_DASH && |
|
1847 style != STROKE_DASH_DOT && |
|
1848 style != STROKE_DASH_DOT_DOT ) { |
|
1849 throw new IllegalArgumentException("Invalid style: " + style); |
|
1850 } |
|
1851 if(targetData.isJavaCommandBuffer) { |
|
1852 targetData.commandBuffer.setStrokeStyle(style); |
|
1853 } else { |
|
1854 OS.graphicsContext_setStrokeStyle(handle, style); |
|
1855 } |
|
1856 } |
|
1857 |
|
1858 /** |
|
1859 * Sets the stroke width in pixels. |
|
1860 * |
|
1861 * @param width The stroke width in pixels |
|
1862 * @throws IllegalArgumentException if width is negative or zero |
|
1863 * @throws IllegalStateException if no target is bound |
|
1864 */ |
|
1865 public void setStrokeWidth(int width) { |
|
1866 checkState(); |
|
1867 if(width < 0) { |
|
1868 throw new IllegalArgumentException("Invalid width: " + width); |
|
1869 } |
|
1870 if(targetData.isJavaCommandBuffer) { |
|
1871 targetData.commandBuffer.setStrokeWidth(width); |
|
1872 } else { |
|
1873 OS.graphicsContext_setStrokeWidth(handle, width); |
|
1874 } |
|
1875 } |
|
1876 |
|
1877 /** |
|
1878 * Translates the origin of this graphics context to point (x,y). All coordinates used in subsequent |
|
1879 * rendering operations are relative to this new origin. |
|
1880 * |
|
1881 * @param x the x coordinate of new origin |
|
1882 * @param y the y coordinate of new origin |
|
1883 * @throws IllegalStateException if no target is bound |
|
1884 */ |
|
1885 public void translate(int x, int y) { |
|
1886 checkState(); |
|
1887 if(targetData.isJavaCommandBuffer) { |
|
1888 targetData.commandBuffer.translate(x, y); |
|
1889 } else { |
|
1890 OS.graphicsContext_translate(handle, x, y); |
|
1891 } |
|
1892 } |
|
1893 |
|
1894 /** |
|
1895 * Scales the coordinate system by (x, y). All coordinates used in subsequent |
|
1896 * rendering operations are scaled with these values. |
|
1897 * |
|
1898 * @param x the x scaling factor |
|
1899 * @param y the y scaling factor |
|
1900 * @throws IllegalStateException if no target is bound |
|
1901 */ |
|
1902 public void scale(int x, int y) { |
|
1903 checkState(); |
|
1904 if(targetData.isJavaCommandBuffer) { |
|
1905 targetData.commandBuffer.scale(x, y); |
|
1906 } else { |
|
1907 OS.graphicsContext_scale(handle, x, y); |
|
1908 } |
|
1909 } |
|
1910 |
|
1911 /** |
|
1912 * Resets any transformations that were made using translate(), scale(). |
|
1913 * |
|
1914 * @throws IllegalStateException if no target is bound |
|
1915 */ |
|
1916 public void resetTransform() { |
|
1917 checkState(); |
|
1918 if(targetData.isJavaCommandBuffer) { |
|
1919 targetData.commandBuffer.resetTransform(); |
|
1920 } else { |
|
1921 OS.graphicsContext_resetTransform(handle); |
|
1922 } |
|
1923 } |
|
1924 |
|
1925 /** |
|
1926 * Disposes this graphics context and frees all native resources. If there is a target bound, it is released |
|
1927 * automatically before cleaning resources. If this instance has already been disposed request is silently ignored. |
|
1928 */ |
|
1929 public void dispose() { |
|
1930 Utils.validateUiThread(); |
|
1931 // If already disposed just return |
|
1932 if (disposed) { |
|
1933 return; |
|
1934 } else { |
|
1935 // in case there's a bound target release it before disposing |
|
1936 if (targetData.target != null) { |
|
1937 releaseTarget(); |
|
1938 } |
|
1939 // dispose native peer |
|
1940 OS.graphicsContext_dispose(handle); |
|
1941 handle = 0; |
|
1942 disposed = true; |
|
1943 } |
|
1944 } |
|
1945 |
|
1946 /** |
|
1947 * Gets the status of this graphics context. |
|
1948 * |
|
1949 * @return True if this instance has been already disposed otherwise false |
|
1950 */ |
|
1951 public boolean isDisposed() { |
|
1952 return disposed; |
|
1953 } |
|
1954 |
|
1955 /** |
|
1956 * Gets the status of this graphics context. |
|
1957 * |
|
1958 * @return True if this instance is currently being used |
|
1959 */ |
|
1960 public boolean isActive() { |
|
1961 return (targetData.target != null); |
|
1962 } |
|
1963 |
|
1964 /** |
|
1965 * Returns native side handle. |
|
1966 * @return the native handle. |
|
1967 */ |
|
1968 public int getHandle() { |
|
1969 return handle; |
|
1970 } |
|
1971 |
|
1972 /** |
|
1973 * Saves graphics context settings. |
|
1974 */ |
|
1975 public void saveSettings() { |
|
1976 checkState(); |
|
1977 if(targetData.isJavaCommandBuffer) { |
|
1978 targetData.commandBuffer.saveSettings(); |
|
1979 } else { |
|
1980 OS.graphicsContext_saveSettings(handle); |
|
1981 } |
|
1982 } |
|
1983 |
|
1984 /** |
|
1985 * Restores graphics context settings. |
|
1986 */ |
|
1987 public void restoreSettings() { |
|
1988 checkState(); |
|
1989 if(targetData.isJavaCommandBuffer) { |
|
1990 targetData.commandBuffer.restoreSettings(); |
|
1991 } else { |
|
1992 OS.graphicsContext_restoreSettings(handle); |
|
1993 } |
|
1994 } |
|
1995 |
|
1996 /** |
|
1997 * private ,method for checking the state of this instance. |
|
1998 */ |
|
1999 private void checkState() { |
|
2000 Utils.validateUiThread(); |
|
2001 if (disposed) { |
|
2002 throw new IllegalStateException("GraphicsContext already disposed"); |
|
2003 } |
|
2004 if ( targetData.target == null ) { |
|
2005 throw new IllegalStateException("No target set"); |
|
2006 } |
|
2007 } |
|
2008 |
|
2009 /** |
|
2010 * Validates manipulation argument. |
|
2011 * @param manipulation Value to be checked |
|
2012 * @return true if given argument is valid, otherwise false |
|
2013 */ |
|
2014 private boolean isManipulationValid(int manipulation) { |
|
2015 if ((manipulation != Image.TRANS_NONE) && |
|
2016 (manipulation != Image.TRANS_ROT90) && |
|
2017 (manipulation != Image.TRANS_ROT180)&& |
|
2018 (manipulation != Image.TRANS_ROT270) && |
|
2019 (manipulation != Image.TRANS_MIRROR) && |
|
2020 (manipulation != Image.TRANS_FLIP_HORIZONTAL) && |
|
2021 (manipulation != Image.TRANS_FLIP_VERTICAL) && |
|
2022 (manipulation != Image.TRANS_MIRROR_ROT180) && |
|
2023 (manipulation != Image.TRANS_MIRROR_ROT270) && |
|
2024 (manipulation != Image.TRANS_MIRROR_ROT90)) { |
|
2025 return false; |
|
2026 } |
|
2027 return true; |
|
2028 } |
|
2029 |
|
2030 /** |
|
2031 * Processes command buffer |
|
2032 * @param buffer The buffer to be processed |
|
2033 */ |
|
2034 private void processBuffer(JavaCommandBuffer buffer) { |
|
2035 int i = 0; |
|
2036 int intCount = buffer.intParamCount(); |
|
2037 int imageCount = 0; |
|
2038 int stringCount = 0; |
|
2039 int rgbCount = 0; |
|
2040 int[] intParams = buffer.intParams(); |
|
2041 Vector images = buffer.images(); |
|
2042 String strings = buffer.strParams(); |
|
2043 Vector rgbs = buffer.rgbParams(); |
|
2044 |
|
2045 while( i < intCount ) { |
|
2046 switch ((intParams[i] >> 24)) { |
|
2047 // |
|
2048 // Draw op code handling |
|
2049 // |
|
2050 case JavaCommandBuffer.DRAW_PREFIX: |
|
2051 { |
|
2052 switch (intParams[i++]) { |
|
2053 case JavaCommandBuffer.OP_DRAWARC: |
|
2054 { |
|
2055 OS.graphicsContext_drawArc(handle, |
|
2056 intParams[i++], |
|
2057 intParams[i++], |
|
2058 intParams[i++], |
|
2059 intParams[i++], |
|
2060 intParams[i++], |
|
2061 intParams[i++]); |
|
2062 break; |
|
2063 } |
|
2064 case JavaCommandBuffer.OP_DRAWLINE: |
|
2065 { |
|
2066 OS.graphicsContext_drawLine(handle, |
|
2067 intParams[i++], |
|
2068 intParams[i++], |
|
2069 intParams[i++], |
|
2070 intParams[i++]); |
|
2071 break; |
|
2072 } |
|
2073 case JavaCommandBuffer.OP_DRAWIMAGE1: |
|
2074 { |
|
2075 Image img = (Image)images.elementAt(imageCount++); |
|
2076 OS.graphicsContext_drawImage(handle, |
|
2077 img.handle, |
|
2078 intParams[i++], |
|
2079 intParams[i++]); |
|
2080 // As we made a shallow copy of the image in buffer |
|
2081 // its safe to delete that here |
|
2082 img.dispose(); |
|
2083 break; |
|
2084 } |
|
2085 case JavaCommandBuffer.OP_DRAWIMAGE2: |
|
2086 { |
|
2087 Image img = (Image)images.elementAt(imageCount++); |
|
2088 OS.graphicsContext_drawImage(handle, |
|
2089 img.handle, |
|
2090 intParams[i++], |
|
2091 intParams[i++], |
|
2092 intParams[i++], |
|
2093 intParams[i++], |
|
2094 intParams[i++], |
|
2095 intParams[i++], |
|
2096 intParams[i++], |
|
2097 intParams[i++], |
|
2098 intParams[i++]); |
|
2099 // As we made a shallow copy of the image in buffer |
|
2100 // its safe to delete that here |
|
2101 img.dispose(); |
|
2102 break; |
|
2103 } |
|
2104 case JavaCommandBuffer.OP_DRAWFOCUS: |
|
2105 { |
|
2106 OS.graphicsContext_drawFocus(handle, |
|
2107 intParams[i++], |
|
2108 intParams[i++], |
|
2109 intParams[i++], |
|
2110 intParams[i++]); |
|
2111 break; |
|
2112 } |
|
2113 case JavaCommandBuffer.OP_DRAWELLIPSE: |
|
2114 { |
|
2115 OS.graphicsContext_drawEllipse(handle, |
|
2116 intParams[i++], |
|
2117 intParams[i++], |
|
2118 intParams[i++], |
|
2119 intParams[i++]); |
|
2120 break; |
|
2121 } |
|
2122 case JavaCommandBuffer.OP_DRAWPOINT: |
|
2123 { |
|
2124 OS.graphicsContext_drawPoint(handle, intParams[i++], intParams[i++]); |
|
2125 break; |
|
2126 } |
|
2127 case JavaCommandBuffer.OP_DRAWPOLYGON: |
|
2128 { |
|
2129 int arraySize = intParams[i++]; |
|
2130 int[] pointArray = new int[arraySize]; |
|
2131 System.arraycopy(intParams, i, pointArray, 0, arraySize); |
|
2132 i += arraySize; |
|
2133 OS.graphicsContext_drawPolygon(handle, pointArray); |
|
2134 break; |
|
2135 } |
|
2136 case JavaCommandBuffer.OP_DRAWPOLYLINE: |
|
2137 { |
|
2138 int arraySize = intParams[i++]; |
|
2139 int [] pointArray = new int[arraySize]; |
|
2140 System.arraycopy(intParams, i, pointArray, 0, arraySize); |
|
2141 i += arraySize; |
|
2142 OS.graphicsContext_drawPolyline(handle, pointArray); |
|
2143 break; |
|
2144 } |
|
2145 case JavaCommandBuffer.OP_DRAWRECT: |
|
2146 { |
|
2147 OS.graphicsContext_drawRect(handle, intParams[i++], intParams[i++], intParams[i++], intParams[i++]); |
|
2148 break; |
|
2149 } |
|
2150 case JavaCommandBuffer.OP_DRAWRGB_INT: |
|
2151 { |
|
2152 int index = rgbCount++; |
|
2153 int[] rgbData = (int[])rgbs.elementAt(index); |
|
2154 OS.graphicsContext_drawRGB(handle, |
|
2155 rgbData, |
|
2156 intParams[i++], |
|
2157 intParams[i++], |
|
2158 intParams[i++], |
|
2159 intParams[i++], |
|
2160 intParams[i++], |
|
2161 intParams[i++], |
|
2162 (intParams[i++] != 0), |
|
2163 intParams[i++]); |
|
2164 rgbs.setElementAt(null, index); |
|
2165 break; |
|
2166 } |
|
2167 case JavaCommandBuffer.OP_DRAWRGB_BYTE: |
|
2168 { |
|
2169 int index1 = rgbCount++; |
|
2170 byte[] rgbData = (byte[])rgbs.elementAt(index1); |
|
2171 int index2 = rgbCount++; |
|
2172 byte[] transparencyMask = (byte[])rgbs.elementAt(index2); |
|
2173 OS.graphicsContext_drawRGB(handle, |
|
2174 rgbData, |
|
2175 transparencyMask, |
|
2176 intParams[i++], |
|
2177 intParams[i++], |
|
2178 intParams[i++], |
|
2179 intParams[i++], |
|
2180 intParams[i++], |
|
2181 intParams[i++], |
|
2182 intParams[i++], |
|
2183 intParams[i++]); |
|
2184 rgbs.setElementAt(null, index1); |
|
2185 rgbs.setElementAt(null, index2); |
|
2186 break; |
|
2187 } |
|
2188 case JavaCommandBuffer.OP_DRAWRGB_SHORT: |
|
2189 { |
|
2190 int index = rgbCount++; |
|
2191 short[] rgbData = (short[])rgbs.elementAt(index); |
|
2192 OS.graphicsContext_drawRGB(handle, |
|
2193 rgbData, |
|
2194 intParams[i++], |
|
2195 intParams[i++], |
|
2196 intParams[i++], |
|
2197 intParams[i++], |
|
2198 intParams[i++], |
|
2199 intParams[i++], |
|
2200 (intParams[i++] != 0), |
|
2201 intParams[i++], |
|
2202 intParams[i++]); |
|
2203 rgbs.setElementAt(null, index); |
|
2204 break; |
|
2205 } |
|
2206 case JavaCommandBuffer.OP_DRAWROUNDRECT: |
|
2207 { |
|
2208 OS.graphicsContext_fillRoundRect(handle, |
|
2209 intParams[i++], |
|
2210 intParams[i++], |
|
2211 intParams[i++], |
|
2212 intParams[i++], |
|
2213 intParams[i++], |
|
2214 intParams[i++]); |
|
2215 break; |
|
2216 } |
|
2217 case JavaCommandBuffer.OP_DRAWSTRING: |
|
2218 { |
|
2219 int stringLength = intParams[i++]; |
|
2220 String string = strings.substring(stringCount, stringCount + stringLength); |
|
2221 stringCount += stringLength; |
|
2222 OS.graphicsContext_drawString(handle, |
|
2223 string, |
|
2224 intParams[i++], |
|
2225 intParams[i++], |
|
2226 intParams[i++], |
|
2227 intParams[i++], |
|
2228 intParams[i++], |
|
2229 intParams[i++], |
|
2230 (intParams[i++] != 0)); |
|
2231 break; |
|
2232 } |
|
2233 default: |
|
2234 throw new RuntimeException("Internal error: Unknown opcode"); |
|
2235 } |
|
2236 break; |
|
2237 } |
|
2238 |
|
2239 // |
|
2240 // Fill op codes handling |
|
2241 // |
|
2242 case JavaCommandBuffer.FILL_PREFIX: |
|
2243 { |
|
2244 switch (intParams[i++]) { |
|
2245 case JavaCommandBuffer.OP_FILLRECT: |
|
2246 { |
|
2247 OS.graphicsContext_fillRect(handle, |
|
2248 intParams[i++], |
|
2249 intParams[i++], |
|
2250 intParams[i++], |
|
2251 intParams[i++]); |
|
2252 break; |
|
2253 } |
|
2254 case JavaCommandBuffer.OP_FILLARC: |
|
2255 { |
|
2256 OS.graphicsContext_fillArc(handle, |
|
2257 intParams[i++], |
|
2258 intParams[i++], |
|
2259 intParams[i++], |
|
2260 intParams[i++], |
|
2261 intParams[i++], |
|
2262 intParams[i++]); |
|
2263 break; |
|
2264 } |
|
2265 case JavaCommandBuffer.OP_FILLGRADIENTRECT: |
|
2266 { |
|
2267 OS.graphicsContext_fillGradientRect(handle, |
|
2268 intParams[i++], |
|
2269 intParams[i++], |
|
2270 intParams[i++], |
|
2271 intParams[i++], |
|
2272 (intParams[i++] != 0), |
|
2273 (intParams[i++] != 0)); |
|
2274 break; |
|
2275 } |
|
2276 case JavaCommandBuffer.OP_FILLELLIPSE: |
|
2277 { |
|
2278 OS.graphicsContext_fillEllipse(handle, |
|
2279 intParams[i++], |
|
2280 intParams[i++], |
|
2281 intParams[i++], |
|
2282 intParams[i++]); |
|
2283 break; |
|
2284 } |
|
2285 case JavaCommandBuffer.OP_FILLPOLYGON: |
|
2286 { |
|
2287 int arraySize = intParams[i++]; |
|
2288 int[] pointArray = new int[arraySize]; |
|
2289 System.arraycopy(intParams, i, pointArray, 0, arraySize); |
|
2290 i += arraySize; |
|
2291 OS.graphicsContext_fillPolygon(handle, pointArray); |
|
2292 break; |
|
2293 } |
|
2294 case JavaCommandBuffer.OP_FILLROUNDRECT: |
|
2295 { |
|
2296 OS.graphicsContext_fillRoundRect(handle, |
|
2297 intParams[i++], |
|
2298 intParams[i++], |
|
2299 intParams[i++], |
|
2300 intParams[i++], |
|
2301 intParams[i++], |
|
2302 intParams[i++]); |
|
2303 break; |
|
2304 } |
|
2305 default: |
|
2306 throw new RuntimeException("Internal error: Unknown opcode"); |
|
2307 } |
|
2308 break; |
|
2309 } |
|
2310 |
|
2311 // |
|
2312 // Setter op code handling |
|
2313 // |
|
2314 case JavaCommandBuffer.SET_PREFIX: |
|
2315 { |
|
2316 switch (intParams[i++]) { |
|
2317 case JavaCommandBuffer.OP_SETBACKGROUNDALPHA: |
|
2318 { |
|
2319 OS.graphicsContext_setBackgroundAlpha(handle, intParams[i++]); |
|
2320 break; |
|
2321 } |
|
2322 case JavaCommandBuffer.OP_SETBACKGROUNDCOLOR: |
|
2323 { |
|
2324 OS.graphicsContext_setBackgroundColor(handle, intParams[i++], (intParams[i++] != 0)); |
|
2325 break; |
|
2326 } |
|
2327 case JavaCommandBuffer.OP_SETBLENDINGMODE: |
|
2328 { |
|
2329 OS.graphicsContext_setBlendingMode(handle, intParams[i++]); |
|
2330 break; |
|
2331 } |
|
2332 case JavaCommandBuffer.OP_SETCLIP: |
|
2333 { |
|
2334 OS.graphicsContext_setClip(handle, |
|
2335 intParams[i++], |
|
2336 intParams[i++], |
|
2337 intParams[i++], |
|
2338 intParams[i++], |
|
2339 (intParams[i++] != 0)); |
|
2340 break; |
|
2341 } |
|
2342 case JavaCommandBuffer.OP_SETFONT: |
|
2343 { |
|
2344 OS.graphicsContext_setFont(handle, intParams[i++]); |
|
2345 break; |
|
2346 } |
|
2347 case JavaCommandBuffer.OP_SETFOREGROUNDALPHA: |
|
2348 { |
|
2349 OS.graphicsContext_setForegroundAlpha(handle, intParams[i++]); |
|
2350 break; |
|
2351 } |
|
2352 case JavaCommandBuffer.OP_SETFOREGROUNDCOLOR: |
|
2353 { |
|
2354 OS.graphicsContext_setForegroundColor(handle, intParams[i++], (intParams[i++] != 0)); |
|
2355 break; |
|
2356 } |
|
2357 case JavaCommandBuffer.OP_SETSTROKESTYLE: |
|
2358 { |
|
2359 OS.graphicsContext_setStrokeStyle(handle, intParams[i++]); |
|
2360 break; |
|
2361 } |
|
2362 case JavaCommandBuffer.OP_SETSTROKEWIDTH: |
|
2363 { |
|
2364 OS.graphicsContext_setStrokeWidth(handle, intParams[i++]); |
|
2365 break; |
|
2366 } |
|
2367 default: |
|
2368 throw new RuntimeException("Internal error: Unknown opcode"); |
|
2369 } |
|
2370 break; |
|
2371 } |
|
2372 |
|
2373 // |
|
2374 // misc op code handling |
|
2375 // |
|
2376 case JavaCommandBuffer.MISC_PREFIX: |
|
2377 { |
|
2378 switch (intParams[i++]) { |
|
2379 case JavaCommandBuffer.OP_CANCELCLIPPING: |
|
2380 { |
|
2381 OS.graphicsContext_cancelClipping(handle); |
|
2382 break; |
|
2383 } |
|
2384 case JavaCommandBuffer.OP_TRANSLATE: |
|
2385 { |
|
2386 OS.graphicsContext_translate(handle, intParams[i++], intParams[i++]); |
|
2387 break; |
|
2388 } |
|
2389 case JavaCommandBuffer.OP_SCALE: |
|
2390 { |
|
2391 OS.graphicsContext_scale(handle, intParams[i++], intParams[i++]); |
|
2392 break; |
|
2393 } |
|
2394 case JavaCommandBuffer.OP_RESETTRANSFORM: |
|
2395 { |
|
2396 OS.graphicsContext_resetTransform(handle); |
|
2397 break; |
|
2398 } |
|
2399 case JavaCommandBuffer.OP_COPYAREA1: |
|
2400 { |
|
2401 break; |
|
2402 } |
|
2403 case JavaCommandBuffer.OP_COPYAREA2: |
|
2404 { |
|
2405 break; |
|
2406 } |
|
2407 default: |
|
2408 throw new RuntimeException("Internal error: Unknown opcode"); |
|
2409 } |
|
2410 break; |
|
2411 } |
|
2412 default: |
|
2413 throw new RuntimeException("Internal error: Unkonwn opcode category"); |
|
2414 } |
|
2415 } |
|
2416 } |
|
2417 |
|
2418 private final int handle(Widget w) { |
|
2419 return Internal_PackageSupport.handle(w); |
|
2420 } |
|
2421 } |