Small refactoring.

This commit is contained in:
Miroslav Bendík 2012-09-01 16:17:58 +02:00
parent 660b543491
commit f0e064744b
2 changed files with 10 additions and 9 deletions

@ -16,7 +16,7 @@ using namespace std;
PixelAttributes::PixelAttributes(): PixelAttributes::PixelAttributes():
m_width(0) m_width(0)
{ {
for (size_t i = 0; i < BlockCount; ++i) { for (size_t i = 0; i < LineCount; ++i) {
m_pixelAttributes[i] = 0; m_pixelAttributes[i] = 0;
} }
} }
@ -29,23 +29,24 @@ PixelAttributes::~PixelAttributes()
void PixelAttributes::setWidth(int width) void PixelAttributes::setWidth(int width)
{ {
freeAttributes(); freeAttributes();
m_width = width; m_width = width + 1; // 1px gradient calculation
for (size_t i = 0; i < BlockCount; ++i) { for (size_t i = 0; i < LineCount; ++i) {
m_pixelAttributes[i] = new PixelAttribute[m_width + 1]; m_pixelAttributes[i] = new PixelAttribute[m_width];
} }
} }
void PixelAttributes::scroll() void PixelAttributes::scroll()
{ {
memcpy(m_pixelAttributes[FirstLine], m_pixelAttributes[LastLine], (m_width + 1) * sizeof(PixelAttribute)); size_t lineLength = m_width * sizeof(PixelAttribute);
for (size_t i = 1; i < BlockCount - 1; ++i) { memcpy(m_pixelAttributes[FirstLine], m_pixelAttributes[LastLine], lineLength);
memcpy(m_pixelAttributes[i], m_pixelAttributes[EmptyLine], (m_width + 1) * sizeof(PixelAttribute)); for (size_t i = 1; i < LineCount - 1; ++i) {
memcpy(m_pixelAttributes[i], m_pixelAttributes[EmptyLine], lineLength);
} }
} }
void PixelAttributes::freeAttributes() void PixelAttributes::freeAttributes()
{ {
for (size_t i = 0; i < BlockCount; ++i) { for (size_t i = 0; i < LineCount; ++i) {
if (m_pixelAttributes[i] != 0) { if (m_pixelAttributes[i] != 0) {
delete[] m_pixelAttributes[i]; delete[] m_pixelAttributes[i];
m_pixelAttributes[i] = 0; m_pixelAttributes[i] = 0;

@ -38,7 +38,7 @@ private:
FirstLine = 0, FirstLine = 0,
LastLine = BLOCK_SIZE, LastLine = BLOCK_SIZE,
EmptyLine = BLOCK_SIZE + 1, EmptyLine = BLOCK_SIZE + 1,
BlockCount = BLOCK_SIZE + 2 LineCount = BLOCK_SIZE + 2
}; };
PixelAttribute *m_pixelAttributes[BLOCK_SIZE + 2]; // 1px gradient + empty PixelAttribute *m_pixelAttributes[BLOCK_SIZE + 2]; // 1px gradient + empty
int m_width; int m_width;