Esempio n. 1
0
// 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;
}
Esempio n. 2
0
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(&center, 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(&center, 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(&center, 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(&center, sizeof(BPoint));
			fSender->Attach(&angle, sizeof(float));
			break;
		}
		case BGradient::TYPE_NONE:
		{
			GTRACE(("ServerLink::AttachGradient> type == TYPE_NONE\n"));
			break;
		}
	}
	return B_OK;
}