summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2012-08-14 11:03:33 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2012-08-14 11:03:33 (GMT)
commitb05a847e967f5223b287e85f06b2be382b89fe19 (patch)
treebeb6176d2c3bfffd48e50e6d038ee420f9d12ed4 /src
parentc259521e5e7985176d9ed19b4be509c4e820d954 (diff)
downloadpowder-b05a847e967f5223b287e85f06b2be382b89fe19.zip
powder-b05a847e967f5223b287e85f06b2be382b89fe19.tar.gz
Fix crash when using search (std::remove doesn't seem to work as I expected), Add clickable author names for search. Fixes #95
Diffstat (limited to 'src')
-rw-r--r--src/client/ThumbnailBroker.cpp30
-rw-r--r--src/interface/SaveButton.cpp100
-rw-r--r--src/interface/SaveButton.h5
-rw-r--r--src/search/SearchView.cpp4
4 files changed, 58 insertions, 81 deletions
diff --git a/src/client/ThumbnailBroker.cpp b/src/client/ThumbnailBroker.cpp
index e8114b9..3a6bc14 100644
--- a/src/client/ThumbnailBroker.cpp
+++ b/src/client/ThumbnailBroker.cpp
@@ -96,9 +96,6 @@ void ThumbnailBroker::RenderThumbnail(GameSave * gameSave, int width, int height
void ThumbnailBroker::RetrieveThumbnail(int saveID, int saveDate, int width, int height, ThumbnailListener * tListener)
{
-#ifdef DEBUG
- std::cout << typeid(*this).name() << " New Thumbnail Retrieval request for " << saveID << ":" << saveDate << std::endl;
-#endif
AttachThumbnailListener(tListener);
pthread_mutex_lock(&thumbnailQueueMutex);
bool running = thumbnailQueueRunning;
@@ -127,7 +124,9 @@ void ThumbnailBroker::FlushThumbQueue()
while(thumbnailComplete.size())
{
if(CheckThumbnailListener(thumbnailComplete.front().first))
+ {
thumbnailComplete.front().first->OnThumbnailReady(thumbnailComplete.front().second);
+ }
else
{
#ifdef DEBUG
@@ -146,13 +145,13 @@ void ThumbnailBroker::thumbnailQueueProcessTH()
while(true)
{
//Shutdown after 2 seconds of idle
- //if(time(NULL) - lastAction > 2)
- //{
- // pthread_mutex_lock(&thumbnailQueueMutex);
- // thumbnailQueueRunning = false;
- // pthread_mutex_unlock(&thumbnailQueueMutex);
- // break;
- //}
+ if(time(NULL) - lastAction > 2)
+ {
+ pthread_mutex_lock(&thumbnailQueueMutex);
+ thumbnailQueueRunning = false;
+ pthread_mutex_unlock(&thumbnailQueueMutex);
+ break;
+ }
//Renderer
pthread_mutex_lock(&thumbnailQueueMutex);
@@ -379,6 +378,15 @@ void ThumbnailBroker::AttachThumbnailListener(ThumbnailListener * tListener)
void ThumbnailBroker::DetachThumbnailListener(ThumbnailListener * tListener)
{
pthread_mutex_lock(&listenersMutex);
- std::remove(validListeners.begin(), validListeners.end(), tListener);
+
+ std::vector<ThumbnailListener*>::iterator iter = validListeners.begin();
+ while (iter != validListeners.end())
+ {
+ if(*iter == tListener)
+ iter = validListeners.erase(iter);
+ else
+ ++iter;
+ }
+
pthread_mutex_unlock(&listenersMutex);
} \ No newline at end of file
diff --git a/src/interface/SaveButton.cpp b/src/interface/SaveButton.cpp
index 4e7c1de..b4e67bd 100644
--- a/src/interface/SaveButton.cpp
+++ b/src/interface/SaveButton.cpp
@@ -21,7 +21,8 @@ SaveButton::SaveButton(Point position, Point size, SaveInfo * save):
voteColour(255, 0, 0),
selectable(false),
selected(false),
- waitingForThumb(false)
+ waitingForThumb(false),
+ isMouseInsideAuthor(false)
{
if(save)
{
@@ -65,7 +66,8 @@ SaveButton::SaveButton(Point position, Point size, SaveFile * file):
selectable(false),
selected(false),
wantsDraw(false),
- waitingForThumb(false)
+ waitingForThumb(false),
+ isMouseInsideAuthor(false)
{
if(file)
{
@@ -127,66 +129,6 @@ void SaveButton::Tick(float dt)
ThumbnailBroker::Ref().RenderThumbnail(file->GetGameSave(), Size.X-3, Size.Y-25, this);
}
}
-
- /*Thumbnail * tempThumb;
- float scaleFactorY = 1.0f, scaleFactorX = 1.0f;
- if(!thumbnail)
- {
- if(save)
- {
- if(!save->GetGameSave() && save->GetID())
- {
- tempThumb = Client::Ref().GetThumbnail(save->GetID(), 0);
- if(tempThumb)
- {
- thumbnail = new Thumbnail(*tempThumb); //Store a local copy of the thumbnail
- }
- }
- else if(save->GetGameSave())
- {
- thumbnail = SaveRenderer::Ref().Render(save->GetGameSave());
- }
- else
- {
- thumbnail = NULL;
- }
- }
- if(file)
- {
- if(file->GetThumbnail())
- {
- thumbnail = new Thumbnail(*file->GetThumbnail());
- }
- else if(file->GetGameSave())
- {
- thumbnail = SaveRenderer::Ref().Render(file->GetGameSave());
- }
- else
- {
- thumbnail = NULL;
- }
- }
- if(thumbnail && thumbnail->Data)
- {
- if(thumbnail->Size.Y > (Size.Y-25))
- {
- scaleFactorY = ((float)(Size.Y-25))/((float)thumbnail->Size.Y);
- }
- if(thumbnail->Size.X > Size.X-3)
- {
- scaleFactorX = ((float)Size.X-3)/((float)thumbnail->Size.X);
- }
- if(scaleFactorY < 1.0f || scaleFactorX < 1.0f)
- {
- float scaleFactor = scaleFactorY < scaleFactorX ? scaleFactorY : scaleFactorX;
- pixel * thumbData = thumbnail->Data;
- thumbnail->Data = Graphics::resample_img(thumbData, thumbnail->Size.X, thumbnail->Size.Y, thumbnail->Size.X * scaleFactor, thumbnail->Size.Y * scaleFactor);
- thumbnail->Size.X *= scaleFactor;
- thumbnail->Size.Y *= scaleFactor;
- free(thumbData);
- }
- }
- }*/
}
void SaveButton::Draw(const Point& screenPos)
@@ -236,17 +178,15 @@ void SaveButton::Draw(const Point& screenPos)
g->drawrect(screenPos.X+(Size.X-thumbBoxSize.X)/2, screenPos.Y+(Size.Y-21-thumbBoxSize.Y)/2, thumbBoxSize.X, thumbBoxSize.Y, 180, 180, 180, 255);
}
- if(isMouseInside)
- {
- //g->drawrect(screenPos.X, screenPos.Y, Size.X, Size.Y, 255, 255, 255, 255);
+ if(isMouseInside && !isMouseInsideAuthor)
g->drawtext(screenPos.X+(Size.X-Graphics::textwidth((char *)name.c_str()))/2, screenPos.Y+Size.Y - 21, name, 255, 255, 255, 255);
- g->drawtext(screenPos.X+(Size.X-Graphics::textwidth((char *)save->userName.c_str()))/2, screenPos.Y+Size.Y - 10, save->userName, 200, 230, 255, 255);
- }
else
- {
g->drawtext(screenPos.X+(Size.X-Graphics::textwidth((char *)name.c_str()))/2, screenPos.Y+Size.Y - 21, name, 180, 180, 180, 255);
+
+ if(isMouseInsideAuthor)
+ g->drawtext(screenPos.X+(Size.X-Graphics::textwidth((char *)save->userName.c_str()))/2, screenPos.Y+Size.Y - 10, save->userName, 200, 230, 255, 255);
+ else
g->drawtext(screenPos.X+(Size.X-Graphics::textwidth((char *)save->userName.c_str()))/2, screenPos.Y+Size.Y - 10, save->userName, 100, 130, 160, 255);
- }
}
if(file)
{
@@ -290,7 +230,10 @@ void SaveButton::OnMouseUnclick(int x, int y, unsigned int button)
if(isButtonDown)
{
- DoAction();
+ if(isMouseInsideAuthor)
+ DoAuthorAction();
+ else
+ DoAction();
}
isButtonDown = false;
@@ -308,6 +251,16 @@ void SaveButton::OnMouseClick(int x, int y, unsigned int button)
isButtonDown = true;
}
+void SaveButton::OnMouseMovedInside(int x, int y, int dx, int dy)
+{
+ if(y > Size.Y-11)
+ {
+ isMouseInsideAuthor = true;
+ }
+ else
+ isMouseInsideAuthor = false;
+}
+
void SaveButton::OnMouseEnter(int x, int y)
{
isMouseInside = true;
@@ -316,6 +269,13 @@ void SaveButton::OnMouseEnter(int x, int y)
void SaveButton::OnMouseLeave(int x, int y)
{
isMouseInside = false;
+ isMouseInsideAuthor = false;
+}
+
+void SaveButton::DoAuthorAction()
+{
+ if(actionCallback)
+ actionCallback->AuthorActionCallback(this);
}
void SaveButton::DoAction()
diff --git a/src/interface/SaveButton.h b/src/interface/SaveButton.h
index a5902cd..d1ae05a 100644
--- a/src/interface/SaveButton.h
+++ b/src/interface/SaveButton.h
@@ -18,6 +18,7 @@ class SaveButtonAction
{
public:
virtual void ActionCallback(ui::SaveButton * sender) {}
+ virtual void AuthorActionCallback(ui::SaveButton * sender) {}
virtual void SelectedCallback(ui::SaveButton * sender) {}
virtual ~SaveButtonAction() {}
};
@@ -30,6 +31,7 @@ class SaveButton : public Component, public ThumbnailListener
std::string name;
bool wantsDraw;
bool waitingForThumb;
+ bool isMouseInsideAuthor;
public:
SaveButton(Point position, Point size, SaveInfo * save);
SaveButton(Point position, Point size, SaveFile * file);
@@ -41,6 +43,8 @@ public:
virtual void OnMouseEnter(int x, int y);
virtual void OnMouseLeave(int x, int y);
+ virtual void OnMouseMovedInside(int x, int y, int dx, int dy);
+
virtual void Draw(const Point& screenPos);
virtual void Tick(float dt);
@@ -55,6 +59,7 @@ public:
SaveFile * GetSaveFile() { return file; }
inline bool GetState() { return state; }
virtual void DoAction();
+ virtual void DoAuthorAction();
virtual void DoSelection();
void SetActionCallback(SaveButtonAction * action);
protected:
diff --git a/src/search/SearchView.cpp b/src/search/SearchView.cpp
index 80248e2..866c492 100644
--- a/src/search/SearchView.cpp
+++ b/src/search/SearchView.cpp
@@ -493,6 +493,10 @@ void SearchView::NotifySaveListChanged(SearchModel * sender)
{
v->c->Selected(sender->GetSave()->GetID(), sender->GetSelected());
}
+ virtual void AuthorActionCallback(ui::SaveButton * sender)
+ {
+ v->Search("user:"+sender->GetSave()->GetUserName());
+ }
};
class TagAction: public ui::ButtonAction