示例#1
0
文件: Version.cpp 项目: fjz13/Medusa
bool Version::TryParse(const StringRef& versionString, Version& outVersion)
{
	outVersion = Version::Zero;
	List<HeapString> parts;
	StringParser::Split(versionString, StringRef("."), parts);

	uint length = (uint)parts.Count();
	RETURN_FALSE_IF(length < 2 || length>4);

	long outMajor;
	if (parts[0].TryParseInt(outMajor))
	{
		outVersion.SetMajor((uint)outMajor);
	}
	else
	{
		return false;
	}

	long outMinor;
	if (parts[1].TryParseInt(outMinor))
	{
		outVersion.SetMinor((uint)outMinor);
	}
	else
	{
		return false;
	}

	length -= 2;
	if (length > 0)
	{
		long outBuild;
		if (parts[2].TryParseInt(outBuild))
		{
			outVersion.SetBuild((uint)outBuild);
		}
		else
		{
			return false;
		}

		--length;
		if (length > 0)
		{
			long outRevision;
			if (parts[3].TryParseInt(outRevision))
			{
				outVersion.SetRevision((uint)outRevision);
			}
			else
			{
				return false;
			}
		}
	}

	return true;
}
示例#2
0
bool SkylineBinPack::RectangleFits(int skylineNodeIndex, const Size2U& size, uint &outY) const
{
    RETURN_FALSE_IF(mLines[skylineNodeIndex].Origin.X + size.Width > mBinSize.Width);
    outY = mLines[skylineNodeIndex].Origin.Y;

    int widthLeft = size.Width;
    while (widthLeft > 0)
    {
        outY = Math::Max(outY, mLines[skylineNodeIndex].Origin.Y);
        RETURN_FALSE_IF(outY + size.Height > mBinSize.Height);

        widthLeft -= mLines[skylineNodeIndex].Width;
        ++skylineNodeIndex;
        assert(skylineNodeIndex < (int)mLines.Count() || widthLeft <= 0);
    }
    return true;
}
示例#3
0
bool DynamicAtlasRGBAImage::AddImageRect(const Size2U& size,int pitch,const MemoryData& imageData, PixelType pixelType,
								  Rect2U& outRect, bool isFlipY/*=false*/,GraphicsPixelConvertMode mode/*=PixelConvertMode::Normal*/)
{
	RETURN_FALSE_IF(size>mMaxImageSize);
	outRect=mPack.Insert(size,SkylineBinPack::LevelChoiceHeuristic::LevelBottomLeft);
	if (outRect!=Rect2U::Zero)
	{
		outRect.Size-=1;	//should -1 to remove edge
		CopyImage(outRect,imageData,pixelType,pitch,isFlipY,mode);
		return true;
	}

	RETURN_FALSE_IF(mImageSize>=mMaxImageSize);	//is full


	//try to expand
	//1.new a bigger image
	Size2U newImageSize=mImageSize;
	do 
	{
		newImageSize.Width=Math::Min((uint)Math::NextPOT(newImageSize.Width),mMaxImageSize.Width);
		newImageSize.Height=Math::Min((uint)Math::NextPOT(newImageSize.Height),mMaxImageSize.Width);
		mPack.GrowSize(mImageSize);	//not re layout the original rects,maybe do it in the future
		outRect=mPack.Insert(size,SkylineBinPack::LevelChoiceHeuristic::LevelBottomLeft);
		if (outRect!=Rect2U::Zero)
		{
			MemoryData newImageData=MemoryData::Alloc(mImageSize.Area()*BytesPerComponent());
			//2.copy image data to new image

			ImageFactory::CopyImage(newImageData,mPixelType,newImageSize,Rect2U(Point2F::Zero,mImageSize),mImageData, mPixelType,0,false,GraphicsPixelConvertMode::Normal);
			mImageSize=newImageSize;
			mImageData=newImageData;

			//draw new image
			outRect.Size-=1;//should -1 to remove edge
			CopyImage(outRect,imageData,pixelType,pitch,isFlipY,mode);
			return true;
		}

	} while (newImageSize<mMaxImageSize);

	return false;
}
示例#4
0
bool CanvasPanel::ArrangeChildren(const Rect2F& limitRect/*=Rect2F::Zero*/, NodeLayoutArrangeFlags arrangeFlags/*=NodeLayoutArrangeFlags::None*/)
{
	RETURN_FALSE_IF(mIsCollapsed);

	for (auto child : mNodes)
	{
		child->ArrangeRecursively(Rect2F::Zero);
	}

	return true;
}
示例#5
0
bool BlockReadStream::Seek(intp offset, SeekOrigin direction /*= SeekOrigin::Current*/)const
{
	switch (direction)
	{
	case SeekOrigin::Head:
	{
		RETURN_FALSE_IF(offset<0||(uintp)offset > Length());
		uint blockIndex = (uint)offset / (uint32)mBuffer.Length();
		uint pos = offset % (uint32)mBuffer.Length();

		if (mBlockIndex != blockIndex)
		{
			mBlockIndex = blockIndex;
			LoadCurrentBlock();
			mBuffer.SetPosition(pos);
		}
		else
		{
			mBuffer.SetPosition(pos);
		}

		return true;
	}
	case SeekOrigin::Current:
	{
		intp pos = (intp)Position();
		pos += offset;
		if (pos < 0 || (uintp)pos >= Length())
		{
			return false;
		}

		return Seek(pos, SeekOrigin::Head);
	}
	case SeekOrigin::End:
	{
		offset += Length();
		if (offset < 0 || (uintp)offset >= Length())
		{
			return false;
		}
		return Seek(offset, SeekOrigin::Head);
	}
	default:
		break;
	}
	return false;
}
/* virtual */ OP_BOOLEAN
SVGDOMMatrixTransformImpl::SetValue(int idx, double x)
{
	SVGMatrix tmp;
	m_transform->GetMatrix(tmp);

	if (m_transform->GetTransformType() != SVGTRANSFORM_MATRIX)
	{
		m_transform->SetMatrix(tmp);
	}
	else
	{
		RETURN_FALSE_IF(tmp[idx] == SVGNumber(x));
	}

	m_transform->values[idx] = SVGNumber(x);
	return OpBoolean::IS_TRUE;
}
示例#7
0
bool BehaviorConfig::LoadFromData(const FileIdRef& fileId, const MemoryData& data, uint format /*= 0*/)
{
	Unload();
	RETURN_FALSE_IF(data.IsNull());

	pugi::xml_document doc;
	pugi::xml_parse_result result = doc.load_buffer(data.Data(), data.Size());
	if (!result)
	{
		Log::AssertFailedFormat("Cannot parse xml:{} because {}", fileId, result.description());
		return false;
	}
	for (const auto& child : doc.first_child().children())
	{
		StringRef typeName = child.name();
		StringRef id = child.attribute("Id").value();
		if (id.IsEmpty())
		{
			id = typeName;
		}

#ifdef MEDUSA_SAFE_CHECK
		if (ContainsId(id))
		{
			Log::AssertFailedFormat("Duplicate id:{} in {}", id.c_str(), typeName.c_str());
		}
#endif

		IBehavior* behavior = BehaviorFactory::Instance().SmartCreate(typeName);
		behavior->LoadFromXmlNode(child);
		behavior->Initialize();
		if (id.EndWith("Behavior"))
		{
			Add(id, behavior);
		}
		else
		{
			Add(id + "Behavior", behavior);
		}
	}


	return true;
}
示例#8
0
bool ITimelineModel::TryGetFrame(float time, uint& outPrevFrameIndex, uint& outNextFrameIndex, float& outPercent, uint startIndex /*= 0*/) const
{
	if (mIsPrecomputed)
	{
		RETURN_FALSE_IF(time < 0.f);

		float index = time *mFPS;
		outNextFrameIndex = (int)Math::Ceil(index);
		double integer;
		outPercent = (float)Math::Mod(index, &integer);
		outPrevFrameIndex = (int)integer;
	}
	else
	{
		return TryGetFrameHelper(time, outPrevFrameIndex, outNextFrameIndex, outPercent, startIndex);
	}
	return true;

}
示例#9
0
bool PODNode::TryGetMatrix( float frame,Matrix4& outMatrix ) const
{
	outMatrix.LoadIdentity();
	RETURN_FALSE_IF(frame<0.f);

	uint frameIndex=(uint)frame;
	float frameBlend=frame-(float)frameIndex;

	outMatrix=Matrix4::Identity;

	if (!AnimationMatrixes.IsEmpty())
	{
		GetMatrix(frameIndex,outMatrix);
	}
	else
	{
		GetScaleMatrix(frameIndex,frameBlend,outMatrix);
		GetRotateMatrix(frameIndex,frameBlend,outMatrix);
		GetTranslateMatrix(frameIndex,frameBlend,outMatrix);
	}

	return true;
}