/// <summary> /// Draw Timer tick /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void DrawTimer_Tick(object sender, EventArgs e) { // If not floating panel and the panel is active and AutoRefresh is OK if (this.DockAreas != DockAreas.Float && DockPanel.ActiveDocument == this) { int elapsed = Environment.TickCount - Time; Time = Environment.TickCount; // Stop the drawtimer DrawTimer.Stop(); //Animation.Update(TimeSpan.FromMilliseconds(elapsed)); Animation.Update(new GameTime(TimeSpan.Zero, TimeSpan.Zero, TimeSpan.Zero, TimeSpan.FromMilliseconds(elapsed))); GlFramesControl.Invalidate(); GlTilesControl.Invalidate(); GlPreviewControl.Invalidate(); // Restart the draw timer DrawTimer.Start(); } }
/// <summary> /// OnPaint /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void GlFramesControl_Paint(object sender, PaintEventArgs e) { // Cleanup GlFramesControl.MakeCurrent(); Display.ClearBuffers(); SpriteBatch.Begin(); // Background texture Rectangle dst = new Rectangle(Point.Empty, GlFramesControl.Size); SpriteBatch.Draw(CheckerBoard, dst, dst, Color.White); // Oops ! if (Animation.TileSet != null) { // Mouse location Point mouse = GlFramesControl.PointToClient(Control.MousePosition); // Display each frames Rectangle rect = Rectangle.Empty; for (int id = 0; id < Animation.Frames.Count; id++) { Tile tile = Animation.TileSet.GetTile(Animation.Frames[id]); if (tile == null) { continue; } rect.Size = tile.Size; //Animation.TileSet.Texture.Blit(rect, tile.Rectangle); //Display.BlitTexture(Animation.TileSet.Texture, rect, tile.Rectangle); SpriteBatch.Draw(Animation.TileSet.Texture, rect, tile.Rectangle, Color.White); if (rect.Contains(mouse) || id == FrameID) { SpriteBatch.DrawRectangle(rect, Color.White); } rect.X += tile.Size.Width; if (rect.X > Display.ViewPort.Width) { break; } } } SpriteBatch.End(); GlFramesControl.SwapBuffers(); }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void AnimationForm_Load(object sender, EventArgs e) { GlTilesControl.MakeCurrent(); Display.Init(); GlFramesControl.MakeCurrent(); Display.Init(); GlPreviewControl.MakeCurrent(); Display.Init(); SpriteBatch = new SpriteBatch(); // Preload background texture resource CheckerBoard = new Texture2D(ResourceManager.GetInternalResource("ArcEngine.Resources.checkerboard.png")); CheckerBoard.HorizontalWrap = TextureWrapFilter.Repeat; CheckerBoard.VerticalWrap = TextureWrapFilter.Repeat; BuildInterface(); // Draw timer DrawTimer.Start(); }
/// <summary> /// OnResize /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void GlFramesControl_Resize(object sender, EventArgs e) { GlFramesControl.MakeCurrent(); Display.ViewPort = new Rectangle(new Point(), GlFramesControl.Size); }