コード例 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="pixelSize"></param>
        /// <param name="height"></param>
        /// <returns></returns>
        public PreviewDrawer CreatePreview(Size pixelSize, int height)
        {
            PreviewDrawer drawer = new PreviewDrawer(pixelSize, size, maxHeight /*middle*/);
            int           mh     = height - 2;
            int           z      = 0;

            for (int i = bottoms.Length - 1; i >= 0; i--)
            {
                drawer.Draw(bottoms[i], 0, 0, z++);
            }
            if (overlay)
            {
                z--;
                mh++;
            }
            for (int i = 0; i < mh; i++)
            {
                drawer.Draw(middle, 0, 0, z++);
            }
            for (int i = tops.Length - 1; i >= 0; i--)
            {
                drawer.Draw(tops[i], 0, 0, z++);
            }

            return(drawer);
        }
コード例 #2
0
        /// <summary>
        /// Builds a nice preview of a train.
        /// </summary>
        public PreviewDrawer CreatePreview(Size pixelSize, int trainlength)
        {
            PreviewDrawer pd = new PreviewDrawer(pixelSize, new Size(1, 3), 0);

            // build up rail like
            //
            //     /~~~~~
            //    /
            for (int x = -10; x < 0; x++)
            {
                pd.Draw(RailPattern.get(Direction.WEST, Direction.EAST), x, 0);
            }
            pd.Draw(RailPattern.get(Direction.WEST, Direction.SOUTHEAST), 0, 0);
            for (int x = 1; x <= 10; x++)
            {
                pd.Draw(RailPattern.get(Direction.NORTHWEST, Direction.SOUTHEAST), x, x);
            }

            TrainCarContribution[] cars = Create(trainlength);

            /*if( cars==null ) {
             *  for( int i=6; cars==null && i<15; i++ )
             *      cars = create(i);
             *  for( int i=4; cars==null && i>0; i-- )
             *      cars = create(i);
             *  if( cars==null )
             *      return pd;	// no preview
             * }*/

            if (cars == null)
            {
                return(pd);                     // no preview
            }
            int[] pos    = new int[] { -2, 0, -1, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5 };
            int[] angle  = new int[] { 12, 12, 13, 14, 14, 14, 14, 14 };
            int[] offset = new int[] { 0, 0, 0, 0, 4, +2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };

            using (DrawContext dc = new DrawContext(pd.Surface))
            {
                for (int i = 7; i >= 0; i--)
                {
                    if (cars.Length <= i)
                    {
                        continue;               // no car
                    }

                    Point pt = pd.GetPoint(pos[i * 2], pos[i * 2 + 1]);
                    cars[i].Draw(pd.Surface,
                                 new Point(pt.X + offset[i * 2], pt.Y + offset[i * 2 + 1] - 9), angle[i]);
                }
            }

            return(pd);
        }
コード例 #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="pixelSize"></param>
        /// <returns></returns>
        public override PreviewDrawer CreatePreview(Size pixelSize)
        {
            PreviewDrawer drawer = new PreviewDrawer(pixelSize, new Size(7, 1), 1);

            drawer.Draw(sprites[currentColor][Direction.WEST, PlaceSide.Fore], 3, 1);
            drawer.Draw(sprites[currentColor][Direction.EAST, PlaceSide.Back], 2, 0);
            if (hilights != null)
            {
                drawer.Draw(hilights[currentHighlight][Direction.WEST, PlaceSide.Fore], 3, 1);
                drawer.Draw(hilights[currentHighlight][Direction.EAST, PlaceSide.Back], 2, 0);
            }
            return(drawer);
        }
コード例 #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="pixelSize"></param>
        /// <returns></returns>
        public override PreviewDrawer CreatePreview(Size pixelSize)
        {
            PreviewDrawer drawer = new PreviewDrawer(pixelSize, new Size(10, 1), 0);

            for (int x = 9; x >= 0; x--)
            {
                if (x == 5)
                {
                    drawer.Draw(sprites[0, 0], x, 0);
                }
                //drawer.draw( RoadPattern.get((byte)Direction.EAST), x,0 );
                if (x == 5)
                {
                    drawer.Draw(sprites[0, 1], x, 0);
                }
            }
            return(drawer);
        }
コード例 #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="pixelSize"></param>
        /// <returns></returns>
        public override PreviewDrawer CreatePreview(Size pixelSize)
        {
            PreviewDrawer drawer = new PreviewDrawer(pixelSize, size, tops.Length + bottoms.Length + 1 /*middle*/);

            int z = 0;

            for (int i = bottoms.Length - 1; i >= 0; i--)
            {
                drawer.Draw(bottoms[i], 0, 0, z++);
            }
            if (overlay)
            {
                drawer.Draw(middle, 0, 0, z - 1);
            }
            drawer.Draw(middle, 0, 0, z++);
            for (int i = tops.Length - 1; i >= 0; i--)
            {
                drawer.Draw(tops[i], 0, 0, z++);
            }

            return(drawer);
        }
コード例 #6
0
        /// <summary>
        /// Creates the preview image of the land builder.
        /// </summary>
        public override PreviewDrawer CreatePreview(Size pixelSize)
        {
            PreviewDrawer drawer = new PreviewDrawer(pixelSize, new Size(10, 10), 0);

            for (int y = 0; y < 10; y++)
            {
                for (int x = 0; x < 10; x++)
                {
                    drawer.Draw(sprite, x, y);
                }
            }

            return(drawer);
        }
コード例 #7
0
        /// <summary>
        /// Creates the preview image of the land builder.
        /// </summary>
        public override PreviewDrawer CreatePreview(Size pixelSize)
        {
            PreviewDrawer drawer = new PreviewDrawer(pixelSize, new Size(3, 3), 0);

            for (int y = 0; y < 3; y++)
            {
                for (int x = 2; x >= 0; x--)
                {
                    drawer.Draw(sprites[GetSpriteIndex(x, y, 0, 2, 0, 2)], x, y);
                }
            }

            return(drawer);
        }
コード例 #8
0
 /// <summary>
 ///
 /// </summary>
 public override void UpdatePreview()
 {
     using (PreviewDrawer drawer = new PreviewDrawer(preview.Size, new Size(3, 3), 0))
     {
         for (int x = 0; x < 3; x++)
         {
             for (int y = 0; y < 3; y++)
             {
                 drawer.Draw(LandPropertyVoxel.sprite, x, y);
             }
         }
         if (preview.Image != null)
         {
             preview.Image.Dispose();
         }
         preview.Image = drawer.CreateBitmap();
     }
 }
コード例 #9
0
ファイル: ControllerForm.cs プロジェクト: wcp16/FreeTrainSDL
        /// <summary>
        /// Called when a selection of the structure has changed.
        /// </summary>
        protected virtual void UpdatePreview(DummyCarContribution builder)
        {
            //DummyCarContribution builder = (DummyCarContribution)typeBox.SelectedItem;
            using (PreviewDrawer drawer = new PreviewDrawer(preview.Size, new Size(10, 1), 0))
            {
                drawer.Draw(builder.GetSprites(), 5, 0);

                if (previewBitmap != null)
                {
                    previewBitmap.Dispose();
                }
                preview.Image = previewBitmap = drawer.CreateBitmap();
            }
            //if (isPlacing)
            //currentController = builder.createBuilder(this.siteImpl);
            //else
            //currentController = builder.createRemover(this.siteImpl);
        }
コード例 #10
0
        /// <summary> This should be called by the IInspectorDrawer of the inspector during every OnGUI event. </summary>
        /// <param name="inspectorDimensions"> The position and bounds for where the inspecto should be drawn. </param>
        /// <param name="anyInspectorPartMouseovered"> True if any inspector part is currently mouseovered. </param>
        public override void OnGUI(Rect inspectorDimensions, bool anyInspectorPartMouseovered)
        {
            UnityEngine.Profiling.Profiler.BeginSample("OnGUI");

                        #if DEV_MODE && DEBUG_CLICK
            var ev = Event.current;
            if (ev.rawType == EventType.MouseDown)
            {
                Debug.Log(StringUtils.ToColorizedString(ToString() + " Event=", ev, ", e.type=", ev.type, ", button=", ev.button, ", mousePos=", ev.mousePosition, ", GUIUtility.hotControl=", GUIUtility.hotControl));
            }
                        #endif

                        #if DEV_MODE && PI_ASSERTATIONS
            if (inspectorDimensions.width <= 0f)
            {
                Debug.LogError(GetType().Name + ".OnGUI inspectorDimensions.width <= 0f: " + inspectorDimensions);
            }
                        #endif

            //this can happen e.g. if the preferences file gets reimported due to being altered outside of Unity
            if (Preferences == null)
            {
                Preferences = GetPreferences();
            }

                        #if DEV_MODE && DEBUG_MOUSEOVERED_PART
            if (State.drawer.VisibleMembers.Length > 0 && DrawGUI.IsUnityObjectDrag)
            {
                Debug.Log(StringUtils.ToColorizedString(ToString(), ".OnGUI with mouseoveredPart=", MouseoveredPart, ", Event=" + StringUtils.ToString(Event.current), ", ignoreAllMouseInputs=", InspectorDrawer.Manager.IgnoreAllMouseInputs, "´, ObjectPickerIsOpen=", ObjectPicker.IsOpen, ", anyInspectorPartMouseovered=", anyInspectorPartMouseovered, ", InspectorDrawer.MouseIsOver=", InspectorDrawer.MouseIsOver, ", DrawGUI.CanRequestMousePosition=", Cursor.CanRequestLocalPosition));
            }
                        #endif

            InspectorUtility.BeginInspector(this, ref anyInspectorPartMouseovered);

            Rect toolbarRect;
            Rect viewportRect;
            Rect previewAreaRect;
            GetDrawPositions(inspectorDimensions, out toolbarRect, out viewportRect, out previewAreaRect);

            // trying to fix a bug where the default inspector layout gets wacky if both it and this window are open
            // by making sure all values that could affect it are restored back to normal
            // var indentLevelWas = EditorGUI.indentLevel;
            var labelWidthWas = EditorGUIUtility.labelWidth;
            var matrixWas     = GUI.matrix;

            var currentEvent = Event.current;
            switch (currentEvent.type)
            {
            case EventType.Layout:
                State.nextUpdateCachedValues--;
                if (State.nextUpdateCachedValues <= 0)
                {
                    UpdateCachedValuesFromFields();
                }
                OnCursorPositionOrLayoutChanged();
                break;

            case EventType.MouseMove:
            case EventType.MouseDrag:
            case EventType.DragUpdated:
                if (IgnoreViewportMouseInputs())
                {
                                                #if DEV_MODE
                    //Debug.Log("ignoring "+ currentEvent.type+"...");
                                                #endif
                    break;
                }

                OnCursorPositionOrLayoutChanged();
                InspectorDrawer.RefreshView();
                break;
            }

            bool dirty;
            try
            {
                dirty = DrawViewport(viewportRect);
            }
            catch (Exception e)
            {
                if (ExitGUIUtility.ShouldRethrowException(e))
                {
                    NowDrawingPart              = InspectorPart.None;
                    DrawGUI.IndentLevel         = 0;
                    EditorGUIUtility.labelWidth = labelWidthWas;
                    GUI.skin   = null;
                    GUI.matrix = matrixWas;
                    throw;
                }
                                #if DEV_MODE
                Debug.LogWarning(ToString() + " " + e);
                                #endif

                // Always throw ExitGUI exception if exceptions were caught to avoid GUI Layout warnings.
                ExitGUIUtility.ExitGUI();
                return;
            }

                        #if !POWER_INSPECTOR_LITE
            NowDrawingPart = InspectorPart.Toolbar;
            {
                Toolbar.Draw(toolbarRect);

                                #if UNITY_2019_3_OR_NEWER
                Color lineColor;
                if (DrawGUI.IsProSkin)
                {
                    lineColor = Preferences.theme.ComponentSeparatorLine;
                }
                else
                {
                    lineColor = new Color32(153, 153, 153, 255);
                }
                var lineRect = toolbarRect;
                lineRect.height = 1f;
                lineRect.y      = toolbarRect.height;
                DrawGUI.DrawLine(lineRect, lineColor);
                                #endif
            }
                        #endif
            NowDrawingPart = InspectorPart.Other;

            try
            {
                if (DrawPreviewArea)
                {
                    NowDrawingPart = InspectorPart.PreviewArea;
                    {
                        previewDrawer.Draw(previewAreaRect);
                    }
                    NowDrawingPart = InspectorPart.Other;
                }
            }
                        #if DEV_MODE
            catch (ArgumentException e)            // GUILayout: Mismatched LayoutGroup.repaint
            {
                Debug.LogError(StringUtils.ToString(Event.current) + " " + e + "\nEvent=" + StringUtils.ToString(Event.current));
                        #else
            catch (ArgumentException)
            {
                        #endif
                // new test to avoid GUI Error: You are pushing more GUIClips than you are popping. Make sure they are balanced.
                NowDrawingPart = InspectorPart.None;
                ExitGUIUtility.ExitGUI();
            }

            //TO DO: Move to EndInspector if these are needed?
            //trying to fix a bug where the default inspector layout gets wacky if both it and this window are open
            //by making sure all values that could affect it are restored back to normal
            DrawGUI.IndentLevel         = 0;
            EditorGUIUtility.labelWidth = labelWidthWas;
            GUI.skin   = null;
            GUI.matrix = matrixWas;

            if (dirty)
            {
                InspectorDrawer.RefreshView();
            }

            InspectorUtility.EndInspector(this);

            UnityEngine.Profiling.Profiler.EndSample();
        }
コード例 #11
0
        public MainForm()
        {
            InitializeComponent();
            Text = appName;
            var display = new MadcaDisplay(new PictureBox()
            {
                Location = new Point(), Size = ClientSize
            });
            var fumen            = new MadcaFumenData();
            var scoreBook        = fumen.ScoreBook;
            var noteBook         = fumen.NoteBook;
            var operationManager = new OperationManager();
            var status           = new EditorStatus(EditorMode.Add, NoteMode.Touch, 8, new TimingPosition(8, 1));

            for (var i = 0; i < 100; ++i)
            {
                scoreBook.AddScoreLast(new Score(4, 4));
            }

            // スクロールバーのための初期設定(ちょっと雑実装?)
            display.VScrollBar.Maximum = (int)(scoreBook.Size.BarRatio * display.EditorLaneEnvironment.TimingUnitHeight);
            display.VScrollBar.Value   = display.VScrollBar.Maximum;

            SetEditorMode(EditorMode.Add, status);
            tsbAdd.Click    += (s, e) => SetEditorMode(EditorMode.Add, status);
            tsbEdit.Click   += (s, e) => SetEditorMode(EditorMode.Edit, status);
            tsbDelete.Click += (s, e) => SetEditorMode(EditorMode.Delete, status);

            tsbUndo.Enabled = tsbRedo.Enabled = false;
            tsbUndo.Checked = tsbRedo.Checked = false;
            tsbUndo.Click  += (s, e) =>
            {
                operationManager.Undo();
                display.PictureBox.Refresh();
            };
            tsbRedo.Click += (s, e) =>
            {
                operationManager.Redo();
                display.PictureBox.Refresh();
            };
            operationManager.UndoStatusChanged += (b) => tsbUndo.Enabled = b;
            operationManager.RedoStatusChanged += (b) => tsbRedo.Enabled = b;

            SetNoteMode(NoteMode.Touch, status);
            tsbTouch.Click    += (s, e) => SetNoteMode(NoteMode.Touch, status);
            tsbChain.Click    += (s, e) => SetNoteMode(NoteMode.Chain, status);
            tsbSlideL.Click   += (s, e) => SetNoteMode(NoteMode.SlideL, status);
            tsbSlideR.Click   += (s, e) => SetNoteMode(NoteMode.SlideR, status);
            tsbSnapU.Click    += (s, e) => SetNoteMode(NoteMode.SnapU, status);
            tsbSnapD.Click    += (s, e) => SetNoteMode(NoteMode.SnapD, status);
            tsbHold.Click     += (s, e) => SetNoteMode(NoteMode.Hold, status);
            tsbHoldStep.Click += (s, e) => SetNoteMode(NoteMode.HoldRelay, status);
            tsbField.Click    += (s, e) => SetNoteMode(NoteMode.Field, status);

            #region ToolStripMenuItemの設定

            tsmiOpen.Click += (s, e) =>
            {
                using (var dialog = new OpenFileDialog()
                {
                    Filter = "MADCA譜面ファイル(*.mdc)|*.mdc",
                    Title = "開く"
                })
                {
                    var result = dialog.ShowDialog();
                    if (result == DialogResult.OK)
                    {
                        string jsonString = default;
                        try
                        {
                            jsonString = File.ReadAllText(dialog.FileName);
                        }
                        catch (Exception)
                        {
                            MessageBox.Show(
                                "譜面ファイルの読み取りに失敗しました。",
                                "エラー",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                            return;
                        }
                        try
                        {
                            var fumenInput = JsonSerializer.Deserialize <JsonObject>(jsonString, new JsonSerializerOptions());
                            if (fumenInput == null)
                            {
                                MessageBox.Show(
                                    "譜面データのデシリアライズに失敗しました。",
                                    "エラー",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                            }
                            else
                            {
                                try
                                {
                                    MyUtil.Normalize(fumenInput);
                                    fumen.Exchange(fumenInput);
                                }
                                catch (Exception)
                                {
                                    MessageBox.Show(
                                        "譜面データの読み込みに失敗しました。",
                                        "エラー",
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Error);
                                }
                            }
                        }
                        catch (Exception)
                        {
                            MessageBox.Show(
                                "譜面データのデシリアライズに失敗しました。",
                                "エラー",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                        }
                    }
                }
            };

            tsmiSaveAs.Click += (s, e) =>
            {
                using (var dialog = new SaveFileDialog()
                {
                    FileName = "NewScore.mdc",
                    Filter = "MADCA譜面ファイル(*.mdc)|*.mdc",
                    Title = "名前を付けて保存"
                })
                {
                    var result = dialog.ShowDialog();
                    if (result == DialogResult.OK)
                    {
                        string jsonString = default;
                        try
                        {
                            jsonString = JsonSerializer.Serialize(fumen.Exchange(), new JsonSerializerOptions
                            {
                                WriteIndented = true
                            });
                            try
                            {
                                File.WriteAllText(dialog.FileName, jsonString);
                            }
                            catch (Exception)
                            {
                                MessageBox.Show(
                                    "譜面データの書き込みに失敗しました。",
                                    "エラー",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                            }
                        }
                        catch (Exception)
                        {
                            MessageBox.Show("譜面データのシリアライズに失敗しました。");
                        }
                    }
                }
            };

            #endregion

            #region 分数指定用ComboBoxの設定

            var beatStride = new List <uint>()
            {
                4, 8, 12, 16, 24, 32, 48, 64
            };
            tscbBeat.Items.AddRange(beatStride.Select(x => $"1 / {x}").ToArray());
            tscbBeat.Items.Add("カスタム...");
            tscbBeat.SelectedIndexChanged += (s, e) =>
            {
                if (tscbBeat.SelectedIndex == tscbBeat.Items.Count - 1)
                {
                    using (var dialog = new BeatStrideDialog())
                    {
                        dialog.BeatStrideConfirmed += (_, t) =>
                        {
                            status.BeatStride = t;
                            // 反映されない...(すでに存在するものの場合は反映された)
                            tscbBeat.Text = $"{t.CntValue} / {t.DivValue}";
                        };
                        dialog.ShowDialog();
                    }
                    return;
                }
                if (tscbBeat.SelectedIndex < 0 || tscbBeat.SelectedIndex >= beatStride.Count)
                {
                    return;
                }
                status.BeatStride = new TimingPosition(beatStride[tscbBeat.SelectedIndex], 1);
            };
            tscbBeat.SelectedIndex = 0;

            #endregion

            #region ノーツサイズ設定用UI関連

            var noteSizeUpDown = new NumericUpDown()
            {
                Font    = new Font("Yu Gothic UI", 9),
                Minimum = 1,
                Maximum = MadcaEnv.LaneCount
            };
            noteSizeUpDown.ValueChanged += (s, e) =>
            {
                status.NoteSize = (int)noteSizeUpDown.Value;
                tscbFavoriteNoteSize.SelectedIndex = -1;
                display.PictureBox.Refresh();
            };
            var idx = toolStrip1.Items.IndexOf(tsbAddFavoriteSize);
            toolStrip1.Items.Insert(idx, new ToolStripControlHost(noteSizeUpDown));

            var favoriteSize = new List <int>();
            tsbAddFavoriteSize.Click += (s, e) =>
            {
                var size = (int)noteSizeUpDown.Value;
                if (!favoriteSize.Contains(size))
                {
                    favoriteSize.Add(size);
                    tscbFavoriteNoteSize.Items.Clear();
                    tscbFavoriteNoteSize.Items.AddRange(favoriteSize.OrderBy(n => n).Select(x => x.ToString()).ToArray());
                }
                tscbFavoriteNoteSize.SelectedItem = size.ToString();
            };

            tscbFavoriteNoteSize.SelectedIndexChanged += (s, e) =>
            {
                if (tscbFavoriteNoteSize.SelectedIndex == -1)
                {
                    return;
                }
                var selectedIndex = tscbFavoriteNoteSize.SelectedIndex;
                var item          = tscbFavoriteNoteSize.SelectedItem.ToString();
                noteSizeUpDown.Value = int.Parse(item);
                tscbFavoriteNoteSize.SelectedIndex = selectedIndex;
            };

            tsbDeleteFavoriteSize.Click += (s, e) =>
            {
                if (tscbFavoriteNoteSize.SelectedIndex == -1)
                {
                    return;
                }
                var item = tscbFavoriteNoteSize.SelectedItem.ToString();
                favoriteSize.Remove(int.Parse(item));
                var selectedIndex = tscbFavoriteNoteSize.SelectedIndex;
                tscbFavoriteNoteSize.Items.RemoveAt(tscbFavoriteNoteSize.SelectedIndex);
                tscbFavoriteNoteSize.SelectedIndex = selectedIndex < tscbFavoriteNoteSize.Items.Count ? selectedIndex : tscbFavoriteNoteSize.Items.Count - 1;
            };

            noteSizeUpDown.Value = status.NoteSize;

            #endregion

#if DEBUG
            var time = new Stopwatch();
            display.PictureBox.Paint += (s, e) => time.Restart();
#endif
            display.PictureBox.Paint += (s, e) =>
            {
                e.Graphics.SmoothingMode     = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
                e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
                // まずレーンを描画
                LaneDrawer.Draw(e.Graphics, display.EditorLaneEnvironment, scoreBook.Scores);
                PreviewDrawer.Draw(e.Graphics, display.PreviewDisplayEnvironment, scoreBook.Scores);
                // 次にレーン上にノーツを描画
                NoteDrawer.DrawToLane(e.Graphics, display.EditorLaneEnvironment, noteBook);
                NoteDrawer.DrawToPreview(e.Graphics, display.PreviewDisplayEnvironment, noteBook);
            };

            SizeChanged += (s, e) =>
            {
                display.PictureBox.Size = ClientSize;
            };
            Controls.Add(display.PictureBox);
            MinimumSize = new Size((int)display.EditorLaneEnvironment.SideMargin * 2, 10);

            SetEventToSetCursor(display, noteBook, status);
            SetEventToPutNote(display, noteBook, scoreBook.Scores, operationManager, status);
            SetEventToPutHold(display, noteBook, scoreBook.Scores, operationManager, status);
            SetEventToPutHoldRelay(display, noteBook, scoreBook.Scores, operationManager, status);
            SetEventToReLocateNote(display, noteBook, scoreBook.Scores, operationManager, status);
            SetEventToReSizeNote(display, noteBook, scoreBook.Scores, operationManager, status);
            SetEventToDeleteNote(display, noteBook, operationManager, status);
            SetEventToDrawPreviewNote(display, scoreBook.Scores, status);
            SetEventForRefreshRule(display); // 各種SetEvent関数の最後に置く
#if DEBUG
            display.PictureBox.Paint += (s, e) =>
            {
                time.Stop();
                Console.WriteLine($"Time[ms]: {time.ElapsedMilliseconds}");
            };
#endif
        }
コード例 #12
0
        /// <summary>
        ///
        /// </summary>
        public override void UpdatePreview()
        {
            PreviewDrawer drawer;

            // TODO: locations of the previews are uttely incorrect. fix them

            // direction N
            using (drawer = new PreviewDrawer(pictureN.ClientSize, new Size(2, 4), 0))
            {
                drawer.Draw(RailPattern.getSlope(Direction.NORTH, 3), 1, -1);
                drawer.Draw(RailPattern.getSlope(Direction.NORTH, 2), 1, 0);
                drawer.Draw(RailPattern.getSlope(Direction.NORTH, 1), 0, 2);
                drawer.Draw(RailPattern.getSlope(Direction.NORTH, 0), 0, 3);
                if (pictureN.Image != null)
                {
                    pictureN.Image.Dispose();
                }
                pictureN.Image = drawer.CreateBitmap();
            }

            // direction S
            using (drawer = new PreviewDrawer(pictureS.ClientSize, new Size(2, 4), 0))
            {
                drawer.Draw(RailPattern.getSlope(Direction.SOUTH, 0), 0, 0);
                drawer.Draw(RailPattern.getSlope(Direction.SOUTH, 1), 0, 1);
                drawer.Draw(RailPattern.getSlope(Direction.SOUTH, 2), 1, 1);
                drawer.Draw(RailPattern.getSlope(Direction.SOUTH, 3), 1, 2);
                if (pictureS.Image != null)
                {
                    pictureS.Image.Dispose();
                }
                pictureS.Image = drawer.CreateBitmap();
            }

            // direction E
            using (drawer = new PreviewDrawer(pictureE.ClientSize, new Size(4, 2), 0))
            {
                drawer.Draw(RailPattern.getSlope(Direction.EAST, 3), 3, 0);
                drawer.Draw(RailPattern.getSlope(Direction.EAST, 2), 2, 0);
                drawer.Draw(RailPattern.getSlope(Direction.EAST, 1), 0, 1);
                drawer.Draw(RailPattern.getSlope(Direction.EAST, 0), -1, 1);
                if (pictureE.Image != null)
                {
                    pictureE.Image.Dispose();
                }
                pictureE.Image = drawer.CreateBitmap();
            }

            // direction W
            using (drawer = new PreviewDrawer(pictureW.ClientSize, new Size(4, 2), 0))
            {
                drawer.Draw(RailPattern.getSlope(Direction.WEST, 3), 1, 0);
                drawer.Draw(RailPattern.getSlope(Direction.WEST, 2), 2, 0);
                drawer.Draw(RailPattern.getSlope(Direction.WEST, 1), 2, 1);
                drawer.Draw(RailPattern.getSlope(Direction.WEST, 0), 3, 1);
                if (pictureW.Image != null)
                {
                    pictureW.Image.Dispose();
                }
                pictureW.Image = drawer.CreateBitmap();
            }
        }