/*FILE HEADER**************************************************************
 *
 *  File name		: $Id$
 *  RCS Revision Number	: $Revision: 1.1 $
 *  Last Modified	: $Date: 94/10/28 09:23:31 $
 *  CSCI name		: Real-Time Graphics System - Applications Interface
 *  CSC name		: All functions
 *  Notes:
 *      This file contains code used to debug and test the SVME-770 RTGS.
 *      This code is provided as an example of how to call the RTGS functions
 *      from a host application.
 *  History		:
 *      Created 94/01/17 by Jeff Sanderson
 *
 *END FILE HEADER*********************************************************/

#include "dy4std.h"
#include "es.h"
#include "css.h"

#include "rtgs_ai.h"
#include "video.h"
#include "colours.h"

#include "test.h"

#define NUM_TEXT_FONTS 72

void test_drawtext( void );
/*-----------------------------------------------------------------------*/

void test_drawtext( void )
{
    int      i, len;
    int      x, y, y1, y2, y3, y4;
    char     *str1;
    char     *str2;
    char     *str3;
    char     *str4;
    char     *s1 = " !#$%&'()*+,-./:;<=>?@[\]^_`{|}~";
    char     *s2 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    char     *s3 = "abcdefghijklmnopqrstuvwxyz";
    char     *s4 = "0123456789";
    point_t  *str_sz;

    init( "Draw text test" );

    len = strlen( s1 ) + 4;
    str1 = (char *)Gcc_malloc( len, 0);
    malloc_check( str1 );
    Copy_string_to_gcc( s1, str1, len );

    len = strlen( s2 ) + 4;
    str2 = (char *)Gcc_malloc( len, 0);
    malloc_check( str2 );
    Copy_string_to_gcc( s2, str2, len );

    len = strlen( s3 ) + 4;
    str3 = (char *)Gcc_malloc( len, 0);
    malloc_check( str3 );
    Copy_string_to_gcc( s3, str3, len );

    len = strlen( s4 ) + 4;
    str4 = (char *)Gcc_malloc( len, 0);
    malloc_check( str4 );
    Copy_string_to_gcc( s4, str4, len );

    str_sz = (point_t *)Gcc_malloc( sizeof( point_t ), 0);
    malloc_check( str_sz );

    x = 0x20;
    for( i = 0 ; i < NUM_TEXT_FONTS ; i++ )
    {
        Clear_screen( GRAY_2, 0, 0 );
        Set_text_font( i );
        
        Inquire_text_extent( str1, str_sz );
        Gcc_sync();
        y1 = str_sz->y;

        Inquire_text_extent( str2, str_sz );
        Gcc_sync();
        y2 = str_sz->y;

        Inquire_text_extent( str3, str_sz );
        Gcc_sync();
        y3 = str_sz->y;

        Inquire_text_extent( str4, str_sz );
        Gcc_sync();
        y4 = str_sz->y;

        y = 10;

	Printf("Calling draw text\n");
        Set_foreground_colour( WHITE );
        Set_background_colour( BLACK );
        Set_transparency_mode( OPAQUE );
        Draw_text( x, y, str1 );
        y += y1 + 8;
        Draw_text( x, y, str2 );
        y += y2 + 8;
        Draw_text( x, y, str3 );
        y += y3 + 8;
        Draw_text( x, y, str4 );
        y += y4 + 8;

        Set_transparency_mode( TRANSPARENT );
        Draw_text( x, y, str1 );
        y += y1 + 8;
        Draw_text( x, y, str2 );
        y += y2 + 8;
        Draw_text( x, y, str3 );
        y += y3 + 8;
        Draw_text( x, y, str4 );
        y += y4 + 8;

	Printf("Calling Install_font %d\n",i);
	Install_font( i );

	Printf("Calling draw text\n");
        Set_foreground_colour( CYAN );
        Set_background_colour( BLACK );
        Set_transparency_mode( OPAQUE );
        Draw_text( x, y, str1 );
        y += y1 + 8;
        Draw_text( x, y, str2 );
        y += y2 + 8;
        Draw_text( x, y, str3 );
        y += y3 + 8;
        Draw_text( x, y, str4 );
        y += y4 + 8;

        Set_transparency_mode( TRANSPARENT );
        Draw_text( x, y, str1 );
        y += y1 + 8;
        Draw_text( x, y, str2 );
        y += y2 + 8;
        Draw_text( x, y, str3 );
        y += y3 + 8;
        Draw_text( x, y, str4 );
        y += y4 + 8;

	Key_wait();
    }
}

/*-----------------------------------------------------------------------*/
