Megalextoria
Retro computing and gaming, sci-fi books, tv and movies and other geeky stuff.

Home » Archive » comp.sys.amiga » 18,19,20,21 of 21 - Last batch
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
18,19,20,21 of 21 - Last batch [message #293892] Tue, 09 December 1986 04:04
crunch is currently offline  crunch
Messages: 49
Registered: August 1985
Karma: 0
Member
Article-I.D.: well.2181
Posted: Tue Dec  9 04:04:25 1986
Date-Received: Wed, 10-Dec-86 03:00:31 EST
Reply-To: crunch@well.UUCP (John Draper)
Organization: Whole Earth Lectronic Link, Sausalito CA
Lines: 1365

#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create:
#	pgad.c
#	mp.c
#	reqn.c
#	utilmen.c
# This archive created: Tue Dec  9 01:01:55 1986
export PATH; PATH=/bin:/usr/bin:$PATH
if test -f 'pgad.c'
then
	echo shar: "will not over-write existing file 'pgad.c'"
else
cat << \SHAR_EOF > 'pgad.c'
/*=========================================================================
  pgad.c - Gadget display functions.   These functions print out all of the
  structures.  It is an independent module and others can easily be
  added.
 
  Change History:
   11/16/86 - RRL added display stuff for a standard header, intuitexts
              and cleaned up some other stuff. The output should now
              compile without errors. The gadget names are now used
              to provide symbolic names for borders, images, etc.
=========================================================================*/
 
/*  The usual header files to be inserted later  */
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include "gad.h"
 
/* constants */
 
/* external functions */
 
/* external variables */
 
extern char *gadnames[];
extern int nextgad;
extern struct Gadget *gads[];
extern char gadimage [MAX_PROPINFOS] [NAM_SIZ];
extern char selectimage [MAX_PROPINFOS] [NAM_SIZ];
extern struct IntuiText *ITMap[]; /* Pointers to the Gad's Intuitexts */
 
/* globals */
char quote = 34;
char upcasebuf[NAM_SIZ];
 
/*----------- Get name of gadget, given it's address ------------*/
char *getname(gad)
struct Gadget *gad;
{
    int i;
 
    for (i=0; iXY, num, name);        /* display the border */
    fprintf(fd, "struct Border %s_bord_%d = {\n",name, num);
    fprintf(fd, "  %d,  %d,       /* LeftEdge, TopEdge */\n",
                    border->LeftEdge, border->TopEdge);
    fprintf(fd, "  %d,  %d,  %s,  /* FrontPen, BackPen, DrawMode*/\n",
              border->FrontPen, border->BackPen,
              modename(border->DrawMode));
    fprintf(fd, "  5,             /* Count of XY pairs */  \n");
    fprintf(fd, "  (SHORT *)&%s_Pairs_%d, /* XY pairs */\n",name, num);
    fprintf(fd, "  NULL           /* Next Border */\n");
    fprintf(fd, "};\n\n");
}
/*=======================================================================
 disp_render - Displays the "thingie" pointed to by the GadgetRender
 field.   This would be a border or an image.
=========================================================================*/
disp_render(fd, gad, rendnum, index)
FILE *fd;
struct Gadget *gad;
int rendnum;
int index;
{
    long   flags;
    struct Border *bord;
    struct Image *im;
    struct PropInfo *pi;
 
 
 
    flags = (long)gad->UserData;
 
    if ((flags & GAD_BORDER_TYPE) == GAD_BORDER_TYPE) {
       bord = (struct Border *)gad->GadgetRender;
       if (bord != NULL)
          disp_border(fd, bord, rendnum, gadnames[index]);
    }
    if ((flags & GAD_IMAGE_TYPE) == GAD_IMAGE_TYPE) {
       im = (struct Image *)gad->GadgetRender;
       if (im != NULL) {
          imagout(fd, im, gadimage[index]);
       }
    }
    if ((flags & SEL_IMAGE_TYPE) == SEL_IMAGE_TYPE) {
       im = (struct Image *)gad->SelectRender;
       if (im != NULL) {
          imagout(fd, im, selectimage[index]);
       }
    }
 
    if (gad->GadgetType == PROPGADGET) {
       pi = (struct PropInfo *)gad->SpecialInfo;
       if ((pi->Flags & AUTOKNOB) == AUTOKNOB) {
       startcomment(fd);
       fprintf(fd," * Image structure for %s proportional gadget knob.\n",
               gadnames[index]);
       endcomment(fd);
       fprintf(fd,"struct Image %s_knobim;\n",gadnames[index]);
       }
    }
 
    if (gad->GadgetText != NULL)
       disp_texts(fd,gad,rendnum,gadnames[index]);
}
 
/*=======================================================================
  dispstring - Displays the Stringinfo buffer and the stringInfo
  structure.  A number "num" is passed that identifies it from another
  string gadget in the set of gadgets.   It is passed in from the
  "save as source" function in the filemen.c module
========================================================================*/
dispstring(fd, sinfo, num, size, name)
FILE *fd;
struct StringInfo *sinfo;
int num;                     /* Part of the structure name */
int size;                    /* Size is the length of the string buffer */
char *name;
{   startcomment(fd);
    fprintf(fd, " *  String information for the %s string gadget.\n",name);
    endcomment(fd);
    fprintf(fd, "UBYTE %s_sbuf_%d[%d] = %c123456789%c;\n",
             name,num, size, quote, quote);
    fprintf(fd, "UBYTE %s_ubuf_%d[%d];\n\n",name, num, size);
    fprintf(fd, "struct StringInfo %s_txstr_%d = {\n", name,num);
    fprintf(fd, "  %s_sbuf_%d, %s_ubuf_%d, /* Buffer, UndoBuffer  */\n",
             name, num, name, num);
    fprintf(fd, "  %d, %d, %d,  /* BufferPos, MaxChars, DispPos   */\n",
             sinfo->BufferPos, sinfo->MaxChars, sinfo->DispPos);
    fprintf(fd, "  %d, %d,      /* UndoPos, NumChars              */\n",
             sinfo->UndoPos, sinfo->NumChars);
    fprintf(fd, "  %d, %d, %d,  /* DispCount, CLeft, CTop         */\n",
             sinfo->DispCount, sinfo->CLeft, sinfo->CTop);
    fprintf(fd, "  0x%lx, %ld   /* LayerPtr, LongInt              */\n",
             sinfo->LayerPtr, sinfo->LongInt);
    fprintf(fd, "  0x%lx        /* AltKeyMap                      */\n",
             sinfo->AltKeyMap);
    fprintf(fd, "};\n\n");
}
 
/*=======================================================================
  disp_props - Display PropInfo structure
========================================================================*/
disp_props(fd, prop, num, name)
FILE *fd;
struct PropInfo *prop;
int num;
char *name;
{
    int   cnt = 0;
    startcomment(fd);
    fprintf(fd, " * Proportional gadget info for the %s gadget.\n",name);
    endcomment(fd);
    fprintf(fd, "struct PropInfo %s_prop_%d = {\n",name, num);
    fprintf(fd, "   /* Flags                     */\n");
    fprintf(fd, "   ");
    if (prop->Flags == 0) fprintf(fd, "NULL");
 
    if (prop->Flags & AUTOKNOB) {
       fprintf(fd, "AUTOKNOB"); cnt++;
    }
    if (prop->Flags & FREEHORIZ) {
      if (cnt > 0) fprintf(fd, " | ");
      fprintf(fd, "FREEHORIZ");
      cnt++;
    }
    if (prop->Flags & FREEVERT) {
      if (cnt > 0) fprintf(fd, " | ");
      fprintf(fd, "FREEVERT");
      cnt++;
    }
    if (prop->Flags & PROPBORDERLESS) {
      if (cnt > 0) fprintf(fd, " | ");
      fprintf(fd, "PROPBORDERLESS");
      cnt++;
    }
    if (prop->Flags & KNOBHIT) {
      if (cnt > 0) fprintf(fd, " | ");
      fprintf(fd, "KNOBHIT");
      cnt++;
    }
    fprintf(fd, ",\n");
    /* the following values should be set to zero */
    fprintf(fd, "  0x0000, 0x0000,   /* HorizPot, VertPot     */\n");
   fprintf(fd,  "  0x%04x, 0x%04x,   /* HorizBody, VertBody   */\n",
           prop->HorizBody, prop->VertBody);
    fprintf(fd, "  %4d, %4d,   /* CWidth, CHeight       */\n",
           prop->CWidth, prop->CHeight);
    fprintf(fd, "  0x%04x, 0x%04x,   /* HPotRes, VPotRes      */\n",
           prop->HPotRes, prop->VPotRes);
    fprintf(fd, "  %4d, %4d    /* LeftBorder, TopBorder */\n",
           prop->LeftBorder,  prop->TopBorder);
    fprintf(fd, "};\n\n");
}
 
/*=======================================================================
  disp_pairs - Displays the gadget pairs
========================================================================*/
disp_pairs(fd, pairs, num, name)
FILE *fd;
SHORT *pairs;
int num;
char *name;
{
    int   i;
 
    fprintf(fd, "SHORT %s_Pairs_%d[] = {\n",name, num);
    for (i=0; i<10; i++) {
        fprintf(fd, "  %d", *pairs++);
        if ( i != 9) fprintf(fd, ",   ");
        else         fprintf(fd, "    ");
        if (i & 1)   fprintf(fd, "\n");
    }
    fprintf(fd, "};\n");
 
}
 
 
/*=======================================================================
  $$$  DispGadget - Displays the Gadget in "struct" form thru serial device
  later will vector it anywhere
========================================================================*/
disp_gadget(fd, gad, ren_type, rnum, inum, name, ind)
FILE *fd;
struct Gadget *gad;
int ren_type;        /* Specifies Border or Image */
int rnum;            /* A unique number identifying border or image */
int inum;            /* A unique number as above to be displayed in source*/
char *name;
int ind;
{
    int cnt;          /* Number of flags set */
    char *gnam;       /* Gadget name that gets printed */
    long flags;
    struct PropInfo *pi;
 
    /*  Set gadget render type here */
    flags = (long)gad->UserData;
    if (name == NULL) gnam = "gad";
    else gnam = name;
 
    startcomment(fd);
    fprintf(fd," *  Gadget Structure definition for the %s gadget.\n",gnam);
    endcomment(fd);
 
    fprintf(fd, "struct Gadget %s = {\n", gnam);
    if (gad->NextGadget != NULL)
              fprintf(fd, " &");
    else fprintf(fd, "  ");
    fprintf(fd, "%s,     /* NextGadget pointer */\n",
               getname(gad->NextGadget));
    fprintf(fd, "  %d, %d,    /* LeftEdge, TopEdge  */\n",
               gad->LeftEdge, gad->TopEdge);
     fprintf(fd,"  %d, %d,    /* Width, Height      */\n",
               gad->Width, gad->Height);
 
     fprintf(fd, "  /* Gadget Flags */\n");
    cnt = 0;
    fprintf(fd, "  ");
    if (gad->Flags == 0) {
        fprintf(fd, "GADGHCOMP"); /* complement is zero */
        cnt++;
    }
    if (gad->Flags & SELECTED) {
       if (cnt > 0) fprintf(fd, " | ");
       fprintf(fd, " SELECTED");
       cnt++;
    }
    if (gad->Flags & GADGHNONE) {
       if (cnt > 0) fprintf(fd, " | ");
       fprintf(fd, " GADGHNONE");
       cnt++;
    }
    if (gad->Flags & GADGHBOX) {
       if (cnt > 0) fprintf(fd, " | ");
       fprintf(fd, " GADGHBOX");
       cnt++;
    }
    if (gad->Flags & GADGHIMAGE) {
       if (cnt > 0) fprintf(fd, " | " );
       fprintf(fd, " GADGHIMAGE");
       cnt++;
    }
    if (gad->Flags & GADGIMAGE) {
       if (cnt > 0) fprintf(fd, " | ");
       fprintf(fd, " GADGIMAGE");
       cnt++;
    }
    if (gad->Flags & GRELBOTTOM) {
       if (cnt > 0) fprintf(fd, " | ");
       fprintf(fd, " GRELBOTTOM");
       cnt++;
    }
    if (gad->Flags & GRELRIGHT) {
       if (cnt > 0) fprintf(fd, " | ");
       fprintf(fd, " GRELRIGHT");
       cnt++;
    }
    if (gad->Flags & GRELWIDTH) {
       if (cnt > 0) fprintf(fd, " | ");
       fprintf(fd, " GRELWIDTH");
       cnt++;
    }
    if (gad->Flags & GRELHEIGHT) {
       if (cnt > 0) fprintf(fd, " | ");
       fprintf(fd, " GRELHEIGHT");
       cnt++;
    }
    if (gad->Flags & GADGDISABLED) {
       if (cnt > 0) fprintf(fd, " | ");
       fprintf(fd, " GADGDISABLED");
       cnt++;
    }
 
    fprintf(fd, ",\n");     /* put comma at end */
    fprintf(fd, "  /* Activation Flags */\n");
    cnt = 0;
    fprintf(fd, " ");
    if (gad->Activation == NULL) fprintf(fd, " NULL");
 
    if (gad->Activation & RELVERIFY ) {
       fprintf(fd, " RELVERIFY");
       cnt++;
    }
    if (gad->Activation & GADGIMMEDIATE ) {
        if (cnt > 0) fprintf(fd, " | ");
        fprintf(fd, "GADGIMMEDIATE");
        cnt++;
    }
    if (gad->Activation & ENDGADGET) {
        if (cnt > 0) fprintf(fd, " | ");
        fprintf(fd, "ENDGADGET");
        cnt++;
    }
    if (gad->Activation & FOLLOWMOUSE) {
        if (cnt > 0) fprintf(fd, " | ");
        fprintf(fd, "FOLLOWMOUSE");
        cnt++;
    }
    if (gad->Activation & TOGGLESELECT) {
        if (cnt > 0) fprintf(fd, " | ");
        fprintf(fd, "TOGGLESELECT");
        cnt++;
    }
    if (gad->Activation & LONGINT) {
        if (cnt > 0) fprintf(fd, " | ");
        fprintf(fd, "LONGINT");
        cnt++;
    }
    if (gad->Activation & RIGHTBORDER) {
        if (cnt > 0) fprintf(fd, " | ");
        fprintf(fd, "RIGHTBORDER");
        cnt++;
    }
    if (gad->Activation & LEFTBORDER) {
        if (cnt > 0) fprintf(fd, " | ");
        fprintf(fd, "LEFTBORDER");
        cnt++;
    }
    if (gad->Activation & TOPBORDER) {
        if (cnt > 0) fprintf(fd, " | ");
        fprintf(fd, "TOPBORDER");
        cnt++;
    }
    if (gad->Activation & BOTTOMBORDER) {
        if (cnt > 0) fprintf(fd, " | ");
        fprintf(fd, "BOTTOMBORDER");
        cnt++;
    }
    if (gad->Activation & STRINGCENTER) {
        if (cnt > 0) fprintf(fd, " | ");
        fprintf(fd, "STRINGCENTER");
        cnt++;
    }
    if (gad->Activation & STRINGRIGHT) {
        if (cnt > 0) fprintf(fd, " | ");
        fprintf(fd, "STRINGRIGHT");
        cnt++;
    }
    if (gad->Activation & ALTKEYMAP) {
        if (cnt > 0) fprintf(fd, " | ");
        fprintf(fd, "ALTKEYMAP");
        cnt++;
    }
 
 
    fprintf(fd, ",\n");     /* put comma at end */
    fprintf(fd, "  /* GadgetType */\n");
    switch (gad->GadgetType) {
        case BOOLGADGET: fprintf(fd, "  BOOLGADGET,\n"); break;
        case PROPGADGET: fprintf(fd, "  PROPGADGET,\n"); break;
        case STRGADGET : fprintf(fd, "  STRGADGET,\n"); break;
    }                    /* $$$ */
 
    fprintf(fd, "  ");
 
    if (gad->GadgetRender == NULL)
       fprintf(fd, "NULL, ");
    else {   /* We get the name of the select and print it */
           flags = (long)gad->UserData;
 
           if ((flags & GAD_BORDER_TYPE) == GAD_BORDER_TYPE)
              fprintf(fd, "(APTR)&%s_bord_%d,  ",gnam, rnum);
 
           if (gad->GadgetType == PROPGADGET)  {
              pi = (struct PropInfo *)gad->SpecialInfo;
              if ((pi->Flags & AUTOKNOB) == AUTOKNOB)
                 fprintf(fd, "(APTR)&%s_knobim,   ",gnam);
              else if ((flags & GAD_IMAGE_TYPE) == GAD_IMAGE_TYPE)
                 fprintf(fd, "(APTR)&%s,    ", gadimage[ind]);
           }
           else if ((flags & GAD_IMAGE_TYPE) == GAD_IMAGE_TYPE)
              fprintf(fd, "(APTR)&%s,   ", gadimage[ind]);
 
    }
    fprintf(fd," /*  GadgetRender */\n");
 
    fprintf(fd, "  ");
 
    if (gad->SelectRender == NULL)
       fprintf(fd, "NULL,  ");
 
    else {   /* ### We get name of SelectRender and print it */
           flags = (long)gad->UserData;
           if ((flags & SEL_BORDER_TYPE) == SEL_BORDER_TYPE)
              fprintf(fd, "(APTR)&%s_bord_%d,  ",gnam, rnum);
 
           if (gad->GadgetType == PROPGADGET)  {
              pi = (struct PropInfo *)gad->SpecialInfo;
              if ((pi->Flags & AUTOKNOB) == AUTOKNOB)
                fprintf(fd, "NULL,  ");
              else if ((flags & SEL_IMAGE_TYPE) == SEL_IMAGE_TYPE)
                fprintf(fd, "(APTR)&%s,  ", selectimage[ind]);
              }
           else if ((flags & SEL_IMAGE_TYPE) == SEL_IMAGE_TYPE)
              fprintf(fd, "(APTR)&%s,  ", selectimage[ind]);
 
    }
    fprintf(fd, "  /* SelectRender */\n ");
    if (gad->GadgetText == NULL)
       fprintf(fd, "  NULL,    /* GadgetText */\n");
    else {   /* We get name of IntuiText and print it */
       fprintf(fd, "  &%s_Text_0,  /* GadgetText */\n", gnam);
    }
    fprintf(fd, "  0x%lx,    /* MutualExclude */\n", gad->MutualExclude);
 
    switch(gad->GadgetType) {
       case BOOLGADGET: fprintf(fd, "  NULL,  ",
                               gad->SpecialInfo);
            break;
       case STRGADGET:  fprintf(fd, "  (APTR)&%s_txstr_%d,  ",gnam, inum);
            break;
       case PROPGADGET: fprintf(fd, "  (APTR)&%s_prop_%d,  ",gnam, inum);
           break;
    }
    fprintf(fd, " /* SpecialInfo */\n");
    fprintf(fd, "  %sGAD,    /* GadgetID         */\n", upname(gnam));
    fprintf(fd, "  0x%lx     /* UserData Pointer */\n",gad->UserData);
    fprintf(fd, "};\n\n");
 
}
 
/*=========================================================================
  disp_Header prints out all of the standard #includes and generates
  some #defines using the gadget names. It also prints the text attribute
  structures used for intuitexts.  RRL
=========================================================================*/
disp_Header(fd)
FILE *fd;
  {
    int i;
    startcomment(fd);
    fprintf(fd," *                    Gadget Structure Definitions\n");
    fprintf(fd," * \n");
    fprintf(fd," * The following structures were defined using the Gadget Editor
 created \n");
    fprintf(fd," * by the Programmer's Network.\n");
    fprintf(fd," * The credits for the Gadget Editor are:\n");
    fprintf(fd," * \n");
    fprintf(fd," *     John Draper    - Initial design, coordination, and integr
ation.\n");
    fprintf(fd," *     Ray Larson     - Images and Intuitext. \n");
    fprintf(fd," *     Brent Southard - Saving and restoring gadgets in binary f
orm.\n");
    fprintf(fd," *     Dave Milligan  - Gadget Editor Main menu.\n");
    fprintf(fd," * \n");
    fprintf(fd," * \n");
    endcomment(fd);
 
 
    fprintf(fd,"/*  The header files needed for gadget definitions  */ \n");
    fprintf(fd,"#include  \n");
    fprintf(fd,"#include  \n");
    fprintf(fd,"#include  \n");
    fprintf(fd,"#include  \n");
    fprintf(fd,"#include  \n");
    fprintf(fd,"#include  \n\n");
    fprintf(fd,"#include  \n");
    fprintf(fd,"#include  \n");
 
    fprintf(fd,"/*  Definitions for Gadget ID numbers               */ \n");
    for(i=0; i < nextgad; i++)
       fprintf(fd,"#define  %sGAD   %d\n",upname(gadnames[i]),i);
 
    /* output text attribute structures */
    startcomment(fd);
    fprintf(fd," *  Text attribute structures used in rendering IntuiTexts\n");
    endcomment(fd);
 
 
    fprintf(fd,"\nchar def_font[] =\"topaz.font\";\n");
    fprintf(fd,"\n");
    fprintf(fd,"struct TextAttr TxtAt_Plain = { (UBYTE *)def_font, 8,\n");
    fprintf(fd,"        FS_NORMAL, FPF_ROMFONT};\n");
    fprintf(fd,"\n");
    fprintf(fd,"struct TextAttr TxtAt_BIU = {(UBYTE *)def_font, 8, \n");
    fprintf(fd,"        FSF_BOLD | FSF_ITALIC | FSF_UNDERLINED, FPF_ROMFONT};\n"
);
    fprintf(fd,"\n");
    fprintf(fd,"struct TextAttr TxtAt_BU = {(UBYTE *)def_font, 8, \n");
    fprintf(fd,"        FSF_BOLD | FSF_UNDERLINED, FPF_ROMFONT};\n");
    fprintf(fd,"\n");
    fprintf(fd,"struct TextAttr TxtAt_BI = {(UBYTE *)def_font, 8, \n");
    fprintf(fd,"       FSF_BOLD | FSF_ITALIC, FPF_ROMFONT};\n");
    fprintf(fd,"\n");
    fprintf(fd,"struct TextAttr TxtAt_B ={(UBYTE *)def_font, 8, \n");
    fprintf(fd,"       FSF_BOLD, FPF_ROMFONT};\n");
    fprintf(fd,"\n");
    fprintf(fd,"struct TextAttr TxtAt_IU ={(UBYTE *)def_font, 8,\n");
    fprintf(fd,"       FSF_ITALIC | FSF_UNDERLINED, FPF_ROMFONT};\n");
    fprintf(fd,"\n");
    fprintf(fd,"struct TextAttr TxtAt_I ={(UBYTE *)def_font, 8, \n");
    fprintf(fd,"       FSF_ITALIC, FPF_ROMFONT};\n");
    fprintf(fd,"\n");
    fprintf(fd,"struct TextAttr TxtAt_U ={(UBYTE *)def_font, 8, \n");
    fprintf(fd,"       FSF_UNDERLINED, FPF_ROMFONT};\n");
    fprintf(fd,"\n");
    fprintf(fd,"\n");
 
 /* that's it for the header file */
}
 
/*=========================================================================
  font_name - takes a byte containing font style flags and returns
  a pointer to a strint matching one of the font names.                 RRL
=========================================================================*/
char *font_name(style)
UBYTE style;
{  switch (style)
    {
     case 0: return("&TxtAt_Plain");  break;
     case 1: return("&TxtAt_U");      break;
     case 2: return("&TxtAt_B");      break;
     case 3: return("&TxtAt_BU");     break;
     case 4: return("&TxtAt_I");      break;
     case 5: return("&TxtAt_IU");     break;
     case 6: return("&TxtAt_BI");     break;
     case 7: return("&TxtAt_BIU");    break;
     };
 
}
/*=========================================================================
  disp_texts prints out all of the IntuiTexts associated with a gadget. RRL
=========================================================================*/
disp_texts(fd,gad,num,name)
FILE *fd;
struct Gadget *gad;
int num;
char *name;
{
    int i;
    struct IntuiText *text;
    BOOL first = TRUE;
 
   if (gad->GadgetText == NULL) return;
 
   /* map the linked list of intuitexts into an array */
  ITMap[0] = gad->GadgetText;
  for(i = 0; i < 50 && ITMap[i] != NULL; i++)
     ITMap[i+1] = ITMap[i]->NextText;
 
  /* print out the intuitext structures */
    startcomment(fd);
    fprintf(fd," *  IntuiTexts for the %s gadget.\n",name);
    endcomment(fd);
 
  for (i--; i >= 0 ; i--) {
    text = ITMap[i];
    fprintf(fd,"struct IntuiText %s_Text_%d = {\n",name,i);
    fprintf(fd,"   %d, %d,     /* FrontPen, BackPen */\n",
             text->FrontPen,text->BackPen);
    fprintf(fd,"   %s,       /* DrawMode */\n",modename(text->DrawMode));
    fprintf(fd,"   %d, %d,     /* LeftEdge, TopEdge */\n",
              text->LeftEdge,text->TopEdge);
     /* the following comes from the header file */
    fprintf(fd,"   %s, /* ITextFont Pointer */ \n",
            font_name(text->ITextFont->ta_Style));
 
    fprintf(fd,"   /* The IText */\n");
    fprintf(fd,"   (UBYTE *)\"%s\",\n",text->IText);
    if (first) {
                 first = FALSE;
                 fprintf(fd,"   NULL\n");
               }
    else fprintf(fd,"   &%s_Text_%d    /* NextText */\n", name, i+1);
    fprintf(fd," };\n");
    fprintf(fd,"\n\n");
   }
 
 
}
SHAR_EOF
fi
if test -f 'mp.c'
then
	echo shar: "will not over-write existing file 'mp.c'"
else
cat << \SHAR_EOF > 'mp.c'
/*=======================================================================
  mp.c - Process the mouse on the screen.   and handle all mouse actions
========================================================================*/
 
/*  The usual header files to be inserted later  */
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include "gad.h"
 
/* --------------- change list -------------
 
6/10/86 - jd  Changed PropInfo flag setting to avoid crashing if none
          allocated.   Added new global "pflag" that holds the flags.
 
6/12/86 - jd  Changed proc_button() to change the border pairs when the
          gadget is re-sized.
 
11/15/86- RRL added a call to ClearAllTexts (in ITextEd.c) to remove old
          intuitexts when a gadget is moved to a new position
 
11/17/86- RRL moved the pflag setting to addgad.c
---------------------------------------------*/
 
/* extern vars */
 
extern int new_sel;
extern int pflag;
extern int curgad;
extern int nextgad;
extern int nextlink;
extern struct RastPort *rp;
extern struct Window *w;
extern struct NewWindow nw;
extern struct Gadget testgad;
 
extern struct Gadget *gads[];
extern struct IntuiText *Texts[];
extern struct PropInfo *props[];
extern struct StringInfo *strings[];
extern UBYTE *gadnames[];
extern UBYTE names [MAX_NUM_GADGETS]  [NAM_SIZ];
 
/* Extern functions */
 
extern UBYTE *getrname();
 
/* global vars */
 
int frst = 5;
int new_sel;
int rt_button;
int oldgad = FALSE;
int siz_flag;
SHORT Left, Top, Width, Height;
int erase;
int link = FALSE;    /* Do NOT link until told to */
 
/*=======================================================================
   Process the mouse movements,   this function gets called a lot,  so
  lets not dilly dally around folks,  just keep that line a movin
========================================================================*/
proc_mouse(addr, x, y)
APTR addr;                /* From IAddress field of IntuiMessage */
SHORT x, y;
{
    static SHORT OLeft, OTop, OWidth, OHeight;
    static SHORT Ox, Oy;  /* old mouse positions */
    long  flags;
 
    /* Because we may be re-drawing the boxes,  we have to restore the
       old box,  IE,  Last box drawn,  wherever that is */
    if (new_sel) {
       OLeft = Left;
       OWidth = Width;
       OTop = Top;
       OHeight = Height;
       Ox = x ;
       Oy = y ;
       new_sel = FALSE;
       /* Erase will be set TRUE, thus draw_box will be called */
    }
    x -= Ox ;
    y -= Oy ;
    Ox += x ;
    Oy += y ;
    if (rt_button) {                     /* $$$ */
 
       if (erase) {
          draw_box(rp, OLeft-1, OTop-1, OWidth, OHeight);
       }
       if (!siz_flag) Left += x;
       else Width += x ;
 
       if (!siz_flag) Top += y;
       else Height += y ;
 
       draw_box(rp, Left-1, Top-1, Width, Height);
       OLeft = Left;   OTop = Top;
       OWidth = Width; OHeight = Height;
       erase = TRUE;
    }
    else {
      /* If in the menu area,  then clear RMBTRAP */
      if (Oy < 11)
        w->Flags &= ~RMBTRAP;
      else
        w->Flags |= RMBTRAP;
    }
}
/*========================================================================
  Process the mouse when a button is pressed,  accepts the mouse location
  at the time the button was pressed, passed through from the Intuimessge
========================================================================*/
proc_button(code, x, y)
USHORT code;
SHORT x,y;
{
    int which;       /* Index into the gadget located by "findmouse" */
    static long Lf, Tp, Wd, Ht;
    struct PropInfo *pi;
    struct Border *bd;
    SHORT *pairs;
    long flags;
    UBYTE *str;
 
    if (code == MENUDOWN) {
        rt_button = TRUE;
        if ((which = findmouse(x,y)) == -1) {
          erase = FALSE;             /* Drawing new gadget */
          new_sel = FALSE;
          oldgad = FALSE;
          Left = x;  Top = y;        /* Creating a "New" gadget */
          Width = 0; Height = 0;     /* Starts at this coords */
          siz_flag = TRUE;           /* default mode */
 
          /* Clear out testgad structure */
          testgad.SpecialInfo = NULL;
          testgad.GadgetRender = NULL;
          testgad.SelectRender = NULL;
          testgad.GadgetText = NULL;
       }
       else {
          erase = TRUE;              /* We intend to re-draw current gad */
          if (in_corner(which, x, y)) {
              siz_flag = TRUE;
         }
         else  {
              siz_flag = FALSE;
         }
         /*  Select new CURRENT gadget */
          curgad = which;
          Left = gads[which]->LeftEdge;
          Top  = gads[which]->TopEdge;
          Width = gads[which]->Width;
          Height = gads[which]->Height;
 
          /* Mark spot where old rect is so we can clean it up */
          Lf = (long)(Left-1);
          Tp = (long)(Top-1);
          Wd = (long)Width;
          Ht = (long)Height;
 
          /* Snatch old gadget structure into temp structure  */
          testgad          = *gads[curgad];
 
          /* Set a few flags */
          oldgad = TRUE;
          new_sel = TRUE;     /* Used by proc_mouse to reload the OLD */
                              /*  Rectangle values to properly erase */
       }
       ModifyIDCMP(w, nw.IDCMPFlags);
    }
    if (code == MENUUP) {           /*  */
       rt_button = FALSE;
       link = TRUE;                 /* OK  you have permission */
       siz_flag = TRUE;             /* default mode */
       testgad.TopEdge = Top;
       testgad.LeftEdge = Left;
       testgad.Height = Height;
       testgad.Width = Width;
       frst = 5;                 /* remove later */
 
       /* We should prabably have an option here to change the border
          around the gadget if it gets re-sized.  We must check the
          option flag, if TRUE,  then change the "appropriate pairs"
          value in the gadget.
       */
       ModifyIDCMP(w, nw.IDCMPFlags);
       if (!oldgad && Width > 8 && Height > 4) {
            addgad();                 /* $$$ Allocate the gadget */
       }
      flags = (long)testgad.UserData;
 
       if ((testgad.GadgetType != PROPGADGET) &&
          ((flags & GAD_IMAGE_TYPE) != GAD_IMAGE_TYPE)) {
          bd = (struct Border *)testgad.GadgetRender;
          pairs = bd->XY;
          pairs[2] = pairs[4] = Width;
          pairs[5] = pairs[7] = Height;
       }
       if (gads[curgad] != NULL) {
          *gads[curgad] = testgad;       /* Update Gadget data */
 
           /* Force user to enter gadget name */
           if (gadnames[curgad] == NULL) {
             str = getrname("Enter Gadget name");
             strcpy(names[curgad], str);
             gadnames[curgad] = names[curgad];
           }
       }
       /* $$$ Erase the border - perhaps            */
/*         draw_box(rp, Left-1, Top-1, Width, Height);
          erase = FALSE;
*/
       /* ### Refresh the gadgets */
       if (nextlink == nextgad && nextlink != NULL) {
          draw_box(rp, Left-1, Top-1, Width, Height);
          SetAPen(rp, 0L);
          SetDrMd(rp, JAM1);
          /* remove old intuitexts */
          ClearAllTexts(gads[curgad],Lf+1L,Tp+1L);
          RectFill(rp, Lf-1L, Tp-1L, Lf+Wd+2L, Tp+Ht+2L);
          RefreshGadgets(gads[0], w, NULL);
       }
    }
}
/* ----------------------------------------------------------------------
  Find the location of the mouse and determine if it falls on any gadget,
  return an index into the gadget structure where the mouse is pointing
  to.  It involves searching each of the "Gadget" structures looking for
  a "LeftEdge/TopEdge" that falls "under" the mouse.
-----------------------------------------------------------------------*/
int findmouse(x, y)
SHORT x, y;           /* Coordinates of the mouse */
{
     int   ind = 0;  /* Index into Gadget pointer array */
     if (nextgad == NULL) return(-1);
 
     for (ind = 0;  ind < nextgad; ind++) {
        if (x >= gads[ind]->LeftEdge &&
           x <= (gads[ind]->LeftEdge + gads[ind]->Width) &&
           y >= gads[ind]->TopEdge &&
           y <= (gads[ind]->TopEdge + gads[ind]->Height))
          return(ind);
     }
     return(-1);
}
/*------------------------------------------------------------------------
  Determine if the mouse was pressed in the corner of the box, indicating
  that the user wants to change the gadget's size.
------------------------------------------------------------------------*/
int in_corner(which, x, y)
int which;                    /* Index to specific gadget */
SHORT x, y;                   /* Mouse location */
{
    SHORT left, top, deltx, delty;
 
    top  = y - gads[which]->Height;
    left = x - gads[which]->Width;
    deltx = gads[which]->LeftEdge - left;
    delty = gads[which]->TopEdge - top;
 
    if (deltx < 8 && deltx > -8 && delty < 6 && delty > -6)
       return(TRUE);
    else
       return(FALSE);
}
SHAR_EOF
fi
if test -f 'reqn.c'
then
	echo shar: "will not over-write existing file 'reqn.c'"
else
cat << \SHAR_EOF > 'reqn.c'
/*========================================================================
  reqn.c - General purpose requestor code.  Contains the following functions:
 
  Init_all_req() - Initializes all requestors
  initreq        - Initializes a particular requestor
  getrname       - Brings up requestor that returns pointer to a name
                   also accepts an input string thats displayed on the
                   requestor.
==========================================================================*/
 
/*  The usual header files inserted here */
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
 
/*=========================================
  Important requestor constants wich might
  eventually get moved into "gad.h" file,
  but for now,  we keep it here.
=========================================*/
 
#define OK_BUT    1
#define CAN_BUT   2
#define NAM_GAD   3
 
/*=========================================
  External declarations
==========================================*/
 
extern struct Window *w;
extern struct NewWindow nw;
extern struct IntuiMessage *GetMsg();
 
/*=========================================
  Border around the GetName requestor
==========================================*/
 
SHORT req_pairs[] = {
  0,     0,
  257,   0,
  257,  60,
  0,    60,
  0,     0
};
 
struct Border req_bord = {
  -1,  -1,
  1,  3,  JAM2,
  5,
  (SHORT *)&req_pairs,
  NULL
};
 
 
/*=========================================
  Gadgets, Borders, Etc to the getname
  requestor
==========================================*/
 
SHORT Pairs_1[] = {
  0,     0,
  65,    0,
  65,   10,
  0,    10,
  0,     0
};
 
struct Border bord_1 = {
  -1,  -1,
  1,  3,  JAM2,
  5,
  (SHORT *)&Pairs_1,
  NULL
};
 
struct IntuiText OKtext = {2,2,JAM1, 34, 1, NULL,
  (UBYTE *) "OK", NULL};
 
struct Gadget ok_but = {
  NULL, 121, 39, 65, 10,
  GADGHCOMP,
  GADGIMMEDIATE | ENDGADGET | RELVERIFY,
  BOOLGADGET | REQGADGET,
  (APTR)&bord_1,  (APTR)&bord_1,
  &OKtext, NULL,
  NULL,   OK_BUT, NULL
};
 
SHORT Pairs_2[] = {
  0,     0,
  63,     0,
  63,     10,
  0,     10,
  0,     0
};
struct Border bord_2 = {
  -1,  -1,
  1,  3,  JAM2,
  5,
  (SHORT *)&Pairs_2,
  NULL
};
 
struct IntuiText CANCELtext = {2,2,JAM1, 14, 1, NULL,
  (UBYTE *) "CANCEL", NULL};
 
struct Gadget can_but = {
 &ok_but, 37, 39, 63, 10,
 GADGHCOMP,
 GADGIMMEDIATE | ENDGADGET | RELVERIFY,
  BOOLGADGET | REQGADGET,
  (APTR)&bord_2,  (APTR)&bord_2,
  &CANCELtext, NULL,
  NULL,   CAN_BUT, NULL,
};
 
SHORT Pairs_3[] = {
  0,     0,
  152,     0,
  152,     10,
  0,     10,
  0,     0
};
struct Border bord_3 = {
  -1,  -1,
  1,  3,  JAM2,
  5,
  (SHORT *)&Pairs_3,
  NULL
};
 
UBYTE sbuf_1[256] = '\0';
 
struct StringInfo txstr_1 = {
  sbuf_1, NULL,
  0, 256, 0,
  0, 0,
  0, 0, 0,
  0, 0,
  0
};
 
struct IntuiText req_name = {2,2, JAM1, 10, 10, NULL, NULL, NULL};
 
struct Gadget nametext = {
 &can_but, 36, 21, 152, 10,
 GADGHCOMP,
  RELVERIFY | ENDGADGET,
  STRGADGET | REQGADGET,
  (APTR)&bord_3,  (APTR)&bord_3,
  NULL,
  NULL,
  (APTR)&txstr_1,   NAM_GAD, NULL
};
 
struct Requester Save_req;
 
 
/*======================================================================
  Code that Initializes ALL requestors in the Gadget Editor program
=======================================================================*/
init_all_req()
{
    initreq(&Save_req, &nametext, &req_bord);
}
/*======================================================================
  InitReq(req, gad, bord) - Initializes a requestor,  req is a pointer to a
  previously allocated requestor.  Later on,  perhaps we can Allocate
  one and return a pointer to it,   However,  because cleaning up
  is tricky,   I'm taking the easy way out
=======================================================================*/
initreq(req, gad, bord)
struct Requester *req;       /* Pointer to a requestor */
struct Gadget *gad;          /* First gadget in requestor */
struct Border *bord;         /* Pointer to border */
{
    InitRequester(req);      /* Init the requestor */
    req->LeftEdge  = 169;
    req->TopEdge   = 44;
    req->Width     = 257;
    req->Height    = 60;
    req->ReqGadget = gad;             /* First Gadget */
    req->ReqText   = NULL;            /* First Intuitext */
    req->BackFill  = 1;               /* Backgnd color */
    req->Flags     = 0;               /* Must have at least one */
    req->ReqBorder = bord;            /* Outside border */
 
}
/*======================================================================
  nam_info - Return a pointer to the stringinfo structure to the
  filename requester.   We do this because it's good programming
  practice to keep this module isolated as much as possible from
  the main program.
=======================================================================*/
struct StringInfo *nam_info()
{
    return(&txstr_1);
}
 
/*======================================================================
 
       Brings up this requester  called: Save_req
       -----------------------------------------
      |                                         |
      |        SAVE FILENAME AS:                |
      |    ------------------------------       |
      |   | MyPresentation               |      |
      |    ------------------------------       |
      |                                         |
      |   ----------        -------------       |
      |  |    OK    |      |    CANCEL   |      |
      |   ----------        -------------       |
      |                                         |
       -----------------------------------------
 
In an attempt to isolate this routine from knowing the names of the
Gadget structures,  It relies on the GadgetID field to identify which
gadget got struck.   OK_BUT is the OK button gadget,  CAN_BUT is the
"CANCEL" button.
=======================================================================*/
UBYTE *getrname(str)
UBYTE *str;                /* Message string "SAVE FILENAME AS:" */
{
  int   looping=TRUE;
  struct IntuiMessage *mes;
  struct StringInfo *si = NULL;
  struct Gadget *gad;
  ULONG class;
  ULONG iflags;
 
  /*-------- Set up the IntuiText for the gadget -------*/
  req_name.IText = str;
  Save_req.ReqText = &req_name;
  iflags = nw.IDCMPFlags;         /* Current flag settings */
 
  /*-------- Open up the requester $$$---------*/
  if ((Request(&Save_req, w)) == 1L) {
     iflags |= REQSET;
     ModifyIDCMP(w, iflags);
     while (looping) {
         if ((mes = (struct IntuiMessage *)GetMsg(w->UserPort)) == 0L) {
            Wait(1L<UserPort->mp_SigBit);
            continue;
         }
         class = mes->Class;
         gad = (struct Gadget *)mes->IAddress;
         ReplyMsg(mes);
 
        /*-------- Handle the case where requester clears --------*/
        if (class == GADGETDOWN && gad->GadgetID == CAN_BUT) {
            return(NULL);
        }
        if (class == REQSET) {
           ActivateGadget(&nametext, w, &Save_req);
           txstr_1.BufferPos = txstr_1.MaxChars;
           RefreshGadgets(&nametext, w, &Save_req);
        }
 
        if (class == GADGETDOWN && gad->GadgetID == OK_BUT) {
            return(sbuf_1);
        }
 
        if (class == GADGETUP && gad == &nametext) {
           ModifyIDCMP(w, nw.IDCMPFlags);
           return(sbuf_1);
        }
 
        if (class == REQCLEAR) {
            looping = FALSE;
        }
 
     } /* while */
  } /* if request */
  else printf("Requester error...\n");
}
/* ==================================
   get_req_name - Get a string from the
   standard requester.   Return with
   the string in the given pointer.
====================================*/
get_req_name(in_str, out_str)
UBYTE *in_str;             /* Input name displayed in requester */
UBYTE *out_str;            /* Output name displayed in req */
{   UBYTE *temp;
    if (out_str != NULL) {
       strcpy(txstr_1.Buffer, out_str);
       txstr_1.BufferPos = strlen(txstr_1.Buffer) + 1;
    }
    else {
       *txstr_1.Buffer = '\0';
        txstr_1.BufferPos = 0;
    }
    if ((temp = getrname(in_str)) != NULL) {
        strcpy(out_str, temp);
        return (TRUE);
    }
   else return (FALSE);
}
 
SHAR_EOF
fi
if test -f 'utilmen.c'
then
	echo shar: "will not over-write existing file 'utilmen.c'"
else
cat << \SHAR_EOF > 'utilmen.c'
/*========================================================================
   Utilmen.c - Utility menu functions are in this module.  Might want
   to break it up into two pieces later.   For now,  we keep just one
========================================================================*/
 
/*  The usual header files to be inserted later  */
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
 
/* constants */
 
/* external functions */
 
/* external variables */
extern struct Gadget *gads[];
extern char *gadnames[];
extern int nextgad;
extern struct Window *w;
extern int link;    /* Do not add gadget unless told to */
 
/* global vars */
 
int nextlink = 0;      /* Next link */
 
/*----------------------------------------------------------------------
  Link Gadgets to the window.  Sets a global var "lastlinked", so it
  can keep track of what was already linked to the list.
-----------------------------------------------------------------------*/
 
linkgadgets()
{
    int i;
    if (nextgad != NULL || link == TRUE) {
      for (i= nextlink; iGadgetType > 0 ||
             gads[i]->GadgetType < 4 ) {
                   AddGadget(w, gads[i], -1L);
                   nextlink++;
         }
         else {
            kprintf("Enter gadget type first!!!\n");
            link = FALSE;
            return();
         }
      }
      if (link) {
        RefreshGadgets(gads[0], w, NULL);
      }
      link = FALSE;
   }
   else {
kprintf("Bad news!!! nextgad is %d\n", nextgad);
 
   }
}
 

SHAR_EOF
fi
exit 0
#	End of shell archive
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Last batch
Next Topic: Re: Blitter
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Fri Apr 19 19:48:16 EDT 2024

Total time taken to generate the page: 0.02468 seconds