Hi!
I've recently started using SFML for the .NET platform and everything has gone smooth so far. Since the reason for
me using SFML with C# instead of C++ is because C# offers (IMO) better support and ease when creating window applications.
As you might all know; to be able to draw in a Windows Form with SFML you have to connect a SFML
device (RenderWindow in this case) with a Window Control. I wanted to do this in a structured way so I chose to make
a class controlling the drawing. So far it looks like this:
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using SFML;
using SFML.Graphics;
using SFML.Window;
namespace X_C_Sharp
{
class SFMLPanel : Panel
{
RenderWindow _renderWindow;
//SFML.Graphics.View _renderView;
public SFMLPanel() : base()
{
this.SetStyle(ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.Opaque, true);
_renderWindow = new RenderWindow(this.Handle);
//_renderWindow.CurrentView.SetFromRect(new FloatRect(0, 0, this.Width, this.Height));
}
protected override void OnPaint(PaintEventArgs e)
{
_renderWindow.Clear(new Color(255, 255, 255));
base.OnPaint(e);
_renderWindow.Display();
//this.Invalidate();
}
// To be implemented...
protected override void OnResize(EventArgs eventargs)
{
base.OnResize(eventargs);
}
public void Draw(Drawable objectToDraw)
{
_renderWindow.Draw(objectToDraw);
}
public void Draw(PostFx postFX)
{
_renderWindow.Draw(postFX);
}
}
}
As of now I think this class provides the required functions which I need though there are a few drawbacks which I haven't been able
to solve (the reason for me posting this thread). You can think of this new panel (replacing System.Windows.Forms.Panel) as 2 objects; a layout
and a drawing area (this is where SFML comes into the picture). The problem is that the SFML area i stretched to fit the layout (Panel area).
For example; when I increase the panel size I do not want the SFML area (its size) to stretch but instead increase its size (bigger drawing area).
Currently all pictures and shapes which are drawn is stretched and none of them has the specified size (the size which I specify in pixels).
What I though could be a solution was altering the RenderWindow view (commented out) but all my attempts altering the view has been in vain.
The size of the view seems to be constant (though I just assume since I haven't been working much at all with SFML).