summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2012-04-03 13:07:39 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2012-04-03 13:07:39 (GMT)
commit73c5082cbcdd3a986765723bd4182e45386ce766 (patch)
tree99a0040636c9700a893044ebc36d949fa1da5873 /src
parentefddc12e5d2aadc5eee1927245ad38b9dee89aed (diff)
downloadpowder-73c5082cbcdd3a986765723bd4182e45386ce766.zip
powder-73c5082cbcdd3a986765723bd4182e45386ce766.tar.gz
Super, megaheavyweight thumbnail renderer
Diffstat (limited to 'src')
-rw-r--r--src/Graphics.cpp34
-rw-r--r--src/game/GameView.cpp4
-rw-r--r--src/interface/SaveButton.cpp44
-rw-r--r--src/search/Thumbnail.cpp81
-rw-r--r--src/search/Thumbnail.h37
-rw-r--r--src/simulation/SaveLoader.cpp51
-rw-r--r--src/simulation/SaveLoader.h16
-rw-r--r--src/simulation/Simulation.cpp8
-rw-r--r--src/stamps/StampsModel.cpp6
-rw-r--r--src/stamps/StampsView.cpp3
10 files changed, 193 insertions, 91 deletions
diff --git a/src/Graphics.cpp b/src/Graphics.cpp
index 9d9c36b..ad3696d 100644
--- a/src/Graphics.cpp
+++ b/src/Graphics.cpp
@@ -2388,25 +2388,29 @@ void Graphics::AttachSDLSurface(SDL_Surface * surface)
void Graphics::Blit()
{
- pixel * dst;
- pixel * src = vid;
- int j, x = 0, y = 0, w = XRES+BARSIZE, h = YRES+MENUSIZE, pitch = XRES+BARSIZE;
- if (SDL_MUSTLOCK(sdl_scrn))
- if (SDL_LockSurface(sdl_scrn)<0)
- return;
- dst=(pixel *)sdl_scrn->pixels+y*sdl_scrn->pitch/PIXELSIZE+x;
- for (j=0; j<h; j++)
+ if(sdl_scrn)
{
- memcpy(dst, src, w*PIXELSIZE);
- dst+=sdl_scrn->pitch/PIXELSIZE;
- src+=pitch;
+ pixel * dst;
+ pixel * src = vid;
+ int j, x = 0, y = 0, w = XRES+BARSIZE, h = YRES+MENUSIZE, pitch = XRES+BARSIZE;
+ if (SDL_MUSTLOCK(sdl_scrn))
+ if (SDL_LockSurface(sdl_scrn)<0)
+ return;
+ dst=(pixel *)sdl_scrn->pixels+y*sdl_scrn->pitch/PIXELSIZE+x;
+ for (j=0; j<h; j++)
+ {
+ memcpy(dst, src, w*PIXELSIZE);
+ dst+=sdl_scrn->pitch/PIXELSIZE;
+ src+=pitch;
+ }
+ if (SDL_MUSTLOCK(sdl_scrn))
+ SDL_UnlockSurface(sdl_scrn);
+ SDL_UpdateRect(sdl_scrn,0,0,0,0);
}
- if (SDL_MUSTLOCK(sdl_scrn))
- SDL_UnlockSurface(sdl_scrn);
- SDL_UpdateRect(sdl_scrn,0,0,0,0);
}
-Graphics::Graphics()
+Graphics::Graphics():
+ sdl_scrn(NULL)
{
vid = (pixel *)malloc(PIXELSIZE * ((XRES+BARSIZE) * (YRES+MENUSIZE)));
}
diff --git a/src/game/GameView.cpp b/src/game/GameView.cpp
index 8c1c14a..532bcea 100644
--- a/src/game/GameView.cpp
+++ b/src/game/GameView.cpp
@@ -747,7 +747,7 @@ void GameView::NotifyClipboardChanged(GameModel * sender)
delete clipboardThumb;
if(sender->GetClipboard())
{
- clipboardThumb = new Thumbnail(0, 0, (pixel*)malloc((256*256)*PIXELSIZE), ui::Point(256, 256));
+ clipboardThumb = new Thumbnail(sender->GetClipboard());//new Thumbnail(0, 0, (pixel*)malloc((256*256)*PIXELSIZE), ui::Point(256, 256));
}
else
clipboardThumb = NULL;
@@ -760,7 +760,7 @@ void GameView::NotifyStampChanged(GameModel * sender)
delete stampThumb;
if(sender->GetStamp())
{
- stampThumb = new Thumbnail(0, 0, (pixel*)malloc((256*256)*PIXELSIZE), ui::Point(256, 256));
+ stampThumb = new Thumbnail(sender->GetStamp());//new Thumbnail(0, 0, (pixel*)malloc((256*256)*PIXELSIZE), ui::Point(256, 256));
}
else
stampThumb = NULL;
diff --git a/src/interface/SaveButton.cpp b/src/interface/SaveButton.cpp
index 775e38b..6b0e9cf 100644
--- a/src/interface/SaveButton.cpp
+++ b/src/interface/SaveButton.cpp
@@ -57,26 +57,30 @@ void SaveButton::Tick(float dt)
if(tempThumb)
{
thumbnail = new Thumbnail(*tempThumb); //Store a local copy of the thumbnail
- if(thumbnail->Data)
- {
- if(thumbnail->Size.Y > (Size.Y-25))
- {
- scaleFactorY = ((float)(Size.Y-25))/((float)thumbnail->Size.Y);
- }
- if(thumbnail->Size.X > Size.X-3)
- {
- scaleFactorX = ((float)Size.X-3)/((float)thumbnail->Size.X);
- }
- if(scaleFactorY < 1.0f || scaleFactorX < 1.0f)
- {
- float scaleFactor = scaleFactorY < scaleFactorX ? scaleFactorY : scaleFactorX;
- pixel * thumbData = thumbnail->Data;
- thumbnail->Data = Graphics::resample_img(thumbData, thumbnail->Size.X, thumbnail->Size.Y, thumbnail->Size.X * scaleFactor, thumbnail->Size.Y * scaleFactor);
- thumbnail->Size.X *= scaleFactor;
- thumbnail->Size.Y *= scaleFactor;
- free(thumbData);
- }
- }
+ }
+ }
+ else
+ {
+ thumbnail = new Thumbnail(save);
+ }
+ if(thumbnail && thumbnail->Data)
+ {
+ if(thumbnail->Size.Y > (Size.Y-25))
+ {
+ scaleFactorY = ((float)(Size.Y-25))/((float)thumbnail->Size.Y);
+ }
+ if(thumbnail->Size.X > Size.X-3)
+ {
+ scaleFactorX = ((float)Size.X-3)/((float)thumbnail->Size.X);
+ }
+ if(scaleFactorY < 1.0f || scaleFactorX < 1.0f)
+ {
+ float scaleFactor = scaleFactorY < scaleFactorX ? scaleFactorY : scaleFactorX;
+ pixel * thumbData = thumbnail->Data;
+ thumbnail->Data = Graphics::resample_img(thumbData, thumbnail->Size.X, thumbnail->Size.Y, thumbnail->Size.X * scaleFactor, thumbnail->Size.Y * scaleFactor);
+ thumbnail->Size.X *= scaleFactor;
+ thumbnail->Size.Y *= scaleFactor;
+ free(thumbData);
}
}
}
diff --git a/src/search/Thumbnail.cpp b/src/search/Thumbnail.cpp
new file mode 100644
index 0000000..2fcd34a
--- /dev/null
+++ b/src/search/Thumbnail.cpp
@@ -0,0 +1,81 @@
+/*
+ * Thumbnail.cpp
+ *
+ * Created on: Apr 3, 2012
+ * Author: Simon
+ */
+
+#include "Thumbnail.h"
+#include "simulation/Simulation.h"
+#include "simulation/SaveLoader.h"
+#include "Renderer.h"
+
+Thumbnail::Thumbnail(const Thumbnail & thumb):
+ ID(thumb.ID),
+ Datestamp(thumb.Datestamp),
+ Data(thumb.Data),
+ Size(thumb.Size)
+{
+ //Ensure the actual thumbnail data is copied
+ if(thumb.Data)
+ {
+ Data = (pixel *)malloc((thumb.Size.X*thumb.Size.Y) * PIXELSIZE);
+ memcpy(Data, thumb.Data, (thumb.Size.X*thumb.Size.Y) * PIXELSIZE);
+ }
+ else
+ {
+ Data = NULL;
+ }
+}
+
+Thumbnail::Thumbnail(int _id, int _datestamp, pixel * _data, ui::Point _size):
+ ID(_id),
+ Datestamp(_datestamp),
+ Data(_data),
+ Size(_size)
+{
+}
+
+Thumbnail::Thumbnail(Save * save):
+ ID(0),
+ Datestamp(0),
+ Data(NULL),
+ Size(XRES+BARSIZE, YRES+MENUSIZE)
+{
+ Graphics * g = new Graphics();
+ Simulation * sim = new Simulation();
+ Renderer * ren = new Renderer(g, sim);
+ sim->Load(save->GetData(), save->GetDataLength());
+ ren->render_parts();
+
+ int width, height;
+
+ pixel * dst;
+ pixel * src = g->vid;
+
+ if(SaveLoader::Info(save->GetData(), save->GetDataLength(), width, height))
+ goto fail;
+
+ dst = Data = (pixel *)malloc(PIXELSIZE * ((width*CELL)*(height*CELL)));
+
+ for(int i = 0; i < height*CELL; i++)
+ {
+ memcpy(dst, src, (width*CELL)*PIXELSIZE);
+ dst+=(width*CELL);///PIXELSIZE;
+ src+=XRES+BARSIZE;
+ }
+
+ Size = ui::Point(width*CELL, height*CELL);
+fail:
+ delete ren;
+ delete sim;
+ delete g;
+}
+
+Thumbnail::~Thumbnail()
+{
+ if(Data)
+ {
+ free(Data);
+ }
+}
diff --git a/src/search/Thumbnail.h b/src/search/Thumbnail.h
index 6311a23..3ed9dd2 100644
--- a/src/search/Thumbnail.h
+++ b/src/search/Thumbnail.h
@@ -4,43 +4,18 @@
#include <iostream>
#include "Graphics.h"
#include "interface/Point.h"
+#include "Save.h"
class Thumbnail
{
public:
- Thumbnail(const Thumbnail & thumb):
- ID(thumb.ID),
- Datestamp(thumb.Datestamp),
- Data(thumb.Data),
- Size(thumb.Size)
- {
- //Ensure the actual thumbnail data is copied
- if(thumb.Data)
- {
- Data = (pixel *)malloc((thumb.Size.X*thumb.Size.Y) * PIXELSIZE);
- memcpy(Data, thumb.Data, (thumb.Size.X*thumb.Size.Y) * PIXELSIZE);
- }
- else
- {
- Data = NULL;
- }
- }
+ Thumbnail(const Thumbnail & thumb);
- Thumbnail(int _id, int _datestamp, pixel * _data, ui::Point _size):
- ID(_id),
- Datestamp(_datestamp),
- Data(_data),
- Size(_size)
- {
- }
+ Thumbnail(int _id, int _datestamp, pixel * _data, ui::Point _size);
- ~Thumbnail()
- {
- if(Data)
- {
- free(Data);
- }
- }
+ Thumbnail(Save * save);
+
+ ~Thumbnail();
int ID, Datestamp;
ui::Point Size;
diff --git a/src/simulation/SaveLoader.cpp b/src/simulation/SaveLoader.cpp
index 97ab45e..2683a6f 100644
--- a/src/simulation/SaveLoader.cpp
+++ b/src/simulation/SaveLoader.cpp
@@ -10,7 +10,7 @@
//!TODO: enum for LoadSave return
-int SaveLoader::LoadSave(unsigned char * data, int dataLength, Simulation * sim, bool replace, int x, int y)
+int SaveLoader::Info(unsigned char * data, int dataLength, int & width, int & height)
{
unsigned char * saveData = data;
if (dataLength<16)
@@ -19,34 +19,65 @@ int SaveLoader::LoadSave(unsigned char * data, int dataLength, Simulation * sim,
}
if(saveData[0] == 'O' && saveData[1] == 'P' && saveData[2] == 'S')
{
- return OPSLoadSave(data, dataLength, sim);
+ return OPSInfo(data, dataLength, width, height);
}
else if((saveData[0]==0x66 && saveData[1]==0x75 && saveData[2]==0x43) || (saveData[0]==0x50 && saveData[1]==0x53 && saveData[2]==0x76))
{
- return PSVLoadSave(data, dataLength, sim, replace, x, y);
+ return PSVInfo(data, dataLength, width, height);
}
return 1;
}
-unsigned char * SaveLoader::BuildSave(int & dataLength, Simulation * sim, int orig_x0, int orig_y0, int orig_w, int orig_h)
+int SaveLoader::Load(unsigned char * data, int dataLength, Simulation * sim, bool replace, int x, int y)
{
- unsigned char * temp = OPSBuildSave(dataLength, sim, orig_x0, orig_y0, orig_w, orig_h);
+ unsigned char * saveData = data;
+ if (dataLength<16)
+ {
+ return 1;
+ }
+ if(saveData[0] == 'O' && saveData[1] == 'P' && saveData[2] == 'S')
+ {
+ return OPSLoad(data, dataLength, sim);
+ }
+ else if((saveData[0]==0x66 && saveData[1]==0x75 && saveData[2]==0x43) || (saveData[0]==0x50 && saveData[1]==0x53 && saveData[2]==0x76))
+ {
+ return PSVLoad(data, dataLength, sim, replace, x, y);
+ }
+ return 1;
+}
+
+unsigned char * SaveLoader::Build(int & dataLength, Simulation * sim, int orig_x0, int orig_y0, int orig_w, int orig_h)
+{
+ unsigned char * temp = OPSBuild(dataLength, sim, orig_x0, orig_y0, orig_w, orig_h);
if(!temp)
- temp = PSVBuildSave(dataLength, sim, orig_x0, orig_y0, orig_w, orig_h);
+ temp = PSVBuild(dataLength, sim, orig_x0, orig_y0, orig_w, orig_h);
return temp;
}
-int SaveLoader::OPSLoadSave(unsigned char * data, int dataLength, Simulation * sim)
+int SaveLoader::OPSInfo(unsigned char * data, int dataLength, int & width, int & height)
+{
+ return 2;
+}
+
+
+int SaveLoader::OPSLoad(unsigned char * data, int dataLength, Simulation * sim)
+{
+ return 2;
+}
+
+unsigned char * SaveLoader::OPSBuild(int & dataLength, Simulation * sim, int orig_x0, int orig_y0, int orig_w, int orig_h)
{
return 0;
}
-unsigned char * SaveLoader::OPSBuildSave(int & dataLength, Simulation * sim, int orig_x0, int orig_y0, int orig_w, int orig_h)
+int SaveLoader::PSVInfo(unsigned char * data, int dataLength, int & width, int & height)
{
+ width = data[6];
+ height = data[7];
return 0;
}
-int SaveLoader::PSVLoadSave(unsigned char * data, int dataLength, Simulation * sim, bool replace, int x0, int y0)
+int SaveLoader::PSVLoad(unsigned char * data, int dataLength, Simulation * sim, bool replace, int x0, int y0)
{
unsigned char * d = NULL, * c = data;
int q,i,j,k,x,y,p=0,*m=NULL, ver, pty, ty, legacy_beta=0, tempGrav = 0;
@@ -640,7 +671,7 @@ corrupt:
return 1;
}
-unsigned char * SaveLoader::PSVBuildSave(int & dataLength, Simulation * sim, int orig_x0, int orig_y0, int orig_w, int orig_h)
+unsigned char * SaveLoader::PSVBuild(int & dataLength, Simulation * sim, int orig_x0, int orig_y0, int orig_w, int orig_h)
{
unsigned char *d = (unsigned char*)calloc(1,3*(XRES/CELL)*(YRES/CELL)+(XRES*YRES)*15+MAXSIGNS*262), *c;
int i,j,x,y,p=0,*m=(int*)calloc(XRES*YRES, sizeof(int));
diff --git a/src/simulation/SaveLoader.h b/src/simulation/SaveLoader.h
index 1fb2143..2e92817 100644
--- a/src/simulation/SaveLoader.h
+++ b/src/simulation/SaveLoader.h
@@ -12,12 +12,16 @@
class SaveLoader {
public:
- static int LoadSave(unsigned char * data, int dataLength, Simulation * sim, bool replace, int x, int y);
- static unsigned char * BuildSave(int & dataLength, Simulation * sim, int orig_x0, int orig_y0, int orig_w, int orig_h);
- static int OPSLoadSave(unsigned char * data, int dataLength, Simulation * sim);
- static unsigned char * OPSBuildSave(int & dataLength, Simulation * sim, int orig_x0, int orig_y0, int orig_w, int orig_h);
- static int PSVLoadSave(unsigned char * data, int dataLength, Simulation * sim, bool replace, int x, int y);
- static unsigned char * PSVBuildSave(int & dataLength, Simulation * sim, int orig_x0, int orig_y0, int orig_w, int orig_h);
+ static int Info(unsigned char * data, int dataLength, int & width, int & height);
+ static int Load(unsigned char * data, int dataLength, Simulation * sim, bool replace, int x, int y);
+ static unsigned char * Build(int & dataLength, Simulation * sim, int orig_x0, int orig_y0, int orig_w, int orig_h);
+private:
+ static int OPSInfo(unsigned char * data, int dataLength, int & width, int & height);
+ static int OPSLoad(unsigned char * data, int dataLength, Simulation * sim);
+ static unsigned char * OPSBuild(int & dataLength, Simulation * sim, int orig_x0, int orig_y0, int orig_w, int orig_h);
+ static int PSVInfo(unsigned char * data, int dataLength, int & width, int & height);
+ static int PSVLoad(unsigned char * data, int dataLength, Simulation * sim, bool replace, int x, int y);
+ static unsigned char * PSVBuild(int & dataLength, Simulation * sim, int orig_x0, int orig_y0, int orig_w, int orig_h);
};
#endif /* SAVELOADER_H_ */
diff --git a/src/simulation/Simulation.cpp b/src/simulation/Simulation.cpp
index ec17454..7b1dca8 100644
--- a/src/simulation/Simulation.cpp
+++ b/src/simulation/Simulation.cpp
@@ -10,22 +10,22 @@
int Simulation::Load(unsigned char * data, int dataLength)
{
- return SaveLoader::LoadSave(data, dataLength, this, true, 0, 0);
+ return SaveLoader::Load(data, dataLength, this, true, 0, 0);
}
int Simulation::Load(int x, int y, unsigned char * data, int dataLength)
{
- return SaveLoader::LoadSave(data, dataLength, this, false, x, y);
+ return SaveLoader::Load(data, dataLength, this, false, x, y);
}
unsigned char * Simulation::Save(int & dataLength)
{
- return SaveLoader::BuildSave(dataLength, this, 0, 0, XRES, YRES);
+ return SaveLoader::Build(dataLength, this, 0, 0, XRES, YRES);
}
unsigned char * Simulation::Save(int x1, int y1, int x2, int y2, int & dataLength)
{
- return SaveLoader::BuildSave(dataLength, this, x1, y1, x2-x1, y2-y1);
+ return SaveLoader::Build(dataLength, this, x1, y1, x2-x1, y2-y1);
}
void Simulation::clear_area(int area_x, int area_y, int area_w, int area_h)
diff --git a/src/stamps/StampsModel.cpp b/src/stamps/StampsModel.cpp
index f76d4f1..b679d13 100644
--- a/src/stamps/StampsModel.cpp
+++ b/src/stamps/StampsModel.cpp
@@ -11,7 +11,8 @@
#include "StampsModelException.h"
StampsModel::StampsModel():
- stamp(NULL)
+ stamp(NULL),
+ currentPage(1)
{
// TODO Auto-generated constructor stub
stampIDs = Client::Ref().GetStamps();
@@ -27,6 +28,7 @@ void StampsModel::AddObserver(StampsView * observer)
{
observers.push_back(observer);
observer->NotifyStampsListChanged(this);
+ observer->NotifyPageChanged(this);
}
void StampsModel::notifyStampsListChanged()
@@ -61,6 +63,8 @@ void StampsModel::UpdateStampsList(int pageNumber)
{
std::vector<Save*> tempStampsList = stampsList;
stampsList.clear();
+ currentPage = pageNumber;
+ notifyPageChanged();
/*notifyStampsListChanged();
for(int i = 0; i < tempStampsList.size(); i++)
{
diff --git a/src/stamps/StampsView.cpp b/src/stamps/StampsView.cpp
index ddb3fb4..bddfb4f 100644
--- a/src/stamps/StampsView.cpp
+++ b/src/stamps/StampsView.cpp
@@ -87,13 +87,12 @@ void StampsView::NotifyStampsListChanged(StampsModel * sender)
int buttonAreaWidth, buttonAreaHeight, buttonXOffset, buttonYOffset;
vector<Save*> saves = sender->GetStampsList();
- Client::Ref().ClearThumbnailRequests();
for(i = 0; i < stampButtons.size(); i++)
{
RemoveComponent(stampButtons[i]);
delete stampButtons[i];
}
-
+ stampButtons.clear();
buttonXOffset = 0;
buttonYOffset = 50;
buttonAreaWidth = Size.X;