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,7 +104,6 @@ function initGUIFilters() { Engine.GetGUIObjectByName("negateFilter").checked = false; - Engine.GetGUIObjectByName("modGenericFilter").caption = translate("Filter"); displayModLists(); } @@ -251,7 +250,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,7 @@ #include "gui/CGUISprite.h" #include "gui/ObjectBases/IGUIScrollBarOwner.h" +#include "gui/SettingTypes/CGUIString.h" #include "lib/external_libraries/libsdl.h" #include @@ -57,6 +58,18 @@ protected: /** + * Adds a text object. + */ + CGUIText& AddText(); + + /** + * Adds a text generated by the given arguments. + */ + CGUIText& AddText(const CGUIString& Text, const CStrW& Font, const float& Width, const float& BufferZone); + + void SetupGeneratedText(); + + /** * @see IGUIObject#HandleMessage() */ virtual void HandleMessage(SGUIMessage& Message); @@ -103,6 +116,20 @@ */ void UpdateText(int from = 0, int to_before = -1, int to_after = -1); + void UpdateGeneratedText(); + + /** + * Draws the Text. + * + * @param index Index value of text. Mostly this will be 0 + * @param color + * @param pos Position + * @param z Z value + * @param clipping Clipping rectangle, don't even add a parameter + * to get no clipping. + */ + virtual void DrawText(size_t index, const CGUIColor& color, const CPos& pos, float z, const CRect& clipping = CRect()); + /** * Delete the current selection. Also places the pointer at the * crack between the two segments kept. @@ -178,6 +205,16 @@ */ bool m_SelectingText; + /** + * Whether the cached text is currently valid (if not then SetupText will be called by Draw) + */ + bool m_GeneratedTextsValid; + + /** + * Texts that are generated and ready to be rendered. + */ + std::vector m_GeneratedTexts; + // *** Things for one-line input control *** // float m_HorizontalScroll; @@ -198,6 +235,7 @@ i32 m_BufferPosition; float m_BufferZone; CStrW m_Caption; + CGUIString m_PlaceholderText; i32 m_CellID; CStrW m_Font; CStrW m_MaskChar; @@ -211,6 +249,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 @@ -52,6 +52,7 @@ m_CursorVisState(true), m_CursorBlinkRate(0.5), m_ComposingText(), + m_GeneratedTextsValid(), m_iComposedLength(), m_iComposedPos(), m_iInsertPos(), @@ -88,18 +89,36 @@ 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() { } +CGUIText& CInput::AddText() +{ + m_GeneratedTexts.emplace_back(); + return m_GeneratedTexts.back(); +} + +CGUIText& CInput::AddText(const CGUIString& Text, const CStrW& Font, const float& Width, const float& BufferZone) +{ + // Avoids a move constructor + IGUIObject &pObject = *static_cast(this); + m_GeneratedTexts.emplace_back(pObject.GetGUI(), Text, Font, Width, BufferZone, &pObject); + return m_GeneratedTexts.back(); +} + void CInput::UpdateBufferPositionSetting() { SetSetting("buffer_position", m_iBufferPos, false); @@ -114,6 +133,16 @@ m_iComposedPos = 0; } +void CInput::SetupGeneratedText() +{ + 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, 0, m_BufferZone, this); + m_GeneratedTextsValid = true; +} + InReaction CInput::ManuallyHandleEvent(const SDL_Event_* ev) { ENSURE(m_iBufferPos != -1); @@ -905,6 +934,15 @@ UpdateText(); } + if (Message.value == "placeholder_text" || + Message.value == "size" || + Message.value == "font" || + Message.value == "z" || + Message.value == "text_valign") + { + m_GeneratedTextsValid = false; + } + UpdateAutoScroll(); break; @@ -1140,6 +1178,8 @@ GetScrollBar(0).SetZ(GetBufferedZ()); GetScrollBar(0).SetLength(m_CachedActualSize.bottom - m_CachedActualSize.top); } + + m_GeneratedTextsValid = false; } void CInput::Draw() @@ -1484,6 +1524,27 @@ glDisable(GL_SCISSOR_TEST); tech->EndPass(); + + if (m_Caption.empty() && !m_PlaceholderText.GetRawString().empty()) + DrawText(0, m_PlaceholderColor, m_CachedActualSize.TopLeft(), bz, cliparea); +} + +void CInput::DrawText(size_t index, const CGUIColor& color, const CPos& pos, float z, const CRect& clipping) +{ + UpdateGeneratedText(); + + IGUIObject &pObject = *static_cast(this); + ENSURE(index < m_GeneratedTexts.size() && "Trying to draw a Generated Text Index within a CInput that doesn't exist"); + + m_GeneratedTexts.at(index).Draw(pObject.GetGUI(), color, pos, z, clipping); +} + +void CInput::UpdateGeneratedText() +{ + if (m_GeneratedTextsValid) + return; + + SetupGeneratedText(); } void CInput::UpdateText(int from, int to_before, int to_after)