//-----------------------------------------------------------------------
	void CGUIParticleSystemManager::parseNewAffector(const CGUIString& type, DataStreamPtr& stream, CGUIParticleSystem* sys)
	{
		// Create new affector
		CGUIParticleAffector* pAff = sys->addAffector(type);
		// Parse affector details
		CGUIString line;

		while(!stream->eof())
		{
			line = stream->getLine();
			// Ignore comments & blanks
			if (!(line.length() == 0 || line.substr(0,2) == "//"))
			{
				if (line == "}")
				{
					// Finished affector
					break;
				}
				else
				{
					// Attribute
					StringUtil::toLowerCase(line);
					parseAffectorAttrib(line, pAff);
				}
			}
		}
	}
示例#2
0
	int32 StringToValue<int16>( const CGUIString& rString, int16& rValue)
	{
		long value = strtol(rString.c_str(), 0, 10);
		if( value > (long)(std::numeric_limits<int16>::max()))
		{
			GUI_THROW( GUI_FORMAT(
				"[StringToValue[int16]]: Value <%s> exceeds range of destination type",
				rString.c_str()));
			return -1;
		}
		rValue = static_cast<int16>(value);
		return 0;
	}
示例#3
0
	int32 StringToValue<uint8>( const CGUIString& rString, uint8& rValue)
	{
		unsigned long value = strtoul(rString.c_str(), 0, 10);
		if( value > std::numeric_limits<uint8>::max() )
		{
			GUI_THROW( GUI_FORMAT(
				"[StringToValue[uint8]]: Value <%s> exceeds range of destination type",
				rString.c_str()));
			return -1;
		}
		rValue = static_cast<uint8>(value);
		return 0;
	}
示例#4
0
	int32 StringToValue<EImageOrientation>( const CGUIString& rString, EImageOrientation& rValue)
	{
		if( rString == "eImageOrientation_Normal" )
		{
			rValue = eImageOrientation_Normal;
		}
		else if( rString == "eImageOrientation_90CW" )
		{
			rValue = eImageOrientation_90CW;
		}
		else if( rString == "eImageOrientation_90CCW" )
		{
			rValue = eImageOrientation_90CCW;
		}
		else if( rString == "eImageOrientation_FlipHorizon" )
		{
			rValue = eImageOrientation_FlipHorizon;
		}
		else if( rString == "eImageOrientation_FlipVertical" )
		{
			rValue = eImageOrientation_FlipVertical;
		}
		else
		{
			GUI_THROW( GUI_FORMAT(
				"[StringToValue[EImageOrientation]]: string value format is wrong! <%s>",
				rString.c_str()));
			return -1;
		}
		return 0;
	}
示例#5
0
	//------------------------------------------------------------------------------
	void CGUIWgtParticle2D::SetParticle2D( const CGUIString& rParticle2DName )
	{
		GUI_TRACE( GUI_FORMAT( "[CGUIWgtParticle2D::SetParticle2D]: play particle %s", rParticle2DName.c_str()));

		if( rParticle2DName.empty() )
		{
			//clear
			SetParticle2D( NULL );
		}
		else
		{
			CGUIParticle2DSystem* pParticle2D = CGUIParticle2DManager::Instance()->AllocateResource( rParticle2DName );
			SetParticle2D( pParticle2D );
			pParticle2D->RefRelease();
		}
	}
示例#6
0
文件: GUIutil.cpp 项目: Marlinc/0ad
bool __ParseString<CGUIString>(const CStrW& Value, CGUIString &Output)
{
	// TODO: i18n: Might want to translate the Value perhaps

	Output.SetValue(Value);
	return true;
}
示例#7
0
	//------------------------------------------------------------------------------
	int32 CGUIMusicData_openal::DoLoad()
	{
		// identify file type by extension
		CGUIString strExt;
		size_t pos = m_strPath.find_last_of(".");
		if( pos != CGUIString::npos )
		{
			strExt = m_strPath.substr(pos);
		}
		for ( uint32 i=0; i<strExt.size(); ++i)
		{
			strExt[i] = tolower(strExt[i]);
		}

		CGUIString	strScenePath = CGUISceneManager::Instance()->GetScenePath( m_strSceneName ) + m_strPath;
		CGUIString	strFullPath;
		GSystem->GenerateFullPath( strScenePath, strFullPath );
		if (strExt == ".ogg")
		{
			//load ogg file
			if( LoadOggFile( strFullPath ) != true)
			{
				GUI_THROW( GUI_FORMAT("[CGUISoundData_openal::DoLoad]: failed to load ogg file <%s>!", m_strPath.c_str()));
				return -1;
			}
		}
		else
		{
			GUI_THROW( GUI_FORMAT("[CGUISoundData_openal::DoLoad]: doesn't support the sound type <%s>!", strExt.c_str()));
			return -1;
		}

		//assign the buffer to this source
		//alSourcei( m_nSourceId, AL_BUFFER, m_nBufferId);

		//set source position
		alSource3f( m_nSourceId,AL_POSITION, 0, 0, 0);

		//set source velocity
		alSource3f( m_nSourceId,AL_VELOCITY, 0, 0, 0);
		return 0;
	}
示例#8
0
	//------------------------------------------------------------------------------
	std::vector<CGUIString>	StringToVector(const CGUIString& rString )
	{
		std::vector<CGUIString> aListString;
		CGUIString::size_type idx = 0;

		while( idx < rString.size())
		{
			CGUIString::size_type ret = rString.find(",", idx);
			aListString.push_back(rString.substr(idx, ret));
			if( ret == CGUIString::npos )
			{
				break;
			}
			else
			{
				idx = ret+1;
			}
		}
		return aListString;
	}
示例#9
0
	int32 StringToValue<CGUIVector2>( const CGUIString& rString, CGUIVector2& rValue)
	{
		//string should have format as "x,y"
		std::vector<CGUIString> aListString= StringToVector(rString);

		if( aListString.size() != 2 )
		{
			GUI_THROW( GUI_FORMAT(
				"[StringToValue[StringToValue]]: string value format is wrong! <%s>",
				rString.c_str()));
			return -1;
		}

		StringToValue(aListString[0], rValue.x);
		StringToValue(aListString[1], rValue.y);
		return 0;
	}
示例#10
0
	int32 StringToValue<CGUIIntSize>( const CGUIString& rString, CGUIIntSize& rValue)
	{
		//string should have format as "width,height"
		std::vector<CGUIString> aListString= StringToVector(rString);

		if( aListString.size() != 2 )
		{
			GUI_THROW( GUI_FORMAT(
				"[StringToValue[CGUIIntSize]]: string value format is wrong! <%s>",
				rString.c_str()));
			return -1;
		}

		StringToValue( aListString[0], rValue.m_uWidth );
		StringToValue( aListString[1], rValue.m_uHeight );
		return 0;
	}
示例#11
0
	int32 StringToValue<CGUIRotator>( const CGUIString& rString, CGUIRotator& rValue)
	{
		//string should have format as "pitch,yaw,roll"
		std::vector<CGUIString> aListString= StringToVector(rString);

		if( aListString.size() != 3 )
		{
			GUI_THROW( GUI_FORMAT(
				"[StringToValue[StringToValue]]: string value format is wrong! <%s>",
				rString.c_str()));
			return -1;
		}

		StringToValue(aListString[0], rValue.Pitch);
		StringToValue(aListString[1], rValue.Yaw);
		StringToValue(aListString[2], rValue.Roll);
		return 0;
	}
示例#12
0
	int32 StringToValue<CGUIRect>( const CGUIString& rString, CGUIRect& rValue)
	{
		//string should have format as "left, top, right,bottom"
		std::vector<CGUIString> aListString= StringToVector(rString);
		if( aListString.size() != 4 )
		{
			GUI_THROW( GUI_FORMAT(
				"[StringToValue[CGUIRect]]: string value format is wrong! <%s>",
				rString.c_str()));
			return -1;
		}

		StringToValue( aListString[0], rValue.m_fLeft );
		StringToValue( aListString[1], rValue.m_fTop );
		StringToValue( aListString[2], rValue.m_fRight );
		StringToValue( aListString[3], rValue.m_fBottom );
		return 0;
	}
示例#13
0
	//------------------------------------------------------------------------------
	int32 CGUITiledMap::ParseTMXFile( const CGUIString& rFileName )
	{
		Reset();

		m_pMapInfo = new CGUITiledMapInfo;
		if( 0 != m_pMapInfo->InitWithTMXFile( rFileName ) )
		{
			GUI_THROW( GUI_FORMAT("[CGUITiledMap::ParseTMXFile]: failed parse tmx file %s", rFileName.c_str() ));
			return -1;
		}

		for( uint32 i=0; i<m_pMapInfo->GetLayerInfos().size(); ++i ) 
		{
			CGUITiledMapLayer* pLayer = new CGUITiledMapLayer( this, i );
			m_arrayLayer.push_back( pLayer );
		}		

		return 0;
	}
示例#14
0
	int32 StringToValue<EScreenValue>( const CGUIString& rString, EScreenValue& rValue)
	{
		if( rString == "eScreenValue_Pixel" )
		{
			rValue = eScreenValue_Pixel;
		}
		else if( rString == "eScreenValue_Percentage" )
		{
			rValue = eScreenValue_Percentage;
		}
		else
		{
			GUI_THROW( GUI_FORMAT(
				"[StringToValue[EScreenValue]]: string value format is wrong! <%s>",
				rString.c_str()));
			return -1;
		}
		return 0;
	}
示例#15
0
	int32 StringToValue<EOrientation>( const CGUIString& rString, EOrientation& rValue)
	{
		if( rString == "eOrientation_Vertical" )
		{
			rValue = eOrientation_Vertical;
		}
		else if( rString == "eOrientation_Horizontal" )
		{
			rValue = eOrientation_Horizontal;
		}
		else
		{
			GUI_THROW( GUI_FORMAT(
				"[StringToValue[EOrientation]]: string value format is wrong! <%s>",
				rString.c_str()));
			return -1;
		}
		return 0;
	}
示例#16
0
	int32 StringToValue<EParticle2DSystemMode>( const CGUIString& rString, EParticle2DSystemMode& rValue)
	{
		if( rString == "eParticle2DSystemMode_Gravity" )
		{
			rValue = eParticle2DSystemMode_Gravity;
		}
		else if( rString == "eParticle2DSystemMode_Radius" )
		{
			rValue = eParticle2DSystemMode_Radius;
		}
		else
		{
			GUI_THROW( GUI_FORMAT(
				"[StringToValue[EParticle2DSystemMode]]: string value format is wrong! <%s>",
				rString.c_str()));
			return -1;
		}
		return 0;
	}
示例#17
0
	int32 StringToValue<EBlendFunc>( const CGUIString& rString, EBlendFunc& rValue)
	{
		if( rString == "eBlendFunc_ZERO" )
		{
			rValue = eBlendFunc_ZERO;
		}
		else if( rString == "eBlendFunc_ONE" )
		{
			rValue = eBlendFunc_ONE;
		}
		else if( rString == "eBlendFunc_SRC_COLOR" )
		{
			rValue = eBlendFunc_SRC_COLOR;
		}
		else if( rString == "eBlendFunc_ONE_MINUS_SRC_COLOR" )
		{
			rValue = eBlendFunc_ONE_MINUS_SRC_COLOR;
		}
		else if( rString == "eBlendFunc_SRC_ALPHA" )
		{
			rValue = eBlendFunc_SRC_ALPHA;
		}
		else if( rString == "eBlendFunc_ONE_MINUS_SRC_ALPHA" )
		{
			rValue = eBlendFunc_ONE_MINUS_SRC_ALPHA;
		}
		else if( rString == "eBlendFunc_DST_ALPHA" )
		{
			rValue = eBlendFunc_DST_ALPHA;
		}
		else if( rString == "eBlendFunc_ONE_MINUS_DST_ALPHA" )
		{
			rValue = eBlendFunc_ONE_MINUS_DST_ALPHA;
		}
		else
		{
			GUI_THROW( GUI_FORMAT(
				"[StringToValue[EBlendFunc]]: string value format is wrong! <%s>",
				rString.c_str()));
			return -1;
		}
		return 0;
	}
示例#18
0
	int32 StringToValue<bool>( const CGUIString& rString, bool& rValue)
	{
		if( rString == "true")
		{
			rValue = true;
			return 0;
		}
		else if (  rString == "false")
		{
			rValue = false;
			return 0;
		}
		else
		{
			GUI_THROW( GUI_FORMAT(
				"[StringToValue[bool]]: string value format is wrong! <%s>",
				rString.c_str()));
			return -1;
		}
	}
示例#19
0
	int32 StringToValue<ETextAlignmentVert>( const CGUIString& rString, ETextAlignmentVert& rValue)
	{
		if( rString == "eTextAlignment_Vert_Up" )
		{
			rValue = eTextAlignment_Vert_Up;
		}
		else if( rString == "eTextAlignment_Vert_Down" )
		{
			rValue = eTextAlignment_Vert_Down;
		}
		else if( rString == "eTextAlignment_Vert_Center" )
		{
			rValue = eTextAlignment_Vert_Center;
		}
		else
		{
			GUI_THROW( GUI_FORMAT(
				"[StringToValue[ETextAlignmentVert]]: string value format is wrong! <%s>",
				rString.c_str()));
			return -1;
		}
		return 0;
	}
示例#20
0
	int32 StringToValue<EInterpolationType>( const CGUIString& rString, EInterpolationType& rValue)
	{
		if( rString == "eInterpolationType_Linear" )
		{
			rValue = eInterpolationType_Linear;
		}
		else if( rString == "eInterpolationType_EaseIn" )
		{
			rValue = eInterpolationType_EaseIn;
		}
		else if( rString == "eInterpolationType_EaseInOut" )
		{
			rValue = eInterpolationType_EaseInOut;
		}
		else
		{
			GUI_THROW( GUI_FORMAT(
				"[StringToValue[EInterpolationType]]: string value format is wrong! <%s>",
				rString.c_str()));
			return -1;
		}
		return 0;
	}
示例#21
0
	int32 StringToValue<ETextAlignmentHorz>( const CGUIString& rString, ETextAlignmentHorz& rValue)
	{
		if( rString == "eTextAlignment_Horz_Left" )
		{
			rValue = eTextAlignment_Horz_Left;
		}
		else if( rString == "eTextAlignment_Horz_Right" )
		{
			rValue = eTextAlignment_Horz_Right;
		}
		else if( rString == "eTextAlignment_Horz_Center" )
		{
			rValue = eTextAlignment_Horz_Center;
		}
		else
		{
			GUI_THROW( GUI_FORMAT(
				"[StringToValue[ETextAlignmentHorz]]: string value format is wrong! <%s>",
				rString.c_str()));
			return -1;
		}
		return 0;
	}
示例#22
0
	int32 StringToValue<CGUIColor>( const CGUIString& rString, CGUIColor& rValue)
	{
		//string should have format as "r,g,b,a"
		std::vector<CGUIString> aListString= StringToVector(rString);

		if( aListString.size() != 4 )
		{
			GUI_THROW( GUI_FORMAT(
				"[StringToValue[CGUIColor]]: string value format is wrong! <%s>",
				rString.c_str()));
			return -1;
		}

		uint8 nColor;
		StringToValue(aListString[0], nColor );
		rValue.SetRed( nColor / 255.0f );
		StringToValue(aListString[1], nColor );
		rValue.SetGreen( nColor / 255.0f );
		StringToValue(aListString[2], nColor );
		rValue.SetBlue( nColor / 255.0f );
		StringToValue(aListString[3], nColor );
		rValue.SetAlpha( nColor / 255.0f );
		return 0;
	}
示例#23
0
bool __ParseString<CGUIString>(const CStrW& Value, CGUIString& Output)
{
	Output.SetValue(Value);
	return true;
}
示例#24
0
JSBool JSI_IGUIObject::getProperty(JSContext* cx, JSObject* obj, jsid id, jsval* vp)
{
	IGUIObject* e = (IGUIObject*)JS_GetInstancePrivate(cx, obj, &JSI_IGUIObject::JSI_class, NULL);
	if (!e)
		return JS_FALSE;

	jsval idval;
	if (!JS_IdToValue(cx, id, &idval))
		return JS_FALSE;

	std::string propName;
	if (!ScriptInterface::FromJSVal(cx, idval, propName))
		return JS_FALSE;

	// Skip some things which are known to be functions rather than properties.
	// ("constructor" *must* be here, else it'll try to GetSettingType before
	// the private IGUIObject* has been set (and thus crash). The others are
	// partly for efficiency, and also to allow correct reporting of attempts to
	// access nonexistent properties.)
	if (propName == "constructor" ||
		propName == "prototype"   ||
		propName == "toString"    ||
		propName == "focus"       ||
		propName == "blur"        ||
		propName == "getComputedSize"
	   )
		return JS_TRUE;

	// Use onWhatever to access event handlers
	if (propName.substr(0, 2) == "on")
	{
		CStr eventName (CStr(propName.substr(2)).LowerCase());
		std::map<CStr, JSObject**>::iterator it = e->m_ScriptHandlers.find(eventName);
		if (it == e->m_ScriptHandlers.end())
			*vp = JSVAL_NULL;
		else
			*vp = OBJECT_TO_JSVAL(*(it->second));
		return JS_TRUE;
	}


	// Handle the "parent" property specially
	if (propName == "parent")
	{
		IGUIObject* parent = e->GetParent();
		if (parent)
		{
			// If the object isn't parentless, return a new object
			*vp = OBJECT_TO_JSVAL(parent->GetJSObject());
		}
		else
		{
			// Return null if there's no parent
			*vp = JSVAL_NULL;
		}
		return JS_TRUE;
	}
	// Also handle "name" specially
	else if (propName == "name")
	{
		*vp = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, e->GetName().c_str()));
		return JS_TRUE;
	}
	// Handle all other properties
	else
	{
		// Retrieve the setting's type (and make sure it actually exists)
		EGUISettingType Type;
		if (e->GetSettingType(propName, Type) != PSRETURN_OK)
		{
			JS_ReportError(cx, "Invalid GUIObject property '%s'", propName.c_str());
			return JS_FALSE;
		}

		// (All the cases are in {...} to avoid scoping problems)
		switch (Type)
		{
		case GUIST_bool:
			{
				bool value;
				GUI<bool>::GetSetting(e, propName, value);
				*vp = value ? JSVAL_TRUE : JSVAL_FALSE;
				break;
			}

		case GUIST_int:
			{
				int value;
				GUI<int>::GetSetting(e, propName, value);
				*vp = INT_TO_JSVAL(value);
				break;
			}

		case GUIST_float:
			{
				float value;
				GUI<float>::GetSetting(e, propName, value);
				// Create a garbage-collectable double
				return JS_NewNumberValue(cx, value, vp);
			}

		case GUIST_CColor:
			{
				CColor colour;
				GUI<CColor>::GetSetting(e, propName, colour);
				JSObject* obj = JS_NewObject(cx, &JSI_GUIColor::JSI_class, NULL, NULL);
				*vp = OBJECT_TO_JSVAL(obj); // root it

				jsval c;
				// Attempt to minimise ugliness through macrosity
				#define P(x) if (!JS_NewNumberValue(cx, colour.x, &c)) return JS_FALSE; JS_SetProperty(cx, obj, #x, &c)
					P(r);
					P(g);
					P(b);
					P(a);
				#undef P

				break;
			}

		case GUIST_CClientArea:
			{
				CClientArea area;
				GUI<CClientArea>::GetSetting(e, propName, area);
				JSObject* obj = JS_NewObject(cx, &JSI_GUISize::JSI_class, NULL, NULL);
				*vp = OBJECT_TO_JSVAL(obj); // root it
				try
				{
				#define P(x, y, z) g_ScriptingHost.SetObjectProperty_Double(obj, #z, area.x.y)
					P(pixel,	left,	left);
					P(pixel,	top,	top);
					P(pixel,	right,	right);
					P(pixel,	bottom,	bottom);
					P(percent,	left,	rleft);
					P(percent,	top,	rtop);
					P(percent,	right,	rright);
					P(percent,	bottom,	rbottom);
				#undef P
				}
				catch (PSERROR_Scripting_ConversionFailed)
				{
					debug_warn(L"Error creating size object!");
					break;
				}

				break;
			}

		case GUIST_CGUIString:
			{
				CGUIString value;
				GUI<CGUIString>::GetSetting(e, propName, value);
				*vp = ScriptInterface::ToJSVal(cx, value.GetOriginalString());
				break;
			}

		case GUIST_CStr:
			{
				CStr value;
				GUI<CStr>::GetSetting(e, propName, value);
				*vp = ScriptInterface::ToJSVal(cx, value);
				break;
			}

		case GUIST_CStrW:
			{
				CStrW value;
				GUI<CStrW>::GetSetting(e, propName, value);
				*vp = ScriptInterface::ToJSVal(cx, value);
				break;
			}

		case GUIST_CGUISpriteInstance:
			{
				CGUISpriteInstance *value;
				GUI<CGUISpriteInstance>::GetSettingPointer(e, propName, value);
				*vp = ScriptInterface::ToJSVal(cx, value->GetName());
				break;
			}

		case GUIST_EAlign:
			{
				EAlign value;
				GUI<EAlign>::GetSetting(e, propName, value);
				CStr word;
				switch (value)
				{
				case EAlign_Left: word = "left"; break;
				case EAlign_Right: word = "right"; break;
				case EAlign_Center: word = "center"; break;
				default: debug_warn(L"Invalid EAlign!"); word = "error"; break;
				}
				*vp = ScriptInterface::ToJSVal(cx, word);
				break;
			}

		case GUIST_EVAlign:
			{
				EVAlign value;
				GUI<EVAlign>::GetSetting(e, propName, value);
				CStr word;
				switch (value)
				{
				case EVAlign_Top: word = "top"; break;
				case EVAlign_Bottom: word = "bottom"; break;
				case EVAlign_Center: word = "center"; break;
				default: debug_warn(L"Invalid EVAlign!"); word = "error"; break;
				}
				*vp = ScriptInterface::ToJSVal(cx, word);
				break;
			}

		case GUIST_CGUIList:
			{
				CGUIList value;
				GUI<CGUIList>::GetSetting(e, propName, value);

				JSObject *obj = JS_NewArrayObject(cx, 0, NULL);
				*vp = OBJECT_TO_JSVAL(obj); // root it
				
				for (size_t i = 0; i < value.m_Items.size(); ++i)
				{
					jsval val = ScriptInterface::ToJSVal(cx, value.m_Items[i].GetOriginalString());
					JS_SetElement(cx, obj, (jsint)i, &val);
				}

				break;
			}

		default:
			JS_ReportError(cx, "Setting '%s' uses an unimplemented type", propName.c_str());
			DEBUG_WARN_ERR(ERR::LOGIC);
			return JS_FALSE;
		}

		return JS_TRUE;
	}
}
示例#25
0
SGUIText CGUI::GenerateText(const CGUIString &string,
							const CStrW& FontW, const float &Width, const float &BufferZone,
							const IGUIObject *pObject)
{
	SGUIText Text; // object we're generating

	CStrIntern Font(FontW.ToUTF8());
	
	if (string.m_Words.size() == 0)
		return Text;

	float x=BufferZone, y=BufferZone; // drawing pointer
	int from=0;
	bool done=false;

	bool FirstLine = true;	// Necessary because text in the first line is shorter
							// (it doesn't count the line spacing)

	// Images on the left or the right side.
	std::vector<SGenerateTextImage> Images[2];
	int pos_last_img=-1;	// Position in the string where last img (either left or right) were encountered.
							//  in order to avoid duplicate processing.

	// Easier to read.
	bool WordWrapping = (Width != 0);

	// get the alignment type for the control we are computing the text for since
	// we are computing the horizontal alignment in this method in order to not have
	// to run through the TextCalls a second time in the CalculateTextPosition method again
	EAlign align;
	GUI<EAlign>::GetSetting(pObject, "text_align", align);

	// Go through string word by word
	for (int i=0; i<(int)string.m_Words.size()-1 && !done; ++i)
	{
		// Pre-process each line one time, so we know which floating images
		//  will be added for that line.

		// Generated stuff is stored in Feedback.
		CGUIString::SFeedback Feedback;

		// Preliminary line_height, used for word-wrapping with floating images.
		float prelim_line_height=0.f;

		// Width and height of all text calls generated.
		string.GenerateTextCall(Feedback, Font,
								string.m_Words[i], string.m_Words[i+1],
								FirstLine);

		// Loop through our images queues, to see if images has been added.
		
		// Check if this has already been processed.
		//  Also, floating images are only applicable if Word-Wrapping is on
		if (WordWrapping && i > pos_last_img)
		{
			// Loop left/right
			for (int j=0; j<2; ++j)
			{
				for (std::vector<CStr>::const_iterator it = Feedback.m_Images[j].begin(); 
					it != Feedback.m_Images[j].end();
					++it)
				{
					SGUIText::SSpriteCall SpriteCall;
					SGenerateTextImage Image;

					// Y is if no other floating images is above, y. Else it is placed
					//  after the last image, like a stack downwards.
					float _y;
					if (!Images[j].empty())
						_y = std::max(y, Images[j].back().m_YTo);
					else
						_y = y; 

					// Get Size from Icon database
					SGUIIcon icon = GetIcon(*it);

					CSize size = icon.m_Size;
					Image.SetupSpriteCall((j==CGUIString::SFeedback::Left), SpriteCall, Width, _y, size, icon.m_SpriteName, BufferZone, icon.m_CellID);

					// Check if image is the lowest thing.
					Text.m_Size.cy = std::max(Text.m_Size.cy, Image.m_YTo);

					Images[j].push_back(Image);
					Text.m_SpriteCalls.push_back(SpriteCall);
				}
			}
		}

		pos_last_img = std::max(pos_last_img, i);

		x += Feedback.m_Size.cx;
		prelim_line_height = std::max(prelim_line_height, Feedback.m_Size.cy);

		// If Width is 0, then there's no word-wrapping, disable NewLine.
		if ((WordWrapping && (x > Width-BufferZone || Feedback.m_NewLine)) || i == (int)string.m_Words.size()-2)
		{
			// Change 'from' to 'i', but first keep a copy of its value.
			int temp_from = from;
			from = i;

			static const int From=0, To=1;
			//int width_from=0, width_to=width;
			float width_range[2];
			width_range[From] = BufferZone;
			width_range[To] = Width - BufferZone;

			// Floating images are only applicable if word-wrapping is enabled.
			if (WordWrapping)
			{
				// Decide width of the line. We need to iterate our floating images.
				//  this won't be exact because we're assuming the line_height
				//  will be as our preliminary calculation said. But that may change,
				//  although we'd have to add a couple of more loops to try straightening
				//  this problem out, and it is very unlikely to happen noticeably if one
				//  structures his text in a stylistically pure fashion. Even if not, it
				//  is still quite unlikely it will happen.
				// Loop through left and right side, from and to.
				for (int j=0; j<2; ++j)
				{
					for (std::vector<SGenerateTextImage>::const_iterator it = Images[j].begin(); 
						it != Images[j].end(); 
						++it)
					{
						// We're working with two intervals here, the image's and the line height's.
						//  let's find the union of these two.
						float union_from, union_to;

						union_from = std::max(y, it->m_YFrom);
						union_to = std::min(y+prelim_line_height, it->m_YTo);
						
						// The union is not empty
						if (union_to > union_from)
						{
							if (j == From)
								width_range[From] = std::max(width_range[From], it->m_Indentation);
							else
								width_range[To] = std::min(width_range[To], Width - it->m_Indentation);
						}
					}
				}
			}

			// Reset X for the next loop
			x = width_range[From];

			// Now we'll do another loop to figure out the height and width of
			//  the line (the height of the largest character and the width is
			//  the sum of all of the individual widths). This
			//  couldn't be determined in the first loop (main loop)
			//  because it didn't regard images, so we don't know
			//  if all characters processed, will actually be involved
			//  in that line.
			float line_height=0.f;
			float line_width=0.f;
			for (int j=temp_from; j<=i; ++j)
			{
				// We don't want to use Feedback now, so we'll have to use
				//  another.
				CGUIString::SFeedback Feedback2;

				// Don't attach object, it'll suppress the errors
				//  we want them to be reported in the final GenerateTextCall()
				//  so that we don't get duplicates.
				string.GenerateTextCall(Feedback2, Font,
										string.m_Words[j], string.m_Words[j+1],
										FirstLine);

				// Append X value.
				x += Feedback2.m_Size.cx;

				if (WordWrapping && x > width_range[To] && j!=temp_from && !Feedback2.m_NewLine)
					break;

				// Let line_height be the maximum m_Height we encounter.
				line_height = std::max(line_height, Feedback2.m_Size.cy);

				line_width += Feedback2.m_Size.cx;

				if (WordWrapping && Feedback2.m_NewLine)
					break;
			}

			float dx = 0.f;
			// compute offset based on what kind of alignment
			switch (align)
			{
			case EAlign_Left:
				// don't add an offset
				dx = 0.f;
				break;

			case EAlign_Center:
				dx = ((width_range[To] - width_range[From]) - line_width) / 2;
				break;

			case EAlign_Right:
				dx = width_range[To] - line_width;
				break;

			default:
				debug_warn(L"Broken EAlign in CGUI::GenerateText()");
				break;
			}
			// Reset x once more
			x = width_range[From];
			// Move down, because font drawing starts from the baseline
			y += line_height;

			// Do the real processing now
			for (int j=temp_from; j<=i; ++j)
			{
				// We don't want to use Feedback now, so we'll have to use
				//  another one.
				CGUIString::SFeedback Feedback2;

				// Defaults
				string.GenerateTextCall(Feedback2, Font,
										string.m_Words[j], string.m_Words[j+1], 
										FirstLine, pObject);

				// Iterate all and set X/Y values
				// Since X values are not set, we need to make an internal
				//  iteration with an increment that will append the internal
				//  x, that is what x_pointer is for.
				float x_pointer=0.f;

				std::vector<SGUIText::STextCall>::iterator it;
				for (it = Feedback2.m_TextCalls.begin(); it != Feedback2.m_TextCalls.end(); ++it)
				{
					it->m_Pos = CPos(dx + x + x_pointer, y);

					x_pointer += it->m_Size.cx;

					if (it->m_pSpriteCall)
					{
						it->m_pSpriteCall->m_Area += it->m_Pos - CSize(0,it->m_pSpriteCall->m_Area.GetHeight());
					}
				}

				// Append X value.
				x += Feedback2.m_Size.cx;

				Text.m_Size.cx = std::max(Text.m_Size.cx, x+BufferZone);

				// The first word overrides the width limit, what we
				//  do, in those cases, are just drawing that word even
				//  though it'll extend the object.
				if (WordWrapping) // only if word-wrapping is applicable
				{
					if (Feedback2.m_NewLine)
					{
						from = j+1;

						// Sprite call can exist within only a newline segment,
						//  therefore we need this.
						Text.m_SpriteCalls.insert(Text.m_SpriteCalls.end(), Feedback2.m_SpriteCalls.begin(), Feedback2.m_SpriteCalls.end());
						break;
					}
					else
					if (x > width_range[To] && j==temp_from)
					{
						from = j+1;
						// do not break, since we want it to be added to m_TextCalls
					}
					else
					if (x > width_range[To])
					{
						from = j;
						break;
					}
				}

				// Add the whole Feedback2.m_TextCalls to our m_TextCalls.
				Text.m_TextCalls.insert(Text.m_TextCalls.end(), Feedback2.m_TextCalls.begin(), Feedback2.m_TextCalls.end());
				Text.m_SpriteCalls.insert(Text.m_SpriteCalls.end(), Feedback2.m_SpriteCalls.begin(), Feedback2.m_SpriteCalls.end());

				if (j == (int)string.m_Words.size()-2)
					done = true;
			}

			// Reset X
			x = 0.f;

			// Update height of all
			Text.m_Size.cy = std::max(Text.m_Size.cy, y+BufferZone);

			FirstLine = false;

			// Now if we entered as from = i, then we want
			//  i being one minus that, so that it will become
			//  the same i in the next loop. The difference is that
			//  we're on a new line now.
			i = from-1;
		}
	}

	return Text;
}
示例#26
0
	//------------------------------------------------------------------------------
	bool CGUIMusicData_openal::LoadOggFile( const CGUIString& rFilename ) const
	{
		//open file
		FILE *pFile = fopen( rFilename.c_str(), "rb" );
		if( !pFile)
		{
			return false;
		}

		ov_callbacks sCallbacks;
		sCallbacks.read_func = ov_read_func;
		sCallbacks.seek_func = ov_seek_func;
		sCallbacks.close_func = ov_close_func;
		sCallbacks.tell_func = ov_tell_func;
		if (ov_open_callbacks(pFile, &m_aVorbisFile, NULL, 0, sCallbacks) != 0)
		{
			fclose( pFile );
			return false;
		}

		// Get some information about the file (Channels, Format, and Frequency)
		if( false == GetOggVorbisInfo( &m_aVorbisFile, &m_nFrequency, &m_nFormat, &m_nFormat, &m_nBufferSize ) )
		{
			ov_clear(&m_aVorbisFile);
			return false;
		}

		// Allocate a buffer to be used to store decoded data for all Buffers
		m_pDecodeBuffer = (char*)malloc(m_nBufferSize);
		if ( !m_pDecodeBuffer )
		{
			ov_clear(&m_aVorbisFile);
			return false;
		}

		// Generate a Source to playback the Buffers
		alGenSources(1, &m_nSourceId);
		if (alGetError() != AL_NO_ERROR)
		{
			return false;
		}

		// Generate some AL Buffers for streaming
		alGenBuffers( GUI_MUSIC_NUMBUFFERS, m_nBuffers );
		if (alGetError() != AL_NO_ERROR)
		{
			return false;
		}

		// Fill all the Buffers with decoded audio data from the OggVorbis file
		for (int iLoop = 0; iLoop < GUI_MUSIC_NUMBUFFERS; iLoop++)
		{
			unsigned long ulBytesWritten = DecodeOggVorbis(&m_aVorbisFile, m_pDecodeBuffer, m_nBufferSize, m_nChannels);
			if (ulBytesWritten)
			{
				alBufferData(m_nBuffers[iLoop], m_nFormat, m_pDecodeBuffer, ulBytesWritten, m_nFrequency);
				alSourceQueueBuffers(m_nSourceId, 1, &m_nBuffers[iLoop]);
			}
		}

		return true;
	}
	//-----------------------------------------------------------------------
	void CGUIParticleSystemManager::parseScript(DataStreamPtr& stream, const CGUIString& groupName)
	{
#if OGRE_USE_NEW_COMPILERS == 1
		ScriptCompilerManager::getSingleton().parseScript(stream, groupName);
#else // OGRE_USE_NEW_COMPILERS
		CGUIString line;
		CGUIParticleSystem* pSys;
		vector<CGUIString>::type vecparams;

		pSys = 0;

		while(!stream->eof())
		{
			line = stream->getLine();
			// Ignore comments & blanks
			if (!(line.length() == 0 || line.substr(0,2) == "//"))
			{
				if (pSys == 0)
				{
					// No current system
					// So first valid data should be a system name
					if (StringUtil::startsWith(line, "particle_system "))
					{
						// chop off the 'particle_system ' needed by new compilers
						line = line.substr(16);
					}
					pSys = createTemplate(line, groupName);
					pSys->_notifyOrigin(stream->getName());
					// Skip to and over next {
					skipToNextOpenBrace(stream);
				}
				else
				{
					// Already in a system
					if (line == "}")
					{
						// Finished system
						pSys = 0;
					}
					else if (line.substr(0,7) == "emitter")
					{
						// new emitter
						// Get typename
						vecparams = StringUtil::split(line, "\t ");
						if (vecparams.size() < 2)
						{
							// Oops, bad emitter
							LogManager::getSingleton().logMessage("Bad particle system emitter line: '"
								+ line + "' in " + pSys->getName());
							skipToNextCloseBrace(stream);

						}
						skipToNextOpenBrace(stream);
						parseNewEmitter(vecparams[1], stream, pSys);

					}
					else if (line.substr(0,8) == "affector")
					{
						// new affector
						// Get typename
						vecparams = StringUtil::split(line, "\t ");
						if (vecparams.size() < 2)
						{
							// Oops, bad affector
							LogManager::getSingleton().logMessage("Bad particle system affector line: '"
								+ line + "' in " + pSys->getName());
							skipToNextCloseBrace(stream);

						}
						skipToNextOpenBrace(stream);
						parseNewAffector(vecparams[1],stream, pSys);
					}
					else
					{
						// Attribute
						parseAttrib(line, pSys);
					}

				}

			}


		}
#endif // OGRE_USE_NEW_COMPILERS
	}
示例#28
0
	//------------------------------------------------------------------------------
	int IGUIStringConv_iconv::Utf8ToWChar( const CGUIString& rSrc, CGUIStringW& rDst )
	{
		if( rSrc.empty())
		{
			rDst.clear();
			return 0;
		}

		//open iconv
		iconv_t cd = iconv_open ("UTF-16LE", "UTF-8");
		if( cd == (iconv_t)-1 )
		{
			throw CGUIException(
				"[MultiByteToWideChar]: failed to open iconv, errno is %d",
				errno);
			return -1;
		}

		//convert
		size_t	buf_size = rSrc.size()+1;
		size_t	inbytesleft = rSrc.size();
		size_t	outbytesleft = buf_size;
		char*	dst = (char*)(new wchar[buf_size]);
		char*	pOutBuf = NULL;
		char*	pInBuf = (char*)(rSrc.c_str());

		bool	bError = false;

		while(inbytesleft > 0) 
		{
			pOutBuf = dst;
			outbytesleft = buf_size*sizeof(wchar);

			size_t retbytes = iconv(cd, &pInBuf, &inbytesleft, &pOutBuf, &outbytesleft);

			if (dst != pOutBuf)  
			{
				// wchar is 4byte in mac, but iconv return a "utf-16" buff which is 2byte per code
				if (sizeof(wchar) == 4) 
				{
					for (int iChar = 0; iChar < (pOutBuf-dst)/2; iChar++)
					{
						unsigned short* pU16Char = (unsigned short*)&dst[2*iChar];
						rDst.push_back((wchar)*pU16Char);
					}
				}
				else if (sizeof(wchar) == 2) 
				{
					rDst.append((wchar*)dst, (pOutBuf-dst)/sizeof(wchar));
				}
			} 

			//check ret
			if( retbytes == size_t(-1) )
			{
				if( errno == E2BIG )
				{
					continue;
				}
				else
				{
					bError = true;
					break;
				}
			}
			else
			{
				//success
				break;
			}
		}

		delete[] dst;
		if( bError)
		{
			switch(errno)
			{
			case EILSEQ:
				throw CGUIException(
					"[MultiByteToWideChar]: failed to iconv, errno is EILSEQ");
				return -1;
			case EINVAL:
				throw CGUIException(
					"[MultiByteToWideChar]: failed to iconv, errno is EINVAL");
				return -1;
			default:
				throw CGUIException(
					"[MultiByteToWideChar]: failed to iconv, errno is %d",
					errno);
				return -1;
			}
		}

		//close iconv
		int ret = iconv_close(cd);
		if( ret == -1 )
		{
			throw CGUIException(
				"[MultiByteToWideChar]: failed to close iconv, errno is %d",
				errno);
			return -1;
		}

		return 0;
	}
示例#29
0
JSBool JSI_IGUIObject::setProperty(JSContext* cx, JSObject* obj, jsid id, JSBool UNUSED(strict), jsval* vp)
{
	IGUIObject* e = (IGUIObject*)JS_GetInstancePrivate(cx, obj, &JSI_IGUIObject::JSI_class, NULL);
	if (!e)
		return JS_FALSE;

	jsval idval;
	if (!JS_IdToValue(cx, id, &idval))
		return JS_FALSE;

	std::string propName;
	if (!ScriptInterface::FromJSVal(cx, idval, propName))
		return JS_FALSE;

	if (propName == "name")
	{
		std::string value;
		if (!ScriptInterface::FromJSVal(cx, *vp, value))
			return JS_FALSE;
		e->SetName(value);
		return JS_TRUE;
	}

	// Use onWhatever to set event handlers
	if (propName.substr(0, 2) == "on")
	{
		if (!JSVAL_IS_OBJECT(*vp) || !JS_ObjectIsFunction(cx, JSVAL_TO_OBJECT(*vp)))
		{
			JS_ReportError(cx, "on- event-handlers must be functions");
			return JS_FALSE;
		}

		CStr eventName (CStr(propName.substr(2)).LowerCase());
		e->SetScriptHandler(eventName, JSVAL_TO_OBJECT(*vp));

		return JS_TRUE;
	}

	// Retrieve the setting's type (and make sure it actually exists)
	EGUISettingType Type;
	if (e->GetSettingType(propName, Type) != PSRETURN_OK)
	{
		JS_ReportError(cx, "Invalid setting '%s'", propName.c_str());
		return JS_TRUE;
	}

	switch (Type)
	{

	case GUIST_CStr:
		{
			std::string value;
			if (!ScriptInterface::FromJSVal(cx, *vp, value))
				return JS_FALSE;

			GUI<CStr>::SetSetting(e, propName, value);
			break;
		}

	case GUIST_CStrW:
		{
			std::wstring value;
			if (!ScriptInterface::FromJSVal(cx, *vp, value))
				return JS_FALSE;

			GUI<CStrW>::SetSetting(e, propName, value);
			break;
		}

	case GUIST_CGUISpriteInstance:
		{
			std::string value;
			if (!ScriptInterface::FromJSVal(cx, *vp, value))
				return JS_FALSE;

			GUI<CGUISpriteInstance>::SetSetting(e, propName, CGUISpriteInstance(value));
			break;
		}

	case GUIST_CGUIString:
		{
			std::wstring value;
			if (!ScriptInterface::FromJSVal(cx, *vp, value))
				return JS_FALSE;

			CGUIString str;
			str.SetValue(value);
			GUI<CGUIString>::SetSetting(e, propName, str);
			break;
		}

	case GUIST_EAlign:
		{
			std::string value;
			if (!ScriptInterface::FromJSVal(cx, *vp, value))
				return JS_FALSE;

			EAlign a;
			if (value == "left") a = EAlign_Left;
			else if (value == "right") a = EAlign_Right;
			else if (value == "center" || value == "centre") a = EAlign_Center;
			else
			{
				JS_ReportError(cx, "Invalid alignment (should be 'left', 'right' or 'center')");
				return JS_FALSE;
			}
			GUI<EAlign>::SetSetting(e, propName, a);
			break;
		}

	case GUIST_EVAlign:
		{
			std::string value;
			if (!ScriptInterface::FromJSVal(cx, *vp, value))
				return JS_FALSE;

			EVAlign a;
			if (value == "top") a = EVAlign_Top;
			else if (value == "bottom") a = EVAlign_Bottom;
			else if (value == "center" || value == "centre") a = EVAlign_Center;
			else
			{
				JS_ReportError(cx, "Invalid alignment (should be 'top', 'bottom' or 'center')");
				return JS_FALSE;
			}
			GUI<EVAlign>::SetSetting(e, propName, a);
			break;
		}

	case GUIST_int:
		{
			int32 value;
			if (JS_ValueToInt32(cx, *vp, &value) == JS_TRUE)
				GUI<int>::SetSetting(e, propName, value);
			else
			{
				JS_ReportError(cx, "Cannot convert value to int");
				return JS_FALSE;
			}
			break;
		}

	case GUIST_float:
		{
			jsdouble value;
			if (JS_ValueToNumber(cx, *vp, &value) == JS_TRUE)
				GUI<float>::SetSetting(e, propName, (float)value);
			else
			{
				JS_ReportError(cx, "Cannot convert value to float");
				return JS_FALSE;
			}
			break;
		}

	case GUIST_bool:
		{
			JSBool value;
			if (JS_ValueToBoolean(cx, *vp, &value) == JS_TRUE)
				GUI<bool>::SetSetting(e, propName, value||0); // ||0 to avoid int-to-bool compiler warnings
			else
			{
				JS_ReportError(cx, "Cannot convert value to bool");
				return JS_FALSE;
			}
			break;
		}

	case GUIST_CClientArea:
		{
			if (JSVAL_IS_STRING(*vp))
			{
				std::wstring value;
				if (!ScriptInterface::FromJSVal(cx, *vp, value))
					return JS_FALSE;

				if (e->SetSetting(propName, value) != PSRETURN_OK)
				{
					JS_ReportError(cx, "Invalid value for setting '%s'", propName.c_str());
					return JS_FALSE;
				}
			}
			else if (JSVAL_IS_OBJECT(*vp) && JS_InstanceOf(cx, JSVAL_TO_OBJECT(*vp), &JSI_GUISize::JSI_class, NULL))
			{
				CClientArea area;
				GUI<CClientArea>::GetSetting(e, propName, area);

				JSObject* obj = JSVAL_TO_OBJECT(*vp);
				#define P(x, y, z) area.x.y = (float)g_ScriptingHost.GetObjectProperty_Double(obj, #z)
					P(pixel,	left,	left);
					P(pixel,	top,	top);
					P(pixel,	right,	right);
					P(pixel,	bottom,	bottom);
					P(percent,	left,	rleft);
					P(percent,	top,	rtop);
					P(percent,	right,	rright);
					P(percent,	bottom,	rbottom);
				#undef P

				GUI<CClientArea>::SetSetting(e, propName, area);
			}
			else
			{
				JS_ReportError(cx, "Size only accepts strings or GUISize objects");
				return JS_FALSE;
			}
			break;
		}

	case GUIST_CColor:
		{
			if (JSVAL_IS_STRING(*vp))
			{
				std::wstring value;
				if (!ScriptInterface::FromJSVal(cx, *vp, value))
					return JS_FALSE;

				if (e->SetSetting(propName, value) != PSRETURN_OK)
				{
					JS_ReportError(cx, "Invalid value for setting '%s'", propName.c_str());
					return JS_FALSE;
				}
			}
			else if (JSVAL_IS_OBJECT(*vp) && JS_InstanceOf(cx, JSVAL_TO_OBJECT(*vp), &JSI_GUIColor::JSI_class, NULL))
			{
				CColor colour;
				JSObject* obj = JSVAL_TO_OBJECT(*vp);
				jsval t; double s;
				#define PROP(x) JS_GetProperty(cx, obj, #x, &t); \
								JS_ValueToNumber(cx, t, &s); \
								colour.x = (float)s
				PROP(r); PROP(g); PROP(b); PROP(a);
				#undef PROP

				GUI<CColor>::SetSetting(e, propName, colour);
			}
			else
			{
				JS_ReportError(cx, "Color only accepts strings or GUIColor objects");
				return JS_FALSE;
			}
			break;
		}

	case GUIST_CGUIList:
		{
			JSObject* obj = JSVAL_TO_OBJECT(*vp);
			jsuint length;
			if (JSVAL_IS_OBJECT(*vp) && JS_GetArrayLength(cx, obj, &length) == JS_TRUE)
			{
				CGUIList list;

				for (int i=0; i<(int)length; ++i)
				{
					jsval element;
					if (! JS_GetElement(cx, obj, i, &element))
					{
						JS_ReportError(cx, "Failed to get list element");
						return JS_FALSE;
					}

					std::wstring value;
					if (!ScriptInterface::FromJSVal(cx, element, value))
						return JS_FALSE;

					CGUIString str;
					str.SetValue(value);
					
					list.m_Items.push_back(str);
				}

				GUI<CGUIList>::SetSetting(e, propName, list);
			}
			else
			{
				JS_ReportError(cx, "List only accepts a GUIList object");
				return JS_FALSE;
			}
			break;
		}

		// TODO Gee: (2004-09-01) EAlign and EVAlign too.

	default:
		JS_ReportError(cx, "Setting '%s' uses an unimplemented type", propName.c_str());
		break;
	}

	return !JS_IsExceptionPending(cx);
}
示例#30
0
	int32 StringToValue<real>( const CGUIString& rString, real& rValue)
	{
		rValue = static_cast<real>(strtod(rString.c_str(), 0));

		return 0;
	}