File: PixelAttributes.cpp

package info (click to toggle)
minetestmapper 20200328-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 252 kB
  • sloc: cpp: 2,454; sh: 65; ansic: 32; makefile: 9
file content (53 lines) | stat: -rw-r--r-- 1,239 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
 * =====================================================================
 *        Version:  1.0
 *        Created:  25.08.2012 10:55:27
 *         Author:  Miroslav Bendík
 *        Company:  LinuxOS.sk
 * =====================================================================
 */

#include "PixelAttributes.h"
#include <cstring>

PixelAttributes::PixelAttributes():
	m_width(0)
{
	for (size_t i = 0; i < LineCount; ++i) {
		m_pixelAttributes[i] = nullptr;
	}
}

PixelAttributes::~PixelAttributes()
{
	freeAttributes();
}

void PixelAttributes::setWidth(int width)
{
	freeAttributes();
	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()
{
	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 < LineCount; ++i) {
		if (m_pixelAttributes[i] != nullptr) {
			delete[] m_pixelAttributes[i];
			m_pixelAttributes[i] = nullptr;
		}
	}
}