minetestmapper/PixelAttributes.cpp

54 lines
1.2 KiB
C++
Raw Permalink Normal View History

2012-08-25 13:19:58 +02:00
/*
* =====================================================================
* Version: 1.0
* Created: 25.08.2012 10:55:27
* Author: Miroslav Bendík
* Company: LinuxOS.sk
* =====================================================================
*/
#include "PixelAttributes.h"
2020-03-27 12:45:31 +01:00
#include <cstring>
2012-08-25 13:19:58 +02:00
2012-09-01 14:36:14 +02:00
PixelAttributes::PixelAttributes():
m_width(0)
2012-08-25 13:19:58 +02:00
{
2012-09-01 16:17:58 +02:00
for (size_t i = 0; i < LineCount; ++i) {
2020-03-26 23:07:27 +01:00
m_pixelAttributes[i] = nullptr;
2012-09-01 14:36:14 +02:00
}
}
PixelAttributes::~PixelAttributes()
{
freeAttributes();
2012-08-25 13:19:58 +02:00
}
void PixelAttributes::setWidth(int width)
{
2012-09-01 14:36:14 +02:00
freeAttributes();
2012-09-01 16:17:58 +02:00
m_width = width + 1; // 1px gradient calculation
for (size_t i = 0; i < LineCount; ++i) {
m_pixelAttributes[i] = new PixelAttribute[m_width];
2012-08-25 13:19:58 +02:00
}
}
void PixelAttributes::scroll()
{
2020-03-27 12:45:31 +01:00
size_t lineLength = m_width * sizeof(PixelAttribute);
memcpy(m_pixelAttributes[FirstLine], m_pixelAttributes[LastLine], lineLength);
2012-09-01 16:17:58 +02:00
for (size_t i = 1; i < LineCount - 1; ++i) {
2020-03-27 12:45:31 +01:00
memcpy(m_pixelAttributes[i], m_pixelAttributes[EmptyLine], lineLength);
2012-09-01 14:36:14 +02:00
}
}
void PixelAttributes::freeAttributes()
{
2012-09-01 16:17:58 +02:00
for (size_t i = 0; i < LineCount; ++i) {
2020-03-26 23:07:27 +01:00
if (m_pixelAttributes[i] != nullptr) {
2012-09-01 14:36:14 +02:00
delete[] m_pixelAttributes[i];
2020-03-26 23:07:27 +01:00
m_pixelAttributes[i] = nullptr;
2012-09-01 14:36:14 +02:00
}
2012-08-25 13:27:40 +02:00
}
2012-08-25 13:19:58 +02:00
}