#ifndef dpl_2d_h
#define dpl_2d_h
#ifdef __cplusplus
extern "C" {
#endif

#include <dpl/dpltypes.h>

#define WORDS_PER_DISPLAY_CHUNK 30

typedef struct s_dpl2d_display {
  void  *remote;
  struct s_dpl2d_display *next;
  struct s_dpl2d_display *tail;
  int32  size;
  int32  open;
  int32  data[WORDS_PER_DISPLAY_CHUNK];
} dpl2d_DISPLAY;

typedef enum dpl2d_OPEN_MODE
{
  dpl2d_open_mode_error,
  dpl2d_open_mode_clear,
  dpl2d_open_mode_append
} dpl2d_OPEN_MODE;

typedef enum dpl2d_CLIP_MODE
{
  dpl2d_clip_mode_error,
  dpl2d_clip_mode_OR,
  dpl2d_clip_mode_AND,
  dpl2d_clip_mode_XOR,
  dpl2d_clip_mode_SET,
  dpl2d_clip_mode_CLEAR
} dpl2d_CLIP_MODE;

typedef int32 *dpl_2d_snapshot;

typedef float32 dpl2d_MATRIX [6];

/* displaylist creation, destruction */

extern dpl2d_DISPLAY *dpl2d_NewDisplayList ( void );

extern int32 dpl2d_DeleteDisplayList ( dpl2d_DISPLAY *display );

extern int32 dpl2d_OpenDisplayList ( dpl2d_DISPLAY *display, dpl2d_OPEN_MODE append );

extern int32 dpl2d_CloseDisplayList ( dpl2d_DISPLAY *display );

extern int32 dpl2d_FlushDisplayList ( dpl2d_DISPLAY *display );

extern int32 dpl2d_AddOpenPolyline ( dpl2d_DISPLAY *display );

extern int32 dpl2d_AddClosePolyline ( dpl2d_DISPLAY *display );

extern int32 dpl2d_AddOpenLines ( dpl2d_DISPLAY *display );

extern int32 dpl2d_AddCloseLines ( dpl2d_DISPLAY *display );

extern int32 dpl2d_AddOpenPolypoint ( dpl2d_DISPLAY *display );

extern int32 dpl2d_AddClosePolypoint ( dpl2d_DISPLAY *display );

extern int32 dpl2d_AddPoint ( dpl2d_DISPLAY *display, float32 x, float32 y );

extern int32 dpl2d_AddCircle( dpl2d_DISPLAY *display, float32 x, float32 y, float32 r, int32 filled );

extern int32 dpl2d_AddPushState ( dpl2d_DISPLAY *display );

extern int32 dpl2d_AddPopState ( dpl2d_DISPLAY *display );

extern int32 dpl2d_AddSetColor ( dpl2d_DISPLAY *display, float32 r, float32 g, float32 b );

extern int32 dpl2d_AddSetAlpha ( dpl2d_DISPLAY *display, float32 a );

extern int32 dpl2d_AddSetMatrix ( dpl2d_DISPLAY *display, dpl2d_MATRIX );

extern int32 dpl2d_AddConcatMatrix ( dpl2d_DISPLAY *display, dpl2d_MATRIX, int32 post );

extern int32 dpl2d_AddSetLineWidth ( dpl2d_DISPLAY *display,
   float32 w );

/* clip region support */
extern int32 dpl2d_AddFullScreenClipRegion ( dpl2d_DISPLAY *display );

extern int32 dpl2d_AddClearClipRegion ( dpl2d_DISPLAY *display );

extern int32 dpl2d_AddOpenClipPolygon ( dpl2d_DISPLAY *display );

extern int32 dpl2d_AddCloseClipPolygon ( dpl2d_DISPLAY *display,
   dpl2d_CLIP_MODE mode );

extern int32 dpl2d_AddClipCircle ( dpl2d_DISPLAY *display,
   float32 x, float32 y, float32 rad,
   dpl2d_CLIP_MODE mode );


extern int32 dpl2d_AddCallDisplayList ( dpl2d_DISPLAY *display,
                                 dpl2d_DISPLAY *sub_display );

extern int32 dpl2d_SetViewDisplayList ( dpl_VIEW *v, dpl2d_DISPLAY *disp );

extern dpl2d_DISPLAY *dpl2d_GetViewDisplayList ( dpl_VIEW *v );

/* and now the 2-D matrix support */

extern void dpl2d_IdMatrix        ( dpl2d_MATRIX m );
extern void dpl2d_TranslateMatrix ( dpl2d_MATRIX m,
  float32 x, float32 y );
extern void dpl2d_RotateMatrix ( dpl2d_MATRIX m,
  float32 angle );
extern void dpl2d_ScaleMatrix ( dpl2d_MATRIX m,
  float32 sx, float32 sy );
extern void dpl2d_ConcatMatrix ( dpl2d_MATRIX m,
    dpl2d_MATRIX a,
    dpl2d_MATRIX b );

#ifdef __cplusplus
}
#endif
#endif

