コード例 #1
0
ファイル: ConfigList.java プロジェクト: typosone/CraftGuide
  static String[] layoutText(String text, int width) {
    if (width < 64) {
      width = 64; // Arbitrary minimum width, to prevent excessive wrapping. Space for at least 4
      // characters.
    }

    FontRenderer fr = Minecraft.getMinecraft().fontRenderer;
    List<String> lines = fr.listFormattedStringToWidth(text, width);

    return lines.toArray(new String[lines.size()]);
  }
コード例 #2
0
  @SideOnly(Side.CLIENT)
  private KnowledgeObject<?> getHoveredObject(
      FontRenderer fontRenderer, int mouseX, int mouseY, int x, int y) {
    if (!(mouseX >= x
        && mouseX <= x + CompendiumPageHandler.innerWidth
        && mouseY >= y
        && parsed.contains(linkColor))) return null;

    boolean origFont = fontRenderer.getUnicodeFlag();
    fontRenderer.setUnicodeFlag(true);

    List<String> list =
        fontRenderer.listFormattedStringToWidth(parsed, CompendiumPageHandler.innerWidth);

    if (mouseY <= y + list.size() * fontRenderer.FONT_HEIGHT) {
      boolean multiLine = false;
      int count = -1, index, prevIndex;
      String lineStr;

      for (int line = 0; line < list.size(); line++) {
        lineStr = list.get(line);
        prevIndex = -1;

        while ((index = lineStr.indexOf(linkColor, ++prevIndex)) != -1) {
          prevIndex = index;

          if (multiLine) multiLine = false;
          else ++count;

          int startX = x + fontRenderer.getStringWidth(lineStr.substring(0, prevIndex = index));

          if ((index = lineStr.indexOf(EnumChatFormatting.BLACK.toString(), index)) == -1) {
            index = lineStr.length();
            multiLine = true;
          }

          if (mouseY >= y + line * fontRenderer.FONT_HEIGHT
              && mouseY <= y + (line + 1) * fontRenderer.FONT_HEIGHT
              && mouseX >= startX
              && mouseX
                  <= startX + fontRenderer.getStringWidth(lineStr.substring(prevIndex, index))) {
            fontRenderer.setUnicodeFlag(origFont);
            return count < parsedObjects.size() ? parsedObjects.get(count) : null;
          }
        }
      }
    }

    fontRenderer.setUnicodeFlag(origFont);
    return null;
  }
コード例 #3
0
  public static int getSplitStringHeight(FontRenderer fontRenderer, String input, int width) {

    @SuppressWarnings("rawtypes")
    List stringRows = fontRenderer.listFormattedStringToWidth(input, width);
    return stringRows.size() * fontRenderer.FONT_HEIGHT;
  }