Takashi Inoue / F746_GUI_Other

Dependents:   DISCO-F746NG_test001

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Circle.cpp Source File

Circle.cpp

00001 //
00002 //  2016/04/27, Copyright (c) 2016 Takashi Inoue
00003 //  Button OverLapping Class Source File
00004 //  ver 0.9 rev 0.1 2016/5/17
00005 //-----------------------------------------------------------
00006 
00007 #include "mbed.h"
00008 #include "Circle.hpp"
00009 #include "GUIconst.hpp"
00010 
00011 namespace TakaIno
00012 {
00013 // Constructor
00014 Circle::Circle()
00015 {
00016     m_c_info.i_lcd_width = BSP_LCD_GetXSize();
00017 }
00018 
00019 Circle::Circle(struct CircleInfo cirinfo = DEF_CIR_INFO[0])
00020 {
00021     m_c_info.i_lcd_width = BSP_LCD_GetXSize();
00022     m_c_info = cirinfo;
00023 }
00024 
00025 Circle::~Circle()
00026 {
00027     ;
00028 }
00029 
00030 bool Circle::DrawCircle(bool dsp_circle)
00031 {
00032     GetLcdPtrOth()->SetTextColor(m_c_info.i_txtColor);
00033     GetLcdPtrOth()->SetBackColor(m_c_info.i_bakColor);
00034     GetLcdPtrOth()->FillCircle((uint16_t)m_c_info.i_Xpos, (uint16_t)m_c_info.i_Ypos, (uint16_t)m_c_info.i_Radius);
00035 
00036     if( m_c_info.i_disp_c_str )    {
00037         GetLcdPtrOth()->SetTextColor(m_c_info.i_c_str_col );
00038         GetLcdPtrOth()->SetBackColor(m_c_info.i_txtColor);
00039         GetLcdPtrOth()->SetFont(m_c_info.i_c_fonts);
00040         GetLcdPtrOth()->DisplayStringAt(CalX(m_c_info.i_Xpos), (uint16_t)m_c_info.i_Ypos,
00041                                         (uint8_t *)m_c_info.i_c_str[0].c_str(), (Text_AlignModeTypdef)0x01);
00042     }
00043 
00044 
00045     return true;
00046 }
00047 
00048 //Draw Circle at (Xpos, Ypos)
00049 bool Circle::DrawCircle(int16_t Xpos, int16_t Ypos, int16_t Radius, uint32_t txtColor, uint32_t bakColor,
00050                         bool disp_c_str_flg, uint32_t c_str_col, int16_t str_idx,
00051                         const string c_f_str,  const string c_b_str, sFONT &c_fonts)
00052 {
00053     GetLcdPtrOth()->SetTextColor(txtColor);
00054     GetLcdPtrOth()->SetBackColor(bakColor);
00055     GetLcdPtrOth()->FillCircle((uint16_t)Xpos, (uint16_t)Ypos, (uint16_t)Radius);
00056 
00057     m_c_info.i_Xpos = Xpos;      //Set GUI Circle Infomation
00058     m_c_info.i_Ypos = Ypos;
00059     m_c_info.i_Radius = Radius;
00060     m_c_info.i_txtColor = txtColor;
00061     m_c_info.i_bakColor = bakColor;
00062 
00063     //if (display string on) then draw string
00064     if( disp_c_str_flg )    {
00065         m_c_info.i_disp_c_str = disp_c_str_flg;
00066         m_c_info.i_c_str_col = c_str_col;
00067         m_c_info.i_c_str_idx = str_idx;
00068         m_c_info.i_c_str[0] = c_f_str;
00069         m_c_info.i_c_str[1] = c_b_str;
00070         m_c_info.i_c_fonts = &c_fonts;
00071 
00072         GetLcdPtrOth()->SetTextColor(c_str_col);
00073         GetLcdPtrOth()->SetBackColor(m_c_info.i_txtColor);
00074         GetLcdPtrOth()->SetFont(m_c_info.i_c_fonts);
00075         GetLcdPtrOth()->DisplayStringAt(CalX(Xpos), (uint16_t)Ypos,
00076                                         (uint8_t *)m_c_info.i_c_str[0].c_str(), (Text_AlignModeTypdef)0x01);
00077 
00078     }
00079 
00080 
00081     return true;
00082 }
00083 
00084 //Reverse Circle Color (TextColor <--> BackColor))
00085 bool Circle::ReverseCircleColor()
00086 {
00087     uint32_t tmp_color;
00088 
00089     tmp_color = m_c_info.i_txtColor;
00090 
00091     GetLcdPtrOth()->SetTextColor( m_c_info.i_bakColor );
00092     m_c_info.i_txtColor = m_c_info.i_bakColor;
00093 
00094     GetLcdPtrOth()->SetBackColor(tmp_color);
00095     m_c_info.i_bakColor = tmp_color;
00096 
00097     GetLcdPtrOth()->FillCircle((uint16_t)m_c_info.i_Xpos, (uint16_t)m_c_info.i_Ypos,
00098                                (uint16_t)m_c_info.i_Radius );
00099 
00100     if( m_c_info.i_c_str_idx == 0 )   m_c_info.i_c_str_idx = 1;
00101     else    m_c_info.i_c_str_idx = 0;
00102 
00103     //if (display string on) then draw string
00104     if( m_c_info.i_disp_c_str )    {
00105 
00106         GetLcdPtrOth()->SetTextColor(m_c_info.i_c_str_col);
00107         GetLcdPtrOth()->SetBackColor(m_c_info.i_txtColor);
00108 
00109         GetLcdPtrOth()->DisplayStringAt(CalX(m_c_info.i_Xpos), (uint16_t)m_c_info.i_Ypos,
00110                                         (uint8_t *)m_c_info.i_c_str[m_c_info.i_c_str_idx].c_str(), (Text_AlignModeTypdef)0x01);
00111 
00112     }
00113 
00114     return true;
00115 
00116 }
00117 
00118 //Display or Erase Circle
00119 bool Circle::DispOrEraseCircle(bool disp_flg)
00120 {
00121     if( disp_flg )  {
00122         //display
00123         GetLcdPtrOth()->SetTextColor( m_c_info.i_txtColor );   //set current text color
00124 
00125         GetLcdPtrOth()->FillCircle((uint16_t)m_c_info.i_Xpos, (uint16_t)m_c_info.i_Ypos,
00126                                    (uint16_t)m_c_info.i_Radius );
00127 
00128         //if (display string on) then draw string
00129         if( m_c_info.i_disp_c_str )    {
00130 
00131             GetLcdPtrOth()->SetTextColor(m_c_info.i_c_str_col);
00132             GetLcdPtrOth()->SetBackColor(m_c_info.i_txtColor);
00133             GetLcdPtrOth()->DisplayStringAt(CalX(m_c_info.i_Xpos), (uint16_t)m_c_info.i_Ypos,
00134                                             (uint8_t *)m_c_info.i_c_str[m_c_info.i_c_str_idx].c_str(), (Text_AlignModeTypdef)0x01);
00135 
00136         }
00137     } else    {
00138         //erase
00139         GetLcdPtrOth()->SetTextColor( GUIinit::bk_info.i_bakColor );   //set current text color
00140 
00141         GetLcdPtrOth()->FillCircle((uint16_t)m_c_info.i_Xpos, (uint16_t)m_c_info.i_Ypos,
00142                                    (uint16_t)m_c_info.i_Radius );
00143     }
00144 
00145 
00146     return true;
00147 }
00148 
00149 
00150 // If panel touched, return true
00151 bool Circle::CircleTouched()
00152 {
00153     if( !PanelTouchedOth() )    return false;
00154     if( !IsOnCircle() ) return false;
00155     return true;
00156 }
00157 
00158 // If touched position is on the circle, return true
00159 bool Circle::IsOnCircle()
00160 {
00161     int16_t x,y,Len;
00162     TS_StateTypeDef tss = GetTsStateOth();
00163 
00164 
00165     int nTouch = multiTouch_ ? tss.touchDetected : 1;
00166 
00167     for (int n=0; n<nTouch; n++) {
00168         x = (int16_t)tss.touchX[n];
00169         y = (int16_t)tss.touchY[n];
00170         Len = (uint16_t)sqrt((double)((m_c_info.i_Xpos - x)*(m_c_info.i_Xpos - x)+
00171                                       (m_c_info.i_Ypos - y)*(m_c_info.i_Ypos - y)));
00172         if( Len <= m_c_info.i_Radius )    return true;
00173 
00174     }
00175     return false;
00176 }
00177 
00178 //Move circle
00179 bool Circle::MoveCircle(bool move_flg, int16_t xstep, int16_t ystep)
00180 {
00181     m_c_info.i_move_flg = move_flg;
00182 
00183     m_c_info.i_Xstep = xstep;
00184     m_c_info.i_Ystep = ystep;
00185 
00186     return true;
00187 }
00188 bool Circle::MoveCircle(bool move_flg)
00189 {
00190     m_c_info.i_move_flg = move_flg;
00191     return true;
00192 }
00193 
00194 bool Circle::ChangeCirclePos()
00195 {
00196 //        if( m_c_info.i_Xstep != 0 || m_c_info.i_Ystep != 0)  {
00197     if( m_c_info.i_move_flg ) {
00198         GetLcdPtrOth()->SetTextColor( GUIinit::bk_info.i_bakColor );   //set current text color
00199 
00200         GetLcdPtrOth()->FillCircle((uint16_t)m_c_info.i_Xpos, (uint16_t)m_c_info.i_Ypos,
00201                                    (uint16_t)m_c_info.i_Radius );
00202 
00203         int16_t befo_x = m_c_info.i_Xpos;
00204         m_c_info.i_Xpos += m_c_info.i_Xstep;
00205         if( ((int32_t)g_width - (int32_t)m_c_info.i_Radius) < (int32_t)m_c_info.i_Xpos ) {
00206             m_c_info.i_Xpos = befo_x; //
00207             m_c_info.i_Xstep *= (-1);
00208         }
00209         if( (int32_t)m_c_info.i_Radius > (int32_t)m_c_info.i_Xpos ) {
00210             m_c_info.i_Xpos = befo_x; //
00211             m_c_info.i_Xstep *= (-1);
00212         }
00213 
00214         int16_t befo_y = m_c_info.i_Ypos;
00215         m_c_info.i_Ypos += m_c_info.i_Ystep;
00216         if( ((int32_t)g_lcd_height - (int32_t)m_c_info.i_Radius) < (int32_t)m_c_info.i_Ypos ) {
00217             m_c_info.i_Ypos = befo_y; //
00218             m_c_info.i_Ystep *= (-1);
00219         }
00220         if( (int32_t)(m_c_info.i_Radius + g_height_offset) > (int32_t)m_c_info.i_Ypos ) {
00221             m_c_info.i_Ypos = befo_y; //
00222             m_c_info.i_Ystep *= (-1);
00223         }
00224 
00225 
00226     }
00227 
00228     GetLcdPtrOth()->SetTextColor( m_c_info.i_txtColor );   //set current text color
00229 
00230     GetLcdPtrOth()->FillCircle((uint16_t)m_c_info.i_Xpos, (uint16_t)m_c_info.i_Ypos,
00231                                (uint16_t)m_c_info.i_Radius );
00232 
00233     //if (display string on) then draw string
00234     if( m_c_info.i_disp_c_str )    {
00235 
00236         GetLcdPtrOth()->SetTextColor(m_c_info.i_c_str_col);
00237         GetLcdPtrOth()->SetBackColor(m_c_info.i_txtColor);
00238         GetLcdPtrOth()->DisplayStringAt(CalX(m_c_info.i_Xpos), (uint16_t)m_c_info.i_Ypos,
00239                                         (uint8_t *)m_c_info.i_c_str[m_c_info.i_c_str_idx].c_str(), (Text_AlignModeTypdef)0x01);
00240 
00241 
00242 
00243 
00244     }
00245     return true;
00246 }
00247 
00248 uint16_t Circle::PosX(int16_t x, const string str, sFONT &sfont)
00249 {
00250     return (uint16_t)((uint16_t)x - str.length() * sfont.Width/2);
00251 
00252 }
00253 
00254 uint16_t Circle::CalX(int16_t x)
00255 {
00256     if( m_c_info.i_lcd_width / 2 < x )   {
00257         x -= m_c_info.i_lcd_width / 2;
00258     } else   {
00259         x += m_c_info.i_lcd_width / 2;
00260     }
00261     return (uint16_t)x;
00262 }
00263 }
00264 
00265 
00266 
00267 
00268