|
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 API and implementation |
|
10 *******************************************************************************/ |
|
11 #ifndef GRAPHICS_H |
|
12 #define GRAPHICS_H |
|
13 |
|
14 #include <QImage> |
|
15 #include <QPixmap> |
|
16 #ifdef __SYMBIAN32__ |
|
17 #include <EGL/egl.h> |
|
18 #endif |
|
19 |
|
20 class QFont; |
|
21 class QByteArray; |
|
22 |
|
23 namespace Java { namespace GFX { |
|
24 |
|
25 class Buffer; |
|
26 class GraphicsContext; |
|
27 class GraphicsFactory; |
|
28 class Image; |
|
29 class ImageLoader; |
|
30 class ImageDataWrapper; |
|
31 class PaletteDataWrapper; |
|
32 class WindowSurface; |
|
33 |
|
34 /** |
|
35 * gfx errors |
|
36 */ |
|
37 enum TGfxError |
|
38 { |
|
39 EGfxErrorNone = 0, |
|
40 EGfxErrorNoMemory = 1, |
|
41 EGfxErrorIO = 2, |
|
42 EGfxErrorIllegalArgument = 4, |
|
43 EGfxErrorIllegalState = 5, |
|
44 EGfxErrorArrayIndexOutOfBounds = 6 |
|
45 }; |
|
46 |
|
47 /** |
|
48 * Rendering target types |
|
49 */ |
|
50 enum TTargetType |
|
51 { |
|
52 ETypeNone = 0, |
|
53 ETypeWidget = 1, |
|
54 ETypeImage = 2, |
|
55 ETypeBuffer = 3, |
|
56 ETypeWindowSurface = 4 |
|
57 }; |
|
58 |
|
59 /** |
|
60 * Image pixel formats |
|
61 */ |
|
62 enum TImageFormat |
|
63 { |
|
64 EFormatNone = 0, |
|
65 EFormatRGB32 = 1, |
|
66 EFormatARGB32 = 2, |
|
67 EFormatARGB32Premultiplied = 3, |
|
68 EFormatRGB16 = 4, |
|
69 EFormatRGB555 = 5, |
|
70 EFormatRGB444 = 6, |
|
71 EFormatARGB4444Premultiplied = 7, |
|
72 EFormatMONO = 8 |
|
73 }; |
|
74 |
|
75 /** |
|
76 * Native image types |
|
77 */ |
|
78 enum TImageType |
|
79 { |
|
80 ENone = -1, |
|
81 EImage = 0, |
|
82 EPixmap = 1 |
|
83 }; |
|
84 |
|
85 /** |
|
86 * Image transforms |
|
87 */ |
|
88 enum TTransform |
|
89 { |
|
90 ETransNone = 100, |
|
91 ETransRot90 = 101, |
|
92 ETransRot180 = 102, |
|
93 ETransRot270 = 103, |
|
94 ETransMirror = 104, |
|
95 ETransMirrorRot90 = 105, |
|
96 ETransMirrorRot180 = 106, |
|
97 ETransMirrorRot270 = 107, |
|
98 ETransFlipHorizontal = 108, |
|
99 ETransFlipVertical = 109 |
|
100 }; |
|
101 |
|
102 /** |
|
103 * Blending modes |
|
104 */ |
|
105 enum TBlendingMode |
|
106 { |
|
107 ESrc = 10, |
|
108 ESrcOver = 11, |
|
109 EXor = 12 |
|
110 }; |
|
111 |
|
112 /** |
|
113 * Stroke styles |
|
114 */ |
|
115 enum TStrokeStyle |
|
116 { |
|
117 EStrokeNo = 0, |
|
118 EStrokeSolid = 1, |
|
119 EStrokeDot = 2, |
|
120 EStrokeDash = 3, |
|
121 EStrokeDashDot = 4, |
|
122 EStrokeDashDotDot = 5 |
|
123 }; |
|
124 |
|
125 /** |
|
126 * Indices for font metrics data |
|
127 */ |
|
128 enum TFontMetricsDataIndex |
|
129 { |
|
130 EFmAscent = 0, |
|
131 EFmAverageCharWidth = 1, |
|
132 EFmDescent = 2, |
|
133 EFmHeight = 3, |
|
134 EFmLeading = 4 |
|
135 }; |
|
136 |
|
137 /** |
|
138 * Common indexes for rectangle data arrays |
|
139 */ |
|
140 enum TRectIndex |
|
141 { |
|
142 ERectX = 0, |
|
143 ERectY = 1, |
|
144 ERectWidth = 2, |
|
145 ERectHeight = 3 |
|
146 }; |
|
147 |
|
148 /** |
|
149 * Window surface types |
|
150 * |
|
151 */ |
|
152 enum WindowSurfaceType |
|
153 { |
|
154 WsTypeUnknown = 0x0000, // unknonwn or uninitialized type |
|
155 WsTypeQtImage = 0x0001, // QImage |
|
156 WsTypeQtPixmap = 0x0002, // QPixmap |
|
157 WsTypeSymbianBitmap = 0x0004, // CFbsBitmap |
|
158 WsTypeEglSurface = 0x0016 // EGL surface |
|
159 }; |
|
160 |
|
161 |
|
162 /** |
|
163 * Interface to Buffer. |
|
164 */ |
|
165 class Buffer |
|
166 { |
|
167 public: |
|
168 /** |
|
169 * Destructor |
|
170 * Use dispose instead of delete |
|
171 */ |
|
172 virtual ~Buffer() {} |
|
173 |
|
174 /** |
|
175 * Disposes this instance of buffer |
|
176 */ |
|
177 virtual void dispose() = 0; |
|
178 |
|
179 /** |
|
180 * Retrieves bindable target of Buffer, i.e. QPaintDevice. |
|
181 * @return bindable |
|
182 */ |
|
183 virtual QPaintDevice* getBindable() = 0; |
|
184 |
|
185 /** |
|
186 * Gets the invalid rect, i.e. rectangle containing area where |
|
187 * draw operations have affected. |
|
188 * |
|
189 * Values are stored in aRect array as follows: |
|
190 * <ul> |
|
191 * <li>aRect[ERectX] - the x coordinate of rect</li> |
|
192 * <li>aRect[ERectY] - the y coordinate of rect</li> |
|
193 * <li>aRect[ERectWidth] - the width of rect</li> |
|
194 * <li>aRect[ERectHeight] - the height of rect</li> |
|
195 * </ul> |
|
196 * |
|
197 * @param aRect Int array where rect data is populated |
|
198 */ |
|
199 virtual void getInvalidRect(int aRect[]) = 0; |
|
200 |
|
201 /** |
|
202 * Retrieves wrapped buffer object |
|
203 * @return QPicture |
|
204 */ |
|
205 virtual QPicture* getPicture() = 0; |
|
206 |
|
207 }; |
|
208 |
|
209 /** |
|
210 * WindowSurface class wraps actual rendering surface for sharing it between java grapchics |
|
211 * external renderers like m3g and m2g. It also perfroms needed blitting activations in case |
|
212 * external renderer does not directly support current surface type. |
|
213 * |
|
214 * Example of using WindowSurface |
|
215 * <code> |
|
216 * // Set supported surface types of external renderer |
|
217 * int caps = Java::GXF:SwImage | Java::GFX::PBuffer; |
|
218 * // get surface |
|
219 * QPaintDevice* surface = WindowSurface.bind(caps); |
|
220 * // cast device to actual type |
|
221 * switch (WindowSurface.getType) |
|
222 * { |
|
223 * case SwImage: |
|
224 * surface = static_cast<QImage*>(surface); |
|
225 * break; |
|
226 * case PBuffer: |
|
227 * surface = static_cast<QGLPixelBuffer*>(surface); |
|
228 * |
|
229 * </code> |
|
230 * |
|
231 * After using surface WindowSurface.release() must be called |
|
232 */ |
|
233 class WindowSurface |
|
234 { |
|
235 public: |
|
236 |
|
237 /** |
|
238 * Destructor |
|
239 * @note use dispose method instead of delete |
|
240 */ |
|
241 virtual ~WindowSurface() {} |
|
242 |
|
243 /** |
|
244 * Binds this surface for rendering outside GraphicsContext, e.g. rendering by m3g. |
|
245 * When rendering has been finished by external renderer release() must be called on this instance. |
|
246 * |
|
247 * Surface type given to caller depends on the graphics hardware configuration, the |
|
248 * graphics system used by QPainter and on the capabilites given on the aCapability parameter. |
|
249 * Note that the minimun requirement is that SwImage (QImage) is supported. |
|
250 * |
|
251 * If caller is for instance capable for rendering on VgImage and QImage it should set value for |
|
252 * aCapabilites as shown below. If in this case QPainter is operating in OpenVG (Hw) the returned surface is VgImage, |
|
253 * if it is on turn operating on software based raster paintengine returned surface is SwImage (QImage). |
|
254 * |
|
255 * <code> |
|
256 * int caps = Java::GFX::SwImage|Java::GFX::VgImage; |
|
257 * </code> |
|
258 * |
|
259 * IMPORTANT: The caller must not delete QPaintDevice pointer returned from bind -method |
|
260 * |
|
261 * @param aCapabilies The hints of supported surface types, one or combination of surfacetypes |
|
262 * defined in WindowSurfaceTypes, Default SwImage |
|
263 * @return QPaintDevice to be used as rendering target |
|
264 */ |
|
265 virtual void bind(int aCapabilies = WsTypeQtImage) = 0; |
|
266 |
|
267 /** |
|
268 * Prepares this window surface for painting. Must be called before painting starts. |
|
269 * Should be called by UI toolkits, not by external renderers, like m3g. |
|
270 * @param aX The x-coordinate of the paint area |
|
271 * @param aY The y-coordinate of the paint area |
|
272 * @param aWidth The width of the paint area |
|
273 * @param aHeight The height of the paint area |
|
274 */ |
|
275 virtual void beginPaint(int aX, int aY, int aWidth, int aHeight) = 0; |
|
276 |
|
277 /** |
|
278 * Ends painting intiated by call to beginPaint. Must be when painting has ended. |
|
279 * Should be called by UI toolkits, not by external renderers, like m3g. |
|
280 */ |
|
281 virtual void endPaint() = 0; |
|
282 |
|
283 /** |
|
284 * Flushes the contents of this window surface to the display. Should be called by |
|
285 * UI toolkits. |
|
286 */ |
|
287 virtual void flush() = 0; |
|
288 |
|
289 /** |
|
290 * Gets the type of the windowSurface |
|
291 * @return One of types defined in WindowSurfaceType |
|
292 */ |
|
293 virtual int getType() = 0; |
|
294 |
|
295 /** |
|
296 * Getter for the QPaintDevice of contained target. Primarily to be used |
|
297 * when drawing to window surface target with QPainter |
|
298 * @return The paintDevice of the target |
|
299 */ |
|
300 virtual QPaintDevice* getDevice() = 0; |
|
301 |
|
302 #ifdef __SYMBIAN32__ |
|
303 /** |
|
304 * Getter for egl surface. |
|
305 * @return The egl draw surface id, or EGL_NO_SURFACE if the target is not egl type |
|
306 */ |
|
307 virtual EGLSurface getEglSurface() = 0; |
|
308 |
|
309 /** |
|
310 * Getter for current the API that is currently bound to EGL. |
|
311 * In order to get valid return value the type of this window surface |
|
312 * must be WsTypeEglSurface. |
|
313 * @return The API that's bound to EGL |
|
314 */ |
|
315 virtual EGLenum getEglApi() = 0; |
|
316 #endif |
|
317 |
|
318 /** |
|
319 * Getter for QImage |
|
320 * @return The target QImage, or NULL it is not the true type of target |
|
321 */ |
|
322 virtual QImage* getQtImage() = 0; |
|
323 |
|
324 /** |
|
325 * Refreshes the window surface data. Refresh needs to be called |
|
326 * e.g. when Qt has changed its window surface when switching from sw to hw |
|
327 * rendering. |
|
328 */ |
|
329 virtual void refresh() = 0; |
|
330 /** |
|
331 * Releases external renderer from this instance. |
|
332 * Calling this method automatically blits all pixels rendered on the surface to |
|
333 * actual target, i.e. to widget or offscreen image. |
|
334 */ |
|
335 virtual void release() = 0; |
|
336 |
|
337 /** |
|
338 * Disposes this instance of windowsurface |
|
339 */ |
|
340 virtual void dispose() = 0; |
|
341 |
|
342 // Symbian specific methods |
|
343 |
|
344 #ifdef __SYMBIAN32__ |
|
345 /** |
|
346 * Getter for symbian bitmap. |
|
347 * @return The symbian bitmap if it is available, otherwise NULL |
|
348 */ |
|
349 virtual CFbsBitmap* getSymbianBitmap() = 0; |
|
350 #endif |
|
351 |
|
352 /** |
|
353 * Switches to software rendering if the window goes invisible |
|
354 * and back to hardware rendering when becoming visible. |
|
355 */ |
|
356 virtual void handleSymbianWindowVisibilityChange(bool aVisible) = 0; |
|
357 }; |
|
358 |
|
359 |
|
360 |
|
361 /** |
|
362 * Interface to graphics context |
|
363 */ |
|
364 class GraphicsContext |
|
365 { |
|
366 public: |
|
367 /** |
|
368 * Destructor |
|
369 * @note use dispose method instead of delete |
|
370 */ |
|
371 virtual ~GraphicsContext() {} |
|
372 |
|
373 /** |
|
374 * Gets window surface for currrently bound target |
|
375 */ |
|
376 virtual WindowSurface* getWindowSurface() = 0; |
|
377 |
|
378 /** |
|
379 * Disposes graphics context, i.e. frees all resources. |
|
380 */ |
|
381 virtual void dispose() = 0; |
|
382 |
|
383 /** |
|
384 * Binds graphics context to given rendering target. |
|
385 * @param aTarget The rendering target handle. |
|
386 * @param aType The type of given rendering target. |
|
387 * @param aBufferFlushTargetHandle The actual target where the buffer will be flushed to |
|
388 * @exception GfxException |
|
389 */ |
|
390 virtual void bindTarget(int aTarget, TTargetType aType, const int& aBufferFlushTargetHandle) = 0; |
|
391 |
|
392 /** |
|
393 * Renders draw commands stored in given buffer to currently bound target. |
|
394 * @param aBuffer The rendering target handle. |
|
395 * @exception GfxException |
|
396 */ |
|
397 virtual void render(Buffer* aBuffer) = 0; |
|
398 |
|
399 /** |
|
400 * Releases current rendering target and frees resources. |
|
401 * After calling release target no graphics operations are allowed |
|
402 * as there's no target to render to. Note, there is no checking for |
|
403 * existing target, so it fails on platform operations. |
|
404 */ |
|
405 virtual void releaseTarget() = 0; |
|
406 |
|
407 /** |
|
408 * Copies rectangular area from currently bound target to given image target. |
|
409 * The copy rectangle top left corned is defined by x and y and bottom right corner |
|
410 * by image width and height. |
|
411 * |
|
412 * @param aImage The image to copy into |
|
413 * @param aX The x coordinate of top left corner copy area |
|
414 * @param aY The y coordinate of top left corner copy area |
|
415 */ |
|
416 virtual void copyArea(Image* aImage, int aX, int aY) = 0; |
|
417 |
|
418 /** |
|
419 * Copies rectangular area within currently bound target from source |
|
420 * location to destination location. |
|
421 * |
|
422 * @param aSrcX The top left x coordinate of source rectangle |
|
423 * @param aSrcY The top left y coordinate of source rectangle |
|
424 * @param aWidth The width of source rectangle |
|
425 * @param aHeight The height of source rectangle |
|
426 * @param aDestX The top left x coordinate for the copy |
|
427 * @param aDestY The top left y coordinate for the copy |
|
428 * @param aPaint If to generate paint events for the new and obscured areas |
|
429 */ |
|
430 virtual void copyArea(int aSrcX, int aSrcY, int aWidth, int aHeight, int aDestX, int aDestY, bool aPaint) = 0; |
|
431 |
|
432 /** |
|
433 * Draws outline of elliptical arc within specified rectangle. |
|
434 * Arc is drawn counterclockwise. |
|
435 * |
|
436 * @param aX The x coordinate of top left corner of arc rectangle |
|
437 * @param aY The y coordinate of top left corner of arc rectangle |
|
438 * @param aWidth The width of arc rectangle |
|
439 * @param aHeight The height of arc rectangle |
|
440 * @param aStartAngle The starting angle for arc |
|
441 * @param aArcAngle The span angle for arc |
|
442 */ |
|
443 virtual void drawArc(int aX, int aY, int aWidth, int aHeight, int aStartAngle, int aArcAngle) = 0; |
|
444 |
|
445 /** |
|
446 * Draws an ellipse specified by rectangle. |
|
447 * |
|
448 * @param aX The x coordinate of top left corner of ellipse rectangle |
|
449 * @param aY The y coordinate of top left corner of ellipse rectangle |
|
450 * @param aWidth The width of ellipse rectangle |
|
451 * @param aHeight The height of ellipse rectangle |
|
452 */ |
|
453 virtual void drawEllipse(int aX, int aY, int aWidth, int aHeight) = 0; |
|
454 |
|
455 /** |
|
456 * Draws a focus rectangle specified by the parameters. |
|
457 * |
|
458 * @param aX The x coordinate of top left corner of the rectangle |
|
459 * @param aY The y coordinate of top left corner of the rectangle |
|
460 * @param aWidth The width of the rectangle |
|
461 * @param aHeight The height of the rectangle |
|
462 */ |
|
463 virtual void drawFocus(int aX, int aY, int aWidth, int aHeight) = 0; |
|
464 |
|
465 /** |
|
466 * Draws an image at (x, y) by copying a part of image into the paint device. |
|
467 * The default, (0, 0) (and negative) means all the way to the bottom-right of the image. |
|
468 * |
|
469 * @param aImage The source from where to draw |
|
470 * @param aManipulation The transformation to be applied to the region before it is drawn |
|
471 * @param aTx The top-left x coordinate in the paint device that is to be drawn onto |
|
472 * @param aTy The top-left y coordinate in the paint device that is to be drawn onto |
|
473 * @param aTw The width of the image that is to be drawn onto. |
|
474 * @param aTh The heigth of the image that is to be drawn onto. |
|
475 * @param aSx The top-left x coordinate in image that is to be drawn |
|
476 * @param aSy The top-left y coordinate in image that is to be drawn |
|
477 * @param aSw The width of the image that is to be drawn. |
|
478 * @param aSh The heigth of the image that is to be drawn. |
|
479 * @see QPainter::drawImage |
|
480 */ |
|
481 virtual void drawImage(Image* aImage, int aManipulation, int aTx, int aTy, int aTw = -1, int aTh = -1, |
|
482 int aSx = 0, int aSy = 0, int aSw = -1, int aSh = -1) = 0; |
|
483 |
|
484 /** |
|
485 * Draws image to specified cooridnates |
|
486 * |
|
487 * @param aImage The image that is to be drawn |
|
488 * @param x The x-coordinate where to draw |
|
489 * @param y The y-coordinate where to draw |
|
490 */ |
|
491 virtual void drawImage(Image* aImage, int x, int y) = 0; |
|
492 |
|
493 /** |
|
494 * Draws a line between defined points. |
|
495 * |
|
496 * @param aX1 The x coordinate of staring point |
|
497 * @param aY1 The y coordinate of staring point |
|
498 * @param aX2 The x coordinate of ending point |
|
499 * @param aY2 The y coordinate of ending point |
|
500 */ |
|
501 virtual void drawLine(int aX1, int aY1, int aX2, int aY2) = 0; |
|
502 |
|
503 /** |
|
504 * Draws a point to specified location. |
|
505 * |
|
506 * @param aX The x coordinate to draw the point |
|
507 * @param aY The y coordinate to draw the point |
|
508 */ |
|
509 virtual void drawPoint(int aX, int aY) = 0; |
|
510 |
|
511 /** |
|
512 * Draws a closed polygon which is defined integer array of coorinates. |
|
513 * Lines are drawn between each consecutive x,y pairs and between first and last point. |
|
514 * |
|
515 * @param aPointArray An array alternating x and y values which are the verices of the polygon |
|
516 * @param aLength The number of point pairs in array |
|
517 */ |
|
518 virtual void drawPolygon(int aPointArray[], int aLength) = 0; |
|
519 |
|
520 /** |
|
521 * Draws polyline which is defined integer array of coorinates. |
|
522 * Lines are drawn between each consecutive x,y pairs, but not between first and last coordinate. |
|
523 * |
|
524 * @param pointArray An array alternating x and y values which are the corners of the polyline |
|
525 * @param aLength The number of point pairs in array |
|
526 */ |
|
527 virtual void drawPolyline(int aPointArray[],int aLength) = 0; |
|
528 |
|
529 /** |
|
530 * Draws outline rectangle specified by the arguments. |
|
531 * |
|
532 * @param aX The x coordinate of top left corner of rectangle |
|
533 * @param aY The y coordinate of top left corner of rectangle |
|
534 * @param aWidth The width of rectangle |
|
535 * @param aHeight The height of rectangle |
|
536 */ |
|
537 virtual void drawRect(int aX, int aY, int aWidth, int aHeight) = 0; |
|
538 |
|
539 /** |
|
540 * Draws a series of RGB+transparency values to specified region |
|
541 * |
|
542 * Scanlength can be negative which results in reading <code>aRgbData</code> array in reverse direction |
|
543 * |
|
544 * @param aRgbData an array or ARGB values in format #AARRGGBB |
|
545 * @param aRgbDataLength The length of aRgbData array |
|
546 * @param aOffset the array index of the first ARGB value |
|
547 * @param aScanlenght the relative arra offset between consecutive rows in the <code>aRgbData</code> array |
|
548 * @param aX the horizontal location of the region to be rendered |
|
549 * @param aY the vertical location of the region to be rendered |
|
550 * @param aWidth the width of the region to be rendered |
|
551 * @param aHeight the height of the region to be rendered |
|
552 * @param aProcessAlpha <code>true</code> if <code>rgbData</code> has an alpha channel, <code>false</code> if all pixels are fully opaque |
|
553 * @param aManipulation an transformation made on the region before drawing it |
|
554 * @throws GfxException |
|
555 */ |
|
556 virtual void drawRGB(int aRgbData[], int aRgbDataLength, int aOffset, int aScanlength, int aX, int aY, int aWidth, int aHeight, bool aProcessAlpha, int aManipulation) = 0; |
|
557 |
|
558 /** |
|
559 * Draws a series of RGB+transparency values to specified region |
|
560 * |
|
561 * Scanlength can be negative which results in reading <code>aRgbData</code> array in reverse direction |
|
562 * |
|
563 * @param aRgbData an array or RGB values in format 1 bit perpixel |
|
564 * @param aTransparencyMask an array of mask values |
|
565 * @param aRgbDataLength The length of aRgbData array |
|
566 * @param aOffset the array index of the first RGB value |
|
567 * @param aScanlenght the relative arra offset between consecutive rows in the <code>aRgbData</code> array |
|
568 * @param aX the horizontal location of the region to be rendered |
|
569 * @param aY the vertical location of the region to be rendered |
|
570 * @param aWidth the width of the region to be rendered |
|
571 * @param aHeight the height of the region to be rendered |
|
572 * @param aManipulation an transformation made on the region before drawing it |
|
573 * @param aFormat an image format in which <code>aRgbData</code> array is stored. |
|
574 * @throws GfxException |
|
575 */ |
|
576 virtual void drawRGB(char aRgbData[], char aTransparencyMask[], int aRgbDataLength, int aOffset, int aScanlength, int aX, int aY, int aWidth, int aHeight, int aManipulation, int aFormat) = 0; |
|
577 |
|
578 /** |
|
579 * Draws a series of RGB+transparency values to specified region |
|
580 * |
|
581 * Scanlength can be negative which results in reading <code>aRgbData</code> array in reverse direction |
|
582 * |
|
583 * @param aRgbData an array or aRGB values in 16 bit per pixel |
|
584 * @param aTransparencyMask an array of mask values |
|
585 * @param aRgbDataLength The length of aRgbData array |
|
586 * @param aOffset the array index of the first RGB value |
|
587 * @param aScanlenght the relative arra offset between consecutive rows in the <code>aRgbData</code> array |
|
588 * @param aX the horizontal location of the region to be rendered |
|
589 * @param aY the vertical location of the region to be rendered |
|
590 * @param aWidth the width of the region to be rendered |
|
591 * @param aHeight the height of the region to be rendered |
|
592 * @param aProcessAlpha <code>true</code> if <code>rgbData</code> has an alpha channel, <code>false</code> if all pixels are fully opaque |
|
593 * @param aManipulation an transformation made on the region before drawing it |
|
594 * @param aFormat an image format in which <code>aRgbData</code> array is stored. |
|
595 * @throws GfxException |
|
596 */ |
|
597 virtual void drawRGB(short aRgbData[], int aRgbDataLength, int aOffset, int aScanlength, int aX, int aY, int aWidth, int aHeight, bool aProcessAlpha, int aManipulation, int aFormat) = 0; |
|
598 |
|
599 /** |
|
600 * Draws outline round-cornered rectangle specified by the arguments. |
|
601 * |
|
602 * @param aX The x coordinate of top left corner of rectangle |
|
603 * @param aY The y coordinate of top left corner of rectangle |
|
604 * @param aWidth The width of rectangle |
|
605 * @param aHeight The height of rectangle |
|
606 * @param aArcWidth The width of the rectangle corner arc |
|
607 * @param aArcHeight The heiht of the rectangle corner arc |
|
608 */ |
|
609 virtual void drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) = 0; |
|
610 |
|
611 /** |
|
612 * Draws the given string, using the receiver's current font and foreground color. |
|
613 * Test is drawn within the rectangle with origin (x, y), width and height. |
|
614 * No tab expansion or carriage return processing will be performed. |
|
615 * If isTransparent is true, then the background of the rectangular |
|
616 * area where the string is being drawn will not be modified, |
|
617 * otherwise it will be filled with the receiver's background color. |
|
618 * Alignments and flags can be combined by using the bit-wise or operation. |
|
619 * |
|
620 * @param aText The string to be drawn |
|
621 * @param aX The x coordinate of the top left corner of the rectangular area where the string is to be drawn |
|
622 * @param aY The y coordinate of the top left corner of the rectangular area where the string is to be drawn |
|
623 * @param aWidth The rectangular area width where the string is to be drawn. |
|
624 * If -1 then the width is calculated based on the given <code>aText</code>, <code>aAlignments</code> and <code>aFlags</code>. |
|
625 * @param aHeight The rectangular area height where the string is to be drawn. |
|
626 * If -1 then the height is calculated based on the given <code>aText</code>, <code>aAlignments</code> and <code>aFlags</code>. |
|
627 * @param aLength Length of the given text |
|
628 * @param aAlingments Alignments @see Qt::AlignmentFlag |
|
629 * @param aFlags Flags @see Qt::TextFlag |
|
630 * @param aIsTransparent If true the background will be transparent, |
|
631 * otherwise it will be opaque |
|
632 */ |
|
633 virtual void drawString( |
|
634 const unsigned short* aText, int aX, int aY, int aWidth, int aHeight, |
|
635 int aLength, int aAlignments, int aFlags, bool aIsTransparent) = 0; |
|
636 |
|
637 /** |
|
638 * Draws given window surface to current target. |
|
639 * |
|
640 * @param aSurface The WindowSurface to draw |
|
641 * @param aX The x-coordinate of the area to draw |
|
642 * @param aY The y-coordinate of the area to draw |
|
643 * @param aWidth The width of the area to draw |
|
644 * @param aHeigth The height of the area to draw |
|
645 */ |
|
646 virtual void drawWindowSurface(WindowSurface* aSurface, int aX, int aY, int aWidth, int aHeight) = 0; |
|
647 |
|
648 /** |
|
649 * Fill interior of circular or elliptical arc within specified rectangular area. |
|
650 * |
|
651 * @param aX The x coordinate of top left corner of arc rectangle |
|
652 * @param aY The y coordinate of top left corner of arc rectangle |
|
653 * @param aWidth The width of arc rectangle |
|
654 * @param aHeight The height of arc rectangle |
|
655 * @param aStartAngle The starting angle for arc |
|
656 * @param aArcAngle The span angle for arc |
|
657 */ |
|
658 virtual void fillArc(int aX, int aY, int aWidth, int aHeight, int aStartAngle, int aArcAngle) = 0; |
|
659 |
|
660 /** |
|
661 * Fills interior of an ellipse/oval within specified rectangular area, using current color. |
|
662 * |
|
663 * @param aX The x coordinate of top left corner of ellipse rectangle |
|
664 * @param aY The y coordinate of top left corner of ellipse rectangle |
|
665 * @param aWidth The width of ellipse rectangle |
|
666 * @param aHeight The height of ellipse rectangle |
|
667 */ |
|
668 virtual void fillEllipse(int aX, int aY, int aWidth, int aHeight) = 0; |
|
669 |
|
670 /** |
|
671 * Fills interior of specified rectangle with a gradient sweeping from left to right or top to bottom |
|
672 * from foregroundcolor to backgroundcolor or from backgroundcolor to foregroundcolor depending on swapColors. |
|
673 * |
|
674 * @param aX The x coordinate of top left corner of rectangle |
|
675 * @param aY The y coordinate of top left corner of rectangle |
|
676 * @param aWidth The width of rectangle |
|
677 * @param aHeight The height of rectangle |
|
678 * @param aVertical if true sweeps from top to bottom, else sweeps from left to right |
|
679 * @param aSwapColors if true sweep is done from backgroundcolor to foregroundcolor, else from foregroundcolor to backgroundcolor |
|
680 */ |
|
681 virtual void fillGradientRect(int aX, int aY, int aWidth, int aHeight, bool aVertical, bool aSwapColors) = 0; |
|
682 |
|
683 /** |
|
684 * Fills interior of closed polygon which is specified by array of integer coordinates, |
|
685 * using current color. Lines are drawn between each consecutive x,y pairs and between first and last point. |
|
686 * |
|
687 * @param aPointArray An array alternating x and y values which are the verices of the polygon |
|
688 * @param aLength The number of points in <code>aPointarray</code> |
|
689 */ |
|
690 virtual void fillPolygon(int aPointArray[], int aLength) = 0; |
|
691 |
|
692 /** |
|
693 * Fills interior of the specified rectangle, using current color. |
|
694 * |
|
695 * @param aX The x coordinate of top left corner of rectangle |
|
696 * @param aY The y coordinate of top left corner of rectangle |
|
697 * @param aWidth The width of rectangle |
|
698 * @param aHeight The height of rectangle |
|
699 */ |
|
700 virtual void fillRect(int aX, int aY, int aWidth, int aHeight) = 0; |
|
701 |
|
702 /** |
|
703 * Fills interior of round-cornered rectangle, using current color. |
|
704 * |
|
705 * @param aX The x coordinate of top left corner of rectangle |
|
706 * @param aY The y coordinate of top left corner of rectangle |
|
707 * @param aWidth The width of rectangle |
|
708 * @param aHeight The height of rectangle |
|
709 * @param aArcWidth The width of the rectangle corner arc |
|
710 * @param aArcHeight The heiht of the rectangle corner arc |
|
711 */ |
|
712 virtual void fillRoundRect(int aX, int aY, int aWidth, int aHeight, int aArcWidth, int aArcHeight) = 0; |
|
713 |
|
714 /** |
|
715 * Get the width of the specified character in the font which is |
|
716 * currently selected into the receiver. |
|
717 * @param aCh The character to be measured |
|
718 * @param aIsAdvanced If true advanced width of the given character is returned. |
|
719 * @return If <code>aIsAdvanced</code> is false return width of the actual character, |
|
720 * not including the leading and tailing whitespace or overhang. |
|
721 */ |
|
722 virtual int getCharacterWidth(char aCh, bool aIsAdvanced) = 0; |
|
723 |
|
724 /** |
|
725 * Gets the <code>FontMetrics</code> data. |
|
726 * |
|
727 * Values are stored in the data array according to the |
|
728 * <code>TFontMetricsDataIndex</code> enum. |
|
729 * |
|
730 * @param aData The integer array where to copy <code>FontMetrics</code> data. |
|
731 * @param aFont If not null then Fontmetrics data will be based on it |
|
732 * otherwise data is based on the font which is currently selected. |
|
733 */ |
|
734 |
|
735 virtual void getFontMetricsData(int aData[], const QFont& aFont) = 0; |
|
736 /** |
|
737 * Gets the <code>FontMetrics</code> data that is |
|
738 * on the font which is currently selected. |
|
739 * |
|
740 * Values are stored in the data array according to the |
|
741 * <code>TFontMetricsDataIndex</code> enum. |
|
742 * |
|
743 * @param aData The integer array where to copy <code>FontMetrics</code> data. |
|
744 */ |
|
745 virtual void getFontMetricsData(int aData[]) = 0; |
|
746 |
|
747 /** |
|
748 * Gets the alpha component of the background color. |
|
749 * |
|
750 * @return The alpha value (0-255) |
|
751 */ |
|
752 virtual int getBackgroundAlpha() = 0; |
|
753 |
|
754 /** |
|
755 * Get the current background color |
|
756 * The return value also holds a value for the alpha-channel. |
|
757 * |
|
758 * @return An ARGB quadruplet on the format #AARRGGBB, equivalent to an unsigned int. |
|
759 */ |
|
760 virtual int getBackgroundColor() = 0; |
|
761 |
|
762 /** |
|
763 * Gets current blending mode. |
|
764 * Default blending mode is SRC_OVER. |
|
765 * |
|
766 * @return one of TBlendingMode |
|
767 */ |
|
768 virtual int getBlendingMode() = 0; |
|
769 |
|
770 /** |
|
771 * Gets the current clip rectangle. Retrieved clip is copied in given integer array which |
|
772 * must have at least size of 4, in order to populate all clip values. |
|
773 * |
|
774 * Values are stored in clip array as follows: |
|
775 * <ul> |
|
776 * <li>aClipArray[ERectX] - the x coordinate of clip</li> |
|
777 * <li>aClipArray[ERectY] - the y coordinate of clip |
|
778 * <li>aClipArray[ERectWidth] - the width of clip |
|
779 * <li>aClipArray[ERectHeight] - the height of clip |
|
780 * </ul> |
|
781 * @param clipArray The int array where to copy clip data |
|
782 */ |
|
783 virtual void getClip(int aClipArray[]) = 0; |
|
784 |
|
785 /** |
|
786 * Gets the alpha component of the foreground color. |
|
787 * |
|
788 * @return The alpha value (0-255) |
|
789 */ |
|
790 virtual int getForegroundAlpha() = 0; |
|
791 |
|
792 /** |
|
793 * Get the current foreground color |
|
794 * The return value also holds a value for the alpha-channel. |
|
795 * |
|
796 * @return An ARGB quadruplet on the format #AARRGGBB, equivalent to an unsigned int. |
|
797 */ |
|
798 virtual int getForegroundColor() = 0; |
|
799 |
|
800 /** |
|
801 * Returns a bounding box required by the given <code>string</code> when it is |
|
802 * drawn inside the given rectangle (<code>rectX</code>, <code>rectY</code>, |
|
803 * <code>rectWidth</code>, <code>rectHeight</code>) with the given <code>flags</code> |
|
804 * and <code>alignments</code> using the currently set font. |
|
805 * If the text does not fit within the given rectangle then the required bounding box |
|
806 * is returned. |
|
807 * |
|
808 * @param aBoundingBox The integer array where to copy bounding box data. |
|
809 * Result is stored in the array as follows: |
|
810 * <ul> |
|
811 * <li>aBoundingBox[ERectX] - top-left x of the text bounding box</li> |
|
812 * <li>aBoundingBox[ERectY] - top-left y of the text bounding box</li> |
|
813 * <li>aBoundingBox[ERectWidth] - the width of the text bounding box</li> |
|
814 * <li>aBoundingBox[ERectHeight] - the height of the text bounding box</li> |
|
815 * </ul> |
|
816 * @param aText The string |
|
817 * @param aTextLength Text length. |
|
818 * @param aAlingments Alignments @see Qt::AlignmentFlag |
|
819 * @param aFlags Flags @see Qt::TextFlag |
|
820 * @param aRectX Drawing rectangle's top-left x coordinate. |
|
821 * @param aRectY Drawing rectangle's top-left y coordinate. |
|
822 * @param aRectWidth Drawing rectangle width. |
|
823 * @param aRectHeight Drawing rectangle height. |
|
824 */ |
|
825 virtual void getTextBoundingBox( |
|
826 int aBoundingBox[], const unsigned short* aText, int aTextLength, int aAlignments, |
|
827 int aFlags, int aRectX, int aRectY, int aRectWidth, int aRectHeight) = 0; |
|
828 |
|
829 /** |
|
830 * Gets the stroke width in pixels. |
|
831 * |
|
832 * @return stroke width in pixels |
|
833 */ |
|
834 virtual int getStrokeWidth() = 0; |
|
835 |
|
836 /** |
|
837 * Gets the current pen/line style. |
|
838 * @see Qt::PenStyle |
|
839 * @return Style |
|
840 */ |
|
841 virtual int getStrokeStyle() = 0; |
|
842 |
|
843 /** |
|
844 * Gets the x coorinate of translated origin |
|
845 * @return the x coorinate of translated origin |
|
846 */ |
|
847 virtual int getTranslateX() = 0; |
|
848 |
|
849 /** |
|
850 * Gets the y coorinate of translated origin |
|
851 * @return the y coorinate of translated origin |
|
852 */ |
|
853 virtual int getTranslateY() = 0; |
|
854 |
|
855 /** |
|
856 * Sets alpha component of background color. |
|
857 * |
|
858 * @param aAlpha The alpha value to be set in range 0-255 |
|
859 */ |
|
860 virtual void setBackgroundAlpha(int aAlpha) = 0; |
|
861 |
|
862 /** |
|
863 * Set the current background color |
|
864 * |
|
865 * @param aArgb An ARGB quadruplet on the format #AARRGGBB, equivalent to an unsigned int. |
|
866 * @param aUpdateAlpha if true alpha values is also changed otherwise not |
|
867 */ |
|
868 virtual void setBackgroundColor(int aArgb, bool aUpdateAlpha) = 0; |
|
869 |
|
870 /** |
|
871 * Sets blending mode. The blending mode dictates how rendered pixels are combined with the destination pixels. |
|
872 * The default blending mode is ESrcOver, i.e. if not other mode is set using this method. |
|
873 * |
|
874 * If the bound target does not have and alpha channel the set mode has no effect. |
|
875 * |
|
876 * @param aMode The blending mode to be set |
|
877 */ |
|
878 virtual void setBlendingMode(TBlendingMode aMode) = 0; |
|
879 |
|
880 /** |
|
881 * Returns if clipped or not. |
|
882 * @return True if clipping region is set, and false otherwise |
|
883 */ |
|
884 virtual bool hasClipping() = 0; |
|
885 |
|
886 /** |
|
887 * Reset clipping region |
|
888 */ |
|
889 virtual void cancelClipping() = 0; |
|
890 |
|
891 /** |
|
892 * Sets the clip rectangle where draw operations will take affect. |
|
893 * Rendering operations have no effect outside of the clipping area. |
|
894 * |
|
895 * If intersects is set as true then the clip area is set to area where the current and given |
|
896 * clip rectangle intersect, i.e. where they overlap. |
|
897 * |
|
898 * @param aX The x coordinate for the clip area |
|
899 * @param aY The y coordinate for the clip area |
|
900 * @param aWidth The width of the clip area |
|
901 * @param aHeight The height of the clip area |
|
902 * @param aIntersects if true clip is set as interscetion of current and given clip rectangle, |
|
903 * otherwise the clip is set as specified |
|
904 */ |
|
905 virtual void setClip(int aX, int aY, int aWidth, int aHeight, bool aIntersects) = 0; |
|
906 |
|
907 /** |
|
908 * Sets font which is used in drawString. |
|
909 * |
|
910 * @param aFontHandle The handle of native QFont |
|
911 */ |
|
912 virtual void setFont(int aFontHandle) = 0; |
|
913 |
|
914 /** |
|
915 * Sets alpha component of foreground color. |
|
916 * |
|
917 * @param aAlpha The alpha value to be set in range 0-255 |
|
918 */ |
|
919 virtual void setForegroundAlpha(int aAlpha) = 0; |
|
920 |
|
921 /** |
|
922 * Set the current foreground color |
|
923 * |
|
924 * @param aArgb An ARGB quadruplet on the format #AARRGGBB, equivalent to an unsigned int. |
|
925 * @param aUpdateAlpha if true alpha values is also changed otherwise not |
|
926 */ |
|
927 virtual void setForegroundColor(int aArgb, bool aUpdateAlpha) = 0; |
|
928 |
|
929 /** |
|
930 * Sets the stroke width in pixels. |
|
931 * |
|
932 * @param aWidth The stroke width in pixels |
|
933 */ |
|
934 virtual void setStrokeWidth(int aWidth) = 0; |
|
935 |
|
936 /** |
|
937 * Sets the stroke style. |
|
938 * |
|
939 * @param aStyle The style to be set |
|
940 */ |
|
941 virtual void setStrokeStyle(TStrokeStyle aStyle) = 0; |
|
942 |
|
943 /** |
|
944 * Translates the origin of this graphics context to point (x,y). All coordinates used in subsequet |
|
945 * rendering operations are relative to this new origin. |
|
946 * |
|
947 * @param aX the x coordinate of new origin |
|
948 * @param aY the y coordinate of new origin |
|
949 */ |
|
950 virtual void translate(int aX, int aY) = 0; |
|
951 |
|
952 /** |
|
953 * Scales the coordinate system by (x, y). All coordinates used in subsequent |
|
954 * rendering operations are scaled with these values. |
|
955 * |
|
956 * @param x the x scaling factor. |
|
957 * @param y the y scaling factor |
|
958 */ |
|
959 virtual void scale(int aX, int aY) = 0; |
|
960 |
|
961 /** |
|
962 * Resets any transformations that were made using translate(), scale(). |
|
963 */ |
|
964 virtual void resetTransform() = 0; |
|
965 |
|
966 /** |
|
967 * Saves all the painter settings. |
|
968 */ |
|
969 virtual void saveSettings() = 0; |
|
970 |
|
971 /** |
|
972 * Restores all the painter settings. |
|
973 */ |
|
974 virtual void restoreSettings() = 0; |
|
975 |
|
976 }; |
|
977 |
|
978 class Image |
|
979 { |
|
980 public: |
|
981 /** |
|
982 * Destructor |
|
983 * @note use dispose method instead of delete |
|
984 */ |
|
985 virtual ~Image() {} |
|
986 |
|
987 /** |
|
988 * Creates new image with given size. |
|
989 * @param aWidth The width of the image to be created. |
|
990 * @param aHeight The height of the image to be created. |
|
991 * @param aFillColor The initial color for the image in format #00RRGGBB |
|
992 * where hight order byte, i.e. alpha is ingored |
|
993 * @param aFormat The format for new image, this does not apply to all images. |
|
994 * @exception GfxException |
|
995 */ |
|
996 virtual void createBySize(int aWidth, int aHeight, int aFillColor, TImageFormat aFormat) = 0; |
|
997 |
|
998 /** |
|
999 * Creates new image from given existing image. |
|
1000 * If the given copy region is empty, the whole image is copied. |
|
1001 * |
|
1002 * @param aImage The image to create the copy from. |
|
1003 * @param aX The top-left x coordinate of the copy region. |
|
1004 * @param aY The top-left y coordinate of the copy region. |
|
1005 * @param aWidth The width of the copy region. |
|
1006 * @param aHeight The height of the copy region. |
|
1007 * @exception GfxException |
|
1008 */ |
|
1009 virtual void createFromImage( |
|
1010 Image* aImage, int aX = 0, int aY = 0, int aWidth = 0, int aHeight = 0) = 0; |
|
1011 |
|
1012 /** |
|
1013 * Creates new image from given image data. |
|
1014 * |
|
1015 * @param aData The image data to create from. |
|
1016 * @exception GfxException |
|
1017 */ |
|
1018 virtual void createFromImageData(ImageDataWrapper* aData) = 0; |
|
1019 |
|
1020 /** |
|
1021 * Creates new image from given <code>rgbData</code> array containing argb values. |
|
1022 * |
|
1023 * @param aRgbData a RGB data array where one pixel is specified as 0xAARRGGBB |
|
1024 * @param aWidth The width of the image |
|
1025 * @param aHeight The height of the image |
|
1026 * @param aHasAlpha If true the rgb data has also an alpha channel, |
|
1027 * otherwise all pixels are fully opaque, e.g. 0xFFRRGGBB. |
|
1028 */ |
|
1029 virtual void createFromRGB(int* aRgbdata, int aWidth, int aHeight, bool aHasAlpha) = 0; |
|
1030 |
|
1031 /** |
|
1032 * Disposes image, i.e. frees all related resources. |
|
1033 */ |
|
1034 virtual void dispose() = 0; |
|
1035 |
|
1036 /** |
|
1037 * Retrieves bindable target of image, i.e. QPaintDevice. |
|
1038 * @return bindable |
|
1039 */ |
|
1040 virtual QPaintDevice* getBindable() = 0; |
|
1041 |
|
1042 /** |
|
1043 * Gets the format of the image. |
|
1044 * |
|
1045 * @return a format in which image is represented. |
|
1046 */ |
|
1047 virtual int getFormat() = 0; |
|
1048 |
|
1049 /** |
|
1050 * Gets the height of the image. |
|
1051 * @return height |
|
1052 */ |
|
1053 virtual int getHeight() = 0; |
|
1054 |
|
1055 /** |
|
1056 * Returnes native QPixmap. |
|
1057 * If the image in guestion is not QPixmap, null is returned. |
|
1058 * Note that the caller of this method must not delete returned pixmap. |
|
1059 * @return native QPixmap or null if type is not QPixmap |
|
1060 */ |
|
1061 virtual QPixmap* getPixmap() = 0; |
|
1062 |
|
1063 /** |
|
1064 * Copies image rgb (32-bit) data of given region to given data array. |
|
1065 * @param aRgbdata The array to copy the data into. |
|
1066 * @param aOffset The offset of image data start in array to copy into. |
|
1067 * @param aScanlength The relative offset between corresponding pixels in consecutive rows of the region. |
|
1068 * @param aX The x-coordinate of top-left corner of area to be copied. |
|
1069 * @param aY The y-coordinate of top-left corner of area to be copied. |
|
1070 * @param aWidth The width of the area to be copied. |
|
1071 * @param aHeight The height of the area to be copied. |
|
1072 * @exception GfxException |
|
1073 */ |
|
1074 virtual void getRgb(int* aRgbdata, int aOffset, int aScanlength, int aX, int aY, int aWidth, int aHeight) = 0; |
|
1075 |
|
1076 |
|
1077 /** |
|
1078 * Copies image rgb (1-bit) data of given region to given data array. |
|
1079 * @param aRgbdata The array to copy the data into. |
|
1080 * @param aTransparencyMask The array to copy transparency values into |
|
1081 * @param aOffset The offset of image data start in array to copy into. |
|
1082 * @param aScanlength The relative offset between corresponding pixels in consecutive rows of the region. |
|
1083 * @param aX The x-coordinate of top-left corner of area to be copied. |
|
1084 * @param aY The y-coordinate of top-left corner of area to be copied. |
|
1085 * @param aWidth The width of the area to be copied. |
|
1086 * @param aHeight The height of the area to be copied. |
|
1087 * @param aFormat The format of an image data. |
|
1088 * @exception GfxException |
|
1089 */ |
|
1090 virtual void getRgb(char* aRgbdata, char* aTransparencyMask ,int aOffset, int aScanlength, int aX, int aY, int aWidth, int aHeight, int aFormat) = 0; |
|
1091 |
|
1092 /** |
|
1093 * Copies image rgb (16-bit) data of given region to given data array. |
|
1094 * @param aRgbdata The array to copy the data into. |
|
1095 * @param aOffset The offset of image data start in array to copy into. |
|
1096 * @param aScanlength The relative offset between corresponding pixels in consecutive rows of the region. |
|
1097 * @param aX The x-coordinate of top-left corner of area to be copied. |
|
1098 * @param aY The y-coordinate of top-left corner of area to be copied. |
|
1099 * @param aWidth The width of the area to be copied. |
|
1100 * @param aHeight The height of the area to be copied. |
|
1101 * @param aFormat The format of an image data. |
|
1102 * @exception GfxException |
|
1103 */ |
|
1104 virtual void getRgb(short* aRgbdata, int aOffset, int aScanlength, int aX, int aY, int aWidth, int aHeight, int aFormat) = 0; |
|
1105 |
|
1106 /** |
|
1107 * Gets the width of the image. |
|
1108 * @return width |
|
1109 */ |
|
1110 virtual int getWidth() = 0; |
|
1111 |
|
1112 /** |
|
1113 * Converts this image to QImage for pixel access. |
|
1114 * If conversion fails a null image is returned. |
|
1115 * @return QImage instance created from wrapped Qt's image type. |
|
1116 */ |
|
1117 virtual QImage toImage() = 0; |
|
1118 |
|
1119 /** |
|
1120 * Transforms image with given transformation. |
|
1121 * @param aTransform The transform type |
|
1122 */ |
|
1123 virtual void transform(TTransform aTransform) = 0; |
|
1124 |
|
1125 /** |
|
1126 * Retrieves image's native type |
|
1127 * @return Image native type |
|
1128 */ |
|
1129 virtual TImageType type() = 0; |
|
1130 |
|
1131 /** |
|
1132 * Returns true if the image object has the alpha channel, otherwise returns false. |
|
1133 */ |
|
1134 virtual bool hasAlphaChannel() = 0; |
|
1135 |
|
1136 /** |
|
1137 * Returns the global alpha value for the image. |
|
1138 */ |
|
1139 virtual int getAlpha() = 0; |
|
1140 |
|
1141 /** |
|
1142 * Returns true if image has mask data set (instead of alpha channel). |
|
1143 */ |
|
1144 virtual bool hasMask() = 0; |
|
1145 }; |
|
1146 |
|
1147 class ImageLoader |
|
1148 { |
|
1149 |
|
1150 public: |
|
1151 |
|
1152 /** |
|
1153 * Destructor |
|
1154 * @note use dispose method instead of delete |
|
1155 */ |
|
1156 virtual ~ImageLoader() {} |
|
1157 |
|
1158 /** |
|
1159 * Appends data to internal buffer. |
|
1160 * @param aData Data array containg data to be appended |
|
1161 * @param aLength Length of bytes to be appended |
|
1162 * @param aOffset Offset from beginning of data array from where to start append |
|
1163 * @exception GfxException |
|
1164 */ |
|
1165 virtual void append(const char* aData, int aLength, int aOffset) = 0; |
|
1166 |
|
1167 /** |
|
1168 * Creates internal buffer with given initial buffer size. |
|
1169 * @param aBufferSize Initial size for buffer to be created |
|
1170 * @exception GfxException |
|
1171 */ |
|
1172 virtual void beginStream(int aBufferSize) = 0; |
|
1173 |
|
1174 /** |
|
1175 * Ends data stream and creates image based on configuration. |
|
1176 * @return Interface for created image. |
|
1177 * @exception GfxException |
|
1178 */ |
|
1179 virtual Image* endStream() = 0; |
|
1180 |
|
1181 /** |
|
1182 * Disposes loader and releases all related resources. |
|
1183 */ |
|
1184 virtual void dispose() = 0; |
|
1185 |
|
1186 /** |
|
1187 * Loads image from file directly using the native APIs. Java security |
|
1188 * checks are bypassed. |
|
1189 * @param aFilename The filename to pass to the native APIs. |
|
1190 * @return Image The loaded image. |
|
1191 */ |
|
1192 virtual Image* load(const QString& aFileName) = 0; |
|
1193 |
|
1194 /** |
|
1195 * The image will be scaled to this size on load. Useful for SVG images. |
|
1196 * @param aWidth The width to scale to when the Image is loaded. |
|
1197 * @param aHeight The height to scale to when the Image is loaded. |
|
1198 */ |
|
1199 virtual void setLoadSize(int aWidth, int aHeight) = 0; |
|
1200 }; |
|
1201 |
|
1202 /** |
|
1203 * Interface for wrapping SWT image data structure |
|
1204 */ |
|
1205 class ImageDataWrapper |
|
1206 { |
|
1207 // Definitios |
|
1208 public: |
|
1209 |
|
1210 /** |
|
1211 * SWT image types |
|
1212 */ |
|
1213 typedef enum { |
|
1214 EUndefinedImage = -1, // unknown format image |
|
1215 EBmpImage = 0, // a Windows BMP format image |
|
1216 EBmpRleImage = 1, // a run-length encoded Windows BMP format image |
|
1217 EGifImage = 2, // a GIF format image |
|
1218 EIcoImage = 3, // a ICO format image |
|
1219 EJpegImage = 4, // a JPEG format image |
|
1220 EPngImage = 5 // a PNG format image |
|
1221 } TImageType; |
|
1222 |
|
1223 /** |
|
1224 * Choices how to dispose the current GIF image |
|
1225 * before displaying the next one in SWT |
|
1226 */ |
|
1227 typedef enum { |
|
1228 EDmUnspecified = 0, // disposal method is unspecified |
|
1229 EDmFillNone, // leave the previous image in place |
|
1230 EDmFillBackground, |
|
1231 EDmFillPrevious |
|
1232 } TDisposalMethod; |
|
1233 |
|
1234 /** |
|
1235 * Data types |
|
1236 */ |
|
1237 typedef enum { |
|
1238 EPixelData = 0, |
|
1239 EAlphaData, |
|
1240 EMaskData |
|
1241 } TDataType; |
|
1242 |
|
1243 // Methods |
|
1244 public: |
|
1245 /** |
|
1246 * Dtor |
|
1247 */ |
|
1248 virtual ~ImageDataWrapper() {} |
|
1249 |
|
1250 /** |
|
1251 * Get image width , in pixels |
|
1252 * @return Width, in pixels |
|
1253 */ |
|
1254 virtual int getWidth() = 0; |
|
1255 |
|
1256 /** |
|
1257 * Get image height , in pixels |
|
1258 * @return Height, in pixels |
|
1259 */ |
|
1260 virtual int getHeight() = 0; |
|
1261 |
|
1262 /** |
|
1263 * Set image size, in pixels |
|
1264 * @param aWidth Width, in pixels |
|
1265 * @param aHeight, in pixels |
|
1266 */ |
|
1267 virtual void setSize(int aWidth, int aHeight) = 0; |
|
1268 |
|
1269 /** |
|
1270 * Get global alpha value to be used for every pixel. |
|
1271 * @return Alpha value |
|
1272 */ |
|
1273 virtual int getAlpha() = 0; |
|
1274 |
|
1275 /** |
|
1276 * Set global alpha value to be used for every pixel. |
|
1277 * @param aAlpha Global alpha |
|
1278 */ |
|
1279 virtual void setAlpha(int aAlpha) = 0; |
|
1280 |
|
1281 /** |
|
1282 * Get number of bytes per scanline. |
|
1283 * @return Number of bytes per scanline. |
|
1284 */ |
|
1285 virtual int getBytesPerLine() = 0; |
|
1286 |
|
1287 /** |
|
1288 * Set number of bytes per scanline. |
|
1289 * @param aBytesPerLine Number of bytes per scanline. |
|
1290 */ |
|
1291 virtual void setBytesPerLine(int aBytesPerLine) = 0; |
|
1292 |
|
1293 /** |
|
1294 * Get delay time before displaying the next image in an animation |
|
1295 * @return Delay time |
|
1296 */ |
|
1297 virtual int getDelayTime() = 0; |
|
1298 |
|
1299 /** |
|
1300 * Set time to delay before displaying the next image in an animation |
|
1301 * @param aDelayTime Delay time |
|
1302 */ |
|
1303 virtual void setDelayTime(int aDelayTime) = 0; |
|
1304 |
|
1305 /** |
|
1306 * Get color depth of the image, in bits per pixel. |
|
1307 * @return Color depth |
|
1308 */ |
|
1309 virtual int getDepth() = 0; |
|
1310 |
|
1311 /** |
|
1312 * Set color depth of the image, in bits per pixel. |
|
1313 * @param aDepth Color depth |
|
1314 */ |
|
1315 virtual void setDepth(int aDepth) = 0; |
|
1316 |
|
1317 /** |
|
1318 * Get number of the scanline pad. |
|
1319 * @return Scanline pad |
|
1320 */ |
|
1321 virtual int getScanlinePad() = 0; |
|
1322 |
|
1323 /** |
|
1324 * Set number of the scanline pad. |
|
1325 * @param aScanlinePad Scanline pad |
|
1326 */ |
|
1327 virtual void setScanlinePad(int aScanlinePad) = 0; |
|
1328 |
|
1329 /** |
|
1330 * Get number of the scanline pad of the mask. |
|
1331 * @return Mask's scanline pad |
|
1332 */ |
|
1333 virtual int getMaskPad() = 0; |
|
1334 |
|
1335 /** |
|
1336 * Set number of the scanline pad of the mask. |
|
1337 * @param aMaskPad Mask's scanline pad |
|
1338 */ |
|
1339 virtual void setMaskPad(int aMaskPad) = 0; |
|
1340 |
|
1341 /** |
|
1342 * Get transparent pixel. |
|
1343 * @return The transparent pixel |
|
1344 */ |
|
1345 virtual int getTransparentPixel() = 0; |
|
1346 |
|
1347 /** |
|
1348 * Set transparent pixel. |
|
1349 * @param aTransparentPixel Defines the transparent pixel |
|
1350 */ |
|
1351 virtual void setTransparentPixel(int aTransparentPixel) = 0; |
|
1352 |
|
1353 /** |
|
1354 * Get top-left x coordinate of the image within the logical screen. |
|
1355 * @return Top-left corner point. |
|
1356 */ |
|
1357 virtual int getTopLeftX() = 0; |
|
1358 |
|
1359 /** |
|
1360 * Get top-left y coordinate of the image within the logical screen. |
|
1361 * @return Top-left corner point. |
|
1362 */ |
|
1363 virtual int getTopLeftY() = 0; |
|
1364 |
|
1365 /** |
|
1366 * Set top-left corner of the image within the logical screen. |
|
1367 * @param aX Top-left x coordinate |
|
1368 * @param aY Top-left y coordinate |
|
1369 */ |
|
1370 virtual void setTopLeftCorner(int aX, int aY) = 0; |
|
1371 |
|
1372 |
|
1373 /** |
|
1374 * Get how to dispose of image before displaying the next. |
|
1375 * @return Dispose method |
|
1376 */ |
|
1377 virtual TDisposalMethod getDisposalMethod() = 0; |
|
1378 |
|
1379 /** |
|
1380 * Set how to dispose of image before displaying the next. |
|
1381 * @param aDisposalMethod Disposal method |
|
1382 */ |
|
1383 virtual void setDisposalMethod(int aDisposalMethod) = 0; |
|
1384 |
|
1385 /** |
|
1386 * Get image type. |
|
1387 * @return Type |
|
1388 */ |
|
1389 virtual TImageType getImageType() = 0; |
|
1390 |
|
1391 /** |
|
1392 * Set image type |
|
1393 * @param aImageType Image type |
|
1394 */ |
|
1395 virtual void setImageType(int aImageType) = 0; |
|
1396 |
|
1397 /** |
|
1398 * Get data |
|
1399 * @param aType Data type. |
|
1400 * @return Data |
|
1401 */ |
|
1402 virtual char* getData(TDataType aType) = 0; |
|
1403 |
|
1404 /** |
|
1405 * Get data size |
|
1406 * @param aType Data type. |
|
1407 * @return Data size |
|
1408 */ |
|
1409 virtual int getDataSize(TDataType aType) = 0; |
|
1410 |
|
1411 /** |
|
1412 * Set data |
|
1413 * @param aSrc Source image |
|
1414 */ |
|
1415 virtual void setData(Image* aSrc) = 0; |
|
1416 |
|
1417 /** |
|
1418 * Set data size |
|
1419 * @param aType Data type. |
|
1420 * @param aData The QByteArray encapsulating the data |
|
1421 */ |
|
1422 virtual void setData(ImageDataWrapper::TDataType aType, const QByteArray& aData) = 0; |
|
1423 |
|
1424 /** |
|
1425 * Get palette data |
|
1426 * @return Palette data |
|
1427 */ |
|
1428 virtual PaletteDataWrapper* getPaletteData() = 0; |
|
1429 |
|
1430 /** |
|
1431 * Set palette data |
|
1432 * @param aPaletteData Palette data |
|
1433 */ |
|
1434 virtual void setPaletteData(PaletteDataWrapper* aPaletteData) = 0; |
|
1435 |
|
1436 /** |
|
1437 * For checking if image color mapping is indexed or direct. |
|
1438 * @return <code>true</code> if mapping is direct |
|
1439 */ |
|
1440 virtual bool isDirect() = 0; |
|
1441 |
|
1442 }; |
|
1443 |
|
1444 /** |
|
1445 * Interface for wrapping SWT palette structure |
|
1446 */ |
|
1447 class PaletteDataWrapper |
|
1448 { |
|
1449 // Data types |
|
1450 public: |
|
1451 /** |
|
1452 * Data structure for direct palettes |
|
1453 * |
|
1454 * To extract a component from a colour: first apply the mask and then |
|
1455 * shift the result by the specified value. |
|
1456 * |
|
1457 * To combine components in order to build a colour, for each component: |
|
1458 * first shift by the opposite of the specified value and then apply the |
|
1459 * mask. Finally, combine all three components with a OR operator. |
|
1460 * |
|
1461 * In both cases, a positive value indicates a left shift whereas a |
|
1462 * negative one indicates a right shift. |
|
1463 */ |
|
1464 struct TDirectData |
|
1465 { |
|
1466 /** |
|
1467 * Ctor |
|
1468 */ |
|
1469 TDirectData(int aRMask = 0, int aGMask = 0, int aBMask = 0, |
|
1470 int aRShift = 0, int aGShift = 0, int aBShift = 0) |
|
1471 : mRedMask(aRMask), mGreenMask(aGMask), mBlueMask(aBMask), |
|
1472 mRedShift(aRShift), mGreenShift(aGShift), mBlueShift(aBShift) {} |
|
1473 |
|
1474 /** |
|
1475 * Copy ctor |
|
1476 */ |
|
1477 TDirectData(const TDirectData& aRhs) |
|
1478 { |
|
1479 *this = aRhs; |
|
1480 } |
|
1481 |
|
1482 /** |
|
1483 * Asignment operator |
|
1484 */ |
|
1485 TDirectData& operator=(const TDirectData& aRhs) |
|
1486 { |
|
1487 if(this != &aRhs) |
|
1488 { |
|
1489 mRedMask = aRhs.mRedMask; |
|
1490 mGreenMask = aRhs.mGreenMask; |
|
1491 mBlueMask = aRhs.mBlueMask; |
|
1492 mRedShift = aRhs.mRedShift; |
|
1493 mGreenShift = aRhs.mGreenShift; |
|
1494 mBlueShift = aRhs.mBlueShift; |
|
1495 } |
|
1496 return *this; |
|
1497 } |
|
1498 |
|
1499 int mRedMask; |
|
1500 int mGreenMask; |
|
1501 int mBlueMask; |
|
1502 int mRedShift; |
|
1503 int mGreenShift; |
|
1504 int mBlueShift; |
|
1505 |
|
1506 }; |
|
1507 |
|
1508 /** |
|
1509 * Indexed rgb data |
|
1510 */ |
|
1511 struct TIndexedRgb |
|
1512 { |
|
1513 /** |
|
1514 * Ctor |
|
1515 */ |
|
1516 TIndexedRgb(int aRed = -1, int aGreen = -1, int aBlue = -1) |
|
1517 : mRed(aRed), mGreen(aGreen), mBlue(aBlue) {} |
|
1518 |
|
1519 /** |
|
1520 * Copy ctor |
|
1521 */ |
|
1522 TIndexedRgb(const TIndexedRgb& aRhs) |
|
1523 { |
|
1524 *this = aRhs; |
|
1525 } |
|
1526 |
|
1527 /** |
|
1528 * Asignment operator |
|
1529 */ |
|
1530 TIndexedRgb& operator=(const TIndexedRgb& aRhs) |
|
1531 { |
|
1532 if(this != &aRhs) |
|
1533 { |
|
1534 mRed = aRhs.mRed; |
|
1535 mGreen = aRhs.mGreen; |
|
1536 mBlue = aRhs.mBlue; |
|
1537 } |
|
1538 return *this; |
|
1539 } |
|
1540 |
|
1541 int mRed; |
|
1542 int mGreen; |
|
1543 int mBlue; |
|
1544 }; |
|
1545 |
|
1546 // Methods |
|
1547 public: |
|
1548 /** |
|
1549 * Dtor |
|
1550 */ |
|
1551 virtual ~PaletteDataWrapper() {} |
|
1552 |
|
1553 /** |
|
1554 * For checking if image color mapping is indexed or direct. |
|
1555 * @return <code>true</code> if mapping is direct |
|
1556 */ |
|
1557 virtual bool isDirect() = 0; |
|
1558 |
|
1559 /** |
|
1560 * Returns direct data. |
|
1561 * @return Direct data. Null if the palette data is indexed. |
|
1562 */ |
|
1563 virtual TDirectData* getDirectData() = 0; |
|
1564 |
|
1565 /** |
|
1566 * Returns number of the indexed data. |
|
1567 * @return Indexed data count. Zero if the palette data is direct. |
|
1568 */ |
|
1569 virtual int getIndexedRgbCount() = 0; |
|
1570 |
|
1571 /** |
|
1572 * Returns indexed data. |
|
1573 * @param aIndex Defains location of the wanted rgb data. |
|
1574 * @return Indexed rgb data. The returned structure contains invalid values if the |
|
1575 * palette is direct. |
|
1576 */ |
|
1577 virtual TIndexedRgb getIndexedRgb(int aIndex) = 0; |
|
1578 |
|
1579 |
|
1580 virtual QVector<QRgb>* getIndexedPalette() = 0; |
|
1581 }; |
|
1582 |
|
1583 class Surface |
|
1584 { |
|
1585 public: |
|
1586 //virtual void* getTarget() = 0; |
|
1587 //virtual void setTarget(int aTarget, TTargetType aType) = 0; |
|
1588 }; |
|
1589 |
|
1590 /* |
|
1591 * Exception class for graphics. |
|
1592 * |
|
1593 * @param errorCode The graphics errorcode which maps to java exception |
|
1594 * @param msg The detailed description of exception occured |
|
1595 * |
|
1596 * @see jniutils resolveException for java exception mapping |
|
1597 */ |
|
1598 class GfxException { |
|
1599 public: |
|
1600 GfxException(const int& aErrorCode, const QString aMsg) : mErrorCode(aErrorCode) |
|
1601 { |
|
1602 mMsg = new char[aMsg.size()+1]; |
|
1603 strcpy(mMsg, aMsg.toAscii().data()); |
|
1604 }; |
|
1605 //~GfxException() { delete mMsg; }; |
|
1606 int getErrorCode() { return mErrorCode; }; |
|
1607 const char* getMsg() { return (const char*)mMsg; }; |
|
1608 private: |
|
1609 int mErrorCode; |
|
1610 char* mMsg; |
|
1611 }; |
|
1612 |
|
1613 /** |
|
1614 * Interface to graphics factory |
|
1615 */ |
|
1616 |
|
1617 class GraphicsFactory |
|
1618 { |
|
1619 public: |
|
1620 |
|
1621 /** |
|
1622 * Creates a WindowSurface instance for paint device. |
|
1623 * @param aSurface Target paint device for the window surface |
|
1624 * @param aType The type of paint device, one of defined types in WindowSurfaceType enum |
|
1625 */ |
|
1626 static WindowSurface* createWindowSurface(QPaintDevice* aSurface, WindowSurfaceType aType); |
|
1627 |
|
1628 /** |
|
1629 * Creates a WindowSurface instance for window owning widget. |
|
1630 * @param aWidget Window owning widget |
|
1631 * @param aAutoRefresh If true the Qt window surface pointer is updated each time |
|
1632 * the bind is called, otherwise not |
|
1633 */ |
|
1634 static WindowSurface* createWindowSurface(QWidget* aWidget, bool aAutoRefresh); |
|
1635 |
|
1636 /** |
|
1637 * Creates a Buffer instance. |
|
1638 */ |
|
1639 static Buffer* createBuffer(); |
|
1640 |
|
1641 /** |
|
1642 * Creates a graphics context instance. |
|
1643 */ |
|
1644 static GraphicsContext* createGraphicsContext(); |
|
1645 |
|
1646 /** |
|
1647 * Creates an image with given width, height and initial fillColor. |
|
1648 * |
|
1649 * @param aWidth Image width |
|
1650 * @param aHeight Image height |
|
1651 * @param aFillColor The initial color for the image in format #00RRGGBB |
|
1652 * where hight order byte, i.e. alpha is ingored |
|
1653 */ |
|
1654 static Image* createImage(int aWidth, int aHeight, int aFillColor); |
|
1655 |
|
1656 /** |
|
1657 * Create a copy based on the given image. |
|
1658 * If the given copy region is empty, the whole image is copied. |
|
1659 * |
|
1660 * @param aImage The source image |
|
1661 * @param aX The top-left x coordinate of the copy region. |
|
1662 * @param aY The top-left y coordinate of the copy region. |
|
1663 * @param aWidth The width of the copy region. |
|
1664 * @param aHeight The height of the copy region. |
|
1665 * @see Image::createImage |
|
1666 */ |
|
1667 static Image* createImage( |
|
1668 Image* aImage, int aX = 0, int aY = 0, int aWidth = 0, int aHeight = 0); |
|
1669 |
|
1670 /** |
|
1671 * Create image from a QImage |
|
1672 * |
|
1673 * @param aImage The source QImage |
|
1674 */ |
|
1675 static Image* createImage(const QImage& aImage); |
|
1676 |
|
1677 /** |
|
1678 * Create image from a QPixmap. |
|
1679 * |
|
1680 * @param aImage The source QPixmap |
|
1681 */ |
|
1682 static Image* createImage(const QPixmap& aPixmap); |
|
1683 |
|
1684 /** |
|
1685 * Creates an image based on the given ARGB data array. |
|
1686 * @param aRgbData ARGB data array. One pixel is specified as 0xAARRGGBB. |
|
1687 * @param aWidth Image width |
|
1688 * @param aHeight Image height |
|
1689 * @param aHasAlpha If true the rgb data has also an alpha channel, |
|
1690 * otherwise all pixels are fully opaque, e.g. 0xFFRRGGBB. |
|
1691 */ |
|
1692 static Image* createImage(int* aRgbData, int aWidth, int aHeight, bool aHasAlpha); |
|
1693 |
|
1694 /** |
|
1695 * Creates new imageloader instance |
|
1696 */ |
|
1697 static ImageLoader* createImageLoader(); |
|
1698 |
|
1699 /** |
|
1700 * TODO |
|
1701 */ |
|
1702 static Image* createImage(ImageDataWrapper* aImageDataPtr); |
|
1703 |
|
1704 /** |
|
1705 * TODO |
|
1706 */ |
|
1707 static ImageDataWrapper* createImageData(Image* aImage = NULL); |
|
1708 |
|
1709 /** |
|
1710 * TODO |
|
1711 */ |
|
1712 static PaletteDataWrapper* createPaletteData(PaletteDataWrapper::TDirectData& aDirectData); |
|
1713 |
|
1714 /** |
|
1715 * TODO |
|
1716 */ |
|
1717 static PaletteDataWrapper* createPaletteData(QVector<QRgb>& aIndexedData); |
|
1718 }; |
|
1719 |
|
1720 }} |
|
1721 #endif //GRAPHICS_H |