This commit is contained in:
vrd
2023-03-06 10:24:32 +02:00
parent cc7a689dc1
commit 9ef74b8283
5 changed files with 70 additions and 28 deletions
+7
View File
@@ -52,6 +52,13 @@ Make sure you satisfy the dependencies and have permissons and execute:
HOW TO USE:
tft ${MY_TFT_FILE}
Navigation:
arrows - move the camera
h, j, k, l - move around the tree
Enter, Space - display the selected person's tree
+ - show full names
- - show first names only
TFT FORMAT:
- All spaces are ignored e.g.: Adam 0 and Adam0 are equivalent
- '_' in names is converted to ' '
+31 -8
View File
@@ -7,6 +7,7 @@
#include "utils.hpp"
using std::cout;
using std::string;
static WINDOW* info_tab;
@@ -141,10 +142,10 @@ static U16 strUtf8Symbols(const std::string& str)
return num;
}
U16 Person::boxWidth() const
{
return strUtf8Symbols(name) + 4;
}
/* U16 Person::boxWidth() const */
/* { */
/* return strUtf8Symbols(name) + 4; */
/* } */
/* WINDOW* Person::createPad()const */
@@ -158,9 +159,30 @@ U16 Person::boxWidth() const
/* return pad; */
/* } */
void Person::draw(const I16 drawY, const I16 drawX, bool selected, bool hasSpouse, bool isSpouse, bool hasKids) const
U16 Person::draw(const I16 drawY, const I16 drawX, bool selected, bool hasSpouse,
bool hasParents, bool hasKids, bool wholeName) const
{
const U16 width = boxWidth(); /* pad width */
string display_name; /* todo remove? */
if(wholeName)
{
display_name = name;
}
else
{
size_t space = name.find(' ');
if(space != string::npos)
{
/* name[space] = '\0'; */
display_name = name.substr(0, space);
/* name[space] = ' '; */
}
else
{
display_name = name;
}
}
const U16 width = strUtf8Symbols(display_name) + 4; /* pad width */
if(willBeVisible(drawY, drawX, BOX_HEIGHT, width))
{
@@ -173,14 +195,15 @@ void Person::draw(const I16 drawY, const I16 drawX, bool selected, bool hasSpous
/* wattron(pad, color_pair); */
wborder(pad, ACS_VLINE, ACS_VLINE, ACS_HLINE, ACS_HLINE,
isSpouse ? ACS_TTEE : ACS_LTEE, hasSpouse ? ACS_TTEE : ACS_URCORNER,
hasParents ? ACS_LTEE : ACS_TTEE, hasSpouse ? ACS_TTEE : ACS_URCORNER,
hasKids ? ACS_LTEE : ACS_LLCORNER, ACS_LRCORNER );
mvwaddstr(pad, 2, 2, name.data());
mvwaddstr(pad, 2, 2, display_name.data());
/* wattroff(pad, color_pair); */
drawpad(pad, drawY, drawX);
delwin(pad);
}
return width;
}
+4 -2
View File
@@ -55,12 +55,14 @@ public:
void displayInfo() const;
const EventTime& birth() const { return birth_; };
U16 boxWidth() const;
/* U16 boxWidth(bool wholeName) const; */
/* Draw a Person's box on the terminal
drawY,drawX - top left coordinates where to draw (negative if outside the screen)
hasSpouse, hasSpouse, hasChildren - wheather the person has them on display
returns the width of the box*/
void draw(I16 drawY, I16 drawX, bool selected, bool hasSpouse, bool isSpouse, bool hasChildren=false) const;
U16 draw(I16 drawY, I16 drawX, bool selected, bool hasSpouse,
bool hasParents, bool hasChildren=false, bool wholeName=true) const;
std::string name;
EventTime birth_;
+27 -18
View File
@@ -436,7 +436,6 @@ static void displayHelp()
werase(help_tab);
wrefresh(help_tab); /* todo: dont update */
delwin(help_tab);
}
void Tree::display()
@@ -446,7 +445,7 @@ void Tree::display()
I32 c;
do
{
c = std::toupper(getch());
c = getch();
switch(c)
{
@@ -456,8 +455,9 @@ void Tree::display()
break;
case ' ':
case '\n':
/* focused_ = selected_; */
focused_ = findRootAncestor(selected_);
offsetX_ = 0;
offsetY_ = 0;
draw();
break;
case KEY_LEFT:
@@ -476,26 +476,35 @@ void Tree::display()
++offsetY_;
draw();
break;
case 'H':
case '=':
case '+':
zoom_ = 1;
draw();
break;
case '-':
zoom_ = 0;
draw();
break;
case 'h':
selectLeft();
break;
case 'J':
case 'j':
selectDown();
break;
case 'K':
case 'k':
selectUp();
break;
case 'L':
case 'l':
selectRight();
break;
case 'I':
case 'i':
people[selected_].displayInfo();
draw();
break;
default: break;
}
}
while(c != 'W');
while(c != 'w');
}
void Tree::updateRels(person_id id)
@@ -535,8 +544,8 @@ void Tree::draw() const
erase(); //Clear the screen
wnoutrefresh(stdscr);
I16 drawY = offsetY_/* (LINES) / 2 */;
I16 drawX = offsetX_/* (COLS) / 2 */;
I16 drawY = offsetY_;
I16 drawX = offsetX_;
drawLineWithWives(focused_, drawY, drawX);
doupdate();
@@ -710,15 +719,15 @@ I16 Tree::drawLineWithWives(const person_id id, I16 drawY, const I16 drawX) cons
spouse = rel.id;
}
const size_t numKids = children.size();
person.draw(drawY, drawX,
id == selected_, spouse!=Nobody, false, numKids!=0);
U16 person_w = person.draw(drawY, drawX,
id == selected_, spouse!=Nobody, true, numKids!=0, zoom_==1);
U16 spouse_width = 0;
U16 spouse_w = 0;
if (spouse != Nobody)
{
people[spouse].draw(drawY, drawX + person.boxWidth() + spouse_dist_,
spouse == selected_, false, true);
spouse_width = spouse_dist_ + people[spouse].boxWidth();
U16 spouse_box = people[spouse].draw(drawY, drawX + person_w + spouse_dist_,
spouse == selected_, false, false, false, zoom_==1);
spouse_w = spouse_dist_ + spouse_box;
}
auto childX = drawX;
@@ -740,7 +749,7 @@ I16 Tree::drawLineWithWives(const person_id id, I16 drawY, const I16 drawX) cons
}
}
return max(drawX + person.boxWidth() + dist_between_ + spouse_width,
return max(drawX + person_w + dist_between_ + spouse_w,
childX);
}
+1
View File
@@ -107,6 +107,7 @@ private:
person_id selected_ = 0;
I16 offsetX_ = 0; /* offset of the tree in relation to the screen*/
I16 offsetY_ = 0;
U8 zoom_ = 0;
U8 dist_between_ = 1; /* distance between people */
U8 spouse_dist_ = 0; /* distance between spouses */
//Search, ect.