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 - detlion1643

Pages: [1]
1
Graphics / Re: [2.1] Custom drawing shapes
« on: July 18, 2014, 07:50:44 pm »
... Thanks Laurent. That fixed up the custom class based off sf::Shape.

It's mostly meant as a learning experience for right now. Gotta start somewhere. Thanks for the gui links though, I might end up with one of them for now.

It took me a lot of learning to even get my framework project up and running with my main project. With includes/links/etc.

I've got lots more learning to do, but this is a great start. Thanks again guys!

2
Graphics / Re: [2.1] Custom drawing shapes
« on: July 18, 2014, 05:26:43 pm »
Here is where I based my custom class off of: https://github.com/SFML/SFML/wiki/Source:-Draw-Rounded-Rectangle

Here is my class:
namespace Graphics
        {

                class RoundedRectangle : public sf::Shape
                {
                        private:
                                sf::Vector2f size;
                                float cornerradius;
                                unsigned int cornerpoints;
                        public:
                                RoundedRectangle(int, int, sf::Vector2f, int, unsigned int, float, sf::Color);
                                void setSize(const sf::Vector2f& Size);
                                const sf::Vector2f& getSize();
                                void setCornerRadius(float CornerRadius);
                                float getCornerRadius();
                                void setCornerPoints(unsigned int CornerPoints);
                                virtual unsigned int getPointCount();
                                virtual sf::Vector2f getPoint(unsigned int Index);
                };

        }

Implementation:
#pragma region Graphics

                EZFile::Graphics::RoundedRectangle::RoundedRectangle(int Left, int Top, sf::Vector2f Size, int CornerRadius, unsigned int CornerPoints, float OutlineThickness, sf::Color OutlineColor)
                {
                        setPosition(Left, Top);
                        size = Size;
                        cornerradius = CornerRadius;
                        cornerpoints = CornerPoints;
                        setOutlineThickness(OutlineThickness);
                        setOutlineColor(OutlineColor);
                        update();

                }
                void EZFile::Graphics::RoundedRectangle::setSize(const sf::Vector2f& Size)
                {
                        size = Size;
                        update();
                }

                const sf::Vector2f& EZFile::Graphics::RoundedRectangle::getSize()
                {
                        return size;
                }

                void EZFile::Graphics::RoundedRectangle::setCornerRadius(float CornerRadius)
                {
                        cornerradius = CornerRadius;
                        update();
                }

                float EZFile::Graphics::RoundedRectangle::getCornerRadius()
                {
                        return cornerradius;
                }

                void EZFile::Graphics::RoundedRectangle::setCornerPoints(unsigned int CornerPoints)
                {
                        cornerpoints = CornerPoints;
                }

                unsigned int EZFile::Graphics::RoundedRectangle::getPointCount()
                {
                        return cornerpoints * 4;
                }

                sf::Vector2f EZFile::Graphics::RoundedRectangle::getPoint(unsigned int Index)
                {
                        if(Index >= cornerpoints*4)
                                return sf::Vector2f(0,0);

                        float deltaAngle = 90.0f/(cornerpoints-1);
                        sf::Vector2f center;
                        unsigned int centerIndex = Index/cornerpoints;
                        unsigned int offset = 0;
                        static const float pi = 3.141592654f;

                        switch(centerIndex)
                        {
                                case 0: center.x = size.x - cornerradius; center.y = cornerradius; break;
                                case 1: center.x = cornerradius; center.y = cornerradius; break;
                                case 2: center.x = cornerradius; center.y = size.y - cornerradius; break;
                                case 3: center.x = size.x - cornerradius; center.y = size.y - cornerradius; break;
                        }

                        return sf::Vector2f(cornerradius*cos(deltaAngle*(Index-centerIndex)*pi/180)+center.x,
                        cornerradius*sin(deltaAngle*(Index-centerIndex)*pi/180)-center.y);
                }

#pragma endregion Graphics

And how I'm trying to use it (based on the first line of the example in the link:
/// Usage example:
/// \code
/// sf::RoundedRectangleShape roundedRectangle;
/// ....

EZFile::Graphics::RoundedRectangle shp;


Here is the other link I looked at:http://en.sfml-dev.org/forums/index.php?topic=973.0

This is just the beginning of a variety of controls I am making. My first control (button) will make a normal rectangle, but if it has a cornerradius of greater than 0, it uses that and makes a rounded rectangle instead. I'm planning on lots of controls (checkboxes, radio buttons, scrollable lists) with each one having options of different styles/etc.

3
Graphics / [2.1] Custom drawing shapes
« on: July 18, 2014, 04:09:57 pm »
Hello everyone,

Obligatory first post "thanks for the great libraries"!

With that out of the way, I have found a couple of posts and a wiki page regarding rounded rectangle shapes. However, none of them make sense anymore as I believe something must've been changed with sf::Shape in SFML 2.1. All of the examples create a new class inheriting from sf::Shape (or even previously from that creating an sf::Shape).

So I went about creating an entire class that inherits from sf::Shape (based on the example in the wiki). After everything was done, creating a new instance of that class results in an error message: "object of abstract class type ***::***::RoundedRectangle is not allowed:"

Now I'm still new to c++ (know a ton of c# and used to override .Net paint events (GID/GDI+) to custom draw controls) but I feel like I just gotta reach out to the forum here...

I'm unsure where to go from here. From reading, it seems like I'd have to plot every usable point and use a vertex array with the sf::LineStrip primitive to connect them all? If so, any ideas for plotting the points on the corners? Is there a different better way?

Pages: [1]