terça-feira, 21 de julho de 2020

FMX - Embaralhando frases

Este programa foi criado num projeto C++,
utilizando é claro o C++ Builder da Embarcadero,
mas a parte lógica foi criada em C,
sendo que nada impede os mais experientes
converterem este código para outras linguagens.
Fiz uso da biblioteca FMX,
que é simplesmente incrível e poderosa.
A maioria de meus programas no C++ Builder,
eu utilizo a biblioteca VCL,
mas as vezes sinto falta do FMX,
e me rendo a sua soberania.
Viva o C++, Viva o C++ Builder, Viva FMX!



Veja abaixo os códigos do programa:

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

#include <fmx.h>
#pragma hdrstop
#include <time.h>
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.fmx"
TForm1 *Form1;
int a;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
 //---------------------------------------------------------------------------
void __fastcall TForm1::Label_Manual ( TObject *Sender ) {
   Image1 -> Width = 600;
   Image1 -> Height = 350;
   Image1 -> Position -> X = 0;
   Image1 -> Position -> Y = 0;

   Image2 -> Width = 600;
   Image2 -> Height = 350;
   Image2 -> Position -> X = 0;
   Image2 -> Position -> Y = 0;

   Edit1 -> SetFocus ( );
   Edit1 -> Font -> Size = 10;
   Edit1 -> Width = 130;
   Edit1 -> Height = 17;
   Edit1 -> Position -> X = 287;
   Edit1 -> Position -> Y = 35;

   Label1 -> Position -> X = 140;
   Label1 -> Position -> Y = 90;
   Label1 -> Size -> Width = 400;
   Label1 -> Size -> Height = 35;
   Label1 -> TextSettings -> Font -> Size = 19;
   Label1 -> TextSettings -> FontColor = claRed;
   Label1 -> Size -> PlatformDefault = False;
   Label1 -> Font -> Style = TFontStyles ( ) << fsBold << fsItalic;

   Label2 -> Position -> X = 140;
   Label2 -> Position -> Y = 170;
   Label2 -> Size -> Width = 400;
   Label2 -> Size -> Height = 35;
   Label2 -> TextSettings -> Font -> Size = 19;
   Label2 -> TextSettings -> FontColor = claBlue;
   Label2 -> Size -> PlatformDefault = False;
   Label2 -> Font -> Style = TFontStyles ( ) << fsBold << fsItalic;

   Button1 -> TextSettings -> Font -> Size = 16;
   Button1 -> TextSettings -> FontColor = claBlue;
   Button1 -> TextSettings -> Font -> Family = "Arial";
   Button1 -> TextSettings -> Font -> Style = TFontStyles ( ) << fsBold << fsItalic;
   Button1 -> Position -> X = 430;
   Button1 -> Position -> Y = 35;
   Button1 -> Height = 18;
   Button1 -> Width = 30;
   Button1 -> Text = "OK";
   Button1 -> OnClick = FormShow;

   RoundRect1 -> Position -> X = 340;
   RoundRect1 -> Position -> Y = 270;
   RoundRect1 -> Height = 18;
   RoundRect1 -> Width = 100;
   //RoundRect1 -> Text = "NOVA FRASE";

}
//---------------------------------------------------------------------------
int Resolve_Problema ( int x ) {
int j, b, p;

int lenv;
char *Vet;
char *Vet_2;
String st;
char *r;
st += Form1 -> Edit1 -> Text;

Vet = ( char * )  malloc ( 28 );
r = Vet;

wcstombs (  Vet, st.c_str ( ), 50 );
Form1 -> Label1 -> Text = Vet;

if ( x >= 2 ) {
//Beep ( 500, 500 );
srand ( time ( NULL ) );
for ( b = 0; b < strlen ( Vet ); b++ ) {
j = rand ( ) % ( strlen ( Vet ) );
char t = r [ j ];
r [ j ] = r [ b ];
r [ b ] = t;
}
Form1 -> Label2 -> Text = " ";
for ( p = 0; p < strlen ( Vet ); p++ ) {
  Form1 -> Label2 -> Text = Form1 -> Label2 -> Text + r [ p ];
}
}
return ( 0 );
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormShow ( TObject *Sender ) {
int x;
Label_Manual ( Sender );
a++;
x++;
   Resolve_Problema ( x );
   Image2 -> Visible = false;
   Image1 -> Visible = true;
   RoundRect1 -> Visible = false;
if ( a >= 2 ) {
Form1 -> Image1 -> Visible = false;
Form1 -> Image2 -> Visible = true;
Edit1 -> Visible = false;

Button1 -> Position -> X = 140;
Button1 -> Position -> Y = 270;
Button1 -> Height = 18;
Button1 -> Width = 100;
Button1 -> Text = "EMBARALHA";
RoundRect1 -> Visible = true;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::RoundRect1Click ( TObject *Sender ) {
   a = 0;
   Label_Manual ( Sender );
   FormShow ( Sender );
   Image2 -> Visible = false;
   Image1 -> Visible = true;
   Edit1 -> Visible = true;
   Label1 -> Text = " ";
   Label2 -> Text = " ";
}

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



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

#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <System.Classes.hpp>
#include <FMX.Controls.hpp>
#include <FMX.Forms.hpp>
#include <FMX.Controls.Presentation.hpp>
#include <FMX.Edit.hpp>
#include <FMX.Objects.hpp>
#include <FMX.StdCtrls.hpp>
#include <FMX.Types.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TImage *Image1;
TImage *Image2;
TEdit *Edit1;
TButton *Button1;
TLabel *Label1;
TLabel *Label2;
TRoundRect *RoundRect1;
void __fastcall FormShow(TObject *Sender);
    void __fastcall Label_Manual ( TObject *Sender );
void __fastcall RoundRect1Click(TObject *Sender);
private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif

Nenhum comentário:

Postar um comentário

Observação: somente um membro deste blog pode postar um comentário.