2008-10-15 01:27:42 +04:00
|
|
|
/*
|
2009-08-27 15:12:41 +04:00
|
|
|
* Copyright 2006-2009, Haiku, Inc. All rights reserved.
|
|
|
|
* Distributed under the terms of the MIT License.
|
2008-10-15 01:27:42 +04:00
|
|
|
*/
|
2008-11-08 14:58:54 +03:00
|
|
|
#ifndef _GRADIENT_H
|
|
|
|
#define _GRADIENT_H
|
2008-10-15 01:27:42 +04:00
|
|
|
|
2009-08-26 15:10:23 +04:00
|
|
|
|
2008-10-15 01:27:42 +04:00
|
|
|
#include <Archivable.h>
|
|
|
|
#include <GraphicsDefs.h>
|
|
|
|
#include <List.h>
|
|
|
|
|
|
|
|
|
2020-05-28 03:25:21 +03:00
|
|
|
class BDataIO;
|
2008-10-15 01:27:42 +04:00
|
|
|
class BMessage;
|
|
|
|
class BRect;
|
|
|
|
|
|
|
|
|
2009-08-26 15:10:23 +04:00
|
|
|
// WARNING! This is experimental API and may change! Be prepared to
|
|
|
|
// recompile your software in a next version of haiku. In particular,
|
|
|
|
// the offsets are currently specified on [0..255], but may be changed
|
|
|
|
// to the interval [0..1]. This class also does not have any FBC padding,
|
|
|
|
// So your software will definitely break when this class gets new
|
|
|
|
// virtuals. And the object size may change too...
|
|
|
|
|
|
|
|
|
2008-10-15 01:27:42 +04:00
|
|
|
class BGradient : public BArchivable {
|
2008-11-08 17:56:56 +03:00
|
|
|
public:
|
2009-02-15 18:15:49 +03:00
|
|
|
enum Type {
|
2008-11-08 17:56:56 +03:00
|
|
|
TYPE_LINEAR = 0,
|
|
|
|
TYPE_RADIAL,
|
|
|
|
TYPE_RADIAL_FOCUS,
|
|
|
|
TYPE_DIAMOND,
|
|
|
|
TYPE_CONIC,
|
|
|
|
TYPE_NONE
|
|
|
|
};
|
|
|
|
|
2009-02-15 18:15:49 +03:00
|
|
|
struct ColorStop {
|
|
|
|
ColorStop(const rgb_color c, float o);
|
|
|
|
ColorStop(uint8 r, uint8 g, uint8 b, uint8 a, float o);
|
|
|
|
ColorStop(const ColorStop& other);
|
|
|
|
ColorStop();
|
2020-05-28 03:25:21 +03:00
|
|
|
|
2009-02-15 18:15:49 +03:00
|
|
|
bool operator!=(const ColorStop& other) const;
|
2020-05-28 03:25:21 +03:00
|
|
|
|
2008-11-08 17:56:56 +03:00
|
|
|
rgb_color color;
|
|
|
|
float offset;
|
|
|
|
};
|
|
|
|
|
2008-10-15 01:27:42 +04:00
|
|
|
public:
|
2009-08-26 15:10:23 +04:00
|
|
|
BGradient();
|
2020-08-11 18:43:25 +03:00
|
|
|
BGradient(const BGradient& other);
|
2009-08-26 15:10:23 +04:00
|
|
|
BGradient(BMessage* archive);
|
|
|
|
virtual ~BGradient();
|
2020-05-28 03:25:21 +03:00
|
|
|
|
2009-08-26 15:10:23 +04:00
|
|
|
status_t Archive(BMessage* into,
|
|
|
|
bool deep = true) const;
|
2020-05-28 03:25:21 +03:00
|
|
|
|
2009-08-26 15:10:23 +04:00
|
|
|
BGradient& operator=(const BGradient& other);
|
2020-05-28 03:25:21 +03:00
|
|
|
|
2009-08-26 15:10:23 +04:00
|
|
|
bool operator==(const BGradient& other) const;
|
|
|
|
bool operator!=(const BGradient& other) const;
|
|
|
|
bool ColorStopsAreEqual(
|
|
|
|
const BGradient& other) const;
|
2020-05-28 03:25:21 +03:00
|
|
|
|
2009-08-26 15:10:23 +04:00
|
|
|
void SetColorStops(const BGradient& other);
|
2020-05-28 03:25:21 +03:00
|
|
|
|
2009-08-26 15:10:23 +04:00
|
|
|
int32 AddColor(const rgb_color& color,
|
|
|
|
float offset);
|
|
|
|
bool AddColorStop(const ColorStop& colorStop,
|
|
|
|
int32 index);
|
2020-05-28 03:25:21 +03:00
|
|
|
|
2009-08-26 15:10:23 +04:00
|
|
|
bool RemoveColor(int32 index);
|
2020-05-28 03:25:21 +03:00
|
|
|
|
2009-08-26 15:10:23 +04:00
|
|
|
bool SetColorStop(int32 index,
|
|
|
|
const ColorStop& colorStop);
|
|
|
|
bool SetColor(int32 index, const rgb_color& color);
|
|
|
|
bool SetOffset(int32 index, float offset);
|
2020-05-28 03:25:21 +03:00
|
|
|
|
2009-08-26 15:10:23 +04:00
|
|
|
int32 CountColorStops() const;
|
|
|
|
ColorStop* ColorStopAt(int32 index) const;
|
|
|
|
ColorStop* ColorStopAtFast(int32 index) const;
|
|
|
|
ColorStop* ColorStops() const;
|
|
|
|
void SortColorStopsByOffset();
|
2020-05-28 03:25:21 +03:00
|
|
|
|
2009-08-26 15:10:23 +04:00
|
|
|
Type GetType() const
|
|
|
|
{ return fType; }
|
2020-05-28 03:25:21 +03:00
|
|
|
|
2009-08-26 15:10:23 +04:00
|
|
|
void MakeEmpty();
|
|
|
|
|
2020-05-28 03:25:21 +03:00
|
|
|
status_t Flatten(BDataIO* stream) const;
|
|
|
|
static status_t Unflatten(BGradient *&output, BDataIO* stream);
|
|
|
|
|
2008-10-15 01:27:42 +04:00
|
|
|
private:
|
|
|
|
friend class BGradientLinear;
|
|
|
|
friend class BGradientRadial;
|
|
|
|
friend class BGradientRadialFocus;
|
|
|
|
friend class BGradientDiamond;
|
|
|
|
friend class BGradientConic;
|
|
|
|
|
2009-08-26 15:10:23 +04:00
|
|
|
union {
|
|
|
|
struct {
|
|
|
|
float x1, y1, x2, y2;
|
|
|
|
} linear;
|
|
|
|
struct {
|
|
|
|
float cx, cy, radius;
|
|
|
|
} radial;
|
|
|
|
struct {
|
|
|
|
float cx, cy, fx, fy, radius;
|
|
|
|
} radial_focus;
|
|
|
|
struct {
|
|
|
|
float cx, cy;
|
|
|
|
} diamond;
|
|
|
|
struct {
|
|
|
|
float cx, cy, angle;
|
|
|
|
} conic;
|
|
|
|
} fData;
|
2008-10-15 01:27:42 +04:00
|
|
|
|
2009-08-26 15:10:23 +04:00
|
|
|
BList fColorStops;
|
|
|
|
Type fType;
|
2008-10-15 01:27:42 +04:00
|
|
|
};
|
|
|
|
|
2008-11-08 14:58:54 +03:00
|
|
|
#endif // _GRADIENT_H
|