public void TestThatBitmapOperationsUtilityExecutesPenToolProperly()
        {
            BitmapManager manager = new BitmapManager
            {
                ActiveDocument = new Document(10, 10),
                PrimaryColor   = Colors.Black
            };

            manager.ActiveDocument.AddNewLayer("Test layer", 10, 10);

            BitmapOperationsUtility util = new BitmapOperationsUtility(manager);

            List <Coordinates> mouseMove = new List <Coordinates>(new[] { new Coordinates(0, 0) });

            util.ExecuteTool(new Coordinates(0, 0), mouseMove, new MockedSinglePixelPenTool());
            Assert.Equal(manager.ActiveLayer.GetPixel(0, 0), Colors.Black);
        }
        public BuildingUI(MapEditorController controller, Building building)
        {
            InitializeComponent();

            this.controller = controller;
            this.building   = building;

            // Initialize Image
            if (building != null)
            {
                // TODO: Register for move events.

                // Get Image
                BitmapManager manager = BitmapManager.Instance;
                this.Image = manager.getBitmap(building.Type);
            }
        }
Пример #3
0
 public PenTool(BitmapManager bitmapManager)
 {
     Cursor              = Cursors.Pen;
     ActionDisplay       = "Click and move to draw.";
     Toolbar             = new PenToolbar();
     toolSizeSetting     = Toolbar.GetSetting <SizeSetting>("ToolSize");
     pixelPerfectSetting = Toolbar.GetSetting <BoolSetting>("PixelPerfectEnabled");
     ClearPreviewLayerOnEachIteration = false;
     BitmapManager   = bitmapManager;
     paint.BlendMode = SKBlendMode.Src;
     Brushes.Add(new CircleBrush());
     Brush    = Brushes[0];
     lineTool = new LineTool
     {
         AutomaticallyResizeCanvas = AutomaticallyResizeCanvas
     };
 }
        public UnitUI(MapEditorController controller, UnitComponent unit)
        {
            InitializeComponent();

            this.controller = controller;
            this.unit       = unit;

            // Initialize Image
            if (unit != null)
            {
                // TODO: Register for move events.

                // Get Image
                BitmapManager manager = BitmapManager.Instance;
                this.Image = manager.getBitmap(unit.Type);
            }
        }
Пример #5
0
        public void TestThatCenterContentCentersContentForSingleLayer(int docWidth, int docHeight)
        {
            Document      doc     = new Document(docWidth, docHeight);
            BitmapManager manager = new BitmapManager
            {
                ActiveDocument = doc
            };

            manager.ActiveDocument.AddNewLayer("test");

            manager.ActiveLayer.SetPixel(new Coordinates(0, 0), Colors.Green);

            doc.CenterContent();

            Assert.Equal(Math.Floor(docWidth / 2f), manager.ActiveLayer.OffsetX);
            Assert.Equal(Math.Floor(docHeight / 2f), manager.ActiveLayer.OffsetY);
        }
Пример #6
0
        public void TestThatClipCanvasWorksForSingleLayer(int initialWidth, int initialHeight, int additionalPixelX, int additionalPixelY)
        {
            Document      document = new Document(initialWidth, initialHeight);
            BitmapManager manager  = new BitmapManager
            {
                ActiveDocument = document
            };

            manager.AddNewLayer("test");
            manager.ActiveLayer.SetPixel(new Coordinates((int)Math.Ceiling(initialWidth / 2f),
                                                         (int)Math.Ceiling(initialHeight / 2f)), Colors.Black);

            manager.ActiveLayer.SetPixel(new Coordinates(additionalPixelX, additionalPixelY), Colors.Black);

            document.ClipCanvas();

            Assert.Equal(manager.ActiveLayer.Width, document.Width);
            Assert.Equal(manager.ActiveLayer.Height, document.Height);
        }
Пример #7
0
        public void TestThatBitmapChangesExecuteToolExecutesPenTool()
        {
            BitmapManager bitmapManager = new BitmapManager
            {
                ActiveDocument = new Document(5, 5)
            };

            bitmapManager.AddNewLayer("Layer");
            bitmapManager.SetActiveTool(new MockedSinglePixelPen());
            bitmapManager.PrimaryColor = Colors.Green;

            bitmapManager.MouseController.StartRecordingMouseMovementChanges(true);
            bitmapManager.MouseController.RecordMouseMovementChange(new Coordinates(1, 1));
            bitmapManager.MouseController.StopRecordingMouseMovementChanges();

            bitmapManager.ExecuteTool(new Coordinates(1, 1), true);

            Assert.Equal(Colors.Green, bitmapManager.ActiveLayer.GetPixelWithOffset(1, 1));
        }
Пример #8
0
        public static byte[] CreateScreenPacket(Bitmap screen)
        {
            List <byte> packet = new List <byte>();

            packet.Add((byte)PacketType.Screen);

            byte[]      jpegEncoded = BitmapManager.EncodeToJPEG(screen, 0.5, 0.5, 0.25);
            List <byte> jpegSize    = new List <byte>(BitConverter.GetBytes(jpegEncoded.Length));

            if (BitConverter.IsLittleEndian)
            {
                jpegSize.Reverse();
            }

            packet.AddRange(jpegSize);
            packet.AddRange(jpegEncoded);

            return(packet.ToArray());
        }
        public BuildingPalette()
        {
            InitializeComponent();
            BuildingFactory uf = BuildingFactory.Instance;

            this.flowLayoutPanel1.SuspendLayout();
            foreach (string type in uf.getBuildingTypes())
            {
                PictureBox buildingBox = new PictureBox();
                buildingBox.Name = type;
                buildingBox.Size = new Size(50, 50);
                BitmapManager manager = BitmapManager.Instance;
                buildingBox.Image    = manager.getBitmap(type);
                buildingBox.SizeMode = PictureBoxSizeMode.StretchImage;
                buildingBox.Margin   = new Padding(1, 1, 1, 1);
                buildingBox.Click   += uiBuildingIcon_Click;
                this.flowLayoutPanel1.Controls.Add(buildingBox);
            }
            this.flowLayoutPanel1.ResumeLayout();
        }
Пример #10
0
        public void InitializeForm()
        {
            mBitmapManager = new BitmapManager(new Bitmap((Bitmap)PicMain.Image, new Size(PicMain.Width, PicMain.Height)));
            mAppState      = new ApplicationState();
            mAppState.Area = new CircleArea(new Point(-100, -100), 100);
            HistogramR.InitializeHistogram(Color.Red);
            HistogramG.InitializeHistogram(Color.Green);
            HistogramB.InitializeHistogram(Color.Blue);

            FilterPreviewR.InitializePreviewChart();
            FilterPreviewG.InitializePreviewChart();
            FilterPreviewB.InitializePreviewChart();
            CustomFunctionFilter f = mBitmapManager.GetProperFilter(Filter.CustomFunction) as CustomFunctionFilter;

            FilterPreviewR.UpdateData(f.RawRedValues);
            FilterPreviewG.UpdateData(f.RawGreenValues);
            FilterPreviewB.UpdateData(f.RawBlueValues);


            ApplyFilterUI();
            ApplyModeUI();
        }
Пример #11
0
        private void Run()
        {
            while (isRunning)
            {
                if (previousScreen != null)
                {
                    previousScreen.Dispose();
                }

                if (currentScreen != null)
                {
                    previousScreen = BitmapManager.CloneBitmap(currentScreen);
                    currentScreen.Dispose();
                }

                currentScreen = ScreenManager.Screenshot();
                bool sendScreen = false;

                if (previousScreen != null)
                {
                    if (BitmapManager.BitmapChanged(previousScreen, currentScreen, 1000000, 70))
                    {
                        sendScreen = true;
                    }
                }
                else
                {
                    sendScreen = true;
                }

                if (sendScreen)
                {
                    subject.Notify(BitmapManager.CloneBitmap(currentScreen));
                }

                Thread.Sleep(100);
            }
        }
Пример #12
0
        public MainViewModel()
        {
            BitmapSource     = BitmapManager.SaveToBmp(10, 10, new byte[400]);
            RenderCommand    = new RenderCommand(this);
            SafeImageCommand = new SafeImageCommand(this);
            TextBoxInput     =
                //Test Input String (Cube of 3x3 Spheres)
                @"1440, 1440
S([400;-600;600], 300, [255;0;0])
S([400;0;600], 300, [255;0;0])
S([400;600;600], 300, [255;0;0])
S([400;-600;0], 300, [255;0;0])
S([400;0;0], 300, [255;0;0])
S([400;600;0], 300, [255;0;0])
S([400;-600;-600], 300, [255;0;0])
S([400;0;-600], 300, [255;0;0])
S([400;600;-600], 300, [255;0;0])
S([800;-600;600], 300, [255;0;0])
S([800;0;600], 300, [255;0;0])
S([800;600;600], 300, [255;0;0])
S([800;-600;0], 300, [255;0;0])
S([800;0;0], 300, [255;0;0])
S([800;600;0], 300, [255;0;0])
S([800;-600;-600], 300, [255;0;0])
S([800;0;-600], 300, [255;0;0])
S([800;600;-600], 300, [255;0;0])
S([1200;-600;600], 300, [255;0;0])
S([1200;0;600], 300, [255;0;0])
S([1200;600;600], 300, [255;0;0])
S([1200;-600;0], 300, [255;0;0])
S([1200;0;0], 300, [255;0;0])
S([1200;600;0], 300, [255;0;0])
S([1200;-600;-600], 300, [255;0;0])
S([1200;0;-600], 300, [255;0;0])
S([1200;600;-600], 300, [255;0;0])";
        }
Пример #13
0
 public XResource()
 {
     TextFormats = new TextFormatManager(DWriteFactory);
     Bitmaps     = new BitmapManager(WICFactory);
     TextLayouts = new TextLayoutManager(DWriteFactory, TextFormats);
 }
Пример #14
0
 private void BitmapChangedHandler(BitmapManager bitmapManager)
 {
     ImageSource = TypesConverters.BitmapToImageSource(bitmapManager.MainBitmap.Bitmap);
 }
Пример #15
0
 public FloodFillTool(BitmapManager bitmapManager)
 {
     ActionDisplay          = "Press on an area to fill it.";
     BitmapManager          = bitmapManager;
     UseDocumentRectForUndo = true;
 }
Пример #16
0
        public void TestThatIsOperationToolWorks()
        {
            MockedSinglePixelPen singlePixelPen = new MockedSinglePixelPen();

            Assert.True(BitmapManager.IsOperationTool(singlePixelPen));
        }
Пример #17
0
 public Bitmap GetCurrentScreen()
 {
     return(BitmapManager.CloneBitmap(currentScreen));
 }
 public void Execute(object parameter)
 {
     BitmapManager.SaveToPng(_mainViewModel.BitmapSource);
 }
Пример #19
0
 public DocumentProvider(BitmapManager bitmapManager)
 {
     _bitmapManager = bitmapManager;
 }
        internal void setPreviewImage(string type)
        {
            BitmapManager manager = BitmapManager.Instance;

            previewBox.Image = manager.getBitmap(type);
        }
Пример #21
0
        /// <summary>
        /// Constructs a View model from a rectangles (images) that were loaded
        /// </summary>
        /// <param name="rects">The loaded rects</param>
        public LoadedImagesTreeViewModel(IEnumerable <PPRect> rects)
        {
            eventAggregator = ServiceLocator.Current.GetInstance <IEventAggregator>();

            var folderImage = BitmapManager.LoadBitmap("folder.png");

            folderImageVM = folderImage != null ? new ImageViewModel(folderImage) : null;

            //Paths = images.Select(x => x.ImagePath);
            FSEntries = CreateFSEntries(rects);

            Unload = new RelayCommand((x) =>
            {
                //Task.Factory.StartNew(() =>
                //{
                var node = x as NodeVM;
                IEnumerable <string> paths = Enumerable.Empty <string>();


                var nodesToUnload = new Stack <NodeVM>();
                nodesToUnload.Push(node);

                while (nodesToUnload.Count > 0)
                {
                    var currNode = nodesToUnload.Pop();
                    if (currNode.IsDirectory)
                    {
                        foreach (var childNode in currNode.Children)
                        {
                            nodesToUnload.Push(childNode);
                        }
                    }
                    else
                    {
                        paths = paths.Append(currNode.Path);
                    }
                }

                eventAggregator.GetEvent <UnloadImagesEvent>().Publish(new UnloadImagesPayload(paths));
                //only uppon success
                if (RemoveNode(FSEntries, node))
                {
                    PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(FSEntries)));
                }
                //}, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.FromCurrentSynchronizationContext());
            }, (_) => true);

            OpenInFileExplorer = new RelayCommand((x) =>
            {
                var path            = ((NodeVM)x).Path;
                var explorerService = new Services.OpenFileExplorer();
                if (System.IO.Directory.Exists(path) || System.IO.File.Exists(path))
                {
                    explorerService.ShowFileExplorer(path);
                }
                else
                {
                    throw new InvalidOperationException($"Error occured, the file system entry {path} does not exist anymore");
                }
            }, (_) => true);

            NodeRightClick = new RelayCommand((x) =>
            {
                if (x is NodeVM node)
                {
                    node.IsSelected = true;
                }
            }, (_) => true);
        }
Пример #22
0
 public ColorPickerTool(DocumentProvider documentProvider, BitmapManager bitmapManager)
 {
     ActionDisplay  = defaultActionDisplay;
     _docProvider   = documentProvider;
     _bitmapManager = bitmapManager;
 }
Пример #23
0
 public EraserTool(BitmapManager bitmapManager)
 {
     ActionDisplay = "Draw to remove color from a pixel.";
     Toolbar       = new BasicToolbar();
     pen           = new PenTool(bitmapManager);
 }
Пример #24
0
 public ZoomTool(BitmapManager bitmapManager)
 {
     CanStartOutsideCanvas = true;
     ActionDisplay         = "Click and move to zoom. Click to zoom in, hold alt and click to zoom out.";
     BitmapManager         = bitmapManager;
 }
Пример #25
0
        public void Test_BitmapManager()
        {
            using (BitmapManager bitmapManager = new BitmapManager("bitmap", _bufferManager))
            {
                bitmapManager.SetLength(1024 * 256);

                Random random_a, random_b;

                {
                    var seed = _random.Next();

                    random_a = new Random(seed);
                    random_b = new Random(seed);
                }

                {
                    for (int i = 0; i < 1024; i++)
                    {
                        var p = random_a.Next(0, 1024 * 256);
                        bitmapManager.Set(p, true);
                    }

                    for (int i = 0; i < 1024; i++)
                    {
                        var p = random_b.Next(0, 1024 * 256);
                        Assert.IsTrue(bitmapManager.Get(p));
                    }

                    {
                        int count = 0;

                        for (int i = 0; i < 1024 * 256; i++)
                        {
                            if (bitmapManager.Get(i))
                            {
                                count++;
                            }
                        }

                        Assert.IsTrue(count <= 1024);
                    }
                }

                {
                    for (int i = 0; i < 1024 * 256; i++)
                    {
                        bitmapManager.Set(i, true);
                    }

                    for (int i = 0; i < 1024; i++)
                    {
                        var p = random_a.Next(0, 1024 * 256);
                        bitmapManager.Set(p, false);
                    }

                    for (int i = 0; i < 1024; i++)
                    {
                        var p = random_b.Next(0, 1024 * 256);
                        Assert.IsTrue(!bitmapManager.Get(p));
                    }

                    {
                        int count = 0;

                        for (int i = 0; i < 1024 * 256; i++)
                        {
                            if (!bitmapManager.Get(i))
                            {
                                count++;
                            }
                        }

                        Assert.IsTrue(count <= 1024);
                    }
                }
            }
        }
Пример #26
0
 public FloodFill(BitmapManager bitmapManager)
 {
     ActionDisplay = "Press on a area to fill it.";
     BitmapManager = bitmapManager;
 }
Пример #27
0
 public ZoomTool(BitmapManager bitmapManager)
 {
     ActionDisplay = defaultActionDisplay;
     BitmapManager = bitmapManager;
 }