home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Exec 4 / CD_Magazyn_EXEC_nr_4.iso / Recent / dev / c / GSys.lha / gsys / ggraphics / GScreen.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-09-30  |  15.5 KB  |  754 lines

  1.  
  2. /* Author Anders Kjeldsen */
  3.  
  4. #ifndef GSCREEN_CPP
  5. #define GSCREEN_CPP
  6.  
  7. #include "ggraphics/GScreen.h"
  8. #include "gsystem/GObject.cpp"
  9. #include "ggraphics/GRequestDisplay.cpp"
  10.  
  11. #ifdef GAMIGA
  12.  
  13. #ifdef GAMIGA_PPC
  14. #ifndef CyberGfxBase
  15. struct Library *CyberGfxBase = NULL;
  16. #endif
  17. #endif
  18.  
  19. #ifndef IntuitionBase
  20. struct IntuitionBase *IntuitionBase = NULL;
  21. #endif
  22.  
  23. #ifndef AslBase
  24. struct Library *AslBase = NULL;
  25. #endif
  26.  
  27. #ifndef GfxBase
  28. struct GfxBase *GfxBase = NULL;
  29. #endif
  30.  
  31. //#ifndef DOSBase
  32. //struct DosLibrary *DOSBase = NULL;
  33. //#endif
  34.  
  35. #ifndef GadToolsBase
  36. struct Library *GadToolsBase = NULL;
  37. #endif
  38.  
  39.  
  40. ULONG GfxLibs = 0;
  41. BOOL InitGfx()
  42. {
  43. //    if ( GfxLibs == 0 )
  44. //    {
  45.         if (!CyberGfxBase) CyberGfxBase = (struct Library *)OpenLibrary((unsigned char *)"cybergraphics.library", NULL);
  46.         if (CyberGfxBase)
  47.         {
  48.             if (!IntuitionBase) IntuitionBase = (struct IntuitionBase *)OpenLibrary((unsigned char *)"intuition.library", NULL);
  49.             if (IntuitionBase)
  50.             {
  51.                 if (!AslBase) AslBase = OpenLibrary((unsigned char *)"asl.library", NULL);
  52.                 if (AslBase)
  53.                 {
  54.                     if (!GfxBase) GfxBase = (struct GfxBase *)OpenLibrary((unsigned char *)"graphics.library",NULL);
  55.                     if (GfxBase)
  56.                     {
  57.                         if (DOSBase)
  58.                         {
  59.                             if (!GadToolsBase) GadToolsBase = (struct Library *)OpenLibrary((unsigned char *)"gadtools.library",NULL);
  60.                             if (GadToolsBase)
  61.                             {
  62.                                 GfxLibs++;
  63.                                 return TRUE;
  64.                             }
  65.                         }
  66.                     }
  67.                 }
  68.             }
  69.         }
  70. //    }
  71.     return FALSE;
  72. }
  73.  
  74. BOOL DeInitGfx()
  75. {
  76. //    if ( GfxLibs == 1 )
  77. //    {
  78.         if (CyberGfxBase)
  79.         {
  80.             CloseLibrary(CyberGfxBase);
  81.             CyberGfxBase = NULL;
  82.         }
  83.         if (IntuitionBase)
  84.         {
  85.             CloseLibrary((struct Library *)IntuitionBase);
  86.             IntuitionBase = NULL;
  87.         }
  88.         if (AslBase)
  89.         {
  90.             CloseLibrary((struct Library *)AslBase);
  91.             AslBase = NULL;
  92.         }
  93.         if (GfxBase)
  94.         {
  95.             CloseLibrary((struct Library *)GfxBase);    
  96.             GfxBase = NULL;
  97.         }
  98.         if (DOSBase)
  99.         {
  100. //            FreeDosObject( DOS_FIB, (void *) FileInfoBlock);
  101.         }
  102.         if (GadToolsBase)
  103.         {
  104.             CloseLibrary(GadToolsBase);
  105.             GadToolsBase = NULL;
  106.         }
  107. //    }
  108. //    GfxLibs--;
  109.     return TRUE;
  110. }
  111.  
  112. GScreen::GScreen(class GRequestDisplay *GRequestDisplay)
  113. {
  114.     memset((void *)this, 0, sizeof (GScreen));
  115.  
  116.     Own24BitPixelArray = NULL;
  117. //    BackupGBitMap = NULL;
  118.     AmigaScreen = NULL;
  119.     AmigaWindow = NULL;
  120.     AmigaVisualInfo = NULL;    
  121.  
  122.     DDBytesPix = NULL;
  123.     DDBytesRow = NULL;
  124.     DDPxlFmt = NULL;
  125.     DDBuffer = NULL;
  126.  
  127.     InitGfx();
  128.  
  129.     if (GRequestDisplay)
  130.     {
  131.         if (GRequestDisplay->Status)
  132.         {
  133.             printf(" OK!\n");
  134.             if (GRequestDisplay->Depth >= 8)
  135.             {
  136.                 if (AmigaScreen = OpenScreenTags(
  137.                     NULL,
  138.                     SA_Left, 0,
  139.                     SA_Top, 0,
  140.                     SA_Width, GRequestDisplay->Width,
  141.                     SA_Height, GRequestDisplay->Height,
  142.                     SA_Depth, GRequestDisplay->Depth,
  143.                     SA_DetailPen, 1,
  144.                     SA_BlockPen, 2,
  145.                     SA_Title, NULL,
  146.                     SA_ShowTitle, FALSE,
  147.                     SA_Draggable, FALSE,
  148.                     SA_Quiet, TRUE,
  149.                     SA_DisplayID, GRequestDisplay->ScrModeRequester->sm_DisplayID,
  150.                     SA_Type, CUSTOMSCREEN,
  151.                     TAG_DONE))
  152.                 {
  153.                     ScrWidth = AmigaScreen->Width;
  154.                     ScrHeight = AmigaScreen->Height;
  155.                     ScrDepth = GRequestDisplay->Depth;
  156.  
  157.                     if (AmigaWindow = OpenWindowTags(NULL,
  158.                         WA_Left, 0,
  159.                         WA_Top, 0,
  160.                         WA_Width, ScrWidth,
  161.                         WA_Height, ScrHeight,
  162.                         WA_DetailPen, 1,
  163.                         WA_BlockPen, 2,
  164.                         WA_IDCMP, MENUPICK | MOUSEBUTTONS | REFRESHWINDOW | MOUSEMOVE | INTUITICKS,
  165.                         WA_Flags, WFLG_BACKDROP | WFLG_SMART_REFRESH | WFLG_ACTIVATE | WFLG_RMBTRAP | WFLG_BORDERLESS,
  166.                         WA_Gadgets, NULL,
  167.                         WA_Title, NULL,
  168.                         WA_MinWidth, ScrWidth,
  169.                         WA_MaxWidth, ScrWidth,
  170.                         WA_MinHeight, ScrHeight,
  171.                         WA_MaxHeight, ScrHeight,
  172.                         WA_Checkmark, NULL,
  173.                         WA_ScreenTitle, NULL,
  174.                         WA_SuperBitMap, NULL,
  175.                         WA_CustomScreen, (ULONG) AmigaScreen,
  176.                         TAG_DONE))
  177.                     {
  178.                         if ( AmigaVisualInfo = GetVisualInfo(AmigaScreen, TAG_DONE) )
  179.                         {
  180. //                            BackupGBitMap = new GBitMap(ScrWidth, ScrHeight, ScrDepth);
  181.                             
  182. //                            if (BackupGBitMap->Valid)
  183. //                            {
  184.                                 AmigaScreenBuffer[0] = AllocScreenBuffer(AmigaScreen, NULL, SB_SCREEN_BITMAP);
  185.                                 AmigaScreenBuffer[1] = AllocScreenBuffer(AmigaScreen, NULL, NULL); //SB_COPY_BITMAP
  186.  
  187.                                 DispPort=CreateMsgPort();
  188.                                 WritePort=CreateMsgPort();
  189.  
  190.                                 if ( (DispPort && WritePort) && (AmigaScreenBuffer[0] && AmigaScreenBuffer[1]) )
  191.                                 {
  192.                                     if (WaitWrite)
  193.                                     {
  194.                                         AmigaScreenBuffer[0]->sb_DBufInfo->dbi_SafeMessage.mn_ReplyPort=WritePort;
  195.                                         AmigaScreenBuffer[1]->sb_DBufInfo->dbi_SafeMessage.mn_ReplyPort=WritePort;
  196.                                     }
  197.                                     else
  198.                                     {
  199.                                         AmigaScreenBuffer[0]->sb_DBufInfo->dbi_SafeMessage.mn_ReplyPort=NULL;
  200.                                         AmigaScreenBuffer[1]->sb_DBufInfo->dbi_SafeMessage.mn_ReplyPort=NULL;
  201.                                     }
  202.  
  203.                                     SafeToWrite=TRUE;
  204.  
  205.                                     if (WaitWrite)
  206.                                     {
  207.                                         AmigaScreenBuffer[0]->sb_DBufInfo->dbi_DispMessage.mn_ReplyPort=DispPort;
  208.                                         AmigaScreenBuffer[1]->sb_DBufInfo->dbi_DispMessage.mn_ReplyPort=DispPort;
  209.                                     }
  210.                                     else
  211.                                     {
  212.                                         AmigaScreenBuffer[0]->sb_DBufInfo->dbi_DispMessage.mn_ReplyPort=NULL;
  213.                                         AmigaScreenBuffer[1]->sb_DBufInfo->dbi_DispMessage.mn_ReplyPort=NULL;
  214.                                     }
  215.  
  216.                                     SafeToSwap=1;
  217.                                     CurBuffer=1;
  218. //                                    Valid = TRUE;
  219.                                 }
  220.                                 else
  221.                                 {
  222.                                     printf("could not allocate dbuffer screenbuffers\n");
  223.                                 }
  224. //                            }
  225.                         }
  226.                     }                
  227.                 }
  228.             }
  229.         }
  230.     }
  231. }
  232.  
  233. GScreen::GScreen(ULONG Width, ULONG Height, UWORD Depth)
  234. {
  235.     memset((void *)this, 0, sizeof (GScreen));
  236.     
  237. /*
  238.     Own24BitPixelArray = NULL;
  239.     BackupGBitMap = NULL;
  240.     AmigaScreen = NULL;
  241.     AmigaWindow = NULL;
  242.     AmigaVisualInfo = NULL;    
  243.     DDBytesPix = NULL;
  244.     DDBytesRow = NULL;
  245.     DDPxlFmt = NULL;
  246.     DDBuffer = NULL;
  247. */
  248.     InitGfx();
  249.  
  250.     if (Depth >= 8)
  251.     {
  252.         if (Width)
  253.         {
  254.             if (Height)
  255.             {
  256.                 ULONG ModeID = BestCModeIDTags( CYBRBIDTG_Depth, Depth,
  257.                                 CYBRBIDTG_NominalWidth, Width,
  258.                                 CYBRBIDTG_NominalHeight, Height,
  259.                                 TAG_DONE );
  260.  
  261.                 if (AmigaScreen = OpenScreenTags(
  262.                     NULL,
  263.                     SA_Left, 0,
  264.                     SA_Top, 0,
  265.                     SA_Width, Width,
  266.                     SA_Height, Height,
  267.                     SA_Depth, Depth,
  268.                     SA_DetailPen, 1,
  269.                     SA_BlockPen, 2,
  270.                     SA_Title, NULL,
  271.                     SA_ShowTitle, FALSE,
  272.                     SA_Draggable, FALSE,
  273.                     SA_Quiet, TRUE,
  274.                     SA_DisplayID, ModeID,
  275.                     SA_Type, CUSTOMSCREEN,
  276.                     TAG_DONE))
  277.                 {
  278.                     ScrWidth = AmigaScreen->Width;
  279.                     ScrHeight = AmigaScreen->Height;
  280.                     ScrDepth = Depth;
  281.  
  282.                     if (AmigaWindow = OpenWindowTags(NULL,
  283.                         WA_Left, 0,
  284.                         WA_Top, 0,
  285.                         WA_Width, ScrWidth,
  286.                         WA_Height, ScrHeight,
  287.                         WA_DetailPen, 1,
  288.                         WA_BlockPen, 2,
  289.                         WA_IDCMP, MENUPICK | MOUSEBUTTONS | REFRESHWINDOW | MOUSEMOVE | INTUITICKS,
  290.                         WA_Flags, WFLG_BACKDROP | WFLG_SMART_REFRESH | WFLG_ACTIVATE | WFLG_RMBTRAP | WFLG_BORDERLESS,
  291.                         WA_Gadgets, NULL,
  292.                         WA_Title, NULL,
  293.                         WA_MinWidth, ScrWidth,
  294.                         WA_MaxWidth, ScrWidth,
  295.                         WA_MinHeight, ScrHeight,
  296.                         WA_MaxHeight, ScrHeight,
  297.                         WA_Checkmark, NULL,
  298.                         WA_ScreenTitle, NULL,
  299.                         WA_SuperBitMap, NULL,
  300.                         WA_CustomScreen, (ULONG) AmigaScreen,
  301.                         TAG_DONE))
  302.                     {
  303.                         if ( AmigaVisualInfo = GetVisualInfo(AmigaScreen, TAG_DONE) )
  304.                         {
  305. //                            BackupGBitMap = new GBitMap(ScrWidth, ScrHeight, ScrDepth);
  306.                             
  307. //                            if (BackupGBitMap->Valid)
  308. //                            {
  309.                                 if ( AmigaScreenBuffer[0] = AllocScreenBuffer(AmigaScreen, NULL, SB_SCREEN_BITMAP) )
  310.                                 {
  311.                                     if ( AmigaScreenBuffer[1] = AllocScreenBuffer(AmigaScreen, NULL, NULL) )
  312.                                     {
  313.  
  314.                                         DispPort=CreateMsgPort();
  315.                                         WritePort=CreateMsgPort();
  316.  
  317.                                         if ( (DispPort && WritePort) )
  318.                                         {
  319.                                             if (WaitWrite)
  320.                                             {
  321.                                                 AmigaScreenBuffer[0]->sb_DBufInfo->dbi_SafeMessage.mn_ReplyPort=WritePort;
  322.                                                 AmigaScreenBuffer[1]->sb_DBufInfo->dbi_SafeMessage.mn_ReplyPort=WritePort;
  323.                                             }
  324.                                             else
  325.                                             {
  326.                                                 AmigaScreenBuffer[0]->sb_DBufInfo->dbi_SafeMessage.mn_ReplyPort=NULL;
  327.                                                 AmigaScreenBuffer[1]->sb_DBufInfo->dbi_SafeMessage.mn_ReplyPort=NULL;
  328.                                             }
  329.  
  330.                                             SafeToWrite=TRUE;
  331.  
  332.                                             if (WaitWrite)
  333.                                             {
  334.                                                 AmigaScreenBuffer[0]->sb_DBufInfo->dbi_DispMessage.mn_ReplyPort=DispPort;
  335.                                                 AmigaScreenBuffer[1]->sb_DBufInfo->dbi_DispMessage.mn_ReplyPort=DispPort;
  336.                                             }
  337.                                             else
  338.                                             {
  339.                                                 AmigaScreenBuffer[0]->sb_DBufInfo->dbi_DispMessage.mn_ReplyPort=NULL;
  340.                                                 AmigaScreenBuffer[1]->sb_DBufInfo->dbi_DispMessage.mn_ReplyPort=NULL;
  341.                                             }
  342.                                             SafeToSwap=1;
  343.                                             CurBuffer=1;
  344. //                                            Valid = TRUE;
  345.                                         }
  346.                                         else
  347.                                         {
  348.                                             printf("could not allocate dbuffer screenbuffers\n");
  349.                                         }
  350.                                     }
  351.                                 }
  352. //                            }
  353.                         }
  354.                     }                
  355.                 }
  356.             }
  357.         }
  358.     }
  359. }
  360.  
  361. GScreen::~GScreen()
  362. {
  363.         if (AmigaScreen)
  364.         {
  365.             if (Own24BitPixelArray)
  366.             {
  367.                 free((APTR)Own24BitPixelArray);    
  368.             }
  369.  
  370.             if (AmigaScreenBuffer[0])
  371.             {
  372. //                if ( ChangeScreenBuffer(AmigaScreen, AmigaScreenBuffer[0]) )
  373. //                {
  374. //                    AmigaScreen->RastPort.BitMap = AmigaScreenBuffer[0]->sb_BitMap;
  375. //                }
  376.  
  377.                 FreeScreenBuffer(AmigaScreen, AmigaScreenBuffer[0]);
  378.             }
  379.             if (AmigaScreenBuffer[1])
  380.             {
  381.                 FreeScreenBuffer(AmigaScreen, AmigaScreenBuffer[1]);
  382.             }
  383.  
  384.             if (AmigaWindow)
  385.             {
  386.                 CloseWindow(AmigaWindow);
  387.                 AmigaWindow = NULL;
  388.             }
  389.             if (AmigaVisualInfo)
  390.             {
  391.                 FreeVisualInfo(AmigaVisualInfo);
  392.                 AmigaVisualInfo = NULL;
  393.             }
  394.  
  395.             CloseScreen(AmigaScreen);
  396.             AmigaScreen = NULL;
  397.  
  398. //            if (BackupGBitMap)
  399. //            {
  400. //                printf("delete BackupGBitMap\n");
  401. //                delete BackupGBitMap;
  402. //                printf("BackupGBitMapOK\n");
  403. //            }
  404.         }
  405.     DeInitGfx();
  406. }
  407.  
  408. #endif
  409.  
  410. ULONG GScreen::GetWidth()
  411.     if ( IsErrorFree() )
  412.     {
  413. #ifdef GAMIGA
  414.         return (ULONG) AmigaScreen->Width;
  415. #endif
  416.     }
  417.     else return NULL;
  418. }
  419.  
  420. ULONG GScreen::GetHeight()
  421. {
  422.     if ( IsErrorFree() )
  423.     {
  424. #ifdef GAMIGA
  425.         return (ULONG) AmigaScreen->Height;
  426. #endif
  427.     }
  428.     else return NULL;
  429. }
  430.  
  431. UWORD GScreen::GetDepth()
  432. {
  433.     if ( IsErrorFree() )
  434.     {
  435. #ifdef GAMIGA
  436.         return AmigaScreen->RastPort.BitMap->Depth;
  437. #endif
  438.     }
  439.     else return NULL;
  440. }
  441.  
  442.  
  443. void GScreen::WaitSafeToWrite()
  444. {
  445. #ifdef GAMIGA
  446.     if (WaitWrite)
  447.     {
  448.         if (!SafeToWrite)
  449.         {
  450.             while ( !GetMsg(WritePort) )
  451.             Wait(1L<<(WritePort->mp_SigBit));
  452.                 SafeToWrite=1;
  453.               }
  454.     }
  455. #endif
  456. }
  457.  
  458.  
  459. void GScreen::SwapScreenBuffers()
  460. {
  461. #ifdef GAMIGA
  462.  
  463.     SafeToSwap=1;
  464.  
  465.     if ( ChangeScreenBuffer(AmigaScreen, AmigaScreenBuffer[CurBuffer]) )
  466.     {
  467.         SafeToSwap=0;
  468.         SafeToWrite=0;
  469.         CurBuffer ^= 1;  /* toggle buffer */
  470. //        AmigaScreen->RastPort.BitMap = AmigaScreenBuffer[CurBuffer]->sb_BitMap;
  471.     }
  472. #endif
  473.  
  474. }
  475.  
  476. APTR GScreen::LockScreen()
  477. {
  478. #ifdef GAMIGA
  479.     ULONG DDWidth = NULL;
  480.     ULONG DDHeight = NULL;
  481.  
  482.     struct TagItem LBMTags[] =
  483.     {
  484.         LBMI_WIDTH, (ULONG)&DDWidth,
  485.         LBMI_HEIGHT, (ULONG)&DDHeight,
  486.         LBMI_PIXFMT, (ULONG)&DDPxlFmt,
  487.         LBMI_BYTESPERPIX, (ULONG)&DDBytesPix,
  488.         LBMI_BYTESPERROW, (ULONG)&DDBytesRow,
  489.         LBMI_BASEADDRESS, (ULONG)&DDBuffer,
  490.         TAG_DONE,
  491.     };
  492.  
  493.     if (CyberGfxBase)
  494.     {
  495.         if ( GetCyberMapAttr(AmigaScreenBuffer[CurBuffer]->sb_BitMap, CYBRMATTR_ISCYBERGFX ) )
  496.         {
  497.             Handle = LockBitMapTagList((APTR) AmigaScreenBuffer[CurBuffer]->sb_BitMap, LBMTags);
  498.             if (Handle) return DDBuffer;
  499.         }
  500.     }
  501.     return NULL;
  502. #endif
  503. }
  504.  
  505. void GScreen::UnLockScreen()
  506. {
  507. #ifdef GAMIGA
  508.     if (Handle)
  509.     {
  510.         UnLockBitMap(Handle);
  511.         Handle = NULL;
  512.         DDBuffer = NULL;
  513.     }
  514. #endif
  515. }
  516.  
  517. BOOL GScreen::AttachOwnPixelArray()
  518. {
  519.     if ( IsErrorFree() )
  520.     {
  521.         Own24BitPixelArray = new ULONG[GetWidth() * GetHeight()];
  522.         if (Own24BitPixelArray) return TRUE;
  523.     }
  524.     return FALSE;
  525. }
  526.  
  527. void GScreen::LoadPixelArray()
  528. {
  529.     if ( IsErrorFree() )
  530.     {
  531. //        WaitSafeToWrite();    // should not be here
  532.         if ( Own24BitPixelArray )
  533.         {
  534. #ifdef GAMIGA
  535.         WritePixelArray(Own24BitPixelArray, (UWORD) 0, (UWORD) 0, (UWORD) ScrWidth*4, (struct RastPort *)&AmigaScreen->RastPort, (UWORD) 0, (UWORD) 0, (UWORD) ScrWidth, (UWORD) ScrHeight, (UBYTE) RECTFMT_ARGB);
  536. #endif
  537. //        SwapScreenBuffers();    // should not be here
  538.         }
  539.     }
  540. }
  541.  
  542. void GScreen::LoadPixelArrayDirect()
  543. {
  544.     WaitSafeToWrite();
  545.  
  546.     APTR DrwBuf;
  547.     if ( DrwBuf = LockScreen() )
  548.     {
  549.         ULONG *SrcBuf = Own24BitPixelArray;
  550.  
  551.         if (DDBytesPix == 4)
  552.         {
  553.             ULONG *Pix32 = (ULONG *)DDBuffer;
  554.             int x,y;
  555.             for (y=0; y<ScrHeight; y++)
  556.             {
  557.                 for (x=0; x<ScrWidth; x++)
  558.                 {
  559.                     Pix32[0] = SrcBuf[0];
  560.                     Pix32++;
  561.                     SrcBuf++;
  562.                 }    
  563.             }
  564.         }
  565.     }
  566.  
  567.     UnLockScreen();
  568.     SwapScreenBuffers();    
  569. }
  570.  
  571. ULONG *GScreen::GetOwnPixelArray()
  572. {
  573.     if ( IsErrorFree() )
  574.     {
  575.         return Own24BitPixelArray;
  576.     }
  577.     else return NULL;
  578. }
  579.  
  580.  
  581. /*
  582. *  SetTrueColorPalette()
  583. *  Sets the palette to a 323 TrueColor palette, which is a bad-quality truecolor table
  584. */
  585.  
  586. void GScreen::SetTrueColorPalette()
  587. {
  588.     ULONG color;
  589.     for (color=0; color<256; color++)
  590.     {
  591. #ifdef GAMIGA
  592.         ULONG r, g, b;
  593.         r = (color>>5)<<29;
  594.         g = (color>>3)<<30;
  595.         b = color<<29;
  596.         SetRGB32(&AmigaScreen->ViewPort, color, r, g, b);
  597. #endif
  598.     }
  599. }
  600.  
  601. //LoadRGB4(&ActionScr->ViewPort, (UWORD *)&SetPal_Action, 256);
  602.  
  603.  
  604.  
  605.  
  606. /*
  607. BOOL GScreen::InsertGImage(class GImage *GImage)
  608. {
  609.     if (GImage)
  610.     {
  611.         if (FirstGImageToDraw)
  612.         {
  613.             class GImage *CurrentGImage = FirstGImageToDraw->NextGImageZ;
  614.             class GImage *PreviousGImage = FirstGImageToDraw;
  615.             while (CurrentGImage->ZPosition < GImage)
  616.             {
  617.                 PreviousGImage = CurrentGImage;
  618.                 CurrentGImage = CurrentGImage->NextGImageZ;
  619.             }
  620.             GImage->NextGImageZ = CurrentGImage;
  621.             PreviousGImage->NextGImageZ = GImage;
  622.             return TRUE;
  623.         }
  624.         else
  625.         {
  626.             FirstGImageToDraw = GImage;
  627.             GImage->NextGImageZ = NULL;
  628.             return TRUE;
  629.         }
  630.     }
  631. }
  632. */
  633.  
  634. void GScreen::PutPixel(ULONG X, ULONG Y, ULONG RGB)
  635. {
  636. #ifdef GAMIGA
  637.     if (AmigaScreen)
  638.     {
  639.     //    SetAPen(&AmigaScreen->RastPort, (UBYTE) RGB);
  640.     //    WritePixel(&AmigaScreen->RastPort, X, Y);
  641.     //    printf("WriteRGBPixel(&AmigaScreen->RastPort, X, Y, RGB)\n");
  642.         if (Handle && DDBuffer)
  643.         {
  644.             if (DDBytesPix == 4)
  645.             {
  646.                 ULONG *Pixels = (ULONG *)DDBuffer;
  647.                 Pixels[ X + (Y * ScrWidth) ] = RGB;
  648.             }
  649.             else if (DDBytesPix == 2)
  650.             {
  651.                 UWORD *Pixels = (UWORD *)DDBuffer;
  652.                 Pixels[ X + (Y * ScrWidth) ] = G24to16(RGB);
  653.             }
  654.             else if (DDBytesPix == 1)
  655.             {
  656.                 UBYTE *Pixels = (UBYTE *)DDBuffer;
  657.                 Pixels[ X + (Y * ScrWidth) ] = G24to8(RGB);
  658.             }
  659.         }
  660.         else if (CyberGfxBase) WriteRGBPixel(&AmigaScreen->RastPort, X, Y, RGB);
  661.  
  662.     }
  663. #endif
  664. }
  665.  
  666. /*
  667. void GScreen::DrawLine(class GVertex *P1, class GVertex *P2, UBYTE Pen)
  668. {
  669.  
  670. #ifdef GAMIGA
  671.     SetAPen(&AmigaScreen->RastPort, Pen);
  672.     Move(&AmigaScreen->RastPort, (WORD) P1->Z + ScrWidth/2, (WORD) P1->Y + ScrHeight/2);
  673.     Draw(&AmigaScreen->RastPort, (WORD) P2->Z + ScrWidth/2, (WORD) P2->Y + ScrHeight/2);
  674. #endif
  675. }
  676.  
  677. */
  678.  
  679. void GScreen::DrawLine(int x1, int y1, int x2, int y2, UBYTE Pen)
  680. {
  681.     SetAPen(&AmigaScreen->RastPort, Pen);
  682.     Move(&AmigaScreen->RastPort, x1, y1);
  683.     Draw(&AmigaScreen->RastPort, x2, y2);
  684. }
  685.  
  686.  
  687.  
  688.  
  689. #define    SMSG_LMU    0x00011000    /* Screen Message: Left Mouse Button released */
  690. #define    SMSG_LMD    0x00012000    /* Screen Message: Left Mouse Button pressed */
  691. #define    SMSG_RMU    0x00021000    /* Screen Message: Right Mouse Button released */
  692. #define    SMSG_RMD    0x00022000    /* Screen Message: Right Mouse Button pressed */
  693.  
  694. ULONG GScreen::CheckScreenMsgs()
  695. {
  696.     ULONG RETURN = NULL;
  697.     if ((AmigaWinMsg = (struct IntuiMessage *) (GT_GetIMsg(AmigaWindow->UserPort))))
  698.     {
  699.     ULONG imsgCode = AmigaWinMsg->Code;
  700.     ULONG imsgClass = AmigaWinMsg->Class;
  701.  
  702.     switch(imsgClass)
  703.         {
  704.             case IDCMP_MOUSEBUTTONS:
  705.  
  706.             switch (imsgCode)
  707.             {
  708.                 case SELECTDOWN:
  709.                     RETURN = SMSG_LMD;
  710.                 break;
  711.  
  712.                 case SELECTUP:
  713.                     RETURN = SMSG_LMU;
  714.                 break;
  715.  
  716.                 case MENUDOWN:
  717.                     RETURN = SMSG_RMD;
  718.                 break;
  719.  
  720.                 case MENUUP:
  721.                     RETURN = SMSG_RMU;
  722.                 break;
  723.             }
  724.             break;
  725.  
  726.         }
  727.         GT_ReplyIMsg(AmigaWinMsg);
  728.     }
  729.     return RETURN;
  730. }
  731.  
  732. /* GetMouseX() & GetMouseY() returns the mousepointer-coordinates on the screen */
  733.  
  734. WORD GScreen::GetMouseX()
  735. {
  736. #ifdef GAMIGA
  737.     return AmigaScreen->MouseX;
  738. #endif
  739.  
  740. }
  741.  
  742. WORD GScreen::GetMouseY()
  743. {
  744. #ifdef GAMIGA
  745.     return AmigaScreen->MouseY;
  746. #endif
  747.  
  748. }
  749.  
  750.  
  751.  
  752.  
  753. #endif /* ifndef GSCREENMET */