~valavanisalex/ubuntu/oneiric/inkscape/inkscape_0.48.1-2ubuntu4

« back to all changes in this revision

Viewing changes to src/extension/param/color.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Kees Cook, Ted Gould, Kees Cook
  • Date: 2009-06-24 14:00:43 UTC
  • mfrom: (1.1.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20090624140043-07stp20mry48hqup
Tags: 0.47~pre0-0ubuntu1
* New upstream release

[ Ted Gould ]
* debian/control: Adding libgsl0 and removing version specifics on boost

[ Kees Cook ]
* debian/watch: updated to run uupdate and mangle pre-release versions.
* Dropped patches that have been taken upstream:
  - 01_mips
  - 02-poppler-0.8.3
  - 03-chinese-inkscape
  - 05_fix_latex_patch
  - 06_gcc-4.4
  - 07_cdr2svg
  - 08_skip-bad-utf-on-pdf-import
  - 09_gtk-clist
  - 10_belarussian
  - 11_libpng
  - 12_desktop
  - 13_slider
  - 100_svg_import_improvements
  - 102_sp_pattern_painter_free
  - 103_bitmap_type_print

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2005-2007 Authors:
 
3
 *   Ted Gould <ted@gould.cx>
 
4
 *   Johan Engelen <johan@shouraizou.nl>
 
5
 *   Christopher Brown <audiere@gmail.com>
 
6
 * Released under GNU GPL, read the file 'COPYING' for more information
 
7
 */
 
8
 
 
9
#ifdef HAVE_CONFIG_H
 
10
# include "config.h"
 
11
#endif
 
12
 
 
13
#include <iostream>
 
14
#include <sstream>
 
15
 
 
16
#include <gtkmm/adjustment.h>
 
17
#include <gtkmm/box.h>
 
18
#include <gtkmm/spinbutton.h>
 
19
 
 
20
#include <xml/node.h>
 
21
 
 
22
#include "../extension.h"
 
23
#include "color.h"
 
24
 
 
25
#include <color.h>
 
26
#include "widgets/sp-color-selector.h"
 
27
#include "widgets/sp-color-notebook.h"
 
28
#include "preferences.h"
 
29
 
 
30
 
 
31
namespace Inkscape {
 
32
namespace Extension {
 
33
 
 
34
void sp_color_param_changed(SPColorSelector *csel, GObject *cp);
 
35
 
 
36
 
 
37
/** \brief  Free the allocated data. */
 
38
ParamColor::~ParamColor(void)
 
39
{
 
40
 
 
41
}
 
42
 
 
43
guint32
 
44
ParamColor::set( guint32 in, SPDocument * /*doc*/, Inkscape::XML::Node * /*node*/ )
 
45
{
 
46
    _value = in;
 
47
 
 
48
    gchar * prefname = this->pref_name();
 
49
    std::string value;
 
50
    string(value);
 
51
    
 
52
    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
 
53
    prefs->setString(extension_pref_root + prefname, value);
 
54
    g_free(prefname);
 
55
 
 
56
    return _value;
 
57
}
 
58
 
 
59
/** \brief  Initialize the object, to do that, copy the data. */
 
60
ParamColor::ParamColor (const gchar * name, const gchar * guitext, const gchar * desc, const Parameter::_scope_t scope, bool gui_hidden, const gchar * gui_tip, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml) :
 
61
    Parameter(name, guitext, desc, scope, gui_hidden, gui_tip, ext)
 
62
{
 
63
    const char * defaulthex = NULL;
 
64
    if (sp_repr_children(xml) != NULL)
 
65
        defaulthex = sp_repr_children(xml)->content();
 
66
 
 
67
    gchar * pref_name = this->pref_name();
 
68
    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
 
69
    Glib::ustring paramval = prefs->getString(extension_pref_root + pref_name);
 
70
    g_free(pref_name);
 
71
 
 
72
    if (!paramval.empty())
 
73
        defaulthex = paramval.data();
 
74
 
 
75
    _value = atoi(defaulthex);
 
76
 
 
77
    return;
 
78
}
 
79
 
 
80
void
 
81
ParamColor::string (std::string &string)
 
82
{
 
83
    char str[16];
 
84
    sprintf(str, "%i", _value);
 
85
    string += str;
 
86
    return;
 
87
}
 
88
 
 
89
Gtk::Widget *
 
90
ParamColor::get_widget( SPDocument * /*doc*/, Inkscape::XML::Node * /*node*/, sigc::signal<void> * changeSignal )
 
91
{
 
92
        if (_gui_hidden) return NULL;
 
93
 
 
94
    _changeSignal = new sigc::signal<void>(*changeSignal);
 
95
    Gtk::HBox * hbox = Gtk::manage(new Gtk::HBox(false, 4));
 
96
    SPColorSelector* spColorSelector = (SPColorSelector*)sp_color_selector_new(SP_TYPE_COLOR_NOTEBOOK);
 
97
 
 
98
    ColorSelector* colorSelector = spColorSelector->base;
 
99
    if (_value < 1) {
 
100
        _value = 0xFF000000;
 
101
    }
 
102
    SPColor *color = new SPColor( _value );
 
103
    float alpha = (_value & 0xff) / 255.0F;
 
104
    colorSelector->setColorAlpha(*color, alpha);
 
105
 
 
106
    hbox->pack_start (*Glib::wrap(&spColorSelector->vbox), true, true, 0);
 
107
    g_signal_connect(G_OBJECT(spColorSelector), "changed",  G_CALLBACK(sp_color_param_changed), (void*)this);
 
108
 
 
109
    gtk_widget_show(GTK_WIDGET(spColorSelector));
 
110
    hbox->show();
 
111
 
 
112
    return dynamic_cast<Gtk::Widget *>(hbox);
 
113
}
 
114
 
 
115
void
 
116
sp_color_param_changed(SPColorSelector *csel, GObject *obj)
 
117
{
 
118
    const SPColor color = csel->base->getColor();
 
119
    float alpha = csel->base->getAlpha();
 
120
 
 
121
    ParamColor* ptr = (ParamColor*)obj;
 
122
    ptr->set(color.toRGBA32( alpha ), NULL, NULL);
 
123
 
 
124
    ptr->_changeSignal->emit();
 
125
}
 
126
 
 
127
};  /* namespace Extension */
 
128
};  /* namespace Inkscape */