示例#1
0
        public Task PublishPixelSelectedEvent(PixelSelectedEventArgs e)
        {
            if (this.PixelSelected != null)
            {
                this.PixelSelected.Invoke(this, e);
            }

            return(Task.FromResult(0));
        }
示例#2
0
        private async void PixelMatrix_PixelSelected(object sender, PixelSelectedEventArgs e)
        {
            // ***
            // *** Get the current mode.
            // ***
            DrawMode mode = await this.GetDrawMode(e.KeyModifiers);

            // ***
            // *** Cache the old color of this pixel.
            // ***
            ColorItem selectedItem = await this.ColorMatrix.GetItem(e.Row, e.Column);

            switch (mode)
            {
            case DrawMode.PickColor:
            {
                ColorItem colorItem = await this.ColorMatrix.GetItem(e.Row, e.Column);

                this.PixelColor         = colorItem;
                this.PickColorIsChecked = false;

                if (_sandWasChecked)
                {
                    this.SandIsChecked = true;
                }
                else
                {
                    this.DrawIsChecked = true;
                }
            }
            break;

            case DrawMode.Draw:
            {
                if (selectedItem != this.PixelColor || selectedItem.ItemType != ColorItem.ColorItemType.Pixel)
                {
                    // ***
                    // *** Update the pixel.
                    // ***
                    Color color = this.PixelColor;
                    await this.ColorMatrix.SetItem(e.Row, e.Column, color, ColorItem.ColorItemType.Pixel);

                    // ***
                    // *** Set up the undo task.
                    // ***
                    async Task undoAction()
                    {
                        await this.ColorMatrix.SetItem(e.Row, e.Column, selectedItem);
                    }

                    async Task redoAction()
                    {
                        await this.ColorMatrix.SetItem(e.Row, e.Column, color, ColorItem.ColorItemType.Pixel);
                    }

                    await this.UndoService.AddUndoTask(undoAction, redoAction, $"Set Pixel [{e.Column}, {e.Row}, {this.PixelColor.ToString()}]");
                }
            }
            break;

            case DrawMode.Erase:
            {
                if (selectedItem != this.BackgroundColor || selectedItem.ItemType != ColorItem.ColorItemType.Background)
                {
                    // ***
                    // *** Update the pixel.
                    // ***
                    await this.ColorMatrix.SetItem(e.Row, e.Column, this.BackgroundColor, ColorItem.ColorItemType.Background);

                    // ***
                    // *** Set up the undo task.
                    // ***
                    async Task undoAction()
                    {
                        await this.ColorMatrix.SetItem(e.Row, e.Column, selectedItem);
                    }

                    async Task redoAction()
                    {
                        await this.ColorMatrix.SetItem(e.Row, e.Column, this.BackgroundColor, ColorItem.ColorItemType.Background);
                    }

                    await this.UndoService.AddUndoTask(undoAction, redoAction, $"Clear Pixel [{e.Column}, {e.Row}]");
                }
            }
            break;

            case DrawMode.EraseColor:
            {
                if (selectedItem.ItemType != ColorItem.ColorItemType.Background)
                {
                    // ***
                    // *** Clone the current matrix for the undo.
                    // ***
                    IColorMatrix oldColorMatrix = await this.ColorMatrix.CloneAsync();

                    await this.ColorMatrix.ReplaceColorAsync(selectedItem, this.BackgroundColor, true);

                    // ***
                    // *** Set up the undo task.
                    // ***
                    async Task undoAction()
                    {
                        await this.ColorMatrix.CopyFrom(oldColorMatrix);
                    }

                    async Task redoAction()
                    {
                        await this.ColorMatrix.ReplaceColorAsync(selectedItem, this.BackgroundColor, true);
                    }

                    await this.UndoService.AddUndoTask(undoAction, redoAction, $"Clear Pixels [{e.Column}, {e.Row}]");
                }
            }
            break;

            case DrawMode.Sand:
            {
                if (selectedItem != this.PixelColor || selectedItem.ItemType != ColorItem.ColorItemType.Sand)
                {
                    // ***
                    // *** Update the pixel.
                    // ***
                    Color color = this.PixelColor;
                    color.A = 255;
                    await this.ColorMatrix.SetItem(e.Row, e.Column, color, ColorItem.ColorItemType.Sand);

                    // ***
                    // *** Set up the undo task.
                    // ***
                    async Task undoAction()
                    {
                        await this.ColorMatrix.SetItem(e.Row, e.Column, selectedItem);
                    }

                    async Task redoAction()
                    {
                        await this.ColorMatrix.SetItem(e.Row, e.Column, color, ColorItem.ColorItemType.Sand);
                    }

                    await this.UndoService.AddUndoTask(undoAction, redoAction, $"Set Sand Pixel [{e.Column}, {e.Row}, {this.PixelColor.ToString()}]");
                }
            }
            break;
            }
        }
示例#3
0
 private async void LedMatrix_PixelSelected(object sender, PixelSelectedEventArgs e)
 {
     await this.PixelEventService.PublishPixelSelectedEvent(e);
 }