//----------------------------------------------------------------------------
///
/// \brief   CANDis screen showing can messages
///
///          Static table
///
/// \date   20220903
/// \author Maximilian Seesslen <mes@seesslen.net>
///
//----------------------------------------------------------------------------


//---Includes-----------------------------------------------------------------


//---Own------------------------------

#include <lepto/lepto.h>
#include <lepto/log.h>
#include <screen_settings.hpp>


//---Declaration--------------------------------------------------------------


constexpr const char* const CScreenSettings::m_interfaceStrings[];

CScreenSettings::CScreenSettings(SEepromConfigCustom &config )
   :m_config(config)
{
   const int border=6;
   OPoint a(120+border, border,absolut);
   constexpr const OPoint r(128-(2*border), 64-(2*border), ECoordinateType::sizes);
   addWidget( m_pButtonInterface = new OButton(a, r,
                        m_interfaceStrings[ (int)m_config.interface ],
                        OButton::EButtonStyle::flatSmallBorder) );
   m_pButtonInterface->eventSignal.connect(this,
                        &CScreenSettings::slotInterfacePressed );

   a += OPoint ( 0, 64 );
   addWidget( m_pButtonRtcSync = new OButtonSwitch(a, r,
                        "SYNC", OButton::EButtonStyle::flatSmallBorder) );
   m_pButtonRtcSync->setSwitchValue( m_config.fields.periodicSyncRtc );
   m_pButtonRtcSync->eventSignal.connect(this, &CScreenSettings::slotConfigChanged );

   a += OPoint ( 0, 64 );
   addWidget( m_pButtonTotalOff = new OButtonSwitch(a, r,
                        "T-OFF", OButton::EButtonStyle::flatSmallBorder) );
   m_pButtonTotalOff->setSwitchValue( m_config.fields.totalOff );
   m_pButtonTotalOff->eventSignal.connect(this, &CScreenSettings::slotConfigChanged );

   a += OPoint ( 0, 64 );
   addWidget( m_pButtonScreenSaver = new OButtonSwitch(a, r,
                        "SCR", OButton::EButtonStyle::flatSmallBorder) );
   m_pButtonScreenSaver->setSwitchValue( m_config.fields.screensaver );
   m_pButtonScreenSaver->eventSignal.connect(this, &CScreenSettings::slotConfigChanged );
}


void CScreenSettings::draw() /* virtual override */
{
   OWidget::display().setFg( green );
   OWidget::display().setFont( getFont11() );
   OWidget::display().drawBar(0,0,239,319, black, black);
   OWidget::display().setBg( black );
   OWidget::display().setDrawBackground(true);
   int row=0;
   int lineDist=64;
   // 'static' saves 48 bytes
   static const char* const lines[]{"INTERFACE", "CAN/USB", nullptr};
   static const char* const lines2[]{"PERIODIC", "SYNC RTC", nullptr};
   static const char* const lines3[]{"MAIN OFF", "ON SLEEP", nullptr};
   static const char* const lines4[]{"SCREEN", "SAVER", nullptr};

   OWidget::display().drawLines(120/2, ( lineDist / 2 )+(row * lineDist),
                                lines );
   row++;

   OWidget::display().drawLines(120/2, ( lineDist / 2 )+(row * lineDist),
                                lines2 );
   row++;

   OWidget::display().drawLines(120/2, ( lineDist / 2 )+(row * lineDist),
                                lines3 );
   row++;

   OWidget::display().drawLines(120/2, ( lineDist / 2 )+(row * lineDist),
                                lines4 );
   row++;

   for(int i1=1; i1<=row; i1++)
   {
      OWidget::display().drawHLine(0, i1*lineDist, 239, darkGreen);
   }

   OScreen::draw();
}


//---fin----------------------------------------------------------------------
