Retired Document
Important: This sample code may not represent best practices for current development. The project may use deprecated symbols and illustrate technologies and techniques that are no longer recommended.
Sources/GraphicsEnvTest.cp
/* |
File: GraphicsEnvTest.cp |
Contains: GraphicsEnvTest.cp contains the needed test functions for testing out graphics |
environment utility classes. |
Written by: |
Copyright: Copyright © 1993-1999 by Apple Computer, Inc., All Rights Reserved. |
You may incorporate this Apple sample source code into your program(s) without |
restriction. This Apple sample source code has been provided "AS IS" and the |
responsibility for its operation is yours. You are not permitted to redistribute |
this Apple sample source code as "Apple sample source code" after having made |
changes. If you're going to re-distribute the source, we require that you make |
it clear in the source that the code was descended from Apple sample source |
code, but that you've made changes. |
Change History (most recent first): |
8/18/1999 Karl Groethe Updated for Metrowerks Codewarror Pro 2.1 |
*/ |
// HEADER FILES |
// Main interface for the application framework |
#ifndef _APPLICATION_ |
#include "Application.h" |
#endif |
// For graphics environment testing |
#ifndef _GRAPHICSENV_ |
#include "GraphicsEnv.h" |
#endif |
// CONSTANTS |
const short H = 10; // horizontal offset of graphics drawing in window |
const short V = 20; // initial vertical offset of graphics in window |
const short DELTA = 15; // delta value of vertical offsets |
// CLASSES |
class TMyApplication : public TGUIApplication |
// Our sub-TApplication class, override DoCreateDocument for creation of a special window. |
{ |
public: |
TMyApplication(); |
virtual void DoCreateDocument(); |
}; |
class TMyWindow : public TWindow |
// Override Draw to specify what is drawn in the window. |
{ |
public: |
virtual void Draw(); |
}; |
TMyApplication::TMyApplication() |
{ |
} |
// MEMBER FUNCTIONS |
#pragma segment Application |
void TMyApplication::DoCreateDocument() |
{ |
Str255 myTitle; |
Pstrcpy(myTitle, "\pGraphics Env. Tests"); |
// Create this time my TMyWindow document, and add it to the TApplication list. |
TMyWindow * aWindow = new TMyWindow; |
aWindow->SetTitle(&myTitle); |
this->AddDocument(aWindow); |
// Quick test, show and hide the window. |
aWindow->Hide(); |
Delay(60 * 1, NULL); |
aWindow->Show(); |
} |
// Global styles |
TFontEnvironment myGenevaBold(srcOr, |
kFontIDGeneva, |
9, |
bold); |
TFontEnvironment myGenevaInvBold(notSrcCopy, |
kFontIDGeneva, |
10, |
bold); |
TPenEnvironment myThickLine(srcOr, |
qd. dkGray, |
5, |
5); |
TColorEnvironment myMetalGray(36000, |
40500, |
37500); |
TColorEnvironment myMetalBlue(26312, |
14340, |
47359); |
#pragma segment Window |
void TMyWindow::Draw() |
{ |
// Paint background in metal color |
myMetalGray.SetForeground(); // set gray foreground |
Rect windowRect = this->GetExtent(); // get window extent |
::PaintRect(&windowRect); // paint background with gray |
// Set real background & foreground colors |
myMetalBlue.SetForeground(); // set blue paint foreground |
myMetalGray.SetBackground(); // set gray background |
// Draw something into my special window. |
::MoveTo(H, V); |
myGenevaBold.Set(); |
::DrawString("\pThis is a color and Quickdraw test."); |
::MoveTo(H, V + DELTA); |
myGenevaInvBold.Set(); |
::DrawString("\pI will use various classes, do"); |
::MoveTo(H, V + 2 * DELTA); |
myGenevaBold.Reset(); // reset font values to default state |
::DrawString("\pthey they work or not?"); |
::MoveTo(H, V + 3 * DELTA); |
myThickLine.Set(); // draw thick line |
::Line(200, 0); |
myThickLine.Reset(); // back to thin lines |
::MoveTo(H, V + 4 * DELTA); |
::Line(200, 0); |
::MoveTo(H, V + 5 * DELTA); |
::Line(200, 0); |
::PenNormal(); // restore pen |
} |
// M A I N F U N C T I O N |
void main(void) |
{ |
TMyApplication * myApp = new TMyApplication; |
myApp->Start(); |
} |
// _________________________________________________________________________________________________________ // |
/* Change History (most recent last): |
No Init. Date Comment |
1 khs 1/2/93 New file |
2 khs 1/7/93 Cleanup |
*/ |
Copyright © 2003 Apple Computer, Inc. All Rights Reserved. Terms of Use | Privacy Policy | Updated: 2003-01-14