home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 3 / goldfish_volume_3.bin / files / gfx / misc / imagefx_sdk / sas / examples / xstyle / mandala.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-15  |  6.5 KB  |  286 lines

  1. /*
  2.  * A Mandala Enhanced Drawing Mode for ImageFX 2.0
  3.  *
  4.  */
  5.  
  6. #include <exec/types.h>
  7. #include <scan/modall.h>
  8. #include <scan/drawinfo.h>
  9. #include <string.h>
  10. #include "common.h"
  11.  
  12. /**********************************************************************\
  13.  
  14.                                 Library Vectors
  15.  
  16. \**********************************************************************/
  17.  
  18. /*
  19.  * XDM_Attr:
  20.  *
  21.  * Return to ImageFX some information about the Drawing Style (eg.
  22.  * whether Options are needed, whether we work on greyscale or
  23.  * color, etc.).  Called when ImageFX first scans the drawing
  24.  * style directory.
  25.  *
  26.  */
  27. ULONG __saveds __asm XDS_Attr (register __a0 struct XDrawAttr *attr)
  28. {
  29.    attr->Flags = XDMF_RedrawTrap | XDMF_UndoTrap;
  30.    attr->Priority = 121;
  31.    attr->Iterations = 4;
  32.    return(0);
  33. }
  34.  
  35. /*
  36.  * XDS_Begin:
  37.  *
  38.  * Prepare before a pixel affecting operation.
  39.  *
  40.  */
  41. int __saveds __asm XDS_Begin (register __a0 struct IDrawInfo *di)
  42. {
  43.    di->SPrivate = (APTR)ScanBase->MainBuffer;
  44.    return(1);
  45. }
  46.  
  47. /*
  48.  * XDS_End:
  49.  *
  50.  * Cleanup after a pixel affecting operation.
  51.  *
  52.  */
  53. void __saveds __asm XDS_End (register __a0 struct IDrawInfo *di)
  54. {
  55. }
  56.  
  57. static orig_le, orig_te;
  58.  
  59. /*
  60.  * XDS_Get:
  61.  *
  62.  *
  63.  */
  64. int __saveds __asm XDS_Get (register __a0 struct IDrawInfo *di)
  65. {
  66.    struct Buffer *buf = (struct Buffer *)di->SPrivate;
  67.  
  68.    if (!buf) return(0);
  69.  
  70.    switch(di->SIteration)
  71.    {
  72.       case 0 :
  73.          orig_le = di->LE;
  74.          orig_te = di->TE;
  75.          break;
  76.       case 1 :
  77.          di->LE = (buf->Width / 2) + ((buf->Width / 2) - orig_le) - di->Width;
  78.          di->TE = orig_te;
  79.          break;
  80.       case 2 :
  81.          di->LE = (buf->Width / 2) + ((buf->Width / 2) - orig_le) - di->Width;
  82.          di->TE = (buf->Height / 2) + ((buf->Height / 2) - orig_te) - di->Height;
  83.          break;
  84.       case 3 :
  85.          di->LE = orig_le;
  86.          di->TE = (buf->Height / 2) + ((buf->Height / 2) - orig_te) - di->Height;
  87.          break;
  88.    }
  89.  
  90.    GetFromBuf(buf, di);
  91.  
  92.    return(1);
  93. }
  94.  
  95. /*
  96.  * XDS_Put:
  97.  *
  98.  *
  99.  */
  100. int __saveds __asm XDS_Put (register __a0 struct IDrawInfo *di)
  101. {
  102.    struct Buffer *buf = (struct Buffer *)di->SPrivate;
  103.  
  104.    if (!buf) return(0);
  105.  
  106.    PutToBuf(buf, di);
  107.  
  108.    return(1);
  109. }
  110.  
  111. /*
  112.  * XDS_Options:
  113.  *
  114.  * Present a window to the user allowing him to adjust drawing style
  115.  * options.  Arguments may optionally be passed from an Arexx command.
  116.  *
  117.  */
  118. int __saveds __asm XDS_Options (register __a0 LONG *args)
  119. {
  120.    return(0);
  121. }
  122.  
  123. /*
  124.  * XDS_LoadPrefs:
  125.  *
  126.  * Set preferences according to information loaded from disk.
  127.  *
  128.  */
  129. int __saveds __asm XDS_LoadPrefs (register __a0 void *prefs)
  130. {
  131.    return(1);
  132. }
  133.  
  134. /*
  135.  * XDS_SavePrefs:
  136.  *
  137.  * Request preferences settings that are about to be saved to disk.
  138.  *
  139.  */
  140. int __saveds __asm XDS_SavePrefs (register __a0 void *prefs)
  141. {
  142.    return(1);
  143. }
  144.  
  145. int __saveds __asm XDS_Init (void)
  146. {
  147.    return(1);
  148. }
  149.  
  150. void __saveds __asm XDS_Cleanup (void)
  151. {
  152. }
  153.  
  154. void __saveds __asm XDS_Redraw (register __d0 int left,
  155.                                 register __d1 int top,
  156.                                 register __d2 int right,
  157.                                 register __d3 int bottom)
  158. {
  159.    struct Buffer *buf = ScanBase->MainBuffer;
  160.    int w, h;
  161.  
  162.    w = (right - left) + 1;
  163.    h = (bottom - top) + 1;
  164.  
  165.    RedrawArea(left, top, right, bottom);
  166.  
  167. #define MIRRORX1(x)   ((buf->Width/2) + ((buf->Width/2) - (x)) - (w))
  168. #define MIRRORY1(y)   ((buf->Height/2) + ((buf->Height/2) - (y)) - (h))
  169.  
  170.    RedrawArea(MIRRORX1(left), top, MIRRORX1(left)+w-1, bottom);
  171.    RedrawArea(MIRRORX1(left), MIRRORY1(top), MIRRORX1(left)+w-1, MIRRORY1(top)+h-1);
  172.    RedrawArea(left, MIRRORY1(top), right, MIRRORY1(top)+h-1);
  173. }
  174.  
  175. BOOL __saveds __asm XDS_SaveUndo (register __a0 struct Buffer *buf,
  176.                                   register __d0 int left,
  177.                                   register __d1 int top,
  178.                                   register __d2 int w,
  179.                                   register __d3 int h)
  180. {
  181.    int x1, y1, x2, y2;
  182.    int right, bottom;
  183.  
  184.    right = left + w - 1;
  185.    bottom = top + h - 1;
  186.  
  187.    x1 = MIRRORX1(left);
  188.    y1 = top;
  189.    x2 = MIRRORX1(left)+w-1;
  190.    y2 = bottom;
  191.    if (x1 < left) left = x1;
  192.    if (y1 < top) top = y1;
  193.    if (x2 > right) right = x2;
  194.    if (y2 > bottom) bottom = y2;
  195.  
  196.    x1 = MIRRORX1(left);
  197.    y1 = MIRRORY1(top);
  198.    x2 = MIRRORX1(left)+w-1;
  199.    y2 = MIRRORY1(top)+h-1;
  200.    if (x1 < left) left = x1;
  201.    if (y1 < top) top = y1;
  202.    if (x2 > right) right = x2;
  203.    if (y2 > bottom) bottom = y2;
  204.  
  205.    x1 = left;
  206.    y1 = MIRRORY1(top);
  207.    x2 = right;
  208.    y2 = MIRRORY1(top)+h-1;
  209.    if (x1 < left) left = x1;
  210.    if (y1 < top) top = y1;
  211.    if (x2 > right) right = x2;
  212.    if (y2 > bottom) bottom = y2;
  213.  
  214.    return(SaveUndo(buf, left, top, (right-left+1), (bottom-top+1)));
  215. }
  216.  
  217. /**********************************************************************\
  218.  
  219.                          Library Initialization Stuff
  220.  
  221. \**********************************************************************/
  222.  
  223. /*
  224.  * This is the table of all the functions that can be called in this
  225.  * module.  The first four (Open, Close, Expunge, and Null) are reserved
  226.  * for system use and MUST be specified in the order shown.  The actual
  227.  * functions are in the standard module startup code.
  228.  */
  229. ULONG FuncTable[] = {
  230.    /* These four MUST be present in this order */
  231.    (ULONG) LibOpen,
  232.    (ULONG) LibClose,
  233.    (ULONG) LibExpunge,
  234.    (ULONG) LibNull,
  235.  
  236.    /* Specific to the module */
  237.    (ULONG) XDS_Attr,
  238.    (ULONG) XDS_Begin,
  239.    (ULONG) XDS_End,
  240.    (ULONG) XDS_Get,
  241.    (ULONG) XDS_Put,
  242.    (ULONG) XDS_Options,
  243.    (ULONG) XDS_LoadPrefs,
  244.    (ULONG) XDS_SavePrefs,
  245.    (ULONG) 0,
  246.    (ULONG) 0,
  247.    (ULONG) XDS_Init,
  248.    (ULONG) XDS_Cleanup,
  249.    (ULONG) XDS_Redraw,
  250.    (ULONG) XDS_SaveUndo,
  251.  
  252.    /* End with -1L */
  253.    (ULONG) -1L
  254. };
  255.  
  256. /*
  257.  * These are used by the standard module startup code.
  258.  * LibraryName is the name of the library, and LibraryID is a short
  259.  * description of the library.  Both of these are largely irrelavent,
  260.  * but they are included just for completeness.
  261.  */
  262. UBYTE LibraryID[]    = "$VER: Mandala Drawing Style 2.0.15 (15.2.95)";
  263. UBYTE LibraryType    = NT_XDRAWSTYLE;
  264.  
  265. /*
  266.  * This is called by the standard module startup code when Image Scan
  267.  * first opens the module.  Here we should fill in the NumGads,
  268.  * NewGad, Language, and LangCount fields of the provided ModuleBase
  269.  * structure if necessary.
  270.  */
  271. long  __asm UserOpen (register __a6 struct ModuleBase *modbase)
  272. {
  273.    return(TRUE);
  274. }
  275.  
  276. /*
  277.  * This is called by the standard module startup code when Image Scan
  278.  * closes the module.  It should cleanup anything allocated or obtained
  279.  * in the UserOpen() function.
  280.  */
  281. long  __asm UserClose (register __a6 struct ModuleBase *modbase)
  282. {
  283.    return(TRUE);
  284. }
  285.  
  286.