Example #1
0
        protected override void DrawSelf(SpriteBatch sb)
        {
            var innerDimension = GetInnerDimensions();

            if (WithBox)
            {
                Drawing.DrawAdvBox(sb, (int)innerDimension.X, (int)innerDimension.Y,
                                   (int)innerDimension.Width, (int)innerDimension.Height,
                                   _currentColor, BoxTexture, CornerSize);
            }
            else
            {
                if (Texture != null)
                {
                    if (!UseRotation)
                    {
                        sb.Draw(Texture, innerDimension.ToRectangle(), _currentColor);
                    }
                    else
                    {
                        sb.Draw(Texture, innerDimension.Center(), null, _currentColor, Rotation, Texture.Size() * 0.5f, TextureScale, 0, 0);
                    }
                }
            }
            if (ButtonText != "")
            {
                var txtMeasure = Main.fontMouseText.MeasureString(ButtonText);
                Terraria.Utils.DrawBorderStringFourWay(sb, Main.fontMouseText, ButtonText,
                                                       innerDimension.Center().X, innerDimension.Center().Y + 4,
                                                       ButtonTextColor,
                                                       Color.Black, txtMeasure * 0.5f);
            }
            PostDraw?.Invoke(this, sb);
        }
Example #2
0
        /// <inheritdoc />
        public void Draw(TimeSpan total, TimeSpan elapsed, bool isRunningSlowly)
        {
            PreDraw?.Invoke(this, new DrawEventArgs(total, elapsed, isRunningSlowly, Campaign.Renderer));

            InternalDraw(total, elapsed, isRunningSlowly);

            PostDraw?.Invoke(this, new DrawEventArgs(total, elapsed, isRunningSlowly, Campaign.Renderer));
        }
Example #3
0
            /// <summary>
            /// Invokes the Xna PostDraw event.
            /// </summary>
            /// <param name="gameTime"></param>
            public static void InvokePostDraw(GameTime gameTime)
            {
                var args = new XnaDrawEventArgs
                {
                    GameTime = gameTime
                };

                PostDraw.Invoke(args);
            }
Example #4
0
 protected override void DrawSelf(SpriteBatch spriteBatch)
 {
     if (!Visible)
     {
         return;
     }
     this.DrawPanel(spriteBatch, MainTexture, Color);
     PostDraw?.Invoke(this, spriteBatch);
     base.DrawSelf(spriteBatch);
 }
Example #5
0
        /// <inheritdoc />
        public void Draw(TimeSpan total, TimeSpan elapsed, bool isRunningSlowly)
        {
            PreDraw?.Invoke(this, new DrawEventArgs(total, elapsed, isRunningSlowly, UserInterface.Renderer));

            if (Cursor != null)
            {
                UserInterface.Renderer.Draw(Cursor.Texture, lastLocation);
            }

            PostDraw?.Invoke(this, new DrawEventArgs(total, elapsed, isRunningSlowly, UserInterface.Renderer));
        }
Example #6
0
        /// <inheritdoc />
        public void Draw(TimeSpan total, TimeSpan elapsed, bool isRunningSlowly)
        {
            if (!IsVisible)
            {
                return;
            }

            PreDraw?.Invoke(this, new DrawEventArgs(total, elapsed, isRunningSlowly, UserInterface.Renderer));

            UserInterface.Renderer.Draw(background, destination, Background);
            InternalDraw(total, elapsed, isRunningSlowly);

            PostDraw?.Invoke(this, new DrawEventArgs(total, elapsed, isRunningSlowly, UserInterface.Renderer));
        }
Example #7
0
        public virtual void Draw(SpriteBatch spriteBatch, float deltaTime)
        {
            PreDraw?.Invoke(spriteBatch, deltaTime);
            var drawRect = DrawRect;

            switch (shape)
            {
            case Shape.Rectangle:
                if (secondaryColor.HasValue)
                {
                    GUI.DrawRectangle(spriteBatch, drawRect, secondaryColor.Value, isFilled, thickness: 2);
                }
                GUI.DrawRectangle(spriteBatch, drawRect, color, isFilled, thickness: IsSelected ? 3 : 1);
                break;

            case Shape.Circle:
                if (secondaryColor.HasValue)
                {
                    ShapeExtensions.DrawCircle(spriteBatch, DrawPos, size / 2, sides, secondaryColor.Value, thickness: 2);
                }
                ShapeExtensions.DrawCircle(spriteBatch, DrawPos, size / 2, sides, color, thickness: IsSelected ? 3 : 1);
                break;

            case Shape.Cross:
                float halfSize = size / 2;
                if (secondaryColor.HasValue)
                {
                    GUI.DrawLine(spriteBatch, DrawPos + Vector2.UnitY * halfSize, DrawPos - Vector2.UnitY * halfSize, secondaryColor.Value, width: 2);
                    GUI.DrawLine(spriteBatch, DrawPos + Vector2.UnitX * halfSize, DrawPos - Vector2.UnitX * halfSize, secondaryColor.Value, width: 2);
                }
                GUI.DrawLine(spriteBatch, DrawPos + Vector2.UnitY * halfSize, DrawPos - Vector2.UnitY * halfSize, color, width: IsSelected ? 3 : 1);
                GUI.DrawLine(spriteBatch, DrawPos + Vector2.UnitX * halfSize, DrawPos - Vector2.UnitX * halfSize, color, width: IsSelected ? 3 : 1);
                break;

            default: throw new NotImplementedException(shape.ToString());
            }
            if (IsSelected)
            {
                if (showTooltip && !string.IsNullOrEmpty(tooltip))
                {
                    var offset = tooltipOffset ?? new Vector2(size, -size / 2);
                    GUI.DrawString(spriteBatch, DrawPos + offset, tooltip, textColor, textBackgroundColor);
                }
            }
            PostDraw?.Invoke(spriteBatch, deltaTime);
        }
Example #8
0
        /// <inheritdoc />
        public void Draw(TimeSpan total, TimeSpan elapsed, bool isRunningSlowly)
        {
            PreDraw?.Invoke(this, new DrawEventArgs(total, elapsed, isRunningSlowly, Renderer));

            foreach (Dialog dialog in Dialogs)
            {
                dialog.Draw(total, elapsed, isRunningSlowly);
            }

            foreach (Window window in Windows)
            {
                window.Draw(total, elapsed, isRunningSlowly);
            }

            Mouse.Draw(total, elapsed, isRunningSlowly);

            PostDraw?.Invoke(this, new DrawEventArgs(total, elapsed, isRunningSlowly, Renderer));
        }
Example #9
0
 void OnPostDraw()
 {
     PostDraw?.Invoke();
 }
Example #10
0
 protected override void DrawSelf(SpriteBatch spriteBatch)
 {
     this.DrawPanel(spriteBatch, MainTexture, Color);
     PostDraw?.Invoke(this, spriteBatch);
 }
Example #11
0
        //TODO: Investigate passing Render options
        /// <summary>
        /// Sets up windowing and keyboard input
        /// Calls Draw() method in rendering loop
        /// Calls Dispose() when done
        /// </summary>
        public void Run()
        {
            var inputTracker = new InputTracker();

            _contextWindow.Closed += Stop;
            _running = true;
            while (_running)
            {
                _frameTimer.Start();

                InputSnapshot inputSnapshot = _contextWindow.PumpEvents();
                // Somehow we have to check again after PumpEvents()
                if (!_running)
                {
                    break;
                }
                inputTracker.UpdateFrameInput(inputSnapshot);

                var prevFrameTicksInSeconds = _frameTimer.prevFrameTicksInSeconds;
                _camera.Update(_frameTimer.prevFrameTicksInSeconds, inputTracker);

                PreDraw_Time_Camera?.Invoke(prevFrameTicksInSeconds, _camera);
                PreDraw_Time_Input?.Invoke(prevFrameTicksInSeconds, inputSnapshot);
                PreDraw_Time_Camera_Descriptors?.Invoke(
                    prevFrameTicksInSeconds,
                    _camera,
                    PNTTBRuntimeGeometry,
                    PNRuntimeGeometry,
                    PTRuntimeGeometry,
                    PCRuntimeGeometry,
                    PRuntimeGeometry);

                // blocking wait for delegates as they may submit to the command buffer
                _graphicsDevice.WaitForIdle();

                //TODO: split this up into pre and post too!
                buildCommandListTasks[buildCommandListTasks.Length - 1] = Task.Run(() => this.BuildCommandList());
                for (int i = 0; i < buildCommandListTasks.Length - 1; i++)
                {
                    var child = _allChildren[i];
                    buildCommandListTasks[i] = Task.Run(() => child.BuildCommandList());
                }

                // Wait untill every command list has been built
                Task.WaitAll(buildCommandListTasks);


                // Perform draw tasks which should be done before "main" draw e.g. shadow maps
                for (int i = 0; i < _childrenPre.Count; i++)
                {
                    var child = _childrenPre[i];
                    drawTasksPre[i] = Task.Run(() => child.Draw());
                    //TODO: Maybe WaitForIdle
                }

                Task.WaitAll(drawTasksPre);

                Draw();


                PostDraw?.Invoke(prevFrameTicksInSeconds);

                // Perform draw tasks which should be after after "main" draw e.g. UI updates
                for (int i = 0; i < _childrenPost.Count; i++)
                {
                    var child = _childrenPost[i];
                    drawTasksPost[i] = Task.Run(() => child.Draw());
                }

                Task.WaitAll(drawTasksPost);

                if (_renderOptions.LimitFrames)
                {
                    limitFrameRate_Blocking();
                }


                // Wait for submitted UI Tasks
                _graphicsDevice.WaitForIdle();
                _graphicsDevice.SwapBuffers();


                _frameTimer.Stop();
            }

            _contextWindow.Closed -= Stop;
            Dispose();
        }
Example #12
0
 internal static void InvokeOnPostDraw(GameTime gameTime)
 {
     PostDraw?.Invoke(gameTime);
 }