Motoo Tanaka / Mbed 2 deprecated Dentaku Featured

Dependencies:   SPI_STMPE610 UniGraphic mbed vt100

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers TFTMenu.cpp Source File

TFTMenu.cpp

00001 /** mbed oscilloscope my implementation of a oscillo scope
00002  * Copyright (c) 2014, 2015 Motoo Tanaka @ Design Methodology Lab
00003  *
00004  * TFTMenu.cpp
00005  *
00006  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00007  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00008  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00009  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00010  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00011  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00012  * THE SOFTWARE.
00013  */
00014 #include "mbed.h"
00015 #include <ILI9341.h>
00016 #include "SPI_STMPE610.h"
00017 #include "Arial12x12.h"
00018 //#include "Arial24x23.h"
00019 #include "Arial28x28.h"
00020 //#include "Arial43x48_numb.h"
00021 #include "vt100.h"
00022 #include <string.h>
00023 
00024 #include "TFTMenu.h"
00025 
00026 extern ILI9341 TFT ;
00027 extern SPI_STMPE610 TSC ;
00028 extern vt100 *tty ;
00029 
00030 
00031 TFTMenuItem::TFTMenuItem(int x1, int y1, int x2, int y2, FuncPtr fnc, 
00032     char *name, uint16_t mcolor, uint16_t fcolor, int l_margin, int t_margin ) 
00033 {
00034     left = x1 ;
00035     right = x2 ;
00036     top = y1 ;
00037     bottom = y2 ;
00038     if (name) {
00039         label = new char[strlen(name)+1] ;
00040         strcpy(label, name) ;
00041         font_color = fcolor ;
00042     }
00043     menu_color = mcolor ;
00044     
00045     left_margin = l_margin ; // 7 ; 
00046     top_margin = t_margin ; // 10 ; 
00047     func = fnc ;
00048 }
00049 
00050 TFTMenuItem::~TFTMenuItem() 
00051 {
00052     left = 0 ;
00053     right = 0 ;
00054     top = 0 ;
00055     bottom = 0 ;
00056     if (label) {
00057         free(label) ;
00058     }
00059 }
00060 
00061 TFTRadioButton::TFTRadioButton(int x1, int y1, int x2, int y2, FuncPtr fnc, 
00062     char *name, uint16_t mcolor, uint16_t fcolor,
00063     char *altname, uint16_t altmcolor, uint16_t altfcolor, 
00064     bool sel) : TFTMenuItem(x1,y1,x2,y2,fnc,name,mcolor,fcolor)
00065 {
00066     if (altname) {
00067         alt_label = new char[strlen(altname) + 1] ;
00068         strcpy(alt_label, altname) ;
00069     } else {
00070         alt_label = 0 ;
00071     }
00072     alt_font_color = altfcolor ;
00073     alt_menu_color = altmcolor ;
00074     selected = sel ;
00075 }
00076 
00077 TFTRadioButton::~TFTRadioButton() 
00078 {
00079     left = 0 ;
00080     right = 0 ;
00081     top = 0 ;
00082     bottom = 0 ;
00083     if (label) {
00084         delete label ;
00085     }
00086     if (alt_label) {
00087         delete alt_label ;
00088     }
00089 }
00090 
00091 bool TFTRadioButton::hit(int x, int y)
00092 {
00093     bool result = false ;
00094     if ((left <= x)&&(x <= right)&&(top <= y)&&(y <= bottom)) {
00095         result = true ;
00096         if (selected) {
00097             selected = false ;
00098         } else {
00099             selected = true ;
00100         }
00101         draw() ;
00102     }
00103     return( result ) ;
00104 }
00105 
00106 void TFTRadioButton::select(bool value)
00107 {
00108     selected = value ;
00109 }
00110 
00111 uint16_t TFTMenuItem::getColor(void) 
00112 {
00113     return(menu_color) ;
00114 }
00115 
00116 bool TFTMenuItem::hit(int x, int y) 
00117 {
00118     bool result = false ;
00119     if ((left <= x)&&(x <= right)&&(top <= y)&&(y <= bottom)) {
00120         result = true ;
00121         draw() ;
00122     }
00123 //    draw() ;
00124     return( result ) ;
00125 }
00126 
00127 void TFTMenuItem::doIt(void)
00128 {
00129     if (func) {
00130         func() ;
00131     }
00132 }
00133 
00134 void TFTMenuItem::font_margin(int x, int y) 
00135 {
00136     top_margin = y ;
00137     left_margin = x ;
00138 }
00139 
00140 void TFTMenuItem::draw(int offset_x, int offset_y)
00141 {
00142     TFT.BusEnable(true) ;
00143     TFT.fillrect(left+offset_x, top+offset_y, right+offset_x, bottom+offset_y, Black) ;
00144     TFT.fillrect(left+offset_x, top+offset_y, right+offset_x, bottom+offset_y, menu_color) ;
00145     wait(0.1) ;
00146     TFT.locate(left+offset_x+left_margin, top+offset_y+top_margin) ;
00147     TFT.foreground(font_color) ;
00148     TFT.background(menu_color) ;
00149     TFT.set_font((unsigned char *)Arial28x28) ;
00150     wait(0.1) ;
00151     TFT.printf(label) ;
00152     TFT.BusEnable(false) ;
00153 }
00154 
00155 void TFTRadioButton::draw(int offset_x, int offset_y)
00156 {
00157     TFT.BusEnable(true) ;
00158     if (selected) {
00159         TFT.fillrect(left+offset_x, top+offset_y, right+offset_x, bottom+offset_y, Black) ;
00160         TFT.fillrect(left+offset_x, top+offset_y, right+offset_x, bottom+offset_y, alt_menu_color) ;
00161         wait(0.1) ;
00162         TFT.locate(left+offset_x+left_margin, top+offset_y+top_margin) ;
00163         TFT.foreground(alt_font_color) ;
00164         TFT.background(alt_menu_color) ;
00165         TFT.set_font((unsigned char *)Arial12x12) ;
00166         wait(0.1) ;
00167         TFT.printf(alt_label) ;
00168     } else {
00169         TFTMenuItem::draw(offset_x, offset_y) ;
00170     }
00171     TFT.BusEnable(false) ;
00172 }
00173         
00174 
00175 void TFTMenuItem::highlight(int offset_x, int offset_y)
00176 {
00177     TFT.BusEnable(true) ;
00178     TFT.rect(left+offset_x, top+offset_y, right+offset_x, bottom+offset_y, font_color) ;
00179     TFT.BusEnable(false) ;
00180 }