home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 October: Mac OS SDK / Dev.CD Oct 96 SDK / Dev.CD Oct 96 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / Developer University / DUProjects / GraphicsGX / Sources / Frame.cpp < prev    next >
Encoding:
Text File  |  1996-08-16  |  4.8 KB  |  171 lines  |  [TEXT/CWIE]

  1. //    Copyright © 1995 Apple Computer, Inc. All rights reserved.
  2. //    Release Version:    $ 1.0 d11 $
  3.  
  4. //=======================================================================
  5. #ifndef FRAME_H
  6. #include "Frame.h"
  7. #endif
  8.  
  9. #ifndef PART_H
  10. #include "Part.h"
  11. #endif
  12.  
  13. // ----- Framework Layer -----
  14. #ifndef FWUTIL_H
  15. #include "FWUtil.h"                // FW_CFacetContext, FW_Beep()
  16. #endif
  17.  
  18. #ifndef FWCONTXT_H
  19. #include "FWContxt.h"            // FW_CViewContext
  20. #endif
  21.  
  22. #ifndef FWPRHDLR_H
  23. #include "FWPrHdlr.h"            // FW_CPrintHandler
  24. #endif
  25.  
  26. // ----- Graphic Includes -----
  27. #ifndef FWRECT_H
  28. #include <FWRect.h>                // FW_CRect
  29. #endif
  30.  
  31. #ifndef FWRECSHP_H
  32. #include "FWRecShp.h"            // FW_CRectShape
  33. #endif
  34.  
  35. #ifndef FWGXUTIL_H
  36. #include "FWGXUtil.h"            // FW_CGraphicContextGX
  37. #endif
  38.  
  39. // for QuickDraw GX
  40. #ifndef __GXGRAPHICS__
  41. #include <GXGraphics.h>                // GXNewRectangle()
  42. #endif
  43.  
  44. #ifndef __GXENVIRONMENT__
  45. #include <GXEnvironment.h>            // GXNewWindowViewPort()
  46. #endif
  47.  
  48. #include <GXFonts.h>
  49. #include <GXLayout.h>
  50.  
  51.  
  52. //========================================================================================
  53. #ifdef FW_BUILD_MAC
  54. #pragma segment GraphicsGX
  55. #endif
  56.  
  57. //========================================================================================
  58. FW_DEFINE_AUTO(CGraphicsGXFrame)
  59.  
  60. //========================================================================================
  61. CGraphicsGXFrame::CGraphicsGXFrame(Environment* ev, ODFrame* odFrame, 
  62.                                     FW_CPresentation* presentation, CGraphicsGXPart* graphicsgxPart)
  63.   : FW_CFrame(ev, odFrame, presentation, graphicsgxPart)
  64. {
  65.     FW_END_CONSTRUCTOR
  66. }
  67.  
  68. //----------------------------------------------------------------------------------------
  69. CGraphicsGXFrame::~CGraphicsGXFrame()
  70. {
  71.     FW_START_DESTRUCTOR
  72. }
  73.  
  74. //----------------------------------------------------------------------------------------
  75. void 
  76. CGraphicsGXFrame::Draw(Environment *ev, ODFacet* odFacet, ODShape* invalidShape)    // Override
  77. {
  78.     this->MyDrawWithODF(ev, odFacet, invalidShape);
  79.     {
  80.         FW_CGraphicContextGX gxContext(ev, odFacet, invalidShape);
  81.         this->MyDrawGXBoxes(ev, gxContext);
  82.         this->MyDrawGXText(ev, gxContext);
  83.     }
  84. }
  85.  
  86. //----------------------------------------------------------------------------------------
  87. void 
  88. CGraphicsGXFrame::MyDrawWithODF(Environment *ev, ODFacet* odFacet, ODShape* invalidShape)
  89. {
  90.     FW_CViewContext context(ev, this, odFacet, invalidShape);
  91.     FW_CRect rect(FW_IntToFixed(25), FW_IntToFixed(25), FW_IntToFixed(75), FW_IntToFixed(75) );
  92.     FW_CRectShape rectShape(rect, FW_kFill);
  93.     rectShape.GetInk().SetForeColor(FW_kRGBGreen);
  94.     rectShape.Render(context);
  95. }
  96.  
  97. //----------------------------------------------------------------------------------------
  98. void 
  99. CGraphicsGXFrame::MyDrawGXBoxes(Environment *ev, FW_CGraphicContextGX& context)
  100. {
  101.     gxRectangle     rectData = {ff(100), ff(100), ff(200), ff(300)};    
  102.     Fixed rotateCenter = ff(150);
  103.     gxShape shape = ::GXNewRectangle(&rectData); 
  104.     context.DrawShape(shape);
  105.  
  106.     ::GXRotateShape(shape, ff(-45), rotateCenter, rotateCenter);
  107.     gxColor myColor;
  108.     myColor.space = gxRGBSpace;
  109.     myColor.profile = NULL;
  110.     myColor.element.rgb.red = 0x8000;
  111.     myColor.element.rgb.green = 0x1000;
  112.     myColor.element.rgb.blue = 0xE000;
  113.     ::GXSetShapeColor(shape, &myColor);
  114.     context.DrawShape(shape);
  115.  
  116.     ::GXDisposeShape(shape);
  117. }
  118.  
  119. //----------------------------------------------------------------------------------------
  120. void 
  121. CGraphicsGXFrame::MyDrawGXText(Environment *ev, FW_CGraphicContextGX& context)
  122. {
  123.     gxPoint position = {ff(50), ff(50)};
  124.     gxShape textShape = 
  125.             ::GXNewText(20, (unsigned char*)"     The ffish in GX", &position);
  126.  
  127.     gxStyle textStyle = ::GXNewStyle();
  128.     gxRunFeature runFeature[1];
  129. //        runFeature[0].featureType = ligaturesType;
  130.     runFeature[0].featureSelector = gxNoLigatureSplits;
  131.     ::GXSetStyleRunFeatures(textStyle, 1, runFeature);
  132.     ::GXSetStyleTextSize(textStyle, ff(36));
  133.     ::GXSetShapeStyle(textShape, textStyle);
  134.  
  135.     gxFont aFont; 
  136.     long numFonts = ::GXFindFonts(nil, gxFullFontName, gxMacintoshPlatform, 
  137.                     gxRomanScript, gxEnglishLanguage, strlen("Apple Chancery"), 
  138.                     (const unsigned char*)"Apple Chancery", 1, 1, &aFont);
  139.     ::GXSetShapeFont(textShape, aFont);
  140.     for (short i = 0; i <=3; i++)
  141.     {
  142.         ::GXRotateShape(textShape, ff(i*15), position.x, position.y);
  143.         context.DrawShape(textShape);
  144.     }
  145.     ::GXDisposeShape(textShape);
  146. }
  147.  
  148. //------------------------------------------------------------------------------
  149. FW_CPrintHandler* 
  150. CGraphicsGXFrame::NewPrintHandler(Environment* ev)
  151. {
  152.     FW_CPart* part = GetPart(ev);
  153.     return new FW_CPrintHandler(part, this);
  154. }
  155.  
  156. //------------------------------------------------------------------------------
  157. FW_Boolean 
  158. CGraphicsGXFrame::IsCurrentlyPrintable(Environment* ev) const
  159. {
  160.     return TRUE;
  161. }
  162.  
  163. //------------------------------------------------------------------------------
  164. void 
  165. CGraphicsGXFrame::GetPrintContentExtent(Environment *ev, FW_CPoint& extent) const
  166. {
  167.     FW_CRect frameRect = this->GetBounds(ev);
  168.     extent = frameRect.Size();
  169. }
  170.  
  171.