Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: BSP_DISCO_F746NG
button.cpp
00001 #include "button.h" 00002 #include "mbed.h" 00003 00004 #include "stm32746g_discovery_lcd.h" 00005 00006 int Button::strlen(uint8_t *str) 00007 { 00008 int i = 0; 00009 while(str[i]) 00010 { 00011 i++; 00012 } 00013 return i; 00014 } 00015 00016 00017 Button::Button(int x, int y, int width, int height, uint32_t bgColor, uint32_t borderWidth) 00018 : m_x(x), m_y(y), m_width(width), m_height(height), m_bgColor(bgColor), m_borderWidth(borderWidth) 00019 { 00020 00021 } 00022 00023 bool Button::contain(int x, int y) 00024 { 00025 m_etat = (x > m_x && x < m_x + m_width && y > m_y && y < m_y + m_height); 00026 return m_etat; 00027 } 00028 00029 void Button::draw() 00030 { 00031 int x = m_x; 00032 while (x < m_x + m_width) { 00033 int y = m_y; 00034 while (y < m_y + m_height) { 00035 if (y - m_y < m_borderWidth) 00036 BSP_LCD_DrawPixel(x, y, m_borderColor); 00037 else if ( (m_y + m_height) - y <= m_borderWidth) 00038 BSP_LCD_DrawPixel(x, y, m_borderColor); 00039 else if (x - m_x < m_borderWidth) 00040 BSP_LCD_DrawPixel(x, y, m_borderColor); 00041 else if ( (m_x + m_width) - x <= m_borderWidth) 00042 BSP_LCD_DrawPixel(x, y, m_borderColor); 00043 else 00044 BSP_LCD_DrawPixel(x, y, m_bgColor); 00045 00046 y++; 00047 } 00048 x++; 00049 } 00050 BSP_LCD_SetTextColor(m_textColor); 00051 BSP_LCD_SetBackColor(m_bgColor); 00052 BSP_LCD_DisplayStringAt((m_x + m_width/2)- 8*(strlen(m_text)/2), (m_y + m_height/2) - 5, (uint8_t *)&m_text, LEFT_MODE); 00053 00054 } 00055 00056 void Button::setText(const char *str, uint32_t textColor){ 00057 m_textColor = textColor; 00058 sprintf((char*)m_text, str); 00059 00060 }
Generated on Wed Jul 13 2022 14:45:46 by
