private void GamePage_LayoutUpdated(object sender, EventArgs e) { if (uiRenderer == null || LayoutRoot.ActualWidth > 0 && LayoutRoot.ActualHeight > 0) { uiRenderer = new UIElementRenderer(LayoutRoot, (int)LayoutRoot.ActualWidth, (int)LayoutRoot.ActualHeight); } }
void GamePage_LayoutUpdated(object sender, EventArgs e) { int width = (int)ActualWidth; int height = (int)ActualHeight; if (uiRenderer != null && uiRenderer.Texture != null && uiRenderer.Texture.Width == width && uiRenderer.Texture.Height == height) { return; } // Ensure the page size is valid if (width <= 0 || height <= 0) { return; } //UIElementRenderer // uiRenderer = this.get(); // Do we already have a UIElementRenderer of the correct size? // Before constructing a new UIElementRenderer, be sure to Dispose the old one if (uiRenderer != null) { uiRenderer.Dispose(); } uiRenderer = new UIElementRenderer(this, width, height); }
void GamePage_LayoutUpdated(object sender, EventArgs e) { if (null == silverlightRenderer) { silverlightRenderer = new UIElementRenderer(this, 800, 480); } }
private void InitializeXNA() { _device = SharedGraphicsDeviceManager.Current.GraphicsDevice; // Set the sharing mode of the graphics device to turn on XNA rendering _device.SetSharingMode(true); // Create a new SpriteBatch, which can be used to draw textures. _spriteBatch = new SpriteBatch(_device); BackgroundRenderer = new UIElementRenderer(this, _device.Viewport.Width, _device.Viewport.Height); // Create a timer for this page _gameTimer = new GameTimer(); _gameTimer.UpdateInterval = TimeSpan.FromTicks(333333); _gameTimer.Update += new EventHandler <GameTimerEventArgs>(_gameTimer_Update); _gameTimer.Draw += new EventHandler <GameTimerEventArgs>(_gameTimer_Draw); _cameraMatrix = Matrix.CreateLookAt(Vector3.Zero, Vector3.Forward, Vector3.Up); _projectionMatrix = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver2, (float)(this.LayoutRoot.ActualWidth / this.LayoutRoot.ActualHeight), 0.01f, 10000.0f); foreach (LocationsVM.Location l in myVM.SelectedNearbyLocations) { l.Object3dEffect = new BasicEffect(_device); l.Object3dEffect.World = l.WorldMatrix; l.Object3dEffect.View = _cameraMatrix; l.Object3dEffect.Projection = _projectionMatrix; l.Object3dEffect.TextureEnabled = true; } _gameTimer.Start(); }
void MainPage_LayoutUpdated(object sender, EventArgs e) { // Create the UIElementRenderer to draw the Silverlight page to a texture. // Verify the page has a valid size if (ActualWidth <= 0 && ActualHeight <= 0) { return; } int width = (int)ActualWidth; int height = (int)ActualHeight; // See if the UIElementRenderer is already the page's size if ((elementRenderer != null) && (elementRenderer.Texture != null) && (elementRenderer.Texture.Width == width) && (elementRenderer.Texture.Height == height)) { return; } // Dispose the UIElementRenderer before creating a new one if (elementRenderer != null) { elementRenderer.Dispose(); } elementRenderer = new UIElementRenderer(this, width, height); }
protected override void Write(UIElementRenderer renderer, TaskList taskList) { var checkbox = GetClassedElement <Toggle>("task-list"); checkbox.value = taskList.Checked; checkbox.SetEnabled(false); renderer.WriteInline(checkbox); }
/*public override bool animate() * { * }*/ public void draw() { if (uirInternal != null) { uirInternal.Dispose(); } uirInternal = null; repaint(); }
protected override void Write(UIElementRenderer renderer, CodeBlock obj) { var codeBlock = GetClassedElement <VisualElement>("code"); codeBlock.RegisterCallback <MouseUpEvent>(CopyToClipboard); renderer.Push(codeBlock); renderer.WriteLeafRawLines(obj); renderer.Pop(); }
protected override void Write(UIElementRenderer renderer, CodeInline obj) { var codeInline = GetClassedElement <Label>("code"); codeInline.text = obj.Content; codeInline.RegisterCallback <AttachToPanelEvent>(OnAttach); renderer.WriteInline(codeInline); }
protected override void Write(UIElementRenderer renderer, LiteralInline obj) { if (obj.Content.IsEmpty) { return; } renderer.WriteText(ref obj.Content); }
void GamePage_LayoutUpdated(object sender, EventArgs e) { // Create the UIElementRenderer to draw the XAML page to a texture. // Check for 0 because when we navigate away the LayoutUpdate event // is raised but ActualWidth and ActualHeight will be 0 in that case. if (ActualWidth > 0 && ActualHeight > 0 && elementRenderer == null) { elementRenderer = new UIElementRenderer(this, (int)640, (int)480); } }
public void CreateAndInit() { m_rootRenderer = m_widgetHandler.CreateWidgetRenderer(m_screen.Root); m_textureManager = new UITextureManager(); // Load all associated atlases. foreach (outki.Atlas a in m_screen.Atlases) { if (a != null) m_textureManager.AddAtlas(a); } }
protected override void Write(UIElementRenderer renderer, LineBreakInline obj) { if (obj.IsHard) { renderer.WriteInline(GetClassedElement <Label>("linebreak")); } else { // Soft line break. renderer.WriteText(" "); } }
protected override void OnNavigatedFrom(NavigationEventArgs e) { // Stop the timer timer.Stop(); // Set the sharing mode of the graphics device to turn off XNA rendering SharedGraphicsDeviceManager.Current.GraphicsDevice.SetSharingMode(false); base.OnNavigatedFrom(e); elementRenderer.Dispose(); elementRenderer = null; }
public GamePage() { InitializeComponent(); // Get the content manager from the application contentManager = (Application.Current as App).Content; // Create a timer for this page timer = new GameTimer(); timer.UpdateInterval = TimeSpan.FromTicks(333333); timer.Update += OnUpdate; timer.Draw += OnDraw; scoreboardRenderer = new UIElementRenderer(scoreboard, 456, 60); }
void GamePage_LayoutUpdated(object sender, EventArgs e) { // 指定窗口的宽和高 if ((ActualWidth > 0) && (ActualHeight > 0)) { SharedGraphicsDeviceManager.Current.PreferredBackBufferWidth = (int)ActualWidth; SharedGraphicsDeviceManager.Current.PreferredBackBufferHeight = (int)ActualHeight; } // 实例化 silverlight 元素绘制器 if (elementRenderer == null) { elementRenderer = new UIElementRenderer(this, (int)ActualWidth, (int)ActualHeight); } }
public GamePage() { HEIGHT = SharedGraphicsDeviceManager.DefaultBackBufferWidth; WIDTH = SharedGraphicsDeviceManager.DefaultBackBufferHeight; // Create a timer for this page timer = new GameTimer(); timer.UpdateInterval = TimeSpan.FromTicks(333333); timer.Update += OnUpdate; timer.Draw += OnDraw; _uiRender = new UIElementRenderer(this, WIDTH, HEIGHT); contentManager = (Application.Current as App).Content; InitializeComponent(); }
protected override void Write(UIElementRenderer renderer, AutolinkInline link) { var url = link.Url; var lowerScheme = string.Empty; if (link.IsEmail) { url = "mailto:" + url; } var isValidUri = Uri.IsWellFormedUriString(url, UriKind.RelativeOrAbsolute); if (!isValidUri) { var match = LinkInlineRenderer.SchemeCheck.Match(url); if (match.Success) { lowerScheme = match.Groups[1].Value.ToLower(); } else { lowerScheme = "#"; } } else { var uri = new Uri(url); lowerScheme = uri.Scheme.ToLower(); } var linkLabel = GetClassedElement <VisualElement>("link", lowerScheme); if (isValidUri) { linkLabel.RegisterCallback <MouseUpEvent>(evt => { if (LinkInlineRenderer.SchemeLinkHandlers.ContainsKey(lowerScheme)) { LinkInlineRenderer.SchemeLinkHandlers[lowerScheme]?.Invoke(url); } }); } linkLabel.tooltip = url; renderer.Push(linkLabel); renderer.WriteText(url); renderer.Pop(); }
protected override void OnNavigatedTo(NavigationEventArgs e) { SharedGraphicsDeviceManager.Current.GraphicsDevice.SetSharingMode(true); // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(SharedGraphicsDeviceManager.Current.GraphicsDevice); _missileManager = new Missile.missileManager(contentManager); _line = new Lines(contentManager); _uiRender = new UIElementRenderer(this, 800, 480); timer.Start(); base.OnNavigatedTo(e); }
private void GamePage_LayoutUpdated(object sender, EventArgs e) { // Create the UIElementRenderer to draw the XAML page to a texture. // Check for 0 because when we navigate away the LayoutUpdate event // is raised but ActualWidth and ActualHeight will be 0 in that case. if ((ActualWidth > 0) && (ActualHeight > 0)) { SharedGraphicsDeviceManager.Current.PreferredBackBufferWidth = (int)ActualWidth; SharedGraphicsDeviceManager.Current.PreferredBackBufferHeight = (int)ActualHeight; } if (null == elementRenderer) { elementRenderer = new UIElementRenderer(this, (int)ActualWidth, (int)ActualHeight); } }
protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e) { // Stop the timer timer.Stop(); isActive = false; // Set the sharing mode of the graphics device to turn off XNA rendering SharedGraphicsDeviceManager.Current.GraphicsDevice.SetSharingMode(false); if (e.NavigationMode == System.Windows.Navigation.NavigationMode.Back) { elementRenderer.Dispose(); elementRenderer = null; } base.OnNavigatedFrom(e); }
private void SetupTheUIRenderer() { if (uiRenderer != null && uiRenderer.Texture != null && uiRenderer.Texture.Width == 800 && uiRenderer.Texture.Height == 480) { return; } // Before constructing a new UIElementRenderer, be sure to Dispose the old one if (uiRenderer != null) { uiRenderer.Dispose(); } // Create the renderer uiRenderer = new UIElementRenderer(this, 800, 480); }
protected override void OnNavigatedTo(NavigationEventArgs e) { // Set the sharing mode of the graphics device to turn on XNA rendering SharedGraphicsDeviceManager.Current.GraphicsDevice.SetSharingMode(true); // TODO: use this.content to load your game content here if (!AppLoaded) { game.CLoadContent(); AppLoaded = true; } UiElementRenderer = new UIElementRenderer(LayoutRoot, SharedGraphicsDeviceManager.Current.GraphicsDevice.Viewport.Width, SharedGraphicsDeviceManager.Current.GraphicsDevice.Viewport.Height); // Start the timer timer.Start(); base.OnNavigatedTo(e); }
protected override void Write(UIElementRenderer renderer, EmphasisInline obj) { string delimiterClass = null; switch (obj.DelimiterChar) { case '*': case '_': delimiterClass = obj.DelimiterCount == 2 ? "bold" : "italic"; break; case '~': delimiterClass = obj.DelimiterCount == 2 ? "strikethrough" : "subscript"; break; case '^': delimiterClass = "superscript"; break; case '+': delimiterClass = "inserted"; break; case '=': delimiterClass = "marked"; break; } if (delimiterClass != null) { renderer.Push(GetClassedElement <VisualElement>(delimiterClass)); renderer.WriteChildren(obj); renderer.Pop(); } else { renderer.WriteChildren(obj); } }
void MainPage_LayoutUpdated(object sender, EventArgs e) { // Create the UIElementRenderer to draw the XAML page to a texture. // Check for 0 because when we navigate away the LayoutUpdate event // is raised but ActualWidth and ActualHeight will be 0 in that case. if ((ActualWidth > 0) && (ActualHeight > 0)) { SharedGraphicsDeviceManager.Current.PreferredBackBufferWidth = (int)ActualWidth; SharedGraphicsDeviceManager.Current.PreferredBackBufferHeight = (int)ActualHeight; } // make sure page size is valid if (ActualWidth == 0 || ActualHeight == 0) { return; } // see if we already have the right sized renderer if (elementRenderer != null && elementRenderer.Texture != null && elementRenderer.Texture.Width == (int)ActualWidth && elementRenderer.Texture.Height == (int)ActualHeight) { return; } if (null == elementRenderer) { if (ActualHeight > ActualWidth) { elementRenderer = new UIElementRenderer(this, (int)ActualHeight, (int)ActualWidth); } else { elementRenderer = new UIElementRenderer(this, (int)ActualWidth, (int)ActualHeight); } } }
public void Destory() { log.I("LGame 2D Engine Shutdown"); isClose = true; XNAConfig.Dispose(); useXNAListener = false; if (this.sl_listener != null) { this.sl_listener.Dispose(GamePage, true); this.sl_listener = null; } if (UIElementRenderer != null) { UIElementRenderer.Dispose(); UIElementRenderer = null; } if (content != null) { content.Unload(); content = null; } }
protected override void Write(UIElementRenderer renderer, ListBlock listBlock) { renderer.Push(GetClassedElement <VisualElement>("list")); foreach (var item in listBlock.OfType <ListItemBlock>()) { var listItem = GetClassedElement <VisualElement>("list-item"); renderer.Push(listItem); var marker = listBlock.IsOrdered ? $"{item.Order}." : $"{listBlock.BulletType}"; var classes = listBlock.IsOrdered ? "inline" : "bullet"; renderer.WriteChildren(item); listItem.Children()?.FirstOrDefault()?.Insert(0, GetTextElement <Label>(marker, classes)); renderer.Pop(); } renderer.Pop(); }
void GamePage_LayoutUpdated(object sender, EventArgs e) { // Create the UIElementRenderer to draw the XAML page to a texture. // Check for 0 because when we navigate away the LayoutUpdate event // is raised but ActualWidth and ActualHeight will be 0 in that case. if (ActualWidth > 0 && ActualHeight > 0 && elementRenderer == null) { elementRenderer = new UIElementRenderer(this, (int)ActualWidth, (int)ActualHeight); } }
void XNARendering_LayoutUpdated(object sender, EventArgs e) { // make sure page size is valid if (ActualWidth == 0 || ActualHeight == 0) return; // see if we already have the right sized renderer if (elementRenderer != null && elementRenderer.Texture != null && elementRenderer.Texture.Width == (int)ActualWidth && elementRenderer.Texture.Height == (int)ActualHeight) { return; } // dispose the current renderer if (elementRenderer != null) elementRenderer.Dispose(); // create the renderer elementRenderer = new UIElementRenderer(this, (int)ActualWidth, (int)ActualHeight); }
public void Initialization(bool l, bool f, LMode m) { log.I("GPU surface"); this.landscape = l; this.fullScreen = f; this.mode = m; if (landscape == false) { if (LSystem.MAX_SCREEN_HEIGHT > LSystem.MAX_SCREEN_WIDTH) { int tmp_height = LSystem.MAX_SCREEN_HEIGHT; LSystem.MAX_SCREEN_HEIGHT = LSystem.MAX_SCREEN_WIDTH; LSystem.MAX_SCREEN_WIDTH = tmp_height; } } this.CheckDisplayMode(); RectBox d = GetScreenDimension(); LSystem.SCREEN_LANDSCAPE = landscape; this.maxWidth = (int)d.GetWidth(); this.maxHeight = (int)d.GetHeight(); if (landscape && (d.GetWidth() > d.GetHeight())) { maxWidth = (int)d.GetWidth(); maxHeight = (int)d.GetHeight(); } else if (landscape && (d.GetWidth() < d.GetHeight())) { maxHeight = (int)d.GetWidth(); maxWidth = (int)d.GetHeight(); } else if (!landscape && (d.GetWidth() < d.GetHeight())) { maxWidth = (int)d.GetWidth(); maxHeight = (int)d.GetHeight(); } else if (!landscape && (d.GetWidth() > d.GetHeight())) { maxHeight = (int)d.GetWidth(); maxWidth = (int)d.GetHeight(); } if (mode != LMode.Max) { if (landscape) { this.width = LSystem.MAX_SCREEN_WIDTH; this.height = LSystem.MAX_SCREEN_HEIGHT; } else { this.width = LSystem.MAX_SCREEN_HEIGHT; this.height = LSystem.MAX_SCREEN_WIDTH; } } else { if (landscape) { this.width = maxWidth >= LSystem.MAX_SCREEN_WIDTH ? LSystem.MAX_SCREEN_WIDTH : maxWidth; this.height = maxHeight >= LSystem.MAX_SCREEN_HEIGHT ? LSystem.MAX_SCREEN_HEIGHT : maxHeight; } else { this.width = maxWidth >= LSystem.MAX_SCREEN_HEIGHT ? LSystem.MAX_SCREEN_HEIGHT : maxWidth; this.height = maxHeight >= LSystem.MAX_SCREEN_WIDTH ? LSystem.MAX_SCREEN_WIDTH : maxHeight; } } if (mode == LMode.Fill) { LSystem.scaleWidth = ((float)maxWidth) / width; LSystem.scaleHeight = ((float)maxHeight) / height; } else if (mode == LMode.FitFill) { RectBox res = GraphicsUtils.FitLimitSize(width, height, maxWidth, maxHeight); maxWidth = res.width; maxHeight = res.height; LSystem.scaleWidth = ((float)maxWidth) / width; LSystem.scaleHeight = ((float)maxHeight) / height; } else if (mode == LMode.Ratio) { maxWidth = MeasureSpec.GetSize(maxWidth); maxHeight = MeasureSpec.GetSize(maxHeight); float userAspect = (float)width / (float)height; float realAspect = (float)maxWidth / (float)maxHeight; if (realAspect < userAspect) { maxHeight = MathUtils.Round(maxWidth / userAspect); } else { maxWidth = MathUtils.Round(maxHeight * userAspect); } LSystem.scaleWidth = ((float)maxWidth) / width; LSystem.scaleHeight = ((float)maxHeight) / height; } else if (mode == LMode.MaxRatio) { maxWidth = MeasureSpec.GetSize(maxWidth); maxHeight = MeasureSpec.GetSize(maxHeight); float userAspect = (float)width / (float)height; float realAspect = (float)maxWidth / (float)maxHeight; if ((realAspect < 1 && userAspect > 1) || (realAspect > 1 && userAspect < 1)) { userAspect = (float)height / (float)width; } if (realAspect < userAspect) { maxHeight = MathUtils.Round(maxWidth / userAspect); } else { maxWidth = MathUtils.Round(maxHeight * userAspect); } LSystem.scaleWidth = ((float)maxWidth) / width; LSystem.scaleHeight = ((float)maxHeight) / height; } else { LSystem.scaleWidth = 1; LSystem.scaleHeight = 1; } if (landscape) { GamePage.Orientation = Microsoft.Phone.Controls.PageOrientation.Landscape | Microsoft.Phone.Controls.PageOrientation.LandscapeLeft | Microsoft.Phone.Controls.PageOrientation.LandscapeRight; GamePage.SupportedOrientations = Microsoft.Phone.Controls.SupportedPageOrientation.Landscape; } else { GamePage.Orientation = Microsoft.Phone.Controls.PageOrientation.Portrait | Microsoft.Phone.Controls.PageOrientation.PortraitDown | Microsoft.Phone.Controls.PageOrientation.PortraitUp; GamePage.SupportedOrientations = Microsoft.Phone.Controls.SupportedPageOrientation.Portrait; } LSystem.screenRect = new RectBox(0, 0, width, height); graphics.PreferredBackBufferFormat = displayMode.Format; graphics.PreferredBackBufferWidth = maxWidth; graphics.PreferredBackBufferHeight = maxHeight; if (GamePage != null) { UIElementRenderer = new UIElementRenderer(GamePage, maxWidth, maxHeight); } //������Ⱦ����ʾ��ͬ�� graphics.SynchronizeWithVerticalRetrace = true; graphics.ApplyChanges(); isFPS = false; if (maxFrames <= 0) { SetFPS(LSystem.DEFAULT_MAX_FPS); } LSystem.screenActivity = this; LSystem.screenProcess = (process = new LProcess(this, width, height)); StringBuilder sbr = new StringBuilder(); sbr.Append("Mode:").Append(mode); log.I(sbr.ToString()); sbr.Clear(); sbr.Append("Width:").Append(width).Append(",Height:" + height); log.I(sbr.ToString()); sbr.Clear(); sbr.Append("MaxWidth:").Append(maxWidth) .Append(",MaxHeight:" + maxHeight); log.I(sbr.ToString()); sbr.Clear(); sbr.Append("Scale:").Append(IsScale()); log.I(sbr.ToString()); if (GamePage != null) { GamePage.Background = null; GamePage.Foreground = null; GamePage.Style = null; GamePage.AllowDrop = false; GamePage.Visibility = System.Windows.Visibility.Collapsed; /*System.Windows.Interop.Settings settings = new System.Windows.Interop.Settings(); settings.EnableFrameRateCounter = true; settings.EnableCacheVisualization = true; settings.EnableRedrawRegions = true; settings.MaxFrameRate = maxFrames; System.Windows.Media.BitmapCache cache = new System.Windows.Media.BitmapCache(); cache.RenderAtScale = 1; GamePage.CacheMode = cache;*/ GamePage.Opacity = 1f; } }
// This can be overriden for custom drawing. public virtual void RenderSubElement(UIRenderContext rctx, ref UIElementLayout myLayout, outki.UIElement element, UIElementRenderer renderer, ref UIElementLayout layout) { renderer.Render(rctx, ref layout); }
public override void prerender() { if (str.Length == 0) { return; } if (currentFont == null) { currentFont = new XNAFont(); } int off = uirCache.IndexOf(this); if (off > -1) { uir = uirCache[off].uir; uirCache.RemoveAt(off); uirCache.Insert(0, this); return; } SilverlightImplementation.textBlockInstance.Text = str; SilverlightImplementation.textBlockInstance.Foreground = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromArgb(col.A, col.R, col.G, col.B)); currentFont.applyFont(SilverlightImplementation.textBlockInstance); SilverlightImplementation.textBlockInstance.Measure(new Size(10000, 10000)); int dw = (int)SilverlightImplementation.textBlockInstance.DesiredSize.Width; int dh = (int)SilverlightImplementation.textBlockInstance.DesiredSize.Height; uir = new UIElementRenderer(SilverlightImplementation.textBlockInstance, dw, dh); uir.Render(); uirCache.Insert(0, this); if (uirCache.Count > 50) { uirCache[50].uir.Dispose(); uirCache.RemoveAt(50); } }
protected override void OnNavigatedTo(NavigationEventArgs e) { // Set the sharing mode of the graphics device to turn on XNA rendering SharedGraphicsDeviceManager.Current.GraphicsDevice.SetSharingMode(true); // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(SharedGraphicsDeviceManager.Current.GraphicsDevice); uiElementRenderer = new UIElementRenderer(grdResult, 800, 480); // TODO: use this.content to load your game content here LoadContent(); // Start the timer timer.Start(); base.OnNavigatedTo(e); }
private void img_Tap(object sender) { gridBlanc.Width = 0; gridBlanc.Height = 0; gridBlanc.Margin = new Thickness(400, 240, 0, 0); //On cherche la bonne question à afficher dbc = new DataBaseContext(DataBaseContext.DBConnectionString); question = dbc.Questions.First(x => x.Id == int.Parse((sender as Image_Texture).IdQuestion.ToString())); dbc.Dispose(); txtQuestion.Text = question.Intitule; //Audio mp3.IsMuted = false; mp3.Source = new Uri(question.Mp3, UriKind.Relative); mp3.Position = new TimeSpan(0); mp3.Volume = 1; uiRenderer = new UIElementRenderer(gridLayout, SharedGraphicsDeviceManager.Current.GraphicsDevice.Viewport.Width, SharedGraphicsDeviceManager.Current.GraphicsDevice.Viewport.Height); }
/* Additional For XNA Rendering */ private void XNARendering(object sender, EventArgs e) { if (hudRenderer != null && hudRenderer.Texture != null && hudRenderer.Texture.Width == (int)ActualWidth && hudRenderer.Texture.Height == (int)ActualHeight) { return; } if (hudRenderer != null) hudRenderer.Dispose(); if (ActualHeight > 0 || ActualWidth > 0) { hudRenderer = new UIElementRenderer(this, (int)ActualWidth, (int)ActualHeight); } }
void GameOverPage_LayoutUpdated(object sender, EventArgs e) { // Create the UIElementRenderer to draw the XAML page to a texture. // Check for 0 because when we navigate away the LayoutUpdate event // is raised but ActualWidth and ActualHeight will be 0 in that case. if ((ActualWidth > 0) && (ActualHeight > 0)) { SharedGraphicsDeviceManager.Current.PreferredBackBufferWidth = (int)ActualWidth; SharedGraphicsDeviceManager.Current.PreferredBackBufferHeight = (int)ActualHeight; } // make sure page size is valid if (ActualWidth == 0 || ActualHeight == 0) return; // see if we already have the right sized renderer if (elementRenderer != null && elementRenderer.Texture != null && elementRenderer.Texture.Width == (int)ActualWidth && elementRenderer.Texture.Height == (int)ActualHeight) { return; } if (null == elementRenderer) { if (ActualHeight > ActualWidth) elementRenderer = new UIElementRenderer(this, (int)ActualHeight, (int)ActualWidth); else elementRenderer = new UIElementRenderer(this, (int)ActualWidth, (int)ActualHeight); } }
private void SetupTheUIRenderer() { if (uiRenderer != null && uiRenderer.Texture != null && uiRenderer.Texture.Width == 800 && uiRenderer.Texture.Height == 480) { return; } // Before constructing a new UIElementRenderer, be sure to Dispose the old one if (uiRenderer != null) uiRenderer.Dispose(); // Create the renderer uiRenderer = new UIElementRenderer(this, 800, 480); }
void GamePage_LayoutUpdated(object sender, EventArgs e) { int width = (int)ActualWidth; int height = (int)ActualHeight; if (width <= 0 || height <= 0) return; if (uiRenderer != null && uiRenderer.Texture != null && uiRenderer.Texture.Width == width && uiRenderer.Texture.Height == height) { return; } if (uiRenderer != null) uiRenderer.Dispose(); uiRenderer = new UIElementRenderer(this, width, height); }
protected override void Write(UIElementRenderer renderer, ThematicBreakBlock obj) { renderer.WriteBlock(GetClassedElement <VisualElement>("thematicbreak")); }
protected override void Write(UIElementRenderer renderer, ParagraphBlock obj) { renderer.Push(GetClassedElement <VisualElement>("paragraph")); renderer.WriteLeafInline(obj); renderer.Pop(); }
protected override void OnNavigatedTo(NavigationEventArgs e) { // Définissez le mode de partage de l'appareil graphique pour activer le rendu XNA SharedGraphicsDeviceManager.Current.GraphicsDevice.SetSharingMode(true); mp3.IsMuted = true; //On parse var data = this.NavigationContext.QueryString; id = int.Parse(data["id"]); question = new Question(); gridBlanc.Margin = new Thickness(900); gridBlanc.Width = 0; // Créer un nouveau SpriteBatch, qui peut être utilisé pour dessiner des textures. spriteBatch = new SpriteBatch(SharedGraphicsDeviceManager.Current.GraphicsDevice); // TODO: utilisez ce contenu pour charger ici le contenu de votre jeu //On récupère la Photo dbc = new DataBaseContext(DataBaseContext.DBConnectionString); var photo = from album in dbc.Photos where album.Id == int.Parse(this.NavigationContext.QueryString["id"]) select album; img = new BitmapImage(); using (IsolatedStorageFile isoStorage = IsolatedStorageFile.GetUserStoreForApplication()) { if (isoStorage.FileExists(photo.First().Background)) { using (IsolatedStorageFileStream fileStream = isoStorage.OpenFile(photo.First().Background, FileMode.Open, FileAccess.Read)) { img.SetSource(fileStream); fileStream.Close(); } } } imgRendu.Source = img; _uiRenderer = new UIElementRenderer(gridImage, SharedGraphicsDeviceManager.Current.GraphicsDevice.Viewport.Width, SharedGraphicsDeviceManager.Current.GraphicsDevice.Viewport.Height); /** * LES OBJETS **/ lstInteractionsPhotos = new List<InteractionPhoto>(); var images = from image in dbc.InteractionsPhotos where image.PhotoId == int.Parse(this.NavigationContext.QueryString["id"]) select image; texture_InteractionsPhotos = new List<Image_TexturePhoto>(); foreach (var interaction in images) { texture_InteractionsPhotos.Add(new Image_TexturePhoto(interaction.QuestionId, interaction.Question.Nom, new Vector2((float)interaction.X/512 * 800, (float)interaction.Y/307 * 480), (int)((float)interaction.Longueur/512 * 800), (int)((float)interaction.Hauteur/307 * 480))); //Créé fonction qui permet d'ajouter une image dans la classe image_interaction /*if (i != interaction.Id) { if (interaction.Id != images.First().Id) { textureTmp.LoadContent((Application.Current as App).Content); texture_InteractionsPhotos.Add(textureTmp); } textureTmp = new Image_Texture(interaction.QuestionId, interaction.Question.Nom, interaction.Url, new Vector2(interaction.X, interaction.Y), interaction.Longueur, interaction.Hauteur); } else {*/ //texture_InteractionsPhotos.Add(AjoutTexture(interaction.Url, new Vector2(interaction.X, interaction.Y), interaction.Longueur, interaction.Hauteur, (Application.Current as App).Content); //Ajouter une image a l'objet Image_interaction crée précédement. //} } foreach (Image_TexturePhoto interaction in texture_InteractionsPhotos) { interaction.LoadContent(contentManager); } dbc.Dispose(); _victor = new Victor("marche", new Vector2(100,300)); _victor.LoadContent(contentManager); _collision = false; click_souris = false; /*_retour = new Image_Texture(-1, "retour", "previous", new Vector2(0, 0), 50, 50); _retour.LoadContent(contentManager); */ if(!first) { TouchPanel.EnabledGestures = GestureType.Tap; souris.X = 200; souris.Y = 300; Vector2 tmpVector = new Vector2(200, 300); _victor.Position = tmpVector; _victor.repositionnement(); } /** * LES INTERACTIONS **/ TouchPanel.EnabledGestures = GestureType.Tap; // Démarrez la minuterie timer.Start(); base.OnNavigatedTo(e); }
protected override void OnNavigatedTo(NavigationEventArgs e) { // Définissez le mode de partage de l'appareil graphique pour activer le rendu XNA SharedGraphicsDeviceManager.Current.GraphicsDevice.SetSharingMode(true); if (sonPremiere) { mp3.IsMuted = false; mp3.Source = new Uri("/MP3/Home/Menu/HomeMenu.mp3", UriKind.Relative); mp3.Position = new TimeSpan(0); mp3.Volume = 1; mp3.Play(); sonPremiere = false; } else mp3.IsMuted = true; // Créer un nouveau SpriteBatch, qui peut être utilisé pour dessiner des textures. spriteBatch = new SpriteBatch(SharedGraphicsDeviceManager.Current.GraphicsDevice); question = new Question(); gridBlanc.Margin = new Thickness(900); gridBlanc.Width = 0; if (first == true) { // TODO: utilisez ce contenu pour charger ici le contenu de votre jeu //On récupère le niveau et la scène var data = this.NavigationContext.QueryString; niveau = data["niveau"]; lvl = data["scene"]; //Connexion à la BDD dbc = new DataBaseContext(DataBaseContext.DBConnectionString); /** * BACKGROUND **/ //On récupère l'arrière plan de la scène var bg = from scene in dbc.Scenes where scene.Nom == lvl select scene; //On affecte background = (Application.Current as App).Content.Load<Texture2D>(bg.First().Background); positionBackground = Vector2.Zero; //Debug, indication des coordonnées du pointeur font = (Application.Current as App).Content.Load<SpriteFont>(@"SpriteFont1"); /** * LES OBJETS **/ lstImage_Interactions = new List<Interaction>(); var images = from image in dbc.Interactions where image.Scene.Nom == lvl select image; /** * RENDU **/ int i = -1; Image_Texture textureTmp = new Image_Texture(); texture_Interactions = new List<Image_Texture>(); foreach (var interaction in images) { //Si l'interaction n'a pas encore d'image //Créé fonction qui permet d'ajouter une image dans la classe image_interaction if(i != interaction.Id) { if(interaction.Id != images.First().Id)//Si il y a eu une interaction avant, on lance le loader { textureTmp.LoadContent(contentManager); texture_Interactions.Add(textureTmp); } textureTmp = new Image_Texture(interaction.QuestionId, interaction.Question.Nom, interaction.Url, new Vector2(interaction.X, interaction.Y), interaction.Longueur, interaction.Hauteur); } else//Si l'interaction à deja une image ou plusieurs, on rajoute une image { textureTmp.AjoutTexture(interaction.Url, new Vector2(interaction.X, interaction.Y), interaction.Longueur, interaction.Hauteur, (Application.Current as App).Content); //Ajouter une image a l'objet Image_interaction crée précédement. } i = interaction.Id; } if (images.Count() != 0)//Si il y a des interactions, il faut lancer le content pour la dernière interaction et l'ajouter a la liste { textureTmp.LoadContent(contentManager); texture_Interactions.Add(textureTmp); } //On s'occupe de la lampe _lampe = new Image_Texture(-1, "lampe_cuisine", "lampe_cuisine", new Vector2(1250, 0), 130, 258); _lampe.LoadContent(contentManager); _rotationLampe = 0; _deltaRotationLampe = 10; _directionLampe = true; //On s'occupe des aiguilles _petiteAiguille = new Image_Texture(-1, "petite_aiguille", "aiguille-p", new Vector2(379, 43), 3, 12); _petiteAiguille.LoadContent(contentManager); _rotationGrandeAiguille = 180; _grandeAiguille = new Image_Texture(-1, "grande_aiguille", "aiguille-g", new Vector2(379, 43), 3, 23); _grandeAiguille.LoadContent(contentManager); _rotationPetiteAiguille = 180; //On s'occupe de la flamme _flammesSprite = new BouteilleCours("FlammesSprites", new Vector2(860, 290), 4); _flammesSprite.LoadContent(contentManager); /** * FERMETURE BDD **/ dbc.Dispose(); _uiRenderer = new UIElementRenderer(gridLayout, SharedGraphicsDeviceManager.Current.GraphicsDevice.Viewport.Width, SharedGraphicsDeviceManager.Current.GraphicsDevice.Viewport.Height); /** * LES INTERACTIONS **/ TouchPanel.EnabledGestures = GestureType.Tap; /** * AUTRES **/ _victor = new Victor("marche", new Vector2(200, 300)); _victor.LoadContent(contentManager); first = false; } //On replace victor au milieu de l'écran else { TouchPanel.EnabledGestures = GestureType.Tap; souris.X = 200; souris.Y = 300; _destinationSouris.X = 200; _destinationSouris.Y = 300; Vector2 tmpVector = new Vector2(200, 300); _victor.Position = tmpVector; _victor.repositionnement(); } _puzzleTexture = contentManager.Load<Texture2D>("puzzle1"); _puzzle = new Rectangle(900, 900, 0, 0); Session.isPuzzleCuisineAvailable(); _puzzleApparition = 50; _collision = false; //_retour = new Image_Texture(-1, "retour", "previous", new Vector2(0, 0), 50, 50); //_retour.LoadContent(contentManager); // Démarrez la minuterie timer.Start(); base.OnNavigatedTo(e); }
/// <summary> /// Handles the LayoutUpdated event of the GamePage control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> private void GamePage_LayoutUpdated(object sender, EventArgs e) { // make sure page size is valid if (this.ActualWidth == 0 || this.ActualHeight == 0) { return; } // see if we already have the right sized renderer if (this.elementRenderer != null && this.elementRenderer.Texture != null && this.elementRenderer.Texture.Width == (int)ActualWidth && this.elementRenderer.Texture.Height == (int)ActualHeight) { return; } // dispose the current renderer if (this.elementRenderer != null) { this.elementRenderer.Dispose(); } // create the renderer this.elementRenderer = new UIElementRenderer(this, (int)ActualWidth, (int)ActualHeight); }
/// <summary> /// UpdateLayout /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void GamePage_LayoutUpdated(object sender, EventArgs e) { if ((ActualWidth > 0) && (ActualHeight > 0)) { SharedGraphicsDeviceManager.Current.PreferredBackBufferWidth = (int)ActualWidth; SharedGraphicsDeviceManager.Current.PreferredBackBufferHeight = (int)ActualHeight; } if (null == elementRenderer) { elementRenderer = new UIElementRenderer(this, (int)ActualWidth, (int)ActualHeight); } }
protected override void Write(UIElementRenderer renderer, LinkInline link) { var url = link.Url; if (link.IsImage) { var imageElement = GetClassedElement <Image>("image"); if (IsAssetDirectory(url)) { var image = AssetDatabase.LoadAssetAtPath <Texture>(url); if (image) { SetupImage(imageElement, image); } } else { async Task DownloadImage(string MediaUrl) { UnityWebRequest request = UnityWebRequestTexture.GetTexture(MediaUrl); var asyncOp = request.SendWebRequest(); while (!asyncOp.isDone) { await Task.Delay(100); } #if UNITY_2020_1_OR_NEWER if (request.result == UnityWebRequest.Result.ConnectionError || request.result == UnityWebRequest.Result.ProtocolError) #else if (request.isNetworkError || request.isHttpError) #endif { Debug.Log(request.error); } else { SetupImage(imageElement, ((DownloadHandlerTexture)request.downloadHandler).texture); } } _ = DownloadImage(link.Url); } renderer.Push(imageElement); renderer.WriteChildren(link); foreach (var child in imageElement.Children()) { child.AddToClassList("alt-text"); } renderer.Pop(); } else { var lowerScheme = string.Empty; var isValidUri = Uri.IsWellFormedUriString(url, UriKind.RelativeOrAbsolute); if (!isValidUri) { var match = LinkInlineRenderer.SchemeCheck.Match(url); if (match.Success) { lowerScheme = match.Groups[1].Value.ToLower(); } else { lowerScheme = "#"; } } else { var uri = new Uri(url); lowerScheme = uri.Scheme.ToLower(); } var linkLabel = GetClassedElement <VisualElement>("link", lowerScheme); linkLabel.tooltip = url; if (isValidUri) { linkLabel.RegisterCallback <MouseUpEvent>(evt => { if (LinkInlineRenderer.SchemeLinkHandlers.ContainsKey(lowerScheme)) { LinkInlineRenderer.SchemeLinkHandlers[lowerScheme]?.Invoke(url); } }); } renderer.Push(linkLabel); renderer.WriteChildren(link); renderer.Pop(); } }
protected override void Write(UIElementRenderer renderer, HtmlEntityInline obj) { var transcoded = obj.Transcoded; renderer.WriteText(ref transcoded); }