Funções Solidtec

Files at this revision

API Documentation at this revision

Comitter:
marcusncunha
Date:
Tue Nov 06 16:28:00 2018 +0000
Parent:
0:73f074c39876
Commit message:
11_06_2018

Changed in this revision

tela.cpp Show annotated file Show diff for this revision Revisions of this file
tela.h Show annotated file Show diff for this revision Revisions of this file
--- a/tela.cpp	Fri Dec 08 19:15:28 2017 +0000
+++ b/tela.cpp	Tue Nov 06 16:28:00 2018 +0000
@@ -40,6 +40,11 @@
     desenharImagemKey(PICTURE, imagem, cor, xDaImagem, yDaImagem);
 }
 
+void desenhaBotao(uint32_t cor, botao *botaoObjeto){
+    _lcd.SetTextColor(cor);
+    _lcd.FillRect(botaoObjeto->retanguloObjeto.x, botaoObjeto->retanguloObjeto.y, botaoObjeto->retanguloObjeto.largura, botaoObjeto->retanguloObjeto.altura);
+}
+
 void desenhaCaixaMensagem(const unsigned long *PICTURE, dadosImagem imagem, uint32_t corDeBordaCaixa, uint32_t corDeFundoCaixa, dadosRetanguloBase *baseMensagem){
     int xDaImagem = baseMensagem->x + (baseMensagem->largura - imagem.largura) / 2;
     int yDaImagem = baseMensagem->y + (baseMensagem->altura - imagem.altura) / 2;
@@ -124,6 +129,109 @@
     }
 }
 
+void desenhaBotaoComLabel(string label, int tamanhoFonte, uint32_t corSemClickLabel, uint32_t corSemClick, botao *botaoObjeto){
+    int diferencaX = 0;
+    int diferencaY = 0;
+    switch(tamanhoFonte){
+        case 16:
+            _lcd.SetFont(&Font16);
+            diferencaX = label.length() * 12;
+            diferencaY = 15;
+        break;
+        case 20:
+            _lcd.SetFont(&Font20);
+            diferencaX = label.length() * 15;
+            diferencaY = 20;
+        break;
+        case 24:
+            _lcd.SetFont(&Font16);
+            diferencaX = label.length() * 18;
+            diferencaY = 25;
+        break;
+        default:
+            _lcd.SetFont(&Font12);
+            diferencaX = label.length() * 7;
+            diferencaY = 10;
+        break;
+    }
+    int xDoLabel = botaoObjeto->retanguloObjeto.x + (botaoObjeto->retanguloObjeto.largura - diferencaX) / 2;
+    int yDoLabel = botaoObjeto->retanguloObjeto.y + (botaoObjeto->retanguloObjeto.altura - diferencaY) / 2;
+    
+    desenhaBotao(corSemClick, botaoObjeto);
+    _lcd.SetTextColor(corSemClickLabel);
+    _lcd.SetBackColor(corSemClick);
+    _lcd.DisplayStringAt(xDoLabel, yDoLabel, (uint8_t *)label.c_str(), LEFT_MODE);
+}
+
+void iniciarBotaoComLabel(string label, int tamanhoFonte, uint32_t corSemClickLabel, uint32_t corComClickLabel, uint32_t corSemClick, uint32_t corComClick, botao *botaoObjeto, TS_StateTypeDef *toqueTela){
+    bool isDentroBotaoX = 0;
+    bool isDentroBotaoY = 0;
+    int diferencaX = 0;
+    int diferencaY = 0;
+    switch(tamanhoFonte){
+        case 16:
+            _lcd.SetFont(&Font16);
+            diferencaX = label.length() * 12;
+            diferencaY = 15;
+        break;
+        case 20:
+            _lcd.SetFont(&Font20);
+            diferencaX = label.length() * 15;
+            diferencaY = 20;
+        break;
+        case 24:
+            _lcd.SetFont(&Font16);
+            diferencaX = label.length() * 18;
+            diferencaY = 25;
+        break;
+        default:
+            _lcd.SetFont(&Font12);
+            diferencaX = label.length() * 7;
+            diferencaY = 10;
+        break;
+    }
+    int xDoLabel = botaoObjeto->retanguloObjeto.x + (botaoObjeto->retanguloObjeto.largura - diferencaX) / 2;
+    int yDoLabel = botaoObjeto->retanguloObjeto.y + (botaoObjeto->retanguloObjeto.altura - diferencaY) / 2;
+    uint16_t cliqueX = toqueTela->touchX[0];
+    uint16_t cliqueY = toqueTela->touchY[0];
+    
+    //Testar se foi na área do botão em x e marca o flag
+    if((cliqueX > botaoObjeto->retanguloObjeto.x) && (cliqueX < ( botaoObjeto->retanguloObjeto.x + botaoObjeto->retanguloObjeto.largura))){
+        isDentroBotaoX = 1;
+    }
+    
+    //Testar se foi na área do botão em y e marca o flag
+    if((cliqueY > botaoObjeto->retanguloObjeto.y) && (cliqueY < ( botaoObjeto->retanguloObjeto.y + botaoObjeto->retanguloObjeto.altura))){
+        isDentroBotaoY = 1;
+    }
+    
+    //Testa se está dentro da área do botão XY
+    if(isDentroBotaoX && isDentroBotaoY){
+        //Se ele não estava pressionado
+        if(!(botaoObjeto->isPressed)){
+            botaoObjeto->depressTime.start();
+            botaoObjeto->isPressed = 1;
+            desenhaBotao(corComClick, botaoObjeto);
+            _lcd.SetTextColor(corComClickLabel);
+            _lcd.SetBackColor(corComClick);
+            _lcd.DisplayStringAt(xDoLabel, yDoLabel, (uint8_t *)label.c_str(), LEFT_MODE);
+          }
+     }else{
+        //Se ele estava pressionado
+        if((botaoObjeto->isPressed)){
+            botaoObjeto->depressTime.stop();
+            botaoObjeto->isPressed = 0;
+            if(botaoObjeto->depressTime.read() > TEMPO_PRESSIONADO_BOTAO){
+                botaoObjeto->updateFlag = 1;
+            }
+            desenhaBotao(corSemClick, botaoObjeto);
+            _lcd.SetTextColor(corSemClickLabel);
+            _lcd.SetBackColor(corSemClick);
+            _lcd.DisplayStringAt(xDoLabel, yDoLabel, (uint8_t *)label.c_str(), LEFT_MODE);
+        }
+    }
+}
+
 void iniciarBotaoComImagemClick(const unsigned long *PICTURE, const unsigned long *PICTURECLK, dadosImagem imagem, dadosImagem imagemClk,uint32_t corSemClick, uint32_t corComClick, botao *botaoObjeto, TS_StateTypeDef *toqueTela){
     bool isDentroBotaoX = 0;
     bool isDentroBotaoY = 0;
--- a/tela.h	Fri Dec 08 19:15:28 2017 +0000
+++ b/tela.h	Tue Nov 06 16:28:00 2018 +0000
@@ -6,6 +6,7 @@
 #include "mbed.h"
 #include "LCD_DISCO_F746NG.h"
 #include "TS_DISCO_F746NG.h"
+#include <string> 
 
 //Constantes de Botão 
 #define TEMPO_PRESSIONADO_BOTAO 0.01000f
@@ -61,6 +62,8 @@
 ** Função desenhaBotaoComImagem desenha o botão retangular com a cor informada e coloca a imagem sobreposta com Key
 */
 void desenhaBotaoComImagem (const unsigned long *PICTURE, dadosImagem imagem, uint32_t cor, botao *botaoObjeto);
+
+void desenhaBotaoComLabel(string label, int tamanhoFonte, uint32_t corSemClickLabel, uint32_t corSemClick, botao *botaoObjeto);
 /*
 ** Função iniciarBotaoArea limita área de toque aonde cria um evento de botão. Para funcionar tem que gerar
 ** condição de update do flag e função de callback
@@ -90,6 +93,8 @@
 */
 void iniciarBotaoComImagem(const unsigned long *PICTURE, dadosImagem imagem, uint32_t corSemClick, uint32_t corComClick, botao *botaoObjeto, TS_StateTypeDef *toqueTela);
 
+void iniciarBotaoComLabel(string label, int tamanhoFonte, uint32_t corSemClickLabel, uint32_t corComClickLabel, uint32_t corSemClick, uint32_t corComClick, botao *botaoObjeto, TS_StateTypeDef *toqueTela);
+
 void iniciarBotaoComImagemClick(const unsigned long *PICTURE, const unsigned long *PICTURECLK, dadosImagem imagem, dadosImagem imagemClk,uint32_t corSemClick, uint32_t corComClick, botao *botaoObjeto, TS_StateTypeDef *toqueTela);
 
 /*