Use VideoBuffer in place of thumbnail

This commit is contained in:
Simon Robertshaw
2013-03-15 12:59:55 +00:00
parent 6b68c04cd6
commit 73b6ff4efb
11 changed files with 68 additions and 61 deletions

View File

@@ -1,3 +1,4 @@
#include <iostream>
#include <typeinfo> #include <typeinfo>
#include "ThumbRenderRequest.h" #include "ThumbRenderRequest.h"
#include "client/GameSave.h" #include "client/GameSave.h"
@@ -17,10 +18,7 @@ ThumbRenderRequest::ThumbRenderRequest(GameSave * save, bool decorations, bool f
RequestBroker::ProcessResponse ThumbRenderRequest::Process(RequestBroker & rb) RequestBroker::ProcessResponse ThumbRenderRequest::Process(RequestBroker & rb)
{ {
#ifdef DEBUG VideoBuffer * thumbnail = SaveRenderer::Ref().Render(Save, Decorations, Fire);
std::cout << typeid(*this).name() << " Processing render request" << std::endl;
#endif
Thumbnail * thumbnail = SaveRenderer::Ref().Render(Save, Decorations, Fire);
delete Save; delete Save;
Save = NULL; Save = NULL;

View File

@@ -1040,18 +1040,18 @@ void GameView::OnMouseUp(int x, int y, unsigned button)
{ {
if(placeSaveThumb) if(placeSaveThumb)
{ {
int thumbX = selectPoint2.X - (placeSaveThumb->Size.X/2); int thumbX = selectPoint2.X - (placeSaveThumb->Width/2);
int thumbY = selectPoint2.Y - (placeSaveThumb->Size.Y/2); int thumbY = selectPoint2.Y - (placeSaveThumb->Height/2);
if(thumbX<0) if(thumbX<0)
thumbX = 0; thumbX = 0;
if(thumbX+(placeSaveThumb->Size.X)>=XRES) if(thumbX+(placeSaveThumb->Width)>=XRES)
thumbX = XRES-placeSaveThumb->Size.X; thumbX = XRES-placeSaveThumb->Width;
if(thumbY<0) if(thumbY<0)
thumbY = 0; thumbY = 0;
if(thumbY+(placeSaveThumb->Size.Y)>=YRES) if(thumbY+(placeSaveThumb->Height)>=YRES)
thumbY = YRES-placeSaveThumb->Size.Y; thumbY = YRES-placeSaveThumb->Height;
c->PlaceSave(ui::Point(thumbX, thumbY)); c->PlaceSave(ui::Point(thumbX, thumbY));
} }
@@ -1852,24 +1852,24 @@ void GameView::OnDraw()
{ {
if(placeSaveThumb && selectPoint2.X!=-1) if(placeSaveThumb && selectPoint2.X!=-1)
{ {
int thumbX = selectPoint2.X - (placeSaveThumb->Size.X/2); int thumbX = selectPoint2.X - (placeSaveThumb->Width/2);
int thumbY = selectPoint2.Y - (placeSaveThumb->Size.Y/2); int thumbY = selectPoint2.Y - (placeSaveThumb->Height/2);
ui::Point thumbPos = c->NormaliseBlockCoord(ui::Point(thumbX, thumbY)); ui::Point thumbPos = c->NormaliseBlockCoord(ui::Point(thumbX, thumbY));
if(thumbPos.X<0) if(thumbPos.X<0)
thumbPos.X = 0; thumbPos.X = 0;
if(thumbPos.X+(placeSaveThumb->Size.X)>=XRES) if(thumbPos.X+(placeSaveThumb->Width)>=XRES)
thumbPos.X = XRES-placeSaveThumb->Size.X; thumbPos.X = XRES-placeSaveThumb->Width;
if(thumbPos.Y<0) if(thumbPos.Y<0)
thumbPos.Y = 0; thumbPos.Y = 0;
if(thumbPos.Y+(placeSaveThumb->Size.Y)>=YRES) if(thumbPos.Y+(placeSaveThumb->Height)>=YRES)
thumbPos.Y = YRES-placeSaveThumb->Size.Y; thumbPos.Y = YRES-placeSaveThumb->Height;
ren->draw_image(placeSaveThumb->Data, thumbPos.X, thumbPos.Y, placeSaveThumb->Size.X, placeSaveThumb->Size.Y, 128); ren->draw_image(placeSaveThumb, thumbPos.X, thumbPos.Y, 128);
ren->xor_rect(thumbPos.X, thumbPos.Y, placeSaveThumb->Size.X, placeSaveThumb->Size.Y); ren->xor_rect(thumbPos.X, thumbPos.Y, placeSaveThumb->Width, placeSaveThumb->Width);
} }
} }
else else

View File

@@ -102,7 +102,7 @@ private:
ui::Point mousePosition; ui::Point mousePosition;
Thumbnail * placeSaveThumb; VideoBuffer * placeSaveThumb;
SimulationSample sample; SimulationSample sample;

View File

@@ -55,6 +55,16 @@ void VideoBuffer::Resize(int width, int height, bool resample)
int newWidth = width; int newWidth = width;
int newHeight = height; int newHeight = height;
pixel * newBuffer; pixel * newBuffer;
if(newHeight == -1 && newWidth == -1)
return;
if(newHeight == -1)
{
newHeight = ((float)Height)*((float)newWidth/(float)Width);
}
if(newWidth == -1)
{
newWidth = ((float)Width)*((float)newHeight/(float)Height);
}
if(resample) if(resample)
newBuffer = Graphics::resample_img(Buffer, Width, Height, newWidth, newHeight); newBuffer = Graphics::resample_img(Buffer, Width, Height, newWidth, newHeight);
else else
@@ -1113,16 +1123,6 @@ pixel *Graphics::render_packed_rgb(void *image, int width, int height, int cmp_s
return res; return res;
} }
void Graphics::draw_image(const VideoBuffer & vidBuf, int x, int y, int a)
{
draw_image(vidBuf.Buffer, x, y, vidBuf.Width, vidBuf.Height, a);
}
void Graphics::draw_image(VideoBuffer * vidBuf, int x, int y, int a)
{
draw_image(vidBuf->Buffer, x, y, vidBuf->Width, vidBuf->Height, a);
}
VideoBuffer Graphics::DumpFrame() VideoBuffer Graphics::DumpFrame()
{ {
#ifdef OGLI #ifdef OGLI

View File

@@ -386,4 +386,14 @@ void PIXELMETHODS_CLASS::draw_image(pixel *img, int x, int y, int w, int h, int
blendpixel(x+i, y+j, r, g, b, a); blendpixel(x+i, y+j, r, g, b, a);
img++; img++;
} }
}
void PIXELMETHODS_CLASS::draw_image(const VideoBuffer & vidBuf, int x, int y, int a)
{
draw_image(vidBuf.Buffer, x, y, vidBuf.Width, vidBuf.Height, a);
}
void PIXELMETHODS_CLASS::draw_image(VideoBuffer * vidBuf, int x, int y, int a)
{
draw_image(vidBuf->Buffer, x, y, vidBuf->Width, vidBuf->Height, a);
} }

View File

@@ -129,6 +129,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(VideoBuffer * vidBuf, int w, int h, int a);
VideoBuffer DumpFrame(); VideoBuffer DumpFrame();

View File

@@ -39,7 +39,6 @@ SaveButton::SaveButton(Point position, Point size, SaveInfo * save):
} }
std::string votes, icon; std::string votes, icon;
int j;
votes = format::NumberToString<int>(save->GetVotesUp()-save->GetVotesDown()); votes = format::NumberToString<int>(save->GetVotesUp()-save->GetVotesDown());
icon += 0xBB; icon += 0xBB;

View File

@@ -277,9 +277,9 @@ void PreviewView::OnDraw()
g->clearrect(Position.X-2, Position.Y-2, Size.X+4, Size.Y+4); g->clearrect(Position.X-2, Position.Y-2, Size.X+4, Size.Y+4);
//Save preview (top-left) //Save preview (top-left)
if(savePreview && savePreview->Data) if(savePreview && savePreview->Buffer)
{ {
g->draw_image(savePreview->Data, (Position.X+1)+(((XRES/2)-savePreview->Size.X)/2), (Position.Y+1)+(((YRES/2)-savePreview->Size.Y)/2), savePreview->Size.X, savePreview->Size.Y, 255); g->draw_image(savePreview, (Position.X+1)+(((XRES/2)-savePreview->Width)/2), (Position.Y+1)+(((YRES/2)-savePreview->Height)/2), 255);
} }
g->drawrect(Position.X, Position.Y, (XRES/2)+1, (YRES/2)+1, 255, 255, 255, 100); g->drawrect(Position.X, Position.Y, (XRES/2)+1, (YRES/2)+1, 255, 255, 255, 100);
g->draw_line(Position.X+XRES/2, Position.Y+1, Position.X+XRES/2, Position.Y+Size.Y-2, 200, 200, 200, 255); g->draw_line(Position.X+XRES/2, Position.Y+1, Position.X+XRES/2, Position.Y+Size.Y-2, 200, 200, 200, 255);
@@ -420,17 +420,17 @@ void PreviewView::NotifySaveChanged(PreviewModel * sender)
{ {
savePreview = SaveRenderer::Ref().Render(save->GetGameSave(), false, true); savePreview = SaveRenderer::Ref().Render(save->GetGameSave(), false, true);
if(savePreview && savePreview->Data && !(savePreview->Size.X == XRES/2 && savePreview->Size.Y == YRES/2)) if(savePreview && savePreview->Buffer && !(savePreview->Width == XRES/2 && savePreview->Width == YRES/2))
{ {
int newSizeX, newSizeY; int newSizeX, newSizeY;
pixel * oldData = savePreview->Data; pixel * oldData = savePreview->Buffer;
float factorX = ((float)XRES/2)/((float)savePreview->Size.X); float factorX = ((float)XRES/2)/((float)savePreview->Width);
float factorY = ((float)YRES/2)/((float)savePreview->Size.Y); float factorY = ((float)YRES/2)/((float)savePreview->Height);
float scaleFactor = factorY < factorX ? factorY : factorX; float scaleFactor = factorY < factorX ? factorY : factorX;
savePreview->Data = Graphics::resample_img(oldData, savePreview->Size.X, savePreview->Size.Y, savePreview->Size.X*scaleFactor, savePreview->Size.Y*scaleFactor); savePreview->Buffer = Graphics::resample_img(oldData, savePreview->Width, savePreview->Height, savePreview->Width*scaleFactor, savePreview->Height*scaleFactor);
delete[] oldData; delete[] oldData;
savePreview->Size.X *= scaleFactor; savePreview->Width *= scaleFactor;
savePreview->Size.Y *= scaleFactor; savePreview->Height *= scaleFactor;
} }
} }
} }
@@ -582,15 +582,15 @@ void PreviewView::NotifyCommentsChanged(PreviewModel * sender)
/*void PreviewView::NotifyPreviewChanged(PreviewModel * sender) /*void PreviewView::NotifyPreviewChanged(PreviewModel * sender)
{ {
savePreview = sender->GetGameSave(); savePreview = sender->GetGameSave();
if(savePreview && savePreview->Data && !(savePreview->Size.X == XRES/2 && savePreview->Size.Y == YRES/2)) if(savePreview && savePreview->Data && !(savePreview->Width == XRES/2 && savePreview->Height == YRES/2))
{ {
int newSizeX, newSizeY; int newSizeX, newSizeY;
float factorX = ((float)XRES/2)/((float)savePreview->Size.X); float factorX = ((float)XRES/2)/((float)savePreview->Width);
float factorY = ((float)YRES/2)/((float)savePreview->Size.Y); float factorY = ((float)YRES/2)/((float)savePreview->Height);
float scaleFactor = factorY < factorX ? factorY : factorX; float scaleFactor = factorY < factorX ? factorY : factorX;
savePreview->Data = Graphics::resample_img(savePreview->Data, savePreview->Size.X, savePreview->Size.Y, savePreview->Size.X*scaleFactor, savePreview->Size.Y*scaleFactor); savePreview->Data = Graphics::resample_img(savePreview->Data, savePreview->Width, savePreview->Height, savePreview->Width*scaleFactor, savePreview->Height*scaleFactor);
savePreview->Size.X *= scaleFactor; savePreview->Width *= scaleFactor;
savePreview->Size.Y *= scaleFactor; savePreview->Height *= scaleFactor;
} }
}*/ }*/

View File

@@ -7,7 +7,6 @@
#include "preview/PreviewController.h" #include "preview/PreviewController.h"
#include "preview/PreviewModel.h" #include "preview/PreviewModel.h"
#include "interface/Button.h" #include "interface/Button.h"
#include "search/Thumbnail.h"
#include "interface/Label.h" #include "interface/Label.h"
#include "interface/Textbox.h" #include "interface/Textbox.h"
@@ -17,6 +16,7 @@ namespace ui
class AvatarButton; class AvatarButton;
} }
class VideoBuffer;
class PreviewModel; class PreviewModel;
class PreviewController; class PreviewController;
class PreviewView: public ui::Window { class PreviewView: public ui::Window {
@@ -24,7 +24,7 @@ class PreviewView: public ui::Window {
class LoginAction; class LoginAction;
class AutoCommentSizeAction; class AutoCommentSizeAction;
PreviewController * c; PreviewController * c;
Thumbnail * savePreview; VideoBuffer * savePreview;
ui::Button * openButton; ui::Button * openButton;
ui::Button * browserOpenButton; ui::Button * browserOpenButton;
ui::Button * favButton; ui::Button * favButton;

View File

@@ -32,10 +32,10 @@ SaveRenderer::SaveRenderer(){
#endif #endif
} }
Thumbnail * SaveRenderer::Render(GameSave * save, bool decorations, bool fire) VideoBuffer * SaveRenderer::Render(GameSave * save, bool decorations, bool fire)
{ {
int width, height; int width, height;
Thumbnail * tempThumb; VideoBuffer * tempThumb;
width = save->blockWidth; width = save->blockWidth;
height = save->blockHeight; height = save->blockHeight;
bool doCollapse = save->Collapsed(); bool doCollapse = save->Collapsed();
@@ -104,7 +104,7 @@ Thumbnail * SaveRenderer::Render(GameSave * save, bool decorations, bool fire)
} }
} }
tempThumb = new Thumbnail(0, 0, pData, ui::Point(width*CELL, height*CELL)); tempThumb = new VideoBuffer(pData, width*CELL, height*CELL);
delete[] pData; delete[] pData;
delete[] texData; delete[] texData;
pData = NULL; pData = NULL;
@@ -139,7 +139,7 @@ Thumbnail * SaveRenderer::Render(GameSave * save, bool decorations, bool fire)
dst+=(width*CELL);///PIXELSIZE; dst+=(width*CELL);///PIXELSIZE;
src+=XRES+BARSIZE; src+=XRES+BARSIZE;
} }
tempThumb = new Thumbnail(0, 0, pData, ui::Point(width*CELL, height*CELL)); tempThumb = new VideoBuffer(pData, width*CELL, height*CELL);
if(pData) if(pData)
free(pData); free(pData);
#endif #endif
@@ -150,7 +150,7 @@ Thumbnail * SaveRenderer::Render(GameSave * save, bool decorations, bool fire)
return tempThumb; return tempThumb;
} }
Thumbnail * SaveRenderer::Render(unsigned char * saveData, int dataSize, bool decorations, bool fire) VideoBuffer * SaveRenderer::Render(unsigned char * saveData, int dataSize, bool decorations, bool fire)
{ {
GameSave * tempSave; GameSave * tempSave;
try { try {
@@ -158,14 +158,12 @@ Thumbnail * SaveRenderer::Render(unsigned char * saveData, int dataSize, bool de
} catch (std::exception & e) { } catch (std::exception & e) {
//Todo: make this look a little less shit //Todo: make this look a little less shit
VideoBuffer buffer(64, 64); VideoBuffer * buffer = new VideoBuffer(64, 64);
buffer.BlendCharacter(32, 32, 'x', 255, 255, 255, 255); buffer->BlendCharacter(32, 32, 'x', 255, 255, 255, 255);
Thumbnail * thumb = new Thumbnail(0, 0, buffer.Buffer, ui::Point(64, 64)); return buffer;
return thumb;
} }
Thumbnail * thumb = Render(tempSave, decorations, fire); VideoBuffer * thumb = Render(tempSave, decorations, fire);
delete tempSave; delete tempSave;
return thumb; return thumb;
} }

View File

@@ -6,7 +6,7 @@
#include "Singleton.h" #include "Singleton.h"
class GameSave; class GameSave;
class Thumbnail; class VideoBuffer;
class Graphics; class Graphics;
class Simulation; class Simulation;
class Renderer; class Renderer;
@@ -17,8 +17,8 @@ class SaveRenderer: public Singleton<SaveRenderer> {
Renderer * ren; Renderer * ren;
public: public:
SaveRenderer(); SaveRenderer();
Thumbnail * Render(GameSave * save, bool decorations = true, bool fire = true); VideoBuffer * Render(GameSave * save, bool decorations = true, bool fire = true);
Thumbnail * Render(unsigned char * saveData, int saveDataSize, bool decorations = true, bool fire = true); VideoBuffer * Render(unsigned char * saveData, int saveDataSize, bool decorations = true, bool fire = true);
virtual ~SaveRenderer(); virtual ~SaveRenderer();
private: private: