From 69f62cdf6d491fe8bd472d7b8ff1266f4e5668ed Mon Sep 17 00:00:00 2001 From: Gwilherm Baudic Date: Wed, 13 Nov 2024 20:39:10 +0100 Subject: [PATCH] Add PasswordField widget --- SConstruct | 1 + include/guisan.hpp | 1 + include/guisan/widgets/passwordfield.hpp | 99 ++++++++++++++++++++++++ src/SConscript | 1 + src/widgets/passwordfield.cpp | 93 ++++++++++++++++++++++ 5 files changed, 195 insertions(+) create mode 100644 include/guisan/widgets/passwordfield.hpp create mode 100644 src/widgets/passwordfield.cpp diff --git a/SConstruct b/SConstruct index ade8d19..cb45b86 100644 --- a/SConstruct +++ b/SConstruct @@ -112,6 +112,7 @@ widget_headers = [ 'include/guisan/widgets/label.hpp', 'include/guisan/widgets/listbox.hpp', 'include/guisan/widgets/messagebox.hpp', + 'include/guisan/widgets/passwordfield.hpp', 'include/guisan/widgets/progressbar.hpp', 'include/guisan/widgets/radiobutton.hpp', 'include/guisan/widgets/scrollarea.hpp', diff --git a/include/guisan.hpp b/include/guisan.hpp index 65aba43..6673257 100644 --- a/include/guisan.hpp +++ b/include/guisan.hpp @@ -102,6 +102,7 @@ #include #include #include +#include #include #include #include diff --git a/include/guisan/widgets/passwordfield.hpp b/include/guisan/widgets/passwordfield.hpp new file mode 100644 index 0000000..f3affd1 --- /dev/null +++ b/include/guisan/widgets/passwordfield.hpp @@ -0,0 +1,99 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * Copyright (c) 2004, 2005, 2006, 2007 Olof Naessén and Per Larsson + * + * Js_./ + * Per Larsson a.k.a finalman _RqZ{a<^_aa + * Olof Naessén a.k.a jansem/yakslem _asww7!uY`> )\a// + * _Qhm`] _f "'c 1!5m + * Visit: http://guichan.darkbits.org )Qk

ws?a-?' ._/L #' + * binary forms, with or without )4d[#7r, . ' )d`)[ + * modification, are permitted provided _Q-5'5W..j/?' -?!\)cam' + * that the following conditions are met: j<. a J@\ + * this list of conditions and the j(]1u + +namespace gcn +{ + /** + * A text field in which you can write or display a line of text. + * Unlike a TextField the text will appear as '*' instead of the real content. + * If for some reason the Font you are using does not contain this character, the + * PasswordField will be filled by spaces. + */ + class GCN_CORE_DECLSPEC PasswordField: + public TextField + { + public: + /** + * Default constructor. + */ + PasswordField(); + + /** + * Constructor. Initializes the passwordfield with a given string. + * + * @param text the initial text. + */ + PasswordField(const std::string& text); + + // Inherited from Widget + + void draw(Graphics* graphics) override; + + }; +} + +#endif // end GCN_PASSWORDFIELD_HPP diff --git a/src/SConscript b/src/SConscript index 67a863d..175cde9 100644 --- a/src/SConscript +++ b/src/SConscript @@ -44,6 +44,7 @@ widget_sources = [ 'widgets/label.cpp', 'widgets/listbox.cpp', 'widgets/messagebox.cpp', + 'widgets/passwordfield.cpp', 'widgets/progressbar.cpp', 'widgets/radiobutton.cpp', 'widgets/scrollarea.cpp', diff --git a/src/widgets/passwordfield.cpp b/src/widgets/passwordfield.cpp new file mode 100644 index 0000000..8d97a80 --- /dev/null +++ b/src/widgets/passwordfield.cpp @@ -0,0 +1,93 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * Copyright (c) 2004, 2005, 2006, 2007 Olof Naessén and Per Larsson + * + * Js_./ + * Per Larsson a.k.a finalman _RqZ{a<^_aa + * Olof Naessén a.k.a jansem/yakslem _asww7!uY`> )\a// + * _Qhm`] _f "'c 1!5m + * Visit: http://guichan.darkbits.org )Qk

ws?a-?' ._/L #' + * binary forms, with or without )4d[#7r, . ' )d`)[ + * modification, are permitted provided _Q-5'5W..j/?' -?!\)cam' + * that the following conditions are met: j<. a J@\ + * this list of conditions and the j(]1ugetRow(0).size(), '*'); + std::string realText(mText->getRow(0)); + + // Switch replacement text before drawing it to hide it + mText->setRow(0, encodedText); + TextField::draw(graphics); + mText->setRow(0, realText); + } + +}