added branch selection
This commit is contained in:
@@ -120,10 +120,13 @@ int main (int argc, char *argv[]) {
|
|||||||
char commandInput[255] = "";
|
char commandInput[255] = "";
|
||||||
unsigned char keyPressed = 0;
|
unsigned char keyPressed = 0;
|
||||||
|
|
||||||
|
char title[30] = "this is a test";
|
||||||
|
|
||||||
branch b = create_branch(NULL, (nomi_vec2){0,1}, 0, TART_COLOR_BLUE_BACKGROUND);
|
trunk tr = CreateTrunk(title,create_branch(NULL, (nomi_vec2){-0.5,1}, 0, TART_COLOR_GREEN_FOREGROUND));
|
||||||
branch b1 = create_branch(&b,(nomi_vec2){1,1}, 50, TART_COLOR_BLUE_BACKGROUND);
|
AddBranch(&tr, create_branch(&tr.branches[0],(nomi_vec2){0.2,2*1}, 10, TART_COLOR_GREEN_FOREGROUND));
|
||||||
branch b2 = create_branch(&b1,(nomi_vec2){1,1}, 20, TART_COLOR_BRIGHT_GREEN_BACKGROUND);
|
AddBranch(&tr, create_branch(&tr.branches[1],(nomi_vec2){-0.5,1}, 50, TART_COLOR_GREEN_FOREGROUND));
|
||||||
|
AddBranch(&tr, create_branch(&tr.branches[0],(nomi_vec2){-0.5,1}, 50, TART_COLOR_GREEN_FOREGROUND));
|
||||||
|
NomiInit(&tr);
|
||||||
|
|
||||||
// Window Createion
|
// Window Createion
|
||||||
struct tart_window window = tart_create_window();
|
struct tart_window window = tart_create_window();
|
||||||
@@ -157,29 +160,30 @@ int main (int argc, char *argv[]) {
|
|||||||
tart_restore_window(&window);
|
tart_restore_window(&window);
|
||||||
tart_restore_buffer(tart_get_buffer(&window, 0));
|
tart_restore_buffer(tart_get_buffer(&window, 0));
|
||||||
|
|
||||||
b = create_branch(NULL, (nomi_vec2){0,1}, 0, branch1Color);
|
//b = create_branch(NULL, (nomi_vec2){-0.5,1}, 0, branch1Color);
|
||||||
b1 = create_branch(&b,(nomi_vec2){1,4*2}, 20, branch2Color);
|
//b1 = create_branch(&b,(nomi_vec2){0.2,2*1}, 10, branch2Color);
|
||||||
b2 = create_branch(&b1,(nomi_vec2){1,0}, 10, branch3Color);
|
//b2 = create_branch(&b,(nomi_vec2){-1.0,1}, 50, branch3Color);
|
||||||
|
|
||||||
if(keyPressed) {
|
if(keyPressed) {
|
||||||
|
|
||||||
char c = term_tinput();
|
char c = term_tinput();
|
||||||
|
|
||||||
if( c == '1') {
|
|
||||||
branch1Color = TART_COLOR_WHITE_BACKGROUND;
|
//if( c == '1') {
|
||||||
branch2Color = TART_COLOR_GREEN_FOREGROUND;
|
// branch1Color = TART_COLOR_WHITE_FOREGROUND;
|
||||||
branch3Color = TART_COLOR_GREEN_FOREGROUND;
|
// branch2Color = TART_COLOR_GREEN_FOREGROUND;
|
||||||
}
|
// branch3Color = TART_COLOR_GREEN_FOREGROUND;
|
||||||
if( c == '2') {
|
//}
|
||||||
branch2Color = TART_COLOR_WHITE_BACKGROUND;
|
//if( c == '2') {
|
||||||
branch1Color = TART_COLOR_GREEN_FOREGROUND;
|
// branch2Color = TART_COLOR_WHITE_FOREGROUND;
|
||||||
branch3Color = TART_COLOR_GREEN_FOREGROUND;
|
// branch1Color = TART_COLOR_GREEN_FOREGROUND;
|
||||||
}
|
// branch3Color = TART_COLOR_GREEN_FOREGROUND;
|
||||||
if( c == '3') {
|
//}
|
||||||
branch3Color = TART_COLOR_WHITE_BACKGROUND;
|
//if( c == '3') {
|
||||||
branch1Color = TART_COLOR_GREEN_FOREGROUND;
|
// branch3Color = TART_COLOR_WHITE_FOREGROUND;
|
||||||
branch2Color = TART_COLOR_GREEN_FOREGROUND;
|
// branch1Color = TART_COLOR_GREEN_FOREGROUND;
|
||||||
}
|
// branch2Color = TART_COLOR_GREEN_FOREGROUND;
|
||||||
|
//}
|
||||||
|
|
||||||
//Speual
|
//Speual
|
||||||
SetRichTextBox(&inputRtb, str, strlen(str), NULL_CELL);
|
SetRichTextBox(&inputRtb, str, strlen(str), NULL_CELL);
|
||||||
@@ -276,16 +280,32 @@ int main (int argc, char *argv[]) {
|
|||||||
keyPressed = 0;
|
keyPressed = 0;
|
||||||
term_handled_key();
|
term_handled_key();
|
||||||
}
|
}
|
||||||
|
if(mode == NORMAL_MODE) {
|
||||||
|
//NomiNavigation(c);
|
||||||
|
branchId* ids = NomiNavigation(c);
|
||||||
|
for(int i = 0; i < MAX_BRANCHES; i++) {
|
||||||
|
str[i] = ids[i]+48;
|
||||||
|
}
|
||||||
|
str[MAX_BRANCHES] = '\n';
|
||||||
|
ids = LocateBranch(&tr);
|
||||||
|
for(int i = 0; i < MAX_BRANCHES; i++) {
|
||||||
|
str[1+MAX_BRANCHES+i] = ids[i]+48;
|
||||||
|
}
|
||||||
|
str[(MAX_BRANCHES*2)+1] = '\n';
|
||||||
|
ids = LocateBranch(&tr);
|
||||||
|
for(int i = 0; i < MAX_BRANCHES; i++) {
|
||||||
|
str[2+(MAX_BRANCHES*2)+i] = ids[i]+48;
|
||||||
|
}
|
||||||
|
term_handled_key();
|
||||||
|
}
|
||||||
keyPressed = 0;
|
keyPressed = 0;
|
||||||
}
|
}
|
||||||
drawTextBox(&window, &inputRtb, 0);
|
drawTextBox(&window, &inputRtb, 0);
|
||||||
|
LocateBranch(&tr);
|
||||||
|
|
||||||
|
|
||||||
// Drawing Branches
|
// Drawing Branches
|
||||||
DrawBranch(&b,100, &window, 0);
|
DrawTrunk(&tr, &window, 0);
|
||||||
DrawBranch(&b1,100, &window, 0);
|
|
||||||
DrawBranch(&b2,100, &window, 0);
|
|
||||||
|
|
||||||
tart_draw_window(&window, 0);
|
tart_draw_window(&window, 0);
|
||||||
if(mode == COMMAND_MODE) {
|
if(mode == COMMAND_MODE) {
|
||||||
|
|||||||
173
source/nomi.c
173
source/nomi.c
@@ -6,6 +6,9 @@
|
|||||||
|
|
||||||
#define SPIREL_MOD 0.618055f
|
#define SPIREL_MOD 0.618055f
|
||||||
|
|
||||||
|
#define NOMAI_END_OF_THOUGHT(id) <*ID:#id/>
|
||||||
|
#define NOMAI_MARKERS_TO_STRING(marker) #marker
|
||||||
|
|
||||||
|
|
||||||
struct nomiSpirel {
|
struct nomiSpirel {
|
||||||
struct tart_cell selected_cell;
|
struct tart_cell selected_cell;
|
||||||
@@ -18,31 +21,111 @@ struct nomiSpirel {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct nomiMenu {
|
struct nomiMenu {
|
||||||
struct nomiSpirel branches[30];
|
struct nomiSpirel branches[MAX_BRANCHES];
|
||||||
struct tart_vec2 startPos;
|
struct tart_vec2 startPos;
|
||||||
struct tart_vec2 size;
|
struct tart_vec2 size;
|
||||||
struct tart_vec2 origin;
|
struct tart_vec2 origin;
|
||||||
unsigned char brachIds[30];
|
unsigned char brachIds[MAX_BRANCHES];
|
||||||
|
};
|
||||||
|
|
||||||
|
struct nomiNavigation {
|
||||||
|
branchId branches[30]; // this list of the traveld branches.
|
||||||
|
unsigned char depth; // The current depth is the id of the selected branch.
|
||||||
|
branch* selectedBranch;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct nomiNavigation __nav__ = {
|
||||||
|
.branches = {0},
|
||||||
|
.depth = 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This will Init Nomi
|
* This will Init Nomi
|
||||||
*/
|
*/
|
||||||
void NomiInit();
|
void NomiInit(trunk* tr) {
|
||||||
|
__nav__ = (struct nomiNavigation){ .branches = {0}, .depth = 0, .selectedBranch = &tr->branches[0] };
|
||||||
|
}
|
||||||
|
|
||||||
|
branchId* NomiNavigation(char input) {
|
||||||
|
|
||||||
|
switch(input) {
|
||||||
|
case '1':
|
||||||
|
__nav__.branches[__nav__.depth] = 1;
|
||||||
|
__nav__.depth++;
|
||||||
|
break;
|
||||||
|
case '2':
|
||||||
|
__nav__.branches[__nav__.depth] = 2;
|
||||||
|
__nav__.depth++;
|
||||||
|
break;
|
||||||
|
case '3':
|
||||||
|
__nav__.branches[__nav__.depth] = 3;
|
||||||
|
__nav__.depth++;
|
||||||
|
break;
|
||||||
|
case '0':
|
||||||
|
if(__nav__.depth > 0) {
|
||||||
|
__nav__.branches[__nav__.depth] = 0;
|
||||||
|
__nav__.depth--;
|
||||||
|
__nav__.branches[__nav__.depth] = 0;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return __nav__.branches;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This will create the truk of the note.
|
* This will create the truk of the note.
|
||||||
* */
|
* */
|
||||||
trunk* CreateTrunk();
|
trunk CreateTrunk(char* title, branch root) {
|
||||||
|
trunk t = {
|
||||||
|
.title = title,
|
||||||
|
.branchCount = 1,
|
||||||
|
.branches = {0},
|
||||||
|
.text = 0,
|
||||||
|
};
|
||||||
|
t.branches[0] = root;
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DrawTrunk(trunk *tr, struct tart_window* w, tart_byte b) {
|
||||||
|
unsigned int f = 30;
|
||||||
|
for(int i = 0; i < tr->branchCount; i++) {
|
||||||
|
DrawBranch(&tr->branches[i], 100, w, b);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This is a test
|
* This is a test
|
||||||
* */
|
* */
|
||||||
void CreaetBranch(trunk* trunk);
|
void AddBranch(trunk* t, branch br) {
|
||||||
|
if(t->branchCount < MAX_BRANCHES) {
|
||||||
|
t->branches[t->branchCount] = br;
|
||||||
|
t->branchCount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Locate Branch
|
* Locate Branch
|
||||||
* */
|
* */
|
||||||
branch* LocateBranch();
|
branchId* LocateBranch(trunk* t) {
|
||||||
|
char found = 1;
|
||||||
|
for(int i = 0; i < t->branchCount; i++) {
|
||||||
|
found = 1;
|
||||||
|
for(int idIdx = 0; idIdx < 30; idIdx++) {
|
||||||
|
if(t->branches[i].navId[idIdx] != __nav__.branches[idIdx]){
|
||||||
|
found = 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
if(found == 1) {
|
||||||
|
__nav__.selectedBranch->cell.background = TART_COLOR_GREEN_FOREGROUND;
|
||||||
|
__nav__.selectedBranch = &t->branches[i];
|
||||||
|
__nav__.selectedBranch->cell.background = TART_COLOR_WHITE_FOREGROUND;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return __nav__.selectedBranch->navId;
|
||||||
|
}
|
||||||
|
|
||||||
float t = 0;
|
float t = 0;
|
||||||
|
|
||||||
@@ -80,20 +163,57 @@ nomi_curve RotateCurve(nomi_curve og, nomi_vec2 d) {
|
|||||||
|
|
||||||
branch create_branch(branch* parent, nomi_vec2 d, unsigned char percent,
|
branch create_branch(branch* parent, nomi_vec2 d, unsigned char percent,
|
||||||
unsigned char b) {
|
unsigned char b) {
|
||||||
branch branch;
|
branch br = {
|
||||||
branch.curve.start = (nomi_vec2){
|
.navId = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
|
||||||
|
.childrenCount = 0,
|
||||||
|
.parent = parent
|
||||||
|
};
|
||||||
|
|
||||||
|
br.curve.start = (nomi_vec2){
|
||||||
0,
|
0,
|
||||||
0};
|
0};
|
||||||
branch.curve.c0 = (nomi_vec2){
|
br.curve.c0 = (nomi_vec2){
|
||||||
(( 25) * -1),
|
(( 25) * -1),
|
||||||
((35/2.f) * -1)}; // controle point 0
|
((35/2.f) * -1)}; // controle point 0
|
||||||
branch.curve.c1 = (nomi_vec2){
|
br.curve.c1 = (nomi_vec2){
|
||||||
(( -10) * -1),
|
(( -10) * -1),
|
||||||
((35/2.f) * -1)}; // controle point 1
|
((35/2.f) * -1)}; // controle point 1
|
||||||
branch.curve.end = (nomi_vec2){
|
br.curve.end = (nomi_vec2){
|
||||||
(( 3) * -1),
|
(( 3) * -1),
|
||||||
((20/2.f) * -1)};
|
((20/2.f) * -1)};
|
||||||
branch.curve = RotateCurve(branch.curve, d);
|
br.curve = RotateCurve(br.curve, d);
|
||||||
|
|
||||||
|
branch* p = parent;
|
||||||
|
branchId tmpId[MAX_BRANCHES] = {1};
|
||||||
|
int depth = 1;
|
||||||
|
br.id = 1;
|
||||||
|
if (parent != NULL) {
|
||||||
|
|
||||||
|
parent->childrenCount++;
|
||||||
|
br.id = parent->childrenCount;
|
||||||
|
tmpId[0] = br.id;
|
||||||
|
|
||||||
|
for(int i = 1; i < MAX_BRANCHES; i++) {
|
||||||
|
tmpId[i] = p->id;
|
||||||
|
depth = i+1;
|
||||||
|
if(p->parent != NULL) {
|
||||||
|
p = p->parent;
|
||||||
|
}else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int i = 0; i < depth; i++) {
|
||||||
|
br.navId[i] = tmpId[depth-1 - i];
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
depth = 0;
|
||||||
|
br.navId[0] = 1;
|
||||||
|
br.id = 1;
|
||||||
|
}
|
||||||
|
br.depth = depth;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if(parent != NULL) {
|
if(parent != NULL) {
|
||||||
float count = percent/100.f;
|
float count = percent/100.f;
|
||||||
@@ -107,17 +227,17 @@ branch create_branch(branch* parent, nomi_vec2 d, unsigned char percent,
|
|||||||
count *((1-count)*((1-count)*parent->curve.c0.y + count * parent->curve.c1.y) +
|
count *((1-count)*((1-count)*parent->curve.c0.y + count * parent->curve.c1.y) +
|
||||||
count * ((1-count)*parent->curve.c1.y + parent->curve.end.y)),
|
count * ((1-count)*parent->curve.c1.y + parent->curve.end.y)),
|
||||||
};
|
};
|
||||||
branch.startPos.x = dpos.x += parent->startPos.x;
|
br.startPos.x = dpos.x += parent->startPos.x;
|
||||||
branch.startPos.y = dpos.y += parent->startPos.y*1;
|
br.startPos.y = dpos.y += parent->startPos.y*1;
|
||||||
branch.cell = NULL_CELL;
|
br.cell = NULL_CELL;
|
||||||
branch.cell.background = b;
|
br.cell.background = b;
|
||||||
return branch;
|
return br;
|
||||||
}
|
}
|
||||||
branch.cell = NULL_CELL;
|
br.cell = NULL_CELL;
|
||||||
branch.cell.background = b;
|
br.cell.background = b;
|
||||||
branch.startPos.x = term_current_size().x/2.f;
|
br.startPos.x = term_current_size().x/2.f;
|
||||||
branch.startPos.y = term_current_size().y/2.f;
|
br.startPos.y = term_current_size().y/2.f;
|
||||||
return branch;
|
return br;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -130,7 +250,7 @@ branch create_branch(branch* parent, nomi_vec2 d, unsigned char percent,
|
|||||||
*/
|
*/
|
||||||
void DrawBranch(branch* branch, unsigned char p, struct tart_window* w, tart_byte b) {
|
void DrawBranch(branch* branch, unsigned char p, struct tart_window* w, tart_byte b) {
|
||||||
// List of random chars to be renderd
|
// List of random chars to be renderd
|
||||||
char cellChart[] = {'%','*','\\','/','l','&','7','+','=','^',':'};
|
char cellChart[] = {'0','1','2','3','l','&','7','+','=','^',':'};
|
||||||
unsigned int iderations = 0;
|
unsigned int iderations = 0;
|
||||||
|
|
||||||
|
|
||||||
@@ -143,7 +263,12 @@ void DrawBranch(branch* branch, unsigned char p, struct tart_window* w, tart_byt
|
|||||||
iderations++; // for selecting a random char to be renderd
|
iderations++; // for selecting a random char to be renderd
|
||||||
|
|
||||||
|
|
||||||
branch->cell.display = cellChart[rand_r(&iderations)%11];
|
//branch->cell.display = cellChart[rand_r(&iderations)%11];
|
||||||
|
if(branch->id > 0 && branch->id < 11) {
|
||||||
|
branch->cell.display = cellChart[branch->id];
|
||||||
|
}else {
|
||||||
|
branch->cell.display = cellChart[10];
|
||||||
|
}
|
||||||
|
|
||||||
dpos = (struct tart_vec2){
|
dpos = (struct tart_vec2){
|
||||||
(1-count)*((1-count)*((1-count)*branch->curve.start.x + count * branch->curve.c0.x) +
|
(1-count)*((1-count)*((1-count)*branch->curve.start.x + count * branch->curve.c0.x) +
|
||||||
|
|||||||
@@ -40,19 +40,25 @@ typedef struct {
|
|||||||
// All of the different notes
|
// All of the different notes
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char* text; // This is the data that is in that branch
|
char* text; // This is the data that is in that branch
|
||||||
|
branchId id; // This holds the branch id.
|
||||||
|
branchId navId[MAX_BRANCHES];
|
||||||
|
branchId depth;
|
||||||
branchId children[MAX_CHILDREN]; // holds the branchIds of its children
|
branchId children[MAX_CHILDREN]; // holds the branchIds of its children
|
||||||
|
branchId childrenCount;
|
||||||
|
|
||||||
struct tart_cell cell;
|
struct tart_cell cell;
|
||||||
void* parent; // points the the branches parent
|
void* parent; // points the the branches parent
|
||||||
char type; // holds the type as in if this struct is a branch or a trunk
|
char type; // holds the type as in if this struct is a branch or a trunk
|
||||||
float angle;
|
float angle;
|
||||||
nomi_vec2 startPos; // the starting position of the branch
|
nomi_vec2 startPos; // the starting position of the branch
|
||||||
nomi_curve curve;
|
nomi_curve curve;
|
||||||
branchId id; // This holds the branch id.
|
|
||||||
} branch;
|
} branch;
|
||||||
|
|
||||||
// The Root of the tree structure
|
// The Root of the tree structure
|
||||||
typedef struct {
|
typedef struct {
|
||||||
branch branches[MAX_BRANCHES];
|
branch branches[MAX_BRANCHES];
|
||||||
|
branchId branchCount;
|
||||||
const char* title;
|
const char* title;
|
||||||
char* text;
|
char* text;
|
||||||
} trunk;
|
} trunk;
|
||||||
@@ -60,21 +66,23 @@ typedef struct {
|
|||||||
/*
|
/*
|
||||||
* This will Init Nomi
|
* This will Init Nomi
|
||||||
*/
|
*/
|
||||||
void NomiInit();
|
void NomiInit(trunk* tr);
|
||||||
|
branchId* NomiNavigation(char input);
|
||||||
/*
|
/*
|
||||||
* This will create the truk of the note.
|
* This will create the truk of the note.
|
||||||
* */
|
* */
|
||||||
trunk* CreateTrunk();
|
trunk CreateTrunk(char* title, branch root);
|
||||||
|
void DrawTrunk(trunk* tr, struct tart_window* w, tart_byte b);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This is a test
|
* This is a test
|
||||||
* */
|
* */
|
||||||
void CreaetBranch(trunk* trunk);
|
void AddBranch(trunk* t, branch br);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Locate Branch
|
* Locate Branch
|
||||||
* */
|
* */
|
||||||
branch* LocateBranch();
|
branchId* LocateBranch(trunk* t);
|
||||||
|
|
||||||
branch create_branch(branch* parent, nomi_vec2 d, unsigned char percent, unsigned char b);
|
branch create_branch(branch* parent, nomi_vec2 d, unsigned char percent, unsigned char b);
|
||||||
/*
|
/*
|
||||||
|
|||||||
Reference in New Issue
Block a user