コード例 #1
0
        /// <inheritdoc/>
        protected override void OnDrawing(UltravioletTime time)
        {
            // We specify that we want to start drawing to a render target with the SetRenderTarget() method.
            Ultraviolet.GetGraphics().SetRenderTarget(rtarget);

            // IMPORTANT NOTE!
            // When a render target is set for rendering, Ultraviolet will automatically clear it to a lovely shade of dark purple.
            // You can change this behavior by passing RenderTargetUsage.PreserveContents to the render target constructor.
            Ultraviolet.GetGraphics().Clear(Color.Black);

            var effect     = content.Load <Effect>(GlobalEffectID.Noise);
            var effectTime = (Single)time.TotalTime.TotalSeconds * 0.1f;

            effect.Parameters["time"].SetValue(effectTime);

            var blank = content.Load <Texture2D>(GlobalTextureID.Blank);

            spriteBatch.Begin(SpriteSortMode.Deferred, null, null, null, null, effect);
            spriteBatch.Draw(blank, new RectangleF(0, 0, rtarget.Width, rtarget.Height), Color.White);
            spriteBatch.End();

            // When we finish drawing to a render target, we can revert to the compositor target by passing
            // null to the SetRenderTarget() method.
            Ultraviolet.GetGraphics().SetRenderTarget(null);
            Ultraviolet.GetGraphics().Clear(Color.CornflowerBlue);

            // IMPORTANT NOTE!
            // A render target (including its buffers) CANNOT BE BOUND FOR READING AND WRITING SIMULTANEOUSLY.
            // You MUST revert to a different render target before trying to draw your buffers!
            var compositor = Ultraviolet.GetPlatform().Windows.GetPrimary().Compositor;
            var compWidth  = compositor.Width;
            var compHeight = compositor.Height;

            var font = content.Load <SpriteFont>(GlobalFontID.SegoeUI);

            spriteBatch.Begin(SpriteSortMode.Deferred, null);
            spriteBatch.Draw(rbufferColor, new Vector2(
                                 (compWidth - rbufferColor.Width) / 2,
                                 (compHeight - rbufferColor.Height) / 2), Color.White);

            var instruction = Ultraviolet.Platform == UltravioletPlatform.Android ?
                              "Tap to save the image to the gallery" :
                              "Press F1 to save the image to a file";

            spriteBatch.DrawString(font, instruction,
                                   new Vector2(8f, 8f), Color.White);
            spriteBatch.DrawString(font, confirmMsgText ?? String.Empty,
                                   new Vector2(8f, 8f + font.Regular.LineSpacing), Color.White * (Single)confirmMsgOpacity);

            spriteBatch.End();

            // IMPORTANT NOTE!
            // Remember, we can't be bound for both reading and writing. We're currently bound for reading,
            // so we need to remember to unbind our buffers before we write to them again in the next frame.
            // The UnbindTexture() method is provided for convenience; if you know which sampler your texture
            // is bound to, you can either unbind the sampler manually, or bind another texture to it using SetTexture().
            Ultraviolet.GetGraphics().UnbindTexture(rbufferColor);

            base.OnDrawing(time);
        }
コード例 #2
0
        /// <summary>
        /// Converts the specified render target to a bitmap image.
        /// </summary>
        /// <param name="rt">The render target to convert.</param>
        /// <returns>The converted bitmap image.</returns>
        private Bitmap ConvertRenderTargetToBitmap(RenderTarget2D rt)
        {
            // HACK: Our buffer has been rounded up to the nearest
            // power of two, so at this point we clip it back down
            // to the size of the window.

            var window       = Ultraviolet.GetPlatform().Windows.GetPrimary();
            var windowWidth  = window.DrawableSize.Width;
            var windowHeight = window.DrawableSize.Height;

            var data = new Color[rt.Width * rt.Height];

            rt.GetData(data);

            var bmp   = new Bitmap(windowWidth, windowHeight);
            var pixel = 0;

            for (int y = 0; y < rt.Height; y++)
            {
                for (int x = 0; x < rt.Width; x++)
                {
                    if (x < windowWidth && y < windowHeight)
                    {
                        var rawColor = data[pixel];

                        bmp.SetPixel(x, y,
                                     System.Drawing.Color.FromArgb(255,
                                                                   System.Drawing.Color.FromArgb((Int32)rawColor.ToArgb())));
                    }
                    pixel++;
                }
            }

            return(bmp);
        }
コード例 #3
0
        protected override void OnDrawing(UltravioletTime time)
        {
            spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend);

            var settings = new TextLayoutSettings(spriteFont, null, null, TextFlags.Standard);

            if (Ultraviolet.Platform == UltravioletPlatform.Android || Ultraviolet.Platform == UltravioletPlatform.iOS)
            {
                textRenderer.Draw(spriteBatch, "Tap the screen to reset the scrolling text.",
                                  Vector2.One * 8f, Color.White, settings);
            }
            else
            {
                textRenderer.Draw(spriteBatch, $"Press {Ultraviolet.GetInput().GetActions().ResetScrollingText.Primary} to reset the scrolling text.",
                                  Vector2.One * 8f, Color.White, settings);
            }

            var window = Ultraviolet.GetPlatform().Windows.GetPrimary();
            var x      = (window.DrawableSize.Width - textBlock.Width.Value) / 2;
            var y      = (window.DrawableSize.Height - textBlock.Height.Value) / 2;

            textBlock.Draw(time, spriteBatch, new Vector2(x, y), Color.White);

            spriteBatch.End();

            base.OnDrawing(time);
        }
コード例 #4
0
        /// <summary>
        /// Called when the scene is being rendered.
        /// </summary>
        /// <param name="time">Time elapsed since the last call to Draw.</param>
        protected override void OnDrawing(UltravioletTime time)
        {
            spriteBatch.Begin();

            //player sprite draw
            spriteBatch.DrawSprite(this.playerObj.animations[this.playerObj.animationIndex], this.playerObj.position);

            //if a bullet is being fired, draw it
            if (firingBullet)
            {
                spriteBatch.DrawSprite(this.firedBullet.animations[this.firedBullet.animationIndex], this.firedBullet.position);
            }

            textFormatter.Reset();
            textFormatter.AddArgument(Ultraviolet.GetGraphics().FrameRate);
            textFormatter.AddArgument(GC.GetTotalMemory(false) / 1024);
            textFormatter.AddArgument(Environment.Is64BitProcess ? "64-bit" : "32-bit");
            textFormatter.Format("{0:decimals:2} FPS\nAllocated: {1:decimals:2} kb\n{2}", textBuffer);

            spriteBatch.DrawString(spriteFont, textBuffer, Vector2.One * 8f, TwistedLogik.Ultraviolet.Color.White);

            var size     = Ultraviolet.GetPlatform().Windows.GetCurrent().ClientSize;
            var settings = new TextLayoutSettings(spriteFont, size.Width, size.Height, TextFlags.AlignCenter | TextFlags.AlignMiddle);

            textRenderer.Draw(spriteBatch, "Welcome to the |c:FFFF00C0|Ultraviolet Framework|c|!", Vector2.Zero, TwistedLogik.Ultraviolet.Color.White, settings);

            //physicsTestObject.DrawObject(spriteBatch, true, textRenderer, settings);
            groundTestObject.DrawObject(spriteBatch, true, textRenderer, settings);

            spriteBatch.End();

            base.OnDrawing(time);
        }
コード例 #5
0
        /// <inheritdoc/>
        public override void DrawAndSwap(UltravioletTime time,
                                         Action <UltravioletContext, UltravioletTime, IUltravioletWindow> onWindowDrawing,
                                         Action <UltravioletContext, UltravioletTime, IUltravioletWindow> onWindowDrawn)
        {
            var graphics = (OpenGLUltravioletGraphics)Ultraviolet.GetGraphics();
            var platform = Ultraviolet.GetPlatform();

            var glenv     = graphics.OpenGLEnvironment;
            var glcontext = graphics.OpenGLContext;

            foreach (var window in platform.Windows)
            {
                glenv.DesignateCurrentWindow(window, glcontext);

                window.Compositor.BeginFrame();
                window.Compositor.BeginContext(CompositionContext.Scene);

                onWindowDrawing?.Invoke(Ultraviolet, time, window);

                glenv.DrawFramebuffer(time);

                onWindowDrawn?.Invoke(Ultraviolet, time, window);

                window.Compositor.Compose();
                window.Compositor.Present();

                glenv.SwapFramebuffers();
            }

            glenv.DesignateCurrentWindow(null, glcontext);

            graphics.SetRenderTargetToBackBuffer();
            graphics.UpdateFrameCount();
        }
コード例 #6
0
        /// <summary>
        /// Loads the screen's panel definition from the specified asset.
        /// </summary>
        /// <param name="asset">The name of the asset that contains the panel definition.</param>
        /// <returns>The panel definition that was loaded from the specified asset.</returns>
        protected virtual WatchedAsset <UIPanelDefinition> LoadPanelDefinition(String asset)
        {
            if (String.IsNullOrEmpty(asset))
            {
                return(null);
            }

            var display = Window?.Display ?? Ultraviolet.GetPlatform().Displays.PrimaryDisplay;
            var density = display.DensityBucket;

            Scale = display.DensityScale;

            var watch = Ultraviolet.GetUI().WatchingViewFilesForChanges;

            if (watch)
            {
                var definition = new WatchedAsset <UIPanelDefinition>(LocalContent, asset, density, OnValidatingUIPanelDefinition, OnReloadingUIPanelDefinition);
                return(definition);
            }
            else
            {
                var definition = LocalContent.Load <UIPanelDefinition>(asset, density);
                return(new WatchedAsset <UIPanelDefinition>(LocalContent, definition));
            }
        }
コード例 #7
0
        protected override void OnDrawing(UltravioletTime time)
        {
            var window = Ultraviolet.GetPlatform().Windows.GetPrimary();
            var width  = window.DrawableSize.Width;
            var height = window.DrawableSize.Height;

            spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend);

            var instruction = Ultraviolet.Platform == UltravioletPlatform.Android || Ultraviolet.Platform == UltravioletPlatform.iOS ?
                              "|c:FFFFFF00|Tap the screen|c| to activate one of the sound effect players." :
                              "Press the |c:FFFFFF00|1-8 number keys|c| to activate one of the sound effect players.";
            var attribution =
                instruction + "\n\n" +
                "\"|c:FFFFFF00|grenade.wav|c|\" by ljudman (http://freesound.org/people/ljudman)\n" +
                "Licensed under Creative Commons: Sampling+\n" +
                "|c:FF808080|http://creativecommons.org/licenses/sampling+/1.0/|c|";

            var settings = new TextLayoutSettings(spriteFont, width, height, TextFlags.AlignMiddle | TextFlags.AlignCenter);

            textRenderer.CalculateLayout(attribution, textLayoutCommands, settings);
            textRenderer.Draw(spriteBatch, textLayoutCommands, Vector2.Zero, Color.White);

            spriteBatch.End();

            base.OnDrawing(time);
        }
コード例 #8
0
        /// <summary>
        /// Sets the current render target.
        /// </summary>
        private void SetRenderTargetInternal(RenderTarget2D renderTarget,
                                             Color?clearColor = null, Double?clearDepth = null, Int32?clearStencil = null)
        {
            Ultraviolet.ValidateResource(renderTarget);

            var usage = renderTarget?.RenderTargetUsage ?? backBufferRenderTargetUsage;

            if (usage == RenderTargetUsage.PlatformContents)
            {
                usage = Capabilities.SupportsPreservingRenderTargetContentInHardware ?
                        RenderTargetUsage.PreserveContents :
                        RenderTargetUsage.DiscardContents;
            }

            var oglRenderTarget = (OpenGLRenderTarget2D)renderTarget;

            if (oglRenderTarget != this.renderTarget)
            {
                var targetName = gl.DefaultFramebuffer;
                var targetSize = Size2.Zero;

                if (oglRenderTarget != null)
                {
                    oglRenderTarget.ValidateStatus();

                    targetName = oglRenderTarget.OpenGLName;
                    targetSize = renderTarget.Size;
                }
                else
                {
                    var currentWindow = Ultraviolet.GetPlatform().Windows.GetCurrent();
                    if (currentWindow != null)
                    {
                        targetSize = currentWindow.DrawableSize;
                    }
                }

                OpenGLState.BindFramebuffer(targetName);

                if (this.renderTarget != null)
                {
                    this.renderTarget.UnbindWrite();
                }

                this.renderTarget = oglRenderTarget;

                if (this.renderTarget != null)
                {
                    this.renderTarget.BindWrite();
                }

                this.viewport = default(Viewport);
                SetViewport(new Viewport(0, 0, targetSize.Width, targetSize.Height));

                if (usage == RenderTargetUsage.DiscardContents)
                {
                    Clear(clearColor ?? Color.FromArgb(0xFF442288), clearDepth ?? 1.0, clearStencil ?? 0);
                }
            }
        }
コード例 #9
0
        /// <summary>
        /// Handles SDL2's MOUSEBUTTONUP event.
        /// </summary>
        private void OnMouseButtonUp(ref SDL_MouseButtonEvent evt)
        {
            if (!Ultraviolet.GetInput().EmulateMouseWithTouchInput&& evt.which == SDL_TOUCH_MOUSEID)
            {
                return;
            }

            var window = Ultraviolet.GetPlatform().Windows.GetByID((int)evt.windowID);
            var button = GetUltravioletButton(evt.button);

            this.states[(int)button].OnUp();

            if (evt.clicks == 1)
            {
                buttonStateClicks |= (uint)SDL_BUTTON(evt.button);
                OnClick(window, button);
            }

            if (evt.clicks == 2)
            {
                buttonStateDoubleClicks |= (uint)SDL_BUTTON(evt.button);
                OnDoubleClick(window, button);
            }

            OnButtonReleased(window, button);
        }
コード例 #10
0
        /// <inheritdoc/>
        protected override void OnLoadingContent()
        {
            var window = Ultraviolet.GetPlatform().Windows.GetPrimary();

            if (!headless)
            {
                // HACK: AMD drivers produce weird rasterization artifacts when rendering
                // to a NPOT render buffer??? So we have to fix it with this stupid hack???
                var width  = MathUtil.FindNextPowerOfTwo(window.DrawableSize.Width);
                var height = MathUtil.FindNextPowerOfTwo(window.DrawableSize.Height);

                rtargetColorBuffer        = Texture2D.CreateRenderBuffer(RenderBufferFormat.Color, width, height);
                rtargetDepthStencilBuffer = Texture2D.CreateRenderBuffer(RenderBufferFormat.Depth24Stencil8, width, height);
                rtarget = RenderTarget2D.Create(width, height);
                rtarget.Attach(rtargetColorBuffer);
                rtarget.Attach(rtargetDepthStencilBuffer);
            }

            if (loader != null)
            {
                content = ContentManager.Create("Content");
                loader(content);
            }

            base.OnLoadingContent();
        }
コード例 #11
0
        private void DrawAlignedText()
        {
            var window = Ultraviolet.GetPlatform().Windows.GetPrimary();
            var width  = window.DrawableSize.Width;
            var height = window.DrawableSize.Height;

            var settingsTopLeft = new TextLayoutSettings(spriteFontSegoe, width, height, TextFlags.AlignTop | TextFlags.AlignLeft);

            textRenderer.Draw(spriteBatch, "Aligned top left", Vector2.Zero, Color.White, settingsTopLeft);

            var settingsTopCenter = new TextLayoutSettings(spriteFontSegoe, width, height, TextFlags.AlignTop | TextFlags.AlignCenter);

            textRenderer.Draw(spriteBatch, "Aligned top center", Vector2.Zero, Color.White, settingsTopCenter);

            var settingsTopRight = new TextLayoutSettings(spriteFontSegoe, width, height, TextFlags.AlignTop | TextFlags.AlignRight);

            textRenderer.Draw(spriteBatch, "Aligned top right", Vector2.Zero, Color.White, settingsTopRight);

            var settingsBottomLeft = new TextLayoutSettings(spriteFontSegoe, width, height, TextFlags.AlignBottom | TextFlags.AlignLeft);

            textRenderer.Draw(spriteBatch, "Aligned bottom left", Vector2.Zero, Color.White, settingsBottomLeft);

            var settingsBottomCenter = new TextLayoutSettings(spriteFontSegoe, width, height, TextFlags.AlignBottom | TextFlags.AlignCenter);

            textRenderer.Draw(spriteBatch, "Aligned bottom center", Vector2.Zero, Color.White, settingsBottomCenter);

            var settingsBottomRight = new TextLayoutSettings(spriteFontSegoe, width, height, TextFlags.AlignBottom | TextFlags.AlignRight);

            textRenderer.Draw(spriteBatch, "Aligned bottom right", Vector2.Zero, Color.White, settingsBottomRight);
        }
コード例 #12
0
        private void DrawColoredAndStyledText()
        {
            var window = Ultraviolet.GetPlatform().Windows.GetPrimary();
            var width  = window.DrawableSize.Width;
            var height = window.DrawableSize.Height;

            if (textLayoutCommands.Settings.Width != width || textLayoutCommands.Settings.Height != height)
            {
                const string text =
                    "Ultraviolet Formatting Commands\n" +
                    "\n" +
                    "||c:AARRGGBB| - Changes the color of text.\n" +
                    "|c:FFFF0000|red|c| |c:FFFF8000|orange|c| |c:FFFFFF00|yellow|c| |c:FF00FF00|green|c| |c:FF0000FF|blue|c| |c:FF6F00FF|indigo|c| |c:FFFF00FF|magenta|c|\n" +
                    "\n" +
                    "||font:name| - Changes the current font.\n" +
                    "We can |font:segoe|transition to a completely different font|font| within a single line\n" +
                    "\n" +
                    "||b| and ||i| - Changes the current font style.\n" +
                    "|b|bold|b| |i|italic|i| |b||i|bold italic|i||b|\n" +
                    "\n" +
                    "||style:name| - Changes to a preset style.\n" +
                    "|style:preset1|this is preset1|style| |style:preset2|this is preset2|style|\n" +
                    "\n" +
                    "||icon:name| - Draws an icon in the text.\n" +
                    "[|icon:ok| OK] [|icon:cancel| Cancel]";

                var settings = new TextLayoutSettings(spriteFontGaramond, width, height, TextFlags.AlignMiddle | TextFlags.AlignCenter);
                textRenderer.CalculateLayout(text, textLayoutCommands, settings);
            }

            textRenderer.Draw(spriteBatch, textLayoutCommands, Vector2.Zero, Color.White);
        }
コード例 #13
0
        /// <inheritdoc/>
        public void RegisterImportersAndProcessors(IEnumerable <Assembly> additionalAssemblies)
        {
            Contract.EnsureNot(registered, UltravioletStrings.ContentHandlersAlreadyRegistered);

            var asmUltravioletCore = typeof(UltravioletContext).Assembly;
            var asmUltravioletImpl = Ultraviolet.GetType().Assembly;

            var asmUltravioletPlatform = Ultraviolet.GetPlatform().GetType().Assembly;
            var asmUltravioletContent  = Ultraviolet.GetContent().GetType().Assembly;
            var asmUltravioletGraphics = Ultraviolet.GetGraphics().GetType().Assembly;
            var asmUltravioletAudio    = Ultraviolet.GetAudio().GetType().Assembly;
            var asmUltravioletInput    = Ultraviolet.GetInput().GetType().Assembly;
            var asmUltravioletUI       = Ultraviolet.GetUI().GetType().Assembly;

            var assemblies = new[] {
                asmUltravioletCore,
                asmUltravioletImpl,
                asmUltravioletPlatform,
                asmUltravioletContent,
                asmUltravioletGraphics,
                asmUltravioletAudio,
                asmUltravioletInput,
                asmUltravioletUI
            }.Union(additionalAssemblies ?? Enumerable.Empty <Assembly>()).Where(x => x != null).Distinct();

            foreach (var asm in assemblies)
            {
                importers.RegisterAssembly(asm);
                processors.RegisterAssembly(asm);
            }

            registered = true;
        }
コード例 #14
0
ファイル: Game.cs プロジェクト: Tide-Productions/ProjectSpark
        protected override void OnLoadingContent()
        {
            //TODO: Attach & Detach Window & Apply changes
            var gfx = Ultraviolet.GetGraphics();

            Ultraviolet.GetPlatform().Windows.GetPrimary().Caption = "Project Spark Test";
            Ultraviolet.GetPlatform().Windows.GetPrimary().ClientSize = new Size2(1280, 720);
            camera   = new Camera();
            _content = ContentManager.Create("Content");
            Resources.ContentManager = _content;
            LoadInputBindings();
            Resources.Input = Ultraviolet.GetInput();
            Resources.gfx   = Ultraviolet.GetGraphics();
            tr = new TextRenderer();
            tr.RegisterGlyphShader("shaky", new Shaky());
            tr.RegisterGlyphShader("wavy", new Wavy());
            spriteBatch = SpriteBatch.Create();

            LoadContentManifests();
            base.OnLoadingContent();

            Anonymous = _content.Load <SpriteFont>(GlobalFontID.Anonymous16);
            Rabelo    = _content.Load <SpriteFont>(GlobalFontID.Rabelo16);
            Trebuchet = _content.Load <SpriteFont>(GlobalFontID.TrebuchetMS16);

            States.Push(new MainMenuState());
        }
コード例 #15
0
        /// <inheritdoc/>
        protected override void OnDrawing(UltravioletTime time)
        {
            var fps = Ultraviolet.GetGraphics().FrameRate;

            Array.Copy(fpsHistory, 1, fpsHistory, 0, fpsHistory.Length - 1);
            fpsHistory[fpsHistory.Length - 1] = fps;

            var gfx            = Ultraviolet.GetGraphics();
            var window         = Ultraviolet.GetPlatform().Windows.GetPrimary();
            var drawableWidth  = window.DrawableSize.Width;
            var drawableHeight = window.DrawableSize.Height;
            var aspectRatio    = drawableWidth / (float)drawableHeight;

            spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend);
            for (int i = 0; i < 5000; i++)
            {
                var x = rng.Next(drawableWidth);
                var y = rng.Next(drawableHeight);
                spriteBatch.DrawSprite(sprite[rng.Next(sprite.AnimationCount)].Controller, new Vector2(x, y));
            }
            spriteBatch.End();

            effect.World              = Matrix.CreateRotationY((float)(2.0 * Math.PI * time.TotalTime.TotalSeconds));
            effect.View               = Matrix.CreateLookAt(new Vector3(0, 0, 5), Vector3.Zero, Vector3.Up);
            effect.Projection         = Matrix.CreatePerspectiveFieldOfView((float)Math.PI / 4f, aspectRatio, 1f, 1000f);
            effect.VertexColorEnabled = true;

            foreach (var pass in this.effect.CurrentTechnique.Passes)
            {
                pass.Apply();

                gfx.SetRasterizerState(RasterizerState.CullNone);
                gfx.SetGeometryStream(geometryStream);
                gfx.DrawPrimitives(PrimitiveType.TriangleList, 0, 1);
            }

            strFormatter.Reset();
            strFormatter.AddArgument(fps);
            strFormatter.Format("{0:decimals:2}", strBuffer);

            spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend);

            for (int i = 0; i < fpsHistory.Length; i++)
            {
                var historyFps    = fpsHistory[i];
                var historyWidth  = drawableWidth / fpsHistory.Length;
                var historyHeight = (Int32)(historyFps * 2.0);
                var historyX      = i * historyWidth;
                var historyY      = drawableHeight - historyHeight;
                var historyColor  = historyFps < 55 ? (historyFps < 40 ? Color.Red : Color.Yellow) : Color.Lime;
                spriteBatch.Draw(blankTexture, new RectangleF(historyX, historyY, historyWidth, historyHeight), historyColor * 0.5f);
            }
            spriteBatch.Draw(blankTexture, new RectangleF(0, drawableHeight - 120, drawableWidth, 1), Color.White);
            spriteBatch.DrawString(spriteFont, strBuffer, Vector2.Zero, Color.White);

            spriteBatch.End();

            base.OnDrawing(time);
        }
コード例 #16
0
        /// <inheritdoc/>
        protected override void OnInitialized()
        {
            SetFileSourceFromManifestIfExists("UvStressTest.Content.uvarc");

            Ultraviolet.GetPlatform().Windows.GetPrimary().Caption = "UvStressTest";

            base.OnInitialized();
        }
コード例 #17
0
 /// <summary>
 /// Initializes the application's context after it has been acquired.
 /// </summary>
 partial void InitializeContext()
 {
     orientationDidChangeNotification = UIDevice.Notifications.ObserveOrientationDidChange((sender, args) =>
     {
         var messageData     = Ultraviolet.Messages.CreateMessageData <OrientationChangedMessageData>();
         messageData.Display = Ultraviolet.GetPlatform().Displays[0];
         Ultraviolet.Messages.Publish(UltravioletMessages.OrientationChanged, messageData);
     });
 }
コード例 #18
0
        /// <summary>
        /// Gets a <see cref="WatchedAsset{T}"/> which watches the specified asset. The <see cref="WatchedAsset{T}"/> which is returned
        /// is owned by the content manager and shared between all callers of this method. If the watched asset has not already been
        /// loaded, it will be loaded and added to the content manager's internal cache.
        /// </summary>
        /// <typeparam name="TOutput">The type of object being loaded.</typeparam>
        /// <param name="asset">The identifier of the asset to load.</param>
        /// <returns>The <see cref="WatchedAsset{T}"/> instance which this content manager uses to watch the specified asset.</returns>
        public WatchedAsset <TOutput> GetSharedWatchedAsset <TOutput>(AssetID asset)
        {
            Contract.EnsureNotDisposed(this, Disposed);

            var primaryDisplay        = Ultraviolet.GetPlatform().Displays.PrimaryDisplay;
            var primaryDisplayDensity = primaryDisplay.DensityBucket;

            return(GetSharedWatchedAssetInternal <TOutput>(AssetID.GetAssetPath(asset), primaryDisplayDensity));
        }
コード例 #19
0
        /// <summary>
        /// Converts the composite document to a <see cref="UvssDocument"/> instance appropriate
        /// for the primary display's screen density.
        /// </summary>
        /// <returns>The <see cref="UvssDocument"/> which was created.</returns>
        public UvssDocument ToUvssDocument()
        {
            Contract.EnsureNotDisposed(this, Disposed);

            var primaryDisplay        = Ultraviolet.GetPlatform().Displays.PrimaryDisplay;
            var primaryDisplayDensity = primaryDisplay?.DensityBucket ?? ScreenDensityBucket.Desktop;

            return(ToUvssDocumentInternal(primaryDisplayDensity));
        }
コード例 #20
0
        /// <inheritdoc/>
        public override void Update(IUltravioletWindow window = null)
        {
            var win         = window ?? Ultraviolet.GetPlatform().Windows.GetCurrent() ?? Ultraviolet.GetPlatform().Windows.GetPrimary();
            var aspectRatio = win.DrawableSize.Width / (Single)win.DrawableSize.Height;

            view = Matrix.CreateLookAt(Position, Target, Up);
            proj = Matrix.CreatePerspectiveFieldOfView(FieldOfView, aspectRatio, NearPlaneDistance, FarPlaneDistance);
            Matrix.Multiply(ref view, ref proj, out viewproj);
        }
コード例 #21
0
        /// <summary>
        /// Handles SDL2's KEYUP event.
        /// </summary>
        private void OnKeyUp(ref SDL_KeyboardEvent evt)
        {
            var window = Ultraviolet.GetPlatform().Windows.GetByID((int)evt.windowID);

            states[(int)evt.keysym.scancode].OnUp();

            OnButtonReleased(window, (Scancode)evt.keysym.scancode);
            OnKeyReleased(window, (Key)evt.keysym.keycode);
        }
コード例 #22
0
ファイル: Game.cs プロジェクト: FaustVX/GravityWorld
        public Game()
            : base("FaustVX", "My Test1")
        {
            _gravityThread = new Thread(CalculateGravityField);

            void CalculateGravityField()
            {
                var size   = 8;
                var window = Ultraviolet.GetPlatform().Windows.GetPrimary();

                while (true)
                {
                    if (_ship is Ship ship && _movers?.ToArray() is CelestialBody[] movers && SelectedMover is var selectedMover)
                    {
                        var windowSize   = new Vector2(window.ClientSize.Width, window.ClientSize.Height);
                        var centerWindow = windowSize / 2;

                        var width  = (window.ClientSize.Width / size) + 1;
                        var height = (window.ClientSize.Height / size) + 1;
                        var field  = new (Rectangle rect, Color color)[width, height];
                        var half   = size / 2f;
#if DEBUG
                        var mouse = Ultraviolet.GetInput().GetMouse().Position;
#endif
                        var offset = TotalOffset - centerWindow;

                        for (var x = 0; x < width; x++)
                        {
                            for (var y = 0; y < height; y++)
                            {
                                var position = new Vector2(x * size + half, y * size + half) + offset;

                                var force = Vector2.Zero;
                                for (int i = 0; i < movers.Length; i++)
                                {
                                    var mover = movers[i];
                                    if ((mover.Position - position).LengthSquared() >= mover.CalculateGravityRadiusSquared(1, Globals.MinimumGravityForCalculation))
                                    {
                                        continue;
                                    }
                                    mover.CalculateGravity(position, 1, out _, out var force2);
                                    force += force2;
                                }
                                var magnitude = force.Length();
#if DEBUG
                                var rect = new RectangleF(position.X, position.Y, size, size);
                                if (rect.Contains(mouse.X + offset.X, mouse.Y + offset.Y))
                                {
                                    Ultraviolet.GetPlatform().Windows.GetPrimary().Caption += $" -- pointed gravity: {magnitude:0.00000}m/s/s";
                                }
#endif

                                magnitude *= Globals.G / 2;
                                var color = magnitude <= 1 ? Color.Green.Interpolate(Color.Blue, EasingFunction(magnitude, 3)) : Color.Red.Interpolate(Color.Blue, 1 / (magnitude));

                                field[x, y] = (new Rectangle(x * size, y * size, size, size), color);
コード例 #23
0
        /// <summary>
        /// Gets a <see cref="WatchedAsset{T}"/> which watches the specified asset. The <see cref="WatchedAsset{T}"/> which is returned
        /// is owned by the content manager and shared between all callers of this method. If the watched asset has not already been
        /// loaded, it will be loaded and added to the content manager's internal cache.
        /// </summary>
        /// <typeparam name="TOutput">The type of object being loaded.</typeparam>
        /// <param name="asset">The path to the asset to load.</param>
        /// <returns>The <see cref="WatchedAsset{T}"/> instance which this content manager uses to watch the specified asset.</returns>
        public WatchedAsset <TOutput> GetSharedWatchedAsset <TOutput>(String asset)
        {
            Contract.RequireNotEmpty(asset, nameof(asset));
            Contract.EnsureNotDisposed(this, Disposed);

            var primaryDisplay        = Ultraviolet.GetPlatform().Displays.PrimaryDisplay;
            var primaryDisplayDensity = primaryDisplay.DensityBucket;

            return(GetSharedWatchedAssetInternal <TOutput>(asset, primaryDisplayDensity));
        }
コード例 #24
0
ファイル: ComboBox.cs プロジェクト: hayate891/ultraviolet
        /// <summary>
        /// Updates the value of the <see cref="ActualMaxDropDownHeight"/> property.
        /// </summary>
        private void UpdateActualMaxDropDownHeight()
        {
            var primary = Ultraviolet.GetPlatform().Windows.GetPrimary();
            var actualMaxDropDownHeight = Double.IsNaN(MaxDropDownHeight) ? Display.PixelsToDips(primary.Compositor.Height) / 3.0 : MaxDropDownHeight;

            if (actualMaxDropDownHeight != GetValue <Double>(ActualMaxDropDownHeightProperty))
            {
                SetValue(ActualMaxDropDownHeightPropertyKey, actualMaxDropDownHeight);
            }
        }
コード例 #25
0
        /// <summary>
        /// Gets a value indicating whether the specified asset is registered as a dependency of another asset.
        /// </summary>
        /// <param name="asset">The asset identifier of the main asset to evaluate.</param>
        /// <param name="dependency">The file path of the dependency asset to evaluate.</param>
        /// <returns><see langword="true"/> if <paramref name="dependency"/> is a dependency of <paramref name="asset"/>; otherwise, <see langword="false"/>.</returns>
        public Boolean IsAssetDependencyPath(AssetID asset, String dependency)
        {
            Contract.Ensure <ArgumentException>(asset.IsValid, nameof(asset));
            Contract.Require(dependency, nameof(dependency));
            Contract.EnsureNotDisposed(this, Disposed);

            var primaryDisplay        = Ultraviolet.GetPlatform().Displays.PrimaryDisplay;
            var primaryDisplayDensity = primaryDisplay?.DensityBucket ?? ScreenDensityBucket.Desktop;

            return(IsAssetDependencyPathInternal(AssetID.GetAssetPath(asset), dependency, primaryDisplayDensity));
        }
コード例 #26
0
        /// <summary>
        /// Adds the specified dependency to an asset. If the asset is being watched for changes, then any
        /// changes to the specified dependency will also cause the main asset to be reloaded.
        /// </summary>
        /// <param name="asset">The asset path of the asset for which to add a dependency.</param>
        /// <param name="dependency">The asset path of the dependency to add to the specified asset.</param>
        public void AddAssetDependency(String asset, String dependency)
        {
            Contract.Require(asset, nameof(asset));
            Contract.Require(dependency, nameof(dependency));
            Contract.EnsureNotDisposed(this, Disposed);

            var primaryDisplay        = Ultraviolet.GetPlatform().Displays.PrimaryDisplay;
            var primaryDisplayDensity = primaryDisplay?.DensityBucket ?? ScreenDensityBucket.Desktop;

            AddAssetDependencyInternal(asset, dependency, primaryDisplayDensity);
        }
コード例 #27
0
        /// <inheritdoc/>
        public override void BeginFrame()
        {
            Contract.EnsureNotDisposed(this, Disposed);

            var window   = Ultraviolet.GetPlatform().Windows.GetCurrent();
            var graphics = Ultraviolet.GetGraphics();

            graphics.SetRenderTarget(null);
            graphics.SetViewport(new Viewport(0, 0, window.DrawableSize.Width, window.DrawableSize.Height));
            graphics.Clear(Color.CornflowerBlue, 1.0f, 0);
        }
コード例 #28
0
        protected override void OnDrawing(UltravioletTime time)
        {
            var window = Ultraviolet.GetPlatform().Windows.GetCurrent();
            var input  = Ultraviolet.GetInput();

            if (input.GetKeyboard().IsKeyDown(Key.Backslash))
            {
                window.Position = new Point2(0, 40);
            }
            this.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend);
            _colorList  = new List <Color>();
            cpu._Halted = false;
            cpu.Loop();
            for (int y = 0; y < _height; y++)
            {
                for (int yScale = 0; yScale < _scale; yScale++)
                {
                    for (int x = 0; x < _width; x++)
                    {
                        for (int xScale = 0; xScale < _scale; xScale++)
                        {
                            switch (cpu._PPU._frameData[y, x])
                            {
                            case 0:
                                _colorList.Add(_white);
                                break;

                            case 1:
                                _colorList.Add(_dark);
                                break;

                            case 2:
                                _colorList.Add(_light);
                                break;

                            case 3:
                                _colorList.Add(_black);
                                break;
                            }
                        }
                    }
                }
            }
            _canvas.Clear(_black);
            _canvas.SetData(_colorList.ToArray());
            _canvas.Flip(SurfaceFlipDirection.Vertical);
            _frameBuffer.SetData(_canvas);
            this.spriteBatch.Flush();
            this.spriteBatch.Draw(_frameBuffer, new Vector2(0, 0), null, Color.White, 0f, new Vector2(0, 0), 1, SpriteEffects.None, 0f);
            this.spriteBatch.End();

            _canvas.Clear(_black);
            base.OnDrawing(time);
        }
コード例 #29
0
        /// <summary>
        /// Adds the specified dependency to an asset. If the asset is being watched for changes, then any
        /// changes to the specified dependency will also cause the main asset to be reloaded.
        /// </summary>
        /// <param name="asset">The asset identifier of the asset for which to add a dependency.</param>
        /// <param name="dependency">The asset identifier of the dependency to add to the specified asset.</param>
        public void AddAssetDependency(AssetID asset, AssetID dependency)
        {
            Contract.Ensure <ArgumentException>(asset.IsValid, nameof(asset));
            Contract.Ensure <ArgumentException>(dependency.IsValid, nameof(dependency));
            Contract.EnsureNotDisposed(this, Disposed);

            var primaryDisplay        = Ultraviolet.GetPlatform().Displays.PrimaryDisplay;
            var primaryDisplayDensity = primaryDisplay?.DensityBucket ?? ScreenDensityBucket.Desktop;

            AddAssetDependencyInternal(AssetID.GetAssetPath(asset), AssetID.GetAssetPath(dependency), primaryDisplayDensity);
        }
コード例 #30
0
        /// <summary>
        /// Handles the Drawing event for ultravioletPanel1.
        /// </summary>
        /// <param name="sender">The object that raised the event.</param>
        /// <param name="e">An EventArgs that contains the event data.</param>
        private void ultravioletPanel1_Drawing(Object sender, EventArgs e)
        {
            spriteBatch.Begin();

            var size     = Ultraviolet.GetPlatform().Windows.GetCurrent().Compositor.Size;
            var settings = new TextLayoutSettings(spriteFont, size.Width, size.Height, TextFlags.AlignCenter | TextFlags.AlignMiddle);

            textRenderer.Draw(spriteBatch, "Welcome to the |c:FFFF00C0|Ultraviolet Framework|c|!", Vector2.Zero, Color.White, settings);

            spriteBatch.End();
        }