aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRealBadAngel <maciej.kasatkin@o2.pl>2016-02-09 10:43:38 +0100
committerest31 <MTest31@outlook.com>2016-02-13 02:35:52 +0100
commit5ca48a35a610aefd5c34d615cb49900f423b7aa6 (patch)
tree4b268373a5face1fa94b4a29146a4e0a517987a4 /src
parentbd439338282fccb2c50fd1395e55843259914e25 (diff)
downloadminetest-5ca48a35a610aefd5c34d615cb49900f423b7aa6.tar.gz
minetest-5ca48a35a610aefd5c34d615cb49900f423b7aa6.tar.bz2
minetest-5ca48a35a610aefd5c34d615cb49900f423b7aa6.zip
Formspec: recreate item_image_button pressed state for its image and label
Diffstat (limited to 'src')
-rw-r--r--src/guiFormSpecMenu.cpp28
-rw-r--r--src/guiFormSpecMenu.h48
2 files changed, 54 insertions, 22 deletions
diff --git a/src/guiFormSpecMenu.cpp b/src/guiFormSpecMenu.cpp
index 226cc6cf0..8a657a2ff 100644
--- a/src/guiFormSpecMenu.cpp
+++ b/src/guiFormSpecMenu.cpp
@@ -1503,10 +1503,6 @@ void GUIFormSpecMenu::parseItemImageButton(parserData* data,std::string element)
Environment->setFocus(e);
}
- e->setUseAlphaChannel(true);
- e->setImage(guiScalingImageButton(Environment->getVideoDriver(), NULL, geom.X, geom.Y));
- e->setPressedImage(guiScalingImageButton(Environment->getVideoDriver(), NULL, geom.X, geom.Y));
- e->setScaleImage(true);
spec.ftype = f_Button;
rect+=data->basepos-padding;
spec.rect=rect;
@@ -1514,13 +1510,8 @@ void GUIFormSpecMenu::parseItemImageButton(parserData* data,std::string element)
pos = padding + AbsoluteRect.UpperLeftCorner;
pos.X += stof(v_pos[0]) * (float) spacing.X;
pos.Y += stof(v_pos[1]) * (float) spacing.Y;
- m_itemimages.push_back(ImageDrawSpec("", item_name, pos, geom));
-
- StaticTextSpec label_spec(
- utf8_to_wide(label),
- rect
- );
- m_static_texts.push_back(label_spec);
+ m_itemimages.push_back(ImageDrawSpec("", item_name, e, pos, geom));
+ m_static_texts.push_back(StaticTextSpec(utf8_to_wide(label), rect, e));
return;
}
errorstream<< "Invalid ItemImagebutton element(" << parts.size() << "): '" << element << "'" << std::endl;
@@ -2442,6 +2433,11 @@ void GUIFormSpecMenu::drawMenu()
core::rect<s32> imgrect(0, 0, spec.geom.X, spec.geom.Y);
// Viewport rectangle on screen
core::rect<s32> rect = imgrect + spec.pos;
+ if (spec.parent_button && spec.parent_button->isPressed()) {
+ rect += core::dimension2d<s32>(
+ skin->getSize(irr::gui::EGDS_BUTTON_PRESSED_IMAGE_OFFSET_X),
+ skin->getSize(irr::gui::EGDS_BUTTON_PRESSED_IMAGE_OFFSET_Y));
+ }
drawItemStack(driver, m_font, item, rect, &AbsoluteClippingRect,
m_gamedef, IT_ROT_NONE);
}
@@ -2474,8 +2470,16 @@ void GUIFormSpecMenu::drawMenu()
*/
for (u32 i = 0; i < m_static_texts.size(); i++) {
const StaticTextSpec &spec = m_static_texts[i];
+ core::rect<s32> rect = spec.rect;
+ if (spec.parent_button && spec.parent_button->isPressed()) {
+ // Use image offset instead of text's because its a bit smaller
+ // and fits better, also TEXT_OFFSET_X is always 0
+ rect += core::dimension2d<s32>(
+ skin->getSize(irr::gui::EGDS_BUTTON_PRESSED_IMAGE_OFFSET_X),
+ skin->getSize(irr::gui::EGDS_BUTTON_PRESSED_IMAGE_OFFSET_Y));
+ }
video::SColor color(255, 255, 255, 255);
- m_font->draw(spec.text.c_str(), spec.rect, color, true, true, &spec.rect);
+ m_font->draw(spec.text.c_str(), rect, color, true, true, &rect);
}
/*
diff --git a/src/guiFormSpecMenu.h b/src/guiFormSpecMenu.h
index 9955048a3..005b91369 100644
--- a/src/guiFormSpecMenu.h
+++ b/src/guiFormSpecMenu.h
@@ -139,36 +139,53 @@ class GUIFormSpecMenu : public GUIModalMenu
struct ImageDrawSpec
{
- ImageDrawSpec()
+ ImageDrawSpec():
+ parent_button(NULL)
{
}
ImageDrawSpec(const std::string &a_name,
const std::string &a_item_name,
+ gui::IGUIButton *a_parent_button,
const v2s32 &a_pos, const v2s32 &a_geom):
name(a_name),
- item_name (a_item_name),
+ item_name(a_item_name),
+ parent_button(a_parent_button),
pos(a_pos),
- geom(a_geom)
+ geom(a_geom),
+ scale(true)
{
- scale = true;
}
ImageDrawSpec(const std::string &a_name,
+ const std::string &a_item_name,
const v2s32 &a_pos, const v2s32 &a_geom):
name(a_name),
+ item_name(a_item_name),
+ parent_button(NULL),
pos(a_pos),
- geom(a_geom)
+ geom(a_geom),
+ scale(true)
+ {
+ }
+ ImageDrawSpec(const std::string &a_name,
+ const v2s32 &a_pos, const v2s32 &a_geom):
+ name(a_name),
+ parent_button(NULL),
+ pos(a_pos),
+ geom(a_geom),
+ scale(true)
{
- scale = true;
}
ImageDrawSpec(const std::string &a_name,
const v2s32 &a_pos):
name(a_name),
- pos(a_pos)
+ parent_button(NULL),
+ pos(a_pos),
+ scale(false)
{
- scale = false;
}
std::string name;
std::string item_name;
+ gui::IGUIButton *parent_button;
v2s32 pos;
v2s32 geom;
bool scale;
@@ -229,17 +246,28 @@ class GUIFormSpecMenu : public GUIModalMenu
};
struct StaticTextSpec {
- StaticTextSpec()
+ StaticTextSpec():
+ parent_button(NULL)
{
}
StaticTextSpec(const std::wstring &a_text,
const core::rect<s32> &a_rect):
text(a_text),
- rect(a_rect)
+ rect(a_rect),
+ parent_button(NULL)
+ {
+ }
+ StaticTextSpec(const std::wstring &a_text,
+ const core::rect<s32> &a_rect,
+ gui::IGUIButton *a_parent_button):
+ text(a_text),
+ rect(a_rect),
+ parent_button(a_parent_button)
{
}
std::wstring text;
core::rect<s32> rect;
+ gui::IGUIButton *parent_button;
};
public: