コード例 #1
0
  public int getVWidth() {
    // g.setColor(0);
    if (width > 0) return width; // cached

    int w = 0;
    int imgWidth = imgWidth();

    for (int index = 0; index < elementCount; index++) {
      Object ob = elementData[index];
      if (ob != null) {

        if (ob instanceof String) {
          // string element
          w += font.stringWidth((String) ob);
        } else if ((ob instanceof Integer) && imageList != null) {
          // image element or color
          int i = (((Integer) ob).intValue());
          switch (i & 0xff000000) {
            case IMAGE:
              w += imgWidth;
              break;
          }
        } // Integer
      } // if ob!=null
    } // for
    return width = w;
  }
コード例 #2
0
ファイル: TrackTile.java プロジェクト: keyeMyria/bbTracker
  protected void doPaintAxis(final Graphics g) {
    if (scaleSizeInPixel == 0 || mapBackground != null) {
      return;
    }

    final Font font = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_SMALL);
    g.setFont(font);
    g.setColor(0x00000000);

    final int textBottom = height - 4 - SCALE_HEIGTH;
    int left = 0;
    for (int i = 0; i < scaleConfiguration.labelLocation.length; i++) {
      final float location = scaleConfiguration.labelLocation[i];
      final float value = scaleConfiguration.labelValue[i];
      String label = Utils.floatToString(value, true);
      if (location == 0) {
        left = (font.stringWidth(label) / 2) + 2;
      } else if (location == 1) {
        label += " " + scaleConfiguration.unit;
      }
      g.drawString(
          label,
          left + (int) (scaleSizeInPixel * location),
          textBottom,
          Graphics.BOTTOM | Graphics.HCENTER);
    }
    g.drawRect(left, height - 2 - SCALE_HEIGTH, scaleSizeInPixel, SCALE_HEIGTH);
    g.fillRect(left, height - 2 - SCALE_HEIGTH, scaleSizeInPixel / 2, SCALE_HEIGTH);
  }
コード例 #3
0
ファイル: DateTimeRow.java プロジェクト: naveen/j2me-hacking
  public void validate() {
    int w = getWidth();
    int h = (FireScreen.defaultTickerFont.getHeight()) + (2 * PADTOP);
    if (label != null) {
      label.format(w, false);
      h += label.getHeight() + PADTOP;
    }
    if (h < getMinHeight()) h = getMinHeight();
    setHeight(h);

    Font f = FireScreen.defaultTickerFont;

    dayWidth = f.stringWidth("33") + 2;
    monthWidth = f.stringWidth("22") + 2;
    yearWidth = f.stringWidth("20088") + 2;
    hourWidth = f.stringWidth("44") + 2;
    minuteWidth = f.stringWidth("66") + 2;
    pointer = DAY;
  }
コード例 #4
0
 private void showStartChoice(Graphics g) {
   g.drawImage(Resource.loadImage(Resource.PIC_ID_CHOICE_BG), 0, 0, 0);
   choiceCursor.show(
       g,
       Resource.POS_SEIGNEUR_CHOICE[choiceIndex][0],
       Resource.POS_SEIGNEUR_CHOICE[choiceIndex][1]);
   String info =
       Resource.STR_SEIGNEUR_NAME[choiceIndex]
           + "  城池X"
           + Resource.NUM_SEIGNEUR_CITYS[choiceIndex]
           + "  武将X"
           + Resource.NUM_SEIGNEUR_GENERALS[choiceIndex];
   g.setColor(0XFFFFFF);
   Font font = g.getFont();
   g.drawString(info, (engine.getScreenWidth() - font.stringWidth(info)) >> 1, 456, 0);
 }
コード例 #5
0
ファイル: AboutScreen.java プロジェクト: raghulj/btis
  /**
   * Takes an array of messages and a 'Screen-width' and returns the same messages, but any string
   * in that that is wider than 'width' will be split up into 2 or more Strings that will fit on the
   * screen 'Spliting' up a String is done on the basis of Words, so if a single WORD is longer than
   * 'width' it will be on a Line on it's own, but that line WILL be WIDER than 'width'
   *
   * @param message
   * @param width the maximum width a string may be before being split up.
   * @return
   */
  private String[] formatMessage(String[] message, int width) {
    Vector result = new Vector(message.length);
    for (int i = 0; i < message.length; i++) {
      if (DEFAULT_SIMPLE_FONT.stringWidth(message[i]) <= width) {
        result.addElement(message[i]);
      } else {
        String[] splitUp =
            StringUtil.chopStrings(message[i], " ", AboutScreen.DEFAULT_SIMPLE_FONT, width);
        for (int j = 0; j < splitUp.length; j++) {
          result.addElement(splitUp[j]);
        }
      }
    }

    String[] finalResult = new String[result.size()];
    for (int i = 0; i < finalResult.length; i++) {
      finalResult[i] = (String) result.elementAt(i);
    }
    return finalResult;
  }
コード例 #6
0
  private void showRank(Graphics g) {

    Image title = Resource.loadImage(Resource.PIC_ID_RANK_TITLE);
    Image item = Resource.loadImage(Resource.PIC_ID_RANK_ITEM);
    Image foot = Resource.loadImage(Resource.PIC_ID_RANK_FOOT);

    int titleX = (engine.getScreenWidth() - title.getWidth()) >> 1;
    int titleY = 30;
    g.drawImage(title, titleX, titleY, 20);

    Font font = g.getFont();
    int itemX = titleX + ((title.getWidth() - item.getWidth()) >> 1);
    int itemY = titleY + title.getHeight();
    int deltaH = (item.getHeight() - font.getHeight()) >> 1;
    int sx = 0, sy = 0;
    String ss = null;
    int rankX = 43 - 20, idX = 43 + 80, scoresX = 188 + 50, seiX = 309 + 30, timeX = 467 + 10;
    for (int i = 0; i < 11; ++i) {
      g.drawImage(item, itemX, itemY, 20);
      sy = itemY + deltaH;
      itemY += item.getHeight();
      if (i == 0) {
        /*显示表头*/
        rankX += itemX;
        idX += itemX;
        scoresX += itemX;
        seiX += itemX;
        timeX += itemX;

        g.setColor(165, 173, 64);
        g.drawString("游戏排名", rankX, sy, 20);
        g.drawString("用户ID", idX, sy, 20);
        g.drawString("积分", scoresX, sy, 20);
        g.drawString("所用主公", seiX, sy, 20);
        g.drawString("统一时间", timeX, sy, 20);

        /*计算表数据坐标*/
        rankX += font.stringWidth("游戏") - 2;
        idX += ((font.stringWidth("用户ID") - font.stringWidth("0234**98")) >> 1);
        scoresX += ((font.stringWidth("积分") - font.stringWidth("34567")) >> 1);
        seiX += ((font.stringWidth("所用主公") - font.stringWidth("曹操")) >> 1);
        timeX += ((font.stringWidth("统一时间") - font.stringWidth("2012-03-24 23:58")) >> 1);
      } else {
        if (rankingList != null) {
          if (i <= rankingList.length) {
            g.setColor(0XFFFF00);
            g.drawString(Integer.toString(rankingList[i - 1].getRanking()), rankX, sy, 20);
            g.setColor(0XFFFFFF);
            String userId = rankingList[i - 1].getUserId();
            int userIdLen = userId.length();
            g.drawString(
                userId.substring(0, 4) + "**" + userId.substring(userIdLen - 2), idX, sy, 20);
            g.drawString(Integer.toString(rankingList[i - 1].getScores()), scoresX, sy, 20);
            String remark = rankingList[i - 1].getRemark();
            g.drawString(remark.substring(0, remark.indexOf(";")), seiX, sy, 20);
            String time = rankingList[i - 1].getTime();
            g.drawString(time.substring(0, time.length() - 3), timeX, sy, 20);
          }
        }
      }
    }

    int footX = titleX + ((title.getWidth() - foot.getWidth()) >> 1);
    int footY = itemY;
    g.drawImage(foot, footX, footY, 20);
    g.setColor(0XFFFF00);
    if (attainment != null) {
      ss = Integer.toString(attainment.getRanking());
    } else {
      ss = "榜上无名";
    }
    sx = footX + 175 + ((98 - font.stringWidth(ss)) >> 1);
    sy = footY + 9 + ((33 - font.getHeight()) >> 1);
    g.drawString(ss, sx, sy, 20);

    sx = footX + 508;
    sy = footY + 6;
    DrawUtil.drawRect(g, sx, sy, 89, 39, 3);
  }
コード例 #7
0
  public void drawItem(Graphics g, int offset, boolean selected, boolean drawsec) {
    // g.setColor(0);
    boolean ralign = false;
    boolean underline = false;

    // #if NICK_COLORS
    // # 	boolean nick=false;
    // #endif

    int w = offset;
    int dw;
    int imageYOfs = ((getVHeight() - imgHeight()) >> 1);
    // #if ALCATEL_FONT
    // #         int fontYOfs=(( getVHeight()-font.getHeight() )>>1) +1;
    // #else
    int fontYOfs = ((getVHeight() - font.getHeight()) >> 1);
    // #endif
    int imgWidth = imgWidth();

    g.setFont(font);
    for (int index = 0; index < elementCount; index++) {
      Object ob = elementData[index];
      if (ob != null) {

        if (ob instanceof String) {
          // string element
          String s = (String) ob;
          // #if NICK_COLORS
          // #                     if (nick) {
          // #                         int color=g.getColor();
          // #                         dw=0;
          // #                         int p1=0;
          // #                         while (p1<s.length()) {
          // #                             int p2=p1;
          // #                             char c1=s.charAt(p1);
          // #                             //processing the same cp
          // #                             while (p2<s.length()) {
          // #                                 char c2=s.charAt(p2);
          // #                                 if ( (c1&0xff00) != (c2 &0xff00) ) break;
          // #                                 p2++;
          // #                             }
          // #                             g.setColor( (c1>255) ? ColorScheme.strong(color) :
          // color);
          // #                             dw=font.substringWidth(s, p1, p2-p1);
          // #                             if (ralign) w-=dw;
          // #                             g.drawSubstring( s, p1, p2-p1,
          // #                                     w,fontYOfs,Graphics.LEFT|Graphics.TOP);
          // #                             if (!ralign) w+=dw;
          // #                             p1=p2;
          // #                         }
          // #
          // #                         g.setColor(color);
          // #                     } else {
          // #endif
          dw = font.stringWidth(s);
          if (ralign) w -= dw;
          g.drawString(s, w, fontYOfs, Graphics.LEFT | Graphics.TOP);
          if (underline) {
            int y = getVHeight() - 1;
            g.drawLine(w, y, w + dw, y);
            underline = false;
          }
          if (!ralign) w += dw;
          // #if NICK_COLORS
          // #                     }
          // #endif

        } else if ((ob instanceof Integer)) {
          // image element or color
          int i = ((Integer) ob).intValue();
          switch (i & 0xff000000) {
            case IMAGE:
              if (imageList == null) break;
              if (ralign) w -= imgWidth;
              imageList.drawImage(g, ((Integer) ob).intValue(), w, imageYOfs);
              if (!ralign) w += imgWidth;
              break;
            case COLOR:
              g.setColor(0xFFFFFF & i);
              break;
            case RALIGN:
              ralign = true;
              w = g.getClipWidth() - 1;
              break;
            case UNDERLINE:
              underline = true;
              break;
              // #if NICK_COLORS
              // #                         case NICK_ON:
              // #                             nick=true;
              // #                             break;
              // #                         case NICK_OFF:
              // #                             nick=false;
              // #                             break;
              // #endif
          }
        } /* Integer*/ else if (ob instanceof VirtualElement) {
          int clipw = g.getClipWidth();
          int cliph = g.getClipHeight();
          ((VirtualElement) ob).drawItem(g, 0, false, false);
          g.setClip(g.getTranslateX(), g.getTranslateY(), clipw, cliph);
          // TODO: рисование не с нулевой позиции и вычисление ширины
        }
      } // if ob!=null
    } // for
  }