2015-08-16 16:14:46 -05:00
|
|
|
// 6 april 2015
|
|
|
|
|
2016-04-24 12:32:20 -05:00
|
|
|
// TODO add a uiVerifyControlType() function that can be used by control implementations to verify controls
|
|
|
|
|
2015-08-16 16:14:46 -05:00
|
|
|
#ifndef __LIBUI_UI_H__
|
|
|
|
#define __LIBUI_UI_H__
|
|
|
|
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
|
2015-11-16 09:55:44 -06:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2015-12-05 17:42:28 -06:00
|
|
|
// TODO add __declspec(dllimport) on windows
|
2015-08-16 16:14:46 -05:00
|
|
|
#ifndef _UI_EXTERN
|
|
|
|
#define _UI_EXTERN extern
|
|
|
|
#endif
|
|
|
|
|
2016-04-23 20:38:51 -05:00
|
|
|
// C++ is really really really really really really dumb about enums, so screw that and just make them anonymous
|
|
|
|
// This has the advantage of being ABI-able should we ever need an ABI...
|
|
|
|
#define _UI_ENUM(s) typedef unsigned int s; enum
|
|
|
|
|
2015-08-16 16:14:46 -05:00
|
|
|
typedef struct uiInitOptions uiInitOptions;
|
|
|
|
|
|
|
|
struct uiInitOptions {
|
|
|
|
size_t Size;
|
|
|
|
};
|
|
|
|
|
|
|
|
_UI_EXTERN const char *uiInit(uiInitOptions *options);
|
|
|
|
_UI_EXTERN void uiUninit(void);
|
|
|
|
_UI_EXTERN void uiFreeInitError(const char *err);
|
|
|
|
|
|
|
|
_UI_EXTERN void uiMain(void);
|
|
|
|
_UI_EXTERN void uiQuit(void);
|
|
|
|
|
2015-12-04 22:42:03 -06:00
|
|
|
// TODO write a test for this after adding multiline entries
|
|
|
|
_UI_EXTERN void uiQueueMain(void (*f)(void *data), void *data);
|
|
|
|
|
2015-08-16 16:14:46 -05:00
|
|
|
_UI_EXTERN void uiOnShouldQuit(int (*f)(void *data), void *data);
|
|
|
|
|
|
|
|
_UI_EXTERN void uiFreeText(char *text);
|
|
|
|
|
|
|
|
typedef struct uiControl uiControl;
|
|
|
|
|
|
|
|
struct uiControl {
|
2016-04-24 12:31:33 -05:00
|
|
|
uint32_t Signature;
|
|
|
|
uint32_t OSSignature;
|
|
|
|
uint32_t TypeSignature;
|
2016-04-24 17:46:03 -05:00
|
|
|
void (*Destroy)(uiControl *);
|
2015-08-16 16:14:46 -05:00
|
|
|
uintptr_t (*Handle)(uiControl *);
|
2016-04-24 17:46:03 -05:00
|
|
|
uiControl *(*Parent)(uiControl *);
|
|
|
|
void (*SetParent)(uiControl *, uiControl *);
|
|
|
|
void (*UpdateChildren)(uiControl *);
|
|
|
|
int (*Toplevel)(uiControl *);
|
|
|
|
int (*Visible)(uiControl *);
|
|
|
|
void (*Show)(uiControl *);
|
|
|
|
void (*Hide)(uiControl *);
|
|
|
|
int (*Enabled)(uiControl *);
|
|
|
|
void (*Enable)(uiControl *);
|
|
|
|
void (*Disable)(uiControl *);
|
2015-08-16 16:14:46 -05:00
|
|
|
};
|
2016-04-24 12:31:33 -05:00
|
|
|
#define uiControl(this) ((uiControl *) (this))
|
2015-08-16 21:19:15 -05:00
|
|
|
_UI_EXTERN void uiControlDestroy(uiControl *);
|
2015-08-16 22:16:42 -05:00
|
|
|
_UI_EXTERN uintptr_t uiControlHandle(uiControl *);
|
2015-08-17 18:11:35 -05:00
|
|
|
_UI_EXTERN uiControl *uiControlParent(uiControl *);
|
2015-08-16 21:19:15 -05:00
|
|
|
_UI_EXTERN void uiControlSetParent(uiControl *, uiControl *);
|
2016-04-24 17:46:03 -05:00
|
|
|
_UI_EXTERN void uiControlUpdateChildren(uiControl *);
|
|
|
|
_UI_EXTERN int uiControlToplevel(uiControl *);
|
|
|
|
_UI_EXTERN int uiControlVisible(uiControl *);
|
2015-08-16 21:19:15 -05:00
|
|
|
_UI_EXTERN void uiControlShow(uiControl *);
|
|
|
|
_UI_EXTERN void uiControlHide(uiControl *);
|
2016-04-24 17:46:03 -05:00
|
|
|
_UI_EXTERN int uiControlEnabled(uiControl *);
|
2015-08-16 21:19:15 -05:00
|
|
|
_UI_EXTERN void uiControlEnable(uiControl *);
|
|
|
|
_UI_EXTERN void uiControlDisable(uiControl *);
|
2015-08-16 16:14:46 -05:00
|
|
|
|
2016-04-24 17:49:28 -05:00
|
|
|
_UI_EXTERN uiControl *uiAllocControl(size_t n, uint32_t OSsig, uint32_t typesig, const char *typenamestr);
|
|
|
|
_UI_EXTERN void uiFreeControl(uiControl *);
|
|
|
|
|
2015-08-16 16:14:46 -05:00
|
|
|
typedef struct uiWindow uiWindow;
|
2016-04-24 12:31:33 -05:00
|
|
|
#define uiWindow(this) ((uiWindow *) (this))
|
2015-08-16 16:14:46 -05:00
|
|
|
_UI_EXTERN char *uiWindowTitle(uiWindow *w);
|
|
|
|
_UI_EXTERN void uiWindowSetTitle(uiWindow *w, const char *title);
|
|
|
|
_UI_EXTERN void uiWindowOnClosing(uiWindow *w, int (*f)(uiWindow *w, void *data), void *data);
|
|
|
|
_UI_EXTERN void uiWindowSetChild(uiWindow *w, uiControl *child);
|
|
|
|
_UI_EXTERN int uiWindowMargined(uiWindow *w);
|
|
|
|
_UI_EXTERN void uiWindowSetMargined(uiWindow *w, int margined);
|
|
|
|
_UI_EXTERN uiWindow *uiNewWindow(const char *title, int width, int height, int hasMenubar);
|
|
|
|
|
|
|
|
typedef struct uiButton uiButton;
|
2016-04-24 12:31:33 -05:00
|
|
|
#define uiButton(this) ((uiButton *) (this))
|
2015-08-16 16:14:46 -05:00
|
|
|
_UI_EXTERN char *uiButtonText(uiButton *b);
|
|
|
|
_UI_EXTERN void uiButtonSetText(uiButton *b, const char *text);
|
|
|
|
_UI_EXTERN void uiButtonOnClicked(uiButton *b, void (*f)(uiButton *b, void *data), void *data);
|
|
|
|
_UI_EXTERN uiButton *uiNewButton(const char *text);
|
|
|
|
|
|
|
|
typedef struct uiBox uiBox;
|
2016-04-24 12:31:33 -05:00
|
|
|
#define uiBox(this) ((uiBox *) (this))
|
2015-08-16 16:14:46 -05:00
|
|
|
_UI_EXTERN void uiBoxAppend(uiBox *b, uiControl *child, int stretchy);
|
|
|
|
_UI_EXTERN void uiBoxDelete(uiBox *b, uintmax_t index);
|
|
|
|
_UI_EXTERN int uiBoxPadded(uiBox *b);
|
|
|
|
_UI_EXTERN void uiBoxSetPadded(uiBox *b, int padded);
|
|
|
|
_UI_EXTERN uiBox *uiNewHorizontalBox(void);
|
|
|
|
_UI_EXTERN uiBox *uiNewVerticalBox(void);
|
|
|
|
|
|
|
|
typedef struct uiEntry uiEntry;
|
2016-04-24 12:31:33 -05:00
|
|
|
#define uiEntry(this) ((uiEntry *) (this))
|
2015-08-16 16:14:46 -05:00
|
|
|
_UI_EXTERN char *uiEntryText(uiEntry *e);
|
|
|
|
_UI_EXTERN void uiEntrySetText(uiEntry *e, const char *text);
|
|
|
|
_UI_EXTERN void uiEntryOnChanged(uiEntry *e, void (*f)(uiEntry *e, void *data), void *data);
|
|
|
|
_UI_EXTERN int uiEntryReadOnly(uiEntry *e);
|
|
|
|
_UI_EXTERN void uiEntrySetReadOnly(uiEntry *e, int readonly);
|
|
|
|
_UI_EXTERN uiEntry *uiNewEntry(void);
|
|
|
|
|
|
|
|
typedef struct uiCheckbox uiCheckbox;
|
2016-04-24 12:31:33 -05:00
|
|
|
#define uiCheckbox(this) ((uiCheckbox *) (this))
|
2015-08-16 16:14:46 -05:00
|
|
|
_UI_EXTERN char *uiCheckboxText(uiCheckbox *c);
|
|
|
|
_UI_EXTERN void uiCheckboxSetText(uiCheckbox *c, const char *text);
|
|
|
|
_UI_EXTERN void uiCheckboxOnToggled(uiCheckbox *c, void (*f)(uiCheckbox *c, void *data), void *data);
|
|
|
|
_UI_EXTERN int uiCheckboxChecked(uiCheckbox *c);
|
|
|
|
_UI_EXTERN void uiCheckboxSetChecked(uiCheckbox *c, int checked);
|
|
|
|
_UI_EXTERN uiCheckbox *uiNewCheckbox(const char *text);
|
|
|
|
|
|
|
|
typedef struct uiLabel uiLabel;
|
2016-04-24 12:31:33 -05:00
|
|
|
#define uiLabel(this) ((uiLabel *) (this))
|
2015-08-16 16:14:46 -05:00
|
|
|
_UI_EXTERN char *uiLabelText(uiLabel *l);
|
|
|
|
_UI_EXTERN void uiLabelSetText(uiLabel *l, const char *text);
|
2015-08-16 22:08:00 -05:00
|
|
|
_UI_EXTERN uiLabel *uiNewLabel(const char *text);
|
2015-08-16 16:14:46 -05:00
|
|
|
|
|
|
|
typedef struct uiTab uiTab;
|
2016-04-24 12:31:33 -05:00
|
|
|
#define uiTab(this) ((uiTab *) (this))
|
2015-08-16 22:08:00 -05:00
|
|
|
_UI_EXTERN void uiTabAppend(uiTab *t, const char *name, uiControl *c);
|
2015-08-16 16:14:46 -05:00
|
|
|
_UI_EXTERN void uiTabInsertAt(uiTab *t, const char *name, uintmax_t before, uiControl *c);
|
|
|
|
_UI_EXTERN void uiTabDelete(uiTab *t, uintmax_t index);
|
|
|
|
_UI_EXTERN uintmax_t uiTabNumPages(uiTab *t);
|
|
|
|
_UI_EXTERN int uiTabMargined(uiTab *t, uintmax_t page);
|
|
|
|
_UI_EXTERN void uiTabSetMargined(uiTab *t, uintmax_t page, int margined);
|
|
|
|
_UI_EXTERN uiTab *uiNewTab(void);
|
|
|
|
|
|
|
|
typedef struct uiGroup uiGroup;
|
2016-04-24 12:31:33 -05:00
|
|
|
#define uiGroup(this) ((uiGroup *) (this))
|
2015-08-16 16:14:46 -05:00
|
|
|
_UI_EXTERN char *uiGroupTitle(uiGroup *g);
|
|
|
|
_UI_EXTERN void uiGroupSetTitle(uiGroup *g, const char *title);
|
|
|
|
_UI_EXTERN void uiGroupSetChild(uiGroup *g, uiControl *c);
|
|
|
|
_UI_EXTERN int uiGroupMargined(uiGroup *g);
|
|
|
|
_UI_EXTERN void uiGroupSetMargined(uiGroup *g, int margined);
|
|
|
|
_UI_EXTERN uiGroup *uiNewGroup(const char *title);
|
|
|
|
|
|
|
|
// spinbox/slider rules:
|
|
|
|
// setting value outside of range will automatically clamp
|
|
|
|
// initial value is minimum
|
|
|
|
// complaint if min >= max?
|
|
|
|
|
|
|
|
typedef struct uiSpinbox uiSpinbox;
|
2016-04-24 12:31:33 -05:00
|
|
|
#define uiSpinbox(this) ((uiSpinbox *) (this))
|
2015-08-16 22:08:00 -05:00
|
|
|
_UI_EXTERN intmax_t uiSpinboxValue(uiSpinbox *s);
|
2015-08-16 16:14:46 -05:00
|
|
|
_UI_EXTERN void uiSpinboxSetValue(uiSpinbox *s, intmax_t value);
|
|
|
|
_UI_EXTERN void uiSpinboxOnChanged(uiSpinbox *s, void (*f)(uiSpinbox *s, void *data), void *data);
|
|
|
|
_UI_EXTERN uiSpinbox *uiNewSpinbox(intmax_t min, intmax_t max);
|
|
|
|
|
|
|
|
typedef struct uiProgressBar uiProgressBar;
|
2016-04-24 12:31:33 -05:00
|
|
|
#define uiProgressBar(this) ((uiProgressBar *) (this))
|
2015-08-16 16:14:46 -05:00
|
|
|
// TODO uiProgressBarValue()
|
2015-08-16 22:08:00 -05:00
|
|
|
_UI_EXTERN void uiProgressBarSetValue(uiProgressBar *p, int n);
|
2015-08-16 16:14:46 -05:00
|
|
|
_UI_EXTERN uiProgressBar *uiNewProgressBar(void);
|
|
|
|
|
|
|
|
typedef struct uiSlider uiSlider;
|
2016-04-24 12:31:33 -05:00
|
|
|
#define uiSlider(this) ((uiSlider *) (this))
|
2015-08-16 22:08:00 -05:00
|
|
|
_UI_EXTERN intmax_t uiSliderValue(uiSlider *s);
|
2015-08-16 16:14:46 -05:00
|
|
|
_UI_EXTERN void uiSliderSetValue(uiSlider *s, intmax_t value);
|
|
|
|
_UI_EXTERN void uiSliderOnChanged(uiSlider *s, void (*f)(uiSlider *s, void *data), void *data);
|
|
|
|
_UI_EXTERN uiSlider *uiNewSlider(intmax_t min, intmax_t max);
|
|
|
|
|
|
|
|
typedef struct uiSeparator uiSeparator;
|
2016-04-24 12:31:33 -05:00
|
|
|
#define uiSeparator(this) ((uiSeparator *) (this))
|
2015-08-16 22:44:23 -05:00
|
|
|
_UI_EXTERN uiSeparator *uiNewHorizontalSeparator(void);
|
2015-08-16 16:14:46 -05:00
|
|
|
|
|
|
|
typedef struct uiCombobox uiCombobox;
|
2016-04-24 12:31:33 -05:00
|
|
|
#define uiCombobox(this) ((uiCombobox *) (this))
|
2015-08-16 16:14:46 -05:00
|
|
|
_UI_EXTERN void uiComboboxAppend(uiCombobox *c, const char *text);
|
2015-10-08 13:23:04 -05:00
|
|
|
_UI_EXTERN intmax_t uiComboboxSelected(uiCombobox *c);
|
2015-10-09 12:47:02 -05:00
|
|
|
_UI_EXTERN void uiComboboxSetSelected(uiCombobox *c, intmax_t n);
|
2015-10-08 13:23:04 -05:00
|
|
|
_UI_EXTERN void uiComboboxOnSelected(uiCombobox *c, void (*f)(uiCombobox *c, void *data), void *data);
|
2015-08-16 16:14:46 -05:00
|
|
|
_UI_EXTERN uiCombobox *uiNewCombobox(void);
|
|
|
|
_UI_EXTERN uiCombobox *uiNewEditableCombobox(void);
|
|
|
|
|
|
|
|
typedef struct uiRadioButtons uiRadioButtons;
|
2016-04-24 12:31:33 -05:00
|
|
|
#define uiRadioButtons(this) ((uiRadioButtons *) (this))
|
2015-08-16 16:14:46 -05:00
|
|
|
_UI_EXTERN void uiRadioButtonsAppend(uiRadioButtons *r, const char *text);
|
|
|
|
_UI_EXTERN uiRadioButtons *uiNewRadioButtons(void);
|
|
|
|
|
|
|
|
typedef struct uiDateTimePicker uiDateTimePicker;
|
2016-04-24 12:31:33 -05:00
|
|
|
#define uiDateTimePicker(this) ((uiDateTimePicker *) (this))
|
2015-08-16 16:14:46 -05:00
|
|
|
_UI_EXTERN uiDateTimePicker *uiNewDateTimePicker(void);
|
|
|
|
_UI_EXTERN uiDateTimePicker *uiNewDatePicker(void);
|
|
|
|
_UI_EXTERN uiDateTimePicker *uiNewTimePicker(void);
|
|
|
|
|
2015-12-06 00:18:32 -06:00
|
|
|
// TODO merge with uiEntry? some things can't be shared (for instance, the future Invalid()
|
|
|
|
// TODO how are line endings converted?
|
|
|
|
// TODO provide a facility for allowing horizontal scrolling
|
|
|
|
// TODO provide a facility for entering tab stops?
|
|
|
|
typedef struct uiMultilineEntry uiMultilineEntry;
|
2016-04-24 12:31:33 -05:00
|
|
|
#define uiMultilineEntry(this) ((uiMultilineEntry *) (this))
|
2015-12-06 00:18:32 -06:00
|
|
|
_UI_EXTERN char *uiMultilineEntryText(uiMultilineEntry *e);
|
|
|
|
_UI_EXTERN void uiMultilineEntrySetText(uiMultilineEntry *e, const char *text);
|
|
|
|
_UI_EXTERN void uiMultilineEntryAppend(uiMultilineEntry *e, const char *text);
|
|
|
|
_UI_EXTERN void uiMultilineEntryOnChanged(uiMultilineEntry *e, void (*f)(uiMultilineEntry *e, void *data), void *data);
|
|
|
|
_UI_EXTERN int uiMultilineEntryReadOnly(uiMultilineEntry *e);
|
|
|
|
_UI_EXTERN void uiMultilineEntrySetReadOnly(uiMultilineEntry *e, int readonly);
|
|
|
|
_UI_EXTERN uiMultilineEntry *uiNewMultilineEntry(void);
|
|
|
|
|
2015-08-16 16:14:46 -05:00
|
|
|
typedef struct uiMenuItem uiMenuItem;
|
2016-04-24 15:20:57 -05:00
|
|
|
#define uiMenuItem(this) ((uiMenuItem *) (this))
|
|
|
|
_UI_EXTERN void uiMenuItemEnable(uiMenuItem *m);
|
|
|
|
_UI_EXTERN void uiMenuItemDisable(uiMenuItem *m);
|
|
|
|
_UI_EXTERN void uiMenuItemOnClicked(uiMenuItem *m, void (*f)(uiMenuItem *sender, uiWindow *window, void *data), void *data);
|
|
|
|
_UI_EXTERN int uiMenuItemChecked(uiMenuItem *m);
|
|
|
|
_UI_EXTERN void uiMenuItemSetChecked(uiMenuItem *m, int checked);
|
2016-04-24 12:31:33 -05:00
|
|
|
|
2016-04-24 15:20:57 -05:00
|
|
|
typedef struct uiMenu uiMenu;
|
|
|
|
#define uiMenu(this) ((uiMenu *) (this))
|
2015-08-16 22:44:23 -05:00
|
|
|
_UI_EXTERN uiMenuItem *uiMenuAppendItem(uiMenu *m, const char *name);
|
2015-08-16 16:14:46 -05:00
|
|
|
_UI_EXTERN uiMenuItem *uiMenuAppendCheckItem(uiMenu *m, const char *name);
|
|
|
|
_UI_EXTERN uiMenuItem *uiMenuAppendQuitItem(uiMenu *m);
|
|
|
|
_UI_EXTERN uiMenuItem *uiMenuAppendPreferencesItem(uiMenu *m);
|
|
|
|
_UI_EXTERN uiMenuItem *uiMenuAppendAboutItem(uiMenu *m);
|
|
|
|
_UI_EXTERN void uiMenuAppendSeparator(uiMenu *m);
|
|
|
|
_UI_EXTERN uiMenu *uiNewMenu(const char *name);
|
|
|
|
|
2015-11-27 22:23:54 -06:00
|
|
|
_UI_EXTERN char *uiOpenFile(uiWindow *parent);
|
|
|
|
_UI_EXTERN char *uiSaveFile(uiWindow *parent);
|
|
|
|
_UI_EXTERN void uiMsgBox(uiWindow *parent, const char *title, const char *description);
|
|
|
|
_UI_EXTERN void uiMsgBoxError(uiWindow *parent, const char *title, const char *description);
|
2015-08-16 16:14:46 -05:00
|
|
|
|
2015-10-08 17:03:24 -05:00
|
|
|
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 *);
|
2015-12-17 12:50:07 -06:00
|
|
|
// TODO document that resizes cause a full redraw for non-scrolling areas; implementation-defined for scrolling areas
|
2015-10-08 17:03:24 -05:00
|
|
|
void (*MouseEvent)(uiAreaHandler *, uiArea *, uiAreaMouseEvent *);
|
2015-12-17 12:50:07 -06:00
|
|
|
// TODO document that on first show if the mouse is already in the uiArea then one gets sent with left=0
|
|
|
|
// TODO what about when the area is hidden and then shown again?
|
2015-12-17 13:20:17 -06:00
|
|
|
void (*MouseCrossed)(uiAreaHandler *, uiArea *, int left);
|
2015-10-08 17:03:24 -05:00
|
|
|
void (*DragBroken)(uiAreaHandler *, uiArea *);
|
|
|
|
int (*KeyEvent)(uiAreaHandler *, uiArea *, uiAreaKeyEvent *);
|
|
|
|
};
|
|
|
|
|
2016-04-24 12:31:33 -05:00
|
|
|
#define uiArea(this) ((uiArea *) (this))
|
2015-12-17 12:50:07 -06:00
|
|
|
// TODO give a better name
|
2015-12-17 18:16:30 -06:00
|
|
|
// TODO document the types of width and height
|
2015-12-17 12:50:07 -06:00
|
|
|
_UI_EXTERN void uiAreaSetSize(uiArea *a, intmax_t width, intmax_t height);
|
2015-10-09 14:27:57 -05:00
|
|
|
// TODO uiAreaQueueRedraw()
|
|
|
|
_UI_EXTERN void uiAreaQueueRedrawAll(uiArea *a);
|
2016-01-24 20:50:10 -06:00
|
|
|
_UI_EXTERN void uiAreaScrollTo(uiArea *a, double x, double y, double width, double height);
|
2015-10-08 17:03:24 -05:00
|
|
|
_UI_EXTERN uiArea *uiNewArea(uiAreaHandler *ah);
|
2015-12-17 12:50:07 -06:00
|
|
|
_UI_EXTERN uiArea *uiNewScrollingArea(uiAreaHandler *ah, intmax_t width, intmax_t height);
|
2015-10-08 17:03:24 -05:00
|
|
|
|
|
|
|
struct uiAreaDrawParams {
|
|
|
|
uiDrawContext *Context;
|
|
|
|
|
2015-12-17 12:50:07 -06:00
|
|
|
// TODO document that this is only defined for nonscrolling areas
|
2015-12-17 12:54:54 -06:00
|
|
|
double AreaWidth;
|
|
|
|
double AreaHeight;
|
2015-10-08 17:03:24 -05:00
|
|
|
|
2015-12-17 12:54:54 -06:00
|
|
|
double ClipX;
|
|
|
|
double ClipY;
|
|
|
|
double ClipWidth;
|
|
|
|
double ClipHeight;
|
2015-10-08 17:03:24 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct uiDrawPath uiDrawPath;
|
|
|
|
typedef struct uiDrawBrush uiDrawBrush;
|
|
|
|
typedef struct uiDrawStrokeParams uiDrawStrokeParams;
|
2015-10-11 10:13:01 -05:00
|
|
|
typedef struct uiDrawMatrix uiDrawMatrix;
|
2015-10-08 17:03:24 -05:00
|
|
|
|
|
|
|
typedef struct uiDrawBrushGradientStop uiDrawBrushGradientStop;
|
|
|
|
|
2016-04-23 20:38:51 -05:00
|
|
|
_UI_ENUM(uiDrawBrushType) {
|
2015-10-08 17:03:24 -05:00
|
|
|
uiDrawBrushTypeSolid,
|
|
|
|
uiDrawBrushTypeLinearGradient,
|
|
|
|
uiDrawBrushTypeRadialGradient,
|
|
|
|
uiDrawBrushTypeImage,
|
2016-04-23 20:38:51 -05:00
|
|
|
};
|
2015-10-08 17:03:24 -05:00
|
|
|
|
2016-04-23 20:38:51 -05:00
|
|
|
_UI_ENUM(uiDrawLineCap) {
|
2015-10-08 17:03:24 -05:00
|
|
|
uiDrawLineCapFlat,
|
|
|
|
uiDrawLineCapRound,
|
|
|
|
uiDrawLineCapSquare,
|
2016-04-23 20:38:51 -05:00
|
|
|
};
|
2015-10-08 17:03:24 -05:00
|
|
|
|
2016-04-23 20:38:51 -05:00
|
|
|
_UI_ENUM(uiDrawLineJoin) {
|
2015-10-08 17:03:24 -05:00
|
|
|
uiDrawLineJoinMiter,
|
|
|
|
uiDrawLineJoinRound,
|
|
|
|
uiDrawLineJoinBevel,
|
2016-04-23 20:38:51 -05:00
|
|
|
};
|
2015-10-08 17:03:24 -05:00
|
|
|
|
2015-10-10 12:01:48 -05:00
|
|
|
// this is the default for botoh cairo and Direct2D (in the latter case, from the C++ helper functions)
|
2015-10-08 17:03:24 -05:00
|
|
|
// 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
|
|
|
|
|
2016-04-23 20:38:51 -05:00
|
|
|
_UI_ENUM(uiDrawFillMode) {
|
2015-10-08 17:03:24 -05:00
|
|
|
uiDrawFillModeWinding,
|
|
|
|
uiDrawFillModeAlternate,
|
2016-04-23 20:38:51 -05:00
|
|
|
};
|
2015-10-08 17:03:24 -05:00
|
|
|
|
2015-10-11 10:13:01 -05:00
|
|
|
struct uiDrawMatrix {
|
|
|
|
double M11;
|
|
|
|
double M12;
|
|
|
|
double M21;
|
|
|
|
double M22;
|
|
|
|
double M31;
|
|
|
|
double M32;
|
|
|
|
};
|
|
|
|
|
2015-10-08 17:03:24 -05:00
|
|
|
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;
|
2015-10-16 09:46:26 -05:00
|
|
|
// TODO what if this is 0? on windows there will be a crash with dashing
|
2015-10-08 17:03:24 -05:00
|
|
|
double Thickness;
|
|
|
|
double MiterLimit;
|
2015-10-16 09:09:41 -05:00
|
|
|
double *Dashes;
|
|
|
|
// TOOD what if this is 1 on Direct2D?
|
|
|
|
// TODO what if a dash is 0 on Cairo or Quartz?
|
|
|
|
size_t NumDashes;
|
|
|
|
double DashPhase;
|
2015-10-08 17:03:24 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
_UI_EXTERN uiDrawPath *uiDrawNewPath(uiDrawFillMode fillMode);
|
|
|
|
_UI_EXTERN void uiDrawFreePath(uiDrawPath *p);
|
|
|
|
|
|
|
|
_UI_EXTERN void uiDrawPathNewFigure(uiDrawPath *p, double x, double y);
|
2015-10-11 20:15:08 -05:00
|
|
|
_UI_EXTERN void uiDrawPathNewFigureWithArc(uiDrawPath *p, double xCenter, double yCenter, double radius, double startAngle, double sweep, int negative);
|
2015-10-08 17:03:24 -05:00
|
|
|
_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?
|
2015-10-09 22:19:21 -05:00
|
|
|
// TODO what if sweep < 0?
|
2015-10-11 20:15:08 -05:00
|
|
|
_UI_EXTERN void uiDrawPathArcTo(uiDrawPath *p, double xCenter, double yCenter, double radius, double startAngle, double sweep, int negative);
|
2015-10-08 17:03:24 -05:00
|
|
|
_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
|
|
|
|
|
2015-10-11 10:13:01 -05:00
|
|
|
_UI_EXTERN void uiDrawMatrixSetIdentity(uiDrawMatrix *m);
|
|
|
|
_UI_EXTERN void uiDrawMatrixTranslate(uiDrawMatrix *m, double x, double y);
|
2015-10-12 00:43:12 -05:00
|
|
|
_UI_EXTERN void uiDrawMatrixScale(uiDrawMatrix *m, double xCenter, double yCenter, double x, double y);
|
2015-10-11 10:13:01 -05:00
|
|
|
_UI_EXTERN void uiDrawMatrixRotate(uiDrawMatrix *m, double x, double y, double amount);
|
2015-10-11 11:36:48 -05:00
|
|
|
_UI_EXTERN void uiDrawMatrixSkew(uiDrawMatrix *m, double x, double y, double xamount, double yamount);
|
2015-10-11 10:13:01 -05:00
|
|
|
_UI_EXTERN void uiDrawMatrixMultiply(uiDrawMatrix *dest, uiDrawMatrix *src);
|
|
|
|
_UI_EXTERN int uiDrawMatrixInvertible(uiDrawMatrix *m);
|
|
|
|
_UI_EXTERN int uiDrawMatrixInvert(uiDrawMatrix *m);
|
|
|
|
_UI_EXTERN void uiDrawMatrixTransformPoint(uiDrawMatrix *m, double *x, double *y);
|
|
|
|
_UI_EXTERN void uiDrawMatrixTransformSize(uiDrawMatrix *m, double *x, double *y);
|
|
|
|
|
2015-10-12 20:11:42 -05:00
|
|
|
_UI_EXTERN void uiDrawTransform(uiDrawContext *c, uiDrawMatrix *m);
|
|
|
|
|
2015-10-13 10:16:06 -05:00
|
|
|
// TODO add a uiDrawPathStrokeToFill() or something like that
|
|
|
|
_UI_EXTERN void uiDrawClip(uiDrawContext *c, uiDrawPath *path);
|
2015-10-12 20:11:42 -05:00
|
|
|
|
2015-10-11 10:13:01 -05:00
|
|
|
_UI_EXTERN void uiDrawSave(uiDrawContext *c);
|
|
|
|
_UI_EXTERN void uiDrawRestore(uiDrawContext *c);
|
|
|
|
|
2016-01-10 20:02:40 -06:00
|
|
|
// TODO manage the use of Text, Font, and TextFont, and of the uiDrawText prefix in general
|
|
|
|
|
|
|
|
///// TODO
|
2015-12-22 18:01:56 -06:00
|
|
|
typedef struct uiDrawFontFamilies uiDrawFontFamilies;
|
|
|
|
|
|
|
|
_UI_EXTERN uiDrawFontFamilies *uiDrawListFontFamilies(void);
|
|
|
|
_UI_EXTERN uintmax_t uiDrawFontFamiliesNumFamilies(uiDrawFontFamilies *ff);
|
|
|
|
_UI_EXTERN char *uiDrawFontFamiliesFamily(uiDrawFontFamilies *ff, uintmax_t n);
|
2015-12-22 18:17:27 -06:00
|
|
|
_UI_EXTERN void uiDrawFreeFontFamilies(uiDrawFontFamilies *ff);
|
2016-01-10 20:02:40 -06:00
|
|
|
///// END TODO
|
2015-12-22 18:01:56 -06:00
|
|
|
|
2016-01-07 17:37:43 -06:00
|
|
|
typedef struct uiDrawTextLayout uiDrawTextLayout;
|
2016-01-10 20:02:40 -06:00
|
|
|
typedef struct uiDrawTextFont uiDrawTextFont;
|
|
|
|
typedef struct uiDrawTextFontDescriptor uiDrawTextFontDescriptor;
|
2016-01-12 20:52:45 -06:00
|
|
|
typedef struct uiDrawTextFontMetrics uiDrawTextFontMetrics;
|
2015-12-24 17:05:16 -06:00
|
|
|
|
2016-04-23 20:38:51 -05:00
|
|
|
_UI_ENUM(uiDrawTextWeight) {
|
2015-12-24 17:05:16 -06:00
|
|
|
uiDrawTextWeightThin,
|
|
|
|
uiDrawTextWeightUltraLight,
|
|
|
|
uiDrawTextWeightLight,
|
|
|
|
uiDrawTextWeightBook,
|
|
|
|
uiDrawTextWeightNormal,
|
|
|
|
uiDrawTextWeightMedium,
|
|
|
|
uiDrawTextWeightSemiBold,
|
|
|
|
uiDrawTextWeightBold,
|
|
|
|
uiDrawTextWeightUtraBold,
|
|
|
|
uiDrawTextWeightHeavy,
|
|
|
|
uiDrawTextWeightUltraHeavy,
|
2016-04-23 20:38:51 -05:00
|
|
|
};
|
2015-12-24 17:05:16 -06:00
|
|
|
|
2016-04-23 20:38:51 -05:00
|
|
|
_UI_ENUM(uiDrawTextItalic) {
|
2015-12-24 17:05:16 -06:00
|
|
|
uiDrawTextItalicNormal,
|
|
|
|
uiDrawTextItalicOblique,
|
|
|
|
uiDrawTextItalicItalic,
|
2016-04-23 20:38:51 -05:00
|
|
|
};
|
2015-12-24 17:05:16 -06:00
|
|
|
|
2016-04-23 20:38:51 -05:00
|
|
|
_UI_ENUM(uiDrawTextStretch) {
|
2015-12-24 17:05:16 -06:00
|
|
|
uiDrawTextStretchUltraCondensed,
|
|
|
|
uiDrawTextStretchExtraCondensed,
|
|
|
|
uiDrawTextStretchCondensed,
|
|
|
|
uiDrawTextStretchSemiCondensed,
|
|
|
|
uiDrawTextStretchNormal,
|
|
|
|
uiDrawTextStretchSemiExpanded,
|
|
|
|
uiDrawTextStretchExpanded,
|
|
|
|
uiDrawTextStretchExtraExpanded,
|
|
|
|
uiDrawTextStretchUltraExpanded,
|
2016-04-23 20:38:51 -05:00
|
|
|
};
|
2015-12-24 17:05:16 -06:00
|
|
|
|
2016-01-10 20:02:40 -06:00
|
|
|
struct uiDrawTextFontDescriptor {
|
2016-01-07 17:37:43 -06:00
|
|
|
const char *Family;
|
|
|
|
double Size;
|
|
|
|
uiDrawTextWeight Weight;
|
|
|
|
uiDrawTextItalic Italic;
|
|
|
|
uiDrawTextStretch Stretch;
|
|
|
|
};
|
|
|
|
|
2016-01-12 20:52:45 -06:00
|
|
|
struct uiDrawTextFontMetrics {
|
|
|
|
double Ascent;
|
|
|
|
double Descent;
|
|
|
|
double Leading;
|
2016-01-12 21:07:24 -06:00
|
|
|
// TODO do these two mean the same across all platforms?
|
2016-01-12 20:52:45 -06:00
|
|
|
double UnderlinePos;
|
|
|
|
double UnderlineThickness;
|
|
|
|
};
|
2015-12-24 17:05:16 -06:00
|
|
|
|
2016-01-10 20:02:40 -06:00
|
|
|
_UI_EXTERN uiDrawTextFont *uiDrawLoadClosestFont(const uiDrawTextFontDescriptor *desc);
|
|
|
|
_UI_EXTERN void uiDrawFreeTextFont(uiDrawTextFont *font);
|
|
|
|
_UI_EXTERN uintptr_t uiDrawTextFontHandle(uiDrawTextFont *font);
|
|
|
|
_UI_EXTERN void uiDrawTextFontDescribe(uiDrawTextFont *font, uiDrawTextFontDescriptor *desc);
|
|
|
|
// TODO make copy with given attributes methods?
|
2016-01-12 20:52:45 -06:00
|
|
|
// TODO yuck this name
|
|
|
|
_UI_EXTERN void uiDrawTextFontGetMetrics(uiDrawTextFont *font, uiDrawTextFontMetrics *metrics);
|
2016-01-10 20:02:40 -06:00
|
|
|
|
2016-01-15 19:19:56 -06:00
|
|
|
// TODO initial line spacing? and what about leading?
|
2016-01-14 19:02:01 -06:00
|
|
|
_UI_EXTERN uiDrawTextLayout *uiDrawNewTextLayout(const char *text, uiDrawTextFont *defaultFont, double width);
|
2016-01-07 17:37:43 -06:00
|
|
|
_UI_EXTERN void uiDrawFreeTextLayout(uiDrawTextLayout *layout);
|
2016-01-14 19:02:01 -06:00
|
|
|
// TODO get width
|
|
|
|
_UI_EXTERN void uiDrawTextLayoutSetWidth(uiDrawTextLayout *layout, double width);
|
|
|
|
_UI_EXTERN void uiDrawTextLayoutExtents(uiDrawTextLayout *layout, double *width, double *height);
|
2016-01-07 17:37:43 -06:00
|
|
|
|
2016-04-19 14:38:24 -05:00
|
|
|
// and the attributes that you can set on a text layout
|
|
|
|
_UI_EXTERN void uiDrawTextLayoutSetColor(uiDrawTextLayout *layout, intmax_t startChar, intmax_t endChar, double r, double g, double b, double a);
|
|
|
|
|
2016-01-07 17:37:43 -06:00
|
|
|
_UI_EXTERN void uiDrawText(uiDrawContext *c, double x, double y, uiDrawTextLayout *layout);
|
2015-12-24 17:05:16 -06:00
|
|
|
|
2016-04-23 20:38:51 -05:00
|
|
|
_UI_ENUM(uiModifiers) {
|
2015-10-08 17:03:24 -05:00
|
|
|
uiModifierCtrl = 1 << 0,
|
|
|
|
uiModifierAlt = 1 << 1,
|
|
|
|
uiModifierShift = 1 << 2,
|
|
|
|
uiModifierSuper = 1 << 3,
|
2016-04-23 20:38:51 -05:00
|
|
|
};
|
2015-10-08 17:03:24 -05:00
|
|
|
|
2015-12-17 12:54:54 -06:00
|
|
|
// TODO document drag captures
|
2015-10-08 17:03:24 -05:00
|
|
|
struct uiAreaMouseEvent {
|
2015-12-17 12:54:54 -06:00
|
|
|
// TODO document what these mean for scrolling areas
|
2015-10-14 07:49:06 -05:00
|
|
|
double X;
|
|
|
|
double Y;
|
2015-10-08 17:03:24 -05:00
|
|
|
|
2015-12-17 12:54:54 -06:00
|
|
|
// TODO see draw above
|
|
|
|
double AreaWidth;
|
|
|
|
double AreaHeight;
|
2015-10-08 17:03:24 -05:00
|
|
|
|
|
|
|
uintmax_t Down;
|
|
|
|
uintmax_t Up;
|
|
|
|
|
|
|
|
uintmax_t Count;
|
|
|
|
|
|
|
|
uiModifiers Modifiers;
|
|
|
|
|
|
|
|
uint64_t Held1To64;
|
|
|
|
};
|
|
|
|
|
2016-04-23 20:38:51 -05:00
|
|
|
_UI_ENUM(uiExtKey) {
|
2015-10-08 17:03:24 -05:00
|
|
|
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,
|
2016-04-23 20:38:51 -05:00
|
|
|
};
|
2015-10-08 17:03:24 -05:00
|
|
|
|
|
|
|
struct uiAreaKeyEvent {
|
|
|
|
char Key;
|
|
|
|
uiExtKey ExtKey;
|
|
|
|
uiModifiers Modifier;
|
|
|
|
|
|
|
|
uiModifiers Modifiers;
|
|
|
|
|
|
|
|
int Up;
|
|
|
|
};
|
|
|
|
|
2016-04-14 11:54:37 -05:00
|
|
|
typedef struct uiFontButton uiFontButton;
|
2016-04-24 12:31:33 -05:00
|
|
|
#define uiFontButton(this) ((uiFontButton *) (this))
|
2016-04-20 12:40:54 -05:00
|
|
|
// TODO document this returns a new font
|
|
|
|
_UI_EXTERN uiDrawTextFont *uiFontButtonFont(uiFontButton *b);
|
|
|
|
// TOOD SetFont, mechanics
|
|
|
|
_UI_EXTERN void uiFontButtonOnChanged(uiFontButton *b, void (*f)(uiFontButton *, void *), void *data);
|
2016-04-14 11:54:37 -05:00
|
|
|
_UI_EXTERN uiFontButton *uiNewFontButton(void);
|
|
|
|
|
2015-11-16 09:55:44 -06:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-08-16 16:14:46 -05:00
|
|
|
#endif
|