示例#1
0
    var _syncStoreToPs = function (document, layers, coalesce, type, options) {
        var documentStore = this.flux.store("document"),
            layerStruct = documentStore.getDocument(document.id).layers,
            layerEffectPlayObjects = [],
            syncOptions = {
                paintOptions: {
                    immediateUpdate: true,
                    quality: "draft"
                },
                historyStateInfo: {
                    name: nls.localize("strings.ACTIONS.SET_LAYER_EFFECTS"),
                    target: documentLib.referenceBy.id(document.id),
                    coalesce: !!coalesce,
                    suppressHistoryStateNotification: !!coalesce
                }
            },
            types = _.isArray(type) ? type : [type];

        options = _.merge({}, options, syncOptions);

        // Map the layers to a list of playable objects
        layers.forEach(function (curLayer) {
            // get this layer directly from the store and build a layer effect adapter object
            var layerFromStore = layerStruct.byID(curLayer.id),
                referenceID = layerEffectLib.referenceBy.id(curLayer.id),
                layerHasEffects = curLayer.usedToHaveLayerEffect;

            types.forEach(function (type) {
                var descriptorType = LayerEffect.getDescriptorType(type),
                    layerEffectsFromStore = layerFromStore.getLayerEffectsByType(type),
                    effectAdapterObject = layerEffectsFromStore
                        .map(function (effect) {
                            return effect.toAdapterObject();
                        }).toArray();

                if (layerHasEffects) {
                    layerEffectPlayObjects.push({
                        layer: curLayer,
                        playObject: layerEffectLib.setExtendedLayerEffect(descriptorType,
                            referenceID, effectAdapterObject)
                    });
                } else {
                    if (effectAdapterObject.length > 0) {
                        layerEffectPlayObjects.push({
                            layer: curLayer,
                            playObject: layerEffectLib.setLayerEffect(descriptorType, referenceID, effectAdapterObject)
                        });
                        layerHasEffects = true;
                    }
                }
            });
        });

        return layerActionsUtil.playLayerActions(document, Immutable.List(layerEffectPlayObjects), true, options);
    };
示例#2
0
    var setFillColor = function (document, layers, color, options) {
        // if a color is provided, adjust the alpha to one that can be represented as a fraction of 255
        color = color ? color.normalizeAlpha() : null;
        // if enabled is not provided, assume it is true
        options = _.merge({}, options);
        options.enabled = (options.enabled === undefined) ? true : options.enabled;

        // dispatch the change event    
        var dispatchPromise = _fillChangeDispatch.call(this,
                document,
                layers,
                { color: color, enabled: options.enabled, ignoreAlpha: options.ignoreAlpha },
                events.document.history.FILL_COLOR_CHANGED,
                options.coalesce),
            colorPromise;

        options = _mergeOptions(options, document, nls.localize("strings.ACTIONS.SET_FILL_COLOR"));

        if (!color && options.enabled) {
            // If color is not supplied, we want each layer to use it's own color
            var actions = layers.map(function (layer) {
                var layerRef = contentLayerLib.referenceBy.id(layer.id),
                    setFillObj = contentLayerLib.setShapeFillTypeSolidColor(layerRef, layer.fill.color);

                return {
                    layer: layer,
                    playObject: setFillObj
                };
            }, this);

            colorPromise = layerActionsUtil.playLayerActions(document, actions, true, options);
        } else {
            // build the playObject
            var contentLayerRef = contentLayerLib.referenceBy.current,
                layerRef = layerLib.referenceBy.current,
                fillColor = options.enabled ? color : null,
                fillColorObj = contentLayerLib.setShapeFillTypeSolidColor(contentLayerRef, fillColor);
                
            // submit to Ps
            if (options.enabled && !options.ignoreAlpha) {
                var fillOpacityObj = layerLib.setFillOpacity(layerRef, color.opacity);
                colorPromise = layerActionsUtil.playSimpleLayerActions(document, layers, [fillColorObj, fillOpacityObj],
                    true, options);
            } else {
                colorPromise = layerActionsUtil.playSimpleLayerActions(document, layers, fillColorObj, true, options);
            }
        }

        return Promise.join(dispatchPromise, colorPromise);
    };
示例#3
0
    var setStrokeColor = function (document, layers, color, options) {
        // if a color is provided, adjust the alpha to one that can be represented as a fraction of 255
        color = color ? color.normalizeAlpha() : null;
        options = _.merge({}, options); // make a copy of the options

        // if enabled is not provided, assume it is true
        // derive the type of event to be dispatched based on this parameter's existence
        var eventName,
            enabledChanging;
        if (options.enabled === undefined || options.enabled === null) {
            options.enabled = true;
            eventName = events.document.history.STROKE_COLOR_CHANGED;
        } else {
            eventName = events.document.history.STROKE_ENABLED_CHANGED;
            enabledChanging = true;
        }

        options = _mergeOptions(options, document, nls.localize("strings.ACTIONS.SET_STROKE_COLOR"));

        var colorPromise,
            psColor,
            strokeObj,
            layerRef = contentLayerLib.referenceBy.current;

        if (_allStrokesExist(layers)) {
            // optimistically dispatch the change event    
            var dispatchPromise = _strokeChangeDispatch.call(this,
                document,
                layers,
                { enabled: options.enabled, color: color, ignoreAlpha: options.ignoreAlpha },
                eventName,
                options.coalesce);

            if (!color && options.enabled) {
                // If color is not supplied, we use existing color from our model
                var actions = layers.map(function (layer) {
                    psColor = layer.stroke.color.toJS();

                    if (options.ignoreAlpha) {
                        delete psColor.a;
                    }

                    var layerRef = contentLayerLib.referenceBy.id(layer.id),
                        setStrokeObj = contentLayerLib.setStrokeFillTypeSolidColor(layerRef, psColor);

                    return {
                        layer: layer,
                        playObject: setStrokeObj
                    };
                }, this);

                colorPromise = layerActionsUtil.playLayerActions(document, actions, true, options);
            } else {
                // remove the alpha component based on ignoreAlpha param
                psColor = color ? color.toJS() : null;
                if (psColor && options.ignoreAlpha) {
                    delete psColor.a;
                }
                
                strokeObj = contentLayerLib.setStrokeFillTypeSolidColor(layerRef, options.enabled ? psColor : null);
                colorPromise = layerActionsUtil.playSimpleLayerActions(document, layers, strokeObj, true, options);
            }
            
            // after both, if enabled has potentially changed, transfer to resetBounds
            return Promise.join(dispatchPromise,
                colorPromise,
                function () {
                    if (enabledChanging) {
                        return this.transfer(layerActions.resetBounds, document, layers);
                    }
                }.bind(this));
        } else {
            // remove the alpha component based on ignoreAlpha param
            psColor = color ? color.toJS() : null;
            
            if (psColor && options.ignoreAlpha) {
                delete psColor.a;
            }

            strokeObj = contentLayerLib.setStrokeFillTypeSolidColor(layerRef, options.enabled ? psColor : null);
            
            return layerActionsUtil.playSimpleLayerActions(document, layers, strokeObj, true, options)
                .bind(this)
                .then(function () {
                    // upon completion, fetch the stroke info for all layers
                    _refreshStrokes.call(this, document, layers);
                });
        }
    };