Wakeup Light with touch user interface, anti-aliased Font, SD card access and RTC usage on STM32F746NG-DISCO board
Dependencies: BSP_DISCO_F746NG_patch_fixed LCD_DISCO_F746NG TS_DISCO_F746NG FATFileSystem TinyJpgDec_interwork mbed-src
Diff: UI.cpp
- Revision:
- 6:aa51cc3b9f90
- Parent:
- 5:13c70bcde7f6
- Child:
- 7:dc29f6647486
--- a/UI.cpp Mon Nov 09 17:53:22 2015 +0000 +++ b/UI.cpp Tue Nov 10 22:39:50 2015 +0000 @@ -1,5 +1,10 @@ #include "WakeupLight.h" +#include "Images/ic_alarm_white_48dp_1x.h" +#include "Images/ic_navigate_before_white_24dp_1x.h" +#include "Images/ic_notifications_none_white_48dp_1x.h" +#include "Images/ic_query_builder_white_48dp_1x.h" + #define CLIENT_COLOR_BG ((uint32_t)0xFF000000) #define CLIENT_COLOR_FG ((uint32_t)0xFFD0D0D0) @@ -39,7 +44,7 @@ UI_STRUCT uiMain; UI_BOX_LIST_ITEM_STRUCT uiMainItems[]= { - { "Clock" }, { "Clock\nWith Words" }, { "Adjust\nTimers" }, { "Lights On" }, { "Lights Off" }, { "Color Test" } + { "Clock", ic_query_builder_white_48dp_1x }, { "Clock\nWith Words", ic_query_builder_white_48dp_1x }, { "Adjust\nTimers", ic_notifications_none_white_48dp_1x }, { "Lights On", NULL }, { "Lights Off", NULL }, { "Color Test", NULL } }; // @@ -146,6 +151,81 @@ UI_ShowDisplayTextCenter(x,y,BUTTON_WIDTH,BUTTON_HEIGHT,text); } +void UI_DrawBitmapWithAlpha(uint32_t Xpos,uint32_t Ypos,uint8_t *pbmp) +{ + uint32_t index = 0, width = 0, height = 0, bit_pixel = 0; + uint32_t x; + uint32_t part; + uint32_t color[3]; + uint32_t value; + + /* Get bitmap data address offset */ + index = *(__IO uint16_t *) (pbmp + 10); + index |= (*(__IO uint16_t *) (pbmp + 12)) << 16; + + /* Read bitmap width */ + width = *(uint16_t *) (pbmp + 18); + width |= (*(uint16_t *) (pbmp + 20)) << 16; + + /* Read bitmap height */ + height = *(uint16_t *) (pbmp + 22); + height |= (*(uint16_t *) (pbmp + 24)) << 16; + + /* Read bit/pixel */ + bit_pixel = *(uint16_t *) (pbmp + 28); + + /* Get the layer pixel format */ + if ((bit_pixel/8) != 4) + { + DPrintf("UI_DrawBitmapWithAlpha: This is no alpha picture.\r\n"); + return; + } + + /* Bypass the bitmap header */ + pbmp += (index + (width * (height - 1) * (bit_pixel/8))); + + for(index=0; index < height; index++) + { + for (x=0;x<width;x++) + { + value=uiLcd.ReadPixel(Xpos+x,Ypos+index); + + color[0]=value & 0xFF; + color[1]=(value >> 8) & 0xFF; + color[2]=(value >> 16) & 0xFF; + + if (pbmp[3]>0) + { + // add red + part=(color[0]+(pbmp[0]*pbmp[3]/255)); + if (part>255) + part=255; + color[0]=part; + + // add green + part=(color[1]+(pbmp[1]*pbmp[3]/255)); + if (part>255) + part=255; + color[1]=part; + + // add blue + part=(color[2]+(pbmp[2]*pbmp[3]/255)); + if (part>255) + part=255; + color[2]=part; + + // draw pixel + uiLcd.DrawPixel(Xpos+x,Ypos+index,color[0] | (color[1] << 8) | (color[2] << 16) | ((uint32_t)0xFF << 24)); + } + + pbmp+=4; + } + + /* Increment the source and destination buffers */ + pbmp -= 2*(width*(bit_pixel/8)); + } +} + // // box list // @@ -188,6 +268,12 @@ uiLcd.SetBackColor(BOX_COLOR_BG); uiLcd.SetTextColor(BOX_COLOR_FG); UI_ShowDisplayText(startX+BOX_TEXT_SPACING,startY+BOX_TEXT_SPACING,uiCurrent->data.boxList.items[box].name); + + // draw icon + if (uiCurrent->data.boxList.items[box].image!=NULL) + UI_DrawBitmapWithAlpha(startX+width-BOX_SPACING-48,startY+height-BOX_SPACING-48,uiCurrent->data.boxList.items[box].image); +// uiLcd.DrawBitmap(0,0,uiCurrent->data.boxList.items[box].image); +// uiLcd.DrawBitmap(startX+width-BOX_SPACING-48,startY+height-BOX_SPACING-48,uiCurrent->data.boxList.items[box].image); } } } @@ -462,7 +548,7 @@ uiLcd.SetBackColor(HEADER_COLOR_BG); uiLcd.SetTextColor(HEADER_COLOR_FG); if ((uiCurrent->flags & UI_FLAG_HAS_BACK_BUTTON)!=0) - uiLcd.DisplayStringAt(5,2,(uint8_t *)"<-",LEFT_MODE); + UI_DrawBitmapWithAlpha(0,1,ic_navigate_before_white_24dp_1x); } // show clock