home *** CD-ROM | disk | FTP | other *** search
/ Dream 57 / Amiga_Dream_57.iso / Amiga / Programmation / c / Extensions / APPSource.lha / APlusPlus / libsource / GBorder.cxx < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-29  |  5.5 KB  |  179 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/GBorder.cxx,v $
  9.  **   $Revision: 1.13 $
  10.  **   $Date: 1994/07/31 13:18:20 $
  11.  **   $Author: Armin_Vogt $
  12.  **
  13.  ******************************************************************************/
  14.  
  15.  
  16. extern "C" {
  17. #ifdef __GNUG__
  18. #include <inline/graphics.h>
  19. #endif
  20.  
  21. #ifdef __SASC
  22. #include <proto/graphics.h>
  23. #endif
  24. #include <string.h>
  25. }
  26.  
  27. #include <APlusPlus/graphics/GBorder.h>
  28. #include <APlusPlus/graphics/GraphicObject.h>
  29. #include <APlusPlus/intuition/GWindow.h>
  30.  
  31.  
  32. static const char rcs_id[] = "$Id: GBorder.cxx,v 1.13 1994/07/31 13:18:20 Armin_Vogt Exp Armin_Vogt $";
  33.  
  34.  
  35. GBorder::~GBorder()
  36. {
  37. }
  38.  
  39. void GBorder::drawBorder(GraphicObject *graphicObj,GWindow *homeWindow)
  40. {
  41.    ULONG bgCol;
  42.    if (graphicObj->getAttribute(GOB_BackgroundColor,bgCol))
  43.    {
  44.       homeWindow->setAPen(bgCol);
  45.       homeWindow->setOPen(bgCol);
  46.       homeWindow->setDrMd(JAM1);
  47.       homeWindow->rectFill(NORM_X(graphicObj->left()), NORM_Y(graphicObj->top()),
  48.                            NORM_X(graphicObj->right()), NORM_Y(graphicObj->bottom()));
  49.  
  50.    }
  51. }
  52.  
  53. BevelBox::BevelBox()
  54. {
  55. }
  56.  
  57. void BevelBox::makeBorder(GraphicObject *graphicObj)
  58. {
  59.    graphicObj->setBorders(2,1,2,1);
  60. }
  61.  
  62. void BevelBox::drawBorder(GraphicObject *graphicObj,GWindow *homeWindow)
  63. {
  64.    GBorder::drawBorder(graphicObj,homeWindow);
  65.    ULONG recessed=0;
  66.    graphicObj->getAttribute(GOB_BevelRecessed,(ULONG&)recessed);
  67.  
  68.    homeWindow->setStdClip();
  69.    homeWindow->drawBevelBox(NORM_X(graphicObj->left()),
  70.                             NORM_Y(graphicObj->top()),
  71.                             graphicObj->width(),graphicObj->height(),recessed);
  72.    homeWindow->resetStdClip();
  73. }
  74.  
  75.  
  76. void LineBorder::makeBorder(GraphicObject *graphicObj)
  77. {
  78.    graphicObj->setBorders(1,1,1,1);
  79. }
  80.  
  81. void LineBorder::drawBorder(GraphicObject *graphicObj,GWindow *homeWindow)
  82. {
  83.    GBorder::drawBorder(graphicObj,homeWindow);
  84.  
  85.    WORD polyTable[5][2];
  86.       polyTable[0][0] = (WORD)NORM_X(graphicObj->left());
  87.       polyTable[0][1] = (WORD)NORM_Y(graphicObj->top());
  88.       polyTable[1][0] = (WORD)NORM_X(graphicObj->right());
  89.       polyTable[1][1] = (WORD)NORM_Y(graphicObj->top());
  90.       polyTable[2][0] = (WORD)NORM_X(graphicObj->right());
  91.       polyTable[2][1] = (WORD)NORM_Y(graphicObj->bottom());
  92.       polyTable[3][0] = (WORD)NORM_X(graphicObj->left());
  93.       polyTable[3][1] = (WORD)NORM_Y(graphicObj->bottom());
  94.       polyTable[4][0] = (WORD)NORM_X(graphicObj->left());
  95.       polyTable[4][1] = (WORD)NORM_Y(graphicObj->top());
  96.    homeWindow->setStdClip();
  97.    homeWindow->setAPen(1);
  98.    homeWindow->move(polyTable[0][0],polyTable[0][1]);
  99.    homeWindow->polyDraw(5,&polyTable[0][0]);
  100.    homeWindow->resetStdClip();
  101. }
  102.  
  103.  
  104. NeXTBorder::NeXTBorder(UBYTE *titleFontName,UBYTE titleFontSize)
  105.    : titleFont(titleFontName,titleFontSize)
  106. {
  107. }
  108.  
  109. void NeXTBorder::makeBorder(GraphicObject *graphicObj)
  110. {
  111.    UBYTE fontHeight = titleFont.ySize();
  112.    graphicObj->setBorders(fontHeight,fontHeight,fontHeight,fontHeight);
  113. }
  114.  
  115. void NeXTBorder::drawBorder(GraphicObject *graphicObj,GWindow *homeWindow)
  116. {
  117.    GBorder::drawBorder(graphicObj,homeWindow);
  118.  
  119.    WORD bWidth = titleFont.ySize(),bHeight = titleFont.ySize();
  120.    #define X 0
  121.    #define Y 1
  122.  
  123.    homeWindow->setStdClip();
  124.    homeWindow->setDrMd(JAM1);
  125.  
  126.  
  127.    WORD polyTable[3][2];
  128.    WORD startX,endX;
  129.    STRPTR title=NULL;
  130.    if (graphicObj->getAttribute(GOB_BorderTitle,(ULONG&)title))
  131.    {
  132.       _dprintf("bordertext = '%s'\n",(char*)title);
  133.       homeWindow->setFont(titleFont);
  134.       // the title is placed in a gap of the top borderline with no space left
  135.       WORD titlePixLen = 1+TextLength(homeWindow->rp(),title,strlen(title));
  136.       startX = (WORD)NORM_X((LONG)graphicObj->left()+(graphicObj->width()-titlePixLen)/2);
  137.       endX = startX+titlePixLen;
  138.       homeWindow->setDrMd(JAM1);
  139.       homeWindow->setAPen(1);
  140.       homeWindow->moveTx(startX+1,(WORD)NORM_Y(graphicObj->top()+1));
  141.       homeWindow->text((UBYTE*)title);
  142.    }
  143.    else startX = endX = (WORD)NORM_X((LONG)graphicObj->left()+bWidth);
  144.  
  145.    polyTable[0][X] = startX;
  146.    polyTable[0][Y] = (WORD)NORM_Y((LONG)graphicObj->top()+bHeight/2);
  147.    polyTable[1][X] = (WORD)NORM_X((LONG)graphicObj->left()+bWidth/2);
  148.    polyTable[1][Y] = polyTable[0][Y];
  149.    polyTable[2][X] = polyTable[1][X];
  150.    polyTable[2][Y] = (WORD)NORM_Y((LONG)graphicObj->bottom()-bHeight/2);
  151.    homeWindow->setAPen(1);
  152.    homeWindow->polyDraw(3,&polyTable[0][0]);
  153.    polyTable[0][Y]++; polyTable[1][Y]++; polyTable[1][X]++; polyTable[2][X]++;
  154.    homeWindow->setAPen(2);
  155.    homeWindow->polyDraw(3,&polyTable[0][0]);
  156.  
  157.    polyTable[0][X] = polyTable[2][X]+(WORD)1;
  158.    polyTable[0][Y] = polyTable[2][Y];
  159.    polyTable[1][X] = (WORD)NORM_X((LONG)graphicObj->right()-bWidth/2);
  160.    polyTable[1][Y] = polyTable[0][Y];
  161.    polyTable[2][X] = polyTable[1][X];
  162.    polyTable[2][Y] = (WORD)NORM_Y((LONG)graphicObj->top()+bHeight/2+1);
  163.    homeWindow->polyDraw(3,&polyTable[0][0]);
  164.    homeWindow->setAPen(1);
  165.    polyTable[0][Y]--; polyTable[1][Y]--; polyTable[1][X]--; polyTable[2][X]--;
  166.    homeWindow->polyDraw(3,&polyTable[0][0]);
  167.  
  168.    polyTable[0][X] = polyTable[2][X]+(WORD)1;
  169.    polyTable[0][Y] = polyTable[2][Y]-(WORD)1;
  170.    polyTable[1][X] = endX;
  171.    polyTable[1][Y] = polyTable[0][Y];
  172.    homeWindow->polyDraw(2,&polyTable[0][0]);
  173.    polyTable[0][Y]++; polyTable[1][Y]++;
  174.    homeWindow->setAPen(2);
  175.    homeWindow->polyDraw(2,&polyTable[0][0]);
  176.  
  177.    homeWindow->resetStdClip();
  178. }
  179.