// Example 'text'
// Tommy Grandefors
// 2D32 Graphic library
// Beta v1.0
// May 1997

#include <graphix.hh>
#include <videodef.hh>
#include <keydefs.hh> //Contains defines for the most common keyboard codes.
#include <keyboard.hh>

#include <conio.h>
#include <iostream.h>

void ScrollText(void);

Graphix myGfx; //Create the main object of this library.
Keyboard myKbd; //Use the special keyboard handler.
volatile int* kbdPtr = myKbd.InstallKeyboard(); //Set pointer to key-pressed/released vector

void main(void)
{
   if( myGfx.SetVideoMode(SVGA640x480x256) < 0)
   {
      cout << "Can't initiate SVGA video mode 640x480x256" << endl;
      return;
   }

   myGfx.Print(0,  0, "This is the default font color used.");
   myGfx.Print(0, 10, "Now we will change to font color 10");
   myGfx.SetFontColor(10);
   myGfx.Print(0, 20, "Now we are using font color 10");
   myGfx.Print(0, 30, "Ok, now we will print 10 strings with 10 different colors ranging from 80 - 90");

   int y = 40;
   for(int i = 80; i < 90; i++)
   {
      myGfx.SetFontColor(i);
      myGfx.Print(0, y, "This is a simple text string!");
      y += 10;
   }
      
   myGfx.Print(0, 160, "Note: this library will in a near future support True Type Fonts.");   

   ScrollText();

   myKbd.UnInstallKeyboard(); //Use the old keyboard handler again.

   myGfx.SetVideoMode(TEXT);
}

void ScrollText(void)
{
   int x = 0;
   int y = 300;
   int direction = -2;

   while(! ( *(kbdPtr + PRESS_ESC) ) )
   {
      myGfx.Print(x, y, "Press 'Esc' key to quit!");
      myGfx.WaitVerticalRetrace();
      myGfx.FilledBox(x, y, x + 192, y + 8, 0); //192 = 24 characters in the string * 8 pixels width of each character
      x -= direction;
      if( (x + 192) >= 640 )
	 direction = 2;
      else
	 if( x <= 0 )
	    direction = -2;
   }
}
