📄 extgraph.h
字号:
/*
* File: extgraph.h
* Version: 3.1
* Last modified on Sat Nov 6 17:28:28 PST 1999 by magi
* -----------------------------------------------------
* This interface is the extended graphics interface.
* It includes all of the facilities in graphics.h, plus
* several additional functions that are designed to
* support more sophisticated, interactive graphics.
*/
#ifdef __cplusplus
#pragma message ( "You are compiling in C++ mode which will probably cause compile errors with" )
#pragma message ( "the 'bool' type as well as link errors such as 'undefined external symbol'." )
#pragma message ( "Most likely, you have saved your source code with a name ending in .cpp;" )
#pragma message ( "it needs to end in .c." )
#endif
#ifndef _extgraph_h
#define _extgraph_h
#include "genlib.h"
/* Exported functions */
/* Section 1 -- Basic functions from graphics.h */
#include "graphics.h"
/* Section 2 -- Elliptical arcs */
/*
* Function: DrawEllipticalArc
* Usage: DrawEllipticalArc(rx, ry, start, sweep);
* -----------------------------------------------
* This procedure draws an elliptical arc. It is exactly
* the same in its operation as DrawArc in the graphics.h
* interface, except that the radius is different along the
* two axes.
*/
void DrawEllipticalArc(double rx, double ry,
double start, double sweep);
/* Section 3 -- Graphical regions*/
/*
* Functions: StartFilledRegion, EndFilledRegion
* Usage: StartFilledRegion(density);
* . . . other calls . . .
* EndFilledRegion();
* ------------------------------
* These calls make it possible to draw filled shapes on the
* display. After calling StartFilledRegion, any calls to
* DrawLine and DrawArc are used to create a shape definition
* and do not appear on the screen until EndFilledRegion is
* called. The lines and arcs must be consecutive, in the
* sense that each new element must start where the last
* one ended. MovePen calls may occur at the beginning
* or the end of the region, but not in the interior. When
* EndFilledRegion is called, the entire region appears on the
* screen, with its interior filled in. The density parameter
* is a number between 0 and 1 and indicates how the dot density
* to be used for the fill pattern. If density is 1, the shape
* will be filled in a solid color; if it is 0, the fill will be
* invisible. In between, the implementation will use a dot
* pattern that colors some of the screen dots but not others.
*/
void StartFilledRegion(double density);
void EndFilledRegion(void);
/* Section 4 -- String functions */
/*
* Function: DrawTextString
* Usage: DrawTextString(text);
* ----------------------------
* This function displays the string text at the current point
* in the current font and size. The current point is updated
* so that the next DrawTextString command would continue from
* the next character position. The string may not include the
* newline character.
*/
void DrawTextString(string text);
/*
* Function: TextStringWidth
* Usage: w = TextStringWidth(text);
* ---------------------------------
* This function returns the width of the text string if displayed
* at the current font and size.
*/
double TextStringWidth(string text);
/*
* Function: SetFont
* Usage: SetFont(font);
* ---------------------
* This function sets a new font according to the font string,
* which is case-independent. Different systems support different
* fonts, although common ones like "Times" and "Courier" are often
* supported. Initially, the font is set to "Default" which is
* always supported, although the underlying font is system
* dependent. If the font name is unrecognized, no error is
* generated, and the font remains unchanged. If you need to
* detect this condition, you can call GetFont to see if the
* change took effect. By not generating an error in this case,
* programs become more portable.
*/
void SetFont(string font);
/*
* Function: GetFont
* Usage: font = GetFont();
* ------------------------
* This function returns the current font name as a string.
*/
string GetFont(void);
/*
* Function: SetPointSize
* Usage: SetPointSize(size);
* --------------------------
* This function sets a new point size. If the point size is
* not supported for a particular font, the closest existing
* size is selected.
*/
void SetPointSize(int size);
/*
* Function: GetPointSize
* Usage: size = GetPointSize();
* -----------------------------
* This function returns the current point size.
*/
int GetPointSize(void);
/*
* Text style constants
* --------------------
* The constants Bold and Italic are used in the SetStyle
* command to specify the desired text style. They may also
* be used in combination by adding these constants together,
* as in Bold + Italic. The constant Normal indicates the
* default style.
*/
#define Normal 0
#define Bold 1
#define Italic 2
/*
* Function: SetStyle
* Usage: SetStyle(style);
* -----------------------
* This function establishes the current style properties
* for text based on the parameter style, which is an integer
* representing the sum of any of the text style constants.
*/
void SetStyle(int style);
/*
* Function: GetStyle
* Usage: style = GetStyle();
* --------------------------
* This function returns the current style.
*/
int GetStyle(void);
/*
* Functions: GetFontAscent, GetFontDescent, GetFontHeight
* Usage: ascent = GetFontAscent();
* descent = GetFontDescent();
* height = GetFontHeight();
* -------------------------------------------------------
* These functions return properties of the current font that are
* used to calculate how to position text vertically on the page.
* The ascent of a font is the distance from the baseline to the
* top of the largest character; the descent is the maximum
* distance any character extends below the baseline. The height
* is the total distance between two lines of text, including the
* interline space (which is called leading).
*
* Examples:
* To change the value of y so that it indicates the next text
* line, you need to execute
*
* y -= GetFontHeight();
*
* To center text vertically around the coordinate y, you need
* to start the pen at
*
* y - GetFontAscent() / 2
*/
double GetFontAscent(void);
double GetFontDescent(void);
double GetFontHeight(void);
/* Section 5 -- Mouse support */
/*
* Functions: GetMouseX, GetMouseY
* Usage: x = GetMouseX();
* y = GetMouseY();
* -------------------------------
* These functions return the x and y coordinates of the mouse,
* respectively. The coordinate values are real numbers measured
* in inches from the origin and therefore match the drawing
* coordinates.
*/
double GetMouseX(void);
double GetMouseY(void);
/*
* Functions: MouseButtonIsDown
* Usage: if (MouseButtonIsDown()) . . .
* -------------------------------------
* This function returns TRUE if the mouse button is currently
* down. For maximum compatibility among implementations, the
* mouse is assumed to have one button. If the mouse has more
* than one button, this function returns TRUE if any button
* is down.
*/
bool MouseButtonIsDown(void);
/*
* Functions: WaitForMouseDown, WaitForMouseUp
* Usage: WaitForMouseDown();
* WaitForMouseUp();
* -------------------------------------------
* The WaitForMouseDown function waits until the mouse button
* is pressed and then returns. WaitForMouseUp waits for the
* button to be released.
*/
void WaitForMouseDown(void);
void WaitForMouseUp(void);
/* Section 6 -- Color support */
/*
* Function: HasColor
* Usage: if (HasColor()) . . .
* ----------------------------
* This function returns TRUE if the graphics window can display a
* color image. Note that this condition is stronger than simply
* checking whether a color display is available. Because color
* windows require more memory than black and white ones, this
* function will return FALSE with a color screen if there is
* not enough memory to store a colored image. On the Macintosh,
* for example, it is usually necessary to increase the partition
* size to at least 1MB before color windows can be created.
*/
bool HasColor(void);
/*
* Function: SetPenColor
* Usage: SetPenColor(color);
* --------------------------
* This function sets the color of the pen used for any drawing,
* including lines, text, and filled regions. The color is a
* string, which will ordinarily be one of the following
* predefined color names:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -