2014-06-05 15:12:49 +00:00
|
|
|
#include "Canvas.h"
|
|
|
|
|
|
|
|
#include <cassert>
|
|
|
|
|
2014-06-10 13:13:16 +00:00
|
|
|
#include "CanvasPortion.h"
|
|
|
|
#include "CanvasPreview.h"
|
|
|
|
|
2014-06-05 15:12:49 +00:00
|
|
|
Canvas::Canvas()
|
|
|
|
{
|
|
|
|
horizontal_portion_count = 1;
|
|
|
|
vertical_portion_count = 1;
|
|
|
|
width = 1;
|
|
|
|
height = 1;
|
|
|
|
portions.push_back(new CanvasPortion());
|
2014-06-10 13:13:16 +00:00
|
|
|
|
2014-06-12 15:45:59 +00:00
|
|
|
preview = new CanvasPreview;
|
2014-06-05 15:12:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Canvas::~Canvas()
|
|
|
|
{
|
|
|
|
for (auto portion: portions)
|
|
|
|
{
|
|
|
|
delete portion;
|
|
|
|
}
|
2014-06-10 13:13:16 +00:00
|
|
|
delete preview;
|
2014-06-05 15:12:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Canvas::setSize(int width, int height)
|
|
|
|
{
|
2014-06-12 15:45:59 +00:00
|
|
|
horizontal_portion_count = 1 + (width - 1) / 400;
|
|
|
|
vertical_portion_count = 1 + (height - 1) / 400;
|
2014-06-05 15:12:49 +00:00
|
|
|
|
|
|
|
int portion_width = width / horizontal_portion_count;
|
|
|
|
int portion_height = height / vertical_portion_count;
|
|
|
|
|
|
|
|
for (auto portion: portions)
|
|
|
|
{
|
|
|
|
delete portion;
|
|
|
|
}
|
|
|
|
portions.clear();
|
|
|
|
|
|
|
|
int done_width = 0;
|
|
|
|
int done_height = 0;
|
|
|
|
|
|
|
|
for (int y = 0; y < vertical_portion_count; y++)
|
|
|
|
{
|
|
|
|
done_width = 0;
|
|
|
|
for (int x = 0; x < horizontal_portion_count; x++)
|
|
|
|
{
|
2014-06-12 15:45:59 +00:00
|
|
|
CanvasPortion *portion = new CanvasPortion(preview);
|
2014-06-05 15:12:49 +00:00
|
|
|
|
|
|
|
portion->setSize((x == horizontal_portion_count - 1) ? width - done_width : portion_width,
|
2014-08-18 15:33:15 +00:00
|
|
|
(y == vertical_portion_count - 1) ? height - done_height : portion_height,
|
|
|
|
done_width,
|
|
|
|
done_height);
|
2014-06-05 15:12:49 +00:00
|
|
|
|
|
|
|
done_width += portion->getWidth();
|
|
|
|
if (x == horizontal_portion_count - 1)
|
|
|
|
{
|
|
|
|
done_height += portion->getHeight();
|
|
|
|
}
|
|
|
|
|
|
|
|
portions.push_back(portion);
|
|
|
|
}
|
|
|
|
assert(done_width == width);
|
|
|
|
}
|
|
|
|
assert(done_height == height);
|
|
|
|
|
|
|
|
this->width = width;
|
|
|
|
this->height = height;
|
2014-06-10 13:13:16 +00:00
|
|
|
|
2014-08-18 15:16:17 +00:00
|
|
|
// Smaller preview
|
2014-08-19 09:25:27 +00:00
|
|
|
while (width > 1000 or height > 700)
|
2014-08-18 15:16:17 +00:00
|
|
|
{
|
|
|
|
width = width / 2;
|
|
|
|
height = height / 2;
|
|
|
|
}
|
|
|
|
preview->setSize(this->width, this->height, width, height);
|
2014-06-05 15:12:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CanvasPortion *Canvas::at(int x, int y) const
|
|
|
|
{
|
|
|
|
assert(x >= 0 && x < horizontal_portion_count);
|
|
|
|
assert(y >= 0 && y < vertical_portion_count);
|
|
|
|
|
|
|
|
return portions[y * horizontal_portion_count + x];
|
|
|
|
}
|