aboutsummaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorMinetest-j45 <55553015+Minetest-j45@users.noreply.github.com>2021-08-30 15:22:40 +0100
committerGitHub <noreply@github.com>2021-08-30 15:22:40 +0100
commit7824a4956bf489b4e2cc35e0c97272eee06be6ba (patch)
tree70243765dc1743a83596f9c6eec122fb417ef92c /src/gui
parent607add326feb44e078b843464ce4a8de09f28743 (diff)
parent35445d24f425c6291a0580b468919ca83de716fd (diff)
downloaddragonfireclient-7824a4956bf489b4e2cc35e0c97272eee06be6ba.tar.xz
Merge pull request #1 from EliasFleckenstein03/master
update
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/CMakeLists.txt1
-rw-r--r--src/gui/StyleSpec.h47
-rw-r--r--src/gui/cheatMenu.cpp2
-rw-r--r--src/gui/guiButton.cpp7
-rw-r--r--src/gui/guiButton.h35
-rw-r--r--src/gui/guiButtonItemImage.cpp5
-rw-r--r--src/gui/guiButtonItemImage.h7
-rw-r--r--src/gui/guiChatConsole.cpp17
-rw-r--r--src/gui/guiChatConsole.h4
-rw-r--r--src/gui/guiConfirmRegistration.cpp12
-rw-r--r--src/gui/guiEditBox.cpp126
-rw-r--r--src/gui/guiEditBox.h14
-rw-r--r--src/gui/guiEditBoxWithScrollbar.cpp77
-rw-r--r--src/gui/guiEditBoxWithScrollbar.h2
-rw-r--r--src/gui/guiEngine.cpp36
-rw-r--r--src/gui/guiEngine.h3
-rw-r--r--src/gui/guiFormSpecMenu.cpp88
-rw-r--r--src/gui/guiFormSpecMenu.h8
-rw-r--r--src/gui/guiHyperText.cpp2
-rw-r--r--src/gui/guiInventoryList.cpp2
-rw-r--r--src/gui/guiKeyChangeMenu.cpp94
-rw-r--r--src/gui/guiScene.cpp15
-rw-r--r--src/gui/guiScene.h1
-rw-r--r--src/gui/intlGUIEditBox.cpp723
-rw-r--r--src/gui/intlGUIEditBox.h75
-rw-r--r--src/gui/modalMenu.cpp171
-rw-r--r--src/gui/modalMenu.h9
-rw-r--r--src/gui/touchscreengui.cpp18
-rw-r--r--src/gui/touchscreengui.h9
29 files changed, 460 insertions, 1150 deletions
diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt
index f93b85aff..ea6e44ab7 100644
--- a/src/gui/CMakeLists.txt
+++ b/src/gui/CMakeLists.txt
@@ -24,7 +24,6 @@ set(gui_SRCS
${CMAKE_CURRENT_SOURCE_DIR}/guiTable.cpp
${CMAKE_CURRENT_SOURCE_DIR}/guiHyperText.cpp
${CMAKE_CURRENT_SOURCE_DIR}/guiVolumeChange.cpp
- ${CMAKE_CURRENT_SOURCE_DIR}/intlGUIEditBox.cpp
${CMAKE_CURRENT_SOURCE_DIR}/modalMenu.cpp
${CMAKE_CURRENT_SOURCE_DIR}/profilergraph.cpp
PARENT_SCOPE
diff --git a/src/gui/StyleSpec.h b/src/gui/StyleSpec.h
index f2844ce28..fc92a861b 100644
--- a/src/gui/StyleSpec.h
+++ b/src/gui/StyleSpec.h
@@ -55,6 +55,8 @@ public:
BORDERCOLORS,
BORDERWIDTHS,
SOUND,
+ SPACING,
+ SIZE,
NUM_PROPERTIES,
NONE
};
@@ -119,6 +121,10 @@ public:
return BORDERWIDTHS;
} else if (name == "sound") {
return SOUND;
+ } else if (name == "spacing") {
+ return SPACING;
+ } else if (name == "size") {
+ return SIZE;
} else {
return NONE;
}
@@ -259,27 +265,40 @@ public:
return rect;
}
- irr::core::vector2d<s32> getVector2i(Property prop, irr::core::vector2d<s32> def) const
+ v2f32 getVector2f(Property prop, v2f32 def) const
{
const auto &val = properties[prop];
if (val.empty())
return def;
- irr::core::vector2d<s32> vec;
- if (!parseVector2i(val, &vec))
+ v2f32 vec;
+ if (!parseVector2f(val, &vec))
return def;
return vec;
}
- irr::core::vector2d<s32> getVector2i(Property prop) const
+ v2s32 getVector2i(Property prop, v2s32 def) const
+ {
+ const auto &val = properties[prop];
+ if (val.empty())
+ return def;
+
+ v2f32 vec;
+ if (!parseVector2f(val, &vec))
+ return def;
+
+ return v2s32(vec.X, vec.Y);
+ }
+
+ v2s32 getVector2i(Property prop) const
{
const auto &val = properties[prop];
FATAL_ERROR_IF(val.empty(), "Unexpected missing property");
- irr::core::vector2d<s32> vec;
- parseVector2i(val, &vec);
- return vec;
+ v2f32 vec;
+ parseVector2f(val, &vec);
+ return v2s32(vec.X, vec.Y);
}
gui::IGUIFont *getFont() const
@@ -432,22 +451,20 @@ private:
return true;
}
- bool parseVector2i(const std::string &value, irr::core::vector2d<s32> *parsed_vec) const
+ bool parseVector2f(const std::string &value, v2f32 *parsed_vec) const
{
- irr::core::vector2d<s32> vec;
+ v2f32 vec;
std::vector<std::string> v_vector = split(value, ',');
if (v_vector.size() == 1) {
- s32 x = stoi(v_vector[0]);
+ f32 x = stof(v_vector[0]);
vec.X = x;
vec.Y = x;
} else if (v_vector.size() == 2) {
- s32 x = stoi(v_vector[0]);
- s32 y = stoi(v_vector[1]);
- vec.X = x;
- vec.Y = y;
+ vec.X = stof(v_vector[0]);
+ vec.Y = stof(v_vector[1]);
} else {
- warningstream << "Invalid vector2d string format: \"" << value
+ warningstream << "Invalid 2d vector string format: \"" << value
<< "\"" << std::endl;
return false;
}
diff --git a/src/gui/cheatMenu.cpp b/src/gui/cheatMenu.cpp
index 7687f10d9..31acfb780 100644
--- a/src/gui/cheatMenu.cpp
+++ b/src/gui/cheatMenu.cpp
@@ -30,7 +30,7 @@ FontMode CheatMenu::fontStringToEnum(std::string str)
else if (str == "FM_Mono")
return FM_Mono;
else if (str == "FM_Fallback")
- return FM_Fallback;
+ return _FM_Fallback;
else if (str == "FM_Simple")
return FM_Simple;
else if (str == "FM_SimpleMono")
diff --git a/src/gui/guiButton.cpp b/src/gui/guiButton.cpp
index b98e5de82..d6dbddf54 100644
--- a/src/gui/guiButton.cpp
+++ b/src/gui/guiButton.cpp
@@ -506,6 +506,13 @@ video::SColor GUIButton::getOverrideColor() const
return OverrideColor;
}
+#if IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR > 8
+video::SColor GUIButton::getActiveColor() const
+{
+ return video::SColor(0,0,0,0); // unused?
+}
+#endif
+
void GUIButton::enableOverrideColor(bool enable)
{
OverrideColorEnabled = enable;
diff --git a/src/gui/guiButton.h b/src/gui/guiButton.h
index 4e1b04aac..834405f51 100644
--- a/src/gui/guiButton.h
+++ b/src/gui/guiButton.h
@@ -69,6 +69,12 @@ using namespace irr;
class ISimpleTextureSource;
+#if (IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR <= 8)
+#define OVERRIDE_19
+#else
+#define OVERRIDE_19 override
+#endif
+
class GUIButton : public gui::IGUIButton
{
public:
@@ -97,22 +103,27 @@ public:
virtual gui::IGUIFont* getActiveFont() const override;
//! Sets another color for the button text.
- virtual void setOverrideColor(video::SColor color);
+ virtual void setOverrideColor(video::SColor color) OVERRIDE_19;
//! Gets the override color
- virtual video::SColor getOverrideColor(void) const;
+ virtual video::SColor getOverrideColor(void) const OVERRIDE_19;
+
+ #if IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR > 8
+ //! Gets the currently used text color
+ virtual video::SColor getActiveColor() const override;
+ #endif
//! Sets if the button text should use the override color or the color in the gui skin.
- virtual void enableOverrideColor(bool enable);
+ virtual void enableOverrideColor(bool enable) OVERRIDE_19;
//! Checks if an override color is enabled
- virtual bool isOverrideColorEnabled(void) const;
+ virtual bool isOverrideColorEnabled(void) const OVERRIDE_19;
// PATCH
//! Sets an image which should be displayed on the button when it is in the given state.
virtual void setImage(gui::EGUI_BUTTON_IMAGE_STATE state,
video::ITexture* image=nullptr,
- const core::rect<s32>& sourceRect=core::rect<s32>(0,0,0,0));
+ const core::rect<s32>& sourceRect=core::rect<s32>(0,0,0,0)) OVERRIDE_19;
//! Sets an image which should be displayed on the button when it is in normal state.
virtual void setImage(video::ITexture* image=nullptr) override;
@@ -141,7 +152,7 @@ public:
*/
virtual void setSprite(gui::EGUI_BUTTON_STATE state, s32 index,
video::SColor color=video::SColor(255,255,255,255),
- bool loop=false, bool scale=false);
+ bool loop=false, bool scale=false) OVERRIDE_19;
#if (IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR <= 8)
void setSprite(gui::EGUI_BUTTON_STATE state, s32 index, video::SColor color, bool loop) override {
@@ -150,16 +161,16 @@ public:
#endif
//! Get the sprite-index for the given state or -1 when no sprite is set
- virtual s32 getSpriteIndex(gui::EGUI_BUTTON_STATE state) const;
+ virtual s32 getSpriteIndex(gui::EGUI_BUTTON_STATE state) const OVERRIDE_19;
//! Get the sprite color for the given state. Color is only used when a sprite is set.
- virtual video::SColor getSpriteColor(gui::EGUI_BUTTON_STATE state) const;
+ virtual video::SColor getSpriteColor(gui::EGUI_BUTTON_STATE state) const OVERRIDE_19;
//! Returns if the sprite in the given state does loop
- virtual bool getSpriteLoop(gui::EGUI_BUTTON_STATE state) const;
+ virtual bool getSpriteLoop(gui::EGUI_BUTTON_STATE state) const OVERRIDE_19;
//! Returns if the sprite in the given state is scaled
- virtual bool getSpriteScale(gui::EGUI_BUTTON_STATE state) const;
+ virtual bool getSpriteScale(gui::EGUI_BUTTON_STATE state) const OVERRIDE_19;
//! Sets if the button should behave like a push button. Which means it
//! can be in two states: Normal or Pressed. With a click on the button,
@@ -199,13 +210,13 @@ public:
virtual bool isScalingImage() const override;
//! Get if the shift key was pressed in last EGET_BUTTON_CLICKED event
- virtual bool getClickShiftState() const
+ virtual bool getClickShiftState() const OVERRIDE_19
{
return ClickShiftState;
}
//! Get if the control key was pressed in last EGET_BUTTON_CLICKED event
- virtual bool getClickControlState() const
+ virtual bool getClickControlState() const OVERRIDE_19
{
return ClickControlState;
}
diff --git a/src/gui/guiButtonItemImage.cpp b/src/gui/guiButtonItemImage.cpp
index d8b9042ac..d9ab4b935 100644
--- a/src/gui/guiButtonItemImage.cpp
+++ b/src/gui/guiButtonItemImage.cpp
@@ -30,7 +30,7 @@ using namespace gui;
GUIButtonItemImage::GUIButtonItemImage(gui::IGUIEnvironment *environment,
gui::IGUIElement *parent, s32 id, core::rect<s32> rectangle,
- ISimpleTextureSource *tsrc, std::string item, Client *client,
+ ISimpleTextureSource *tsrc, const std::string &item, Client *client,
bool noclip)
: GUIButton (environment, parent, id, rectangle, tsrc, noclip)
{
@@ -39,13 +39,12 @@ GUIButtonItemImage::GUIButtonItemImage(gui::IGUIEnvironment *environment,
item, getActiveFont(), client);
sendToBack(m_image);
- m_item_name = item;
m_client = client;
}
GUIButtonItemImage *GUIButtonItemImage::addButton(IGUIEnvironment *environment,
const core::rect<s32> &rectangle, ISimpleTextureSource *tsrc,
- IGUIElement *parent, s32 id, const wchar_t *text, std::string item,
+ IGUIElement *parent, s32 id, const wchar_t *text, const std::string &item,
Client *client)
{
GUIButtonItemImage *button = new GUIButtonItemImage(environment,
diff --git a/src/gui/guiButtonItemImage.h b/src/gui/guiButtonItemImage.h
index aad923bda..205e957a7 100644
--- a/src/gui/guiButtonItemImage.h
+++ b/src/gui/guiButtonItemImage.h
@@ -33,16 +33,15 @@ public:
//! constructor
GUIButtonItemImage(gui::IGUIEnvironment *environment, gui::IGUIElement *parent,
s32 id, core::rect<s32> rectangle, ISimpleTextureSource *tsrc,
- std::string item, Client *client, bool noclip = false);
+ const std::string &item, Client *client, bool noclip = false);
//! Do not drop returned handle
static GUIButtonItemImage *addButton(gui::IGUIEnvironment *environment,
const core::rect<s32> &rectangle, ISimpleTextureSource *tsrc,
- IGUIElement *parent, s32 id, const wchar_t *text, std::string item,
- Client *client);
+ IGUIElement *parent, s32 id, const wchar_t *text,
+ const std::string &item, Client *client);
private:
- std::string m_item_name;
Client *m_client;
GUIItemImage *m_image;
};
diff --git a/src/gui/guiChatConsole.cpp b/src/gui/guiChatConsole.cpp
index ef471106d..baaaea5e8 100644
--- a/src/gui/guiChatConsole.cpp
+++ b/src/gui/guiChatConsole.cpp
@@ -17,6 +17,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
+#include "IrrCompileConfig.h"
#include "guiChatConsole.h"
#include "chat.h"
#include "client/client.h"
@@ -326,7 +327,6 @@ void GUIChatConsole::drawText()
tmp->draw(
fragment.text,
destrect,
- video::SColor(255, 255, 255, 255),
false,
false,
&AbsoluteClippingRect);
@@ -607,13 +607,7 @@ bool GUIChatConsole::OnEvent(const SEvent& event)
prompt.nickCompletion(names, backwards);
return true;
} else if (!iswcntrl(event.KeyInput.Char) && !event.KeyInput.Control) {
- #if defined(__linux__) && (IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR < 9)
- wchar_t wc = L'_';
- mbtowc( &wc, (char *) &event.KeyInput.Char, sizeof(event.KeyInput.Char) );
- prompt.input(wc);
- #else
- prompt.input(event.KeyInput.Char);
- #endif
+ prompt.input(event.KeyInput.Char);
return true;
}
}
@@ -625,6 +619,13 @@ bool GUIChatConsole::OnEvent(const SEvent& event)
m_chat_backend->scroll(rows);
}
}
+#if (IRRLICHT_VERSION_MT_REVISION >= 2)
+ else if(event.EventType == EET_STRING_INPUT_EVENT)
+ {
+ prompt.input(std::wstring(event.StringInput.Str->c_str()));
+ return true;
+ }
+#endif
return Parent ? Parent->OnEvent(event) : false;
}
diff --git a/src/gui/guiChatConsole.h b/src/gui/guiChatConsole.h
index 204f9f9cc..1152f2b2d 100644
--- a/src/gui/guiChatConsole.h
+++ b/src/gui/guiChatConsole.h
@@ -68,12 +68,12 @@ public:
// Irrlicht draw method
virtual void draw();
- bool canTakeFocus(gui::IGUIElement* element) { return false; }
-
virtual bool OnEvent(const SEvent& event);
virtual void setVisible(bool visible);
+ virtual bool acceptsIME() { return true; }
+
private:
void reformatConsole();
void recalculateConsolePosition();
diff --git a/src/gui/guiConfirmRegistration.cpp b/src/gui/guiConfirmRegistration.cpp
index 020a2796a..4ca9a64ed 100644
--- a/src/gui/guiConfirmRegistration.cpp
+++ b/src/gui/guiConfirmRegistration.cpp
@@ -25,7 +25,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <IGUIButton.h>
#include <IGUIStaticText.h>
#include <IGUIFont.h>
-#include "intlGUIEditBox.h"
+#include "guiEditBoxWithScrollbar.h"
#include "porting.h"
#include "gettext.h"
@@ -109,10 +109,9 @@ void GUIConfirmRegistration::regenerateGui(v2u32 screensize)
porting::mt_snprintf(info_text_buf, sizeof(info_text_buf),
info_text_template.c_str(), m_playername.c_str());
- wchar_t *info_text_buf_wide = utf8_to_wide_c(info_text_buf);
- gui::IGUIEditBox *e = new gui::intlGUIEditBox(info_text_buf_wide, true,
- Environment, this, ID_intotext, rect2, false, true);
- delete[] info_text_buf_wide;
+ std::wstring info_text_w = utf8_to_wide(info_text_buf);
+ gui::IGUIEditBox *e = new GUIEditBoxWithScrollBar(info_text_w.c_str(),
+ true, Environment, this, ID_intotext, rect2, false, true);
e->drop();
e->setMultiLine(true);
e->setWordWrap(true);
@@ -192,8 +191,7 @@ void GUIConfirmRegistration::acceptInput()
bool GUIConfirmRegistration::processInput()
{
- std::wstring m_password_ws = narrow_to_wide(m_password);
- if (m_password_ws != m_pass_confirm) {
+ if (utf8_to_wide(m_password) != m_pass_confirm) {
gui::IGUIElement *e = getElementFromId(ID_message);
if (e)
e->setVisible(true);
diff --git a/src/gui/guiEditBox.cpp b/src/gui/guiEditBox.cpp
index 11d080be9..ba548aa2d 100644
--- a/src/gui/guiEditBox.cpp
+++ b/src/gui/guiEditBox.cpp
@@ -19,6 +19,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "guiEditBox.h"
+#include "IrrCompileConfig.h"
#include "IGUISkin.h"
#include "IGUIEnvironment.h"
#include "IGUIFont.h"
@@ -208,35 +209,19 @@ bool GUIEditBox::OnEvent(const SEvent &event)
}
}
break;
- case EET_KEY_INPUT_EVENT: {
-#if (defined(__linux__) || defined(__FreeBSD__)) || defined(__DragonFly__)
- // ################################################################
- // ValkaTR:
- // This part is the difference from the original intlGUIEditBox
- // It converts UTF-8 character into a UCS-2 (wchar_t)
- wchar_t wc = L'_';
- mbtowc(&wc, (char *)&event.KeyInput.Char,
- sizeof(event.KeyInput.Char));
-
- // printf( "char: %lc (%u) \r\n", wc, wc );
-
- SEvent irrevent(event);
- irrevent.KeyInput.Char = wc;
- // ################################################################
-
- if (processKey(irrevent))
- return true;
-#else
+ case EET_KEY_INPUT_EVENT:
if (processKey(event))
return true;
-#endif // defined(linux)
-
break;
- }
case EET_MOUSE_INPUT_EVENT:
if (processMouse(event))
return true;
break;
+#if (IRRLICHT_VERSION_MT_REVISION >= 2)
+ case EET_STRING_INPUT_EVENT:
+ inputString(*event.StringInput.Str);
+ return true;
+#endif
default:
break;
}
@@ -689,6 +674,51 @@ bool GUIEditBox::onKeyDelete(const SEvent &event, s32 &mark_begin, s32 &mark_end
return true;
}
+void GUIEditBox::inputChar(wchar_t c)
+{
+ if (c == 0)
+ return;
+ core::stringw s(&c, 1);
+ inputString(s);
+}
+
+void GUIEditBox::inputString(const core::stringw &str)
+{
+ if (!isEnabled() || !m_writable)
+ return;
+
+ u32 len = str.size();
+ if (Text.size()+len <= m_max || m_max == 0) {
+ core::stringw s;
+ if (m_mark_begin != m_mark_end) {
+ // replace marked text
+ s32 real_begin = m_mark_begin < m_mark_end ? m_mark_begin : m_mark_end;
+ s32 real_end = m_mark_begin < m_mark_end ? m_mark_end : m_mark_begin;
+
+ s = Text.subString(0, real_begin);
+ s.append(str);
+ s.append(Text.subString(real_end, Text.size() - real_end));
+ Text = s;
+ m_cursor_pos = real_begin + len;
+ } else {
+ // append string
+ s = Text.subString(0, m_cursor_pos);
+ s.append(str);
+ s.append(Text.subString(m_cursor_pos,
+ Text.size() - m_cursor_pos));
+ Text = s;
+ m_cursor_pos += len;
+ }
+
+ m_blink_start_time = porting::getTimeMs();
+ setTextMarkers(0, 0);
+ }
+
+ breakText();
+ sendGuiEvent(EGET_EDITBOX_CHANGED);
+ calculateScrollPos();
+}
+
bool GUIEditBox::processMouse(const SEvent &event)
{
switch (event.MouseInput.Event) {
@@ -747,6 +777,7 @@ bool GUIEditBox::processMouse(const SEvent &event)
s32 pos = m_vscrollbar->getPos();
s32 step = m_vscrollbar->getSmallStep();
m_vscrollbar->setPos(pos - event.MouseInput.Wheel * step);
+ return true;
}
break;
default:
@@ -817,3 +848,54 @@ void GUIEditBox::updateVScrollBar()
}
}
}
+
+void GUIEditBox::deserializeAttributes(
+ io::IAttributes *in, io::SAttributeReadWriteOptions *options = 0)
+{
+ IGUIEditBox::deserializeAttributes(in, options);
+
+ setOverrideColor(in->getAttributeAsColor("OverrideColor"));
+ enableOverrideColor(in->getAttributeAsBool("OverrideColorEnabled"));
+ setMax(in->getAttributeAsInt("MaxChars"));
+ setWordWrap(in->getAttributeAsBool("WordWrap"));
+ setMultiLine(in->getAttributeAsBool("MultiLine"));
+ setAutoScroll(in->getAttributeAsBool("AutoScroll"));
+ core::stringw ch = in->getAttributeAsStringW("PasswordChar");
+
+ if (ch.empty())
+ setPasswordBox(in->getAttributeAsBool("PasswordBox"));
+ else
+ setPasswordBox(in->getAttributeAsBool("PasswordBox"), ch[0]);
+
+ setTextAlignment((EGUI_ALIGNMENT)in->getAttributeAsEnumeration(
+ "HTextAlign", GUIAlignmentNames),
+ (EGUI_ALIGNMENT)in->getAttributeAsEnumeration(
+ "VTextAlign", GUIAlignmentNames));
+
+ setWritable(in->getAttributeAsBool("Writable"));
+ // setOverrideFont(in->getAttributeAsFont("OverrideFont"));
+}
+
+//! Writes attributes of the element.
+void GUIEditBox::serializeAttributes(
+ io::IAttributes *out, io::SAttributeReadWriteOptions *options = 0) const
+{
+ // IGUIEditBox::serializeAttributes(out,options);
+
+ out->addBool("OverrideColorEnabled", m_override_color_enabled);
+ out->addColor("OverrideColor", m_override_color);
+ // out->addFont("OverrideFont",m_override_font);
+ out->addInt("MaxChars", m_max);
+ out->addBool("WordWrap", m_word_wrap);
+ out->addBool("MultiLine", m_multiline);
+ out->addBool("AutoScroll", m_autoscroll);
+ out->addBool("PasswordBox", m_passwordbox);
+ core::stringw ch = L" ";
+ ch[0] = m_passwordchar;
+ out->addString("PasswordChar", ch.c_str());
+ out->addEnum("HTextAlign", m_halign, GUIAlignmentNames);
+ out->addEnum("VTextAlign", m_valign, GUIAlignmentNames);
+ out->addBool("Writable", m_writable);
+
+ IGUIEditBox::serializeAttributes(out, options);
+}
diff --git a/src/gui/guiEditBox.h b/src/gui/guiEditBox.h
index 3e41c7e51..2a5c911bc 100644
--- a/src/gui/guiEditBox.h
+++ b/src/gui/guiEditBox.h
@@ -19,6 +19,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#pragma once
+#include "irrlichttypes.h"
#include "IGUIEditBox.h"
#include "IOSOperator.h"
#include "guiScrollBar.h"
@@ -129,6 +130,16 @@ public:
//! called if an event happened.
virtual bool OnEvent(const SEvent &event);
+ //! Writes attributes of the element.
+ virtual void serializeAttributes(io::IAttributes *out,
+ io::SAttributeReadWriteOptions *options) const;
+
+ //! Reads attributes of the element
+ virtual void deserializeAttributes(
+ io::IAttributes *in, io::SAttributeReadWriteOptions *options);
+
+ virtual bool acceptsIME() { return isEnabled() && m_writable; };
+
protected:
virtual void breakText() = 0;
@@ -147,7 +158,8 @@ protected:
virtual s32 getCursorPos(s32 x, s32 y) = 0;
bool processKey(const SEvent &event);
- virtual void inputChar(wchar_t c) = 0;
+ virtual void inputString(const core::stringw &str);
+ virtual void inputChar(wchar_t c);
//! returns the line number that the cursor is on
s32 getLineFromPos(s32 pos);
diff --git a/src/gui/guiEditBoxWithScrollbar.cpp b/src/gui/guiEditBoxWithScrollbar.cpp
index 707dbb7db..c72070787 100644
--- a/src/gui/guiEditBoxWithScrollbar.cpp
+++ b/src/gui/guiEditBoxWithScrollbar.cpp
@@ -481,44 +481,6 @@ void GUIEditBoxWithScrollBar::setTextRect(s32 line)
m_current_text_rect += m_frame_rect.UpperLeftCorner;
}
-
-void GUIEditBoxWithScrollBar::inputChar(wchar_t c)
-{
- if (!isEnabled())
- return;
-
- if (c != 0) {
- if (Text.size() < m_max || m_max == 0) {
- core::stringw s;
-
- if (m_mark_begin != m_mark_end) {
- // replace marked text
- const s32 realmbgn = m_mark_begin < m_mark_end ? m_mark_begin : m_mark_end;
- const s32 realmend = m_mark_begin < m_mark_end ? m_mark_end : m_mark_begin;
-
- s = Text.subString(0, realmbgn);
- s.append(c);
- s.append(Text.subString(realmend, Text.size() - realmend));
- Text = s;
- m_cursor_pos = realmbgn + 1;
- } else {
- // add new character
- s = Text.subString(0, m_cursor_pos);
- s.append(c);
- s.append(Text.subString(m_cursor_pos, Text.size() - m_cursor_pos));
- Text = s;
- ++m_cursor_pos;
- }
-
- m_blink_start_time = porting::getTimeMs();
- setTextMarkers(0, 0);
- }
- }
- breakText();
- calculateScrollPos();
- sendGuiEvent(EGET_EDITBOX_CHANGED);
-}
-
// calculate autoscroll
void GUIEditBoxWithScrollBar::calculateScrollPos()
{
@@ -682,54 +644,21 @@ void GUIEditBoxWithScrollBar::setBackgroundColor(const video::SColor &bg_color)
//! Writes attributes of the element.
void GUIEditBoxWithScrollBar::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options = 0) const
{
- // IGUIEditBox::serializeAttributes(out,options);
-
out->addBool("Border", m_border);
out->addBool("Background", m_background);
- out->addBool("OverrideColorEnabled", m_override_color_enabled);
- out->addColor("OverrideColor", m_override_color);
// out->addFont("OverrideFont", OverrideFont);
- out->addInt("MaxChars", m_max);
- out->addBool("WordWrap", m_word_wrap);
- out->addBool("MultiLine", m_multiline);
- out->addBool("AutoScroll", m_autoscroll);
- out->addBool("PasswordBox", m_passwordbox);
- core::stringw ch = L" ";
- ch[0] = m_passwordchar;
- out->addString("PasswordChar", ch.c_str());
- out->addEnum("HTextAlign", m_halign, GUIAlignmentNames);
- out->addEnum("VTextAlign", m_valign, GUIAlignmentNames);
- out->addBool("Writable", m_writable);
-
- IGUIEditBox::serializeAttributes(out, options);
+
+ GUIEditBox::serializeAttributes(out, options);
}
//! Reads attributes of the element
void GUIEditBoxWithScrollBar::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options = 0)
{
- IGUIEditBox::deserializeAttributes(in, options);
+ GUIEditBox::deserializeAttributes(in, options);
setDrawBorder(in->getAttributeAsBool("Border"));
setDrawBackground(in->getAttributeAsBool("Background"));
- setOverrideColor(in->getAttributeAsColor("OverrideColor"));
- enableOverrideColor(in->getAttributeAsBool("OverrideColorEnabled"));
- setMax(in->getAttributeAsInt("MaxChars"));
- setWordWrap(in->getAttributeAsBool("WordWrap"));
- setMultiLine(in->getAttributeAsBool("MultiLine"));
- setAutoScroll(in->getAttributeAsBool("AutoScroll"));
- core::stringw ch = in->getAttributeAsStringW("PasswordChar");
-
- if (!ch.size())
- setPasswordBox(in->getAttributeAsBool("PasswordBox"));
- else
- setPasswordBox(in->getAttributeAsBool("PasswordBox"), ch[0]);
-
- setTextAlignment((EGUI_ALIGNMENT)in->getAttributeAsEnumeration("HTextAlign", GUIAlignmentNames),
- (EGUI_ALIGNMENT)in->getAttributeAsEnumeration("VTextAlign", GUIAlignmentNames));
-
- // setOverrideFont(in->getAttributeAsFont("OverrideFont"));
- setWritable(in->getAttributeAsBool("Writable"));
}
bool GUIEditBoxWithScrollBar::isDrawBackgroundEnabled() const { return false; }
diff --git a/src/gui/guiEditBoxWithScrollbar.h b/src/gui/guiEditBoxWithScrollbar.h
index b863ee614..3f7450dcb 100644
--- a/src/gui/guiEditBoxWithScrollbar.h
+++ b/src/gui/guiEditBoxWithScrollbar.h
@@ -49,8 +49,6 @@ protected:
virtual void breakText();
//! sets the area of the given line
virtual void setTextRect(s32 line);
- //! adds a letter to the edit box
- virtual void inputChar(wchar_t c);
//! calculates the current scroll position
void calculateScrollPos();
//! calculated the FrameRect
diff --git a/src/gui/guiEngine.cpp b/src/gui/guiEngine.cpp
index c5ad5c323..694baf482 100644
--- a/src/gui/guiEngine.cpp
+++ b/src/gui/guiEngine.cpp
@@ -75,8 +75,6 @@ video::ITexture *MenuTextureSource::getTexture(const std::string &name, u32 *id)
if (name.empty())
return NULL;
- m_to_delete.insert(name);
-
#if ENABLE_GLES
video::ITexture *retval = m_driver->findTexture(name.c_str());
if (retval)
@@ -88,6 +86,7 @@ video::ITexture *MenuTextureSource::getTexture(const std::string &name, u32 *id)
image = Align2Npot2(image, m_driver);
retval = m_driver->addTexture(name.c_str(), image);
+ m_to_delete.insert(name);
image->drop();
return retval;
#else
@@ -122,12 +121,14 @@ void MenuMusicFetcher::fetchSounds(const std::string &name,
/******************************************************************************/
GUIEngine::GUIEngine(JoystickController *joystick,
gui::IGUIElement *parent,
+ RenderingEngine *rendering_engine,
IMenuManager *menumgr,
MainMenuData *data,
bool &kill) :
+ m_rendering_engine(rendering_engine),
m_parent(parent),
m_menumanager(menumgr),
- m_smgr(RenderingEngine::get_scene_manager()),
+ m_smgr(rendering_engine->get_scene_manager()),
m_data(data),
m_kill(kill)
{
@@ -139,7 +140,7 @@ GUIEngine::GUIEngine(JoystickController *joystick,
m_buttonhandler = new TextDestGuiEngine(this);
//create texture source
- m_texture_source = new MenuTextureSource(RenderingEngine::get_video_driver());
+ m_texture_source = new MenuTextureSource(rendering_engine->get_video_driver());
//create soundmanager
MenuMusicFetcher soundfetcher;
@@ -157,7 +158,7 @@ GUIEngine::GUIEngine(JoystickController *joystick,
g_fontengine->getTextHeight());
rect += v2s32(4, 0);
- m_irr_toplefttext = gui::StaticText::add(RenderingEngine::get_gui_env(),
+ m_irr_toplefttext = gui::StaticText::add(rendering_engine->get_gui_env(),
m_toplefttext, rect, false, true, 0, -1);
//create formspecsource
@@ -169,6 +170,7 @@ GUIEngine::GUIEngine(JoystickController *joystick,
-1,
m_menumanager,
NULL /* &client */,
+ m_rendering_engine->get_gui_env(),
m_texture_source,
m_sound_manager,
m_formspecgui,
@@ -233,7 +235,7 @@ void GUIEngine::run()
{
// Always create clouds because they may or may not be
// needed based on the game selected
- video::IVideoDriver *driver = RenderingEngine::get_video_driver();
+ video::IVideoDriver *driver = m_rendering_engine->get_video_driver();
cloudInit();
@@ -260,10 +262,10 @@ void GUIEngine::run()
fog_pixelfog, fog_rangefog);
}
- while (RenderingEngine::run() && (!m_startgame) && (!m_kill)) {
+ while (m_rendering_engine->run() && (!m_startgame) && (!m_kill)) {
const irr::core::dimension2d<u32> &current_screen_size =
- RenderingEngine::get_video_driver()->getScreenSize();
+ m_rendering_engine->get_video_driver()->getScreenSize();
// Verify if window size has changed and save it if it's the case
// Ensure evaluating settings->getBool after verifying screensize
// First condition is cheaper
@@ -294,11 +296,11 @@ void GUIEngine::run()
drawHeader(driver);
drawFooter(driver);
- RenderingEngine::get_gui_env()->drawAll();
+ m_rendering_engine->get_gui_env()->drawAll();
driver->endScene();
- IrrlichtDevice *device = RenderingEngine::get_raw_device();
+ IrrlichtDevice *device = m_rendering_engine->get_raw_device();
u32 frametime_min = 1000 / (device->isWindowFocused()
? g_settings->getFloat("fps_max")
: g_settings->getFloat("fps_max_unfocused"));
@@ -331,7 +333,7 @@ GUIEngine::~GUIEngine()
//clean up texture pointers
for (image_definition &texture : m_textures) {
if (texture.texture)
- RenderingEngine::get_video_driver()->removeTexture(texture.texture);
+ m_rendering_engine->get_video_driver()->removeTexture(texture.texture);
}
delete m_texture_source;
@@ -351,13 +353,13 @@ void GUIEngine::cloudInit()
v3f(0,0,0), v3f(0, 60, 100));
m_cloud.camera->setFarValue(10000);
- m_cloud.lasttime = RenderingEngine::get_timer_time();
+ m_cloud.lasttime = m_rendering_engine->get_timer_time();
}
/******************************************************************************/
void GUIEngine::cloudPreProcess()
{
- u32 time = RenderingEngine::get_timer_time();
+ u32 time = m_rendering_engine->get_timer_time();
if(time > m_cloud.lasttime)
m_cloud.dtime = (time - m_cloud.lasttime) / 1000.0;
@@ -378,7 +380,7 @@ void GUIEngine::cloudPostProcess(u32 frametime_min, IrrlichtDevice *device)
u32 busytime_u32;
// not using getRealTime is necessary for wine
- u32 time = RenderingEngine::get_timer_time();
+ u32 time = m_rendering_engine->get_timer_time();
if(time > m_cloud.lasttime)
busytime_u32 = time - m_cloud.lasttime;
else
@@ -486,8 +488,6 @@ void GUIEngine::drawHeader(video::IVideoDriver *driver)
splashrect += v2s32((screensize.Width/2)-(splashsize.X/2),
((free_space/2)-splashsize.Y/2)+10);
- video::SColor bgcolor(255,50,50,50);
-
draw2DImageFilterScaled(driver, texture, splashrect,
core::rect<s32>(core::position2d<s32>(0,0),
core::dimension2di(texture->getOriginalSize())),
@@ -531,7 +531,7 @@ void GUIEngine::drawFooter(video::IVideoDriver *driver)
bool GUIEngine::setTexture(texture_layer layer, const std::string &texturepath,
bool tile_image, unsigned int minsize)
{
- video::IVideoDriver *driver = RenderingEngine::get_video_driver();
+ video::IVideoDriver *driver = m_rendering_engine->get_video_driver();
if (m_textures[layer].texture) {
driver->removeTexture(m_textures[layer].texture);
@@ -598,7 +598,7 @@ void GUIEngine::updateTopLeftTextSize()
rect += v2s32(4, 0);
m_irr_toplefttext->remove();
- m_irr_toplefttext = gui::StaticText::add(RenderingEngine::get_gui_env(),
+ m_irr_toplefttext = gui::StaticText::add(m_rendering_engine->get_gui_env(),
m_toplefttext, rect, false, true, 0, -1);
}
diff --git a/src/gui/guiEngine.h b/src/gui/guiEngine.h
index eef1ad8aa..70abce181 100644
--- a/src/gui/guiEngine.h
+++ b/src/gui/guiEngine.h
@@ -50,6 +50,7 @@ struct image_definition {
/* forward declarations */
/******************************************************************************/
class GUIEngine;
+class RenderingEngine;
class MainMenuScripting;
class Clouds;
struct MainMenuData;
@@ -150,6 +151,7 @@ public:
*/
GUIEngine(JoystickController *joystick,
gui::IGUIElement *parent,
+ RenderingEngine *rendering_engine,
IMenuManager *menumgr,
MainMenuData *data,
bool &kill);
@@ -188,6 +190,7 @@ private:
/** update size of topleftext element */
void updateTopLeftTextSize();
+ RenderingEngine *m_rendering_engine = nullptr;
/** parent gui element */
gui::IGUIElement *m_parent = nullptr;
/** manager to add menus to */
diff --git a/src/gui/guiFormSpecMenu.cpp b/src/gui/guiFormSpecMenu.cpp
index 973fc60a8..c6435804f 100644
--- a/src/gui/guiFormSpecMenu.cpp
+++ b/src/gui/guiFormSpecMenu.cpp
@@ -19,6 +19,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <cstdlib>
+#include <cmath>
#include <algorithm>
#include <iterator>
#include <limits>
@@ -64,7 +65,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "guiInventoryList.h"
#include "guiItemImage.h"
#include "guiScrollContainer.h"
-#include "intlGUIEditBox.h"
#include "guiHyperText.h"
#include "guiScene.h"
@@ -96,10 +96,10 @@ inline u32 clamp_u8(s32 value)
GUIFormSpecMenu::GUIFormSpecMenu(JoystickController *joystick,
gui::IGUIElement *parent, s32 id, IMenuManager *menumgr,
- Client *client, ISimpleTextureSource *tsrc, ISoundManager *sound_manager,
- IFormSource *fsrc, TextDest *tdst,
+ Client *client, gui::IGUIEnvironment *guienv, ISimpleTextureSource *tsrc,
+ ISoundManager *sound_manager, IFormSource *fsrc, TextDest *tdst,
const std::string &formspecPrepend, bool remap_dbl_click):
- GUIModalMenu(RenderingEngine::get_gui_env(), parent, id, menumgr, remap_dbl_click),
+ GUIModalMenu(guienv, parent, id, menumgr, remap_dbl_click),
m_invmgr(client),
m_tsrc(tsrc),
m_sound_manager(sound_manager),
@@ -145,12 +145,12 @@ GUIFormSpecMenu::~GUIFormSpecMenu()
}
void GUIFormSpecMenu::create(GUIFormSpecMenu *&cur_formspec, Client *client,
- JoystickController *joystick, IFormSource *fs_src, TextDest *txt_dest,
- const std::string &formspecPrepend, ISoundManager *sound_manager)
+ gui::IGUIEnvironment *guienv, JoystickController *joystick, IFormSource *fs_src,
+ TextDest *txt_dest, const std::string &formspecPrepend, ISoundManager *sound_manager)
{
if (cur_formspec == nullptr) {
cur_formspec = new GUIFormSpecMenu(joystick, guiroot, -1, &g_menumgr,
- client, client->getTextureSource(), sound_manager, fs_src,
+ client, guienv, client->getTextureSource(), sound_manager, fs_src,
txt_dest, formspecPrepend);
cur_formspec->doPause = false;
@@ -497,19 +497,39 @@ void GUIFormSpecMenu::parseList(parserData *data, const std::string &element)
3
);
- v2f32 slot_spacing = data->real_coordinates ?
- v2f32(imgsize.X * 1.25f, imgsize.Y * 1.25f) : spacing;
+ auto style = getDefaultStyleForElement("list", spec.fname);
- v2s32 pos = data->real_coordinates ? getRealCoordinateBasePos(v_pos)
- : getElementBasePos(&v_pos);
+ v2f32 slot_scale = style.getVector2f(StyleSpec::SIZE, v2f32(0, 0));
+ v2f32 slot_size(
+ slot_scale.X <= 0 ? imgsize.X : std::max<f32>(slot_scale.X * imgsize.X, 1),
+ slot_scale.Y <= 0 ? imgsize.Y : std::max<f32>(slot_scale.Y * imgsize.Y, 1)
+ );
+
+ v2f32 slot_spacing = style.getVector2f(StyleSpec::SPACING, v2f32(-1, -1));
+ v2f32 default_spacing = data->real_coordinates ?
+ v2f32(imgsize.X * 0.25f, imgsize.Y * 0.25f) :
+ v2f32(spacing.X - imgsize.X, spacing.Y - imgsize.Y);
+
+ slot_spacing.X = slot_spacing.X < 0 ? default_spacing.X :
+ imgsize.X * slot_spacing.X;
+ slot_spacing.Y = slot_spacing.Y < 0 ? default_spacing.Y :
+ imgsize.Y * slot_spacing.Y;
+
+ slot_spacing += slot_size;
+
+ v2s32 pos = data->real_coordinates ? getRealCoordinateBasePos(v_pos) :
+ getElementBasePos(&v_pos);
core::rect<s32> rect = core::rect<s32>(pos.X, pos.Y,
- pos.X + (geom.X - 1) * slot_spacing.X + imgsize.X,
- pos.Y + (geom.Y - 1) * slot_spacing.Y + imgsize.Y);
+ pos.X + (geom.X - 1) * slot_spacing.X + slot_size.X,
+ pos.Y + (geom.Y - 1) * slot_spacing.Y + slot_size.Y);
GUIInventoryList *e = new GUIInventoryList(Environment, data->current_parent,
- spec.fid, rect, m_invmgr, loc, listname, geom, start_i, imgsize,
- slot_spacing, this, data->inventorylist_options, m_font);
+ spec.fid, rect, m_invmgr, loc, listname, geom, start_i,
+ v2s32(slot_size.X, slot_size.Y), slot_spacing, this,
+ data->inventorylist_options, m_font);
+
+ e->setNotClipped(style.getBool(StyleSpec::NOCLIP, false));
m_inventorylists.push_back(e);
m_fields.push_back(spec);
@@ -907,7 +927,7 @@ void GUIFormSpecMenu::parseAnimatedImage(parserData *data, const std::string &el
core::rect<s32> rect = core::rect<s32>(pos, pos + geom);
- GUIAnimatedImage *e = new GUIAnimatedImage(Environment, this, spec.fid,
+ GUIAnimatedImage *e = new GUIAnimatedImage(Environment, data->current_parent, spec.fid,
rect, texture_name, frame_count, frame_duration, m_tsrc);
if (parts.size() >= 7)
@@ -1526,21 +1546,13 @@ void GUIFormSpecMenu::createTextField(parserData *data, FieldSpec &spec,
}
gui::IGUIEditBox *e = nullptr;
- static constexpr bool use_intl_edit_box = USE_FREETYPE &&
- IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR < 9;
-
- if (use_intl_edit_box && g_settings->getBool("freetype")) {
- e = new gui::intlGUIEditBox(spec.fdefault.c_str(), true, Environment,
- data->current_parent, spec.fid, rect, is_editable, is_multiline);
- } else {
- if (is_multiline) {
- e = new GUIEditBoxWithScrollBar(spec.fdefault.c_str(), true, Environment,
- data->current_parent, spec.fid, rect, is_editable, true);
- } else if (is_editable) {
- e = Environment->addEditBox(spec.fdefault.c_str(), rect, true,
- data->current_parent, spec.fid);
- e->grab();
- }
+ if (is_multiline) {
+ e = new GUIEditBoxWithScrollBar(spec.fdefault.c_str(), true, Environment,
+ data->current_parent, spec.fid, rect, is_editable, true);
+ } else if (is_editable) {
+ e = Environment->addEditBox(spec.fdefault.c_str(), rect, true,
+ data->current_parent, spec.fid);
+ e->grab();
}
auto style = getDefaultStyleForElement(is_multiline ? "textarea" : "field", spec.fname);
@@ -2725,7 +2737,7 @@ void GUIFormSpecMenu::parseModel(parserData *data, const std::string &element)
{
std::vector<std::string> parts = split(element, ';');
- if (parts.size() < 5 || (parts.size() > 9 &&
+ if (parts.size() < 5 || (parts.size() > 10 &&
m_formspec_version <= FORMSPEC_API_VERSION)) {
errorstream << "Invalid model element (" << parts.size() << "): '" << element
<< "'" << std::endl;
@@ -2733,8 +2745,8 @@ void GUIFormSpecMenu::parseModel(parserData *data, const std::string &element)
}
// Avoid length checks by resizing
- if (parts.size() < 9)
- parts.resize(9);
+ if (parts.size() < 10)
+ parts.resize(10);
std::vector<std::string> v_pos = split(parts[0], ',');
std::vector<std::string> v_geom = split(parts[1], ',');
@@ -2745,6 +2757,7 @@ void GUIFormSpecMenu::parseModel(parserData *data, const std::string &element)
bool inf_rotation = is_yes(parts[6]);
bool mousectrl = is_yes(parts[7]) || parts[7].empty(); // default true
std::vector<std::string> frame_loop = split(parts[8], ',');
+ std::string speed = unescape_string(parts[9]);
MY_CHECKPOS("model", 0);
MY_CHECKGEOM("model", 1);
@@ -2781,7 +2794,7 @@ void GUIFormSpecMenu::parseModel(parserData *data, const std::string &element)
core::rect<s32> rect(pos, pos + geom);
- GUIScene *e = new GUIScene(Environment, RenderingEngine::get_scene_manager(),
+ GUIScene *e = new GUIScene(Environment, m_client->getSceneManager(),
data->current_parent, rect, spec.fid);
auto meshnode = e->setMesh(mesh);
@@ -2804,6 +2817,7 @@ void GUIFormSpecMenu::parseModel(parserData *data, const std::string &element)
}
e->setFrameLoop(frame_loop_begin, frame_loop_end);
+ e->setAnimationSpeed(stof(speed));
auto style = getStyleForElement("model", spec.fname);
e->setStyles(style);
@@ -3505,8 +3519,6 @@ bool GUIFormSpecMenu::getAndroidUIInput()
GUIInventoryList::ItemSpec GUIFormSpecMenu::getItemAtPos(v2s32 p) const
{
- core::rect<s32> imgrect(0, 0, imgsize.X, imgsize.Y);
-
for (const GUIInventoryList *e : m_inventorylists) {
s32 item_index = e->getItemIndexAtPos(p);
if (item_index != -1)
@@ -3837,7 +3849,7 @@ ItemStack GUIFormSpecMenu::verifySelectedItem()
return ItemStack();
}
-void GUIFormSpecMenu::acceptInput(FormspecQuitMode quitmode=quit_mode_no)
+void GUIFormSpecMenu::acceptInput(FormspecQuitMode quitmode)
{
if(m_text_dst)
{
diff --git a/src/gui/guiFormSpecMenu.h b/src/gui/guiFormSpecMenu.h
index 37106cb65..926de66d5 100644
--- a/src/gui/guiFormSpecMenu.h
+++ b/src/gui/guiFormSpecMenu.h
@@ -152,6 +152,7 @@ public:
gui::IGUIElement* parent, s32 id,
IMenuManager *menumgr,
Client *client,
+ gui::IGUIEnvironment *guienv,
ISimpleTextureSource *tsrc,
ISoundManager *sound_manager,
IFormSource* fs_src,
@@ -162,8 +163,9 @@ public:
~GUIFormSpecMenu();
static void create(GUIFormSpecMenu *&cur_formspec, Client *client,
- JoystickController *joystick, IFormSource *fs_src, TextDest *txt_dest,
- const std::string &formspecPrepend, ISoundManager *sound_manager);
+ gui::IGUIEnvironment *guienv, JoystickController *joystick, IFormSource *fs_src,
+ TextDest *txt_dest, const std::string &formspecPrepend,
+ ISoundManager *sound_manager);
void setFormSpec(const std::string &formspec_string,
const InventoryLocation &current_inventory_location)
@@ -253,7 +255,7 @@ public:
void updateSelectedItem();
ItemStack verifySelectedItem();
- void acceptInput(FormspecQuitMode quitmode);
+ void acceptInput(FormspecQuitMode quitmode=quit_mode_no);
bool preprocessEvent(const SEvent& event);
bool OnEvent(const SEvent& event);
bool doPause;
diff --git a/src/gui/guiHyperText.cpp b/src/gui/guiHyperText.cpp
index 88931cdf9..ccfdcb81d 100644
--- a/src/gui/guiHyperText.cpp
+++ b/src/gui/guiHyperText.cpp
@@ -1088,7 +1088,7 @@ bool GUIHyperText::OnEvent(const SEvent &event)
if (event.MouseInput.Event == EMIE_MOUSE_MOVED)
checkHover(event.MouseInput.X, event.MouseInput.Y);
- if (event.MouseInput.Event == EMIE_MOUSE_WHEEL) {
+ if (event.MouseInput.Event == EMIE_MOUSE_WHEEL && m_vscrollbar->isVisible()) {
m_vscrollbar->setPos(m_vscrollbar->getPos() -
event.MouseInput.Wheel * m_vscrollbar->getSmallStep());
m_text_scrollpos.Y = -m_vscrollbar->getPos();
diff --git a/src/gui/guiInventoryList.cpp b/src/gui/guiInventoryList.cpp
index 58d7ae771..290ae40e7 100644
--- a/src/gui/guiInventoryList.cpp
+++ b/src/gui/guiInventoryList.cpp
@@ -101,8 +101,6 @@ void GUIInventoryList::draw()
&& m_invmgr->getInventory(selected_item->inventoryloc) == inv
&& selected_item->listname == m_listname
&& selected_item->i == item_i;
- core::rect<s32> clipped_rect(rect);
- clipped_rect.clipAgainst(AbsoluteClippingRect);
bool hovering = m_hovered_i == item_i;
ItemRotationKind rotation_kind = selected ? IT_ROT_SELECTED :
(hovering ? IT_ROT_HOVERED : IT_ROT_NONE);
diff --git a/src/gui/guiKeyChangeMenu.cpp b/src/gui/guiKeyChangeMenu.cpp
index a7270da06..719a4101a 100644
--- a/src/gui/guiKeyChangeMenu.cpp
+++ b/src/gui/guiKeyChangeMenu.cpp
@@ -46,7 +46,7 @@ enum
GUI_ID_KEY_BACKWARD_BUTTON,
GUI_ID_KEY_LEFT_BUTTON,
GUI_ID_KEY_RIGHT_BUTTON,
- GUI_ID_KEY_USE_BUTTON,
+ GUI_ID_KEY_AUX1_BUTTON,
GUI_ID_KEY_FLY_BUTTON,
GUI_ID_KEY_FAST_BUTTON,
GUI_ID_KEY_JUMP_BUTTON,
@@ -71,6 +71,7 @@ enum
GUI_ID_KEY_MINIMAP_BUTTON,
GUI_ID_KEY_SCREENSHOT_BUTTON,
GUI_ID_KEY_CHATLOG_BUTTON,
+ GUI_ID_KEY_BLOCK_BOUNDS_BUTTON,
GUI_ID_KEY_HUD_BUTTON,
GUI_ID_KEY_FOG_BUTTON,
GUI_ID_KEY_CHEAT_MENU_BUTTON,
@@ -187,7 +188,7 @@ void GUIKeyChangeMenu::regenerateGui(v2u32 screensize)
{
core::rect<s32> rect(0, 0, option_w, 30 * s);
rect += topleft + v2s32(option_x, option_y);
- const wchar_t *text = wgettext("\"Special\" = climb down");
+ const wchar_t *text = wgettext("\"Aux1\" = climb down");
Environment->addCheckBox(g_settings->getBool("aux1_descends"), rect, this,
GUI_ID_CB_AUX1_DESCENDS, text);
delete[] text;
@@ -258,7 +259,7 @@ bool GUIKeyChangeMenu::acceptInput()
{
for (key_setting *k : key_settings) {
std::string default_key;
- g_settings->getDefaultNoEx(k->setting_name, default_key);
+ Settings::getLayer(SL_DEFAULTS)->getNoEx(k->setting_name, default_key);
if (k->key.sym() != default_key)
g_settings->set(k->setting_name, k->key.sym());
@@ -422,47 +423,48 @@ void GUIKeyChangeMenu::add_key(int id, const wchar_t *button_name, const std::st
void GUIKeyChangeMenu::init_keys()
{
- this->add_key(GUI_ID_KEY_FORWARD_BUTTON, wgettext("Forward"), "keymap_forward");
- this->add_key(GUI_ID_KEY_BACKWARD_BUTTON, wgettext("Backward"), "keymap_backward");
- this->add_key(GUI_ID_KEY_LEFT_BUTTON, wgettext("Left"), "keymap_left");
- this->add_key(GUI_ID_KEY_RIGHT_BUTTON, wgettext("Right"), "keymap_right");
- this->add_key(GUI_ID_KEY_USE_BUTTON, wgettext("Special"), "keymap_special1");
- this->add_key(GUI_ID_KEY_JUMP_BUTTON, wgettext("Jump"), "keymap_jump");
- this->add_key(GUI_ID_KEY_SNEAK_BUTTON, wgettext("Sneak"), "keymap_sneak");
- this->add_key(GUI_ID_KEY_DROP_BUTTON, wgettext("Drop"), "keymap_drop");
- this->add_key(GUI_ID_KEY_INVENTORY_BUTTON, wgettext("Inventory"), "keymap_inventory");
- this->add_key(GUI_ID_KEY_ENDERCHEST_BUTTON,wgettext("Enderchest"), "keymap_enderchest");
- this->add_key(GUI_ID_KEY_HOTBAR_PREV_BUTTON,wgettext("Prev. item"), "keymap_hotbar_previous");
- this->add_key(GUI_ID_KEY_HOTBAR_NEXT_BUTTON,wgettext("Next item"), "keymap_hotbar_next");
- this->add_key(GUI_ID_KEY_ZOOM_BUTTON, wgettext("Zoom"), "keymap_zoom");
- this->add_key(GUI_ID_KEY_CAMERA_BUTTON, wgettext("Change camera"), "keymap_camera_mode");
- this->add_key(GUI_ID_KEY_MINIMAP_BUTTON, wgettext("Toggle minimap"), "keymap_minimap");
- this->add_key(GUI_ID_KEY_FLY_BUTTON, wgettext("Toggle fly"), "keymap_freemove");
- this->add_key(GUI_ID_KEY_PITCH_MOVE, wgettext("Toggle pitchmove"), "keymap_pitchmove");
- this->add_key(GUI_ID_KEY_FAST_BUTTON, wgettext("Toggle fast"), "keymap_fastmove");
- this->add_key(GUI_ID_KEY_NOCLIP_BUTTON, wgettext("Toggle noclip"), "keymap_noclip");
- this->add_key(GUI_ID_KEY_MUTE_BUTTON, wgettext("Mute"), "keymap_mute");
- this->add_key(GUI_ID_KEY_DEC_VOLUME_BUTTON,wgettext("Dec. volume"), "keymap_decrease_volume");
- this->add_key(GUI_ID_KEY_INC_VOLUME_BUTTON,wgettext("Inc. volume"), "keymap_increase_volume");
- this->add_key(GUI_ID_KEY_AUTOFWD_BUTTON, wgettext("Autoforward"), "keymap_autoforward");
- this->add_key(GUI_ID_KEY_CHAT_BUTTON, wgettext("Chat"), "keymap_chat");
- this->add_key(GUI_ID_KEY_SCREENSHOT_BUTTON,wgettext("Screenshot"), "keymap_screenshot");
- this->add_key(GUI_ID_KEY_RANGE_BUTTON, wgettext("Range select"), "keymap_rangeselect");
- this->add_key(GUI_ID_KEY_DEC_RANGE_BUTTON, wgettext("Dec. range"), "keymap_decrease_viewing_range_min");
- this->add_key(GUI_ID_KEY_INC_RANGE_BUTTON, wgettext("Inc. range"), "keymap_increase_viewing_range_min");
- this->add_key(GUI_ID_KEY_CONSOLE_BUTTON, wgettext("Console"), "keymap_console");
- this->add_key(GUI_ID_KEY_CMD_BUTTON, wgettext("Command"), "keymap_cmd");
- this->add_key(GUI_ID_KEY_CMD_LOCAL_BUTTON, wgettext("Local command"), "keymap_cmd_local");
- this->add_key(GUI_ID_KEY_HUD_BUTTON, wgettext("Toggle HUD"), "keymap_toggle_hud");
- this->add_key(GUI_ID_KEY_CHATLOG_BUTTON, wgettext("Toggle chat log"), "keymap_toggle_chat");
- this->add_key(GUI_ID_KEY_FOG_BUTTON, wgettext("Toggle fog"), "keymap_toggle_fog");
- this->add_key(GUI_ID_KEY_CHEAT_MENU_BUTTON,wgettext("Toggle C. Menu"),"keymap_toggle_cheat_menu");
- this->add_key(GUI_ID_KEY_KILLAURA_BUTTON, wgettext("Killaura"), "keymap_toggle_killaura");
- this->add_key(GUI_ID_KEY_FREECAM_BUTTON, wgettext("Freecam"), "keymap_toggle_freecam");
- this->add_key(GUI_ID_KEY_SCAFFOLD_BUTTON, wgettext("Scaffold"), "keymap_toggle_scaffold");
- this->add_key(GUI_ID_KEY_SELECT_UP_BUTTON, wgettext("C. Menu Up"), "keymap_select_up");
- this->add_key(GUI_ID_KEY_SELECT_DOWN_BUTTON,wgettext("C. Menu Down"), "keymap_select_down");
- this->add_key(GUI_ID_KEY_SELECT_LEFT_BUTTON,wgettext("C. Menu Left"), "keymap_select_left");
- this->add_key(GUI_ID_KEY_SELECT_RIGHT_BUTTON,wgettext("C. Menu Right"),"keymap_select_right");
- this->add_key(GUI_ID_KEY_SELECT_CONFIRM_BUTTON,wgettext("C. Menu Enter"),"keymap_select_confirm");
+ this->add_key(GUI_ID_KEY_FORWARD_BUTTON, wgettext("Forward"), "keymap_forward");
+ this->add_key(GUI_ID_KEY_BACKWARD_BUTTON, wgettext("Backward"), "keymap_backward");
+ this->add_key(GUI_ID_KEY_LEFT_BUTTON, wgettext("Left"), "keymap_left");
+ this->add_key(GUI_ID_KEY_RIGHT_BUTTON, wgettext("Right"), "keymap_right");
+ this->add_key(GUI_ID_KEY_AUX1_BUTTON, wgettext("Aux1"), "keymap_aux1");
+ this->add_key(GUI_ID_KEY_JUMP_BUTTON, wgettext("Jump"), "keymap_jump");
+ this->add_key(GUI_ID_KEY_SNEAK_BUTTON, wgettext("Sneak"), "keymap_sneak");
+ this->add_key(GUI_ID_KEY_DROP_BUTTON, wgettext("Drop"), "keymap_drop");
+ this->add_key(GUI_ID_KEY_INVENTORY_BUTTON, wgettext("Inventory"), "keymap_inventory");
+ this->add_key(GUI_ID_KEY_ENDERCHEST_BUTTON, wgettext("Enderchest"), "keymap_enderchest");
+ this->add_key(GUI_ID_KEY_HOTBAR_PREV_BUTTON, wgettext("Prev. item"), "keymap_hotbar_previous");
+ this->add_key(GUI_ID_KEY_HOTBAR_NEXT_BUTTON, wgettext("Next item"), "keymap_hotbar_next");
+ this->add_key(GUI_ID_KEY_ZOOM_BUTTON, wgettext("Zoom"), "keymap_zoom");
+ this->add_key(GUI_ID_KEY_CAMERA_BUTTON, wgettext("Change camera"), "keymap_camera_mode");
+ this->add_key(GUI_ID_KEY_MINIMAP_BUTTON, wgettext("Toggle minimap"), "keymap_minimap");
+ this->add_key(GUI_ID_KEY_FLY_BUTTON, wgettext("Toggle fly"), "keymap_freemove");
+ this->add_key(GUI_ID_KEY_PITCH_MOVE, wgettext("Toggle pitchmove"), "keymap_pitchmove");
+ this->add_key(GUI_ID_KEY_FAST_BUTTON, wgettext("Toggle fast"), "keymap_fastmove");
+ this->add_key(GUI_ID_KEY_NOCLIP_BUTTON, wgettext("Toggle noclip"), "keymap_noclip");
+ this->add_key(GUI_ID_KEY_MUTE_BUTTON, wgettext("Mute"), "keymap_mute");
+ this->add_key(GUI_ID_KEY_DEC_VOLUME_BUTTON, wgettext("Dec. volume"), "keymap_decrease_volume");
+ this->add_key(GUI_ID_KEY_INC_VOLUME_BUTTON, wgettext("Inc. volume"), "keymap_increase_volume");
+ this->add_key(GUI_ID_KEY_AUTOFWD_BUTTON, wgettext("Autoforward"), "keymap_autoforward");
+ this->add_key(GUI_ID_KEY_CHAT_BUTTON, wgettext("Chat"), "keymap_chat");
+ this->add_key(GUI_ID_KEY_SCREENSHOT_BUTTON, wgettext("Screenshot"), "keymap_screenshot");
+ this->add_key(GUI_ID_KEY_RANGE_BUTTON, wgettext("Range select"), "keymap_rangeselect");
+ this->add_key(GUI_ID_KEY_DEC_RANGE_BUTTON, wgettext("Dec. range"), "keymap_decrease_viewing_range_min");
+ this->add_key(GUI_ID_KEY_INC_RANGE_BUTTON, wgettext("Inc. range"), "keymap_increase_viewing_range_min");
+ this->add_key(GUI_ID_KEY_CONSOLE_BUTTON, wgettext("Console"), "keymap_console");
+ this->add_key(GUI_ID_KEY_CMD_BUTTON, wgettext("Command"), "keymap_cmd");
+ this->add_key(GUI_ID_KEY_CMD_LOCAL_BUTTON, wgettext("Local command"), "keymap_cmd_local");
+ this->add_key(GUI_ID_KEY_BLOCK_BOUNDS_BUTTON, wgettext("Block bounds"), "keymap_toggle_block_bounds");
+ this->add_key(GUI_ID_KEY_HUD_BUTTON, wgettext("Toggle HUD"), "keymap_toggle_hud");
+ this->add_key(GUI_ID_KEY_CHATLOG_BUTTON, wgettext("Toggle chat log"), "keymap_toggle_chat");
+ this->add_key(GUI_ID_KEY_FOG_BUTTON, wgettext("Toggle fog"), "keymap_toggle_fog");
+ this->add_key(GUI_ID_KEY_CHEAT_MENU_BUTTON, wgettext("Toggle C. Menu"), "keymap_toggle_cheat_menu");
+ this->add_key(GUI_ID_KEY_KILLAURA_BUTTON, wgettext("Killaura"), "keymap_toggle_killaura");
+ this->add_key(GUI_ID_KEY_FREECAM_BUTTON, wgettext("Freecam"), "keymap_toggle_freecam");
+ this->add_key(GUI_ID_KEY_SCAFFOLD_BUTTON, wgettext("Scaffold"), "keymap_toggle_scaffold");
+ this->add_key(GUI_ID_KEY_SELECT_UP_BUTTON, wgettext("C. Menu Up"), "keymap_select_up");
+ this->add_key(GUI_ID_KEY_SELECT_DOWN_BUTTON, wgettext("C. Menu Down"), "keymap_select_down");
+ this->add_key(GUI_ID_KEY_SELECT_LEFT_BUTTON, wgettext("C. Menu Left"), "keymap_select_left");
+ this->add_key(GUI_ID_KEY_SELECT_RIGHT_BUTTON, wgettext("C. Menu Right"), "keymap_select_right");
+ this->add_key(GUI_ID_KEY_SELECT_CONFIRM_BUTTON, wgettext("C. Menu Enter"), "keymap_select_confirm");
}
diff --git a/src/gui/guiScene.cpp b/src/gui/guiScene.cpp
index 5f4c50b91..f0cfbec5e 100644
--- a/src/gui/guiScene.cpp
+++ b/src/gui/guiScene.cpp
@@ -34,9 +34,6 @@ GUIScene::GUIScene(gui::IGUIEnvironment *env, scene::ISceneManager *smgr,
m_cam = m_smgr->addCameraSceneNode(0, v3f(0.f, 0.f, -100.f), v3f(0.f));
m_cam->setFOV(30.f * core::DEGTORAD);
- scene::ILightSceneNode *light = m_smgr->addLightSceneNode(m_cam);
- light->setRadius(1000.f);
-
m_smgr->getParameters()->setAttribute(scene::ALLOW_ZWRITE_ON_TRANSPARENT, true);
}
@@ -60,6 +57,7 @@ scene::IAnimatedMeshSceneNode *GUIScene::setMesh(scene::IAnimatedMesh *mesh)
m_mesh = m_smgr->addAnimatedMeshSceneNode(mesh);
m_mesh->setPosition(-m_mesh->getBoundingBox().getCenter());
m_mesh->animateJoints();
+
return m_mesh;
}
@@ -73,10 +71,13 @@ void GUIScene::setTexture(u32 idx, video::ITexture *texture)
material.setFlag(video::EMF_FOG_ENABLE, true);
material.setFlag(video::EMF_BILINEAR_FILTER, false);
material.setFlag(video::EMF_BACK_FACE_CULLING, false);
+ material.setFlag(video::EMF_ZWRITE_ENABLE, true);
}
void GUIScene::draw()
{
+ m_driver->clearBuffers(video::ECBF_DEPTH);
+
// Control rotation speed based on time
u64 new_time = porting::getTimeMs();
u64 dtime_ms = 0;
@@ -161,6 +162,14 @@ void GUIScene::setFrameLoop(s32 begin, s32 end)
m_mesh->setFrameLoop(begin, end);
}
+/**
+ * Sets the animation speed (FPS) for the mesh
+ */
+void GUIScene::setAnimationSpeed(f32 speed)
+{
+ m_mesh->setAnimationSpeed(speed);
+}
+
/* Camera control functions */
inline void GUIScene::calcOptimalDistance()
diff --git a/src/gui/guiScene.h b/src/gui/guiScene.h
index 08eb7f350..0f5f3a891 100644
--- a/src/gui/guiScene.h
+++ b/src/gui/guiScene.h
@@ -37,6 +37,7 @@ public:
void setTexture(u32 idx, video::ITexture *texture);
void setBackgroundColor(const video::SColor &color) noexcept { m_bgcolor = color; };
void setFrameLoop(s32 begin, s32 end);
+ void setAnimationSpeed(f32 speed);
void enableMouseControl(bool enable) noexcept { m_mouse_ctrl = enable; };
void setRotation(v2f rot) noexcept { m_custom_rot = rot; };
void enableContinuousRotation(bool enable) noexcept { m_inf_rot = enable; };
diff --git a/src/gui/intlGUIEditBox.cpp b/src/gui/intlGUIEditBox.cpp
deleted file mode 100644
index a61619148..000000000
--- a/src/gui/intlGUIEditBox.cpp
+++ /dev/null
@@ -1,723 +0,0 @@
-// 11.11.2011 11:11 ValkaTR
-//
-// This is a copy of intlGUIEditBox from the irrlicht, but with a
-// fix in the OnEvent function, which doesn't allowed input of
-// other keyboard layouts than latin-1
-//
-// Characters like: ä ö ü õ ы й ю я ъ № € ° ...
-//
-// This fix is only needed for linux, because of a bug
-// in the CIrrDeviceLinux.cpp:1014-1015 of the irrlicht
-//
-// Also locale in the programm should not be changed to
-// a "C", "POSIX" or whatever, it should be set to "",
-// or XLookupString will return nothing for the international
-// characters.
-//
-// From the "man setlocale":
-//
-// On startup of the main program, the portable "C" locale
-// is selected as default. A program may be made
-// portable to all locales by calling:
-//
-// setlocale(LC_ALL, "");
-//
-// after program initialization....
-//
-
-// Copyright (C) 2002-2013 Nikolaus Gebhardt
-// This file is part of the "Irrlicht Engine".
-// For conditions of distribution and use, see copyright notice in irrlicht.h
-
-#include <util/numeric.h>
-#include "intlGUIEditBox.h"
-
-#include "IGUISkin.h"
-#include "IGUIEnvironment.h"
-#include "IGUIFont.h"
-#include "IVideoDriver.h"
-//#include "irrlicht/os.cpp"
-#include "porting.h"
-//#include "Keycodes.h"
-#include "log.h"
-
-/*
- todo:
- optional scrollbars
- ctrl+left/right to select word
- double click/ctrl click: word select + drag to select whole words, triple click to select line
- optional? dragging selected text
- numerical
-*/
-
-namespace irr
-{
-namespace gui
-{
-
-//! constructor
-intlGUIEditBox::intlGUIEditBox(const wchar_t* text, bool border,
- IGUIEnvironment* environment, IGUIElement* parent, s32 id,
- const core::rect<s32>& rectangle, bool writable, bool has_vscrollbar)
- : GUIEditBox(environment, parent, id, rectangle, border, writable)
-{
- #ifdef _DEBUG
- setDebugName("intlintlGUIEditBox");
- #endif
-
- Text = text;
-
- if (Environment)
- m_operator = Environment->getOSOperator();
-
- if (m_operator)
- m_operator->grab();
-
- // this element can be tabbed to
- setTabStop(true);
- setTabOrder(-1);
-
- IGUISkin *skin = 0;
- if (Environment)
- skin = Environment->getSkin();
- if (m_border && skin)
- {
- m_frame_rect.UpperLeftCorner.X += skin->getSize(EGDS_TEXT_DISTANCE_X)+1;
- m_frame_rect.UpperLeftCorner.Y += skin->getSize(EGDS_TEXT_DISTANCE_Y)+1;
- m_frame_rect.LowerRightCorner.X -= skin->getSize(EGDS_TEXT_DISTANCE_X)+1;
- m_frame_rect.LowerRightCorner.Y -= skin->getSize(EGDS_TEXT_DISTANCE_Y)+1;
- }
-
- if (skin && has_vscrollbar) {
- m_scrollbar_width = skin->getSize(gui::EGDS_SCROLLBAR_SIZE);
-
- if (m_scrollbar_width > 0) {
- createVScrollBar();
- }
- }
-
- breakText();
-
- calculateScrollPos();
- setWritable(writable);
-}
-
-//! Sets whether to draw the background
-void intlGUIEditBox::setDrawBackground(bool draw)
-{
-}
-
-void intlGUIEditBox::updateAbsolutePosition()
-{
- core::rect<s32> oldAbsoluteRect(AbsoluteRect);
- IGUIElement::updateAbsolutePosition();
- if ( oldAbsoluteRect != AbsoluteRect )
- {
- breakText();
- }
-}
-
-
-//! draws the element and its children
-void intlGUIEditBox::draw()
-{
- if (!IsVisible)
- return;
-
- const bool focus = Environment->hasFocus(this);
-
- IGUISkin* skin = Environment->getSkin();
- if (!skin)
- return;
-
- m_frame_rect = AbsoluteRect;
-
- // draw the border
-
- if (m_border)
- {
- if (m_writable) {
- skin->draw3DSunkenPane(this, skin->getColor(EGDC_WINDOW),
- false, true, m_frame_rect, &AbsoluteClippingRect);
- }
-
- m_frame_rect.UpperLeftCorner.X += skin->getSize(EGDS_TEXT_DISTANCE_X)+1;
- m_frame_rect.UpperLeftCorner.Y += skin->getSize(EGDS_TEXT_DISTANCE_Y)+1;
- m_frame_rect.LowerRightCorner.X -= skin->getSize(EGDS_TEXT_DISTANCE_X)+1;
- m_frame_rect.LowerRightCorner.Y -= skin->getSize(EGDS_TEXT_DISTANCE_Y)+1;
- }
-
- updateVScrollBar();
- core::rect<s32> localClipRect = m_frame_rect;
- localClipRect.clipAgainst(AbsoluteClippingRect);
-
- // draw the text
-
- IGUIFont* font = m_override_font;
- if (!m_override_font)
- font = skin->getFont();
-
- s32 cursorLine = 0;
- s32 charcursorpos = 0;
-
- if (font)
- {
- if (m_last_break_font != font)
- {
- breakText();
- }
-
- // calculate cursor pos
-
- core::stringw *txtLine = &Text;
- s32 startPos = 0;
-
- core::stringw s, s2;
-
- // get mark position
- const bool ml = (!m_passwordbox && (m_word_wrap || m_multiline));
- const s32 realmbgn = m_mark_begin < m_mark_end ? m_mark_begin : m_mark_end;
- const s32 realmend = m_mark_begin < m_mark_end ? m_mark_end : m_mark_begin;
- const s32 hlineStart = ml ? getLineFromPos(realmbgn) : 0;
- const s32 hlineCount = ml ? getLineFromPos(realmend) - hlineStart + 1 : 1;
- const s32 lineCount = ml ? m_broken_text.size() : 1;
-
- // Save the override color information.
- // Then, alter it if the edit box is disabled.
- const bool prevOver = m_override_color_enabled;
- const video::SColor prevColor = m_override_color;
-
- if (!Text.empty()) {
- if (!IsEnabled && !m_override_color_enabled)
- {
- m_override_color_enabled = true;
- m_override_color = skin->getColor(EGDC_GRAY_TEXT);
- }
-
- for (s32 i=0; i < lineCount; ++i)
- {
- setTextRect(i);
-
- // clipping test - don't draw anything outside the visible area
- core::rect<s32> c = localClipRect;
- c.clipAgainst(m_current_text_rect);
- if (!c.isValid())
- continue;
-
- // get current line
- if (m_passwordbox)
- {
- if (m_broken_text.size() != 1)
- {
- m_broken_text.clear();
- m_broken_text.emplace_back();
- }
- if (m_broken_text[0].size() != Text.size())
- {
- m_broken_text[0] = Text;
- for (u32 q = 0; q < Text.size(); ++q)
- {
- m_broken_text[0] [q] = m_passwordchar;
- }
- }
- txtLine = &m_broken_text[0];
- startPos = 0;
- }
- else
- {
- txtLine = ml ? &m_broken_text[i] : &Text;
- startPos = ml ? m_broken_text_positions[i] : 0;
- }
-
-
- // draw normal text
- font->draw(txtLine->c_str(), m_current_text_rect,
- m_override_color_enabled ? m_override_color : skin->getColor(EGDC_BUTTON_TEXT),
- false, true, &localClipRect);
-
- // draw mark and marked text
- if (focus && m_mark_begin != m_mark_end && i >= hlineStart && i < hlineStart + hlineCount)
- {
-
- s32 mbegin = 0, mend = 0;
- s32 lineStartPos = 0, lineEndPos = txtLine->size();
-
- if (i == hlineStart)
- {
- // highlight start is on this line
- s = txtLine->subString(0, realmbgn - startPos);
- mbegin = font->getDimension(s.c_str()).Width;
-
- // deal with kerning
- mbegin += font->getKerningWidth(
- &((*txtLine)[realmbgn - startPos]),
- realmbgn - startPos > 0 ? &((*txtLine)[realmbgn - startPos - 1]) : 0);
-
- lineStartPos = realmbgn - startPos;
- }
- if (i == hlineStart + hlineCount - 1)
- {
- // highlight end is on this line
- s2 = txtLine->subString(0, realmend - startPos);
- mend = font->getDimension(s2.c_str()).Width;
- lineEndPos = (s32)s2.size();
- }
- else
- mend = font->getDimension(txtLine->c_str()).Width;
-
- m_current_text_rect.UpperLeftCorner.X += mbegin;
- m_current_text_rect.LowerRightCorner.X = m_current_text_rect.UpperLeftCorner.X + mend - mbegin;
-
- // draw mark
- skin->draw2DRectangle(this, skin->getColor(EGDC_HIGH_LIGHT), m_current_text_rect, &localClipRect);
-
- // draw marked text
- s = txtLine->subString(lineStartPos, lineEndPos - lineStartPos);
-
- if (!s.empty())
- font->draw(s.c_str(), m_current_text_rect,
- m_override_color_enabled ? m_override_color : skin->getColor(EGDC_HIGH_LIGHT_TEXT),
- false, true, &localClipRect);
-
- }
- }
-
- // Return the override color information to its previous settings.
- m_override_color_enabled = prevOver;
- m_override_color = prevColor;
- }
-
- // draw cursor
-
- if (m_word_wrap || m_multiline)
- {
- cursorLine = getLineFromPos(m_cursor_pos);
- txtLine = &m_broken_text[cursorLine];
- startPos = m_broken_text_positions[cursorLine];
- }
- s = txtLine->subString(0,m_cursor_pos-startPos);
- charcursorpos = font->getDimension(s.c_str()).Width +
- font->getKerningWidth(L"_", m_cursor_pos-startPos > 0 ? &((*txtLine)[m_cursor_pos-startPos-1]) : 0);
-
- if (m_writable) {
- if (focus && (porting::getTimeMs() - m_blink_start_time) % 700 < 350) {
- setTextRect(cursorLine);
- m_current_text_rect.UpperLeftCorner.X += charcursorpos;
-
- font->draw(L"_", m_current_text_rect,
- m_override_color_enabled ? m_override_color : skin->getColor(EGDC_BUTTON_TEXT),
- false, true, &localClipRect);
- }
- }
- }
-
- // draw children
- IGUIElement::draw();
-}
-
-
-s32 intlGUIEditBox::getCursorPos(s32 x, s32 y)
-{
- IGUIFont* font = m_override_font;
- IGUISkin* skin = Environment->getSkin();
- if (!m_override_font)
- font = skin->getFont();
-
- const u32 lineCount = (m_word_wrap || m_multiline) ? m_broken_text.size() : 1;
-
- core::stringw *txtLine = NULL;
- s32 startPos = 0;
- u32 curr_line_idx = 0;
- x += 3;
-
- for (; curr_line_idx < lineCount; ++curr_line_idx) {
- setTextRect(curr_line_idx);
- if (curr_line_idx == 0 && y < m_current_text_rect.UpperLeftCorner.Y)
- y = m_current_text_rect.UpperLeftCorner.Y;
- if (curr_line_idx == lineCount - 1 && y > m_current_text_rect.LowerRightCorner.Y)
- y = m_current_text_rect.LowerRightCorner.Y;
-
- // is it inside this region?
- if (y >= m_current_text_rect.UpperLeftCorner.Y && y <= m_current_text_rect.LowerRightCorner.Y) {
- // we've found the clicked line
- txtLine = (m_word_wrap || m_multiline) ? &m_broken_text[curr_line_idx] : &Text;
- startPos = (m_word_wrap || m_multiline) ? m_broken_text_positions[curr_line_idx] : 0;
- break;
- }
- }
-
- if (x < m_current_text_rect.UpperLeftCorner.X)
- x = m_current_text_rect.UpperLeftCorner.X;
- else if (x > m_current_text_rect.LowerRightCorner.X)
- x = m_current_text_rect.LowerRightCorner.X;
-
- s32 idx = font->getCharacterFromPos(txtLine->c_str(), x - m_current_text_rect.UpperLeftCorner.X);
- // Special handling for last line, if we are on limits, add 1 extra shift because idx
- // will be the last char, not null char of the wstring
- if (curr_line_idx == lineCount - 1 && x == m_current_text_rect.LowerRightCorner.X)
- idx++;
-
- return rangelim(idx + startPos, 0, S32_MAX);
-}
-
-
-//! Breaks the single text line.
-void intlGUIEditBox::breakText()
-{
- IGUISkin* skin = Environment->getSkin();
-
- if ((!m_word_wrap && !m_multiline) || !skin)
- return;
-
- m_broken_text.clear(); // need to reallocate :/
- m_broken_text_positions.clear();
-
- IGUIFont* font = m_override_font;
- if (!m_override_font)
- font = skin->getFont();
-
- if (!font)
- return;
-
- m_last_break_font = font;
-
- core::stringw line;
- core::stringw word;
- core::stringw whitespace;
- s32 lastLineStart = 0;
- s32 size = Text.size();
- s32 length = 0;
- s32 elWidth = RelativeRect.getWidth() - m_scrollbar_width - 10;
- wchar_t c;
-
- for (s32 i=0; i<size; ++i)
- {
- c = Text[i];
- bool lineBreak = false;
-
- if (c == L'\r') // Mac or Windows breaks
- {
- lineBreak = true;
- c = ' ';
- if (Text[i+1] == L'\n') // Windows breaks
- {
- Text.erase(i+1);
- --size;
- }
- }
- else if (c == L'\n') // Unix breaks
- {
- lineBreak = true;
- c = ' ';
- }
-
- // don't break if we're not a multi-line edit box
- if (!m_multiline)
- lineBreak = false;
-
- if (c == L' ' || c == 0 || i == (size-1))
- {
- if (!word.empty()) {
- // here comes the next whitespace, look if
- // we can break the last word to the next line.
- s32 whitelgth = font->getDimension(whitespace.c_str()).Width;
- s32 worldlgth = font->getDimension(word.c_str()).Width;
-
- if (m_word_wrap && length + worldlgth + whitelgth > elWidth)
- {
- // break to next line
- length = worldlgth;
- m_broken_text.push_back(line);
- m_broken_text_positions.push_back(lastLineStart);
- lastLineStart = i - (s32)word.size();
- line = word;
- }
- else
- {
- // add word to line
- line += whitespace;
- line += word;
- length += whitelgth + worldlgth;
- }
-
- word = L"";
- whitespace = L"";
- }
-
- whitespace += c;
-
- // compute line break
- if (lineBreak)
- {
- line += whitespace;
- line += word;
- m_broken_text.push_back(line);
- m_broken_text_positions.push_back(lastLineStart);
- lastLineStart = i+1;
- line = L"";
- word = L"";
- whitespace = L"";
- length = 0;
- }
- }
- else
- {
- // yippee this is a word..
- word += c;
- }
- }
-
- line += whitespace;
- line += word;
- m_broken_text.push_back(line);
- m_broken_text_positions.push_back(lastLineStart);
-}
-
-
-void intlGUIEditBox::setTextRect(s32 line)
-{
- core::dimension2du d;
-
- IGUISkin* skin = Environment->getSkin();
- if (!skin)
- return;
-
- IGUIFont* font = m_override_font ? m_override_font : skin->getFont();
-
- if (!font)
- return;
-
- // get text dimension
- const u32 lineCount = (m_word_wrap || m_multiline) ? m_broken_text.size() : 1;
- if (m_word_wrap || m_multiline)
- {
- d = font->getDimension(m_broken_text[line].c_str());
- }
- else
- {
- d = font->getDimension(Text.c_str());
- d.Height = AbsoluteRect.getHeight();
- }
- d.Height += font->getKerningHeight();
-
- // justification
- switch (m_halign)
- {
- case EGUIA_CENTER:
- // align to h centre
- m_current_text_rect.UpperLeftCorner.X = (m_frame_rect.getWidth()/2) - (d.Width/2);
- m_current_text_rect.LowerRightCorner.X = (m_frame_rect.getWidth()/2) + (d.Width/2);
- break;
- case EGUIA_LOWERRIGHT:
- // align to right edge
- m_current_text_rect.UpperLeftCorner.X = m_frame_rect.getWidth() - d.Width;
- m_current_text_rect.LowerRightCorner.X = m_frame_rect.getWidth();
- break;
- default:
- // align to left edge
- m_current_text_rect.UpperLeftCorner.X = 0;
- m_current_text_rect.LowerRightCorner.X = d.Width;
-
- }
-
- switch (m_valign)
- {
- case EGUIA_CENTER:
- // align to v centre
- m_current_text_rect.UpperLeftCorner.Y =
- (m_frame_rect.getHeight()/2) - (lineCount*d.Height)/2 + d.Height*line;
- break;
- case EGUIA_LOWERRIGHT:
- // align to bottom edge
- m_current_text_rect.UpperLeftCorner.Y =
- m_frame_rect.getHeight() - lineCount*d.Height + d.Height*line;
- break;
- default:
- // align to top edge
- m_current_text_rect.UpperLeftCorner.Y = d.Height*line;
- break;
- }
-
- m_current_text_rect.UpperLeftCorner.X -= m_hscroll_pos;
- m_current_text_rect.LowerRightCorner.X -= m_hscroll_pos;
- m_current_text_rect.UpperLeftCorner.Y -= m_vscroll_pos;
- m_current_text_rect.LowerRightCorner.Y = m_current_text_rect.UpperLeftCorner.Y + d.Height;
-
- m_current_text_rect += m_frame_rect.UpperLeftCorner;
-
-}
-
-void intlGUIEditBox::inputChar(wchar_t c)
-{
- if (!isEnabled() || !m_writable)
- return;
-
- if (c != 0)
- {
- if (Text.size() < m_max || m_max == 0)
- {
- core::stringw s;
-
- if (m_mark_begin != m_mark_end)
- {
- // replace marked text
- const s32 realmbgn = m_mark_begin < m_mark_end ? m_mark_begin : m_mark_end;
- const s32 realmend = m_mark_begin < m_mark_end ? m_mark_end : m_mark_begin;
-
- s = Text.subString(0, realmbgn);
- s.append(c);
- s.append( Text.subString(realmend, Text.size()-realmend) );
- Text = s;
- m_cursor_pos = realmbgn+1;
- }
- else
- {
- // add new character
- s = Text.subString(0, m_cursor_pos);
- s.append(c);
- s.append( Text.subString(m_cursor_pos, Text.size()-m_cursor_pos) );
- Text = s;
- ++m_cursor_pos;
- }
-
- m_blink_start_time = porting::getTimeMs();
- setTextMarkers(0, 0);
- }
- }
- breakText();
- sendGuiEvent(EGET_EDITBOX_CHANGED);
- calculateScrollPos();
-}
-
-
-void intlGUIEditBox::calculateScrollPos()
-{
- if (!m_autoscroll)
- return;
-
- // calculate horizontal scroll position
- s32 cursLine = getLineFromPos(m_cursor_pos);
- setTextRect(cursLine);
-
- // don't do horizontal scrolling when wordwrap is enabled.
- if (!m_word_wrap)
- {
- // get cursor position
- IGUISkin* skin = Environment->getSkin();
- if (!skin)
- return;
- IGUIFont* font = m_override_font ? m_override_font : skin->getFont();
- if (!font)
- return;
-
- core::stringw *txtLine = m_multiline ? &m_broken_text[cursLine] : &Text;
- s32 cPos = m_multiline ? m_cursor_pos - m_broken_text_positions[cursLine] : m_cursor_pos;
-
- s32 cStart = m_current_text_rect.UpperLeftCorner.X + m_hscroll_pos +
- font->getDimension(txtLine->subString(0, cPos).c_str()).Width;
-
- s32 cEnd = cStart + font->getDimension(L"_ ").Width;
-
- if (m_frame_rect.LowerRightCorner.X < cEnd)
- m_hscroll_pos = cEnd - m_frame_rect.LowerRightCorner.X;
- else if (m_frame_rect.UpperLeftCorner.X > cStart)
- m_hscroll_pos = cStart - m_frame_rect.UpperLeftCorner.X;
- else
- m_hscroll_pos = 0;
-
- // todo: adjust scrollbar
- }
-
- if (!m_word_wrap && !m_multiline)
- return;
-
- // vertical scroll position
- if (m_frame_rect.LowerRightCorner.Y < m_current_text_rect.LowerRightCorner.Y)
- m_vscroll_pos += m_current_text_rect.LowerRightCorner.Y - m_frame_rect.LowerRightCorner.Y; // scrolling downwards
- else if (m_frame_rect.UpperLeftCorner.Y > m_current_text_rect.UpperLeftCorner.Y)
- m_vscroll_pos += m_current_text_rect.UpperLeftCorner.Y - m_frame_rect.UpperLeftCorner.Y; // scrolling upwards
-
- // todo: adjust scrollbar
- if (m_vscrollbar)
- m_vscrollbar->setPos(m_vscroll_pos);
-}
-
-
-//! Create a vertical scrollbar
-void intlGUIEditBox::createVScrollBar()
-{
- s32 fontHeight = 1;
-
- if (m_override_font) {
- fontHeight = m_override_font->getDimension(L"").Height;
- } else {
- if (IGUISkin* skin = Environment->getSkin()) {
- if (IGUIFont* font = skin->getFont()) {
- fontHeight = font->getDimension(L"").Height;
- }
- }
- }
-
- irr::core::rect<s32> scrollbarrect = m_frame_rect;
- scrollbarrect.UpperLeftCorner.X += m_frame_rect.getWidth() - m_scrollbar_width;
- m_vscrollbar = new GUIScrollBar(Environment, getParent(), -1,
- scrollbarrect, false, true);
-
- m_vscrollbar->setVisible(false);
- m_vscrollbar->setSmallStep(3 * fontHeight);
- m_vscrollbar->setLargeStep(10 * fontHeight);
-}
-
-
-//! Writes attributes of the element.
-void intlGUIEditBox::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options=0) const
-{
- // IGUIEditBox::serializeAttributes(out,options);
-
- out->addBool ("OverrideColorEnabled", m_override_color_enabled );
- out->addColor ("OverrideColor", m_override_color);
- // out->addFont("OverrideFont",m_override_font);
- out->addInt ("MaxChars", m_max);
- out->addBool ("WordWrap", m_word_wrap);
- out->addBool ("MultiLine", m_multiline);
- out->addBool ("AutoScroll", m_autoscroll);
- out->addBool ("PasswordBox", m_passwordbox);
- core::stringw ch = L" ";
- ch[0] = m_passwordchar;
- out->addString("PasswordChar", ch.c_str());
- out->addEnum ("HTextAlign", m_halign, GUIAlignmentNames);
- out->addEnum ("VTextAlign", m_valign, GUIAlignmentNames);
- out->addBool ("Writable", m_writable);
-
- IGUIEditBox::serializeAttributes(out,options);
-}
-
-
-//! Reads attributes of the element
-void intlGUIEditBox::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options=0)
-{
- IGUIEditBox::deserializeAttributes(in,options);
-
- setOverrideColor(in->getAttributeAsColor("OverrideColor"));
- enableOverrideColor(in->getAttributeAsBool("OverrideColorEnabled"));
- setMax(in->getAttributeAsInt("MaxChars"));
- setWordWrap(in->getAttributeAsBool("WordWrap"));
- setMultiLine(in->getAttributeAsBool("MultiLine"));
- setAutoScroll(in->getAttributeAsBool("AutoScroll"));
- core::stringw ch = in->getAttributeAsStringW("PasswordChar");
-
- if (ch.empty())
- setPasswordBox(in->getAttributeAsBool("PasswordBox"));
- else
- setPasswordBox(in->getAttributeAsBool("PasswordBox"), ch[0]);
-
- setTextAlignment( (EGUI_ALIGNMENT) in->getAttributeAsEnumeration("HTextAlign", GUIAlignmentNames),
- (EGUI_ALIGNMENT) in->getAttributeAsEnumeration("VTextAlign", GUIAlignmentNames));
-
- setWritable(in->getAttributeAsBool("Writable"));
- // setOverrideFont(in->getAttributeAsFont("OverrideFont"));
-}
-
-
-} // end namespace gui
-} // end namespace irr
diff --git a/src/gui/intlGUIEditBox.h b/src/gui/intlGUIEditBox.h
deleted file mode 100644
index 2abc12d1a..000000000
--- a/src/gui/intlGUIEditBox.h
+++ /dev/null
@@ -1,75 +0,0 @@
-// Copyright (C) 2002-2013 Nikolaus Gebhardt
-// This file is part of the "Irrlicht Engine".
-// For conditions of distribution and use, see copyright notice in irrlicht.h
-
-#pragma once
-
-#include "IrrCompileConfig.h"
-//#ifdef _IRR_COMPILE_WITH_GUI_
-
-#include "guiEditBox.h"
-#include "irrArray.h"
-#include "IOSOperator.h"
-
-namespace irr
-{
-namespace gui
-{
- class intlGUIEditBox : public GUIEditBox
- {
- public:
-
- //! constructor
- intlGUIEditBox(const wchar_t* text, bool border, IGUIEnvironment* environment,
- IGUIElement* parent, s32 id, const core::rect<s32>& rectangle,
- bool writable = true, bool has_vscrollbar = false);
-
- //! destructor
- virtual ~intlGUIEditBox() {}
-
- //! Sets whether to draw the background
- virtual void setDrawBackground(bool draw);
-
- virtual bool isDrawBackgroundEnabled() const { return true; }
-
- //! draws the element and its children
- virtual void draw();
-
- //! Updates the absolute position, splits text if required
- virtual void updateAbsolutePosition();
-
- //! Writes attributes of the element.
- virtual void serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const;
-
- //! Reads attributes of the element
- virtual void deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options);
-
- virtual void setCursorChar(const wchar_t cursorChar) {}
-
- virtual wchar_t getCursorChar() const { return L'|'; }
-
- virtual void setCursorBlinkTime(u32 timeMs) {}
-
- virtual u32 getCursorBlinkTime() const { return 500; }
-
- protected:
- //! Breaks the single text line.
- virtual void breakText();
- //! sets the area of the given line
- virtual void setTextRect(s32 line);
- //! adds a letter to the edit box
- virtual void inputChar(wchar_t c);
- //! calculates the current scroll position
- void calculateScrollPos();
-
- s32 getCursorPos(s32 x, s32 y);
-
- //! Create a vertical scrollbar
- void createVScrollBar();
- };
-
-
-} // end namespace gui
-} // end namespace irr
-
-//#endif // _IRR_COMPILE_WITH_GUI_
diff --git a/src/gui/modalMenu.cpp b/src/gui/modalMenu.cpp
index 9b1e6dd9c..0d3fb55f0 100644
--- a/src/gui/modalMenu.cpp
+++ b/src/gui/modalMenu.cpp
@@ -183,6 +183,64 @@ static bool isChild(gui::IGUIElement *tocheck, gui::IGUIElement *parent)
return false;
}
+#ifdef __ANDROID__
+
+bool GUIModalMenu::simulateMouseEvent(
+ gui::IGUIElement *target, ETOUCH_INPUT_EVENT touch_event)
+{
+ SEvent mouse_event{}; // value-initialized, not unitialized
+ mouse_event.EventType = EET_MOUSE_INPUT_EVENT;
+ mouse_event.MouseInput.X = m_pointer.X;
+ mouse_event.MouseInput.Y = m_pointer.Y;
+ switch (touch_event) {
+ case ETIE_PRESSED_DOWN:
+ mouse_event.MouseInput.Event = EMIE_LMOUSE_PRESSED_DOWN;
+ mouse_event.MouseInput.ButtonStates = EMBSM_LEFT;
+ break;
+ case ETIE_MOVED:
+ mouse_event.MouseInput.Event = EMIE_MOUSE_MOVED;
+ mouse_event.MouseInput.ButtonStates = EMBSM_LEFT;
+ break;
+ case ETIE_LEFT_UP:
+ mouse_event.MouseInput.Event = EMIE_LMOUSE_LEFT_UP;
+ mouse_event.MouseInput.ButtonStates = 0;
+ break;
+ default:
+ return false;
+ }
+ if (preprocessEvent(mouse_event))
+ return true;
+ if (!target)
+ return false;
+ return target->OnEvent(mouse_event);
+}
+
+void GUIModalMenu::enter(gui::IGUIElement *hovered)
+{
+ sanity_check(!m_hovered);
+ m_hovered.grab(hovered);
+ SEvent gui_event{};
+ gui_event.EventType = EET_GUI_EVENT;
+ gui_event.GUIEvent.Caller = m_hovered.get();
+ gui_event.GUIEvent.EventType = EGET_ELEMENT_HOVERED;
+ gui_event.GUIEvent.Element = gui_event.GUIEvent.Caller;
+ m_hovered->OnEvent(gui_event);
+}
+
+void GUIModalMenu::leave()
+{
+ if (!m_hovered)
+ return;
+ SEvent gui_event{};
+ gui_event.EventType = EET_GUI_EVENT;
+ gui_event.GUIEvent.Caller = m_hovered.get();
+ gui_event.GUIEvent.EventType = EGET_ELEMENT_LEFT;
+ m_hovered->OnEvent(gui_event);
+ m_hovered.reset();
+}
+
+#endif
+
bool GUIModalMenu::preprocessEvent(const SEvent &event)
{
#ifdef __ANDROID__
@@ -230,89 +288,50 @@ bool GUIModalMenu::preprocessEvent(const SEvent &event)
}
if (event.EventType == EET_TOUCH_INPUT_EVENT) {
- SEvent translated;
- memset(&translated, 0, sizeof(SEvent));
- translated.EventType = EET_MOUSE_INPUT_EVENT;
- gui::IGUIElement *root = Environment->getRootGUIElement();
-
- if (!root) {
- errorstream << "GUIModalMenu::preprocessEvent"
- << " unable to get root element" << std::endl;
- return false;
- }
- gui::IGUIElement *hovered =
- root->getElementFromPoint(core::position2d<s32>(
- event.TouchInput.X, event.TouchInput.Y));
-
- translated.MouseInput.X = event.TouchInput.X;
- translated.MouseInput.Y = event.TouchInput.Y;
- translated.MouseInput.Control = false;
+ irr_ptr<GUIModalMenu> holder;
+ holder.grab(this); // keep this alive until return (it might be dropped downstream [?])
- if (event.TouchInput.touchedCount == 1) {
- switch (event.TouchInput.Event) {
- case ETIE_PRESSED_DOWN:
+ switch ((int)event.TouchInput.touchedCount) {
+ case 1: {
+ if (event.TouchInput.Event == ETIE_PRESSED_DOWN || event.TouchInput.Event == ETIE_MOVED)
m_pointer = v2s32(event.TouchInput.X, event.TouchInput.Y);
- translated.MouseInput.Event = EMIE_LMOUSE_PRESSED_DOWN;
- translated.MouseInput.ButtonStates = EMBSM_LEFT;
+ if (event.TouchInput.Event == ETIE_PRESSED_DOWN)
m_down_pos = m_pointer;
- break;
- case ETIE_MOVED:
- m_pointer = v2s32(event.TouchInput.X, event.TouchInput.Y);
- translated.MouseInput.Event = EMIE_MOUSE_MOVED;
- translated.MouseInput.ButtonStates = EMBSM_LEFT;
- break;
- case ETIE_LEFT_UP:
- translated.MouseInput.Event = EMIE_LMOUSE_LEFT_UP;
- translated.MouseInput.ButtonStates = 0;
- hovered = root->getElementFromPoint(m_down_pos);
- // we don't have a valid pointer element use last
- // known pointer pos
- translated.MouseInput.X = m_pointer.X;
- translated.MouseInput.Y = m_pointer.Y;
-
- // reset down pos
- m_down_pos = v2s32(0, 0);
- break;
- default:
- break;
+ gui::IGUIElement *hovered = Environment->getRootGUIElement()->getElementFromPoint(core::position2d<s32>(m_pointer));
+ if (event.TouchInput.Event == ETIE_PRESSED_DOWN)
+ Environment->setFocus(hovered);
+ if (m_hovered != hovered) {
+ leave();
+ enter(hovered);
}
- } else if ((event.TouchInput.touchedCount == 2) &&
- (event.TouchInput.Event == ETIE_PRESSED_DOWN)) {
- hovered = root->getElementFromPoint(m_down_pos);
-
- translated.MouseInput.Event = EMIE_RMOUSE_PRESSED_DOWN;
- translated.MouseInput.ButtonStates = EMBSM_LEFT | EMBSM_RIGHT;
- translated.MouseInput.X = m_pointer.X;
- translated.MouseInput.Y = m_pointer.Y;
- if (hovered)
- hovered->OnEvent(translated);
-
- translated.MouseInput.Event = EMIE_RMOUSE_LEFT_UP;
- translated.MouseInput.ButtonStates = EMBSM_LEFT;
-
- if (hovered)
- hovered->OnEvent(translated);
-
- return true;
- } else {
- // ignore unhandled 2 touch events (accidental moving for example)
+ gui::IGUIElement *focused = Environment->getFocus();
+ bool ret = simulateMouseEvent(focused, event.TouchInput.Event);
+ if (!ret && m_hovered != focused)
+ ret = simulateMouseEvent(m_hovered.get(), event.TouchInput.Event);
+ if (event.TouchInput.Event == ETIE_LEFT_UP)
+ leave();
+ return ret;
+ }
+ case 2: {
+ if (event.TouchInput.Event != ETIE_PRESSED_DOWN)
+ return true; // ignore
+ auto focused = Environment->getFocus();
+ if (!focused)
+ return true;
+ SEvent rclick_event{};
+ rclick_event.EventType = EET_MOUSE_INPUT_EVENT;
+ rclick_event.MouseInput.Event = EMIE_RMOUSE_PRESSED_DOWN;
+ rclick_event.MouseInput.ButtonStates = EMBSM_LEFT | EMBSM_RIGHT;
+ rclick_event.MouseInput.X = m_pointer.X;
+ rclick_event.MouseInput.Y = m_pointer.Y;
+ focused->OnEvent(rclick_event);
+ rclick_event.MouseInput.Event = EMIE_RMOUSE_LEFT_UP;
+ rclick_event.MouseInput.ButtonStates = EMBSM_LEFT;
+ focused->OnEvent(rclick_event);
return true;
}
-
- // check if translated event needs to be preprocessed again
- if (preprocessEvent(translated))
+ default: // ignored
return true;
-
- if (hovered) {
- grab();
- bool retval = hovered->OnEvent(translated);
-
- if (event.TouchInput.Event == ETIE_LEFT_UP)
- // reset pointer
- m_pointer = v2s32(0, 0);
-
- drop();
- return retval;
}
}
#endif
diff --git a/src/gui/modalMenu.h b/src/gui/modalMenu.h
index 1cb687f82..ed0da3205 100644
--- a/src/gui/modalMenu.h
+++ b/src/gui/modalMenu.h
@@ -20,6 +20,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#pragma once
#include "irrlichttypes_extrabloated.h"
+#include "irr_ptr.h"
#include "util/string.h"
class GUIModalMenu;
@@ -100,4 +101,12 @@ private:
// This might be necessary to expose to the implementation if it
// wants to launch other menus
bool m_allow_focus_removal = false;
+
+#ifdef __ANDROID__
+ irr_ptr<gui::IGUIElement> m_hovered;
+
+ bool simulateMouseEvent(gui::IGUIElement *target, ETOUCH_INPUT_EVENT touch_event);
+ void enter(gui::IGUIElement *element);
+ void leave();
+#endif
};
diff --git a/src/gui/touchscreengui.cpp b/src/gui/touchscreengui.cpp
index e1a971462..78b18c2d9 100644
--- a/src/gui/touchscreengui.cpp
+++ b/src/gui/touchscreengui.cpp
@@ -40,7 +40,7 @@ const char **button_imagenames = (const char *[]) {
"jump_btn.png",
"down.png",
"zoom.png",
- "aux_btn.png"
+ "aux1_btn.png"
};
const char **joystick_imagenames = (const char *[]) {
@@ -80,8 +80,8 @@ static irr::EKEY_CODE id2keycode(touch_gui_button_id id)
case zoom_id:
key = "zoom";
break;
- case special1_id:
- key = "special1";
+ case aux1_id:
+ key = "aux1";
break;
case fly_id:
key = "freemove";
@@ -425,7 +425,7 @@ TouchScreenGUI::TouchScreenGUI(IrrlichtDevice *device, IEventReceiver *receiver)
m_touchscreen_threshold = g_settings->getU16("touchscreen_threshold");
m_fixed_joystick = g_settings->getBool("fixed_virtual_joystick");
- m_joystick_triggers_special1 = g_settings->getBool("virtual_joystick_triggers_aux");
+ m_joystick_triggers_aux1 = g_settings->getBool("virtual_joystick_triggers_aux1");
m_screensize = m_device->getVideoDriver()->getScreenSize();
button_size = MYMIN(m_screensize.Y / 4.5f,
porting::getDisplayDensity() *
@@ -521,9 +521,9 @@ void TouchScreenGUI::init(ISimpleTextureSource *tsrc)
m_screensize.Y - (3 * button_size)),
L"z", false);
- // init special1/aux button
- if (!m_joystick_triggers_special1)
- initButton(special1_id,
+ // init aux1 button
+ if (!m_joystick_triggers_aux1)
+ initButton(aux1_id,
rect<s32>(m_screensize.X - (1.25 * button_size),
m_screensize.Y - (2.5 * button_size),
m_screensize.X - (0.25 * button_size),
@@ -923,7 +923,7 @@ void TouchScreenGUI::translateEvent(const SEvent &event)
}
if (distance > button_size) {
- m_joystick_status[j_special1] = true;
+ m_joystick_status[j_aux1] = true;
// move joystick "button"
s32 ndx = button_size * dx / distance - button_size / 2.0f;
s32 ndy = button_size * dy / distance - button_size / 2.0f;
@@ -1039,7 +1039,7 @@ bool TouchScreenGUI::doubleTapDetection()
void TouchScreenGUI::applyJoystickStatus()
{
for (unsigned int i = 0; i < 5; i++) {
- if (i == 4 && !m_joystick_triggers_special1)
+ if (i == 4 && !m_joystick_triggers_aux1)
continue;
SEvent translated{};
diff --git a/src/gui/touchscreengui.h b/src/gui/touchscreengui.h
index 761d33207..ad5abae87 100644
--- a/src/gui/touchscreengui.h
+++ b/src/gui/touchscreengui.h
@@ -18,6 +18,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#pragma once
+#include "irrlichttypes.h"
#include <IEventReceiver.h>
#include <IGUIButton.h>
#include <IGUIEnvironment.h>
@@ -38,7 +39,7 @@ typedef enum
jump_id = 0,
crunch_id,
zoom_id,
- special1_id,
+ aux1_id,
after_last_element_id,
settings_starter_id,
rare_controls_starter_id,
@@ -68,7 +69,7 @@ typedef enum
j_backward,
j_left,
j_right,
- j_special1
+ j_aux1
} touch_gui_joystick_move_id;
typedef enum
@@ -216,7 +217,7 @@ private:
// forward, backward, left, right
touch_gui_button_id m_joystick_names[5] = {
- forward_id, backward_id, left_id, right_id, special1_id};
+ forward_id, backward_id, left_id, right_id, aux1_id};
bool m_joystick_status[5] = {false, false, false, false, false};
/*
@@ -236,7 +237,7 @@ private:
int m_joystick_id = -1;
bool m_joystick_has_really_moved = false;
bool m_fixed_joystick = false;
- bool m_joystick_triggers_special1 = false;
+ bool m_joystick_triggers_aux1 = false;
button_info *m_joystick_btn_off = nullptr;
button_info *m_joystick_btn_bg = nullptr;
button_info *m_joystick_btn_center = nullptr;