/// <summary>Creates a new html word element.</summary>
		/// <param name="document">The document this word will belong to.</param>
		/// <param name="parent">The parent html element. Should be a TextElement.</param>
		/// <param name="text">The text of this word.</param>
		public WordElement(Document document,Element parent,string text):base(document,parent){
			SetTag("word");
			
			// Words are CSS driven:
			style.innerText=text;
		}
Esempio n. 2
0
		/// <summary>Creates a new element for the given document and as a child of the given parent with content to parse.</summary>
		/// <param name="document">The document that this element will belong to.</param>
		/// <param name="lexer">An MLLexer containing the tag. No children are read; Just this tag only.</param>
		/// <param name="parent">The element that this element will be parented to.</param>
		private Element(Document document,MLLexer lexer,Element parent):this(document,parent){
			ReadTag(lexer);
		}
Esempio n. 3
0
		/// <summary>Changes the document used by this element and all it's kids. Used by iframes.</summary>
		/// <param name="document">The new document to use.</param>
		public void SetDocument(Document document){
			Document=document;
			if(ChildNodes!=null){
				for(int i=0;i<ChildNodes.Count;i++){
					ChildNodes[i].SetDocument(document);
				}
			}
			
			if(HScrollbar){
				HorizontalScrollbar.Element.SetDocument(document);
			}
			
			if(VScrollbar){
				VerticalScrollbar.Element.SetDocument(document);
			}
		}
//--------------------------------------
Esempio n. 5
0
		/// <summary>Creates a new element for the given document and as a child of the given parent.</summary>
		/// <param name="document">The document that this element will belong to.</param>
		/// <param name="parent">The element that this element will be parented to.</param>
		public Element(Document document,Element parent){
			Document=document;
			ParentNode=parent;
			Style=new ElementStyle(this);
		}
Esempio n. 6
0
	/// <summary>Resolves all &variables; as used by the given document their new values. Used when e.g. the language changes.</summary>
	/// <param name="htmlDocument">The document to update the variables for.</param>
	private static void ResolveAllVariables(Document htmlDocument){
		if(htmlDocument!=null && htmlDocument.html!=null){
			htmlDocument.html.ResetAllVariables();
		}
	}
		/// <summary>Creates a new text element that belongs to the given document.</summary>
		/// <param name="document">The document this element belongs to.</param>
		/// <param name="parent">The parent element for this new element.</param>
		public TextElement(Document document,Element parent):base(document,parent){
			SetTag("span");
		}
Esempio n. 8
0
	/// <summary>Makes sure the default text direction is as given for the given html document.</summary>
	/// <param name="goesLeftwards">True if the default text direction is leftwards.</param>
	/// <param name="htmlDocument">The document to apply the setting to.</param>
	private static void UpdateTextDirection(bool goesLeftwards,Document htmlDocument){
		if(htmlDocument!=null && htmlDocument.html!=null){
			bool currentLeftwards=(htmlDocument.html.style.direction=="rtl");
			if(currentLeftwards != goesLeftwards){
				if(goesLeftwards){
					htmlDocument.html.style.direction="rtl";
				}else{
					htmlDocument.html.style.direction="ltr";
				}
			}
		}
	}
Esempio n. 9
0
	/// <summary>Resolves all &variables; as used by the given document their new values. Used when e.g. the language changes.</summary>
	/// <param name="htmlDocument">The document to update the variables for.</param>
	private static void ResolveVariable(Document htmlDocument,string code){
		if(htmlDocument!=null && htmlDocument.html!=null){
			htmlDocument.html.ResetVariable(code);
		}
	}
Esempio n. 10
0
	/// <summary>Used internally - don't call this one. Startup the UI for use in the Editor with AOT Nitro.</summary>
	/// <param name="nitroAot">True if no gameobject should be generated.</param>
	public static void Start(bool nitroAot){
		
		if(!Started){
			Started=true;
			
			// Setup atlas stacks:
			AtlasStacks.Start();
			
			// Hookup the wrench logging method:
			Wrench.Log.OnLog+=OnLogMessage;
			
			// Hookup the InfiniText logging method:
			InfiniText.Fonts.OnLog+=OnLogMessage;
			
			// Startup the tag handlers:
			Wrench.TagHandlers.Setup();
			
			// Startup the file protocols (internally also starts up the CSS engine):
			FileProtocols.Setup();
			
			// Setup the text/language service:
			if(Variables==null){
				Variables=new FullVariableSet();
				
				if(!nitroAot){
					// Sign up to the variable on change event - whenever a custom var is changed, we need to refresh the screen.
					Variables.OnChange+=OnVariableChange;
					// Ensure that variables is set to whatever the default/current language is.
					OnLanguageChange(Wrench.Text.Language);
					// Sign on to the event that occurs when the language changes.
					Wrench.Text.OnLanguageChanged+=OnLanguageChange;
					// Sign on to the event that occurs when the gender changes.
					Wrench.Text.OnGenderChanged+=ResolveAllVariables;
				}
			}
			
			// Setup the callback queue:
			Callbacks.Start();
			
			// Setup the character providers (for e.g. Emoji):
			CharacterProviders.Setup();
			
			Layer=LayerMask.NameToLayer("PowerUI");
			
			if(Layer<0){
				// Invalid layer.
				#if UNITY_EDITOR
				
				// Create the new layer now (this will actually be a permanent change):
				Layer=PowerUI.LayerManager.Add();
				
				#else
				throw new Exception("Error: PowerUI layer not found. Go to Edit->Project Settings->Tags and add a layer called PowerUI to fix this."+
									" Don't forget to make sure it doesn't render with your main camera too!"
									);
				#endif
			}
			
			// Default FPS:
			SetRate(DefaultRate);
			
			#if !NoNitroRuntime
			// Setup the compiler:
			NitroCode.Setup();
			#endif
		}
		
		if(nitroAot){
			return;
		}
		
		GUINode=GameObject.Find("#PowerUI");
		
		if(GUINode==null){
			// Not started yet.
			
			// Create the UI game object:
			GUINode=new GameObject();
			GUINode.name="#PowerUI";
			
			// Create the camera:
			CameraNode=new GameObject();
			CameraNode.name="Camera";
			
			// Create the updater:
			GlobalUpdater=GUINode.AddComponent<StandardUpdater>();
			
			// Setup the camera:
			GUICamera=CameraNode.AddComponent<Camera>();
		}else{
			// Already started, but we might have updated.
			
			if(CameraNode==null){
				// This can happen if the PowerUI assembly is actively reloaded (e.g. runtime updates).
				CameraNode=GameObject.Find("#PowerUI/Camera");
				CameraTransform=CameraNode.transform;
				GUICamera=CameraNode.GetComponent<Camera>();
			}else{
				// Already started!
				return;
			}
			
		}
		
		// Hide the PowerUI layer from all cameras other than GUICamera: 
		Camera[] cameras=Camera.allCameras;
		
		int layerMask=~(1<<UI.Layer);
		
		for(int i=0;i<cameras.Length;i++){
			// Grab the camera:
			Camera camera=cameras[i];
			
			// Is it the GUICamera?
			if(camera==GUICamera){
				continue;
			}
			
			// Hide the UI layer from it:
			camera.cullingMask&=layerMask;
		}
		
		// Setup the transform:
		CameraTransform=CameraNode.transform;
		CameraTransform.parent=GUINode.transform;
		
		GUICamera.nearClipPlane=0.2f;
		GUICamera.depth=CameraDepth;
		GUICamera.clearFlags=CameraClearFlags.Depth;
		GUICamera.cullingMask=(1<<UI.Layer);
		GUICamera.renderingPath=RenderingPath.Forward;
		
		SetCameraDistance(60f);
		SetFieldOfView(60f);
		
		Renderer=new Renderman();
		
		// Render Mesh.OutputGameObject with the GUI camera:
		Renderer.RenderWithCamera(UI.Layer);
		document=Renderer.RootDocument;
		document.window.top=document.window;
		
		// Some overriding default UI settings:
		document.html.Style.Computed.ChangeTagProperty("color",new PowerUI.Css.Value("#ffffff",PowerUI.Css.ValueType.Color));
		document.html.Style.Computed.ChangeTagProperty("font-size",new PowerUI.Css.Value("14px",PowerUI.Css.ValueType.Pixels));
		document.body.Style.Computed.ChangeTagProperty("overflow",new PowerUI.Css.Value("hidden hidden",PowerUI.Css.ValueType.Point));
		
		UpdateTextDirection();
		
		// Fire the camera event:
		CameraGotCreated(GUICamera);
		
	}
Esempio n. 11
0
	/// <summary>Clears all content from the UI and all WorldUI's. 
	/// Please note that it is safer to set innerHTML to a blank string for a particular UI than calling this.</summary>
	public static void ClearAll(){
		content=null;
		
		if(Renderer!=null){
			Renderer.Destroy();
			Renderer=null;
			document=null;
		}
		
		Fonts.Clear();
		AtlasStacks.Clear();
		Http.Clear();
		SPA.Clear();
		UIAnimation.Clear();
		DynamicTexture.RemoveAll();
		PowerUI.Input.Clear();
		ScreenInfo.Clear();
		WorldUI currentWorldUI=FirstWorldUI;
		
		while(currentWorldUI!=null){
			currentWorldUI.Destroy();
			currentWorldUI=currentWorldUI.UIAfter;
		}
		
		LastWorldUI=null;
		FirstWorldUI=null;
	}
Esempio n. 12
0
		/// <summary>Creates a new World UI with the given pixels of space and a given name.
		/// The gameobjects origin sits at the middle of the UI by default. See <see cref="PowerUI.WorldUI.SetOrigin"/>. 
		/// By default, 100 pixels are 1 world unit. See <see cref="PowerUI.WorldUI.SetResolution"/>.</summary>
		/// <param name="name">The name for the UI's gameobject.</param>
		/// <param name="widthPX">The width in pixels of this UI.</param>
		/// <param name="heightPX">The height in pixels of this UI.</param>
		public WorldUI(string name,int widthPX,int heightPX){
			// Start the UI:
			UI.Start();
			
			// Create the gameobject:
			gameObject=new GameObject();
			gameObject.name=name;
			
			// Grab the name:
			Name=name;
			
			transform=gameObject.transform;
			Renderer=new Renderman(this);
			SetDepthResolution(0.01f);
			
			// Apply the default scale:
			transform.localScale=new Vector3(1/100f,1/100f,1f);
			
			document=Renderer.RootDocument;
			
			// Add it to the UI update linked list:
			if(UI.FirstWorldUI==null){
				UI.FirstWorldUI=UI.LastWorldUI=this;
			}else{
				UIBefore=UI.LastWorldUI;
				UI.LastWorldUI=UI.LastWorldUI.UIAfter=this;
			}
			
			SetDimensions(widthPX,heightPX);
			
			SetInputMode(PowerUI.Input.WorldInputMode);
		}
		/// <summary>Loads a link into the given document.</summary>
		/// <param name="path">The path the link was pointing at.</param>
		/// <param name="document">The document the link will load into.</param>
		private void LoadIntoDocument(FilePath path,Document document){
			
			// Clear the document so it's obvious to the player the link is now loading:
			document.innerHTML="";
			document.location=path;
			
			// Load the html. Note that path.Url is fully resolved at this point:
			TextPackage package=new TextPackage(path.Url,"");
			package.ExtraData=document;
			package.Get(GotLinkText);
			
		}
Esempio n. 14
0
		public override void OnTagLoaded(){
			Loaded=true;
			// Iframes generate a new document object for isolation purposes:
			ContentDocument=new Document(Element.Document.Renderer,Element.Document.window);
			// Setup the iframe ref:
			ContentDocument.window.iframe=Element;
			// Grab the parent document:
			Document originalDocument=Element.Document;
			// Temporarily set the document of this element:
			Element.Document=ContentDocument;
			// Append the documents html node as a child of the iframe:
			Element.appendChild(ContentDocument.html);
			
			Element.Document=originalDocument;
			
			LoadContent();
			// And handle style/ other defaults:
			base.OnTagLoaded();
		}
Esempio n. 15
0
		/// <summary>Creates a new renderer and a new document.</summary>
		public Renderman(){
			ClippingBoundary=new BoxRegion(0,0,Screen.width,Screen.height);
			RootDocument=new Document(this);
			RootDocument.location=new FilePath("resources://","",false);
		}
		/// <summary>Creates a new variable element.</summary>
		/// <param name="document">The html document it will belong to.</param>
		/// <param name="parent">The parent html element.</param>
		public VariableElement(Document document,Element parent):base(document,parent){
			SetTag("span");
		}