Esempio n. 1
0
/*	Even if the subclass overrides onInflate, they should always be
	sure to call the inherited method, so that we get called.
*/
void SkView::onInflate(const SkDOM& dom, const SkDOM::Node* node)
{
	SkScalar x, y;

	x = this->locX();
	y = this->locY();
	(void)dom.findScalar(node, "x", &x);
	(void)dom.findScalar(node, "y", &y);
	this->setLoc(x, y);

	x = this->width();
	y = this->height();
	(void)dom.findScalar(node, "width", &x);
	(void)dom.findScalar(node, "height", &y);
	this->setSize(x, y);

	// inflate the flags

	static const char* gFlagNames[] = {
		"visible", "enabled", "focusable", "flexH", "flexV"
	};
	SkASSERT(SK_ARRAY_COUNT(gFlagNames) == kFlagShiftCount);

	bool     b;
	uint32_t flags = this->getFlags();
	for (unsigned i = 0; i < SK_ARRAY_COUNT(gFlagNames); i++)
		if (dom.findBool(node, gFlagNames[i], &b))
			flags = SkSetClearShift(flags, b, i);
	this->setFlags(flags);
}
void SkPaint_Inflate(SkPaint* paint, const SkDOM& dom, const SkDOM::Node* node)
{
	SkASSERT(paint);
	SkASSERT(&dom);
	SkASSERT(node);

	SkScalar x;

	if (dom.findScalar(node, "stroke-width", &x))
		paint->setStrokeWidth(x);
	if (dom.findScalar(node, "text-size", &x))
		paint->setTextSize(x);
	
	bool	b;

	SkASSERT("legacy: use is-stroke" && !dom.findBool(node, "is-frame", &b));

	if (dom.findBool(node, "is-stroke", &b))
		paint->setStyle(b ? SkPaint::kStroke_Style : SkPaint::kFill_Style);
	if (dom.findBool(node, "is-antialias", &b))
		paint->setAntiAlias(b);
	if (dom.findBool(node, "is-lineartext", &b))
		paint->setLinearText(b);

	const char* str = dom.findAttr(node, "color");
	if (str)
	{
		SkColor	c = paint->getColor();
		if (SkParse::FindColor(str, &c))
			paint->setColor(c);
	}

	// do this AFTER parsing for the color
	if (dom.findScalar(node, "opacity", &x))
	{
		x = SkMaxScalar(0, SkMinScalar(x, SK_Scalar1));
		paint->setAlpha(SkScalarRound(x * 255));
	}

	int	index = dom.findList(node, "text-anchor", "left,center,right");
	if (index >= 0)
		paint->setTextAlign((SkPaint::Align)index);

	SkShader* shader = inflate_shader(dom, node);
	if (shader)
		paint->setShader(shader)->unref();
}
void SkListView::onInflate(const SkDOM& dom, const SkDOM::Node* node)
{
	this->INHERITED::onInflate(dom, node);
	
	{
		bool hasScrollBar;
		if (dom.findBool(node, "scrollBar", &hasScrollBar))
			this->setHasScrollBar(hasScrollBar);
	}

	const SkDOM::Node*	child;

	if ((child = dom.getFirstChild(node, "bindings")) != NULL)
	{
		delete[] fBindings;
		fBindings = NULL;
		fBindingCount = 0;

		SkListSource* listSrc = SkListSource::Factory(dom.findAttr(child, "data-fields"));
		SkASSERT(listSrc);
		fSkinName.set(dom.findAttr(child, "skin-slots"));
		SkASSERT(fSkinName.size());

		this->setListSource(listSrc)->unref();
			
		int count = dom.countChildren(child, "bind");
		if (count > 0)
		{
			fBindings = new BindingRec[count];
			count = 0;	// reuse this to count up to the number of valid bindings

			child = dom.getFirstChild(child, "bind");
			SkASSERT(child);
			do {
				const char* fieldName = dom.findAttr(child, "field");
				const char* slotName = dom.findAttr(child, "slot");
				if (fieldName && slotName)
				{
					fBindings[count].fFieldIndex = listSrc->findFieldIndex(fieldName);
					if (fBindings[count].fFieldIndex >= 0)
						fBindings[count++].fSlotName.set(slotName);
				}
			} while ((child = dom.getNextSibling(child, "bind")) != NULL);

			fBindingCount = SkToU16(count);
			if (count == 0)
			{
				SkDEBUGF(("SkListView::onInflate: no valid <bind> elements in <listsource>\n"));
				delete[] fBindings;
			}
		}
		this->dirtyCache(kAnimCount_DirtyFlag);
		this->setSelection(0);
	}
}
Esempio n. 4
0
void SkTextView::onInflate(const SkDOM& dom, const SkDOM::Node* node)
{
	this->INHERITED::onInflate(dom, node);

	const char* text = dom.findAttr(node, "text");
	if (text)
		this->setText(text);

	SkPoint	margin;
	if (dom.findScalars(node, "margin", (SkScalar*)&margin, 2))
		this->setMargin(margin);
	(void)dom.findBool(node, "do-interp", &fDoInterp);

	SkPaint_Inflate(&fPaint, dom, node);
}
void SkProgressView::onInflate(const SkDOM& dom, const SkDOM::Node* node)
{
    this->INHERITED::onInflate(dom, node);

    const char* s;

    SkASSERT(fOnShader == NULL);
    SkASSERT(fOffShader == NULL);

    if ((s = dom.findAttr(node, "src-on")) != NULL)
        fOnShader = inflate_shader(s);
    if ((s = dom.findAttr(node, "src-off")) != NULL)
        fOffShader = inflate_shader(s);
    (void)dom.findBool(node, "do-interp", &fDoInterp);
}