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/GraphicsEnv.cp
/* |
File: GraphicsEnv.cp |
Contains: GraphicsEnv is a collection of utility classes that could be used for defining grafport values |
(font, pen drawing, color). |
GraphicsEnv.cp contains the graphics environment member functions. |
Written by: Kent Sandvik |
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 |
*/ |
#ifndef _GRAPHICSENV_ |
#include "GraphicsEnv.h" |
#endif |
// _________________________________________________________________________________________________________ // |
// TFontEnvironment member functions. |
// CONSTRUCTORS AND DESTRUCTORS |
#pragma segment GraphicsEnv |
TFontEnvironment::TFontEnvironment(short mode, |
short fontNo, |
short textSize, |
Style newStyle) |
// Set font values in grafport, default values: system font, 12 point, plain text. |
{ |
fMode = mode; |
fFont = fontNo; |
fTextSize = textSize; |
fStyle = newStyle; |
} |
#pragma segment GraphicsEnv |
TFontEnvironment::~TFontEnvironment() |
// Default constructor -- not used for the time being. |
{ |
} |
// MAIN INTERFACE |
#pragma segment GraphicsEnv |
void TFontEnvironment::Set() |
// Set current grafport to defined values concerning fonts. |
{ |
::TextMode(fMode); // set copy mode |
::TextFont(fFont); // set font in current GrafPort |
::TextSize(fTextSize); // set font size in current GrafPort |
::TextFace(fStyle); // set font style in current GrafPort |
} |
#pragma segment GraphicsEnv |
void TFontEnvironment::Reset() |
// Reset the grafport font information to default state. |
{ |
::TextMode(srcOr); // reset copy mode |
::TextFont(0); // reset font in current GrafPort |
::TextSize(0); // reset font size in current GrafPort |
::TextFace(0); // reset font style in current GrafPort |
} |
// _________________________________________________________________________________________________________ // |
// TPenEnvironment member functions. |
// CONSTRUCTORS AND DESTRUCTORS |
#pragma segment GraphicsEnv |
TPenEnvironment::TPenEnvironment(short mode, |
Pattern penPattern, |
short penWidth, |
short penHigh) |
// Set the grafport pen values concerning pattern, mode and size. |
{ |
fMode = mode; |
fPattern = &penPattern; |
fWidth = penWidth; |
fHigh = penHigh; |
} |
#pragma segment GraphicsEnv |
TPenEnvironment::~TPenEnvironment() |
// Default destructor -- not used for the time being. |
{ |
} |
// MAIN INTERFACE |
#pragma segment GraphicsEnv |
void TPenEnvironment::Set() |
// Set pen values for graf port. |
{ |
::PenMode(fMode); // set pattern transfer mode |
::PenPat(fPattern); // set pattern for pen |
::PenSize(fWidth, fHigh); // set pen size |
} |
#pragma segment GraphicsEnv |
void TPenEnvironment::Reset() |
// Reset pen values for graf port. |
{ |
::PenMode(srcOr); // reset pattern transfer mode |
::PenPat(&qd.black); // reset pen pattern |
::PenSize(1, 1); // reset pen size |
} |
// _________________________________________________________________________________________________________ // |
// TColorEnvironment member functions. |
// CONSTRUCTORS AND DESTRUCTORS |
#pragma segment GraphicsEnv |
TColorEnvironment::TColorEnvironment(unsigned short red, |
unsigned short green, |
unsigned short blue) |
// Define colors for grafport. |
{ |
fColor.red = red; |
fColor.green = green; |
fColor.blue = blue; |
} |
#pragma segment GraphicsEnv |
TColorEnvironment::TColorEnvironment(RGBColor theColor) |
// Define RGBValues for grafport. |
{ |
fColor = theColor; // we make use of the bit-fied copying scheme of the compiler |
} |
#pragma segment GraphicsEnv |
TColorEnvironment::~TColorEnvironment() |
// Default destructor -- not used just now. |
{ |
} |
// MAIN INTERFACE |
#pragma segment GraphicsEnv |
void TColorEnvironment::SetForeground() |
// Set foreground color. |
{ |
::RGBForeColor(&fColor); |
} |
#pragma segment GraphicsEnv |
void TColorEnvironment::SetBackground() |
// Set background color. |
{ |
::RGBBackColor(&fColor); |
} |
#pragma segment GraphicsEnv |
void TColorEnvironment::Reset() |
// Reset grafport to black/white. |
{ |
::ForeColor(blackColor); |
::BackColor(whiteColor); |
} |
// _________________________________________________________________________________________________________ // |
/* 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