コード例 #1
0
    //fill

    public void DebugPoint(BaseEventData data)
    {
        coloringScreenReleased();

        if (Time.time < nextWait && !isFinish)           //fill delay condition

        {
            PointerEventData ped = ( PointerEventData )data;
            Vector2          localCursor;
            if (!RectTransformUtility.ScreenPointToLocalPointInRectangle(GetComponent <RectTransform>(), ped.position, ped.pressEventCamera, out localCursor))
            {
                return;
            }

            //print("LocalCursor:" + localCursor);

            /*
             * rumus convert cursor ke dimensi Texture
             * xTexture = xCursor/widthRecTransform*widthTexture
             *
             * Convert local cursor to 0,0 pivot standart
             * xcursor = localCursor.x + defaultlimitX
             */
            intVector2 cursorPosition;
            cursorPosition.x = (int)((localCursor.x + defaultlimitX) / this.GetComponent <RectTransform> ().sizeDelta.x *currentTexture.width);
            cursorPosition.y = (int)((localCursor.y + defaultlimitY) / this.GetComponent <RectTransform> ().sizeDelta.y *currentTexture.height);

            //Stopwatch stopwatch = Stopwatch.StartNew ();

            //check if there any change before storing to undo stack
            nodeColor = currentTexture.GetPixel(cursorPosition.x, cursorPosition.y);
            if (!colorEqual(nodeColor, Color.black) &&
                !colorEqual(nodeColor, selectedColor) &&
                cursorPosition.x >= 0 && cursorPosition.y >= 0 &&
                cursorPosition.x < currentTexture.width && cursorPosition.y < currentTexture.height)
            {
                //store to undo stack
                oldState currentState = new oldState();
                currentState.cursor = cursorPosition;
                currentState.color  = nodeColor;
                undoStack.Push(currentState);

                //apply color filling
                floodFill(cursorPosition, selectedColor, currentTexture);
                currentTexture.Apply();

                redoStack.Clear();
            }

            //stopwatch.Stop ();

            //print ("Elapse time: "+stopwatch.ElapsedMilliseconds);
        }
    }
コード例 #2
0
    public void clickRedo()
    {
        if (redoStack.Count > 0)
        {
            lastUndo = redoStack.Pop();

            //store old state to undo stack
            nodeColor = currentTexture.GetPixel(lastUndo.cursor.x, lastUndo.cursor.y);
            oldState currentState;
            currentState.cursor = lastUndo.cursor;
            currentState.color  = nodeColor;
            undoStack.Push(currentState);

            //apply color filling
            floodFill(lastUndo.cursor, lastUndo.color, currentTexture);
            currentTexture.Apply();
        }
    }