First commit 25/07/1999
This commit is contained in:
253
LetreroDigital/LetreroDigital.cpp
Normal file
253
LetreroDigital/LetreroDigital.cpp
Normal file
@ -0,0 +1,253 @@
|
||||
//---------------------------------------------------------------------------
|
||||
#include <fstream.h>
|
||||
#include <vcl.h>
|
||||
#pragma hdrstop
|
||||
|
||||
#include "LetreroDigital.h"
|
||||
|
||||
#pragma package(smart_init)
|
||||
//---------------------------------------------------------------------------
|
||||
// ValidCtrCheck is used to assure that the components created do not have
|
||||
// any pure virtual functions.
|
||||
//
|
||||
|
||||
static inline TLetreroDigital *ValidCtrCheck()
|
||||
{
|
||||
return new TLetreroDigital(NULL);
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
__fastcall TLetreroDigital::TLetreroDigital(TComponent* Owner)
|
||||
: TGraphicControl(Owner)
|
||||
{
|
||||
Width = 96; // Establecemos valores por defecto
|
||||
Height = 32;
|
||||
BorderStyle = bsSingle;
|
||||
TAMx = 8;
|
||||
TAMy = 16;
|
||||
AX = 2;
|
||||
AY = 2;
|
||||
cLED_ON =clBlack;
|
||||
cLED_OFF=clYellow;
|
||||
|
||||
FCadena = "JD Soft.";
|
||||
// Obtenemos la longitud de la frase. ( En d<>gitos )
|
||||
Flen = FCadena.Length();
|
||||
|
||||
// Asignamos memoria para las fuentes RAW
|
||||
ptr_char = new char[4096];
|
||||
// SetFont( "ASCii.FNT" );
|
||||
|
||||
FBrush = new TBrush;
|
||||
FBrush -> Color = clRed;
|
||||
FBrush -> OnChange = CambioAtributo;
|
||||
|
||||
// Creamos un timer y lo asignamos a DibujaLD(); si ActivarLD = true;
|
||||
FPulsoReloj = new TTimer( this );
|
||||
FPulsoReloj->OnTimer = OnTimerHandler;
|
||||
FPulsoReloj->Interval = 100;
|
||||
FPulsoReloj->Enabled = true;
|
||||
FFrecReloj = 100;
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
void __fastcall TLetreroDigital::OnTimerHandler(TObject *Sender)
|
||||
{
|
||||
DibujaLD( false );
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
__fastcall TLetreroDigital::~TLetreroDigital()
|
||||
{
|
||||
delete FBrush;
|
||||
delete [] ptr_char;
|
||||
delete FPulsoReloj;
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
namespace Letrerodigital
|
||||
{
|
||||
void __fastcall PACKAGE Register()
|
||||
{
|
||||
TComponentClass classes[1] = {__classid(TLetreroDigital)};
|
||||
RegisterComponents("JD Soft.", classes, 0);
|
||||
}
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
void __fastcall TLetreroDigital::SetTAM( int NuevoTAMx, int NuevoTAMy )
|
||||
{
|
||||
TAMx = NuevoTAMx;
|
||||
TAMy = NuevoTAMy;
|
||||
if ( TAMx == 0 ) TAMx = 8;
|
||||
if ( TAMy == 0 ) TAMy = 16;
|
||||
Invalidate(); // y volver a dibujar el componente
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
void __fastcall TLetreroDigital::SetFrecReloj( int NuevoReloj )
|
||||
{
|
||||
if ( NuevoReloj <= 0 ) NuevoReloj = 100;
|
||||
FFrecReloj = NuevoReloj;
|
||||
FPulsoReloj -> Interval = FFrecReloj;
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
void __fastcall TLetreroDigital::SetTAMg( TFPitchFnt Index )
|
||||
{
|
||||
FPitchFnt = Index;
|
||||
switch ( Index )
|
||||
{
|
||||
case 3:
|
||||
TAMx = 8;
|
||||
TAMy = 8;
|
||||
break;
|
||||
case 2:
|
||||
TAMx = 8;
|
||||
TAMy = 16;
|
||||
break;
|
||||
case 1:
|
||||
TAMx = 16;
|
||||
TAMy = 8;
|
||||
break;
|
||||
case 0:
|
||||
TAMx = 16;
|
||||
TAMy = 16;
|
||||
break;
|
||||
default:
|
||||
TAMx = 8;
|
||||
TAMy = 16;
|
||||
}
|
||||
Height = AY * TAMy;
|
||||
Invalidate();
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
void __fastcall TLetreroDigital::SetCadena( AnsiString NuevaCadena )
|
||||
{
|
||||
FCadena = NuevaCadena;
|
||||
// Obtenemos la longitud de la frase. ( En d<>gitos )
|
||||
Flen = FCadena.Length();
|
||||
Invalidate();
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
// Este procedimiento es llamado cada vez que se modifica
|
||||
// la brocha, el l<>piz o el tipo de letra
|
||||
void __fastcall TLetreroDigital::CambioAtributo( TObject * Sender )
|
||||
{
|
||||
Invalidate(); // tras lo cual habr<62> que redibujar el componente
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
void __fastcall TLetreroDigital::SetBrush( TBrush * NuevoValor )
|
||||
{
|
||||
FBrush -> Assign( NuevoValor );
|
||||
Invalidate(); // y volver a dibujar el componente
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
void __fastcall TLetreroDigital::SetLED_Color( TColor NuevoValorON, TColor NuevoValorOFF )
|
||||
{
|
||||
cLED_ON = ( NuevoValorON );
|
||||
cLED_OFF = ( NuevoValorOFF );
|
||||
Invalidate(); // y volver a dibujar el componente
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
void __fastcall TLetreroDigital::SetFont( AnsiString NuevoValor )
|
||||
{
|
||||
fstream fich;
|
||||
|
||||
FFuente = NuevoValor;
|
||||
|
||||
fich.open( FFuente.c_str(), ios::in | ios::binary );
|
||||
|
||||
if ( !fich )
|
||||
{
|
||||
ShowMessage( "Fallo en la apertura\nFuentes RAW no encontradas" );
|
||||
} else {
|
||||
fich.read( ptr_char, 4096 );
|
||||
fich.close();
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
void __fastcall TLetreroDigital::SetAx( int NuevoValor )
|
||||
{
|
||||
AX = NuevoValor;
|
||||
Invalidate();
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
void __fastcall TLetreroDigital::SetAy( int NuevoValor )
|
||||
{
|
||||
AY = NuevoValor;
|
||||
Height = AY * TAMy;
|
||||
Invalidate();
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
void __fastcall TLetreroDigital::Paint()
|
||||
{
|
||||
TRect Area;
|
||||
|
||||
// Preparamos un RECT definiendo el <20>rea ocupada por el componente.
|
||||
Area = GetClientRect();
|
||||
|
||||
|
||||
// Dibujar en el Canvas del componente
|
||||
|
||||
// Establecer la brocha, l<>piz y tipo de letra a usar
|
||||
Canvas -> Brush = FBrush;
|
||||
|
||||
// Rellenamos el <20>rea con la trama y color seleccionados
|
||||
Canvas -> FillRect( Area );
|
||||
|
||||
FPulsoReloj->Enabled = false;
|
||||
DibujaLD( true );
|
||||
FPulsoReloj->Enabled = true;
|
||||
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
void __fastcall TLetreroDigital::DibujaLD( bool RESET )
|
||||
{
|
||||
int i, j, k; // Variables de avance
|
||||
TColor c_elec; // Color en el momento de imprimir
|
||||
int PosX, PosY; // Posicion fisica final
|
||||
char LCaract; // Caracter de linea a tratar
|
||||
char *Frase;
|
||||
|
||||
Frase = FCadena.c_str();
|
||||
|
||||
if ( RESET )
|
||||
{
|
||||
// Obtenemos la longitud de la frase. ( En d<>gitos )
|
||||
Flen = FCadena.Length();
|
||||
if ( Flen == 0 ) Flen = 1;
|
||||
|
||||
// Contador de digito actual a cero
|
||||
BitByte = 0;
|
||||
// Posicion dentro de la frase
|
||||
currByte = 0;
|
||||
}
|
||||
|
||||
// Avance horizontal de bit's ( avance de digitos )
|
||||
for ( i = 0; i < ( Width ); i++ )
|
||||
{
|
||||
k = ( (unsigned char)Frase[ ( (i+BitByte)/TAMx + currByte ) % Flen ] ) << 4;
|
||||
LCaract = ( (char)0x01 << (7 - (i+BitByte)%TAMx) );
|
||||
PosX = /*Left + */AX * i; // Posicion f<>sica horizontal
|
||||
// Avance vertical de bit's
|
||||
for ( j = 0; j < TAMy; j ++ )
|
||||
{
|
||||
PosY = /*Top + */AY * j; // Posicion f<>sica vertical
|
||||
|
||||
if ( ptr_char[ k + j ] & LCaract )
|
||||
c_elec = cLED_ON;
|
||||
else
|
||||
c_elec = cLED_OFF;
|
||||
|
||||
Canvas -> Pixels[ PosX ][ PosY ] = c_elec;
|
||||
}
|
||||
}
|
||||
// Tenemos en cuenta el avance dentro de la frase
|
||||
if ( ( BitByte ++ ) >= 7 )
|
||||
{
|
||||
BitByte = 0; currByte ++;
|
||||
if ( (unsigned)currByte >= Flen )
|
||||
currByte = 0;
|
||||
}
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
void __fastcall TLetreroDigital::SetBorderStyle( TBorderStyle NuevoValor )
|
||||
{
|
||||
FBorderStyle = NuevoValor;
|
||||
Invalidate(); // y volver a dibujar el componente
|
||||
}
|
Reference in New Issue
Block a user