From f4d16d13482681fa7de0977fcb36223137ddfe14 Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Sun, 14 Aug 2005 16:48:44 +0000 Subject: [PATCH] Columns in select lists. Looks better! --- vchannellist.cc | 5 ++++- vrecordinglist.cc | 17 ++++------------- wselectlist.cc | 37 +++++++++++++++++++++++++++++++++++-- wselectlist.h | 5 +++++ 4 files changed, 48 insertions(+), 16 deletions(-) diff --git a/vchannellist.cc b/vchannellist.cc index 4bbfdfc..81159f4 100644 --- a/vchannellist.cc +++ b/vchannellist.cc @@ -68,6 +68,9 @@ void VChannelList::setList(List* tlist) { char str[500]; + sl.addColumn(0); + sl.addColumn(50); + chanList = tlist; Channel* chan; @@ -78,7 +81,7 @@ void VChannelList::setList(List* tlist) while((chan = (Channel*)chanList->getCurrent())) { - sprintf(str, "%lu. %s", chan->number, chan->name); + sprintf(str, "%lu\t%s", chan->number, chan->name); chan->index = sl.addOption(str, first); first = 0; chanList->next(); diff --git a/vrecordinglist.cc b/vrecordinglist.cc index 3c6b0a0..c8bd1e3 100644 --- a/vrecordinglist.cc +++ b/vrecordinglist.cc @@ -71,6 +71,8 @@ void VRecordingList::setDir(Directory* tdir) void VRecordingList::drawData() { sl.clear(); + sl.addColumn(0); + sl.addColumn(110); int first = 1; @@ -78,10 +80,6 @@ void VRecordingList::drawData() char tempB[300]; // FIXME struct tm* btime; - char spaces[13]; - char theNumber[10]; - int theNumberLength; - Directory* dir; recDir->dirList->reset(); while((dir = (Directory*)recDir->dirList->getCurrent())) @@ -92,14 +90,7 @@ void VRecordingList::drawData() continue; } - strcpy(spaces, " "); - theNumberLength = snprintf(theNumber, 9, "%lu", dir->getNumRecordings()); - - spaces[11 - theNumberLength] = '\0'; - - //snprintf(tempA, 299, " %s", dir->name); - snprintf(tempA, 299, " %s%s%s", theNumber, spaces, dir->name); - //int numSize = snprintf(tempA + snprintf(tempA, 299, " %lu\t%s", dir->getNumRecordings(), dir->name); dir->index = sl.addOption(tempA, first); first = 0; @@ -119,7 +110,7 @@ void VRecordingList::drawData() { btime = localtime((time_t*)&rec->start); strftime(tempA, 299, "%0d/%0m %0H:%0M ", btime); - sprintf(tempB, "%s %s", tempA, rec->getProgName()); + sprintf(tempB, "%s\t%s", tempA, rec->getProgName()); rec->index = sl.addOption(tempB, first); first = 0; recList->next(); diff --git a/wselectlist.cc b/wselectlist.cc index c6e27f3..101658c 100644 --- a/wselectlist.cc +++ b/wselectlist.cc @@ -26,6 +26,7 @@ WSelectList::WSelectList() selectedOption = 0; topOption = 0; numOptionsDisplayable = 0; + numColumns = 0; } WSelectList::~WSelectList() @@ -44,6 +45,7 @@ void WSelectList::clear() selectedOption = 0; topOption = 0; numOptionsDisplayable = 0; + numColumns = 0; } void WSelectList::hintSetCurrent(int index) @@ -98,16 +100,47 @@ void WSelectList::draw() if (i == selectedOption) { rectangle(0, ypos, width, fontHeight, Colour::SELECTHIGHLIGHT); - drawText(options[i], 5, ypos, Colour::DARKTEXT); + drawOptionLine(options[i], 5, ypos, Colour::DARKTEXT); } else { - drawText(options[i], 5, ypos, Colour::LIGHTTEXT); + drawOptionLine(options[i], 5, ypos, Colour::LIGHTTEXT); } ypos += ySeperation; } } +void WSelectList::addColumn(int x) +{ + if (numColumns == 10) return; + columns[numColumns++] = x; +} + +void WSelectList::drawOptionLine(char* text, int xpos, int ypos, Colour& colour) +{ + if (!numColumns) + { + drawText(text, xpos, ypos, colour); + } + else + { + char buffer[200]; + strncpy(buffer, text, 199); + int currentColumn = 0; + char* pointer; + + pointer = strtok(buffer, "\t"); + while(pointer) + { + drawText(pointer, xpos + columns[currentColumn], ypos, colour); + currentColumn++; + if (currentColumn == 10) return; + pointer = strtok(NULL, "\t"); + } + } +} + + void WSelectList::up() { if (selectedOption > 0) diff --git a/wselectlist.h b/wselectlist.h index 66d8e28..23c6cae 100644 --- a/wselectlist.h +++ b/wselectlist.h @@ -33,6 +33,7 @@ class WSelectList : public Box WSelectList(); ~WSelectList(); void clear(); + void addColumn(int x); int addOption(char* text, int selected); void draw(); @@ -51,11 +52,15 @@ class WSelectList : public Box void hintSetTop(int index); private: + void drawOptionLine(char* text, int xpos, int ypos, Colour& colour); + char* options[500]; int numOptions; int selectedOption; int topOption; int numOptionsDisplayable; + int columns[10]; + int numColumns; }; #endif -- 2.39.5