home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 64 / CDPRO64.iso / JUEGOS / java / jeditrainer / jeditrainer.jar / com / nokia / mid / ui / DirectGraphicsImplemented.class (.txt) < prev    next >
Encoding:
Java Class File  |  2003-10-02  |  5.1 KB  |  160 lines

  1. package com.nokia.mid.ui;
  2.  
  3. import javax.microedition.lcdui.Graphics;
  4. import javax.microedition.lcdui.Image;
  5.  
  6. public class DirectGraphicsImplemented implements DirectGraphics {
  7.    private Graphics my_g = null;
  8.  
  9.    protected DirectGraphicsImplemented(Graphics g) {
  10.       this.my_g = g;
  11.       g.setStrokeStyle(0);
  12.    }
  13.  
  14.    public void setARGBColor(int argbColor) {
  15.       this.my_g.setColor(argbColor);
  16.    }
  17.  
  18.    public void drawTriangle(int x1, int y1, int x2, int y2, int x3, int y3, int argbColor) {
  19.       this.my_g.setColor(argbColor);
  20.       this.my_g.drawLine(x1, y1, x2, y2);
  21.       this.my_g.drawLine(x2, y2, x3, y3);
  22.       this.my_g.drawLine(x3, y3, x1, y1);
  23.    }
  24.  
  25.    public void fillTriangle(int x1, int y1, int x2, int y2, int x3, int y3, int argbColor) {
  26.       int y_dif = y3 - y2;
  27.       int y_dif2 = Math.abs(y_dif);
  28.       int x_dif = x3 - x2;
  29.       int x_dif2 = Math.abs(x_dif);
  30.       this.my_g.setColor(argbColor);
  31.       this.my_g.drawLine(x1, y1, x2, y2);
  32.       if (x_dif2 > y_dif2) {
  33.          int y_count = y_dif;
  34.          int x_count = x2;
  35.          if (x_dif > 0) {
  36.             for(int i = 1; i < x_dif2; ++i) {
  37.                ++x_count;
  38.                this.my_g.drawLine(x1, y1, x_count, y2 + y_count / x_dif2);
  39.                y_count += y_dif;
  40.             }
  41.          } else {
  42.             for(int var18 = 1; var18 < x_dif2; ++var18) {
  43.                --x_count;
  44.                this.my_g.drawLine(x1, y1, x_count, y2 + y_count / x_dif2);
  45.                y_count += y_dif;
  46.             }
  47.          }
  48.       } else if (y_dif2 > x_dif2) {
  49.          int var22 = x_dif;
  50.          int var24 = y2;
  51.          if (y_dif > 0) {
  52.             for(int var19 = 1; var19 < y_dif2; ++var19) {
  53.                int var10003 = x2 + var22 / y_dif2;
  54.                ++var24;
  55.                this.my_g.drawLine(x1, y1, var10003, var24);
  56.                var22 += x_dif;
  57.             }
  58.          } else {
  59.             for(int var20 = 1; var20 < y_dif2; ++var20) {
  60.                int var26 = x2 + var22 / y_dif2;
  61.                --var24;
  62.                this.my_g.drawLine(x1, y1, var26, var24);
  63.                var22 += x_dif;
  64.             }
  65.          }
  66.       } else {
  67.          int var23 = x_dif;
  68.          int var25 = y_dif;
  69.  
  70.          for(int var21 = 1; var21 < x_dif2; ++var21) {
  71.             ++var23;
  72.             ++var25;
  73.             this.my_g.drawLine(x1, y1, var23, var25);
  74.          }
  75.       }
  76.  
  77.       this.my_g.drawLine(x1, y1, x3, y3);
  78.    }
  79.  
  80.    public void drawPolygon(int[] xPoints, int xOffset, int[] yPoints, int yOffset, int nPoints, int argbColor) {
  81.       this.my_g.setColor(argbColor);
  82.  
  83.       for(int i = 0; i < nPoints - 1; ++i) {
  84.          this.my_g.drawLine(xPoints[xOffset + i], yPoints[yOffset + i], xPoints[xOffset + i + 1], yPoints[yOffset + i + 1]);
  85.       }
  86.  
  87.    }
  88.  
  89.    public void fillPolygon(int[] xPoints, int xOffset, int[] yPoints, int yOffset, int nPoints, int argbColor) {
  90.       this.drawPolygon(xPoints, xOffset, yPoints, yOffset, nPoints, argbColor);
  91.    }
  92.  
  93.    public int getNativePixelFormat() {
  94.       return 888;
  95.    }
  96.  
  97.    public int getAlphaComponent() {
  98.       return 0;
  99.    }
  100.  
  101.    public void drawImage(Image img, int x, int y, int anchor, int manipulation) {
  102.       this.my_g.drawImage(img, x, y, anchor);
  103.    }
  104.  
  105.    public void drawPixels(int[] pixels, boolean transparency, int offset, int scanlength, int x, int y, int width, int height, int manipulation, int format) {
  106.       for(int i = x; i < x + width; ++i) {
  107.          for(int j = y; j < y + height; ++j) {
  108.             this.my_g.setColor(0);
  109.             this.my_g.drawLine(i, j, i, j);
  110.          }
  111.       }
  112.  
  113.    }
  114.  
  115.    public void drawPixels(short[] pixels, boolean transparency, int offset, int scanlength, int x, int y, int width, int height, int manipulation, int format) {
  116.       if (format == 4444) {
  117.          int total_offset = offset;
  118.          int x_limit = x + width;
  119.          int y_limit = y + height;
  120.  
  121.          for(int j = y; j < y_limit; ++j) {
  122.             int current_pixel_offset = total_offset;
  123.  
  124.             for(int i = x; i < x_limit; ++i) {
  125.                int current_pixel = pixels[current_pixel_offset++];
  126.  
  127.                int line_begin;
  128.                for(line_begin = i; i < x_limit - 1 && pixels[current_pixel_offset] == current_pixel; ++current_pixel_offset) {
  129.                   ++i;
  130.                }
  131.  
  132.                if ((current_pixel & '\uf000') != 0) {
  133.                   int pixel_888 = 240 & current_pixel << 4;
  134.                   pixel_888 |= '\uf000' & current_pixel << 8;
  135.                   pixel_888 |= 15728640 & current_pixel << 12;
  136.                   this.my_g.setColor(pixel_888);
  137.                   this.my_g.drawLine(line_begin, j, i, j);
  138.                }
  139.             }
  140.  
  141.             total_offset += scanlength;
  142.          }
  143.       }
  144.  
  145.    }
  146.  
  147.    public void drawPixels(byte[] pixels, byte[] transparencyMask, int offset, int scanlength, int x, int y, int width, int height, int manipulation, int format) {
  148.       this.my_g.drawLine(x, y, width, height);
  149.    }
  150.  
  151.    public void getPixels(int[] pixels, int offset, int scanlength, int x, int y, int width, int height, int format) {
  152.    }
  153.  
  154.    public void getPixels(byte[] pixels, byte[] transparencyMask, int offset, int scanlength, int x, int y, int width, int height, int format) {
  155.    }
  156.  
  157.    public void getPixels(short[] pixels, int offset, int scanlength, int x, int y, int width, int height, int format) {
  158.    }
  159. }
  160.