Add support of pressed_texture of image_button

Fix params number

Add pressed texture name

Fix string def

Fix syntax error
experimental
BlockMen 2013-07-18 21:20:37 +02:00 committed by RealBadAngel
parent 8e2467c393
commit a59f85c1a0
2 changed files with 31 additions and 7 deletions

View File

@ -933,16 +933,24 @@ button[<X>,<Y>;<W>,<H>;<name>;<label>]
image_button[<X>,<Y>;<W>,<H>;<texture name>;<name>;<label>] image_button[<X>,<Y>;<W>,<H>;<texture name>;<name>;<label>]
^ x, y, w, h, and name work as per button ^ x, y, w, h, and name work as per button
^ image is the filename of an image ^ texture name is the filename of an image
^ Position and size units are inventory slots ^ Position and size units are inventory slots
image_button[<X>,<Y>;<W>,<H>;<texture name>;<name>;<label>;<noclip>;<drawborder>] image_button[<X>,<Y>;<W>,<H>;<texture name>;<name>;<label>;<noclip>;<drawborder>]
^ x, y, w, h, and name work as per button ^ x, y, w, h, and name work as per button
^ image is the filename of an image ^ texture name is the filename of an image
^ Position and size units are inventory slots ^ Position and size units are inventory slots
^ noclip true meand imagebutton doesn't need to be within specified formsize ^ noclip true meand imagebutton doesn't need to be within specified formsize
^ drawborder draw button bodrer or not ^ drawborder draw button bodrer or not
image_button[<X>,<Y>;<W>,<H>;<texture name>;<name>;<label>;<noclip>;<drawborder>;<pressed texture name>]
^ x, y, w, h, and name work as per button
^ texture name is the filename of an image
^ Position and size units are inventory slots
^ noclip true meand imagebutton doesn't need to be within specified formsize
^ drawborder draw button bodrer or not
^ pressed texture name is the filename of an image on pressed state
item_image_button[<X>,<Y>;<W>,<H>;<item name>;<name>;<label>] item_image_button[<X>,<Y>;<W>,<H>;<item name>;<name>;<label>]
^ x, y, w, h, name and label work as per button ^ x, y, w, h, name and label work as per button
^ item name is the registered name of an item/node, ^ item name is the registered name of an item/node,

View File

@ -1116,7 +1116,7 @@ void GUIFormSpecMenu::parseVertLabel(parserData* data,std::string element) {
void GUIFormSpecMenu::parseImageButton(parserData* data,std::string element,std::string type) { void GUIFormSpecMenu::parseImageButton(parserData* data,std::string element,std::string type) {
std::vector<std::string> parts = split(element,';'); std::vector<std::string> parts = split(element,';');
if ((parts.size() == 5) || (parts.size() == 7)) { if ((parts.size() == 5) || (parts.size() == 7) || (parts.size() == 8)) {
std::vector<std::string> v_pos = split(parts[0],','); std::vector<std::string> v_pos = split(parts[0],',');
std::vector<std::string> v_geom = split(parts[1],','); std::vector<std::string> v_geom = split(parts[1],',');
std::string image_name = parts[2]; std::string image_name = parts[2];
@ -1136,13 +1136,19 @@ void GUIFormSpecMenu::parseImageButton(parserData* data,std::string element,std:
bool noclip = false; bool noclip = false;
bool drawborder = true; bool drawborder = true;
if ((parts.size() == 7)) { if ((parts.size() >= 7)) {
if (parts[5] == "true") if (parts[5] == "true")
noclip = true; noclip = true;
if (parts[6] == "false") if (parts[6] == "false")
drawborder = false; drawborder = false;
} }
std::string pressed_image_name = "";
if ((parts.size() == 8)) {
pressed_image_name = parts[7];
}
core::rect<s32> rect = core::rect<s32>(pos.X, pos.Y, pos.X+geom.X, pos.Y+geom.Y); core::rect<s32> rect = core::rect<s32>(pos.X, pos.Y, pos.X+geom.X, pos.Y+geom.Y);
@ -1169,21 +1175,31 @@ void GUIFormSpecMenu::parseImageButton(parserData* data,std::string element,std:
spec.is_exit = true; spec.is_exit = true;
video::ITexture *texture = 0; video::ITexture *texture = 0;
video::ITexture *pressed_texture = 0;
//if there's no gamedef specified try to get direct //if there's no gamedef specified try to get direct
//TODO check for possible texture leak //TODO check for possible texture leak
if (m_gamedef != 0) if (m_gamedef != 0) {
texture = m_gamedef->tsrc()->getTexture(image_name); texture = m_gamedef->tsrc()->getTexture(image_name);
else { if ((parts.size() == 8)) {
pressed_texture = m_gamedef->tsrc()->getTexture(pressed_image_name);
}
} else {
if (fs::PathExists(image_name)) { if (fs::PathExists(image_name)) {
texture = Environment->getVideoDriver()->getTexture(image_name.c_str()); texture = Environment->getVideoDriver()->getTexture(image_name.c_str());
m_Textures.push_back(texture); m_Textures.push_back(texture);
} }
if (fs::PathExists(pressed_image_name)) {
pressed_texture = Environment->getVideoDriver()->getTexture(pressed_image_name.c_str());
m_Textures.push_back(pressed_texture);
}
} }
if (parts.size() < 8)
pressed_texture = texture;
gui::IGUIButton *e = Environment->addButton(rect, this, spec.fid, spec.flabel.c_str()); gui::IGUIButton *e = Environment->addButton(rect, this, spec.fid, spec.flabel.c_str());
e->setUseAlphaChannel(true); e->setUseAlphaChannel(true);
e->setImage(texture); e->setImage(texture);
e->setPressedImage(texture); e->setPressedImage(pressed_texture);
e->setScaleImage(true); e->setScaleImage(true);
e->setNotClipped(noclip); e->setNotClipped(noclip);
e->setDrawBorder(drawborder); e->setDrawBorder(drawborder);