home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / pufferfish / source / images.c < prev    next >
C/C++ Source or Header  |  1994-03-29  |  8KB  |  324 lines

  1. /*
  2.  * images.c
  3.  *
  4.  * Image routines
  5.  *
  6.  */
  7. #include <exec/types.h>
  8.  
  9. #include <intuition/intuition.h>
  10. #include <intuition/imageclass.h>
  11.  
  12. #include <clib/exec_protos.h>
  13. #include <clib/graphics_protos.h>
  14. #include <clib/intuition_protos.h>
  15.  
  16. #include "PufferFish.h"
  17.  
  18. struct IntuiText start_text =
  19. {
  20.     1, 0, JAM2, 0, 0, NULL, " Start ", NULL
  21. };
  22.  
  23. struct IntuiText end_text =
  24. {
  25.     1, 0, JAM2, 0, 0, NULL, " End ", NULL
  26. };
  27.  
  28. struct IntuiText drives_text =
  29. {
  30.     1, 0, JAM2, 0, 0, NULL, " Drives ", NULL
  31. };
  32.  
  33. struct IntuiText drivenames_text2[5] =
  34. {
  35.     1, 0, JAM2, 0, 0, NULL, "DF_", NULL,
  36.     1, 0, JAM2, 0, 0, NULL, "DF_", NULL,
  37.     1, 0, JAM2, 0, 0, NULL, "DF_", NULL,
  38.     1, 0, JAM2, 0, 0, NULL, "DF_", NULL,
  39.     1, 0, JAM2, 0, 0, NULL, "", NULL
  40. };
  41.  
  42. struct IntuiText drivenames_text[5] =
  43. {
  44.     1, 0, JAM2, 0, 0, NULL, "DF0: ", &drivenames_text2[0],
  45.     1, 0, JAM2, 0, 0, NULL, "DF1: ", &drivenames_text2[1],
  46.     1, 0, JAM2, 0, 0, NULL, "DF2: ", &drivenames_text2[2],
  47.     1, 0, JAM2, 0, 0, NULL, "DF3: ", &drivenames_text2[3],
  48.     1, 0, JAM2, 0, 0, NULL, "", &drivenames_text2[4]
  49. };
  50.  
  51. /*
  52.  * make_systemimages()
  53.  *
  54.  * Creates system-type images
  55.  *
  56.  * Returns TRUE on success, FALSE otherwise
  57.  *
  58.  */
  59. BOOL make_systemimages( void )
  60. {
  61.     BOOL ret = FALSE;
  62.     
  63.     if( upimage = (struct Image *)NewObject( NULL, "sysiclass",
  64.         SYSIA_DrawInfo,    drawinfo,
  65.         SYSIA_Which,    UPIMAGE,
  66.         TAG_END ))
  67.     {
  68.         if( downimage = (struct Image *)NewObject( NULL, "sysiclass",
  69.             SYSIA_DrawInfo,    drawinfo,
  70.             SYSIA_Which,    DOWNIMAGE,
  71.             TAG_END ))
  72.         {
  73.             if( checkimage = (struct Image *)NewObject( NULL, "sysiclass",
  74.                 SYSIA_DrawInfo, drawinfo,
  75.                 SYSIA_Which,    CHECKIMAGE,
  76.                 TAG_END ))
  77.             {
  78.                 ret = TRUE;
  79.             }
  80.         }
  81.     }
  82.     if( ret == FALSE )
  83.     {
  84.         free_systemimages();
  85.     }
  86.     return( ret );
  87. }
  88.  
  89. /*
  90.  * free_systemimages()
  91.  *
  92.  * Frees images created by make_systemimages()
  93.  *
  94.  */
  95. void free_systemimages( void )
  96. {
  97.     if( checkimage )
  98.     {
  99.         DisposeObject( checkimage );
  100.     }
  101.     if( downimage )
  102.     {
  103.         DisposeObject( downimage );
  104.     }
  105.     if( upimage )
  106.     {
  107.         DisposeObject( upimage );
  108.     }
  109. }
  110.  
  111. int frame_height;
  112.  
  113. /*
  114.  * make_images()
  115.  *
  116.  * Makes all non-system-type images
  117.  *
  118.  * Returns TRUE on success, FALSE otherwise
  119.  *
  120.  */
  121. BOOL make_images( void )
  122. {
  123.     BOOL ret = FALSE;
  124.     ULONG arrowwidth, arrowheight, checkwidth, checkheight;
  125.     int i;
  126.     
  127.     start_text.ITextFont = screen->Font;
  128.     end_text.ITextFont = screen->Font;
  129.     drives_text.ITextFont = screen->Font;
  130.     for( i = 0; i < 5; i += 1 )
  131.     {
  132.         drivenames_text[i].ITextFont = screen->Font;
  133.         drivenames_text2[i].ITextFont = screen->Font;
  134.     }
  135.     drivenames_text[4].IText = additional_device;
  136.     
  137.     GetAttr( IA_Width, upimage, &arrowwidth );
  138.     GetAttr( IA_Height, upimage, &arrowheight );
  139.     GetAttr( IA_Width, checkimage, &checkwidth );
  140.     GetAttr( IA_Height, checkimage, &checkheight );
  141.     if( frameimage = (struct Image *)NewObject( NULL, "frameiclass",
  142.         TAG_END ))
  143.     {
  144.         frame_height = (arrowheight + 2) + (drawinfo->dri_Font->tf_YSize + 2 + 4) + (arrowheight + 2) + (drawinfo->dri_Font->tf_YSize) + GF_TOPBORDER * 3 / 2;
  145.         if( frame = (struct Image *)NewObject( NULL, "frameiclass",
  146.             IA_Top, (win->BorderTop) + GF_TOPBORDER,
  147.             IA_Left, (win->BorderLeft) + GF_LEFTBORDER,
  148.             IA_Width, (arrowwidth * 11 / 2) + drawinfo->dri_Font->tf_XSize * 5 + 8,
  149.             IA_Height, frame_height,
  150.             IA_Recessed, TRUE,
  151.             TAG_END ))
  152.         {
  153.             if( start = (struct Image *)NewObject( NULL, "itexticlass",
  154.                 IA_FGPen, drawinfo->dri_Pens[TEXTPEN],
  155.                 IA_BGPen, drawinfo->dri_Pens[BACKGROUNDPEN],
  156.                 IA_Data, &start_text,
  157.                 TAG_END ))
  158.             {
  159.                 if( end = (struct Image *)NewObject( NULL, "itexticlass",
  160.                     IA_FGPen, drawinfo->dri_Pens[TEXTPEN],
  161.                     IA_BGPen, drawinfo->dri_Pens[BACKGROUNDPEN],
  162.                     IA_Data, &end_text,
  163.                     TAG_END ))
  164.                 {
  165.                     for( i = 0; i < 5; i += 1 )
  166.                     {
  167.                         drivename[i] = (struct Image *)NewObject( NULL, "itexticlass",
  168.                             IA_FGPen, drawinfo->dri_Pens[TEXTPEN],
  169.                             IA_BGPen, drawinfo->dri_Pens[BACKGROUNDPEN],
  170.                             IA_Data, &drivenames_text[i],
  171.                             TAG_END );
  172.                         if( !drivename[i] )
  173.                         {
  174.                             break;
  175.                         }
  176.                     }
  177.                     if( i == 5 )
  178.                     {
  179.                         if( checkheight < drawinfo->dri_Font->tf_YSize )
  180.                         {
  181.                             checkheight = drawinfo->dri_Font->tf_YSize;
  182.                         }
  183.                         if( drive_frame = (struct Image *)NewObject( NULL, "frameiclass",
  184.                             IA_Top, (win->BorderTop) + GF_TOPBORDER,
  185.                             IA_Left, (win->BorderLeft) + GF_LEFTBORDER + arrowwidth * 6 + drawinfo->dri_Font->tf_XSize * 5 + 8,
  186.                             IA_Height, 5 * (checkheight + 5) + GF_TOPBORDER,
  187.                             IA_Width, checkwidth + 4 + 2 * drawinfo->dri_Font->tf_XSize + IntuiTextLength( &drivenames_text[0] ),
  188.                             IA_Recessed, TRUE,
  189.                             TAG_END ))
  190.                         {
  191.                             if( drive = (struct Image *)NewObject( NULL, "itexticlass",
  192.                                 IA_FGPen, drawinfo->dri_Pens[TEXTPEN],
  193.                                 IA_BGPen, drawinfo->dri_Pens[BACKGROUNDPEN],
  194.                                 IA_Data, &drives_text,
  195.                                 TAG_END ))
  196.                             {
  197.                                 ret = TRUE;
  198.                             }
  199.                         }
  200.                     }
  201.                 }
  202.             }
  203.         }
  204.     }
  205.     if( ret == FALSE )
  206.     {
  207.         free_images();
  208.     }
  209.     return( ret );
  210. }
  211.  
  212. /*
  213.  * free_images()
  214.  *
  215.  * Frees all non-system-type images
  216.  *
  217.  */
  218. void free_images( void )
  219. {
  220.     int i;
  221.     
  222.     for( i = 0; i < 5; i += 1 )
  223.     {
  224.         if( drivename[i] )
  225.         {
  226.             DisposeObject( drivename[i] );
  227.         }
  228.     }
  229.     if( drive )
  230.     {
  231.         DisposeObject( drive );
  232.     }
  233.     if( drive_frame )
  234.     {
  235.         DisposeObject( drive_frame );
  236.     }
  237.     if( end )
  238.     {
  239.         DisposeObject( end );
  240.     }
  241.     if( start )
  242.     {
  243.         DisposeObject( start );
  244.     }
  245.     if( frame )
  246.     {
  247.         DisposeObject( frame );
  248.     }
  249.     if( frameimage )
  250.     {
  251.         DisposeObject( frameimage );
  252.     }
  253. }
  254.  
  255. /*
  256.  * draw_images()
  257.  *
  258.  * Draws all images into the window in their correct positions
  259.  *
  260.  */
  261. void draw_images( void )
  262. {
  263.     ULONG newtop, i, width, height;
  264.     
  265.     GetAttr( IA_Width, upimage, &width );
  266.     // Draw top digits frame
  267.     DrawImageState( win->RPort, frame, 0, 0, IDS_NORMAL, drawinfo );
  268.     // Draw bottom digits frame
  269.     DrawImageState( win->RPort, frame, 0, frame_height + GF_TOPBORDER, IDS_NORMAL, drawinfo );
  270.     // Draw drive frame
  271.     DrawImageState( win->RPort, drive_frame, 0, 0, IDS_NORMAL, drawinfo );
  272.     
  273.     // Clear space for titles
  274.     SetAPen( win->RPort, drawinfo->dri_Pens[BACKGROUNDPEN] );
  275.     // Clear top digits title
  276.     RectFill( win->RPort,
  277.         win->BorderLeft + GF_LEFTBORDER * 2,
  278.         win->BorderTop + (GF_TOPBORDER / 2) + 1,
  279.         win->BorderLeft + GF_LEFTBORDER * 2 + IntuiTextLength( &start_text ),
  280.         win->BorderTop + (GF_TOPBORDER / 2) + 1 + drawinfo->dri_Font->tf_YSize);
  281.     // Clear bottom digits title
  282.     RectFill( win->RPort,
  283.         win->BorderLeft + GF_LEFTBORDER * 2,
  284.         win->BorderTop + frame_height + (GF_TOPBORDER / 2) + 1 + drawinfo->dri_Font->tf_YSize,
  285.         win->BorderLeft + GF_LEFTBORDER * 2 + IntuiTextLength( &end_text ),
  286.         win->BorderTop + frame_height + (GF_TOPBORDER / 2) + 1 + 2 * drawinfo->dri_Font->tf_YSize);
  287.     // Clear drive list title
  288.     RectFill( win->RPort,
  289.         win->BorderLeft + GF_LEFTBORDER * 2 + width * 6 + drawinfo->dri_Font->tf_XSize * 5 + 8,
  290.         win->BorderTop + (GF_TOPBORDER / 2) + 1,
  291.         win->BorderLeft + GF_LEFTBORDER * 2 + width * 6 + drawinfo->dri_Font->tf_XSize * 5 + 8 + IntuiTextLength( &drives_text ),
  292.         win->BorderTop + (GF_TOPBORDER / 2) + 1 + drawinfo->dri_Font->tf_YSize);
  293.     // Draw top digits title
  294.     DrawImageState( win->RPort, start,
  295.         win->BorderLeft + GF_LEFTBORDER * 2,
  296.         win->BorderTop + (GF_TOPBORDER / 2) + 1,
  297.         IDS_NORMAL, drawinfo );
  298.     // Draw bottom digits title
  299.     DrawImageState( win->RPort, end,
  300.         win->BorderLeft + GF_LEFTBORDER * 2,
  301.         win->BorderTop + frame_height + (GF_TOPBORDER / 2) + 1 + drawinfo->dri_Font->tf_YSize,
  302.         IDS_NORMAL, drawinfo );
  303.     // Draw drive list title
  304.     DrawImageState( win->RPort, drive,
  305.         win->BorderLeft + GF_LEFTBORDER * 2 + width * 6 + drawinfo->dri_Font->tf_XSize * 5 + 8,
  306.         win->BorderTop + (GF_TOPBORDER / 2) + 1,
  307.         IDS_NORMAL, drawinfo );
  308.     
  309.     // Draw drive names
  310.     GetAttr( IA_Height, checkimage, &height );
  311.     if( height < drawinfo->dri_Font->tf_YSize )
  312.     {
  313.         height = drawinfo->dri_Font->tf_YSize;
  314.     }
  315.     for( i = 0; i < 5; i += 1 )
  316.     {
  317.         newtop = win->BorderTop + GF_TOPBORDER * 2 - 2 + i * (height + 5) + (height - drawinfo->dri_Font->tf_YSize) / 2;
  318.         DrawImageState( win->RPort, drivename[i],
  319.             win->BorderLeft + GF_LEFTBORDER * 2 + width * 6 + drawinfo->dri_Font->tf_XSize * 5 + 8,
  320.             newtop,
  321.             IDS_NORMAL, drawinfo );
  322.     }
  323. }
  324.