#ifndef __MZSTDCHARTS_CHART_H__
#define __MZSTDCHARTS_CHART_H__

#include "mzstdchartsCommon.h"
#include "mzObject.h"
#include "mzString.h"
#include "mzArrayList.h"
#include "mzGuiControl.h"

class DECLSPEC_MZSTDCHARTS CChartValue {
public:
    virtual WINAPI ~CChartValue() {};
protected:
    // Disallow creating CChartValue objects directly
    WINAPI CChartValue() {}
};
typedef CChartValue* PChartValue;


class DECLSPEC_MZSTDCHARTS CChartXYValue : public CChartValue {
public:
    double x;
    double y;
    
    WINAPI CChartXYValue(double x, double y) {
        this->x = x;
        this->y = y;
    }
    virtual WINAPI ~CChartXYValue() {}
};
typedef CChartXYValue* PChartXYValue;


class DECLSPEC_MZSTDCHARTS CChartBarValue : public CChartValue {
public:
    CString x;
    double y;
    
    WINAPI CChartBarValue(CString x, double y) {
        this->x = x;
        this->y = y;
    }
    virtual WINAPI ~CChartBarValue() {}
};
typedef CChartBarValue* PChartBarValue;




class DECLSPEC_MZSTDCHARTS CChartSerie {
public:
    CString name;
    CArrayList* values;
    
    WINAPI CChartSerie(CString name);
    virtual WINAPI ~CChartSerie();
    VOID WINAPI clear();
    VOID WINAPI addXYValue(double x, double y);
    VOID WINAPI addBarValue(CString x, double y);
};
typedef CChartSerie* PChartSerie;



class DECLSPEC_MZSTDCHARTS CChart : public CGuiControl {
public:
    CArrayList* series;

    WINAPI CChart(CSprite* parent, CString name, LONG x, LONG y, LONG width, LONG height);
    WINAPI CChart(CSprite* parent, CStyledWindow* parentWnd, CString name, LONG x, LONG y, LONG width, LONG height);
    virtual WINAPI ~CChart();
    
    // Funkcje obsługi zdarzeń
    virtual VOID WINAPI onDraw(CBitmap *dest);
    virtual BOOL WINAPI update();

	VOID WINAPI addSerie(WCHAR* name);
	VOID WINAPI removeSerie(WCHAR* name);
	VOID WINAPI clearSeries();
	//VOID WINAPI addXYValue($x, $y, $color);
	// Set title
	inline VOID WINAPI setTitle(CString title) { this->_title = title; }
    
protected:
	COLORREF    _backgroundColor;
	COLORREF    _borderColor;
    
    CString     _headerFontName;
    LONG        _headerFontSize;
    
    CString     _labelFontName;
    LONG        _labelFontSize;
    
    LONG        _marginLeft;
	LONG        _marginTop;
	LONG        _marginRight;
	LONG        _marginBottom;

	// Chart Rectangle (without axis)
	LONG        _wLeft;
	LONG        _wTop;
	LONG        _wRight;
	LONG        _wBottom;
	LONG        _wWidth;
	LONG        _wHeight;

    CString _title;
    
    BOOL _doAnimation;
    LONG _h1;
    LONG _h2;
    LONG _h3;
    LONG _h4;
    LONG _h5;

/*
    // Tworzy nową instancję klasy o rozmiarach w na h
	public function __construct($w, $h, $debug = false) {
		$this->prepareCanvas($w, $h, new Color(255,255,255));

		$this->debug = $debug;
        $this->margin_left = 10;
		$this->margin_top = 10;
		$this->margin_right = 10;
		$this->margin_bottom = 10;

		$this->values = array();
	}// konstruktor


	// Tworzy nowy obraz o podanych rozmiarach i podanym tle
	public function PrepareCanvas($width, $height, Color $back) {
		$this->width = $width;
		$this->height = $height;

		//Tworzymy obraz
		$this->canvas = imagecreatetruecolor($width, $height);
		//Allokujemy zadany kolor
		$backColor = imagecolorallocatealpha($this->canvas, $back->R, $back->G, $back->B, $back->A);
		//Wypełniamy tłem cały obraz
		imagefill($this->canvas, 0,0, $backColor);
		imagecolordeallocate($this->canvas, $backColor);
	}// PrepareCanvas


	// Abstrakcyjna metoda - w niej będzie odbywało się rysowanie wykresów
	// Każda klasa dziedzicząca musi tę metodę deklarować
	public abstract function Draw();


	// Metoda odpowiedzialna za wyświetlenie obrazka
	public function Output() {
		if (!$this->debug)
			header('Content-type: image/png');
		imagepng($this->canvas);
		imagedestroy($this->canvas);
	}// Output


	public function AddValue($x, $y, $color) {
		$this->values[] = new ColorPoint2D($x, $y, $color);
	}// AddValue
*/
    
	VOID WINAPI _commonInit(LONG width, LONG height);
    virtual VOID WINAPI _updateCanvas();
};
typedef CChart* PChart;

#endif
