#include "widget/bounding_box.hpp"
#include "ta_multiwriter.hpp"

#include "printf/printf.h"

namespace widget {

  enum class click_type {
    press,
    down,
    release,
  };

  struct widget : bounding_box {
  protected:
    click_type click_state;

  public:
    inline widget(float _x, float _y, float _width, float _height)
      : bounding_box(_x, _y, _width, _height), click_state(click_type::release)
    { }

    inline virtual void draw(ta_multiwriter& multi)
    {
      if (click_state == click_type::press)
        click_state = click_type::down;
      else if (click_state == click_type::down)
        click_state = click_type::release;
    }

    inline virtual void freeze(float _dx, float _dy)
    {
      dx = _dx;
      dy = _dy;
    }

    inline virtual widget * pick(float _x, float _y)
    {
      if (inside(_x, _y))
        return this;
      else
        return nullptr;
    }

    inline virtual void click()
    {
      click_state = click_type::press;
    }
  };
}
