From cb58ced9d9abcd672c79f20930bf1a5f1426a523 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Thu, 8 Oct 2015 18:03:24 -0400 Subject: [PATCH] Started merging uiArea back into main. ui.h merged. --- gtkarea/ui.h | 230 ---------------------------------------------- macarea/ui.h | 230 ---------------------------------------------- ui.h | 233 +++++++++++++++++++++++++++++++++++++++++++++++ winarea_d2d/ui.h | 230 ---------------------------------------------- 4 files changed, 233 insertions(+), 690 deletions(-) delete mode 100644 gtkarea/ui.h delete mode 100644 macarea/ui.h delete mode 100644 winarea_d2d/ui.h diff --git a/gtkarea/ui.h b/gtkarea/ui.h deleted file mode 100644 index 461cb8b1..00000000 --- a/gtkarea/ui.h +++ /dev/null @@ -1,230 +0,0 @@ -// 4 september 2015 - -typedef struct uiArea uiArea; -typedef struct uiAreaHandler uiAreaHandler; -typedef struct uiAreaDrawParams uiAreaDrawParams; -typedef struct uiAreaMouseEvent uiAreaMouseEvent; -typedef struct uiAreaKeyEvent uiAreaKeyEvent; - -typedef struct uiDrawContext uiDrawContext; - -struct uiAreaHandler { - void (*Draw)(uiAreaHandler *, uiArea *, uiAreaDrawParams *); - uintmax_t (*HScrollMax)(uiAreaHandler *, uiArea *); - uintmax_t (*VScrollMax)(uiAreaHandler *, uiArea *); - int (*RedrawOnResize)(uiAreaHandler *, uiArea *); - void (*MouseEvent)(uiAreaHandler *, uiArea *, uiAreaMouseEvent *); - void (*DragBroken)(uiAreaHandler *, uiArea *); - int (*KeyEvent)(uiAreaHandler *, uiArea *, uiAreaKeyEvent *); -}; - -struct uiAreaDrawParams { - uiDrawContext *Context; - - intmax_t ClientWidth; - intmax_t ClientHeight; - - intmax_t ClipX; - intmax_t ClipY; - intmax_t ClipWidth; - intmax_t ClipHeight; - - int DPIX; - int DPIY; - - intmax_t HScrollPos; - intmax_t VScrollPos; -}; - -// TODO dotting/dashing - -typedef struct uiDrawPath uiDrawPath; -typedef struct uiDrawBrush uiDrawBrush; -typedef struct uiDrawStrokeParams uiDrawStrokeParams; - -typedef enum uiDrawBrushType uiDrawBrushType; -typedef struct uiDrawBrushGradientStop uiDrawBrushGradientStop; - -typedef enum uiDrawLineCap uiDrawLineCap; -typedef enum uiDrawLineJoin uiDrawLineJoin; -typedef enum uiDrawFillMode uiDrawFillMode; - -enum uiDrawBrushType { - uiDrawBrushTypeSolid, - uiDrawBrushTypeLinearGradient, - uiDrawBrushTypeRadialGradient, - uiDrawBrushTypeImage, -}; - -enum uiDrawLineCap { - uiDrawLineCapFlat, - uiDrawLineCapRound, - uiDrawLineCapSquare, -}; - -enum uiDrawLineJoin { - uiDrawLineJoinMiter, - uiDrawLineJoinRound, - uiDrawLineJoinBevel, -}; - -// this is the default for botoh cairo and GDI -// Core Graphics doesn't explicitly specify a default, but NSBezierPath allows you to choose one, and this is the initial value -// so we're good to use it too! -#define uiDrawDefaultMiterLimit 10.0 - -enum uiDrawFillMode { - uiDrawFillModeWinding, - uiDrawFillModeAlternate, -}; - -struct uiDrawBrush { - uiDrawBrushType Type; - - // solid brushes - double R; - double G; - double B; - double A; - - // gradient brushes - double X0; // linear: start X, radial: start X - double Y0; // linear: start Y, radial: start Y - double X1; // linear: end X, radial: outer circle center X - double Y1; // linear: end Y, radial: outer circle center Y - double OuterRadius; // radial gradients only - uiDrawBrushGradientStop *Stops; - size_t NumStops; - // TODO extend mode - // cairo: none, repeat, reflect, pad; no individual control - // Direct2D: repeat, reflect, pad; no individual control - // Core Graphics: none, pad; before and after individually - // TODO cairo documentation is inconsistent about pad - - // TODO images - - // TODO transforms -}; - -struct uiDrawBrushGradientStop { - double Pos; - double R; - double G; - double B; - double A; -}; - -struct uiDrawStrokeParams { - uiDrawLineCap Cap; - uiDrawLineJoin Join; - double Thickness; - double MiterLimit; -}; - -uiDrawPath *uiDrawNewPath(uiDrawFillMode); -void uiDrawFreePath(uiDrawPath *); - -void uiDrawPathNewFigure(uiDrawPath *, double, double); -void uiDrawPathNewFigureWithArc(uiDrawPath *, double, double, double, double, double); -void uiDrawPathLineTo(uiDrawPath *, double, double); -// notes: angles are both relative to 0 and go counterclockwise -// TODO is the initial line segment on cairo and OS X a proper join? -void uiDrawPathArcTo(uiDrawPath *, double, double, double, double, double); -void uiDrawPathBezierTo(uiDrawPath *, double, double, double, double, double, double); -// TODO quadratic bezier -void uiDrawPathCloseFigure(uiDrawPath *); - -// TODO effect of these when a figure is already started -void uiDrawPathAddRectangle(uiDrawPath *, double, double, double, double); - -void uiDrawPathEnd(uiDrawPath *); - -void uiDrawStroke(uiDrawContext *, uiDrawPath *, uiDrawBrush *, uiDrawStrokeParams *); -void uiDrawFill(uiDrawContext *, uiDrawPath *, uiDrawBrush *); - -// TODO primitives: -// - rounded rectangles -// - elliptical arcs -// - quadratic bezier curves - -typedef enum uiModifiers uiModifiers; - -enum uiModifiers { - uiModifierCtrl = 1 << 0, - uiModifierAlt = 1 << 1, - uiModifierShift = 1 << 2, - uiModifierSuper = 1 << 3, -}; - -struct uiAreaMouseEvent { - intmax_t X; - intmax_t Y; - - intmax_t ClientWidth; - intmax_t ClientHeight; - intmax_t HScrollPos; - intmax_t VScrollPos; - - uintmax_t Down; - uintmax_t Up; - - uintmax_t Count; - - uiModifiers Modifiers; - - uint64_t Held1To64; -}; - -typedef enum uiExtKey uiExtKey; - -enum uiExtKey { - uiExtKeyEscape = 1, - uiExtKeyInsert, // equivalent to "Help" on Apple keyboards - uiExtKeyDelete, - uiExtKeyHome, - uiExtKeyEnd, - uiExtKeyPageUp, - uiExtKeyPageDown, - uiExtKeyUp, - uiExtKeyDown, - uiExtKeyLeft, - uiExtKeyRight, - uiExtKeyF1, // F1..F12 are guaranteed to be consecutive - uiExtKeyF2, - uiExtKeyF3, - uiExtKeyF4, - uiExtKeyF5, - uiExtKeyF6, - uiExtKeyF7, - uiExtKeyF8, - uiExtKeyF9, - uiExtKeyF10, - uiExtKeyF11, - uiExtKeyF12, - uiExtKeyN0, // numpad keys; independent of Num Lock state - uiExtKeyN1, // N0..N9 are guaranteed to be consecutive - uiExtKeyN2, - uiExtKeyN3, - uiExtKeyN4, - uiExtKeyN5, - uiExtKeyN6, - uiExtKeyN7, - uiExtKeyN8, - uiExtKeyN9, - uiExtKeyNDot, - uiExtKeyNEnter, - uiExtKeyNAdd, - uiExtKeyNSubtract, - uiExtKeyNMultiply, - uiExtKeyNDivide, -}; - -struct uiAreaKeyEvent { - char Key; - uiExtKey ExtKey; - uiModifiers Modifier; - - uiModifiers Modifiers; - - int Up; -}; diff --git a/macarea/ui.h b/macarea/ui.h deleted file mode 100644 index 461cb8b1..00000000 --- a/macarea/ui.h +++ /dev/null @@ -1,230 +0,0 @@ -// 4 september 2015 - -typedef struct uiArea uiArea; -typedef struct uiAreaHandler uiAreaHandler; -typedef struct uiAreaDrawParams uiAreaDrawParams; -typedef struct uiAreaMouseEvent uiAreaMouseEvent; -typedef struct uiAreaKeyEvent uiAreaKeyEvent; - -typedef struct uiDrawContext uiDrawContext; - -struct uiAreaHandler { - void (*Draw)(uiAreaHandler *, uiArea *, uiAreaDrawParams *); - uintmax_t (*HScrollMax)(uiAreaHandler *, uiArea *); - uintmax_t (*VScrollMax)(uiAreaHandler *, uiArea *); - int (*RedrawOnResize)(uiAreaHandler *, uiArea *); - void (*MouseEvent)(uiAreaHandler *, uiArea *, uiAreaMouseEvent *); - void (*DragBroken)(uiAreaHandler *, uiArea *); - int (*KeyEvent)(uiAreaHandler *, uiArea *, uiAreaKeyEvent *); -}; - -struct uiAreaDrawParams { - uiDrawContext *Context; - - intmax_t ClientWidth; - intmax_t ClientHeight; - - intmax_t ClipX; - intmax_t ClipY; - intmax_t ClipWidth; - intmax_t ClipHeight; - - int DPIX; - int DPIY; - - intmax_t HScrollPos; - intmax_t VScrollPos; -}; - -// TODO dotting/dashing - -typedef struct uiDrawPath uiDrawPath; -typedef struct uiDrawBrush uiDrawBrush; -typedef struct uiDrawStrokeParams uiDrawStrokeParams; - -typedef enum uiDrawBrushType uiDrawBrushType; -typedef struct uiDrawBrushGradientStop uiDrawBrushGradientStop; - -typedef enum uiDrawLineCap uiDrawLineCap; -typedef enum uiDrawLineJoin uiDrawLineJoin; -typedef enum uiDrawFillMode uiDrawFillMode; - -enum uiDrawBrushType { - uiDrawBrushTypeSolid, - uiDrawBrushTypeLinearGradient, - uiDrawBrushTypeRadialGradient, - uiDrawBrushTypeImage, -}; - -enum uiDrawLineCap { - uiDrawLineCapFlat, - uiDrawLineCapRound, - uiDrawLineCapSquare, -}; - -enum uiDrawLineJoin { - uiDrawLineJoinMiter, - uiDrawLineJoinRound, - uiDrawLineJoinBevel, -}; - -// this is the default for botoh cairo and GDI -// Core Graphics doesn't explicitly specify a default, but NSBezierPath allows you to choose one, and this is the initial value -// so we're good to use it too! -#define uiDrawDefaultMiterLimit 10.0 - -enum uiDrawFillMode { - uiDrawFillModeWinding, - uiDrawFillModeAlternate, -}; - -struct uiDrawBrush { - uiDrawBrushType Type; - - // solid brushes - double R; - double G; - double B; - double A; - - // gradient brushes - double X0; // linear: start X, radial: start X - double Y0; // linear: start Y, radial: start Y - double X1; // linear: end X, radial: outer circle center X - double Y1; // linear: end Y, radial: outer circle center Y - double OuterRadius; // radial gradients only - uiDrawBrushGradientStop *Stops; - size_t NumStops; - // TODO extend mode - // cairo: none, repeat, reflect, pad; no individual control - // Direct2D: repeat, reflect, pad; no individual control - // Core Graphics: none, pad; before and after individually - // TODO cairo documentation is inconsistent about pad - - // TODO images - - // TODO transforms -}; - -struct uiDrawBrushGradientStop { - double Pos; - double R; - double G; - double B; - double A; -}; - -struct uiDrawStrokeParams { - uiDrawLineCap Cap; - uiDrawLineJoin Join; - double Thickness; - double MiterLimit; -}; - -uiDrawPath *uiDrawNewPath(uiDrawFillMode); -void uiDrawFreePath(uiDrawPath *); - -void uiDrawPathNewFigure(uiDrawPath *, double, double); -void uiDrawPathNewFigureWithArc(uiDrawPath *, double, double, double, double, double); -void uiDrawPathLineTo(uiDrawPath *, double, double); -// notes: angles are both relative to 0 and go counterclockwise -// TODO is the initial line segment on cairo and OS X a proper join? -void uiDrawPathArcTo(uiDrawPath *, double, double, double, double, double); -void uiDrawPathBezierTo(uiDrawPath *, double, double, double, double, double, double); -// TODO quadratic bezier -void uiDrawPathCloseFigure(uiDrawPath *); - -// TODO effect of these when a figure is already started -void uiDrawPathAddRectangle(uiDrawPath *, double, double, double, double); - -void uiDrawPathEnd(uiDrawPath *); - -void uiDrawStroke(uiDrawContext *, uiDrawPath *, uiDrawBrush *, uiDrawStrokeParams *); -void uiDrawFill(uiDrawContext *, uiDrawPath *, uiDrawBrush *); - -// TODO primitives: -// - rounded rectangles -// - elliptical arcs -// - quadratic bezier curves - -typedef enum uiModifiers uiModifiers; - -enum uiModifiers { - uiModifierCtrl = 1 << 0, - uiModifierAlt = 1 << 1, - uiModifierShift = 1 << 2, - uiModifierSuper = 1 << 3, -}; - -struct uiAreaMouseEvent { - intmax_t X; - intmax_t Y; - - intmax_t ClientWidth; - intmax_t ClientHeight; - intmax_t HScrollPos; - intmax_t VScrollPos; - - uintmax_t Down; - uintmax_t Up; - - uintmax_t Count; - - uiModifiers Modifiers; - - uint64_t Held1To64; -}; - -typedef enum uiExtKey uiExtKey; - -enum uiExtKey { - uiExtKeyEscape = 1, - uiExtKeyInsert, // equivalent to "Help" on Apple keyboards - uiExtKeyDelete, - uiExtKeyHome, - uiExtKeyEnd, - uiExtKeyPageUp, - uiExtKeyPageDown, - uiExtKeyUp, - uiExtKeyDown, - uiExtKeyLeft, - uiExtKeyRight, - uiExtKeyF1, // F1..F12 are guaranteed to be consecutive - uiExtKeyF2, - uiExtKeyF3, - uiExtKeyF4, - uiExtKeyF5, - uiExtKeyF6, - uiExtKeyF7, - uiExtKeyF8, - uiExtKeyF9, - uiExtKeyF10, - uiExtKeyF11, - uiExtKeyF12, - uiExtKeyN0, // numpad keys; independent of Num Lock state - uiExtKeyN1, // N0..N9 are guaranteed to be consecutive - uiExtKeyN2, - uiExtKeyN3, - uiExtKeyN4, - uiExtKeyN5, - uiExtKeyN6, - uiExtKeyN7, - uiExtKeyN8, - uiExtKeyN9, - uiExtKeyNDot, - uiExtKeyNEnter, - uiExtKeyNAdd, - uiExtKeyNSubtract, - uiExtKeyNMultiply, - uiExtKeyNDivide, -}; - -struct uiAreaKeyEvent { - char Key; - uiExtKey ExtKey; - uiModifiers Modifier; - - uiModifiers Modifiers; - - int Up; -}; diff --git a/ui.h b/ui.h index 0d3fd24d..2cd60577 100644 --- a/ui.h +++ b/ui.h @@ -246,4 +246,237 @@ _UI_EXTERN char *uiSaveFile(void); _UI_EXTERN void uiMsgBox(const char *title, const char *description); _UI_EXTERN void uiMsgBoxError(const char *title, const char *description); +typedef struct uiArea uiArea; +typedef struct uiAreaHandler uiAreaHandler; +typedef struct uiAreaDrawParams uiAreaDrawParams; +typedef struct uiAreaMouseEvent uiAreaMouseEvent; +typedef struct uiAreaKeyEvent uiAreaKeyEvent; + +typedef struct uiDrawContext uiDrawContext; + +struct uiAreaHandler { + void (*Draw)(uiAreaHandler *, uiArea *, uiAreaDrawParams *); + uintmax_t (*HScrollMax)(uiAreaHandler *, uiArea *); + uintmax_t (*VScrollMax)(uiAreaHandler *, uiArea *); + int (*RedrawOnResize)(uiAreaHandler *, uiArea *); + void (*MouseEvent)(uiAreaHandler *, uiArea *, uiAreaMouseEvent *); + void (*DragBroken)(uiAreaHandler *, uiArea *); + int (*KeyEvent)(uiAreaHandler *, uiArea *, uiAreaKeyEvent *); +}; + +_UI_EXTERN uintmax_t uiMenuItemType(void); +#define uiMenuItem(this) ((uiMenuItem *) uiIsA((this), uiMenuItemType(), 1)) +_UI_EXTERN uiArea *uiNewArea(uiAreaHandler *ah); + +struct uiAreaDrawParams { + uiDrawContext *Context; + + intmax_t ClientWidth; + intmax_t ClientHeight; + + intmax_t ClipX; + intmax_t ClipY; + intmax_t ClipWidth; + intmax_t ClipHeight; + + int DPIX; + int DPIY; + + intmax_t HScrollPos; + intmax_t VScrollPos; +}; + +// TODO dotting/dashing + +typedef struct uiDrawPath uiDrawPath; +typedef struct uiDrawBrush uiDrawBrush; +typedef struct uiDrawStrokeParams uiDrawStrokeParams; + +typedef enum uiDrawBrushType uiDrawBrushType; +typedef struct uiDrawBrushGradientStop uiDrawBrushGradientStop; + +typedef enum uiDrawLineCap uiDrawLineCap; +typedef enum uiDrawLineJoin uiDrawLineJoin; +typedef enum uiDrawFillMode uiDrawFillMode; + +enum uiDrawBrushType { + uiDrawBrushTypeSolid, + uiDrawBrushTypeLinearGradient, + uiDrawBrushTypeRadialGradient, + uiDrawBrushTypeImage, +}; + +enum uiDrawLineCap { + uiDrawLineCapFlat, + uiDrawLineCapRound, + uiDrawLineCapSquare, +}; + +enum uiDrawLineJoin { + uiDrawLineJoinMiter, + uiDrawLineJoinRound, + uiDrawLineJoinBevel, +}; + +// this is the default for botoh cairo and GDI +// Core Graphics doesn't explicitly specify a default, but NSBezierPath allows you to choose one, and this is the initial value +// so we're good to use it too! +#define uiDrawDefaultMiterLimit 10.0 + +enum uiDrawFillMode { + uiDrawFillModeWinding, + uiDrawFillModeAlternate, +}; + +struct uiDrawBrush { + uiDrawBrushType Type; + + // solid brushes + double R; + double G; + double B; + double A; + + // gradient brushes + double X0; // linear: start X, radial: start X + double Y0; // linear: start Y, radial: start Y + double X1; // linear: end X, radial: outer circle center X + double Y1; // linear: end Y, radial: outer circle center Y + double OuterRadius; // radial gradients only + uiDrawBrushGradientStop *Stops; + size_t NumStops; + // TODO extend mode + // cairo: none, repeat, reflect, pad; no individual control + // Direct2D: repeat, reflect, pad; no individual control + // Core Graphics: none, pad; before and after individually + // TODO cairo documentation is inconsistent about pad + + // TODO images + + // TODO transforms +}; + +struct uiDrawBrushGradientStop { + double Pos; + double R; + double G; + double B; + double A; +}; + +struct uiDrawStrokeParams { + uiDrawLineCap Cap; + uiDrawLineJoin Join; + double Thickness; + double MiterLimit; +}; + +_UI_EXTERN uiDrawPath *uiDrawNewPath(uiDrawFillMode fillMode); +_UI_EXTERN void uiDrawFreePath(uiDrawPath *p); + +_UI_EXTERN void uiDrawPathNewFigure(uiDrawPath *p, double x, double y); +_UI_EXTERN void uiDrawPathNewFigureWithArc(uiDrawPath *p, double xCenter, double yCenter, double radius, double startAngle, double endAngle); +_UI_EXTERN void uiDrawPathLineTo(uiDrawPath *p, double x, double y); +// notes: angles are both relative to 0 and go counterclockwise +// TODO is the initial line segment on cairo and OS X a proper join? +_UI_EXTERN void uiDrawPathArcTo(uiDrawPath *p, double xCenter, double yCenter, double radius, double startAngle, double endAngle); +_UI_EXTERN void uiDrawPathBezierTo(uiDrawPath *p, double c1x, double c1y, double c2x, double c2y, double endX, double endY); +// TODO quadratic bezier +_UI_EXTERN void uiDrawPathCloseFigure(uiDrawPath *p); + +// TODO effect of these when a figure is already started +_UI_EXTERN void uiDrawPathAddRectangle(uiDrawPath *p, double x, double y, double width, double height); + +_UI_EXTERN void uiDrawPathEnd(uiDrawPath *p); + +_UI_EXTERN void uiDrawStroke(uiDrawContext *c, uiDrawPath *path, uiDrawBrush *b, uiDrawStrokeParams *p); +_UI_EXTERN void uiDrawFill(uiDrawContext *c, uiDrawPath *path, uiDrawBrush *b); + +// TODO primitives: +// - rounded rectangles +// - elliptical arcs +// - quadratic bezier curves + +typedef enum uiModifiers uiModifiers; + +enum uiModifiers { + uiModifierCtrl = 1 << 0, + uiModifierAlt = 1 << 1, + uiModifierShift = 1 << 2, + uiModifierSuper = 1 << 3, +}; + +struct uiAreaMouseEvent { + intmax_t X; + intmax_t Y; + + intmax_t ClientWidth; + intmax_t ClientHeight; + intmax_t HScrollPos; + intmax_t VScrollPos; + + uintmax_t Down; + uintmax_t Up; + + uintmax_t Count; + + uiModifiers Modifiers; + + uint64_t Held1To64; +}; + +typedef enum uiExtKey uiExtKey; + +enum uiExtKey { + uiExtKeyEscape = 1, + uiExtKeyInsert, // equivalent to "Help" on Apple keyboards + uiExtKeyDelete, + uiExtKeyHome, + uiExtKeyEnd, + uiExtKeyPageUp, + uiExtKeyPageDown, + uiExtKeyUp, + uiExtKeyDown, + uiExtKeyLeft, + uiExtKeyRight, + uiExtKeyF1, // F1..F12 are guaranteed to be consecutive + uiExtKeyF2, + uiExtKeyF3, + uiExtKeyF4, + uiExtKeyF5, + uiExtKeyF6, + uiExtKeyF7, + uiExtKeyF8, + uiExtKeyF9, + uiExtKeyF10, + uiExtKeyF11, + uiExtKeyF12, + uiExtKeyN0, // numpad keys; independent of Num Lock state + uiExtKeyN1, // N0..N9 are guaranteed to be consecutive + uiExtKeyN2, + uiExtKeyN3, + uiExtKeyN4, + uiExtKeyN5, + uiExtKeyN6, + uiExtKeyN7, + uiExtKeyN8, + uiExtKeyN9, + uiExtKeyNDot, + uiExtKeyNEnter, + uiExtKeyNAdd, + uiExtKeyNSubtract, + uiExtKeyNMultiply, + uiExtKeyNDivide, +}; + +struct uiAreaKeyEvent { + char Key; + uiExtKey ExtKey; + uiModifiers Modifier; + + uiModifiers Modifiers; + + int Up; +}; + #endif diff --git a/winarea_d2d/ui.h b/winarea_d2d/ui.h deleted file mode 100644 index 461cb8b1..00000000 --- a/winarea_d2d/ui.h +++ /dev/null @@ -1,230 +0,0 @@ -// 4 september 2015 - -typedef struct uiArea uiArea; -typedef struct uiAreaHandler uiAreaHandler; -typedef struct uiAreaDrawParams uiAreaDrawParams; -typedef struct uiAreaMouseEvent uiAreaMouseEvent; -typedef struct uiAreaKeyEvent uiAreaKeyEvent; - -typedef struct uiDrawContext uiDrawContext; - -struct uiAreaHandler { - void (*Draw)(uiAreaHandler *, uiArea *, uiAreaDrawParams *); - uintmax_t (*HScrollMax)(uiAreaHandler *, uiArea *); - uintmax_t (*VScrollMax)(uiAreaHandler *, uiArea *); - int (*RedrawOnResize)(uiAreaHandler *, uiArea *); - void (*MouseEvent)(uiAreaHandler *, uiArea *, uiAreaMouseEvent *); - void (*DragBroken)(uiAreaHandler *, uiArea *); - int (*KeyEvent)(uiAreaHandler *, uiArea *, uiAreaKeyEvent *); -}; - -struct uiAreaDrawParams { - uiDrawContext *Context; - - intmax_t ClientWidth; - intmax_t ClientHeight; - - intmax_t ClipX; - intmax_t ClipY; - intmax_t ClipWidth; - intmax_t ClipHeight; - - int DPIX; - int DPIY; - - intmax_t HScrollPos; - intmax_t VScrollPos; -}; - -// TODO dotting/dashing - -typedef struct uiDrawPath uiDrawPath; -typedef struct uiDrawBrush uiDrawBrush; -typedef struct uiDrawStrokeParams uiDrawStrokeParams; - -typedef enum uiDrawBrushType uiDrawBrushType; -typedef struct uiDrawBrushGradientStop uiDrawBrushGradientStop; - -typedef enum uiDrawLineCap uiDrawLineCap; -typedef enum uiDrawLineJoin uiDrawLineJoin; -typedef enum uiDrawFillMode uiDrawFillMode; - -enum uiDrawBrushType { - uiDrawBrushTypeSolid, - uiDrawBrushTypeLinearGradient, - uiDrawBrushTypeRadialGradient, - uiDrawBrushTypeImage, -}; - -enum uiDrawLineCap { - uiDrawLineCapFlat, - uiDrawLineCapRound, - uiDrawLineCapSquare, -}; - -enum uiDrawLineJoin { - uiDrawLineJoinMiter, - uiDrawLineJoinRound, - uiDrawLineJoinBevel, -}; - -// this is the default for botoh cairo and GDI -// Core Graphics doesn't explicitly specify a default, but NSBezierPath allows you to choose one, and this is the initial value -// so we're good to use it too! -#define uiDrawDefaultMiterLimit 10.0 - -enum uiDrawFillMode { - uiDrawFillModeWinding, - uiDrawFillModeAlternate, -}; - -struct uiDrawBrush { - uiDrawBrushType Type; - - // solid brushes - double R; - double G; - double B; - double A; - - // gradient brushes - double X0; // linear: start X, radial: start X - double Y0; // linear: start Y, radial: start Y - double X1; // linear: end X, radial: outer circle center X - double Y1; // linear: end Y, radial: outer circle center Y - double OuterRadius; // radial gradients only - uiDrawBrushGradientStop *Stops; - size_t NumStops; - // TODO extend mode - // cairo: none, repeat, reflect, pad; no individual control - // Direct2D: repeat, reflect, pad; no individual control - // Core Graphics: none, pad; before and after individually - // TODO cairo documentation is inconsistent about pad - - // TODO images - - // TODO transforms -}; - -struct uiDrawBrushGradientStop { - double Pos; - double R; - double G; - double B; - double A; -}; - -struct uiDrawStrokeParams { - uiDrawLineCap Cap; - uiDrawLineJoin Join; - double Thickness; - double MiterLimit; -}; - -uiDrawPath *uiDrawNewPath(uiDrawFillMode); -void uiDrawFreePath(uiDrawPath *); - -void uiDrawPathNewFigure(uiDrawPath *, double, double); -void uiDrawPathNewFigureWithArc(uiDrawPath *, double, double, double, double, double); -void uiDrawPathLineTo(uiDrawPath *, double, double); -// notes: angles are both relative to 0 and go counterclockwise -// TODO is the initial line segment on cairo and OS X a proper join? -void uiDrawPathArcTo(uiDrawPath *, double, double, double, double, double); -void uiDrawPathBezierTo(uiDrawPath *, double, double, double, double, double, double); -// TODO quadratic bezier -void uiDrawPathCloseFigure(uiDrawPath *); - -// TODO effect of these when a figure is already started -void uiDrawPathAddRectangle(uiDrawPath *, double, double, double, double); - -void uiDrawPathEnd(uiDrawPath *); - -void uiDrawStroke(uiDrawContext *, uiDrawPath *, uiDrawBrush *, uiDrawStrokeParams *); -void uiDrawFill(uiDrawContext *, uiDrawPath *, uiDrawBrush *); - -// TODO primitives: -// - rounded rectangles -// - elliptical arcs -// - quadratic bezier curves - -typedef enum uiModifiers uiModifiers; - -enum uiModifiers { - uiModifierCtrl = 1 << 0, - uiModifierAlt = 1 << 1, - uiModifierShift = 1 << 2, - uiModifierSuper = 1 << 3, -}; - -struct uiAreaMouseEvent { - intmax_t X; - intmax_t Y; - - intmax_t ClientWidth; - intmax_t ClientHeight; - intmax_t HScrollPos; - intmax_t VScrollPos; - - uintmax_t Down; - uintmax_t Up; - - uintmax_t Count; - - uiModifiers Modifiers; - - uint64_t Held1To64; -}; - -typedef enum uiExtKey uiExtKey; - -enum uiExtKey { - uiExtKeyEscape = 1, - uiExtKeyInsert, // equivalent to "Help" on Apple keyboards - uiExtKeyDelete, - uiExtKeyHome, - uiExtKeyEnd, - uiExtKeyPageUp, - uiExtKeyPageDown, - uiExtKeyUp, - uiExtKeyDown, - uiExtKeyLeft, - uiExtKeyRight, - uiExtKeyF1, // F1..F12 are guaranteed to be consecutive - uiExtKeyF2, - uiExtKeyF3, - uiExtKeyF4, - uiExtKeyF5, - uiExtKeyF6, - uiExtKeyF7, - uiExtKeyF8, - uiExtKeyF9, - uiExtKeyF10, - uiExtKeyF11, - uiExtKeyF12, - uiExtKeyN0, // numpad keys; independent of Num Lock state - uiExtKeyN1, // N0..N9 are guaranteed to be consecutive - uiExtKeyN2, - uiExtKeyN3, - uiExtKeyN4, - uiExtKeyN5, - uiExtKeyN6, - uiExtKeyN7, - uiExtKeyN8, - uiExtKeyN9, - uiExtKeyNDot, - uiExtKeyNEnter, - uiExtKeyNAdd, - uiExtKeyNSubtract, - uiExtKeyNMultiply, - uiExtKeyNDivide, -}; - -struct uiAreaKeyEvent { - char Key; - uiExtKey ExtKey; - uiModifiers Modifier; - - uiModifiers Modifiers; - - int Up; -};