// Helper class for simple bitmap manipulation (not particularly efficient!)
structIMGUI_APIImGuiCaptureImageBuf
{
intWidth;
intHeight;
unsignedint*Data;// RGBA8
ImGuiCaptureImageBuf(){Width=Height=0;Data=NULL;}
~ImGuiCaptureImageBuf(){Clear();}
voidClear();// Free allocated memory buffer if such exists.
voidCreateEmpty(intw,inth);// Reallocate buffer for pixel data and zero it.
boolSaveFile(constchar*filename);// Save pixel data to specified image file.
voidRemoveAlpha();// Clear alpha channel from all pixels.
};
enumImGuiCaptureFlags_:unsignedint
{
ImGuiCaptureFlags_None=0,
ImGuiCaptureFlags_StitchAll=1<<0,// Capture entire window scroll area (by scrolling and taking multiple screenshot). Only works for a single window.
ImGuiCaptureFlags_IncludeOtherWindows=1<<1,// Disable hiding other windows (when CaptureAddWindow has been called by default other windows are hidden)
ImGuiCaptureFlags_IncludeTooltipsAndPopups=1<<2,// Expand capture area to automatically include visible popups and tooltips (use with ImGuiCaptureflags_HideOtherWindows)
ImGuiCaptureFlags_HideMouseCursor=1<<3,// Hide render software mouse cursor during capture.
ImGuiCaptureFlags_Instant=1<<4,// Perform capture on very same frame. Only works when capturing a rectangular region. Unsupported features: content stitching, window hiding, window relocation.
ImGuiCaptureFlags_NoSave=1<<5// Do not save output image.
};
// Defines input and output arguments for capture process.
// When capturing from tests you can usually use the ImGuiTestContext::CaptureXXX() helpers functions.
structImGuiCaptureArgs
{
// [Input]
ImGuiCaptureFlagsInFlags=0;// Flags for customizing behavior of screenshot tool.
ImVector<ImGuiWindow*>InCaptureWindows;// Windows to capture. All other windows will be hidden. May be used with InCaptureRect to capture only some windows in specified rect.
ImRectInCaptureRect;// Screen rect to capture. Does not include padding.
floatInPadding=16.0f;// Extra padding at the edges of the screenshot. Ensure that there is available space around capture rect horizontally, also vertically if ImGuiCaptureFlags_StitchFullContents is not used.
charInOutputFile[256]="";// Output will be saved to a file if InOutputImageBuf is NULL.
ImGuiCaptureImageBuf*InOutputImageBuf=NULL;// _OR_ Output will be saved to image buffer if specified.
intInRecordFPSTarget=30;// FPS target for recording videos.
intInSizeAlign=0;// Resolution alignment (0 = auto, 1 = no alignment, >= 2 = align width/height to be multiple of given value)
// [Output]
ImVec2OutImageSize;// Produced image size.
};
enumImGuiCaptureStatus
{
ImGuiCaptureStatus_InProgress,
ImGuiCaptureStatus_Done,
ImGuiCaptureStatus_Error
};
structImGuiCaptureWindowData
{
ImGuiWindow*Window;
ImRectBackupRect;
ImVec2PosDuringCapture;
};
// Implements functionality for capturing images
structIMGUI_APIImGuiCaptureContext
{
// IO
ImFuncPtr(ImGuiScreenCaptureFunc)ScreenCaptureFunc=NULL;// Graphics backend specific function that captures specified portion of framebuffer and writes RGBA data to `pixels` buffer.
void*ScreenCaptureUserData=NULL;// Custom user pointer which is passed to ScreenCaptureFunc. (Optional)
char*VideoCaptureEncoderPath=NULL;// Video encoder path (not owned, stored externally).
intVideoCaptureEncoderPathSize=0;// Optional. Set in order to edit this parameter from UI.
char*VideoCaptureEncoderParams=NULL;// Video encoder params (not owned, stored externally).
intVideoCaptureEncoderParamsSize=0;// Optional. Set in order to edit this parameter from UI.
char*GifCaptureEncoderParams=NULL;// Video encoder params for GIF output (not owned, stored externally).
intGifCaptureEncoderParamsSize=0;// Optional. Set in order to edit this parameter from UI.
// [Internal]
ImRect_CaptureRect;// Viewport rect that is being captured.
ImRect_CapturedWindowRect;// Top-left corner of region that covers all windows included in capture. This is not same as _CaptureRect.Min when capturing explicitly specified rect.
int_ChunkNo=0;// Number of chunk that is being captured when capture spans multiple frames.
int_FrameNo=0;// Frame number during capture process that spans multiple frames.
ImVec2_MouseRelativeToWindowPos;// Mouse cursor position relative to captured window (when _StitchAll is in use).
ImGuiWindow*_HoveredWindow=NULL;// Window which was hovered at capture start.
constImGuiCaptureArgs*_CaptureArgs=NULL;// Current capture args. Set only if capture is in progress.
ImVector<ImGuiCaptureWindowData>_WindowsData;// Backup windows that will have their rect modified and restored. args->InCaptureWindows can not be used because popups may get closed during capture and no longer appear in that list.
// [Internal] Video recording
bool_VideoRecording=false;// Flag indicating that video recording is in progress.
double_VideoLastFrameTime=0;// Time when last video frame was recorded.
FILE*_VideoEncoderPipe=NULL;// File writing to stdin of video encoder process.
// [Internal] Backups
bool_BackupMouseDrawCursor=false;// Initial value of g.IO.MouseDrawCursor
ImVec2_BackupDisplayWindowPadding;// Backup padding. We set it to {0, 0} during capture.
ImVec2_BackupDisplaySafeAreaPadding;// Backup padding. We set it to {0, 0} during capture.
// (when using ImGuiTestEngine scripting API you may not need to use this at all)
structIMGUI_APIImGuiCaptureToolUI
{
floatSnapGridSize=32.0f;// Size of the grid cell for "snap to grid" functionality.
charOutputLastFilename[256]="";// File name of last captured file.
char*VideoCaptureExtension=NULL;// Video file extension (e.g. ".gif" or ".mp4")
intVideoCaptureExtensionSize=0;// Optional. Set in order to edit this parameter from UI.
ImGuiCaptureArgs_CaptureArgs;// Capture args
bool_StateIsPickingWindow=false;
bool_StateIsCapturing=false;
ImVector<ImGuiID>_SelectedWindows;
char_OutputFileTemplate[256]="";//
int_FileCounter=0;// Counter which may be appended to file name when saving. By default, counting starts from 1. When done this field holds number of saved files.
// Public
ImGuiCaptureToolUI();
voidShowCaptureToolWindow(ImGuiCaptureContext*context,bool*p_open=NULL);// Render a capture tool window with various options and utilities.
// [Internal]
void_CaptureWindowPicker(ImGuiCaptureArgs*args);// Render a window picker that captures picked window to file specified in file_name.
void_CaptureWindowsSelector(ImGuiCaptureContext*context,ImGuiCaptureArgs*args);// Render a selector for selecting multiple windows for capture.
void_SnapWindowsToGrid(floatcell_size);// Snap edges of all visible windows to a virtual grid.
bool_InitializeOutputFile();// Format output file template into capture args struct and ensure target directory exists.