home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / gui / precog2_1.lha / Precognition2_1 / src / src.lha / Library / precognition3d.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-12-12  |  6.9 KB  |  248 lines

  1. #include "precognition3d.h"
  2. #include "precognition_utils.h"
  3. #ifndef __GNUC__
  4. #include <clib/exec_protos.h>
  5. #include <clib/intuition_protos.h>
  6. #include <clib/graphics_protos.h>
  7. #endif
  8. #ifdef __GNUC__
  9. #include <proto/exec.h>
  10. #include <proto/intuition.h>
  11. #include <proto/graphics.h>
  12. #endif
  13. #ifdef __SASC
  14. #include <proto/exec.h>
  15. #include <proto/intuition.h>
  16. #include <proto/graphics.h>
  17. #endif
  18.  
  19. #include "amigamem.h"
  20. /* Additions for prototypes -- EDB */
  21. #include "Intuition_utils.h"
  22. #include <stdlib.h> /* for memory functions -- EDB */
  23.  
  24. /* PENS to use for 3d drawing */
  25.                /* Foreground, Background, Highlight, Shadow */
  26.  
  27. /* 1 bitplane = 2 colors */
  28. pcg_3DPens Std_mono_pens = { 1, 0, 1, 1 }; /* good for both 1.3 and 2.x */
  29.  
  30. /* 2 bitplane and above >= 4 colors */
  31. pcg_3DPens Std_v20_pens = { 1, 0, 2, 1 };   /* correct */
  32. pcg_3DPens Std_v13_pens = { 1, 0, 1, 2 };   /* correct */
  33.  
  34.  
  35. pcg_3DPens StandardPens( void )
  36. {
  37.    return (is_Workbench_v2()) ? Std_v20_pens : Std_v13_pens;
  38. }
  39.  
  40. pcg_3DPens StandardScreenPens( struct Screen *whichscreen )
  41. {
  42.    /*
  43.     *    Purpose: to get proper pens for a given screen
  44.     *
  45.     * mostly to change 3D look to 2D style under monochrome screens
  46.     * Later we might want to have more standard pens for fancier gadgets
  47.     *
  48.     */
  49.  
  50.    struct Screen *testme = NULL;
  51.    int Depth = 0;
  52.  
  53.    if( whichscreen == NULL )
  54.    {
  55.     if( is_Workbench_v2() )
  56.       {
  57.        testme = LockPubScreen( NULL );
  58.       /* Lock default publicscreen here */
  59.       /* testme = default publicscreen */
  60.       }
  61.     else
  62.       {
  63.       /* Lock Workbench Screen here */
  64.       /* testme = Workbench screen */
  65.       testme = malloc( sizeof(struct Screen) );
  66.       GetScreenData(testme, sizeof(struct Screen), WBENCHSCREEN, NULL);
  67.       }
  68.    }
  69.    else /* We have a valid pointer */
  70.    {
  71.     testme = whichscreen;
  72.    }
  73.    /* Lock Screen */
  74.    /* Get Screen Depth here */
  75.    Depth = testme->RastPort.BitMap->Depth;
  76.  
  77.    /* Unlock screen or free resources */
  78.     if( is_Workbench_v2() )
  79.       {
  80.        UnlockPubScreen( NULL, testme );
  81.       }
  82.     else /* 1.3 Amiga OS */
  83.       {
  84.       /* UnLock Workbench Screen here */
  85.       free( testme );
  86.       }
  87.  
  88.    /* If Screen Depth = 1 (monochrome)  */  /* Use standard 2D pens */
  89.       if( Depth == 1 )
  90.         return Std_mono_pens;
  91.  
  92.       else   /* 4 color 3D style is OK */
  93.         return (is_Workbench_v2()) ? Std_v20_pens : Std_v13_pens;
  94.  
  95. }
  96.  
  97. void pcg_Init3DBox(  pcg_3DBox *Box,
  98.                      SHORT      LeftEdge,
  99.                      SHORT      TopEdge,
  100.                      USHORT     Width,
  101.                      USHORT     Height,
  102.                      UBYTE      TopLeftPen,
  103.                      UBYTE      BottomRightPen,
  104.                      Border    *NextBorder )
  105. {
  106.    SHORT Wm1, Wm2, Hm1, Hm2;
  107.  
  108.    Box->TopLeft.LeftEdge   = LeftEdge;
  109.    Box->TopLeft.TopEdge    = TopEdge;
  110.    Box->TopLeft.FrontPen   = TopLeftPen;
  111.    Box->TopLeft.DrawMode   = JAM1;
  112.    Box->TopLeft.NextBorder = &Box->BottomRight;
  113.  
  114.    Box->BottomRight.LeftEdge   = LeftEdge;
  115.    Box->BottomRight.TopEdge    = TopEdge;
  116.    Box->BottomRight.FrontPen   = BottomRightPen;
  117.    Box->BottomRight.DrawMode   = JAM1;
  118.    Box->BottomRight.NextBorder = NextBorder;
  119.  
  120.    Wm1 = Width-1;
  121.    Wm2 = Width-2;
  122.    Hm1 = Height-1;
  123.    Hm2 = Height-2;
  124.  
  125.    Box->Points[ 0] = Wm1;
  126.    Box->Points[ 1] = 0;
  127.    Box->Points[ 2] = 0;
  128.    Box->Points[ 3] = 0;
  129.    Box->Points[ 4] = 0;
  130.    Box->Points[ 5] = Hm1;
  131.    Box->Points[ 6] = 1;
  132.    Box->Points[ 7] = Hm2;
  133.    Box->Points[ 8] = 1;
  134.    Box->Points[ 9] = 1;
  135.  
  136.    Box->Points[10] = 1;
  137.    Box->Points[11] = Hm1;
  138.    Box->Points[12] = Wm1;
  139.    Box->Points[13] = Hm1;
  140.    Box->Points[14] = Wm1;
  141.    Box->Points[15] = 0;
  142.    Box->Points[16] = Wm2;
  143.    Box->Points[17] = 1;
  144.    Box->Points[18] = Wm2;
  145.    Box->Points[19] = Hm2;
  146.  
  147.    Box->TopLeft.Count     = 5;
  148.    Box->TopLeft.XY        = (SHORT *) &Box->Points[0];
  149.    Box->BottomRight.Count = 5;
  150.    Box->BottomRight.XY    = (SHORT *) &Box->Points[10];
  151. }
  152.  
  153. void pcg_Init3DBevel(   pcg_3DBevel *Bevel,
  154.                         SHORT        LeftEdge,
  155.                         SHORT        TopEdge,
  156.                         USHORT       Width,
  157.                         USHORT       Height,
  158.                         USHORT       BevelWidth,
  159.                         UBYTE        TopLeftPen,
  160.                         UBYTE        BottomRightPen,
  161.                         Border      *NextBorder )
  162. {
  163.    pcg_Init3DBox(  &Bevel->Outer,
  164.                     LeftEdge,    TopEdge,
  165.                     Width,       Height,
  166.                     TopLeftPen,  BottomRightPen,
  167.                    &Bevel->Inner.TopLeft );
  168.  
  169.    pcg_Init3DBox(  &Bevel->Inner,
  170.                     LeftEdge+2,           TopEdge+1,
  171.                     Width-4-BevelWidth,   Height-2-BevelWidth,
  172.                     BottomRightPen,       TopLeftPen,
  173.                     NextBorder );
  174. }
  175.  
  176. typedef struct pcg_DoubleBorder
  177. {
  178.    Border b1, b2;
  179. } pcg_DoubleBorder;
  180.  
  181. void pcg_Init3DThinBox( pcg_DoubleBorder *db,
  182.                         SHORT        LeftEdge,
  183.                         SHORT        TopEdge,
  184.                         USHORT       Width,
  185.                         USHORT       Height,
  186.                         SHORT       *Points,
  187.                         UBYTE        TopLeftPen,
  188.                         UBYTE        BottomRightPen,
  189.                         Border      *NextBorder )
  190. {
  191.    SHORT Wm1, Hm1;
  192.  
  193.    db->b1.LeftEdge   = db->b2.LeftEdge = LeftEdge;
  194.    db->b1.TopEdge    = db->b2.TopEdge  = TopEdge;
  195.    db->b1.DrawMode   = db->b2.DrawMode = JAM1;
  196.    db->b1.FrontPen   = TopLeftPen;
  197.    db->b2.FrontPen   = BottomRightPen;
  198.    db->b1.NextBorder = &db->b2;
  199.    db->b2.NextBorder = NextBorder;
  200.    db->b1.XY         = &Points[0];
  201.    db->b1.Count      = 3;
  202.    db->b2.XY         = &Points[4];
  203.    db->b2.Count      = 3;
  204.  
  205.    Wm1 = Width-1;
  206.    Hm1 = Height-1;
  207.  
  208.    Points[ 0] = Wm1;
  209.    Points[ 1] = 0;
  210.    Points[ 2] = 0;
  211.    Points[ 3] = 0;
  212.    Points[ 4] = 0;
  213.    Points[ 5] = Hm1;
  214.    Points[ 6] = Wm1;
  215.    Points[ 7] = Hm1;
  216.    Points[ 8] = Wm1;
  217.    Points[ 9] = 0;
  218.  
  219. }
  220.  
  221.  
  222. void pcg_Init3DThinBevel(  pcg_3DThinBevel *Bevel,
  223.                            SHORT        LeftEdge,
  224.                            SHORT        TopEdge,
  225.                            USHORT       Width,
  226.                            USHORT       Height,
  227.                            USHORT       BevelWidth,
  228.                            UBYTE        TopLeftPen,
  229.                            UBYTE        BottomRightPen,
  230.                            Border      *NextBorder )
  231. {
  232.    pcg_Init3DThinBox(  (pcg_DoubleBorder*) &Bevel->b[0],
  233.                        LeftEdge, TopEdge,
  234.                        Width, Height,
  235.                       &Bevel->Points[0],
  236.                        TopLeftPen,   BottomRightPen,
  237.                       &Bevel->b[2] );
  238.  
  239.    pcg_Init3DThinBox(  (pcg_DoubleBorder*) &Bevel->b[2],
  240.                        LeftEdge+1, TopEdge+1,
  241.                        Width-2-BevelWidth,    Height-2-BevelWidth,
  242.                       &Bevel->Points[10],
  243.                        BottomRightPen, TopLeftPen,
  244.                        NextBorder );
  245.  
  246. }
  247.  
  248.