GPainter Extensions

Guys,

I made some extensions to the GPainter class for the 3.6" BW 128x64 screen.
If someone wants to add to this, just post a msg with your extension method.

Feel free to use in any way you like.

Gus, shall I add this to code.tinyclr.com ?

Usage:


GPainterExtensions paint = new GPainterExtensions();

paint.PrintCentered(0, 30, "Fez Rules"));

Class GPainterExtensions


using System;
using Microsoft.SPOT;

namespace GHIElectronics.Graphics.Simple128x64
{
  class GPainterExtensions : GHIElectronics.Graphics.Simple128x64.GPainter
  {
    /// <summary>
    /// Clears the text that was previously printed with print.
    /// </summary>
    /// <param name="x"></param>
    /// <param name="y"></param>
    /// <param name="str">Same string as print</param>
    public void PrintClear(int x, int y, string str)
    {
      for (int i = 0; i < str.Length; i++)
      {
        Print(x + i * 6, y, ' ');
      }
    }
    
    /// <summary>
    /// Centers the text on the screen to print
    /// </summary>
    /// <param name="x">Not used</param>
    /// <param name="y"></param>
    /// <param name="str"></param>
    public void PrintCentered(int x, int y, string str)
    {
      for (int i = 0; i < str.Length; i++)
      {
        Print(64 - (str.Length * 6) + ((str.Length * 6) / 2) + (i * 6), y, str[i]);
      }
    }

    /// <summary>
    /// Clears the previously printed centered text
    /// </summary>
    /// <param name="x">Not used</param>
    /// <param name="y"></param>
    /// <param name="str"></param>
    public void PrintCenteredClear(int x, int y, string str)
    {
      for (int i = 0; i < str.Length; i++)
      {
        Print(64 - (str.Length * 6) + ((str.Length * 6) / 2) + (i * 6), y, str[i]);
      }
    }

    /// <summary>
    /// Prints right aligned (so x is the sting's end position)
    /// </summary>
    /// <param name="x"></param>
    /// <param name="y"></param>
    /// <param name="str"></param>
    public void PrintRightAligned(int x, int y, string str)
    {
      for (int i = 0; i < str.Length; i++)
      {
        Print(x - (((str.Length) * 6) - (i * 6)), y, str[i]);
      }
    }

    /// <summary>
    /// Clears the previously right aligned text
    /// </summary>
    /// <param name="x"></param>
    /// <param name="y"></param>
    /// <param name="str"></param>
    public void PrintRightAlignedClear(int x, int y, string str)
    {
      for (int i = 0; i < str.Length; i++)
      {
        Print(x - (((str.Length) * 6) - (i * 6)), y, ' ');
      }
    }

    /// <summary>
    /// Print small right aligned (so x is the string's end position)
    /// </summary>
    /// <param name="x"></param>
    /// <param name="y"></param>
    /// <param name="str"></param>
    public void PrintSmallRightAligned(int x, int y, string str)
    {
      for (int i = 0; i < str.Length; i++)
      {
        PrintSmall(x - (((str.Length) * 4) - (i * 4)), y, str[i]);
      }
    }

    /// <summary>
    /// Clears the previously right aligned text
    /// </summary>
    /// <param name="x"></param>
    /// <param name="y"></param>
    /// <param name="str"></param>
    public void PrintSmallRightAlignedClear(int x, int y, string str)
    {
      for (int i = 0; i < str.Length; i++)
      {
        PrintSmall(x - (((str.Length) * 4) - (i * 4)), y, ' ');
      }
    }

  }
}

Nice work!

I am sure Gus wouldn’t mind. :wink:

Yes add it please.

Luckily I have added the 128*64 screen to my robot. Good work Eric ;D

Code added to code share: [url]http://code.tinyclr.com/project/311/gpainter-extensions-for-the-bw-36-128x64-display/[/url]

Greetings