From f0e064744bfad38a12298a3ad3314710e15b9b0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bend=C3=ADk?= Date: Sat, 1 Sep 2012 16:17:58 +0200 Subject: [PATCH] Small refactoring. --- PixelAttributes.cpp | 17 +++++++++-------- PixelAttributes.h | 2 +- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/PixelAttributes.cpp b/PixelAttributes.cpp index 1aaff10..6eda50e 100644 --- a/PixelAttributes.cpp +++ b/PixelAttributes.cpp @@ -16,7 +16,7 @@ using namespace std; PixelAttributes::PixelAttributes(): m_width(0) { - for (size_t i = 0; i < BlockCount; ++i) { + for (size_t i = 0; i < LineCount; ++i) { m_pixelAttributes[i] = 0; } } @@ -29,23 +29,24 @@ PixelAttributes::~PixelAttributes() void PixelAttributes::setWidth(int width) { freeAttributes(); - m_width = width; - for (size_t i = 0; i < BlockCount; ++i) { - m_pixelAttributes[i] = new PixelAttribute[m_width + 1]; + m_width = width + 1; // 1px gradient calculation + for (size_t i = 0; i < LineCount; ++i) { + m_pixelAttributes[i] = new PixelAttribute[m_width]; } } void PixelAttributes::scroll() { - memcpy(m_pixelAttributes[FirstLine], m_pixelAttributes[LastLine], (m_width + 1) * sizeof(PixelAttribute)); - for (size_t i = 1; i < BlockCount - 1; ++i) { - memcpy(m_pixelAttributes[i], m_pixelAttributes[EmptyLine], (m_width + 1) * sizeof(PixelAttribute)); + size_t lineLength = m_width * sizeof(PixelAttribute); + memcpy(m_pixelAttributes[FirstLine], m_pixelAttributes[LastLine], lineLength); + for (size_t i = 1; i < LineCount - 1; ++i) { + memcpy(m_pixelAttributes[i], m_pixelAttributes[EmptyLine], lineLength); } } void PixelAttributes::freeAttributes() { - for (size_t i = 0; i < BlockCount; ++i) { + for (size_t i = 0; i < LineCount; ++i) { if (m_pixelAttributes[i] != 0) { delete[] m_pixelAttributes[i]; m_pixelAttributes[i] = 0; diff --git a/PixelAttributes.h b/PixelAttributes.h index cb19c00..1e84215 100644 --- a/PixelAttributes.h +++ b/PixelAttributes.h @@ -38,7 +38,7 @@ private: FirstLine = 0, LastLine = BLOCK_SIZE, EmptyLine = BLOCK_SIZE + 1, - BlockCount = BLOCK_SIZE + 2 + LineCount = BLOCK_SIZE + 2 }; PixelAttribute *m_pixelAttributes[BLOCK_SIZE + 2]; // 1px gradient + empty int m_width;