Fix stamp and local save thumbnails being stretched

This commit is contained in:
jacob1 2019-03-03 23:45:33 -05:00
parent d021cbb5cf
commit 772148900e
9 changed files with 47 additions and 28 deletions

View File

@ -79,14 +79,14 @@ void RequestBroker::Shutdown()
void RequestBroker::RenderThumbnail(GameSave * gameSave, int width, int height, RequestListener * tListener) 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); 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); pthread_mutex_lock(&requestQueueMutex);
requestQueue.push_back(r); requestQueue.push_back(r);

View File

@ -52,7 +52,7 @@ public:
void FlushThumbQueue(); void FlushThumbQueue();
void RetrieveImage(ByteString imageUrl, int width, int height, RequestListener * tListener); 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 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 saveDate, int width, int height, RequestListener * tListener);
void RetrieveThumbnail(int saveID, int width, int height, RequestListener * tListener); void RetrieveThumbnail(int saveID, int width, int height, RequestListener * tListener);

View File

@ -1,3 +1,4 @@
#include <cmath>
#include <iostream> #include <iostream>
#include <typeinfo> #include <typeinfo>
#include "ThumbRenderRequest.h" #include "ThumbRenderRequest.h"
@ -5,14 +6,16 @@
#include "graphics/Graphics.h" #include "graphics/Graphics.h"
#include "simulation/SaveRenderer.h" #include "simulation/SaveRenderer.h"
ThumbRenderRequest::ThumbRenderRequest(GameSave * save, bool decorations, bool fire, int width, int height, ListenerHandle listener, int identifier): ThumbRenderRequest::ThumbRenderRequest(GameSave * save, bool decorations, bool fire, int width, int height, bool autoRescale, ListenerHandle listener, int identifier):
RequestBroker::Request(ThumbnailRender, listener, 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) RequestBroker::ProcessResponse ThumbRenderRequest::Process(RequestBroker & rb)
@ -24,7 +27,18 @@ RequestBroker::ProcessResponse ThumbRenderRequest::Process(RequestBroker & rb)
if (thumbnail) if (thumbnail)
{ {
if (!autoRescale)
thumbnail->Resize(Width, Height, true); 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; ResultObject = (void*)thumbnail;
rb.requestComplete((Request*)this); rb.requestComplete((Request*)this);
return RequestBroker::Finished; return RequestBroker::Finished;

View File

@ -4,11 +4,13 @@ class GameSave;
class ThumbRenderRequest: public RequestBroker::Request class ThumbRenderRequest: public RequestBroker::Request
{ {
public: public:
GameSave * Save;
int Width, Height; int Width, Height;
bool Decorations; bool Decorations;
bool Fire; bool Fire;
GameSave * Save; bool autoRescale;
ThumbRenderRequest(GameSave * save, bool decorations, bool fire, int width, int height, ListenerHandle listener, int identifier = 0);
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 RequestBroker::ProcessResponse Process(RequestBroker & rb);
virtual ~ThumbRenderRequest(); virtual ~ThumbRenderRequest();
virtual void Cleanup(); virtual void Cleanup();

View File

@ -158,8 +158,8 @@ public:
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 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(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(const VideoBuffer & vidBuf, int x, int y, int a);
void draw_image(VideoBuffer * vidBuf, int w, int h, 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); void draw_rgba_image(const unsigned char *data, int x, int y, float alpha);
Graphics(); Graphics();

View File

@ -133,6 +133,8 @@ void SaveButton::OnResponseReady(void * imagePtr, int identifier)
delete thumbnail; delete thumbnail;
thumbnail = image; thumbnail = image;
waitingForThumb = false; waitingForThumb = false;
if (file)
thumbSize = ui::Point(thumbnail->Width, thumbnail->Height);
} }
} }
@ -158,7 +160,7 @@ void SaveButton::Tick(float dt)
else if(file && file->GetGameSave()) else if(file && file->GetGameSave())
{ {
waitingForThumb = true; 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);
} }
} }
} }
@ -166,8 +168,8 @@ void SaveButton::Tick(float dt)
void SaveButton::Draw(const Point& screenPos) void SaveButton::Draw(const Point& screenPos)
{ {
Graphics * g = GetGraphics(); Graphics * g = GetGraphics();
float scaleFactor; float scaleFactor = (Size.Y-25)/((float)YRES);
ui::Point thumbBoxSize(0, 0); ui::Point thumbBoxSize = ui::Point(((float)XRES)*scaleFactor, ((float)YRES)*scaleFactor);
wantsDraw = true; 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); 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); //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); g->draw_image(thumbnail, screenPos.X-3+(Size.X-thumbBoxSize.X)/2, screenPos.Y+(Size.Y-21-thumbBoxSize.Y)/2, 255);
else 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()) 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); 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); 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 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); 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) if (isMouseInside)
{ {

View File

@ -28,6 +28,7 @@ class SaveButton : public Component, public RequestListener
SaveFile * file; SaveFile * file;
SaveInfo * save; SaveInfo * save;
VideoBuffer * thumbnail; VideoBuffer * thumbnail;
ui::Point thumbSize = ui::Point(0, 0);
String name; String name;
String votesString; String votesString;
String votesBackground; String votesBackground;

View File

@ -71,7 +71,7 @@ LocalSaveActivity::LocalSaveActivity(SaveFile save, FileSavedCallback * callback
SetOkayButton(okayButton); SetOkayButton(okayButton);
if(save.GetGameSave()) 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() void LocalSaveActivity::Save()

View File

@ -184,7 +184,7 @@ ServerSaveActivity::ServerSaveActivity(SaveInfo save, ServerSaveActivity::SaveUp
AddComponent(RulesButton); AddComponent(RulesButton);
if(save.GetGameSave()) 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) : ServerSaveActivity::ServerSaveActivity(SaveInfo save, bool saveNow, ServerSaveActivity::SaveUploadedCallback * callback) :