minetestmapper/PixelAttributes.cpp

57 lines
1.2 KiB
C++
Raw 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
* =====================================================================
*/
2012-09-01 14:36:14 +02:00
#include <cstdlib>
#include <cstring>
2012-08-25 13:19:58 +02:00
#include "PixelAttributes.h"
2012-08-25 13:27:40 +02:00
using namespace std;
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) {
2012-09-01 14:36:14 +02:00
m_pixelAttributes[i] = 0;
}
}
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()
{
2012-09-01 16:17:58 +02:00
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);
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) {
2012-09-01 14:36:14 +02:00
if (m_pixelAttributes[i] != 0) {
delete[] m_pixelAttributes[i];
m_pixelAttributes[i] = 0;
}
2012-08-25 13:27:40 +02:00
}
2012-08-25 13:19:58 +02:00
}