From 5aaeaf32474b0f4807aa2343a0611225ccafad4c Mon Sep 17 00:00:00 2001 From: Venelin Date: Wed, 19 Jun 2024 22:50:29 +0300 Subject: [PATCH] add indication for people with subtrees --- src/person.cpp | 41 +++++++++++++++++++++++---------- src/person.hpp | 17 +++++++++++--- src/tree.cpp | 61 +++++++++----------------------------------------- src/tree.hpp | 4 ++-- 4 files changed, 56 insertions(+), 67 deletions(-) diff --git a/src/person.cpp b/src/person.cpp index 712f5da..ee625c3 100644 --- a/src/person.cpp +++ b/src/person.cpp @@ -90,10 +90,29 @@ static U16 Utf8SymbolsCount(const string& str) return num; } -U16 Person::draw(const I16 drawY, const I16 drawX, bool selected, bool hasSpouse, - bool hasParents, bool hasKids, bool wholeName) const +U16 Person::drawAsFocused(const I16 drawY, const I16 drawX, bool selected, bool hasSpouse, + bool hasKids, bool wholeName) const { - string display_name; /* todo remove? */ + auto topright = hasSpouse ? ACS_TTEE : ACS_URCORNER; + auto botleft = hasKids ? ACS_LTEE : ACS_LLCORNER; + + return draw(drawY, drawX, selected, wholeName, + ACS_LTEE, topright, + botleft, ACS_LRCORNER ); +} + +U16 Person::drawAsSpouse(I16 drawY, I16 drawX, bool selected, bool hasTree, bool wholeName) const +{ + auto topright = hasTree ? '@' : ACS_URCORNER; + return draw(drawY, drawX, selected, wholeName, + ACS_TTEE, topright, + ACS_LLCORNER, ACS_LRCORNER ); +} + +U16 Person::draw(I16 drawY, I16 drawX, bool selected, bool wholeName, + U32 topleft, U32 topright, U32 botleft, U32 botright) const +{ + string display_name; if(wholeName) { display_name = name; @@ -103,9 +122,7 @@ U16 Person::draw(const I16 drawY, const I16 drawX, bool selected, bool hasSpouse size_t space = name.find(' '); if(space != string::npos) { - /* name[space] = '\0'; */ display_name = name.substr(0, space); - /* name[space] = ' '; */ } else { @@ -113,24 +130,23 @@ U16 Person::draw(const I16 drawY, const I16 drawX, bool selected, bool hasSpouse } } - const U16 width = Utf8SymbolsCount(display_name) + 4; /* pad width */ + + /* pad width */ + const U16 width = Utf8SymbolsCount(display_name) + 4; if(willBeVisible(drawY, drawX, BOX_HEIGHT, width)) { AutoWin pad( newpad(BOX_HEIGHT, width) ); auto color_pair = COLOR_PAIR( selected ? COLOR_SELECTED - : (sex==M ? COLOR_MALE : COLOR_FEMALE) ); + : (sex==M ? COLOR_MALE : COLOR_FEMALE) ); wbkgd(pad, color_pair); /* wattron(pad, color_pair); */ - auto top_left = hasParents ? ACS_LTEE : ACS_TTEE; - auto top_right = hasSpouse ? ACS_TTEE : ACS_URCORNER; - auto bot_left = hasKids ? ACS_LTEE : ACS_LLCORNER; wborder(pad, ACS_VLINE, ACS_VLINE, ACS_HLINE, ACS_HLINE, - top_left, top_right, - bot_left, ACS_LRCORNER ); + topleft, topright, + botleft, botright); mvwaddstr(pad, 2, 2, display_name.data()); @@ -139,4 +155,5 @@ U16 Person::draw(const I16 drawY, const I16 drawX, bool selected, bool hasSpouse drawpad(pad, drawY, drawX); } return width; + } diff --git a/src/person.hpp b/src/person.hpp index 7a24fa8..5399ce7 100644 --- a/src/person.hpp +++ b/src/person.hpp @@ -51,15 +51,26 @@ public: void displayInfo() const; - /* Draw a Person's box on the terminal + /* Draw a Person's box on the terminal, as a part of the focused tree drawY,drawX - top left coordinates where to draw (negative if outside the screen) + partOfMain - is the person a decendant of the current root hasSpouse, hasSpouse, hasChildren - wheather the person has them on display returns the width of the box*/ - U16 draw(I16 drawY, I16 drawX, bool selected, bool hasSpouse, - bool hasParents, bool hasChildren=false, bool wholeName=true) const; + U16 drawAsFocused(I16 drawY, I16 drawX, bool selected, bool hasSpouse, + bool hasChildren=false, bool wholeName=true) const; + + /* Draw a Person's box on the terminal, as a spouse of someone in the focused tree + drawY,drawX - top left coordinates where to draw (negative if outside the screen) + hasTree - weather the spouse has a tree that can be displayed + returns the width of the box*/ + U16 drawAsSpouse(I16 drawY, I16 drawX, bool selected, bool hasTree, bool wholeName=true) const; std::string name; EventTime birth; Sex sex; EventTime death; + +private: + U16 draw(I16 drawY, I16 drawX, bool selected, bool wholeName, + U32 topleft, U32 topright, U32 botleft, U32 botright) const; }; diff --git a/src/tree.cpp b/src/tree.cpp index f02b3a8..0a59198 100644 --- a/src/tree.cpp +++ b/src/tree.cpp @@ -434,7 +434,7 @@ void Tree::draw(const person_id selected, const U8 zoom, const I16 offsetY, cons erase(); //Clear the screen wnoutrefresh(stdscr); - drawLineWithWives(focused_, offsetY, offsetX); + drawLineWithSpouses(focused_, offsetY, offsetX); doupdate(); } @@ -494,62 +494,23 @@ static U8 linkToChild(I16 startY, I16 startX, I16 endX, bool moreSiblings) return 2; } - -/* I16 Tree::drawLine(person_id id, I16 drawY, I16 drawX) const */ -/* { */ -/* people_[id].draw(drawY, drawX, true, false, true); */ - -/* vector children; */ -/* for(U32 i=0; i children; - for(const auto& rel: rels) - { - if (rel.type == RelType::Parent) - children.push_back(rel.id); + person_id spouse = findSpouse(id); + vector children = findChildren(id); - else if (rel.type == RelType::Spouse && spouse == Nobody) - spouse = rel.id; - } const size_t numKids = children.size(); - U16 person_w = person.draw(drawY, drawX, - id == selected_, spouse!=Nobody, true, numKids!=0, zoom_==1); + U16 person_w = person.drawAsFocused(drawY, drawX, + id == selected_, spouse!=Nobody, numKids!=0, zoom_>=1); U16 spouse_w = 0; if (spouse != Nobody) { - U16 spouse_box = people_[spouse].draw(drawY, drawX + person_w + spouse_dist_, - spouse == selected_, false, false, false, zoom_==1); + bool spouse_has_tree = (findParent(spouse, M) != Nobody) || (findParent(spouse, F) != Nobody); + U16 spouse_box = people_[spouse].drawAsSpouse(drawY, drawX + person_w + spouse_dist_, + spouse == selected_, spouse_has_tree, zoom_>=1); spouse_w = spouse_dist_ + spouse_box; } @@ -560,7 +521,7 @@ I16 Tree::drawLineWithWives(const person_id id, I16 drawY, const I16 drawX) cons drawY += BOX_HEIGHT; auto lnHt = linkToFirstBorn(drawY, childX, numKids > 1); /* Link height */ - childX = drawLineWithWives(children[0], drawY + lnHt, childX); + childX = drawLineWithSpouses(children[0], drawY + lnHt, childX); for(size_t j = 1; j < numKids; ++j) { @@ -568,7 +529,7 @@ I16 Tree::drawLineWithWives(const person_id id, I16 drawY, const I16 drawX) cons lnHt = linkToChild(drawY+1, prevX+1, childX+1, j < numKids-1) + 1; prevX = childX; - childX = drawLineWithWives(children[j], drawY + lnHt, childX); + childX = drawLineWithSpouses(children[j], drawY + lnHt, childX); } } diff --git a/src/tree.hpp b/src/tree.hpp index 62d1396..4371930 100644 --- a/src/tree.hpp +++ b/src/tree.hpp @@ -87,8 +87,8 @@ private: void updateRels(person_id); /* draw a line of people starting from person with id - return the farthest X that will be drawn */ - I16 drawLineWithWives(person_id, I16 drawY, I16 drawX) const; + return the farthest X on the screen where it will be drawn */ + I16 drawLineWithSpouses(person_id, I16 drawY, I16 drawX) const; std::string treeName_; std::vector people_; //The data for each member