Class TextRenderer


  • @Deprecated
    public class TextRenderer
    extends java.lang.Object
    Deprecated.
    A game specific, fast text renderer (no memory allocs during runtime).
    Important! The text displayed must not reach the screen limits!

    It renders the text and the digits in image buffers and the display functions of this class just copies the image buffers back to the graphic context.

    The text buffer is copied first, then the configured amount of digits of the optional integer are copied next to the text with leading zeros.

    This class can be used to display game information such as scores, levels, etc.

    You can find a complete game API sample named 'Scape' in the TotalCross examples folder.
    Here is some sample code:

     import totalcross.game.*;
     import totalcross.util.props.*;
     ...
    
     public class Ping extends GameEngine {
    
       // 2 text renderers to quickly display level and score values
    
       private TextRenderer levelRenderer;
       private TextRenderer scoreRenderer;
    
     //---------------------------------------------------------
     // overload the API's game init event.
     // this function is called when the game is launched.
     //---------------------------------------------------------
    
     public void onGameInit() {
    
         // create two text renderers, one for the 'level' and one for the 'score'
         // we use the current font, the text should be black on the game background
    
         // level display has 2 digits: max value is 99
    
         levelRenderer=createTextRenderer(getFont(),Color.BLACK,"level:",2);
    
         // score display has 5 digits: max value is 99999
    
         scoreRenderer=createTextRenderer(getFont(),Color.BLACK,"score:",5);
       }
    
     //---------------------------------------------------------
     // overload TotalCross' onPaint function.
     //---------------------------------------------------------
    
     public void onPaint(Graphics gfx) {
    
       ...
       if (gameIsRunning) {  // game engine's running state
    
         ...
         // display the game level & score, both enable transparency
    
         levelRenderer.display(15,2,level,true);
         scoreRenderer.display(80,2,score,true);
         ...
       }
       ...
     }
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected int fmH
      Deprecated.
      height in pixels of the drawing (= font metrics height).
      protected int textWidth
      Deprecated.
      width in pixels of the text.
      protected boolean zeroPadding
      Deprecated.
      enable left zero padding.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected TextRenderer​(Font font, int foreColor, int backColor, java.lang.String text, int maxDigits)
      Deprecated.
      Creates a text renderer with the given parameters.
      protected TextRenderer​(Font font, int foreColor, int backColor, java.lang.String text, int maxDigits, boolean zeroPadding)
      Deprecated.
      Creates a text renderer with the given parameters.
    • Method Summary

      All Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      void display​(int x, int y, boolean transparent)
      Deprecated.
      Display a text rendering.
      void display​(int x, int y, int value)
      Deprecated.
      Display a text rendering.
      int getHeight()
      Deprecated.
      Returns the height of the current font
      int getWidth()
      Deprecated.
      Returns the maximum width of the text plus the number of digits
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • fmH

        protected int fmH
        Deprecated.
        height in pixels of the drawing (= font metrics height).
      • textWidth

        protected int textWidth
        Deprecated.
        width in pixels of the text.
      • zeroPadding

        protected boolean zeroPadding
        Deprecated.
        enable left zero padding.
    • Constructor Detail

      • TextRenderer

        protected TextRenderer​(Font font,
                               int foreColor,
                               int backColor,
                               java.lang.String text,
                               int maxDigits,
                               boolean zeroPadding)
                        throws ImageException
        Deprecated.
        Creates a text renderer with the given parameters.
        Parameters:
        font - to use
        foreColor - text foreground color
        backColor - text background color
        text - to be displayed before the digits (or null if none)
        maxDigits - the number of digits to display. E.g.: 4 means the max value shown will be 9999.
        zeroPadding - pad with leading zeros.
        Throws:
        ImageException
      • TextRenderer

        protected TextRenderer​(Font font,
                               int foreColor,
                               int backColor,
                               java.lang.String text,
                               int maxDigits)
                        throws ImageException
        Deprecated.
        Creates a text renderer with the given parameters.
        Parameters:
        font - to use
        foreColor - text foreground color
        backColor - text background color
        text - to be displayed before the digits (or null if none)
        maxDigits - the number of digits to display. E.g.: 4 means the max value shown will be 9999.
        Throws:
        ImageException
    • Method Detail

      • display

        public void display​(int x,
                            int y,
                            boolean transparent)
        Deprecated.
        Display a text rendering. This function just draws the text to the GameEngineMainWindow at the specified x,y position.
        Parameters:
        x - position.
        y - position.
        transparent - should the background be preserved.
      • display

        public void display​(int x,
                            int y,
                            int value)
        Deprecated.
        Display a text rendering. This function just copies back the image buffer of the text to the GameEngineMainWindow at the specified x,y position and displays the integer value next to the text by using pre-rendered digit image buffers.
        Parameters:
        x - position.
        y - position.
        value - positive integer value to draw next to the text.
      • getWidth

        public int getWidth()
        Deprecated.
        Returns the maximum width of the text plus the number of digits
      • getHeight

        public int getHeight()
        Deprecated.
        Returns the height of the current font