rename crs_* types to ct_*
This commit is contained in:
parent
2d76f8221e
commit
1dd5dd79c8
6 changed files with 75 additions and 75 deletions
|
|
@ -3,7 +3,7 @@
|
||||||
#include "ncrswrap.h"
|
#include "ncrswrap.h"
|
||||||
#include "tree.h"
|
#include "tree.h"
|
||||||
|
|
||||||
int ct_init(struct crs_tree **const tree) {
|
int ct_init(struct ct_tree **const tree) {
|
||||||
/* Initialise NCurses Library & Root Node */
|
/* Initialise NCurses Library & Root Node */
|
||||||
init_ncurses();
|
init_ncurses();
|
||||||
init_tree(tree);
|
init_tree(tree);
|
||||||
|
|
@ -12,8 +12,8 @@ int ct_init(struct crs_tree **const tree) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ct_update(struct crs_tree *const tree) {
|
void ct_update(struct ct_tree *const tree) {
|
||||||
struct crs_nodedims * term_dims;
|
struct ct_dims * term_dims;
|
||||||
int term_width, term_height;
|
int term_width, term_height;
|
||||||
const int key = wgetch(curscr);
|
const int key = wgetch(curscr);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
#include "tree.h"
|
#include "tree.h"
|
||||||
|
|
||||||
/* === External Interface === */
|
/* === External Interface === */
|
||||||
int ct_init(struct crs_tree **const tree);
|
int ct_init(struct ct_tree **const tree);
|
||||||
void ct_update(struct crs_tree *const tree);
|
void ct_update(struct ct_tree *const tree);
|
||||||
|
|
||||||
#endif /* CURSETREE_CURSETREE_H */
|
#endif /* CURSETREE_CURSETREE_H */
|
||||||
|
|
|
||||||
|
|
@ -5,35 +5,35 @@
|
||||||
#include "ncrswrap.h"
|
#include "ncrswrap.h"
|
||||||
#include "node.h"
|
#include "node.h"
|
||||||
|
|
||||||
/* Internal allocator method for crs_node structures.
|
/* Internal allocator method for ct_node structures.
|
||||||
*/
|
*/
|
||||||
static inline struct crs_node *__alloc_node(const enum crs_nodetype type) {
|
static inline struct ct_node *__alloc_node(const enum ct_nodetype type) {
|
||||||
struct crs_node *node = (struct crs_node *)malloc(sizeof(struct crs_node));
|
struct ct_node *node = (struct ct_node *)malloc(sizeof(struct ct_node));
|
||||||
node->type = type;
|
node->type = type;
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Construct a new window node (crs_node of type NODE_WIN).
|
/* Construct a new window node (ct_node of type NODE_WIN).
|
||||||
*/
|
*/
|
||||||
struct crs_node *init_window_node(WINDOW *const win) {
|
struct ct_node *init_window_node(WINDOW *const win) {
|
||||||
struct crs_node *node = __alloc_node(NODE_WINDOW);
|
struct ct_node *node = __alloc_node(NODE_WINDOW);
|
||||||
node->win = win;
|
node->win = win;
|
||||||
|
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct crs_node *
|
static struct ct_node *
|
||||||
auto_window_node(const struct crs_nodedims *const dims) {
|
auto_window_node(const struct ct_dims *const dims) {
|
||||||
WINDOW *win = newwin(dims->height, dims->width, dims->y, dims->x);
|
WINDOW *win = newwin(dims->height, dims->width, dims->y, dims->x);
|
||||||
return init_window_node(win);
|
return init_window_node(win);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct crs_node *init_abstract_node(struct crs_node *const node0,
|
static struct ct_node *init_abstract_node(struct ct_node *const node0,
|
||||||
struct crs_node *const node1,
|
struct ct_node *const node1,
|
||||||
const enum crs_axis axis,
|
const enum ct_axis axis,
|
||||||
const float ratio,
|
const float ratio,
|
||||||
struct crs_nodedims *const dims) {
|
struct ct_dims *const dims) {
|
||||||
struct crs_node *node = __alloc_node(NODE_ABSTRACT);
|
struct ct_node *node = __alloc_node(NODE_ABSTRACT);
|
||||||
node->axis = axis;
|
node->axis = axis;
|
||||||
node->ratio = ratio;
|
node->ratio = ratio;
|
||||||
node->dims = dims;
|
node->dims = dims;
|
||||||
|
|
@ -43,7 +43,7 @@ static struct crs_node *init_abstract_node(struct crs_node *const node0,
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
void destroy_node(struct crs_node *const node) {
|
void destroy_node(struct ct_node *const node) {
|
||||||
if (node->type == NODE_WINDOW) {
|
if (node->type == NODE_WINDOW) {
|
||||||
/* Window Node */
|
/* Window Node */
|
||||||
delwin(node->win);
|
delwin(node->win);
|
||||||
|
|
@ -59,12 +59,12 @@ end:
|
||||||
free(node);
|
free(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline struct crs_nodedims *__alloc_dims(int x, int y, int width,
|
static inline struct ct_dims *__alloc_dims(int x, int y, int width,
|
||||||
int height) {
|
int height) {
|
||||||
struct crs_nodedims *dims;
|
struct ct_dims *dims;
|
||||||
|
|
||||||
dims = (struct crs_nodedims *)malloc(sizeof(struct crs_nodedims));
|
dims = (struct ct_dims *)malloc(sizeof(struct ct_dims));
|
||||||
*dims = (struct crs_nodedims){
|
*dims = (struct ct_dims){
|
||||||
.x = x,
|
.x = x,
|
||||||
.y = y,
|
.y = y,
|
||||||
.width = width,
|
.width = width,
|
||||||
|
|
@ -73,23 +73,23 @@ static inline struct crs_nodedims *__alloc_dims(int x, int y, int width,
|
||||||
return dims;
|
return dims;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline struct crs_nodedims *
|
static inline struct ct_dims *
|
||||||
__dup_dims(const struct crs_nodedims *const dims) {
|
__dup_dims(const struct ct_dims *const dims) {
|
||||||
struct crs_nodedims *dup;
|
struct ct_dims *dup;
|
||||||
dup = (struct crs_nodedims *)malloc(sizeof(struct crs_nodedims));
|
dup = (struct ct_dims *)malloc(sizeof(struct ct_dims));
|
||||||
memcpy(dup, dims, sizeof(struct crs_nodedims));
|
memcpy(dup, dims, sizeof(struct ct_dims));
|
||||||
|
|
||||||
return dup;
|
return dup;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline struct crs_nodedims *termdims(void) {
|
static inline struct ct_dims *termdims(void) {
|
||||||
struct crs_nodedims *dims = __alloc_dims(0, 0, 0, 0);
|
struct ct_dims *dims = __alloc_dims(0, 0, 0, 0);
|
||||||
termsize(dims->width, dims->height);
|
termsize(dims->width, dims->height);
|
||||||
|
|
||||||
return dims;
|
return dims;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void nodesize(const struct crs_node *const node, int *const width,
|
static inline void nodesize(const struct ct_node *const node, int *const width,
|
||||||
int *const height) {
|
int *const height) {
|
||||||
if (node->type == NODE_WINDOW) {
|
if (node->type == NODE_WINDOW) {
|
||||||
/* Window Node */
|
/* Window Node */
|
||||||
|
|
@ -102,11 +102,11 @@ static inline void nodesize(const struct crs_node *const node, int *const width,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline struct crs_nodedims *nodedims(const struct crs_node *const node) {
|
static inline struct ct_dims *nodedims(const struct ct_node *const node) {
|
||||||
struct crs_nodedims *dims;
|
struct ct_dims *dims;
|
||||||
if (node->type == NODE_WINDOW) {
|
if (node->type == NODE_WINDOW) {
|
||||||
/* Window Node */
|
/* Window Node */
|
||||||
dims = (struct crs_nodedims *)malloc(sizeof(struct crs_nodedims));
|
dims = (struct ct_dims *)malloc(sizeof(struct ct_dims));
|
||||||
getbegyx(node->win, dims->y, dims->x);
|
getbegyx(node->win, dims->y, dims->x);
|
||||||
getmaxyx(node->win, dims->height, dims->width);
|
getmaxyx(node->win, dims->height, dims->width);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -123,12 +123,12 @@ static inline struct crs_nodedims *nodedims(const struct crs_node *const node) {
|
||||||
* WARNING: This function does not guarantee the x,y positions returned
|
* WARNING: This function does not guarantee the x,y positions returned
|
||||||
* WARNING: are valid screen coordinates.
|
* WARNING: are valid screen coordinates.
|
||||||
*/
|
*/
|
||||||
static int bifurcate_dims(const struct crs_nodedims *const parent_dims,
|
static int bifurcate_dims(const struct ct_dims *const parent_dims,
|
||||||
const enum crs_axis axis, const float ratio,
|
const enum ct_axis axis, const float ratio,
|
||||||
struct crs_nodedims **const dims0,
|
struct ct_dims **const dims0,
|
||||||
struct crs_nodedims **const dims1) {
|
struct ct_dims **const dims1) {
|
||||||
assert(0 < ratio && ratio < 1);
|
assert(0 < ratio && ratio < 1);
|
||||||
struct crs_nodedims *_dims0, *_dims1;
|
struct ct_dims *_dims0, *_dims1;
|
||||||
|
|
||||||
_dims0 = __dup_dims(parent_dims);
|
_dims0 = __dup_dims(parent_dims);
|
||||||
_dims1 = __dup_dims(parent_dims);
|
_dims1 = __dup_dims(parent_dims);
|
||||||
|
|
@ -156,8 +156,8 @@ static int bifurcate_dims(const struct crs_nodedims *const parent_dims,
|
||||||
* NOTE: a call doupdate(3x) call afterwards to flush ncurses
|
* NOTE: a call doupdate(3x) call afterwards to flush ncurses
|
||||||
* NOTE: virtual screen to the physical screen.
|
* NOTE: virtual screen to the physical screen.
|
||||||
*/
|
*/
|
||||||
void resize_node(struct crs_node *const node,
|
void resize_node(struct ct_node *const node,
|
||||||
struct crs_nodedims *const new_dims) {
|
struct ct_dims *const new_dims) {
|
||||||
if (node->type == NODE_WINDOW) {
|
if (node->type == NODE_WINDOW) {
|
||||||
/* Window Node */
|
/* Window Node */
|
||||||
resizemv_window(new_dims->x, new_dims->y, new_dims->width, new_dims->height,
|
resizemv_window(new_dims->x, new_dims->y, new_dims->width, new_dims->height,
|
||||||
|
|
@ -168,7 +168,7 @@ void resize_node(struct crs_node *const node,
|
||||||
} else {
|
} else {
|
||||||
/* Abstract Node */
|
/* Abstract Node */
|
||||||
assert(node->type == NODE_ABSTRACT);
|
assert(node->type == NODE_ABSTRACT);
|
||||||
struct crs_nodedims *dims0, *dims1;
|
struct ct_dims *dims0, *dims1;
|
||||||
|
|
||||||
free(node->dims);
|
free(node->dims);
|
||||||
node->dims = new_dims;
|
node->dims = new_dims;
|
||||||
|
|
@ -185,14 +185,14 @@ void resize_node(struct crs_node *const node,
|
||||||
* axis - controls which direction the subdivision occurs
|
* axis - controls which direction the subdivision occurs
|
||||||
* invert_axis - invert index of the original node in the new abstract node
|
* invert_axis - invert index of the original node in the new abstract node
|
||||||
*/
|
*/
|
||||||
void bifurcate_window_node(struct crs_node **const node,
|
void bifurcate_window_node(struct ct_node **const node,
|
||||||
const enum crs_axis axis, const int invert_axis,
|
const enum ct_axis axis, const int invert_axis,
|
||||||
const float ratio) {
|
const float ratio) {
|
||||||
assert((*node)->type == NODE_WINDOW);
|
assert((*node)->type == NODE_WINDOW);
|
||||||
struct crs_nodedims *dims0, *dims1;
|
struct ct_dims *dims0, *dims1;
|
||||||
struct crs_node *node0, *node1;
|
struct ct_node *node0, *node1;
|
||||||
|
|
||||||
struct crs_nodedims *original_dims = nodedims(*node);
|
struct ct_dims *original_dims = nodedims(*node);
|
||||||
if (bifurcate_dims(original_dims, axis, ratio, &dims0, &dims1)) {
|
if (bifurcate_dims(original_dims, axis, ratio, &dims0, &dims1)) {
|
||||||
/* TODO: handle this error properly */
|
/* TODO: handle this error properly */
|
||||||
free(original_dims);
|
free(original_dims);
|
||||||
|
|
@ -218,7 +218,7 @@ void bifurcate_window_node(struct crs_node **const node,
|
||||||
/* Collapse an abstract node, killing one child node and resizing
|
/* Collapse an abstract node, killing one child node and resizing
|
||||||
* the other to take its place.
|
* the other to take its place.
|
||||||
*/
|
*/
|
||||||
static void collapse_abstract_node(struct crs_node **const node,
|
static void collapse_abstract_node(struct ct_node **const node,
|
||||||
const int collapse_i) {
|
const int collapse_i) {
|
||||||
assert((*node)->type == NODE_ABSTRACT);
|
assert((*node)->type == NODE_ABSTRACT);
|
||||||
assert(0 <= collapse_i && collapse_i < NODE_CHILD_N);
|
assert(0 <= collapse_i && collapse_i < NODE_CHILD_N);
|
||||||
|
|
@ -226,7 +226,7 @@ static void collapse_abstract_node(struct crs_node **const node,
|
||||||
// WARNING: only works for NODE_CHILD_N=2 (binary trees)
|
// WARNING: only works for NODE_CHILD_N=2 (binary trees)
|
||||||
destroy_node((*node)->child[!collapse_i]);
|
destroy_node((*node)->child[!collapse_i]);
|
||||||
|
|
||||||
struct crs_node *collapse_target = (*node)->child[collapse_i];
|
struct ct_node *collapse_target = (*node)->child[collapse_i];
|
||||||
free(*node);
|
free(*node);
|
||||||
*node = collapse_target;
|
*node = collapse_target;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,13 +9,13 @@ typedef struct _win_st WINDOW;
|
||||||
|
|
||||||
/* MACRO:
|
/* MACRO:
|
||||||
* Get widnow node start x,y coordinates, width, & height.
|
* Get widnow node start x,y coordinates, width, & height.
|
||||||
* void NODEDIMS(struct crs_node *node, struct crs_nodedims dims);
|
* void NODEDIMS(struct ct_node *node, struct ct_dims dims);
|
||||||
*/
|
*/
|
||||||
#define GET_WNODEDIMS(dims, node) \
|
#define GET_WNODEDIMS(dims, node) \
|
||||||
(getbegyx((node)->win, dims.y, dims.x)); \
|
(getbegyx((node)->win, dims.y, dims.x)); \
|
||||||
getmaxyx((node)->win, dims.y, dims.x)
|
getmaxyx((node)->win, dims.y, dims.x)
|
||||||
|
|
||||||
enum crs_nodetype {
|
enum ct_nodetype {
|
||||||
NODE_WINDOW,
|
NODE_WINDOW,
|
||||||
NODE_ABSTRACT,
|
NODE_ABSTRACT,
|
||||||
};
|
};
|
||||||
|
|
@ -23,37 +23,37 @@ enum crs_nodetype {
|
||||||
/* Stores a node's starting x,y coordinates, width, & height.
|
/* Stores a node's starting x,y coordinates, width, & height.
|
||||||
* NOTE: Intended for interfunction communication.
|
* NOTE: Intended for interfunction communication.
|
||||||
*/
|
*/
|
||||||
struct crs_nodedims {
|
struct ct_dims {
|
||||||
int x, y, width, height;
|
int x, y, width, height;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum crs_axis {
|
enum ct_axis {
|
||||||
AXIS_X,
|
AXIS_X,
|
||||||
AXIS_Y,
|
AXIS_Y,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct crs_node {
|
struct ct_node {
|
||||||
enum crs_nodetype type;
|
enum ct_nodetype type;
|
||||||
// union value depends on crs_node.type
|
// union value depends on ct_node.type
|
||||||
union {
|
union {
|
||||||
WINDOW *win;
|
WINDOW *win;
|
||||||
struct {
|
struct {
|
||||||
enum crs_axis axis;
|
enum ct_axis axis;
|
||||||
float ratio;
|
float ratio;
|
||||||
struct crs_nodedims *dims;
|
struct ct_dims *dims;
|
||||||
struct crs_node *child[NODE_CHILD_N];
|
struct ct_node *child[NODE_CHILD_N];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
/* === External Interface === */
|
/* === External Interface === */
|
||||||
struct crs_node *init_window_node(WINDOW *const win);
|
struct ct_node *init_window_node(WINDOW *const win);
|
||||||
void destroy_node(struct crs_node *const node);
|
void destroy_node(struct ct_node *const node);
|
||||||
void resize_node(struct crs_node *const node,
|
void resize_node(struct ct_node *const node,
|
||||||
struct crs_nodedims *const new_dims);
|
struct ct_dims *const new_dims);
|
||||||
|
|
||||||
void bifurcate_window_node(struct crs_node **const node,
|
void bifurcate_window_node(struct ct_node **const node,
|
||||||
const enum crs_axis axis, const int invert_axis,
|
const enum ct_axis axis, const int invert_axis,
|
||||||
const float ratio);
|
const float ratio);
|
||||||
|
|
||||||
#endif /* CURSETREE_NODE_H */
|
#endif /* CURSETREE_NODE_H */
|
||||||
|
|
|
||||||
|
|
@ -5,26 +5,26 @@
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*/
|
*/
|
||||||
static struct crs_node *init_root_node(void) {
|
static struct ct_node *init_root_node(void) {
|
||||||
WINDOW *rootwin;
|
WINDOW *rootwin;
|
||||||
|
|
||||||
rootwin = root_window();
|
rootwin = root_window();
|
||||||
return init_window_node(rootwin);
|
return init_window_node(rootwin);
|
||||||
}
|
}
|
||||||
|
|
||||||
int init_tree(struct crs_tree **const tree) {
|
int init_tree(struct ct_tree **const tree) {
|
||||||
*tree = (struct crs_tree *)malloc(sizeof(struct crs_tree));
|
*tree = (struct ct_tree *)malloc(sizeof(struct ct_tree));
|
||||||
(*tree)->root = init_root_node();
|
(*tree)->root = init_root_node();
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
void destroy_tree(struct crs_tree *const tree) {
|
void destroy_tree(struct ct_tree *const tree) {
|
||||||
destroy_node(tree->root);
|
destroy_node(tree->root);
|
||||||
endwin();
|
endwin();
|
||||||
free(tree);
|
free(tree);
|
||||||
}
|
}
|
||||||
|
|
||||||
void resize_tree(struct crs_tree *const tree, struct crs_nodedims *const dims) {
|
void resize_tree(struct ct_tree *const tree, struct ct_dims *const dims) {
|
||||||
resize_node(tree->root, dims);
|
resize_node(tree->root, dims);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,13 +3,13 @@
|
||||||
|
|
||||||
#include "node.h"
|
#include "node.h"
|
||||||
|
|
||||||
struct crs_tree {
|
struct ct_tree {
|
||||||
struct crs_node *root;
|
struct ct_node *root;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* === External Interface === */
|
/* === External Interface === */
|
||||||
int init_tree(struct crs_tree **const tree);
|
int init_tree(struct ct_tree **const tree);
|
||||||
void destroy_tree(struct crs_tree *const tree);
|
void destroy_tree(struct ct_tree *const tree);
|
||||||
void resize_tree(struct crs_tree *const tree, struct crs_nodedims *const dims);
|
void resize_tree(struct ct_tree *const tree, struct ct_dims *const dims);
|
||||||
|
|
||||||
#endif /* CURSETREE_TREE_H */
|
#endif /* CURSETREE_TREE_H */
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue