Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
Offline Matasx  
#1 Posted : Wednesday, October 9, 2013 8:34:49 AM(UTC)
Matasx

Joined: 8/30/2013(UTC)
Posts: 43

Thanks: 11 times
Was thanked: 1 time(s) in 1 post(s)
Hi, is it possible to have render inside WinForms. E.g. in panel or some component?
Thanks.

Wanna join the discussion?! Login to your forum accountregister a new account. Or Connect via Facebook Twitter Google

Offline Flavio Damasco  
#2 Posted : Thursday, October 10, 2013 10:06:25 AM(UTC)
Flavio Damasco

Joined: 5/15/2013(UTC)
Posts: 45
Location: Hannover

Was thanked: 2 time(s) in 2 post(s)
Hi, I am informing my colleagues of this support request ;)
UserPostedImage
Offline Steve  
#3 Posted : Thursday, October 10, 2013 10:51:10 AM(UTC)
Steve

Joined: 5/6/2013(UTC)
Posts: 15

Was thanked: 2 time(s) in 2 post(s)
Originally Posted by: Matasx Go to Quoted Post
Hi, is it possible to have render inside WinForms. E.g. in panel or some component?
Thanks.


Yes. We are doing it in the Editor.
Since WPF is not able to do this, we are using a WindowsFormsHost within WPF to host the Rendering.

Have a look at the WindowsFormsHost ViewportHost and its usages,
as well as the WpfHostedFormsWindow
Offline Matasx  
#4 Posted : Thursday, October 10, 2013 12:12:36 PM(UTC)
Matasx

Joined: 8/30/2013(UTC)
Posts: 43

Thanks: 11 times
Was thanked: 1 time(s) in 1 post(s)
Ok, that sounds great. ThumpUp But, I'm using pure old WinForms (no WPF) - is it somehow possible?
Offline Benjamin  
#5 Posted : Thursday, October 10, 2013 8:14:45 PM(UTC)
Benjamin

Medals: Admin

Joined: 8/20/2011(UTC)
Posts: 1,421
Location: Hannover

Thanks: 18 times
Was thanked: 97 time(s) in 92 post(s)
Yes, very easy to do so. Every time you start an app on Windows it is rendered in a WinForms control, on WPF we use the WpfHostedFormsWindow as described by Steve.

Do you want us to provide a full sample how to use the FormsWindow as a panel in Forms window? If so please provide us with some code so we can guide you in the correct direction.

Basically you just derive from FormsWindow and use the FormsWindow(Control panel) constructor to set the panel you want to use for rendering. Then you create your Delta Engine App at initialization time in your Forms window via: new App(Window windowToRegister) (see WindowsOpenTK project or the Editor as an example)
Offline Matasx  
#6 Posted : Thursday, October 10, 2013 8:37:42 PM(UTC)
Matasx

Joined: 8/30/2013(UTC)
Posts: 43

Thanks: 11 times
Was thanked: 1 time(s) in 1 post(s)
Originally Posted by: Benjamin Nitschke Go to Quoted Post
Basically you just derive from FormsWindow and use the FormsWindow(Control panel) constructor to set the panel you want to use for rendering. Then you create your Delta Engine App at initialization time in your Forms window via: new App(Window windowToRegister) (see WindowsOpenTK project or the Editor as an example)


Thanks for your advice, but I need more hints.
Quote:
Basically you just derive from FormsWindow.

What class should I derive from FormsWindow? My form must be derived from System.Windows.Forms.Form and C# does not support multiple inheritance.
Offline Benjamin  
#7 Posted : Thursday, October 10, 2013 9:02:16 PM(UTC)
Benjamin

Medals: Admin

Joined: 8/20/2011(UTC)
Posts: 1,421
Location: Hannover

Thanks: 18 times
Was thanked: 97 time(s) in 92 post(s)
Just create a new class like the WpfHostedFormsWindow (which is derived from FormsWindow too, but not a WPF or WinForms thingy).

Then you create it inside your Forms window and use new App(window) and .Run to start the DE. If you could create a small application I can help better to inject the code at the right place. Then we can also include it as an example in the DE release.
Offline Matasx  
#8 Posted : Thursday, October 10, 2013 9:08:42 PM(UTC)
Matasx

Joined: 8/30/2013(UTC)
Posts: 43

Thanks: 11 times
Was thanked: 1 time(s) in 1 post(s)
Ok, here is what I'm trying to do (I know, I'm doing it wrong).
Code:
    public partial class Form1 : Form
    {
        private PanelRender Delta;
        public Form1()
        {
            InitializeComponent();
            Delta = new PanelRender(panel1);
            new App(); //v0.9.9.4 has no arguments and it is abstract class!
        }

        protected class PanelRender : FormsWindow
        {
            public PanelRender(Control panel) : base(panel)
            {
            }
        }
    }
Offline Benjamin  
#9 Posted : Friday, October 11, 2013 7:06:22 PM(UTC)
Benjamin

Medals: Admin

Joined: 8/20/2011(UTC)
Posts: 1,421
Location: Hannover

Thanks: 18 times
Was thanked: 97 time(s) in 92 post(s)
Here is an example for you (included in the next Delta Engine release also). It shows a line rendered with the Delta Engine on a plain Forms window:

Code:

	public partial class ExampleForm : Form
	{
		public ExampleForm()
		{
			InitializeComponent();
			Show();
			new RenderApp(new RenderPanel(panel1));
		}
	}

	public class RenderPanel : FormsWindow
	{
		public RenderPanel(Control panel)
			: base(panel)
		{
		}
	}

	public class RenderApp : App
	{
		public RenderApp(RenderPanel renderPanel)
			: base(renderPanel)
		{
			new Line2D(Vector2D.Zero, Vector2D.One, Color.Yellow);
			Run();
		}
	}


Screenshot and full source code + project files are attached.
File Attachment(s):
WindowsFormsExample.zip (5kb) downloaded 2 time(s).
Benjamin attached the following image(s):
WindowsFormsExample.png (4kb) downloaded 1 time(s).

You cannot view/download attachments. Try to login or register.
thanks 1 user thanked Benjamin for this useful post.
Matasx on 10/11/2013(UTC)
Offline Matasx  
#10 Posted : Friday, October 11, 2013 9:01:03 PM(UTC)
Matasx

Joined: 8/30/2013(UTC)
Posts: 43

Thanks: 11 times
Was thanked: 1 time(s) in 1 post(s)
It is strange. App has no constructor with one parameter. Neither protected.

Code:
// Assembly DeltaEngine.WindowsSharpDX.dll, v0.9.9.4

using System;

namespace DeltaEngine.Platforms
{
    public abstract class App
    {
        protected App();

        protected T Resolve<T>() where T : class;
        protected void Run();
    }
}
Offline ollimorp  
#11 Posted : Saturday, October 12, 2013 2:02:15 AM(UTC)
ollimorp

Joined: 7/22/2013(UTC)
Posts: 13

Thanks: 1 times
Was thanked: 2 time(s) in 2 post(s)
Hi Matasx,

you´re right. This implementation of the App-Class just exists in the OpenTK-DLL:

Code:

/// <summary>
	/// Initializes the OpenTK20Resolver and the window to get started. To execute the app call Run.
	/// </summary>
	public abstract class App
	{
		protected App() {}

		internal App(Window windowToRegister)
		{
			resolver.RegisterInstance(windowToRegister);
		}

		private readonly OpenTK20Resolver resolver = new OpenTK20Resolver();

		protected void Run()
		{
			resolver.Run();
		}

		protected internal T Resolve<T>() where T : class
		{
			return resolver.Resolve<T>();
		}
	}
}


Due to the internal-scope of the "RegisterInstance(windowToRegister)"-Method, you have to extend the original DeltaEngine.WindowsSharpDX assembly with your custom App-class (the code above) and add your DLL-reference to your project.

thanks 1 user thanked ollimorp for this useful post.
Matasx on 10/12/2013(UTC)
Offline Matasx  
#12 Posted : Saturday, October 12, 2013 3:15:51 PM(UTC)
Matasx

Joined: 8/30/2013(UTC)
Posts: 43

Thanks: 11 times
Was thanked: 1 time(s) in 1 post(s)
Ok. With your help, I've managed to run it even under SharpDX. But, when I close main form, it throws an expcetion in program Main entry (Application.Run(new Form1()); or new Form1().ShowDialog(); - it doesn't matter)
Code:
System.ObjectDisposedException was unhandled
  HResult=-2146232798
  Message=K uvolněnému objektu nelze přistupovat. (=Cannot access to disposed object)
Název objektu: Form1
  Source=System.Windows.Forms
  ObjectName=Form1
  StackTrace:
       v System.Windows.Forms.Control.CreateHandle()
       v System.Windows.Forms.Form.CreateHandle()
       v System.Windows.Forms.Control.get_Handle()
       v System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       v System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       v System.Windows.Forms.Application.RunDialog(Form form)
       v System.Windows.Forms.Form.ShowDialog(IWin32Window owner)
       v System.Windows.Forms.Form.ShowDialog()
       v DeltaExperiments.Program.Main() v ..\DeltaExperiments\Program.cs:řádek 41
       v System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       v System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       v Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       v System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       v System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       v System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       v System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       v System.Threading.ThreadHelper.ThreadStart()
Offline Benjamin  
#13 Posted : Monday, October 14, 2013 2:15:07 AM(UTC)
Benjamin

Medals: Admin

Joined: 8/20/2011(UTC)
Posts: 1,421
Location: Hannover

Thanks: 18 times
Was thanked: 97 time(s) in 92 post(s)
I forgot to mention that we made that OpenTK App constructor public so it is easier to use it. We have only tested it with OpenTK, the other frameworks will also work, but are not tested well and might have more issues (like the one you mentioned via SharpDX).

In the next release you can find a more complete example in the Samples folder. In the meantime please modify the App.cs file in WindowsOpenTK yourself and let me know if you can get it all to work.
Rss Feed  Atom Feed
Users browsing this topic
OceanSpiders 2.0
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Powered by YAF.NET | YAF.NET © 2003-2018, Yet Another Forum.NET
This page was generated in 0.213 seconds.