#include #include #include #include #include"person.h" #include "help.h" using std::cout; WINDOW* info_tab; EventTime::EventTime(I16 Year, U8 Month, U16 Day, I8 Hour, I8 Minute) : year(Year) , month(Month) , day(Day) , hour(Hour) , minute(Minute) { assert(month <= 12 && day <= 31 && hour <= 23 && minute <= 59 && "Invalid EventTime data"); } 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 waddstr(info_tab, "??"); waddch(info_tab, '.'); if (month != UNKNOWN_DATE) wprintw(info_tab, "%d", month); else waddstr(info_tab, "??"); waddch(info_tab, '.'); if (year != UNKNOWN_DATE) wprintw(info_tab, "%d", year); else waddstr(info_tab, "????"); waddch(info_tab, '\n'); } Person::Person(const char* name, EventTime birth, bool isMale, EventTime death) : name_(name) , numRel_(0) , birth_(birth) , isMale_(isMale) , death_(death) { } bool Person::operator==(const Person &other)const { return name_ == other.name_ && isMale_ == other.isMale_; //TODO && day == other.day || !day || !other.day) && (month == other.month || !month || !other.month) && (year == other.year || !year || !other.year); } void Person::save(std::ofstream &file)const { // char nameLen = name_.size(); file.write(reinterpret_cast(&nameLen), sizeof(nameLen)); file.write(name_.data(), nameLen * sizeof(name_[0])); file.write(reinterpret_cast(&numRel_), sizeof(numRel_)); file.write(reinterpret_cast(&isMale_), sizeof(isMale_)); //file.write(reinterpret_cast(&day), sizeof(day)); TODO //file.write(reinterpret_cast(&month), sizeof(month)); //file.write(reinterpret_cast(&year), sizeof(year)); } void Person::load(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(&numRel_), sizeof(numRel_)); file.read(reinterpret_cast(&isMale_), sizeof(isMale_)); //file.read(reinterpret_cast(&day), sizeof(day)); TODO //file.read(reinterpret_cast(&month), sizeof(month)); //file.read(reinterpret_cast(&year), sizeof(year)); } void Person::rename(const char* newName) { name_ = newName; } void Person::displayInfo()const { info_tab = newwin(LINES, COLS, 0, 0); waddstr(info_tab, name_.data()); waddch(info_tab,'\n'); waddstr(info_tab, "Birth: "); birth_.print(); waddstr(info_tab, "Death: "); death_.print(); mvwaddstr(info_tab, LINES-1, 0, "Press any key to return."); wrefresh(info_tab); getch(); /* waint press */ werase(info_tab); wrefresh(info_tab); /* todo: dont update */ delwin(info_tab); } bool Person::isMale() const { return isMale_; } static U16 strUtf8Symbols(const std::string& str) { U16 num = 0; for(char c: str) num += ((c & 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; */ /* } */ void Person::draw(const I16 drawY, const I16 drawX, bool selected, bool hasSpouse, bool isSpouse, bool hasKids) const { const U16 width = boxWidth(); /* pad width */ if(willBeVisible(drawY, drawX, BOX_HEIGHT, width)) { WINDOW* pad = newpad(BOX_HEIGHT, width); auto color_pair = COLOR_PAIR( selected ? COLOR_SELECTED : (isMale_ ? COLOR_MALE : COLOR_FEMALE) ); wbkgd(pad, color_pair); /* wattron(pad, color_pair); */ wborder(pad, ACS_VLINE, ACS_VLINE, ACS_HLINE, ACS_HLINE, isSpouse ? ACS_TTEE : ACS_LTEE, hasSpouse ? ACS_TTEE : ACS_URCORNER, hasKids ? ACS_LTEE : ACS_LLCORNER, ACS_LRCORNER ); mvwaddstr(pad, 2, 2, name_.data()); /* wattroff(pad, color_pair); */ drawpad(pad, drawY, drawX); delwin(pad); } }