File: SectionHeader.cpp

package info (click to toggle)
scummvm 2.9.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 450,268 kB
  • sloc: cpp: 4,297,604; asm: 28,322; python: 12,901; sh: 11,219; java: 8,477; xml: 7,843; perl: 2,633; ansic: 2,465; yacc: 1,670; javascript: 1,020; makefile: 933; lex: 578; awk: 275; objc: 82; sed: 11; php: 1
file content (94 lines) | stat: -rw-r--r-- 2,964 bytes parent folder | download | duplicates (2)
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
/* ScummVM - Graphic Adventure Engine
 *
 * ScummVM is the legal property of its developers, whose names
 * are too numerous to list here. Please refer to the COPYRIGHT
 * file distributed with this source distribution.
 *
 * This program 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 3 of the License, or
 * (at your option) any later version.
 *
 * This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

/*
 * This code is based on the CRAB engine
 *
 * Copyright (c) Arvind Raja Yadav
 *
 * Licensed under MIT
 *
 */

#include "graphics/managed_surface.h"
#include "crab/crab.h"
#include "crab/ui/SectionHeader.h"

namespace Crab {

using namespace pyrodactyl::ui;
using namespace pyrodactyl::text;
using namespace pyrodactyl::image;

void SectionHeader::load(rapidxml::xml_node<char> *node) {

	if (TextData::load(node, nullptr, false)) {
		loadStr(_text, "text", node);
		_text.insertChar(' ', 0);
		_text += " ";

		loadImgKey(_img, "img", node);

		loadBool(_drawL, "left", node);
		loadBool(_drawR, "right", node);

		Graphics::ManagedSurface *surf = g_engine->_textManager->renderTextBlended(_font, _text, _col);

		if (_align == ALIGN_CENTER) {
			_left.x = x - surf->w / 2 - g_engine->_imageManager->getTexture(_img).w();
			_left.y = y - surf->h / 2 + g_engine->_imageManager->getTexture(_img).h() / 2;

			_right.x = x + surf->w / 2;
			_right.y = y - surf->h / 2 + g_engine->_imageManager->getTexture(_img).h() / 2;
		} else if (_align == ALIGN_LEFT) {
			_left.x = x - g_engine->_imageManager->getTexture(_img).w();
			_left.y = y + surf->h / 2 - g_engine->_imageManager->getTexture(_img).h() / 2;

			_right.x = x + surf->w;
			_right.y = y + surf->h / 2 - g_engine->_imageManager->getTexture(_img).h() / 2;
		} else {
			_left.x = x - surf->w - g_engine->_imageManager->getTexture(_img).w();
			_left.y = y + surf->h / 2 - g_engine->_imageManager->getTexture(_img).h() / 2;

			_right.x = x;
			_right.y = y + surf->h / 2 - g_engine->_imageManager->getTexture(_img).h() / 2;
		}

		delete surf;
	}

}

void SectionHeader::draw(const int &xOffset, const int &yOffset) {
	draw(_text, xOffset, yOffset);
}

void SectionHeader::draw(const Common::String &str, const int &xOffset, const int &yOffset) {
	if (_drawL)
		g_engine->_imageManager->draw(_left.x + xOffset, _left.y + yOffset, _img);

	if (_drawR)
		g_engine->_imageManager->draw(_right.x + xOffset, _right.y + yOffset, _img, (Rect*)nullptr, FLIP_X);

	TextData::draw(str, xOffset, yOffset);
}

} // End of namespace Crab