#pragma once

#include "board.h"

#include <U8g2lib.h>
#include <U8x8lib.h>

#include "measure.h"
#include "connect.h"

#include "image.h"

#define CONTROLSTRIP_YPOS 40
#define CONTROLSLINE_H 14
#define CONTROLSLINE_W 64
#define SCREENWIDTH 256
#define CONTROLLOFFSET 0
#define CONTROLRADIUS 6
#define INDICATORWIDTH 29
#define INDICATORHEIGHT 13
#define INDICATORRADIUS 3

#define SCREENREFRESH 20

enum displayState
{
  mainscreen,
  setupscreen
};

typedef enum 
{
  LocTop,
  LocRight,
  LocBottom,
  LocLeft,
  locNone
}e_buttonLoc;

class c_onScreenButton
{
  uint16_t _xpos;
  uint16_t _ypos;
  uint16_t _xTpos;
  uint16_t _yTpos;
  uint16_t _radius;
  uint16_t _width;
  uint16_t _height;

  const String _name;
  const uint8_t _index;
  e_buttonLoc _location;

  bool _state;
  bool _visible;

  bool (*const _stateFn)() = NULL;

public:
  c_onScreenButton(String name, uint8_t index, e_buttonLoc location) : 
          _xpos(1),
          _width(1),
          _name(name),
          _index(index),
          _location(location),
          _stateFn(NULL)
  {
    _visible = false;
    
  }
  c_onScreenButton(String name, uint8_t index, e_buttonLoc location, bool (*stateFn)()) : 
          _xpos(1),
          _width(1),
          _name(name),
          _index(index),
          _location(location),
          _stateFn(stateFn)
  {
    _visible = false;
  }

  void drawButton();
  void begin(uint16_t xpos, uint16_t ypos, uint16_t width, uint16_t height, uint16_t radius);
  void setState(bool state) { _state = state; }
  bool getState(void)
  {
    if (_stateFn != NULL)
    {
      //Serial.printf("%s: call stateFn\n",_name.c_str());
      return _stateFn();
    }
    return _state;
  }

  void setVisible(bool state) { _visible = state; }
  bool getVisible(void) { return _visible; }
  uint8_t getIndex(void) { return _index; }
  e_buttonLoc getLocation( void ) {return _location; }
};
//#endif

void initDisplay(void);
void handleDisplay(void);