EasyX Graphics Library API Reference
Device Context Management
Functions for initializing, configuring, and managing the graphics window and device context.
void clearcliprgn();
Removes the current clipping region, allowing drawing operations to affect the entire device surface.
void cleardevice();
Clears the entire graphics device using the current background color and resets the current drawing position to the origin (0, 0).
void closegraph();
Destroys the graphics window and releases associated resources.
void getaspectratio(float* xAsp, float* yAsp);
Retrieves the current aspect ratio correction factors for the x and y axes.
HWND initgraph(int width, int height, int flag = NULL);
Creates and initializes a graphics window with the specified dimensions. Returns the window handle (HWND). Optional flags control window behavior.
void setaspectratio(float xAsp, float yAsp);
Sets the aspect ratio for scaling operations. Values greater than 1.0 stretch the axis, while values less than 1.0 compress it.
void setcliprgn(HRGN region);
Establishes a clipping region using a Windows GDI region handle. Subsequent drawing operation are constrained to this region.
void setorigin(int x, int y);
Relocates the coordinate system origin to the specified physical coordinates (x, y).
void graphdefaults();
Resets all device context attributes to their default values, including viewport settings, current position, colors, line styles, fill patterns, and font characteristics.
Color Model Operations
Utilities for color space conversions and component extraction.
COLORREF BGR(COLORREF color);
Swaps the red and blue components of the specified RGB color value. Useful for converting between RGB and BGR formats.
BYTE GetBValue(COLORREF rgb);
BYTE GetGValue(COLORREF rgb);
BYTE GetRValue(COLORREF rgb);
Extract the blue, green, or red component (0-255) from an RGB color value.
COLORREF RGB(BYTE red, BYTE green, BYTE blue);
Constructs a color value from individual red, green, and blue components (0-255).
COLORREF HSLtoRGB(float H, float S, float L);
Converts a color from HSL (Hue, Saturation, Lightness) coler space to RGB.
COLORREF HSVtoRGB(float H, float S, float V);
Converts a color from HSV (Hue, Saturation, Value) color space to RGB.
COLORREF RGBtoGRAY(COLORREF rgb);
Calculates the grayscale equivalent of the specified RGB color using luminance weighting.
void RGBtoHSL(COLORREF rgb, float* H, float* S, float* L);
Decomposes an RGB color into HSL components.
void RGBtoHSV(COLORREF rgb, float* H, float* S, float* V);
Decomposes an RGB color into HSV components.
Primitive Drawing Functions
Core rendering operations for geometric shapes.
Arcs and Curves
void arc(int left, int top, int right, int bottom, double startAngle, double endAngle);
Draws an elliptical arc within the specified bounding rectangle. Angles are measured in radians, with 0 radians pointing east (3 o'clock position).
void polybezier(const POINT* points, int num);
Renders a sequence of cubic Bézier curves. The points array must contain 3n+1 points, organized as: start point, control point 1, control point 2, end point (which becomes the next start point), etc.
Circles and Ellipses
void circle(int x, int y, int radius);
Draws a circular outline centered at (x, y) with the specified radius.
void ellipse(int left, int top, int right, int bottom);
Draws an elliptical outline within the specified bounding rectangle.
void pie(int left, int top, int right, int bottom, double startAngle, double endAngle);
Draws a pie wedge (sector) outline using an elliptical arc.
void fillcircle(int x, int y, int radius);
Renders a filled circle with a border outline.
void fillellipse(int left, int top, int right, int bottom);
Renders a filled ellipse with a border outline.
void fillpie(int left, int top, int right, int bottom, double startAngle, double endAngle);
Renders a filled pie wedge with a border outline.
void solidcircle(int x, int y, int radius);
Renders a filled circle without a border.
void solidellipse(int left, int top, int right, int bottom);
Renders a filled ellipse without a border.
void solidpie(int left, int top, int right, int bottom, double startAngle, double endAngle);
Renders a filled pie wedge without a border.
Rectangles
void rectangle(int left, int top, int right, int bottom);
Draws a rectangular outline.
void fillrectangle(int left, int top, int right, int bottom);
Renders a filled rectangle with a border outline.
void solidrectangle(int left, int top, int right, int bottom);
Renders a filled rectangle without a border.
void roundrect(int left, int top, int right, int bottom, int ellipseWidth, int ellipseHeight);
Draws a rounded rectangle outline. The ellipseWidth and ellipseHeight parameters specify the dimensions of the ellipse used to round the corners.
void fillroundrect(int left, int top, int right, int bottom, int ellipseWidth, int ellipseHeight);
Renders a filled rounded rectangle with a border.
void solidroundrect(int left, int top, int right, int bottom, int ellipseWidth, int ellipseHeight);
Renders a filled rounded rectangle without a border.
Polygons
void polygon(const POINT* points, int num);
Draws a closed polygon outline using the specified array of points. The function automatically closes the path from the last point to the first.
void fillpolygon(const POINT* points, int num);
Renders a filled polygon with a border outline.
void solidpolygon(const POINT* points, int num);
Renders a filled polygon without a border.
void polyline(const POINT* points, int num);
Draws a series of connected line segments without closing the path.
Clearing Operations
void clearcircle(int x, int y, int radius);
Erases a circular area by filling it with the current background color.
void clearellipse(int left, int top, int right, int bottom);
Erases an elliptical area using the background color.
void clearpie(int left, int top, int right, int bottom, double startAngle, double endAngle);
Erases a pie wedge area using the background color.
void clearpolygon(const POINT* points, int num);
Erases a polygonal area using the background color.
void clearrectangle(int left, int top, int right, int bottom);
Erases a rectangular area using the background color.
void clearroundrect(int left, int top, int right, int bottom, int ellipseWidth, int ellipseHeight);
Erases a rounded rectangular area using the background color.
Lines and Pixels
void line(int x1, int y1, int x2, int y2);
Draws a line segment from (x1, y1) to (x2, y2).
void putpixel(int x, int y, COLORREF color);
Setss the color of the pixel at the specified coordinates.
COLORREF getpixel(int x, int y);
Retrieves the color of the pixel at the specified coordinates.
Flood Fill
void floodfill(int x, int y, COLORREF color, int fillType = FLOODFILLBORDER);
Fills an area starting from (x, y).
FLOODFILLBORDER(0): Fills until reaching the specified border color.FLOODFILLSURFACE(1): Fills contiguous areas matching the specified surface color.
Device Dimensions
int getwidth();
Returns the width of the current drawing device in pixels.
int getheight();
Returns the height of the current drawing device in pixels.
Rendering Attributes
Functions for controlling fill patterns, line styles, and color settings.
Background and Fill
COLORREF getbkcolor();
Returns the current background color.
void setbkcolor(COLORREF color);
Sets the background color for the device.
int getbkmode();
Retrieves the current background mode for text and patterned fills (OPAQUE or TRANSPARENT).
void setbkmode(int mode);
Sets the background mode. OPAQUE fills backgrounds with the current background color; TRANSPARENT leaves backgrounds unchanged.
COLORREF getfillcolor();
Returns the current fill color.
void setfillcolor(COLORREF color);
Sets the color used for filling shapes.
void getfillstyle(FILLSTYLE* style);
Retrieves the current fill style configuration.
void setfillstyle(const FILLSTYLE* style);
void setfillstyle(int pattern, long hatch = NULL, IMAGE* patternImg = NULL);
void setfillstyle(BYTE* pattern8x8);
Configures the fill pattern. Options include solid fills, hatched patterns, and custom 8x8 bitmap patterns defined by the user.
int getpolyfillmode();
Returns the current polygon fill mode (ALTERNATE or WINDING).
void setpolyfillmode(int mode);
Sets the polygon fill algorithm. ALTERNATE fills areas between odd and even boundary crossings; WINDING fills based on non-zero winding number.
Line Attributes
COLORREF getlinecolor();
Returns the current line drawing color.
void setlinecolor(COLORREF color);
Sets the color for line and border drawing.
void getlinestyle(LINESTYLE* style);
Retrieves the current line style configuration.
void setlinestyle(const LINESTYLE* style);
void setlinestyle(int style, int thickness = 1, const DWORD* userPattern = NULL, DWORD patternCount = 0);
Configures line appearance including solid/dashed styles, thickness in pixels, and custom dash patterns.
Raster Operations
int getrop2();
Retrieves the current binary raster operation (ROP2) for foreground mixing.
Style Objects
class FILLSTYLE;
Encapsulates fill pattern attributes including style, hatch pattern, and optional pattern image.
class LINESTYLE;
Encapsulates line attributes including style, thickness, and custom dash pattern data.
Text Output
Functions for rendering text with precise positioning and formatting.
void outtextxy(int x, int y, LPCTSTR str);
void outtextxy(int x, int y, TCHAR c);
Outputs a string or character at the specified coordinates. The text is rendered using the current font, color, and background mode.
int drawtext(LPCTSTR str, RECT* rect, UINT format);
int drawtext(TCHAR c, RECT* rect, UINT format);
Formats and draws text within the specified rectangular region. Supports alignment flags (DT_LEFT, DT_CENTER, DT_RIGHT), line breaks (DT_WORDBREAK), and clipping (DT_CLIPPING).
COLORREF gettextcolor();
Returns the current text color.
void settextcolor(COLORREF color);
Sets the color for text rendering.
void gettextstyle(LOGFONT* font);
Retrieves the current font configuration in a LOGFONT structure.
void settextstyle(const LOGFONT* font);
void settextstyle(int height, int width, LPCTSTR faceName);
Configures the font attributes including height, width (0 for default aspect ratio), and typeface name.
int textheight(LPCTSTR str);
int textheight(TCHAR c);
Calculates the vertical pixel height required to display the specified text using the current font.
int textwidth(LPCTSTR str);
int textwidth(TCHAR c);
Calculates the horizontal pixel width required to display the specified text using the current font.
Image Manipulation
Operations for loading, saving, and manipulating bitmap images.
class IMAGE(int width = 0, int height = 0);
Constructs an off-screen image buffer with the specified dimensions. Default constructor creates a null image.
IMAGE* GetWorkingImage();
Returns a pointer to the current active drawing target (either the screen or an IMAGE object).
void SetWorkingImage(IMAGE* img = NULL);
Sets the current drawing target. Passing NULL selects the default graphics window.
void getimage(IMAGE* dest, int srcX, int srcY, int srcWidth, int srcHeight);
Captures a rectangular region from the current drawing device into the destination image object.
void loadimage(IMAGE* dest, LPCTSTR filename, int width = 0, int height = 0, bool resize = false);
Loads an image from disk into the specified image object. Supports BMP, GIF, JPG, PNG, and TIF formats. Optional parameters control stretching and automatic resizing.
void putimage(int x, int y, IMAGE* src, DWORD rop = SRCCOPY);
Renders the source image onto the current drawing device at the specified coordinates. The raster operation code (rop) determines how pixels are combined (e.g., SRCCOPY, SRCAND, SRCINVERT).
void saveimage(LPCTSTR filename, IMAGE* img = NULL);
Saves the specified image (or the current window if NULL) to disk. The file extension determines the format (bmp, gif, jpg, png, tif).
void Resize(IMAGE* img, int width, int height);
Resizes the specified image buffer to new dimensions.
void rotateimage(IMAGE* dest, IMAGE* src, double radians, COLORREF backColor = BLACK, bool autoSize = false, bool highQuality = true);
Rotates the source image by the specified angle and stores the result in the destination image. Optional parameters control the background fill color, automatic destination sizing, and interpolation quality.
DWORD* GetImageBuffer(IMAGE* img = NULL);
Returns a pointer to the raw pixel buffer of the specified image for direct memory access.
HDC GetImageHDC(IMAGE* img = NULL);
Retrieves the Windows Device Context (HDC) handle for the specified image, enabling interoperability with GDI functions.
Mouse Input
Event-driven mouse handling and state queries.
void FlushMouseMsgBuffer();
Discards all pending mouse messages from the input queue.
bool MouseHit();
Returns true if mouse messages are available in the queue without removing them.
MOUSEMSG GetMouseMsg();
Retrieves and removes the next mouse message from the queue. Blocks until a message is available.
bool PeekMouseMsg(MOUSEMSG* msg, bool removeMsg);
Checks for mouse messages without blocking. If removeMsg is true, the message is removed from the queue.
struct MOUSEMSG;
Mouse message structure containing:
UINT uMsg: Message type (WM_MOUSEMOVE, WM_LBUTTONDOWN, etc.)bool mkCtrl: Control key statebool mkShift: Shift key statebool mkLButton: Left button statebool mkMButton: Middle button statebool mkRButton: Right button stateint x,int y: Cursor position in physical coordinatesint wheel: Wheel rotation delta
Batch Rendering and Utilities
Performance optimization and system integration functions.
void BeginBatchDraw();
Suspends immediate screen updates. All subsequent drawing operations are buffered internally until EndBatchDraw or FlushBatchDraw is called, reducing flicker and improving performance for complex scenes.
void EndBatchDraw();
void EndBatchDraw(int left, int top, int right, int bottom);
Resumes immediate screen updates and flushes the buffer. The overloaded version updates only the specified rectangular region.
void FlushBatchDraw();
void FlushBatchDraw(int left, int top, int right, int bottom);
Flushes the drawing buffer to the screen without ending batch mode. Useful for displaying intermediate frames during batch operations.
HWND GetHWnd();
Returns the window handle (HWND) of the graphics window for integration with Win32 API functions.
bool InputBox(LPTSTR buffer, int maxLength, LPCTSTR prompt = NULL, LPCTSTR title = NULL, LPCTSTR defaultText = NULL, int width = 0, int height = 0, bool hideCancel = true);
Displays a modal dialog box to collect user input. Returns true if confirmed, false if cancelled. The buffer receives the input string, limited to maxLength characters.