SavvyUI C++ UI Library
Loading...
Searching...
No Matches
GraphicsContext Class Reference

Provides static methods for GDI+ initialization and image rendering. More...

#include <GraphicsContext.h>

Static Public Member Functions

static void initGdiPlus ()
 Initializes the GDI+ library.
static void terminateGdiPlus ()
 Terminates the GDI+ library and frees resources.
static Gdiplus::Image * imageFileToImage (const wstring &filePath)
 Loads an image from a file path into a GDI+ Image object.
static Gdiplus::Image * imageBytesToImage (const BYTE *imageBytes, size_t size)
 Loads an image from a byte array into a GDI+ Image object.
static Gdiplus::Image * imageResourceToImage (HINSTANCE hInst, int resourceID, const ImageType &imageType)
 Loads a PNG, GIF, or JPG image using its resource ID from .rc file as a GDI+ Image object.
static void drawImageFile (Graphics *g, Bounds rect, const wstring &filePath, const ImageAlignment &alignment=ImageAlignment::TOPCENTER, BOOL showBorder=FALSE)
 Draws an image loaded from a file onto a device context.
static void drawImage (Graphics *g, Bounds rect, Gdiplus::Image *image, const ImageAlignment &alignment=ImageAlignment::TOPCENTER, BOOL showBorder=FALSE)
 Draws a GDI+ Image onto a device context.
static void drawImageBytes (Graphics *g, Bounds rect, const BYTE *imageBytes, size_t size, const ImageAlignment &alignment=ImageAlignment::TOPCENTER, BOOL showBorder=FALSE)
 Draws an image represented by a byte array onto a device context.
static void drawImageResource (Graphics *g, Bounds rect, int resourceID, const ImageType &imageType, const ImageAlignment &alignment=ImageAlignment::TOPCENTER, BOOL showBorder=FALSE)
 Draws a GDI+ Image onto a device context.
static void linearGradient (Graphics *g, Bounds rect, int startR, int startG, int startB, int endR, int endG, int endB, int startAlpha=0, int endAlpha=0, BOOL directionVertical=TRUE, const wstring &text=L"", int textR=0, int textG=0, int textB=0)
 Fills a rect with a linear gradient colors.

Detailed Description

Provides static methods for GDI+ initialization and image rendering.

This class offers utility functions to initialize and terminate GDI+, load images from files, and draw images onto device contexts with alignment and optional borders.

Member Function Documentation

◆ drawImage()

void GraphicsContext::drawImage ( Graphics * g,
Bounds rect,
Gdiplus::Image * image,
const ImageAlignment & alignment = ImageAlignment::TOPCENTER,
BOOL showBorder = FALSE )
static

Draws a GDI+ Image onto a device context.

Parameters
hDCHandle to the device context where the image will be drawn.
rectThe target rectangle in which to draw the image.
imagePointer to the Gdiplus::Image to draw.
alignmentSpecifies the image alignment within the rectangle. Default is "topCenter".
showBorderIf TRUE, draws a border around the image. Default is FALSE.

◆ drawImageBytes()

void GraphicsContext::drawImageBytes ( Graphics * g,
Bounds rect,
const BYTE * imageBytes,
size_t size,
const ImageAlignment & alignment = ImageAlignment::TOPCENTER,
BOOL showBorder = FALSE )
static

Draws an image represented by a byte array onto a device context.

Parameters
hDCHandle to the device context where the image will be drawn.
rectThe target rectangle in which to draw the image.
imageBytesPointer to the image bytes.
sizethe size of the imageBytes array.
alignmentSpecifies the image alignment within the rectangle. Default is "topCenter".
showBorderIf TRUE, draws a border around the image. Default is FALSE.

◆ drawImageFile()

void GraphicsContext::drawImageFile ( Graphics * g,
Bounds rect,
const wstring & filePath,
const ImageAlignment & alignment = ImageAlignment::TOPCENTER,
BOOL showBorder = FALSE )
static

Draws an image loaded from a file onto a device context.

Parameters
hDCHandle to the device context where the image will be drawn.
rectThe target rectangle in which to draw the image.
filePathThe path to the image file.
alignmentSpecifies the image alignment within the rectangle. Default is "topCenter".
showBorderIf TRUE, draws a border around the image. Default is FALSE.

◆ drawImageResource()

void GraphicsContext::drawImageResource ( Graphics * g,
Bounds rect,
int resourceID,
const ImageType & imageType,
const ImageAlignment & alignment = ImageAlignment::TOPCENTER,
BOOL showBorder = FALSE )
static

Draws a GDI+ Image onto a device context.

Parameters
hDCHandle to the device context where the image will be drawn.
rectThe target rectangle in which to draw the image.
resourceIDID from the .rc resource
alignmentSpecifies the image alignment within the rectangle. Default is "topCenter".
showBorderIf TRUE, draws a border around the image. Default is FALSE.

◆ imageBytesToImage()

Gdiplus::Image * GraphicsContext::imageBytesToImage ( const BYTE * imageBytes,
size_t size )
static

Loads an image from a byte array into a GDI+ Image object.

Returns
Pointer to the loaded Gdiplus::Image object, or nullptr if loading fails.

◆ imageFileToImage()

Gdiplus::Image * GraphicsContext::imageFileToImage ( const wstring & filePath)
static

Loads an image from a file path into a GDI+ Image object.

Parameters
filePathThe path to the image file.
Returns
Pointer to the loaded Gdiplus::Image object, or nullptr if loading fails.

◆ imageResourceToImage()

Gdiplus::Image * GraphicsContext::imageResourceToImage ( HINSTANCE hInst,
int resourceID,
const ImageType & imageType )
static

Loads a PNG, GIF, or JPG image using its resource ID from .rc file as a GDI+ Image object.

Returns
Pointer to the loaded Gdiplus::Image object, or nullptr if loading fails.

◆ initGdiPlus()

void GraphicsContext::initGdiPlus ( )
static

Initializes the GDI+ library.

Must be called before using any GDI+ functionality.

◆ linearGradient()

void GraphicsContext::linearGradient ( Graphics * g,
Bounds rect,
int startR,
int startG,
int startB,
int endR,
int endG,
int endB,
int startAlpha = 0,
int endAlpha = 0,
BOOL directionVertical = TRUE,
const wstring & text = L"",
int textR = 0,
int textG = 0,
int textB = 0 )
static

Fills a rect with a linear gradient colors.

◆ terminateGdiPlus()

void GraphicsContext::terminateGdiPlus ( )
static

Terminates the GDI+ library and frees resources.

Should be called when GDI+ is no longer needed.


The documentation for this class was generated from the following file: