// Author: Juan Carlos De Abreu (jcabreur@gmail.com)
//
// This file define the interface Control class that define all the common
// characteristic og elements in a window.

#ifndef GUI_CONTROL_H__
#define GUI_CONTROL_H__

#include "../global.h"
#include "../Base/Functor/Functors.h"

BEGIN_TEG_NAMESPACE();
BEGIN_NAMESPACE(gui);

class Control {
 public:
  // Control constructor and destructor.
  Control();
  Control(int x, int y, int width, int height);
  virtual ~Control();

  // Accessor and mutator methods to Control attributes.
  inline int x() const { return x_; }
  inline int y() const { return y_; }
  inline int width() const { return width_; }
  inline int height() const { return height_; }
  inline bool is_visible() const { return is_visible_; }
  inline bool is_pressed() const { return is_pressed_; }
  void set_x(int x) { x_ = x; }
  void set_y(int y) { y_ = y; }
  void set_is_visible(bool is_visible) { is_visible_ = is_visible; }
  void set_is_pressed(bool is_pressed) { is_pressed_ = is_pressed; }

  // Method to switch the flag is_pressed_ and is_visible_.
  inline void ToggleIsPressed() { is_pressed_ = !is_pressed_; }
  inline void ToggleIsVisible() { is_visible_ = !is_visible_; }

  // Method to display the control.
  virtual void Render() const = 0;

  // Method to execute the functor when the control is pressed.
  inline void onClick() { if (function_to_call_) function_to_call_->call(); }

 protected:
  // Control attributes, relative control position to the window where is
  // contained, control width and height, flags to know if the control is
  // visible and if pressed and a function to call when the control is pressed.
  int x_, y_;
  int width_, height_;
  bool is_visible_;
  bool is_pressed_;
  Functor0<void> *function_to_call_;
};

END_NAMESPACE(gui);
END_TEG_NAMESPACE();

#endif  // GUI_CONTROL_H__
