diff options
| author | Simon Robertshaw <simon@hardwired.org.uk> | 2012-01-19 13:44:59 (GMT) |
|---|---|---|
| committer | Simon Robertshaw <simon@hardwired.org.uk> | 2012-01-19 13:44:59 (GMT) |
| commit | 44639a6423c03552a3c0faafab27ef8f395f73a6 (patch) | |
| tree | 1a4fc49a56060759fcbec6f18e9159cf126e8606 /src/search | |
| parent | 4a60b97c700c2f1843b7e99313554cb89fb5da4e (diff) | |
| download | powder-44639a6423c03552a3c0faafab27ef8f395f73a6.zip powder-44639a6423c03552a3c0faafab27ef8f395f73a6.tar.gz | |
Some folder changes, started search and client
Diffstat (limited to 'src/search')
| -rw-r--r-- | src/search/Save.h | 5 | ||||
| -rw-r--r-- | src/search/SearchController.cpp | 3 | ||||
| -rw-r--r-- | src/search/SearchController.h | 5 | ||||
| -rw-r--r-- | src/search/SearchModel.cpp | 16 | ||||
| -rw-r--r-- | src/search/SearchModel.h | 3 | ||||
| -rw-r--r-- | src/search/SearchView.cpp | 54 | ||||
| -rw-r--r-- | src/search/SearchView.h | 17 | ||||
| -rw-r--r-- | src/search/Thumbnail.h | 49 |
8 files changed, 143 insertions, 9 deletions
diff --git a/src/search/Save.h b/src/search/Save.h index a3ef485..91a1ec4 100644 --- a/src/search/Save.h +++ b/src/search/Save.h @@ -10,8 +10,6 @@ class Save private: int id; int votesUp, votesDown; - string userName; - string name; public: Save(int _id, int _votesUp, int _votesDown, string _userName, string _name): id(_id), @@ -22,6 +20,9 @@ public: { } + string userName; + string name; + void SetName(string name){ this->name = name; } string GetName(){ return name; } diff --git a/src/search/SearchController.cpp b/src/search/SearchController.cpp index cf13f2e..90750e0 100644 --- a/src/search/SearchController.cpp +++ b/src/search/SearchController.cpp @@ -8,6 +8,9 @@ SearchController::SearchController() searchModel = new SearchModel(); searchView = new SearchView(); searchModel->AddObserver(searchView); + searchView->AttachController(this); + + searchModel->UpdateSaveList(); //Set up interface //windowPanel.AddChild(); diff --git a/src/search/SearchController.h b/src/search/SearchController.h index 8755a07..10dd9bd 100644 --- a/src/search/SearchController.h +++ b/src/search/SearchController.h @@ -4,15 +4,16 @@ #include "interface/Panel.h" #include "SearchModel.h" #include "SearchView.h" - +class SearchView; +class SearchModel; class SearchController { private: SearchModel * searchModel; SearchView * searchView; - ui::Panel * windowPanel; public: SearchController(); + SearchView * GetView() { return searchView; } }; #endif // SEARCHCONTROLLER_H diff --git a/src/search/SearchModel.cpp b/src/search/SearchModel.cpp index 63188bd..494d490 100644 --- a/src/search/SearchModel.cpp +++ b/src/search/SearchModel.cpp @@ -9,10 +9,24 @@ void SearchModel::UpdateSaveList() { saveList.clear(); notifySaveListChanged(); - saveList.push_back(Save(1, 45, 5, "Simon", "Post logic gates")); + for(int i = 0; i < 16; i++) + { + saveList.push_back(Save(2198, 2333, 315, "dima-gord", "Destroyable city 5 (wth metro)")); + } notifySaveListChanged(); } +vector<Save> SearchModel::GetSaveList() +{ + return saveList; +} + +void SearchModel::AddObserver(SearchView * observer) +{ + observers.push_back(observer); + observer->NotifySaveListChanged(this); +} + void SearchModel::notifySaveListChanged() { for(int i = 0; i < observers.size(); i++) diff --git a/src/search/SearchModel.h b/src/search/SearchModel.h index 0951577..85d4177 100644 --- a/src/search/SearchModel.h +++ b/src/search/SearchModel.h @@ -7,6 +7,7 @@ using namespace std; +class SearchView; class SearchModel { private: @@ -15,7 +16,7 @@ private: void notifySaveListChanged(); public: SearchModel(); - void AddObserver(SearchView * observer){ observers.push_back(observer); } + void AddObserver(SearchView * observer); void UpdateSaveList(); vector<Save> GetSaveList(); }; diff --git a/src/search/SearchView.cpp b/src/search/SearchView.cpp index 4b551f3..29d6eef 100644 --- a/src/search/SearchView.cpp +++ b/src/search/SearchView.cpp @@ -1,10 +1,60 @@ #include "SearchView.h" +#include "interface/SaveButton.h" +#include "Misc.h" -SearchView::SearchView() +SearchView::SearchView(): + ui::Window(ui::Point(0, 0), ui::Point(XRES+BARSIZE, YRES+MENUSIZE)), + saveButtons(vector<ui::SaveButton*>()) { + nextButton = new ui::Button(ui::Point(XRES+BARSIZE-52, YRES+MENUSIZE-18), ui::Point(50, 16), "Next \x95"); + previousButton = new ui::Button(ui::Point(1, YRES+MENUSIZE-18), ui::Point(50, 16), "\x96 Prev"); + + nextButton->SetAlignment(AlignRight, AlignBottom); + previousButton->SetAlignment(AlignLeft, AlignBottom); + AddComponent(nextButton); + AddComponent(previousButton); } -void SearchView::NotifySaveListChanged(SearchModel * sender) +SearchView::~SearchView() { +} +void SearchView::NotifySaveListChanged(SearchModel * sender) +{ + int i = 0; + int buttonWidth, buttonHeight, saveX = 0, saveY = 0, savesX = 4, savesY = 3, buttonPadding = 2; + int buttonAreaWidth, buttonAreaHeight, buttonXOffset, buttonYOffset; + buttonXOffset = 0; + buttonYOffset = 50; + buttonAreaWidth = Size.X; + buttonAreaHeight = Size.Y - buttonYOffset - 18; + buttonWidth = (buttonAreaWidth/savesX) - buttonPadding*2; + buttonHeight = (buttonAreaHeight/savesY) - buttonPadding*2; + for(i = 0; i < saveButtons.size(); i++) + { + RemoveComponent(saveButtons[i]); + delete saveButtons[i]; + } + vector<Save> saves = sender->GetSaveList(); + for(i = 0; i < saves.size(); i++) + { + if(saveX == savesX) + { + if(saveY == savesY-1) + break; + saveX = 0; + saveY++; + } + ui::SaveButton * saveButton; + saveButton = new ui::SaveButton( + ui::Point( + buttonXOffset + buttonPadding + saveX*(buttonWidth+buttonPadding*2), + buttonYOffset + buttonPadding + saveY*(buttonHeight+buttonPadding*2) + ), + ui::Point(buttonWidth, buttonHeight), + saves[i]); + saveButtons.push_back(saveButton); + AddComponent(saveButton); + saveX++; + } } diff --git a/src/search/SearchView.h b/src/search/SearchView.h index e540f21..c68d42c 100644 --- a/src/search/SearchView.h +++ b/src/search/SearchView.h @@ -1,13 +1,28 @@ #ifndef SEARCHVIEW_H #define SEARCHVIEW_H +#include <vector> +#include "SearchController.h" +#include "interface/SaveButton.h" +#include "interface/Button.h" + +using namespace std; + class SearchModel; +class SearchController; -class SearchView +class SearchView: public ui::Window { +private: + SearchController * c; + vector<ui::SaveButton*> saveButtons; + ui::Button * nextButton; + ui::Button * previousButton; public: void NotifySaveListChanged(SearchModel * sender); SearchView(); + virtual ~SearchView(); + void AttachController(SearchController * _c) { c = _c; } }; #endif // SEARCHVIEW_H diff --git a/src/search/Thumbnail.h b/src/search/Thumbnail.h new file mode 100644 index 0000000..3b865ca --- /dev/null +++ b/src/search/Thumbnail.h @@ -0,0 +1,49 @@ +#ifndef THUMBNAIL_H +#define THUMBNAIL_H + +#include "Graphics.h" +#include "interface/Point.h" + +class Thumbnail +{ +public: + Thumbnail(const Thumbnail & thumb): + ID(thumb.ID), + Datestamp(thumb.Datestamp), + Data(thumb.Data), + Size(thumb.Size) + { + //Ensure the actual thumbnail data is copied + if(thumb.Data) + { + Data = (pixel *)malloc((thumb.Size.X*thumb.Size.Y) * PIXELSIZE); + memcpy(Data, thumb.Data, (thumb.Size.X*thumb.Size.Y) * PIXELSIZE); + } + else + { + Data = NULL; + } + } + + Thumbnail(int _id, int _datestamp, pixel * _data, ui::Point _size): + ID(_id), + Datestamp(_datestamp), + Data(_data), + Size(_size) + { + } + + ~Thumbnail() + { + if(Data) + { + free(Data); + } + } + + int ID, Datestamp; + ui::Point Size; + pixel * Data; +}; + +#endif // THUMBNAIL_H |
