예제 #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
        protected override void Update(CanvasContext2D context)
        {
            if (Status != RaceStatus.Fail && Status != RaceStatus.Win)
            {
                context.DrawImage(_timeLeftFrame, 308, 10);

                Type.SetField(context, "textAlign", "right");
                context.FillStyle = "#00AD11";

                if (TimeLeft > 10000 || Math.Floor((TimeLeft / 300) % 2) != 0)
                {
                    if (TimeLeft < 0)
                    {
                        TimeLeft = 0;
                    }
                    context.Font = "110px Digital";
                    context.FillText(Math.Floor(TimeLeft / 1000).ToString(), 475, 105);
                }

                if (Speed > 0)
                {
                    context.Save();
                    context.Scale(-1, 1);
                    long width = Math.Floor((10 * Speed) / MaxSpeed) * 22;
                    if (width > 0)
                    {
                        context.DrawImage(_meterImage, 220 - width, 0, width, 102, -561 - width, 20, width, 102);
                    }
                    context.Restore();
                }

                context.Font = "30px Digital";
                context.FillText(Math.Floor(Speed * 5) + " Km/h", 780, 120);

                int rpmWidth = Math.Floor(_rpm / 500) * 22 + 22;

                context.DrawImage(_meterImage, 220 - rpmWidth, 0, rpmWidth, 102, 240 - rpmWidth, 20, rpmWidth, 102);
                context.FillText(Math.Floor(_rpm) + " RPM", 130, 120);

                context.BeginPath();
                context.LineWidth   = 3;
                context.StrokeStyle = "#00AD11";
                context.MoveTo(5, 150);
                float x = 5 + Math.Min(Position * 735 / RoadLength, 735);
                context.LineTo(x, 150);
                context.Stroke();
                context.ClosePath();

                context.BeginPath();
                context.StrokeStyle = "#006808";
                context.MoveTo(x, 150);
                context.LineTo(790, 150);
                context.Stroke();
                context.ClosePath();
                context.DrawImage(_markerImage, x, 142);
            }

            if (Status == RaceStatus.Running)
            {
                TimeLeft -= DeltaTime;

                if (TimeLeft < 0)
                {
                    _music.Pause();
                    CarSystem.CarObject.CurrentAnimation = "Forward";
                    Status = RaceStatus.Fail;
                    ShowMessage(_failMessage);
                    RemoveSystem(_engineSoundSystem);
                    RemoveSystem(_npcSystem);
                    pendingTimers.Add(Window.SetTimeout(delegate()
                    {
                        UpdateMessage("<p>Press a key to continue.</p>");
                    }, 3000));
                }
            }
        }
예제 #3
0
        public void Paint()
        {
            CanvasContext2D g = (CanvasContext2D)Canvas.GetContext(Rendering.Render2D);

            g.FillStyle = "rgb(20, 22, 31)";
            g.FillRect(0, 0, Width, Height);
            if (!ImagesLoaded)
            {
                return;
            }
            int netHeight = (Height - buffer * 2);
            int netWidth  = (Width - buffer * 2);

            RowCount = Math.Round(Math.Max(netHeight / ThumbHeight, 1));
            ColCount = Math.Round(Math.Max(netWidth / HorzSpacing, 1));

            horzMultiple = ((float)netWidth + 13) / (float)ColCount;

            startIndex = Math.Round((startIndex / ItemsPerPage) * ItemsPerPage);

            Rectangle rectf;
            int       index = startIndex;

            for (int y = 0; y < rowCount; y++)
            {
                for (int x = 0; x < colCount; x++)
                {
                    if (index >= items.Count)
                    {
                        if (items.Count == 0 || showAddButton)
                        {
                            rectf = Rectangle.Create(Left + x * horzMultiple + 3f + startOffset, Top + y * VertSpacing, ThumbWidth - 10, 60);
                            g.DrawImage(thumbnailSize == ThumbnailSize.Big ? bmpBackgroundWide : bmpBackground, (int)((float)x * horzMultiple) + startOffset, y * VertSpacing);


                            //g.FillText(emptyText, rectf.X,rectf,Y, rectf.Width);
                            //g.DrawString(showAddButton ? addText : emptyText, UiTools.StandardRegular, (addButtonHover && showAddButton) ? UiTools.YellowTextBrush : UiTools.StadardTextBrush, rectf, UiTools.StringFormatCenterCenter);
                        }
                        break;
                    }



                    rectf = Rectangle.Create(Left + x * horzMultiple + 3 + startOffset, Top + y * VertSpacing, ThumbWidth - 14, 60);
                    //Brush textBrush = UiTools.StadardTextBrush;
                    string textBrush = "white";

                    if (index == hoverItem || (index == selectedItem && hoverItem == -1))
                    {
                        g.DrawImage(thumbnailSize == ThumbnailSize.Big ? bmpBackgroundWideHover : bmpBackgroundHover, Left + (int)((float)x * horzMultiple) + startOffset, Top + y * VertSpacing);
                        textBrush = "yellow";
                    }
                    else
                    {
                        g.DrawImage(thumbnailSize == ThumbnailSize.Big ? bmpBackgroundWide : bmpBackground, Left + (int)((float)x * horzMultiple) + startOffset, Top + y * VertSpacing);
                    }

                    (items[index]).Bounds = Rectangle.Create((int)(Left + x * horzMultiple) + startOffset, Top + (int)(y * VertSpacing), (int)horzMultiple, (int)VertSpacing);
                    try
                    {
                        ImageElement bmpThumb = items[index].Thumbnail;
                        if (bmpThumb != null)
                        {
                            g.DrawImage(bmpThumb, Left + (int)(x * horzMultiple) + 2 + startOffset, Top + y * VertSpacing + 3);

                            g.StrokeStyle = "rgb(0,0,0)";
                            g.Rect(Left + (int)((float)x * horzMultiple) + 2 + startOffset, Top + y * VertSpacing + 3, items[index].Thumbnail.Width, items[index].Thumbnail.Height);
                        }
                        else
                        {
                            items[index].Thumbnail     = (ImageElement)Document.CreateElement("img");
                            items[index].Thumbnail.Src = items[index].ThumbnailUrl;
                            items[index].Thumbnail.AddEventListener("load", delegate(ElementEvent e) { Refresh(); }, false);
                        }
                    }
                    // TODO FIX this!
                    catch
                    {
                    }

                    //if (((IThumbnail)items[index]).IsImage)
                    //{
                    //    g.DrawImage(Properties.Resources.InsertPictureHS, (int)((float)x * horzMultiple) + 79, y * VertSpacing + 1);
                    //}
                    //if (((IThumbnail)items[index]).IsTour)
                    //{
                    //    g.DrawImage(Properties.Resources.TourIcon, (int)((float)x * horzMultiple) + 79, y * VertSpacing + 1);
                    //}
                    //g.DrawString(((IThumbnail), UiTools.StandardRegular, textBrush, rectf, UiTools.StringFormatThumbnails);
                    g.FillStyle   = textBrush;
                    g.StrokeStyle = textBrush;
                    g.LineWidth   = 1;
                    g.Font        = "normal 8pt Arial";
                    g.FillText(items[index].Name, rectf.X, rectf.Y + rectf.Height, rectf.Width);
                    //g.FillText(items[index].Name, 10, 10);
                    index++;
                }
                if (index >= items.Count)
                {
                    break;
                }
            }
        }
예제 #4
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();
        }