Skip to content
Permalink
Browse files

Fix stamp and local save thumbnails being stretched

  • Loading branch information...
jacob1 committed Mar 4, 2019
1 parent d021cbb commit 772148900ee0ce8bad927d3b1c7392bcf816ae59
@@ -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);
@@ -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);
@@ -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)
@@ -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;
@@ -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();
@@ -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();
@@ -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);
}
}

@@ -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;

@@ -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);
@@ -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)
{
@@ -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;
@@ -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()
@@ -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) :

0 comments on commit 7721489

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.