Fix stamp and local save thumbnails being stretched
This commit is contained in:
parent
d021cbb5cf
commit
772148900e
@ -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 @@ public:
|
||||
|
||||
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,3 +1,4 @@
|
||||
#include <cmath>
|
||||
#include <iostream>
|
||||
#include <typeinfo>
|
||||
#include "ThumbRenderRequest.h"
|
||||
@ -5,14 +6,16 @@
|
||||
#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)
|
||||
@ -24,7 +27,18 @@ RequestBroker::ProcessResponse ThumbRenderRequest::Process(RequestBroker & rb)
|
||||
|
||||
if (thumbnail)
|
||||
{
|
||||
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 @@ 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 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();
|
||||
|
@ -133,6 +133,8 @@ void SaveButton::OnResponseReady(void * imagePtr, int identifier)
|
||||
delete thumbnail;
|
||||
thumbnail = image;
|
||||
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())
|
||||
{
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
//thumbBoxSize = ui::Point(thumbnail->Width, thumbnail->Height);
|
||||
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) :
|
||||
|
Loading…
Reference in New Issue
Block a user