failed attempt to make graphics faster, but at least now that control is nicely wrapped in a class

This commit is contained in:
codeimp 2007-10-16 21:15:27 +00:00
parent 3f2d296376
commit 588a789198
8 changed files with 224 additions and 38 deletions

View file

@ -107,6 +107,9 @@
<Compile Include="Interface\PreferencesForm.Designer.cs">
<DependentUpon>PreferencesForm.cs</DependentUpon>
</Compile>
<Compile Include="Interface\RenderTargetControl.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="Interface\ResourceListView.cs">
<SubType>Component</SubType>
</Compile>
@ -194,6 +197,7 @@
</ItemGroup>
<ItemGroup>
<Content Include="Resources\Builder.ico" />
<None Include="Resources\floor0_3.bmp" />
<None Include="Resources\Properties.png" />
<None Include="Resources\NewMap2.png" />
<None Include="Resources\Zoom.png" />

View file

@ -49,6 +49,7 @@ namespace CodeImp.DoomBuilder.Interface
this.menuedit = new System.Windows.Forms.ToolStripMenuItem();
this.itemmapoptions = new System.Windows.Forms.ToolStripMenuItem();
this.menutools = new System.Windows.Forms.ToolStripMenuItem();
this.itemreloadresources = new System.Windows.Forms.ToolStripMenuItem();
this.configurationToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.preferencesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.menuhelp = new System.Windows.Forms.ToolStripMenuItem();
@ -75,8 +76,7 @@ namespace CodeImp.DoomBuilder.Interface
this.yposlabel = new System.Windows.Forms.ToolStripStatusLabel();
this.panelinfo = new System.Windows.Forms.Panel();
this.redrawtimer = new System.Windows.Forms.Timer(this.components);
this.display = new System.Windows.Forms.Panel();
this.itemreloadresources = new System.Windows.Forms.ToolStripMenuItem();
this.display = new CodeImp.DoomBuilder.Interface.RenderTargetControl();
toolStripMenuItem1 = new System.Windows.Forms.ToolStripSeparator();
toolStripMenuItem2 = new System.Windows.Forms.ToolStripSeparator();
toolStripMenuItem3 = new System.Windows.Forms.ToolStripSeparator();
@ -86,6 +86,7 @@ namespace CodeImp.DoomBuilder.Interface
this.menumain.SuspendLayout();
this.toolbar.SuspendLayout();
this.statusbar.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.display)).BeginInit();
this.SuspendLayout();
//
// toolStripMenuItem1
@ -115,6 +116,11 @@ namespace CodeImp.DoomBuilder.Interface
toolStripStatusLabel1.Text = ",";
toolStripStatusLabel1.ToolTipText = "Current X, Y coordinates on map";
//
// toolStripSeparator4
//
toolStripSeparator4.Name = "toolStripSeparator4";
toolStripSeparator4.Size = new System.Drawing.Size(194, 6);
//
// menumain
//
this.menumain.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
@ -239,6 +245,14 @@ namespace CodeImp.DoomBuilder.Interface
this.menutools.Size = new System.Drawing.Size(44, 20);
this.menutools.Text = "Tools";
//
// itemreloadresources
//
this.itemreloadresources.Name = "itemreloadresources";
this.itemreloadresources.Size = new System.Drawing.Size(197, 22);
this.itemreloadresources.Tag = "reloadresources";
this.itemreloadresources.Text = "Reload Resources";
this.itemreloadresources.Click += new System.EventHandler(this.InvokeTaggedAction);
//
// configurationToolStripMenuItem
//
this.configurationToolStripMenuItem.Name = "configurationToolStripMenuItem";
@ -481,7 +495,6 @@ namespace CodeImp.DoomBuilder.Interface
// display
//
this.display.BackColor = System.Drawing.SystemColors.AppWorkspace;
this.display.BackgroundImage = global::CodeImp.DoomBuilder.Properties.Resources.Splash2;
this.display.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center;
this.display.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.display.CausesValidation = false;
@ -490,27 +503,15 @@ namespace CodeImp.DoomBuilder.Interface
this.display.Name = "display";
this.display.Size = new System.Drawing.Size(731, 372);
this.display.TabIndex = 5;
this.display.TabStop = false;
this.display.MouseLeave += new System.EventHandler(this.display_MouseLeave);
this.display.MouseDown += new System.Windows.Forms.MouseEventHandler(this.display_MouseDown);
this.display.MouseMove += new System.Windows.Forms.MouseEventHandler(this.display_MouseMove);
this.display.MouseClick += new System.Windows.Forms.MouseEventHandler(this.display_MouseClick);
this.display.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.display_MouseDoubleClick);
this.display.Resize += new System.EventHandler(this.display_Resize);
this.display.MouseEnter += new System.EventHandler(this.display_MouseEnter);
this.display.MouseClick += new System.Windows.Forms.MouseEventHandler(this.display_MouseClick);
this.display.MouseUp += new System.Windows.Forms.MouseEventHandler(this.display_MouseUp);
//
// itemreloadresources
//
this.itemreloadresources.Name = "itemreloadresources";
this.itemreloadresources.Size = new System.Drawing.Size(197, 22);
this.itemreloadresources.Tag = "reloadresources";
this.itemreloadresources.Text = "Reload Resources";
this.itemreloadresources.Click += new System.EventHandler(this.InvokeTaggedAction);
//
// toolStripSeparator4
//
toolStripSeparator4.Name = "toolStripSeparator4";
toolStripSeparator4.Size = new System.Drawing.Size(194, 6);
this.display.MouseEnter += new System.EventHandler(this.display_MouseEnter);
//
// MainForm
//
@ -541,6 +542,7 @@ namespace CodeImp.DoomBuilder.Interface
this.toolbar.PerformLayout();
this.statusbar.ResumeLayout(false);
this.statusbar.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.display)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
@ -564,7 +566,7 @@ namespace CodeImp.DoomBuilder.Interface
private System.Windows.Forms.Timer redrawtimer;
private System.Windows.Forms.ToolStripMenuItem menuhelp;
private System.Windows.Forms.ToolStripMenuItem itemhelpabout;
private System.Windows.Forms.Panel display;
private CodeImp.DoomBuilder.Interface.RenderTargetControl display;
private System.Windows.Forms.ToolStripMenuItem itemnorecent;
private System.Windows.Forms.ToolStripStatusLabel xposlabel;
private System.Windows.Forms.ToolStripStatusLabel yposlabel;

View file

@ -65,7 +65,7 @@ namespace CodeImp.DoomBuilder.Interface
#region ================== Properties
public bool MouseInDisplay { get { return mouseinside; } }
public Panel Display { get { return display; } }
public RenderTargetControl Display { get { return display; } }
#endregion
@ -89,6 +89,9 @@ namespace CodeImp.DoomBuilder.Interface
// Make recent items list
CreateRecentFiles();
// Show splash
ShowSplashDisplay();
// Keep last position and size
lastposition = this.Location;
lastsize = this.Size;
@ -316,9 +319,7 @@ namespace CodeImp.DoomBuilder.Interface
public void ShowSplashDisplay()
{
// Change display to show splash logo
display.BackColor = System.Drawing.SystemColors.AppWorkspace;
display.BackgroundImage = global::CodeImp.DoomBuilder.Properties.Resources.Splash2;
display.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center;
display.SetSplashLogoDisplay();
this.Update();
}
@ -326,9 +327,7 @@ namespace CodeImp.DoomBuilder.Interface
public void ClearDisplay()
{
// Clear the display
display.BackColor = Color.Black;
display.BackgroundImage = null;
display.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;
display.SetManualRendering();
this.Update();
}

View file

@ -132,15 +132,15 @@
<metadata name="toolStripStatusLabel1.GenerateMember" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
<metadata name="toolStripSeparator4.GenerateMember" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
<metadata name="menumain.Locked" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="menumain.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="toolStripSeparator4.GenerateMember" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
<metadata name="toolbar.Locked" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>

View file

@ -0,0 +1,154 @@
#region ================== Copyright (c) 2007 Pascal vd Heiden
/*
* Copyright (c) 2007 Pascal vd Heiden, www.codeimp.com
* This program is released under GNU General Public License
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#endregion
#region ================== Namespaces
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Text;
using System.Globalization;
using System.Windows.Forms;
using CodeImp.DoomBuilder.Controls;
using CodeImp.DoomBuilder.Geometry;
using CodeImp.DoomBuilder.Rendering;
using CodeImp.DoomBuilder.Editing;
#endregion
namespace CodeImp.DoomBuilder.Interface
{
public class RenderTargetControl : PictureBox
{
#region ================== Constants
#endregion
#region ================== Variables
// Reference to image to render from
private Image img = null;
#endregion
#region ================== Properties
#endregion
#region ================== Constructor / Disposer
// Constructor
public RenderTargetControl()
{
// Initialize
this.SetStyle(ControlStyles.FixedWidth, true);
this.SetStyle(ControlStyles.FixedHeight, true);
}
// Diposer
protected override void Dispose(bool disposing)
{
// Clean up
// Done
base.Dispose(disposing);
}
#endregion
#region ================== Overrides
// Paint method
protected override void OnPaint(PaintEventArgs pe)
{
/*
// Copy area that needs to be redrawn
if(img != null)
{
pe.Graphics.FillRectangle(Brushes.Black, pe.ClipRectangle);
pe.Graphics.DrawImage(img, pe.ClipRectangle, pe.ClipRectangle, GraphicsUnit.Pixel);
}
*/
// Pass on to base
// Do we really want this?
base.OnPaint(pe);
}
#endregion
#region ================== Methods
// This sets the render source
public void SetImageSource(Image srcimg)
{
// Set new source image
img = srcimg;
this.Image = img;
}
// This sets up the control to display the splash logo
public void SetSplashLogoDisplay()
{
// Remove render image
this.img = null;
// Change display to show splash logo
this.SetStyle(ControlStyles.SupportsTransparentBackColor, false);
this.SetStyle(ControlStyles.ContainerControl, false);
this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
this.SetStyle(ControlStyles.UserPaint, true);
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
this.SetStyle(ControlStyles.Opaque, false);
this.UpdateStyles();
this.BackColor = System.Drawing.SystemColors.AppWorkspace;
this.BackgroundImage = global::CodeImp.DoomBuilder.Properties.Resources.Splash2;
this.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center;
this.Image = null;
}
// This sets up the control for manual rendering
public void SetManualRendering()
{
// Change display for rendering
/*
this.SetStyle(ControlStyles.SupportsTransparentBackColor, false);
this.SetStyle(ControlStyles.ContainerControl, false);
this.SetStyle(ControlStyles.OptimizedDoubleBuffer, false);
this.SetStyle(ControlStyles.UserPaint, true);
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
this.SetStyle(ControlStyles.Opaque, true);
*/
this.SetStyle(ControlStyles.SupportsTransparentBackColor, false);
this.SetStyle(ControlStyles.ContainerControl, false);
this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
this.SetStyle(ControlStyles.UserPaint, true);
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
this.SetStyle(ControlStyles.Opaque, false);
this.UpdateStyles();
this.BackColor = Color.Black;
this.BackgroundImage = null;
this.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;
//this.BackgroundImage = global::CodeImp.DoomBuilder.Properties.Resources.floor0_3;
//this.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Tile;
this.Image = img;
}
#endregion
}
}

View file

@ -34,19 +34,39 @@ namespace CodeImp.DoomBuilder.Interface
{
internal class ResourceListView : ListView
{
#region ================== Constants
private const string DRAG_TYPE = "ReorderItems";
#endregion
#region ================== Variables
// List of items
private List<ListViewItem> dragitems;
#endregion
#region ================== Properties
// Disable sorting
public new SortOrder Sorting { get { return SortOrder.None; } set { base.Sorting = SortOrder.None; } }
#endregion
#region ================== Constructor
// Constructor
public ResourceListView(): base()
{
// List for dragged items
dragitems = new List<ListViewItem>();
}
#endregion
#region ================== Overrides
// When items are dropped
protected override void OnDragDrop(DragEventArgs e)
{
@ -246,6 +266,10 @@ namespace CodeImp.DoomBuilder.Interface
}
}
#endregion
#region ================== Methods
// This deselects all items
private void DeselectAll()
{
@ -256,5 +280,7 @@ namespace CodeImp.DoomBuilder.Interface
base.SelectedItems[i].Selected = false;
}
}
#endregion
}
}

View file

@ -30,6 +30,7 @@ using SlimDX.Direct3D;
using System.ComponentModel;
using CodeImp.DoomBuilder.Geometry;
using SlimDX;
using CodeImp.DoomBuilder.Interface;
#endregion
@ -50,7 +51,7 @@ namespace CodeImp.DoomBuilder.Rendering
private int adapter;
// Main objects
private Panel rendertarget;
private RenderTargetControl rendertarget;
private Capabilities devicecaps;
private Device device;
private Renderer2D renderer2d;
@ -68,7 +69,7 @@ namespace CodeImp.DoomBuilder.Rendering
public bool IsDisposed { get { return isdisposed; } }
public Renderer2D Renderer2D { get { return renderer2d; } }
public Renderer3D Renderer3D { get { return renderer3d; } }
public Panel RenderTarget { get { return rendertarget; } }
public RenderTargetControl RenderTarget { get { return rendertarget; } }
public Viewport Viewport { get { return viewport; } }
#endregion
@ -76,7 +77,7 @@ namespace CodeImp.DoomBuilder.Rendering
#region ================== Constructor / Disposer
// Constructor
public D3DGraphics(Panel rendertarget)
public D3DGraphics(RenderTargetControl rendertarget)
{
// Set render target
this.rendertarget = rendertarget;

View file

@ -92,7 +92,7 @@ namespace CodeImp.DoomBuilder.Rendering
if(!isdisposed)
{
// Clean up
graphics.RenderTarget.BackgroundImage = null;
graphics.RenderTarget.SetImageSource(null);
if(image != null) image.Dispose();
pixels = null;
@ -110,7 +110,7 @@ namespace CodeImp.DoomBuilder.Rendering
public override void Reset()
{
// Trash old image
graphics.RenderTarget.BackgroundImage = null;
graphics.RenderTarget.SetImageSource(null);
if(image != null) image.Dispose();
// Re-create image memory
@ -125,12 +125,12 @@ namespace CodeImp.DoomBuilder.Rendering
height = graphics.RenderTarget.ClientSize.Height;
// Trash old image
graphics.RenderTarget.BackgroundImage = null;
graphics.RenderTarget.SetImageSource(null);
if(image != null) image.Dispose();
// Allocate memory
image = new Bitmap(width, height, PixelFormat.Format32bppArgb);
graphics.RenderTarget.BackgroundImage = image;
graphics.RenderTarget.SetImageSource(image);
}
// This begins a drawing session