示例#1
0
        public override void Draw(TimeSpan ellapsedTime, ViewPort viewPort)
        {
            var resource = (UIResource)Resource;

            var screenX = (Int32)(resource.X * viewPort.ResolutionX) + (Int32)Properties.XOffset;
            var screenY = (Int32)(resource.Y * viewPort.ResolutionY) + (Int32)Properties.YOffset;
            var screenHeight = (Int32)(Resource.Height * viewPort.ResolutionY) + (Int32)Properties.HeightOffset;
            var screenWidth = (Int32)(Resource.Width * viewPort.ResolutionX) + (Int32)Properties.WidthOffset;

            SpriteResource solid = (SpriteResource)ResourceDictionary.GetResource("Solid");
            var texture = (Texture2D)ResourceDictionary.GetResource(solid.TextureKey);

            this._spriteBatch.Draw(texture, new Rectangle(screenX - 10, screenY + 10, screenWidth - 10, screenHeight),
                                new Rectangle(solid.UCoordinate, solid.VCoordinate, solid.Width, solid.Height),
                                new Color(0f, 0f, 0f, 0.5f));

            var pixelReduction = (Int32)((1f - ((AmmoMeter)Actor).AmmoLevel) * resource.Height * viewPort.ResolutionY);

            SpriteResource ammoMeter = (SpriteResource)ResourceDictionary.GetResource(Resource.SpriteKey);

            this._spriteBatch.Draw(texture, new Rectangle(screenX, screenY + pixelReduction, screenWidth, screenHeight - pixelReduction),
                    new Rectangle(ammoMeter.UCoordinate, ammoMeter.VCoordinate, ammoMeter.Width, ammoMeter.Height),
                    new Color(1f, 1f, 1f, 0.5f));

        }
示例#2
0
 //public PickedGeometry() { }
 /// <summary>
 /// The color-coded picking result.
 /// <para>Representing a primitive(point, line, triangle, quad, polygon).</para>
 /// </summary>
 /// <param name="fromViewPort"></param>
 /// <param name="geometryType"></param>
 /// <param name="positions"></param>
 /// <param name="vertexIds"></param>
 /// <param name="stageVertexId"></param>
 /// <param name="fromRenderer"></param>
 public PickedGeometry(ViewPort fromViewPort, PickingGeometryType geometryType, vec3[] positions, uint[] vertexIds, uint stageVertexId, IPickable fromRenderer)
 {
     this.FromViewPort = fromViewPort;
     this.GeometryType = geometryType;
     this.Positions = positions;
     this.VertexIds = vertexIds;
     this.StageVertexId = stageVertexId;
     this.FromRenderer = fromRenderer;
 }
示例#3
0
 public VisualSubsystem(IActorVisualFactory viewFactory, GraphicsDevice graphics, ViewPort viewPort)
 {
     _lockObject = new Object();
     _actorVisuals = new Dictionary<Int32, List<IActorVisual>>();
     _actorVisualMap = new Dictionary<Actor, IActorVisual>();
     _graphics = graphics;
     _viewFactory = viewFactory;
     _viewPort = viewPort;
 }
        /// <summary>
        /// BitArray tables are fairly confusing.
        /// Each entry is X bits long, where X is the length of a matched enum table. X is rounded up to the nearest 8.
        /// </summary>
        public void CreateBitArrayTable(string tableName, int address, string sourceTable, params int[] encoding)
        {
            var token         = new ModelDelta();
            var sourceAddress = Model.GetAddressFromAnchor(new NoDataChangeDeltaModel(), -1, sourceTable);
            var sourceRun     = (ArrayRun)Model.GetNextRun(sourceAddress);
            var bytesToEncode = (int)Math.Ceiling(sourceRun.ElementCount / 8.0);

            for (int i = 0; i < encoding.Length; i++)
            {
                Model.WriteMultiByteValue(address + i * bytesToEncode, bytesToEncode, token, encoding[i]);
            }

            ViewPort.Goto.Execute(address.ToString("X2"));
            ViewPort.Edit($"^{tableName}[data{BitArray.SharedFormatString}{sourceTable}]{encoding.Length} ");
        }
        public void FindCanFindMultiple()
        {
            var array     = new byte[0x1000];
            var searchFor = new byte[] { 0x84, 0x23, 0xBB, 0x21 };

            searchFor.CopyTo(array, 0x240);
            searchFor.CopyTo(array, 0xA70);
            var port = new ViewPort(new LoadedFile("test", array));

            var results = port.Find("84 23 BB 21").Select(result => result.start).ToList();

            Assert.Equal(2, results.Count);
            Assert.Contains(0x240, results);
            Assert.Contains(0xA70, results);
        }
        public void AddressExtendOnHeightChanged()
        {
            var viewPort = new ViewPort(new LoadedFile("test.txt", new byte[0x200]))
            {
                Width = 0x10, Height = 0x10
            };
            var changeCount = 0;

            viewPort.Headers.CollectionChanged += (sender, e) => changeCount += 1;

            viewPort.Height++;

            Assert.InRange(changeCount, 1, viewPort.Height);
            Assert.Equal(viewPort.Height, viewPort.Headers.Count);
        }
        public void AddressUpdateOnScroll()
        {
            var viewPort = new ViewPort(new LoadedFile("test.txt", new byte[0x200]))
            {
                Width = 0x10, Height = 0x10
            };
            var changeCount = 0;

            viewPort.Headers.CollectionChanged += (sender, e) => changeCount += 1;

            viewPort.ScrollValue++;

            Assert.InRange(changeCount, 1, viewPort.Height);
            Assert.Equal("000020", viewPort.Headers[1]);
        }
        public void EscapeWhileTypingAnchorCancelsChange()
        {
            var buffer   = Enumerable.Repeat((byte)0xFF, 0x200).ToArray();
            var model    = new PokemonModel(buffer);
            var viewPort = new ViewPort("file.txt", model)
            {
                Width = 0x10, Height = 0x10
            };

            viewPort.Edit("^bob"); // no trailing space: still under edit
            viewPort.Edit(ConsoleKey.Escape);

            Assert.IsType <None>(viewPort[0, 0].Format);
            Assert.Equal(NoInfoRun.NullRun, model.GetNextRun(0));
        }
        public void CanUsePointerAsLink()
        {
            var buffer   = new byte[0x200];
            var model    = new PokemonModel(buffer);
            var viewPort = new ViewPort("file.txt", model)
            {
                Width = 0x10, Height = 0x10
            };

            viewPort.SelectionStart = new Point(4, 1);
            viewPort.Edit("<000120>");
            viewPort.FollowLink(4, 1);

            Assert.Equal("000120", viewPort.Headers[0]);
        }
        public void AnchorCarriesSourceInformation()
        {
            var buffer   = new byte[0x100];
            var model    = new PokemonModel(buffer);
            var viewPort = new ViewPort("file.txt", model)
            {
                Width = 0x10, Height = 0x10
            };

            viewPort.SelectionStart = new Point(0, 1);
            viewPort.Edit("<000020>");
            var anchor = (Core.ViewModels.DataFormats.Anchor)viewPort[0, 2].Format;

            Assert.Contains(16, anchor.Sources);
        }
示例#11
0
        public void ViewPortRequestsDelayedReloadIfReloadFails()
        {
            var viewPort   = new ViewPort(new LoadedFile("file.txt", new byte[50]));
            var fileSystem = new StubFileSystem {
                LoadFile = fileName => throw new IOException()
            };

            var retryCount = 0;

            viewPort.RequestDelayedWork += (sender, e) => retryCount++;

            viewPort.ConsiderReload(fileSystem);

            Assert.Equal(1, retryCount);
        }
        public void TableWithOneElement_AddMoreCausesRepoint_CanSeeAllElements()
        {
            SetFullModel(0xFF);
            ViewPort.Edit("^table[a: b: c: d:]1 ");
            Model[8] = 1; // to force the repoint
            var tableTool = ViewPort.Tools.TableTool;

            tableTool.AddCount = 3;
            tableTool.Append.Execute();

            var viewStart = ViewPort.DataOffset;
            var table     = (ITableRun)Model.GetNextRun(viewStart);

            Assert.Equal(table.Start, viewStart);
        }
 public BaseViewModelTestClass(int modelLength)
 {
     Data     = new byte[modelLength];
     Model    = new PokemonModel(Data, singletons: Singletons);
     ViewPort = new ViewPort("file.txt", Model, InstantDispatch.Instance, Singletons)
     {
         Width = 0x10, Height = 0x10
     };
     ViewPort.OnError += (sender, e) => { if (!string.IsNullOrEmpty(e))
                                          {
                                              Errors.Add(e);
                                          }
     };
     ViewPort.OnMessage += (sender, e) => Messages.Add(e);
 }
示例#14
0
        /// <summary>
        /// Calls a render function for each cell within the grid,
        /// passing as an argument any overlapping items
        /// </summary>
        public void Render(Action <Point2D, IEnumerable <ISpatial2DThing <T> > > renderer)
        {
            Read(() =>
            {
                foreach (var row in Rows)
                {
                    foreach (var p in row.Where(p => ViewPort.Overlaps(p)))
                    {
                        renderer.Invoke(p, GetObjectsOverlapping(p));
                    }
                }

                return(1);
            });
        }
示例#15
0
        public void ScrollingRightAndLeftCancel()
        {
            var loadedFile = new LoadedFile("test", new byte[25]);

            loadedFile.Contents[3] = 0x10;
            var viewPort = new ViewPort(loadedFile)
            {
                Width = 5, Height = 5
            };

            viewPort.Scroll.Execute(Direction.Left);
            viewPort.Scroll.Execute(Direction.Right);

            Assert.Equal(0x10, viewPort[3, 0].Value);
        }
示例#16
0
        public void OpeningStringFormatIncludesOpeningQuote()
        {
            var buffer   = Enumerable.Repeat((byte)0xFF, 0x200).ToArray();
            var model    = new PokemonModel(buffer);
            var viewPort = new ViewPort("test.txt", model)
            {
                Width = 0x10, Height = 0x10
            };

            viewPort.Edit("^bob\"\" \"Hello World!\"");
            var anchor      = (Anchor)viewPort[0, 0].Format;
            var innerFormat = (PCS)anchor.OriginalFormat;

            Assert.Equal("\"H", innerFormat.ThisCharacter);
        }
示例#17
0
        public PaletteElementViewModel(ViewPort viewPort, ChangeHistory <ModelDelta> history, string runFormat, PaletteFormat format, int itemAddress) : base(viewPort, runFormat, itemAddress)
        {
            this.format = format;

            var table = (ITableRun)viewPort.Model.GetNextRun(itemAddress);

            Colors = new PaletteCollection(viewPort, viewPort.Model, history);
            Colors.RequestPageSet += HandleColorsPageSet;
            TableName              = viewPort.Model.GetAnchorFromAddress(-1, table.Start);
            var destination = Model.ReadPointer(Start);
            var run         = viewPort.Model.GetNextRun(destination) as IPaletteRun;

            Pages = run?.Pages ?? 0;
            UpdateColors(Start, 0);
        }
        public void BackspaceBeforeEditChangesPreviousCurrentCell()
        {
            for (byte i = 0; i < 255; i++)
            {
                Data[i] = i;
            }

            ViewPort.SelectionStart = new Point(4, 4); // current value: 0x44
            ViewPort.Edit(ConsoleKey.Backspace);
            Assert.Equal(new Point(4, 4), ViewPort.SelectionStart);

            ViewPort.Edit(ConsoleKey.Backspace); // if I hit an arrow key now, it'll give up on the edit and just make the value something reasonable
            ViewPort.Edit(ConsoleKey.Backspace); // but since I hit backspace, it commits the erasure and starts erasing the next cell
            Assert.Equal(0xFF, ViewPort[4, 4].Value);
        }
        public void CanFindPointer()
        {
            var buffer   = new byte[0x100];
            var model    = new PokemonModel(buffer);
            var viewPort = new ViewPort("file.txt", model)
            {
                Width = 0x10, Height = 0x10
            };

            viewPort.SelectionStart = new Point(4, 1);
            viewPort.Edit("<000058> 23 19");
            var results = viewPort.Find("<000058> 23 19");

            Assert.Single(results);
        }
        public void AddressUpdateOnWidthChanged()
        {
            var viewPort = new ViewPort(new LoadedFile("test.txt", new byte[0x200]))
            {
                PreferredWidth = -1, Width = 0x10, Height = 0x10
            };
            var changeCount = 0;

            viewPort.Headers.CollectionChanged += (sender, e) => changeCount += 1;

            viewPort.Width++;

            Assert.InRange(changeCount, 1, viewPort.Height);
            Assert.Equal("000011", viewPort.Headers[1]);
        }
        public void ArrowMovementWhileTypingAnchorCommitsChange()
        {
            var buffer   = Enumerable.Repeat((byte)0xFF, 0x200).ToArray();
            var model    = new PokemonModel(buffer);
            var viewPort = new ViewPort("file.txt", model)
            {
                Width = 0x10, Height = 0x10
            };

            viewPort.Edit("^bob"); // no trailing space: still under edit

            viewPort.SelectionStart = new Point(1, 1);

            Assert.IsNotType <None>(viewPort[0, 0].Format);
        }
        public void CreatingAPointerOutsideTheDataRangeErrors()
        {
            var errors   = new List <string>();
            var data     = new byte[0x200];
            var model    = new PokemonModel(data);
            var viewPort = new ViewPort("file.txt", model)
            {
                Width = 0x10, Height = 0x10
            };

            viewPort.OnError += (sender, message) => errors.Add(message);
            viewPort.Edit("<000400>");

            Assert.Single(errors);
        }
示例#23
0
        public void ViewPortMovesWhenStringToolMovesData()
        {
            var buffer   = Enumerable.Repeat((byte)0xFF, 0x200).ToArray();
            var model    = new PokemonModel(buffer);
            var viewPort = new ViewPort("file.txt", model)
            {
                Width = 0x10, Height = 0x10
            };

            viewPort.Edit("^bob\"\" \"Some Text\" 00 <000100>");
            viewPort.Tools.StringTool.Address = 0;

            viewPort.Tools.StringTool.Content = "Some More Text";
            Assert.NotEqual(0, int.Parse(viewPort.Headers[0], NumberStyles.HexNumber));
        }
        public void MoveSelectionEndWorks()
        {
            var loadedFile = new LoadedFile("test", new byte[25]);
            var viewPort   = new ViewPort(loadedFile)
            {
                Width = 5, Height = 5
            };

            viewPort.SelectionStart = new Point(0, 0);

            viewPort.MoveSelectionStart.Execute(Direction.Right);
            viewPort.MoveSelectionEnd.Execute(Direction.Down);

            Assert.Equal(new Point(1, 1), viewPort.SelectionEnd);
        }
        public void TypingBracesOnDataTriesToInterpretThatDataAsPointer()
        {
            var data     = new byte[0x200];
            var model    = new PokemonModel(data);
            var viewPort = new ViewPort("file.txt", model)
            {
                Width = 0x10, Height = 0x10
            };

            viewPort.Edit("00 01 00 08");
            viewPort.SelectionStart = new Point(0, 0);
            viewPort.Edit("<>"); // typing this should interpret the bytes as a pointer and add it.

            Assert.Equal(0x100, ((Pointer)viewPort[0, 0].Format).Destination);
        }
        public void UnderEditCellsKnowTheirEditLength()
        {
            ViewPort.Edit("^array[a: b. c. d<>]4 ");

            ViewPort.SelectionStart = new Point(0, 0);
            ViewPort.Edit("2");
            Assert.Equal(2, ((UnderEdit)ViewPort[0, 0].Format).EditWidth);

            ViewPort.SelectionStart = new Point(6, 0);
            ViewPort.Edit("2");
            Assert.Equal(4, ((UnderEdit)ViewPort[4, 0].Format).EditWidth);

            ViewPort.SelectionStart = new Point(8, 6);
            ViewPort.Edit("^");
            Assert.Equal(4, ((UnderEdit)ViewPort[8, 6].Format).EditWidth);
        }
示例#27
0
        public void ViewPortNameEndsWithStarIfNeedsSave()
        {
            var viewPort         = new ViewPort(new LoadedFile("path/to/myfile.txt", new byte[10]));
            int nameChangedCount = 0;

            viewPort.PropertyChanged += (sender, e) => { if (e.PropertyName == nameof(viewPort.Name))
                                                         {
                                                             nameChangedCount++;
                                                         }
            };

            viewPort.Edit("12 34 56");

            Assert.EndsWith("*", viewPort.Name);
            Assert.Equal(1, nameChangedCount);
        }
示例#28
0
        public void CanUndoFormatChange()
        {
            var data     = new byte[0x100];
            var model    = new PokemonModel(data);
            var viewPort = new ViewPort("file.txt", model)
            {
                Width = 0x10, Height = 0x10
            };

            viewPort.SelectionStart = new Point(4, 0);
            viewPort.Edit("<000030>");
            Assert.Equal(0x04, model.GetNextRun(0).Start);

            viewPort.Undo.Execute();
            Assert.Equal(int.MaxValue, model.GetNextRun(0).Start);
        }
示例#29
0
        public void UndoWorksAfterMidPointerEdit()
        {
            var buffer   = Enumerable.Repeat((byte)0xFF, 0x200).ToArray();
            var model    = new PokemonModel(buffer);
            var viewPort = new ViewPort("file.txt", model)
            {
                Width = 0x10, Height = 0x10
            };

            viewPort.Edit("<000100>");
            viewPort.SelectionStart = new Point(1, 0);
            viewPort.Edit("<000180>");
            viewPort.Undo.Execute();

            Assert.Equal(0x000100, model.ReadPointer(0));
        }
示例#30
0
        public void AnchorEditTextUpdatesWithSelectionChange()
        {
            var buffer = Enumerable.Repeat((byte)0xFF, 0x200).ToArray();
            var model  = new PokemonModel(buffer);

            model.ObserveAnchorWritten(new ModelDelta(), "bob", new NoInfoRun(0x08));
            var viewPort = new ViewPort("file.txt", model)
            {
                Width = 0x10, Height = 0x10
            };

            viewPort.SelectionStart = new Point(0x08, 0);

            Assert.True(viewPort.AnchorTextVisible);
            Assert.Equal("^bob", viewPort.AnchorText);
        }
示例#31
0
        public void ModifyingAnchorTextUpdatesTheAnchor()
        {
            var buffer = Enumerable.Repeat((byte)0xFF, 0x200).ToArray();
            var model  = new PokemonModel(buffer);

            model.ObserveAnchorWritten(new ModelDelta(), "bob", new NoInfoRun(0x08));
            var viewPort = new ViewPort("file.txt", model)
            {
                Width = 0x10, Height = 0x10
            };

            viewPort.SelectionStart = new Point(0x08, 0);
            viewPort.AnchorText     = "^bob\"\"";

            Assert.IsType <PCSRun>(model.GetNextRun(0x08));
        }
示例#32
0
        public void AnchorTextAlwaysCoercesToStartWithAnchorCharacter()
        {
            var buffer = Enumerable.Repeat((byte)0xFF, 0x200).ToArray();
            var model  = new PokemonModel(buffer);

            model.ObserveAnchorWritten(new ModelDelta(), "bob", new NoInfoRun(0x08));
            var viewPort = new ViewPort("file.txt", model)
            {
                Width = 0x10, Height = 0x10
            };

            viewPort.SelectionStart = new Point(0x08, 0);
            viewPort.AnchorText     = "tom\"\"";

            Assert.Equal("^tom\"\"", viewPort.AnchorText); // not that the ^ was added to the front
        }
示例#33
0
        private void ArrangeTrainerPokemonTeamData(byte structType, byte pokemonCount)
        {
            CreateTextTable(HardcodeTablesModel.PokemonNameTable, 0x100, "ABCDEFGHIJKLMNOP".Select(c => c.ToString()).ToArray());
            CreateTextTable(HardcodeTablesModel.MoveNamesTable, 0x140, "qrstuvwxyz".Select(c => c.ToString()).ToArray());
            CreateTextTable(HardcodeTablesModel.ItemsTableName, 0x180, "0123456789".Select(c => c.ToString()).ToArray());

            Model[TrainerPokemonTeamRun.TrainerFormat_StructTypeOffset]   = structType;
            Model[TrainerPokemonTeamRun.TrainerFormat_PokemonCountOffset] = pokemonCount;
            Model.WritePointer(new ModelDelta(), TrainerPokemonTeamRun.TrainerFormat_PointerOffset, 0x60);

            ViewPort.Goto.Execute("00");
            ViewPort.SelectionStart = new Point(4, 2);
            ViewPort.Edit($"^trainertable[team<{TrainerPokemonTeamRun.SharedFormatString}>]1 ");

            ViewPort.Goto.Execute("00");
        }
示例#34
0
        public override void Draw(TimeSpan ellapsedTime, ViewPort viewPort)
        {
            if (this._actor.Effect == null)
                return;

            Vector3 position = new Vector3(_actor.Location.X * Settings.MetersToPixels, _actor.Location.Y * Settings.MetersToPixels, 0f);

            _actor.Effect.Update((Single)ellapsedTime.TotalSeconds);

            //if (!_isTriggered)
            //{
                _actor.Effect.Trigger((Single)ellapsedTime.TotalSeconds, ref position);
                _isTriggered = true;
            //}

            this._renderer.RenderEffect(_actor.Effect, ref world, ref view, ref projection, ref cameraPosition);
        }
示例#35
0
        /// <summary>
        /// render scene in every view port.
        /// </summary>
        /// <param name="viewPort"></param>
        /// <param name="clientRectangle"></param>
        /// <param name="pickingGeometryType"></param>
        private void RenderViewPort(ViewPort viewPort, Rectangle clientRectangle, PickingGeometryType pickingGeometryType)
        {
            if (viewPort.Enabled)
            {
                // render in this view port.
                if (viewPort.Visiable)
                {
                    // render scene in this view port.
                    viewPort.Render(this, clientRectangle, pickingGeometryType);
                }

                // render children viewport.
                foreach (ViewPort item in viewPort.Children)
                {
                    this.RenderViewPort(item, clientRectangle, pickingGeometryType);
                }
            }
        }
示例#36
0
        public WorldView()
        {
            _penGrid1 = new Pen(Color.Gray, 3);
              _penGrid2 = new Pen(Color.Gray, 1);
              _penAngle = new Pen(Color.Black, 6);
              _penRadar = new Pen(Color.Green, 6);
              _brushRun = new SolidBrush(Color.Red);
              _brushPark = new SolidBrush(Color.Blue);
              _font = new Font(FontFamily.GenericSerif, 8, FontStyle.Regular);
              _fontBrush = new SolidBrush(Color.Black);
              _brushRobot = new SolidBrush(Color.Gray);

              _drivedPoints = new LinkedList<PositionInfo>();
              _parkedSpot = new List<PositionInfo>();
              _viewPort = new ViewPort(-1, 4, -2, 2);
              lockObj = new object();
              InitializeComponent();

              if (Constants.IsWinCE) {
            timer1.Interval = 100;
              }
        }
        private void Form_Load(object sender, EventArgs e)
        {
            foreach (var item in Enum.GetValues(typeof(PickingGeometryType)))
            {
                this.cmbPickingGeometryType.Items.Add(item);
            }
            this.cmbPickingGeometryType.SelectedIndex = 1;

            {
                var frmBulletinBoard = new FormBulletinBoard();
                //frmBulletinBoard.Dump = true;
                frmBulletinBoard.Show();
                this.bulletinBoard = frmBulletinBoard;
            }
            {
                //this.glCanvas1.ShowSystemCursor = false;
            }
            {
                // default(perspective)
                var camera = new Camera(
                    new vec3(15, 5, 0), new vec3(0, 0, 0), new vec3(0, 1, 0),
                    CameraType.Perspecitive, this.glCanvas1.Width, this.glCanvas1.Height);
                var rotator = new FirstPerspectiveManipulater();
                rotator.StepLength = 0.5f;
                rotator.Bind(camera, this.glCanvas1);
                var scene = new Scene(camera, this.glCanvas1);
                //scene.Cursor.Enabled = false;
                this.scene = scene;
                ViewPort rootViewPort = scene.RootViewPort;
                rootViewPort.ClearColor = Color.White;
                ViewPort viewPort = rootViewPort.Children[0];
                viewPort.ClearColor = Color.Gray;
                viewPort.BeforeLayout += viewPort_BeforeLayout;
                viewPort.AfterLayout += perspectiveViewPort_AfterLayout;
                this.glCanvas1.Resize += scene.Resize;
            }
            {
                // top
                var camera = new Camera(
                new vec3(0, 0, 25), new vec3(0, 0, 0), new vec3(0, 1, 0),
                CameraType.Perspecitive, this.glCanvas1.Width, this.glCanvas1.Height);
                ViewPort viewPort = new ViewPort(camera, AnchorStyles.None, new Padding(), new Size());
                viewPort.ClearColor = Color.Gray;
                viewPort.BeforeLayout += viewPort_BeforeLayout;
                viewPort.AfterLayout += topViewPort_AfterLayout;
                this.scene.RootViewPort.Children.Add(viewPort);
            }
            {
                // front
                var camera = new Camera(
                new vec3(0, 25, 0), new vec3(0, 0, 0), new vec3(0, 0, -1),
                CameraType.Perspecitive, this.glCanvas1.Width, this.glCanvas1.Height);
                ViewPort viewPort = new ViewPort(camera, AnchorStyles.None, new Padding(), new Size());
                viewPort.ClearColor = Color.Gray;
                viewPort.BeforeLayout += viewPort_BeforeLayout;
                viewPort.AfterLayout += frontViewPort_AfterLayout;
                this.scene.RootViewPort.Children.Add(viewPort);
            }
            {
                // left
                var camera = new Camera(
                new vec3(-25, 0, 0), new vec3(0, 0, 0), new vec3(0, 0, -1),
                CameraType.Perspecitive, this.glCanvas1.Width, this.glCanvas1.Height);
                ViewPort viewPort = new ViewPort(camera, AnchorStyles.None, new Padding(), new Size());
                viewPort.ClearColor = Color.Gray;
                viewPort.BeforeLayout += viewPort_BeforeLayout;
                viewPort.AfterLayout += leftViewPort_AfterLayout;
                this.scene.RootViewPort.Children.Add(viewPort);
            }
            {
                var uiAxis = new UIAxis(AnchorStyles.Left | AnchorStyles.Bottom,
              new Padding(3, 3, 3, 3), new Size(128, 128));
                uiAxis.Initialize();
                this.scene.RootUI.Children.Add(uiAxis);
            }
            {
                var font = new Font("Courier New", 32);
                var uiText = new UIText(AnchorStyles.Left | AnchorStyles.Bottom,
                    new Padding(0, 0, 0, 0), new Size(250, 20), -100, 100,
                   font.GetFontBitmap("[index: 0123456789]").GetFontTexture());
                uiText.Text = "";
                this.uiText = uiText;
                this.scene.RootUI.Children.Add(uiText);
            }
            {
                GroundRenderer ground = GroundRenderer.Create(new GroundModel(20));
                ground.Initialize();
                ground.Scale = new vec3(20, 20, 20);
                ground.WorldPosition = new vec3(0, 0, 0);
                SceneObject obj = ground.WrapToSceneObject(name: "Ground", generateBoundingBox: true);
                this.scene.RootObject.Children.Add(obj);
            }
            {
                bool useHighlightedPickingEffect = false;
                if (MessageBox.Show("Use highlighted picking effect?", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
                {
                    useHighlightedPickingEffect = true;
                }
                List<PickableRenderer> list = GetPickableRenderers();
                const float distance = 10;
                float sideCount = (float)Math.Sqrt(list.Count);
                int sideCounti = (int)sideCount;
                float x = -sideCount * distance / 2;
                float z = -sideCount * distance / 2;
                //float x = 0, z = 0;
                for (int i = 0; i < list.Count; i++)
                {
                    PickableRenderer item = list[i];
                    SceneObject obj;
                    if (useHighlightedPickingEffect)
                    {
                        var model = item.DataSource;
                        var highlightRenderer = new HighlightRenderer(model, item.PositionNameInIBufferable);
                        var renderer = new HighlightedPickableRenderer(
                            highlightRenderer, item);
                        renderer.WorldPosition = new vec3(x, 2, z);
                        renderer.Initialize();
                        obj = renderer.WrapToSceneObject(generateBoundingBox: true);
                    }
                    else
                    {
                        item.WorldPosition = new vec3(x, 2, z);
                        obj = item.WrapToSceneObject(generateBoundingBox: true);
                    }
                    this.scene.RootObject.Children.Add(obj);

                    x += distance;
                    if (i % sideCounti == sideCounti - 1)
                    { z += distance; x = -sideCount * distance / 2; }
                }
            }
            {
                this.glCanvas1.MouseDown += glCanvas1_MouseDown;
                this.glCanvas1.MouseMove += glCanvas1_MouseMove;
                this.glCanvas1.MouseUp += glCanvas1_MouseUp;
            }
            {
                var builder = new StringBuilder();
                builder.AppendLine("1: Scene's property grid.");
                builder.AppendLine("2: Canvas' property grid.");
                builder.AppendLine("3: Form's property grid.");
                builder.AppendLine("4: Save to bitmap file.");
                builder.AppendLine("Ctrl+Mouse: Picking.");
                MessageBox.Show(builder.ToString());
            }
        }
示例#38
0
 public override VisualHitTestResult GetHitResult(Vector2 location, ViewPort viewPort)
 {
     return new VisualHitTestResult(_actor, Vector2.Zero, false);
 }
示例#39
0
 public override void Draw(TimeSpan ellapsedTime, ViewPort viewPort)
 {
    
 }
        protected override void OnPaint(PaintEventArgs pe)
        {
            var g = pe.Graphics;
            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            g.Clear(Color.White);

            var bmp = new Bitmap(Width*2, Height*2);
            var lockBmp = new LockBitmap(bmp);
            var viewport = new ViewPort(bmp.Width, bmp.Height);
            var data = _fractal.GetFractal(_defaultRange, viewport);

            lockBmp.LockBits();
            for (int x = 0; x < bmp.Width; x++)
            {
                for (int y = 0; y < bmp.Height; y++)
                {
                    var n = data[x, y];
                    var color = Color.White;
                    if (n >= _maxTries)
                        color = Color.Black;
                    lockBmp.SetPixel(x, y, color);
                }
            }
            lockBmp.UnlockBits();

            var bmpResized = ResizeImage(bmp, Width, Height);
            g.DrawImage(bmpResized, 0, 0);
            //base.OnPaint(pe);
        }
示例#41
0
 public override VisualHitTestResult GetHitResult(Vector2 location, ViewPort viewPort)
 {
     return new VisualHitTestResult(this._actor, new Vector2(0f, 0f), false);
 }
示例#42
0
        /// <summary>
        /// Pick primitives in specified <paramref name="viewPort"/>.
        /// </summary>
        /// <param name="viewPort"></param>
        /// <param name="pickingRect">rect in OpenGL's window coordinate system.(Left Down is (0, 0)), size).</param>
        /// <param name="clientRectangle">whole canvas' rectangle.</param>
        /// <param name="pickingGeometryType"></param>
        /// <returns></returns>
        private List<Tuple<Point, PickedGeometry>> ColorCodedPicking(ViewPort viewPort, Rectangle pickingRect, Rectangle clientRectangle, PickingGeometryType pickingGeometryType)
        {
            var result = new List<Tuple<Point, PickedGeometry>>();

            // if depth buffer is valid in specified rect, then maybe something is picked.
            //if (DepthBufferValid(pickingRect))
            {
                lock (this.synObj)
                {
                    var arg = new RenderEventArgs(clientRectangle, viewPort, pickingGeometryType);
                    // Render all PickableRenderers for color-coded picking.
                    List<IPickable> pickableRendererList = Render4Picking(arg);
                    // Read pixels in specified rect and get the VertexIds they represent.
                    List<Tuple<Point, uint>> stageVertexIdList = ReadPixels(pickingRect);
                    // Get all picked geometrys.
                    foreach (Tuple<Point, uint> tuple in stageVertexIdList)
                    {
                        int x = tuple.Item1.X;
                        int y = tuple.Item1.Y;
                        //if (x < 0 || clientRectangle.Width <= x || y < 0 || clientRectangle.Height <= y) { continue; }

                        uint stageVertexId = tuple.Item2;
                        PickedGeometry pickedGeometry = GetPickGeometry(arg,
                           x, y, stageVertexId, pickableRendererList);
                        if (pickedGeometry != null)
                        {
                            result.Add(new Tuple<Point, PickedGeometry>(new Point(x, y), pickedGeometry));
                        }
                    }
                }
            }

            return result;
        }
示例#43
0
        public void UpdateVisibleRange(int offset, int visible, int lineHeight)
        {
            _viewPort = new ViewPort(offset, visible, lineHeight, Width);

            Invalidate();
            Update();
        }
示例#44
0
            public void Draw(ViewPort viewPort, PaintEventArgs e, int height)
            {
                var bounds = Bounds;
                bounds.Offset(0, -viewPort.Offset);

                if (Type == DiffEditorButtonType.CopyLeft || Type == DiffEditorButtonType.DeleteLeft)
                {
                    e.Graphics.DrawLine(
                        SystemPens.ControlDark,
                        bounds.Right,
                        bounds.Top + 1,
                        bounds.Right,
                        bounds.Bottom - 2
                    );
                }
                else
                {
                    e.Graphics.DrawLine(
                        SystemPens.ControlDark,
                        bounds.Left - 1,
                        bounds.Top + 1,
                        bounds.Left - 1,
                        bounds.Bottom - 2
                    );
                }

                int top = Math.Max(bounds.Top, 0);
                int bottom = Math.Min(bounds.Bottom, height);
                if (bottom - top < viewPort.LineHeight)
                    bottom = top + viewPort.LineHeight;

                e.Graphics.DrawImage(
                    Image,
                    bounds.Left + (bounds.Width - Image.Width) / 2,
                    top + ((bottom - top) - Image.Height) / 2
                );
            }
示例#45
0
            public void Draw(ViewPort viewPort, PaintEventArgs e, int height)
            {
                var bounds = new Rectangle(
                    0,
                    EditMarker.Line * viewPort.LineHeight - viewPort.Offset,
                    viewPort.Width,
                    EditMarker.Length * viewPort.LineHeight
                );

                e.Graphics.FillRectangle(
                    Color.LightBrush,
                    bounds
                );

                e.Graphics.DrawLine(
                    SystemPens.ControlDark,
                    bounds.Left,
                    bounds.Top,
                    bounds.Width - 1,
                    bounds.Top
                );

                e.Graphics.DrawLine(
                    SystemPens.ControlDark,
                    bounds.Left,
                    bounds.Bottom - 1,
                    bounds.Width - 1,
                    bounds.Bottom - 1
                );

                foreach (var button in Buttons)
                {
                    if (button != null)
                        button.Draw(viewPort, e, height);
                }
            }
示例#46
0
 // TODO: big bug: when mouse is picking something and move outside of viewport to anothher one, camera will go wrong.
 /// <summary>
 /// Initializes a new instance of the <see cref="RenderEventArgs"/> class.
 /// </summary>
 /// <param name="canvasRect"></param>
 /// <param name="viewPort">camera used during rendering.</param>
 /// <param name="pickingGeometryType">Target geometry type(point, line, triangle, quad or polygon) for color-coded-picking; otherwise useless.</param>
 public RenderEventArgs(Rectangle canvasRect, ViewPort viewPort, PickingGeometryType pickingGeometryType)
 {
     this.CanvasRect = canvasRect;
     this.UsingViewPort = viewPort;
     this.PickingGeometryType = pickingGeometryType;
 }