예제 #1
0
        public void Draw(RenderContext renderContext, float opacity, Color color)
        {
            if (renderContext.gl == null)
            {
                Vector3d viewPoint = Vector3d.TransformCoordinate(renderContext.ViewPoint, ViewTransform);

                double drawHeight = (Height / renderContext.FovAngle) * renderContext.Height / 180;

                foreach (Text3d t3d in Items)
                {
                    Vector3d screenSpacePnt = renderContext.WVP.Transform(t3d.center);
                    if (screenSpacePnt.Z < 0)
                    {
                        continue;
                    }

                    if (Vector3d.Dot((Vector3d)viewPoint, (Vector3d)t3d.center) < .55)
                    {
                        continue;
                    }

                    Vector3d screenSpaceTop = renderContext.WVP.Transform(t3d.top);

                    double rotation = Math.Atan2(screenSpacePnt.X - screenSpaceTop.X, screenSpacePnt.Y - screenSpaceTop.Y);


                    CanvasContext2D ctx = renderContext.Device;
                    ctx.Save();

                    ctx.Translate(screenSpacePnt.X, screenSpacePnt.Y);
                    ctx.Rotate(-rotation); // todo update with up vector
                    ctx.Alpha        = opacity;
                    ctx.FillStyle    = color.ToString();
                    ctx.Font         = "normal" + " " + (false ? "bold" : "normal") + " " + Math.Round(drawHeight * 1.2).ToString() + "px " + "Arial";
                    ctx.TextBaseline = TextBaseline.Top;

                    TextMetrics tm = ctx.MeasureText(t3d.Text);

                    ctx.FillText(t3d.Text, -tm.Width / 2, -drawHeight / 2);
                    ctx.Restore();
                }
            }
            else
            {
                // gl version
                if (glyphCache == null || glyphCache.Version > glyphVersion)
                {
                    PrepareBatch();
                }
                if (glyphCache.Ready == false)
                {
                    return;
                }


                TextShader.Use(renderContext, vertexBuffer.VertexBuffer, glyphCache.Texture.Texture2d);

                renderContext.gl.drawArrays(GL.TRIANGLES, 0, vertexBuffer.Count);
            }
        }
예제 #2
0
        private void CreateCircleGeometry(RenderContext renderContext)
        {
            CanvasContext2D ctx = renderContext.Device;

            ctx.Save();
            ctx.Scale(1, Width / Height);
            ctx.Translate(X, Y);
            ctx.Rotate(RotationAngle * RC);
            ctx.BeginPath();
            ctx.Arc(0, 0, Width, 0, Math.PI * 2, false);
            ctx.ClosePath();
            ctx.LineWidth = 0;
            ctx.FillStyle = Color.ToString();
            ctx.Alpha     = Opacity;
            ctx.Fill();
            ctx.Restore();
        }
예제 #3
0
        private void CreateStarGeometry(RenderContext renderContext)
        {
            CanvasContext2D ctx = renderContext.Device;

            ctx.Save();
            ctx.Translate(X, Y);
            ctx.Rotate(RotationAngle * RC);
            ctx.BeginPath();

            double centerX = 0;
            double centerY = 0;
            double radius  = Width / 2;

            double radiansPerSegment = ((double)Math.PI * 2) / 5;

            bool first = true;

            for (int i = 0; i < 5; i++)
            {
                double rads = i * radiansPerSegment - (Math.PI / 2);
                if (first)
                {
                    first = false;
                    ctx.MoveTo(centerX + Math.Cos(rads) * (Width / 2), centerY + Math.Sin(rads) * (Height / 2));
                }
                else
                {
                    ctx.LineTo(centerX + Math.Cos(rads) * (Width / 2), centerY + Math.Sin(rads) * (Height / 2));
                }

                double rads2 = i * radiansPerSegment + (radiansPerSegment / 2) - (Math.PI / 2);
                ctx.LineTo(centerX + Math.Cos(rads2) * (Width / 5.3), centerY + Math.Sin(rads2) * (Height / 5.3));
            }

            ctx.ClosePath();
            ctx.LineWidth = 0;
            ctx.FillStyle = Color.ToString();


            ctx.Alpha = Opacity;
            ctx.Fill();
            ctx.Restore();
        }
예제 #4
0
        private void CreateDonutGeometry(RenderContext renderContext)
        {
            //todo move to dashed lines in future
            CanvasContext2D ctx = renderContext.Device;

            ctx.Save();
            ctx.Translate(X, Y);
            ctx.Scale(1, Height / Width);
            ctx.Rotate(RotationAngle * RC);
            ctx.BeginPath();
            ctx.Arc(0, 0, Width / 2, 0, Math.PI * 2, false);

            ctx.ClosePath();
            ctx.LineWidth   = 9;
            ctx.StrokeStyle = Color.ToString();
            ctx.Alpha       = Opacity;
            ctx.Stroke();
            ctx.Restore();
        }
예제 #5
0
        private void CreateLineGeometry(RenderContext renderContext)
        {
            //todo this needs to be Dashed rounded lines..

            CanvasContext2D ctx = renderContext.Device;

            ctx.Save();
            double radius = Width / 2;

            ctx.Translate(X, Y);
            ctx.Rotate(RotationAngle * RC);

            ctx.MoveTo(-radius, 0);
            ctx.LineTo(radius, 0);
            ctx.LineWidth   = 9;
            ctx.StrokeStyle = Color.ToString();
            ctx.Alpha       = Opacity;
            ctx.Stroke();
            ctx.Restore();
        }
예제 #6
0
        private void CreateRectGeometry(RenderContext renderContext)
        {
            CanvasContext2D ctx = renderContext.Device;

            ctx.Save();
            ctx.Translate(X, Y);
            ctx.Rotate(RotationAngle * RC);

            ctx.BeginPath();
            ctx.MoveTo(-Width / 2, -Height / 2);
            ctx.LineTo(Width / 2, -Height / 2);
            ctx.LineTo(Width / 2, +Height / 2);
            ctx.LineTo(-Width / 2, +Height / 2);
            ctx.ClosePath();
            ctx.LineWidth = 0;
            ctx.FillStyle = Color.ToString();

            ctx.Alpha = Opacity;
            ctx.Fill();
            ctx.Restore();
        }
예제 #7
0
        public override void Draw3D(RenderContext renderContext, bool designTime)
        {
            if (texture == null)
            {
                InitializeTexture();
            }

            if (!textureReady)
            {
                return;
            }
            CanvasContext2D ctx = renderContext.Device;

            ctx.Save();

            ctx.Translate(X, Y);
            ctx.Rotate(RotationAngle * RC);
            ctx.Alpha = Opacity;
            ctx.DrawImage(texture, -Width / 2, -Height / 2, Width, Height);
            ctx.Restore();
        }
예제 #8
0
        //public static TextOverlay(Canvas canvas, TextObject textObject)
        //{
        //    this.canvas = canvas;
        //    this.TextObject = textObject;
        //    this.Name = textObject.Text.Split(new char[] { '\r', '\n' })[0];
        //    X = 0;
        //    Y = 0;

        //}


        public override void Draw3D(RenderContext renderContext, bool designTime)
        {
            //TextBlock textBlock = new TextBlock();
            //textBlock.Width = this.Width;
            //textBlock.Height = this.Height;
            //textBlock.Foreground = new SolidColorBrush(TextObject.ForgroundColor);
            //textBlock.Text = TextObject.Text;
            //textBlock.FontWeight = TextObject.Bold ? FontWeights.Bold : FontWeights.Normal;
            //textBlock.FontSize = TextObject.FontSize * 1.2;
            //textBlock.HorizontalAlignment = HorizontalAlignment.Left;
            //TranslateTransform tt = new TranslateTransform();
            //tt.X = this.X - (Width / 2);
            //tt.Y = this.Y - (Height / 2);
            //textBlock.RenderTransform = tt;
            //canvas.Children.Add(textBlock);
            //textBlock.Opacity = this.Opacity;

            CanvasContext2D ctx = renderContext.Device;

            ctx.Save();

            ctx.Translate(X, Y);
            ctx.Rotate(RotationAngle * RC);
            ctx.Alpha        = Opacity;
            ctx.FillStyle    = TextObject.ForgroundColor.ToString();
            ctx.Font         = (TextObject.Italic ? "italic" : "normal") + " " + (TextObject.Bold ? "bold" : "normal") + " " + Math.Round(TextObject.FontSize * 1.2).ToString() + "px " + TextObject.FontName;
            ctx.TextBaseline = TextBaseline.Top;

            String text = TextObject.Text;

            if (text.IndexOf("{$") > -1)
            {
                if (text.IndexOf("{$DATE}") > -1)
                {
                    string date = String.Format("{0:yyyy/MM/dd}", SpaceTimeController.Now);
                    text = text.Replace("{$DATE}", date);
                }

                if (text.IndexOf("{$TIME}") > -1)
                {
                    string time = String.Format("{0:HH:mm:ss}", SpaceTimeController.Now);
                    text = text.Replace("{$TIME}", time);
                }


                //  text = text.Replace("{$DIST}", UiTools.FormatDistance(WWTControl.Singleton.SolarSystemCameraDistance));
                text = text.Replace("{$LAT}", Coordinates.FormatDMS(WWTControl.Singleton.RenderContext.ViewCamera.Lat));
                text = text.Replace("{$LNG}", Coordinates.FormatDMS(WWTControl.Singleton.RenderContext.ViewCamera.Lat));
                text = text.Replace("{$RA}", Coordinates.FormatDMS(WWTControl.Singleton.RenderContext.ViewCamera.RA));
                text = text.Replace("{$DEC}", Coordinates.FormatDMS(WWTControl.Singleton.RenderContext.ViewCamera.Dec));
                text = text.Replace("{$FOV}", Coordinates.FormatDMS(WWTControl.Singleton.RenderContext.FovAngle));
            }



            string[] lines = text.Split("\n");

            double baseline  = -(Height / 2);
            double lineSpace = TextObject.FontSize * 1.7;

            foreach (string line in lines)
            {
                List <string> parts = Util.GetWrappedText(ctx, line, Width);
                foreach (string part in parts)
                {
                    ctx.FillText(part, -Width / 2, baseline);
                    baseline += lineSpace;
                }
            }

            ctx.Restore();
        }