Index: binaries/data/mods/mod/gui/gui.rnc =================================================================== --- binaries/data/mods/mod/gui/gui.rnc +++ binaries/data/mods/mod/gui/gui.rnc @@ -71,6 +71,8 @@ attribute maxwidth { xsd:decimal }? & attribute multiline { bool }?& attribute offset { pos }?& + attribute placeholder_text { text }?& + attribute placeholder_color { ccolor }?& attribute readonly { bool }?& attribute scrollbar { bool }?& attribute scrollbar_style { text }?& Index: binaries/data/mods/mod/gui/gui.rng =================================================================== --- binaries/data/mods/mod/gui/gui.rng +++ binaries/data/mods/mod/gui/gui.rng @@ -435,6 +435,14 @@ + + + + + + + + Index: binaries/data/mods/mod/gui/modmod/modmod.js =================================================================== --- binaries/data/mods/mod/gui/modmod/modmod.js +++ binaries/data/mods/mod/gui/modmod/modmod.js @@ -104,8 +104,6 @@ function initGUIFilters() { Engine.GetGUIObjectByName("negateFilter").checked = false; - Engine.GetGUIObjectByName("modGenericFilter").caption = translate("Filter"); - displayModLists(); } @@ -251,7 +249,6 @@ let searchText = Engine.GetGUIObjectByName("modGenericFilter").caption; if (searchText && - searchText != translate("Filter") && folder.indexOf(searchText) == -1 && mod.name.indexOf(searchText) == -1 && mod.label.indexOf(searchText) == -1 && Index: binaries/data/mods/mod/gui/modmod/modmod.xml =================================================================== --- binaries/data/mods/mod/gui/modmod/modmod.xml +++ binaries/data/mods/mod/gui/modmod/modmod.xml @@ -18,9 +18,11 @@ type="input" style="ModernInput" size="16 0 176 100%" + placeholder_color="gray" > applyFilters(); applyFilters(); + Filter Index: source/gui/ObjectTypes/CInput.h =================================================================== --- source/gui/ObjectTypes/CInput.h +++ source/gui/ObjectTypes/CInput.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2019 Wildfire Games. +/* Copyright (C) 2020 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -20,6 +20,8 @@ #include "gui/CGUISprite.h" #include "gui/ObjectBases/IGUIScrollBarOwner.h" +#include "gui/ObjectBases/IGUITextOwner.h" +#include "gui/SettingTypes/CGUIString.h" #include "lib/external_libraries/libsdl.h" #include @@ -31,7 +33,7 @@ * any other features than word-wrapping, and we need to be * able to rapidly change the string. */ -class CInput : public IGUIObject, public IGUIScrollBarOwner +class CInput : public IGUIObject, public IGUIScrollBarOwner, public IGUITextOwner { GUI_OBJECT(CInput) @@ -56,6 +58,8 @@ int GetXTextPosition(const std::list::const_iterator& c, const float& x, float& wanted) const; protected: + void SetupText(); + /** * @see IGUIObject#HandleMessage() */ @@ -198,6 +202,7 @@ i32 m_BufferPosition; float m_BufferZone; CStrW m_Caption; + CGUIString m_PlaceholderText; i32 m_CellID; CStrW m_Font; CStrW m_MaskChar; @@ -211,6 +216,7 @@ CGUISpriteInstance m_SpriteSelectArea; CGUIColor m_TextColor; CGUIColor m_TextColorSelected; + CGUIColor m_PlaceholderColor; }; #endif // INCLUDED_CINPUT Index: source/gui/ObjectTypes/CInput.cpp =================================================================== --- source/gui/ObjectTypes/CInput.cpp +++ source/gui/ObjectTypes/CInput.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2019 Wildfire Games. +/* Copyright (C) 2020 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -24,6 +24,7 @@ #include "graphics/TextRenderer.h" #include "gui/CGUI.h" #include "gui/CGUIScrollBarVertical.h" +#include "gui/CGUIText.h" #include "lib/sysdep/clipboard.h" #include "lib/timer.h" #include "lib/utf8.h" @@ -45,6 +46,7 @@ : IGUIObject(pGUI), IGUIScrollBarOwner(*static_cast(this)), + IGUITextOwner(*static_cast(this)), m_iBufferPos(-1), m_iBufferPos_Tail(-1), m_SelectingText(), @@ -89,12 +91,16 @@ RegisterSetting("sprite_selectarea", m_SpriteSelectArea); RegisterSetting("textcolor", m_TextColor); RegisterSetting("textcolor_selected", m_TextColorSelected); + RegisterSetting("placeholder_text", m_PlaceholderText); + RegisterSetting("placeholder_color", m_PlaceholderColor); CFG_GET_VAL("gui.cursorblinkrate", m_CursorBlinkRate); CGUIScrollBarVertical* bar = new CGUIScrollBarVertical(pGUI); bar->SetRightAligned(true); AddScrollBar(bar); + + AddText(); } CInput::~CInput() @@ -115,6 +121,14 @@ m_iComposedPos = 0; } +void CInput::SetupText() +{ + ENSURE(m_GeneratedTexts.size() == 1); + CStrIntern font_name(m_Font.ToUTF8()); + CFontMetrics font(font_name); + m_GeneratedTexts[0] = CGUIText(m_pGUI, m_PlaceholderText, m_Font, font.GetHeight(), m_BufferZone, this); +} + InReaction CInput::ManuallyHandleEvent(const SDL_Event_* ev) { ENSURE(m_iBufferPos != -1); @@ -905,6 +919,15 @@ UpdateText(); } + if (Message.value == "placeholder_text" || + Message.value == "size" || + Message.value == "placeholder_text" || + Message.value == "text_valign" || + Message.value == "placeholder_color") + { + m_GeneratedTextsValid = false; + } + UpdateAutoScroll(); break; @@ -1132,6 +1155,7 @@ // update our scrollbar positions IGUIObject::UpdateCachedSize(); + IGUITextOwner::UpdateCachedSize(); if (m_ScrollBar) { @@ -1484,6 +1508,10 @@ glDisable(GL_SCISSOR_TEST); tech->EndPass(); + + if (m_Caption.empty() && !m_PlaceholderText.GetRawString().empty()) + DrawText(0, m_PlaceholderColor, m_CachedActualSize.TopLeft(), bz); + } void CInput::UpdateText(int from, int to_before, int to_after)