Skip to content

Commit

Permalink
Fix stamp and local save thumbnails being stretched
Browse files Browse the repository at this point in the history
  • Loading branch information
jacob1 committed Mar 4, 2019
1 parent d021cbb commit 7721489
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 28 deletions.
6 changes: 3 additions & 3 deletions src/client/requestbroker/RequestBroker.cpp
Expand Up @@ -79,14 +79,14 @@ void RequestBroker::Shutdown()

void RequestBroker::RenderThumbnail(GameSave * gameSave, int width, int height, RequestListener * tListener)
{
RenderThumbnail(gameSave, true, true, width, height, tListener);
RenderThumbnail(gameSave, true, true, width, height, false, tListener);
}

void RequestBroker::RenderThumbnail(GameSave * gameSave, bool decorations, bool fire, int width, int height, RequestListener * tListener)
void RequestBroker::RenderThumbnail(GameSave * gameSave, bool decorations, bool fire, int width, int height, bool autoRescale, RequestListener * tListener)
{
ListenerHandle handle = AttachRequestListener(tListener);

ThumbRenderRequest * r = new ThumbRenderRequest(new GameSave(*gameSave), decorations, fire, width, height, handle);
ThumbRenderRequest * r = new ThumbRenderRequest(new GameSave(*gameSave), decorations, fire, width, height, autoRescale, handle);

pthread_mutex_lock(&requestQueueMutex);
requestQueue.push_back(r);
Expand Down
2 changes: 1 addition & 1 deletion src/client/requestbroker/RequestBroker.h
Expand Up @@ -52,7 +52,7 @@ class RequestBroker: public Singleton<RequestBroker>

void FlushThumbQueue();
void RetrieveImage(ByteString imageUrl, int width, int height, RequestListener * tListener);
void RenderThumbnail(GameSave * gameSave, bool decorations, bool fire, int width, int height, RequestListener * tListener);
void RenderThumbnail(GameSave * gameSave, bool decorations, bool fire, int width, int height, bool autoRescale, RequestListener * tListener);
void RenderThumbnail(GameSave * gameSave, int width, int height, RequestListener * tListener);
void RetrieveThumbnail(int saveID, int saveDate, int width, int height, RequestListener * tListener);
void RetrieveThumbnail(int saveID, int width, int height, RequestListener * tListener);
Expand Down
32 changes: 23 additions & 9 deletions src/client/requestbroker/ThumbRenderRequest.cpp
@@ -1,18 +1,21 @@
#include <cmath>
#include <iostream>
#include <typeinfo>
#include "ThumbRenderRequest.h"
#include "client/GameSave.h"
#include "graphics/Graphics.h"
#include "simulation/SaveRenderer.h"

ThumbRenderRequest::ThumbRenderRequest(GameSave * save, bool decorations, bool fire, int width, int height, ListenerHandle listener, int identifier):
RequestBroker::Request(ThumbnailRender, listener, identifier)
ThumbRenderRequest::ThumbRenderRequest(GameSave * save, bool decorations, bool fire, int width, int height, bool autoRescale, ListenerHandle listener, int identifier):
RequestBroker::Request(ThumbnailRender, listener, identifier),
Save(save),
Width(width),
Height(height),
Decorations(decorations),
Fire(fire),
autoRescale(autoRescale)
{
Save = save;
Width = width;
Height = height;
Decorations = decorations;
Fire = fire;

}

RequestBroker::ProcessResponse ThumbRenderRequest::Process(RequestBroker & rb)
Expand All @@ -22,9 +25,20 @@ RequestBroker::ProcessResponse ThumbRenderRequest::Process(RequestBroker & rb)
delete Save;
Save = NULL;

if(thumbnail)
if (thumbnail)
{
thumbnail->Resize(Width, Height, true);
if (!autoRescale)
thumbnail->Resize(Width, Height, true);
else
{
int scaleX = (int)std::ceil((float)thumbnail->Width / Width);
int scaleY = (int)std::ceil((float)thumbnail->Height / Height);
int scale = scaleX > scaleY ? scaleX : scaleY;
int newWidth = thumbnail->Width / scale, newHeight = thumbnail->Height / scale;
thumbnail->Resize(newWidth, newHeight, true);
Width = newWidth;
Height = newHeight;
}
ResultObject = (void*)thumbnail;
rb.requestComplete((Request*)this);
return RequestBroker::Finished;
Expand Down
6 changes: 4 additions & 2 deletions src/client/requestbroker/ThumbRenderRequest.h
Expand Up @@ -4,11 +4,13 @@ class GameSave;
class ThumbRenderRequest: public RequestBroker::Request
{
public:
GameSave * Save;
int Width, Height;
bool Decorations;
bool Fire;
GameSave * Save;
ThumbRenderRequest(GameSave * save, bool decorations, bool fire, int width, int height, ListenerHandle listener, int identifier = 0);
bool autoRescale;

ThumbRenderRequest(GameSave * save, bool decorations, bool fire, int width, int height, bool autoRescale, ListenerHandle listener, int identifier = 0);
virtual RequestBroker::ProcessResponse Process(RequestBroker & rb);
virtual ~ThumbRenderRequest();
virtual void Cleanup();
Expand Down
4 changes: 2 additions & 2 deletions src/graphics/Graphics.h
Expand Up @@ -158,8 +158,8 @@ class Graphics
void gradientrect(int x, int y, int width, int height, int r, int g, int b, int a, int r2, int g2, int b2, int a2);

void draw_image(pixel *img, int x, int y, int w, int h, int a);
void draw_image(const VideoBuffer & vidBuf, int w, int h, int a);
void draw_image(VideoBuffer * vidBuf, int w, int h, int a);
void draw_image(const VideoBuffer & vidBuf, int x, int y, int a);
void draw_image(VideoBuffer * vidBuf, int x, int y, int a);
void draw_rgba_image(const unsigned char *data, int x, int y, float alpha);

Graphics();
Expand Down
20 changes: 11 additions & 9 deletions src/gui/interface/SaveButton.cpp
Expand Up @@ -128,11 +128,13 @@ SaveButton::~SaveButton()
void SaveButton::OnResponseReady(void * imagePtr, int identifier)
{
VideoBuffer * image = (VideoBuffer*)imagePtr;
if(image)
if (image)
{
delete thumbnail;
thumbnail = image;
waitingForThumb = false;
if (file)
thumbSize = ui::Point(thumbnail->Width, thumbnail->Height);
}
}

Expand All @@ -158,16 +160,16 @@ void SaveButton::Tick(float dt)
else if(file && file->GetGameSave())
{
waitingForThumb = true;
RequestBroker::Ref().RenderThumbnail(file->GetGameSave(), true, false, thumbBoxSize.X, thumbBoxSize.Y, this);
RequestBroker::Ref().RenderThumbnail(file->GetGameSave(), true, false, thumbBoxSize.X, thumbBoxSize.Y, true, this);
}
}
}

void SaveButton::Draw(const Point& screenPos)
{
Graphics * g = GetGraphics();
float scaleFactor;
ui::Point thumbBoxSize(0, 0);
float scaleFactor = (Size.Y-25)/((float)YRES);
ui::Point thumbBoxSize = ui::Point(((float)XRES)*scaleFactor, ((float)YRES)*scaleFactor);

wantsDraw = true;

Expand All @@ -176,15 +178,13 @@ void SaveButton::Draw(const Point& screenPos)
g->fillrect(screenPos.X, screenPos.Y, Size.X, Size.Y, 100, 170, 255, 100);
}

scaleFactor = (Size.Y-25)/((float)YRES);
thumbBoxSize = ui::Point(((float)XRES)*scaleFactor, ((float)YRES)*scaleFactor);
if(thumbnail)
if (thumbnail)
{
//thumbBoxSize = ui::Point(thumbnail->Width, thumbnail->Height);
if(save && save->id)
if (save && save->id)
g->draw_image(thumbnail, screenPos.X-3+(Size.X-thumbBoxSize.X)/2, screenPos.Y+(Size.Y-21-thumbBoxSize.Y)/2, 255);
else
g->draw_image(thumbnail, screenPos.X+(Size.X-thumbBoxSize.X)/2, screenPos.Y+(Size.Y-21-thumbBoxSize.Y)/2, 255);
g->draw_image(thumbnail, screenPos.X+(Size.X-thumbSize.X)/2, screenPos.Y+(Size.Y-21-thumbSize.Y)/2, 255);
}
else if (file && !file->GetGameSave())
g->drawtext(screenPos.X+(Size.X-Graphics::textwidth("Error loading save"))/2, screenPos.Y+(Size.Y-28)/2, "Error loading save", 180, 180, 180, 255);
Expand Down Expand Up @@ -257,6 +257,8 @@ 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, 210, 230, 255, 255);
else
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 (thumbSize.X)
g->xor_rect(screenPos.X+(Size.X-thumbSize.X)/2, screenPos.Y+(Size.Y-21-thumbSize.Y)/2, thumbSize.X, thumbSize.Y);

if (isMouseInside)
{
Expand Down
1 change: 1 addition & 0 deletions src/gui/interface/SaveButton.h
Expand Up @@ -28,6 +28,7 @@ class SaveButton : public Component, public RequestListener
SaveFile * file;
SaveInfo * save;
VideoBuffer * thumbnail;
ui::Point thumbSize = ui::Point(0, 0);
String name;
String votesString;
String votesBackground;
Expand Down
2 changes: 1 addition & 1 deletion src/gui/save/LocalSaveActivity.cpp
Expand Up @@ -71,7 +71,7 @@ LocalSaveActivity::LocalSaveActivity(SaveFile save, FileSavedCallback * callback
SetOkayButton(okayButton);

if(save.GetGameSave())
RequestBroker::Ref().RenderThumbnail(save.GetGameSave(), true, false, Size.X-16, -1, this);
RequestBroker::Ref().RenderThumbnail(save.GetGameSave(), true, false, Size.X-16, -1, false, this);
}

void LocalSaveActivity::Save()
Expand Down
2 changes: 1 addition & 1 deletion src/gui/save/ServerSaveActivity.cpp
Expand Up @@ -184,7 +184,7 @@ ServerSaveActivity::ServerSaveActivity(SaveInfo save, ServerSaveActivity::SaveUp
AddComponent(RulesButton);

if(save.GetGameSave())
RequestBroker::Ref().RenderThumbnail(save.GetGameSave(), false, true, (Size.X/2)-16, -1, this);
RequestBroker::Ref().RenderThumbnail(save.GetGameSave(), false, true, (Size.X/2)-16, -1, false, this);
}

ServerSaveActivity::ServerSaveActivity(SaveInfo save, bool saveNow, ServerSaveActivity::SaveUploadedCallback * callback) :
Expand Down

0 comments on commit 7721489

Please sign in to comment.