Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: .Net resize window [Solved]  (Read 5145 times)

0 Members and 3 Guests are viewing this topic.

Mad Engineer

  • Newbie
  • *
  • Posts: 26
    • View Profile
    • Email
.Net resize window [Solved]
« on: January 19, 2014, 04:17:40 pm »
I want to know how to re-size view when i re-size pictureBox.

This is my code so far, but it doesn't work well:

private RenderWindow window = null;

SFML.Graphics.View view = new SFML.Graphics.View();

window = new RenderWindow(pictureBox1.Handle);

view.Reset(new FloatRect(0f, 0f, pictureBox1.Width, pictureBox1.Height));
           
window.SetView(view);

private void Form1_Resize(object sender, EventArgs e)
{
            view.Reset(new FloatRect(0f, 0f, pictureBox1.Width, pictureBox1.Height));
            window.SetView(view);
 
}

When i start program everything is great, but when i re-size window(pictureBox) all Sprites start to get wider when i reduce size and smaller when i increase size.
« Last Edit: January 19, 2014, 06:42:50 pm by Mad Engineer »

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: .Net resize window
« Reply #1 on: January 19, 2014, 05:17:20 pm »
Are you sure the resized event handler gets called?

And also, maybe you should handle the picture box resized instead of the form resized (since SFML is hosted in the picturebox and not the form).
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

Mad Engineer

  • Newbie
  • *
  • Posts: 26
    • View Profile
    • Email
Re: .Net resize window
« Reply #2 on: January 19, 2014, 05:25:06 pm »
Yes it is called i tested it with changing text in label. And i have tried to put it in pictureBox_Resize but still get same result;

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: .Net resize window
« Reply #3 on: January 19, 2014, 05:45:12 pm »
Can you post a complete and minimal example (something that I can copy and paste) that shows the problem? I have a few ideas what may be wrong, but first I need to see how you handle your form/drawing/events.
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

Mad Engineer

  • Newbie
  • *
  • Posts: 26
    • View Profile
    • Email
Re: .Net resize window
« Reply #4 on: January 19, 2014, 05:54:49 pm »
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using SFML.Window;
using SFML.Graphics;

namespace Test
{
    public partial class Form1 : Form
    {
        private RenderWindow window = null;

        SFML.Graphics.View view = new SFML.Graphics.View();

        float mousePositionXpictureBox;
        float mousePositionYpictureBox;

        float mousePositionXMap;
        float mousePositionYMap;

        bool mouseInRender = false;

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            window = new RenderWindow(pictureBox1.Handle);

            view.Reset(new FloatRect(0f, 0f, pictureBox1.Width, pictureBox1.Height));
            window.SetView(view);

            timer1.Enabled = true;

        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            window.Clear(SFML.Graphics.Color.Red);

            //DRAW BEGIN

           

            //DRAW END
            window.Display();

            if (mouseInRender == true)
            {
                if (mousePositionXpictureBox < 100)
                {
                    view.Move(new Vector2f(-5f, 0f));
                    window.SetView(view);
                   
                }
                if (mousePositionXpictureBox > pictureBox1.Width - 100f)
                {
                    view.Move(new Vector2f(5f, 0f));
                    window.SetView(view);
                   
                }

                if (mousePositionYpictureBox < 100)
                {
                    view.Move(new Vector2f(0f, -5f));
                    window.SetView(view);
                   
                }
                if (mousePositionYpictureBox > pictureBox1.Height - 100f)
                {
                    view.Move(new Vector2f(0, 5f));
                    window.SetView(view);
                   
                }
            }

           

        }

        private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
        {
            mousePositionXpictureBox = e.X;
            mousePositionYpictureBox = e.Y;

            mousePositionXMap = e.X + view.Center.X - pictureBox1.Width / 2;
            mousePositionYMap = e.Y + view.Center.Y - pictureBox1.Height / 2;

        }

        private void pictureBox1_MouseLeave(object sender, EventArgs e)
        {
            mouseInRender = false;
        }

        private void pictureBox1_MouseEnter(object sender, EventArgs e)
        {
            mouseInRender = true;
        }

        private void Form1_Resize(object sender, EventArgs e)
        {
            view.Reset(new FloatRect(0f, 0f, pictureBox1.Width, pictureBox1.Height));
            window.SetView(view);
        }

    }
}

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: .Net resize window
« Reply #5 on: January 19, 2014, 06:11:05 pm »
In your timer1_Tick you need to call window.DispatchEvents().

Also, I don't recommend using a timer to do your SFML drawing. I recommend you initialize SFML from outside the form as in the example I posted here. This can have a standard drawing loop with WinForms.  ;)
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

Mad Engineer

  • Newbie
  • *
  • Posts: 26
    • View Profile
    • Email
Re: .Net resize window
« Reply #6 on: January 19, 2014, 06:13:52 pm »
omg , dat line of code XD . Ty so much for help :D