diff options
| author | Simon Robertshaw <simon@hardwired.org.uk> | 2012-02-11 16:08:59 (GMT) |
|---|---|---|
| committer | Simon Robertshaw <simon@hardwired.org.uk> | 2012-02-11 16:08:59 (GMT) |
| commit | 9f7b06ff47e12076a261b6a209b27c558741eb8a (patch) | |
| tree | d0b4c8f53d976b1e2c1d771da47d7a9e4517db4d /src/preview | |
| parent | 54741c79ef6169eda47745ea4f13e4e1d9982497 (diff) | |
| download | powder-9f7b06ff47e12076a261b6a209b27c558741eb8a.zip powder-9f7b06ff47e12076a261b6a209b27c558741eb8a.tar.gz | |
Comments on save preview and some minor changes for vote bars
Diffstat (limited to 'src/preview')
| -rw-r--r-- | src/preview/Comment.h | 24 | ||||
| -rw-r--r-- | src/preview/PreviewModel.cpp | 84 | ||||
| -rw-r--r-- | src/preview/PreviewModel.h | 10 | ||||
| -rw-r--r-- | src/preview/PreviewView.cpp | 64 | ||||
| -rw-r--r-- | src/preview/PreviewView.h | 6 |
5 files changed, 178 insertions, 10 deletions
diff --git a/src/preview/Comment.h b/src/preview/Comment.h new file mode 100644 index 0000000..a53f6cd --- /dev/null +++ b/src/preview/Comment.h @@ -0,0 +1,24 @@ +/* + * Comment.h + * + * Created on: Feb 11, 2012 + * Author: Simon + */ + +#ifndef COMMENT_H_ +#define COMMENT_H_ + +class Comment +{ +public: + int authorID; + std::string authorName; + std::string comment; + Comment(int userID, std::string username, std::string commentText): + authorID(userID), authorName(username), comment(commentText) + { + } +}; + + +#endif /* COMMENT_H_ */ diff --git a/src/preview/PreviewModel.cpp b/src/preview/PreviewModel.cpp index dba7aa1..371d917 100644 --- a/src/preview/PreviewModel.cpp +++ b/src/preview/PreviewModel.cpp @@ -11,11 +11,14 @@ PreviewModel::PreviewModel(): save(NULL), savePreview(NULL), + saveComments(NULL), doOpen(false), updateSavePreviewWorking(false), updateSavePreviewFinished(false), updateSaveInfoWorking(false), - updateSaveInfoFinished(false) + updateSaveInfoFinished(false), + updateSaveCommentsWorking(false), + updateSaveCommentsFinished(false) { // TODO Auto-generated constructor stub @@ -31,6 +34,11 @@ void * PreviewModel::updateSavePreviewTHelper(void * obj) return ((PreviewModel*)obj)->updateSavePreviewT(); } +void * PreviewModel::updateSaveCommentsTHelper(void * obj) +{ + return ((PreviewModel*)obj)->updateSaveCommentsT(); +} + void * PreviewModel::updateSaveInfoT() { Save * tempSave = Client::Ref().GetSave(tSaveID, tSaveDate); @@ -45,15 +53,38 @@ void * PreviewModel::updateSavePreviewT() return tempThumb; } +void * PreviewModel::updateSaveCommentsT() +{ + std::vector<Comment*> * tempComments = Client::Ref().GetComments(tSaveID, 0, 10); + updateSaveCommentsFinished = true; + return tempComments; +} + void PreviewModel::UpdateSave(int saveID, int saveDate) { this->tSaveID = saveID; this->tSaveDate = saveDate; - save = NULL; - savePreview = NULL; + if(save) + { + delete save; + save = NULL; + } + if(savePreview) + { + delete savePreview; + savePreview = NULL; + } + if(saveComments) + { + for(int i = 0; i < saveComments->size(); i++) + delete saveComments->at(i); + delete saveComments; + saveComments = NULL; + } notifyPreviewChanged(); notifySaveChanged(); + notifySaveCommentsChanged(); if(!updateSavePreviewWorking) { @@ -68,6 +99,13 @@ void PreviewModel::UpdateSave(int saveID, int saveDate) updateSaveInfoFinished = false; pthread_create(&updateSaveInfoThread, 0, &PreviewModel::updateSaveInfoTHelper, this); } + + if(!updateSaveCommentsWorking) + { + updateSaveCommentsWorking = true; + updateSaveCommentsFinished = false; + pthread_create(&updateSaveCommentsThread, 0, &PreviewModel::updateSaveCommentsTHelper, this); + } } void PreviewModel::SetDoOpen(bool doOpen) @@ -90,6 +128,11 @@ Save * PreviewModel::GetSave() return save; } +std::vector<Comment*> * PreviewModel::GetComments() +{ + return saveComments; +} + void PreviewModel::notifyPreviewChanged() { for(int i = 0; i < observers.size(); i++) @@ -106,6 +149,14 @@ void PreviewModel::notifySaveChanged() } } +void PreviewModel::notifySaveCommentsChanged() +{ + for(int i = 0; i < observers.size(); i++) + { + observers[i]->NotifyCommentsChanged(this); + } +} + void PreviewModel::AddObserver(PreviewView * observer) { observers.push_back(observer); observer->NotifyPreviewChanged(this); @@ -118,6 +169,11 @@ void PreviewModel::Update() { if(updateSavePreviewFinished) { + if(savePreview) + { + delete savePreview; + savePreview = NULL; + } updateSavePreviewWorking = false; pthread_join(updateSavePreviewThread, (void**)(&savePreview)); notifyPreviewChanged(); @@ -128,11 +184,33 @@ void PreviewModel::Update() { if(updateSaveInfoFinished) { + if(save) + { + delete save; + save = NULL; + } updateSaveInfoWorking = false; pthread_join(updateSaveInfoThread, (void**)(&save)); notifySaveChanged(); } } + + if(updateSaveCommentsWorking) + { + if(updateSaveCommentsFinished) + { + if(saveComments) + { + for(int i = 0; i < saveComments->size(); i++) + delete saveComments->at(i); + delete saveComments; + saveComments = NULL; + } + updateSaveCommentsWorking = false; + pthread_join(updateSaveCommentsThread, (void**)(&saveComments)); + notifySaveCommentsChanged(); + } + } } PreviewModel::~PreviewModel() { diff --git a/src/preview/PreviewModel.h b/src/preview/PreviewModel.h index e0e5966..84ce83d 100644 --- a/src/preview/PreviewModel.h +++ b/src/preview/PreviewModel.h @@ -12,6 +12,7 @@ #include <pthread.h> #include "PreviewView.h" #include "search/Save.h" +#include "preview/Comment.h" #include "search/Thumbnail.h" using namespace std; @@ -22,8 +23,10 @@ class PreviewModel { vector<PreviewView*> observers; Save * save; Thumbnail * savePreview; + std::vector<Comment*> * saveComments; void notifyPreviewChanged(); void notifySaveChanged(); + void notifySaveCommentsChanged(); //Background retrieval int tSaveID; @@ -40,10 +43,17 @@ class PreviewModel { pthread_t updateSaveInfoThread; static void * updateSaveInfoTHelper(void * obj); void * updateSaveInfoT(); + + bool updateSaveCommentsWorking; + volatile bool updateSaveCommentsFinished; + pthread_t updateSaveCommentsThread; + static void * updateSaveCommentsTHelper(void * obj); + void * updateSaveCommentsT(); public: PreviewModel(); Thumbnail * GetPreview(); Save * GetSave(); + std::vector<Comment*> * GetComments(); void AddObserver(PreviewView * observer); void UpdateSave(int saveID, int saveDate); bool GetDoOpen(); diff --git a/src/preview/PreviewView.cpp b/src/preview/PreviewView.cpp index 3a731dc..aae792d 100644 --- a/src/preview/PreviewView.cpp +++ b/src/preview/PreviewView.cpp @@ -5,6 +5,7 @@ * Author: Simon */ +#include <vector> #include "PreviewView.h" #include "interface/Point.h" #include "interface/Window.h" @@ -51,6 +52,11 @@ PreviewView::PreviewView(): saveNameLabel->SetAlignment(AlignLeft, AlignBottom); AddComponent(saveNameLabel); + saveDescriptionTextblock = new ui::Textblock(ui::Point(5, (YRES/2)+15+14+17), ui::Point((XRES/2)-10, Size.Y-((YRES/2)+15+14+17)-21), ""); + saveDescriptionTextblock->SetAlignment(AlignLeft, AlignTop); + saveDescriptionTextblock->SetTextColour(ui::Colour(180, 180, 180)); + AddComponent(saveDescriptionTextblock); + authorDateLabel = new ui::Label(ui::Point(5, (YRES/2)+15+14), ui::Point(100, 16), ""); authorDateLabel->SetAlignment(AlignLeft, AlignBottom); AddComponent(authorDateLabel); @@ -78,13 +84,13 @@ void PreviewView::OnDraw() if(!votesUp && !votesDown) return; else - factor = (float)(((float)(XRES/2))/((float)(votesUp+votesDown))); - g->fillrect(Position.X, Position.Y+YRES/2, XRES/2, 10, 200, 50, 50, 255); - g->fillrect(Position.X, Position.Y+YRES/2, (int)(((float)votesUp)*factor), 10, 50, 200, 50, 255); - g->fillrect(Position.X, Position.Y+(YRES/2), 14, 10, 0, 0, 0, 100); - g->fillrect(Position.X+(XRES/2)-14, Position.Y+(YRES/2), 14, 10, 0, 0, 0, 100); - g->draw_icon(Position.X+2, Position.Y+(YRES/2)+2, IconVoteUp); - g->draw_icon(Position.X+(XRES/2)-12, Position.Y+(YRES/2), IconVoteDown); + factor = (float)(((float)(XRES/2)-2)/((float)(votesUp+votesDown))); + g->fillrect(1+Position.X, 1+Position.Y+YRES/2, (XRES/2)-2, 8, 200, 50, 50, 255); + g->fillrect(1+Position.X, 1+Position.Y+YRES/2, (int)(((float)votesUp)*factor), 8, 50, 200, 50, 255); + g->fillrect(1+Position.X, 1+Position.Y+(YRES/2), 14, 8, 0, 0, 0, 100); + g->fillrect(Position.X+(XRES/2)-15, 1+Position.Y+(YRES/2), 14, 8, 0, 0, 0, 100); + g->draw_icon(1+Position.X+2, Position.Y+(YRES/2)+2, IconVoteUp); + g->draw_icon(Position.X+(XRES/2)-12, Position.Y+(YRES/2)-1, IconVoteDown); } void PreviewView::OnTick(float dt) @@ -107,6 +113,7 @@ void PreviewView::NotifySaveChanged(PreviewModel * sender) votesDown = save->votesDown; saveNameLabel->SetText(save->name); authorDateLabel->SetText("\bgAuthor:\bw " + save->userName + " \bgDate:\bw "); + saveDescriptionTextblock->SetText(save->Description); } else { @@ -114,6 +121,49 @@ void PreviewView::NotifySaveChanged(PreviewModel * sender) votesDown = 0; saveNameLabel->SetText(""); authorDateLabel->SetText(""); + saveDescriptionTextblock->SetText(""); + } +} + +void PreviewView::NotifyCommentsChanged(PreviewModel * sender) +{ + for(int i = 0; i < commentComponents.size(); i++) + { + RemoveComponent(commentComponents[i]); + delete commentComponents[i]; + } + commentComponents.clear(); + + int currentY = 0; + ui::Label * tempUsername; + ui::Textblock * tempComment; + std::vector<Comment*> * tempComments = sender->GetComments(); + if(tempComments) + { + for(int i = 0; i < tempComments->size(); i++) + { + tempUsername = new ui::Label(ui::Point((XRES/2) + 5, currentY+5), ui::Point(Size.X-((XRES/2) + 10), 16), tempComments->at(i)->authorName); + tempUsername->SetAlignment(AlignLeft, AlignBottom); + currentY += 16; + tempComment = new ui::Textblock(ui::Point((XRES/2) + 5, currentY+5), ui::Point(Size.X-((XRES/2) + 10), -1), tempComments->at(i)->comment); + tempComment->SetAlignment(AlignLeft, AlignTop); + tempComment->SetTextColour(ui::Colour(180, 180, 180)); + currentY += tempComment->Size.Y+4; + + if(currentY > Size.Y) + { + delete tempUsername; + delete tempComment; + break; + } + else + { + commentComponents.push_back(tempComment); + AddComponent(tempComment); + commentComponents.push_back(tempUsername); + AddComponent(tempUsername); + } + } } } diff --git a/src/preview/PreviewView.h b/src/preview/PreviewView.h index 9368732..11ed4bd 100644 --- a/src/preview/PreviewView.h +++ b/src/preview/PreviewView.h @@ -7,12 +7,15 @@ #ifndef PREVIEWVIEW_H_ #define PREVIEWVIEW_H_ + +#include <vector> #include "interface/Window.h" #include "preview/PreviewController.h" #include "preview/PreviewModel.h" #include "interface/Button.h" #include "search/Thumbnail.h" #include "interface/Label.h" +#include "interface/Textblock.h" class PreviewModel; class PreviewController; @@ -23,6 +26,8 @@ class PreviewView: public ui::Window { ui::Button * browserOpenButton; ui::Label * saveNameLabel; ui::Label * authorDateLabel; + ui::Textblock * saveDescriptionTextblock; + std::vector<ui::Component*> commentComponents; int votesUp; int votesDown; public: @@ -30,6 +35,7 @@ public: PreviewView(); void NotifyPreviewChanged(PreviewModel * sender); void NotifySaveChanged(PreviewModel * sender); + void NotifyCommentsChanged(PreviewModel * sender); virtual void OnDraw(); virtual void OnTick(float dt); virtual void OnMouseDown(int x, int y, unsigned button); |
