(*
 * Title:    drawtypes.h
 * Purpose:  Defines types used by the object level interface for draw files
 *
 *)


(*
 * The types defined here are used for detailed access to objects.
 * This will not normally be #included by a client of  the DrawFile modules
 * - it gets pulled in by h.drawfobj.
 *)

#ifndef __drawftypes_h
#define __drawftypes_h

#ifndef __os_h
#include "os.h"
#endif
#ifndef __sprite_h
#include "sprite.h"
#endif
#ifndef __drawfdiag_h
#include "drawfdiag.h"
#endif

type draw_sizetyp_ptr = ^draw_sizetyp;
     draw_sizetyp = integer;
     draw_coltyp_ptr = ^draw_coltyp;
     draw_coltyp = integer;
     draw_pathwidth_ptr = ^draw_pathwidth;
     draw_pathwidth = integer;
     draw_bboxtyp_ptr = ^draw_bboxtyp;
     draw_bboxtyp = draw_box;

(* Permissible join style values *)

const   join_mitred    = $00;  (* mitred joins *)
        join_round     = $01;  (* round joins *)
        join_bevelled  = $02;  (* bevelled joins *)

type draw_jointyp_ptr = ^draw_jointyp;
     draw_jointyp = integer;

(* Permissible cap style values *)

const   cap_butt       = $00;  (* butt caps *)
        cap_round      = $01;  (* round caps *)
        cap_square     = $02;  (* projecting square caps *)
        cap_triang     = $03;  (* triangular caps *)

type draw_captyp_ptr = ^draw_captyp;
     draw_captyp = integer;


(* Types of winding rule *)

const
  wind_nonzero = 0;
  wind_evenodd = 1;

type draw_windtyp_ptr = ^draw_windtyp;
     draw_windtyp = integer;


(* Dash types *)

const
  dash_absent  = 0;
  dash_present = 1;

type draw_dashtyp_ptr = ^draw_dashtyp;
     draw_dashtyp = integer;


(* Values used for pack/unpack of draw data *)

const   packmask_join     = $03;
        packmask_endcap   = $0C;
        packmask_startcap = $30;
        packmask_windrule = $40;
        packmask_dashed   = $80;
        packshft_join     =   0;
        packshft_endcap   =   2;
        packshft_startcap =   4;
        packshft_windrule =   6;
        packshft_dashed   =   7;


(* A Path style *)

type draw_pathstyle_ptr = ^draw_pathstyle;
     draw_pathstyle =
       record
         joincapwind : byte;       (* 1 byte  *) (* bit 0..1 join         *)
                                                 (* bit 2..3 end cap      *)
                                                 (* bit 4..5 start cap    *)
                                                 (* bit 6    winding rule *)
                                                 (* bit 7    dashed       *)
         reserved8 : byte;         (* 1 byte  *)
         tricapwid : byte;         (* 1 byte  *) (* 1/16th of line width *)
         tricaphei : byte          (* 1 byte  *) (* 1/16th of line width *)
       end;


type draw_fontref_ptr = ^draw_fontref;
     draw_fontref = byte;          (* 1 byte *)


(* Text style *)

type draw_textstyle_ptr = ^draw_textstyle;
     draw_textstyle =
       record
         fontref : draw_fontref;    (* 1 byte  *)
         reserved1 : byte;          (* 1 byte  *)
         reserved2 : byte;          (* 1 byte  *)
         reserved3 : byte           (* 1 byte  *)
       end;


type draw_fontsize_ptr = ^draw_fontsize;
     draw_fontsize = integer;       (* 4 bytes, unsigned *)


type fontrec_ptr = ^fontrec;
     fontrec =
       record
         typeface : integer;       (* index into fontname table *)
         typesizex : integer;
         typesizey : integer;
         textcolour : draw_coltyp; (* text colour RGB *)
         background : draw_coltyp  (* hint for anti-aliased printing RGB *)
       end;


const
  draw_OBJFONTLIST =  0;
  draw_OBJTEXT     =  1;
  draw_OBJPATH     =  2;
  draw_OBJSPRITE   =  5;
  draw_OBJGROUP    =  6;
  draw_OBJTEXTAREA =  9;
  draw_OBJTEXTCOL  = 10;

type draw_tagtyp_ptr = ^draw_tagtyp;
     draw_tagtyp = integer;

type draw_objcoord_ptr = ^draw_objcoord;
     draw_objcoord =
       record
         x, y : integer
       end;

(* -------------------------------------------------------------------------  *
 *
 * File header
 *
 *
 *)                                                               
type draw_fileheader_ptr = ^draw_fileheader;
     draw_fileheader =
       record
         title : array[0..3] of byte;
         majorstamp : integer;
         minorstamp : integer;
         progident : packed array[1..11] of char;
         bbox : draw_bboxtyp      (* 4 words *)
       end;


(* -------------------------------------------------------------------------  *
 * General header for graphic objects
 *
 *)   

type draw_objhdr_ptr = ^draw_objhdr;
     draw_objhdr =
       record
         tag : draw_tagtyp;       (* 1 word  *)
         size : draw_sizetyp;     (* 1 word  *)
         bbox : draw_bboxtyp      (* 4 words *)
       end;


(* -------------------------------------------------------------------------
 *
 * A font list 
 *
 *
 *)

type draw_fontliststrhdr_ptr = ^draw_fontliststrhdr;
     draw_fontliststrhdr =
       record
         tag : draw_tagtyp;       (* 1 word  *)
         size : draw_sizetyp      (* 1 word  *)
       end;

type draw_fontliststr_ptr = ^draw_fontliststr;
     draw_fontliststr =
       record
         tag : draw_tagtyp;       (* 1 word  *)
         size : draw_sizetyp;     (* 1 word  *)
         fontref : draw_fontref;  (*  check size        *)
         fontname : packed array[1..1] of char
                                  (* String, null terminated *)
       end;


(* ------------------------------------------------------------------------- 
 *
 *
 * A line of text                                                             *
 *
 *)

type draw_textstrhdr_ptr = ^draw_textstrhdr;
     draw_textstrhdr =
       record
         tag : draw_tagtyp;             (* 1 word *)
         size : draw_sizetyp;           (* 1 word *)
         bbox : draw_bboxtyp;           (* 4 words *)
         textcolour : draw_coltyp;      (* 1 word  *)
         background : draw_coltyp;      (* 1 word  *)
         textstyle : draw_textstyle;    (* 1 word  *)
         fsizex : draw_fontsize;        (* 1 word, unsigned *)
         fsizey : draw_fontsize;        (* 1 word, unsigned *)
         coord : draw_objcoord          (* 2 words *)
       end;

type draw_textstr_ptr = ^draw_textstr;
     draw_textstr =
       record
         tag : draw_tagtyp;           (* 1 word  *)
         size : draw_sizetyp;         (* 1 word  *)
         bbox : draw_bboxtyp;         (* 4 words *)
         textcolour : draw_coltyp;    (* 1 word  *)
         background : draw_coltyp;    (* 1 word  *)
         textstyle : draw_textstyle;  (* 1 word  *)
         fsizex : draw_fontsize;      (* 1 word, unsigned *)
         fsizey : draw_fontsize;      (* 1 word, unsigned *)
         coord : draw_objcoord;       (* 2 words *)
         text : packed array[1..1] of char
                                      (* String, null terminated *)
       end;


(* -------------------------------------------------------------------------  *
 *
 * Elements within a path                                                     *
 *
 *)

const
  draw_PathTERM  = 0;     (* end of path                                   *)
  draw_PathMOVE  = 2;     (* move to (x,y), starts new subpath             *)
  draw_PathLINE  = 8;     (* line to (x,y)                                 *)
  draw_PathCURVE = 6;     (* bezier curve to (x3,y3) with 2 control points *)
  draw_PathCLOSE = 5;     (* close current subpath with a line             *)

type draw_path_tagtype_ptr = ^draw_path_tagtype;
     draw_path_tagtype = integer;

type Path_movestr_ptr = ^Path_movestr;
     Path_movestr =
       record
         tag : draw_path_tagtype;
         x, y : integer
       end;

type Path_linestr_ptr = ^Path_linestr;
     Path_linestr =
       record
         tag : draw_path_tagtype;
         x, y : integer
       end;

type Path_curvestr_ptr = ^Path_curvestr;
     Path_curvestr =
       record
         tag : draw_path_tagtype;
         x1, y1 : integer;
         x2, y2 : integer;
         x3, y3 : integer
       end;

type Path_closestr_ptr = ^Path_closestr;
     Path_closestr =
       record
         tag : draw_path_tagtype
       end;

type Path_termstr_ptr = ^Path_termstr;
     Path_termstr =
       record
         tag : draw_path_tagtype
       end;

type Largest_path_str_tag = 0..4;
     Largest_path_str_ptr = ^Largest_path_str;
     Largest_path_str =
       record               (* Use ONLY for space checking purposes *)
         case Largest_path_str_tag of
           0 : (a : Path_movestr);
           1 : (b : Path_linestr);
           2 : (c : Path_curvestr);
           3 : (d : Path_closestr);
           4 : (e : Path_termstr)
       end;

type Path_eleptr_tag = 0..6;
     Path_eleptr_ptr = ^Path_eleptr;
     Path_eleptr =
       record
         case Path_eleptr_tag of
           0 : (move : Path_movestr);
           1 : (line : Path_linestr);
           2 : (curve : Path_curvestr);
           3 : (close : Path_closestr);
           4 : (term : Path_termstr);
           5 : (bytep : ^byte);
           6 : (wordp : ^integer)
       end;


(* -------------------------------------------------------------------------  *
 *
 * Optional dashpattern                                                       *
 *
 *)


type draw_dashstrhdr_ptr = ^draw_dashstrhdr;
     draw_dashstrhdr =
       record
         dashstart : integer;    (* 1 word *)   (* distance into pattern *)
         dashcount : integer     (* 1 word *)   (* number of elements    *)
       end;

type draw_dashstr_ptr = ^draw_dashstr;
     draw_dashstr =
       record
         dashstart : integer;    (* 1 word *)   (* distance into pattern *)
         dashcount : integer;    (* 1 word *)   (* number of elements    *)
         dashelements : array[0..5] of integer
                         (* dashcount words *)  (* elements of pattern   *)
       end;


(* -------------------------------------------------------------------------  *
 *
 * Unpacked joint,start cap,end cap structure - as fed to drawmod_stroke etc  *
 *
 *)

type draw_jointspec_ptr = ^draw_jointspec;
     draw_jointspec =
       record
         join : byte;
         endcap : byte;
         startcap : byte;
         reserved : byte;  (* must be zero *)
         mitrelimit : byte;
         endtricapwid : short;
         endtricaphei : short;
         starttricapwid : short;
         starttricaphei : short
       end;


(* -------------------------------------------------------------------------  *
 *
 * A path
 *
 *)                                                                    

type draw_pathstrhdr_ptr = ^draw_pathstrhdr;
     draw_pathstrhdr =
       record
         tag : draw_tagtyp;          (* 1 word  *)
         size : draw_sizetyp;        (* 1 word  *)
         bbox : draw_bboxtyp;        (* 4 words *)
         fillcolour : draw_coltyp;   (* 1 word  *)
         pathcolour : draw_coltyp;   (* 1 word  *)
         pathwidth : draw_pathwidth; (* 1 word  *)
         pathstyle : draw_pathstyle  (* 1 word  *)
       end;

type draw_pathstr_ptr = ^draw_pathstr;
     draw_pathstr =
       record
         tag : draw_tagtyp;          (* 1 word  *)
         size : draw_sizetyp;        (* 1 word  *)
         bbox : draw_bboxtyp;        (* 4 words *)
         fillcolour : draw_coltyp;   (* 1 word  *)
         pathcolour : draw_coltyp;   (* 1 word  *)
         pathwidth : draw_pathwidth; (* 1 word  *)
         pathstyle : draw_pathstyle; (* 1 word  *)
         data : draw_dashstr; (* optional dash pattern, then path elements *)
         PATH : integer
       end;


(* -------------------------------------------------------------------------
 *
 *
 * A sprite
 *
 *)                                                                  

type draw_spristrhdr_ptr = ^draw_spristrhdr;
     draw_spristrhdr =
       record
         tag : draw_tagtyp;       (* 1 word  *)  
         size : draw_sizetyp;     (* 1 word  *)   
         bbox : draw_bboxtyp      (* 4 words *) 
       end;

type draw_spristr_ptr = ^draw_spristr;
     draw_spristr =
       record
         tag : draw_tagtyp;       (* 1 word  *)
         size : draw_sizetyp;     (* 1 word  *)
         bbox : draw_bboxtyp;     (* 4 words *)
         sprite : sprite_header;
         palette : array[1..1] of integer
                                (* depends on sprite.mode (or not present) *)
       end;


(* -------------------------------------------------------------------------  *
 *
 * A grouping                                                                 *
 *)

type draw_groupnametyp_ptr = ^draw_groupnametyp;
     draw_groupnametyp =
       record
         ch : packed array[1..11] of char  (* 12 bytes *)
       end;

type draw_groustr_ptr = ^draw_groustr;
     draw_groustr =
       record
         tag : draw_tagtyp;       (* 1 word   *)
         size : draw_sizetyp;     (* 1 word   *)
         bbox : draw_bboxtyp;     (* 4 words  *)
         name : draw_groupnametyp (* 12 bytes *)
       end;


(* -------------------------------------------------------------------------  *
 *
 * A text column                                                              * These only appear nested within a text area.
 *
 *)

type draw_textcolhdr_ptr = ^draw_textcolhdr;
     draw_textcolhdr =
       record
         tag : draw_tagtyp;        (* 1 word  *)
         size : draw_sizetyp;      (* 1 word  *)
         bbox : draw_bboxtyp       (* 4 words *)
       end;


(* -------------------------------------------------------------------------  *
 *
 * A text area object
 *
 *
 *)

type draw_textareastrhdr_ptr = ^draw_textareastrhdr;
     draw_textareastrhdr =
       record
         tag : draw_tagtyp;        (* 1 word  *)
         size : draw_sizetyp;      (* 1 word  *)
         bbox : draw_bboxtyp;      (* 4 words *)
         column : draw_textcolhdr  (* Hook for pointing to text columns *)
       end;

type draw_textareahdr_ptr = ^draw_textareahdr;
     draw_textareahdr =
       record
         tag : draw_tagtyp;        (* 1 word  *)
         size : draw_sizetyp;      (* 1 word  *)
         bbox : draw_bboxtyp       (* 4 words *)
         (* Text columns go in here *)
       end;

(* End structure - follows all the column *)
type draw_textareastrend_ptr = ^draw_textareastrend;
     draw_textareastrend =         (* Structure for getting size *)
       record
         endmark : integer;       (* 1 word, always 0 *)
         blank1 : integer;        (* 1 word, reserved for future expansion *)
         blank2 : integer;        (* 1 word, reserved for future expansion *)
         textcolour : draw_coltyp;(* 1 word *)
         backcolour : draw_coltyp (* 1 word *)
         (* String goes in here *)
       end;

type draw_textareaend_ptr = ^draw_textareaend;
     draw_textareaend =
       record
         endmark : integer;    (* 1 word, always 0 *)
         blank1 : integer;     (* 1 word, reserved for future expansion *)
         blank2 : integer;     (* 1 word, reserved for future expansion *)
         textcolour : draw_coltyp; (* 1 word *)
         backcolour : draw_coltyp; (* 1 word *)
         text : packed array[1..1] of char
                               (* String, null terminated *)
       end;

#endif

(* end of drawtypes.h *)
