Use VideoBuffer in place of thumbnail
This commit is contained in:
parent
6b68c04cd6
commit
73b6ff4efb
@ -1,3 +1,4 @@
|
||||
#include <iostream>
|
||||
#include <typeinfo>
|
||||
#include "ThumbRenderRequest.h"
|
||||
#include "client/GameSave.h"
|
||||
@ -17,10 +18,7 @@ ThumbRenderRequest::ThumbRenderRequest(GameSave * save, bool decorations, bool f
|
||||
|
||||
RequestBroker::ProcessResponse ThumbRenderRequest::Process(RequestBroker & rb)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cout << typeid(*this).name() << " Processing render request" << std::endl;
|
||||
#endif
|
||||
Thumbnail * thumbnail = SaveRenderer::Ref().Render(Save, Decorations, Fire);
|
||||
VideoBuffer * thumbnail = SaveRenderer::Ref().Render(Save, Decorations, Fire);
|
||||
|
||||
delete Save;
|
||||
Save = NULL;
|
||||
|
@ -1040,18 +1040,18 @@ void GameView::OnMouseUp(int x, int y, unsigned button)
|
||||
{
|
||||
if(placeSaveThumb)
|
||||
{
|
||||
int thumbX = selectPoint2.X - (placeSaveThumb->Size.X/2);
|
||||
int thumbY = selectPoint2.Y - (placeSaveThumb->Size.Y/2);
|
||||
int thumbX = selectPoint2.X - (placeSaveThumb->Width/2);
|
||||
int thumbY = selectPoint2.Y - (placeSaveThumb->Height/2);
|
||||
|
||||
if(thumbX<0)
|
||||
thumbX = 0;
|
||||
if(thumbX+(placeSaveThumb->Size.X)>=XRES)
|
||||
thumbX = XRES-placeSaveThumb->Size.X;
|
||||
if(thumbX+(placeSaveThumb->Width)>=XRES)
|
||||
thumbX = XRES-placeSaveThumb->Width;
|
||||
|
||||
if(thumbY<0)
|
||||
thumbY = 0;
|
||||
if(thumbY+(placeSaveThumb->Size.Y)>=YRES)
|
||||
thumbY = YRES-placeSaveThumb->Size.Y;
|
||||
if(thumbY+(placeSaveThumb->Height)>=YRES)
|
||||
thumbY = YRES-placeSaveThumb->Height;
|
||||
|
||||
c->PlaceSave(ui::Point(thumbX, thumbY));
|
||||
}
|
||||
@ -1852,24 +1852,24 @@ void GameView::OnDraw()
|
||||
{
|
||||
if(placeSaveThumb && selectPoint2.X!=-1)
|
||||
{
|
||||
int thumbX = selectPoint2.X - (placeSaveThumb->Size.X/2);
|
||||
int thumbY = selectPoint2.Y - (placeSaveThumb->Size.Y/2);
|
||||
int thumbX = selectPoint2.X - (placeSaveThumb->Width/2);
|
||||
int thumbY = selectPoint2.Y - (placeSaveThumb->Height/2);
|
||||
|
||||
ui::Point thumbPos = c->NormaliseBlockCoord(ui::Point(thumbX, thumbY));
|
||||
|
||||
if(thumbPos.X<0)
|
||||
thumbPos.X = 0;
|
||||
if(thumbPos.X+(placeSaveThumb->Size.X)>=XRES)
|
||||
thumbPos.X = XRES-placeSaveThumb->Size.X;
|
||||
if(thumbPos.X+(placeSaveThumb->Width)>=XRES)
|
||||
thumbPos.X = XRES-placeSaveThumb->Width;
|
||||
|
||||
if(thumbPos.Y<0)
|
||||
thumbPos.Y = 0;
|
||||
if(thumbPos.Y+(placeSaveThumb->Size.Y)>=YRES)
|
||||
thumbPos.Y = YRES-placeSaveThumb->Size.Y;
|
||||
if(thumbPos.Y+(placeSaveThumb->Height)>=YRES)
|
||||
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
|
||||
|
@ -102,7 +102,7 @@ private:
|
||||
|
||||
ui::Point mousePosition;
|
||||
|
||||
Thumbnail * placeSaveThumb;
|
||||
VideoBuffer * placeSaveThumb;
|
||||
|
||||
SimulationSample sample;
|
||||
|
||||
|
@ -55,6 +55,16 @@ void VideoBuffer::Resize(int width, int height, bool resample)
|
||||
int newWidth = width;
|
||||
int newHeight = height;
|
||||
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)
|
||||
newBuffer = Graphics::resample_img(Buffer, Width, Height, newWidth, newHeight);
|
||||
else
|
||||
@ -1113,16 +1123,6 @@ pixel *Graphics::render_packed_rgb(void *image, int width, int height, int cmp_s
|
||||
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()
|
||||
{
|
||||
#ifdef OGLI
|
||||
|
@ -387,3 +387,13 @@ void PIXELMETHODS_CLASS::draw_image(pixel *img, int x, int y, int w, int h, int
|
||||
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);
|
||||
}
|
@ -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 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();
|
||||
|
||||
|
@ -39,7 +39,6 @@ SaveButton::SaveButton(Point position, Point size, SaveInfo * save):
|
||||
}
|
||||
|
||||
std::string votes, icon;
|
||||
int j;
|
||||
|
||||
votes = format::NumberToString<int>(save->GetVotesUp()-save->GetVotesDown());
|
||||
icon += 0xBB;
|
||||
|
@ -277,9 +277,9 @@ void PreviewView::OnDraw()
|
||||
g->clearrect(Position.X-2, Position.Y-2, Size.X+4, Size.Y+4);
|
||||
|
||||
//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->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);
|
||||
|
||||
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;
|
||||
pixel * oldData = savePreview->Data;
|
||||
float factorX = ((float)XRES/2)/((float)savePreview->Size.X);
|
||||
float factorY = ((float)YRES/2)/((float)savePreview->Size.Y);
|
||||
pixel * oldData = savePreview->Buffer;
|
||||
float factorX = ((float)XRES/2)/((float)savePreview->Width);
|
||||
float factorY = ((float)YRES/2)/((float)savePreview->Height);
|
||||
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;
|
||||
savePreview->Size.X *= scaleFactor;
|
||||
savePreview->Size.Y *= scaleFactor;
|
||||
savePreview->Width *= scaleFactor;
|
||||
savePreview->Height *= scaleFactor;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -582,15 +582,15 @@ void PreviewView::NotifyCommentsChanged(PreviewModel * sender)
|
||||
/*void PreviewView::NotifyPreviewChanged(PreviewModel * sender)
|
||||
{
|
||||
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;
|
||||
float factorX = ((float)XRES/2)/((float)savePreview->Size.X);
|
||||
float factorY = ((float)YRES/2)/((float)savePreview->Size.Y);
|
||||
float factorX = ((float)XRES/2)/((float)savePreview->Width);
|
||||
float factorY = ((float)YRES/2)/((float)savePreview->Height);
|
||||
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->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->Width *= scaleFactor;
|
||||
savePreview->Height *= scaleFactor;
|
||||
}
|
||||
}*/
|
||||
|
||||
|
@ -7,7 +7,6 @@
|
||||
#include "preview/PreviewController.h"
|
||||
#include "preview/PreviewModel.h"
|
||||
#include "interface/Button.h"
|
||||
#include "search/Thumbnail.h"
|
||||
#include "interface/Label.h"
|
||||
#include "interface/Textbox.h"
|
||||
|
||||
@ -17,6 +16,7 @@ namespace ui
|
||||
class AvatarButton;
|
||||
}
|
||||
|
||||
class VideoBuffer;
|
||||
class PreviewModel;
|
||||
class PreviewController;
|
||||
class PreviewView: public ui::Window {
|
||||
@ -24,7 +24,7 @@ class PreviewView: public ui::Window {
|
||||
class LoginAction;
|
||||
class AutoCommentSizeAction;
|
||||
PreviewController * c;
|
||||
Thumbnail * savePreview;
|
||||
VideoBuffer * savePreview;
|
||||
ui::Button * openButton;
|
||||
ui::Button * browserOpenButton;
|
||||
ui::Button * favButton;
|
||||
|
@ -32,10 +32,10 @@ SaveRenderer::SaveRenderer(){
|
||||
#endif
|
||||
}
|
||||
|
||||
Thumbnail * SaveRenderer::Render(GameSave * save, bool decorations, bool fire)
|
||||
VideoBuffer * SaveRenderer::Render(GameSave * save, bool decorations, bool fire)
|
||||
{
|
||||
int width, height;
|
||||
Thumbnail * tempThumb;
|
||||
VideoBuffer * tempThumb;
|
||||
width = save->blockWidth;
|
||||
height = save->blockHeight;
|
||||
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[] texData;
|
||||
pData = NULL;
|
||||
@ -139,7 +139,7 @@ Thumbnail * SaveRenderer::Render(GameSave * save, bool decorations, bool fire)
|
||||
dst+=(width*CELL);///PIXELSIZE;
|
||||
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)
|
||||
free(pData);
|
||||
#endif
|
||||
@ -150,7 +150,7 @@ Thumbnail * SaveRenderer::Render(GameSave * save, bool decorations, bool fire)
|
||||
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;
|
||||
try {
|
||||
@ -158,14 +158,12 @@ Thumbnail * SaveRenderer::Render(unsigned char * saveData, int dataSize, bool de
|
||||
} catch (std::exception & e) {
|
||||
|
||||
//Todo: make this look a little less shit
|
||||
VideoBuffer buffer(64, 64);
|
||||
buffer.BlendCharacter(32, 32, 'x', 255, 255, 255, 255);
|
||||
VideoBuffer * buffer = new VideoBuffer(64, 64);
|
||||
buffer->BlendCharacter(32, 32, 'x', 255, 255, 255, 255);
|
||||
|
||||
Thumbnail * thumb = new Thumbnail(0, 0, buffer.Buffer, ui::Point(64, 64));
|
||||
|
||||
return thumb;
|
||||
return buffer;
|
||||
}
|
||||
Thumbnail * thumb = Render(tempSave, decorations, fire);
|
||||
VideoBuffer * thumb = Render(tempSave, decorations, fire);
|
||||
delete tempSave;
|
||||
return thumb;
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
#include "Singleton.h"
|
||||
|
||||
class GameSave;
|
||||
class Thumbnail;
|
||||
class VideoBuffer;
|
||||
class Graphics;
|
||||
class Simulation;
|
||||
class Renderer;
|
||||
@ -17,8 +17,8 @@ class SaveRenderer: public Singleton<SaveRenderer> {
|
||||
Renderer * ren;
|
||||
public:
|
||||
SaveRenderer();
|
||||
Thumbnail * Render(GameSave * save, bool decorations = true, bool fire = true);
|
||||
Thumbnail * Render(unsigned char * saveData, int saveDataSize, bool decorations = true, bool fire = true);
|
||||
VideoBuffer * Render(GameSave * save, bool decorations = true, bool fire = true);
|
||||
VideoBuffer * Render(unsigned char * saveData, int saveDataSize, bool decorations = true, bool fire = true);
|
||||
virtual ~SaveRenderer();
|
||||
|
||||
private:
|
||||
|
Loading…
Reference in New Issue
Block a user