From 5e9d2d85012206ee3684350c8b405875f7fb7ec4 Mon Sep 17 00:00:00 2001 From: Venelin Date: Sun, 18 Dec 2022 00:35:01 +0200 Subject: [PATCH] initial draw --- main.cpp | 3 ++- person.cpp | 11 +++++++++++ person.h | 3 +++ tree.cpp | 37 +++++++++++++++++++++++++++---------- 4 files changed, 43 insertions(+), 11 deletions(-) diff --git a/main.cpp b/main.cpp index bc082d7..8f791c4 100644 --- a/main.cpp +++ b/main.cpp @@ -8,10 +8,11 @@ using std::cout; int main() { setlocale(LC_ALL, ""); + initscr(); /* Start curses mode */ noecho(); cbreak(); /* get input instantly */ - refresh(); /* if not present the first real refresh is missed */ + wnoutrefresh(stdscr); /* if not present the first real refresh is missed */ /*Tree test1("Dechkovi"); //addTree Dechkovi addTree Karamanovi load 0 load 1 (to work with these example trees) Tree test2("Karamanovi"); diff --git a/person.cpp b/person.cpp index 46623e0..562d246 100644 --- a/person.cpp +++ b/person.cpp @@ -158,3 +158,14 @@ void Person::print()const /* cout << '\n'; */ } + +WINDOW* Person::createPad()const +{ + U16 width = name_.size() + 4; + WINDOW* pad = newpad(5, width); + + box(pad, 5, width); + mvwaddstr(pad, 2, 2, name_.data()); + + return pad; +} diff --git a/person.h b/person.h index bfc85b0..912384e 100644 --- a/person.h +++ b/person.h @@ -2,6 +2,7 @@ #include #include +#include #include "common/basicTypes.h" struct EventTime @@ -33,6 +34,8 @@ public: void rename(const char* newName); void print()const; + WINDOW* createPad()const; + friend class Tree; private: diff --git a/tree.cpp b/tree.cpp index cf96618..92aa4b3 100644 --- a/tree.cpp +++ b/tree.cpp @@ -8,7 +8,7 @@ using std::cout; Tree::Tree() - : treeName("Unnamed") + : treeName("Unnamed") , numPeople(0) {} @@ -34,7 +34,7 @@ Tree Tree::operator+ (const Tree& other)// result.numPeople = idCounter; //The number of members the resulting tree has result.people.resize(result.numPeople); - result.people = people; //Adds the members of the I tree to the resulting tree + result.people = people; //Adds the members of the I tree to the resulting tree for (unsigned i=0; i < other.numPeople; ++i) //Adds the members of the II tree to the resulting tree { if (newId[i] >= numPeople) @@ -48,14 +48,14 @@ Tree Tree::operator+ (const Tree& other)// for (unsigned i=0; i < other.numPeople; ++i) //Adds the relatives from the II tree { - if (newId[i] >= numPeople) //If the member is found in the II tree but not in the I + if (newId[i] >= numPeople) //If the member is found in the II tree but not in the I { result.relatives.push(other.relatives[i]); result.relations.push(other.relations[i]); } else //If he's found in both { - for (unsigned j = 0; j < other.people[i].numRel_; ++j) //Adds the number of relatives from the II to the number in the I + for (unsigned j = 0; j < other.people[i].numRel_; ++j) //Adds the number of relatives from the II to the number in the I { if(newId[other.relatives[i][j]] > numPeople) ++result.people[newId[i]].numRel_; @@ -66,7 +66,7 @@ Tree Tree::operator+ (const Tree& other)// result.relatives[newId[i]] = relatives[newId[i]]; result.relations[newId[i]] = relations[newId[i]]; - result.relatives[newId[i]] += other.relatives[i]; //The relatives from the II tree + result.relatives[newId[i]] += other.relatives[i]; //The relatives from the II tree result.relations[newId[i]] += other.relations[i]; } } @@ -95,7 +95,7 @@ Tree& Tree::operator+=(const Tree& other) } people.resize(idCounter); - for (unsigned i = 0; i < other.numPeople; ++i) //Adds the member personal data of II tree to I tree + for (unsigned i = 0; i < other.numPeople; ++i) //Adds the member personal data of II tree to I tree { if (newId[i] >= numPeople) people.push(other.people[i]); @@ -103,7 +103,7 @@ Tree& Tree::operator+=(const Tree& other) relatives.resize(idCounter); relations.resize(idCounter); - for (unsigned i = 0; i < other.numPeople; ++i) //Merges the relative data + for (unsigned i = 0; i < other.numPeople; ++i) //Merges the relative data { if (newId[i] >= numPeople) { @@ -114,7 +114,7 @@ Tree& Tree::operator+=(const Tree& other) } else //If the member is present in both trees { - for (unsigned j = 0; j < other.people[i].numRel_; ++j) //Adds the number of relatives from the II to the number in the I + for (unsigned j = 0; j < other.people[i].numRel_; ++j) //Adds the number of relatives from the II to the number in the I { if (newId[other.relatives[i][j]] >= numPeople) ++people[newId[i]].numRel_; @@ -160,7 +160,7 @@ void Tree::rename(const char* newName) unsigned Tree::findId(const char* name, const short year, const unsigned char month, const unsigned char day)const { - //TODO + //TODO //Person sought(name, day, month, year,) for (unsigned i = 0; i < numPeople; ++i) { @@ -378,7 +378,7 @@ void Tree::removeRelation(const char* firstName, const char* secondName) void Tree::removePerson(const unsigned id) { - unsigned relId; //Íoìåð íà òåêóùèÿ ðîäíèíàòà + unsigned relId; //Íoìåð íà òåêóùèÿ ðîäíèíàòà for (unsigned i = 0; i < people[id].numRel_; ++i) //Ïðåìàõâàò ñå âðúçêèòå íà ÷ëåíà çà ïðåìàõâàíå { relId = relatives[id][i]; @@ -442,6 +442,23 @@ void Tree::removeRelation(const unsigned firstId, const unsigned secondId) void Tree::draw() const { + WINDOW* father = people[0].createPad(); + WINDOW* mother = people[1].createPad(); + + U16 fw = getmaxx(father); /* return size, not coords */ + U16 fh = getmaxy(father); + U16 mw = getmaxx(mother); + U16 mh = getmaxy(mother); + + U16 drawX = (COLS - fw - mw) / 2; + pnoutrefresh(father, 0, 0, + 1, drawX, + 1 +fh-1, drawX + fw-1); + + /* pnoutrefresh(mother, 0, 0, 1, d */ + + doupdate(); + getch(); }