DVX_GUI/dvx/dvxApp.h

127 lines
4.4 KiB
C

// dvx_app.h — Layer 5: Application API for DV/X GUI
#ifndef DVX_APP_H
#define DVX_APP_H
#include "dvxTypes.h"
#include "dvxVideo.h"
#include "dvxDraw.h"
#include "dvxComp.h"
#include "dvxWm.h"
#include <time.h>
// ============================================================
// Application context
// ============================================================
typedef struct AppContextT {
DisplayT display;
WindowStackT stack;
DirtyListT dirty;
BlitOpsT blitOps;
BitmapFontT font;
ColorSchemeT colors;
PopupStateT popup;
SysMenuStateT sysMenu;
KbMoveResizeT kbMoveResize;
CursorT cursors[5]; // indexed by CURSOR_xxx
int32_t cursorId; // active cursor shape
uint32_t cursorFg; // pre-packed cursor colors
uint32_t cursorBg;
bool running;
int32_t mouseX;
int32_t mouseY;
int32_t mouseButtons;
int32_t keyModifiers; // current BIOS shift state (KEY_MOD_xxx)
int32_t prevMouseX;
int32_t prevMouseY;
int32_t prevMouseButtons;
clock_t lastIconClickTime;
int32_t lastIconClickId; // window ID of last-clicked minimized icon (-1 = none)
clock_t lastCloseClickTime;
int32_t lastCloseClickId; // window ID of last-clicked close gadget (-1 = none)
int32_t iconRefreshIdx; // next minimized icon to refresh (staggered)
int32_t frameCount; // frame counter for periodic tasks
void (*idleCallback)(void *ctx); // called instead of yield when non-NULL
void *idleCtx;
WindowT *modalWindow; // if non-NULL, only this window receives input
// Tooltip state
clock_t tooltipHoverStart; // when mouse stopped moving
const char *tooltipText; // text to show (NULL = hidden)
int32_t tooltipX; // screen position
int32_t tooltipY;
int32_t tooltipW; // size (pre-computed)
int32_t tooltipH;
} AppContextT;
// Initialize the application (VESA mode, input, etc.)
int32_t dvxInit(AppContextT *ctx, int32_t requestedW, int32_t requestedH, int32_t preferredBpp);
// Shut down and restore text mode
void dvxShutdown(AppContextT *ctx);
// Run the main event loop (returns when ctx->running is set to false)
void dvxRun(AppContextT *ctx);
// Process one iteration of the event loop.
// Returns true if the GUI is still running, false if it wants to exit.
bool dvxUpdate(AppContextT *ctx);
// Create a window
WindowT *dvxCreateWindow(AppContextT *ctx, const char *title, int32_t x, int32_t y, int32_t w, int32_t h, bool resizable);
// Destroy a window
void dvxDestroyWindow(AppContextT *ctx, WindowT *win);
// Resize a window to fit its widget tree's minimum size
void dvxFitWindow(AppContextT *ctx, WindowT *win);
// Invalidate a region of a window's content area (triggers repaint)
void dvxInvalidateRect(AppContextT *ctx, WindowT *win, int32_t x, int32_t y, int32_t w, int32_t h);
// Invalidate entire window content
void dvxInvalidateWindow(AppContextT *ctx, WindowT *win);
// Minimize a window (show as icon at bottom of screen)
void dvxMinimizeWindow(AppContextT *ctx, WindowT *win);
// Maximize a window (expand to fill screen or maxW/maxH)
void dvxMaximizeWindow(AppContextT *ctx, WindowT *win);
// Request exit from main loop
void dvxQuit(AppContextT *ctx);
// Set window title
void dvxSetTitle(AppContextT *ctx, WindowT *win, const char *title);
// Get the default font
const BitmapFontT *dvxGetFont(const AppContextT *ctx);
// Get the color scheme
const ColorSchemeT *dvxGetColors(const AppContextT *ctx);
// Get the display
DisplayT *dvxGetDisplay(AppContextT *ctx);
// Get blit ops
const BlitOpsT *dvxGetBlitOps(const AppContextT *ctx);
// Load an icon for a window from an image file
int32_t dvxSetWindowIcon(AppContextT *ctx, WindowT *win, const char *path);
// Create an accelerator table (caller must free with dvxFreeAccelTable)
AccelTableT *dvxCreateAccelTable(void);
// Free an accelerator table
void dvxFreeAccelTable(AccelTableT *table);
// Add an entry to an accelerator table
void dvxAddAccel(AccelTableT *table, int32_t key, int32_t modifiers, int32_t cmdId);
// Copy text to the shared clipboard
void dvxClipboardCopy(const char *text, int32_t len);
// Get clipboard contents (returns pointer to internal buffer, NULL if empty)
const char *dvxClipboardGet(int32_t *outLen);
#endif // DVX_APP_H