Exemplo n.º 1
0
        /*******************************************************
         * Save File Menu
         *
         * Arguments: Object Sender and EventArgs e
         * Return Type: void
         * Use Case:
         ******************************************************/
        private void saveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (savePath != null)
            {
                Bitmap imageMap = new Bitmap(PaintCanvas.Width, PaintCanvas.Height);
                PaintCanvas.DrawToBitmap(imageMap, PaintCanvas.Bounds);

                PictureBox saveBox = new PictureBox();
                saveBox.Image = imageMap;

                //code to save the file;
                saveBox.Image.Save(savePath, ImageFormat.Png);
            }
            else
            {
                SaveFileDialog saveDialog1 = new SaveFileDialog();
                saveDialog1.Filter = "png (*.png)|*.png";

                DialogResult result = saveDialog1.ShowDialog();
                if (result == DialogResult.OK)
                {
                    string fileName = saveDialog1.FileName;
                    savePath = fileName;

                    Bitmap imageMap = new Bitmap(PaintCanvas.Width, PaintCanvas.Height);
                    PaintCanvas.DrawToBitmap(imageMap, PaintCanvas.Bounds);

                    PictureBox saveBox = new PictureBox();
                    saveBox.Image = imageMap;

                    //code to save the file;
                    saveBox.Image.Save(fileName, ImageFormat.Png);
                }
            }
        }
Exemplo n.º 2
0
    void Start()
    {
        if (instance != null)
        {
            Debug.LogError("Multiple PaintCanvas not implemented yet.");
        }
        instance = this;
        rectT    = GetComponent <RectTransform>();
        var rawimg = GetComponent <RawImage>();

        //rt = rawimg.mainTexture as RenderTexture;
        tex            = new Texture2D(width, height, TextureFormat.RGBA32, false);
        tex.filterMode = FilterMode.Point;
        rawimg.texture = tex;

        EventTrigger trigger = GetComponent <EventTrigger>();

        EventTrigger.Entry entry = new EventTrigger.Entry();
        entry.eventID = EventTriggerType.Drag;
        entry.callback.AddListener((data) => { OnDraw((PointerEventData)data); });
        trigger.triggers.Add(entry);

        entry         = new EventTrigger.Entry();
        entry.eventID = EventTriggerType.PointerDown;
        entry.callback.AddListener((data) => { OnDraw((PointerEventData)data); });
        trigger.triggers.Add(entry);
    }
Exemplo n.º 3
0
    private void Start()
    {
        var data       = PaintCanvas.GetAllTextureData();
        var zippeddata = data.Compress();

        RpcSendFullTexture(zippeddata);
    }
Exemplo n.º 4
0
 /*******************************************************
  * New File Menu
  *
  * Arguments: Object Sender and EventArgs e
  * Return Type: void
  * Use Case:
  ******************************************************/
 private void newToolStripMenuItem_Click(object sender, EventArgs e)
 {
     lines.Clear();
     strokes.Clear();
     PaintCanvas.Image = null;
     PaintCanvas.Refresh();
 }
Exemplo n.º 5
0
        /*******************************************************
         * Undo button Click
         *
         * Arguments: Object Sender and EventArgs e
         * Return Type: void
         * Use Case:
         ******************************************************/
        private void UndoButton_Click(object sender, EventArgs e)
        {
            textBox1.Text = "Undo";
            if (UndoStack.Count > 0)
            {
                string      action = UndoStack.Pop();
                PaintAction newAction;

                switch (action)
                {
                case "Line":
                    newAction = lines[lines.Count - 1];
                    RedoStack.Push(newAction);

                    lines.RemoveAt(lines.Count - 1);
                    lines.TrimExcess();
                    break;

                case "Stroke":
                    newAction = strokes[strokes.Count - 1];
                    RedoStack.Push(newAction);

                    strokes.RemoveAt(strokes.Count - 1);
                    strokes.TrimExcess();
                    break;

                default:
                    Console.WriteLine("Undo Button Error!");
                    break;
                }
            }

            PaintCanvas.Refresh();
        }
Exemplo n.º 6
0
        /*******************************************************
         * Mouse Up Click
         *
         * Arguments: Object Sender and EventArgs e
         * Return Type: void
         * Use Case:
         ******************************************************/
        private void PaintCanvas_MouseUp(object sender, MouseEventArgs e)
        {
            if (isLineSelected && !point1.IsEmpty && !point2.IsEmpty)
            {
                Line newLine = new Line(selectedPen, point1, point2);
                lines.Add(newLine);
                UndoStack.Push("Line");

                PaintCanvas.Refresh();

                point1 = Point.Empty;
                point2 = Point.Empty;
            }

            if (isPencilSelected || isEraserSelected || isPaintSelected || isCustom)
            {
                strokes.Add(currentStroke);
                UndoStack.Push("Stroke");

                PaintCanvas.Refresh();

                currentStroke = new Stroke(selectedPen, new List <Point>());
            }

            Cursor = Cursors.Default;
        }
Exemplo n.º 7
0
 public GeneralRenderer(PaintCanvas PaintEvent)
 {
     Paint            += PaintEvent;
     HorizontalOptions = LayoutOptions.Fill;
     VerticalOptions   = LayoutOptions.Fill;
     BackgroundColor   = Globals.BackgroundColor;
 }
 private void Clear(object sender, EventArgs e)
 {
     pathsLL.Clear();
     colorsLL.Clear();
     changesLL.Clear();
     libraryBitmap = null;
     PaintCanvas.InvalidateSurface();
 }
Exemplo n.º 9
0
        /*******************************************************
         * Mouse Move Event
         *
         * Arguments: Object Sender and EventArgs e
         * Return Type: void
         * Use Case:
         ******************************************************/
        private void PaintCanvas_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left && (isPencilSelected || isEraserSelected || isPaintSelected))

            {
                currentStroke.Points.Add(new Point(e.Location.X - 10, e.Location.Y + 10));

                PaintCanvas.Refresh();
            }
        }
Exemplo n.º 10
0
    private void Start()
    {
        //Fetch the GameObject's Renderer component
        objRender = GetComponent <Renderer>();
        //Change the GameObject's Material Color to red
        objRender.material.color = Color.red;

        var data       = PaintCanvas.GetAllTextureData();
        var zippeddata = data.Compress();

        RpcSendFullTexture(zippeddata);
    }
Exemplo n.º 11
0
 void Start()
 {
     Texture2D texture = Resources.Load<Texture2D> ("Images/Painter/clearButton");
     gameObject.AddComponent<SpriteRenderer> ();
     GetComponent<SpriteRenderer>().sprite = SpriteManager.GetSprite(texture);
     transform.localScale = new Vector3 (rate*(8/10.0f),rate*(8/10.0f),1f);
     float sizeX = GetComponent<SpriteRenderer>().sprite.bounds.extents.x;
     transform.localPosition = new Vector3 (sizeX - sizeX*rate*3.4f, sizeX*rate, -0.5f);
     gameObject.AddComponent <BoxCollider2D>();
     ButtonAnimation.SetAnimation (transform, "", "button_click02");
     paintCanvasScript = GameObject.Find ("PaintCanvas").GetComponent<PaintCanvas> ();
 }
 private void Undo(object sender, EventArgs e)
 {
     try {
         var node = pathsLL.Last;
         pathsLL.Remove(pathsLL.Last);
         changesLL.AddLast(node);
         PaintCanvas.InvalidateSurface();
     } catch (System.ArgumentException ex)
     {
         // The user expects anything to happens as they have nothing to undo
     }
 }
Exemplo n.º 13
0
    public void Start()
    {
#if UNITY_WEBGL && !UNITY_EDITOR
        _ = ServerServiceHelper.CreateClient <WebglGameClient>();
#else
        _ = ServerServiceHelper.CreateClient <TcpGameClient>();
#endif

        lazyScriptHandler = FindObjectOfType <LazyScriptHandler>();
        paintBoard        = FindObjectOfType <PaintCanvas>();
        ServerServiceHelper.RegisterChatCallBacks(RecieveChatMessage, UserJoinedMessage);
        ServerServiceHelper.RegisterGameCallBacks(RecievePixelUpdate);
    }
        private async void LoadImage(object sender, EventArgs e)
        {
            IPhotoLibrary photoLibrary = DependencyService.Get <IPhotoLibrary>();

            using (Stream stream = await photoLibrary.PickPhotoAsync())
            {
                if (stream != null)
                {
                    libraryBitmap = SKBitmap.Decode(stream);
                    PaintCanvas.InvalidateSurface();
                }
            }
        }
Exemplo n.º 15
0
        /*******************************************************
         * Redo button Click
         *
         * Arguments: Object Sender and EventArgs e
         * Return Type: void
         * Use Case:
         ******************************************************/
        private void RedoButton_Click(object sender, EventArgs e)
        {
            textBox1.Text = "Redo";

            if (RedoStack.Count > 0)
            {
                var action = RedoStack.Pop();

                if (action is Line)
                {
                    lines.Add((Line)action);
                    UndoStack.Push("Line");
                    PaintCanvas.Refresh();
                }

                if (action is Stroke)
                {
                    strokes.Add((Stroke)action);
                    UndoStack.Push("Stroke");
                    PaintCanvas.Refresh();
                }
            }
        }
Exemplo n.º 16
0
        public HostViewModel(PaintCanvas host, List <ShapeToolParam> shapeParams, JsonSceneStore sceneStore, params ShapeTool[] tools)
        {
            shapeStateInfo = tools.ToDictionary(k => k.Id, v => v.Serialize(v.Example).ToDictionary(k => k.Key, v => v.Value.GetType()));

            ShapeTools      = new ObservableCollection <ShapeTool>(tools);
            ShapeToolParams = new ObservableCollection <ShapeToolParam>(shapeParams);

            ShapeParams = new List <IShapeParam>(ShapeToolParams.Select(p => p.Param));

            emptyShape = new EmptyShapeObject();

            DeleteCommand = new RelayCommand(DeleteSelectedShape, () => (selectedShape ?? emptyShape) != emptyShape && (selectedShape ?? emptyShape) != SelectedShapeTool?.Example);
            SaveCommand   = new RelayCommand(SaveScene);
            LoadCommand   = new RelayCommand(LoadScene);

            Host            = host;
            this.sceneStore = sceneStore;
            Host.MouseUp   += Host_MouseUp;
            Host.MouseMove += Host_MouseMove;
            Host.MouseDown += Host_MouseDown;

            scene = this;

            hostMouseStrategy = new HostMouseStrategy(
                scene,
                new EllipseGeometry {
                RadiusX = 3, RadiusY = 3
            },
                new ShapeMouseStrategy(scene));

            createMouseStrategy = new CreateShapeMoseStrategy(scene);

            SelectedShape = emptyShape;

            SetMode(ToolMode.Host);
        }
Exemplo n.º 17
0
 private void PaintCanvas_Loaded(object sender, RoutedEventArgs e)
 {
     PaintCanvas.SetBook(new StoryBook());
 }
Exemplo n.º 18
0
 private void RpcSendFullTexture(byte[] textureData)
 {
     PaintCanvas.SetAllTextureData(textureData.Decompress());
 }