ref: 1890aeca379976e46deabb0ce844aefc8be1a2c5
dir: /nate.h/
#pragma lib "libnate.a" typedef struct Nelem Nelem; typedef struct Nelemfunctions Nelemfunctions; typedef struct Nlist Nlist; typedef struct Nlistelem Nlistelem; /**************/ /* list types */ /**************/ struct Nlist { Nlistelem* first; int num; }; struct Nlistelem { Nelem* item; Nlistelem* next; }; /****************/ /* common types */ /****************/ typedef int (*OnclickHandler)(Mouse, Nelem*, void*); typedef char* (*StringGetter)(void); typedef struct Nmargin Nmargin; struct Nmargin { int left; int top; int right; int bottom; }; #define NMargin(l, t, r, b) ((Nmargin){l, t, r, b}) #define NMargin2(x, y) ((Nmargin){x, y, x, y}) /******************/ /* user functions */ /******************/ void nateinit(void); void nateredraw(int all); int natemouseevent(Mouse); #define NAssign(T, A, B) ((T*)(nassign((Nelem**)A, B))) Nelem* nassign(Nelem**, Nelem*); extern int nateborders; extern int natetracehit; extern int natetracedraw; extern int natedebugfd; struct { Image *red; Image *green; Image *blue; } ncolor; /**********************/ /* end user functions */ /**********************/ struct Nelem { char *type; char *name; Rectangle r; Nlist children; int nchildren; /* -1=inf, 0=none, n otherwise */ Nelemfunctions* funcs; }; struct Nelemfunctions { Rectangle (*calcsize)(Nelem*, Image*, Rectangle); void (*draw)(Nelem*, Image*); Nelem* (*checkhit)(Nelem*, Image*, Mouse); int (*hit)(Nelem*, Mouse); void (*free)(Nelem*); Nlist* (*getchildren)(Nelem*); char* (*getname)(Nelem*); }; /*******************/ /* nlist functions */ /*******************/ void linit(Nlist* list); int lhas(Nlist* list, Nelem* item); void ladd(Nlist* list, Nelem* item); void lins(Nlist* list, Nelem* item); void ldel(Nlist* list, Nelem* item); void linsert(Nlist* list, Nelem* before, Nelem* item); void lforeach(Nlist* list, void (*f)(Nelem*, int, void*), void*); void lfreelist(Nlist* list); Nelem* lgetfirst(Nlist* list); Nelem* lsetfirst(Nlist* list, Nelem* item); /********************/ /* helper functions */ /********************/ // calls on Nelem Rectangle ncallcalcsize(Nelem*, Image*, Rectangle); void ncalldraw(Nelem*, Image*); Nelem* ncallcheckhit(Nelem*, Image*, Mouse); int ncallhit(Nelem*, Mouse); void ncallfree(Nelem*); Nlist* ncallgetchildren(Nelem*); /***********************/ /* root set management */ /***********************/ // register Nelem as root void nregister(Nelem*); // deregister Nelem as root (free for collection) void nderegister(Nelem*); // true if Nelem is root int nisroot(Nelem*); // register root element void nregroot(Nelem*); /************************/ /* more syntactic sugar */ /************************/ #define DECL_ACCESSOR(Type, Acc) Type* (*Acc)(void) #define DECL_ACCESSOR_OneParam(Type, Acc, T1) Type* (*Acc)(T1) #define DECL_ACCESSOR_TwoParams(Type, Acc, T1, T2) Type* (*Acc)(T1, T2) #define DECL_ACCESSOR_ThreeParams(Type, Acc, T1, T2, T3) Type* (*Acc)(T1, T2, T3)