Advertisement
Runer112

lcdGUI.cpp

Aug 10th, 2012
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <MI0283QT2.h>
  2. #include <ADS7846.h>
  3. #include <fonts.h>
  4.  
  5. #include "lcdGUI.h"
  6.  
  7. #ifdef BUTTON
  8. #ifndef lcdGUI_BUTTON
  9. #define lcdGUI_BUTTON
  10. void Gui::addButton(uint16_t _left, uint16_t _top, uint16_t _width, uint16_t _height, char * _caption, uint8_t _size,uint8_t _id)
  11. {
  12.   Button * btn = (Button*)malloc(sizeof(Button));
  13.  
  14.   if(btn != NULL)
  15.   {
  16.     btn->next          = NULL;
  17.     btn->x             = _left;
  18.     btn->y             = _top;
  19.     btn->width         = _width;
  20.     btn->height        = _height;
  21.     btn->size          = _size;
  22.  
  23.     if (strlen(_caption) == 0)
  24.       btn->text = NULL;
  25.     else
  26.     {
  27.       btn->text = (char *)malloc(strlen(_caption) + 1);
  28.       if (btn->text != NULL)
  29.         strcpy(btn->text, _caption);
  30.     }
  31.    
  32.     btn->id            = _id;
  33.    
  34.     if (btnPtr == NULL)
  35.       btnPtr = btn;
  36.     else
  37.       lastBtnPtr->next = btn;
  38.    
  39.     lastBtnPtr = btn;
  40.   }
  41.   btn->draw(lcd, false);
  42. }
  43. #endif
  44. #endif
  45.  
  46. #ifndef lcdGUI_cpp
  47. #define lcdGUI_cpp
  48.  
  49. void buttonPressed(Button*);
  50. void buttonReleased(Button*);
  51. void sliderValueChanged(Slider*);
  52.  
  53. Gui::Gui(lcdPtr _lcd, tpPtr _tp)
  54. {
  55.   lcd = _lcd;
  56.   tp = _tp;
  57. }
  58.  
  59. void Gui::addTextbox(uint16_t X, uint16_t Y, uint16_t W, char * T, char * DFT, uint8_t S, uint8_t ID)
  60. {
  61.   TextBox * txtBox = (TextBox*)malloc(sizeof(TextBox));
  62.  
  63.   if(txtBox != NULL)
  64.   {
  65.     txtBox->x = X;
  66.     txtBox->y = Y;
  67.     txtBox->width = W;
  68.     txtBox->id = ID;
  69.     txtBox->size = S;
  70.     txtBox->next = NULL;
  71.   }
  72.  
  73.   if(strlen(T) == 0)
  74.     txtBox->text = NULL;
  75.   else
  76.   {
  77.     txtBox->text = (char*)malloc(strlen(T)+1);
  78.     if(txtBox->text != NULL)
  79.       strcpy(txtBox->text, T);
  80.   }
  81.  
  82.   if(strlen(DFT) == 0)
  83.     txtBox->defaultText = NULL;
  84.   else
  85.   {
  86.     txtBox->defaultText = (char*)malloc(strlen(DFT)+1);
  87.     if(txtBox->defaultText != NULL)
  88.       strcpy(txtBox->defaultText, DFT);
  89.   }
  90.  
  91.   if(txtPtr == NULL)
  92.     txtPtr = txtBox;
  93.   else
  94.     lastTxtPtr->next = txtBox;
  95.  
  96.   lastTxtPtr = txtBox;
  97.  
  98.   txtBox->draw(lcd, false);
  99. }
  100.  
  101. void Gui::addSlider(uint16_t X, uint16_t Y, uint16_t W, uint16_t H, float V, uint8_t ID)
  102. {
  103.   Slider * sld = (Slider*)malloc(sizeof(Slider));
  104.  
  105.   if(sld != NULL)
  106.   {
  107.     sld->x = X;
  108.     sld->y = Y;
  109.     sld->width = W;
  110.     sld->height = H;
  111.     sld->value = V;
  112.     sld->id = ID;
  113.     sld->next = NULL;
  114.   }
  115.  
  116.   if(sldPtr == NULL)
  117.     sldPtr = sld;
  118.   else
  119.     lastSldPtr->next = sld;
  120.    
  121.   lastSldPtr = sld;
  122.   sld->draw(lcd, false);
  123. }
  124.  
  125. void Gui::addStatusBar(char * T, uint8_t S)
  126. {
  127.   if(statBarPtr == NULL)
  128.   {
  129.     StatusBar * stbr = (StatusBar*)malloc(sizeof(StatusBar));
  130.     if(stbr != NULL)
  131.     {
  132.       if(strlen(T) == NULL)
  133.         return;
  134.       else
  135.       {
  136.         stbr->size = S;
  137.         stbr->text = (char*)malloc(strlen(T)+1);
  138.         if(stbr->text != NULL)
  139.           strcpy(stbr->text, T);
  140.       }
  141.     }
  142.     statBarPtr = stbr;
  143.     stbr->draw(lcd);
  144.   }
  145. }
  146.  
  147. void Gui::addCheckbox(uint16_t X, uint16_t Y, char * T, bool A, uint8_t ID)
  148. {
  149.   CheckBox * chk = (CheckBox*)malloc(sizeof(CheckBox));
  150.  
  151.   if(chk != NULL)
  152.   {
  153.     chk->x = X;
  154.     chk->y = Y;
  155.     chk->isActive = A;
  156.     chk->next = NULL;
  157.     chk->id = ID;
  158.     if(strlen(T) == 0)
  159.       chk->text = NULL;
  160.     else
  161.     {
  162.       chk->text  = (char*)malloc(strlen(T)+1);
  163.       if(chk->text != NULL)
  164.         strcpy(chk->text, T);
  165.     }
  166.     if(chkPtr == NULL)
  167.       chkPtr = chk;
  168.     else
  169.       lastChkPtr->next = chk;
  170.    
  171.     lastChkPtr = chk;
  172.    
  173.     chk->draw(lcd, false);
  174.   }
  175. }
  176.  
  177. void Gui::service(bool draw)
  178. {  
  179.   if(draw)
  180.   {
  181.     lcd->clear(COLOR_BG);
  182.    
  183.     //draw statusbar
  184.     if(statBarPtr != NULL)
  185.       statBarPtr->draw(lcd);
  186.     //draw buttons
  187.     Button * tmpBtnPtr = btnPtr;
  188.     while(tmpBtnPtr != NULL)
  189.     {
  190.       tmpBtnPtr->draw(lcd, false);
  191.       tmpBtnPtr = tmpBtnPtr->next;
  192.     }
  193.     //draw textboxes
  194.     TextBox * tmpTxtPtr = txtPtr;
  195.     while(tmpTxtPtr != NULL)
  196.     {
  197.       tmpTxtPtr->draw(lcd, false);
  198.       tmpTxtPtr = tmpTxtPtr->next;
  199.     }
  200.     //draw sliders
  201.     Slider * tmpSldPtr = sldPtr;
  202.     while(tmpSldPtr != NULL)
  203.     {
  204.       tmpSldPtr->draw(lcd, false);
  205.       tmpSldPtr = tmpSldPtr->next;
  206.     }
  207.     //draw checkboxes
  208.     CheckBox * tmpChkPtr = chkPtr;
  209.     while(tmpChkPtr != NULL)
  210.     {
  211.       tmpChkPtr->draw(lcd, false);
  212.       tmpChkPtr = tmpChkPtr->next;
  213.     }
  214.   }
  215.  
  216.   //check buttons
  217.   tp->service();
  218.  
  219.   uint8_t currPress = tp->getPressure();
  220.  
  221.   if(currPress > MIN_PRESSURE)
  222.   {
  223.     //check buttons
  224.     Button * btn = buttonFromPos(tp->getX(), tp->getY());
  225.     if(lastBtnPressed != btn && lastBtnPressed != NULL)
  226.     {
  227.       lastBtnPressed->draw(lcd, false);
  228.       if(lastBtnPressed == buttonFromPos(tp->getX(), tp->getY()))
  229.         buttonReleased(lastBtnPressed);
  230.       lastBtnPressed = NULL;
  231.     }
  232.     if(btn != NULL && btn != lastBtnPressed)
  233.     {
  234.       btn->draw(lcd, true);
  235.       lastBtnPressed = btn;
  236.       buttonPressed(btn);
  237.     }
  238.    
  239.     //check textboxes
  240.     TextBox * txt = textboxFromPos(tp->getX(), tp->getY());
  241.     if(lastTxtPressed != txt && lastTxtPressed != NULL)
  242.     {
  243.       lastTxtPressed->draw(lcd, false);
  244.       lastTxtPressed = NULL;
  245.     }
  246.     if(txt != NULL && txt != lastTxtPressed)
  247.     {
  248.       txt->draw(lcd, true);
  249.       lastTxtPressed = txt;
  250.     }
  251.    
  252.     //check sliders
  253.     Slider * sld = sliderFromPos(tp->getX(), tp->getY());
  254.     if(sld != NULL)
  255.     {
  256.       float oldVal = sld->value;
  257.       sld->value = (float)(tp->getX()-sld->x)/sld->width*1024;
  258.       if(oldVal != sld->value)
  259.         sliderValueChanged(sld);
  260.     }
  261.     if(lastSldPressed != sld && lastSldPressed != NULL)
  262.     {
  263.       lastSldPressed->draw(lcd, false);
  264.       lastSldPressed = NULL;
  265.     }
  266.     if(sld != NULL && sld != lastSldPressed)
  267.     {
  268.       sld->draw(lcd, true);
  269.       lastSldPressed = sld;
  270.     }
  271.     if(sld != NULL && sld == lastSldPressed)
  272.       sld->draw(lcd, true);
  273.    
  274.     //check checkboxes
  275.     CheckBox * chk = checkboxFromPos(tp->getX(), tp->getY());
  276.     if(lastChkPressed != chk && lastChkPressed != NULL)
  277.     {
  278.       lastChkPressed->draw(lcd, false);
  279.       lastChkPressed = NULL;
  280.     }
  281.     if(chk != NULL && chk != lastChkPressed)
  282.     {
  283.       chk->isActive = !chk->isActive;
  284.       chk->draw(lcd, true);
  285.       lastChkPressed = chk;
  286.     }
  287.    
  288.   }
  289.   else
  290.   {
  291.     //deselect selected buttons
  292.     if(lastBtnPressed != NULL)
  293.     {
  294.       buttonReleased(lastBtnPressed);
  295.       lastBtnPressed->draw(lcd, false);
  296.       lastBtnPressed = NULL;
  297.     }
  298.     //deselect selected sliders
  299.     if(lastSldPressed != NULL)
  300.     {
  301.       lastSldPressed->draw(lcd, false);
  302.       lastSldPressed = NULL;
  303.     }
  304.    
  305.     if(lastChkPressed != NULL)
  306.     {
  307.       lastChkPressed->draw(lcd, false);
  308.       lastChkPressed = NULL;
  309.     }
  310.   }
  311. }
  312.  
  313. void Gui::service()
  314. {
  315.   service(false);
  316. }
  317.  
  318. void Gui::refresh()
  319. {
  320.   service(true);
  321. }
  322.  
  323. void Gui::deleteButton(Button * _button)
  324. {
  325.   if (_button != NULL)
  326.   {
  327.     lcd->fillRect(_button->x, _button->y, _button->x + _button->width, _button->y + _button->height, COLOR_BG);
  328.    
  329.     Button * btn  = btnPtr;
  330.     Button * prev = NULL;
  331.     while (btn != NULL)
  332.     {
  333.       if (btn == _button)
  334.       {
  335.         if (prev == NULL)
  336.           btnPtr = btn->next;
  337.         else
  338.           prev->next = btn->next;
  339.        
  340.         if (btn->text != NULL)
  341.           free(btn->text);
  342.        
  343.         free(btn);
  344.         return;
  345.       }
  346.       prev = btn;
  347.       btn  = btn->next;
  348.     }
  349.   }
  350. }
  351.  
  352. void Gui::deleteTextbox(TextBox * txt)
  353. {
  354.   if (txt != NULL)
  355.   {
  356.     lcd->fillRect(txt->x, txt->y, txt->x + txt->width, txt->y + FONT_HEIGHT+4, COLOR_BG);
  357.    
  358.     TextBox * tmpTxtPtr  = txtPtr;
  359.     TextBox * prev = NULL;
  360.     while (tmpTxtPtr != NULL)
  361.     {
  362.       if (tmpTxtPtr == txt)
  363.       {
  364.         if (prev == NULL)
  365.           txtPtr = tmpTxtPtr->next;
  366.         else
  367.           prev->next = tmpTxtPtr->next;
  368.        
  369.         if (tmpTxtPtr->text != NULL)
  370.           free(tmpTxtPtr->text);
  371.         if(tmpTxtPtr->defaultText != NULL)
  372.           free(tmpTxtPtr->defaultText);
  373.        
  374.         free(tmpTxtPtr);
  375.         return;
  376.       }
  377.       prev = tmpTxtPtr;
  378.       tmpTxtPtr  = tmpTxtPtr->next;
  379.     }
  380.   }
  381. }
  382.  
  383. void Gui::deleteSlider(Slider * sld)
  384. {
  385.   if (sld != NULL)
  386.   {
  387.     lcd->fillRect(sld->x, sld->y, sld->x + sld->width, sld->y + sld->height, COLOR_BG);
  388.    
  389.     Slider * tmpSldPtr  = sldPtr;
  390.     Slider * prev = NULL;
  391.     while (tmpSldPtr != NULL)
  392.     {
  393.       if (tmpSldPtr == sld)
  394.       {
  395.         if (prev == NULL)
  396.           sldPtr = tmpSldPtr->next;
  397.         else
  398.           prev->next = tmpSldPtr->next;
  399.  
  400.         free(tmpSldPtr);
  401.         return;
  402.       }
  403.       prev = tmpSldPtr;
  404.       tmpSldPtr  = tmpSldPtr->next;
  405.     }
  406.   }
  407. }
  408.  
  409. void Gui::deleteStatusbar()
  410. {
  411.   if(statBarPtr != NULL)
  412.   {
  413.     lcd->fillRect(0,0,lcd->getWidth(),statBarPtr->size*FONT_HEIGHT+4,COLOR_BG);
  414.     free(statBarPtr->text);
  415.     free(statBarPtr);
  416.     statBarPtr = NULL;
  417.   }
  418. }
  419.  
  420. void Gui::deleteCheckbox(CheckBox * chk)
  421. {
  422.   if (chk != NULL)
  423.   {
  424.     lcd->fillRect(chk->x, chk->y, chk->x + strlen(chk->text)*FONT_WIDTH+FONT_HEIGHT+10, chk->y + FONT_HEIGHT+4, COLOR_BG);
  425.    
  426.     CheckBox * tmpChkPtr  = chkPtr;
  427.     CheckBox * prev = NULL;
  428.     while (tmpChkPtr != NULL)
  429.     {
  430.       if (tmpChkPtr == chk)
  431.       {
  432.         if (prev == NULL)
  433.           chkPtr = tmpChkPtr->next;
  434.         else
  435.           prev->next = tmpChkPtr->next;
  436.        
  437.         if (tmpChkPtr->text != NULL)
  438.           free(tmpChkPtr->text);
  439.        
  440.         free(tmpChkPtr);
  441.         return;
  442.       }
  443.       prev = tmpChkPtr;
  444.       tmpChkPtr  = tmpChkPtr->next;
  445.     }
  446.   }
  447. }
  448.  
  449. Button * Gui::buttonFromId(uint8_t _id)
  450. {
  451.   Button * btn = btnPtr;
  452.  
  453.   while (btn != NULL)
  454.   {
  455.     if (btn->id == _id)
  456.         return btn;
  457.     btn = (Button*)btn->next;
  458.   }
  459.   return NULL;
  460. }
  461.  
  462. TextBox * Gui::textboxFromId(uint8_t _id)
  463. {
  464.   TextBox * txt = txtPtr;
  465.  
  466.   while (txt != NULL)
  467.   {
  468.     if (txt->id == _id)
  469.         return txt;
  470.     txt = (TextBox*)txt->next;
  471.   }
  472.   return NULL;
  473. }
  474.  
  475. Slider * Gui::sliderFromId(uint8_t _id)
  476. {
  477.   Slider * sld = sldPtr;
  478.  
  479.   while (sld != NULL)
  480.   {
  481.     if (sld->id == _id)
  482.         return sld;
  483.     sld = (Slider*)sld->next;
  484.   }
  485.   return NULL;
  486. }
  487.  
  488. CheckBox * Gui::checkboxFromId(uint8_t _id)
  489. {
  490.   CheckBox * chk = chkPtr;
  491.  
  492.   while (chk != NULL)
  493.   {
  494.     if (chk->id == _id)
  495.         return chk;
  496.     chk = (CheckBox*)chk->next;
  497.   }
  498.   return NULL;
  499. }
  500.  
  501. Button * Gui::buttonFromPos(uint16_t _x, uint16_t _y)
  502. {
  503.   Button * btn = (Button*)btnPtr;
  504.   while (btn != NULL)
  505.   {
  506.     if ((_x >= btn->x) && (_x < btn->x + btn->width) &&
  507.         (_y >= btn->y)  && (_y < btn->y  + btn->height))
  508.     {
  509.       return btn;
  510.     }
  511.     btn = (Button*)btn->next;
  512.   }
  513.   return NULL;
  514. }
  515.  
  516. TextBox * Gui::textboxFromPos(uint16_t _x, uint16_t _y)
  517. {
  518.   TextBox * txt = (TextBox*)txtPtr;
  519.   while (txt != NULL)
  520.   {
  521.     uint16_t height = FONT_HEIGHT*txt->size+4;
  522.     if ((_x >= txt->x) && (_x < txt->x + txt->width) &&
  523.         (_y >= txt->y)  && (_y < txt->y  + height))
  524.     {
  525.       return txt;
  526.     }
  527.     txt = (TextBox*)txt->next;
  528.   }
  529.   return NULL;
  530. }
  531.  
  532. Slider * Gui::sliderFromPos(uint16_t _x, uint16_t _y)
  533. {
  534.   Slider * sld = sldPtr;
  535.   while (sld != NULL)
  536.   {
  537.     if ((_x >= sld->x) && (_x < sld->x + sld->width) &&
  538.         (_y >= sld->y)  && (_y < sld->y  + sld->height))
  539.     {
  540.       return sld;
  541.     }
  542.     sld = sld->next;
  543.   }
  544.   return NULL;
  545. }
  546.  
  547. CheckBox * Gui::checkboxFromPos(uint16_t _x, uint16_t _y)
  548. {
  549.   CheckBox * chk = chkPtr;
  550.   while (chk != NULL)
  551.   {
  552.     if ((_x >= chk->x) && (_x < chk->x + strlen(chk->text)*FONT_WIDTH+FONT_HEIGHT+10) &&
  553.         (_y >= chk->y)  && (_y < chk->y  + FONT_HEIGHT+2))
  554.     {
  555.       return chk;
  556.     }
  557.     chk = chk->next;
  558.   }
  559.   return NULL;
  560. }
  561.  
  562.  
  563. /*
  564. --------------------------------------------
  565. BUTTON
  566. --------------------------------------------
  567. */
  568.  
  569. void Button::draw(lcdPtr lcd, bool isDown)
  570. {
  571.   uint16_t clr = (isDown) ? COLOR_BUTTON_PRESSED : COLOR_BUTTON;
  572.   uint16_t clrUpLine = (isDown) ? COLOR_BUTTON_PRESSED_UPPERLINE : COLOR_BUTTON_UPPERLINE;
  573.   uint16_t clrLwLine = (isDown) ? COLOR_BUTTON_PRESSED_LOWERLINE : COLOR_BUTTON_LOWERLINE;
  574.   lcd->fillRect(x, y+1, x + width, y + height-1, clr);
  575.   lcd->drawLine(x+1,y,x+width-1,y,clrUpLine);
  576.   lcd->drawLine(x+1,y+height,x+width-1,y+height,clrLwLine);
  577.   lcd->drawText(x + (width-strlen(text)*FONT_WIDTH*size)/2, y + (height-FONT_HEIGHT*size)/2, text, size, COLOR_BUTTON_TEXT, clr);
  578. }
  579.  
  580. /*
  581. --------------------------------------------
  582. TEXTBOX
  583. --------------------------------------------
  584. */
  585.  
  586. void TextBox::draw(lcdPtr lcd, bool isDown)
  587. {
  588.   uint16_t clr = (isDown) ? COLOR_TEXTBOX_PRESSED : COLOR_TEXTBOX;
  589.   uint8_t height = FONT_HEIGHT*size+4;
  590.  
  591.   lcd->drawLine(x,y+height-3,x,y+height,clr);
  592.   lcd->drawLine(x+width,y+height-3,x+width,y+height,clr);
  593.   lcd->drawLine(x,y+height-1,x+width,y+height-1,clr);
  594.   if(isDown)
  595.     lcd->drawLine(x,y+height,x+width,y+height,clr);
  596.   else
  597.     lcd->drawLine(x,y+height,x+width,y+height,COLOR_BG);
  598.  
  599.   char * content = (text == NULL) ? defaultText : text;
  600.  
  601.   char * tmpTxt = "";
  602.   for(int i=0; i<width/(FONT_WIDTH*size); i++)
  603.     strcat(tmpTxt, " ");
  604.  
  605.   content = (isDown) ? tmpTxt : content;
  606.  
  607.   uint16_t clrTxt = (text == NULL) ? COLOR_TEXTBOX_TEXT_DEFAULT : COLOR_TEXTBOX_TEXT;
  608.  
  609.   if(strlen(content)*FONT_WIDTH*size < width)
  610.     lcd->drawText(x+4, y+2, content, size, clrTxt, COLOR_BG);
  611.   else
  612.   {
  613.     uint8_t i = 0;
  614.     while(i*FONT_WIDTH*size < width - 4*FONT_WIDTH*size)
  615.     {
  616.       lcd->drawChar(x+4+i*FONT_WIDTH,y+2,content[i++],size,clrTxt,COLOR_BG);
  617.     }
  618.     lcd->drawText(x+4+i*FONT_WIDTH,y+2,"...",size,clrTxt,COLOR_BG);
  619.   }
  620. }
  621.  
  622. void TextBox::changeText(lcdPtr lcd, char * T)
  623. {
  624.   if(T != NULL)
  625.   {
  626.     if(strlen(T) == 0)
  627.       text = NULL;
  628.     else
  629.     {
  630.       free(text);
  631.       text = (char*)malloc(strlen(T)+1);
  632.       if(text != NULL)
  633.         strcpy(text, T);
  634.     }
  635.     draw(lcd, false);
  636.   }
  637. }
  638.  
  639. void TextBox::addText(lcdPtr lcd, char * T)
  640. {
  641.   if(strlen(T) != NULL)
  642.   {
  643.     if(text != NULL)
  644.     {
  645.       char * tmpTxt = (char*)malloc(strlen(text)+strlen(T)+1);
  646.       if(tmpTxt != NULL)
  647.       {
  648.         strcpy(tmpTxt, text);
  649.         strcat(tmpTxt, T);
  650.         free(text);
  651.         text = tmpTxt;
  652.         draw(lcd, false);
  653.       }
  654.     }
  655.   }
  656. }
  657. /*
  658. --------------------------------------------
  659. SLIDER
  660. --------------------------------------------
  661. */
  662.  
  663. void Slider::draw(lcdPtr lcd, bool isDown)
  664. {
  665.   if(value>1023)
  666.     value = 1023;
  667.   if(value<0)
  668.     value = 0;
  669.  
  670.   float valToX = (float)value/1024*width;
  671.  
  672.   lcd->fillRect(x,y+(height-2)/2,x+valToX,y+height/2,COLOR_SLIDER_VALUE);
  673.   lcd->fillRect(x+valToX,y+(height-2)/2,x+width,y+height/2,COLOR_SLIDER);
  674.  
  675.   lcd->fillRect(x-10,y,x+width+10,y+(height-2)/2-1,COLOR_BG);
  676.   lcd->fillRect(x-10,y+height/2+1,x+width+10,y+height,COLOR_BG);
  677.   lcd->fillRect(x-10,y,x-1,y+height,COLOR_BG);
  678.   lcd->fillRect(x+width+1,y,x+width+10,y+height,COLOR_BG);
  679.  
  680.   lcd->fillCircle(x+valToX,y+height/2,height/2,COLOR_SLIDER_CIRCLE);
  681.   lcd->fillCircle(x+valToX,y+height/2,2,COLOR_SLIDER_VALUE);
  682.   lcd->drawCircle(x+valToX,y+height/2,height/2,COLOR_SLIDER_VALUE);
  683. }
  684.  
  685. /*
  686. --------------------------------------------
  687. STATUSBAR
  688. --------------------------------------------
  689. */
  690.  
  691. void StatusBar::draw(lcdPtr lcd)
  692. {
  693.   lcd->fillRect(0,0,lcd->getWidth(), size*FONT_HEIGHT+4,COLOR_STATUSBAR);
  694.   lcd->drawText(2,2,text,size,COLOR_STATUSBAR_TEXT,COLOR_STATUSBAR);
  695. }
  696.  
  697. /*
  698. --------------------------------------------
  699. CHECKBOX
  700. --------------------------------------------
  701. */
  702.  
  703. void CheckBox::draw(lcdPtr lcd, bool isDown)
  704. {
  705.   uint16_t clr = (isDown) ? COLOR_CHECK_PRESSED : COLOR_CHECK ;
  706.   if(!isActive && !isDown)
  707.   {
  708.     lcd->fillRect(x,y,x+FONT_HEIGHT,y+FONT_HEIGHT,clr);
  709.     lcd->fillRect(x+1,y+1,x+FONT_HEIGHT-1,y+FONT_HEIGHT-1,COLOR_BG);
  710.     lcd->fillRect(x+FONT_HEIGHT,y,x+FONT_HEIGHT+2,y+FONT_HEIGHT,COLOR_BG);
  711.   }
  712.   lcd->drawRect(x,y,x+FONT_HEIGHT,y+FONT_HEIGHT,clr);
  713.   lcd->drawText(x+FONT_HEIGHT+8,y+1,text,1,COLOR_CHECK_TEXT,COLOR_BG);
  714.  
  715.   if(isActive)
  716.   {  
  717.     //line 1 (upper)
  718.     lcd->drawLine(x+2,y+6,x+6,y+10,COLOR_CHECK_PRESSED);
  719.     lcd->drawLine(x+7,y+10,x+FONT_HEIGHT+2,y+3,COLOR_CHECK_PRESSED);
  720.     //line 2 (middle)
  721.     lcd->drawLine(x+2,y+5,x+6,y+9,COLOR_CHECK_PRESSED);
  722.     lcd->drawLine(x+7,y+9,x+FONT_HEIGHT+2,y+2,COLOR_CHECK_PRESSED);
  723.     //line 3 (middle)
  724.     lcd->drawLine(x+3,y+5,x+6,y+8,COLOR_CHECK_PRESSED);
  725.     lcd->drawLine(x+7,y+8,x+FONT_HEIGHT+1,y+2,COLOR_CHECK_PRESSED);
  726.     //line 4 (lower)
  727.     lcd->drawLine(x+3,y+4,x+6,y+7,COLOR_CHECK_PRESSED);
  728.     lcd->drawLine(x+7,y+7,x+FONT_HEIGHT+1,y+1,COLOR_CHECK_PRESSED);
  729.   }
  730. }
  731. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement