/* Główna klasa rysowania wykresu */

#ifndef GD_GRAPH_PS_H

#define GD_GRAPH_PS_H
#define __NOLIBBASE__

#include <proto/dos.h>
#include <math.h>
#include "datastream.h"

extern Library *DOSBase;

#define PATTERN_SOLID   0
#define PATTERN_DASHED  1
#define PATTERN_DOTTED  2

//-------------------------------------------------------------------------------------------------------

class Graph
  {
    long width, height, translate_x, translate_y;
    GdDataStream *stream;

    protected:

    double x_scale_min, x_scale_max, x_grid_size;
    double y_scale_min, y_scale_max, y_grid_size;
    double x_multiplier;
    long x_grid_num, y_grid_num;
    long x_data_to_graph(double x);
    long y_data_to_graph(double y);

    public:

    Graph(long w, long h, GdDataStream *s);
    ~Graph() {};
    virtual void moveto(long x, long y) = 0;
    virtual void lineto(long x, long y) = 0;
    virtual void rgbcolor(unsigned char r, unsigned char g, unsigned char b) = 0;
    virtual void pattern(short pat) = 0;
    virtual void stroke() = 0;
    virtual void clear() = 0;
    void drawgraph();
    long get_width() {return width;}
    long get_height() {return height;}

    void resize(long new_width, long new_height)
      {
        width = new_width;
        height = new_height;
      }

    void translate(long new_x, long new_y)
      {
        translate_x = new_x;
        translate_y = new_y;
      }
  };


class AxedGraph : public Graph
  {
    long width, height, delta_x, delta_y;
    char sctexts_x[240];        /* max 16 texts of 15 characters for Y axis */
    char sctexts_y[176];        /* max 11 texts of 15 characters for X axis */

    public:

    AxedGraph(long w, long h, GdDataStream *s)
      : Graph(w, h, s),
        width(w),
        height(h)
      {}

    ~AxedGraph() {}

    void drawgraph();
    long x_axis_prepare();
    void x_axis_draw();
    long y_axis_prepare();
    void y_axis_draw();

    void text_ct(long x, long y, char *string)      /* align = center, vailgn = top */
      {
        text(x - (strwidth(string) / 2), y - baseline(), string);
      }

    void text_rm(long x, long y, char *string)      /* align = right, valign = middle */
      {
        text(x - strwidth(string), y + (font_height() / 2) - baseline(), string);
      }

    virtual void text(long x, long y, char *string) = 0;
    virtual long strwidth(char *string) = 0;
    virtual long font_height() = 0;
    virtual long baseline() = 0;
    virtual void setfont(char *fontname, long fontsize) = 0;
  };


#endif
