Exemple #1
0
        Rect DrawResolutionPreview(Rect pos, ScreenshotResolution resolution)
        {
            Vector2 size = GetRenderSize(resolution, m_ConfigAsset.m_PreviewGalleryZoom, m_ConfigAsset.m_GalleryDisplayMode);

            if (size == Vector2.zero)
            {
                return(pos);
            }

            // If can not draw the rect in the current row, create a new row
            if (pos.x > m_ConfigAsset.m_MarginHorizontal && pos.x + size.x + m_ConfigAsset.m_MarginHorizontal > m_WindowWidth)
            {
                pos.x = m_ConfigAsset.m_MarginHorizontal;
                pos.y = height + m_ConfigAsset.m_GalleryPaddingVertical;
            }
            pos.width  = size.x;
            pos.height = size.y;

            // Draw the white background
            Rect borderpos = pos;

            borderpos.x      -= m_ConfigAsset.m_GalleryBorderSize;
            borderpos.y      -= m_ConfigAsset.m_GalleryBorderSize;
            borderpos.width  += 2 * m_ConfigAsset.m_GalleryBorderSize;
            borderpos.height += 2 * m_ConfigAsset.m_GalleryBorderSize + m_ConfigAsset.m_GalleryTextHeight;


            // Draw the resolution texture
            if (resolution.m_Texture != null)
            {
                EditorGUI.DrawTextureTransparent(pos, resolution.m_Texture);
            }
            else
            {
                EditorGUI.DrawTextureTransparent(pos, m_BackgroundTexture);
                EditorGUI.LabelField(pos, "Needs to be updated.", m_NameStyle);
            }

            // Display the resolution name
            Rect labelpos = pos;

            labelpos.y      = pos.y + size.y + 5;
            labelpos.height = m_ConfigAsset.m_GalleryTextHeight;
            EditorGUI.LabelField(labelpos, resolution.ToString(), m_NameStyle);

            // Increment the box position
            pos.x += size.x + m_ConfigAsset.m_GalleryPaddingVertical;
            height = (int)Mathf.Max(height, pos.y + size.y + 5 + m_ConfigAsset.m_GalleryTextHeight);
            width  = (int)Mathf.Max(width, size.x);

            return(pos);
        }
Exemple #2
0
        protected Vector2 GetRenderSize(ScreenshotResolution resolution, float zoom, PreviewConfigAsset.GalleryDisplayMode mode)
        {
            int displayWidth, displayHeight;
            int width  = resolution.ComputeTargetWidth();
            int height = resolution.ComputeTargetHeight();

            if (resolution.m_Texture != null)
            {
                width  = resolution.m_Texture.width;
                height = resolution.m_Texture.height;
            }

            if (width <= 0 || height <= 0)
            {
                EditorGUILayout.LabelField("Invalid dimensions for resolution " + resolution.ToString());
                return(Vector2.zero);
            }

            // Compute the box dimensions depending on the display mode
            if (mode == PreviewConfigAsset.GalleryDisplayMode.RATIOS)
            {
                displayWidth  = (int)((m_WindowWidth - m_ConfigAsset.m_MarginHorizontal) * zoom);
                displayHeight = (int)(displayWidth * height / width);
            }
            else if (mode == PreviewConfigAsset.GalleryDisplayMode.PIXELS || resolution.m_PPI <= 0)
            {
                displayWidth  = (int)(width * zoom / PixelsPerPoint());
                displayHeight = (int)(height * zoom / PixelsPerPoint());
            }
            else
            {
                displayWidth  = (int)(width * zoom / resolution.m_PPI * m_ConfigAsset.m_ScreenPPI / PixelsPerPoint());
                displayHeight = (int)(height * zoom / resolution.m_PPI * m_ConfigAsset.m_ScreenPPI / PixelsPerPoint());
            }

            // Invert the scaling
            displayWidth  = (int)((float)displayWidth / resolution.m_Scale);
            displayHeight = (int)((float)displayHeight / resolution.m_Scale);

            return(new Vector2(displayWidth, displayHeight));
        }