add indication for people with subtrees

This commit is contained in:
Venelin
2024-06-19 22:50:29 +03:00
parent c96bbdbecf
commit 5aaeaf3247
4 changed files with 56 additions and 67 deletions
+29 -12
View File
@@ -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;
}
+14 -3
View File
@@ -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;
};
+11 -50
View File
@@ -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<person_id> children; */
/* for(U32 i=0; i<relations_[id].size(); ++i) */
/* { */
/* if (relations_[id][i].type == RelType::Parent) */
/* children.push_back(relations_[id][i].id); */
/* } */
/* if (!children.empty()) */
/* { */
/* auto prevX = drawX; */
/* drawY += BOX_HEIGHT; */
/* auto lnHt = linkToFirstBorn(drawY, drawX); /\* Link height *\/ */
/* drawX = drawLine(children[0], drawY + lnHt, drawX); */
/* for(size_t j = 1; j < children.size(); ++j) */
/* { */
/* lnHt = linkToChild(drawY+1, prevX+1, drawX+1); */
/* prevX = drawX; */
/* drawX = drawLine(children[j], drawY + lnHt, drawX); */
/* } */
/* return drawX; */
/* } */
/* return drawX + people_[id].boxWidth() + dist_between_; */
/* } */
I16 Tree::drawLineWithWives(const person_id id, I16 drawY, const I16 drawX) const
I16 Tree::drawLineWithSpouses(const person_id id, I16 drawY, const I16 drawX) const
{
const Person& person = people_[id];
const auto& rels = relations_[id];
person_id spouse = Nobody;
vector<person_id> children;
for(const auto& rel: rels)
{
if (rel.type == RelType::Parent)
children.push_back(rel.id);
person_id spouse = findSpouse(id);
vector<person_id> 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);
}
}
+2 -2
View File
@@ -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<Person> people_; //The data for each member