/// <summary> /// OnMouseUp /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void GLTileControl_MouseUp(object sender, MouseEventArgs e) { // Transmit event to the selection box if (CollisionSelection != null && ColisionBox.Checked) { CollisionSelection.OnMouseUp(e); } }
/// <summary> /// OnMouseMove /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void GLTileControl_MouseMove(object sender, MouseEventArgs e) { // If scrolling with the middle mouse button if (e.Button == MouseButtons.Middle || e.Button == MouseButtons.Right) { // Smooth the value //Point pos = Point.Empty; TileOffset.X -= (LastMousePos.X - e.X) / 1; TileOffset.Y -= (LastMousePos.Y - e.Y) / 1; // Store last mouse location LastMousePos = e.Location; return; } // Prints the location of the mouse //int zoomvalue = Int32.Parse((string)ZoomBox.SelectedItem) / 100; int zoomvalue = int.Parse((string)ZoomBox.SelectedItem); PositionLabel.Text = (int)((e.Location.X - TileOffset.X) / zoomvalue) + "," + (int)((e.Location.Y - TileOffset.Y) / zoomvalue); // Prints the size of the current tile SizeLabel.Text = CollisionSelection.Rectangle.Width + "," + CollisionSelection.Rectangle.Height; // Set the collision box if (CollisionSelection != null && ColisionBox.Checked) { CollisionSelection.OnMouseMove(e); } // Set the hotspot if (HotSpotBox.Checked && e.Button == MouseButtons.Left) { if (CurrentTile != null) { // Get zoom value //int zoomvalue = Int32.Parse((string)ZoomBox.SelectedItem) / 100; Point pos = Point.Empty; pos.X = (e.Location.X - TileOffset.X) / zoomvalue; pos.Y = (e.Location.Y - TileOffset.Y) / zoomvalue; CurrentTile.Pivot = pos; } } }
/// <summary> /// OnMouseDown /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void GLTileControl_MouseDown(object sender, MouseEventArgs e) { // Size the selection box if (CollisionSelection.MouseTool == MouseTools.NoTool && e.Button == MouseButtons.Left && ColisionBox.Checked) { int zoomvalue = Int32.Parse((string)ZoomBox.SelectedItem); CollisionSelection.Rectangle.X = (e.Location.X - TileOffset.X) / zoomvalue; CollisionSelection.Rectangle.Y = (e.Location.Y - TileOffset.Y) / zoomvalue; CollisionSelection.Rectangle.Width = 0; CollisionSelection.Rectangle.Height = 0; CollisionSelection.MouseTool = MouseTools.SizeDownRight; } // Transmit event to the selection box if (CollisionSelection != null && ColisionBox.Checked) { CollisionSelection.OnMouseDown(e); } // Set the hotspot if (HotSpotBox.Checked && e.Button == MouseButtons.Left) { if (CurrentTile != null) { // Get zoom value int zoomvalue = Int32.Parse((string)ZoomBox.SelectedItem); Point pos = Point.Empty; pos.X = (e.Location.X - TileOffset.X) / zoomvalue; pos.Y = (e.Location.Y - TileOffset.Y) / zoomvalue; CurrentTile.Pivot = pos; } } // Pan the texture if (e.Button == MouseButtons.Middle || e.Button == MouseButtons.Right) { LastMousePos = e.Location; } }
/// <summary> /// OnPaint event /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void GLTileControl_Paint(object sender, PaintEventArgs e) { GLTileControl.MakeCurrent(); Display.ClearBuffers(); Batch.Begin(); // Background texture Rectangle dst = new Rectangle(Point.Empty, GLTileControl.Size); Batch.Draw(CheckerBoard, dst, dst, Color.White); // No tiles, no draw ! if (CurrentTile != null) { // Get zoom value float zoomvalue = float.Parse((string)ZoomBox.SelectedItem); // Draw the tile Vector4 zoom = new Vector4(); zoom.X = TileOffset.X; zoom.Y = TileOffset.Y; zoom.Z = CurrentTile.Rectangle.Width * zoomvalue; zoom.W = CurrentTile.Rectangle.Height * zoomvalue; // Texture source Vector4 src = new Vector4( CurrentTile.Rectangle.X, CurrentTile.Rectangle.Y, CurrentTile.Size.Width, CurrentTile.Size.Height); Batch.Draw(TileSet.Texture, zoom, src, Color.White); // Draw Collision box if (CollisionSelection != null && ColisionBox.Checked) { CollisionSelection.Zoom = zoomvalue; CollisionSelection.Offset = TileOffset; CurrentTile.CollisionBox = CollisionSelection.Rectangle; CollisionSelection.Draw(Batch); } // Draw origin if (HotSpotBox.Checked) { Point pos = Point.Empty; pos.X = (int)(CurrentTile.Pivot.X * zoomvalue + TileOffset.X); pos.Y = (int)(CurrentTile.Pivot.Y * zoomvalue + TileOffset.Y); Rectangle rect = new Rectangle(pos, new Size((int)zoomvalue, (int)zoomvalue)); Batch.FillRectangle(rect, Color.Red); } } Batch.End(); GLTileControl.SwapBuffers(); }