add config.h and cleanup
This commit is contained in:
+15
-81
@@ -1,6 +1,6 @@
|
||||
#include <iostream>
|
||||
#include <assert.h>
|
||||
#include<ctype.h>
|
||||
#include <ctype.h>
|
||||
#include <ncursesw/ncurses.h>
|
||||
|
||||
#include"person.hpp"
|
||||
@@ -23,24 +23,6 @@ EventTime::EventTime(I16 Year, U8 Month, U16 Day, I8 Hour, I8 Minute)
|
||||
|
||||
void EventTime::print() const
|
||||
{
|
||||
/* if (day != UNKNOWN_DATE) */
|
||||
/* cout << (I32)day; */
|
||||
/* else */
|
||||
/* cout << "??"; */
|
||||
/* cout << '.'; */
|
||||
|
||||
/* if (month != UNKNOWN_DATE) */
|
||||
/* cout << (I32)month; */
|
||||
/* else */
|
||||
/* cout << "??"; */
|
||||
/* cout << '.'; */
|
||||
|
||||
/* if (year != UNKNOWN_DATE) */
|
||||
/* cout << year; */
|
||||
/* else */
|
||||
/* cout << "????"; */
|
||||
/* cout << '\n'; */
|
||||
|
||||
if (day != UNKNOWN_DATE)
|
||||
wprintw(info_tab, "%d", day);
|
||||
else
|
||||
@@ -61,11 +43,11 @@ void EventTime::print() const
|
||||
}
|
||||
|
||||
|
||||
Person::Person(const char* aName, EventTime birth, Sex aSex, EventTime death)
|
||||
Person::Person(const char* aName, EventTime aBirth, Sex aSex, EventTime aDeath)
|
||||
: name(aName)
|
||||
, birth_(birth)
|
||||
, birth(aBirth)
|
||||
, sex(aSex)
|
||||
, death_(death)
|
||||
, death(aDeath)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -75,40 +57,6 @@ bool Person::operator==(const Person &other)const
|
||||
return name == other.name; //&& sex == other.sex; //TODO && day == other.day || !day || !other.day) && (month == other.month || !month || !other.month) && (year == other.year || !year || !other.year);
|
||||
}
|
||||
|
||||
|
||||
void Person::write(std::ofstream &file)const
|
||||
{
|
||||
//
|
||||
char nameLen = name.size();
|
||||
file.write(reinterpret_cast<char*>(&nameLen), sizeof(nameLen));
|
||||
file.write(name.data(), nameLen * sizeof(name[0]));
|
||||
file.write(reinterpret_cast<const char*>(&sex), sizeof(sex));
|
||||
//file.write(reinterpret_cast<const char*>(&day), sizeof(day)); TODO
|
||||
//file.write(reinterpret_cast<const char*>(&month), sizeof(month));
|
||||
//file.write(reinterpret_cast<const char*>(&year), sizeof(year));
|
||||
}
|
||||
|
||||
void Person::read(std::ifstream &file)
|
||||
{
|
||||
U8 nameLen;
|
||||
file.read((char*)&nameLen, sizeof(nameLen)); //Check len
|
||||
|
||||
char nameBuf[128];
|
||||
file.read(nameBuf, nameLen * sizeof(*nameBuf));
|
||||
nameBuf[nameLen] = '\0';
|
||||
name = nameBuf;
|
||||
|
||||
file.read(reinterpret_cast<char*>(&sex), sizeof(sex));
|
||||
//file.read(reinterpret_cast<char*>(&day), sizeof(day)); TODO
|
||||
//file.read(reinterpret_cast<char*>(&month), sizeof(month));
|
||||
//file.read(reinterpret_cast<char*>(&year), sizeof(year));
|
||||
}
|
||||
|
||||
void Person::rename(const char* newName)
|
||||
{
|
||||
name = newName;
|
||||
}
|
||||
|
||||
void Person::displayInfo()const
|
||||
{
|
||||
info_tab = newwin(LINES, COLS, 0, 0);
|
||||
@@ -117,10 +65,10 @@ void Person::displayInfo()const
|
||||
waddch(info_tab,'\n');
|
||||
|
||||
waddstr(info_tab, "Birth: ");
|
||||
birth_.print();
|
||||
birth.print();
|
||||
|
||||
waddstr(info_tab, "Death: ");
|
||||
death_.print();
|
||||
death.print();
|
||||
|
||||
mvwaddstr(info_tab, LINES-1, 0, "Press any key to return.");
|
||||
|
||||
@@ -133,32 +81,15 @@ void Person::displayInfo()const
|
||||
}
|
||||
|
||||
|
||||
static U16 strUtf8Symbols(const std::string& str)
|
||||
static U16 strUtf8Symbols(const char* str)
|
||||
{
|
||||
U16 num = 0;
|
||||
for(char c: str)
|
||||
num += ((c & 0xC0) != 0x80);
|
||||
for(; *str != '\0'; ++str)
|
||||
num += ((*str & 0xC0) != 0x80);
|
||||
|
||||
return num;
|
||||
}
|
||||
|
||||
/* U16 Person::boxWidth() const */
|
||||
/* { */
|
||||
/* return strUtf8Symbols(name) + 4; */
|
||||
/* } */
|
||||
|
||||
|
||||
/* WINDOW* Person::createPad()const */
|
||||
/* { */
|
||||
/* U16 width = name.size() + 4; */
|
||||
/* WINDOW* pad = newpad(5, width); */
|
||||
|
||||
/* box(pad, 5, width); */
|
||||
/* mvwaddstr(pad, 2, 2, name.data()); */
|
||||
|
||||
/* return pad; */
|
||||
/* } */
|
||||
|
||||
U16 Person::draw(const I16 drawY, const I16 drawX, bool selected, bool hasSpouse,
|
||||
bool hasParents, bool hasKids, bool wholeName) const
|
||||
{
|
||||
@@ -182,7 +113,7 @@ U16 Person::draw(const I16 drawY, const I16 drawX, bool selected, bool hasSpouse
|
||||
}
|
||||
}
|
||||
|
||||
const U16 width = strUtf8Symbols(display_name) + 4; /* pad width */
|
||||
const U16 width = strUtf8Symbols(display_name.data()) + 4; /* pad width */
|
||||
|
||||
if(willBeVisible(drawY, drawX, BOX_HEIGHT, width))
|
||||
{
|
||||
@@ -194,9 +125,12 @@ U16 Person::draw(const I16 drawY, const I16 drawX, bool selected, bool hasSpouse
|
||||
wbkgd(pad, color_pair);
|
||||
/* wattron(pad, color_pair); */
|
||||
|
||||
auto top_left = hasParents ? ACS_LTEE : ACS_TTEE;
|
||||
auto top_right = hasSpouse ? ACS_TTEE : ACS_URCORNER;
|
||||
auto bot_left = hasKids ? ACS_LTEE : ACS_LLCORNER;
|
||||
wborder(pad, ACS_VLINE, ACS_VLINE, ACS_HLINE, ACS_HLINE,
|
||||
hasParents ? ACS_LTEE : ACS_TTEE, hasSpouse ? ACS_TTEE : ACS_URCORNER,
|
||||
hasKids ? ACS_LTEE : ACS_LLCORNER, ACS_LRCORNER );
|
||||
top_left, top_right,
|
||||
bot_left, ACS_LRCORNER );
|
||||
|
||||
mvwaddstr(pad, 2, 2, display_name.data());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user