Example #1
0
        /// <summary>Creates a thumbnail based on an existing image without a frame.</summary>
        /// <param name="file">The full path to the original image.</param>
        /// <param name="thumbFolder">The folder where the thumbnail should be saved.</param>
        /// <param name="preview">The variant of the preview.</param>
        /// <param name="saveThumb">if set to <c>true</c> the thumbnail should save.</param>
        /// <returns>The preview BitmapImage.</returns>
        public BitmapImage BuildThumbnail(string file, string thumbFolder, ShowPreview preview, bool saveThumb)
        {
            if (preview == ShowPreview.No && !File.Exists(thumbFolder))
            {
                Directory.CreateDirectory(Path.Combine(Path.GetDirectoryName(file) + @"\", thumbFolder));
            }

            return(CreateThumbnail(file, thumbFolder, Border.None, null, 0, null, 0, preview, saveThumb));
        }
Example #2
0
        private void UpdateState(string name)
        {
            if (name == "FilePath")
            {
                if (!string.IsNullOrEmpty(filePath) &&
                    File.Exists(FilePath))
                {
                    // Set current definition
                    var fileInfo   = new FileInfo(FilePath);
                    var definition = ThemedHighlightingManager.Instance.GetDefinitionByExtension(fileInfo.Extension);
                    if (definition != null)
                    {
                        CurrentSyntax = definition.Name;
                    }
                    else
                    {
                        CurrentSyntax = "None";
                    }

                    // Do not preview files over 4MB or binary
                    IsLargeOrBinary = fileInfo.Length > 4096000 || Utils.IsBinary(FilePath);

                    // Disable highlighting for large number of matches
                    HighlightDisabled = GrepResult?.Matches?.Count > 5000;

                    // Tell View to show window
                    ShowPreview?.Invoke(this, new ShowEventArgs {
                        ClearContent = true
                    });
                }
                else
                {
                    // Tell View to show window and clear content
                    ShowPreview?.Invoke(this, new ShowEventArgs {
                        ClearContent = true
                    });
                }
            }

            if (name == "LineNumber")
            {
                // Tell View to show window but not clear content
                ShowPreview?.Invoke(this, new ShowEventArgs {
                    ClearContent = false
                });
            }

            if (name == "CurrentSyntax")
            {
                // Tell View to show window and clear content
                ShowPreview?.Invoke(this, new ShowEventArgs {
                    ClearContent = true
                });
            }
        }
Example #3
0
        /// <summary>Creates a thumbnail based on RGB values with a single frame.</summary>
        /// <param name="file">The full path to the new image.</param>
        /// <param name="thumbFolder">The folder where the thumbnail should be saved.</param>
        /// <param name="rgb">The desired color as RGB values.</param>
        /// <param name="borderBrush">The border brush.</param>
        /// <param name="borderSize">Size of the border.</param>
        /// <param name="preview">The variant of the preview.</param>
        /// <param name="saveThumb">if set to <c>true</c> the thumbnail should save.</param>
        /// <returns>The preview BitmapImage.</returns>
        public BitmapImage BuildThumbnail(string file, string thumbFolder, byte[] rgb, SolidColorBrush borderBrush, int borderSize,
                                          ShowPreview preview, bool saveThumb)
        {
            if (preview == ShowPreview.No && !File.Exists(thumbFolder))
            {
                Directory.CreateDirectory(Path.Combine(Path.GetDirectoryName(file) + @"\", thumbFolder));
            }

            return(CreateThumbnail(file, thumbFolder, rgb, Border.Single, ColorConverterService.SolidColorBrushToSolidBrush(borderBrush), borderSize,
                                   null, 0, preview, saveThumb));
        }
Example #4
0
        private void UpdateState(string name)
        {
            if (name == nameof(GrepResult))
            {
                MarkerLineNumbers = GrepResult.SearchResults.Where(sr => !sr.IsContext)
                                    .Select(sr => sr.LineNumber).Distinct().ToList();
            }

            if (name == nameof(FilePath))
            {
                ClearPositionMarkers();
                if (!string.IsNullOrEmpty(filePath) &&
                    File.Exists(FilePath))
                {
                    // Set current definition
                    var fileInfo   = new FileInfo(FilePath);
                    var definition = ThemedHighlightingManager.Instance.GetDefinitionByExtension(fileInfo.Extension);
                    CurrentSyntax = definition != null ? definition.Name : Resources.Preview_SyntaxNone;

                    try
                    {
                        // Do not preview files over 4MB or binary
                        IsPdf           = Utils.IsPdfFile(FilePath);
                        IsLargeOrBinary = fileInfo.Length > 4096000 || Utils.IsBinary(FilePath) || IsPdf;
                    }
                    catch (System.IO.IOException ex)
                    {
                        // Is the file locked and cannot be read by IsBinary?
                        // message is shown in the preview window
                        logger.Error(ex, "Failure in check for large or binary");
                    }

                    // Disable highlighting for large number of matches
                    HighlightDisabled = GrepResult?.Matches?.Count > 5000;

                    // Tell View to show window
                    ShowPreview?.Invoke(this, EventArgs.Empty);
                }
                else
                {
                    // Tell View to show window and clear content
                    ShowPreview?.Invoke(this, EventArgs.Empty);
                }
            }
        }
Example #5
0
        private void UpdateState(string name)
        {
            if (name == nameof(FilePath))
            {
                if (!string.IsNullOrEmpty(filePath) &&
                    File.Exists(FilePath))
                {
                    // Set current definition
                    var fileInfo   = new FileInfo(FilePath);
                    var definition = ThemedHighlightingManager.Instance.GetDefinitionByExtension(fileInfo.Extension);
                    if (definition != null)
                    {
                        CurrentSyntax = definition.Name;
                    }
                    else
                    {
                        CurrentSyntax = "None";
                    }

                    try
                    {
                        // Do not preview files over 4MB or binary
                        IsLargeOrBinary = fileInfo.Length > 4096000 || Utils.IsBinary(FilePath);
                    }
                    catch (System.IO.IOException ex)
                    {
                        // Is the file locked and cannot be read by IsBinary?
                        // message is shown in the preview window
                        logger.Error(ex, "Failure in check for large or binary");
                    }

                    // Disable highlighting for large number of matches
                    HighlightDisabled = GrepResult?.Matches?.Count > 5000;

                    // Tell View to show window
                    ShowPreview?.Invoke(this, new ShowEventArgs {
                        ClearContent = true
                    });
                }
                else
                {
                    // Tell View to show window and clear content
                    ShowPreview?.Invoke(this, new ShowEventArgs {
                        ClearContent = true
                    });
                }
            }

            if (name == nameof(LineNumber))
            {
                // Tell View to show window but not clear content
                ShowPreview?.Invoke(this, new ShowEventArgs {
                    ClearContent = false
                });
            }

            if (name == nameof(CurrentSyntax))
            {
                // Tell View to show window and clear content
                ShowPreview?.Invoke(this, new ShowEventArgs {
                    ClearContent = true
                });
            }
        }
Example #6
0
        private BitmapImage SwitchDoing(Image b, string file, string thumbFolder, Border border, SolidBrush outerBorderBrush, int outerBorderSize,
                                        SolidBrush innerBorderBrush, int innerBorderSize, ShowPreview preview, bool saveThumb)
        {
            string logMessage;

            switch (border)
            {
            case Border.Single:
                b = imageService.CreateSingleBorder(b, outerBorderBrush, outerBorderSize);
                break;

            case Border.Double:
                b = imageService.CreateDoubleBorder(b, outerBorderBrush, innerBorderBrush, outerBorderSize, innerBorderSize);
                break;

            case Border.None:
                break;

            default:
                var ex = new ArgumentOutOfRangeException(nameof(border), border, null);

                logMessage = $"[{GetType().Name}] Exception at {MethodBase.GetCurrentMethod()}: {ex}";
                unityContainer.Resolve <ILoggerFacade>().Log(logMessage, Category.Exception, Priority.High);

                DialogService.Exception(ex, DialogService.ExceptionType.Universal);
                throw ex;
            }

            switch (preview)
            {
            case ShowPreview.No:
                if (!saveThumb)
                {
                    return(null);
                }

                var newFile = Path.Combine(Path.GetDirectoryName(file) + @"\", thumbFolder) + @"\" + Path.GetFileName(file);

                b.Save(newFile, ImageFormat.Jpeg);

                logMessage = $"[{GetType().Name}] File ({newFile}) was created";
                unityContainer.Resolve <ILoggerFacade>().Log(logMessage, Category.Debug, Priority.None);

                return(null);

            case ShowPreview.Original:
                logMessage = $"[{GetType().Name}] Preview in original size was created";
                unityContainer.Resolve <ILoggerFacade>().Log(logMessage, Category.Debug, Priority.None);

                return(imageService.GetBitmapImageFromImage(b, ImageFormat.Jpeg));

            case ShowPreview.Thumbnail:
                logMessage = $"[{GetType().Name}] Preview in thumbnail size was created";
                unityContainer.Resolve <ILoggerFacade>().Log(logMessage, Category.Debug, Priority.None);

                return(imageService.GetBitmapImageFromImage(b, ImageFormat.Jpeg));

            default:
                var ex = new ArgumentOutOfRangeException(nameof(preview), preview, null);

                logMessage = $"[{GetType().Name}] Exception at {MethodBase.GetCurrentMethod()}: {ex}";
                unityContainer.Resolve <ILoggerFacade>().Log(logMessage, Category.Exception, Priority.High);

                DialogService.Exception(ex, DialogService.ExceptionType.Universal);
                throw ex;
            }
        }
Example #7
0
        private BitmapImage CreateThumbnail(string file, string thumbFolder, Border border, SolidBrush outerBorderBrush, int outerBorderSize,
                                            SolidBrush innerBorderBrush, int innerBorderSize, ShowPreview preview, bool saveThumb)
        {
            ChoiceDimension(preview == ShowPreview.Original);

            var b = saveThumb && preview != ShowPreview.Original
                ? imageService.ResizeImage(file, ThumbDim[0], ThumbDim[1])
                : imageService.ResizeImage(file, ThumbDim[0], ThumbDim[1], false);

            return(SwitchDoing(b, file, thumbFolder, border, outerBorderBrush, outerBorderSize, innerBorderBrush, innerBorderSize, preview, saveThumb));
        }
Example #8
0
        private BitmapImage CreateThumbnail(string file, string thumbFolder, IReadOnlyList <byte> rgb, Border border, SolidBrush outerBorderBrush,
                                            int outerBorderSize, SolidBrush innerBorderBrush, int innerBorderSize, ShowPreview preview, bool saveThumb)
        {
            ChoiceDimension(preview == ShowPreview.Original);

            var b = new Bitmap(ThumbDim[0], ThumbDim[1]);

            using (var g = Graphics.FromImage(b))
            {
                g.FillRectangle(new SolidBrush(Color.FromArgb(rgb[0], rgb[1], rgb[2])), 0, 0, ThumbDim[0], ThumbDim[1]);
                g.DrawImage(b, 0, 0, ThumbDim[0], ThumbDim[1]);
                g.Dispose();
            }

            return(SwitchDoing(b, file, thumbFolder, border, outerBorderBrush, outerBorderSize, innerBorderBrush, innerBorderSize, preview, saveThumb));
        }
Example #9
0
        /// <summary>Creates a thumbnail based on an existing image double a frame.</summary>
        /// <param name="file">The full path to the original image.</param>
        /// <param name="thumbFolder">The folder where the thumbnail should be saved.</param>
        /// <param name="outerBorderBrush">The outer border brush.</param>
        /// <param name="outerBorderSize">Size of the outer border.</param>
        /// <param name="innerBorderBrush">The inner border brush.</param>
        /// <param name="innerBorderSize">Size of the inner border.</param>
        /// <param name="preview">The variant of the preview.</param>
        /// <param name="saveThumb">if set to <c>true</c> the thumbnail should save.</param>
        /// <returns>The preview BitmapImage.</returns>
        public BitmapImage BuildThumbnail(string file, string thumbFolder, SolidColorBrush outerBorderBrush, int outerBorderSize,
                                          SolidColorBrush innerBorderBrush, int innerBorderSize, ShowPreview preview, bool saveThumb)
        {
            if (preview == ShowPreview.No && !File.Exists(thumbFolder))
            {
                Directory.CreateDirectory(Path.Combine(Path.GetDirectoryName(file) + @"\", thumbFolder));
            }

            return(CreateThumbnail(file, thumbFolder, Border.Double, ColorConverterService.SolidColorBrushToSolidBrush(outerBorderBrush),
                                   outerBorderSize, ColorConverterService.SolidColorBrushToSolidBrush(innerBorderBrush), innerBorderSize, preview, saveThumb));
        }
Example #10
0
    private void Update()
    {
        DoBlockPlacer();


        if (Input.GetKeyDown(KeyCode.G))
        {
            GameObject   zombieGO = GameObject.Instantiate((GameObject)Resources.Load("Enemy/ENEMY_ZOMBIE"));
            NavMeshAgent NVA      = zombieGO.AddComponent <NavMeshAgent>();
            NVA.radius = 7.46f;
            NVA.height = 16f;
            zombieGO.AddComponent <EnemyZombieAI>();
        }
        if (noColPaintMode)
        {
            //No colour paint mode
            RaycastHit _hit;
            Ray        _ray = Camera.main.ScreenPointToRay(Input.mousePosition);

            if (Physics.Raycast(_ray, out _hit, Mathf.Infinity))
            {
                if (Vector3.Distance(_hit.point, Camera.main.transform.position) > minToCamera)
                {
                    if (Input.GetKeyDown(KeyCode.Mouse0))
                    {
                        //Colour object
                        if (_hit.collider.gameObject != null)
                        {
                            Transform mainObj = Util.getInitialParent(_hit.collider.transform, this.transform.name);
                            Debug.Log("Painting " + mainObj.name + " To have no colour");
                            GOData god = mainObj.GetComponent <GOData>();
                            if (god != null)
                            {
                                god.coloured = false;
                            }
                            //Add block to non-coloured layer
                            Util.MoveToLayer(mainObj, 10);
                        }
                    }
                    else
                    {
                        //Preview Selection
                        if (_hit.collider.gameObject != null)
                        {
                            Transform mainObj = Util.getInitialParent(_hit.collider.transform, this.transform.name);
                        }
                    }
                }
            }
        }
        else if (colourPaintMode)
        {
            //Colour paint mode
            RaycastHit _hit;
            Ray        _ray = Camera.main.ScreenPointToRay(Input.mousePosition);

            if (Physics.Raycast(_ray, out _hit, Mathf.Infinity))
            {
                if (Vector3.Distance(_hit.point, Camera.main.transform.position) > minToCamera)
                {
                    if (Input.GetKeyDown(KeyCode.Mouse0))
                    {
                        //Colour Object
                        if (_hit.collider.gameObject != null)
                        {
                            Transform mainObj = Util.getInitialParent(_hit.collider.transform, this.transform.name);
                            Debug.Log("Painting " + mainObj.name + " To have colour");
                            GOData god = mainObj.GetComponent <GOData>();
                            if (god != null)
                            {
                                god.coloured = true;
                            }
                            //Add block to coloured layer
                            Util.MoveToLayer(mainObj, 9);
                        }
                    }
                    else
                    {
                        //Preview Selection
                        if (_hit.collider.gameObject != null)
                        {
                            Transform mainObj = Util.getInitialParent(_hit.collider.transform, this.transform.name);
                        }
                    }
                }
            }
        }
        else if (demolishMode)
        {
            //Demolish mode
            RaycastHit _hit;
            Ray        _ray = Camera.main.ScreenPointToRay(Input.mousePosition);

            if (Physics.Raycast(_ray, out _hit, Mathf.Infinity))
            {
                if (Vector3.Distance(_hit.point, Camera.main.transform.position) > minToCamera)
                {
                    if (Input.GetKeyDown(KeyCode.Mouse0))
                    {
                        //Delete object
                        if (_hit.collider.gameObject != null)
                        {
                            Transform mainObj = Util.getInitialParent(_hit.collider.transform, this.transform.name);
                            Debug.Log("Deleting: " + mainObj.name);
                            if (mapData.Contains(mainObj.gameObject))
                            {
                                mapData.Remove(mainObj.gameObject); Destroy(mainObj.gameObject);
                            }
                        }
                    }
                    else
                    {
                        //Preview Selection
                        if (_hit.collider.gameObject != null)
                        {
                            Transform      mainObj = Util.getInitialParent(_hit.collider.transform, this.transform.name);
                            MeshRenderer[] mr      = mainObj.GetComponentsInChildren <MeshRenderer>();
                            lastSelectedPreview = mainObj.gameObject;
                            foreach (MeshRenderer _mr in mr)
                            {
                                ShowPreview sp = _mr.gameObject.AddComponent <ShowPreview>();
                                sp.Load(mainObj.gameObject, this, _mr);
                            }
                        }
                    }
                }
            }
        }
    }