aboutsummaryrefslogtreecommitdiff
path: root/src/gui/guiButtonImage.cpp
blob: b507ffecee0dacaaad250882309f8f71b69f0b33 (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
/*
Minetest
Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#include "guiButtonImage.h"

#include "client/guiscalingfilter.h"
#include "debug.h"
#include "IGUIEnvironment.h"
#include "IGUIImage.h"
#include "IVideoDriver.h"
#include "StyleSpec.h"

using namespace irr;
using namespace gui;

GUIButtonImage::GUIButtonImage(gui::IGUIEnvironment *environment,
		gui::IGUIElement *parent, s32 id, core::rect<s32> rectangle,
		ISimpleTextureSource *tsrc, bool noclip)
	: GUIButton (environment, parent, id, rectangle, tsrc, noclip)
{
	m_image = Environment->addImage(
			core::rect<s32>(0,0,rectangle.getWidth(),rectangle.getHeight()), this);
	m_image->setScaleImage(isScalingImage());
	sendToBack(m_image);
}

void GUIButtonImage::setForegroundImage(video::ITexture *image)
{
	if (image == m_foreground_image)
		return;

	if (image != nullptr)
		image->grab();

	if (m_foreground_image != nullptr)
		m_foreground_image->drop();

	m_foreground_image = image;
	m_image->setImage(image);
}

//! Set element properties from a StyleSpec
void GUIButtonImage::setFromStyle(const StyleSpec& style)
{
	GUIButton::setFromStyle(style);

	video::IVideoDriver *driver = Environment->getVideoDriver();

	if (style.isNotDefault(StyleSpec::FGIMG)) {
		video::ITexture *texture = style.getTexture(StyleSpec::FGIMG,
				getTextureSource());

		setForegroundImage(guiScalingImageButton(driver, texture,
			AbsoluteRect.getWidth(), AbsoluteRect.getHeight()));
		setScaleImage(true);
	} else {
		setForegroundImage(nullptr);
	}
}

void GUIButtonImage::setScaleImage(bool scaleImage)
{
	GUIButton::setScaleImage(scaleImage);
	m_image->setScaleImage(scaleImage);
}

GUIButtonImage *GUIButtonImage::addButton(IGUIEnvironment *environment,
		const core::rect<s32> &rectangle, ISimpleTextureSource *tsrc,
		IGUIElement *parent, s32 id, const wchar_t *text,
		const wchar_t *tooltiptext)
{
	GUIButtonImage *button = new GUIButtonImage(environment,
			parent ? parent : environment->getRootGUIElement(), id, rectangle, tsrc);

	if (text)
		button->setText(text);

	if (tooltiptext)
		button->setToolTipText(tooltiptext);

	button->drop();
	return button;
}
opt">] = { {CONTENT_GRASS, 1}, {CONTENT_TREE, 4}, {CONTENT_LEAVES, 5}, {CONTENT_GRASS_FOOTSTEPS, 6}, {CONTENT_MESE, 7}, {CONTENT_MUD, 8}, {CONTENT_CLOUD, 10}, {CONTENT_COALSTONE, 11}, {CONTENT_WOOD, 12}, {CONTENT_SAND, 13}, {CONTENT_COBBLE, 18}, {CONTENT_STEEL, 19}, {CONTENT_GLASS, 20}, {CONTENT_MOSSYCOBBLE, 22}, {CONTENT_GRAVEL, 23}, {CONTENT_SANDSTONE, 24}, {CONTENT_CACTUS, 25}, {CONTENT_BRICK, 26}, {CONTENT_CLAY, 27}, {CONTENT_PAPYRUS, 28}, {CONTENT_BOOKSHELF, 29}, }; MapNode mapnode_translate_to_internal(MapNode n_from, u8 version) { MapNode result = n_from; if(version <= 19) { content_t c_from = n_from.getContent(); for(u32 i=0; i<sizeof(trans_table_19)/sizeof(trans_table_19[0]); i++) { if(trans_table_19[i][1] == c_from) { result.setContent(trans_table_19[i][0]); break; } } } return result; } void content_mapnode_get_name_id_mapping(NameIdMapping *nimap) { nimap->set(0, "default:stone"); nimap->set(2, "default:water_flowing"); nimap->set(3, "default:torch"); nimap->set(9, "default:water_source"); nimap->set(14, "default:sign_wall"); nimap->set(15, "default:chest"); nimap->set(16, "default:furnace"); nimap->set(17, "default:chest_locked"); nimap->set(21, "default:fence_wood"); nimap->set(30, "default:rail"); nimap->set(31, "default:ladder"); nimap->set(32, "default:lava_flowing"); nimap->set(33, "default:lava_source"); nimap->set(0x800, "default:dirt_with_grass"); nimap->set(0x801, "default:tree"); nimap->set(0x802, "default:leaves"); nimap->set(0x803, "default:dirt_with_grass_footsteps"); nimap->set(0x804, "default:mese"); nimap->set(0x805, "default:dirt"); nimap->set(0x806, "default:cloud"); nimap->set(0x807, "default:coalstone"); nimap->set(0x808, "default:wood"); nimap->set(0x809, "default:sand"); nimap->set(0x80a, "default:cobble"); nimap->set(0x80b, "default:steelblock"); nimap->set(0x80c, "default:glass"); nimap->set(0x80d, "default:mossycobble"); nimap->set(0x80e, "default:gravel"); nimap->set(0x80f, "default:sandstone"); nimap->set(0x810, "default:cactus"); nimap->set(0x811, "default:brick"); nimap->set(0x812, "default:clay"); nimap->set(0x813, "default:papyrus"); nimap->set(0x814, "default:bookshelf"); nimap->set(0x815, "default:jungletree"); nimap->set(0x816, "default:junglegrass"); nimap->set(0x817, "default:nyancat"); nimap->set(0x818, "default:nyancat_rainbow"); nimap->set(0x819, "default:apple"); nimap->set(0x820, "default:sapling"); // Static types nimap->set(CONTENT_IGNORE, "ignore"); nimap->set(CONTENT_AIR, "air"); } class NewNameGetter { public: NewNameGetter() { old_to_new["CONTENT_STONE"] = "default:stone"; old_to_new["CONTENT_WATER"] = "default:water_flowing"; old_to_new["CONTENT_TORCH"] = "default:torch"; old_to_new["CONTENT_WATERSOURCE"] = "default:water_source"; old_to_new["CONTENT_SIGN_WALL"] = "default:sign_wall"; old_to_new["CONTENT_CHEST"] = "default:chest"; old_to_new["CONTENT_FURNACE"] = "default:furnace"; old_to_new["CONTENT_LOCKABLE_CHEST"] = "default:locked_chest"; old_to_new["CONTENT_FENCE"] = "default:wooden_fence"; old_to_new["CONTENT_RAIL"] = "default:rail"; old_to_new["CONTENT_LADDER"] = "default:ladder"; old_to_new["CONTENT_LAVA"] = "default:lava_flowing"; old_to_new["CONTENT_LAVASOURCE"] = "default:lava_source"; old_to_new["CONTENT_GRASS"] = "default:dirt_with_grass"; old_to_new["CONTENT_TREE"] = "default:tree"; old_to_new["CONTENT_LEAVES"] = "default:leaves"; old_to_new["CONTENT_GRASS_FOOTSTEPS"] = "default:dirt_with_grass_footsteps"; old_to_new["CONTENT_MESE"] = "default:mese"; old_to_new["CONTENT_MUD"] = "default:dirt"; old_to_new["CONTENT_CLOUD"] = "default:cloud"; old_to_new["CONTENT_COALSTONE"] = "default:coalstone"; old_to_new["CONTENT_WOOD"] = "default:wood"; old_to_new["CONTENT_SAND"] = "default:sand"; old_to_new["CONTENT_COBBLE"] = "default:cobble"; old_to_new["CONTENT_STEEL"] = "default:steel"; old_to_new["CONTENT_GLASS"] = "default:glass"; old_to_new["CONTENT_MOSSYCOBBLE"] = "default:mossycobble"; old_to_new["CONTENT_GRAVEL"] = "default:gravel"; old_to_new["CONTENT_SANDSTONE"] = "default:sandstone"; old_to_new["CONTENT_CACTUS"] = "default:cactus"; old_to_new["CONTENT_BRICK"] = "default:brick"; old_to_new["CONTENT_CLAY"] = "default:clay"; old_to_new["CONTENT_PAPYRUS"] = "default:papyrus"; old_to_new["CONTENT_BOOKSHELF"] = "default:bookshelf"; old_to_new["CONTENT_JUNGLETREE"] = "default:jungletree"; old_to_new["CONTENT_JUNGLEGRASS"] = "default:junglegrass"; old_to_new["CONTENT_NC"] = "default:nyancat"; old_to_new["CONTENT_NC_RB"] = "default:nyancat_rainbow"; old_to_new["CONTENT_APPLE"] = "default:apple"; old_to_new["CONTENT_SAPLING"] = "default:sapling"; // Just in case old_to_new["CONTENT_IGNORE"] = "ignore"; old_to_new["CONTENT_AIR"] = "air"; } std::string get(const std::string &old) { std::map<std::string, std::string>::const_iterator i; i = old_to_new.find(old); if(i == old_to_new.end()) return ""; return i->second; } private: std::map<std::string, std::string> old_to_new; }; NewNameGetter newnamegetter; std::string content_mapnode_get_new_name(const std::string &oldname) { return newnamegetter.get(oldname); } content_t legacy_get_id(const std::string &oldname, INodeDefManager *ndef) { std::string newname = content_mapnode_get_new_name(oldname); if(newname == "") return CONTENT_IGNORE; content_t id; bool found = ndef->getId(newname, id); if(!found) return CONTENT_IGNORE; return id; }