dorne/cursetree/surface.c

81 lines
2.1 KiB
C

#include <stdlib.h>
#include "ncrswrap.h"
#include "surface.h"
#include "_ncurses.h"
#include "ncurses.h"
static inline struct ct_surface *__surface(struct ct_dims *const dims,
struct ct_bounds *const bounds,
WINDOW *const win) {
struct ct_surface *surface;
surface = (struct ct_surface *)malloc(sizeof(struct ct_surface));
*surface = (struct ct_surface){
.dims = dims,
.bounds = bounds,
.win = win,
.updatereq = true,
};
return surface;
}
struct ct_surface *new_surface(struct ct_dims *const dims,
struct ct_bounds *const bounds) {
WINDOW *const win = new_window(dims->x, dims->y, dims->width, dims->height);
return __surface(dims, bounds, win);
}
void destroy_surface(const struct ct_surface *const surface) {
delwin(surface->win);
free(surface->dims);
}
void resize_surface(struct ct_surface *const surface,
struct ct_dims *const dims) {
free(surface->dims);
surface->dims = dims;
surface->updatereq = true;
resizemv_window(surface->win, dims->x, dims->y, dims->width, dims->height);
}
void rebind_surface(struct ct_surface *const surface,
struct ct_bounds *const bounds) {
free(surface->bounds);
surface->bounds = bounds;
}
int sfwidth(const struct ct_surface *const surface) {
return getmaxx(surface->win);
}
int sfheight(const struct ct_surface *const surface) {
return getmaxy(surface->win);
}
int sfposx(const struct ct_surface *const surface) {
return getbegx(surface->win);
}
int sfposy(const struct ct_surface *const surface) {
return getbegy(surface->win);
}
struct ct_dims *sfdims(const struct ct_surface *const surface) {
int x, y, width, height;
sfpos(surface, x, y);
sfsize(surface, width, height);
return new_dims(x, y, width, height);
}
void sfclear(struct ct_surface *const surface) {
wclear(surface->win);
surface->updatereq = true;
}
void sfflush(struct ct_surface *const surface) {
wnoutrefresh(surface->win);
surface->updatereq = false;
}