return font->getDimension(L"Ay").Height + font->getKerningHeight();
}
-static gui::IGUIFont *select_font_by_line_height(double target_line_height)
-{
- return g_fontengine->getFont();
-
-/* I have no idea what this is trying to achieve, but scaling the font according
- * to the size of a formspec/dialog does not seem to be a standard (G)UI
- * design and AFAIK no existing nor proposed GUI does this. Besides that it:
- * a) breaks most (current) formspec layouts
- * b) font sizes change depending on the size of the formspec/dialog (see above)
- * meaning that there is no UI consistency
- * c) the chosen fonts are, in general, probably too large
- *
- * Disabling for now.
- *
- * FIXME
- */
-#if 0
- // We don't get to directly select a font according to its
- // baseline-to-baseline height. Rather, we select by em size.
- // The ratio between these varies between fonts. The font
- // engine also takes its size parameter not specified in pixels,
- // as we want, but scaled by display density and gui_scaling,
- // so invert that scaling here. Use a binary search among
- // requested sizes to find the right font. Our starting bounds
- // are an em height of 1 (being careful not to request size 0,
- // which crashes the freetype system) and an em height of the
- // target baseline-to-baseline height.
- unsigned int loreq = ceil(1 / porting::getDisplayDensity()
- / g_settings->getFloat("gui_scaling"));
- unsigned int hireq = ceil(target_line_height
- / porting::getDisplayDensity()
- / g_settings->getFloat("gui_scaling"));
- unsigned int lohgt = font_line_height(g_fontengine->getFont(loreq));
- unsigned int hihgt = font_line_height(g_fontengine->getFont(hireq));
- while(hireq - loreq > 1 && lohgt != hihgt) {
- unsigned int nureq = (loreq + hireq) >> 1;
- unsigned int nuhgt = font_line_height(g_fontengine->getFont(nureq));
- if(nuhgt < target_line_height) {
- loreq = nureq;
- lohgt = nuhgt;
- } else {
- hireq = nureq;
- hihgt = nuhgt;
- }
- }
- return g_fontengine->getFont(target_line_height - lohgt < hihgt - target_line_height ? loreq : hireq);
-#endif
-}
-
GUIFormSpecMenu::GUIFormSpecMenu(irr::IrrlichtDevice* dev,
gui::IGUIElement* parent, s32 id, IMenuManager *menumgr,
InventoryManager *invmgr, IGameDef *gamedef,
m_form_src(fsrc),
m_text_dst(tdst),
m_formspec_version(0),
+ m_focused_element(L""),
m_font(NULL)
#ifdef __ANDROID__
,m_JavaDialogFieldName(L"")
{
std::vector<std::string> parts = split(element,';');
- if (((parts.size() >= 3) || (parts.size() <= 4)) ||
+ if (((parts.size() >= 3) && (parts.size() <= 4)) ||
((parts.size() > 4) && (m_formspec_version > FORMSPEC_API_VERSION)))
{
std::vector<std::string> v_pos = split(parts[0],',');
if (selected == "true")
fselected = true;
- std::wstring wlabel = narrow_to_wide(label.c_str());
+ std::wstring wlabel = narrow_to_wide(label);
core::rect<s32> rect = core::rect<s32>(
pos.X, pos.Y + ((imgsize.Y/2) - m_btn_height),
pos.Y + ((imgsize.Y/2) + m_btn_height));
FieldSpec spec(
- narrow_to_wide(name.c_str()),
+ narrow_to_wide(name),
wlabel, //Needed for displaying text on MSVC
wlabel,
258+m_fields.size()
core::rect<s32>(pos.X, pos.Y, pos.X + dim.X, pos.Y + dim.Y);
FieldSpec spec(
- narrow_to_wide(name.c_str()),
+ narrow_to_wide(name),
L"",
L"",
258+m_fields.size()
label = unescape_string(label);
- std::wstring wlabel = narrow_to_wide(label.c_str());
+ std::wstring wlabel = narrow_to_wide(label);
FieldSpec spec(
- narrow_to_wide(name.c_str()),
+ narrow_to_wide(name),
wlabel,
L"",
258+m_fields.size()
core::rect<s32> rect = core::rect<s32>(pos.X, pos.Y, pos.X+geom.X, pos.Y+geom.Y);
- std::wstring fname_w = narrow_to_wide(name.c_str());
+ std::wstring fname_w = narrow_to_wide(name);
FieldSpec spec(
fname_w,
core::rect<s32> rect = core::rect<s32>(pos.X, pos.Y, pos.X+geom.X, pos.Y+geom.Y);
- std::wstring fname_w = narrow_to_wide(name.c_str());
+ std::wstring fname_w = narrow_to_wide(name);
FieldSpec spec(
fname_w,
core::rect<s32> rect = core::rect<s32>(pos.X, pos.Y,
pos.X + width, pos.Y + (m_btn_height * 2));
- std::wstring fname_w = narrow_to_wide(name.c_str());
+ std::wstring fname_w = narrow_to_wide(name);
FieldSpec spec(
fname_w,
label = unescape_string(label);
- std::wstring wlabel = narrow_to_wide(label.c_str());
+ std::wstring wlabel = narrow_to_wide(label);
FieldSpec spec(
- narrow_to_wide(name.c_str()),
+ narrow_to_wide(name),
wlabel,
L"",
258+m_fields.size()
if (label.length() >= 1)
{
- int font_height = font_line_height(m_font);
+ int font_height = g_fontengine->getTextHeight();
rect.UpperLeftCorner.Y -= font_height;
rect.LowerRightCorner.Y = rect.UpperLeftCorner.Y + font_height;
Environment->addStaticText(spec.flabel.c_str(), rect, false, true, this, 0);
default_val = unescape_string(default_val);
label = unescape_string(label);
- std::wstring wlabel = narrow_to_wide(label.c_str());
+ std::wstring wlabel = narrow_to_wide(label);
FieldSpec spec(
- narrow_to_wide(name.c_str()),
+ narrow_to_wide(name),
wlabel,
- narrow_to_wide(default_val.c_str()),
+ narrow_to_wide(default_val),
258+m_fields.size()
);
if (label.length() >= 1)
{
- int font_height = font_line_height(m_font);
+ int font_height = g_fontengine->getTextHeight();
rect.UpperLeftCorner.Y -= font_height;
rect.LowerRightCorner.Y = rect.UpperLeftCorner.Y + font_height;
Environment->addStaticText(spec.flabel.c_str(), rect, false, true, this, 0);
default_val = unescape_string(default_val);
label = unescape_string(label);
- std::wstring wlabel = narrow_to_wide(label.c_str());
+ std::wstring wlabel = narrow_to_wide(label);
FieldSpec spec(
- narrow_to_wide(name.c_str()),
+ narrow_to_wide(name),
wlabel,
- narrow_to_wide(default_val.c_str()),
+ narrow_to_wide(default_val),
258+m_fields.size()
);
if (label.length() >= 1)
{
- int font_height = font_line_height(m_font);
+ int font_height = g_fontengine->getTextHeight();
rect.UpperLeftCorner.Y -= font_height;
rect.LowerRightCorner.Y = rect.UpperLeftCorner.Y + font_height;
Environment->addStaticText(spec.flabel.c_str(), rect, false, true, this, 0);
if(!data->explicit_size)
errorstream<<"WARNING: invalid use of label without a size[] element"<<std::endl;
- int font_height = font_line_height(m_font);
-
text = unescape_string(text);
std::vector<std::string> lines = split(text, '\n');
// in the integer cases: 0.4 is not exactly
// representable in binary floating point.
s32 posy = pos.Y + ((float)i) * spacing.Y * 2.0 / 5.0;
- std::wstring wlabel = narrow_to_wide(lines[i].c_str());
+ std::wstring wlabel = narrow_to_wide(lines[i]);
core::rect<s32> rect = core::rect<s32>(
- pos.X, posy - font_height,
+ pos.X, posy - m_btn_height,
pos.X + m_font->getDimension(wlabel.c_str()).Width,
- posy + font_height);
+ posy + m_btn_height);
FieldSpec spec(
L"",
wlabel,
pressed_image_name = unescape_string(pressed_image_name);
label = unescape_string(label);
- std::wstring wlabel = narrow_to_wide(label.c_str());
+ std::wstring wlabel = narrow_to_wide(label);
FieldSpec spec(
- narrow_to_wide(name.c_str()),
+ narrow_to_wide(name),
wlabel,
- narrow_to_wide(image_name.c_str()),
+ narrow_to_wide(image_name),
258+m_fields.size()
);
spec.ftype = f_Button;
}
FieldSpec spec(
- narrow_to_wide(name.c_str()),
+ narrow_to_wide(name),
L"",
L"",
258+m_fields.size()
item.deSerialize(item_name, idef);
video::ITexture *texture = idef->getInventoryTexture(item.getDefinition(idef).name, m_gamedef);
- m_tooltips[narrow_to_wide(name.c_str())] =
+ m_tooltips[narrow_to_wide(name)] =
TooltipSpec (item.getDefinition(idef).description,
m_default_tooltip_bgcolor,
m_default_tooltip_color);
label = unescape_string(label);
FieldSpec spec(
- narrow_to_wide(name.c_str()),
- narrow_to_wide(label.c_str()),
- narrow_to_wide(item_name.c_str()),
+ narrow_to_wide(name),
+ narrow_to_wide(label),
+ narrow_to_wide(item_name),
258+m_fields.size()
);
std::vector<std::string> parts = split(element,';');
if (parts.size() == 2) {
std::string name = parts[0];
- m_tooltips[narrow_to_wide(name.c_str())] = TooltipSpec (parts[1], m_default_tooltip_bgcolor, m_default_tooltip_color);
+ m_tooltips[narrow_to_wide(name)] = TooltipSpec (parts[1], m_default_tooltip_bgcolor, m_default_tooltip_color);
return;
} else if (parts.size() == 4) {
std::string name = parts[0];
video::SColor tmp_color1, tmp_color2;
if ( parseColorString(parts[2], tmp_color1, false) && parseColorString(parts[3], tmp_color2, false) ) {
- m_tooltips[narrow_to_wide(name.c_str())] = TooltipSpec (parts[1], tmp_color1, tmp_color2);
+ m_tooltips[narrow_to_wide(name)] = TooltipSpec (parts[1], tmp_color1, tmp_color2);
return;
}
}
<<std::endl;
}
-
-
void GUIFormSpecMenu::regenerateGui(v2u32 screensize)
{
/* useless to regenerate without a screensize */
mydata.table_dyndata[tablename] = table->getDynamicData();
}
+ //set focus
+ if (!m_focused_element.empty())
+ mydata.focused_fieldname = m_focused_element;
+
//preserve focus
gui::IGUIElement *focused_element = Environment->getFocus();
if (focused_element && focused_element->getParent() == this) {
// wide, including border) just fit into the
// default window (800 pixels wide) at 96 DPI
// and default scaling (1.00).
- use_imgsize = 0.53 * screen_dpi * gui_scaling;
+ use_imgsize = 0.5555 * screen_dpi * gui_scaling;
} else {
// In variable-size mode, we prefer to make the
// inventory image size 1/15 of screen height,
imgsize = v2s32(use_imgsize, use_imgsize);
spacing = v2s32(use_imgsize*5.0/4, use_imgsize*15.0/13);
padding = v2s32(use_imgsize*3.0/8, use_imgsize*3.0/8);
- double target_font_height = use_imgsize*15.0/13 * 0.4;
m_btn_height = use_imgsize*15.0/13 * 0.35;
- m_font = select_font_by_line_height(target_font_height);
+ m_font = g_fontengine->getFont();
mydata.size = v2s32(
padding.X*2+spacing.X*(mydata.invsize.X-1.0)+imgsize.X,
mydata.rect =
core::rect<s32>(size.X/2-70, pos.Y,
(size.X/2-70)+140, pos.Y + (m_btn_height*2));
- wchar_t* text = wgettext("Proceed");
+ const wchar_t *text = wgettext("Proceed");
Environment->addButton(mydata.rect, this, 257, text);
delete[] text;
}
m_tooltip_element->setVisible(true);
this->bringToFront(m_tooltip_element);
m_tooltip_element->setText(narrow_to_wide(tooltip_text).c_str());
- s32 tooltip_x = m_pointer.X + m_btn_height;
- s32 tooltip_y = m_pointer.Y + m_btn_height;
s32 tooltip_width = m_tooltip_element->getTextWidth() + m_btn_height;
s32 tooltip_height = m_tooltip_element->getTextHeight() * tt_rows.size() + 5;
+ v2u32 screenSize = driver->getScreenSize();
+ int tooltip_offset_x = m_btn_height;
+ int tooltip_offset_y = m_btn_height;
+#ifdef __ANDROID__
+ tooltip_offset_x *= 3;
+ tooltip_offset_y = 0;
+ if (m_pointer.X > (s32)screenSize.X / 2)
+ tooltip_offset_x = (tooltip_offset_x + tooltip_width) * -1;
+#endif
+ s32 tooltip_x = m_pointer.X + tooltip_offset_x;
+ s32 tooltip_y = m_pointer.Y + tooltip_offset_y;
+ if (tooltip_x + tooltip_width > (s32)screenSize.X)
+ tooltip_x = (s32)screenSize.X - tooltip_width - m_btn_height;
+ if (tooltip_y + tooltip_height > (s32)screenSize.Y)
+ tooltip_y = (s32)screenSize.Y - tooltip_height - m_btn_height;
m_tooltip_element->setRelativePosition(core::rect<s32>(
core::position2d<s32>(tooltip_x, tooltip_y),
core::dimension2d<s32>(tooltip_width, tooltip_height)));
if (m_old_tooltip != m_tooltips[iter->fname].tooltip) {
m_old_tooltip = m_tooltips[iter->fname].tooltip;
m_tooltip_element->setText(narrow_to_wide(m_tooltips[iter->fname].tooltip).c_str());
- s32 tooltip_x = m_pointer.X + m_btn_height;
- s32 tooltip_y = m_pointer.Y + m_btn_height;
- s32 tooltip_width = m_tooltip_element->getTextWidth() + m_btn_height;
- if (tooltip_x + tooltip_width > (s32)screenSize.X)
- tooltip_x = (s32)screenSize.X - tooltip_width - m_btn_height;
std::vector<std::string> tt_rows = str_split(m_tooltips[iter->fname].tooltip, '\n');
+ s32 tooltip_width = m_tooltip_element->getTextWidth() + m_btn_height;
s32 tooltip_height = m_tooltip_element->getTextHeight() * tt_rows.size() + 5;
+ int tooltip_offset_x = m_btn_height;
+ int tooltip_offset_y = m_btn_height;
+#ifdef __ANDROID__
+ tooltip_offset_x *= 3;
+ tooltip_offset_y = 0;
+ if (m_pointer.X > (s32)screenSize.X / 2)
+ tooltip_offset_x = (tooltip_offset_x + tooltip_width) * -1;
+#endif
+ s32 tooltip_x = m_pointer.X + tooltip_offset_x;
+ s32 tooltip_y = m_pointer.Y + tooltip_offset_y;
+ if (tooltip_x + tooltip_width > (s32)screenSize.X)
+ tooltip_x = (s32)screenSize.X - tooltip_width - m_btn_height;
+ if (tooltip_y + tooltip_height > (s32)screenSize.Y)
+ tooltip_y = (s32)screenSize.Y - tooltip_height - m_btn_height;
m_tooltip_element->setRelativePosition(core::rect<s32>(
core::position2d<s32>(tooltip_x, tooltip_y),
core::dimension2d<s32>(tooltip_width, tooltip_height)));
gui::IGUIElement *hovered =
Environment->getRootGUIElement()->getElementFromPoint(
core::position2d<s32>(x, y));
- if (hovered->getType() == gui::EGUIET_TAB_CONTROL) {
+ if (hovered && isMyChild(hovered) &&
+ hovered->getType() == gui::EGUIET_TAB_CONTROL) {
gui::IGUISkin* skin = Environment->getSkin();
assert(skin != NULL);
gui::IGUIFont *old_font = skin->getFont();