draw with wife

This commit is contained in:
vrd
2022-12-28 15:55:42 +02:00
parent b3a2787fcd
commit f77f55366e
5 changed files with 46 additions and 32 deletions
+1 -1
View File
@@ -1 +1 @@
g++ -o bin/debug/famt -std=gnu++20 -g -Og *.cpp -lncursesw g++ -o bin/debug/famt -std=gnu++20 -g -O0 *.cpp -lncursesw
+5
View File
@@ -6,3 +6,8 @@ unsigned strLen(const char* str);
void strCopy(char *to, const char* from); void strCopy(char *to, const char* from);
bool strComp(const char* firts, const char* second); //0 - diffrent 1 - same bool strComp(const char* firts, const char* second); //0 - diffrent 1 - same
char* mergeStr(const char* first, const char* second); char* mergeStr(const char* first, const char* second);
inline I32 max(I32 a, I32 b)
{
return a >= b ? a : b;
}
+3 -3
View File
@@ -20,7 +20,7 @@ int main()
test1.addPerson("Rumen", true, Nobody, Nobody, {1968, 8, 9}); test1.addPerson("Rumen", true, Nobody, Nobody, {1968, 8, 9});
test1.addPerson("Nadejda", false, Nobody, Nobody, {1972, 12, 15}); test1.addPerson("Nadejda", false, Nobody, Nobody, {1972, 12, 15});
/* test1.addRelation(0, Husband, 1); */ test1.addRelation(0, Spouse, 1);
test1.addPerson("Venelin", true, 0, 1, {1998, 6, 9}); test1.addPerson("Venelin", true, 0, 1, {1998, 6, 9});
test1.addPerson("Vasil", true, 0, 1, {2001, 1, 16}); test1.addPerson("Vasil", true, 0, 1, {2001, 1, 16});
/* test1.addRelation(2, Brother, 3); */ /* test1.addRelation(2, Brother, 3); */
@@ -30,12 +30,12 @@ int main()
test2.addPerson("Vasil Dimitrov", true, Nobody, Nobody, {1941, 5, 18}); test2.addPerson("Vasil Dimitrov", true, Nobody, Nobody, {1941, 5, 18});
test2.addPerson("Maria", false); test2.addPerson("Maria", false);
/* test2.addRelation(0, Husband, 1); */ test2.addRelation(0, Spouse, 1);
test2.addPerson("Dimitar", true, 0, 1); test2.addPerson("Dimitar", true, 0, 1);
test2.addPerson("Nadejda", false, 0, 1, {1972, 12, 15}); test2.addPerson("Nadejda", false, 0, 1, {1972, 12, 15});
/* test2.addRelation(2, Brother, 3); */ /* test2.addRelation(2, Brother, 3); */
test2.addPerson("Branimira", false); test2.addPerson("Branimira", false);
/* test2.addRelation(2, Husband, 4); */ test2.addRelation(2, Spouse, 4);
test2.addPerson("Ioan", true, 2, 4); test2.addPerson("Ioan", true, 2, 4);
test2.addPerson("Rumiana", false, 2, 4); test2.addPerson("Rumiana", false, 2, 4);
/* test2.addRelation(5, Brother, 6); */ /* test2.addRelation(5, Brother, 6); */
+36 -28
View File
@@ -389,7 +389,7 @@ void Tree::draw(person_id focused) const
U16 drawY = 0/* (LINES) / 2 */; U16 drawY = 0/* (LINES) / 2 */;
U16 drawX = 0/* (COLS) / 2 */; U16 drawX = 0/* (COLS) / 2 */;
drawLine(focused, drawY, drawX); drawLineWithWives(focused, drawY, drawX);
/* people[0].draw(drawY, drawY); */ /* people[0].draw(drawY, drawY); */
/* for(U32 i=0; i<relations[0].gNum(); ++i) */ /* for(U32 i=0; i<relations[0].gNum(); ++i) */
/* { */ /* { */
@@ -559,40 +559,48 @@ I16 Tree::drawLine(person_id id, I16 drawY, I16 drawX) const
return drawX + people[id].boxWidth() + dist_between; return drawX + people[id].boxWidth() + dist_between;
} }
I16 Tree::drawLineWithWives(person_id id, I16 drawY, I16 drawX) const I16 Tree::drawLineWithWives(person_id id, I16 drawY, const I16 drawX) const
{ {
/* const auto& rels = relations[id]; */ const Person& person = people[id];
/* /\* const auto& rels = relations[id]; *\/ */ const auto& rels = relations[id];
/* people[id].draw(drawY, drawX); */ person.draw(drawY, drawX);
person_id spouse = Nobody;
std::vector<person_id> children;
for(person_id i = 0; i < rels.gNum(); ++i)
{
if(rels[i].type == RelType::Parent)
children.push_back(rels[i].id);
else if(rels[i].type == RelType::Spouse && spouse == Nobody)
spouse = rels[i].id;
}
/* /\* for(U32 i = 0; i < re *\/ */ U16 spouse_width = 0;
if(spouse != Nobody)
{
people[spouse].draw(drawY, drawX + person.boxWidth() + spouse_dist);
spouse_width = spouse_dist + people[spouse].boxWidth();
}
/* std::vector<person_id> children; */ auto childX = drawX;
/* for(U32 i=0; i<relations[id].gNum(); ++i) */ if(!children.empty())
/* { */ {
/* if(relations[id][i] == RelType::Parent) */ auto prevX = childX;
/* children.push_back(relatives[id][i]); */ drawY += BOX_HEIGHT;
/* } */
/* if(!children.empty()) */ auto lnHt = linkToFirstBorn(drawY, childX); /* Link height */
/* { */ childX = drawLineWithWives(children[0], drawY + lnHt, childX);
/* auto prevX = drawX; */
/* drawY += BOX_HEIGHT; */
/* auto lnHt = linkToFirstBorn(drawY, drawX); /\* Link height *\/ */ for(size_t j = 1; j < children.size(); ++j)
/* drawX = drawLine(children[0], drawY + lnHt, drawX); */ {
lnHt = linkToChild(drawY+1, prevX+1, childX+1);
prevX = childX;
childX = drawLineWithWives(children[j], drawY + lnHt, childX);
}
}
/* for(size_t j = 1; j < children.size(); ++j) */ return max(drawX + person.boxWidth() + dist_between + spouse_width,
/* { */ childX);
/* 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; */
} }
+1
View File
@@ -68,6 +68,7 @@ private:
U16 offset = 0; U16 offset = 0;
U8 dist_between = 1; U8 dist_between = 1;
U8 spouse_dist = 0;
//Search, ect. //Search, ect.
}; };