Beispiel #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);
 }
Beispiel #2
0
 public void draw(LGraphics g) {
   if (!disabled) {
     if (click && onClick) {
       g.drawImage(bitmap1, bounds.x, bounds.y);
     } else {
       g.drawImage(bitmap, bounds.x, bounds.y);
     }
   }
 }
Beispiel #3
0
  /**
   * 将LImage转化为LTextureData
   *
   * @param image
   * @return
   */
  private void create(LImage image) {
    if (image == null) {
      return;
    }
    int srcWidth = image.getWidth();
    int srcHeight = image.getHeight();

    this.hasAlpha = image.hasAlpha();

    if (GLEx.isPowerOfTwo(srcWidth) && GLEx.isPowerOfTwo(srcHeight)) {
      this.width = srcWidth;
      this.height = srcHeight;
      this.texHeight = srcHeight;
      this.texWidth = srcWidth;
      this.source = image.getByteBuffer();
      this.pixels = image.getPixels();

      if (image.isAutoDispose()) {
        image.dispose();
        image = null;
      }
      return;
    }

    int texWidth = GLEx.toPowerOfTwo(srcWidth);
    int texHeight = GLEx.toPowerOfTwo(srcHeight);

    this.width = srcWidth;
    this.height = srcHeight;
    this.texHeight = texHeight;
    this.texWidth = texWidth;

    LImage texImage = new LImage(texWidth, texHeight, hasAlpha);

    LGraphics g = texImage.getLGraphics();

    g.drawImage(image, 0, 0);

    if (this.height < texHeight - 1) {
      copyArea(texImage, g, 0, 0, width, 1, 0, texHeight - 1);
      copyArea(texImage, g, 0, height - 1, width, 1, 0, 1);
    }
    if (this.width < texWidth - 1) {
      copyArea(texImage, g, 0, 0, 1, height, texWidth - 1, 0);
      copyArea(texImage, g, width - 1, 0, 1, height, 1, 0);
    }

    this.source = texImage.getByteBuffer();
    this.pixels = texImage.getPixels();

    if (image.isAutoDispose()) {
      image.dispose();
      image = null;
    }
  }
Beispiel #4
0
 public final void paint(LGraphics g) {
   if (!running || isClose()) {
     return;
   }
   if (sleep == 0) {
     if (scrCG == null) {
       return;
     }
     if (scrCG.getBackgroundCG() != null) {
       if (shakeNumber > 0) {
         g.drawImage(
             scrCG.getBackgroundCG(),
             shakeNumber / 2 - LSystem.random.nextInt(shakeNumber),
             shakeNumber / 2 - LSystem.random.nextInt(shakeNumber));
       } else {
         g.drawImage(scrCG.getBackgroundCG(), 0, 0);
       }
     }
     int moveCount = 0;
     for (int i = 0; i < scrCG.getCharas().size(); i++) {
       Chara chara = (Chara) scrCG.getCharas().get(i);
       float value = 1.0f;
       if (chara.next()) {
         value = chara.getNextAlpha();
         moveCount++;
       }
       g.setAlpha(value);
       chara.draw(g);
       g.setAlpha(1.0F);
     }
     drawScreen(g);
     if (desktop != null) {
       desktop.createUI(g);
     }
     if (sprites != null) {
       sprites.createUI(g);
     }
   } else {
     sleep--;
     if (color != null) {
       double alpha = (double) (sleepMax - sleep) / sleepMax;
       if (alpha < 1.0) {
         if (scrCG.getBackgroundCG() != null) {
           g.drawImage(scrCG.getBackgroundCG(), 0, 0);
         }
         g.setAlpha(alpha);
         g.setColor(color);
         g.fillRect(0, 0, getCurrentWidth(), getCurrentHeight());
         g.setAlpha(1.0f);
       }
     }
     if (sleep <= 0) {
       sleep = 0;
       color = null;
     }
   }
 }
Beispiel #5
0
 public void createCustomUI(LGraphics g, int x, int y, int w, int h) {
   if (!visible) {
     return;
   }
   paintObjects(g, x, y, x + w, y + h);
   if (x == 0 && y == 0) {
     paint(g);
   } else {
     g.translate(x, y);
     paint(g);
     g.translate(-x, -y);
   }
 }
Beispiel #6
0
 /**
  * 复制指定的LImage图像区域
  *
  * @param image
  * @param g
  * @param x
  * @param y
  * @param width
  * @param height
  * @param dx
  * @param dy
  */
 public static void copyArea(
     LImage image, LGraphics g, int x, int y, int width, int height, int dx, int dy) {
   LImage tmp = image.getSubImage(x, y, width, height);
   g.drawImage(tmp, x + dx, y + dy);
   tmp.dispose();
   tmp = null;
 }
Beispiel #7
0
  /**
   * 绘制选单
   *
   * @param g
   * @param color1
   * @param color2
   */
  public void drawChoice(LGraphics g) {
    if (!visible) {
      return;
    }
    int x1 = this.getX() - 5;
    int y1 = this.getY();
    int x2 = this.getWidth() + 20;
    int y2 = this.getAllHeight() + 10;
    int w = x2 + 15;
    int h = y2 + 10;
    if (dialogImage == null) {
      dialogImage = createDefaultDialog(w, h);
    }

    Font font = g.getFont();
    try {
      g.setFont(defFont);
      // 选中项
      int i = getDrawContent();

      g.drawImage(dialogImage, x1, y1 - 5);
      if (i >= 0 && i < maxSize) {
        LGradation.getInstance(Color.white, Color.black, getWidth() + 6, getSpace())
            .drawHeight(g, x1 + 14, y1 + getSpace() * getDrawContent() + 2);
        g.setColor(Color.darkGray);
        g.drawRect(x1 + 14, y1 + getSpace() * getDrawContent() + 2, getWidth() + 6, getSpace());
      }

      int index = 0;
      // 遍历文字与颜色信息
      for (; ; ) {
        if (index >= maxSize) {
          break;
        }
        int viewIndex = index + view;
        if (viewIndex >= choice.length) {
          break;
        }
        Color nColor;
        if (colors[viewIndex] != null) {
          nColor = colors[viewIndex];
        } else {
          nColor = Color.white;
        }
        int i1 = 0;
        for (int j1 = 0; j1 < choice[viewIndex].length; j1++) {
          g.drawStyleString(
              choice[viewIndex][j1],
              posX + i1 + 14,
              posY + index * getSpace() + getHeight(),
              Color.darkGray,
              nColor);
          i1 += mesList[j1] + tab;
        }
        index++;
      }
    } finally {
      g.setFont(font);
    }
  }
Beispiel #8
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);
     }
   }
 }
Beispiel #9
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);
     }
   }
 }
Beispiel #10
0
 public void createUI(LGraphics g, int nx, int ny, int x, int y, int w, int h) {
   if (!visible) {
     return;
   }
   Color oldColor = g.getColor();
   g.translate(nx, ny);
   if (alpha > 0.1 && alpha < 1.0) {
     g.setAlpha(alpha);
     g.setColor(color);
     g.fillRect(x, y, w, h);
     g.setAlpha(1.0F);
   } else {
     g.setColor(color);
     g.fillRect(x, y, w, h);
   }
   g.translate(-nx, -ny);
   g.setColor(oldColor);
 }
Beispiel #11
0
 /**
  * 创建默认的选择器背景图片
  *
  * @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;
 }
Beispiel #12
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);
  }
Beispiel #13
0
 public void draw(LGraphics g, int x, int y, int w, int h) {
   switch (style) {
     case 0:
       Color oldColor = g.getColor();
       g.setAntiAlias(true);
       g.setColor(color);
       float alpha = 0.0f;
       int nx = x + w / 2 - (int) r * 4, ny = y + h / 2 - (int) r * 4;
       g.translate(nx, ny);
       for (Iterator it = list.iterator(); it.hasNext(); ) {
         Shape s = (Shape) it.next();
         alpha = isRunning ? alpha + 0.1f : 0.5f;
         g.setAlpha(alpha);
         g.fill(s);
       }
       g.setAntiAlias(false);
       g.setAlpha(1.0F);
       g.translate(-nx, -ny);
       g.setColor(oldColor);
       break;
     case 1:
       g.translate(x, y);
       g.setAntialiasAll(true);
       g.setColor(fill);
       g.drawRect(0, 0, width, height);
       g.setStroke(stroke);
       int sa = angle % 360;
       g.setPaint(border);
       g.drawArc(
           x + (width - paintWidth) / 2,
           y + (height - paintHeight) / 2,
           paintWidth,
           paintHeight,
           sa,
           sa + ANGLE_STEP);
       g.setAntialiasAll(false);
       g.translate(-x, -y);
       break;
   }
 }
Beispiel #14
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);
 }
Beispiel #15
0
 /**
  * 以战场元素绘制战场地图
  *
  * @param g
  * @param x
  * @param y
  * @param w
  * @param h
  */
 public void draw(LGraphics g, int x, int y, int w, int h) {
   if (!isVisible) {
     return;
   }
   switch (fieldMode) {
     case SRPGType.FIELD_NORMAL:
       x1 = x / tileWidth;
       y1 = y / tileHeight;
       x2 = x % tileWidth;
       y2 = y % tileHeight;
       int maxY =
           h / tileHeight
               + (h % tileHeight + limitHeight) / tileHeight
               + (y % tileHeight + limitHeight) / tileHeight;
       int maxX =
           w / tileWidth
               + (w % tileWidth + limitWidth) / tileWidth
               + (x % tileWidth + limitWidth) / tileWidth;
       for (int ny = 0; ny < maxY; ny++) {
         for (int nx = 0; nx < maxX; nx++) {
           posX = x1 + nx;
           posY = y1 + ny;
           if (posX < 0 || posY < 0 || posX >= width || posY >= height) {
             continue;
           }
           int index = chips[posY][posX];
           SRPGFieldElement element = battleList.getBattleElement(index);
           if (element == null) {
             continue;
           }
           g.drawImage(element.image, nx * tileWidth - x2, ny * tileHeight - y2);
         }
       }
       break;
     case SRPGType.FIELD_BIGMAP:
       g.drawImage(bigImageMap, -x, -y);
       break;
     case SRPGType.FIELD_BLEND:
       x1 = x / tileWidth;
       y1 = y / tileHeight;
       x2 = x % tileWidth;
       y2 = y % tileHeight;
       maxY =
           h / tileHeight
               + (h % tileHeight + limitHeight) / tileHeight
               + (y % tileHeight + limitHeight) / tileHeight;
       maxX =
           w / tileWidth
               + (w % tileWidth + limitWidth) / tileWidth
               + (x % tileWidth + limitWidth) / tileWidth;
       g.drawImage(bigImageMap, -x, -y);
       for (int ny = 0; ny < maxY; ny++) {
         for (int nx = 0; nx < maxX; nx++) {
           posX = x1 + nx;
           posY = y1 + ny;
           if (posX < 0 || posY < 0 || posX >= width || posY >= height) {
             continue;
           }
           int index = chips[posY][posX];
           SRPGFieldElement element = battleList.getBattleElement(index);
           if (element == null) {
             continue;
           }
           g.drawImage(element.image, nx * tileWidth - x2, ny * tileHeight - y2);
         }
       }
       break;
   }
 }
Beispiel #16
0
 public void paintObjects(LGraphics g, int minX, int minY, int maxX, int maxY) {
   if (objects == null) {
     return;
   }
   synchronized (objects) {
     int paintSeq = 0;
     boolean isListener = false;
     Iterator iter = objects.iterator();
     Actor thing = null;
     while (iter.hasNext()) {
       thing = (Actor) iter.next();
       if (!thing.isVisible()) {
         continue;
       }
       isListener = (thing.actorListener != null);
       thing.update(elapsedTime);
       if (isListener) {
         thing.actorListener.update(elapsedTime);
       }
       RectBox rect = thing.getRectBox();
       int actorX = minX + thing.getX();
       int actorY = minY + thing.getY();
       int actorWidth = rect.getWidth();
       int actorHeight = rect.getHeight();
       if (actorX + actorWidth < minX
           || actorX > maxX
           || actorY + actorHeight < minY
           || actorY > maxY) {
         continue;
       }
       LImage actorImage = thing.getImage();
       if (actorImage != null) {
         thing.setLastPaintSeqNum(paintSeq++);
         boolean isBitmapFilter = ImageFilterType.NoneFilter != thing.filterType;
         Image bitmap = actorImage.getBufferedImage();
         if (isBitmapFilter) {
           bitmap = factory.doFilter(bitmap, thing.filterType);
         }
         int rotation = thing.getRotation();
         if (thing.alpha < 1.0) {
           g.setAlpha(thing.alpha);
         }
         if (rotation != 0) {
           double halfWidth = actorImage.getWidth() / 2;
           double halfHeight = actorImage.getHeight() / 2;
           double newWidth = actorX + halfWidth;
           double newHeight = actorY + halfHeight;
           atform.setToIdentity();
           atform.scale(thing.scaleX, thing.scaleY);
           atform.translate(newWidth, newHeight);
           atform.rotate(Math.toRadians(rotation));
           atform.translate(-newWidth, -newHeight);
           atform.translate(actorX, actorY);
           g.drawImage(bitmap, atform);
         } else {
           int width = (int) (actorImage.getWidth() * thing.scaleX);
           int height = (int) (actorImage.getHeight() * thing.scaleY);
           g.drawImage(bitmap, actorX, actorY, width, height);
         }
         if (isBitmapFilter) {
           bitmap.flush();
           bitmap = null;
         }
         if (thing.alpha < 1.0) {
           g.setAlpha(1.0F);
         }
       }
       if (actorX == 0 && actorY == 0) {
         thing.draw(g);
         if (isListener) {
           thing.actorListener.draw(g);
         }
       } else {
         g.translate(actorX, actorY);
         thing.draw(g);
         if (isListener) {
           thing.actorListener.draw(g);
         }
         g.translate(-actorX, -actorY);
       }
     }
   }
 }