public ItemCell(Texture2D textureNotSelected, Texture2D textureSelected, float locX, float locY, char cellChar) : base(new Vector2(locX, locY), textureNotSelected, SCALE, false) { this.cellChar = cellChar; holdingThumbnail = null; this.textureNotSelected = textureNotSelected; this.textureSelected = textureSelected; }
public void createSidesMenu() { //Inventory is opened and the menu is preset to clear. openMenu(); clearItemMenu(); //The text of the sub-category is displayed at the top of the menu. mainMenuText.text = "Sides"; //Set the rectangle transform to fit a correct size for the required content to load. rectTransform.sizeDelta = new Vector2(rectTransform.sizeDelta.x, (sides.Length / 2 + 2f) * 150); //If statement for starters for (int i = 0; i < sides.Length; i++) { //Retrieve the game-components inside of the thumbnail image used, including: //The actual gameobject thumbnail, the rect transform element, the image used and the script attached (ItemThumbnail.cs) GameObject gameobjectThumbnail = Instantiate(thumbnailImage, menuScrollView); RectTransform rectTransform = gameobjectThumbnail.GetComponent <RectTransform>(); Image imgThumbnail = gameobjectThumbnail.GetComponent <Image>(); ItemThumbnail thumbnailScript = gameobjectThumbnail.GetComponent <ItemThumbnail>(); //Sizing the thumbnail directly. int div = i / 2; int rest = i % 2; //If its set to 0 (even) if (rest == 0) { //Transform the thumbnail image as shown gameobjectThumbnail.transform.localPosition = new Vector3((1 - 0.5f) * rectTransform.sizeDelta.x, -(div + 1.1f) * rectTransform.sizeDelta.y, 0); } else { //Format the thumbnail image like this instead gameobjectThumbnail.transform.localPosition = new Vector3((2 - 0.5f) * rectTransform.sizeDelta.x, -(div + 1.1f) * rectTransform.sizeDelta.y, 0);; } //Finds the relevant thumbnail sprite element from the starters icon list. imgThumbnail.sprite = sides_icons[i]; //Sets our thumbnail script for every icon used. thumbnailScript.type = typeOfMenuItem.sides; thumbnailScript.index = i; } }
private ItemThumbnail CreateItemThumbnail(FileInfo file) { ItemThumbnail item; if (Setting.ImageExtensions.Contains(file.Extension)) { var dimension = ImageDimension.GetDimensions(file.FullName); item = new ItemThumbnail(file.FullName, file.Name, file.Extension, dimension, (file.Length / 1000).ToString()); } else { item = new ItemThumbnail(file.FullName, file.Name, file.Extension, null, (file.Length / 1000).ToString()); } return(item); }
public static void ResizeItem(ItemThumbnail selectedThumb, Preset preset) { if (selectedThumb.Dimension == null) { return; } //throw new Exception("error, fail to read dimension header"); float width = 0; float height = 0; var info = new FileInfo(selectedThumb.FullName); var id = ""; var tempFilePath = ""; switch (preset.ResizeMode) { case Model.ResizeMode.InPixel: throw new Exception(); case Model.ResizeMode.Percentage: float percentage = preset.Percentage / 100f; width = selectedThumb.Dimension.Width * percentage; height = selectedThumb.Dimension.Height * percentage; break; case Model.ResizeMode.BaseOnOneSide: float ratio = (float)selectedThumb.Dimension.Width / (float)selectedThumb.Dimension.Height; switch ((PredefineSide)preset.PredefineSide) { case PredefineSide.Width: width = preset.BaseNumber; height = preset.BaseNumber / ratio; break; case PredefineSide.Height: height = preset.BaseNumber; width = preset.BaseNumber * ratio; break; default: throw new Exception("no predefine side selected"); } break; default: throw new Exception(); } using (var img = System.Drawing.Image.FromFile(selectedThumb.FullName)) { id = Guid.NewGuid().ToString("N"); tempFilePath = System.IO.Path.Combine(info.Directory.FullName, id); var bitmap = Resizer.ResizeImage(img, (int)Convert.ToDouble(width.ToString()), (int)Convert.ToDouble(height.ToString())); Resizer.SaveJpeg(tempFilePath, bitmap, preset.Quality); } var result = FileOperationAPIWrapper.Send(selectedThumb.FullName); if (!result) { throw new Exception("something went wrong when tried to delete file"); } var temp = new FileInfo(tempFilePath); System.IO.File.Move(tempFilePath, System.IO.Path.ChangeExtension(selectedThumb.FullName, ".jpg")); }