javauis/lcdui_qt/src/javax/microedition/lcdui/DirectGraphicsImpl.java
changeset 23 98ccebc37403
parent 21 2a9601315dfc
child 26 dc7c549001d5
equal deleted inserted replaced
21:2a9601315dfc 23:98ccebc37403
     9 * Initial Contributors:
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    10 * Nokia Corporation - initial contribution.
    11 *
    11 *
    12 * Contributors:
    12 * Contributors:
    13 *
    13 *
    14 * Description: 
    14 * Description:
    15 *
    15 *
    16 */
    16 */
    17 package javax.microedition.lcdui;
    17 package javax.microedition.lcdui;
    18 
    18 
    19 import javax.microedition.lcdui.game.Sprite;
    19 import javax.microedition.lcdui.game.Sprite;
    23 /**
    23 /**
    24  * DirectGraphics interface implementation class.
    24  * DirectGraphics interface implementation class.
    25  *
    25  *
    26  * @see DirectGraphics
    26  * @see DirectGraphics
    27  */
    27  */
    28 class DirectGraphicsImpl implements DirectGraphics {
    28 class DirectGraphicsImpl implements DirectGraphics
       
    29 {
    29 
    30 
    30     private static final int MANIPULATION_MASK = 0x0FFF;
    31     private static final int MANIPULATION_MASK = 0x0FFF;
    31 
    32 
    32     private Graphics graphics;
    33     private Graphics graphics;
    33 
    34 
    34     private int alpha;
    35     private int alpha;
    35 
    36 
    36     DirectGraphicsImpl(Graphics g) {
    37     DirectGraphicsImpl(Graphics g)
       
    38     {
    37         graphics = g;
    39         graphics = g;
    38     }
    40     }
    39 
    41 
    40     public void drawImage(Image img, int x, int y, int anchor,
    42     public void drawImage(Image img, int x, int y, int anchor,
    41             int manipulation) {
    43                           int manipulation)
       
    44     {
    42 
    45 
    43         int transform = getTransformation(manipulation);
    46         int transform = getTransformation(manipulation);
    44         if (transform < 0) {
    47         if(transform < 0)
    45             throw new IllegalArgumentException(
    48         {
    46                     MsgRepository.DIRECTGRAPHICS_EXCEPTION_INVALID_MANIPULATION);
    49             throw new IllegalArgumentException(
       
    50                 MsgRepository.DIRECTGRAPHICS_EXCEPTION_INVALID_MANIPULATION);
    47         }
    51         }
    48         graphics.drawRegion(img, 0, 0, img.getWidth(), img.getHeight(),
    52         graphics.drawRegion(img, 0, 0, img.getWidth(), img.getHeight(),
    49                 transform, x, y, anchor);
    53                             transform, x, y, anchor);
    50     }
    54     }
    51 
    55 
    52     public void drawPixels(final int[] pixels, final boolean transparency,
    56     public void drawPixels(final int[] pixels, final boolean transparency,
    53             final int offset, final int scanlength, final int x, final int y,
    57                            final int offset, final int scanlength, final int x, final int y,
    54             final int width, final int height, final int manipulation,
    58                            final int width, final int height, final int manipulation,
    55             final int format) {
    59                            final int format)
       
    60     {
    56 
    61 
    57         int transform = getTransformation(manipulation);
    62         int transform = getTransformation(manipulation);
    58         if (transform < 0) {
    63         if(transform < 0)
    59             throw new IllegalArgumentException(
    64         {
    60                     MsgRepository.DIRECTGRAPHICS_EXCEPTION_INVALID_MANIPULATION);
    65             throw new IllegalArgumentException(
    61         }
    66                 MsgRepository.DIRECTGRAPHICS_EXCEPTION_INVALID_MANIPULATION);
    62         if (format != TYPE_INT_888_RGB && format != TYPE_INT_8888_ARGB) {
    67         }
    63             throw new IllegalArgumentException(
    68         if(format != TYPE_INT_888_RGB && format != TYPE_INT_8888_ARGB)
    64                     MsgRepository.DIRECTGRAPHICS_EXCEPTION_INVALID_FORMAT);
    69         {
       
    70             throw new IllegalArgumentException(
       
    71                 MsgRepository.DIRECTGRAPHICS_EXCEPTION_INVALID_FORMAT);
    65         }
    72         }
    66 
    73 
    67         final boolean processAlpha = (format == TYPE_INT_8888_ARGB);
    74         final boolean processAlpha = (format == TYPE_INT_8888_ARGB);
    68         ESWTUIThreadRunner.safeSyncExec(new Runnable() {
    75         ESWTUIThreadRunner.safeSyncExec(new Runnable()
    69             public void run() {
    76         {
       
    77             public void run()
       
    78             {
    70                 graphics.getGc().drawRGB(pixels, offset, scanlength,
    79                 graphics.getGc().drawRGB(pixels, offset, scanlength,
    71                         x, y, width, height, processAlpha,
    80                                          x, y, width, height, processAlpha,
    72                         getNativeTransformValue(manipulation));
    81                                          getNativeTransformValue(manipulation));
    73             }
    82             }
    74         });
    83         });
    75     }
    84     }
    76 
    85 
    77     public void drawPixels(final byte[] pixels, final byte[] transparencyMask,
    86     public void drawPixels(final byte[] pixels, final byte[] transparencyMask,
    78             final int offset, final int scanlength, final int x, final int y,
    87                            final int offset, final int scanlength, final int x, final int y,
    79             final int width, final int height, final int manipulation,
    88                            final int width, final int height, final int manipulation,
    80             final int format) {
    89                            final int format)
       
    90     {
    81 
    91 
    82         int transform = getTransformation(manipulation);
    92         int transform = getTransformation(manipulation);
    83         if (transform < 0) {
    93         if(transform < 0)
    84             throw new IllegalArgumentException(
    94         {
    85                     MsgRepository.DIRECTGRAPHICS_EXCEPTION_INVALID_MANIPULATION);
    95             throw new IllegalArgumentException(
    86         }
    96                 MsgRepository.DIRECTGRAPHICS_EXCEPTION_INVALID_MANIPULATION);
    87         if (format != TYPE_BYTE_1_GRAY && format != TYPE_BYTE_2_GRAY) {
    97         }
    88             throw new IllegalArgumentException(
    98         if(format != TYPE_BYTE_1_GRAY && format != TYPE_BYTE_2_GRAY)
    89                     MsgRepository.DIRECTGRAPHICS_EXCEPTION_INVALID_FORMAT);
    99         {
    90         }
   100             throw new IllegalArgumentException(
    91 
   101                 MsgRepository.DIRECTGRAPHICS_EXCEPTION_INVALID_FORMAT);
    92         ESWTUIThreadRunner.safeSyncExec(new Runnable() {
   102         }
    93             public void run() {
   103 
       
   104         ESWTUIThreadRunner.safeSyncExec(new Runnable()
       
   105         {
       
   106             public void run()
       
   107             {
    94                 graphics.getGc().drawRGB(pixels, transparencyMask, offset, scanlength,
   108                 graphics.getGc().drawRGB(pixels, transparencyMask, offset, scanlength,
    95                         x, y, width, height, getNativeTransformValue(manipulation),
   109                                          x, y, width, height, getNativeTransformValue(manipulation),
    96                         getNativeFormatValue(format));
   110                                          getNativeFormatValue(format));
    97             }
   111             }
    98         });
   112         });
    99     }
   113     }
   100 
   114 
   101     public void drawPixels(final short[] pixels, final boolean transparency,
   115     public void drawPixels(final short[] pixels, final boolean transparency,
   102             final int offset, final int scanlength, final int x, final int y,
   116                            final int offset, final int scanlength, final int x, final int y,
   103             final int width, final int height, final int manipulation,
   117                            final int width, final int height, final int manipulation,
   104             final int format) {
   118                            final int format)
       
   119     {
   105 
   120 
   106         int transform = getTransformation(manipulation);
   121         int transform = getTransformation(manipulation);
   107         if (transform < 0) {
   122         if(transform < 0)
   108             throw new IllegalArgumentException(
   123         {
   109                     MsgRepository.DIRECTGRAPHICS_EXCEPTION_INVALID_MANIPULATION);
   124             throw new IllegalArgumentException(
   110         }
   125                 MsgRepository.DIRECTGRAPHICS_EXCEPTION_INVALID_MANIPULATION);
   111         if (format != TYPE_USHORT_4444_ARGB
   126         }
       
   127         if(format != TYPE_USHORT_4444_ARGB
   112                 && format != TYPE_USHORT_444_RGB
   128                 && format != TYPE_USHORT_444_RGB
   113                 && format != TYPE_USHORT_565_RGB
   129                 && format != TYPE_USHORT_565_RGB
   114                 && format != TYPE_USHORT_555_RGB) {
   130                 && format != TYPE_USHORT_555_RGB)
   115             throw new IllegalArgumentException(
   131         {
   116                     MsgRepository.DIRECTGRAPHICS_EXCEPTION_INVALID_FORMAT);
   132             throw new IllegalArgumentException(
       
   133                 MsgRepository.DIRECTGRAPHICS_EXCEPTION_INVALID_FORMAT);
   117         }
   134         }
   118 
   135 
   119         final boolean processAlpha = (format == TYPE_USHORT_4444_ARGB);
   136         final boolean processAlpha = (format == TYPE_USHORT_4444_ARGB);
   120         ESWTUIThreadRunner.safeSyncExec(new Runnable() {
   137         ESWTUIThreadRunner.safeSyncExec(new Runnable()
   121             public void run() {
   138         {
       
   139             public void run()
       
   140             {
   122                 graphics.getGc().drawRGB(pixels, offset, scanlength,
   141                 graphics.getGc().drawRGB(pixels, offset, scanlength,
   123                         x, y, width, height, processAlpha,
   142                                          x, y, width, height, processAlpha,
   124                         getNativeTransformValue(manipulation),
   143                                          getNativeTransformValue(manipulation),
   125                         getNativeFormatValue(format));
   144                                          getNativeFormatValue(format));
   126             }
   145             }
   127         });
   146         });
   128     }
   147     }
   129 
   148 
   130     public void drawPolygon(int[] xPoints, int xOffset, int[] yPoints,
   149     public void drawPolygon(int[] xPoints, int xOffset, int[] yPoints,
   131             int yOffset, int nPoints, int argbColor) {
   150                             int yOffset, int nPoints, int argbColor)
       
   151     {
   132         setARGBColor(argbColor);
   152         setARGBColor(argbColor);
   133         final int[] points = new int[nPoints * 2];
   153         final int[] points = new int[nPoints * 2];
   134         for (int i = 0; i < nPoints; i++) {
   154         for(int i = 0; i < nPoints; i++)
       
   155         {
   135             points[i * 2] = xPoints[xOffset + i];
   156             points[i * 2] = xPoints[xOffset + i];
   136             points[(i * 2) + 1] = yPoints[yOffset + i];
   157             points[(i * 2) + 1] = yPoints[yOffset + i];
   137         }
   158         }
   138         ESWTUIThreadRunner.safeSyncExec(new Runnable() {
   159         ESWTUIThreadRunner.safeSyncExec(new Runnable()
   139             public void run() {
   160         {
       
   161             public void run()
       
   162             {
   140                 graphics.getGc().drawPolygon(points);
   163                 graphics.getGc().drawPolygon(points);
   141             }
   164             }
   142         });
   165         });
   143     }
   166     }
   144 
   167 
   145     public void drawTriangle(int x1, int y1, int x2, int y2, int x3, int y3,
   168     public void drawTriangle(int x1, int y1, int x2, int y2, int x3, int y3,
   146             int argbColor) {
   169                              int argbColor)
       
   170     {
   147         setARGBColor(argbColor);
   171         setARGBColor(argbColor);
   148         final int[] points = {x1, y1, x2, y2, x3, y3};
   172         final int[] points = {x1, y1, x2, y2, x3, y3};
   149         ESWTUIThreadRunner.safeSyncExec(new Runnable() {
   173         ESWTUIThreadRunner.safeSyncExec(new Runnable()
   150             public void run() {
   174         {
       
   175             public void run()
       
   176             {
   151                 graphics.getGc().drawPolygon(points);
   177                 graphics.getGc().drawPolygon(points);
   152             }
   178             }
   153         });
   179         });
   154     }
   180     }
   155 
   181 
   156     public void fillPolygon(int[] xPoints, int xOffset, int[] yPoints,
   182     public void fillPolygon(int[] xPoints, int xOffset, int[] yPoints,
   157             int yOffset, int nPoints, int argbColor) {
   183                             int yOffset, int nPoints, int argbColor)
       
   184     {
   158         setARGBColor(argbColor);
   185         setARGBColor(argbColor);
   159         final int[] points = new int[nPoints * 2];
   186         final int[] points = new int[nPoints * 2];
   160         for (int i = 0; i < nPoints; i++) {
   187         for(int i = 0; i < nPoints; i++)
       
   188         {
   161             points[i * 2] = xPoints[xOffset + i];
   189             points[i * 2] = xPoints[xOffset + i];
   162             points[(i * 2) + 1] = yPoints[yOffset + i];
   190             points[(i * 2) + 1] = yPoints[yOffset + i];
   163         }
   191         }
   164         ESWTUIThreadRunner.safeSyncExec(new Runnable() {
   192         ESWTUIThreadRunner.safeSyncExec(new Runnable()
   165             public void run() {
   193         {
       
   194             public void run()
       
   195             {
   166                 graphics.getGc().fillPolygon(points);
   196                 graphics.getGc().fillPolygon(points);
   167             }
   197             }
   168         });
   198         });
   169     }
   199     }
   170 
   200 
   171     public void fillTriangle(int x1, int y1, int x2, int y2, int x3, int y3,
   201     public void fillTriangle(int x1, int y1, int x2, int y2, int x3, int y3,
   172             int argbColor) {
   202                              int argbColor)
       
   203     {
   173         setARGBColor(argbColor);
   204         setARGBColor(argbColor);
   174         final int[] points = {x1, y1, x2, y2, x3, y3};
   205         final int[] points = {x1, y1, x2, y2, x3, y3};
   175         ESWTUIThreadRunner.safeSyncExec(new Runnable() {
   206         ESWTUIThreadRunner.safeSyncExec(new Runnable()
   176             public void run() {
   207         {
       
   208             public void run()
       
   209             {
   177                 graphics.getGc().fillPolygon(points);
   210                 graphics.getGc().fillPolygon(points);
   178             }
   211             }
   179         });
   212         });
   180     }
   213     }
   181 
   214 
   182 
   215 
   183     public void getPixels(final int[] pixels, final int offset,
   216     public void getPixels(final int[] pixels, final int offset,
   184             final int scanlength, final int x, final int y, final int width,
   217                           final int scanlength, final int x, final int y, final int width,
   185             final int height, final int format) {
   218                           final int height, final int format)
   186         if (format != TYPE_INT_888_RGB) {
   219     {
   187             throw new IllegalArgumentException(
   220         if(format != TYPE_INT_888_RGB)
   188                     MsgRepository.DIRECTGRAPHICS_EXCEPTION_INVALID_FORMAT);
   221         {
   189         }
   222             throw new IllegalArgumentException(
   190         if (width < 0 || height < 0) {
   223                 MsgRepository.DIRECTGRAPHICS_EXCEPTION_INVALID_FORMAT);
   191             throw new IllegalArgumentException(
   224         }
   192                    MsgRepository.DIRECTGRAPHICS_EXCEPTION_INVALID_WIDTH_HEIGHT);
   225         if(width < 0 || height < 0)
   193         }
   226         {
   194         ESWTUIThreadRunner.safeSyncExec(new Runnable() {
   227             throw new IllegalArgumentException(
   195             public void run() {
   228                 MsgRepository.DIRECTGRAPHICS_EXCEPTION_INVALID_WIDTH_HEIGHT);
       
   229         }
       
   230         ESWTUIThreadRunner.safeSyncExec(new Runnable()
       
   231         {
       
   232             public void run()
       
   233             {
   196                 org.eclipse.swt.internal.qt.graphics.Image cgImg;
   234                 org.eclipse.swt.internal.qt.graphics.Image cgImg;
   197                 Object target = graphics.getGc().getBoundTarget();
   235                 Object target = graphics.getGc().getBoundTarget();
   198                 if (target != null && target instanceof org.eclipse.swt.internal.qt.graphics.Image) {
   236                 if(target != null && target instanceof org.eclipse.swt.internal.qt.graphics.Image)
       
   237                 {
   199                     cgImg = (org.eclipse.swt.internal.qt.graphics.Image) target;
   238                     cgImg = (org.eclipse.swt.internal.qt.graphics.Image) target;
   200                 }
   239                 }
   201                 else {
   240                 else
       
   241                 {
   202                     cgImg = new org.eclipse.swt.internal.qt.graphics.Image(width, height);
   242                     cgImg = new org.eclipse.swt.internal.qt.graphics.Image(width, height);
   203                     // TODO: in future the copyArea() signature will change
   243                     // TODO: in future the copyArea() signature will change
   204                     graphics.getGc().copyArea(cgImg, x, y);
   244                     graphics.getGc().copyArea(cgImg, x, y);
   205                 }
   245                 }
   206                 cgImg.getRGB(pixels, offset, scanlength, x, y, width, height);
   246                 cgImg.getRGB(pixels, offset, scanlength, x, y, width, height);
   207                 if (target == null || !(target instanceof org.eclipse.swt.internal.qt.graphics.Image)) {
   247                 if(target == null || !(target instanceof org.eclipse.swt.internal.qt.graphics.Image))
       
   248                 {
   208                     cgImg.dispose();
   249                     cgImg.dispose();
   209                 }
   250                 }
   210             }
   251             }
   211         });
   252         });
   212     }
   253     }
   213 
   254 
   214     public void getPixels(final byte[] pixels, final byte[] transparencyMask,
   255     public void getPixels(final byte[] pixels, final byte[] transparencyMask,
   215             final int offset, final int scanlength, final int x, final int y,
   256                           final int offset, final int scanlength, final int x, final int y,
   216             final int width, final int height, final int format) {
   257                           final int width, final int height, final int format)
   217         if (format != TYPE_BYTE_1_GRAY) {
   258     {
   218             throw new IllegalArgumentException(
   259         if(format != TYPE_BYTE_1_GRAY)
   219                     MsgRepository.DIRECTGRAPHICS_EXCEPTION_INVALID_FORMAT);
   260         {
   220         }
   261             throw new IllegalArgumentException(
   221         if (width < 0 || height < 0) {
   262                 MsgRepository.DIRECTGRAPHICS_EXCEPTION_INVALID_FORMAT);
   222             throw new IllegalArgumentException(
   263         }
   223                    MsgRepository.DIRECTGRAPHICS_EXCEPTION_INVALID_WIDTH_HEIGHT);
   264         if(width < 0 || height < 0)
   224         }
   265         {
   225         ESWTUIThreadRunner.safeSyncExec(new Runnable() {
   266             throw new IllegalArgumentException(
   226             public void run() {
   267                 MsgRepository.DIRECTGRAPHICS_EXCEPTION_INVALID_WIDTH_HEIGHT);
       
   268         }
       
   269         ESWTUIThreadRunner.safeSyncExec(new Runnable()
       
   270         {
       
   271             public void run()
       
   272             {
   227                 org.eclipse.swt.internal.qt.graphics.Image cgImg;
   273                 org.eclipse.swt.internal.qt.graphics.Image cgImg;
   228                 Object target = graphics.getGc().getBoundTarget();
   274                 Object target = graphics.getGc().getBoundTarget();
   229                 if (target != null && target instanceof org.eclipse.swt.internal.qt.graphics.Image) {
   275                 if(target != null && target instanceof org.eclipse.swt.internal.qt.graphics.Image)
       
   276                 {
   230                     cgImg = (org.eclipse.swt.internal.qt.graphics.Image) target;
   277                     cgImg = (org.eclipse.swt.internal.qt.graphics.Image) target;
   231                 }
   278                 }
   232                 else {
   279                 else
       
   280                 {
   233                     cgImg = new org.eclipse.swt.internal.qt.graphics.Image(width, height);
   281                     cgImg = new org.eclipse.swt.internal.qt.graphics.Image(width, height);
   234                     graphics.getGc().copyArea(cgImg, x, y);
   282                     graphics.getGc().copyArea(cgImg, x, y);
   235                 }
   283                 }
   236                 cgImg.getRGB(pixels, transparencyMask, offset, scanlength, x, y, width,
   284                 cgImg.getRGB(pixels, transparencyMask, offset, scanlength, x, y, width,
   237                         height, getNativeFormatValue(format));
   285                              height, getNativeFormatValue(format));
   238                 if (target == null || !(target instanceof org.eclipse.swt.internal.qt.graphics.Image)) {
   286                 if(target == null || !(target instanceof org.eclipse.swt.internal.qt.graphics.Image))
       
   287                 {
   239                     cgImg.dispose();
   288                     cgImg.dispose();
   240                 }
   289                 }
   241             }
   290             }
   242         });
   291         });
   243     }
   292     }
   244 
   293 
   245     public void getPixels(final short[] pixels, final int offset,
   294     public void getPixels(final short[] pixels, final int offset,
   246             final int scanlength, final int x, final int y, final int width,
   295                           final int scanlength, final int x, final int y, final int width,
   247             final int height, final int format) {
   296                           final int height, final int format)
   248         if (format != TYPE_USHORT_4444_ARGB
   297     {
   249             && format != TYPE_USHORT_444_RGB
   298         if(format != TYPE_USHORT_4444_ARGB
   250             && format != TYPE_USHORT_565_RGB
   299                 && format != TYPE_USHORT_444_RGB
   251             && format != TYPE_USHORT_555_RGB) {
   300                 && format != TYPE_USHORT_565_RGB
   252             throw new IllegalArgumentException(
   301                 && format != TYPE_USHORT_555_RGB)
   253                     MsgRepository.DIRECTGRAPHICS_EXCEPTION_INVALID_FORMAT);
   302         {
   254         }
   303             throw new IllegalArgumentException(
   255         if (width < 0 || height < 0) {
   304                 MsgRepository.DIRECTGRAPHICS_EXCEPTION_INVALID_FORMAT);
   256             throw new IllegalArgumentException(
   305         }
   257                    MsgRepository.DIRECTGRAPHICS_EXCEPTION_INVALID_WIDTH_HEIGHT);
   306         if(width < 0 || height < 0)
   258         }
   307         {
   259         ESWTUIThreadRunner.safeSyncExec(new Runnable() {
   308             throw new IllegalArgumentException(
   260             public void run() {
   309                 MsgRepository.DIRECTGRAPHICS_EXCEPTION_INVALID_WIDTH_HEIGHT);
       
   310         }
       
   311         ESWTUIThreadRunner.safeSyncExec(new Runnable()
       
   312         {
       
   313             public void run()
       
   314             {
   261                 org.eclipse.swt.internal.qt.graphics.Image cgImg;
   315                 org.eclipse.swt.internal.qt.graphics.Image cgImg;
   262                 Object target = graphics.getGc().getBoundTarget();
   316                 Object target = graphics.getGc().getBoundTarget();
   263                 if (target != null && target instanceof org.eclipse.swt.internal.qt.graphics.Image) {
   317                 if(target != null && target instanceof org.eclipse.swt.internal.qt.graphics.Image)
       
   318                 {
   264                     cgImg = (org.eclipse.swt.internal.qt.graphics.Image) target;
   319                     cgImg = (org.eclipse.swt.internal.qt.graphics.Image) target;
   265                 }
   320                 }
   266                 else {
   321                 else
       
   322                 {
   267                     cgImg = new org.eclipse.swt.internal.qt.graphics.Image(width, height);
   323                     cgImg = new org.eclipse.swt.internal.qt.graphics.Image(width, height);
   268                     graphics.getGc().copyArea(cgImg, x, y);
   324                     graphics.getGc().copyArea(cgImg, x, y);
   269                 }
   325                 }
   270                 cgImg.getRGB(pixels, offset, scanlength, 0, 0, width, height, getNativeFormatValue(format));
   326                 cgImg.getRGB(pixels, offset, scanlength, 0, 0, width, height, getNativeFormatValue(format));
   271                 if (target == null || !(target instanceof org.eclipse.swt.internal.qt.graphics.Image)) {
   327                 if(target == null || !(target instanceof org.eclipse.swt.internal.qt.graphics.Image))
       
   328                 {
   272                     cgImg.dispose();
   329                     cgImg.dispose();
   273                 }
   330                 }
   274             }
   331             }
   275         });
   332         });
   276     }
   333     }
   277 
   334 
   278     public void setARGBColor(int argbColor) {
   335     public void setARGBColor(int argbColor)
       
   336     {
   279         alpha = (argbColor >> 24) & Graphics.COMPONENT_MASK;
   337         alpha = (argbColor >> 24) & Graphics.COMPONENT_MASK;
   280         graphics.setColor(argbColor);
   338         graphics.setColor(argbColor);
   281         ESWTUIThreadRunner.safeSyncExec(new Runnable() {
   339         ESWTUIThreadRunner.safeSyncExec(new Runnable()
   282             public void run() {
   340         {
       
   341             public void run()
       
   342             {
   283                 graphics.getGc().setForegroundAlpha(alpha);
   343                 graphics.getGc().setForegroundAlpha(alpha);
   284                 graphics.getGc().setBackgroundAlpha(alpha);
   344                 graphics.getGc().setBackgroundAlpha(alpha);
   285             }
   345             }
   286         });
   346         });
   287     }
   347     }
   288 
   348 
   289     public int getAlphaComponent() {
   349     public int getAlphaComponent()
       
   350     {
   290         return alpha;
   351         return alpha;
   291     }
   352     }
   292 
   353 
   293     public int getNativePixelFormat() {
   354     public int getNativePixelFormat()
       
   355     {
   294         // TODO: is this the native pixel format ?
   356         // TODO: is this the native pixel format ?
   295         return TYPE_INT_8888_ARGB;
   357         return TYPE_INT_8888_ARGB;
   296     }
   358     }
   297 
   359 
   298     private static int getTransformation(int manipulation) {
   360     private static int getTransformation(int manipulation)
       
   361     {
   299         // manipulations are C-CW and sprite rotations are CW
   362         // manipulations are C-CW and sprite rotations are CW
   300         int ret = -1;
   363         int ret = -1;
   301         int rotation = manipulation & MANIPULATION_MASK;
   364         int rotation = manipulation & MANIPULATION_MASK;
   302         if ((manipulation & FLIP_HORIZONTAL) != 0) {
   365         if((manipulation & FLIP_HORIZONTAL) != 0)
   303             if ((manipulation & FLIP_VERTICAL) != 0) {
   366         {
       
   367             if((manipulation & FLIP_VERTICAL) != 0)
       
   368             {
   304                 // horiz and vertical flipping
   369                 // horiz and vertical flipping
   305                 switch (rotation) {
   370                 switch(rotation)
   306                     case 0:
   371                 {
   307                         ret = Sprite.TRANS_ROT180;
   372                 case 0:
   308                         break;
   373                     ret = Sprite.TRANS_ROT180;
   309                     case ROTATE_90:
   374                     break;
   310                         ret = Sprite.TRANS_ROT90;
   375                 case ROTATE_90:
   311                         break;
   376                     ret = Sprite.TRANS_ROT90;
   312                     case ROTATE_180:
   377                     break;
   313                         ret = Sprite.TRANS_NONE;
   378                 case ROTATE_180:
   314                         break;
   379                     ret = Sprite.TRANS_NONE;
   315                     case ROTATE_270:
   380                     break;
   316                         ret = Sprite.TRANS_ROT270;
   381                 case ROTATE_270:
   317                         break;
   382                     ret = Sprite.TRANS_ROT270;
   318                     default:
   383                     break;
   319                 }
   384                 default:
   320             }
   385                 }
   321             else {
   386             }
       
   387             else
       
   388             {
   322                 // horizontal flipping
   389                 // horizontal flipping
   323                 switch (rotation) {
   390                 switch(rotation)
   324                     case 0:
   391                 {
   325                         ret = Sprite.TRANS_MIRROR_ROT180;
   392                 case 0:
   326                         break;
   393                     ret = Sprite.TRANS_MIRROR_ROT180;
   327                     case ROTATE_90:
   394                     break;
   328                         ret = Sprite.TRANS_MIRROR_ROT90;
   395                 case ROTATE_90:
   329                         break;
   396                     ret = Sprite.TRANS_MIRROR_ROT90;
   330                     case ROTATE_180:
   397                     break;
   331                         ret = Sprite.TRANS_MIRROR;
   398                 case ROTATE_180:
   332                         break;
   399                     ret = Sprite.TRANS_MIRROR;
   333                     case ROTATE_270:
   400                     break;
   334                         ret = Sprite.TRANS_MIRROR_ROT270;
   401                 case ROTATE_270:
   335                         break;
   402                     ret = Sprite.TRANS_MIRROR_ROT270;
   336                     default:
   403                     break;
   337                 }
   404                 default:
   338             }
   405                 }
   339         }
   406             }
   340         else {
   407         }
   341             if ((manipulation & FLIP_VERTICAL) != 0) {
   408         else
       
   409         {
       
   410             if((manipulation & FLIP_VERTICAL) != 0)
       
   411             {
   342                 // vertical flipping
   412                 // vertical flipping
   343                 switch (rotation) {
   413                 switch(rotation)
   344                     case 0:
   414                 {
   345                         ret = Sprite.TRANS_MIRROR;
   415                 case 0:
   346                         break;
   416                     ret = Sprite.TRANS_MIRROR;
   347                     case ROTATE_90:
   417                     break;
   348                         ret = Sprite.TRANS_MIRROR_ROT270;
   418                 case ROTATE_90:
   349                         break;
   419                     ret = Sprite.TRANS_MIRROR_ROT270;
   350                     case ROTATE_180:
   420                     break;
   351                         ret = Sprite.TRANS_MIRROR_ROT180;
   421                 case ROTATE_180:
   352                         break;
   422                     ret = Sprite.TRANS_MIRROR_ROT180;
   353                     case ROTATE_270:
   423                     break;
   354                         ret = Sprite.TRANS_MIRROR_ROT90;
   424                 case ROTATE_270:
   355                         break;
   425                     ret = Sprite.TRANS_MIRROR_ROT90;
   356                     default:
   426                     break;
   357                 }
   427                 default:
   358             }
   428                 }
   359             else {
   429             }
       
   430             else
       
   431             {
   360                 // no flipping
   432                 // no flipping
   361                 switch (rotation) {
   433                 switch(rotation)
   362                     case 0:
   434                 {
   363                         ret = Sprite.TRANS_NONE;
   435                 case 0:
   364                         break;
   436                     ret = Sprite.TRANS_NONE;
   365                     case ROTATE_90:
   437                     break;
   366                         ret = Sprite.TRANS_ROT270;
   438                 case ROTATE_90:
   367                         break;
   439                     ret = Sprite.TRANS_ROT270;
   368                     case ROTATE_180:
   440                     break;
   369                         ret = Sprite.TRANS_ROT180;
   441                 case ROTATE_180:
   370                         break;
   442                     ret = Sprite.TRANS_ROT180;
   371                     case ROTATE_270:
   443                     break;
   372                         ret = Sprite.TRANS_ROT90;
   444                 case ROTATE_270:
   373                         break;
   445                     ret = Sprite.TRANS_ROT90;
   374                     default:
   446                     break;
       
   447                 default:
   375                 }
   448                 }
   376             }
   449             }
   377         }
   450         }
   378         return ret;
   451         return ret;
   379     }
   452     }
   383      *
   456      *
   384      * @param manipulation LCDUI manipulation
   457      * @param manipulation LCDUI manipulation
   385      *
   458      *
   386      * @return corresponding native transformation value
   459      * @return corresponding native transformation value
   387      */
   460      */
   388     private static int getNativeTransformValue(int manipulation) {
   461     private static int getNativeTransformValue(int manipulation)
       
   462     {
   389         int returnVal = 0;
   463         int returnVal = 0;
   390         switch (manipulation) {
   464         switch(manipulation)
   391             case 0:
   465         {
   392                 returnVal =  org.eclipse.swt.internal.qt.graphics.Image.TRANS_NONE;
   466         case 0:
   393                 break;
   467             returnVal =  org.eclipse.swt.internal.qt.graphics.Image.TRANS_NONE;
   394             case DirectGraphics.FLIP_HORIZONTAL:
   468             break;
   395                 returnVal =  org.eclipse.swt.internal.qt.graphics.Image.TRANS_FLIP_HORIZONTAL;
   469         case DirectGraphics.FLIP_HORIZONTAL:
   396                 break;
   470             returnVal =  org.eclipse.swt.internal.qt.graphics.Image.TRANS_FLIP_HORIZONTAL;
   397             case DirectGraphics.FLIP_VERTICAL:
   471             break;
   398                 returnVal =  org.eclipse.swt.internal.qt.graphics.Image.TRANS_FLIP_VERTICAL;
   472         case DirectGraphics.FLIP_VERTICAL:
   399                 break;
   473             returnVal =  org.eclipse.swt.internal.qt.graphics.Image.TRANS_FLIP_VERTICAL;
   400             case DirectGraphics.ROTATE_90:
   474             break;
   401                 returnVal =  org.eclipse.swt.internal.qt.graphics.Image.TRANS_ROT90;
   475         case DirectGraphics.ROTATE_90:
   402                 break;
   476             returnVal =  org.eclipse.swt.internal.qt.graphics.Image.TRANS_ROT90;
   403             case DirectGraphics.ROTATE_180:
   477             break;
   404                 returnVal =  org.eclipse.swt.internal.qt.graphics.Image.TRANS_ROT180;
   478         case DirectGraphics.ROTATE_180:
   405                 break;
   479             returnVal =  org.eclipse.swt.internal.qt.graphics.Image.TRANS_ROT180;
   406             case DirectGraphics.ROTATE_270:
   480             break;
   407                 returnVal =  org.eclipse.swt.internal.qt.graphics.Image.TRANS_ROT270;
   481         case DirectGraphics.ROTATE_270:
   408                 break;
   482             returnVal =  org.eclipse.swt.internal.qt.graphics.Image.TRANS_ROT270;
   409             default:
   483             break;
   410                 returnVal =  org.eclipse.swt.internal.qt.graphics.Image.TRANS_NONE;
   484         default:
       
   485             returnVal =  org.eclipse.swt.internal.qt.graphics.Image.TRANS_NONE;
   411         }
   486         }
   412         return returnVal;
   487         return returnVal;
   413     }
   488     }
   414 
   489 
   415     /**
   490     /**
   417      *
   492      *
   418      * @param format LCDUI format
   493      * @param format LCDUI format
   419      *
   494      *
   420      * @return corresponding native format value
   495      * @return corresponding native format value
   421      */
   496      */
   422     private static int getNativeFormatValue(int format) {
   497     private static int getNativeFormatValue(int format)
       
   498     {
   423         int returnVal = 0;
   499         int returnVal = 0;
   424         switch (format) {
   500         switch(format)
   425             case 0:
   501         {
   426                 returnVal = org.eclipse.swt.internal.qt.graphics.Image.FORMAT_IMG_NONE;
   502         case 0:
   427                 break;
   503             returnVal = org.eclipse.swt.internal.qt.graphics.Image.FORMAT_IMG_NONE;
   428             case DirectGraphics.TYPE_BYTE_1_GRAY:
   504             break;
   429                 returnVal = org.eclipse.swt.internal.qt.graphics.Image.FORMAT_IMG_MONO;
   505         case DirectGraphics.TYPE_BYTE_1_GRAY:
   430                 break;
   506             returnVal = org.eclipse.swt.internal.qt.graphics.Image.FORMAT_IMG_MONO;
   431             case DirectGraphics.TYPE_INT_8888_ARGB:
   507             break;
   432                 returnVal = org.eclipse.swt.internal.qt.graphics.Image.FORMAT_IMG_ARGB32;
   508         case DirectGraphics.TYPE_INT_8888_ARGB:
   433                 break;
   509             returnVal = org.eclipse.swt.internal.qt.graphics.Image.FORMAT_IMG_ARGB32;
   434             case DirectGraphics.TYPE_INT_888_RGB:
   510             break;
   435                 returnVal = org.eclipse.swt.internal.qt.graphics.Image.FORMAT_IMG_RGB32;
   511         case DirectGraphics.TYPE_INT_888_RGB:
   436                 break;
   512             returnVal = org.eclipse.swt.internal.qt.graphics.Image.FORMAT_IMG_RGB32;
   437             case DirectGraphics.TYPE_USHORT_4444_ARGB:
   513             break;
   438                 returnVal = org.eclipse.swt.internal.qt.graphics.Image.FORMAT_IMG_RGB4444PREMULTIPLIED;
   514         case DirectGraphics.TYPE_USHORT_4444_ARGB:
   439                 break;
   515             returnVal = org.eclipse.swt.internal.qt.graphics.Image.FORMAT_IMG_RGB4444PREMULTIPLIED;
   440             case DirectGraphics.TYPE_USHORT_444_RGB:
   516             break;
   441                 returnVal = org.eclipse.swt.internal.qt.graphics.Image.FORMAT_IMG_RGB444;
   517         case DirectGraphics.TYPE_USHORT_444_RGB:
   442                 break;
   518             returnVal = org.eclipse.swt.internal.qt.graphics.Image.FORMAT_IMG_RGB444;
   443             case DirectGraphics.TYPE_USHORT_555_RGB:
   519             break;
   444                 returnVal = org.eclipse.swt.internal.qt.graphics.Image.FORMAT_IMG_RGB555;
   520         case DirectGraphics.TYPE_USHORT_555_RGB:
   445                 break;
   521             returnVal = org.eclipse.swt.internal.qt.graphics.Image.FORMAT_IMG_RGB555;
   446             case DirectGraphics.TYPE_USHORT_565_RGB:
   522             break;
   447                 returnVal = org.eclipse.swt.internal.qt.graphics.Image.FORMAT_IMG_RGB16;
   523         case DirectGraphics.TYPE_USHORT_565_RGB:
   448                 break;
   524             returnVal = org.eclipse.swt.internal.qt.graphics.Image.FORMAT_IMG_RGB16;
   449             default:
   525             break;
   450                 break;
   526         default:
       
   527             break;
   451         }
   528         }
   452         return returnVal;
   529         return returnVal;
   453     }
   530     }
   454 
   531 
   455 }
   532 }