Exemple #1
0
 public void setField2DBackground(Field2D field, HashMap pathMap, String fileName) {
   setField2D(field);
   LImage background = null;
   if (fileName != null) {
     setTileBackground(fileName);
     background = getBackground();
   } else {
     background = LImage.createImage(getWidth(), getHeight(), false);
   }
   LGraphics g = background.getLGraphics();
   for (int i = 0; i < field.getWidth(); i++) {
     for (int j = 0; j < field.getHeight(); j++) {
       int index = field.getType(j, i);
       Object o = pathMap.get(new Integer(index));
       if (o != null) {
         if (o instanceof LImage) {
           g.drawImage(
               ((LImage) o).getBufferedImage(),
               field.tilesToWidthPixels(i),
               field.tilesToHeightPixels(j),
               null);
         } else if (o instanceof Actor) {
           addObject(((Actor) o), field.tilesToWidthPixels(i), field.tilesToHeightPixels(j));
         }
       }
     }
   }
   g.dispose();
   setBackground(background);
 }
Exemple #2
0
 public synchronized void drawWidth(LGraphics g, int x, int y) {
   try {
     if (drawWidth == null) {
       drawWidth = new LImage(width, height, true);
       LGraphics gl = drawWidth.getLGraphics();
       for (int i = 0; i < width; i++) {
         gl.setColor(
             new Color(
                 (start.getRed() * (width - i)) / width + (end.getRed() * i) / width,
                 (start.getGreen() * (width - i)) / width + (end.getGreen() * i) / width,
                 (start.getBlue() * (width - i)) / width + (end.getBlue() * i) / width,
                 alpha));
         gl.drawLine(i, 0, i, height);
       }
       gl.dispose();
       gl = null;
     }
     g.drawImage(drawWidth, x, y);
   } catch (Exception e) {
     for (int i = 0; i < width; i++) {
       g.setColor(
           new Color(
               (start.getRed() * (width - i)) / width + (end.getRed() * i) / width,
               (start.getGreen() * (width - i)) / width + (end.getGreen() * i) / width,
               (start.getBlue() * (width - i)) / width + (end.getBlue() * i) / width,
               alpha));
       g.drawLine(i + x, y, i + x, y + height);
     }
   }
 }
Exemple #3
0
 public synchronized void drawHeight(LGraphics g, int x, int y) {
   try {
     if (drawHeight == null) {
       drawHeight = new LImage(width, height, true);
       LGraphics gl = drawHeight.getLGraphics();
       for (int i = 0; i < height; i++) {
         gl.setColor(
             new Color(
                 (start.getRed() * (height - i)) / height + (end.getRed() * i) / height,
                 (start.getGreen() * (height - i)) / height + (end.getGreen() * i) / height,
                 (start.getBlue() * (height - i)) / height + (end.getBlue() * i) / height,
                 alpha));
         gl.drawLine(0, i, width, i);
       }
       gl.dispose();
       gl = null;
     }
     g.drawImage(drawHeight, x, y);
   } catch (Exception e) {
     for (int i = 0; i < height; i++) {
       g.setColor(
           new Color(
               (start.getRed() * (height - i)) / height + (end.getRed() * i) / height,
               (start.getGreen() * (height - i)) / height + (end.getGreen() * i) / height,
               (start.getBlue() * (height - i)) / height + (end.getBlue() * i) / height,
               alpha));
       g.drawLine(x, i + y, x + width, i + y);
     }
   }
 }
 /**
  * 创建默认的选择器背景图片
  *
  * @param w
  * @param h
  * @return
  */
 private LImage createDefaultDialog(int w, int h) {
   if (lazyDialog == null) {
     lazyDialog = new HashMap<String, LImage>(10);
   }
   int hash = 1;
   hash = LSystem.unite(hash, w);
   hash = LSystem.unite(hash, h);
   String key = String.valueOf(hash);
   LImage o = (LImage) lazyDialog.get(key);
   if (o == null) {
     o = LImage.createImage(w, h, true);
     LGraphics g = o.getLGraphics();
     LGradation.getInstance(Color.white, Color.black, w, h).drawHeight(g, 0, 0);
     g.setColor(Color.black);
     g.drawRect(0, 0, w - 1, h - 1);
     g.dispose();
     lazyDialog.put(key, o);
   }
   return o;
 }
Exemple #5
0
  public void setTileBackground(LImage image) {
    if (image == null) {
      return;
    }

    int layerWidth = getWidth();
    int layerHeight = getHeight();
    int tileWidth = image.getWidth();
    int tileHeight = image.getHeight();

    LImage background = LImage.createImage(layerWidth, layerHeight, false);
    LGraphics g = background.getLGraphics();
    for (int x = 0; x < layerWidth; x += tileWidth) {
      for (int y = 0; y < layerHeight; y += tileHeight) {
        g.drawImage(image, x, y);
      }
    }
    g.dispose();

    setBackground(background);
  }
Exemple #6
0
 protected void setPixels() {
   int[] dest = image.getPixels();
   if (lastDispose > 0) {
     if (lastDispose == 3) {
       int n = frameCount - 2;
       if (n > 0) {
         lastImage = getFrame(n - 1);
       } else {
         lastImage = null;
       }
     }
     if (lastImage != null) {
       int[] prev = lastImage.getPixels();
       image.setPixels(prev, width, height);
       if (lastDispose == 2) {
         LGraphics g = image.getLGraphics();
         Color c = null;
         if (transparency) {
           c = new Color(0, 0, 0, 0);
         } else {
           c = new Color(lastBgColor);
         }
         g.setColor(c);
         g.fill(lastRect);
         g.dispose();
       }
     }
   }
   int pass = 1;
   int inc = 8;
   int iline = 0;
   for (int i = 0; i < ih; i++) {
     int line = i;
     if (interlace) {
       if (iline >= ih) {
         pass++;
         switch (pass) {
           case 2:
             iline = 4;
             break;
           case 3:
             iline = 2;
             inc = 4;
             break;
           case 4:
             iline = 1;
             inc = 2;
         }
       }
       line = iline;
       iline += inc;
     }
     line += iy;
     if (line < height) {
       int k = line * width;
       int dx = k + ix;
       int dlim = dx + iw;
       if ((k + width) < dlim) {
         dlim = k + width;
       }
       int sx = i * iw;
       while (dx < dlim) {
         int index = ((int) pixels[sx++]) & 0xff;
         int c = act[index];
         if (c != 0) {
           dest[dx] = c;
         }
         dx++;
       }
     }
   }
   image.setPixels(dest, width, height);
 }