ochess/src/base_tab/GameListManager.cpp

71 lines
2.2 KiB
C++
Raw Normal View History

2022-12-25 15:26:16 +01:00
#include "GameListManager.hpp"
GameListManager::GameListManager(wxListCtrl *game_list): game_list(game_list), game_counter(0) {
game_list->InsertColumn(0, L"Id", wxLIST_FORMAT_LEFT, 50);
game_list->InsertColumn(1, L"White", wxLIST_FORMAT_LEFT, 200);
game_list->InsertColumn(2, L"Black", wxLIST_FORMAT_LEFT, 200);
game_list->InsertColumn(3, L"Event", wxLIST_FORMAT_LEFT, 150);
game_list->InsertColumn(4, L"Round", wxLIST_FORMAT_LEFT, 100);
game_list->InsertColumn(5, L"Result", wxLIST_FORMAT_LEFT, 200);
game_list->InsertColumn(6, L"ECO", wxLIST_FORMAT_LEFT, 200);
}
2022-12-25 16:29:17 +01:00
void GameListManager::AddGame(CType White,CType Black,CType Event,CType Round, CType Result, CType Eco){
// Update rows elements
rows.push_back({White,Black,Event,Round,Result,Eco});
// Display the row
DisplayRow(game_counter);
2022-12-25 15:26:16 +01:00
game_counter++;
}
2022-12-25 15:51:00 +01:00
2022-12-25 16:29:17 +01:00
void GameListManager::DisplayRow(long id){
RType row=rows[id];
long index =
game_list->InsertItem(game_counter, std::to_string(id)); // want this for col. 1
game_list->SetItem(index, 1, row.White);
game_list->SetItem(index, 2, row.Black);
game_list->SetItem(index, 3, row.Event);
game_list->SetItem(index, 4, row.Round);
game_list->SetItem(index, 5, row.Result);
game_list->SetItem(index, 6, row.Eco);
}
2022-12-25 15:51:00 +01:00
void GameListManager::Clear(){
game_list->DeleteAllItems();
2022-12-25 16:39:54 +01:00
rows.clear();
}
void GameListManager::ClearDisplayedRow(){
game_list->DeleteAllItems();
2022-12-25 15:51:00 +01:00
}
2022-12-25 17:30:22 +01:00
void GameListManager::MarkItemAsOpen(long item){
game_list->SetItemBackgroundColour(item, *wxGREEN);
}
void GameListManager::MarkItemAsDeleted(long item){
game_list->SetItemBackgroundColour(item, *wxRED);
}
std::vector<long> GameListManager::GetSelectedItems(){
std::vector<long> items;
long selected = -1;
while ((selected = game_list->GetNextItem(selected, wxLIST_NEXT_ALL,
wxLIST_STATE_SELECTED)) !=
wxNOT_FOUND) {
items.push_back(selected);
}
return(items);
}
long GameListManager::GetItemGameId(long item){
wxListItem listItem;
listItem.m_itemId = item; // sets row
listItem.m_col = 0; // sets column to Id (column 0)
game_list->GetItem(listItem); // gets item
return std::stol(listItem.GetText().ToStdString());
}