fill-style.cpp revision 42bf51258f01d33f730d1926e4fd050bbe5d6df2
/**
* @file
* Fill style widget.
*/
/* Authors:
* Lauris Kaplinski <lauris@kaplinski.com>
* Frank Felfe <innerspace@iname.com>
* bulia byak <buliabyak@users.sf.net>
* Jon A. Cruz <jon@joncruz.org>
* Abhishek Sharma
*
* Copyright (C) 1999-2005 authors
* Copyright (C) 2001-2002 Ximian, Inc.
* Copyright (C) 2010 Jon A. Cruz
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#define noSP_FS_VERBOSE
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#endif
#include "verbs.h"
#include "desktop.h"
#include "selection.h"
#include "desktop-handles.h"
#include "desktop-style.h"
#include "display/sp-canvas.h"
#include "document-private.h"
#include "document-undo.h"
#include "gradient-chemistry.h"
#include "inkscape.h"
#include "selection.h"
#include "sp-linear-gradient.h"
#include "sp-pattern.h"
#include "sp-radial-gradient.h"
#include "style.h"
#include "widgets/paint-selector.h"
#include "fill-style.h"
#include "fill-n-stroke-factory.h"
// These can be deleted once we sort out the libart dependence.
#define ART_WIND_RULE_NONZERO 0
/* Fill */
{
}
namespace Inkscape {
{
public:
~FillNStroke();
private:
static void paintModeChangeCB(SPPaintSelector *psel, SPPaintSelector::Mode mode, FillNStroke *self);
static void fillruleChangedCB( SPPaintSelector *psel, SPPaintSelector::FillRule mode, FillNStroke *self );
void dragFromPaint();
void updateFromPaint();
void performUpdate();
bool update;
};
} // namespace Inkscape
{
if (fs) {
}
}
namespace Inkscape {
/**
* Create the fill or stroke style widget, and hook up all the signals.
*/
{
return filler;
}
desktop(0),
psel(0),
lastDrag(0),
dragId(0),
update(false),
{
// Add and connect up the paint selector widget:
this );
this );
this );
this );
}
}
{
if (dragId) {
dragId = 0;
}
psel = 0;
}
/**
* On signal modified, invokes an update of the fill or stroke style paint object.
*/
{
if (flags & ( SP_OBJECT_MODIFIED_FLAG |
#ifdef SP_FS_VERBOSE
#endif
}
}
{
if (dragId) {
dragId = 0;
}
if (this->desktop) {
}
selectChangedConn = desktop->selection->connectChanged(sigc::hide(sigc::mem_fun(*this, &FillNStroke::performUpdate)));
subselChangedConn = desktop->connectToolSubselectionChanged(sigc::hide(sigc::mem_fun(*this, &FillNStroke::performUpdate)));
eventContextConn = desktop->connectEventContextChanged(sigc::hide(sigc::bind(sigc::mem_fun(*this, &FillNStroke::eventContextCB), (Inkscape::UI::Tools::ToolBase *)NULL)));
// Must check flags, so can't call performUpdate() directly.
selectModifiedConn = desktop->selection->connectModified(sigc::hide<0>(sigc::mem_fun(*this, &FillNStroke::selectionModifiedCB)));
}
}
}
/**
* Listen to this "change in tool" event, in case a subselection tool (such as Gradient or Node) selection
* is changed back to a selection tool - especially needed for selected gradient stops.
*/
void FillNStroke::eventContextCB(SPDesktop * /*desktop*/, Inkscape::UI::Tools::ToolBase * /*eventcontext*/)
{
}
/**
* Gets the active fill or stroke style property, then sets the appropriate
* color, alpha, gradient, pattern, etc. for the paint-selector.
*
* @param sel Selection to use, or NULL.
*/
void FillNStroke::performUpdate()
{
return;
}
if ( dragId ) {
// local change; do nothing, but reset the flag
dragId = 0;
return;
}
update = true;
// create temporary style
// query style from desktop into it. This returns a result flag and fills query with the style of subselection, if any, or selection
int result = sp_desktop_query_style(desktop, query, (kind == FILL) ? QUERY_STYLE_PROPERTY_FILL : QUERY_STYLE_PROPERTY_STROKE);
switch (result) {
case QUERY_STYLE_NOTHING:
{
/* No paint at all */
break;
}
case QUERY_STYLE_SINGLE:
case QUERY_STYLE_MULTIPLE_AVERAGED: // TODO: treat this slightly differently, e.g. display "averaged" somewhere in paint selector
{
}
SPPaintServer *server = (kind == FILL) ? query->getFillPaintServer() : query->getStrokePaintServer();
} else if (SP_IS_LINEARGRADIENT(server)) {
} else if (SP_IS_RADIALGRADIENT(server)) {
} else if (SP_IS_PATTERN(server)) {
}
}
break;
}
{
break;
}
}
update = false;
}
/**
* When the mode is changed, invoke a regular changed handler.
*/
FillNStroke *self )
{
#ifdef SP_FS_VERBOSE
#endif
self->updateFromPaint();
}
}
FillNStroke *self )
{
if (self) {
}
}
{
sp_repr_css_set_property(css, "fill-rule", (mode == SPPaintSelector::FILLRULE_EVENODD) ? "evenodd":"nonzero");
css = 0;
_("Change fill rule"));
}
}
{
#ifdef SP_FS_VERBOSE
#endif
self->dragFromPaint();
}
}
{
if (data) {
self->dragFromPaint();
self->performUpdate();
}
}
} else {
}
return keepGoing;
}
/**
* This is called repeatedly while you are dragging a color slider, only for flat color
* modes. Previously it set the color in style but did not update the repr for efficiency, however
* this was flakey and didn't buy us almost anything. So now it does the same as _changed, except
* lumps all its changes for undo.
*/
void FillNStroke::dragFromPaint()
{
return;
}
// Don't attempt too many updates per second.
// Assume a base 15.625ms resolution on the timer.
// local change, do not update from selection
}
if (dragId) {
// previous local flag not cleared yet;
// this means dragged events come too fast, so we better skip this one to speed up display
// (it's safe to do this in any case)
return;
}
update = true;
case SPPaintSelector::MODE_COLOR_RGB:
case SPPaintSelector::MODE_COLOR_CMYK:
{
// local change, do not update from selection
psel->setFlatColor( desktop, (kind == FILL) ? "fill" : "stroke", (kind == FILL) ? "fill-opacity" : "stroke-opacity" );
DocumentUndo::maybeDone(desktop->doc(), (kind == FILL) ? undo_F_label : undo_S_label, SP_VERB_DIALOG_FILL_STROKE,
break;
}
default:
g_warning( "file %s: line %d: Paint %d should not emit 'dragged'",
break;
}
update = false;
}
/**
This is called (at least) when:
1 paint selector mode is switched (e.g. flat color -> gradient)
2 you finished dragging a gradient node and released mouse
3 you changed a gradient selector parameter (e.g. spread)
Must update repr.
*/
{
#ifdef SP_FS_VERBOSE
#endif
self->updateFromPaint();
}
}
void FillNStroke::updateFromPaint()
{
if (!desktop) {
return;
}
update = true;
case SPPaintSelector::MODE_EMPTY:
// This should not happen.
g_warning( "file %s: line %d: Paint %d should not emit 'changed'",
break;
case SPPaintSelector::MODE_MULTIPLE:
// This happens when you switch multiple objects with different gradients to flat color;
// nothing to do here.
break;
case SPPaintSelector::MODE_NONE:
{
css = 0;
break;
}
case SPPaintSelector::MODE_COLOR_RGB:
case SPPaintSelector::MODE_COLOR_CMYK:
{
// FIXME: fix for GTK breakage, see comment in SelectedStyle::on_opacity_changed; here it results in losing release events
}
DocumentUndo::maybeDone(sp_desktop_document(desktop), (kind == FILL) ? undo_F_label : undo_S_label, SP_VERB_DIALOG_FILL_STROKE,
// resume interruptibility
}
// on release, toggle undo_label so that the next drag will not be lumped with this one
if (undo_F_label == undo_F_label_1) {
} else {
}
break;
}
case SPPaintSelector::MODE_SWATCH:
if (items) {
// HACK: reset fill-opacity - that 0.75 is annoying; BUT remove this when we have an opacity slider for all tabs
css = sp_repr_css_attr_new();
}
if (!vector) {
/* No vector in paint selector should mean that we just changed mode */
if (result == QUERY_STYLE_MULTIPLE_SAME) {
} else {
}
if ( vector && createSwatch ) {
}
}
//FIXME: see above
}
if (!vector) {
createSwatch );
if ( gr && createSwatch ) {
}
gr,
} else {
sp_item_set_gradient(SP_ITEM(i->data), vector, gradient_type, (kind == FILL) ? Inkscape::FOR_FILL : Inkscape::FOR_STROKE);
}
}
} else {
// this gradient type.
//FIXME: see above
}
SPGradient *gr = sp_item_set_gradient(SP_ITEM(i->data), vector, gradient_type, (kind == FILL) ? Inkscape::FOR_FILL : Inkscape::FOR_STROKE);
}
}
if (css) {
css = 0;
}
}
break;
case SPPaintSelector::MODE_PATTERN:
if (items) {
if (!pattern) {
/* No Pattern in paint selector should mean that we just
* changed mode - dont do jack.
*/
} else {
// HACK: reset fill-opacity - that 0.75 is annoying; BUT remove this when we have an opacity slider for all tabs
}
// cannot just call sp_desktop_set_style, because we don't want to touch those
// objects who already have the same root pattern but through a different href
// chain. FIXME: move this to a sp_item_set_pattern
continue;
}
// only if this object's pattern is not rooted in our selected pattern, apply
continue;
}
} else {
}
}
css = 0;
} // end if
_("Set pattern on stroke"));
} // end if
break;
case SPPaintSelector::MODE_UNSET:
if (items) {
} else {
}
css = 0;
}
break;
default:
g_warning( "file %s: line %d: Paint selector should not be in "
"mode %d",
break;
}
update = false;
}
} // namespace Inkscape
/*
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 :