home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 2 / FFMCD02.bin / new / gfx / edit / tsmorph / progress.c < prev    next >
C/C++ Source or Header  |  1993-12-21  |  7KB  |  271 lines

  1. // TSMorph - Amiga Morphing program
  2. // Copyright (C) © 1993  Topicsave Limited
  3.  
  4. // This program is free software; you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation; either version 2 of the License, or
  7. // any later version.
  8.  
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. // GNU General Public License for more details.
  13.  
  14. // You should have received a copy of the GNU General Public License
  15. // along with this program; if not, write to the Free Software
  16. // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17.  
  18. // mpaddock@cix.compulink.co.uk
  19.  
  20. //    $Author: M_J_Paddock $
  21. //    $Date: 1992/08/08 01:07:30 $
  22. //    $Revision: 1.4 $
  23.  
  24. /*
  25.  *  Source machine generated by GadToolsBox V2.0
  26.  *  which is (c) Copyright 1991-1993 Jaba Development
  27.  *
  28.  *  GUI Designed by : M J P
  29.  */
  30.  
  31. // Minor editing by MJP
  32.  
  33. #include <exec/types.h>
  34. #include <intuition/intuition.h>
  35. #include <intuition/classes.h>
  36. #include <intuition/classusr.h>
  37. #include <intuition/imageclass.h>
  38. #include <intuition/gadgetclass.h>
  39. #include <libraries/gadtools.h>
  40. #include <graphics/displayinfo.h>
  41. #include <graphics/gfxbase.h>
  42. #include <clib/exec_protos.h>
  43. #include <clib/intuition_protos.h>
  44. #include <clib/gadtools_protos.h>
  45. #include <clib/graphics_protos.h>
  46. #include <clib/utility_protos.h>
  47. #include <string.h>
  48. #include <pragmas/exec_pragmas.h>
  49. #include <pragmas/intuition_pragmas.h>
  50. #include <pragmas/gadtools_pragmas.h>
  51. #include <pragmas/graphics_pragmas.h>
  52. #include <pragmas/utility_pragmas.h>
  53.  
  54. extern struct Library *SysBase,*GfxBase;
  55. extern struct Library *UtilityBase;
  56.  
  57. #include "progress.h"
  58.  
  59. struct Screen         *Scr = NULL;
  60. UBYTE                 *PubScreenName = NULL;
  61. APTR                   VisualInfo = NULL;
  62. struct Window         *ProgressWnd = NULL;
  63. struct Gadget         *ProgressGList = NULL;
  64. struct IntuiMessage    ProgressMsg;
  65. UWORD                  ProgressZoom[4];
  66. struct Gadget         *ProgressGadgets[4];
  67. UWORD                  ProgressLeft = 215;
  68. UWORD                  ProgressTop = 42;
  69. UWORD                  ProgressWidth = 261;
  70. UWORD                  ProgressHeight = 133;
  71. UBYTE                 *ProgressWdt = (UBYTE *)"TSMorph Progress";
  72. struct TextAttr       *Font, Attr;
  73. UWORD                  FontX, FontY;
  74. UWORD                  OffX, OffY;
  75.  
  76. UWORD ProgressGTypes[] = {
  77.     SLIDER_KIND,
  78.     SLIDER_KIND,
  79.     BUTTON_KIND,
  80.     LISTVIEW_KIND
  81. };
  82.  
  83. struct NewGadget ProgressNGad[] = {
  84.     52, 78, 176, 11, (UBYTE *)"Frame", NULL, GD_Frame, PLACETEXT_LEFT, NULL, (APTR)FrameClicked,
  85.     52, 95, 176, 11, (UBYTE *)"Line", NULL, GD_Line, PLACETEXT_LEFT, NULL, (APTR)LineClicked,
  86.     82, 111, 95, 19, (UBYTE *)"Stop", NULL, GD_Stop, PLACETEXT_IN, NULL, (APTR)StopClicked,
  87.     6, 6, 251, 65, NULL, NULL, GD_Info, 0, NULL, NULL
  88. };
  89.  
  90. extern struct List InfoList = {0};
  91.  
  92. ULONG ProgressGTags[] = {
  93.     (GTSL_Max), 999, (GTSL_MaxLevelLen), 4, (GTSL_LevelFormat), (ULONG)"%3ld", (GTSL_LevelPlace), (PLACETEXT_RIGHT), (PGA_Freedom), LORIENT_HORIZ, (GA_RelVerify), TRUE, GA_Disabled,TRUE,(TAG_DONE),
  94.     (GTSL_Max), 999, (GTSL_MaxLevelLen), 4, (GTSL_LevelFormat), (ULONG)"%3ld", (GTSL_LevelPlace), (PLACETEXT_RIGHT), (PGA_Freedom), LORIENT_HORIZ, (GA_RelVerify), TRUE, GA_Disabled,TRUE,(TAG_DONE),
  95.     (TAG_DONE),
  96.     (GTLV_Labels), &InfoList, (GTLV_ReadOnly), TRUE, (TAG_DONE)
  97. };
  98.  
  99. static UWORD ComputeX( UWORD value )
  100. {
  101.     return(( UWORD )((( FontX * value ) + 3 ) / 6 ));
  102. }
  103.  
  104. static UWORD ComputeY( UWORD value )
  105. {
  106.     return(( UWORD )((( FontY * value ) + 5 ) / 10 ));
  107. }
  108.  
  109. static void ComputeFont( UWORD width, UWORD height )
  110. {
  111.     Font = &Attr;
  112.     Font->ta_Name = (STRPTR)Scr->RastPort.Font->tf_Message.mn_Node.ln_Name;
  113.     Font->ta_YSize = FontY = Scr->RastPort.Font->tf_YSize;
  114.     FontX = Scr->RastPort.Font->tf_XSize;
  115.  
  116.     OffX = Scr->WBorLeft;
  117.     OffY = Scr->RastPort.TxHeight + Scr->WBorTop + 1;
  118.  
  119.     if ( width && height ) {
  120.         if (( ComputeX( width ) + OffX + Scr->WBorRight ) > Scr->Width )
  121.             goto UseTopaz;
  122.         if (( ComputeY( height ) + OffY + Scr->WBorBottom ) > Scr->Height )
  123.             goto UseTopaz;
  124.     }
  125.     return;
  126.  
  127. UseTopaz:
  128.     Font->ta_Name = (STRPTR)"topaz.font";
  129.     FontX = FontY = Font->ta_YSize = 8;
  130. }
  131.  
  132. int SetupScreen( void )
  133. {
  134.     if ( ! ( Scr = LockPubScreen( PubScreenName )))
  135.         return( 1L );
  136.  
  137.     ComputeFont( 0, 0 );
  138.  
  139.     if ( ! ( VisualInfo = GetVisualInfo( Scr, TAG_DONE )))
  140.         return( 2L );
  141.  
  142.     return( 0L );
  143. }
  144.  
  145. void CloseDownScreen( void )
  146. {
  147.     if ( VisualInfo ) {
  148.         FreeVisualInfo( VisualInfo );
  149.         VisualInfo = NULL;
  150.     }
  151.  
  152.     if ( Scr        ) {
  153.         UnlockPubScreen( NULL, Scr );
  154.         Scr = NULL;
  155.     }
  156. }
  157.  
  158. int HandleProgressIDCMP( void )
  159. {
  160.     struct IntuiMessage    *m;
  161.     int            (*func)(void);
  162.     BOOL            running = TRUE;
  163.  
  164.     while( m = GT_GetIMsg( ProgressWnd->UserPort )) {
  165.  
  166.         CopyMem(( char * )m, ( char * )&ProgressMsg, (long)sizeof( struct IntuiMessage ));
  167.  
  168.         GT_ReplyIMsg( m );
  169.  
  170.         switch ( ProgressMsg.Class ) {
  171.  
  172.             case    IDCMP_REFRESHWINDOW:
  173.                 GT_BeginRefresh( ProgressWnd );
  174.                 GT_EndRefresh( ProgressWnd, TRUE );
  175.                 break;
  176.  
  177.             case    IDCMP_RAWKEY:
  178.                 running = ProgressRawKey();
  179.                 break;
  180.  
  181.             case    IDCMP_GADGETUP:
  182. //            case    IDCMP_GADGETDOWN:
  183.                 func = ( void * )(( struct Gadget * )ProgressMsg.IAddress )->UserData;
  184.                 running = func();
  185.                 break;
  186.         }
  187.     }
  188.     return( (int) running );
  189. }
  190.  
  191. int OpenProgressWindow( void )
  192. {
  193.     struct NewGadget    ng;
  194.     struct Gadget    *g;
  195.     UWORD        lc, tc;
  196.     UWORD        wleft = ProgressLeft, wtop = ProgressTop, ww, wh;
  197.  
  198.     NewList(&InfoList);
  199.  
  200.     ComputeFont( ProgressWidth, ProgressHeight );
  201.  
  202.     ww = ComputeX( ProgressWidth );
  203.     wh = ComputeY( ProgressHeight );
  204.  
  205.     if (( wleft + ww + OffX + Scr->WBorRight ) > Scr->Width ) wleft = Scr->Width - ww;
  206.     if (( wtop + wh + OffY + Scr->WBorBottom ) > Scr->Height ) wtop = Scr->Height - wh;
  207.  
  208.     if ( ! ( g = CreateContext( &ProgressGList )))
  209.         return( 1L );
  210.  
  211.     for( lc = 0, tc = 0; lc < Progress_CNT; lc++ ) {
  212.  
  213.         CopyMem((char * )&ProgressNGad[ lc ], (char * )&ng, (long)sizeof( struct NewGadget ));
  214.  
  215.         ng.ng_VisualInfo = VisualInfo;
  216.         ng.ng_TextAttr   = Font;
  217.         ng.ng_LeftEdge   = OffX + ComputeX( ng.ng_LeftEdge );
  218.         ng.ng_TopEdge    = OffY + ComputeY( ng.ng_TopEdge );
  219.         ng.ng_Width      = ComputeX( ng.ng_Width );
  220.         ng.ng_Height     = ComputeY( ng.ng_Height);
  221.  
  222.         ProgressGadgets[ lc ] = g = CreateGadgetA((ULONG)ProgressGTypes[ lc ], g, &ng, ( struct TagItem * )&ProgressGTags[ tc ] );
  223.  
  224.         while( ProgressGTags[ tc ] ) tc += 2;
  225.         tc++;
  226.  
  227.         if ( NOT g )
  228.             return( 2L );
  229.     }
  230.  
  231.         ProgressZoom[0] = ProgressZoom[1] = 0;
  232.     if ( ProgressWdt )
  233.         ProgressZoom[2] = TextLength( &Scr->RastPort, (UBYTE *)ProgressWdt, strlen((char *)ProgressWdt )) + 80;
  234.     else
  235.         ProgressZoom[2]  = 80L;
  236.         ProgressZoom[3] = Scr->WBorTop + Scr->RastPort.TxHeight + 1;
  237.  
  238.     if ( ! ( ProgressWnd = OpenWindowTags( NULL,
  239.                 WA_Left,    wleft,
  240.                 WA_Top,        wtop,
  241.                 WA_Width,    ww + OffX + Scr->WBorRight,
  242.                 WA_Height,    wh + OffY + Scr->WBorBottom,
  243.                 WA_IDCMP,    BUTTONIDCMP|LISTVIEWIDCMP|IDCMP_RAWKEY|IDCMP_REFRESHWINDOW,
  244.                 WA_Flags,    WFLG_DRAGBAR|WFLG_DEPTHGADGET|WFLG_SMART_REFRESH,
  245.                 WA_Gadgets,    ProgressGList,
  246.                 WA_Title,    ProgressWdt,
  247.                 WA_ScreenTitle,    "TSMorph ©1993 Topicsave Limited",
  248.                 WA_PubScreen,    Scr,
  249.                 WA_Zoom,    ProgressZoom,
  250.                 TAG_DONE )))
  251.     return( 4L );
  252.  
  253.     GT_RefreshWindow( ProgressWnd, NULL );
  254.  
  255.     return( 0L );
  256. }
  257.  
  258. void CloseProgressWindow( void )
  259. {
  260.     if ( ProgressWnd        ) {
  261.         CloseWindow( ProgressWnd );
  262.         ProgressWnd = NULL;
  263.     }
  264.  
  265.     if ( ProgressGList      ) {
  266.         FreeGadgets( ProgressGList );
  267.         ProgressGList = NULL;
  268.     }
  269. }
  270.  
  271.