Gradient



Gradient class. Use it to store gradient properties of your controls. It shouldn't be overrided because the renderer implementation depends on it.

Gradient require at least 2 points to be drawn. Each point has coordinate and color. Coordinate should be in range 0..1. Depending on gradient type you may draw gradients shown below. In following illustration the first point has green color and the second one has red color.

Gradient types

You can find more information in comments below. Overrided methods can be found in corresponding base class.

class Gradient: public CFeedback
{
public:
    enum TYPE // Supported gradient types
    {
        gtHorizontal = 0, // Horizontal(from left to right)
        gtVertical = 1, // Vertical(from top to bottom)
        gtRadial = 2, // Radial(from center)
        gtDiagonalDown = 3, // From left-top to right-bottom
        gtDiagonalUp = 4, // From left-bottom to right-top
        gtCircle = 5 // The same as gtRadial but drawing appears only inside circle which radius is maximum of width and height of the rectangle where drawing is
    };

    struct POINT // Gradient point
    {
        float Position; // Position in range 0..1
        nitisa::Color Color; // Point color

        bool is_equal(const POINT &other, const float tolerance = Tolerance) const; // Check points are equal
        bool is_not_equal(const POINT &other, const float tolerance = Tolerance) const; // Check points are not equal
    };

    using Points = std::vector<POINT>;
public:
    TYPE getType() const; // Return type
    int getPointCount() const; // Return point count
    POINT getPoint(const int index) const; // Return point by index
    Color getColor(float position); // Return calculated color at specified position(position is in range 0..1)
    const Points &getSortedPoints(); // Return points sorted by position

    bool setType(const TYPE value); // Set type
    bool setPointCount(const int count); // Set point count
    bool setPoints(const int count, POINT *points); // Set points
    bool setPoint(const int index, const POINT value); // Set point
    bool setPoint(const int index, const float position, const Color color); // Set point
    bool setPointPosition(const int index, const float position); // Set point position
    bool setPointColor(const int index, const Color color); // Set point color
    // Since 5.0.0
    bool setPoints(const std::vector<POINT> &points); // Set points

    Gradient();
    Gradient(Callback callback, void *param); // Create with callback informing about changes
    Gradient(const Gradient &other);
    Gradient(Gradient &&other);

    Gradient &operator=(const Gradient &other);
    Gradient &operator=(Gradient &&other);

    bool isEqual(Gradient &other, const float tolerance = Tolerance); // Check whether gradients are equal
    bool isNotEqual(Gradient &other, const float tolerance = Tolerance); // Check whether gradients are not equal

    void AddPoint(const float position, const Color &color); // Add new point
    bool DeletePoint(const int index); // Delete point by index
    bool Clear(); // Delete all points
};

Following operators are also available.

std::wostream &operator<<(std::wostream &stream, const Gradient &a); // Output as source code
Namespace: nitisa
Include: Nitisa/Core/Gradient.h