Code

svg-filters branch merged back to head
[inkscape.git] / src / number-opt-number.h
1 #ifndef SEEN_NUMBER_OPT_NUMBER_H
2 #define SEEN_NUMBER_OPT_NUMBER_H
4 /** \file
5  * <number-opt-number> implementation.
6  */
7 /*
8  * Authors:
9  *   Hugo Rodrigues <haa.rodrigues@gmail.com>
10  *
11  * Copyright (C) 2006 Hugo Rodrigues
12  *
13  * Released under GNU GPL, read the file 'COPYING' for more information
14  */
16 #include <glib.h>
17 #include <glib/gprintf.h>
18 //todo: use glib instead of stdlib
19 #include <stdlib.h>
21 #ifdef HAVE_CONFIG_H
22 #include "config.h"
23 #endif
25 class NumberOptNumber {
27 public:
29     gfloat number; 
31     gfloat optNumber;
33     guint _set : 1;
35     guint optNumber_set : 1;
37     NumberOptNumber()
38     {
39         number = 0.0;
40         optNumber = 0.0;
42         _set = FALSE;
43         optNumber_set = FALSE;
44     }
46     gfloat getNumber()
47     { return number; }
49     gfloat getOptNumber()
50     { return optNumber; }
52     gchar *getValueString(gchar *str)
53     { 
54         if( _set )
55         {
57             if( optNumber_set )
58             {
59                 g_sprintf(str, "%lf %lf", number, optNumber);
60             }
61             else {
62                 g_sprintf(str, "%lf", number);
63             }
64         }
65         return str;
66     }
68     void set(gchar const *str)
69     {
70         if(!str)
71             return;
73         gchar **values = g_strsplit(str, " ", 2);
75         if( values[0] != NULL )
76         {
77             number = strtof(values[0], NULL);
78             _set = TRUE;
80             if( values[1] != NULL )
81             {
82   //              optNumber = g_ascii_strtod(values[1], NULL);
83                 optNumber = strtof(values[1], NULL);
84                 optNumber_set = TRUE;
85             }
86             else
87                 optNumber_set = FALSE;
88         }
89         else {
90                 _set = FALSE;
91                 optNumber_set = FALSE;
92         }
93     }
95 };
97 #endif /* !SEEN_NUMBER_OPT_NUMBER_H */
99 /*
100   Local Variables:
101   mode:c++
102   c-file-style:"stroustrup"
103   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
104   indent-tabs-mode:nil
105   fill-column:99
106   End:
107 */
108 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :