Example #1
0
        protected override void Draw()
        {
            base.Draw();
            ItemPanel.Sprites["items"].Bitmap?.Dispose();
            int width = Size.Width;

            if (Items.Count * LineSize >= Size.Height)
            {
                width -= ItemContainer.VScrollBar.Size.Width + 2;
            }
            ItemPanel.SetSize(width, Items.Count * LineSize);
            // Chunk size doesn't matter as we're redrawing the entire bitmap anyway
            // Only used to be able to exceed the texture size limit to allow for infinite lists
            ItemPanel.Sprites["items"].Bitmap = new Bitmap(width, Math.Max(1, Items.Count * LineSize), Graphics.MaxTextureSize);
            ItemPanel.Sprites["items"].Bitmap.Unlock();
            ItemPanel.Sprites["items"].Bitmap.Font = Font;
            for (int i = 0; i < Items.Count; i++)
            {
                DrawOptions options = DrawOptions.LeftAlign;
                if (i == SelectedIndex)
                {
                    ItemPanel.Sprites["items"].Bitmap.FillRect(0, i * LineSize, width, LineSize, SelectedBackgroundColor);
                    if (DrawSelectionBold)
                    {
                        options |= DrawOptions.Bold;
                    }
                }
                ItemPanel.Sprites["items"].Bitmap.DrawText(Items[i].ToString(), 3, i * LineSize - 3, i == SelectedIndex ? SelectedTextColor : TextColor, options);
            }
            ItemPanel.Sprites["items"].Bitmap.Lock();
            ItemContainer.UpdateAutoScroll();
        }
Example #2
0
        private Image <Bgr, byte> GetVisualRepresentation(VectorOfPoint liquidContour, VectorOfPoint approxLiquidContour,
                                                          VectorOfPoint glassTopContour, VectorOfPoint approxGlassTopContour,
                                                          Point topLiquidPoint1, Point topLiquidPoint2,
                                                          DrawOptions drawOptions = DrawOptions.TopContour | DrawOptions.TopApproxContour |
                                                          DrawOptions.LiquidContour | DrawOptions.ApproxLiquidContour)
        {
            Size imgSize          = new Size(_img.Width, _img.Height);
            Image <Bgr, byte> img = new Image <Bgr, byte>(imgSize);

            Point[] points;

            if (_glassTopContour.Size != 0)
            {
                Point topPoint1 = new Point(topLiquidPoint1.X, glassTopContour.ToArray()[0].Y);
                Point topPoint2 = new Point(topLiquidPoint2.X, glassTopContour.ToArray()[1].Y);

                points = new Point[] { topPoint2, topLiquidPoint2,
                                       topLiquidPoint1, topPoint1 };
                img.DrawPolyline(points, true, new Bgr(Color.DarkMagenta), 1);
            }

            points = liquidContour.ToArray();
            img.DrawPolyline(points, true, new Bgr(Color.Aqua), 2);

            points = approxLiquidContour.ToArray();
            img.DrawPolyline(points, true, new Bgr(Color.DeepPink), 4);

            points = glassTopContour.ToArray();
            img.DrawPolyline(points, true, new Bgr(Color.YellowGreen), 5);

            points = approxGlassTopContour.ToArray();
            img.DrawPolyline(points, true, new Bgr(Color.OrangeRed), 5);

            return(img);
        }
Example #3
0
        private static void SetFgDrawOptions(DrawOptions DrawOpts, OptionsForm options)
        {
            options.chkMap.Checked = (DrawOpts & DrawOptions.DrawMap) != DrawOptions.None;

            options.chkAddjust.Checked = (DrawOpts & DrawOptions.Readjust) != DrawOptions.None;

            options.chkPlayer.Checked = (DrawOpts & DrawOptions.Player) != DrawOptions.None;

            options.chkLineToPoint.Checked = (DrawOpts & DrawOptions.SpotLine) != DrawOptions.None;

            options.chkSpawns.Checked = (DrawOpts & DrawOptions.Spawns) != DrawOptions.None;

            options.chkTrails.Checked = (DrawOpts & DrawOptions.SpawnTrails) != DrawOptions.None;

            options.chkGround.Checked = (DrawOpts & DrawOptions.GroundItems) != DrawOptions.None;

            options.chkTimers.Checked = (DrawOpts & DrawOptions.SpawnTimers) != DrawOptions.None;

            options.chkDirection.Checked = (DrawOpts & DrawOptions.DirectionLines) != DrawOptions.None;

            options.chkHighlight.Checked = (DrawOpts & DrawOptions.SpawnRings) != DrawOptions.None;

            options.chkGrid.Checked = (DrawOpts & DrawOptions.GridLines) != DrawOptions.None;

            options.chkText.Checked = (DrawOpts & DrawOptions.ZoneText) != DrawOptions.None;
        }
Example #4
0
 public void SetDrawOptions(DrawOptions DrawOptions = odl.DrawOptions.LeftAlign)
 {
     if (this.DrawOptions != DrawOptions)
     {
         this.DrawOptions = DrawOptions;
         RedrawText();
     }
 }
Example #5
0
 public virtual void SetText(string Text, DrawOptions DrawOptions = odl.DrawOptions.LeftAlign)
 {
     if (this.Text != Text)
     {
         this.Text        = Text;
         this.DrawOptions = DrawOptions;
         RedrawText();
     }
 }
        private void UpdateView(bool force, ICollection <IDataItem> items)
        {
            var options = new DrawOptions(this.View.ControlSize, this.state.FitToScreenByX, this.state.FitToScreenByY, items);

            if (force || this.state.FitToScreenAlways || this.state.FitToScreenByX || this.state.FitToScreenByY)
            {
                this.View.RefreshView(options);
            }
        }
Example #7
0
 /// <summary>
 /// Constructor of ally unit.
 /// </summary>
 /// <param name="position"></param>
 /// <param name="roundspersecond"></param>
 /// <param name="size"></param>
 /// <param name="color"></param>
 public Unit(LoB game, DrawOptions drawoptions, float roundspersecond)
 {
     Game            = game;
     DrawOptions     = drawoptions;
     History         = new List <Vector2>();
     RoundsPerSecond = roundspersecond;
     CoolDownTimer   = 0;
     Faction         = Faction.Ally;
 }
Example #8
0
 /// <summary>
 /// Constructor of enemy unit.
 /// </summary>
 /// <param name="position"></param>
 /// <param name="roundspersecond"></param>
 /// <param name="size"></param>
 /// <param name="color"></param>
 /// <param name="motionrule"></param>
 public Unit(LoB game, DrawOptions drawoptions, float roundspersecond, Func <Vector2, Vector2> motionrule)
 {
     Game            = game;
     DrawOptions     = drawoptions;
     History         = new List <Vector2>();
     RoundsPerSecond = roundspersecond;
     CoolDownTimer   = 0;
     MotionRule      = motionrule;
     Faction         = Faction.Enemy;
 }
Example #9
0
        public void ApplyOptions(DrawOptions drawOptions)
        {
            if (drawOptions.EqualsTo(_drawOptions))
            {
                return;
            }

            _currentMesh.Flush(_currentTexture, shader, _matrix, layer, renderQueue);
            _drawOptions.CopyFrom(drawOptions);
        }
Example #10
0
        public void Shoot()
        {
            switch (Faction)
            {
            case Faction.Ally:
                if (Mouse.Any && CoolDownTimer <= 0)
                {
                    var cursor      = Mouse.Position;
                    var posL        = DrawOptions.Position;
                    var posR        = Game.Allies.Units.First().DrawOptions.Position;
                    var posLR       = (posL + posR) / 2;
                    var pos         = Mouse.Left ? (Mouse.Right ? posLR : posL) : (Mouse.Right ? posR : throw new InvalidOperationException());
                    var direction   = (cursor - pos).Versor();
                    var velocity    = 5 * direction;  // TODO: 速度の係数をフィールドまたはプロパティにする。
                    var drawoptions = new DrawOptions(DrawOptions.Position, 5, new RawColor4(0, 1, 1, 1));
                    Game.AlliesShells.Add(new Shell(drawoptions, velocity));

                    CoolDownTimer += 1.0f / RoundsPerSecond;
                }
                else
                {
                    CoolDownTimer -= 1.0f / 60.0f;
                    CoolDownTimer  = (CoolDownTimer < 0) ? 0 : CoolDownTimer;
                }

                break;

            case Faction.Enemy:
                if (CoolDownTimer <= 0)
                {
                    Vector2 radtovector2(double rad)
                    {
                        return(new Vector2((float)Math.Cos(rad), (float)Math.Sin(rad)));
                    };

                    var theta       = 2 * Math.PI * Game.Rand.NextDouble();
                    var direction   = radtovector2(theta).Versor();
                    var velocity    = 5 * direction;  // TODO: 速度の係数をフィールドまたはプロパティにする。
                    var drawoptions = new DrawOptions(DrawOptions.Position, 5, new RawColor4(1, 0.5f, 0, 1));
                    Game.EnemiesShells.Add(new Shell(drawoptions, velocity));

                    CoolDownTimer += 1.0f / RoundsPerSecond;
                }
                else
                {
                    CoolDownTimer -= 1.0f / 60.0f;
                    CoolDownTimer  = (CoolDownTimer < 0) ? 0 : CoolDownTimer;
                }

                break;

            case Faction.Neutral:
                break;
            }
        }
Example #11
0
 private void SpawnEnemy(LoB lob)
 {
     if (lob.FrameCount % 100 == 0)
     {
         var randomPosition = new Vector2(lob.Width * (float)lob.Rand.NextDouble(), lob.Height * (float)lob.Rand.NextDouble());
         var drawOptions    = new DrawOptions(randomPosition, 5, new RawColor4(1, 0, 0, 1));
         var theta          = 2 * Math.PI * lob.Rand.NextDouble();
         Func <Vector2, Vector2> motionRule = pos => pos + new Vector2((float)Math.Cos(theta), (float)Math.Sin(theta));
         lob.Enemies.Add(new Unit(lob, drawOptions, 1, motionRule));
     }
 }
Example #12
0
        public void Render(DrawOptions options, bool recording = false)
        {
            using (new GLEnableCap(EnableCap.Texture2D))
            {
                UpdateBuffers();
                GL.BlendFunc(
                    BlendingFactorSrc.SrcAlpha,
                    BlendingFactorDest.OneMinusSrcAlpha);
                GameDrawingMatrix.Enter();
                _physvbo.Scale     = options.Zoom;
                _physvbo.KnobState = options.KnobState;

                _sceneryvbo.Scale = options.Zoom;
                //green lines dont get lifelock
                if (options.KnobState != KnobState.Hidden)
                {
                    _sceneryvbo.KnobState = KnobState.Shown;
                }
                else
                {
                    _sceneryvbo.KnobState = KnobState.Hidden;
                }

                if ((Settings.PreviewMode || recording) && !(recording && !Settings.Recording.EnableColorTriggers))
                {
                    _sceneryvbo.OverrideColor = game.Track.Timeline.GetFrameLineColor(game.Track.Offset);
                    _physvbo.OverrideColor    = game.Track.Timeline.GetFrameLineColor(game.Track.Offset);
                }
                else
                {
                    _sceneryvbo.OverrideColor = (Settings.NightMode ? Constants.DefaultNightLineColor : Constants.DefaultLineColor);
                    _physvbo.OverrideColor    = (Settings.NightMode ? Constants.DefaultNightLineColor : Constants.DefaultLineColor);
                }

                if (options.LineColors)
                {
                    _sceneryvbo.OverrideColor    = Constants.SceneryLineColor;
                    _sceneryvbo.OverridePriority = 1;
                    _physvbo.OverridePriority    = 1;
                }
                else
                {
                    _sceneryvbo.OverridePriority = 255;//force override
                    _physvbo.OverridePriority    = 255;
                }
                _physvbo.Overlay    = options.Overlay;
                _sceneryvbo.Overlay = options.Overlay;
                _sceneryvbo.Draw();
                _decorator.DrawUnder(options);
                _physvbo.Draw();
                GameDrawingMatrix.Exit();
            }
        }
Example #13
0
 public void DrawUnder(DrawOptions options)
 {
     if (options.LineColors)
     {
         _lineaccelrenderer.Draw(options);
         _linecolorrenderer.Draw(options);
     }
     if (options.GravityWells)
     {
         _wellrenderer.Draw(options);
     }
 }
Example #14
0
        public void MergeWith(DrawOptions x)
        {
            if (blendState == null)
            {
                blendState = x.blendState;
            }

            if (shader == null)
            {
                shader = x.shader;
            }
        }
Example #15
0
        public void Render(DrawOptions options)
        {
            using (new GLEnableCap(EnableCap.Texture2D))
            {
                UpdateBuffers();
                GL.BlendFunc(
                    BlendingFactorSrc.SrcAlpha,
                    BlendingFactorDest.OneMinusSrcAlpha);
                GameDrawingMatrix.Enter();
                _physvbo.Scale     = options.Zoom;
                _physvbo.KnobState = options.KnobState;

                _sceneryvbo.Scale = options.Zoom;
                //green lines dont get lifelock
                if (options.KnobState != KnobState.Hidden)
                {
                    _sceneryvbo.KnobState = KnobState.Shown;
                }
                else
                {
                    _sceneryvbo.KnobState = KnobState.Hidden;
                }

                if (options.NightMode)
                {
                    _sceneryvbo.OverrideColor = Constants.DefaultNightLineColor;
                    _physvbo.OverrideColor    = Constants.DefaultNightLineColor;
                }
                else
                {
                    _sceneryvbo.OverrideColor = Constants.DefaultLineColor;
                    _physvbo.OverrideColor    = Constants.DefaultLineColor;
                }
                if (options.LineColors)
                {
                    _sceneryvbo.OverrideColor    = Constants.SceneryLineColor;
                    _sceneryvbo.OverridePriority = 1;
                    _physvbo.OverridePriority    = 1;
                }
                else
                {
                    _sceneryvbo.OverridePriority = 255;//force override
                    _physvbo.OverridePriority    = 255;
                }
                _physvbo.Overlay    = options.Overlay;
                _sceneryvbo.Overlay = options.Overlay;
                _sceneryvbo.Draw();
                _decorator.DrawUnder(options);
                _physvbo.Draw();
                GameDrawingMatrix.Exit();
            }
        }
Example #16
0
        /// <summary>
        /// Returns the size the given string would take up when rendered.
        /// </summary>
        /// <param name="Char">The string to find the size of.</param>
        /// <param name="DrawOptions">Additional options for drawing the string.</param>
        public Size TextSize(string Text, DrawOptions DrawOptions = 0)
        {
            if (Text.Length == 1)
            {
                return(TextSize(Convert.ToChar(Text), DrawOptions));
            }
            IntPtr SDL_Font = this.SDL_Font;

            TTF_SetFontStyle(SDL_Font, Convert.ToInt32(DrawOptions));
            int w, h;

            TTF_SizeText(SDL_Font, Text, out w, out h);
            return(new Size(w, h));
        }
 public void Draw(DrawOptions draw)
 {
     using (new GLEnableCap(EnableCap.Blend))
     {
         _vbo.Bind();
         GL.EnableClientState(ArrayCap.VertexArray);
         GL.EnableClientState(ArrayCap.ColorArray);
         GL.VertexPointer(2, VertexPointerType.Float, GenericVertex.Size, 0);
         GL.ColorPointer(4, ColorPointerType.UnsignedByte, GenericVertex.Size, 8);
         GL.DrawArrays(PrimitiveType.Triangles, 0, _vertexcounter);
         GL.DisableClientState(ArrayCap.ColorArray);
         GL.DisableClientState(ArrayCap.VertexArray);
         _vbo.Unbind();
     }
 }
Example #18
0
        /// <summary>
        /// Returns the size the given character would take up when rendered.
        /// </summary>
        /// <param name="Char">The character to find the size of.</param>
        /// <param name="DrawOptions">Additional options for drawing the character.</param>
        public Size TextSize(char Char, DrawOptions DrawOptions = 0)
        {
            if (Char == ' ')
            {
                Size total   = TextSize("a a", DrawOptions);
                Size nospace = TextSize("aa", DrawOptions);
                return(new Size(total.Width - nospace.Width, total.Height - nospace.Height));
            }
            IntPtr SDL_Font = this.SDL_Font;

            TTF_SetFontStyle(SDL_Font, Convert.ToInt32(DrawOptions));
            int minx, maxx, miny, maxy, adv;

            TTF_GlyphMetrics(SDL_Font, Char, out minx, out maxx, out miny, out maxy, out adv);
            return(new Size(adv, TTF_FontHeight(SDL_Font)));
        }
Example #19
0
 public void resize()
 {
     if (isCongruent())
     {
         int width  = glControl_.Width;
         int height = glControl_.Height;
         projection_ = Matrix4.CreateOrthographic(width, height, DrawOptions.zNear, DrawOptions.zFar);
         // Update drawing constants
         DrawOptions.update(glControl_.Width, glControl_.Height);
         // Coordinate system position
         coordinateSystemOrigin_.X        *= (float)width / prevControlWidth_;
         coordinateSystemOrigin_.Y        *= (float)height / prevControlHeight_;
         coordinateSystemScaleTranslation_ = Matrix4.CreateScale(DrawOptions.defaultScale, DrawOptions.defaultScale, 1.0f) * Matrix4.CreateTranslation(coordinateSystemOrigin_);
         prevControlWidth_  = glControl_.Width;
         prevControlHeight_ = glControl_.Height;
     }
 }
Example #20
0
        private void CreateTextImage(string text, DrawOptions drawOptions, string fileName)
        {
            using (var fileStream = new System.IO.FileStream(fileName, FileMode.Create))
            {
                var size = _graphics.MeasureString(text, drawOptions.Font).ToSize();
                size = new Size(size.Width + (drawOptions.PaddingHorizontal * 2), size.Height + (drawOptions.PaddingVertical * 2));
                Bitmap bmp = new Bitmap(size.Width, size.Height);

                using (Graphics g = Graphics.FromImage(bmp))
                {
                    g.FillRectangle(drawOptions.BackBrush, new Rectangle(0, 0, size.Width, size.Height));
                    g.DrawString(text, drawOptions.Font, drawOptions.ForeBrush, drawOptions.PaddingHorizontal, drawOptions.PaddingVertical);
                }

                bmp.Save(fileStream, System.Drawing.Imaging.ImageFormat.Jpeg);
                bmp.Dispose();
            }
        }
Example #21
0
        public void Draw(DrawOptions draw)
        {
            _accelbuffer.Bind();

            GL.EnableClientState(ArrayCap.VertexArray);
            GL.EnableClientState(ArrayCap.ColorArray);
            GL.VertexPointer(2, VertexPointerType.Float, GenericVertex.Size, 0);
            GL.ColorPointer(4, ColorPointerType.UnsignedByte, GenericVertex.Size, 8);

            _accelibo.Bind();
            GL.DrawElements(PrimitiveType.Triangles, _indices.Count, DrawElementsType.UnsignedInt, 0);
            _accelibo.Unbind();

            GL.DisableClientState(ArrayCap.ColorArray);
            GL.DisableClientState(ArrayCap.VertexArray);

            _accelbuffer.Unbind();
        }
Example #22
0
        private void button2_Click(object sender, EventArgs e)
        {
            var showStatus  = !ModifierKeys.HasFlag(Keys.Shift);
            var drawOptions = new DrawOptions
            {
                Font              = new Font(comboBoxFonts.SelectedItem.ToString(), (float)numericUpDownFontSize.Value),
                ForeBrush         = new SolidBrush(buttonColorFore.BackColor),
                BackBrush         = new SolidBrush(buttonColorBack.BackColor),
                PaddingHorizontal = (int)numericUpDownPaddingHorizontal.Value,
                PaddingVertical   = (int)numericUpDownPaddingVertical.Value
            };

            int count = CreateTextImages(textBoxLines.Text, drawOptions);

            if (showStatus)
            {
                var msg = $"{count} file(s) written to:{Environment.NewLine}{Environment.NewLine}  {textBoxOutput.Text}";
                MessageBox.Show(msg, this.Text);
            }
        }
 string CorrectDrawOptions(double val, DrawOptions drawOptions)
 {
     if (drawOptions == null)
     {
         return("");
     }
     if (val < 1)
     {
         drawOptions.Color = Color.FromArgb(0xFF, 0x51, 0x89, 0x03);
         return("Green");
     }
     else if (val < 2)
     {
         drawOptions.Color = Color.FromArgb(0xFF, 0xF9, 0xAA, 0x0F);
         return("Yellow");
     }
     else
     {
         drawOptions.Color = Color.FromArgb(0xFF, 0xC7, 0x39, 0x0C);
         return("Red");
     }
 }
Example #24
0
        /// <summary>
        /// Draw the current state of the <c>OcTree</c> structure.
        /// </summary>
        /// <param name="option">Options used to draw.</param>
        /// <param name="modelEffect">Effect to apply to the models.</param>
        /// <param name="boxEffect">Effect to apply to the bounding boxes.</param>
        public void Draw(DrawOptions option, Effect modelEffect, BasicEffect boxEffect, bool checkFrustum = true)
        {
            switch (option)
            {
            case DrawOptions.Models:
                DrawModels(CameraManager.ActiveCamera.View, CameraManager.ActiveCamera.Projection,
                           new BoundingFrustum(CameraManager.ActiveCamera.View * CameraManager.ActiveCamera.Projection), modelEffect, checkFrustum);
                break;

            case DrawOptions.Boxes:
                DrawBoxes(CameraManager.ActiveCamera.View, CameraManager.ActiveCamera.Projection,
                          new BoundingFrustum(CameraManager.ActiveCamera.View * CameraManager.ActiveCamera.Projection), boxEffect, checkFrustum);
                break;

            case DrawOptions.Both:
                DrawModels(CameraManager.ActiveCamera.View, CameraManager.ActiveCamera.Projection,
                           new BoundingFrustum(CameraManager.ActiveCamera.View * CameraManager.ActiveCamera.Projection), modelEffect, checkFrustum);
                DrawBoxes(CameraManager.ActiveCamera.View, CameraManager.ActiveCamera.Projection,
                          new BoundingFrustum(CameraManager.ActiveCamera.View * CameraManager.ActiveCamera.Projection), boxEffect, checkFrustum);
                break;
            }
        }
Example #25
0
        private int CreateTextImages(string lines, DrawOptions drawOptions)
        {
            System.IO.Directory.CreateDirectory(textBoxOutput.Text);

            var arrayLines = lines.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
            var headLen    = lines.Count().ToString().Length;
            var headFmt    = $"D{headLen}";

            var fileLen = (255 - (textBoxOutput.Text.Length + 1)) - 4 /*extension*/ - (headLen + 1);

            int index;

            for (index = 0; index < arrayLines.Length; index++)
            {
                var line = arrayLines[index];
                var name = (line.Length > fileLen ? line.Substring(0, fileLen) : line).Replace("\\", "").Replace("/", "");
                var file = System.IO.Path.Combine(textBoxOutput.Text, $"{(index + 1).ToString(headFmt)}.{name}.jpg");

                CreateTextImage(line, drawOptions, file);
            }
            return(index);
        }
 public void DrawText(string text, FormatOptions formatOptions, Matrix transform, DrawOptions drawOptions)
 {
     DrawText(FormatText(text, formatOptions), transform, drawOptions);
 }
Example #27
0
        protected override async Task LoadContent()
        {
            await base.LoadContent();

            var vertices = new Vertex[4];

            vertices[0] = new Vertex {
                Position = new Vector3(-1, -1, 0.5f), TexCoords = new Vector2(0, 0)
            };
            vertices[1] = new Vertex {
                Position = new Vector3(-1, 1, 0.5f), TexCoords = new Vector2(3, 0)
            };
            vertices[2] = new Vertex {
                Position = new Vector3(1, 1, 0.5f), TexCoords = new Vector2(3, 3)
            };
            vertices[3] = new Vertex {
                Position = new Vector3(1, -1, 0.5f), TexCoords = new Vector2(0, 3)
            };

            var indices = new short[] { 0, 1, 2, 0, 2, 3 };

            var vertexBuffer = Buffer.Vertex.New(GraphicsDevice, vertices, GraphicsResourceUsage.Default);
            var indexBuffer  = Buffer.Index.New(GraphicsDevice, indices, GraphicsResourceUsage.Default);
            var meshDraw     = new MeshDraw
            {
                DrawCount     = 4,
                PrimitiveType = PrimitiveType.TriangleList,
                VertexBuffers = new[]
                {
                    new VertexBufferBinding(vertexBuffer,
                                            new VertexDeclaration(VertexElement.Position <Vector3>(),
                                                                  VertexElement.TextureCoordinate <Vector2>()),
                                            4)
                },
                IndexBuffer = new IndexBufferBinding(indexBuffer, false, indices.Length),
            };

            var mesh = new Mesh
            {
                Draw = meshDraw,
            };

            simpleEffect             = new Effect(GraphicsDevice, SpriteEffect.Bytecode);
            parameterCollection      = new ParameterCollection();
            parameterCollectionGroup = new EffectParameterCollectionGroup(GraphicsDevice, simpleEffect, new[] { parameterCollection });
            parameterCollection.Set(TexturingKeys.Texture0, UVTexture);

            vao = VertexArrayObject.New(GraphicsDevice, mesh.Draw.IndexBuffer, mesh.Draw.VertexBuffers);

            myDraws    = new DrawOptions[3];
            myDraws[0] = new DrawOptions {
                Sampler = GraphicsDevice.SamplerStates.LinearClamp, Transform = Matrix.Multiply(Matrix.Scaling(0.4f), Matrix.Translation(-0.5f, 0.5f, 0f))
            };
            myDraws[1] = new DrawOptions {
                Sampler = GraphicsDevice.SamplerStates.LinearWrap, Transform = Matrix.Multiply(Matrix.Scaling(0.4f), Matrix.Translation(0.5f, 0.5f, 0f))
            };
            myDraws[2] = new DrawOptions {
                Sampler = SamplerState.New(GraphicsDevice, new SamplerStateDescription(TextureFilter.Linear, TextureAddressMode.Mirror)), Transform = Matrix.Multiply(Matrix.Scaling(0.4f), Matrix.Translation(0.5f, -0.5f, 0f))
            };
            //var borderDescription = new SamplerStateDescription(TextureFilter.Linear, TextureAddressMode.Border) { BorderColor = Color.Purple };
            //var border = SamplerState.New(GraphicsDevice, borderDescription);
            //myDraws[3] = new DrawOptions { Sampler = border, Transform = Matrix.Multiply(Matrix.Scale(0.3f), Matrix.Translation(-0.5f, -0.5f, 0f)) };
        }
        public void DrawText(IFormattedText formattedText, Matrix transform, DrawOptions drawOptions)
        {
            if (!(formattedText is FormattedText))
            {
                throw new ArgumentException("Argument formattedText is not an object returned by FormatText() method.");
            }

            PInvokes.D3d9.BeginPixEvent(0, "DrawText: " + formattedText.Text);

            var typedFormattedText = (FormattedText)formattedText;
            if ((typedFormattedText.RichTextFormat || typedFormattedText.m_lines.Length > 1 || typedFormattedText.FormatOptions.Alignment != Alignment.LeftTop)
                && (drawOptions.SubstringStart != 0 || drawOptions.SubstringLength != -1 || drawOptions.BaseIndex != 0))
            {
                throw new InvalidOperationException("Drawing substring can only be performed on non-RTF text.");
            }

            var globalOffset = Vector2.Zero;
            globalOffset.X = typedFormattedText.Offset.X + drawOptions.Offset.X;
            globalOffset.Y = typedFormattedText.Offset.Y + drawOptions.Offset.Y;
            if ((drawOptions.DrawFlags & DrawFlags.OffsetByHalfPixel) != 0)
            {
                globalOffset += new Vector2(-0.5f, -0.5f);
            }

            List<PositionedGlyphPage> glyphPages = new List<PositionedGlyphPage>();
            foreach (var line in typedFormattedText.m_lines)
            {
                for (int i = 0; i < (drawOptions.SubstringLength == -1 ? line.m_glyphs.Length : drawOptions.SubstringLength); ++i)
                {
                    var glyph = line.m_glyphs[i + drawOptions.SubstringStart];

                    if (IsWhitespaceChar(glyph.m_glyph))
                    {
                        continue;
                    }

                    var glyphData = Load(glyph.m_glyph, typedFormattedText.FormatOptions);
                    var pagesInX = glyphData.m_pageIndices.GetUpperBound(0);
                    var pagesInY = glyphData.m_pageIndices.GetUpperBound(1);

                    for (int x = 0; x <= pagesInX; ++x)
                    {
                        for (int y = 0; y <= pagesInY; ++y)
                        {
                            var glyphPos = glyph.m_pos + line.m_offset + globalOffset;
                            glyphPos.X -= line.m_glyphs[drawOptions.BaseIndex].m_pos.X;
                            glyphPages.Add(new PositionedGlyphPage
                            {
                                m_pos = glyphPos + new Vector2(x * PageSize, y * PageSize),
                                m_color = drawOptions.ForcedColor == Color.Transparent ? glyph.m_color : drawOptions.ForcedColor,
                                m_hasOutline = IsAnsiChar(glyph.m_glyph)
                                               ? formattedText.FormatOptions.AnsiFont.OutlineThickness > 0
                                               : formattedText.FormatOptions.Font.OutlineThickness > 0,
                                m_pageIndex = glyphData.m_pageIndices[x, y]
                            });
                        }
                    }
                }
            }

            Func<PositionedGlyphPage, int> batchCriteria = page => page.m_pageIndex / PagesInOneCacheTexture / 4;
            bool useBoundingBox = (drawOptions.DrawFlags & DrawFlags.BoundedByBox) != 0;
            int counter = 0;

            var device = GameApp.Instance.GraphicsDevice;
            device.Indices = null;
            device.BlendState = BlendState.AlphaBlend;
            device.DepthStencilState = DepthStencilState.None;
            device.RasterizerState = RasterizerState.CullCounterClockwise;
            m_effect.CurrentTechnique = m_techDraw;
            if ((drawOptions.DrawFlags & DrawFlags.TransformToClipSpace) != 0)
            {
                var mtx = Matrix.Identity;
                mtx.M11 = 2.0f / device.Viewport.Width;
                mtx.M22 = -2.0f / device.Viewport.Height;
                mtx.M41 = -1.0f;
                mtx.M42 = 1.0f;
                transform = mtx * transform;
            }
            m_paramWorldViewProj.SetValue(transform);
            m_paramPageSize.SetValue(new Vector2(PageSize, PageSize));
            m_paramPageUVSize.SetValue(new Vector2((float)PageSize / CacheTextureSize, (float)PageSize / CacheTextureSize));
            m_paramTextureSize.SetValue(new Vector2(CacheTextureSize, CacheTextureSize));
            m_paramInvTextureSize.SetValue(new Vector2(1.0f / CacheTextureSize, 1.0f / CacheTextureSize));
            m_paramNumPages.SetValue(new Vector2(PagesInOneRow, RowsInOneCacheTexture));
            m_paramInvNumPages.SetValue(new Vector2(1.0f / PagesInOneRow, 1.0f / RowsInOneCacheTexture));
            var premultipliedColorScaling = drawOptions.ColorScaling;
            premultipliedColorScaling.X *= premultipliedColorScaling.W;
            premultipliedColorScaling.Y *= premultipliedColorScaling.W;
            premultipliedColorScaling.Z *= premultipliedColorScaling.W;
            m_paramColorScaling.SetValue(premultipliedColorScaling);
            var premultipliedOutlineColor = drawOptions.OutlineColor;
            premultipliedOutlineColor.X *= premultipliedOutlineColor.W;
            premultipliedOutlineColor.Y *= premultipliedOutlineColor.W;
            premultipliedOutlineColor.Z *= premultipliedOutlineColor.W;
            m_paramOutlineColor.SetValue(premultipliedOutlineColor);

            var vertices = new VertexDataDraw[glyphPages.Count * 6];

            foreach (var batch in glyphPages.GroupBy(batchCriteria))
            {
                Texture2D texture = m_cacheTextures[batch.Key * 4].m_physicalRTTexture;
                m_paramTexture.SetValue(texture);

                var arrayStart = counter;

                foreach (var glyphPage in batch)
                {
                    float boundedLeft, boundedTop, boundedWidth, boundedHeight;
                    if (useBoundingBox)
                    {
                        boundedLeft = (drawOptions.BoundingBox.Left - glyphPage.m_pos.X) / PageSize;
                        boundedTop = (drawOptions.BoundingBox.Top - glyphPage.m_pos.Y) / PageSize;
                        boundedWidth = (drawOptions.BoundingBox.Right - glyphPage.m_pos.X) / PageSize;
                        boundedHeight = (drawOptions.BoundingBox.Bottom - glyphPage.m_pos.Y) / PageSize;

                        if (boundedLeft >= 1.0f || boundedTop >= 1.0f || boundedWidth <= 0.0f || boundedHeight <= 0.0f)
                        {
                            continue;
                        }
                        boundedLeft = Math.Max(boundedLeft, 0.0f);
                        boundedTop = Math.Max(boundedTop, 0.0f);
                        boundedWidth = Math.Min(boundedWidth, 1.0f);
                        boundedHeight = Math.Min(boundedHeight, 1.0f);
                    }
                    else
                    {
                        boundedLeft = boundedTop = 0;
                        boundedWidth = boundedHeight = 1;
                    }

                    var localPageIndex = glyphPage.m_pageIndex % PagesInOneCacheTexture;
                    var pageX = localPageIndex % PagesInOneRow;
                    var pageY = localPageIndex / PagesInOneRow;
                    int channel = glyphPage.m_pageIndex / PagesInOneCacheTexture % 4;

                    for (int i = 0; i < 6; ++i)
                    {
                        vertices[counter + i].m_leftTopPos.X = glyphPage.m_pos.X;
                        vertices[counter + i].m_leftTopPos.Y = glyphPage.m_pos.Y;
                        vertices[counter + i].m_localPageXY_mask = new Byte4(pageX, pageY, channel, glyphPage.m_hasOutline ? 1 : 0);
                        vertices[counter + i].m_color = glyphPage.m_color;
                    }
                    vertices[counter + 0].m_corner = new Short2N(boundedLeft, boundedTop);
                    vertices[counter + 1].m_corner = vertices[counter + 4].m_corner = new Short2N(boundedWidth, boundedTop);
                    vertices[counter + 2].m_corner = vertices[counter + 3].m_corner = new Short2N(boundedLeft, boundedHeight);
                    vertices[counter + 5].m_corner = new Short2N(boundedWidth, boundedHeight);

                    counter += 6;
                }

                if (counter == 0)
                {
                    break;
                }

                var batchSize = counter - arrayStart;
                var bufferOffset = CopyInstanceVertices(vertices, arrayStart, batchSize);
                device.SetVertexBuffer(m_verticesDraw);

                foreach (var pass in m_techDraw.Passes)
                {
                    pass.Apply();
                    device.DrawPrimitives(PrimitiveType.TriangleList, bufferOffset, counter / 3);
                }
            }

            PInvokes.D3d9.EndPixEvent();
        }
Example #29
0
 /// <summary>
 /// Clear the current draw mode of the specified options.
 /// </summary>
 /// <param name="options">options to be cleared</param>
 public void ClearDrawOptions(DrawOptions options)
 {
     drawOptions &= ~options;
 }
Example #30
0
 /// <summary>
 /// Set the current draw mode.
 /// </summary>
 /// <param name="options">options to be set</param>
 public void SetDrawOptions(DrawOptions options)
 {
     drawOptions |= options;
 }
Example #31
0
 public override void DrawGlyph(char c, int X, int Y, Color color, DrawOptions DrawOptions = DrawOptions.LeftAlign)
 {
     throw new MethodNotSupportedException(this);
 }
Example #32
0
        protected override async Task LoadContent()
        {
            await base.LoadContent();

            var vertices = new Vertex[4];
            vertices[0] = new Vertex { Position = new Vector3(-1, -1, 0.5f), TexCoords = new Vector2(0, 0) };
            vertices[1] = new Vertex { Position = new Vector3(-1, 1, 0.5f), TexCoords = new Vector2(3, 0) };
            vertices[2] = new Vertex { Position = new Vector3(1, 1, 0.5f), TexCoords = new Vector2(3, 3) };
            vertices[3] = new Vertex { Position = new Vector3(1, -1, 0.5f), TexCoords = new Vector2(0, 3) };

            var indices = new short[] { 0, 1, 2, 0, 2, 3 };

            var vertexBuffer = Buffer.Vertex.New(GraphicsDevice, vertices, GraphicsResourceUsage.Default);
            var indexBuffer = Buffer.Index.New(GraphicsDevice, indices, GraphicsResourceUsage.Default);
            var meshDraw = new MeshDraw
            {
                DrawCount = 4,
                PrimitiveType = PrimitiveType.TriangleList,
                VertexBuffers = new[]
                {
                    new VertexBufferBinding(vertexBuffer,
                        new VertexDeclaration(VertexElement.Position<Vector3>(),
                            VertexElement.TextureCoordinate<Vector2>()),
                        4)
                },
                IndexBuffer = new IndexBufferBinding(indexBuffer, false, indices.Length),
            };

            var mesh = new Mesh
            {
                Draw = meshDraw,
            };

            simpleEffect = new Effect(GraphicsDevice, SpriteEffect.Bytecode);
            parameterCollection = new ParameterCollection();
            parameterCollectionGroup = new EffectParameterCollectionGroup(GraphicsDevice, simpleEffect, new[] { parameterCollection });
            parameterCollection.Set(TexturingKeys.Texture0, UVTexture);

            vao = VertexArrayObject.New(GraphicsDevice, mesh.Draw.IndexBuffer, mesh.Draw.VertexBuffers);

            myDraws = new DrawOptions[3];
            myDraws[0] = new DrawOptions { Sampler = GraphicsDevice.SamplerStates.LinearClamp, Transform = Matrix.Multiply(Matrix.Scaling(0.4f), Matrix.Translation(-0.5f, 0.5f, 0f)) };
            myDraws[1] = new DrawOptions { Sampler = GraphicsDevice.SamplerStates.LinearWrap, Transform = Matrix.Multiply(Matrix.Scaling(0.4f), Matrix.Translation(0.5f, 0.5f, 0f)) };
            myDraws[2] = new DrawOptions { Sampler = SamplerState.New(GraphicsDevice, new SamplerStateDescription(TextureFilter.Linear, TextureAddressMode.Mirror)), Transform = Matrix.Multiply(Matrix.Scaling(0.4f), Matrix.Translation(0.5f, -0.5f, 0f)) };
            //var borderDescription = new SamplerStateDescription(TextureFilter.Linear, TextureAddressMode.Border) { BorderColor = Color.Purple };
            //var border = SamplerState.New(GraphicsDevice, borderDescription);
            //myDraws[3] = new DrawOptions { Sampler = border, Transform = Matrix.Multiply(Matrix.Scale(0.3f), Matrix.Translation(-0.5f, -0.5f, 0f)) };
        }
Example #33
0
        public void Render(float blend)
        {
            _invalidated = false;
            if (_refreshtrack)
            {
                using (_tracksync.AcquireRead())
                {
                    _renderer.RefreshTrack(_track);
                }
                _refreshtrack = false;
            }
            DrawOptions drawOptions = new DrawOptions();

            drawOptions.DrawFlag = _flag != null;
            if (drawOptions.DrawFlag)
            {
                drawOptions.FlagRider = _flag.State;
            }
            drawOptions.Blend        = blend;
            drawOptions.NightMode    = Settings.NightMode;
            drawOptions.GravityWells = Settings.Local.RenderGravityWells;
            drawOptions.LineColors   = !Settings.Local.PreviewMode && (!Playing || Settings.Local.ColorPlayback);
            drawOptions.KnobState    = KnobState.Hidden;
            if (!Playing && game.SelectedTool is MoveTool movetool)
            {
                drawOptions.KnobState = movetool.CanLifelock
                ? KnobState.LifeLock
                : KnobState.Shown;
            }
            drawOptions.Paused              = Paused;
            drawOptions.PlaybackMode        = PlaybackMode;
            drawOptions.Rider               = RenderRiderInfo.State;
            drawOptions.ShowContactLines    = Settings.Local.DrawContactPoints;
            drawOptions.ShowMomentumVectors = Settings.Local.MomentumVectors;
            drawOptions.Zoom           = Zoom;
            drawOptions.RiderDiagnosis = RenderRiderInfo.Diagnosis;
            int renderframe = Offset;

            if (Playing && Offset > 0 && blend < 1)
            {
                //interpolate between last frame and current one
                var current = Timeline.GetFrame(Offset);
                var prev    = Timeline.GetFrame(Offset - 1);
                drawOptions.Rider = Rider.Lerp(prev, current, blend);
                renderframe       = Offset - 1;
            }
            drawOptions.Iteration = IterationsOffset;
            if (!_loadingTrack)
            {
                var changes = Timeline.RequestFrameForRender(renderframe);
                foreach (var change in changes)
                {
                    GameLine line;
                    if (_track.LineLookup.TryGetValue(change, out line))
                    {
                        _renderer.RedrawLine(line);
                    }
                }
            }

            _renderer.Render(_track, Timeline, Camera, drawOptions);
        }