summaryrefslogtreecommitdiff
path: root/src/interface
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/interface
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/interface')
-rw-r--r--src/interface/SaveButton.cpp100
-rw-r--r--src/interface/SaveButton.h5
2 files changed, 35 insertions, 70 deletions
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: