diff options
| author | Simon Robertshaw <simon@hardwired.org.uk> | 2012-07-31 18:49:08 (GMT) |
|---|---|---|
| committer | Simon Robertshaw <simon@hardwired.org.uk> | 2012-07-31 18:49:08 (GMT) |
| commit | 1d258eab6b0ec3740d634f014af5dbff882e0069 (patch) | |
| tree | 956d446f144415d4f188dcca17c7dffba08851c2 /src/interface | |
| parent | 303b546ceb134df48763730cbfd8ce7b6df008a2 (diff) | |
| download | powder-1d258eab6b0ec3740d634f014af5dbff882e0069.zip powder-1d258eab6b0ec3740d634f014af5dbff882e0069.tar.gz | |
ThumbnailBroker for background retrieval and rendering
Diffstat (limited to 'src/interface')
| -rw-r--r-- | src/interface/SaveButton.cpp | 45 | ||||
| -rw-r--r-- | src/interface/SaveButton.h | 6 |
2 files changed, 45 insertions, 6 deletions
diff --git a/src/interface/SaveButton.cpp b/src/interface/SaveButton.cpp index b312d3a..18e382d 100644 --- a/src/interface/SaveButton.cpp +++ b/src/interface/SaveButton.cpp @@ -4,7 +4,7 @@ #include "client/SaveInfo.h" #include "graphics/Graphics.h" #include "Engine.h" -#include "client/Client.h" +#include "client/ThumbnailBroker.h" #include "simulation/SaveRenderer.h" namespace ui { @@ -62,7 +62,8 @@ SaveButton::SaveButton(Point position, Point size, SaveFile * file): voteColour(255, 0, 0), selectable(false), selected(false), - wantsDraw(false) + wantsDraw(false), + waitingForThumb(false) { if(file) { @@ -78,6 +79,8 @@ SaveButton::SaveButton(Point position, Point size, SaveFile * file): SaveButton::~SaveButton() { + ThumbnailBroker::Ref().DetachThumbnailListener(this); + if(thumbnail) delete thumbnail; if(actionCallback) @@ -88,11 +91,43 @@ SaveButton::~SaveButton() delete file; } +void SaveButton::OnThumbnailReady(Thumbnail * thumb) +{ + if(thumb) + { + if(thumbnail) + delete thumbnail; + thumbnail = thumb; + waitingForThumb = false; + } +} + void SaveButton::Tick(float dt) { - Thumbnail * tempThumb; + if(!thumbnail && !waitingForThumb) + { + if(save) + { + if(save->GetGameSave()) + { + waitingForThumb = true; + ThumbnailBroker::Ref().RenderThumbnail(save->GetGameSave(), Size.X-3, Size.Y-25, this); + } + else if(save->GetID()) + { + waitingForThumb = true; + ThumbnailBroker::Ref().RetrieveThumbnail(save->GetID() , Size.X-3, Size.Y-25, this); + } + } + else if(file && file->GetGameSave()) + { + waitingForThumb = true; + ThumbnailBroker::Ref().RenderThumbnail(file->GetGameSave(), Size.X-3, Size.Y-25, this); + } + } + /*Thumbnail * tempThumb; float scaleFactorY = 1.0f, scaleFactorX = 1.0f; - if(!thumbnail/* && wantsDraw*/) + if(!thumbnail) { if(save) { @@ -148,7 +183,7 @@ void SaveButton::Tick(float dt) free(thumbData); } } - } + }*/ } void SaveButton::Draw(const Point& screenPos) diff --git a/src/interface/SaveButton.h b/src/interface/SaveButton.h index faa85d7..a5902cd 100644 --- a/src/interface/SaveButton.h +++ b/src/interface/SaveButton.h @@ -6,6 +6,7 @@ #include "Component.h" #include "client/SaveFile.h" #include "client/SaveInfo.h" +#include "client/ThumbnailListener.h" #include "graphics/Graphics.h" #include "search/Thumbnail.h" #include "interface/Colour.h" @@ -21,13 +22,14 @@ public: virtual ~SaveButtonAction() {} }; -class SaveButton : public Component +class SaveButton : public Component, public ThumbnailListener { SaveFile * file; SaveInfo * save; Thumbnail * thumbnail; std::string name; bool wantsDraw; + bool waitingForThumb; public: SaveButton(Point position, Point size, SaveInfo * save); SaveButton(Point position, Point size, SaveFile * file); @@ -42,6 +44,8 @@ public: virtual void Draw(const Point& screenPos); virtual void Tick(float dt); + virtual void OnThumbnailReady(Thumbnail * thumb); + void SetSelected(bool selected_) { selected = selected_; } bool GetSelected() { return selected; } void SetSelectable(bool selectable_) { selectable = selectable_; } |
