#if ! defined LIBOCELLI_WIDGET
#define LIBOCELLI_WIDGET
//----------------------------------------------------------------------------
///
/// \file   widget.hpp
///
/// \brief  class for graphical widgets
///
/// \date   20220619
/// \author Maximilian Seesslen <mes@seesslen.net>
///
//----------------------------------------------------------------------------


//---Documentation------------------------------------------------------------


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


//---General--------------------------

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

#include <lepto/signal.h>
#include <stdio.h>

// #define USE_BIWAK

#if defined(__arm__)
   // #define USE_BIWAK
#endif
#if defined (USE_BIWAK)
   #include <biwak/gdisplay.h>
   #include <biwak/exception.h>
   #include <biwak/touch.h>
#else

#if 0
int exception(const char *text);
class CGraphicDisplay
{

};

class CTouch
{
public:
   enum class EEventType
   {
      none,
      pressed,
      released,
      clicked
   };

   struct SEvent{
      int x;
      int y;
      EEventType type;
   };
};

#endif

#endif
#include <ocelli/point.h>
#include <ocelli/ocelliTypes.hpp>


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


class OWidget
{

private:

   const OPoint m_p1, m_p2;

protected:

   static CGraphicDisplay *m_display;

public:
   CSignal <void, const Ocelli::SEvent&> eventSignal;

   constexpr OWidget(int x1, int y1, int x2, int y2)
      :m_p1( x1, y1 )
      ,m_p2( x2, y2 )
   {
   }
   constexpr OWidget( const OPoint p1, const OPoint p2)
      :m_p1( OPoint::absolut1( p1, p2 ) )
      ,m_p2( OPoint::absolut2( p1, p2 ) )
   {
   }
   bool lap(int x, int y) const
   {
      if(
            ( x >= m_p1.x )
         && ( x <= m_p2.x )
         && ( y >= m_p1.y )
         && ( y <= m_p2.y ) )
      {
         return(true);
      }
      return(false);
   }
   virtual void draw()
   {};
   virtual void update(const Ocelli::SEvent &event)
   {
      switch(event.type)
      {
         case Ocelli::EEventType::pressed:
            break;
         case Ocelli::EEventType::released:
            break;
         default:
            break;
      }
   };
   static void setDisplay(CGraphicDisplay &display)
   {
      m_display=&display;
   }
   static CGraphicDisplay &display()
   {
      return( *m_display );
   }
   int width() const
   {
      return( ( m_p2.x - m_p1.x) + 1 );
   }
   int height() const
   {
      return( ( m_p2.y - m_p1.y) + 1 );
   }
   void event(const Ocelli::SEvent &event)
   {
      update(event);
      if ( ( event.type == Ocelli::EEventType::clicked )
       ||  ( event.type == Ocelli::EEventType::reserved /*modified*/ ) )
      {
         eventSignal.emitSignal(event);
      }
   }
   const OPoint &p1() const
   {
      return ( m_p1 );
   }
   const OPoint &p2() const
   {
      return ( m_p2 );
   }
   int centerX() const

   {
      return( ( m_p1.x + m_p2.x ) / 2 );
   }
   int centerY() const
   {
      return( ( m_p1.y + m_p2.y ) / 2 );
   }
};


//---fin-----------------------------------------------------------------------
#endif // ? ! LIBOCELLI_WIDGET
