#include #include #include #include #include #include #include #include typedef struct Window Window; typedef struct Widget Widget; typedef struct Rdims Rdims; typedef struct Fanout Fanout; typedef struct Bitmap Bitmap; typedef struct ImgHdr ImgHdr; typedef struct CanvasTool CanvasTool; typedef struct Selection Selection; typedef struct CanvasSync CanvasSync; typedef struct Canvas Canvas; typedef struct Cmd Cmd; typedef enum RedrawMode RedrawMode; struct Window { int id; Keyboardctl *kctl; Mousectl *rawmctl; Channel *rawmc; /* Mouse */ Mousectl *mctl; Widget *w; Image *screen; Screen *_screen; }; struct Widget { Rectangle r; /* the area the widget occupies on screen */ int (*mouse)(Widget *, Mousectl *); int (*sync)(Widget *); void (*redraw)(Widget *, RedrawMode); Rdims (*dims)(Widget *); void (*resize)(Widget *, Point rdim); void (*free)(Widget *); void *aux; Image *screen; Widget *up; Widget *next; Widget *children; }; struct Rdims { Point min; Point des; Point max; }; struct Fanout { void (*sync)(Fanout *); void (*redraw)(Fanout *, RedrawMode); void (*resize)(Fanout *, Point rdim); int nw; Widget **ws; }; struct Bitmap { int Δx; int Δy; ulong chan; uchar *data; }; struct ImgHdr { uchar bytes[5*12]; /* excludes "compressed\n" */ int compressed; ulong chan; Rectangle r; }; struct CanvasTool { int (*mouse)(Widget *canvas, Mousectl *); int (*init)(Widget *canvas); void (*cleanup)(Widget *canvas); void *aux; }; struct Selection { int active; Rectangle r; }; struct CanvasSync { Memimage *mem; Rectangle dirty; }; struct Canvas { CanvasSync *s; Fanout *f; int mag; Image *img; Point pos; CanvasTool tool; Selection sel; }; typedef struct Brush { ulong c; Memimage *p; } Brush; struct Cmd { char *s; int cons; Channel *wmsg; /* a malloc'd Waitmsg, freed by the receiver */ }; enum { RDall, RDinc, }; Cursor topleft, top, topright; Cursor left, right; Cursor bottomleft, bottom, bottomright; Cursor box; Cursor cross; Cursor sweepcursor; Cursor busycursor; char *Egreg; Widget *brushwidget; Widget *colorpickerwidget; Fanout *rootfanout; int npatterns; Bitmap *patternbitmaps[]; Memimage **patterns; Brush brushes[3]; Point INFPT; Point INFDIM; Rectangle INFR; CanvasTool noptool; CanvasTool brushtool; CanvasTool pipette; CanvasTool rselect; CanvasTool zoom; CanvasTool probe; /* colorpicker.c */ Widget *mkcolorpickerwidget(ulong rgba); void setcolorpickercolor(Widget *, ulong rgba); /* cmd.c */ int newcmdwindow(Channel *cmd); void execcmd(Canvas *, Cmd *); /* fanout.c */ void fanoutadd(Fanout *f, Widget *w); void fanoutremove(Fanout *f, Widget *w); Fanout *mkfanout(void); /* fileops.c */ Widget *mkfileopswidget(Widget *canvas); /* frills.c */ void drawshadow(Image *, Rectangle); Widget *mkshadow(Widget *c); Widget *mkbg(Image *); /* hsv.c */ ulong hsvtorgb(ulong); ulong rgbtohsv(ulong); /* layout.c */ Widget *mklayoutmaxwidget(Point dim, Widget *c); Widget *mkxautolayout(void); Widget *mkmargin(int left, int right, int top, int bottom); /* log.c */ void logproccreate(void); void _paintfatal(char *, va_list); /* p9bit.c */ int readimghdr(int fd, ImgHdr *); int loadmem(Memimage *dst, ImgHdr, int fd); int unloadmem(int fd, Memimage *src, Rectangle); /* paint.c */ Brush *getbrush(int); void antsrect(Image *, Rectangle, Rectangle); int loadcanvas(Canvas *, int fd); Widget *newzeroxwindow(Widget *canvas); /* scroll.c */ Widget *mkyscrollbar(Widget *c, Point (*getdim)(Widget *c), void(*scroll)(Widget *c, Point)); Widget *mkxscrollbar(Widget *c, Point (*getdim)(Widget *c), void(*scroll)(Widget *c, Point)); Widget *mkscrollbars(Widget *c, Point (*getdim)(Widget *c), void(*scroll)(Widget *c, Point)); /* sync.c */ int syncimg(Image *, Memimage *, Rectangle); int magsyncimg(Image *img, Memimage *mem, Rectangle imgr, Point pos, int mag); int synccanvasmem(Canvas *, Rectangle); int synccanvasimg(Canvas *, Rectangle); /* toolbox.c */ Widget *mktoolboxwidget(Widget *canvas); void deselecttool(Widget *tb); /* util.c */ void *emalloc(ulong); int min(int, int); int max(int, int); float fmax(float, float); int clampint(int min, int x, int max); Point clamppt(Point, Rectangle); Rectangle clamprect(Rectangle, Rectangle); Rectangle insetrectpt(Rectangle, Point); Point rectdim(Rectangle); Rectangle scalerect(Rectangle, float); int adddim(int, int); Rdims adddims(Rdims, Rdims); Point mtoipt(Point, Widget *); Point mtospt(Point, Widget *); Point stompt(Point, Widget *); Point stoipt(Point, Widget *); Rectangle mtosrect(Rectangle, Widget *); Rectangle stomrect(Rectangle, Widget *); Rectangle stoirect(Rectangle, Widget *); Image *loadbitmap(Bitmap); void fastsetcursor(Mousectl *, Cursor *); int atoifile(char *name, int *); /* widget.c */ Widget *mkwidget(Rectangle, int (*mouse)(Widget *, Mousectl *), int (*sync)(Widget *), void (*redraw)(Widget *, RedrawMode), Rdims (*dims)(Widget *), void (*resize)(Widget *, Point), void (*free)(Widget *w), void *aux ); void freewidget(Widget *); void addchildwidget(Widget *p, Widget *c, Point); void movewidget(Widget *, Point, Image *); Widget *findrootwidget(Widget *); int widgetmousedescend(Widget *, Mousectl *); int widgetmousenop(Widget *, Mousectl *); int widgetsyncnop(Widget *); void widgetredrawnop(Widget *, RedrawMode); void widgetredrawdescend(Widget *, RedrawMode); Rdims widgetdimsnop(Widget *); Rdims widgetdimsdescend(Widget *); void widgetresizenop(Widget *, Point); void widgetresizedescend(Widget *, Point);