示例#1
0
 public DrawPixelIntent(IntentType type, FizzikFrame frame, FizzikLayer layer, int px, int py, Color color)
 {
     this.type  = type;
     this.frame = frame;
     this.layer = layer;
     this.x     = px;
     this.y     = py;
     this.color = color;
 }
        public FizzikFrame(int w, int h, string name = "Frame <Unnamed>")
        {
            imgWidth  = w;
            imgHeight = h;
            this.name = name;

            layers = new List <FizzikLayer>();
            layers.Add(new FizzikLayer(imgWidth, imgHeight, FizzikLayer.getDefaultLayerName(layerNameCount++))); //Add default first layer

            updateTexture();                                                                                     //Texture is initialized in here
        }
        /*
         * Adds a brand new layer on top of the currently selected layer, will select the new layer after creation.
         */
        public FizzikLayer createNewLayer(Object undoObject = null)
        {
            string layerName = FizzikLayer.getDefaultLayerName(layerNameCount++);

            if (undoObject)
            {
                Undo.RecordObject(undoObject, "Create Layer (" + layerName + ")");
            }

            FizzikLayer layer = new FizzikLayer(imgWidth, imgHeight, layerName);

            layers.Insert(workingLayer + 1, layer);
            workingLayer = workingLayer + 1;

            return(layer);
        }
        /*
         * Gets the finalized texture that contains all visible layers and combines them using
         * their appropriate blend modes
         */
        public void updateTexture()
        {
            List <FizzikLayer> visibleLayers = layers.FindAll((layer) => { return(layer.visible && layer.opacity > 0f && !layer.clean); });

            //Wipe texture
            if (texture != null)
            {
                Object.DestroyImmediate(texture);
            }
            texture = null;

            if (visibleLayers.Count > 0)
            {
                Color[] pixels = null;

                foreach (FizzikLayer layer in visibleLayers)
                {
                    if (pixels == null)
                    {
                        pixels = FizzikLayer.blend(layer.pixels, layer.opacity, layer.pixels, layer.opacity, layer.blendMode);
                    }
                    else
                    {
                        pixels = FizzikLayer.blend(pixels, 1f, layer.pixels, layer.opacity, layer.blendMode);
                    }
                }

                texture = new Texture2D(imgWidth, imgHeight);
                texture.SetPixels(pixels);
                texture.filterMode = FilterMode.Point;
                texture.Apply();
            }
            else
            {
                texture = new Texture2D(imgWidth, imgHeight);
                texture.SetPixels(Enumerable.Repeat(Color.clear, imgWidth * imgHeight).ToArray());
                texture.filterMode = FilterMode.Point;
                texture.Apply();
            }
        }
        public override void handleGUI(int windowID)
        {
            base.handleGUI(windowID);

            Event e = Event.current;

            //Layer layouting variables
            FizzikSprite       sprite = editor.getWorkingSprite();
            FizzikFrame        frame  = sprite.getCurrentFrame();
            List <FizzikLayer> layers = frame.layers;

            float w  = currentRect.width;
            float h  = currentRect.height;
            float hw = w / 2;
            float hh = h / 2;

            //Styles
            GUIStyle scrollViewStyle = new GUIStyle(GUI.skin.scrollView);

            GUIStyle layersStyle = new GUIStyle();

            layersStyle.normal.background = layersBackgroundTex;

            GUIStyle layerStyle = new GUIStyle(GUI.skin.button);

            layerStyle.normal.background = layerBackgroundTex;

            GUIStyle layerSelectedStyle = new GUIStyle(layerStyle);

            layerSelectedStyle.normal.background = layerSelectedBackgroundTex;

            GUIStyle layerNameStyle = new GUIStyle();

            layerNameStyle.fixedWidth = LAYER_NAME_WIDTH;
            layerNameStyle.clipping   = TextClipping.Clip;

            GUIStyle layerOverallToolbarStyle = new GUIStyle();

            //Begin GUI
            GUILayout.BeginVertical();

            scrollPosition = GUILayout.BeginScrollView(scrollPosition, scrollViewStyle);

            //Begin Layers
            GUILayout.BeginVertical(layersStyle);

            layerRects.Clear();

            for (int i = layers.Count() - 1; i >= 0; i--)
            {
                FizzikLayer layer = layers[i];

                //Begin Layer
                if (frame.getCurrentLayer() == layer)
                {
                    GUILayout.BeginHorizontal(layerSelectedStyle, GUILayout.Height(LAYER_HEIGHT));
                }
                else
                {
                    GUILayout.BeginHorizontal(layerStyle, GUILayout.Height(LAYER_HEIGHT));
                }

                GUILayout.Box(layer.texture, new GUIStyle(GUI.skin.button), GUILayout.Width(LAYER_HEIGHT), GUILayout.Height(LAYER_HEIGHT));
                GUILayout.Label(layer.name, layerNameStyle);

                GUILayout.EndHorizontal();
                layerRects.Insert(0, GUILayoutUtility.GetLastRect()); //Insert to front so that the layerRects list is in correct layer order
                //End Layer
            }

            GUILayout.EndVertical();
            //End Layers

            //Draw layerRects DEBUG TODO
            foreach (Rect rect in layerRects)
            {
                GUIUtility.DrawRectangle(rect, Color.cyan, true, pixel);
            }

            GUILayout.EndScrollView();
            layersScrollRect = GUILayoutUtility.GetLastRect();

            //Begin Layer Overall Toolbar
            GUILayout.BeginHorizontal(layerOverallToolbarStyle, GUILayout.Height(20));

            GUILayout.FlexibleSpace();

            if (GUILayout.Button("+", GUILayout.Width(16), GUILayout.Height(16)))
            {
                if (isGUIButtonClick())
                {
                    frame.createNewLayer(sprite);
                }
            }
            if (GUILayout.Button("-", GUILayout.Width(16), GUILayout.Height(16)))
            {
                if (isGUIButtonClick())
                {
                    frame.deleteCurrentLayer(sprite);
                }
            }
            GUILayout.Button("a", GUILayout.Width(16), GUILayout.Height(16));
            GUILayout.Button("b", GUILayout.Width(16), GUILayout.Height(16));

            GUILayout.EndHorizontal();
            //End Layer Overall Toolbar

            GUILayout.EndVertical();
            layersOffsetRect = GUILayoutUtility.GetLastRect();
            //End GUI layoutting

            trackMouseClicksAndDrags();

            handleCursors();

            dragWindow();
        }