#ifndef GCGRAPHICITEM_H
#define GCGRAPHICITEM_H

#include "GcObject.h"

#include "gfd.h"
#include "gfd_grifo_fonts.h"

typedef gfd_framebuffer_t gfd_grifo_framebuffer_t;

class GcLogicPalette: public GcObject
{
public:
  enum logic_color_t
  {
    c_normal=0,
    c_friend,
    c_foe,
    c_unknown,
    c_bold,
    c_dimmed,
    c_dbg_highlight,
    c_spare
  };

  GcLogicPalette(const char* const name);

  enum {  num_of_logical_colors=c_spare+1};

  unsigned int operator[](logic_color_t c) const { return ctab[c];}

  void mapTo(logic_color_t logic, unsigned int phy)
  {
    ctab[logic]=phy;
  }

  GC_OBJ_MON_DECLARE(GcLogicPalette)

public:
  unsigned int ctab[num_of_logical_colors];

  //virtual const mex_mt_tag_t* mexMetatype() const;

  friend class GcObjectDebugMonitor;
};

class GcPaintContext
{
public:
  GcPaintContext(gfd_grifo_framebuffer_t& fb_, gfd_framebuffer_t& fb_full_, GcLogicPalette& pal_):
    fb(fb_),
    fb_full(fb_full_),
    pal(&pal_)
  {
  }
  GcPaintContext(const GcPaintContext& pCx):
    fb(pCx.fb),
    fb_full(pCx.fb_full),
    pal(pCx.pal)
  {
  }

  gfd_grifo_framebuffer_t& framebuffer() const { return fb;}
  gfd_framebuffer_t& full_framebuffer() const { return fb_full;}

  GcLogicPalette& palette() const { return *pal;}

  void setPalette(GcLogicPalette& p) const { pal=&p;}

  unsigned int color_occlusion() const { return 0;}
  unsigned int color_background() const { return 1;}
  unsigned int color_debug() const { return 64;}
  unsigned int color_base_raw_sim() const { return 128;}

  /*
  const gfd_font16_t* font_debug_small() const { return &gfd_font_pc_8x8;}
  const gfd_font16_t* font_debug_normal() const { return &gfd_font_fisar_9x12;}

  const gfd_font16_t* font_normal() const { return &gfd_font_f5_14x20;}
  const gfd_font16_t* font_small() const { return &gfd_font_f5_10x14;}
  const gfd_font16_t* font_big() const {return &gfd_font_m3_16x24;}

  const gfd_font16_t* font_normal2() const { return &gfd_font_m3_12x18;}
  */

protected:
  gfd_grifo_framebuffer_t& fb;
  gfd_framebuffer_t& fb_full;
  mutable GcLogicPalette* pal;
};


class GcGraphicItem: public GcObject
{
public:
  GcGraphicItem(const char* name);

  bool visible() const { return isVisible;}
  bool active() const { return isActive;}

  virtual void recalculate();

  virtual void draw(const GcPaintContext&);

  virtual void draw_normal(const GcPaintContext&);
  virtual void draw_blink_in(const GcPaintContext&);
  virtual void draw_blink_out(const GcPaintContext&);

  virtual void draw_inactive(const GcPaintContext&);
  virtual void draw_invisible(const GcPaintContext&);

  virtual void draw_deg_info(const GcPaintContext&);
  virtual void draw_dbg_bounding_box(const GcPaintContext&);

  GC_OBJ_MON_DECLARE(GcGraphicItem)

protected:
  bool isVisible;
  bool isActive;
};

#endif // GCGRAPHICITEM_H
