home *** CD-ROM | disk | FTP | other *** search
- /*
- * A Pantograph Enhanced Drawing Mode for ImageFX 2.0
- *
- */
-
- #include <exec/types.h>
- #include <scan/modall.h>
- #include <scan/drawinfo.h>
- #include <string.h>
- #include "common.h"
-
-
- /**********************************************************************\
-
- Static Variables
-
- \**********************************************************************/
-
- static struct Buffer *panto_buf = NULL;
- static LONG panto_mode = 0;
- static BOOL delta_not_set = TRUE;
-
- /**********************************************************************\
-
- Support Functions
-
- \**********************************************************************/
-
- void InitPantoDraw (void)
- {
- struct Buffer *buf;
- UBYTE *red, *grn, *blu, *pred, *pgrn, *pblu;
- int j;
-
- buf = ScanBase->MainBuffer;
- if (panto_buf = AllocBuffer(NULL, buf->Width, buf->Height, buf->Depth, 8, 0)) {
- for (j = 0; j < buf->Height; j++) {
- if (!GetBufLine(buf, &red, &grn, &blu, j)) break;
- if (!GetBufLine(panto_buf, &pred, &pgrn, &pblu, j)) break;
- memcpy(pred, red, buf->Width);
- if (buf->Depth > 1) {
- memcpy(pgrn, grn, buf->Width);
- memcpy(pblu, blu, buf->Width);
- }
- if (!PutBufLine(panto_buf)) break;
- }
- }
- }
-
- void CleanupPantoDraw (void)
- {
- if (panto_buf) KillBuffer(panto_buf);
- panto_buf = NULL;
- }
-
-
- static short oldx, oldy;
-
- void MovePantograph (int x, int y)
- {
- DrawBoxOnPreview2(oldx - 4, oldy - 4, oldx + 4, oldy + 4);
- oldx = x;
- oldy = y;
- DrawBoxOnPreview2(oldx - 4, oldy - 4, oldx + 4, oldy + 4);
- }
-
- void InitPantograph (int x, int y)
- {
- oldx = x;
- oldy = y;
- DrawBoxOnPreview2(oldx - 4, oldy - 4, oldx + 4, oldy + 4);
- }
-
- void CleanupPantograph (void)
- {
- DrawBoxOnPreview2(oldx - 4, oldy - 4, oldx + 4, oldy + 4);
- }
-
-
- static short coldx = -1, coldy = -1;
-
- void MovePantoCenter (void)
- {
- DrawBoxOnPreview2(coldx - 3, coldy - 3, coldx + 3, coldy + 3);
- coldx = ScanBase->sb_PantoCX;
- coldy = ScanBase->sb_PantoCY;
- DrawBoxOnPreview2(coldx - 3, coldy - 3, coldx + 3, coldy + 3);
- }
-
- void InitPantoCenter (void)
- {
- coldx = ScanBase->sb_PantoCX;
- coldy = ScanBase->sb_PantoCY;
- DrawBoxOnPreview2(coldx - 3, coldy - 3, coldx + 3, coldy + 3);
- }
-
- void CleanupPantoCenter (void)
- {
- if (coldx >= 0) {
- DrawBoxOnPreview2(coldx - 3, coldy - 3, coldx + 3, coldy + 3);
- coldx = -1;
- }
- }
-
- /**********************************************************************\
-
- Library Vectors
-
- \**********************************************************************/
-
- /*
- * XDM_Attr:
- *
- * Return to ImageFX some information about the Drawing Style (eg.
- * whether Options are needed, whether we work on greyscale or
- * color, etc.). Called when ImageFX first scans the drawing
- * style directory.
- *
- */
- ULONG __saveds __asm XDS_Attr (register __a0 struct XDrawAttr *attr)
- {
- attr->Flags = XDMF_AreOptions | XDMF_MouseTrap | XDMF_RedrawTrap;
- attr->Priority = 122;
- return(0);
- }
-
- /*
- * XDS_Begin:
- *
- * Prepare before a pixel affecting operation.
- *
- */
- int __saveds __asm XDS_Begin (register __a0 struct IDrawInfo *di)
- {
- di->SPrivate = (APTR)ScanBase->MainBuffer;
- InitPantoDraw();
- return(1);
- }
-
- /*
- * XDS_End:
- *
- * Cleanup after a pixel affecting operation.
- *
- */
- void __saveds __asm XDS_End (register __a0 struct IDrawInfo *di)
- {
- CleanupPantoDraw();
- }
-
- /*
- * XDS_Get:
- *
- *
- */
- int __saveds __asm XDS_Get (register __a0 struct IDrawInfo *di)
- {
- struct Buffer *buf;
- UBYTE *sr, *sg, *sb;
- UBYTE *dr, *dg, *db;
- UBYTE *red, *grn, *blu;
- int i, j;
- int w, h;
- int x, y;
-
- GetFromBuf((struct Buffer *)di->SPrivate, di);
-
- #ifdef USE_BUFFERS
-
- /*
- * Only copy if space has been allocated for us. Some drawing
- * modes may not require this information, so the buffers may
- * not be allocated to save time & space.
- */
-
- if (di->BPen)
- {
-
- buf = (panto_buf) ? panto_buf : (struct Buffer *)di->SPrivate;
- if (!buf) return(0);
-
- y = di->TE + ScanBase->sb_PantoDY;
-
- w = di->Width;
- h = di->Height;
-
- for (j = 0; j < h; j++, y++)
- {
-
- GetBufLine(di->BPen, &dr, &dg, &db, j);
-
- x = di->LE + ScanBase->sb_PantoDX;
-
- if ((y >= 0) && (y < buf->Height))
- {
- if (GetBufLine(buf, &red, &grn, &blu, y))
- {
- sr = red + x;
- sg = grn + x;
- sb = blu + x;
- for (i = 0; i < w; i++, x++) {
- if ((x < 0) || (x >= buf->Width)) {
- dr[i] = dg[i] = db[i] = 0;
- }
- else {
- dr[i] = sr[i];
- dg[i] = sg[i];
- db[i] = sb[i];
- }
- }
- }
- }
- else
- {
- /* outside bounds of image is black */
- memset(dr, 0, w);
- memset(dg, 0, w);
- memset(db, 0, w);
- }
-
- PutBufLine(di->BPen);
-
- }
-
- }
-
- #else
-
- /*
- * Only copy if space has been allocated for us. Some drawing
- * modes may not require this information, so the buffers may
- * not be allocated to save time & space.
- */
-
- if (di->PenR && di->PenG && di->PenB)
- {
-
- buf = (panto_buf) ? panto_buf : (struct Buffer *)di->SPrivate;
- if (!buf) return(0);
-
- y = di->TE + ScanBase->sb_PantoDY;
-
- w = di->Width;
- h = di->Height;
-
- dr = di->PenR;
- dg = di->PenG;
- db = di->PenB;
-
- for (j = 0; j < h; j++, y++)
- {
-
- x = di->LE + ScanBase->sb_PantoDX;
-
- if ((y >= 0) && (y < buf->Height))
- {
- if (GetBufLine(buf, &red, &grn, &blu, y))
- {
- sr = red + x;
- sg = grn + x;
- sb = blu + x;
- for (i = 0; i < w; i++, x++) {
- if ((x < 0) || (x >= buf->Width)) {
- dr[i] = dg[i] = db[i] = 0;
- }
- else {
- dr[i] = sr[i];
- dg[i] = sg[i];
- db[i] = sb[i];
- }
- }
- }
- }
- else
- {
- /* outside bounds of image is black */
- memset(dr, 0, w);
- memset(dg, 0, w);
- memset(db, 0, w);
- }
-
- dr += di->Width;
- dg += di->Width;
- db += di->Width;
-
- }
-
- }
-
- #endif
-
- return(1);
- }
-
- /*
- * XDS_Put:
- *
- *
- */
- int __saveds __asm XDS_Put (register __a0 struct IDrawInfo *di)
- {
- struct Buffer *buf = (struct Buffer *)di->SPrivate;
-
- PutToBuf(buf, di);
-
- return(1);
- }
-
- #include "panto_strings.h"
-
- #define WID 300
- #define HT 58
-
- enum {
- ID_Okay = 2,
- ID_Cancel,
- ID_Mode,
- };
-
- long mode;
- long ModeArray[] = { G_Mode1, G_Mode2, -1 };
-
- struct NewGad newGads[] = {
- { Scale_ID },
-
- { Button_ID, ID_Okay, 8,HT-16,100,12, G_Okay, NULL,0, NULL, ID_Okay,0,0,0 },
- { Button_ID, ID_Cancel, WID-100-8,HT-16,100,12, G_Cancel, NULL,0,NULL, ID_Cancel,0,0,0 },
- { Cycle_ID, ID_Mode, 80,20,(WID-16-80),12, G_Mode, NULL,0,&mode, (long)ModeArray,0,0,0 },
-
- { Text_ID, 0, WID/2,4,0,0, L_Title, NULL,0,NULL, 2,0,2,0 },
-
- { Border_ID, 0, 0,0,WID,HT, 0, NULL,0,NULL, 0,1,0,0 },
- { Border_ID, 0, 8,13,WID-16,HT-31, 0, NULL,0,NULL, 1,0,0,0 },
-
- { End_ID }
- };
-
- struct NewWindow newWindow = {
- 0,0,WID,HT,
- 0,1,
- GADGETDOWN|GADGETUP|VANILLAKEY,
- BORDERLESS|ACTIVATE|NOCAREREFRESH|SMART_REFRESH|RMBTRAP,
- NULL, /* FirstGadget - Filled later */
- NULL,
- NULL,
- NULL,
- NULL,
- 0,0,0,0,
- WBENCHSCREEN
- };
-
- /*
- * XDS_Options:
- *
- * Present a window to the user allowing him to adjust drawing style
- * options. Arguments may optionally be passed from an Arexx command.
- *
- */
- int __saveds __asm XDS_Options (register __a0 LONG *args)
- {
- int action;
-
- if (args)
- {
- CleanupPantoCenter();
- if (args[0]) ScanBase->sb_PantoCX = atoi((char *)args[0]);
- if (args[1]) ScanBase->sb_PantoCY = atoi((char *)args[1]);
- if (args[2]) panto_mode = 0;
- if (args[3]) panto_mode = 1;
- InitPantoCenter();
- return(0);
- }
-
- newGads[ID_Mode-1].Data4 = panto_mode;
-
- PrepareNW(&newWindow, WID, HT, TRUE);
-
- action = GedWin(&newWindow, newGads, 0, NULL, NULL, ModuleBase->Text ? ModuleBase->Text : Default_Strings);
- if (action == ID_Okay)
- {
- panto_mode = mode;
- delta_not_set = TRUE;
- Learn("DrawStyle ARGS %ls", panto_mode ? "Absolute" : "Relative");
- }
-
- return(0);
- }
-
- /*
- * XDS_LoadPrefs:
- *
- * Set preferences according to information loaded from disk.
- *
- */
- int __saveds __asm XDS_LoadPrefs (register __a0 void *prefs)
- {
- return(1);
- }
-
- /*
- * XDS_SavePrefs:
- *
- * Request preferences settings that are about to be saved to disk.
- *
- */
- int __saveds __asm XDS_SavePrefs (register __a0 void *prefs)
- {
- return(1);
- }
-
- /*
- * XDS_HandleMButton:
- *
- * Handle a mousebutton event from the main window.
- *
- */
- int __saveds __asm XDS_HandleMButton (register __a0 struct IntuiMessage *msg)
- {
- short px, py;
- short x, y;
-
- if (msg->Code == SELECTDOWN)
- {
-
- GetVCoords(msg, &x, &y);
- if (msg->Qualifier & (IEQUALIFIER_LALT | IEQUALIFIER_RALT))
- {
- ScanBase->sb_PantoCX = x;
- ScanBase->sb_PantoCY = y;
- delta_not_set = TRUE;
-
- MovePantoCenter();
- ScanBase->sb_NewFlags &= ~SBF_BUTTONDOWN;
-
- return(1);
- }
-
- if (!(ScanBase->sb_NewFlags & SBF_BUTTONDOWN))
- {
- if (panto_mode == 0)
- {
- /* relative - reset delta each time we click */
- ScanBase->sb_PantoDX = ScanBase->sb_PantoCX - x;
- ScanBase->sb_PantoDY = ScanBase->sb_PantoCY - y;
- }
- else if (panto_mode == 1)
- {
- /* absolute - only set delta the FIRST time we click */
- if (delta_not_set)
- {
- ScanBase->sb_PantoDX = ScanBase->sb_PantoCX - x;
- ScanBase->sb_PantoDY = ScanBase->sb_PantoCY - y;
- delta_not_set = FALSE;
- }
- }
- px = x + ScanBase->sb_PantoDX;
- py = y + ScanBase->sb_PantoDY;
- InitPantograph(px, py);
- }
-
- }
- else if (msg->Code == SELECTUP)
- {
-
- if (ScanBase->sb_NewFlags & SBF_BUTTONDOWN)
- {
- CleanupPantograph();
- }
-
- }
-
- return(0);
- }
-
- /*
- * XDS_HandleMMove:
- *
- * Handle a mousemove event from the main window.
- *
- */
- int __saveds __asm XDS_HandleMMove (register __a0 struct IntuiMessage *msg)
- {
- short px, py;
- short x, y;
-
- if (ScanBase->sb_NewFlags & SBF_BUTTONDOWN)
- {
- GetVCoords (msg, &x, &y);
- px = x + ScanBase->sb_PantoDX;
- py = y + ScanBase->sb_PantoDY;
- MovePantograph(px, py);
- }
-
- return(0);
- }
-
-
- int __saveds __asm XDS_Init (void)
- {
- if (!pWindow) return(0);
- InitPantoCenter();
- delta_not_set = TRUE;
- return(1);
- }
-
- void __saveds __asm XDS_Cleanup (void)
- {
- CleanupPantoCenter();
- }
-
- void __saveds __asm XDS_Redraw (register __d0 int left,
- register __d1 int top,
- register __d2 int right,
- register __d3 int bottom)
- {
- CleanupPantoCenter();
- RedrawArea(left, top, right, bottom);
- InitPantoCenter();
- }
-
-
- RXCMD RxCmd = { NULL, NULL, "CenterX/N,CenterY/N,Relative/S,Absolute/S" };
-
-
- /**********************************************************************\
-
- Library Initialization Stuff
-
- \**********************************************************************/
-
- /*
- * This is the table of all the functions that can be called in this
- * module. The first four (Open, Close, Expunge, and Null) are reserved
- * for system use and MUST be specified in the order shown. The actual
- * functions are in the standard module startup code.
- */
- ULONG FuncTable[] = {
- /* These four MUST be present in this order */
- (ULONG) LibOpen,
- (ULONG) LibClose,
- (ULONG) LibExpunge,
- (ULONG) LibNull,
-
- /* Specific to the module */
- (ULONG) XDS_Attr,
- (ULONG) XDS_Begin,
- (ULONG) XDS_End,
- (ULONG) XDS_Get,
- (ULONG) XDS_Put,
- (ULONG) XDS_Options,
- (ULONG) XDS_LoadPrefs,
- (ULONG) XDS_SavePrefs,
- (ULONG) XDS_HandleMButton,
- (ULONG) XDS_HandleMMove,
- (ULONG) XDS_Init,
- (ULONG) XDS_Cleanup,
- (ULONG) XDS_Redraw,
-
- /* End with -1L */
- (ULONG) -1L
- };
-
- /*
- * These are used by the standard module startup code.
- * LibraryName is the name of the library, and LibraryID is a short
- * description of the library. Both of these are largely irrelavent,
- * but they are included just for completeness.
- */
- UBYTE LibraryID[] = "$VER: Pantograph Drawing Style 2.0.29 (15.2.95)";
- UBYTE LibraryType = NT_XDRAWSTYLE;
-
- /*
- * This is called by the standard module startup code when Image Scan
- * first opens the module. Here we should fill in the NumGads,
- * NewGad, Language, and LangCount fields of the provided ModuleBase
- * structure if necessary.
- */
- long __asm UserOpen (register __a6 struct ModuleBase *modbase)
- {
- modbase->Language = "Style_Pantograph";
- modbase->LangCount = TXT_COUNT;
- modbase->CmdTable = &RxCmd;
- return(TRUE);
- }
-
- /*
- * This is called by the standard module startup code when Image Scan
- * closes the module. It should cleanup anything allocated or obtained
- * in the UserOpen() function.
- */
- long __asm UserClose (register __a6 struct ModuleBase *modbase)
- {
- return(TRUE);
- }
-
-