Patch by Artur Wyszynski:
* Implemented BGradient, BGradientLinear, BGradientRadial, BGradientDiamond, BGradientConic and BGradientRadialFocus new Interface Kit classes. * Implemented all the (AGG-based) backend necessary in the app_server to render gradients (Painter, DrawingEngine) * app_server/View can convert a BGradient layout to screen coordinates. * Added BGradient methods of the Fill* methods in BView. * Implemented a test app and added it to the image as a demo. * Adopted Icon-O-Matic and libs/icon in order to avoid clashing with the new BGradient class. Re-use some parts where possible. Awesome work, Artur! Thanks a lot. Now a more modern looking GUI has just become much easier to implement! :-) TODO: * Remove the need to have gradient type twice in the app_server protocol. * Refactor some parts of the patch to remove duplicated code (Painter, DrawingEngine). * Adopt the BPicture protocol to know about BGradients. * Review some parts of the BArchivable implementation. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@28109 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
* Copyright 2006-2008, Haiku.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Stephan Aßmus <[email protected]>
|
||||
* Artur Wyszynski <[email protected]>
|
||||
*/
|
||||
|
||||
#ifndef GRADIENT_H
|
||||
#define GRADIENT_H
|
||||
|
||||
#include <Archivable.h>
|
||||
#include <GraphicsDefs.h>
|
||||
#include <List.h>
|
||||
|
||||
|
||||
class BMessage;
|
||||
class BRect;
|
||||
|
||||
|
||||
enum gradient_type {
|
||||
B_GRADIENT_LINEAR = 0,
|
||||
B_GRADIENT_RADIAL,
|
||||
B_GRADIENT_RADIAL_FOCUS,
|
||||
B_GRADIENT_DIAMOND,
|
||||
B_GRADIENT_CONIC,
|
||||
B_GRADIENT_NONE
|
||||
};
|
||||
|
||||
|
||||
struct color_step {
|
||||
color_step(const rgb_color c, float o);
|
||||
color_step(uint8 r, uint8 g, uint8 b, uint8 a, float o);
|
||||
color_step(const color_step& other);
|
||||
color_step();
|
||||
|
||||
bool operator!=(const color_step& other) const;
|
||||
|
||||
rgb_color color;
|
||||
float offset;
|
||||
};
|
||||
|
||||
|
||||
class BGradient : public BArchivable {
|
||||
public:
|
||||
BGradient();
|
||||
BGradient(BMessage* archive);
|
||||
virtual ~BGradient();
|
||||
|
||||
status_t Archive(BMessage* into, bool deep = true) const;
|
||||
|
||||
BGradient& operator=(const BGradient& other);
|
||||
|
||||
bool operator==(const BGradient& other) const;
|
||||
bool operator!=(const BGradient& other) const;
|
||||
bool ColorStepsAreEqual(const BGradient& other) const;
|
||||
|
||||
void SetColors(const BGradient& other);
|
||||
|
||||
int32 AddColor(const rgb_color& color, float offset);
|
||||
bool AddColor(const color_step& color, int32 index);
|
||||
|
||||
bool RemoveColor(int32 index);
|
||||
|
||||
bool SetColor(int32 index, const color_step& step);
|
||||
bool SetColor(int32 index, const rgb_color& color);
|
||||
bool SetOffset(int32 index, float offset);
|
||||
|
||||
int32 CountColors() const;
|
||||
color_step* ColorAt(int32 index) const;
|
||||
color_step* ColorAtFast(int32 index) const;
|
||||
color_step* Colors() const;
|
||||
void SortColorStepsByOffset();
|
||||
|
||||
gradient_type Type() const
|
||||
{ return fType; }
|
||||
|
||||
void MakeEmpty();
|
||||
|
||||
private:
|
||||
friend class BGradientLinear;
|
||||
friend class BGradientRadial;
|
||||
friend class BGradientRadialFocus;
|
||||
friend class BGradientDiamond;
|
||||
friend class BGradientConic;
|
||||
|
||||
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;
|
||||
|
||||
BList fColors;
|
||||
gradient_type fType;
|
||||
};
|
||||
|
||||
#endif // GRADIENT_H
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright 2006-2008, Haiku.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Artur Wyszynski <[email protected]>
|
||||
*/
|
||||
|
||||
#ifndef GRADIENT_CONIC_H
|
||||
#define GRADIENT_CONIC_H
|
||||
|
||||
#include <Gradient.h>
|
||||
|
||||
class BPoint;
|
||||
|
||||
class BGradientConic : public BGradient {
|
||||
public:
|
||||
BGradientConic();
|
||||
BGradientConic(const BPoint& center, float angle);
|
||||
BGradientConic(float cx, float cy, float angle);
|
||||
|
||||
BPoint Center() const;
|
||||
void SetCenter(const BPoint& center);
|
||||
void SetCenter(float cx, float cy);
|
||||
|
||||
float Angle() const;
|
||||
void SetAngle(float angle);
|
||||
};
|
||||
|
||||
#endif // GRADIENT_CONIC_H
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright 2006-2008, Haiku.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Artur Wyszynski <[email protected]>
|
||||
*/
|
||||
|
||||
#ifndef GRADIENT_DIAMOND_H
|
||||
#define GRADIENT_DIAMOND_H
|
||||
|
||||
#include <Gradient.h>
|
||||
|
||||
class BPoint;
|
||||
|
||||
class BGradientDiamond : public BGradient {
|
||||
public:
|
||||
BGradientDiamond();
|
||||
BGradientDiamond(const BPoint& center);
|
||||
BGradientDiamond(float cx, float cy);
|
||||
|
||||
BPoint Center() const;
|
||||
void SetCenter(const BPoint& center);
|
||||
void SetCenter(float cx, float cy);
|
||||
};
|
||||
|
||||
#endif // GRADIENT_DIAMOND_H
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright 2006-2008, Haiku.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Artur Wyszynski <[email protected]>
|
||||
*/
|
||||
|
||||
#ifndef GRADIENT_LINEAR_H
|
||||
#define GRADIENT_LINEAR_H
|
||||
|
||||
#include <Gradient.h>
|
||||
|
||||
class BPoint;
|
||||
|
||||
class BGradientLinear : public BGradient {
|
||||
public:
|
||||
BGradientLinear();
|
||||
BGradientLinear(const BPoint& start, const BPoint& end);
|
||||
BGradientLinear(float x1, float y1, float x2, float y2);
|
||||
|
||||
BPoint Start() const;
|
||||
void SetStart(const BPoint& start);
|
||||
void SetStart(float x1, float y1);
|
||||
|
||||
BPoint End() const;
|
||||
void SetEnd(const BPoint& end);
|
||||
void SetEnd(float x2, float y2);
|
||||
};
|
||||
|
||||
#endif // GRADIENT_LINEAR_H
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright 2006-2008, Haiku.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Artur Wyszynski <[email protected]>
|
||||
*/
|
||||
|
||||
#ifndef GRADIENT_RADIAL_H
|
||||
#define GRADIENT_RADIAL_H
|
||||
|
||||
#include <Gradient.h>
|
||||
|
||||
class BPoint;
|
||||
|
||||
class BGradientRadial : public BGradient {
|
||||
public:
|
||||
BGradientRadial();
|
||||
BGradientRadial(const BPoint& center, float radius);
|
||||
BGradientRadial(float cx, float cy, float radius);
|
||||
|
||||
BPoint Center() const;
|
||||
void SetCenter(const BPoint& center);
|
||||
void SetCenter(float cx, float cy);
|
||||
|
||||
float Radius() const;
|
||||
void SetRadius(float radius);
|
||||
};
|
||||
|
||||
#endif // GRADIENT_RADIAL_H
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright 2006-2008, Haiku.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Artur Wyszynski <[email protected]>
|
||||
*/
|
||||
|
||||
#ifndef GRADIENT_RADIAL_FOCUS_H
|
||||
#define GRADIENT_RADIAL_FOCUS_H
|
||||
|
||||
#include <Gradient.h>
|
||||
|
||||
class BPoint;
|
||||
|
||||
class BGradientRadialFocus : public BGradient {
|
||||
public:
|
||||
BGradientRadialFocus();
|
||||
BGradientRadialFocus(const BPoint& center, float radius,
|
||||
const BPoint& focal);
|
||||
BGradientRadialFocus(float cx, float cy, float radius, float fx, float fy);
|
||||
|
||||
BPoint Center() const;
|
||||
void SetCenter(const BPoint& center);
|
||||
void SetCenter(float cx, float cy);
|
||||
|
||||
BPoint Focal() const;
|
||||
void SetFocal(const BPoint& focal);
|
||||
void SetFocal(float fx, float fy);
|
||||
|
||||
float Radius() const;
|
||||
void SetRadius(float radius);
|
||||
};
|
||||
|
||||
#endif // GRADIENT_RADIAL_FOCUS_H
|
||||
@@ -16,6 +16,7 @@
|
||||
#include <InterfaceDefs.h>
|
||||
#include <Rect.h>
|
||||
#include <Size.h>
|
||||
#include <Gradient.h>
|
||||
|
||||
|
||||
// mouse button
|
||||
@@ -317,7 +318,13 @@ public:
|
||||
pattern p = B_SOLID_HIGH);
|
||||
void FillPolygon(const BPoint* ptArray, int32 numPts,
|
||||
BRect bounds, pattern p = B_SOLID_HIGH);
|
||||
|
||||
void FillPolygon(const BPolygon* polygon,
|
||||
const BGradient& gradient);
|
||||
void FillPolygon(const BPoint* ptArray, int32 numPts,
|
||||
const BGradient& gradient);
|
||||
void FillPolygon(const BPoint* ptArray, int32 numPts,
|
||||
BRect bounds, const BGradient& gradient);
|
||||
|
||||
void StrokeTriangle(BPoint pt1, BPoint pt2, BPoint pt3,
|
||||
BRect bounds, pattern p = B_SOLID_HIGH);
|
||||
void StrokeTriangle(BPoint pt1, BPoint pt2, BPoint pt3,
|
||||
@@ -326,17 +333,26 @@ public:
|
||||
pattern p = B_SOLID_HIGH);
|
||||
void FillTriangle(BPoint pt1, BPoint pt2, BPoint pt3,
|
||||
BRect bounds, pattern p = B_SOLID_HIGH);
|
||||
void FillTriangle(BPoint pt1, BPoint pt2, BPoint pt3,
|
||||
const BGradient& gradient);
|
||||
void FillTriangle(BPoint pt1, BPoint pt2, BPoint pt3,
|
||||
BRect bounds, const BGradient& gradient);
|
||||
|
||||
void StrokeRect(BRect r, pattern p = B_SOLID_HIGH);
|
||||
void FillRect(BRect r, pattern p = B_SOLID_HIGH);
|
||||
void FillRect(BRect r, const BGradient& gradient);
|
||||
void FillRegion(BRegion* region,
|
||||
pattern p = B_SOLID_HIGH);
|
||||
void FillRegion(BRegion* region,
|
||||
const BGradient& gradient);
|
||||
void InvertRect(BRect r);
|
||||
|
||||
void StrokeRoundRect(BRect r, float xRadius,
|
||||
float yRadius, pattern p = B_SOLID_HIGH);
|
||||
void FillRoundRect(BRect r, float xRadius, float yRadius,
|
||||
pattern p = B_SOLID_HIGH);
|
||||
void FillRoundRect(BRect r, float xRadius, float yRadius,
|
||||
const BGradient& gradient);
|
||||
|
||||
void StrokeEllipse(BPoint center, float xRadius,
|
||||
float yRadius, pattern p = B_SOLID_HIGH);
|
||||
@@ -344,7 +360,10 @@ public:
|
||||
void FillEllipse(BPoint center, float xRadius,
|
||||
float yRadius, pattern p = B_SOLID_HIGH);
|
||||
void FillEllipse(BRect r, pattern p = B_SOLID_HIGH);
|
||||
|
||||
void FillEllipse(BPoint center, float xRadius,
|
||||
float yRadius, const BGradient& gradient);
|
||||
void FillEllipse(BRect r, const BGradient& gradient);
|
||||
|
||||
void StrokeArc(BPoint center, float xRadius,
|
||||
float yRadius, float startAngle, float arcAngle,
|
||||
pattern p = B_SOLID_HIGH);
|
||||
@@ -355,15 +374,23 @@ public:
|
||||
pattern p = B_SOLID_HIGH);
|
||||
void FillArc(BRect r, float startAngle, float arcAngle,
|
||||
pattern p = B_SOLID_HIGH);
|
||||
|
||||
void FillArc(BPoint center, float xRadius, float yRadius,
|
||||
float startAngle, float arcAngle,
|
||||
const BGradient& gradient);
|
||||
void FillArc(BRect r, float startAngle, float arcAngle,
|
||||
const BGradient& gradient);
|
||||
|
||||
void StrokeBezier(BPoint* controlPoints,
|
||||
pattern p = B_SOLID_HIGH);
|
||||
void FillBezier(BPoint* controlPoints,
|
||||
pattern p = B_SOLID_HIGH);
|
||||
void FillBezier(BPoint* controlPoints,
|
||||
const BGradient& gradient);
|
||||
|
||||
void StrokeShape(BShape* shape,
|
||||
pattern p = B_SOLID_HIGH);
|
||||
void FillShape(BShape* shape, pattern p = B_SOLID_HIGH);
|
||||
void FillShape(BShape* shape, const BGradient& gradient);
|
||||
|
||||
void CopyBits(BRect src, BRect dst);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user