home *** CD-ROM | disk | FTP | other *** search
/ Dream 57 / Amiga_Dream_57.iso / Amiga / Programmation / c / Extensions / APPSource.lha / APlusPlus / libsource / DrawArea.cxx < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-29  |  6.3 KB  |  272 lines

  1. /******************************************************************************
  2.  **
  3.  **   C++ Class Library for the Amiga⌐ system software.
  4.  **
  5.  **   Copyright (C) 1994 by Armin Vogt  **  EMail: armin@uni-paderborn.de
  6.  **   All Rights Reserved.
  7.  **
  8.  **   $Source: apphome:RCS/libsource/DrawArea.cxx,v $
  9.  **   $Revision: 1.12 $
  10.  **   $Date: 1994/07/31 13:16:16 $
  11.  **   $Author: Armin_Vogt $
  12.  **
  13.  ******************************************************************************/
  14.  
  15.  
  16. extern "C" {
  17. #ifdef __GNUG__
  18. #include <inline/graphics.h>
  19. #include <inline/layers.h>
  20. #include <inline/gadtools.h>
  21. #endif
  22.  
  23. #ifdef __SASC
  24. #include <proto/graphics.h>
  25. #include <proto/layers.h>
  26. #include <proto/gadtools.h>
  27. #endif
  28. #include <string.h>
  29. #include <libraries/gadtools.h>
  30. }
  31.  
  32. #include <APlusPlus/graphics/DrawArea.h>
  33. #include <APlusPlus/intuition/GWindow.h>
  34. #include <APlusPlus/intuition/ScreenC.h>
  35. #include <APlusPlus/graphics/FontC.h>
  36.  
  37.  
  38. static const char rcs_id[] = "$Id: DrawArea.cxx,v 1.12 1994/07/31 13:16:16 Armin_Vogt Exp Armin_Vogt $";
  39.  
  40.  
  41. DrawArea::DrawArea(GWindow* homeWindow)
  42. {
  43.    ownClippingInstalled = FALSE;
  44.    oldRegion = NULL;
  45.    regionPtr = NewRegion();
  46.    setGWindow(homeWindow); // initialise rastPort
  47. }
  48.  
  49. void DrawArea::setGWindow(GWindow* homeWindow)
  50. {
  51.    gWindowPtr = homeWindow;
  52.    if (homeWindow)   rastPort = gwindow()->windowPtr()->RPort;
  53.    else rastPort = NULL;
  54. }
  55.  
  56. DrawArea::~DrawArea()
  57. {
  58.    if (isValid())
  59.    {
  60.       DisposeRegion(regionPtr);
  61.       regionPtr = NULL;
  62.    }
  63. }
  64.  
  65.  
  66. /********************* RastPort draw routines *******************************************/
  67.  
  68.  
  69. void DrawArea::setAPen(UBYTE pen)
  70. {
  71.    SetAPen(rp(),pen);
  72. }
  73. void DrawArea::setBPen(UBYTE pen)
  74. {
  75.    SetBPen(rp(),pen);
  76. }
  77. void DrawArea::setDrMd(UBYTE mode)
  78. {
  79.    SetDrMd(rp(),mode);
  80. }
  81.  
  82. void DrawArea::polyDraw(LONG count,WORD* polyTable)
  83. {
  84.    WORD* pt      = polyTable;
  85.    WORD* const p = new WORD[count*2];
  86.    WORD* pp      = p;
  87.  
  88.    for (LONG i=count; i>0; i--) { *pp++=(WORD)abs_X(*pt++); *pp++= (WORD)abs_Y(*pt++); }
  89.    Move(rp(),*p,*(p+1));
  90.    PolyDraw(rp(),count,p);
  91.    delete [] p;
  92. }
  93.  
  94. void DrawArea::rectFill(XYVAL xmin,XYVAL ymin,XYVAL xmax,XYVAL ymax)
  95. {
  96.    xmax = abs_X(xmax);
  97.    ymax = abs_Y(ymax);
  98.  
  99.    if (xmin<xmax && ymin<ymax)   // negative width/height causes GURU MEDITATION!
  100.       RectFill(rp(),abs_X(xmin),abs_Y(ymin),xmax,ymax);
  101. }
  102.  
  103. void DrawArea::scrollRaster(LONG dx,LONG dy,XYVAL xmin,XYVAL ymin,XYVAL xmax,XYVAL ymax)
  104. {
  105.    xmax = abs_X(xmax);
  106.    ymax = abs_Y(ymax);
  107.  
  108.    if (xmin<xmax && ymin<ymax)
  109.       ScrollRaster(rp(),dx,dy,abs_X(xmin),abs_Y(ymin),xmax,ymax);
  110. }
  111.  
  112. void DrawArea::move(XYVAL x,XYVAL y)
  113. {
  114.    Move(rp(),abs_X(x),abs_Y(y));
  115. }
  116. void DrawArea::moveTx(XYVAL x,XYVAL y)
  117. {
  118.    Move(rp(),abs_X(x),abs_Y(y)+rp()->Font->tf_Baseline);
  119. }
  120.  
  121. void DrawArea::draw(XYVAL x,XYVAL y)
  122. {
  123.    Draw(rp(),abs_X(x),abs_Y(y));
  124. }
  125.  
  126. void DrawArea::drawBevelBox(XYVAL xmin,XYVAL ymin,WHVAL width,WHVAL height,BOOL recessed)
  127. {
  128.    /* The taglist usage of DrawBevelBox is a bit weird since the GTBB_Recessed tag only
  129.       needs to be present (regardless of the data value) to get a recessed box,
  130.       while the box is drawn raised just when the GTBB_Recessed tag is totally missing!
  131.    */
  132.    struct TagItem tags[] = {  GT_VisualInfo,(LONG)gwindow()->screenC()->getVisualInfo(),
  133.                               GTBB_Recessed,TRUE,
  134.                               TAG_END};
  135.    if (recessed==FALSE) tags[1].ti_Tag = TAG_END;
  136.  
  137.    DrawBevelBoxA(rp(),abs_X(xmin),abs_Y(ymin),width,height,&tags[0]);
  138. }
  139.  
  140. void DrawArea::drawEllipse(XYVAL x,XYVAL y,WHVAL hr,WHVAL vr)
  141. {
  142.    DrawEllipse(rp(),abs_X(x),abs_Y(y),hr,vr);
  143. }
  144.  
  145. void DrawArea::setFont(FontC& font)
  146. {
  147.    SetFont(rp(),(struct TextFont*)font);
  148. }
  149.  
  150. void DrawArea::text(UBYTE* textString,UWORD textLength)
  151. {
  152.    if (textLength==0) textLength = (UWORD)strlen((const char*)textString);
  153.    Text(rp(),(STRPTR)textString,textLength);
  154. }
  155.  
  156.  
  157. /*********************** Clipping region routines ***************************************/
  158.  
  159.  
  160. void DrawArea::adjustStdClip()
  161.    /* set the clipping rectangle to the dimensions present in the RectObject.
  162.    */
  163. {
  164.    if (isValid())
  165.    {
  166.       if (ownClippingInstalled)    // clip already installed
  167.          InstallClipRegion(layer(),NULL);
  168.  
  169.       clearRegion();    // free the memory of the rectangles incorporated in the ClipRegion's region.
  170.       orRectRegion(0,0,iWidth()-1,iHeight()-1);   // permit drawing within the RectObject.
  171.  
  172.       if (ownClippingInstalled)    // clip already installed
  173.          InstallClipRegion(layer(),region());
  174.    }
  175. }
  176.  
  177. void DrawArea::resetStdClip()
  178. {
  179.    if (isValid())
  180.       InstallClipRegion(layer(),oldRegion);
  181.    oldRegion = NULL; ownClippingInstalled = FALSE;
  182. }
  183.  
  184. void DrawArea::setStdClip()
  185. {
  186.    if (isValid())
  187.       if (ownClippingInstalled==FALSE)
  188.          oldRegion = InstallClipRegion(layer(),region());
  189. }
  190.  
  191. void DrawArea::setRectangle(XYVAL minX,XYVAL minY,XYVAL maxX,XYVAL maxY,struct Rectangle& rect)
  192.    /* transform RectObject relative dimensions into RastPort absolute coords
  193.       and store them into the referenced Rectangle structure.
  194.    */
  195. {
  196.    rect.MinX = (WORD)abs_X(minX);
  197.    rect.MinY = (WORD)abs_Y(minY);
  198.    rect.MaxX = (WORD)abs_X(maxX);
  199.    rect.MaxY = (WORD)abs_Y(maxY);
  200. }
  201.  
  202. void DrawArea::removeClip()
  203. {
  204.    if (ownClippingInstalled)
  205.    {
  206.       InstallClipRegion(layer(),NULL);
  207.    }
  208. }
  209.  
  210. void DrawArea::insertClip()
  211. {
  212.    if (ownClippingInstalled)
  213.    {
  214.       InstallClipRegion(layer(),region());
  215.    }
  216. }
  217.  
  218. void DrawArea::andRectRegion(XYVAL minX,XYVAL minY,XYVAL maxX,XYVAL maxY)
  219. {
  220.    if (isValid())
  221.    {
  222.    struct Rectangle rect;
  223.    setRectangle(minX,minY,maxX,maxY,rect);
  224.    removeClip();
  225.    AndRectRegion(region(),&rect);
  226.    insertClip();
  227.    }
  228. }
  229. void DrawArea::orRectRegion(XYVAL minX,XYVAL minY,XYVAL maxX,XYVAL maxY)
  230. {
  231.    if (isValid())
  232.    {
  233.    struct Rectangle rect;
  234.    setRectangle(minX,minY,maxX,maxY,rect);
  235.    removeClip();
  236.    OrRectRegion(region(),&rect);
  237.    insertClip();
  238.    }
  239. }
  240. void DrawArea::xorRectRegion(XYVAL minX,XYVAL minY,XYVAL maxX,XYVAL maxY)
  241. {
  242.    if (isValid())
  243.    {
  244.    struct Rectangle rect;
  245.    setRectangle(minX,minY,maxX,maxY,rect);
  246.    removeClip();
  247.    XorRectRegion(region(),&rect);
  248.    insertClip();
  249.    }
  250. }
  251. void DrawArea::clearRectRegion(XYVAL minX,XYVAL minY,XYVAL maxX,XYVAL maxY)
  252. {
  253.    if (isValid())
  254.    {
  255.    struct Rectangle rect;
  256.    setRectangle(minX,minY,maxX,maxY,rect);
  257.    removeClip();
  258.    ClearRectRegion(region(),&rect);
  259.    insertClip();
  260.    }
  261. }
  262.  
  263. void DrawArea::clearRegion()
  264. {
  265.    if (isValid())
  266.    {
  267.    removeClip();
  268.    ClearRegion(region());
  269.    insertClip();
  270.    }
  271. }
  272.