delegate draw to persons

This commit is contained in:
vrd
2022-12-24 17:59:54 +02:00
parent 5e9d2d8501
commit cd221476a5
4 changed files with 47 additions and 22 deletions
+14
View File
@@ -169,3 +169,17 @@ WINDOW* Person::createPad()const
return pad; return pad;
} }
void Person::draw(U16 drawY, U16 drawX) const
{
U16 width = name_.size() + 4; /* TODO: get actual lenght */
WINDOW* pad = newpad(BOX_HEIGHT, width);
box(pad, BOX_HEIGHT, width);
mvwaddstr(pad, 2, 2, name_.data());
pnoutrefresh(pad, 0, 0,
drawY, drawX,
drawY + BOX_HEIGHT-1, drawX + width-1);
delwin(pad);
}
+12 -1
View File
@@ -20,22 +20,33 @@ struct EventTime
I8 minute; //0-59 I8 minute; //0-59
}; };
enum { BOX_HEIGHT = 5 };
class Person class Person
{ {
public: public:
Person() = default; Person() = default;
Person(const char* name, EventTime birth, bool sex, EventTime death); Person(const char* name, EventTime birth, bool sex, EventTime death);
/* Person(Person&&) = default; */
/* Person& operator=(Person&&) = default; */
/* Person& operator=(const Person&) = default; */
bool operator==(const Person &other)const; bool operator==(const Person &other)const;
void save(std::ofstream &file)const;// void save(std::ofstream &file)const;//
void load(std::ifstream &file); void load(std::ifstream &file);
void rename(const char* newName); void rename(const char* newName);
void print() const; void print() const;
/* Draw a Person's box on the terminal
drawY,drawX - the coordinates where to draw
returns the width of the box*/
void draw(U16 drawY, U16 drawX) const;
WINDOW* createPad()const; WINDOW* createPad()const;
/* staitc constexpr U8 BOX_HEIGHT = 5; */
friend class Tree; friend class Tree;
private: private:
+13 -15
View File
@@ -7,11 +7,6 @@
using std::cout; using std::cout;
Tree::Tree()
: treeName("Unnamed")
, numPeople(0)
{}
Tree Tree::operator+ (const Tree& other)// Tree Tree::operator+ (const Tree& other)//
{ {
Tree result(treeName + other.treeName); //The tree resulting from the addition Tree result(treeName + other.treeName); //The tree resulting from the addition
@@ -442,18 +437,21 @@ void Tree::removeRelation(const unsigned firstId, const unsigned secondId)
void Tree::draw() const void Tree::draw() const
{ {
WINDOW* father = people[0].createPad(); /* WINDOW* father = people[0].createPad(); */
WINDOW* mother = people[1].createPad(); /* WINDOW* mother = people[1].createPad(); */
U16 fw = getmaxx(father); /* return size, not coords */ /* U16 fw = getmaxx(father); /\* return size, not coords *\/ */
U16 fh = getmaxy(father); /* U16 fh = getmaxy(father); */
U16 mw = getmaxx(mother); /* U16 mw = getmaxx(mother); */
U16 mh = getmaxy(mother); /* U16 mh = getmaxy(mother); */
U16 drawX = (COLS - fw - mw) / 2; /* U16 drawX = (COLS - fw - mw) / 2; */
pnoutrefresh(father, 0, 0, /* pnoutrefresh(father, 0, 0, */
1, drawX, /* 1, drawX, */
1 +fh-1, drawX + fw-1); /* 1 +fh-1, drawX + fw-1); */
people[0].draw(0, 0);
/* pnoutrefresh(mother, 0, 0, 1, d */ /* pnoutrefresh(mother, 0, 0, 1, d */
+7 -5
View File
@@ -21,14 +21,14 @@ enum Relation : U8
ExHusband ExHusband
}; };
const unsigned Nobody = UINT_MAX; //Òîçè íîìåð ùå áúäå çàïàçeí çà ëèïñà íà âðúçêà/÷îâåê const U32 Nobody = UINT_MAX; //Òîçè íîìåð ùå áúäå çàïàçeí çà ëèïñà íà âðúçêà/÷îâåê
class Tree class Tree
{ {
public: public:
Tree(); Tree() = default;
template <class Str> template <class Str>
Tree(Str&& Name) : treeName(std::forward<Str>(Name)), numPeople(0) {} Tree(Str&& Name) : treeName(std::forward<Str>(Name)) {}
/*Tree(const Tree&); /*Tree(const Tree&);
Tree& operator= (const Tree& other);*/ Tree& operator= (const Tree& other);*/
@@ -67,11 +67,13 @@ public:
private: private:
void commonAncestorRec(const unsigned &id, const Array<char> &visited)const; void commonAncestorRec(const unsigned &id, const Array<char> &visited)const;
std::string treeName; std::string treeName = "Unnamed";
unsigned numPeople; unsigned numPeople = 0;
Array<Person> people; //The data for each member Array<Person> people; //The data for each member
Array<Array<unsigned>> relatives; //The relatives of each member Array<Array<unsigned>> relatives; //The relatives of each member
Array<Array<Relation>> relations; //The type of relation each member has with his relatives Array<Array<Relation>> relations; //The type of relation each member has with his relatives
U16 offset = 0;
//Search, ect. //Search, ect.
}; };