Exemplo n.º 1
0
 private void DrawGizmo(RagePixelState state)
 {
     Utility.DrawRectangle(
         Utility.PixelToWorld(default(Vector2Int), state.Transform, state.Sprite, false),
         Utility.PixelToWorld(_size, state.Transform, state.Sprite, false), Color.white
         );
 }
Exemplo n.º 2
0
 private void DrawGizmo(RagePixelState state)
 {
     Utility.DrawRectangle(
         Utility.PixelToWorld(default(IntVector2), state.transform, state.sprite, false),
         Utility.PixelToWorld(m_Size, state.transform, state.sprite, false), Color.white
         );
 }
Exemplo n.º 3
0
        public void OnMouseDrag(RagePixelState state)
        {
            if (Event.current.button != 0 || !ActiveDrag)
            {
                return;
            }

            Vector2Int pixel = state.ScreenToPixel(Event.current.mousePosition, false);

            var lastPixel = _lastMousePixel.Value;

            Utility.DrawPixelLine(state.Sprite.texture, state.Brush, lastPixel, pixel);

            if (state.SpriteRenderer.drawMode == SpriteDrawMode.Tiled)
            {
                var texSize = new Vector2Int(state.Sprite.texture.width, state.Sprite.texture.height);

                var diff    = pixel - lastPixel;
                var lastPos = new Vector2Int(lastPixel.x % texSize.x, lastPixel.y % texSize.y);
                var pos     = lastPos + diff;

                var shift1 = new Vector2Int(0, 0);
                var shift2 = new Vector2Int(texSize.x, 0);
                var shift3 = new Vector2Int(0, texSize.y);
                var shift4 = new Vector2Int(texSize.x, texSize.y);

                Utility.DrawPixelLine(state.Sprite.texture, state.Brush, lastPos + shift1, pos + shift1);
                Utility.DrawPixelLine(state.Sprite.texture, state.Brush, lastPos + shift2, pos + shift2);
                Utility.DrawPixelLine(state.Sprite.texture, state.Brush, lastPos + shift3, pos + shift3);
                Utility.DrawPixelLine(state.Sprite.texture, state.Brush, lastPos + shift4, pos + shift4);
            }
            _lastMousePixel = pixel;
        }
Exemplo n.º 4
0
        public void OnMouseDown(RagePixelState state)
        {
            if (Event.current.button != 0 || !Event.current.control || active)
            {
                return;
            }

            IntVector2 mouse = GetMousePixel(state, false);

            if (!Utility.PixelInBounds(mouse, state.sprite))
            {
                state.paintColor = new Color(0f, 0f, 0f, 0f);
                Event.current.Use();
                state.Repaint();
                return;
            }

            Color newColor = state.sprite.texture.GetPixel((int)mouse.x, (int)mouse.y);

            if (state.mode == RagePixelState.SceneMode.ReplaceColor)
            {
                state.replaceTargetColor = newColor;
            }
            else
            {
                state.paintColor = newColor;
            }

            Event.current.Use();
            m_MarqueeStart = mouse;
            m_MarqueeEnd   = mouse;
            state.Repaint();
        }
Exemplo n.º 5
0
        public void OnMouseUp(RagePixelState state)
        {
            Sprite sprite = state.Sprite;

            Color[] pixels         = Utility.GetPixels(sprite);
            int     originalWidth  = (int)sprite.textureRect.width;
            int     originalHeight = (int)sprite.textureRect.height;

            Texture2D texture = sprite.texture;

            int width  = _size.x;
            int height = _size.y;

            texture.Resize(width, height, texture.format, texture.mipmapCount > 0);
            texture.SetPixels32(Utility.GetDefaultPixels(texture.width, texture.height));

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    if (x < originalWidth && y < originalHeight)
                    {
                        texture.SetPixel(x, y, pixels [y * originalWidth + x]);
                    }
                }
            }

            texture.Apply();
            Utility.SaveImageData(sprite, true);
            ShiftTransformAfterResize(state.Transform, sprite, originalWidth, originalHeight, width, height);
            SceneView.RepaintAll();
        }
Exemplo n.º 6
0
 private void Initialize(RagePixelState state)
 {
     if (!m_Initialized)
     {
         m_Initialized = true;
         m_Size        = new IntVector2(state.sprite.textureRect.size);
     }
 }
Exemplo n.º 7
0
 private void Initialize(RagePixelState state)
 {
     if (!_initialized)
     {
         _initialized = true;
         _size        = Utility.FloorToInt(state.Sprite.textureRect.size);
     }
 }
Exemplo n.º 8
0
 public void OnMouseUp(RagePixelState state)
 {
     if (Event.current.button == 0)
     {
         Utility.SaveImageData(state.sprite, false);
         Event.current.Use();
     }
 }
Exemplo n.º 9
0
 public void OnRepaint(RagePixelState state)
 {
     if (_mDragging)
     {
         DrawMarquee();
         DrawSizeLabel();
     }
 }
Exemplo n.º 10
0
        private void DrawSizeLabel(RagePixelState state)
        {
            Vector2 handleScreenPos = state.PixelToScreen(_size, false);
            Vector2 labelScreenPos  = handleScreenPos + new Vector2(16f, -8f);

            Handles.BeginGUI();
            GUI.Label(new Rect(labelScreenPos.x, labelScreenPos.y, 100f, 100f), _size.x + " x " + _size.y);
            Handles.EndGUI();
        }
Exemplo n.º 11
0
 public void OnMouseDown(RagePixelState state)
 {
     if (Event.current.button == 0)
     {
         _mDragStart = Event.current.mousePosition;
         _mDragging  = true;
         Event.current.Use();
     }
 }
Exemplo n.º 12
0
        public void OnMouseDrag(RagePixelState state)
        {
            if (Event.current.button != 0 || !Event.current.control || !active)
            {
                return;
            }

            m_MarqueeEnd = GetMousePixel(state, true);
            Event.current.Use();
        }
Exemplo n.º 13
0
 public void OnMouseUp(RagePixelState state)
 {
     if (Event.current.button == 0)
     {
         CreateSprite();
         _mDragging = false;
         state.Mode = RagePixelState.SceneMode.Default;
         Event.current.Use();
     }
 }
Exemplo n.º 14
0
        public void OnMouseUp(RagePixelState state)
        {
            if (Event.current.button != 0)
            {
                return;
            }

            m_LastMousePixel = null;
            Utility.SaveImageData(state.sprite, false);
            Event.current.Use();
        }
Exemplo n.º 15
0
        public void OnMouseDrag(RagePixelState state)
        {
            if (Event.current.button != 0 || !activeDrag)
            {
                return;
            }

            IntVector2 pixel = state.ScreenToPixel(Event.current.mousePosition, false);

            Utility.DrawPixelLine(state.sprite.texture, state.brush, m_LastMousePixel.Value, pixel);
            m_LastMousePixel = pixel;
        }
Exemplo n.º 16
0
        public void OnEnable()
        {
            title = "RagePixel";

            if (m_State == null)
            {
                m_State = CreateInstance <RagePixelState> ();
            }

            m_State.Repaint += this.Repaint;
            minSize          = new Vector2(k_ButtonSize * 3f + 14f, k_ButtonSize * 4f + 22f);
            maxSize          = new Vector2(k_ButtonSize * 3f + 14f, k_ButtonSize * 4f + 22f);
        }
Exemplo n.º 17
0
        public void OnEnable()
        {
            titleContent = new GUIContent("RagePixel");

            if (_state == null)
            {
                _state = CreateInstance <RagePixelState> ();
            }

            _state.SetRepaint(this.Repaint);
            minSize = new Vector2(KButtonSize * 3f + 14f, KButtonSize * 4f + 22f);
            maxSize = new Vector2(KButtonSize * 3f + 14f, KButtonSize * 4f + 22f);
        }
Exemplo n.º 18
0
 public void OnMouseDown(RagePixelState state)
 {
     if (Event.current.button == 0)
     {
         IntVector2 pixel      = state.ScreenToPixel(Event.current.mousePosition, false);
         Color      oldColor   = state.sprite.texture.GetPixel((int)pixel.x, (int)pixel.y);
         Texture2D  texture    = state.sprite.texture;
         Rect       spriteRect = state.sprite.textureRect;
         FloodFill(oldColor, state.paintColor, texture, (int)pixel.x, (int)pixel.y, (int)spriteRect.xMin,
                   (int)spriteRect.yMin, (int)spriteRect.xMax, (int)spriteRect.yMax);
         texture.Apply();
         Event.current.Use();
     }
 }
Exemplo n.º 19
0
        public void OnMouseDown(RagePixelState state)
        {
            if (Event.current.button != 0)
            {
                return;
            }

            IntVector2 pixel    = state.ScreenToPixel(Event.current.mousePosition, false);
            IntVector2 minPixel = pixel - state.brush.m_BrushPivot;

            Utility.SetPixelsClamped(state.sprite.texture, minPixel, state.brush.m_Size, state.brush.m_Colors);
            state.sprite.texture.Apply();

            m_LastMousePixel = pixel;
            state.Repaint();
            Event.current.Use();
        }
Exemplo n.º 20
0
        public void OnRepaint(RagePixelState state)
        {
            if (!Active)
            {
                return;
            }

            state.DrawSpriteBounds();

            Rect r = Rect;

            Utility.DrawRectangle(
                Utility.PixelToWorld(new Vector2Int((int)r.xMin, (int)r.yMin), state.Transform, state.Sprite, false),
                Utility.PixelToWorld(new Vector2Int((int)r.xMax + 1, (int)r.yMax + 1), state.Transform, state.Sprite, false),
                Color.white
                );
        }
Exemplo n.º 21
0
        public void OnRepaint(RagePixelState state)
        {
            if (!active)
            {
                return;
            }

            state.DrawSpriteBounds();

            Rect r = rect;

            Utility.DrawRectangle(
                Utility.PixelToWorld(new IntVector2(r.xMin, r.yMin), state.transform, state.sprite, false),
                Utility.PixelToWorld(new IntVector2(r.xMax + 1, r.yMax + 1), state.transform, state.sprite, false),
                Color.white
                );
        }
Exemplo n.º 22
0
        public void OnSceneGui(RagePixelState state)
        {
            Initialize(state);

            Vector2 uvPos    = Utility.PixelToUv(_size, state.Sprite, false);
            Vector3 localPos = Utility.UvToLocal(uvPos, state.Sprite, false);
            Vector3 worldPos = Utility.LocalToWorld(localPos, state.Transform);

            EditorGUI.BeginChangeCheck();
            worldPos = Handles.FreeMoveHandle(worldPos, Quaternion.identity, HandleUtility.GetHandleSize(worldPos) * 0.1f, Vector3.zero, Handles.RectangleHandleCap);
            if (EditorGUI.EndChangeCheck())
            {
                localPos = Utility.WorldToLocal(worldPos, state.Transform);
                uvPos    = Utility.LocalToUv(localPos, state.Sprite, false);
                _size    = Utility.UvToPixel(uvPos, state.Sprite, false);
                _size    = new Vector2Int((int)Mathf.Clamp(_size.x, MinSize, MaxSize), (int)Mathf.Clamp(_size.y, MinSize, MaxSize));
                state.Repaint();
            }
        }
Exemplo n.º 23
0
        public void OnMouseUp(RagePixelState state)
        {
            if (Event.current.button != 0 || !Event.current.control || !active)
            {
                return;
            }

            Rect r = rect;

            r.height   += 1;
            r.width    += 1;
            state.brush = new Brush(state.sprite.texture, r);

            IntVector2 pivot = m_MarqueeEnd.Value - m_MarqueeStart.Value;

            state.brush.m_BrushPivot = new IntVector2(Math.Max(0, pivot.x), Math.Max(0, pivot.y));

            m_MarqueeStart = null;
            m_MarqueeEnd   = null;
            Event.current.Use();
            state.Repaint();
        }
Exemplo n.º 24
0
        public void OnMouseUp(RagePixelState state)
        {
            if (Event.current.button != 0 || !Event.current.control || !Active)
            {
                return;
            }

            Rect r = Rect;

            r.height   += 1;
            r.width    += 1;
            state.Brush = new Brush(state.Sprite.texture, r);

            Vector2Int pivot = _mMarqueeEnd.Value - _mMarqueeStart.Value;

            state.Brush.BrushPivot = new Vector2Int(Math.Max(0, pivot.x), Math.Max(0, pivot.y));

            _mMarqueeStart = null;
            _mMarqueeEnd   = null;
            Event.current.Use();
            state.Repaint();
        }
Exemplo n.º 25
0
 public void OnSceneGui(RagePixelState state)
 {
     return;
 }
Exemplo n.º 26
0
 public void OnRepaint(RagePixelState state)
 {
     DrawGizmo(state);
     DrawSizeLabel(state);
 }
Exemplo n.º 27
0
 public void OnMouseMove(RagePixelState state)
 {
 }
Exemplo n.º 28
0
 public void OnMouseDrag(RagePixelState state)
 {
 }
Exemplo n.º 29
0
 public void OnMouseDown(RagePixelState state)
 {
 }
Exemplo n.º 30
0
 public void OnRepaint(RagePixelState state)
 {
     state.DrawBasicPaintGizmo();
     state.DrawSpriteBounds();
 }