home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / coders / guicreator / demos / printer_functions.c < prev    next >
C/C++ Source or Header  |  1977-12-31  |  15KB  |  317 lines

  1. /*************************************************************************/
  2. /*                                                                       */
  3. /*   Includes                                                            */
  4. /*                                                                       */
  5. /*************************************************************************/
  6.  
  7. #include "Printer_Includes.h"
  8. #include "Printer_Structures.h"
  9.  
  10. /*************************************************************************/
  11. /*                                                                       */
  12. /*   Variables and Structures                                            */
  13. /*                                                                       */
  14. /*************************************************************************/
  15.  
  16. extern struct IntuitionBase  *IntuitionBase;
  17. extern struct GfxBase        *GfxBase;
  18.  
  19. extern struct Library *GadToolsBase;
  20. extern struct Library *AslBase;
  21. extern struct Library *DataTypesBase;
  22.  
  23. extern struct BevelFrame;
  24. extern struct Line;
  25. extern struct Text;
  26.  
  27. /*************************************************************************/
  28. /*                                                                       */
  29. /*   Defines                                                             */
  30. /*                                                                       */
  31. /*************************************************************************/
  32.  
  33. #define RASTERX (GfxBase->DefaultFont->tf_XSize)
  34. #define RASTERY (GfxBase->DefaultFont->tf_YSize)
  35.  
  36. #define XSIZE(x)  ((x)*RASTERX)
  37. #define YSIZE(x)  ((x)*RASTERY)
  38.  
  39. #define XPOS(x)   (XSIZE(x)+customscreen->WBorLeft)
  40. #define YPOS(x)   (YSIZE(x)+customscreen->BarHeight+1)
  41.  
  42. /*************************************************************************/
  43. /*                                                                       */
  44. /*   SleepWindow() und WakenWindow()                                     */
  45. /*                                                                       */
  46. /*************************************************************************/
  47.  
  48. static struct Requester waitrequest;
  49.  
  50. void SleepWindow(struct Window *win)
  51. {
  52.    InitRequester(&waitrequest);
  53.    Request(&waitrequest,win);
  54.    SetWindowPointer(win,WA_BusyPointer,1L,TAG_DONE);
  55. }
  56.  
  57. void WakenWindow(struct Window *win)
  58. {
  59.    EndRequest(&waitrequest,win);
  60.    SetWindowPointer(win,WA_Pointer,0L,TAG_DONE);
  61. }
  62.  
  63. /*************************************************************************/
  64. /*                                                                       */
  65. /*   GUICreatorErrorReport()                                             */
  66. /*                                                                       */
  67. /*************************************************************************/
  68.  
  69. void GUICreatorErrorReport(struct Window *win,ULONG type)
  70. {
  71.    char error[256];
  72.    struct EasyStruct easystruct = { sizeof(struct EasyStruct),0,"Caution:",error,"OK" };
  73.  
  74.    if (type == ERROR_NO_WINDOW_OPENED)
  75.       strcpy(error,"Could not open window (no memory?)");
  76.    else if (type == ERROR_NO_PUBSCREEN_LOCKED)
  77.       strcpy(error,"Could not lock pubscreen");
  78.    else if (type == ERROR_NO_GADGETS_CREATED)
  79.       strcpy(error,"Could not create gadgets");
  80.    else if (type == ERROR_NO_GADGETLIST_CREATED)
  81.       strcpy(error,"Could not create gadgetlist");
  82.    else if (type == ERROR_NO_VISUALINFO)
  83.       strcpy(error,"Could not read visualinfo from screen");
  84.    else if (type == ERROR_NO_PICTURE_LOADED)
  85.       strcpy(error,"Could not read picture data");
  86.    else if (type == ERROR_NO_WINDOW_MENU)
  87.       strcpy(error,"Could not create menu");
  88.    else if (type == ERROR_SCREEN_TOO_SMALL)
  89.       strcpy(error,"This screen is too small for the window");
  90.    else Fault(type,"Error",error,sizeof(error));
  91.  
  92.    if (win && !win->FirstRequest)
  93.       {
  94.       SleepWindow(win);
  95.       EasyRequestArgs(win,&easystruct,NULL,NULL);
  96.       WakenWindow(win);
  97.       }
  98.    else EasyRequestArgs(win,&easystruct,NULL,NULL);
  99.  
  100. }
  101.  
  102. /*************************************************************************/
  103. /*                                                                       */
  104. /*   CreateBevelFrames()                                                 */
  105. /*                                                                       */
  106. /*************************************************************************/
  107.  
  108. void CreateBevelFrames(struct Window *win,APTR visualinfo,ULONG bevelcount,struct BevelFrame bevels[])
  109. {
  110.    ULONG i;
  111.    for (i=0;i<bevelcount;i++)
  112.       {
  113.       DrawBevelBox(win->RPort,bevels[i].bb_LeftEdge,bevels[i].bb_TopEdge,bevels[i].bb_Width,bevels[i].bb_Height,GT_VisualInfo,visualinfo,GTBB_Recessed,TRUE,TAG_END);
  114.       DrawBevelBox(win->RPort,bevels[i].bb_LeftEdge+2,bevels[i].bb_TopEdge+1,bevels[i].bb_Width-4,bevels[i].bb_Height-2,GT_VisualInfo,visualinfo,TAG_END);
  115.       if (bevels[i].bb_Title)
  116.          {
  117.          char title[64];
  118.          sprintf(title," %s ",bevels[i].bb_Title);
  119.          Move(win->RPort,bevels[i].bb_LeftEdge+(bevels[i].bb_Width-XSIZE(strlen(title)))/2,bevels[i].bb_TopEdge+2);
  120.          SetAPen(win->RPort,bevels[i].bb_Color);
  121.          Text(win->RPort,title,strlen(title));
  122.          }
  123.       /* end -if */
  124.       }
  125.    /* end-for */
  126. }
  127.  
  128. /*************************************************************************/
  129. /*                                                                       */
  130. /*   CreateLines()                                                       */
  131. /*                                                                       */
  132. /*************************************************************************/
  133.  
  134. void CreateLines(struct Window *win,ULONG linecount,struct Line lines[])
  135. {
  136.    ULONG i;
  137.    for (i=0;i<linecount;i++)
  138.       {
  139.       SetAPen(win->RPort,lines[i].li_Color);
  140.       Move(win->RPort,lines[i].li_LeftEdge,lines[i].li_TopEdge);
  141.       Draw(win->RPort,lines[i].li_Width>0?lines[i].li_LeftEdge+lines[i].li_Width-1:lines[i].li_LeftEdge+lines[i].li_Width,lines[i].li_Height>0?lines[i].li_TopEdge+lines[i].li_Height-1:lines[i].li_TopEdge+lines[i].li_Height);
  142.       }
  143.    /* end-for */
  144. }
  145.  
  146. /*************************************************************************/
  147. /*                                                                       */
  148. /*   CreateTexts()                                                       */
  149. /*                                                                       */
  150. /*************************************************************************/
  151.  
  152. void CreateTexts(struct Window *win,ULONG textcount,struct Text texts[],long double xscale,long double yscale)
  153. {
  154.    ULONG i;
  155.    for (i=0;i<textcount;i++)
  156.       {
  157.       SetAPen(win->RPort,texts[i].tx_Color);
  158.       Move(win->RPort,texts[i].tx_LeftEdge,texts[i].tx_TopEdge+(ULONG)(yscale*GfxBase->DefaultFont->tf_Baseline));
  159.       Text(win->RPort,texts[i].tx_Text,strlen(texts[i].tx_Text));
  160.       }
  161.    /* end-for */
  162. }
  163.  
  164. /*************************************************************************/
  165. /*                                                                       */
  166. /*   About()                                                             */
  167. /*                                                                       */
  168. /*************************************************************************/
  169.  
  170. void About(struct Window *hostwin)
  171. {
  172.    APTR visualinfo=GetVisualInfo(hostwin->WScreen,TAG_DONE);
  173.    if (visualinfo)
  174.       {
  175.       Object *o=NewDTObject("/About.IFF",DTA_SourceType,DTST_FILE,DTA_GroupID,GID_PICTURE,TAG_DONE);
  176.       if (o)
  177.          {
  178.          struct Gadget  *gadgetlist   = NULL;
  179.          struct Screen  *customscreen = hostwin->WScreen;
  180.          struct Gadget  *gadget       = CreateContext(&gadgetlist);
  181.          if (gadget)
  182.             {
  183.             ULONG height=25,width=34,left=0,top=0;
  184.             ULONG textcount=18;
  185.  
  186.             struct Gadget *wingad;
  187.  
  188.             STRPTR title                  = "About";
  189.             struct Window     *win        = NULL;
  190.  
  191.             struct TextAttr   textattr    = { GfxBase->DefaultFont->tf_Message.mn_Node.ln_Name,GfxBase->DefaultFont->tf_YSize,FS_NORMAL,FPF_DISKFONT };
  192.  
  193.             struct NewGadget  newgad      = { XPOS(1),YPOS(22),XSIZE(32)+200,YSIZE(2),"_OK",&textattr,2,PLACETEXT_IN,visualinfo,NULL };
  194.  
  195.             struct Text       texts[]     = {
  196.                                               200+XPOS(4),YPOS(2),"****************************",1,
  197.                                               200+XPOS(4),YPOS(3),"*                          *",1,
  198.                                               200+XPOS(4),YPOS(4),"*  This  GUI was designed  *",1,
  199.                                               200+XPOS(4),YPOS(5),"*                          *",1,
  200.                                               200+XPOS(4),YPOS(6),"*  with GUI-Creator V 1.0  *",1,
  201.                                               200+XPOS(4),YPOS(7),"*                          *",1,
  202.                                               200+XPOS(4),YPOS(8),"*  © 1995 by               *",1,
  203.                                               200+XPOS(4),YPOS(9),"*  Markus Hillenbrand      *",1,
  204.                                               200+XPOS(4),YPOS(10),"*                          *",1,
  205.                                               200+XPOS(4),YPOS(11),"* ------------------------ *",1,
  206.                                               200+XPOS(4),YPOS(12),"*                          *",1,
  207.                                               200+XPOS(4),YPOS(13),"* GUI-Creator is Shareware *",1,
  208.                                               200+XPOS(4),YPOS(14),"*                          *",1,
  209.                                               200+XPOS(4),YPOS(15),"* Please read the docs for *",1,
  210.                                               200+XPOS(4),YPOS(16),"*                          *",1,
  211.                                               200+XPOS(4),YPOS(17),"* more information!        *",1,
  212.                                               200+XPOS(4),YPOS(18),"*                          *",1,
  213.                                               200+XPOS(4),YPOS(19),"****************************",1,
  214.                                               };
  215.  
  216.             height= YSIZE(height);
  217.             width = XSIZE(width)+200;
  218.             left  = (customscreen->Width-width)/2;
  219.             top   = (customscreen->Height-height)/2;
  220.  
  221.             wingad = gadget = CreateGadget(BUTTON_KIND,gadget,&newgad,GT_Underscore,'_',TAG_END);
  222.  
  223.             if (height>customscreen->Height || width>customscreen->Width) GUICreatorErrorReport(hostwin,ERROR_SCREEN_TOO_SMALL);
  224.             win=OpenWindowTags(NULL,WA_Activate,         TRUE,
  225.                                     WA_CloseGadget,      TRUE,
  226.                                     WA_DepthGadget,      TRUE,
  227.                                     WA_SizeGadget,       FALSE,
  228.                                     WA_DragBar,          TRUE,
  229.                                     WA_Gadgets,          gadgetlist,
  230.                                     WA_InnerHeight,      height,
  231.                                     WA_InnerWidth,       width,
  232.                                     WA_IDCMP,            IDCMP_CLOSEWINDOW|BUTTONIDCMP|IDCMPUPDATE|IDCMP_VANILLAKEY,
  233.                                     WA_Left,             left,
  234.                                     WA_Top,              top,
  235.                                     WA_SmartRefresh,     TRUE,
  236.                                     WA_Title,            title,
  237.                                     WA_CustomScreen,     customscreen,
  238.                                     TAG_END);
  239.             if (win)
  240.                {
  241.                struct IntuiMessage  *imessage   = NULL;
  242.                struct Gadget        *idcmpgad   = NULL;
  243.                struct BitMap        *bitmap     = NULL;
  244.                struct BitMap        *bmcopy     = NULL;
  245.                struct TagItem       *tag        = NULL;
  246.                struct TagItem       *tstate     = NULL;
  247.                ULONG  idcmpclass                = 0;
  248.                UWORD  messagecode               = 0;
  249.                BOOL   running                   = TRUE;
  250.  
  251.                SleepWindow(hostwin);
  252.                SetFont(win->RPort,GfxBase->DefaultFont);
  253.  
  254.                DrawBevelBox(win->RPort,XPOS(1),YPOS(1),204,102,GT_VisualInfo,visualinfo,GTBB_Recessed,TRUE,TAG_END);
  255.                DrawBevelBox(win->RPort,XPOS(3)+200,YPOS(1),XSIZE(30),YSIZE(20),GT_VisualInfo,visualinfo,GTBB_Recessed,TRUE,TAG_END);
  256.  
  257.                SetDTAttrs(o,NULL,NULL,GA_Left,XPOS(1)+2,GA_Top,YPOS(1)+1,GA_Width,200,GA_Height,100,PDTA_Remap,TRUE,PDTA_DestBitMap,&bmcopy,ICA_TARGET,ICTARGET_IDCMP,TAG_DONE);
  258.                AddDTObject(win,NULL,o,-1L);
  259.  
  260.                CreateTexts(win,textcount,texts,1,1);
  261.  
  262.                GT_RefreshWindow(win,NULL);
  263.  
  264.                while (running)
  265.                   {
  266.                   Wait(1L << win->UserPort->mp_SigBit);
  267.                   while (imessage=GT_GetIMsg(win->UserPort))
  268.                      {
  269.                      idcmpgad=(struct Gadget *)imessage->IAddress;
  270.                      idcmpclass=imessage->Class;
  271.                      messagecode =imessage->Code;
  272.  
  273.                      GT_ReplyIMsg(imessage);
  274.  
  275.                      switch(idcmpclass)
  276.                         {
  277.                         case IDCMP_VANILLAKEY:
  278.                            if (messagecode==27 || messagecode=='o' || messagecode=='O') running=FALSE;
  279.                            break;
  280.                         case IDCMP_REFRESHWINDOW:
  281.                            GT_BeginRefresh(win);
  282.                            GT_EndRefresh(win,TRUE);
  283.                            break;
  284.                         case IDCMP_CLOSEWINDOW:
  285.                            running=FALSE;
  286.                            break;
  287.                         case BUTTONIDCMP:
  288.                            running=FALSE;
  289.                            break;
  290.                         case IDCMP_IDCMPUPDATE:
  291.                            tstate=(struct TagItem*)imessage->IAddress;
  292.                            while (tag=NextTagItem(&tstate)) if (tag->ti_Tag==DTA_Sync) RefreshDTObjectA(o,win,NULL,NULL);
  293.                            break;
  294.                         }
  295.                      /* end-switch */
  296.  
  297.                      }
  298.                   /* end-while */
  299.                   }
  300.                /* end-while */
  301.  
  302.                CloseWindow(win);
  303.                WakenWindow(hostwin);
  304.                }
  305.             else GUICreatorErrorReport(hostwin,ERROR_NO_WINDOW_OPENED);
  306.             FreeGadgets(gadgetlist);
  307.             }
  308.          else GUICreatorErrorReport(hostwin,ERROR_NO_GADGETLIST_CREATED);
  309.          DisposeDTObject(o);
  310.          }
  311.       else GUICreatorErrorReport(hostwin,ERROR_NO_PICTURE_LOADED);
  312.       FreeVisualInfo(visualinfo);
  313.       }
  314.    else GUICreatorErrorReport(hostwin,ERROR_NO_VISUALINFO);
  315.  
  316. }
  317.