Fonteditor/CharViewHandler.cs
/// <summary>
/// Draws a matrix with palette indices in the given picture box
/// </summary>
Draws a matrix with palette indices in the given picture box
Draws a matrix with palette indices in the given picture box
public void DrawMatrix(Graphics graphics, byte[,] matrix, int matrixWidth, int matrixHeight, bool showBits, bool drawBoundary = false, int boundaryWidth = 0, int boundaryHeight = 0)
        {
            float w = (float)picture.Width / matrixWidth;
            float h = (float)picture.Height / matrixHeight;
            Font fontForBits = null;
            if (showBits)
            {
                fontForBits = new Font("Arial", 10);
                fontForBits = Utils.ScaleFont(graphics, fontForBits, "--0000--", new Size((int)w, (int)h));
            }
            Brush blackBrush = new SolidBrush(Color.Black);
            Brush whiteBrush = new SolidBrush(Color.White);
            Brush backGroundBrush = new SolidBrush(Constants.colors[Constants.BACKGROUND_COLOR_ID]);
            graphics.FillRectangle(backGroundBrush, 0, 0, picture.Width, picture.Height);
            for (int y = 0; y < matrixHeight; y++)
            {
                for (int x = 0; x < matrixWidth; x++)
                {
                    int colorId = matrix[x, y];
                    Brush boxBrush = new SolidBrush(Constants.colors[colorId]);
                    graphics.FillRectangle(boxBrush, (x) * w, (y) * h, w, h);
                    if (showBits)
                    {
                        String bits = Utils.ByteToString(colorId);
                        SizeF bitsSize = graphics.MeasureString(bits, fontForBits);
                        if (colorId < 8)
                        {
                            graphics.DrawString(bits, fontForBits, blackBrush, x * w + w / 2 - bitsSize.Width / 2, y * h + 2);
                        }
                        else
                        {
                            graphics.DrawString(bits, fontForBits, whiteBrush, x * w + w / 2 - bitsSize.Width / 2, y * h + 2);
                        }
                    }
                }
            }
            if (drawBoundary)
            {
                Pen penRed = new Pen(Color.Red);
                graphics.DrawRectangle(penRed, (matrixWidth - boundaryWidth) / 2 * w, (matrixHeight - boundaryHeight) / 2 * h, boundaryWidth*w , boundaryHeight*h);
            }
        }
public void DrawMatrix ( Graphics graphics , byte [ , ] matrix , int matrixWidth , int matrixHeight , bool showBits , bool drawBoundary = false , int boundaryWidth = 0 , int boundaryHeight = 0 ) { float w = ( float ) picture . Width / matrixWidth ; float h = ( float ) picture . Height / matrixHeight ; Font fontForBits = null ; if ( showBits ) { fontForBits = new Font ( " " , 10 ) ; fontForBits = Utils . ScaleFont ( graphics , fontForBits , " " , new Size ( ( int ) w , ( int ) h ) ) ; } Brush blackBrush = new SolidBrush ( Color . Black ) ; Brush whiteBrush = new SolidBrush ( Color . White ) ; Brush backGroundBrush = new SolidBrush ( Constants . colors [ Constants . BACKGROUND_COLOR_ID ] ) ; graphics . FillRectangle ( backGroundBrush , 0 , 0 , picture . Width , picture . Height ) ; for ( int y = 0 ; y < matrixHeight ; y ++ ) { for ( int x = 0 ; x < matrixWidth ; x ++ ) { int colorId = matrix [ x , y ] ; Brush boxBrush = new SolidBrush ( Constants . colors [ colorId ] ) ; graphics . FillRectangle ( boxBrush , ( x ) * w , ( y ) * h , w , h ) ; if ( showBits ) { String bits = Utils . ByteToString ( colorId ) ; SizeF bitsSize = graphics . MeasureString ( bits , fontForBits ) ; if ( colorId < 8 ) { graphics . DrawString ( bits , fontForBits , blackBrush , x * w + w / 2 - bitsSize . Width / 2 , y * h + 2 ) ; } else { graphics . DrawString ( bits , fontForBits , whiteBrush , x * w + w / 2 - bitsSize . Width / 2 , y * h + 2 ) ; } } } } if ( drawBoundary ) { Pen penRed = new Pen ( Color . Red ) ; graphics . DrawRectangle ( penRed , ( matrixWidth - boundaryWidth ) / 2 * w , ( matrixHeight - boundaryHeight ) / 2 * h , boundaryWidth * w , boundaryHeight * h ) ; } }
Draws a matrix with palette indices in the given picture box
Draws a matrix with palette indices in the given picture box
// clear // draw box // draw bits
graphics
Graphics
matrix
byte[,]
matrixWidth
int
matrixHeight
int
showBits
bool
drawBoundary
bool
boundaryWidth
int
boundaryHeight
int