minus zoom
This commit is contained in:
+40
-23
@@ -3,8 +3,9 @@
|
|||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <ncurses.h>
|
#include <ncurses.h>
|
||||||
|
|
||||||
#include"person.hpp"
|
#include "person.hpp"
|
||||||
#include "utils.hpp"
|
#include "utils.hpp"
|
||||||
|
#include "ui.hpp"
|
||||||
|
|
||||||
using std::cout;
|
using std::cout;
|
||||||
using std::string;
|
using std::string;
|
||||||
@@ -91,52 +92,56 @@ static U16 Utf8SymbolsCount(const string& str)
|
|||||||
}
|
}
|
||||||
|
|
||||||
U16 Person::drawAsFocused(const I16 drawY, const I16 drawX, bool selected, bool hasSpouse,
|
U16 Person::drawAsFocused(const I16 drawY, const I16 drawX, bool selected, bool hasSpouse,
|
||||||
bool hasKids, bool wholeName) const
|
bool hasKids, ZoomLevel zoom) const
|
||||||
{
|
{
|
||||||
auto topright = hasSpouse ? ACS_TTEE : ACS_URCORNER;
|
auto topright = hasSpouse ? ACS_TTEE : ACS_URCORNER;
|
||||||
auto botleft = hasKids ? ACS_LTEE : ACS_LLCORNER;
|
auto botleft = hasKids ? ACS_LTEE : ACS_LLCORNER;
|
||||||
|
|
||||||
return draw(drawY, drawX, selected, wholeName,
|
return draw(drawY, drawX, selected, zoom,
|
||||||
ACS_LTEE, topright,
|
ACS_LTEE, topright,
|
||||||
botleft, ACS_LRCORNER );
|
botleft, ACS_LRCORNER );
|
||||||
}
|
}
|
||||||
|
|
||||||
U16 Person::drawAsSpouse(I16 drawY, I16 drawX, bool selected, bool hasTree, bool wholeName) const
|
U16 Person::drawAsSpouse(I16 drawY, I16 drawX, bool selected, bool hasTree, ZoomLevel zoom) const
|
||||||
{
|
{
|
||||||
auto topright = hasTree ? '@' : ACS_URCORNER;
|
auto topright = hasTree ? '@' : ACS_URCORNER;
|
||||||
return draw(drawY, drawX, selected, wholeName,
|
return draw(drawY, drawX, selected, zoom,
|
||||||
ACS_TTEE, topright,
|
ACS_TTEE, topright,
|
||||||
ACS_LLCORNER, ACS_LRCORNER );
|
ACS_LLCORNER, ACS_LRCORNER );
|
||||||
}
|
}
|
||||||
|
|
||||||
U16 Person::draw(I16 drawY, I16 drawX, bool selected, bool wholeName,
|
U16 Person::draw(I16 drawY, I16 drawX, bool selected, ZoomLevel zoom,
|
||||||
U32 topleft, U32 topright, U32 botleft, U32 botright) const
|
U32 topleft, U32 topright, U32 botleft, U32 botright) const
|
||||||
{
|
{
|
||||||
string display_name;
|
/* pad width */
|
||||||
if(wholeName)
|
U16 width;
|
||||||
|
// pad height
|
||||||
|
U16 height;
|
||||||
|
|
||||||
|
string display_name = name;
|
||||||
|
switch(zoom)
|
||||||
{
|
{
|
||||||
display_name = name;
|
case ZoomLevel::FIRST_NAME:
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
size_t space = name.find(' ');
|
size_t space = display_name.find(' ');
|
||||||
if(space != string::npos)
|
if(space != string::npos)
|
||||||
{
|
{
|
||||||
display_name = name.substr(0, space);
|
display_name.erase(space);
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
display_name = name;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
case ZoomLevel::ALL_NAMES:
|
||||||
|
width = Utf8SymbolsCount(display_name) + 4;
|
||||||
|
height = 5;
|
||||||
|
break;
|
||||||
|
case ZoomLevel::NO_NAME:
|
||||||
|
width = 2;
|
||||||
|
height = 2;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(willBeVisible(drawY, drawX, height, width))
|
||||||
/* pad width */
|
|
||||||
const U16 width = Utf8SymbolsCount(display_name) + 4;
|
|
||||||
|
|
||||||
if(willBeVisible(drawY, drawX, BOX_HEIGHT, width))
|
|
||||||
{
|
{
|
||||||
AutoWin pad( newpad(BOX_HEIGHT, width) );
|
AutoWin pad( newpad(height, width) );
|
||||||
|
|
||||||
auto color_pair = COLOR_PAIR( selected ? COLOR_SELECTED
|
auto color_pair = COLOR_PAIR( selected ? COLOR_SELECTED
|
||||||
: (sex==M ? COLOR_MALE : COLOR_FEMALE) );
|
: (sex==M ? COLOR_MALE : COLOR_FEMALE) );
|
||||||
@@ -157,3 +162,15 @@ U16 Person::draw(I16 drawY, I16 drawX, bool selected, bool wholeName,
|
|||||||
return width;
|
return width;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
U16 person_box_width(ZoomLevel z)
|
||||||
|
{
|
||||||
|
switch(z)
|
||||||
|
{
|
||||||
|
case ZoomLevel::ALL_NAMES:
|
||||||
|
case ZoomLevel::FIRST_NAME:
|
||||||
|
return 5;
|
||||||
|
case NO_NAME:
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
+8
-4
@@ -5,6 +5,8 @@
|
|||||||
#include <ncurses.h>
|
#include <ncurses.h>
|
||||||
#include "common/basicTypes.h"
|
#include "common/basicTypes.h"
|
||||||
|
|
||||||
|
enum ZoomLevel: U8;
|
||||||
|
|
||||||
struct EventTime
|
struct EventTime
|
||||||
{
|
{
|
||||||
enum: I16 { UNKNOWN_DATE=0 };
|
enum: I16 { UNKNOWN_DATE=0 };
|
||||||
@@ -34,7 +36,7 @@ enum BoxColors: U8 {
|
|||||||
};
|
};
|
||||||
|
|
||||||
enum DisplayDimensons: U8 {
|
enum DisplayDimensons: U8 {
|
||||||
BOX_HEIGHT = 5,
|
// BOX_HEIGHT = 5,
|
||||||
LINK_HEIGHT = 3
|
LINK_HEIGHT = 3
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -57,13 +59,13 @@ public:
|
|||||||
hasSpouse, hasSpouse, hasChildren - wheather the person has them on display
|
hasSpouse, hasSpouse, hasChildren - wheather the person has them on display
|
||||||
returns the width of the box*/
|
returns the width of the box*/
|
||||||
U16 drawAsFocused(I16 drawY, I16 drawX, bool selected, bool hasSpouse,
|
U16 drawAsFocused(I16 drawY, I16 drawX, bool selected, bool hasSpouse,
|
||||||
bool hasChildren=false, bool wholeName=true) const;
|
bool hasChildren, ZoomLevel) const;
|
||||||
|
|
||||||
/* Draw a Person's box on the terminal, as a spouse of someone in the focused tree
|
/* 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)
|
drawY,drawX - top left coordinates where to draw (negative if outside the screen)
|
||||||
hasTree - weather the spouse has a tree that can be displayed
|
hasTree - weather the spouse has a tree that can be displayed
|
||||||
returns the width of the box*/
|
returns the width of the box*/
|
||||||
U16 drawAsSpouse(I16 drawY, I16 drawX, bool selected, bool hasTree, bool wholeName=true) const;
|
U16 drawAsSpouse(I16 drawY, I16 drawX, bool selected, bool hasTree, ZoomLevel) const;
|
||||||
|
|
||||||
std::string name;
|
std::string name;
|
||||||
EventTime birth;
|
EventTime birth;
|
||||||
@@ -71,6 +73,8 @@ public:
|
|||||||
EventTime death;
|
EventTime death;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
U16 draw(I16 drawY, I16 drawX, bool selected, bool wholeName,
|
U16 draw(I16 drawY, I16 drawX, bool selected, ZoomLevel,
|
||||||
U32 topleft, U32 topright, U32 botleft, U32 botright) const;
|
U32 topleft, U32 topright, U32 botleft, U32 botright) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
U16 person_box_width(ZoomLevel);
|
||||||
|
|||||||
+4
-4
@@ -426,7 +426,7 @@ void Tree::updateRels(person_id id)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Tree::draw(const person_id selected, const U8 zoom, const I16 offsetY, const I16 offsetX)
|
void Tree::draw(const person_id selected, const ZoomLevel zoom, const I16 offsetY, const I16 offsetX)
|
||||||
{
|
{
|
||||||
selected_ = selected;
|
selected_ = selected;
|
||||||
zoom_ = zoom;
|
zoom_ = zoom;
|
||||||
@@ -503,14 +503,14 @@ I16 Tree::drawLineWithSpouses(const person_id id, I16 drawY, const I16 drawX) co
|
|||||||
|
|
||||||
const size_t numKids = children.size();
|
const size_t numKids = children.size();
|
||||||
U16 person_w = person.drawAsFocused(drawY, drawX,
|
U16 person_w = person.drawAsFocused(drawY, drawX,
|
||||||
id == selected_, spouse!=Nobody, numKids!=0, zoom_>=1);
|
id == selected_, spouse!=Nobody, numKids!=0, zoom_);
|
||||||
|
|
||||||
U16 spouse_w = 0;
|
U16 spouse_w = 0;
|
||||||
if (spouse != Nobody)
|
if (spouse != Nobody)
|
||||||
{
|
{
|
||||||
bool spouse_has_tree = (findParent(spouse, M) != Nobody) || (findParent(spouse, F) != Nobody);
|
bool spouse_has_tree = (findParent(spouse, M) != Nobody) || (findParent(spouse, F) != Nobody);
|
||||||
U16 spouse_box = people_[spouse].drawAsSpouse(drawY, drawX + person_w + spouse_dist_,
|
U16 spouse_box = people_[spouse].drawAsSpouse(drawY, drawX + person_w + spouse_dist_,
|
||||||
spouse == selected_, spouse_has_tree, zoom_>=1);
|
spouse == selected_, spouse_has_tree, zoom_);
|
||||||
spouse_w = spouse_dist_ + spouse_box;
|
spouse_w = spouse_dist_ + spouse_box;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -518,7 +518,7 @@ I16 Tree::drawLineWithSpouses(const person_id id, I16 drawY, const I16 drawX) co
|
|||||||
if (numKids!=0)
|
if (numKids!=0)
|
||||||
{
|
{
|
||||||
auto prevX = childX;
|
auto prevX = childX;
|
||||||
drawY += BOX_HEIGHT;
|
drawY += person_box_width(zoom_);
|
||||||
|
|
||||||
auto lnHt = linkToFirstBorn(drawY, childX, numKids > 1); /* Link height */
|
auto lnHt = linkToFirstBorn(drawY, childX, numKids > 1); /* Link height */
|
||||||
childX = drawLineWithSpouses(children[0], drawY + lnHt, childX);
|
childX = drawLineWithSpouses(children[0], drawY + lnHt, childX);
|
||||||
|
|||||||
+4
-2
@@ -4,6 +4,8 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include "person.hpp"
|
#include "person.hpp"
|
||||||
|
|
||||||
|
enum ZoomLevel: U8;
|
||||||
|
|
||||||
using person_id = U32;
|
using person_id = U32;
|
||||||
enum: person_id {
|
enum: person_id {
|
||||||
Nobody = UINT32_MAX
|
Nobody = UINT32_MAX
|
||||||
@@ -75,7 +77,7 @@ public:
|
|||||||
|
|
||||||
/* void printRel(person_id id)const; //Prints out close relatives */
|
/* void printRel(person_id id)const; //Prints out close relatives */
|
||||||
void printMember(person_id)const;
|
void printMember(person_id)const;
|
||||||
void draw(person_id selected, U8 zoom, I16 offsetY, I16 offsetX);
|
void draw(person_id selected, ZoomLevel, I16 offsetY, I16 offsetX);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// recursion to find common ancestor
|
// recursion to find common ancestor
|
||||||
@@ -97,7 +99,7 @@ private:
|
|||||||
// 0 is the first person in the tree
|
// 0 is the first person in the tree
|
||||||
person_id focused_ = 0; /* the tree was draw based on this person */
|
person_id focused_ = 0; /* the tree was draw based on this person */
|
||||||
person_id selected_;
|
person_id selected_;
|
||||||
U8 zoom_ = 0;
|
ZoomLevel zoom_;
|
||||||
|
|
||||||
// todo: figure out what to do with these constants
|
// todo: figure out what to do with these constants
|
||||||
const U8 dist_between_ = 1; /* distance between people */
|
const U8 dist_between_ = 1; /* distance between people */
|
||||||
|
|||||||
+18
-3
@@ -1,3 +1,4 @@
|
|||||||
|
#include "ui.hpp"
|
||||||
#include "tree.hpp"
|
#include "tree.hpp"
|
||||||
#include "utils.hpp"
|
#include "utils.hpp"
|
||||||
#include "assert.h"
|
#include "assert.h"
|
||||||
@@ -14,10 +15,22 @@ namespace
|
|||||||
person_id selectRightSib(const Tree& t, person_id selected);
|
person_id selectRightSib(const Tree& t, person_id selected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ZoomLevel operator++(ZoomLevel& z)
|
||||||
|
{
|
||||||
|
z = (ZoomLevel)(z + 1);
|
||||||
|
return z;
|
||||||
|
}
|
||||||
|
|
||||||
|
ZoomLevel operator--(ZoomLevel& z)
|
||||||
|
{
|
||||||
|
z = (ZoomLevel)(z - 1);
|
||||||
|
return z;
|
||||||
|
}
|
||||||
|
|
||||||
void displayTree(Tree& t)
|
void displayTree(Tree& t)
|
||||||
{
|
{
|
||||||
person_id selected = 0; // the currently selected selected
|
person_id selected = 0; // the currently selected selected
|
||||||
U8 zoom = 0; // how much info to show for each selected
|
ZoomLevel zoom = ZoomLevel::FIRST_NAME; // how much info to show for each selected
|
||||||
|
|
||||||
// offset of the tree in relation to the top left corner of the screen
|
// offset of the tree in relation to the top left corner of the screen
|
||||||
I16 offsetY = 0, offsetX = 0;
|
I16 offsetY = 0, offsetX = 0;
|
||||||
@@ -57,10 +70,12 @@ void displayTree(Tree& t)
|
|||||||
break;
|
break;
|
||||||
case '=':
|
case '=':
|
||||||
case '+':
|
case '+':
|
||||||
zoom = 1;
|
if(zoom < ZoomLevel::MAX_ZOOM)
|
||||||
|
++zoom;
|
||||||
break;
|
break;
|
||||||
case '-':
|
case '-':
|
||||||
zoom = 0;
|
if(zoom > 0)
|
||||||
|
--zoom;
|
||||||
break;
|
break;
|
||||||
case SELECT_LEFT:
|
case SELECT_LEFT:
|
||||||
selected = selectLeft(t, selected);
|
selected = selectLeft(t, selected);
|
||||||
|
|||||||
+13
-2
@@ -1,6 +1,17 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
// Handles keys and displays the tree
|
// Handles keys and displays the tree
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "common/basicTypes.h"
|
||||||
|
|
||||||
|
enum ZoomLevel: U8
|
||||||
|
{
|
||||||
|
NO_NAME,
|
||||||
|
FIRST_NAME,
|
||||||
|
ALL_NAMES,
|
||||||
|
MAX_ZOOM = ALL_NAMES
|
||||||
|
};
|
||||||
|
ZoomLevel operator++(ZoomLevel&);
|
||||||
|
ZoomLevel operator--(ZoomLevel&);
|
||||||
|
|
||||||
class Tree;
|
class Tree;
|
||||||
void displayTree(Tree&);
|
void displayTree(Tree&);
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ tft ^ should expand to last person (for parents it doesnt)
|
|||||||
tft merge trees relation
|
tft merge trees relation
|
||||||
|
|
||||||
Visualization:
|
Visualization:
|
||||||
- zooming
|
- more granular zooming
|
||||||
- snap to selection/scroll with selection
|
- snap to selection/scroll with selection
|
||||||
- horizontal navigation between cousins
|
- horizontal navigation between cousins
|
||||||
- color on different consoles
|
- color on different consoles
|
||||||
@@ -23,6 +23,7 @@ Visualization:
|
|||||||
- distinct tree regions
|
- distinct tree regions
|
||||||
- aproximate birth day
|
- aproximate birth day
|
||||||
- indicator for people with their own tree
|
- indicator for people with their own tree
|
||||||
|
- centralize when changing focus
|
||||||
|
|
||||||
Compilation
|
Compilation
|
||||||
- static and dynamic ncurses
|
- static and dynamic ncurses
|
||||||
|
|||||||
Reference in New Issue
Block a user