ref: aab184987c79fc7a8e5467200f9ac448700b797f
dir: /n_window.c/
#include <u.h> #include <libc.h> #include <draw.h> #include <event.h> #include "nate.h" #include "nate_construct.h" #include "n_window.h" #define N_TYPE NWindow_Type char* NWindow_Type = "NWindow"; static Rectangle wcalcrect(Nelem* nelem, Image* screen, Rectangle r) { Nelem *f; NWindow *w = (NWindow*)nelem; GUARD(w); f = lgetfirst(&w->children); if (f) ncallcalcrect(f, screen, screen->r); nelem->slot.r = r; return screen->r; } static void wdraw(Nelem* nelem, Image* img) { Nelem *f; NWindow *w = (NWindow*)nelem; GUARD(w); f = lgetfirst(&w->children); if (f) ncalldraw(f, img); } /* could be removed completely, but leave here as an example */ static void wfree(Nelem* nelem) { nd_free(nelem); } static Nelemfunctions Nwindowfunctions = { .calcrect = wcalcrect, .draw = wdraw, .checkhit = nd_checkhit, .free = wfree, }; #define NTYPE NWindow #define NACCS NWindowAccessors DEF_SLOTFUNC(wslot); static NWindowAccessors* makeroot(void) { NWindow* w = (NWindow*)nc_get(); GUARD(w); nregroot(w); return (NACCS*)w->accs; } static NWindowAccessors accs = { .Slot = wslot, .MakeRoot = makeroot, }; NWindowAccessors* New_Window(char *name) { NWindow *e = MakeNelem(NWindow, NWindow_Type, &Nwindowfunctions, &accs, name, 1); nc_push(e); return &accs; }