Пример #1
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);
    }
  }
Пример #2
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;
 }