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:
Stephan Aßmus
2008-10-14 21:27:42 +00:00
parent 9e6975723d
commit 991547ef6c
57 changed files with 3458 additions and 125 deletions
+2
View File
@@ -50,6 +50,7 @@ class ServerLink {
status_t AttachString(const char *string, int32 length = -1);
status_t AttachRegion(const BRegion &region);
status_t AttachShape(BShape &shape);
status_t AttachGradient(const BGradient &gradient);
template <class Type> status_t Attach(const Type& data);
// receive methods
@@ -63,6 +64,7 @@ class ServerLink {
status_t ReadString(char **string);
status_t ReadRegion(BRegion *region);
status_t ReadShape(BShape *shape);
status_t ReadGradient(BGradient *gradient);
template <class Type> status_t Read(Type *data);
// convenience methods
@@ -219,14 +219,23 @@ enum {
AS_STROKE_TRIANGLE,
AS_FILL_ARC,
AS_FILL_ARC_GRADIENT,
AS_FILL_BEZIER,
AS_FILL_BEZIER_GRADIENT,
AS_FILL_ELLIPSE,
AS_FILL_ELLIPSE_GRADIENT,
AS_FILL_POLYGON,
AS_FILL_POLYGON_GRADIENT,
AS_FILL_RECT,
AS_FILL_RECT_GRADIENT,
AS_FILL_REGION,
AS_FILL_REGION_GRADIENT,
AS_FILL_ROUNDRECT,
AS_FILL_ROUNDRECT_GRADIENT,
AS_FILL_SHAPE,
AS_FILL_SHAPE_GRADIENT,
AS_FILL_TRIANGLE,
AS_FILL_TRIANGLE_GRADIENT,
AS_MOVEPENBY,
AS_MOVEPENTO,
+110
View File
@@ -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
+30
View File
@@ -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
+27
View File
@@ -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
+31
View File
@@ -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
+30
View File
@@ -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
+30 -3
View File
@@ -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);
+2
View File
@@ -15,6 +15,7 @@
class BString;
class BRegion;
class BGradient;
namespace BPrivate {
@@ -37,6 +38,7 @@ class LinkReceiver {
status_t ReadString(BString& string, size_t* _length = NULL);
status_t ReadString(char* buffer, size_t bufferSize);
status_t ReadRegion(BRegion* region);
status_t ReadGradient(BGradient *gradient);
template <class Type> status_t Read(Type *data)
{ return Read(data, sizeof(Type)); }
+3
View File
@@ -17,6 +17,7 @@
class BShape;
class BString;
class BGradient;
/*
* Error checking rules: (for if you don't want to check every return code)
@@ -49,6 +50,7 @@ class ServerLink {
status_t AttachString(const char *string, int32 length = -1);
status_t AttachRegion(const BRegion &region);
status_t AttachShape(BShape &shape);
status_t AttachGradient(const BGradient &gradient);
template <class Type> status_t Attach(const Type& data);
// receive methods
@@ -64,6 +66,7 @@ class ServerLink {
status_t ReadString(char** _string, size_t* _length = NULL);
status_t ReadRegion(BRegion *region);
status_t ReadShape(BShape *shape);
status_t ReadGradient(BGradient *gradient);
template <class Type> status_t Read(Type *data);
// convenience methods
+9
View File
@@ -218,14 +218,23 @@ enum {
AS_STROKE_TRIANGLE,
AS_FILL_ARC,
AS_FILL_ARC_GRADIENT,
AS_FILL_BEZIER,
AS_FILL_BEZIER_GRADIENT,
AS_FILL_ELLIPSE,
AS_FILL_ELLIPSE_GRADIENT,
AS_FILL_POLYGON,
AS_FILL_POLYGON_GRADIENT,
AS_FILL_RECT,
AS_FILL_RECT_GRADIENT,
AS_FILL_REGION,
AS_FILL_REGION_GRADIENT,
AS_FILL_ROUNDRECT,
AS_FILL_ROUNDRECT_GRADIENT,
AS_FILL_SHAPE,
AS_FILL_SHAPE_GRADIENT,
AS_FILL_TRIANGLE,
AS_FILL_TRIANGLE_GRADIENT,
AS_DRAW_STRING,
AS_DRAW_STRING_WITH_DELTA,