select siblings and initial tree scrolling
This commit is contained in:
@@ -200,6 +200,17 @@ person_id Tree::findParent(person_id child, bool isParentMale) const
|
||||
return parent;
|
||||
}
|
||||
|
||||
std::vector<person_id> Tree::findChildren(person_id person) const
|
||||
{
|
||||
vector<person_id> children;
|
||||
for(const Relation& rel: relations[person])
|
||||
{
|
||||
if (rel.type == Parent)
|
||||
children.push_back(rel.id);
|
||||
}
|
||||
return children;
|
||||
}
|
||||
|
||||
person_id Tree::findSpouse(person_id person) const
|
||||
{
|
||||
person_id spouse = Nobody;
|
||||
@@ -215,16 +226,16 @@ person_id Tree::findSpouse(person_id person) const
|
||||
}
|
||||
|
||||
|
||||
/* person_id Tree::findRelation(person_id first, person_id second) const */
|
||||
/* { */
|
||||
/* const auto& curRels = relations[first]; */
|
||||
/* for(auto i =0; i<curRels.size(); ++i) */
|
||||
/* { */
|
||||
/* if (curRels[i].id == second) */
|
||||
/* { */
|
||||
|
||||
/* } */
|
||||
|
||||
RelType Tree::findRelation(person_id first, person_id second) const
|
||||
{
|
||||
const auto& curRels = relations[first];
|
||||
for(const Relation& rel: curRels)
|
||||
{
|
||||
if (rel.id == second)
|
||||
return rel.type;
|
||||
}
|
||||
return None;
|
||||
}
|
||||
|
||||
void Tree::saveTree() const
|
||||
{
|
||||
@@ -412,11 +423,21 @@ void Tree::display()
|
||||
focused_ = selected_;
|
||||
draw();
|
||||
break;
|
||||
case KEY_LEFT:
|
||||
--offsetX_;
|
||||
draw();
|
||||
break;
|
||||
case KEY_RIGHT:
|
||||
++offsetX_;
|
||||
draw();
|
||||
break;
|
||||
case KEY_DOWN:
|
||||
selectDown();
|
||||
++offsetY_;
|
||||
draw();
|
||||
break;
|
||||
case KEY_UP:
|
||||
selectUp();
|
||||
--offsetY_;
|
||||
draw();
|
||||
break;
|
||||
case 'h':
|
||||
selectLeft();
|
||||
@@ -445,8 +466,8 @@ void Tree::draw() const
|
||||
erase(); //Clear the screen
|
||||
wnoutrefresh(stdscr);
|
||||
|
||||
I16 drawY = 0/* (LINES) / 2 */;
|
||||
I16 drawX = 0/* (COLS) / 2 */;
|
||||
I16 drawY = offsetY_/* (LINES) / 2 */;
|
||||
I16 drawX = offsetX_/* (COLS) / 2 */;
|
||||
drawLineWithWives(focused_, drawY, drawX);
|
||||
|
||||
doupdate();
|
||||
@@ -660,14 +681,15 @@ void Tree::selectLeft() /* todo */
|
||||
{
|
||||
if (findCommonAncestor(focused_, selected_) != Nobody) //if the selected is part of main tree
|
||||
{
|
||||
|
||||
selectLeftSibSpouse(selected_);
|
||||
}
|
||||
else
|
||||
{
|
||||
person_id spouse = findSpouse(selected_);
|
||||
assert(spouse != Nobody);
|
||||
selected_ = spouse;
|
||||
draw();
|
||||
}
|
||||
draw();
|
||||
}
|
||||
|
||||
|
||||
@@ -710,19 +732,87 @@ void Tree::selectUp()
|
||||
draw();
|
||||
}
|
||||
|
||||
void Tree::selectRight() /* todo */
|
||||
void Tree::selectRight()
|
||||
{
|
||||
if (findCommonAncestor(focused_, selected_) != Nobody) //if the selected is part of main tree
|
||||
{
|
||||
person_id spouse = findSpouse(selected_);
|
||||
if (spouse != Nobody)
|
||||
if (person_id spouse = findSpouse(selected_); spouse != Nobody)
|
||||
{
|
||||
selected_ = spouse;
|
||||
}
|
||||
else
|
||||
;
|
||||
draw();
|
||||
{
|
||||
selectRightSib(selected_);
|
||||
}
|
||||
}
|
||||
else
|
||||
else //if spouse of someone in main tree
|
||||
{
|
||||
person_id spouse = findSpouse(selected_);
|
||||
assert(spouse != Nobody);
|
||||
selectRightSib(spouse);
|
||||
}
|
||||
draw();
|
||||
}
|
||||
|
||||
void Tree::selectLeftSibSpouse(person_id person) /* todo: return a value and split */
|
||||
{
|
||||
person_id leftSib = Nobody;
|
||||
if(findRelation(person, focused_) == Child)
|
||||
{
|
||||
auto siblings = findChildren(focused_);
|
||||
for(auto it = siblings.begin()+1; it < siblings.end(); ++it)
|
||||
{
|
||||
if(*it == person)
|
||||
{
|
||||
leftSib = *(it-1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(person_id sel_par = findParent(person, true); sel_par != Nobody)
|
||||
{
|
||||
auto siblings = findChildren(sel_par);
|
||||
for(auto it = siblings.begin()+1; it < siblings.end(); ++it)
|
||||
{
|
||||
if(*it == person)
|
||||
{
|
||||
leftSib = *(it-1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(leftSib != Nobody)
|
||||
{
|
||||
person_id leftSibSpouse = findSpouse(leftSib);
|
||||
selected_ = leftSibSpouse != Nobody ? leftSibSpouse : leftSib;
|
||||
}
|
||||
}
|
||||
|
||||
void Tree::selectRightSib(person_id person)
|
||||
{
|
||||
if(findRelation(person, focused_) == Child)
|
||||
{
|
||||
auto siblings = findChildren(focused_);
|
||||
for(auto it = siblings.begin(); it < siblings.end()-1; ++it)
|
||||
{
|
||||
if(*it == person)
|
||||
{
|
||||
selected_ = *(it+1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(person_id sel_par = findParent(person, true); sel_par != Nobody)
|
||||
{
|
||||
auto siblings = findChildren(sel_par);
|
||||
for(auto it = siblings.begin(); it < siblings.end()-1; ++it)
|
||||
{
|
||||
if(*it == person)
|
||||
{
|
||||
selected_ = *(it+1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user