sábado, 27 de fevereiro de 2021

FMX - gerando e comparando dois arrays de caracteres



Este programa utiliza três dos seis operadores
relacionais da linguagem C, e a finalidade,
é comparar dois vetores de caracteres do C.
Isto não traz nenhuma novidade para nós,
mas a forma estratégica na qual organizamos 
os códigos para fazer as comparações,
foi perfeita e pode ser utilizada até em outras
comparações, como por exemplo, saber se dois vetores
são iguais ou distinto ou se seus elementos são comuns.
Assista o vídeo e comprove o programa funcionando:





//---------------------------------------------------------------------------
void Cria_Array_Embaralhado ( char *A, char *B ) {
             TObject *Sender;
int i;

Mix_Int ( A );
Mix_Int ( B );

if ( a == 1 ) {
T_Rect ( 160, 75, 150, 20 );
Rectangle3 -> Fill -> Color = claYellow;
Rectangle3 -> Stroke -> Color = claYellow;
Rectangle3 -> XRadius = 10;
Rectangle3 -> YRadius = 10;
//pos X, pos Y, Width, Height, Size, Bool, Color,String
T_Text ( 55, 50, 400, 20, 16, false, 0, "Imprimindo abaixo o array A" );
for ( i = 0; i < 5; i++ ) {
T_Text ( 24 + i * 30, 75, 300, 20, 16, true, 0,  A [ i ] );
C [ i ] = A [ i ];
}
Button1 -> Text = "Gerar o array B";
}
if ( a == 2 ) {
T_Rect ( 160, 125, 150, 20 );
Rectangle3 -> Fill -> Color = claTurquoise;
Rectangle3 -> Stroke -> Color = claTurquoise;
Rectangle3 -> XRadius = 10;
Rectangle3 -> YRadius = 10;
//pos X, pos Y, Width, Height, Size, Bool, Color,String
T_Text ( 55, 100, 400, 20, 16, false, 0, "Imprimindo abaixo o array B" );
for ( i = 0; i < 5; i++ ) {
T_Text ( 24 + i * 30, 125, 300, 20, 16, true, 0, B [ i ] );
D [ i ] = B [ i ];
}
Button1 -> Width = 150;
Button1 -> Text = "Comparar os dois arrays";
}
if ( a == 3 ) {
Compara_Array ( );
Button1 -> Width = 100;
Button1 -> Text = " Sobre ";
}
if ( a == 4 ) {
  Informe ( );
  Button1 -> Width = 100;
  Button1 -> Text = "Nova operação";
  }
  if ( a == 5 ) {
Form1 -> FormCreate ( Sender );
T_Rect ( 30, 35, 550, 240 );
Rectangle3 -> Fill -> Color = claWhite;
Rectangle3 -> Stroke -> Color = claWhite;
a = 0;
for ( i = 0; i < 27; i++ ) {
A [ i ] = ' ';
B [ i ] = ' ';
C [ i ] = ' ';
D [ i ] = ' ';
}
T_Rect ( 320, 280, 260, 50 );
Rectangle3 -> Fill -> Color = claWhite;
Rectangle3 -> Stroke -> Color = claWhite;
  }
}
//------------------------------------------------------------------------





sexta-feira, 26 de fevereiro de 2021

FMX - gerando e comparando dois arrays


Este programa utiliza três dos seis operadores
relacionais da linguagem C, e a finalidade,
é comparar dois vetores de inteiros do C.
Isto não traz nenhuma novidade para nós,
mas a forma estratégica na qual organizamos 
os códigos para fazer as comparações,
foi perfeita e pode ser utilizada até em outras
comparações, como por exemplo, saber se dois vetores
são iguais ou distinto ou se seus elementos são comuns.
Assista o vídeo e comprove o programa funcionando:





//------------------------------------------------------------------------
void __fastcall TForm1::FormCreate ( TObject *Sender ) {
Label_Manual ( Sender );
//pos X, pos Y, Width, Height, Size, Bool, Color,String
T_Text ( 100, 15, 400, 20, 16, true, 3, "FMX - GERANDO E COMPARANDO DOIS ARRAYS II" );
   b++;
  T_Rect ( 39, 300, 30, 20 );
  T_Text_2 ( 40, 300, 30, 20, 20, true, 3, String ( b ) + "°" );
  T_Text_2 ( 60, 300, 70, 20, 20, true, 0, "Teste" );
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click ( TObject *Sender ) {
int A [ 10 ];
int B [ 10 ];
a++;
Cria_Array_Embaralhado ( A, B );
}
//---------------------------------------------------------------------------

terça-feira, 16 de fevereiro de 2021

C++ builder - gerando array e sorteando

 




Este programa preenche um array de inteiro 
com os 10 primeiros números naturais,
mas embaralha-os em seguida e assim temos a
primeira impressão por um componente TText
do C++ builder.
pressionando o botão uma única vez, 
uma caixa de mensagem é ativada,
e o programa passa a ser executado por ela,
e a cada clique no botão desta caixa,
um número de dentro do vetor é sorteado
numa escolha totalmente aleatória.
Confira isto funcionando por favor:




//---------------------------------------------------------------------------
int Sorteia ( int *vet ) {
int i, r, temp;
for ( i = 0; i < tam; i++ )
vet [ i ] = i;
srand ( time ( NULL ) );
for ( i = 0; i < tam; i++ ) {
r = rand ( ) % tam;
temp = vet [ i ];
vet [ i ] = vet [ r ];
vet [ r ] = temp;
}
return 0;
}
//---------------------------------------------------------------------------
void Cria_Array_Embaralhado ( int *vet ) {
int i;
Sorteia ( vet );
T_Rect_2 ( 120, 55, 380, 20 );
Rectangle2 -> Fill -> Color = claYellow;
Rectangle2 -> Stroke -> Color = claYellow;

//pos X, pos Y, Width, Height, Size, Bool, Color,String
T_Text ( 100, 55, 400, 20, 16, false, 0, "Imprimindo abaixo o array aleatório" );
for ( i = 0; i < tam; i++ ) {
T_Text ( 20 + i * 30, 80, 300, 20, 16, false, 0, String ( vet [ i ] ) );
Text1 -> TextSettings -> Font -> Family = "alarm clock";
}
}
//---------------------------------------------------------------------------

domingo, 7 de fevereiro de 2021

C++ builder - botão para dois estados II

 


Em computação que é a nossa área,
os números binários 0 e 1 significam: False e True,
que foram padronizados em C++ como o tipo de dado
primitivo bool, sendo que em C eles são armazenados
em um simples tipo inteiro.
Em outras áreas da tecnologia, estes dois valores
booleanos, que receberam este nome em homenagem
George Boole, assumem outros nomes como: Low and Right,
"Baixo e Alto", Off and On, "Desligado e Ligado".
Em um post passado mostramos um exemplo de um botão,
de um único estado, o programa só realizava uma única ação, 
e por mais que se pressionasse o botão, nada mais acontecia.
Um exemplo de aplicação para isto seria um joguinho da velha,
onde os jogadores não podem pressionar um botão que já foi acionado.
O exemplo sugerido aqui mostra um botão de dois estados,
ele acende e apaga dois leds de modo alternado,
indicando em um label o número binário respectivo a seu estado.





//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate ( TObject *Sender ) {
   Label_Manual ( Sender );

  Image1 = new TImage ( this );
  Image1 -> Bitmap -> LoadFromFile ("One led vermelho aceso.bmp");
  Image1 -> Parent = Form1;
  Image1 -> Height = 50;
  Image1 -> Width = 35;
  Image1 -> Position -> X = 198;
  Image1 -> Position -> Y = 130;
  Label1 -> Text = IntToStr ( 1 );

  Image2 = new TImage ( this );
  Image2 -> Bitmap -> LoadFromFile ("Led_verde_apagado.png");
  Image2 -> Parent = Form1;
  Image2 -> Height = 50;
  Image2 -> Width = 35;
  Image2 -> Position -> X = 396;
  Image2 -> Position -> Y = 132;
  Label2 -> Text = IntToStr ( 0 );
}
//---------------------------------------------------------------------------

quinta-feira, 4 de fevereiro de 2021

C++ builder - detectando colisão entre duas esferas

 


Uma dos recursos mais importantes em jogos, 
é um bloco detector de colisão.
Detectar colisão é fundamental para que outras funções
ou comandos possam ser executados.
Neste exemplo estamos detectando colisão das bordas da janela, 
e entre duas esferas.
 Acompanhem no vídeo e veja como isto funciona .




//---------------------------------------------------------------------------
void __fastcall TForm1::Informe ( TObject *Sender ) {
Canvas -> Font -> Size = 12;
Canvas -> Font -> Name = "Garamond";
Canvas -> Font -> Color = clBlack;
Canvas -> TextOut ( 200, 245, "Por: " );
Canvas -> Font -> Color = clRed;
Canvas -> TextOut ( 240, 245, "Samuel Lima" );
Canvas -> Font -> Color = clBlack;
Canvas -> TextOut ( 200, 260, "sa_sp10@hotmail.com" );
Canvas -> Font -> Name = "Garamond";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::OnPaint ( TObject *Sender ) {
Canvas -> Font -> Size = 16;
Canvas -> Font -> Name = "Arial";
//Alterando o estilo da fonte para Bold e Itálico
Canvas -> Font-> Style = TFontStyles ( ) << fsBold << fsItalic;
//Ajustando a largura das bordas do RoundRect Em torno do form ( Moldura )
Canvas -> Pen -> Width = 10;
//Colorindo as bordas do roundrect ( Moldura ) com rgb
Canvas -> Pen -> Color = static_cast < TColor > ( RGB ( 255, 0, 255 ) );
Canvas -> RoundRect ( 05, 05, 595, 295, 25, 25 );
Canvas -> Font -> Color = clRed;
Canvas -> TextOut ( 50, 12, "DETECTANDO COLISÃO ENTRE DUAS ESFERAS" );
Informe ( Sender );
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormShow ( TObject *Sender ) {
if ( a ==  false ) {
  Shape1 -> Picture -> LoadFromFile ("Bal_blue_claro_3.bmp");
  Shape1 -> Height = 65;
  Shape1 -> Width = 65;

  Shape2 -> Picture -> LoadFromFile ("Bal_pink_2.bmp");
  Shape2 -> Height = 65;
  Shape2 -> Width = 65;
   }
}
//---------------------------------------------------------------------------


quarta-feira, 3 de fevereiro de 2021

FMX - pesquisando string ( Highlighter )

Este programa permite uma precisa pesquisa
na carga de uma matriz bidimensional de string do C,
e o fato mais positivo foi a não necessidade de
funções nativas nem do C e nem do C++ para isto,
fizemos na mão, e aliás estes códigos já utilizamos
a muito tempo desde os tempos que rodávamos nossos
programas na tela do cmd ( Prompt de comando ).
O que deixa o programa bem dinâmico na interação
com o usuário é a capacidade de marcar as pesquisas
encontradas, (  Highlighter ), isto nos deixa muito
satisfeito e não é o primeiro em que fizemos isto. 



//---------------------------------------------------------------------------

#include <fmx.h>
#pragma hdrstop
#define lin  12
#define col 45
#include "Unit1.h"

//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.fmx"
TForm1 *Form1;
bool x = false;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
TImage *Image2;
TImage *Image3;
//---------------------------------------------------------------------------
     char texto [ lin ] [ col ] = {
        "No Meio do Caminho                        ",
"Carlos Drummond de Andrade                ",
"No meio do caminho tinha uma pedra        ",
"Tinha uma pedra no meio do caminho        ",
"Tinha uma pedra                           ",
"No meio do caminho tinha uma pedra.       ",
"Nunca me esquecerei desse acontecimento   ",
"Na vida de minhas retinas tao fatigadas.  ",
"Nunca me esquecerei que no meio do caminho",
"Tinha uma pedra                           ",
"Tinha uma pedra no meio do caminho        ",
"No meio do caminho tinha uma pedra.       "};
  int i, j, t = 0;
//---------------------------------------------------------------------------
TText *Label3 [ lin ] [ col ] = { 0 };
TText *Label4 [ lin ] [ col ] = { 0 };

TRectangle *Rectangle2 [ lin ] [ col ] = { 0 };
TRectangle *Rectangle4;

  //---------------------------------------------------------------------------
void __fastcall TForm1::Label_Manual ( TObject *Sender ) {
Rectangle1 -> Width = 600;
Rectangle1 -> Height = 360;
Rectangle1 -> Position -> X = 0;
Rectangle1 -> Position -> Y = 0;
Rectangle1 -> Fill -> Color = claWhite;
Rectangle1 -> Size -> PlatformDefault = False;
Rectangle1 -> Stroke -> Color = claBlue;
Rectangle1 -> Stroke -> Thickness = 10;
Rectangle1 -> XRadius = 15;
Rectangle1 -> YRadius = 15;

Edit1 -> SetFocus ( );
    Edit1 -> Font -> Size = 10;
    Edit1 -> Width = 70;
    Edit1 -> Height = 20;
    Edit1 -> Position -> X = 80;
Edit1 -> Position -> Y = 320;

Button1 -> Visible = true;
    Button1 -> Width = 30;
    Button1 -> Height = 20;
Button1 -> Position -> X = 165;
Button1 -> Position -> Y = 320;
Button1 -> TextSettings -> Font -> Style = TFontStyles ( ) << fsBold << fsItalic;
Button1 -> TextSettings -> Font -> Family = "Arial";
Button1 -> TextSettings -> Font -> Size = 16;
Button1 -> TextSettings -> FontColor = claBlue;
Button1 -> Text = "Ok";

Button2 -> Visible = false;
Button2 -> Width = 130;
Button2 -> Height = 20;
Button2 -> Position -> X = 445;
Button2 -> Position -> Y = 320;
Button2 -> TextSettings -> Font -> Style = TFontStyles ( ) << fsBold << fsItalic;
Button2 -> TextSettings -> Font -> Family = "Arial";
Button2 -> TextSettings -> Font -> Size = 16;
Button2 -> TextSettings -> FontColor = claBlue;
Button2 -> Text = "Limpa pesquisas";

Label1 -> Position -> X = 80;
Label1 -> Position -> Y = 275;
Label1 -> Size -> Width = 350;
Label1 -> Size -> Height = 20;
Label1 -> AutoSize = True;
Label1 -> TextSettings -> Font -> Size = 14;
Label1 -> TextSettings -> FontColor = claRed;
Label1 -> TextSettings -> Font -> Family = "Consolas";
Label1 -> Font -> Style = TFontStyles ( ) << fsBold << fsItalic;

Label5 -> Position -> X = 180;
Label5 -> Position -> Y = 10;
Label5 -> Size -> Width = 300;
Label5 -> Size -> Height = 19;
Label5 -> TextSettings -> Font -> Size = 18;
Label5 -> TextSettings -> FontColor = claRed;
Label5 -> Font -> Style = TFontStyles ( ) << fsBold << fsItalic;
Label5 -> Text = "FMX - PESQUISANDO STRING";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Informe ( TObject *Sender ) {
  Image2 = new TImage ( this );
  Image2 -> Visible = true;
  Image2 -> Bitmap -> LoadFromFile ("Por.bmp");
  Image2 -> Parent = Form1;
  Image2 -> Height = 40;
  Image2 -> Width = 250;
  Image2 -> Position -> X = 200;
  Image2 -> Position -> Y = 310;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Limpa_Tela ( TObject *Sender ) {
  Image3 = new TImage ( this );
  Image3 -> Visible = true;
  Image3 -> Bitmap -> LoadFromFile ("FundoBranco.bmp");
  Image3 -> Parent = Form1;
  Image3 -> Height = 280;
  Image3 -> Width = 570;
  Image3 -> Position -> X = 10;
  Image3 -> Position -> Y = 30;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Imprime_Texto ( TObject *Sender ) {
for ( i = 0; i < lin; i++ ) {
for ( j = 0; j < col; j++ ) {
  Label3 [ i ] [ j ] = new TText ( this );
  Label3 [ i ] [ j ] -> Parent = Form1;
  Label3 [ i ] [ j ] -> AutoSize = True;
  Label3 [ i ] [ j ] -> TextSettings -> Font -> Family = "Consolas";
  Label3 [ i ] [ j ] -> TextSettings -> Font -> Size = 14;
  Label3 [ i ] [ j ] -> TextSettings -> Font -> Style = TFontStyles ( ) << fsBold << fsItalic;
  Label3 [ i ] [ j ] -> TextSettings -> FontColor = claBlack;
  Label3 [ i ] [ j ] -> Position -> X = 60 + ( j * 10 );
  Label3 [ i ] [ j ] -> Position -> Y = 35 + ( i * 20 );
  Label3 [ i ] [ j ] -> Text += ( texto [ i ] [ j ] );
}
}
}
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate ( TObject *Sender ) {
   Label_Manual ( Sender );
   Imprime_Texto  ( Sender );
   Button2 -> Visible = false;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click ( TObject *Sender ) {;
Limpa_Tela ( Sender );
Image2 -> Visible = false;
Button2 -> Visible = false;
FormCreate ( Sender );
Edit1 -> SetFocus ( );
}
//---------------------------------------------------------------------------


 

terça-feira, 2 de fevereiro de 2021

C++ builder - botão para click único

 


Estamos mostrando neste exemplo um botão
para click único, que poderia ter sido feito
somente configurando nas propriedades 
do objeto TButton do C++ builder,
mas somos rebeldes mesmo então resolvemos
criar tudo na mão, nada foi inserido no form,
e os eventos também foram criados utilizando
apenas códigos, no final, ficou tudo perfeito.
Assista este pequeno vídeo do programa funcionando:




//---------------------------------------------------------------------------

#include <fmx.h>
#pragma hdrstop

#include "Unit1.h"

//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.fmx"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1 ( TComponent* Owner )
: TForm ( Owner )
{
}
   int w;
   TText *Text1;
   TImage *Image1;
   TImage *Image2;
   TImage *Image3;
   TImage *Image4;
TCircle *Circle1;
//---------------------------------------------------------------------------
void __fastcall TForm1::Label_Manual ( TObject *Sender ) {
Rectangle1 -> Width = 600;
Rectangle1 -> Height = 300;
Rectangle1 -> Position -> X = 0;
Rectangle1 -> Position -> Y = 0;
//Rectangle1 -> Fill -> Color = ( RGB ( 255, 0, 205 ) );
Rectangle1 -> Size -> PlatformDefault = False;
Rectangle1 -> Stroke -> Color = claYellow;
//Rectangle1 -> Stroke -> Kind = TBrushKind::Solid;
//Rectangle1 -> Stroke -> Color = ( RGB ( 255, 255, 0 ) );
Rectangle1 -> Stroke -> Thickness = 10;
Rectangle1 -> XRadius = 15;
Rectangle1 -> YRadius = 15;

Label1 -> Position -> X = 220;
Label1 -> Position -> Y = 100;
Label1 -> Size -> Width = 500;
Label1 -> Size -> Height = 19;
//Label4 -> AutoSize = True;
Label1 -> TextSettings -> Font -> Family = "Garamound";
Label1 -> TextSettings -> Font -> Size = 18;
Label1 -> TextSettings -> FontColor = claRed;
Label1 -> Font -> Style = TFontStyles ( ) << fsBold << fsItalic;
//Label1 -> Text = "FMX - PROCESSMESSAGES";

Text1  = new TText ( this );
Text1 -> Parent = Form1;
//Text1 -> AutoSize = True;
Text1 -> TextSettings -> Font -> Family = "Garamound";
Text1 -> TextSettings -> Font -> Size = 20;
Text1 -> TextSettings -> Font -> Style = TFontStyles ( ) << fsBold << fsItalic;
//Text1-> Color = clYellow;
Text1 -> TextSettings -> FontColor = claRed;
Text1 -> Width = 500;
Text1 -> Height = 19;
Text1 -> Position -> Y = 15;
Text1 -> Position -> X = 60;
Text1 -> Text = "FMX - BOTÃO PARA UM ÚNICO ESTADO";

  Image3 = new TImage ( this );
  Image3 -> Bitmap -> LoadFromFile ("Bal_green.bmp");
  Image3 -> Parent = Form1;
  Image3 -> Height = 50;
  Image3 -> Width = 50;
  Image3 -> Position -> X = 60;
  Image3 -> Position -> Y = 230;
  Image3 -> OnClick = Image3Click;

  Image4 = new TImage ( this );
  Image4 -> Bitmap -> LoadFromFile ("Bal_blue_claro.bmp");
  Image4 -> Parent = Form1;
  Image4 -> Height = 50;
  Image4 -> Width = 50;
  Image4 -> Position -> X = 480;
  Image4 -> Position -> Y = 230;
  Image4 -> OnClick = Image4Click;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate ( TObject *Sender ) {
   Label_Manual ( Sender );
  Image1 = new TImage ( this );
  Image1 -> Bitmap -> LoadFromFile ("smiling-face_1.bmp");
  Image1 -> Parent = Form1;
  Image1 -> Height = 50;
  Image1 -> Width = 30;
  Image1 -> Position -> X = 198;
  Image1 -> Position -> Y = 130;
}
//---------------------------------------------------------------------------
int val_ue;
int mouse_Clicked ( ) {
if ( val_ue == 1 ) {
val_ue = 0;
} else {
val_ue = 1;
}
return val_ue;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Image3Click(TObject *Sender) {
  Image3 = new TImage ( this );
  Image3 -> Bitmap -> LoadFromFile ("Bal_green_claro.bmp");
  Image3 -> Parent = Form1;
  Image3 -> Height = 50;
  Image3 -> Width = 50;
  Image3 -> Position -> X = 60;
  Image3 -> Position -> Y = 230;
  if ( mouse_Clicked ( ) == 1 ) {
Beep ( 500, 500 );
  Image1 = new TImage ( this );
  Image1 -> Bitmap -> LoadFromFile ("smiling-face_2.bmp");
  Image1 -> Parent = Form1;
  Image1 -> Height = 50;
  Image1 -> Width = 30;
  Image1 -> Position -> X = 198;
  Image1 -> Position -> Y = 130;

  Image2 = new TImage ( this );
  Image2 -> Bitmap -> LoadFromFile ("Por_5.bmp");
  Image2 -> Parent = Form1;
  Image2 -> Height = 60;
  Image2 -> Width = 210;
  Image2 -> Position -> X = 198;
  Image2 -> Position -> Y = 230;
  }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Image4Click(TObject *Sender) {
  Close ( );
}
//---------------------------------------------------------------------------