Ejemplo n.º 1
0
        public override void Draw(DrawData dd)
        {
            //	draw wave data
            byte[] wavedata = dd.Song.WaveformData;

            if (wavedata != null)
            {
#if (MARKERS)
                Markers.WriteFlag("Wave");
#endif

                int fnd = -1;
                for (int ndx = dd.LFT / Global.pxpersec; ndx < (dd.RIT + Global.pxpersec - 1) / Global.pxpersec; ndx++)
                {
                    if (resources.Wave_Bmps[ndx] == null)
                    {
                        fnd = ndx;
                        break;
                    }
                }

                if (fnd == -1)
                {
                    for (int ndx = 0; ndx < resources.Wave_Bmps.Length; ndx++)
                    {
                        if (resources.Wave_Bmps[ndx] == null)
                        {
                            fnd = ndx;
                            break;
                        }
                    }
                }

                if (fnd != -1)
                {
                    var ht   = Global.Wave_Height;
                    var half = ht >> 1;

                    using (var renderT = new SharpDX.Direct2D1.BitmapRenderTarget(dd.target, CompatibleRenderTargetOptions.None, new Size2F(Global.pxpersec, ht),
                                                                                  null, new SharpDX.Direct2D1.PixelFormat(SharpDX.DXGI.Format.B8G8R8A8_UNorm, AlphaMode.Premultiplied)))
                    {
                        renderT.BeginDraw();
                        renderT.Clear(SharpDX.Color.Black);

                        using (var path = new PathGeometry(Global.Instance.factory2D1))
                        {
                            var sink = path.Open();
                            sink.BeginFigure(new Vector2(Global.pxpersec, half + 1), FigureBegin.Hollow);
                            sink.AddLine(new Vector2(0, half + 1));
                            for (int ndx = 0, src = fnd * 2 * Global.pxpersec; ndx < Global.pxpersec && src < wavedata.Length; ndx++, src += 2)
                            {
                                sink.AddLine(new Vector2(ndx, half + 1 + wavedata[src]));
                            }
                            sink.EndFigure(FigureEnd.Open);
                            sink.Close();

                            renderT.DrawGeometry(path, resources.Wave_RedBrush);
                        }

                        using (var path = new PathGeometry(Global.Instance.factory2D1))
                        {
                            var sink = path.Open();
                            sink.BeginFigure(new Vector2(Global.pxpersec, half - 1), FigureBegin.Hollow);
                            sink.AddLine(new Vector2(0, half - 1));
                            for (int ndx = 0, src = fnd * 2 * Global.pxpersec + 1; ndx < Global.pxpersec && src < wavedata.Length; ndx++, src += 2)
                            {
                                sink.AddLine(new Vector2(ndx, half - 1 - wavedata[src]));
                            }
                            sink.EndFigure(FigureEnd.Open);
                            sink.Close();

                            renderT.DrawGeometry(path, resources.Wave_GreenBrush);
                        }

                        renderT.EndDraw();

                        resources.Wave_Bmps[fnd] = renderT.Bitmap;
                    }
                }


                for (int ndx = dd.LFT / Global.pxpersec, bgn = ndx * Global.pxpersec; ndx < resources.Wave_Bmps.Length && bgn <= dd.RIT; ndx++, bgn += Global.pxpersec)
                {
                    var bmp = resources.Wave_Bmps[ndx];
                    if (bmp == null)
                    {
                        break;
                    }

                    dd.target.DrawBitmap(bmp, new RectangleF(bgn, Global.Wave_Channels, Global.pxpersec, Global.Wave_Height), 1.0f, BitmapInterpolationMode.NearestNeighbor,
                                         new RectangleF(0, 0, Global.pxpersec, Global.Wave_Height));
                }

#if (MARKERS)
                Markers.WriteFlag("WaveEnd");
#endif
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Draw the layer.
        /// </summary>
        /// <param name="renderTime">Time since last render.</param>
        /// <remarks>include base.Render(renderTime); in overloads to preserve updating RenderTime field.</remarks>
        public override void Render(RenderTime renderTime)
        {
            base.Render(renderTime);


            if (_lastRender.TotalSeconds > 4)
            {
                _isDirty = true;
            }


            if (_isDirty)
            {
                _target.BeginDraw();
                _target.Clear(new RawColor4(0, 0, 0, 0.95f));
                _target.Transform = Matrix3x2.Translation(-_location);

                // draw borders
                _target.AntialiasMode = AntialiasMode.PerPrimitive;
                _target.FillGeometry(_state.Geometry, Surface.Brushes.GetBrush(new RawColor4(0, 0, 0, .9f)));
                _target.DrawGeometry(_state.Geometry, Surface.Brushes.GetBrush(_state.Color), 1);


                // draw violations
                DrawVisibleViolations();

                // draw crosshair
                DrawCrosshair();

                // Draw lasso
                DrawLasso();

                // draw view rectangle
                DrawViewRectangle();

                // DrawText();

                _target.Transform = Matrix3x2.Identity;
                _target.EndDraw();
                _isDirty    = false;
                _lastRender = TimeSpan.Zero;
            }
            else
            {
                _lastRender += renderTime.ElapsedTime;
            }



            var minimap = _target.Bitmap;

            var tx = Surface.RenderTarget2D.Transform;

            Surface.RenderTarget2D.Transform = Matrix3x2.Identity;
            Surface.RenderTarget2D.DrawBitmap(
                minimap,
                _viewLocation,
                1f,
                BitmapInterpolationMode.Linear);
            Surface.RenderTarget2D.Transform = tx;
        }