Beispiel #1
0
        private void RenderItem(IntPtr data, uint cx, uint cy)
        {
            bool sourceIsInitialized = _source.Width != 0 || _source.Height != 0;

            if (!sourceIsInitialized)
            {
                if (_loadingMessage == null)
                {
                    Store.Data.Webcam.Window.Dispatcher.Invoke(new Action(AddLoadingMessage));
                }
            }
            else
            {
                if (_loadingMessage != null)
                {
                    Store.Data.Webcam.Window.Dispatcher.Invoke(new Action(RemoveLoadingMessage));
                }
            }

            int   newW             = (int)cx;
            int   newH             = (int)cy;
            int   itemWidth        = (int)_item.Width;
            int   itemHeight       = (int)_item.Height;
            int   itemSourceWidth  = (int)_source.Width;
            int   itemSourceHeight = (int)_source.Height;
            float previewAspect    = (float)cx / cy;
            float itemAspect       = (float)itemWidth / itemHeight;
            float sourceAspect     = (float)itemSourceWidth / itemSourceHeight;

            //calculate new width and height for item to make it fit inside the preview area
            if (previewAspect > itemAspect)
            {
                newW = (int)(cy * itemAspect);
            }
            else
            {
                newH = (int)(cx / itemAspect);
            }

            int centerX = ((int)cx - newW) / 2;
            int centerY = ((int)cy - newH) / 2;

            GS.ViewportPush();
            GS.ProjectionPush();

            float difWidth  = itemAspect < sourceAspect ? (itemSourceWidth - (itemSourceHeight * itemAspect)) / 2.0f : 0.0f;
            float difHeight = itemAspect < sourceAspect ? 0.0f : (itemSourceHeight - (itemSourceWidth / itemAspect)) / 2.0f;

            //setup orthographic projection of the item
            GS.Ortho(difWidth, itemSourceWidth - difWidth, difHeight, itemSourceHeight - difHeight, -100.0f, 100.0f);
            GS.SetViewport(centerX, centerY, newW, newH);

            //render item content
            _source.Render();

            GS.ProjectionPop();
            GS.ViewportPop();

            GS.LoadVertexBuffer(null);
        }
        private void RenderSource(IntPtr data, uint cx, uint cy)
        {
            int   newW          = (int)cx;
            int   newH          = (int)cy;
            int   sourceWidth   = (int)source.Width;
            int   sourceHeight  = (int)source.Height;
            float previewAspect = (float)cx / cy;
            float sourceAspect  = (float)sourceWidth / sourceHeight;

            //calculate new width and height for source to make it fit inside the preview area
            if (previewAspect > sourceAspect)
            {
                newW = (int)(cy * sourceAspect);
            }
            else
            {
                newH = (int)(cx / sourceAspect);
            }

            int centerX = ((int)cx - newW) / 2;
            int centerY = ((int)cy - newH) / 2;

            GS.ViewportPush();
            GS.ProjectionPush();

            //setup orthographic projection of the source
            GS.Ortho(0.0f, sourceWidth, 0.0f, sourceHeight, -100.0f, 100.0f);
            GS.SetViewport(centerX, centerY, newW, newH);

            //render source content
            source.Render();

            GS.ProjectionPop();
            GS.ViewportPop();

            GS.LoadVertexBuffer(null);
        }