Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Index: C:/Users/Frank/Desktop/umtsnew/trunk/src/RCT/RCT/UI/MapControl.cs
- ===================================================================
- --- C:/Users/Frank/Desktop/umtsnew/trunk/src/RCT/RCT/UI/MapControl.cs (revision 239)
- +++ C:/Users/Frank/Desktop/umtsnew/trunk/src/RCT/RCT/UI/MapControl.cs (revision 240)
- @@ -22,8 +22,10 @@
- SvgPictureBoxWindow svgWindow;
- Size svgOriginalSize;
- - private static Size generalSvgSize = new Size(2000, 2000);
- + private static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
- + private static Size generalSvgSize = new Size(2000, 2000);
- +
- public MapControl()
- : base() {
- this.svgRenderer = new GdiGraphicsRenderer();
- @@ -85,7 +87,7 @@
- try {
- if (tracksvg.Length > 0) {
- // Load the source
- - this.svgWindow = new SvgPictureBoxWindow(generalSvgSize.Width, generalSvgSize.Height, svgRenderer);
- + this.svgWindow = new SvgPictureBoxWindow(generalSvgSize.Width, generalSvgSize.Height, svgRenderer);
- var doc = svgWindow.CreateEmptySvgDocument();
- doc.LoadXml(Encoding.UTF8.GetString(tracksvg));
- svgWindow.Document = doc;
- @@ -146,41 +148,42 @@
- /// and zoomed in by the scale factor.
- /// </summary>
- private void DrawCentered(CarStatus cs, Graphics gfx, float scale = 2.0f) {
- - gfx.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
- + gfx.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
- var src = GetClippedSrcRect(_map.Project(GetStatusFor(cs).Position, svgOriginalSize), scale);
- - gfx.Clear(Color.Black); // Background filler for the edges
- - gfx.DrawImage(svgRenderer.RasterImage, ClientRectangle, src, GraphicsUnit.Pixel);
- + gfx.Clear(Color.Black); // Background filler for the edges
- + gfx.DrawImage(svgRenderer.RasterImage, ClientRectangle, src, GraphicsUnit.Pixel);
- + DrawInitialMap(gfx, src);
- int r = (int)Math.Round(37 * scale);
- double ratio = this.Width / (double)src.Width;
- - foreach (var carstats in carsOnMap.Keys.OrderBy(x => x.id)) {
- - var drawStatus = GetStatusFor(carstats);
- - if (drawStatus.Position != null) {
- - Point carPos = _map.Project(drawStatus.Position, svgOriginalSize);
- - if (src.Contains(carPos)) {
- - carPos.Offset((int)(-r / 2), (int)(-r / 2));
- + foreach (var carstats in carsOnMap.Keys.OrderBy(x => x.id)) {
- + var drawStatus = GetStatusFor(carstats);
- + if (drawStatus.Position != null) {
- + Point carPos = _map.Project(drawStatus.Position, svgOriginalSize);
- + if (src.Contains(carPos)) {
- + carPos.Offset((int)(-r / 2), (int)(-r / 2));
- Rectangle dst = new Rectangle((int)Math.Round((carPos.X - src.X) * ratio), (int)Math.Round((carPos.Y - src.Y) * ratio), r, r);
- - DrawCar(gfx, carstats, ref dst, scale);
- - }
- - }
- - }
- + DrawCar(gfx, carstats, ref dst, scale);
- + }
- + }
- + }
- - InvalidateRect = this.ClientRectangle;
- - }
- + InvalidateRect = this.ClientRectangle;
- + }
- /// <summary>
- /// Returns a rectangle of the original image that is
- /// centered around pos. The size is dependant on scale.
- /// </summary>
- - private Rectangle GetClippedSrcRect(Point pos, float scale) {
- - int width = (int)Math.Round(svgOriginalSize.Width / scale);
- - int height = (int)Math.Round(svgOriginalSize.Height / scale);
- + private Rectangle GetClippedSrcRect(Point pos, float scale) {
- + int width = (int)Math.Round(svgOriginalSize.Width / scale);
- + int height = (int)Math.Round(svgOriginalSize.Height / scale);
- Rectangle src = new Rectangle(pos.X - (width / 2), pos.Y - (height / 2), width, height);
- return src;
- - }
- + }
- /// <summary>
- /// Returns last known valid status for cs. Either cached,
- @@ -200,10 +203,10 @@
- private void DrawCar(Graphics gfx, CarStatus cs, ref Rectangle dest, double scale = 1.0) {
- Pen blackpen = new Pen(new SolidBrush(Color.Black), 1);
- using (SolidBrush sb = new SolidBrush(cs.Car.Color)) {
- - gfx.DrawEllipse(new Pen(sb, (int)(3 * scale)), dest);
- - dest.Inflate((int)(2 * scale - 1), (int)(2 * scale - 1));
- + gfx.DrawEllipse(new Pen(sb, (int)(3 * scale)), dest);
- + dest.Inflate((int)(2 * scale - 1), (int)(2 * scale - 1));
- gfx.DrawEllipse(blackpen, dest);
- - dest.Inflate((int)(-3 * scale), (int)(-3 * scale));
- + dest.Inflate((int)(-3 * scale), (int)(-3 * scale));
- gfx.DrawEllipse(blackpen, dest);
- var quad = GetCarAsQuad(dest, cs.Angle, scale);
- @@ -213,7 +216,7 @@
- string speedLabel = cs.CurrentStatus.StreamStatus != StreamStatus.Valid
- ? "?" : cs.Speed.ToString();
- - dest.Inflate((int)(10 * scale), (int)(22 * scale));
- + dest.Inflate((int)(10 * scale), (int)(22 * scale));
- var f = new Font(RCT.UI.RCTPrivateFontCollection.DS_DIGI, (int)(8 + 8 * scale), FontStyle.Bold);
- var p = new PointF(dest.X, dest.Y);
- var r = new RectangleF(p, gfx.MeasureString(speedLabel, f));
- @@ -298,12 +301,18 @@
- public void RefreshBaseImage() {
- lock (this) {
- if (Width > 0 && Height > 0) {
- - BaseImage = svgRenderer.RasterImage.Clone() as Bitmap;
- -
- + Bitmap svgImage = svgRenderer.RasterImage.Clone() as Bitmap;
- + if (BaseImage != null && BaseImage.Size != this.Size) {
- + BaseImage.Dispose();
- + BaseImage = null;
- + }
- + if (BaseImage == null)
- + BaseImage = new Bitmap(this.Width, this.Height);
- lock (BaseImage) {
- using (Graphics gfx = Graphics.FromImage(BaseImage)) {
- - gfx.DrawImage(BaseImage, ClientRectangle, new Rectangle(new Point(0, 0), BaseImage.Size), GraphicsUnit.Pixel);
- - DrawInitialMap(gfx);
- + var rt = new Rectangle(0, 0, svgImage.Width, svgImage.Height);
- + gfx.DrawImage(svgImage, ClientRectangle, rt, GraphicsUnit.Pixel);
- + DrawInitialMap(gfx, rt);
- }
- if (bm != null) bm.Dispose();
- bm = BaseImage.Clone() as Bitmap;
- @@ -316,30 +325,41 @@
- /// Draws initial map with finish lines, sector lines and pitline
- /// </summary>
- /// <param name="gfx"></param>
- - private void DrawInitialMap(Graphics gfx) {
- + private void DrawInitialMap(Graphics gfx, Rectangle srcRect) {
- gfx.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
- Pen thickRedPen = new Pen(new SolidBrush(Color.Red), 2);
- Pen thickBluePen = new Pen(new SolidBrush(Color.Blue), 2);
- +
- + double ratio = this.Width / (double)srcRect.Width;
- +
- + // Finish
- PositionVector finishline = _map.FinishLine;
- - Point point1 = _map.Project(finishline.Pos1, this.Size);
- - Point point2 = _map.Project(finishline.Pos2, this.Size);
- + Point point1 = OffsetPoint(_map.Project(finishline.Pos1, svgOriginalSize), ratio, srcRect);
- + Point point2 = OffsetPoint(_map.Project(finishline.Pos2, svgOriginalSize), ratio, srcRect);
- gfx.DrawLine(thickRedPen, point1, point2);
- + // Sectors
- List<PositionVector> sectors = _map.GetSectors();
- foreach (PositionVector sector in sectors) {
- - Point point3 = _map.Project(sector.Pos1, this.Size);
- - Point point4 = _map.Project(sector.Pos2, this.Size);
- + Point point3 = OffsetPoint(_map.Project(sector.Pos1, svgOriginalSize), ratio, srcRect);
- + Point point4 = OffsetPoint(_map.Project(sector.Pos2, svgOriginalSize), ratio, srcRect);
- gfx.DrawLine(thickRedPen, point3, point4);
- }
- List<PositionVector> pit = _map.GetPit();
- foreach (PositionVector p in pit) {
- - Point point5 = _map.Project(p.Pos1, this.Size);
- - Point point6 = _map.Project(p.Pos2, this.Size);
- + Point point5 = OffsetPoint(_map.Project(p.Pos1, svgOriginalSize), ratio, srcRect);
- + Point point6 = OffsetPoint(_map.Project(p.Pos2, svgOriginalSize), ratio, srcRect);
- gfx.DrawLine(thickBluePen, point5, point6);
- }
- }
- + private Point OffsetPoint(Point point, double ratio, Rectangle rt) {
- + point.X = (int)((point.X - rt.X) * ratio);
- + point.Y = (int)((point.Y - rt.Y) * ratio);
- + return point;
- + }
- +
- protected override void OnPaintBackground(PaintEventArgs pevent) {
- if (_map == null || DoPaintBackground) base.OnPaintBackground(pevent);
- DoPaintBackground = false;
- @@ -364,14 +384,14 @@
- gfx.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
- lock (carsToUpdate) {
- - ClearCarsOnMap(gfx);
- + ClearCarsOnMap(gfx);
- var centerCar = carsToUpdate.FirstOrDefault(x => x.CenterOfMap);
- - if (centerCar != null)
- - DrawCentered(centerCar, gfx);
- - else {
- - DrawCarsOnMap(gfx);
- - }
- + if (centerCar != null)
- + DrawCentered(centerCar, gfx);
- + else {
- + DrawCarsOnMap(gfx);
- + }
- foreach (var cs in carsToUpdate)
- carsOnMap[cs] = GetStatusFor(cs);
- @@ -379,13 +399,15 @@
- carsToUpdate.Clear();
- }
- }
- - Invalidate(InvalidateRect);
- + Invalidate(InvalidateRect);
- }
- Rectangle InvalidateRect; // updated during drawonmap and drawcentered
- #endregion
- - }
- +
- + }
- +
- /// <summary>
- /// Basic Point class with decimal properties.
- /// </summary>
- Index: C:/Users/Frank/Desktop/umtsnew/trunk/src/RCT/RCT/UI/CarControl.cs
- ===================================================================
- --- C:/Users/Frank/Desktop/umtsnew/trunk/src/RCT/RCT/UI/CarControl.cs (revision 239)
- +++ C:/Users/Frank/Desktop/umtsnew/trunk/src/RCT/RCT/UI/CarControl.cs (revision 240)
- @@ -11,6 +11,10 @@
- using RCT.Positional;
- namespace RCT {
- +
- +
- +
- +
- public class CarControl : Control {
- public CarStatus CarStatus { get; private set; }
- private Bitmap bm = null;
- @@ -45,31 +49,35 @@
- }
- CarControl() {
- - /*base.DoubleBuffered = true;
- - this.SetStyle(
- - ControlStyles.UserPaint |
- - ControlStyles.AllPaintingInWmPaint |
- - ControlStyles.OptimizedDoubleBuffer, true);*/
- _streamStatusCheckTimer.Interval = 100;
- _streamStatusCheckTimer.Tick += new EventHandler(_streamStatusCheckTimer_Tick);
- _streamStatusCheckTimer.Enabled = true;
- this.Click += new EventHandler(CarControl_Click);
- + ContextMenu cm = new ContextMenu();
- + cm.MenuItems.Add(new MenuItem("Open centered in new window", new EventHandler(popOutCentered)));
- + this.ContextMenu = cm;
- }
- + private void popOutCentered(object sender, EventArgs args) {
- +
- + }
- +
- private bool expanded = true;
- void CarControl_Click(object sender, EventArgs e) {
- var me = (MouseEventArgs)e;
- - if (me.Y < 40) {
- - // collapse / expand
- - if (expanded) {
- - this.Height = 40;
- - }
- - else {
- - this.Height = 380;
- - }
- - expanded = !expanded;
- - Invalidate();
- - }
- + if (me.Button == System.Windows.Forms.MouseButtons.Left) {
- + if (me.Y < 40) {
- + // collapse / expand
- + if (expanded) {
- + this.Height = 40;
- + }
- + else {
- + this.Height = 380;
- + }
- + expanded = !expanded;
- + Invalidate();
- + }
- + }
- }
- bool doUpdateLapList = false;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement