Guest GuiGa Denunciar mensagem Publicado 2 de Fevereiro de 2013 (editado) Titulo do Projeto: ElementoFace Última Versão: 1.0 Licença: GPL GNU Líder do Projecto: @GuiGa Descrição do Projecto: A unit ElementoFace oferece recursos úteis para criação de layouts baseado em ASCII para console. Painéis, retângulos, quadros sombreados, botões com movimento e outros itens são disponibilizados para a criação de design mais agradáveis. Cada componente criado é gerenciado como um elemento facilmente manipulável e modelável. Com poucas linhas de código, telas repletas de recursos visuais são facilmente desenhadas. Download do código fonte, exemplos e manual Exemplos: Program Teste1; Uses elementoFace, crt; Begin DefinePadroesElementoFace; CriaElemento('ID~PAINEL1|TIPO~PAINEL|STAT~ATIVO|SECAO~TelaCaixas|ORDEM~1|PCOL~1|PLIN~1|DCOL~80|DLIN~25|CORA~2|CONT~NAO|SOMB~NAO|TEXT~Caixas'); CriaElemento('ID~ImgCaixas|TIPO~IMAGEMPTZ|STAT~ATIVO|SECAO~TelaCaixas|ORDEM~2|PCOL~10|PLIN~9|CAMI~.\Caixas'); InvocaElemento('SECAO~TelaCaixas'); ReadKey; End. Resulta em: Program Teste1; Uses elementoFace, crt; Var strA : string; Procedure InicializaElementos; Begin DefinePadroesElementoFace; CriaElemento('ID~PAINEL1|TIPO~PAINEL|STAT~ATIVO|SECAO~TELAINICIAL|ORDEM~1|PCOL~1|PLIN~1|DCOL~80|DLIN~25|CORA~7|CONT~NAO|SOMB~NAO|TEXT~EFace'); CriaElemento('ID~PAINEL2|TIPO~PAINEL|STAT~ATIVO|SECAO~2|ORDEM~1|PCOL~1|PLIN~1|DCOL~80|DLIN~25|CORA~7|CONT~NAO|SOMB~NAO|TEXT~Elementos'); CriaElemento('ID~PAINEL3|TIPO~PAINEL|STAT~ATIVO|SECAO~3|ORDEM~1|PCOL~1|PLIN~1|DCOL~80|DLIN~25|CORA~7|CONT~NAO|SOMB~NAO|TEXT~Simulacao'); CriaElemento('ID~PAINEL4|TIPO~PAINEL|STAT~ATIVO|SECAO~4|ORDEM~1|PCOL~1|PLIN~1|DCOL~80|DLIN~25|CORA~7|CONT~NAO|SOMB~NAO|TEXT~Configuracao'); CriaElemento('ID~PAINEL5|TIPO~PAINEL|STAT~ATIVO|SECAO~NOMEPROJETO|ORDEM~1|PCOL~20|PLIN~5|DCOL~40|DLIN~12|CORA~7|CONT~SIM|SOMB~SIM|TEXT~Nome do Projeto'); CriaElemento('ID~BOTAO1|TIPO~BOTAO|STAT~ATIVO|SECAO~TELAINICIAL|ORDEM~3|PCOL~30|PLIN~4|DCOL~18|DLIN~3|CORA~7|CORB~7|CORC~16|SOMB~SIM|DIMT~NAO|TEXT~Novo Projeto|ACAO~INERTE'); CriaElemento('ID~BOTAO2|TIPO~BOTAO|STAT~ATIVO|SECAO~TELAINICIAL|ORDEM~4|PCOL~30|PLIN~9|DCOL~18|DLIN~3|CORA~7|CORB~7|CORC~16|SOMB~SIM|DIMT~NAO|TEXT~Carregar Projeto|ACAO~INERTE'); CriaElemento('ID~BOTAO3|TIPO~BOTAO|STAT~ATIVO|SECAO~TELAINICIAL|ORDEM~5|PCOL~30|PLIN~14|DCOL~18|DLIN~3|CORA~7|CORB~7|CORC~16|SOMB~SIM|DIMT~NAO|TEXT~Ajuda|ACAO~INERTE'); CriaElemento('ID~BOTAO4|TIPO~BOTAO|STAT~ATIVO|SECAO~TELAINICIAL|ORDEM~6|PCOL~30|PLIN~19|DCOL~18|DLIN~3|CORA~7|CORB~7|CORC~16|SOMB~SIM|DIMT~NAO|TEXT~Sobre|ACAO~INERTE'); CriaElemento('ID~BOTAO5|TIPO~BOTAO|STAT~ATIVO|SECAO~NOMEPROJETO|ORDEM~3|PCOL~31|PLIN~13|DCOL~16|DLIN~1|CORA~7|CORB~7|CORC~16|SOMB~SIM|DIMT~NAO|TEXT~OK|ACAO~INERTE'); CriaElemento('ID~CAMPO1|TIPO~CAMPO|STAT~ATIVO|SECAO~NOMEPROJETO|ORDEM~2|PCOL~22|PLIN~7|DCOL~34|DLIN~1|CORA~16|CORB~7|CORC~16|SOMB~SIM|ORIE~VERT|DIMT~NAO|TEXT~Nome:|ACAO~INERTE'); End; Begin CursorOff; InicializaElementos; InvocaElemento('SECAO~TELAINICIAL'); readkey; FocaElemento('ID~BOTAO1|ACAO~PRESS'); InvocaElemento('SECAO~NOMEPROJETO'); gotoxy(ObtemDadoElementoInt('ID~CAMPO1', 'PCOL') + 1, ObtemDadoElementoInt('ID~CAMPO1', 'PLIN') + 2); strA := LeDado(strA, ObtemDadoElementoInt('ID~CAMPO1', 'DCOL')); InvocaElemento('ID~BOTAO5|ACAO~PRESS'); readkey; End. Resulta em: Program EFace; Uses elementoFace, crt; Var tecla, strA, strB, strC: string; intA, intB, lin : integer; Procedure InicializaElementos; Begin CriaElemento('ID~PAINEL1|TIPO~PAINEL|STAT~ATIVO|SECAO~TelaBotoes|ORDEM~1|PCOL~1|PLIN~1|DCOL~80|DLIN~25|CORA~7|CONT~NAO|SOMB~NAO|TEXT~Exemplo EFace'); CriaElemento('ID~IMAGEM|TIPO~IMAGEMPTZ|STAT~ATIVO|SECAO~TelaBotoes|ORDEM~2|PCOL~7|PLIN~4|CAMI~.\GRADE'); CriaElemento('ID~BOTAOA11|TIPO~BOTAO|STAT~ATIVO|SECAO~TelaBotoes|ORDEM~3|PCOL~57|PLIN~4|DCOL~6|DLIN~1|CORA~7|CORB~7|CORC~16|SOMB~SIM|TEXT~Editar|ACAO~INERTE'); CriaElemento('ID~BOTAOA12|TIPO~BOTAO|STAT~ATIVO|SECAO~TelaBotoes|ORDEM~4|PCOL~57|PLIN~7|DCOL~6|DLIN~1|CORA~7|CORB~7|CORC~16|SOMB~SIM|TEXT~Editar|ACAO~INERTE'); CriaElemento('ID~BOTAOA13|TIPO~BOTAO|STAT~ATIVO|SECAO~TelaBotoes|ORDEM~5|PCOL~57|PLIN~10|DCOL~6|DLIN~1|CORA~7|CORB~7|CORC~16|SOMB~SIM|TEXT~Editar|ACAO~INERTE'); CriaElemento('ID~BOTAOA14|TIPO~BOTAO|STAT~ATIVO|SECAO~TelaBotoes|ORDEM~6|PCOL~57|PLIN~13|DCOL~6|DLIN~1|CORA~7|CORB~7|CORC~16|SOMB~SIM|TEXT~Editar|ACAO~INERTE'); CriaElemento('ID~BOTAOA15|TIPO~BOTAO|STAT~ATIVO|SECAO~TelaBotoes|ORDEM~7|PCOL~57|PLIN~16|DCOL~6|DLIN~1|CORA~7|CORB~7|CORC~16|SOMB~SIM|TEXT~Editar|ACAO~INERTE'); CriaElemento('ID~BOTAOA21|TIPO~BOTAO|STAT~ATIVO|SECAO~TelaBotoes|ORDEM~8|PCOL~65|PLIN~4|DCOL~7|DLIN~1|CORA~7|CORB~7|CORC~16|SOMB~SIM|TEXT~Excluir|ACAO~INERTE'); CriaElemento('ID~BOTAOA22|TIPO~BOTAO|STAT~ATIVO|SECAO~TelaBotoes|ORDEM~9|PCOL~65|PLIN~7|DCOL~7|DLIN~1|CORA~7|CORB~7|CORC~16|SOMB~SIM|TEXT~Excluir|ACAO~INERTE'); CriaElemento('ID~BOTAOA23|TIPO~BOTAO|STAT~ATIVO|SECAO~TelaBotoes|ORDEM~10|PCOL~65|PLIN~10|DCOL~7|DLIN~1|CORA~7|CORB~7|CORC~16|SOMB~SIM|TEXT~Excluir|ACAO~INERTE'); CriaElemento('ID~BOTAOA24|TIPO~BOTAO|STAT~ATIVO|SECAO~TelaBotoes|ORDEM~11|PCOL~65|PLIN~13|DCOL~7|DLIN~1|CORA~7|CORB~7|CORC~16|SOMB~SIM|TEXT~Excluir|ACAO~INERTE'); CriaElemento('ID~BOTAOA25|TIPO~BOTAO|STAT~ATIVO|SECAO~TelaBotoes|ORDEM~12|PCOL~65|PLIN~16|DCOL~7|DLIN~1|CORA~7|CORB~7|CORC~16|SOMB~SIM|TEXT~Excluir|ACAO~INERTE'); CriaElemento('ID~BOTAOA16|TIPO~BOTAO|STAT~ATIVO|SECAO~TelaBotoes|ORDEM~13|PCOL~7|PLIN~19|DCOL~12|DLIN~1|CORA~7|CORB~7|CORC~16|SOMB~SIM|TEXT~Acima|ACAO~INERTE'); CriaElemento('ID~BOTAOA26|TIPO~BOTAO|STAT~ATIVO|SECAO~TelaBotoes|ORDEM~14|PCOL~21|PLIN~19|DCOL~12|DLIN~1|CORA~7|CORB~7|CORC~16|SOMB~SIM|TEXT~Abaixo|ACAO~INERTE'); CriaElemento('ID~BOTAOA17|TIPO~BOTAO|STAT~ATIVO|SECAO~TelaBotoes|ORDEM~15|PCOL~7|PLIN~22|DCOL~12|DLIN~1|CORA~7|CORB~7|CORC~14|SOMB~SIM|TEXT~Leia isto|ACAO~INERTE'); CriaElemento('ID~BOTAOA27|TIPO~BOTAO|STAT~ATIVO|SECAO~TelaBotoes|ORDEM~16|PCOL~21|PLIN~22|DCOL~12|DLIN~1|CORA~7|CORB~7|CORC~16|SOMB~SIM|TEXT~Sair|ACAO~INERTE'); CriaElemento('ID~PAINEL2|TIPO~PAINEL|STAT~ATIVO|SECAO~ExibeTexto|ORDEM~1|PCOL~20|PLIN~6|DCOL~40|DLIN~15|CORA~3|CONT~SIM|SOMB~SIM|TEXT~Novo elemento'); CriaElemento('ID~TEXTO1|TIPO~TEXTO|STAT~ATIVO|SECAO~ExibeTexto|ORDEM~2|PCOL~22|PLIN~8|DCOL~35|DLIN~12|CORA~15|CORB~3|CAMI~.\TextoTeste.txt|REFL~1'); End; Begin InicializaElementos; DefinePadroesElementoFace; InvocaElemento('SECAO~TelaBotoes'); intA := 1; intB := 1; strA := '1'; strB := '1'; tecla := TECLA_UP; while (true) do begin if tecla <> ID_NULL then begin if (tecla = TECLA_UP) and (intB > 1) then dec(intB) else if (tecla = TECLA_DOWN) and (intB < 7) then inc(intB) else if (tecla = TECLA_RIGHT) and (intA < 2) then inc(intA) else if (tecla = TECLA_LEFT) and (intA > 1) then dec(intA); if (tecla = TECLA_ENTER) then begin FocaElemento(concat('ID~BOTAOA', strA, strB, '|ACAO~PRESS|CORC~15')); if (intA = 1) then begin if (intB = 7) then begin InvocaElemento('SECAO~ExibeTexto'); lin := ObtemDadoElementoInt('ID~TEXTO1', 'REFL'); repeat tecla := ObtemTeclaPressionada; if tecla <> ID_NULL then begin if (tecla = TECLA_UP) and (lin > 1) then dec(lin) else if (tecla = TECLA_DOWN) then inc(lin); str(lin, strC); InvocaElemento(concat('ID~TEXTO1|REFL~', strC)); end; until(tecla = TECLA_ESC); InvocaElemento('SECAO~TelaBotoes'); end else begin end; end else begin if (intB = 7) then begin Exit; end else begin end; end; end else begin str(intA, strA); str(intB, strB); FocaElemento(concat('ID~BOTAOA', strA, strB, '|SOMB~NAO')); end; end; tecla := ObtemTeclaPressionada; end; End. Resulta em: Editado 2 de Fevereiro de 2013 por GuiGa Partilhar esta mensagem Ligação para a mensagem Partilhar noutros sites
thoga31 610 Denunciar mensagem Publicado 2 de Fevereiro de 2013 Sugestão: fazer uma implementação com OOP para que nos programas fossem criadas instâncias independentes dos componentes. Knowledge is free! Partilhar esta mensagem Ligação para a mensagem Partilhar noutros sites
Guest GuiGa Denunciar mensagem Publicado 2 de Fevereiro de 2013 (editado) Sugestão: fazer uma implementação com OOP para que nos programas fossem criadas instâncias independentes dos componentes. Olá Sr. @Thoga. Não entendi muito bem a sugestão. Poderia explicar mais? Também não sou bem ambientado com o paradigma orientado à objetos. Editado 2 de Fevereiro de 2013 por GuiGa 2x quote Partilhar esta mensagem Ligação para a mensagem Partilhar noutros sites
thoga31 610 Denunciar mensagem Publicado 2 de Fevereiro de 2013 Primeiro que nada, o Senhor está no Céu A minha sugestão é simples: se recorreres a OOP, o programador estará apto a criar instâncias dos componentes e controlá-los e personalizá-los individualmente. BotaoSair := TBotao.Create(3, 5, 'Sair'); BotaoSair.Mostrar; BotaoSair.CorFundo := WHITE; // ... BotaoSair.Free; O paradigma estrutural não é o melhor para este tipo de projectos. Por exemplo, eu criei uma calculadora gráfica em Object Pascal, onde podes ter no mesmo programa várias instâncias dessa calculadora, cada uma delas totalmente diferente da outra, e cada uma delas controlada individualmente. Investiga melhor o paradigma OOP Knowledge is free! Partilhar esta mensagem Ligação para a mensagem Partilhar noutros sites
Guest GuiGa Denunciar mensagem Publicado 2 de Fevereiro de 2013 (editado) Primeiro que nada, o Senhor está no Céu A minha sugestão é simples: se recorreres a OOP, o programador estará apto a criar instâncias dos componentes e controlá-los e personalizá-los individualmente. BotaoSair := TBotao.Create(3, 5, 'Sair'); BotaoSair.Mostrar; BotaoSair.CorFundo := WHITE; // ... BotaoSair.Free; O paradigma estrutural não é o melhor para este tipo de projectos. Por exemplo, eu criei uma calculadora gráfica em Object Pascal, onde podes ter no mesmo programa várias instâncias dessa calculadora, cada uma delas totalmente diferente da outra, e cada uma delas controlada individualmente. Investiga melhor o paradigma OOP A sim! Entendi perfeitamente. É uma ótima ideia. Talvez eu remodele a unit em breve. Você deu uma olhada no manual? Lá é possível perceber que apesar de não utilizar o conceito orientado a objetos, é possível personalizar de forma individual os componentes. Adaptando seu exemplo: CriaElemento('TIPO~botao|ID~botao1|PCOL~10|PLIN~10|DCOL~auto|DLIN~1|CORA~7|CORB~7|CORC~14|SOMB~sim|ACAO~inerte'); //Cria o botão InvocaElemento('ID~botao1'); //Exibe o botão AlteraDadoElemento('ID~botao1', 'CORC~15'); //Altera a cor do texto para branca //... DestroiElemento('ID~botao1'); //Remove o elemento Apesar de os métodos não estarem dentro do próprio elemento, estes podem ser alterados com grande facilidade e intuitividade. Obrigado pela sugestão. Editado 2 de Fevereiro de 2013 por thoga31 2x quote Partilhar esta mensagem Ligação para a mensagem Partilhar noutros sites
thoga31 610 Denunciar mensagem Publicado 2 de Fevereiro de 2013 (editado) Eu entendi o teu conceito, mas se compararmos o teu código com o bocado que eu inventei, logo se percebe qual o mais intuitivo e fácil de manusear. Fica aqui um excelente exemplo de como se utilizar o paradigma estrutural para estas coisas. Mas agora o meu conselho é tu estudares um pouco de Object Pascal. P.S. - evita fazer quotes duplos. Basta clicar uma vez no botão "Citar". Editado 2 de Fevereiro de 2013 por thoga31 Knowledge is free! Partilhar esta mensagem Ligação para a mensagem Partilhar noutros sites