Пример #1
0
        public override void Draw(CanvasContext2D canv)
        {
            if (!Visible) return;
            string txt = Text;

            if (canv.Font != Font)
                canv.Font = Font;

            //var w = canv.MeasureText(txt).Width;
            //var h = int.Parse(canv.Font.Split("pt")[0]);

            //   canv.fillStyle = "rgba(255,255,255,0.78)";
            // var pad = 3;
            //     canv.fillRect(this.parent.x + this.x - pad, this.parent.y + this.y - h - pad, w + (pad * 2), h + (pad * 2));

            canv.FillStyle = Color;

            canv.FillText(txt, TotalX, TotalY);
        }
Пример #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 Draw(CanvasContext2D canvas)
        {
            canvas.Save();

            foreach (var are in canvasDepths) {
                are.Draw(canvas);
            }

            if (true /*DEBUGs*/) {
                for (var i = 0; i < messages.Count; i++) {
                    canvas.FillText(messages[i], 10, 25 + i * 30);
                }
            }

            canvas.Restore();
        }
Пример #4
0
        public override void Draw(CanvasContext2D canv)
        {
            if (!Visible) return;
            canv.Save();
            if (!Focused) {
                CursorPosition = -1;
                DragPosition = -1;
            }
            DrawTicks++;
            can = canv;

            canv.StrokeStyle = ButtonBorderGrad;
            canv.FillStyle = Clicking ? Button1Grad : Button2Grad;
            canv.LineWidth = 2;
            CHelp.RoundRect(canv, TotalX, TotalY, Width, Height, 2, true, true);
            if (canv.Font != Font)
                canv.Font = Font;

            if (DragPosition != -1) {
                canv.FillStyle = "#598AFF";

                var w1 = canv.MeasureText(Text.Substring(0, Math.Min(DragPosition, CursorPosition))).Width;
                var w2 = canv.MeasureText(Text.Substring(0, Math.Max(DragPosition, CursorPosition))).Width;
                canv.FillRect(TotalX + 8 + w1,
                              TotalY + 3,
                              w2 - w1,
                              ( Height - 7 ));
            }
            canv.FillStyle = "#000000";

            int hc;
            if (canv.Font.IndexOf("pt") != -1)
                hc = int.Parse(canv.Font.Substr(0, canv.Font.IndexOf("pt")));
            else
                hc = int.Parse(canv.Font.Substr(0, canv.Font.IndexOf("px")));
            canv.FillText(Text, TotalX + 8, TotalY + ( ( Height - hc ) / 2 ) + Height / 2);

            if (Focused && ( ( blinkTick++ % 35 ) == 0 ))
                blinked = !blinked;
            if (Focused && blinked) {
                canv.StrokeStyle = "#000000";
                var w = canv.MeasureText(Text.Substring(0, CursorPosition)).Width;
                canv.BeginPath();
                canv.MoveTo(TotalX + 8 + w, TotalY + 3);
                canv.LineTo(TotalX + 8 + w, TotalY + ( Height - 7 ));
                canv.LineWidth = 2;
                canv.Stroke();
            }
            canv.Restore();

            base.Draw(canv);
        }