Exemplo n.º 1
0
        public RocketWidget(ImageBox imageBox, bool transparent, bool autoCreateTexture = true)
        {
            this.imageBox = imageBox;
            if (transparent)
            {
                ogreTextureFormat = OgrePlugin.PixelFormat.PF_A8R8G8B8;
            }
            this.name = RocketWidgetManager.generateRocketWidgetName(this);

            //Create ogre stuff
            sceneManager = Root.getSingleton().createSceneManager(SceneType.ST_GENERIC, "__libRocketScene_" + name);
            camera       = sceneManager.createCamera("libRocketCamera");

            //Create context
            context = Core.CreateContext(name, new Vector2i(imageBox.Width, imageBox.Height));
            context.GetRootElement().AddEventListener("focus", new ElementFocusListener(this), false);
            context.GetRootElement().AddEventListener("blur", new ElementBlurredListener(this), false);

            renderQueueListener = new RocketRenderQueueListener(context, (RenderInterfaceOgre3D)Core.GetRenderInterface());
            renderQueueListener.FrameCompleted += new Action(renderQueueListener_FrameCompleted);
            sceneManager.addRenderQueueListener(renderQueueListener);

            imageBox.NeedKeyFocus   = true;
            imageBox.NeedMouseFocus = true;

            imageBox.MouseButtonPressed  += imageBox_MouseButtonPressed;
            imageBox.MouseButtonReleased += imageBox_MouseButtonReleased;
            imageBox.MouseMove           += imageBox_MouseMove;
            imageBox.MouseDrag           += imageBox_MouseMove;
            imageBox.MouseWheel          += imageBox_MouseWheel;
            imageBox.KeyButtonPressed    += imageBox_KeyButtonPressed;
            imageBox.KeyButtonReleased   += imageBox_KeyButtonReleased;
            imageBox.EventScrollGesture  += imageBox_EventScrollGesture;

            //In mygui lost/got focus is mouse entered / left
            imageBox.MouseSetFocus      += imageBox_MouseSetFocus;
            imageBox.MouseLostFocus     += imageBox_MouseLostFocus;
            imageBox.RootKeyChangeFocus += imageBox_RootKeyChangeFocus;

            RocketInterface.Instance.TextureLoaded += renderOnNextFrame;

            if (autoCreateTexture)
            {
                resized();
            }

            determineRenderingActive();
        }
Exemplo n.º 2
0
        private FreeImageBitmap simpleRender(int width, int height, int aaMode, bool transparentBG, Engine.Color bgColor, RenderTexture renderTexture)
        {
            renderTexture.getViewport(0).clear(FrameBufferType.FBT_COLOUR | FrameBufferType.FBT_DEPTH | FrameBufferType.FBT_STENCIL, bgColor);
            renderTexture.update();
            OgrePlugin.PixelFormat   format       = OgrePlugin.PixelFormat.PF_A8R8G8B8;
            FreeImageAPI.PixelFormat bitmapFormat = FreeImageAPI.PixelFormat.Format32bppRgb;
            if (transparentBG)
            {
                bitmapFormat = FreeImageAPI.PixelFormat.Format32bppArgb;
            }
            FreeImageBitmap bitmap = new FreeImageBitmap(width, height, bitmapFormat);

            bitmap.copyFromRenderTarget(renderTexture, format);

            //Resize if aa is active
            if (aaMode > 1)
            {
                int smallWidth  = width / aaMode;
                int smallHeight = height / aaMode;
                bitmap.Rescale(smallWidth, smallHeight, FREE_IMAGE_FILTER.FILTER_BILINEAR);
            }

            return(bitmap);
        }
Exemplo n.º 3
0
        private IEnumerable <IdleStatus> gridRender(int width, int height, int backBufferWidth, int backBufferHeight, int aaMode, RenderTexture renderTexture, Camera camera, Camera backgroundCamera, bool transparentBG, Engine.Color bgColor, Action <FreeImageBitmap> renderingCompletedCallback)
        {
            float originalLeft, originalRight, originalTop, originalBottom;

            camera.getFrustumExtents(out originalLeft, out originalRight, out originalTop, out originalBottom);

            int imageCountWidth  = width % backBufferWidth == 0 ? width / backBufferWidth : width / backBufferWidth + 1;
            int imageCountHeight = height % backBufferHeight == 0 ? height / backBufferHeight : height / backBufferHeight + 1;

            float gridStepHoriz = (originalRight * 2) / imageCountWidth;
            float gridStepVert  = (originalTop * 2) / imageCountHeight;

            float bgOriginalLeft = 0, bgOriginalRight = 0, bgOriginalTop = 0, bgOriginalBottom = 0, bgGridStepHoriz = 0, bgGridStepVert = 0;

            if (backgroundCamera != null)
            {
                backgroundCamera.getFrustumExtents(out bgOriginalLeft, out bgOriginalRight, out bgOriginalTop, out bgOriginalBottom);
                bgGridStepHoriz = (bgOriginalRight * 2) / imageCountWidth;
                bgGridStepVert  = (bgOriginalTop * 2) / imageCountHeight;
            }

            int imageStepHoriz = backBufferWidth;
            int imageStepVert  = backBufferHeight;

            int finalWidth          = width / aaMode;
            int finalHeight         = height / aaMode;
            int imageStepHorizSmall = finalWidth / imageCountWidth;
            int imageStepVertSmall  = finalHeight / imageCountHeight;

            float left, right, top, bottom;
            float bgLeft, bgRight, bgTop, bgBottom;
            int   totalSS = imageCountWidth * imageCountHeight;

            String updateString = "Rendering piece {0} of " + totalSS;

            OgrePlugin.PixelFormat   format       = OgrePlugin.PixelFormat.PF_A8R8G8B8;
            FreeImageAPI.PixelFormat bitmapFormat = FreeImageAPI.PixelFormat.Format32bppRgb;
            if (transparentBG)
            {
                bitmapFormat = FreeImageAPI.PixelFormat.Format32bppArgb;
            }

            Rectangle       destRect   = new Rectangle();
            Rectangle       srcRect    = new Rectangle(0, 0, imageStepHoriz, imageStepVert);
            FreeImageBitmap fullBitmap = new FreeImageBitmap(finalWidth, finalHeight, bitmapFormat);

            using (FreeImageBitmap pieceBitmap = new FreeImageBitmap(imageStepHoriz, imageStepVert, bitmapFormat))
            {
                bool      aaOn            = aaMode > 1;
                Rectangle scalarRectangle = new Rectangle();
                if (aaOn)
                {
                    scalarRectangle = new Rectangle(0, 0, imageStepHorizSmall, imageStepVertSmall);
                }
                for (int i = 0; i < totalSS; ++i)
                {
                    int y = i / imageCountWidth;
                    int x = i - y * imageCountWidth;

                    left   = originalLeft + gridStepHoriz * x;
                    right  = left + gridStepHoriz;
                    top    = originalTop - gridStepVert * y;
                    bottom = top - gridStepVert;

                    camera.setFrustumExtents(left, right, top, bottom);
                    if (backgroundCamera != null)
                    {
                        bgLeft   = bgOriginalLeft + bgGridStepHoriz * x;
                        bgRight  = bgLeft + bgGridStepHoriz;
                        bgTop    = bgOriginalTop - bgGridStepVert * y;
                        bgBottom = bgTop - bgGridStepVert;

                        backgroundCamera.setFrustumExtents(bgLeft, bgRight, bgTop, bgBottom);
                    }
                    Root.getSingleton().clearEventTimes();
                    renderTexture.getViewport(0).clear(FrameBufferType.FBT_COLOUR | FrameBufferType.FBT_DEPTH | FrameBufferType.FBT_STENCIL, bgColor);
                    renderTexture.update();

                    pieceBitmap.copyFromRenderTarget(renderTexture, format);
                    destRect.X      = x * imageStepHorizSmall;
                    destRect.Y      = y * imageStepVertSmall;
                    destRect.Width  = imageStepHorizSmall;
                    destRect.Height = imageStepVertSmall;
                    if (aaOn)
                    {
                        using (FreeImageBitmap scaled = new FreeImageBitmap(pieceBitmap))
                        {
                            scaled.Rescale(scalarRectangle.Width, scalarRectangle.Height, FREE_IMAGE_FILTER.FILTER_BILINEAR);
                            fullBitmap.Paste(scaled, destRect.X, destRect.Y, int.MaxValue);
                        }
                    }
                    else
                    {
                        fullBitmap.Paste(pieceBitmap, destRect.X, destRect.Y, int.MaxValue);
                    }

                    if (imageRendererProgress != null)
                    {
                        imageRendererProgress.update((uint)(((float)(i + 1) / totalSS) * 100.0f), String.Format(updateString, i + 1));
                        if (imageRendererProgress.Cancel)
                        {
                            break;
                        }
                    }

                    yield return(IdleStatus.Ok);
                }
            }

            renderTexture.getViewport(0).setOverlaysEnabled(true);

            renderingCompletedCallback(fullBitmap);
            yield break;
        }