diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:24:48 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:24:48 +0000 |
commit | cca66b9ec4e494c1d919bff0f71a820d8afab1fa (patch) | |
tree | 146f39ded1c938019e1ed42d30923c2ac9e86789 /src/number-opt-number.h | |
parent | Initial commit. (diff) | |
download | inkscape-upstream/1.2.2.tar.xz inkscape-upstream/1.2.2.zip |
Adding upstream version 1.2.2.upstream/1.2.2upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | src/number-opt-number.h | 137 |
1 files changed, 137 insertions, 0 deletions
diff --git a/src/number-opt-number.h b/src/number-opt-number.h new file mode 100644 index 0000000..6c7aee4 --- /dev/null +++ b/src/number-opt-number.h @@ -0,0 +1,137 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +#ifndef SEEN_NUMBER_OPT_NUMBER_H +#define SEEN_NUMBER_OPT_NUMBER_H + +/** \file + * <number-opt-number> implementation. + */ +/* + * Authors: + * Hugo Rodrigues <haa.rodrigues@gmail.com> + * + * Copyright (C) 2006 Hugo Rodrigues + * + * Released under GNU GPL v2+, read the file 'COPYING' for more information. + */ + +#include <glib.h> +#include <glib/gprintf.h> +#include <cstdlib> + +#include "svg/stringstream.h" + +class NumberOptNumber { + +public: + + float number; + + float optNumber; + + unsigned int _set : 1; + + unsigned int optNumber_set : 1; + + NumberOptNumber() + { + number = 0.0; + optNumber = 0.0; + + _set = FALSE; + optNumber_set = FALSE; + } + + float getNumber() const + { + if(_set) + return number; + return -1; + } + + float getOptNumber() const + { + if(optNumber_set) + return optNumber; + return -1; + } + + void setOptNumber(float num) + { + optNumber_set = true; + optNumber = num; + } + + void setNumber(float num) + { + _set = true; + number = num; + } + + bool optNumIsSet() const { + return optNumber_set; + } + + bool numIsSet() const { + return _set; + } + + std::string getValueString() const + { + Inkscape::SVGOStringStream os; + + if( _set ) + { + + if( optNumber_set ) + { + os << number << " " << optNumber; + } + else { + os << number; + } + } + return os.str(); + } + + void set(char const *str) + { + if(!str) + return; + + char **values = g_strsplit(str, " ", 2); + + if( values[0] != nullptr ) + { + number = g_ascii_strtod(values[0], nullptr); + _set = TRUE; + + if( values[1] != nullptr ) + { + optNumber = g_ascii_strtod(values[1], nullptr); + optNumber_set = TRUE; + } + else + optNumber_set = FALSE; + } + else { + _set = FALSE; + optNumber_set = FALSE; + } + + g_strfreev(values); + } + +}; + +#endif /* !SEEN_NUMBER_OPT_NUMBER_H */ + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : |