minus zoom

This commit is contained in:
vrd
2024-08-27 09:37:45 +03:00
parent e310643c85
commit efdb6fc409
7 changed files with 89 additions and 39 deletions
+40 -23
View File
@@ -3,8 +3,9 @@
#include <ctype.h>
#include <ncurses.h>
#include"person.hpp"
#include "person.hpp"
#include "utils.hpp"
#include "ui.hpp"
using std::cout;
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,
bool hasKids, bool wholeName) const
bool hasKids, ZoomLevel zoom) const
{
auto topright = hasSpouse ? ACS_TTEE : ACS_URCORNER;
auto botleft = hasKids ? ACS_LTEE : ACS_LLCORNER;
return draw(drawY, drawX, selected, wholeName,
return draw(drawY, drawX, selected, zoom,
ACS_LTEE, topright,
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;
return draw(drawY, drawX, selected, wholeName,
return draw(drawY, drawX, selected, zoom,
ACS_TTEE, topright,
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
{
string display_name;
if(wholeName)
/* pad width */
U16 width;
// pad height
U16 height;
string display_name = name;
switch(zoom)
{
display_name = name;
}
else
case ZoomLevel::FIRST_NAME:
{
size_t space = name.find(' ');
size_t space = display_name.find(' ');
if(space != string::npos)
{
display_name = name.substr(0, space);
}
else
{
display_name = name;
display_name.erase(space);
}
}
case ZoomLevel::ALL_NAMES:
width = Utf8SymbolsCount(display_name) + 4;
height = 5;
break;
case ZoomLevel::NO_NAME:
width = 2;
height = 2;
break;
}
/* pad width */
const U16 width = Utf8SymbolsCount(display_name) + 4;
if(willBeVisible(drawY, drawX, BOX_HEIGHT, width))
if(willBeVisible(drawY, drawX, height, width))
{
AutoWin pad( newpad(BOX_HEIGHT, width) );
AutoWin pad( newpad(height, width) );
auto color_pair = COLOR_PAIR( selected ? COLOR_SELECTED
: (sex==M ? COLOR_MALE : COLOR_FEMALE) );
@@ -157,3 +162,15 @@ U16 Person::draw(I16 drawY, I16 drawX, bool selected, bool wholeName,
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
View File
@@ -5,6 +5,8 @@
#include <ncurses.h>
#include "common/basicTypes.h"
enum ZoomLevel: U8;
struct EventTime
{
enum: I16 { UNKNOWN_DATE=0 };
@@ -34,7 +36,7 @@ enum BoxColors: U8 {
};
enum DisplayDimensons: U8 {
BOX_HEIGHT = 5,
// BOX_HEIGHT = 5,
LINK_HEIGHT = 3
};
@@ -57,13 +59,13 @@ public:
hasSpouse, hasSpouse, hasChildren - wheather the person has them on display
returns the width of the box*/
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
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;
U16 drawAsSpouse(I16 drawY, I16 drawX, bool selected, bool hasTree, ZoomLevel) const;
std::string name;
EventTime birth;
@@ -71,6 +73,8 @@ public:
EventTime death;
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;
};
U16 person_box_width(ZoomLevel);
+4 -4
View File
@@ -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;
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();
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;
if (spouse != 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_,
spouse == selected_, spouse_has_tree, zoom_>=1);
spouse == selected_, spouse_has_tree, zoom_);
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)
{
auto prevX = childX;
drawY += BOX_HEIGHT;
drawY += person_box_width(zoom_);
auto lnHt = linkToFirstBorn(drawY, childX, numKids > 1); /* Link height */
childX = drawLineWithSpouses(children[0], drawY + lnHt, childX);
+4 -2
View File
@@ -4,6 +4,8 @@
#include <vector>
#include "person.hpp"
enum ZoomLevel: U8;
using person_id = U32;
enum: person_id {
Nobody = UINT32_MAX
@@ -75,7 +77,7 @@ public:
/* void printRel(person_id id)const; //Prints out close relatives */
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:
// recursion to find common ancestor
@@ -97,7 +99,7 @@ private:
// 0 is the first person in the tree
person_id focused_ = 0; /* the tree was draw based on this person */
person_id selected_;
U8 zoom_ = 0;
ZoomLevel zoom_;
// todo: figure out what to do with these constants
const U8 dist_between_ = 1; /* distance between people */
+18 -3
View File
@@ -1,3 +1,4 @@
#include "ui.hpp"
#include "tree.hpp"
#include "utils.hpp"
#include "assert.h"
@@ -14,10 +15,22 @@ namespace
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)
{
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
I16 offsetY = 0, offsetX = 0;
@@ -57,10 +70,12 @@ void displayTree(Tree& t)
break;
case '=':
case '+':
zoom = 1;
if(zoom < ZoomLevel::MAX_ZOOM)
++zoom;
break;
case '-':
zoom = 0;
if(zoom > 0)
--zoom;
break;
case SELECT_LEFT:
selected = selectLeft(t, selected);
+13 -2
View File
@@ -1,6 +1,17 @@
#pragma once
// 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;
void displayTree(Tree&);
+2 -1
View File
@@ -13,7 +13,7 @@ tft ^ should expand to last person (for parents it doesnt)
tft merge trees relation
Visualization:
- zooming
- more granular zooming
- snap to selection/scroll with selection
- horizontal navigation between cousins
- color on different consoles
@@ -23,6 +23,7 @@ Visualization:
- distinct tree regions
- aproximate birth day
- indicator for people with their own tree
- centralize when changing focus
Compilation
- static and dynamic ncurses