// SetColorStops void BGradient::SetColorStops(const BGradient& other) { MakeEmpty(); for (int32 i = 0; ColorStop* stop = other.ColorStopAt(i); i++) AddColorStop(*stop, i); }
// ColorStopsAreEqual bool BGradient::ColorStopsAreEqual(const BGradient& other) const { int32 count = CountColorStops(); if (count == other.CountColorStops() && fType == other.fType) { bool equal = true; for (int32 i = 0; i < count; i++) { ColorStop* ourStop = ColorStopAtFast(i); ColorStop* otherStop = other.ColorStopAtFast(i); if (*ourStop != *otherStop) { equal = false; break; } } return equal; } return false; }
status_t CanvasMessage::ReadGradient(BGradient** _gradient) { BGradient::Type type; Read(type); BGradient *gradient = NULL; switch (type) { case BGradient::TYPE_NONE: break; case BGradient::TYPE_LINEAR: { BPoint start, end; Read(start); Read(end); gradient = new(std::nothrow) BGradientLinear(start, end); break; } case BGradient::TYPE_RADIAL: { BPoint center; float radius; Read(center); Read(radius); gradient = new(std::nothrow) BGradientRadial(center, radius); break; } case BGradient::TYPE_RADIAL_FOCUS: { BPoint center, focal; float radius; Read(center); Read(focal); Read(radius); gradient = new(std::nothrow) BGradientRadialFocus(center, radius, focal); break; } case BGradient::TYPE_DIAMOND: { BPoint center; Read(center); gradient = new(std::nothrow) BGradientDiamond(center); break; } case BGradient::TYPE_CONIC: { BPoint center; float angle; Read(center); Read(angle); gradient = new(std::nothrow) BGradientConic(center, angle); break; } } if (gradient == NULL) return B_NO_MEMORY; int32 stopCount; status_t result = Read(stopCount); if (result != B_OK) { delete gradient; return result; } for (int32 i = 0; i < stopCount; i++) { rgb_color color; float offset; Read(color); result = Read(offset); if (result != B_OK) return result; gradient->AddColor(color, offset); } *_gradient = gradient; return B_OK; }
void CanvasMessage::AddGradient(const BGradient& gradient) { Add(gradient.GetType()); switch (gradient.GetType()) { case BGradient::TYPE_NONE: break; case BGradient::TYPE_LINEAR: { const BGradientLinear* linear = dynamic_cast<const BGradientLinear *>(&gradient); if (linear == NULL) return; Add(linear->Start()); Add(linear->End()); break; } case BGradient::TYPE_RADIAL: { const BGradientRadial* radial = dynamic_cast<const BGradientRadial *>(&gradient); if (radial == NULL) return; Add(radial->Center()); Add(radial->Radius()); break; } case BGradient::TYPE_RADIAL_FOCUS: { const BGradientRadialFocus* radialFocus = dynamic_cast<const BGradientRadialFocus *>(&gradient); if (radialFocus == NULL) return; Add(radialFocus->Center()); Add(radialFocus->Focal()); Add(radialFocus->Radius()); break; } case BGradient::TYPE_DIAMOND: { const BGradientDiamond* diamond = dynamic_cast<const BGradientDiamond *>(&gradient); if (diamond == NULL) return; Add(diamond->Center()); break; } case BGradient::TYPE_CONIC: { const BGradientConic* conic = dynamic_cast<const BGradientConic *>(&gradient); if (conic == NULL) return; Add(conic->Center()); Add(conic->Angle()); break; } } int32 stopCount = gradient.CountColorStops(); Add(stopCount); for (int32 i = 0; i < stopCount; i++) { BGradient::ColorStop* stop = gradient.ColorStopAt(i); if (stop == NULL) return; Add(stop->color); Add(stop->offset); } }
status_t ServerLink::AttachGradient(const BGradient& gradient) { GTRACE(("ServerLink::AttachGradient\n")); BGradient::Type gradientType = gradient.GetType(); int32 stopCount = gradient.CountColorStops(); GTRACE(("ServerLink::AttachGradient> color stop count == %d\n", (int)stopCount)); fSender->Attach(&gradientType, sizeof(BGradient::Type)); fSender->Attach(&stopCount, sizeof(int32)); if (stopCount > 0) { for (int i = 0; i < stopCount; i++) { fSender->Attach(gradient.ColorStopAtFast(i), sizeof(BGradient::ColorStop)); } } switch (gradientType) { case BGradient::TYPE_LINEAR: { GTRACE(("ServerLink::AttachGradient> type == TYPE_LINEAR\n")); const BGradientLinear* linear = (BGradientLinear*)&gradient; fSender->Attach(linear->Start()); fSender->Attach(linear->End()); break; } case BGradient::TYPE_RADIAL: { GTRACE(("ServerLink::AttachGradient> type == TYPE_RADIAL\n")); const BGradientRadial* radial = (BGradientRadial*)&gradient; BPoint center = radial->Center(); float radius = radial->Radius(); fSender->Attach(¢er, sizeof(BPoint)); fSender->Attach(&radius, sizeof(float)); break; } case BGradient::TYPE_RADIAL_FOCUS: { GTRACE(("ServerLink::AttachGradient> type == TYPE_RADIAL_FOCUS\n")); const BGradientRadialFocus* radialFocus = (BGradientRadialFocus*)&gradient; BPoint center = radialFocus->Center(); BPoint focal = radialFocus->Focal(); float radius = radialFocus->Radius(); fSender->Attach(¢er, sizeof(BPoint)); fSender->Attach(&focal, sizeof(BPoint)); fSender->Attach(&radius, sizeof(float)); break; } case BGradient::TYPE_DIAMOND: { GTRACE(("ServerLink::AttachGradient> type == TYPE_DIAMOND\n")); const BGradientDiamond* diamond = (BGradientDiamond*)&gradient; BPoint center = diamond->Center(); fSender->Attach(¢er, sizeof(BPoint)); break; } case BGradient::TYPE_CONIC: { GTRACE(("ServerLink::AttachGradient> type == TYPE_CONIC\n")); const BGradientConic* conic = (BGradientConic*)&gradient; BPoint center = conic->Center(); float angle = conic->Angle(); fSender->Attach(¢er, sizeof(BPoint)); fSender->Attach(&angle, sizeof(float)); break; } case BGradient::TYPE_NONE: { GTRACE(("ServerLink::AttachGradient> type == TYPE_NONE\n")); break; } } return B_OK; }
status_t LinkReceiver::ReadGradient(BGradient** _gradient) { GTRACE(("LinkReceiver::ReadGradient\n")); BGradient::Type gradientType; int32 colorsCount; Read(&gradientType, sizeof(BGradient::Type)); status_t status = Read(&colorsCount, sizeof(int32)); if (status != B_OK) return status; BGradient* gradient = gradient_for_type(gradientType); if (!gradient) return B_NO_MEMORY; *_gradient = gradient; if (colorsCount > 0) { BGradient::ColorStop stop; for (int i = 0; i < colorsCount; i++) { if ((status = Read(&stop, sizeof(BGradient::ColorStop))) != B_OK) return status; if (!gradient->AddColorStop(stop, i)) return B_NO_MEMORY; } } switch (gradientType) { case BGradient::TYPE_LINEAR: { GTRACE(("LinkReceiver::ReadGradient> type == TYPE_LINEAR\n")); BGradientLinear* linear = (BGradientLinear*)gradient; BPoint start; BPoint end; Read(&start, sizeof(BPoint)); if ((status = Read(&end, sizeof(BPoint))) != B_OK) return status; linear->SetStart(start); linear->SetEnd(end); return B_OK; } case BGradient::TYPE_RADIAL: { GTRACE(("LinkReceiver::ReadGradient> type == TYPE_RADIAL\n")); BGradientRadial* radial = (BGradientRadial*)gradient; BPoint center; float radius; Read(¢er, sizeof(BPoint)); if ((status = Read(&radius, sizeof(float))) != B_OK) return status; radial->SetCenter(center); radial->SetRadius(radius); return B_OK; } case BGradient::TYPE_RADIAL_FOCUS: { GTRACE(("LinkReceiver::ReadGradient> type == TYPE_RADIAL_FOCUS\n")); BGradientRadialFocus* radialFocus = (BGradientRadialFocus*)gradient; BPoint center; BPoint focal; float radius; Read(¢er, sizeof(BPoint)); Read(&focal, sizeof(BPoint)); if ((status = Read(&radius, sizeof(float))) != B_OK) return status; radialFocus->SetCenter(center); radialFocus->SetFocal(focal); radialFocus->SetRadius(radius); return B_OK; } case BGradient::TYPE_DIAMOND: { GTRACE(("LinkReceiver::ReadGradient> type == TYPE_DIAMOND\n")); BGradientDiamond* diamond = (BGradientDiamond*)gradient; BPoint center; if ((status = Read(¢er, sizeof(BPoint))) != B_OK) return status; diamond->SetCenter(center); return B_OK; } case BGradient::TYPE_CONIC: { GTRACE(("LinkReceiver::ReadGradient> type == TYPE_CONIC\n")); BGradientConic* conic = (BGradientConic*)gradient; BPoint center; float angle; Read(¢er, sizeof(BPoint)); if ((status = Read(&angle, sizeof(float))) != B_OK) return status; conic->SetCenter(center); conic->SetAngle(angle); return B_OK; } case BGradient::TYPE_NONE: { GTRACE(("LinkReceiver::ReadGradient> type == TYPE_NONE\n")); break; } } return B_ERROR; }
// operator== bool BGradient::operator==(const BGradient& other) const { return ((other.GetType() == GetType()) && ColorStopsAreEqual(other)); }