/*
 * Scan 'C' Header File
 * Written by Thomas Krehbiel
 *
 * Modules and ScanBase.
 *
 */

#ifndef SCAN_MOD_H


#ifndef EXEC_TYPES_H
#include <exec/types.h>
#endif

#ifndef EXEC_LIBRARIES_H
#include <exec/libraries.h>
#endif

#ifndef EXEC_SEMAPHORES_H
#include <exec/semaphores.h>
#endif

#ifndef LIBRARIES_DOS_H
#include <libraries/dos.h>
#endif

#ifndef SCAN_GED_H
#include <scan/ged.h>
#endif
#ifndef SCAN_PREFS_H
#include <scan/prefs.h>
#endif
#ifndef SCAN_CMD_H
#include <scan/cmd.h>
#endif
#ifndef SCAN_BUF_H
#include <scan/buf.h>
#endif

/*
 * Module Types, to be found in the Node->ln_Type field.  I think NT_USER
 * is defined in exec/nodes.h
 */
#define NT_PREVIEW            (NT_USER-1)
#define NT_SCANNER            (NT_USER-2)
#define NT_RENDER             (NT_USER-3)
#define NT_PRINTER            (NT_USER-4)
#define NT_QUANTIZE           (NT_USER-5)
#define NT_DITHER             (NT_USER-6)
#define NT_LOADER             (NT_USER-7)
#define NT_SAVER              (NT_USER-8)
#define NT_HOOK               (NT_USER-9)
#define NT_DRAWMODE           (NT_USER-10)
#define NT_PEN                (NT_USER-11)
#define NT_PAPER              (NT_USER-12)
#define NT_SYSTEM             (NT_USER-13)

/*
 * ModuleBase - This is the standard library node used by
 *              external modules.  Image Scan will create
 *              this structure when the module is opened.
 *
 *              The module should fill in the NumGads, NewGad,
 *              Language, and LangCount fields before returning
 *              from its custom Open function.
 */

struct ModuleBase {
   struct Library       Library;       /* Standard Exec library */
   UBYTE                Flags;         /* Generic Flags - see below */
   BYTE                 pad;           /* was NumGads - now a pad */
   BPTR                 Segment;       /* AmigaDos module segment */
   struct Library      *SysLib;        /* Exec.library pointer */
   struct ScanBase     *ScanBase;      /* scan.library pointer */
   struct NewGad       *NewGad;        /* Pointer to custom gadgets */
   struct GedContext    GContext;      /* Gadget context maintained by Scan */
   char                *Language;      /* Scan.text "tag" for finding text */
   char               **Text;          /* Text array loaded by Scan */
   long                 LangCount;     /* Count of entries in text array */
   RXCMD               *CmdTable;      /* Table of commands recognized */
   ULONG                PrefID;        /* Prefs file identifier */
   ULONG                PrefLen;       /* Length of prefs data chunk */
   struct NewWindow    *NewWin;        /* NewWindow for preview options */
   ULONG                ExtFlags;      /* Extended flags - future expansion */
   ULONG                Reserved[12];  /* Reserved for expansion */
   /*
    * 64 bytes of space are reserved here
    * for information specific to the
    * module.  Image Scan ignores this
    * data but guarantees its integrity.
    */
};

/*
 * Flag bits:
 */
#define MF_VISIBLE      (0x01)         /* Scan sets this flag when your
                                          module is visible onscreen (ie.
                                          the gadgets may be updated
                                          without fear of crashing). */
#define MF_TEXTLOADED   (0x02)         /* Text has been loaded */

/*
 * Extended flag bits:
 */
#define XF_MOUSETRAP    (0x01)         /* Module should be notified of
                                          mouse button and movement events.
                                          Your module's *_HandleMMove() and
                                          *_HandleMButton() will be called
                                          upon seeing mouse button/movement
                                          events; you should return non-zero
                                          if you processed the event yourself.
                                          You are passed a pointer to a COPY
                                          of the event, do not reply to it.
                                          Only for Scanner, Render, Printer
                                          modules. */
#define XF_24BITREND    (0x02)         /* Rendered images are really 24-bit */
#define XF_MOVEMENU     (0x04)         /* Preview module wants to be notified
                                          when the menu panel moves, gets
                                          hidden, or whatever. */
#define XF_EXTENDEDINIT (0x08)         /* Preview module can handle extended
                                          initialization routine */
#define XF_GHOST        (0x10)         /* Preview module can ghost unused
                                          areas of the screen */
#define XF_STICKY       (0x20)         /* "Sticky" modules remain in memory,
                                          currently only used for savers
                                          such as ANIM and FLC */
#define XF_IDENTIFY     (0x40)         /* Loader can identify headers */
#define XF_LOADNOTIFY   (0x80)         /* Module can handle load notification -
                                          a module vector will be called when
                                          a new image is loaded, created,
                                          whatever by the user */

#define NumGads         pad            /* Ancient compatibility, do not use */

/*
 * ScanBase - The library base maintained by Image Scan.  Hook programs
 *            will open this library to gain access to Image Scan functions,
 *            while modules will be passed a pointer directly to this
 *            base for accessing the same functions.  These fields should
 *            be considered READ ONLY, except where noted otherwise.  They
 *            are intended to be used for Hooks and Modules to gain
 *            information about the current state of Mirage.
 */

struct ScanBase {
   struct Library          Library;       /* Standard Exec library */
   struct Screen          *pScreen;       /* Pointer to menu panel screen */
   struct Window          *pWindow;       /* Pointer to menu panel window */
   struct RastPort        *pRPort;        /* Pointer to menu panel rastport */
   struct UserPrefs        Prefs;         /* User preferences settings */
   struct IntuitionBase   *IntuitionBase; /* Intuition.library base */
   struct GfxBase         *GfxBase;       /* Graphics.library base */
   unsigned long           LastError;     /* Global error variable */
   struct Buffer          *MainBuffer;    /* Main (visible) buffer */
   struct Buffer          *SwapBuffer;    /* Swap (hidden) buffer */
   char                  **Text;          /* Language text array */
   struct SignalSemaphore  Lock;          /* Arbitrate access to library (unused) */
   struct Buffer          *Alpha;         /* Alpha channel buffer */

   /*
    * New as of Mirage 0.53
    */
   signed char             sb_AreaTool;   /* Current region selection */
   signed char             sb_DrawTool;   /* Current drawing tool */
   unsigned char           sb_Channel;    /* Current channel mask setting */
   signed char             sb_GuiLocked;  /* Are graphics locked? */

   signed char             sb_ArexxCmd;   /* Currently execute Arexx cmd? */
   signed char             sb_Iconified;  /* Are we currently iconified? */

   signed char             sb_FillType;   /* Current fill type */
   signed char             sb_FillRange1; /* Gradient fill range #1 */
   signed char             sb_FillRange2; /* Gradient fill range #2 */
   signed char             sb_FillSmooth; /* Gradient fills are smoothed? */
   signed char             sb_FillSkew;   /* Gradient fill "skew" */
   signed char             sb_FillRough;  /* Area fill "roughness" */
   short                   sb_FloodClose; /* Flood fill "closeness" */
   signed char             sb_LightTab;   /* LightTable on? */
   signed char             sb_AlphaMask;  /* Use alpha as stencil/frisket? */

   signed char             sb_EdgeMode;   /* Current edge mode */
   unsigned char           sb_EdgeDir;    /* Edge direction mask */
   short                   sb_EdgeRadius; /* Edge radius affected */

   signed char             sb_Hidden;     /* Menu panel hidden? */
   signed char             sb_TranspRange;/* Transparent range */
   short                   sb_TranspClose;/* Transparent "closeness" */

   signed char             sb_AirRadius;  /* Airbrush radius */
   signed char             sb_DrawMode;   /* Current drawing mode */
   signed char             sb_DrawBlend;  /* Current blend setting */
   signed char             sb_Mode;       /* Which menu we're in */

   short                   sb_GridX,      /* Grid Width */
                           sb_GridY,      /* Grid Height */
                           sb_GOffsetX,   /* Grid X Origin */
                           sb_GOffsetY;   /* Grid Y Origin */

   struct Buffer          *sb_Brush;      /* Current Brush */

   struct ModuleBase      *sb_Scanner;    /* The current Scanner module */
   struct ModuleBase      *sb_Render;     /* The current Render module */
   struct ModuleBase      *sb_Printer;    /* The current Printer module */

   char                   *sb_PubName;    /* Public screen name */
   char                   *sb_ArexxName;  /* Arexx port name */

   BPTR                    sb_CurrentDir; /* Lock on Mirage current dir */
   struct Task            *sb_ThisTask;   /* Pointer to Mirage task */

   char                    sb_DrawAlpha;  /* Alpha channel status for drawing */
   char                    sb_AirDensity; /* Airbrush center density */
   char                    sb_AirSmear;   /* Airbrush smear mode */
   char                    sb_BackPen;    /* Menu panel background pen # */

   struct Screen          *sb_Shanghai;   /* "Shanghai" screen */

   char                    sb_PenType;    /* Type of default pen */
   char                    sb_PenSize;    /* Size of default pen */
   char                    sb_AlphaTab;   /* Light table to swap or alpha? */
   char                    sb_AirRough;   /* Airbrush roughness */

   struct RexxMsg         *sb_HookMsg;    /* Message that invokes a hook */

   struct Screen          *sb_vScreen;    /* Preview screen, or NULL */

   BPTR                    sb_HelpLock;   /* Where the help directory is */

   struct MsgPort         *sb_HostPort;   /* Scan arexx port */

   ULONG                   sb_Magic;      /* Magic constant, just for fun */

   BPTR                    sb_TextLock;   /* Text directory lock */

   short                   sb_PantoDX;    /* Pantograph offsets */
   short                   sb_PantoDY;

   short                   sb_PantoCX;    /* Pantograph center coords */
   short                   sb_PantoCY;

   UBYTE                  *sb_PenArray;   /* Pen definition */
   short                   sb_PenWidth;   /* Pen width */
   short                   sb_PenHeight;  /* Pen height */

   UBYTE                  *sb_AirArray;   /* Airbrush definition */
   short                   sb_AirWidth;   /* Airbrush width */
   short                   sb_AirHeight;  /* Airbrush height */

   UBYTE                   sb_Exclusive;  /* Disable GUI - exclusive access */
   UBYTE                   sb_pad3[3];

   char                    sb_LearnOpts[64];
                                          /* A rather kludgy way to get loader
                                             and saver options back to ImageFX
                                             while learning - modules should
                                             place a string here describing
                                             the options used, and ImageFX
                                             will grab the string and spit
                                             it out to the learn file. */

   ULONG                   Reserved[15];  /* For future expansion */
};

#define MIRAGE_MAGIC      'TEK!'          /* Magic constant */

#define pScreen            ScanBase->pScreen
#define pWindow            ScanBase->pWindow
#define pRPort             ScanBase->pRPort
#define Prefs              ScanBase->Prefs

/*
 * Some defines for ancient compatibility, please don't use in new code.
 */
#ifdef SCANPRIVATE

#define Mode               ScanBase->sb_Mode
#define Hidden             ScanBase->sb_Hidden
#define LightTable         ScanBase->sb_LightTab
#define AlphaMask          ScanBase->sb_AlphaMask

#define AreaTool           ScanBase->sb_AreaTool
#define DrawTool           ScanBase->sb_DrawTool
#define Channel            ScanBase->sb_Channel
#define GridX              ScanBase->sb_GridX
#define GridY              ScanBase->sb_GridY
#define GridXOffs          ScanBase->sb_GOffsetX
#define GridYOffs          ScanBase->sb_GOffsetY

#define GuiLocked          ScanBase->sb_GuiLocked
#define ArexxCommand       ScanBase->sb_ArexxCmd

#define FillType           ScanBase->sb_FillType
#define FillRange1         ScanBase->sb_FillRange1
#define FillRange2         ScanBase->sb_FillRange2
#define FillSmooth         ScanBase->sb_FillSmooth
#define FillSkew           ScanBase->sb_FillSkew
#define FillRoughness      ScanBase->sb_FillRough
#define FloodCloseness     ScanBase->sb_FloodClose

#define DrawMode           ScanBase->sb_DrawMode
#define DrawBlend          ScanBase->sb_DrawBlend

#define EdgeMode           ScanBase->sb_EdgeMode
#define EdgeRadius         ScanBase->sb_EdgeRadius
#define EdgeDir            ScanBase->sb_EdgeDir

#define TransparentRange   ScanBase->sb_TranspRange
#define TransparentCloseness ScanBase->sb_TranspClose

#define Brush              ScanBase->sb_Brush

#define AirbrushRadius     ScanBase->sb_AirRadius
#define AirbrushDensity    ScanBase->sb_AirDensity
#define AirbrushSmear      ScanBase->sb_AirSmear

#define Iconified          ScanBase->sb_Iconified

#define HostPort           ScanBase->sb_HostPort

#endif

#define SCAN_MOD_H
#endif
