home *** CD-ROM | disk | FTP | other *** search
- /*
- * GedSample
- *
- * Sample ImageFX hook that uses the Ged system for an interface.
- * The hook really doesn't do anything; this just shows how to
- * use the Ged system to make an interface.
- *
- * Written by Thomas Krehbiel, 04-Nov-93
- *
- */
-
- #include <scan/hooks.h>
- #include <clib/dos_protos.h>
- #include <clib/intuition_protos.h>
- #include <clib/graphics_protos.h>
-
-
- /* This information is required by the "start.o" startup code. */
- char *HookName = "GedSample";
-
- /* A version string so the Version command works on us. */
- char *HookVersion = "\0$VER: GedSample 2.0.2 (15.2.95)";
-
-
- /*******************************************************************
- *
- * Defines
- *
- *******************************************************************/
-
- #define WINDOW_WIDTH (300)
- #define WINDOW_HEIGHT (100)
-
-
- /*******************************************************************
- *
- * Text Array and Indexes
- *
- *******************************************************************/
-
- #include "gedsample_strings.h"
-
- #if 0
-
- char *DefaultStrings[] = {
- "Dummy",
-
- "GED Sample Window",
- "_Okay",
- "_Cancel",
- "Int:",
- "Str:",
- };
-
- enum {
- G_Dummy = 0,
- G_Title, /* gadget labels must start from 1! */
- G_Okay,
- G_Cancel,
- G_Integer,
- G_String,
- TXT_COUNT
- };
-
- /* This information is required by the "start.o" startup code. */
- char *HookText = "Hook_GedSample";
- int HookTextCount = TXT_COUNT;
-
- #endif
-
- /*******************************************************************
- *
- * These are filled in by the ImageFX Ged system
- *
- *******************************************************************/
-
- LONG OutsideArea[4]; /* will contain border size,
- [0] = leftedge,
- [1] = topedge,
- [2] = width,
- [3] = height */
-
- LONG InsideArea[4]; /* will contain border size,
- [0] = leftedge,
- [1] = topedge,
- [2] = width,
- [3] = height */
-
- LONG IntegerValue;
- char StringValue[80]; /* makes a copy of the string here */
-
- /*******************************************************************
- *
- * Gadget ID's
- *
- *******************************************************************/
-
- enum {
- ID_Okay = 300, /* start high to avoid conflicts */
- ID_Cancel, /* with ImageFX gadgets */
- ID_Integer,
- ID_String
- };
-
- /*******************************************************************
- *
- * Gadget callbacks - these are called when the gadget associated
- * with the callback is "fiddled" with.
- *
- * Be sure to use __saveds for all callbacks!
- *
- * Any callback that returns non-zero will cause GedWin() to
- * return immediately.
- *
- *******************************************************************/
-
- int __saveds IntegerCode (GedIntegerProto)
- {
- /*
- * Check to see if we're within 0 - 100. If not, beep and
- * reset ourselves to those bounds.
- *
- * 'w' and 'val' are found in the GedIntegerProto define.
- * 'w' is a pointer to the window containing the gadget.
- * 'val' is the current value of the gadget.
- */
-
- if (val < 0) {
- DisplayBeep(w->WScreen);
- Ged_Set(w, ID_Integer, 0);
- }
- else if (val > 100) {
- DisplayBeep(w->WScreen);
- Ged_Set(w, ID_Integer, 100);
- }
-
- return(0);
- }
-
- /*******************************************************************
- *
- * NewGad array - defines elements of our interface
- *
- *******************************************************************/
-
- struct NewGad newGads[] = {
-
- { Scale_ID }, /* voodoo magic */
-
- /* okay gadget */
- { Button_ID, /* style */
- ID_Okay, /* gadget id */
- 8, /* left */
- WINDOW_HEIGHT - 16, /* top */
- 100, /* width */
- 12, /* height - 12's a good height for buttons */
- G_Okay, /* label - index into text array */
- NULL, /* code - none needed */
- 0, /* userdata - none needed */
- NULL, /* pointer - not used */
- ID_Okay, /* data1 - exit GedWin with this return code
- when user clicks this gadget */
- 0, /* data2 - unused */
- 0, /* data3 - unused */
- 0, /* data4 - unused */
- 0, /* data5 - unused */
- 0, /* data6 - unused */
- 0, /* data7 - unused */
- 0 /* data8 - unused */
- },
-
- /* cancel gadget */
- { Button_ID, /* style */
- ID_Cancel, /* gadget id */
- WINDOW_WIDTH - 108, /* left */
- WINDOW_HEIGHT - 16, /* top */
- 100, /* width */
- 12, /* height - 12's a good height for buttons */
- G_Cancel, /* label - index into text array */
- NULL, /* code - none needed */
- 0, /* userdata - none needed */
- NULL, /* pointer - not used */
- ID_Cancel, /* data1 - exit GedWin with this return code
- when user clicks this gadget */
- 0, /* data2 - unused */
- 0, /* data3 - unused */
- 0, /* data4 - unused */
- 0, /* data5 - unused */
- 0, /* data6 - unused */
- 0, /* data7 - unused */
- 0 /* data8 - unused */
- },
-
- /* integer gadget */
- { Integer_ID, /* style */
- ID_Integer, /* gadget id */
- 50, /* left */
- 20, /* top */
- 40, /* width */
- 14, /* height - 14's a good height for strings */
- G_Integer, /* label - index into text array */
- IntegerCode, /* code - callback function */
- 0, /* userdata - none needed */
- &IntegerValue, /* pointer - where to store value */
- 0, /* data1 - lowest value (not implemented) */
- 50, /* data2 - initial value */
- 100, /* data3 - highest value (not implemented) */
- ID_String, /* data4 - next gadget id to activate */
- 1, /* data5 - justification
- (0=left, 1=right, 2=center) */
- 0, /* data6 - unused */
- 0, /* data7 - unused */
- 0 /* data8 - unused */
- },
-
- /* string gadget */
- { String_ID, /* style */
- ID_String, /* gadget id */
- WINDOW_WIDTH/2+40, /* left */
- 20, /* top */
- 80, /* width */
- 14, /* height - 14's a good height for strings */
- G_String, /* label - index into text array */
- NULL, /* code - none needed */
- 0, /* userdata - none needed */
- (long *)StringValue, /* pointer - where to store value */
- 80, /* data1 - max chars */
- (long)"Testing", /* data2 - initial string */
- 0, /* data3 - unused */
- ID_Integer, /* data4 - next gadget id to activate */
- 2, /* data5 - justification
- (0=left, 1=right, 2=center) */
- 0, /* data6 - unused */
- 0, /* data7 - unused */
- 0 /* data8 - unused */
- },
-
- /* window title */
- { Text_ID, /* style */
- 0, /* id - none needed */
- WINDOW_WIDTH/2, /* left */
- 4, /* top */
- 0, /* width - unneeded */
- 0, /* height - unneeded */
- G_Title, /* label - index into text array */
- NULL, /* code - none needed */
- 0, /* userdata - none needed */
- NULL, /* pointer - unused */
- 2, /* data1 - drawing pen (2=white) */
- 0, /* data2 - unused */
- 2, /* data3 - justification
- (0=left, 1=right, 2=center) */
- 0, /* data4 - unused */
- 0, /* data5 - unused */
- 0, /* data6 - unused */
- 0, /* data7 - unused */
- 0 /* data8 - unused */
- },
-
- /* window border */
- { Border_ID, /* style */
- 0, /* id - none needed */
- 0, /* left */
- 0, /* top */
- WINDOW_WIDTH, /* width */
- WINDOW_HEIGHT, /* height */
- 0, /* label - none needed */
- NULL, /* code - none needed */
- 0, /* userdata - none needed */
- OutsideArea, /* pointer - (optional) - fill in actual
- size of the border when created;
- useful for drawing stuff inside
- the border so we know where the
- actual border coords are. Use NULL
- if you don't need this. This is just
- here as an example. */
- FALSE, /* data1 - recessed border? */
- TRUE, /* data2 - double thick? */
- 0, /* data3 - unused */
- 0, /* data4 - unused */
- 0, /* data5 - unused */
- 0, /* data6 - unused */
- 0, /* data7 - unused */
- 0 /* data8 - unused */
- },
-
- /* inside border */
- { Border_ID, /* style */
- 0, /* id - none needed */
- 8, /* left */
- 14, /* top */
- WINDOW_WIDTH-16, /* width */
- WINDOW_HEIGHT-14-18, /* height */
- 0, /* label - none needed */
- NULL, /* code - none needed */
- 0, /* userdata - none needed */
- InsideArea, /* pointer - (optional) - fill in actual
- size of the border when created;
- useful for drawing stuff inside
- the border so we know where the
- actual border coords are. Use NULL
- if you don't need this. This is just
- here as an example. */
- TRUE, /* data1 - recessed border? */
- FALSE, /* data2 - double thick? */
- 0, /* data3 - unused */
- 0, /* data4 - unused */
- 0, /* data5 - unused */
- 0, /* data6 - unused */
- 0, /* data7 - unused */
- 0 /* data8 - unused */
- },
-
- { End_ID } /* must end with End_ID! */
- };
-
- /*******************************************************************
- *
- * NewWindow - defines the window (flags and such)
- *
- *******************************************************************/
-
- struct NewWindow newWindow = {
-
- 0, 0, /* left, top */
- WINDOW_WIDTH, WINDOW_HEIGHT, /* width, height */
- 0, 1, /* 1.3 stuff... :) */
- IDCMP_GADGETUP, /* IDCMP flags (must set correctly!) */
- WFLG_BORDERLESS | /* Window flags */
- WFLG_SMART_REFRESH |
- WFLG_NOCAREREFRESH |
- WFLG_RMBTRAP |
- WFLG_ACTIVATE,
- NULL, /* Firstgadget - unused */
- NULL,
- NULL,
- NULL, /* Screen - set by ImageFX in PrepareNW */
- NULL,
- 0,0,0,0, /* Min/max size */
- WBENCHSCREEN /* Type - set by ImageFX in PrepareNW */
-
- };
-
-
- /*******************************************************************
- *
- * Ginit:
- *
- * GedWin initialization callback. This is called twice during
- * initialization; once before the window is opened and once after
- * the window is opened and the gadgets are added. You can tell which
- * case you're dealing with by examining the arguments. If win != NULL
- * then the window is opened and the gadgets are added, otherwise
- * the window isn't open and the gadgets aren't added (in this case
- * you can fiddle with the NewGad array passed in here).
- *
- * Generally this is used to do extra rendering into the window
- * that can't be done with gadgets and such. It can also be
- * used to initialize gadget states, although this would better
- * be done by initializing the NewGad array beforehand.
- *
- * Make sure you use __saveds for all callbacks!
- *
- *******************************************************************/
-
- int __saveds Ginit (struct Window *win, struct NewGad *ng)
- {
- if (win) {
-
- /* this is just an example - it does nothing useful (except
- demonstrate how to find Border_ID positions) */
-
- SetDrMd(win->RPort, COMPLEMENT);
- RectFill(win->RPort, /* recall that InsideArea[] will contain */
- InsideArea[0]+2, /* the coords of a Border_ID */
- InsideArea[1]+1,
- InsideArea[0]+InsideArea[2]-3,
- InsideArea[1]+InsideArea[3]-2);
- Delay(10);
- RectFill(win->RPort, /* recall that InsideArea[] will contain */
- InsideArea[0]+2, /* the coords of a Border_ID */
- InsideArea[1]+1,
- InsideArea[0]+InsideArea[2]-3,
- InsideArea[1]+InsideArea[3]-2);
-
- }
-
- return(1); /* always return 1 */
- }
-
-
- /*******************************************************************
- *
- * Hook entry point is here.
- *
- *******************************************************************/
-
- void hook_main (int argc, char **argv)
- {
- int returncode;
-
- /*
- * PrepareNW() fills in the NewWindow structure with appropriate
- * values to open on the ImageFX screen (or on Workbench).
- */
- PrepareNW(&newWindow,
- WINDOW_WIDTH, WINDOW_HEIGHT, TRUE);
-
- /*
- * GedWin() opens the window, processes events, and returns when
- * the window is closed.
- */
- returncode = GedWin(&newWindow, /* newwindow */
- newGads, /* newgad array */
- ID_Integer, /* id of first string gad to activate */
- Ginit, /* init function callback */
- NULL, /* cleanup function callback */
- HookTextArray); /* text array - from start.o */
-
- if (returncode == ID_Okay) {
- InfoRequest("You hit okay!");
- }
- else if (returncode == ID_Cancel) {
- Errorf("You cancelled, ya bum!");
- }
- }
-