Funções Solidtec

Revision:
1:392e0e10ccf7
Parent:
0:73f074c39876
--- 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;