First commit 25/07/1999
This commit is contained in:
341
DigitNum/DigitNum.cpp
Normal file
341
DigitNum/DigitNum.cpp
Normal file
@ -0,0 +1,341 @@
|
||||
//---------------------------------------------------------------------------
|
||||
#include <vcl.h>
|
||||
#pragma hdrstop
|
||||
#include <math.h>
|
||||
|
||||
#include "DigitNum.h"
|
||||
#pragma package(smart_init)
|
||||
//---------------------------------------------------------------------------
|
||||
// ValidCtrCheck is used to assure that the components created do not have
|
||||
// any pure virtual functions.
|
||||
//
|
||||
|
||||
static inline void ValidCtrCheck(TDigitNum *)
|
||||
{
|
||||
new TDigitNum(NULL);
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
__fastcall TDigitNum::TDigitNum(TComponent* Owner)
|
||||
: TGraphicControl(Owner)
|
||||
{
|
||||
Width = 96; // Establecemos valores por defecto
|
||||
Height = 33;
|
||||
|
||||
vCerosIzq = false;
|
||||
|
||||
BorderStyle = bsSingle;
|
||||
cLED_ON =clRed;
|
||||
cLED_OFF=clBtnFace;
|
||||
cLED_BRDon=clBlack;
|
||||
cLED_BRDoff=clGray;
|
||||
|
||||
FValor = 0;
|
||||
// Obtenemos la longitud de la frase. ( En d<>gitos )
|
||||
FLen = 4;
|
||||
|
||||
FBrush = new TBrush;
|
||||
FBrush -> Color = clBtnFace;
|
||||
FBrush -> Style = bsClear;
|
||||
FBrush -> OnChange = CambioAtributo;
|
||||
Invalidate();
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
namespace Digitnum
|
||||
{
|
||||
void __fastcall PACKAGE Register()
|
||||
{
|
||||
TComponentClass classes[1] = {__classid(TDigitNum)};
|
||||
RegisterComponents("JD soft.", classes, 0);
|
||||
}
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
__fastcall TDigitNum::~TDigitNum()
|
||||
{
|
||||
delete FBrush;
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
void __fastcall TDigitNum::SetCadena( int NuevaCadena )
|
||||
{
|
||||
FValor = NuevaCadena;
|
||||
Invalidate();
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
// Este procedimiento es llamado cada vez que se modifica
|
||||
// la brocha, el l<>piz o el tipo de letra
|
||||
void __fastcall TDigitNum::CambioAtributo( TObject * Sender )
|
||||
{
|
||||
Invalidate(); // tras lo cual habr<62> que redibujar el componente
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
void __fastcall TDigitNum::SetBrush( TBrush * NuevoValor )
|
||||
{
|
||||
FBrush -> Assign( NuevoValor );
|
||||
Invalidate(); // y volver a dibujar el componente
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
void __fastcall TDigitNum::SetLedOn( TColor NuevoValor )
|
||||
{
|
||||
cLED_ON = ( NuevoValor );
|
||||
Invalidate(); // y volver a dibujar el componente
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
void __fastcall TDigitNum::SetLedOff( TColor NuevoValor )
|
||||
{
|
||||
cLED_OFF = ( NuevoValor );
|
||||
Invalidate(); // y volver a dibujar el componente
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
void __fastcall TDigitNum::SetLedBrdOn( TColor NuevoValor )
|
||||
{
|
||||
cLED_BRDon = ( NuevoValor );
|
||||
Invalidate(); // y volver a dibujar el componente
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
void __fastcall TDigitNum::SetLedBrdOff( TColor NuevoValor )
|
||||
{
|
||||
cLED_BRDoff = ( NuevoValor );
|
||||
Invalidate(); // y volver a dibujar el componente
|
||||
}
|
||||
void __fastcall TDigitNum::SetNumDigit( int NuevoValor )
|
||||
{
|
||||
if ( NuevoValor > 0 )
|
||||
{
|
||||
FLen = NuevoValor;
|
||||
Invalidate(); // y volver a dibujar el componente
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
void __fastcall TDigitNum::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 );
|
||||
|
||||
DibujaLD();
|
||||
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
void __fastcall TDigitNum::SetCerosIzq( bool NuevoValor )
|
||||
{
|
||||
vCerosIzq = NuevoValor;
|
||||
Invalidate();
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
void __fastcall TDigitNum::DibujaLD( void )
|
||||
{
|
||||
// Proceso de redibujado de los digitos...
|
||||
int AnchoDigito, i, Digito;
|
||||
// <20> Cuanto espacio le corresponde a cada d<>gito... ?
|
||||
AnchoDigito = Width / FLen;
|
||||
|
||||
// Numero de digitos de la cifra...
|
||||
int Digitos = 1;
|
||||
while ( FValor >= (int)pow10(Digitos) ) Digitos++;
|
||||
|
||||
i = 0;
|
||||
DibujaDigito( (( FValor % (int)pow10(i+1) ) / (int)pow10(i) ), AnchoDigito, AnchoDigito * (FLen - i - 1) );
|
||||
for ( i = 1; i < FLen ; i++ )
|
||||
{
|
||||
Digito = (( FValor % (int)pow10(i+1) ) / (int)pow10(i) );
|
||||
if ( !CerosIzq && i >= Digitos )//!Digito && !CerosIzq )
|
||||
DibujaDigito( 10, AnchoDigito, AnchoDigito * (FLen - i - 1) );
|
||||
else
|
||||
DibujaDigito( Digito, AnchoDigito, AnchoDigito * (FLen - i - 1) );
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
void __fastcall TDigitNum::DibujaDigito( short int Digito, short int AnchoDigit, short int PosInicial )
|
||||
{
|
||||
int PMedio, PVert, Medio, MedioL, MedioH;
|
||||
|
||||
POINT P1[5], P2[7], P3[5], P4[5], P5[5], P6[5], P7[5];
|
||||
|
||||
PMedio = (Height-1) / 8;
|
||||
PVert = AnchoDigit / 5;
|
||||
Medio = (Height-1)/2;//( ( ( PMedio * 6 ) - ( PMedio * 4 ) ) / 2 ) + ( PMedio*4 );
|
||||
MedioL = Medio - ( PMedio / 2 );
|
||||
MedioH = Medio + ( PMedio / 2 );
|
||||
|
||||
/* _ _ _ _ _ _ _
|
||||
|_| _ _ _ _ |
|
||||
1 __ |_| |#|#|#|_| |
|
||||
_ _ _ _ ___/ |_| |#|_|#|_| |
|
||||
|_| |_| |_| 4 |2| 5 ______ |_| |#|#|#|_| |
|
||||
|_| |_| |_| 6 |_| 7 ___ |_| |#|_|#|_| |
|
||||
\__ |_| |#|#|#|_| |
|
||||
3 |_|_ _ _ _ _ _|
|
||||
*/
|
||||
// 1
|
||||
// ______________
|
||||
// \ /
|
||||
// \__________/
|
||||
//
|
||||
P1[0] . x = 1 + 1 + PosInicial; P1[0] . y = 0;
|
||||
P1[1] . x = PVert * 4 - 1 + PosInicial; P1[1] . y = 0;
|
||||
P1[2] . x = PVert * 3 - 1 + PosInicial; P1[2] . y = PMedio*1 - 1;
|
||||
P1[3] . x = PVert * 1 + 1 + PosInicial; P1[3] . y = PMedio*1 - 1;
|
||||
P1[4] . x = 1 + 1 + PosInicial; P1[4] . y = 0;
|
||||
// 2
|
||||
// __________
|
||||
// / \
|
||||
// \__________/
|
||||
//
|
||||
P2[0] . x = 2 + PosInicial; P2[0] . y = Medio ;
|
||||
P2[1] . x = PVert * 1 + 1 + PosInicial; P2[1] . y = MedioL + 1;
|
||||
P2[2] . x = PVert * 3 - 1 + PosInicial; P2[2] . y = MedioL + 1;
|
||||
P2[3] . x = PVert * 4 - 2 + PosInicial; P2[3] . y = Medio ;
|
||||
P2[4] . x = PVert * 3 - 1 + PosInicial; P2[4] . y = MedioH - 1;
|
||||
P2[5] . x = PVert * 1 + 1 + PosInicial; P2[5] . y = MedioH - 1;
|
||||
P2[6] . x = 2 + PosInicial; P2[6] . y = Medio ;
|
||||
// 3
|
||||
// __________
|
||||
// / \
|
||||
// /____________\
|
||||
//
|
||||
P3[0] . x = PVert * 1 + 1 + PosInicial; P3[0] . y = PMedio*7 + 1;
|
||||
P3[1] . x = PVert * 3 - 1 + PosInicial; P3[1] . y = PMedio*7 + 1;
|
||||
P3[2] . x = PVert * 4 - 1 + PosInicial; P3[2] . y = PMedio*8 ;
|
||||
P3[3] . x = PVert * 0 + 2 + PosInicial; P3[3] . y = PMedio*8 ;
|
||||
P3[4] . x = PVert * 1 + 1 + PosInicial; P3[4] . y = PMedio*7 + 1;
|
||||
// .
|
||||
// |\
|
||||
// | |
|
||||
// 4 | |
|
||||
// | |
|
||||
// |/
|
||||
// <20>
|
||||
P4[0] . x = 0 + PosInicial; P4[0] . y = 1;
|
||||
P4[1] . x = PVert * 1 - 1 + PosInicial; P4[1] . y = PMedio*1 + 1;
|
||||
P4[2] . x = PVert * 1 - 1 + PosInicial; P4[2] . y = MedioL - 1;
|
||||
P4[3] . x = 0 + PosInicial; P4[3] . y = Medio - 1;
|
||||
P4[4] . x = 0 + PosInicial; P4[4] . y = 1;
|
||||
// .
|
||||
// /|
|
||||
// | |
|
||||
// 5 | |
|
||||
// | |
|
||||
// \|
|
||||
// <20>
|
||||
P5[0] . x = PVert * 4 + 1 + PosInicial; P5[0] . y = 1;
|
||||
P5[1] . x = PVert * 4 + 1 + PosInicial; P5[1] . y = Medio - 1;
|
||||
P5[2] . x = PVert * 3 + 1 + PosInicial; P5[2] . y = MedioL - 1;
|
||||
P5[3] . x = PVert * 3 + 1 + PosInicial; P5[3] . y = PMedio*1 + 1;
|
||||
P5[4] . x = PVert * 4 + 1 + PosInicial; P5[4] . y = 1;
|
||||
// .
|
||||
// |\
|
||||
// | |
|
||||
// 6 | |
|
||||
// | |
|
||||
// |/
|
||||
// <20>
|
||||
P6[0] . x = 0 + PosInicial; P6[0] . y = Medio + 1;
|
||||
P6[1] . x = PVert * 1 - 1 + PosInicial; P6[1] . y = MedioH + 1;
|
||||
P6[2] . x = PVert * 1 - 1 + PosInicial; P6[2] . y = PMedio*7 - 1;
|
||||
P6[3] . x = 0 + PosInicial; P6[3] . y = PMedio*8 - 1;
|
||||
P6[4] . x = 0 + PosInicial; P6[4] . y = MedioH + 1;
|
||||
// .
|
||||
// /|
|
||||
// | |
|
||||
// 7 | |
|
||||
// | |
|
||||
// \|
|
||||
// <20>
|
||||
P7[0] . x = PVert * 4 + 1 + PosInicial; P7[0] . y = Medio + 1;
|
||||
P7[1] . x = PVert * 4 + 1 + PosInicial; P7[1] . y = PMedio*8 - 1;
|
||||
P7[2] . x = PVert * 3 + 1 + PosInicial; P7[2] . y = PMedio*7 - 1;
|
||||
P7[3] . x = PVert * 3 + 1 + PosInicial; P7[3] . y = MedioH + 1;
|
||||
P7[4] . x = PVert * 4 + 1 + PosInicial; P7[4] . y = Medio + 1;
|
||||
|
||||
|
||||
// 1 === 0, 2, 3, 5, 6, 7, 8, 9,
|
||||
if ( Digito != 1 && Digito != 4 && Digito != 10 )
|
||||
{
|
||||
Canvas -> Brush -> Color = cLED_ON;
|
||||
Canvas -> Pen -> Color = cLED_BRDon;
|
||||
} else {
|
||||
Canvas -> Brush -> Color = cLED_OFF;
|
||||
Canvas -> Pen -> Color = cLED_BRDoff;
|
||||
}
|
||||
Canvas -> Polygon( P1, 4 );
|
||||
// 2 === 2, 3, 4, 5, 6, 8, 9
|
||||
if ( Digito != 0 && Digito != 1 && Digito != 7 && Digito != 10 )
|
||||
{
|
||||
Canvas -> Brush -> Color = cLED_ON;
|
||||
Canvas -> Pen -> Color = cLED_BRDon;
|
||||
} else {
|
||||
Canvas -> Brush -> Color = cLED_OFF;
|
||||
Canvas -> Pen -> Color = cLED_BRDoff;
|
||||
}
|
||||
Canvas -> Polygon( P2, 6 );
|
||||
// 3 === 0, 2, 3, 5, 6, 8, 9
|
||||
if ( Digito != 1 && Digito != 4 && Digito != 7 && Digito != 10 )
|
||||
{
|
||||
Canvas -> Brush -> Color = cLED_ON;
|
||||
Canvas -> Pen -> Color = cLED_BRDon;
|
||||
} else {
|
||||
Canvas -> Brush -> Color = cLED_OFF;
|
||||
Canvas -> Pen -> Color = cLED_BRDoff;
|
||||
}
|
||||
Canvas -> Polygon( P3, 4 );
|
||||
// 4 === 0, 4, 5, 6, 8, 9
|
||||
if ( Digito != 1 && Digito != 2 && Digito != 3&& Digito != 7 && Digito != 10 )
|
||||
{
|
||||
Canvas -> Brush -> Color = cLED_ON;
|
||||
Canvas -> Pen -> Color = cLED_BRDon;
|
||||
} else {
|
||||
Canvas -> Brush -> Color = cLED_OFF;
|
||||
Canvas -> Pen -> Color = cLED_BRDoff;
|
||||
}
|
||||
Canvas -> Polygon( P4, 4 );
|
||||
// 5 === 0, 1, 2, 3, 4, 7, 8, 9
|
||||
if ( Digito != 5 && Digito != 6 && Digito != 10 )
|
||||
{
|
||||
Canvas -> Brush -> Color = cLED_ON;
|
||||
Canvas -> Pen -> Color = cLED_BRDon;
|
||||
} else {
|
||||
Canvas -> Brush -> Color = cLED_OFF;
|
||||
Canvas -> Pen -> Color = cLED_BRDoff;
|
||||
}
|
||||
Canvas -> Polygon( P5, 4 );
|
||||
// 6 === 0, 2, 6, 8
|
||||
if ( Digito == 0 || Digito == 2 || Digito == 6 || Digito == 8 )
|
||||
{
|
||||
Canvas -> Brush -> Color = cLED_ON;
|
||||
Canvas -> Pen -> Color = cLED_BRDon;
|
||||
} else {
|
||||
Canvas -> Brush -> Color = cLED_OFF;
|
||||
Canvas -> Pen -> Color = cLED_BRDoff;
|
||||
}
|
||||
Canvas -> Polygon( P6, 4 );
|
||||
// 7 === 0, 1, 3, 4, 5, 6, 7, 8, 9
|
||||
if ( Digito != 2 && Digito != 10 )
|
||||
{
|
||||
Canvas -> Brush -> Color = cLED_ON;
|
||||
Canvas -> Pen -> Color = cLED_BRDon;
|
||||
} else {
|
||||
Canvas -> Brush -> Color = cLED_OFF;
|
||||
Canvas -> Pen -> Color = cLED_BRDoff;
|
||||
}
|
||||
Canvas -> Polygon( P7, 4 );
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
void __fastcall TDigitNum::SetBorderStyle( TBorderStyle NuevoValor )
|
||||
{
|
||||
FBorderStyle = NuevoValor;
|
||||
Invalidate(); // y volver a dibujar el componente
|
||||
}
|
||||
|
||||
|
BIN
DigitNum/DigitNum.dcr
Normal file
BIN
DigitNum/DigitNum.dcr
Normal file
Binary file not shown.
72
DigitNum/DigitNum.h
Normal file
72
DigitNum/DigitNum.h
Normal file
@ -0,0 +1,72 @@
|
||||
//---------------------------------------------------------------------------
|
||||
#ifndef DigitNumH
|
||||
#define DigitNumH
|
||||
//---------------------------------------------------------------------------
|
||||
#include <SysUtils.hpp>
|
||||
#include <Controls.hpp>
|
||||
#include <Classes.hpp>
|
||||
#include <Forms.hpp>
|
||||
//---------------------------------------------------------------------------
|
||||
class PACKAGE TDigitNum : 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
|
||||
TColor cLED_BRDon; // Color para el borde
|
||||
TColor cLED_BRDoff; // Color para el borde
|
||||
|
||||
|
||||
|
||||
int FValor; // Valor inicial a mostrar
|
||||
int FLen; // N<>mero de digitos a mostrar
|
||||
bool vCerosIzq;
|
||||
|
||||
// Evento OnChange, dirigido a la siguiente funci<63>n:
|
||||
void __fastcall CambioAtributo( TObject * Sender );
|
||||
|
||||
// Dibujo del letrero digital
|
||||
void __fastcall DibujaLD( void );
|
||||
void __fastcall DibujaDigito( short int Digito, short int AnchoDigit, short int PosInicial );
|
||||
|
||||
protected:
|
||||
// Redefinimos el m<>todo Paint, que ser<65> llamado cada vez
|
||||
// que sea necesario redibujar el componente.
|
||||
void __fastcall Paint();
|
||||
public:
|
||||
void __fastcall SetNumDigit( int NuevoValor );
|
||||
void __fastcall SetBrush( TBrush *NuevoValor );
|
||||
void __fastcall SetBorderStyle( TBorderStyle NuevoValor );
|
||||
|
||||
void __fastcall SetLedOn( TColor NuevoValor );
|
||||
void __fastcall SetLedOff( TColor NuevoValor );
|
||||
void __fastcall SetLedBrdOn( TColor NuevoValor );
|
||||
void __fastcall SetLedBrdOff( TColor NuevoValor );
|
||||
void __fastcall SetCerosIzq( bool NuevoValor );
|
||||
|
||||
|
||||
// Cambia la cadena a mostrar: "at RunTime"
|
||||
void __fastcall SetCadena( int NuevaCadena );
|
||||
|
||||
__fastcall TDigitNum(TComponent* Owner);
|
||||
__fastcall ~TDigitNum();
|
||||
__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 = SetLedOn, default = clRed };
|
||||
__property TColor LED_OFF = { read = cLED_OFF, write = SetLedOff, default = clBtnFace };
|
||||
__property TColor LED_BRDon = { read = cLED_BRDon, write = SetLedBrdOn, default = clBlack };
|
||||
__property TColor LED_BRDoff = { read = cLED_BRDoff, write = SetLedBrdOff, default = clGray };
|
||||
|
||||
__property Left ;
|
||||
__property Top ;
|
||||
__property Width ;
|
||||
__property Height ;
|
||||
|
||||
__property bool CerosIzq = { read = vCerosIzq, write = SetCerosIzq, default = false };
|
||||
__property int Value = { read = FValor, write = SetCadena };
|
||||
__property int MaxLength = { read = FLen , write = SetNumDigit , default = 4 };
|
||||
};
|
||||
//---------------------------------------------------------------------------
|
||||
#endif
|
Reference in New Issue
Block a user