First commit 25/07/1999

This commit is contained in:
2021-09-12 22:11:31 +02:00
commit 52703a7441
22 changed files with 1447 additions and 0 deletions

View 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
}

Binary file not shown.

View File

@ -0,0 +1,92 @@
//---------------------------------------------------------------------------
#ifndef LetreroDigitalH
#define LetreroDigitalH
//---------------------------------------------------------------------------
#include <vcl\SysUtils.hpp>
#include <vcl\Controls.hpp>
#include <vcl\Classes.hpp>
#include <vcl\Forms.hpp>
//---------------------------------------------------------------------------
class PACKAGE TLetreroDigital : public TGraphicControl
{
private:
TBorderStyle FBorderStyle; // Con borde o sin borde
TBrush *FBrush; // Para el relleno del fondo
TColor cLED_ON; // Color de la LED encendida y
TColor cLED_OFF; // apagada
AnsiString FFuente; // Fuente a utilizar ( RAW Format 8x16 )
AnsiString FCadena; // Cadena a mostrar
char BitByte; // Contador de digito actual a cero
char currByte; // Posici<63>n dentro de la frase
int AX, AY; // Ancho X, e Y
unsigned int Flen; // Longitud de la frase
int TAMx, TAMy; // Ancho y Alto de las fuentes ( 8 x 16: Deft. )
char *ptr_char; // Puntero a la fuente fija RAW.
bool FActivarLD;
TTimer *FPulsoReloj;
int FFrecReloj;
enum TFPitchFnt { f_16x16, f_16x8, f_8x16, f_8x8 };
TFPitchFnt FPitchFnt;
// Cambia la relaci<63>n segun indice
void __fastcall SetTAMg( TFPitchFnt Index );//, int Index );
// Evento OnChange, dirigido a la siguiente funci<63>n:
void __fastcall CambioAtributo( TObject * Sender );
// Dibujo del letrero digital (Desde cero SI/NO)
void __fastcall DibujaLD( bool RESET );
void __fastcall OnTimerHandler(TObject *Sender);
protected:
// Redefinimos el m<>todo Paint, que ser<65> llamado cada vez
// que sea necesario redibujar el componente.
void __fastcall Paint();
public:
// Cambia la relaci<63>n ALTO/ANCHO "at Run Time".
void __fastcall SetAx( int NuevoValor );
void __fastcall SetAy( int NuevoValor );
void __fastcall SetBrush( TBrush *NuevoValor );
void __fastcall SetBorderStyle( TBorderStyle NuevoValor );
void __fastcall SetLED_Color( TColor NuevoValorON, TColor NuevoValorOFF );
// Tipo de letra RAW
void __fastcall SetFont( AnsiString NuevoValor );
// Cambia la relaci<63>n ALTO/ANCHO.
void __fastcall SetTAM( int NuevoTAMx, int NuevoTAMy );
// Cambia la cadena a mostrar: "at RunTime"
void __fastcall SetCadena( AnsiString NuevaCadena );
// Frecuencia del reloj
void __fastcall SetFrecReloj( int NuevoReloj );
__fastcall TLetreroDigital(TComponent* Owner);
__fastcall ~TLetreroDigital();
__published:
__property TBorderStyle BorderStyle = { read = FBorderStyle, write = SetBorderStyle, default=bsSingle };
__property TBrush *Brush = { read = FBrush, write = SetBrush };
__property TColor LED_ON = { read = cLED_ON, write = cLED_ON, default = clBlack };
__property TColor LED_OFF = { read = cLED_OFF, write = cLED_OFF, default = clYellow };
__property int FrecReloj = { read = FFrecReloj, write = SetFrecReloj, default = 100 };
__property Left ;
__property Top ;
__property Width = { default = 96 };
__property Height = { default = 32 };
__property TFPitchFnt PitchFuente = { read = FPitchFnt, write = SetTAMg };
__property AnsiString FuenteRAW = { read = FFuente, write = SetFont };
__property AnsiString Letrero = { read = FCadena, write = SetCadena };
__property int AmplitudX = { read = AX , write = SetAx , default = 2 };
__property int AmplitudY = { read = AY , write = SetAy , default = 2 };
// __property bool ActivarLD = { read = FPulsoReloj -> Enabled, write = FPulsoReloj -> Enabled };
};
//---------------------------------------------------------------------------
#endif