* min/max visibility scale is now between 0 and 4
* flat icon format optimizes for grays in styles git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@18508 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -23,7 +23,7 @@
|
|||||||
using std::nothrow;
|
using std::nothrow;
|
||||||
|
|
||||||
|
|
||||||
// TODO: put into HaikuCompatibility.h
|
// TODO: put into HaikuBuildCompatibility.h
|
||||||
#ifndef __HAIKU__
|
#ifndef __HAIKU__
|
||||||
# define B_BITMAP_NO_SERVER_LINK 0
|
# define B_BITMAP_NO_SERVER_LINK 0
|
||||||
# define B_BAD_DATA B_ERROR
|
# define B_BAD_DATA B_ERROR
|
||||||
|
|||||||
@@ -20,6 +20,8 @@ enum {
|
|||||||
STYLE_TYPE_SOLID_COLOR = 1,
|
STYLE_TYPE_SOLID_COLOR = 1,
|
||||||
STYLE_TYPE_GRADIENT = 2,
|
STYLE_TYPE_GRADIENT = 2,
|
||||||
STYLE_TYPE_SOLID_COLOR_NO_ALPHA = 3,
|
STYLE_TYPE_SOLID_COLOR_NO_ALPHA = 3,
|
||||||
|
STYLE_TYPE_SOLID_GRAY = 4,
|
||||||
|
STYLE_TYPE_SOLID_GRAY_NO_ALPHA = 5,
|
||||||
|
|
||||||
SHAPE_TYPE_PATH_SOURCE = 10,
|
SHAPE_TYPE_PATH_SOURCE = 10,
|
||||||
|
|
||||||
@@ -33,6 +35,7 @@ enum {
|
|||||||
GRADIENT_FLAG_TRANSFORM = 1 << 1,
|
GRADIENT_FLAG_TRANSFORM = 1 << 1,
|
||||||
GRADIENT_FLAG_NO_ALPHA = 1 << 2,
|
GRADIENT_FLAG_NO_ALPHA = 1 << 2,
|
||||||
GRADIENT_FLAG_16_BIT_COLORS = 1 << 3, // not yet used
|
GRADIENT_FLAG_16_BIT_COLORS = 1 << 3, // not yet used
|
||||||
|
GRADIENT_FLAG_GRAYS = 1 << 4,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
|
|||||||
@@ -170,19 +170,32 @@ _ReadTranslation(LittleEndianBuffer& buffer, Transformable* transformable)
|
|||||||
|
|
||||||
// _ReadColorStyle
|
// _ReadColorStyle
|
||||||
static Style*
|
static Style*
|
||||||
_ReadColorStyle(LittleEndianBuffer& buffer, bool alpha)
|
_ReadColorStyle(LittleEndianBuffer& buffer, bool alpha, bool gray)
|
||||||
{
|
{
|
||||||
rgb_color color;
|
rgb_color color;
|
||||||
if (alpha) {
|
if (alpha) {
|
||||||
|
if (gray) {
|
||||||
|
if (!buffer.Read(color.red)
|
||||||
|
|| !buffer.Read(color.alpha))
|
||||||
|
return NULL;
|
||||||
|
color.green = color.blue = color.red;
|
||||||
|
} else {
|
||||||
if (!buffer.Read((uint32&)color))
|
if (!buffer.Read((uint32&)color))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
color.alpha = 255;
|
color.alpha = 255;
|
||||||
|
if (gray) {
|
||||||
|
if (!buffer.Read(color.red))
|
||||||
|
return NULL;
|
||||||
|
color.green = color.blue = color.red;
|
||||||
|
} else {
|
||||||
if (!buffer.Read(color.red)
|
if (!buffer.Read(color.red)
|
||||||
|| !buffer.Read(color.green)
|
|| !buffer.Read(color.green)
|
||||||
|| !buffer.Read(color.blue))
|
|| !buffer.Read(color.blue))
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return new (nothrow) Style(color);
|
return new (nothrow) Style(color);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -217,6 +230,7 @@ _ReadGradientStyle(LittleEndianBuffer& buffer)
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool alpha = !(gradientFlags & GRADIENT_FLAG_NO_ALPHA);
|
bool alpha = !(gradientFlags & GRADIENT_FLAG_NO_ALPHA);
|
||||||
|
bool gray = gradientFlags & GRADIENT_FLAG_GRAYS;
|
||||||
|
|
||||||
for (int32 i = 0; i < gradientStopCount; i++) {
|
for (int32 i = 0; i < gradientStopCount; i++) {
|
||||||
uint8 stopOffset;
|
uint8 stopOffset;
|
||||||
@@ -226,16 +240,29 @@ _ReadGradientStyle(LittleEndianBuffer& buffer)
|
|||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (alpha) {
|
if (alpha) {
|
||||||
|
if (gray) {
|
||||||
|
if (!buffer.Read(color.red)
|
||||||
|
|| !buffer.Read(color.alpha))
|
||||||
|
return NULL;
|
||||||
|
color.green = color.blue = color.red;
|
||||||
|
} else {
|
||||||
if (!buffer.Read((uint32&)color))
|
if (!buffer.Read((uint32&)color))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
color.alpha = 255;
|
color.alpha = 255;
|
||||||
|
if (gray) {
|
||||||
|
if (!buffer.Read(color.red))
|
||||||
|
return NULL;
|
||||||
|
color.green = color.blue = color.red;
|
||||||
|
} else {
|
||||||
if (!buffer.Read(color.red)
|
if (!buffer.Read(color.red)
|
||||||
|| !buffer.Read(color.green)
|
|| !buffer.Read(color.green)
|
||||||
|| !buffer.Read(color.blue)) {
|
|| !buffer.Read(color.blue)) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
gradient.AddColor(color, stopOffset / 255.0);
|
gradient.AddColor(color, stopOffset / 255.0);
|
||||||
}
|
}
|
||||||
@@ -262,12 +289,22 @@ FlatIconImporter::_ParseStyles(LittleEndianBuffer& buffer,
|
|||||||
Style* style = NULL;
|
Style* style = NULL;
|
||||||
if (styleType == STYLE_TYPE_SOLID_COLOR) {
|
if (styleType == STYLE_TYPE_SOLID_COLOR) {
|
||||||
// solid color
|
// solid color
|
||||||
style = _ReadColorStyle(buffer, true);
|
style = _ReadColorStyle(buffer, true, false);
|
||||||
if (!style)
|
if (!style)
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
} else if (styleType == STYLE_TYPE_SOLID_COLOR_NO_ALPHA) {
|
} else if (styleType == STYLE_TYPE_SOLID_COLOR_NO_ALPHA) {
|
||||||
// solid color without alpha
|
// solid color without alpha
|
||||||
style = _ReadColorStyle(buffer, false);
|
style = _ReadColorStyle(buffer, false, false);
|
||||||
|
if (!style)
|
||||||
|
return B_NO_MEMORY;
|
||||||
|
} else if (styleType == STYLE_TYPE_SOLID_GRAY) {
|
||||||
|
// solid gray plus alpha
|
||||||
|
style = _ReadColorStyle(buffer, true, true);
|
||||||
|
if (!style)
|
||||||
|
return B_NO_MEMORY;
|
||||||
|
} else if (styleType == STYLE_TYPE_SOLID_GRAY_NO_ALPHA) {
|
||||||
|
// solid gray without alpha
|
||||||
|
style = _ReadColorStyle(buffer, false, true);
|
||||||
if (!style)
|
if (!style)
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
} else if (styleType == STYLE_TYPE_GRADIENT) {
|
} else if (styleType == STYLE_TYPE_GRADIENT) {
|
||||||
@@ -452,20 +489,20 @@ _ReadTransformer(LittleEndianBuffer& buffer, VertexSource& source)
|
|||||||
StrokeTransformer* stroke
|
StrokeTransformer* stroke
|
||||||
= new (nothrow) StrokeTransformer(source);
|
= new (nothrow) StrokeTransformer(source);
|
||||||
uint8 width;
|
uint8 width;
|
||||||
uint8 lineJoin;
|
uint8 lineOptions;
|
||||||
uint8 lineCap;
|
|
||||||
uint8 miterLimit;
|
uint8 miterLimit;
|
||||||
// uint8 shorten;
|
// uint8 shorten;
|
||||||
if (!stroke
|
if (!stroke
|
||||||
|| !buffer.Read(width)
|
|| !buffer.Read(width)
|
||||||
|| !buffer.Read(lineJoin)
|
|| !buffer.Read(lineOptions)
|
||||||
|| !buffer.Read(lineCap)
|
|
||||||
|| !buffer.Read(miterLimit)) {
|
|| !buffer.Read(miterLimit)) {
|
||||||
delete stroke;
|
delete stroke;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
stroke->width(width - 128.0);
|
stroke->width(width - 128.0);
|
||||||
|
uint8 lineJoin = lineOptions & 15;
|
||||||
stroke->line_join((agg::line_join_e)lineJoin);
|
stroke->line_join((agg::line_join_e)lineJoin);
|
||||||
|
uint8 lineCap = lineOptions >> 4;
|
||||||
stroke->line_cap((agg::line_cap_e)lineCap);
|
stroke->line_cap((agg::line_cap_e)lineCap);
|
||||||
stroke->miter_limit(miterLimit);
|
stroke->miter_limit(miterLimit);
|
||||||
return stroke;
|
return stroke;
|
||||||
@@ -554,8 +591,8 @@ FlatIconImporter::_ReadPathSourceShape(LittleEndianBuffer& buffer,
|
|||||||
uint8 maxScale;
|
uint8 maxScale;
|
||||||
if (!buffer.Read(minScale) || !buffer.Read(maxScale))
|
if (!buffer.Read(minScale) || !buffer.Read(maxScale))
|
||||||
return NULL;
|
return NULL;
|
||||||
shape->SetMinVisibilityScale((float)minScale);
|
shape->SetMinVisibilityScale(minScale / 63.75);
|
||||||
shape->SetMaxVisibilityScale((float)maxScale);
|
shape->SetMaxVisibilityScale(maxScale / 63.75);
|
||||||
}
|
}
|
||||||
|
|
||||||
// transformers
|
// transformers
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ Shape::Shape(::Style* style)
|
|||||||
|
|
||||||
fHinting(false),
|
fHinting(false),
|
||||||
fMinVisibilityScale(0.0),
|
fMinVisibilityScale(0.0),
|
||||||
fMaxVisibilityScale(255.0)
|
fMaxVisibilityScale(4.0)
|
||||||
|
|
||||||
#ifdef ICON_O_MATIC
|
#ifdef ICON_O_MATIC
|
||||||
, fListeners(8)
|
, fListeners(8)
|
||||||
@@ -203,16 +203,16 @@ Shape::Unarchive(const BMessage* archive)
|
|||||||
// max visibility scale
|
// max visibility scale
|
||||||
if (archive->FindFloat("max visibility scale",
|
if (archive->FindFloat("max visibility scale",
|
||||||
&fMaxVisibilityScale) < B_OK)
|
&fMaxVisibilityScale) < B_OK)
|
||||||
fMaxVisibilityScale = 255.0;
|
fMaxVisibilityScale = 4.0;
|
||||||
|
|
||||||
if (fMinVisibilityScale < 0.0)
|
if (fMinVisibilityScale < 0.0)
|
||||||
fMinVisibilityScale = 0.0;
|
fMinVisibilityScale = 0.0;
|
||||||
if (fMinVisibilityScale > 255.0)
|
if (fMinVisibilityScale > 4.0)
|
||||||
fMinVisibilityScale = 255.0;
|
fMinVisibilityScale = 4.0;
|
||||||
if (fMaxVisibilityScale < 0.0)
|
if (fMaxVisibilityScale < 0.0)
|
||||||
fMaxVisibilityScale = 0.0;
|
fMaxVisibilityScale = 0.0;
|
||||||
if (fMaxVisibilityScale > 255.0)
|
if (fMaxVisibilityScale > 4.0)
|
||||||
fMaxVisibilityScale = 255.0;
|
fMaxVisibilityScale = 4.0;
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
@@ -274,10 +274,10 @@ Shape::MakePropertyObject() const
|
|||||||
object->AddProperty(new BoolProperty(PROPERTY_HINTING, fHinting));
|
object->AddProperty(new BoolProperty(PROPERTY_HINTING, fHinting));
|
||||||
|
|
||||||
object->AddProperty(new FloatProperty(PROPERTY_MIN_VISIBILITY_SCALE,
|
object->AddProperty(new FloatProperty(PROPERTY_MIN_VISIBILITY_SCALE,
|
||||||
fMinVisibilityScale, 0, 255));
|
fMinVisibilityScale, 0, 4));
|
||||||
|
|
||||||
object->AddProperty(new FloatProperty(PROPERTY_MAX_VISIBILITY_SCALE,
|
object->AddProperty(new FloatProperty(PROPERTY_MAX_VISIBILITY_SCALE,
|
||||||
fMaxVisibilityScale, 0, 255));
|
fMaxVisibilityScale, 0, 4));
|
||||||
|
|
||||||
return object;
|
return object;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -193,9 +193,9 @@ StrokeTransformer::MakePropertyObject() const
|
|||||||
miter_limit()));
|
miter_limit()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// shorten
|
// // shorten
|
||||||
object->AddProperty(new FloatProperty(PROPERTY_STROKE_SHORTEN,
|
// object->AddProperty(new FloatProperty(PROPERTY_STROKE_SHORTEN,
|
||||||
shorten()));
|
// shorten()));
|
||||||
|
|
||||||
return object;
|
return object;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user