Sdk/TextAreaWidget: Add support for EchoMode

This commit is contained in:
Jérôme Leclercq
2017-11-10 13:12:04 +01:00
parent 4a238f825a
commit bb6e032b60
5 changed files with 112 additions and 34 deletions

View File

@@ -17,6 +17,15 @@ namespace Ndk
CheckboxState_Max = CheckboxState_Unchecked
};
enum EchoMode
{
EchoMode_Normal,
EchoMode_Password,
EchoMode_PasswordExceptLast,
EchoMode_Max = EchoMode_PasswordExceptLast
};
}
#endif // NAZARA_ENUMS_SDK_HPP

View File

@@ -7,10 +7,10 @@
#ifndef NDK_WIDGETS_TEXTAREAWIDGET_HPP
#define NDK_WIDGETS_TEXTAREAWIDGET_HPP
#include <NDK/Prerequesites.hpp>
#include <NDK/BaseWidget.hpp>
#include <Nazara/Utility/SimpleTextDrawer.hpp>
#include <Nazara/Graphics/TextSprite.hpp>
#include <Nazara/Utility/SimpleTextDrawer.hpp>
#include <NDK/BaseWidget.hpp>
#include <NDK/Widgets/Enums.hpp>
namespace Ndk
{
@@ -30,9 +30,11 @@ namespace Ndk
inline void EnableMultiline(bool enable = true);
inline unsigned int GetCharacterSize() const;
inline const Nz::Vector2ui& GetCursorPosition() const;
inline const Nz::String& GetDisplayText() const;
inline EchoMode GetEchoMode() const;
inline std::size_t GetGlyphUnderCursor() const;
inline std::size_t GetLineCount() const;
inline const Nz::String& GetText() const;
inline const Nz::Color& GetTextColor() const;
@@ -46,8 +48,10 @@ namespace Ndk
void ResizeToContent() override;
inline void SetCharacterSize(unsigned int characterSize);
inline void SetCursorPosition(std::size_t glyphIndex);
inline void SetCursorPosition(Nz::Vector2ui cursorPosition);
inline void SetEchoMode(EchoMode echoMode);
inline void SetReadOnly(bool readOnly = true);
inline void SetText(const Nz::String& text);
inline void SetTextColor(const Nz::Color& text);
@@ -77,11 +81,14 @@ namespace Ndk
void OnTextEntered(char32_t character, bool repeated) override;
void RefreshCursor();
void UpdateDisplayText();
EchoMode m_echoMode;
EntityHandle m_cursorEntity;
EntityHandle m_textEntity;
Nz::SimpleTextDrawer m_drawer;
Nz::SpriteRef m_cursorSprite;
Nz::String m_text;
Nz::TextSpriteRef m_textSprite;
Nz::Vector2ui m_cursorPosition;
std::size_t m_cursorGlyph;

View File

@@ -20,24 +20,34 @@ namespace Ndk
m_multiLineEnabled = enable;
}
inline unsigned int TextAreaWidget::GetCharacterSize() const
{
return m_drawer.GetCharacterSize();
}
inline const Nz::Vector2ui& TextAreaWidget::GetCursorPosition() const
{
return m_cursorPosition;
}
inline const Nz::String & TextAreaWidget::GetDisplayText() const
{
return m_drawer.GetText();
}
inline EchoMode TextAreaWidget::GetEchoMode() const
{
return m_echoMode;
}
inline std::size_t Ndk::TextAreaWidget::GetGlyphUnderCursor() const
{
return m_cursorGlyph;
}
inline std::size_t TextAreaWidget::GetLineCount() const
{
return m_drawer.GetLineCount();
}
inline const Nz::String& TextAreaWidget::GetText() const
{
return m_drawer.GetText();
return m_text;
}
inline const Nz::Color& TextAreaWidget::GetTextColor() const
@@ -92,12 +102,17 @@ namespace Ndk
SetCursorPosition(cursorPosition);
}
inline void TextAreaWidget::SetCharacterSize(unsigned int characterSize)
{
m_drawer.SetCharacterSize(characterSize);
}
inline void TextAreaWidget::SetCursorPosition(std::size_t glyphIndex)
{
OnTextAreaCursorMove(this, &glyphIndex);
m_cursorGlyph = std::min(glyphIndex, m_drawer.GetGlyphCount());
std::size_t lineCount = m_drawer.GetLineCount();
std::size_t line = 0U;
for (std::size_t i = line + 1; i < lineCount; ++i)
@@ -110,8 +125,8 @@ namespace Ndk
const auto& lineInfo = m_drawer.GetLine(line);
m_cursorPosition.y = line;
m_cursorPosition.x = m_cursorGlyph - lineInfo.glyphIndex;
m_cursorPosition.y = static_cast<unsigned int>(line);
m_cursorPosition.x = static_cast<unsigned int>(m_cursorGlyph - lineInfo.glyphIndex);
RefreshCursor();
}
@@ -140,6 +155,13 @@ namespace Ndk
RefreshCursor();
}
inline void TextAreaWidget::SetEchoMode(EchoMode echoMode)
{
m_echoMode = echoMode;
UpdateDisplayText();
}
inline void TextAreaWidget::SetReadOnly(bool readOnly)
{
m_readOnly = readOnly;
@@ -149,11 +171,9 @@ namespace Ndk
inline void TextAreaWidget::SetText(const Nz::String& text)
{
m_drawer.SetText(text);
m_text = text;
m_textSprite->Update(m_drawer);
SetCursorPosition(m_cursorPosition); //< Refresh cursor position (prevent it from being outside of the text)
UpdateDisplayText();
}
inline void TextAreaWidget::SetTextColor(const Nz::Color& text)