Пример #1
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 ();
        }
Пример #2
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 = (int)m_Size.x;
            int height = (int)m_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 ();
        }
Пример #3
0
        public void OnMouseDrag(RagePixelState state)
        {
            if (Event.current.button != 0 || !Event.current.control || !active)
                return;

            m_MarqueeEnd = GetMousePixel (state, true);
            Event.current.Use();
        }
Пример #4
0
 public void OnMouseUp(RagePixelState state)
 {
     if (Event.current.button == 0)
     {
         Utility.SaveImageData (state.sprite, false);
         Event.current.Use ();
     }
 }
Пример #5
0
        public void OnMouseUp(RagePixelState state)
        {
            if (Event.current.button != 0)
                return;

            m_LastMousePixel = null;
            Utility.SaveImageData (state.sprite, false);
            Event.current.Use ();
        }
Пример #6
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;
        }
Пример #7
0
 public void OnMouseDown(RagePixelState state)
 {
     if (Event.current.button == 0)
     {
         m_DragStart = Event.current.mousePosition;
         m_Dragging = true;
         Event.current.Use ();
     }
 }
Пример #8
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);
        }
Пример #9
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 ();
     }
 }
Пример #10
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 ();
        }
Пример #11
0
        public void OnSceneGUI(RagePixelState state)
        {
            Initialize (state);

            Vector2 uvPos = Utility.PixelToUV (m_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.RectangleCap);
            if (EditorGUI.EndChangeCheck ())
            {
                localPos = Utility.WorldToLocal (worldPos, state.transform);
                uvPos = Utility.LocalToUV (localPos, state.sprite, false);
                m_Size = Utility.UVToPixel (uvPos, state.sprite, false);
                m_Size = new IntVector2((int)Mathf.Clamp(m_Size.x, k_MinSize, k_MaxSize), (int)Mathf.Clamp(m_Size.y, k_MinSize, k_MaxSize));
                state.Repaint ();
            }
        }
Пример #12
0
 public void OnMouseUp(RagePixelState state)
 {
     if (Event.current.button == 0)
     {
         CreateSprite ();
         m_Dragging = false;
         state.mode = RagePixelState.SceneMode.Default;
         Event.current.Use ();
     }
 }
Пример #13
0
 public void OnMouseMove(RagePixelState state)
 {
     SceneView.RepaintAll ();
 }
Пример #14
0
 public void OnMouseDrag(RagePixelState state)
 {
     return;
 }
Пример #15
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 ();
        }
Пример #16
0
 public void OnMouseDown(RagePixelState state)
 {
 }
Пример #17
0
 private void BasicModeButton(RagePixelState.SceneMode buttonMode, Texture2D icon)
 {
     EditorGUI.BeginChangeCheck ();
     GUILayout.Toggle (m_State.mode == buttonMode, icon, GUI.skin.button, GUILayout.Width (k_ButtonSize), GUILayout.Height (k_ButtonSize));
     if (EditorGUI.EndChangeCheck () && m_State.mode != buttonMode)
         m_State.mode = buttonMode;
 }
Пример #18
0
 private IntVector2 GetMousePixel(RagePixelState state, bool clamp)
 {
     return state.ScreenToPixel (Event.current.mousePosition, clamp);
 }
Пример #19
0
 public void OnMouseDrag(RagePixelState state)
 {
     Event.current.Use();
 }
Пример #20
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
         );
 }
Пример #21
0
 public void OnRepaint(RagePixelState state)
 {
     DrawGizmo (state);
     DrawSizeLabel (state);
 }
Пример #22
0
        private void DrawSizeLabel(RagePixelState state)
        {
            Vector2 handleScreenPos = state.PixelToScreen (m_Size, false);
            Vector2 labelScreenPos = handleScreenPos + new Vector2 (16f, -8f);

            Handles.BeginGUI ();
            GUI.Label (new Rect (labelScreenPos.x, labelScreenPos.y, 100f, 100f), (int)m_Size.x + " x " + (int)m_Size.y);
            Handles.EndGUI ();
        }
Пример #23
0
 public void OnRepaint(RagePixelState state)
 {
     state.DrawBasicPaintGizmo ();
     state.DrawSpriteBounds ();
 }
Пример #24
0
 public void OnRepaint(RagePixelState state)
 {
     if (m_Dragging)
     {
         DrawMarquee ();
         DrawSizeLabel ();
     }
 }
Пример #25
0
 public void OnSceneGUI(RagePixelState state)
 {
     return;
 }
Пример #26
0
 public void OnMouseMove(RagePixelState state)
 {
 }
Пример #27
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
            );
        }
Пример #28
0
 private void Initialize(RagePixelState state)
 {
     if (!m_Initialized)
     {
         m_Initialized = true;
         m_Size = new IntVector2(state.sprite.textureRect.size);
     }
 }