aboutsummaryrefslogtreecommitdiff
path: root/engines/sword25/gfx/panel.cpp
blob: a9deea76eac25249a71eea428a36fe66f898a2ed (plain)
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
// -----------------------------------------------------------------------------
// This file is part of Broken Sword 2.5
// Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsd�rfer
//
// Broken Sword 2.5 is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// Broken Sword 2.5 is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Broken Sword 2.5; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
// -----------------------------------------------------------------------------

// -----------------------------------------------------------------------------
// Includes
// -----------------------------------------------------------------------------

#include "sword25/gfx/panel.h"

#include "sword25/kernel/inputpersistenceblock.h"
#include "sword25/kernel/outputpersistenceblock.h"
#include "sword25/gfx/graphicengine.h"
#include "sword25/image/image.h"

// -----------------------------------------------------------------------------

#define BS_LOG_PREFIX "PANEL"

// -----------------------------------------------------------------------------
// Construction/Destruction
// -----------------------------------------------------------------------------

BS_Panel::BS_Panel(BS_RenderObjectPtr<BS_RenderObject> ParentPtr, int Width, int Height, unsigned int Color) :
	BS_RenderObject(ParentPtr, BS_RenderObject::TYPE_PANEL),
	m_Color(Color)
{
	m_InitSuccess = false;

	m_Width = Width;
	m_Height = Height;

	if (m_Width < 0)
	{
		BS_LOG_ERRORLN("Tried to initialise a panel with an invalid width (%d).", m_Width);
		return;
	}

	if (m_Height < 0)
	{
		BS_LOG_ERRORLN("Tried to initialise a panel with an invalid height (%d).", m_Height);
		return;
	}

	m_InitSuccess = true;
}

// -----------------------------------------------------------------------------

BS_Panel::BS_Panel(BS_InputPersistenceBlock & Reader, BS_RenderObjectPtr<BS_RenderObject> ParentPtr, unsigned int Handle) :
	BS_RenderObject(ParentPtr, BS_RenderObject::TYPE_PANEL, Handle)
{
	m_InitSuccess = Unpersist(Reader);
}

// -----------------------------------------------------------------------------
	
BS_Panel::~BS_Panel()
{
}

// -----------------------------------------------------------------------------
// Rendern
// -----------------------------------------------------------------------------

bool BS_Panel::DoRender()
{
	// Falls der Alphawert 0 ist, ist das Panel komplett durchsichtig und es muss nichts gezeichnet werden.
	if (m_Color >> 24 == 0) return true;

	BS_GraphicEngine * GfxPtr = static_cast<BS_GraphicEngine *>(BS_Kernel::GetInstance()->GetService("gfx"));
	BS_ASSERT(GfxPtr);

	return GfxPtr->Fill(&m_BBox, m_Color);
}

// -----------------------------------------------------------------------------
// Persistenz
// -----------------------------------------------------------------------------

bool BS_Panel::Persist(BS_OutputPersistenceBlock & Writer)
{
	bool Result = true;

	Result &= BS_RenderObject::Persist(Writer);
	Writer.Write(m_Color);

	Result &= BS_RenderObject::PersistChildren(Writer);

	return Result;
}

// -----------------------------------------------------------------------------

bool BS_Panel::Unpersist(BS_InputPersistenceBlock & Reader)
{
	bool Result = true;

	Result &= BS_RenderObject::Unpersist(Reader);

	unsigned int Color;
	Reader.Read(Color);
	SetColor(Color);

	Result &= BS_RenderObject::UnpersistChildren(Reader);

	return Reader.IsGood() && Result;
}