Esempio n. 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();
        }
Esempio n. 2
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();
        }
Esempio n. 3
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();
            }
        }
Esempio n. 4
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();
        }
Esempio n. 5
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();
        }