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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - delio

Pages: 1 [2] 3 4
16
DotNet / Change C++ to C# problem
« on: April 02, 2014, 03:42:39 pm »
Code: [Select]
class TileMap : public sf::Drawable, public sf::Transformable
{
public:

bool load(const std::string& tileset, sf::Vector2u tileSize, const int* tiles, unsigned int width, unsigned int height)
{

if (!m_tileset.loadFromFile(tileset))
return false;


m_vertices.setPrimitiveType(sf::Quads);
m_vertices.resize(width * height * 4);


for (unsigned int i = 0; i < width; ++i)
for (unsigned int j = 0; j < height; ++j)
{

int tileNumber = tiles[i + j * width];

int tu = tileNumber % (m_tileset.getSize().x / tileSize.x);
int tv = tileNumber / (m_tileset.getSize().x / tileSize.x);


sf::Vertex* quad = &m_vertices[(i + j * width) * 4];

quad[0].position = sf::Vector2f(i * tileSize.x, j * tileSize.y);
quad[1].position = sf::Vector2f((i + 1) * tileSize.x, j * tileSize.y);
quad[2].position = sf::Vector2f((i + 1) * tileSize.x, (j + 1) * tileSize.y);
quad[3].position = sf::Vector2f(i * tileSize.x, (j + 1) * tileSize.y);


quad[0].texCoords = sf::Vector2f(tu * tileSize.x, tv * tileSize.y);
quad[1].texCoords = sf::Vector2f((tu + 1) * tileSize.x, tv * tileSize.y);
quad[2].texCoords = sf::Vector2f((tu + 1) * tileSize.x, (tv + 1) * tileSize.y);
quad[3].texCoords = sf::Vector2f(tu * tileSize.x, (tv + 1) * tileSize.y);
}

return true;
}

private:

virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const
{

states.transform *= getTransform();


states.texture = &m_tileset;


target.draw(m_vertices, states);
}

sf::VertexArray m_vertices;
sf::Texture m_tileset;
};
How can I change it to C# language?
like "sf::RenderWindow" in C++ change to "SFML.Graphics.RenderWindow"
What is a structure? Please guide me.

Thanks

18
General / Re: Get SFML renderwindow on label problem
« on: April 01, 2014, 07:02:22 pm »
but I want to display in a Panel. not making new form.

Programing.cs
Code: [Select]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using SFML;
using SFML.Audio;
using SFML.Window;
using SFML.Graphics;

namespace _01_AddingRibbonSupport
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
    }
}

Form1.cs
Code: [Select]
using System;
using System.Windows.Forms;
using RibbonLib;
using RibbonLib.Interop;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SFML;
using SFML.Audio;
using SFML.Window;
using SFML.Graphics;

namespace _01_AddingRibbonSupport
{
    public partial class Form1 : Form, IRibbonForm
    {
        public class DrawingSurface : System.Windows.Forms.Control
        {
            protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
            {
                // don't call base.OnPaint(e) to prevent forground painting
                // base.OnPaint(e);
            }
            protected override void OnPaintBackground(System.Windows.Forms.PaintEventArgs pevent)
            {
                // don't call base.OnPaintBackground(e) to prevent background painting
                //base.OnPaintBackground(pevent);
            }
        }
        private Ribbon _ribbon = new Ribbon();

        public Form1()
        {
            InitializeComponent();

            DrawingSurface rendersurface = new DrawingSurface(); // our control for SFML to draw on
            rendersurface.Size = new System.Drawing.Size(400, 400); // set our SFML surface control size to be 500 width & 500 height
            lblPlaceHolderDescription.Controls.Add(rendersurface); // add the SFML surface control to our form
            rendersurface.Location = new System.Drawing.Point(100, 100); // center our control on the form

            // initialize sfml
            SFML.Graphics.RenderWindow renderwindow = new SFML.Graphics.RenderWindow(rendersurface.Handle); // creates our SFML RenderWindow on our surface control

            // drawing loop
            while (lblPlaceHolderDescription.Visible) // loop while the window is open
            {
                System.Windows.Forms.Application.DoEvents(); // handle form events
                renderwindow.DispatchEvents(); // handle SFML events - NOTE this is still required when SFML is hosted in another window
                renderwindow.Clear(SFML.Graphics.Color.Yellow); // clear our SFML RenderWindow
                renderwindow.Display(); // display what SFML has drawn to the screen
            }
        }
       
        #region IRibbonForm Members

        public IntPtr WindowHandle
        {
            get
            {
                return this.Handle;
            }
        }

        public void RibbonHeightUpdated(int newHeight)
        {
            this.splitContainer1.SplitterDistance = newHeight;
        }

        #endregion

        private void Form1_Load(object sender, EventArgs e)
        {
            _ribbon.InitFramework(this);
        }

        private void Form1_FormClosed(object sender, FormClosedEventArgs e)
        {
            _ribbon.DestroyFramework();
        }
    }
}

Thanks

19
General / Re: Get SFML renderwindow on label problem
« on: April 01, 2014, 05:25:14 pm »
Thanks  :D, I've change architecture from "Any CPU" to "x64"

And I have another problem.
Code from my upper post, can build successfully.
I've call
renderwindow.Clear(SFML.Graphics.Color.Yellow);
but In label won't be yellow. It display white.




I've follow zsbzsb's code
http://en.sfml-dev.org/forums/index.php?topic=9141.msg61848#msg61848
------------------------------------------------------------------
PS.Sorry for posting wrong thread(I just saw it).

20
General / Re: Get SFML renderwindow on label problem
« on: April 01, 2014, 04:58:33 pm »
I'm using window 64-bit.
So I've change all SFML's dll from 32-bit to 64-bit.
It gave new error.

I wonder that handling in label is the right way to show in WinForm?




21
General / Get SFML renderwindow on label problem
« on: April 01, 2014, 04:40:51 pm »
I want to get SFML renderwindow on label in WinForm.
But when I compiled, It gave me an error like this.


This is my code

Programing.cs
Code: [Select]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using SFML;
using SFML.Audio;
using SFML.Window;
using SFML.Graphics;

namespace _01_AddingRibbonSupport
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
    }
}

Form1.cs
Code: [Select]
using System;
using System.Windows.Forms;
using RibbonLib;
using RibbonLib.Interop;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SFML;
using SFML.Audio;
using SFML.Window;
using SFML.Graphics;

namespace _01_AddingRibbonSupport
{
    public partial class Form1 : Form, IRibbonForm
    {
        public class DrawingSurface : System.Windows.Forms.Control
        {
            protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
            {
                // don't call base.OnPaint(e) to prevent forground painting
                // base.OnPaint(e);
            }
            protected override void OnPaintBackground(System.Windows.Forms.PaintEventArgs pevent)
            {
                // don't call base.OnPaintBackground(e) to prevent background painting
                //base.OnPaintBackground(pevent);
            }
        }
        private Ribbon _ribbon = new Ribbon();

        public Form1()
        {
            InitializeComponent();

            DrawingSurface rendersurface = new DrawingSurface(); // our control for SFML to draw on
            rendersurface.Size = new System.Drawing.Size(400, 400); // set our SFML surface control size to be 500 width & 500 height
            lblPlaceHolderDescription.Controls.Add(rendersurface); // add the SFML surface control to our form
            rendersurface.Location = new System.Drawing.Point(100, 100); // center our control on the form

            // initialize sfml
            SFML.Graphics.RenderWindow renderwindow = new SFML.Graphics.RenderWindow(rendersurface.Handle); // creates our SFML RenderWindow on our surface control

            // drawing loop
            while (lblPlaceHolderDescription.Visible) // loop while the window is open
            {
                System.Windows.Forms.Application.DoEvents(); // handle form events
                renderwindow.DispatchEvents(); // handle SFML events - NOTE this is still required when SFML is hosted in another window
                renderwindow.Clear(SFML.Graphics.Color.Yellow); // clear our SFML RenderWindow
                renderwindow.Display(); // display what SFML has drawn to the screen
            }
        }
       
        #region IRibbonForm Members

        public IntPtr WindowHandle
        {
            get
            {
                return this.Handle;
            }
        }

        public void RibbonHeightUpdated(int newHeight)
        {
            this.splitContainer1.SplitterDistance = newHeight;
        }

        #endregion

        private void Form1_Load(object sender, EventArgs e)
        {
            _ribbon.InitFramework(this);
        }

        private void Form1_FormClosed(object sender, FormClosedEventArgs e)
        {
            _ribbon.DestroyFramework();
        }
    }
}

22
Window / Re: MFC and SFML Window problem
« on: March 29, 2014, 03:47:23 pm »
Warning that Qt can't receive any event from SFML. except the mouse click event.

http://www.qtcentre.org/threads/52568-Qt5-native-messages-not-propogated

23
Window / Re: SFML Events in Qt creator
« on: March 26, 2014, 04:36:48 pm »
I found this

http://www.qtcentre.org/threads/52568-Qt5-native-messages-not-propogated

So, Qt don't receive event from third party?

Is there any c++ GUI creator that support all of SFML event?
and easy to use. Please recommend.


24
Window / Re: SFML Events in Qt creator
« on: March 24, 2014, 02:06:33 pm »
I've call endl, but nothing changed.

The Point is I want to mean that Qt can't detect event mouse wheel move.

25
Window / Re: SFML Events in Qt creator
« on: March 24, 2014, 12:35:54 pm »
Void OnUpdate
void MyCanvas::OnUpdate()
{

           while(RenderWindow::pollEvent(event)) {

               if (event.type == sf::Event::MouseWheelMoved)
                           {
                                cout << "works!" << endl ;
                               
                           }
             
            }
           TileMap map;
           if (!map.load("d:/tileset.png", sf::Vector2u(3, 3), level, x * 4, y * 4))
           {
               system("pause");
           }
// Clear screen

RenderWindow::clear(sf::Color::White);
// Rotate the sprite
RenderWindow::draw(map);
mySprite.rotate(myClock.getElapsedTime().asSeconds() * 100.f);

// Draw it
for (int j = 0; j <= x * 4; ++j)
        {

            sf::Vertex outlinex1[2] =
            {
                sf::Vertex(sf::Vector2f(j * 3, 0), sf::Color(154,154,154)),
                sf::Vertex(sf::Vector2f(j * 3, y * 12), sf::Color(154, 154, 154))

            };
            RenderWindow::draw(outlinex1, 2, sf::Lines);

        }
        for (int j = 0; j <= y * 4; ++j)
        {

            sf::Vertex outliney1[2] =
            {
                sf::Vertex(sf::Vector2f(0, j * 3), sf::Color(154, 154, 154)),
                sf::Vertex(sf::Vector2f(x * 12, j * 3), sf::Color(154, 154, 154))

            };
            RenderWindow::draw(outliney1, 2, sf::Lines);
        }
        for (int i = 0; i <= x; ++i)
        {


            sf::Vertex outlinex[2] =
            {
                sf::Vertex(sf::Vector2f(i * 12, 0), sf::Color::Black),
                sf::Vertex(sf::Vector2f(i * 12, y * 12), sf::Color::Black)

            };
            RenderWindow::draw(outlinex, 2, sf::Lines);


        }
        for (int i = 0; i <= y; ++i)
        {
            sf::Vertex outliney[2] =
            {
                sf::Vertex(sf::Vector2f(0, i * 12), sf::Color::Black),
                sf::Vertex(sf::Vector2f(x * 12, i * 12), sf::Color::Black)

            };
            RenderWindow::draw(outliney, 2, sf::Lines);
        }
myClock.restart();
}
 

Function that called OnUpdate
QSFMLCanvas::QSFMLCanvas(QWidget* Parent, const QPoint& Position, const QSize& Size, unsigned int FrameTime) : QWidget(Parent),
myInitialized (false)
{
// Setup some states to allow direct rendering into the widget
setAttribute(Qt::WA_PaintOnScreen);
setAttribute(Qt::WA_OpaquePaintEvent);
setAttribute(Qt::WA_NoSystemBackground);
// Set strong focus to enable keyboard events to be received
setFocusPolicy(Qt::StrongFocus);
// Setup the widget geometry
move(Position);
resize(Size);
// Setup the timer
myTimer.setInterval(FrameTime);
}
QSFMLCanvas::~QSFMLCanvas() {}
void QSFMLCanvas::showEvent(QShowEvent*)
{
if (!myInitialized)
{
// Under X11, we need to flush the commands sent to the server to ensure that
// SFML will get an updated view of the windows
#ifdef Q_WS_X11
//XFlush(QX11Info::display());
#endif
// Create the SFML window with the widget handle
//RenderWindow::create((void *) winId());
RenderWindow::create(reinterpret_cast<sf::WindowHandle>(winId()));
// Let the derived class do its specific stuff
OnInit();
// Setup the timer to trigger a refresh at specified framerate
connect(&myTimer, SIGNAL(timeout()), this, SLOT(repaint()));
myTimer.start();
myInitialized = true;
}
}
QPaintEngine* QSFMLCanvas::paintEngine() const
{
return 0;
}
void QSFMLCanvas::paintEvent(QPaintEvent*)
{
// Let the derived class do its specific stuff
OnUpdate();
// Display on screen
RenderWindow::display();
}
void QSFMLCanvas::OnInit() {}
void QSFMLCanvas::OnUpdate() {}





 


Thanks
 

26
Window / Re: SFML Events in Qt creator
« on: March 24, 2014, 08:12:48 am »
My source code : https://www.mediafire.com/?3yqk3cdi22m5cbv
I don't know what is important part to show to you, So I give all my source.

27
Window / Re: SFML Events in Qt creator
« on: March 23, 2014, 05:34:00 pm »
Anybody know?
Please don't bored my stupid question.
I've really no idea .

28
Graphics / Re: Zoom problem
« on: March 21, 2014, 01:38:18 pm »
You will have to map your Mouse-Coordinates (which are in Pixel on your Monitor) to you World-Coordinates, to get the Mouse-Position in your world.

Something like this :
sf::View view = window.getView();
//If not in fullscreen you have to substract the window-position, since the mouse-position is the pixel on your monitor
sf::Vector2f mousepos = window.mapPixelToCoords(sf::Mouse::getPosition()-window.getPosition());
view.zoom(0.9f);
view.setCenter(mousepos);
window.setView(view);
//set the cursor to your new center
sf::Mouse::setPosition(window.mapCoordsToPixel(mousepos)+ window.getPosition());
Thank you very much

29
Window / SFML Events in Qt creator
« on: March 21, 2014, 08:05:59 am »
I can't use mousewheel event in Qt.

This is my code
 while(RenderWindow::pollEvent(event)) {
if (event.type == sf::Event::MouseWheelMoved)
                           {
                           cout << "work" << endl;

                           }
}

When I scroll my mouse wheel, It won't cout "work".
How can I fix it
Thanks

30
Graphics / Zoom problem
« on: March 19, 2014, 01:43:24 pm »
#ifdef SFML_STATIC
#pragma comment(lib, "glew.lib")
#pragma comment(lib, "freetype.lib")
#pragma comment(lib, "jpeg.lib")
#pragma comment(lib, "opengl32.lib")
#pragma comment(lib, "winmm.lib")
#pragma comment(lib, "gdi32.lib")  
#endif // SFML_STATIC


#include <SFML/Graphics.hpp>

int posx, posy;
sf::View view1;

int main()
{
        sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
       

        sf::CircleShape shape(100.f);
        shape.setFillColor(sf::Color::Green);
        sf::View view1(sf::FloatRect(0, 0, window.getSize().x, window.getSize().y));
        while (window.isOpen())
        {
                sf::Event event;
                while (window.pollEvent(event))
                {
                        if (event.type == sf::Event::Closed)
                                window.close();
                       

                        if (event.type == sf::Event::MouseMoved)
                        {

                                posx = event.mouseMove.x ;
                                posy = event.mouseMove.y ;
                        }

                        if (event.type == sf::Event::MouseWheelMoved)
                        {

                                if (event.mouseWheel.delta >= 1)
                                {
                                        sf::View view1(sf::FloatRect(0.3f, 0.3f, window.getSize().x, window.getSize().y));
                                        view1.zoom(0.3f);
                                        view1.setCenter(posx, posy);
                                        window.setView(view1);
                                }
                                if (event.mouseWheel.delta <= -1)
                                {
                                        sf::View view1(sf::FloatRect(3.f, 3.f, window.getSize().x, window.getSize().y));
                                        view1.zoom(3.f);
                                        view1.setCenter(posx, posy);
                                        window.setView(view1);
                                }


                        }
                        if (event.type == sf::Event::Resized)
                        {
                                sf::FloatRect visibleArea(0, 0, event.size.width, event.size.height);
                                window.setView(sf::View(visibleArea));
                        }
                }

                window.clear();
                window.draw(shape);
                window.display();
               
        }

        return 0;
}

My problem is, It not zoom to area that cursor point.
I have move center of view into right position but It still have problem.

And when I resize window, It will reset zoom and position. How can I still zoom and position when resize window?
Thanks

Pages: 1 [2] 3 4
anything