Package pu.web.client.gui

Source Code of pu.web.client.gui.Label

package pu.web.client.gui;

import pu.web.client.PUWeb;
import pu.web.client.PU_Font;
import pu.web.client.PU_Rect;

public class Label extends TextElement
{
  private String mText = "";

  public Label(int x, int y, String text)
  {
    super(x, y, 0, 0);
   
    mText = text;
    setFont(PUWeb.gui().getDefaultFont());
  }
 
  public String getText()
  {
    return mText;
  }
 
  public void setText(String text)
  {
    mText = text;
    updateSize();
  }
 
  @Override
  public void setFont(PU_Font font)
  {
    super.setFont(font);
    updateSize();
  }

  public void updateSize()
  {
    int width = 0;
    int height = 0;
    PU_Font font = getFont();
    if(font != null)
    {
      width = font.getStringWidth(mText);
      height = font.getLineHeight()+2;
    }
   
    getRect().width = width;
    getRect().height = height;
  }
 
  @Override
  public void draw(PU_Rect drawArea)
  {
    PU_Rect realRect = new PU_Rect(getRect().x + drawArea.x, getRect().y + drawArea.y, getRect().width, getRect().height);
    PU_Rect inRect = drawArea.intersection(realRect);
   
    PU_Font font = getFont();
    if(font != null)
    {
      font.setColor(getFontColor().r, getFontColor().g, getFontColor().b);
      font.drawTextInRect(mText, drawArea.x + getRect().x, drawArea.y + getRect().y, inRect);
   
  }
}
TOP

Related Classes of pu.web.client.gui.Label

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.