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.
Slider.cpp
00001 #include "Slider.h" 00002 #include <stdio.h> 00003 00004 /* Constructor: define dimensions, positions and colors */ 00005 Slider::Slider(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint32_t c1, uint32_t c2) 00006 { 00007 if(x<(maxWidth-w)) xpos=x; 00008 else xpos=maxWidth-w; 00009 if(y<(maxHeight-h)) ypos=y; 00010 else ypos=maxHeight-h; 00011 if(w<(maxWidth)) width=w; 00012 else width=maxWidth; 00013 if(h<(maxHeight)) height=h; 00014 else height=maxHeight; 00015 color1=c1; 00016 color2=c2; 00017 value=128; 00018 } 00019 00020 /* Draw the slider */ 00021 void Slider::Show() 00022 { 00023 char text[10]; 00024 uint32_t OldTextColor; 00025 uint32_t OldBackColor; 00026 sFONT *font; 00027 00028 // Save previous colors and font 00029 OldTextColor=BSP_LCD_GetTextColor(); 00030 OldBackColor=BSP_LCD_GetBackColor(); 00031 font = BSP_LCD_GetFont(); 00032 00033 // Draw Slider 00034 BSP_LCD_SetTextColor(color2); 00035 BSP_LCD_FillRect(xpos,ypos,width,(height*(255-value))/255); 00036 BSP_LCD_SetTextColor(color1); 00037 BSP_LCD_DrawRect(xpos,ypos,width,(height*(255-value))/255); 00038 BSP_LCD_FillRect(xpos,ypos+(height*(255-value))/255,width,(height*value)/255); 00039 00040 //Draw text value 00041 BSP_LCD_SetFont(&Font16); 00042 BSP_LCD_SetBackColor(color2); 00043 sprintf(text,"%3d",value); 00044 BSP_LCD_DisplayStringAt(xpos,ypos+height,(uint8_t*)text,LEFT_MODE); 00045 00046 //Restore colors and fonts 00047 BSP_LCD_SetTextColor(OldTextColor); 00048 BSP_LCD_SetBackColor(OldBackColor); 00049 BSP_LCD_SetFont(font); 00050 } 00051 00052 /* Move the slider if TouchScreen is in area*/ 00053 void Slider::Move(uint16_t x, uint16_t y) 00054 { 00055 if ((x>=xpos) && (x<=xpos+width) && (y>=ypos) && (y<=ypos+height)) { //(y>=ypos+value*height/100-10) && (y<=ypos+value*height/100+10)) 00056 value=255-(y-ypos)*255/height; 00057 Show(); 00058 } 00059 } 00060 00061 /* read the slider value */ 00062 uint16_t Slider::GetValue() 00063 { 00064 return value; 00065 } 00066 00067 /* write the slider value */ 00068 void Slider::SetValue(uint16_t v) 00069 { 00070 if (v<=255) value=v; 00071 else value=255; 00072 Show(); 00073 } 00074 00075 /* Destructor */ 00076 Slider::~Slider() 00077 { 00078 }
Generated on Thu Jul 14 2022 02:48:08 by
1.7.2