private void SetupCameraControl() { if (_cameraControl != null) { SizeChanged -= OnSizeChanged; } _cameraControl = (CameraControl)GetTemplateChild(CAMERACONTROL_NAME); if (_cameraControl != null) { _compositor = _cameraControl.CompositionCamera.CameraVisual.Compositor; SizeChanged += OnSizeChanged; // World root var worldRoot = SetupWorldRoot(); // Camera setup _cameraControl.ViewportSize = RenderSize.ToVector2(); _cameraControl.Position = new Vector3(0, 0, 1000); _cameraControl.SetAsPerspective(RenderSize.ToVector2()); _cameraControl.PerspectiveDistance = (float)(RenderSize.Height + RenderSize.Width) / 3; // ImageLoader _surfaceFactory = SurfaceFactory.GetSharedSurfaceFactoryForCompositor(_compositor); // Skybox var halfSkyboxSize = _skyboxSize / 2; var negativeHalfSkyboxSize = -_skyboxSize / 2; _skyboxContainer = _compositor.CreateContainerVisual(); _skyboxContainer.CenterPoint = new Vector3(halfSkyboxSize, halfSkyboxSize, halfSkyboxSize); _skyboxContainer.AnchorPoint = new Vector2(halfSkyboxSize, halfSkyboxSize); _skyboxContainer.Offset = new Vector3(negativeHalfSkyboxSize, negativeHalfSkyboxSize, negativeHalfSkyboxSize); _skyboxContainer.RotationAxis = _rotationAxisY; _skyboxContainer.BorderMode = CompositionBorderMode.Hard; _skyboxContainer.Comment = "Skybox"; SetupSkyboxSide(ref _skyboxTop, new Vector3(0, 0, _skyboxSize), new Uri("ms-appx:///Assets/Skybox/Clouds/CloudsTop.jpg"), "SkyboxTop"); SetupSkyboxSide(ref _skyboxLeft, new Vector3(0, 0, _skyboxSize), new Uri("ms-appx:///Assets/Skybox/Clouds/CloudsLeft.jpg"), "SkyboxLeft"); SetupSkyboxSide(ref _skyboxRight, new Vector3(_skyboxSize, 0, 0), new Uri("ms-appx:///Assets/Skybox/Clouds/CloudsRight.jpg"), "SkyboxRight"); SetupSkyboxSide(ref _skyboxBottom, new Vector3(0, _skyboxSize, 0), new Uri("ms-appx:///Assets/Skybox/Clouds/CloudsBottom.jpg"), "SkyboxBottom"); SetupSkyboxSide(ref _skyboxFront, new Vector3(0, 0, 0), new Uri("ms-appx:///Assets/Skybox/Clouds/CloudsFront.jpg"), "SkyboxFront"); SetupSkyboxSide(ref _skyboxBack, new Vector3(0, 0, _skyboxSize), new Uri("ms-appx:///Assets/Skybox/Clouds/CloudsBack.jpg"), "SkyboxBack"); _skyboxTop.RotationAxis = _rotationAxisX; _skyboxLeft.RotationAxis = _rotationAxisY; _skyboxRight.RotationAxis = _rotationAxisY; _skyboxBottom.RotationAxis = _rotationAxisX; _skyboxTop.RotationAngleInDegrees = -90; _skyboxLeft.RotationAngleInDegrees = 90; _skyboxRight.RotationAngleInDegrees = -90; _skyboxBottom.RotationAngleInDegrees = 90; // Set up items in visual tree worldRoot.Children.InsertAtTop(_skyboxContainer); } }
void IGraphicsDriver.RenderCharacter(RenderPoint point, RenderSize size, byte flags, byte[] pixels, int pixelsHeight, int pixelsWidth) { int fontScaleX = (this.displayScaleX * size.Width) / pixelsWidth; int fontScaleY = (this.displayScaleY * size.Height) / pixelsHeight; SDL_Surface surface = (SDL_Surface)Marshal.PtrToStructure(this.surfacePtr, typeof(SDL_Surface)); for (int i = 0; i < pixelsWidth; i++) { int positionX = (point.X * this.displayScaleX) + (i * fontScaleX); for (int j = 0; j < pixelsHeight; j++) { int positionY = (point.Y * this.displayScaleY) + (j * fontScaleY); byte pixel = pixels[(j * pixelsWidth) + i]; for (int deltaY = 0; deltaY < fontScaleY; deltaY++) { for (int deltaX = 0; deltaX < fontScaleX; deltaX++) { Marshal.WriteByte(new IntPtr(surface.pixels.ToInt32() + ((positionY + deltaY) * surface.pitch) + (positionX + deltaX)), pixel); } } } } }
public void SaveIcon(Image In, string Out) { if (!(In.RawFormat.Guid == ImageFormat.Png.Guid)) { In = ConvertToPNG(In); } List <Bitmap> Images = new List <Bitmap>(); foreach (Size RenderSize in RenderSizes) { Console.WriteLine($"Rendering at {RenderSize.ToString()}"); Bitmap Res = (Bitmap)ResizeImage(In, RenderSize); Console.WriteLine($"Resized Format: {Res.RawFormat}"); if (Res.RawFormat.Guid != ImageFormat.Png.Guid) { Res = (Bitmap)ConvertToPNG(Res); } Images.Add(Res); } IconFactory factory = new IconFactory(); if (File.Exists(Out)) { File.SetAttributes(Out, FileAttributes.Normal); File.Delete(Out); } using (FileStream FS = new FileStream(Out, FileMode.CreateNew, FileAccess.Write)) { IconFactory.SavePngsAsIcon(Images, FS); FS.Close(); } }
/// <summary> /// Returns the render image /// </summary> public byte[] GetRenderData(long typeId, RenderSize size) { const string relUri = "/Render"; const string ext = ".png"; return(requestImageData(relUri, typeId, (int)size, ext)); }
public virtual void HitTest(HitTestResult result) { if (RenderSize.IsPointInside(result.PointToTest)) { result.AddVisual(this); } }
/// <summary> /// Saves the image to disk , and returns the path to the image. /// </summary> public Task <string> GetRenderAsync(long typeId, RenderSize size, string path) { const string relUri = "/Render"; const string ext = ".png"; return(requestImageAsync(relUri, typeId, (int)size, ext, path)); }
public LayoutMetrics ToClr() { return(new LayoutMetrics { ActualHeight = ActualHeight, ActualWidth = ActualWidth, LayoutSlot = LayoutSlot.ToClr(), VisualOffset = VisualOffset.ToClr(), LayoutClip = LayoutClip.ToClr(), HiddenDesire = HiddenDesire.ToClr(), DesiredSize = DesiredSize.ToClr(), RenderSize = RenderSize.ToClr(), AbsoluteXform = AbsoluteXform, LayoutXform = LayoutXform, LocalXform = LocalXform, RenderXform = RenderXform, TotalOpacity = TotalOpacity, TotalIsRenderVisible = TotalIsRenderVisible, TotalIsHitTestVisible = TotalIsHitTestVisible, TotalRenderProjection = TotalRenderProjection, }); }
public MainWindow() { InitializeComponent(); #if DEBUG SizeChanged += (sender, e) => { Title = RenderSize.ToString(); }; #endif }
private void SetupCameraControl() { // Unregister if (_cameraControl != null) { SizeChanged -= OnSizeChanged; } // Get template part _cameraControl = (CameraControl)GetTemplateChild(CAMERACONTROL_NAME); // Bail if missing if (_cameraControl == null) { return; } SizeChanged += OnSizeChanged; // Camera setup _cameraControl.SetAsPerspective(RenderSize.ToVector2()); _cameraControl.Yaw = 0; _cameraControl.Pitch = 0; _cameraControl.PerspectiveDistance = 575; _cameraControl.Position = new Vector3(_stageWidth / 2, _stageBackdropHeight / 2, -1 * _stageFloorDepth / 2); // ImageLoader _compositor = _cameraControl.CompositionCamera.CameraVisual.Compositor; _surfaceFactory = SurfaceFactory.GetSharedSurfaceFactoryForCompositor(_compositor); // Stage container _stageContainer = _compositor.CreateContainerVisual(); _stageContainer.CenterPoint = new Vector3(_stageWidth / 2, _stageBackdropHeight / 2, _stageFloorDepth / 2); _stageContainer.AnchorPoint = new Vector2(_stageWidth / 2, _stageBackdropHeight / 2); _stageContainer.Offset = new Vector3(-1 * _stageWidth / 2, -1 * _stageBackdropHeight * 0.75f, -1 * _stageFloorDepth / 4); _stageContainer.RotationAxis = _rotationAxisY; _stageContainer.BorderMode = CompositionBorderMode.Hard; _stageContainer.Comment = "Stage"; // Backdrop + Floor SetupStageSide(StageSide.Backdrop); SetupStageSide(StageSide.Floor); // World root SpriteVisual treeRoot = _compositor.CreateSpriteVisual(); SpriteVisual worldRoot = _compositor.CreateSpriteVisual(); treeRoot.Comment = "TreeRoot"; worldRoot.Comment = "WorldRoot"; ElementCompositionPreview.SetElementChildVisual(_cameraControl, treeRoot); treeRoot.Children.InsertAtTop(worldRoot); worldRoot.Children.InsertAtTop(_stageContainer); }
protected override void OnRender(swm.DrawingContext dc) { var handler = Column.Handler; var graphics = new Graphics(new GraphicsHandler(this, dc, new sw.Rect(RenderSize), new RectangleF(RenderSize.ToEto()), false)); var state = IsSelected ? CellStates.Selected : CellStates.None; #pragma warning disable 618 var args = new DrawableCellPaintEventArgs(graphics, new Rectangle(RenderSize.ToEtoSize()), state, DataContext); #pragma warning restore 618 handler.Callback.OnPaint(handler.Widget, args); }
public void RenderBox(RenderLocation Location, RenderSize Size) { string s = "╔"; string space = ""; string temp = ""; for (int i = Location.X; i < Size.Width; i++) { space += " "; s += "═"; } for (int j = 0; j < Location.X; j++) { temp += " "; } s += "╗" + "\n"; for (int i = Location.Y; i < Size.Height; i++) { s += temp + "║" + space + "║" + "\n"; } s += temp + "╚"; for (int i = 0; i < Size.Width - 1; i++) { s += "═"; } s += "╝" + "\n"; Console.CursorTop = Location.Y; Console.CursorLeft = Location.X; Console.Write(s); //for(int x = Location.X; x < Size.Width; x++) //{ // for (int y = Location.Y; y < Size.Height; y++) // { // SetPosition(x, y); // if (y == Location.Y && x == Location.X) Console.Write("╔"); // else if (y == Size.Height - 1 && x == Location.X) Console.Write("╚"); // else if (y == Location.Y && x == Size.Width - 1) Console.Write("╗"); // else if (y == Size.Height - 1 && x == Size.Width - 1) Console.Write("╝"); // else if (y == Location.Y || y == Size.Height - 1) Console.Write("═"); // else if (x == Location.X || x == Size.Width - 1) Console.Write("║"); // } //} }
public MainWindow() { InitializeComponent(); // default render size RenderSizeRef = new RenderSize(0, 0); // initiate zooming handler _zoomSelectionHandler = new ZoomSelectionHandler(MandelBrotCanvas); _zoomSelectionHandler.ZoomSelected += ZoomSelectionHandler_ZoomSelected; // subscribe to color change ColorMappings.ItemChanged += (map) => RedrawCurrentFrame(); }
private void RotateProcess(Vector2 p0, Vector2 p1) { Vector2 halfRenderSize = RenderSize.ToVector2() * logicScale * 0.5f; Vector2 pos0 = p0 * logicScale - (halfRenderSize); Vector2 pos1 = p1 * logicScale - (halfRenderSize); float rotateR = MathF.Atan2(pos0.X, pos0.Y) - MathF.Atan2(pos1.X, pos1.Y); CanvasRect.Rotation = (CanvasRect.Rotation + rotateR) % (MathF.PI * 2); Matrix4x4 rotateMatrixMid = Matrix4x4.CreateTranslation(new Vector3(-halfRenderSize, 0)); rotateMatrixMid = Matrix4x4.Multiply(rotateMatrixMid, Matrix4x4.CreateRotationZ(rotateR)); rotateMatrixMid = Matrix4x4.Multiply(rotateMatrixMid, Matrix4x4.CreateTranslation(new Vector3(halfRenderSize, 0))); CanvasRect.Position = Vector2.Transform(CanvasRect.Position, rotateMatrixMid); }
/// <summary> /// Returns a value indicating whether this instance and a specified Object represent the same type and value. /// </summary> /// <param name="obj">An object to compare to this instance.</param> /// <returns>true if obj is the same type and value; otherwise, false. </returns> public override bool Equals(object obj) { if (obj != null) { RenderSize o = (RenderSize)obj; if (this.Width != o.Width) { return(false); } if (this.Height != o.Height) { return(false); } return(true); } return(false); }
public void RenderText(string text, RenderLocation Location, RenderSize Size, ConsoleColor backgroundColor = DefaultBackgroundColor, ConsoleColor foregroundColor = DefaultForegroundColor, Alignment textHorizontalAlignment = Alignment.Left) { switch (textHorizontalAlignment) { case Alignment.Left: SetPosition(new RenderLocation(Location.X, Location.Y)); break; case Alignment.Center: SetPosition(new RenderLocation(Location.X + Size.Width / 2 - text.Length / 2, Location.Y)); break; case Alignment.Right: SetPosition(new RenderLocation(Location.X + Size.Width - text.Length - 1, Location.Y)); break; } ChangeColors(backgroundColor, foregroundColor); Console.Write(text); ChangeColors(); }
//protected override Boolean OnDataContextChanging(Object? oldValue, // Object? newValue) //{ // return base.OnDataContextChanging(oldValue, newValue); //} //protected override void OnDataContextChanged(Object? newValue) //{ // base.OnDataContextChanged(newValue); //} //public override void Dispose() //{ //} public override ValueSize Measure(IRenderSize availableSpace, IMeasureContext measureContext) { var rowNumbers = _controls.Keys.ToArray(); var remainingSize = new RenderSize(availableSpace.Width, availableSpace.Height); foreach (var rowNumber in rowNumbers) { var sizeRow = _sizes[rowNumber]; sizeRow.Clear(); var currentRowHeight = 0.0; remainingSize.Width = availableSpace.Width; var row = _controls[rowNumber]; for (var c = 0; c < row.Count; c++) { var ctrlSize = row[c].Measure(remainingSize, measureContext); if (ctrlSize.Width > _columnWidths[c]) { _columnWidths[c] = ctrlSize.Width; } remainingSize.Width -= ctrlSize.Width; currentRowHeight = Math.Max(currentRowHeight, ctrlSize.Height); sizeRow.Add(ctrlSize); } remainingSize.Height -= currentRowHeight; } var widthNeeded = _columnWidths.Values.Sum(w => w); var heightNeeded = availableSpace.Height - remainingSize.Height; return(new ValueSize(widthNeeded, heightNeeded)); }
/// <summary> /// Returns the render image. /// </summary> public Task<byte[]> GetRenderDataAsync(long typeId, RenderSize size) { const string relUri = "/Render"; const string ext = ".png"; return requestImageDataAsync(relUri, typeId, (int) size, ext); }
/// <summary> /// Returns the render image. /// </summary> public byte[] GetRenderData(long typeId, RenderSize size) { return GetRenderDataAsync(typeId, size).Result; }
/// <summary> /// Saves the image to disk , and returns the path to the image. /// </summary> public Task<string> GetRenderAsync(long typeId, RenderSize size, string path) { const string relUri = "/Render"; const string ext = ".png"; return requestImageAsync(relUri, typeId, (int) size, ext, path); }
protected ValueThickness MeasureImpl <TRenderSize>(IVisualElement container, IMeasureContext measureContext, TRenderSize availableSpace, Orientations orientation, List <IVisualElement> currentlyRendering, out Double maxWidth, out Double maxHeight, out Double totalWidth, out Double totalHeight) where TRenderSize : IRenderSize { var remainingSize = new RenderSize(availableSpace.Width, availableSpace.Height, availableSpace.Offset); var current = new RenderRectangle(); totalHeight = 0.0; totalWidth = 0.0; maxWidth = 0.0; maxHeight = 0.0; foreach (var child in _visuals.GetAllChildren()) { currentlyRendering.Add(child); current.Size = measureContext.MeasureElement(child, remainingSize); var offset = SetChildSize(child, current); if (!offset.IsEmpty) { current.Width += offset.Width; current.Height += offset.Height; } switch (orientation) { case Orientations.Horizontal: if (current.Height > maxHeight) { maxHeight = current.Height; } if (_isWrapContent && current.Width + totalWidth > availableSpace.Width && totalHeight + maxHeight < availableSpace.Height) { maxWidth = Math.Max(maxWidth, totalWidth); totalHeight += maxHeight; current.X = 0; current.Y += maxHeight; maxHeight = totalWidth = 0; } current.X += current.Width; totalWidth += current.Width; remainingSize.Width -= current.Width; break; case Orientations.Vertical: if (current.Width > totalWidth) { totalWidth = current.Width; } if (_isWrapContent && current.Height + totalHeight > availableSpace.Height && totalWidth + maxWidth < availableSpace.Width) { maxHeight = Math.Max(maxHeight, totalHeight); totalWidth += maxWidth; current.Y = 0; current.X += maxHeight; maxWidth = totalHeight = 0; } current.Y += current.Height; totalHeight += current.Height; remainingSize.Height -= current.Height; break; } } var margin = container.Margin.GetValue(availableSpace); return(margin); }
public static List <UIElement> RenderText(String text, RenderSize renderSize, Boolean textOnly) { List <UIElement> elements = new List <UIElement>(); TextBlock textBlockTemp = new TextBlock(); InlineCollection inlines = textBlockTemp.Inlines; Match match = tagMatch.Match(text); while (match.Success) { switch (match.Groups["tag"].Value) { case "b": // Bold if (match.Index > 0) { inlines.Add(new Run(text.Substring(0, match.Index))); } Run rB = new Run(match.Groups["text"].Value); rB.FontWeight = FontWeights.Bold; rB.FontSize = 14; inlines.Add(rB); text = text.Substring(match.Index + match.Length); break; case "i": // Italics if (match.Index > 0) { inlines.Add(new Run(text.Substring(0, match.Index))); } Run rI = new Run(match.Groups["text"].Value); rI.FontStyle = FontStyles.Italic; rI.FontSize = 11; inlines.Add(rI); text = text.Substring(match.Index + match.Length); break; case "u": // Underline if (match.Index > 0) { inlines.Add(new Run(text.Substring(0, match.Index))); } Run rU = new Run(match.Groups["text"].Value); rU.TextDecorations = TextDecorations.Underline; rU.FontSize = 11; inlines.Add(rU); text = text.Substring(match.Index + match.Length); break; case "h": // Header if (match.Index > 0) { inlines.Add(new Run(text.Substring(0, match.Index))); } Run rH = new Run(match.Groups["text"].Value); switch (renderSize) { case RenderSize.ExtraLarge: rH.FontSize = 72; break; default: rH.FontSize = 36; break; } rH.FontWeight = FontWeights.Bold; inlines.Add(rH); text = text.Substring(match.Index + match.Length); break; case "br": // Line break if (match.Index > 0) { inlines.Add(new Run(text.Substring(0, match.Index))); } inlines.Add(new LineBreak()); text = text.Substring(match.Index + match.Length); break; case "sk": // Shortcut Key if (match.Index > 0) { inlines.Add(new Run(text.Substring(0, match.Index))); } Run rSK = new Run(match.Groups["text"].Value); rSK.TextDecorations = TextDecorations.Underline; rSK.Foreground = Brushes.Crimson; inlines.Add(rSK); text = text.Substring(match.Index + match.Length); break; case "sm": if (match.Index > 0) { inlines.Add(new Run(text.Substring(0, match.Index))); } Run rS = new Run(match.Groups["text"].Value); rS.FontSize = 11; inlines.Add(rS); text = text.Substring(match.Index + match.Length); break; case "nbsp": // Non-breaking space text = String.Format("{0}{1}{2}", text.Substring(0, match.Index), Convert.ToChar(160), text.Substring(match.Index + match.Length)); break; case "vp": if (textOnly) { text = String.Format("{0}{1}‡{2}", text.Substring(0, match.Index), match.Groups["text"].Value, text.Substring(match.Index + match.Length)); } else { if (!String.IsNullOrEmpty(text.Substring(0, match.Index))) { inlines.Add(new Run(text.Substring(0, match.Index))); } inlines.Add(new Run(match.Groups["text"].Value)); text = text.Substring(match.Index + match.Length); InlineUIContainer vpUIContainer = new InlineUIContainer(); vpUIContainer.BaselineAlignment = BaselineAlignment.Center; Image vp = new Image(); Caching.ImageRepository ir = Caching.ImageRepository.Acquire(); vp.Source = ir.GetBitmapImage("vp", String.Empty); switch (renderSize) { case RenderSize.Tiny: vp.Height = 14; vp.Width = 14; break; default: vp.Height = 18; vp.Width = 18; break; } Caching.ImageRepository.Release(); vpUIContainer.Child = vp; inlines.Add(vpUIContainer); } break; case "vplg": if (textOnly) { text = String.Format("<h>{0}{1}‡{2}</h>", text.Substring(0, match.Index), match.Groups["text"].Value, text.Substring(match.Index + match.Length)); } else { if (!String.IsNullOrEmpty(text.Substring(0, match.Index))) { inlines.Add(new Run(text.Substring(0, match.Index))); } Run rVpLg = new Run(match.Groups["text"].Value); switch (renderSize) { case RenderSize.ExtraLarge: rVpLg.FontSize = 72; break; default: rVpLg.FontSize = 36; break; } rVpLg.FontWeight = FontWeights.Bold; inlines.Add(rVpLg); text = text.Substring(match.Index + match.Length); InlineUIContainer vpUIContainer = new InlineUIContainer(); vpUIContainer.BaselineAlignment = BaselineAlignment.Center; Image vp = new Image(); Caching.ImageRepository ir = Caching.ImageRepository.Acquire(); vp.Source = ir.GetBitmapImage("vplg", String.Empty); Caching.ImageRepository.Release(); switch (renderSize) { case RenderSize.ExtraLarge: vp.Height = 96; vp.Width = 96; break; default: vp.Height = 48; vp.Width = 48; break; } vpUIContainer.Child = vp; inlines.Add(vpUIContainer); } break; case "coin": if (textOnly) { text = String.Format("{0}{1}¢{2}", text.Substring(0, match.Index), match.Groups["text"].Value, text.Substring(match.Index + match.Length)); } else { if (!String.IsNullOrEmpty(text.Substring(0, match.Index))) { inlines.Add(new Run(text.Substring(0, match.Index))); } text = text.Substring(match.Index + match.Length); InlineUIContainer coinUIContainer = new InlineUIContainer(); coinUIContainer.BaselineAlignment = BaselineAlignment.Center; Canvas coinCanvas = new Canvas(); Image coin = new Image(); Caching.ImageRepository ir = Caching.ImageRepository.Acquire(); coin.Source = ir.GetBitmapImage("coin", String.Empty); switch (renderSize) { case RenderSize.Tiny: coinCanvas.Height = coin.Height = 14; coinCanvas.Width = coin.Width = 14; break; default: coinCanvas.Height = coin.Height = 18; coinCanvas.Width = coin.Width = 18; break; } Caching.ImageRepository.Release(); coinCanvas.Children.Add(coin); TextBlock tbNum = new TextBlock(); Run r = new Run(match.Groups["text"].Value); r.FontWeight = FontWeights.Bold; tbNum.Inlines.Add(r); Canvas.SetLeft(tbNum, 10 - 4 * match.Groups["text"].Value.Length); Canvas.SetTop(tbNum, 2); coinCanvas.Children.Add(tbNum); coinUIContainer.Child = coinCanvas; inlines.Add(coinUIContainer); } break; case "coinlg": if (textOnly) { text = String.Format("<h>{0}{1}¢{2}</h>", text.Substring(0, match.Index), match.Groups["text"].Value, text.Substring(match.Index + match.Length)); } else { if (!String.IsNullOrEmpty(text.Substring(0, match.Index))) { inlines.Add(new Run(text.Substring(0, match.Index))); } text = text.Substring(match.Index + match.Length); InlineUIContainer coinUIContainer = new InlineUIContainer(); coinUIContainer.BaselineAlignment = BaselineAlignment.Center; Canvas coinCanvas = new Canvas(); Image coin = new Image(); Caching.ImageRepository ir = Caching.ImageRepository.Acquire(); coin.Source = ir.GetBitmapImage("coinlg", String.Empty); Caching.ImageRepository.Release(); coinCanvas.Children.Add(coin); TextBlock tbNum = new TextBlock(); Run r = new Run(match.Groups["text"].Value); r.FontWeight = FontWeights.Bold; int blurRadius = 0; switch (renderSize) { case RenderSize.ExtraLarge: r.FontSize = 72; coinCanvas.Height = coin.Height = 96; coinCanvas.Width = coin.Width = 96; Canvas.SetLeft(tbNum, 28); blurRadius = 50; break; default: r.FontSize = 36; coinCanvas.Height = coin.Height = 48; coinCanvas.Width = coin.Width = 48; Canvas.SetLeft(tbNum, 14); blurRadius = 30; break; } tbNum.Inlines.Add(r); tbNum.Effect = Caching.DropShadowRepository.GetDSE(blurRadius, Color.FromRgb(192, 192, 192), 1d); coinCanvas.Children.Add(tbNum); coinUIContainer.Child = coinCanvas; inlines.Add(coinUIContainer); } break; case "potion": if (textOnly) { text = String.Format("{0}{1}¤{2}", text.Substring(0, match.Index), match.Groups["text"].Value, text.Substring(match.Index + match.Length)); } else { if (!String.IsNullOrEmpty(text.Substring(0, match.Index))) { inlines.Add(new Run(text.Substring(0, match.Index))); } if (match.Groups["text"].Value != "1") { inlines.Add(new Run(match.Groups["text"].Value)); } text = text.Substring(match.Index + match.Length); InlineUIContainer potionUIContainer = new InlineUIContainer(); potionUIContainer.BaselineAlignment = BaselineAlignment.Center; Image potion = new Image(); Caching.ImageRepository ir = Caching.ImageRepository.Acquire(); potion.Source = ir.GetBitmapImage("potion", String.Empty); switch (renderSize) { case RenderSize.Tiny: potion.Height = 14; potion.Width = 14; break; default: potion.Height = 18; potion.Width = 18; break; } Caching.ImageRepository.Release(); potionUIContainer.Child = potion; inlines.Add(potionUIContainer); } break; case "potionlg": if (textOnly) { text = String.Format("<h>{0}{1}¤{2}</h>", text.Substring(0, match.Index), match.Groups["text"].Value, text.Substring(match.Index + match.Length)); } else { if (!String.IsNullOrEmpty(text.Substring(0, match.Index))) { inlines.Add(new Run(text.Substring(0, match.Index))); } Run rPotionLg = new Run(match.Groups["text"].Value); switch (renderSize) { case RenderSize.ExtraLarge: rPotionLg.FontSize = 72; break; default: rPotionLg.FontSize = 36; break; } rPotionLg.FontWeight = FontWeights.Bold; inlines.Add(rPotionLg); text = text.Substring(match.Index + match.Length); InlineUIContainer potionUIContainer = new InlineUIContainer(); potionUIContainer.BaselineAlignment = BaselineAlignment.Center; Image potion = new Image(); Caching.ImageRepository ir = Caching.ImageRepository.Acquire(); potion.Source = ir.GetBitmapImage("potionlg", String.Empty); Caching.ImageRepository.Release(); switch (renderSize) { case RenderSize.ExtraLarge: potion.Height = 96; potion.Width = 96; break; default: potion.Height = 48; potion.Width = 48; break; } potionUIContainer.Child = potion; inlines.Add(potionUIContainer); } break; default: text = String.Empty; break; } match = tagMatch.Match(text); } if (!String.IsNullOrEmpty(text)) { inlines.Add(new Run(text)); } if (textBlockTemp != null) { elements.Add(textBlockTemp); } return(elements); }
public static List<UIElement> RenderText(String text, RenderSize renderSize, Boolean textOnly) { List<UIElement> elements = new List<UIElement>(); TextBlock textBlockTemp = new TextBlock(); InlineCollection inlines = textBlockTemp.Inlines; Match match = tagMatch.Match(text); while (match.Success) { switch (match.Groups["tag"].Value) { case "b": // Bold if (match.Index > 0) inlines.Add(new Run(text.Substring(0, match.Index))); Run rB = new Run(match.Groups["text"].Value); rB.FontWeight = FontWeights.Bold; rB.FontSize = 14; inlines.Add(rB); text = text.Substring(match.Index + match.Length); break; case "i": // Italics if (match.Index > 0) inlines.Add(new Run(text.Substring(0, match.Index))); Run rI = new Run(match.Groups["text"].Value); rI.FontStyle = FontStyles.Italic; rI.FontSize = 11; inlines.Add(rI); text = text.Substring(match.Index + match.Length); break; case "u": // Underline if (match.Index > 0) inlines.Add(new Run(text.Substring(0, match.Index))); Run rU = new Run(match.Groups["text"].Value); rU.TextDecorations = TextDecorations.Underline; rU.FontSize = 11; inlines.Add(rU); text = text.Substring(match.Index + match.Length); break; case "h": // Header if (match.Index > 0) inlines.Add(new Run(text.Substring(0, match.Index))); Run rH = new Run(match.Groups["text"].Value); switch (renderSize) { case RenderSize.ExtraLarge: rH.FontSize = 72; break; default: rH.FontSize = 36; break; } rH.FontWeight = FontWeights.Bold; inlines.Add(rH); text = text.Substring(match.Index + match.Length); break; case "br": // Line break if (match.Index > 0) inlines.Add(new Run(text.Substring(0, match.Index))); inlines.Add(new LineBreak()); text = text.Substring(match.Index + match.Length); break; case "sk": // Shortcut Key if (match.Index > 0) inlines.Add(new Run(text.Substring(0, match.Index))); Run rSK = new Run(match.Groups["text"].Value); rSK.TextDecorations = TextDecorations.Underline; rSK.Foreground = Brushes.Crimson; inlines.Add(rSK); text = text.Substring(match.Index + match.Length); break; case "sm": if (match.Index > 0) inlines.Add(new Run(text.Substring(0, match.Index))); Run rS = new Run(match.Groups["text"].Value); rS.FontSize = 11; inlines.Add(rS); text = text.Substring(match.Index + match.Length); break; case "nbsp": // Non-breaking space text = String.Format("{0}{1}{2}", text.Substring(0, match.Index), Convert.ToChar(160), text.Substring(match.Index + match.Length)); break; case "vp": if (textOnly) text = String.Format("{0}{1}‡{2}", text.Substring(0, match.Index), match.Groups["text"].Value, text.Substring(match.Index + match.Length)); else { if (!String.IsNullOrEmpty(text.Substring(0, match.Index))) inlines.Add(new Run(text.Substring(0, match.Index))); inlines.Add(new Run(match.Groups["text"].Value)); text = text.Substring(match.Index + match.Length); InlineUIContainer vpUIContainer = new InlineUIContainer(); vpUIContainer.BaselineAlignment = BaselineAlignment.Center; Image vp = new Image(); Caching.ImageRepository ir = Caching.ImageRepository.Acquire(); vp.Source = ir.GetBitmapImage("vp", String.Empty); switch (renderSize) { case RenderSize.Tiny: vp.Height = 14; vp.Width = 14; break; default: vp.Height = 18; vp.Width = 18; break; } Caching.ImageRepository.Release(); vpUIContainer.Child = vp; inlines.Add(vpUIContainer); } break; case "vplg": if (textOnly) text = String.Format("<h>{0}{1}‡{2}</h>", text.Substring(0, match.Index), match.Groups["text"].Value, text.Substring(match.Index + match.Length)); else { if (!String.IsNullOrEmpty(text.Substring(0, match.Index))) inlines.Add(new Run(text.Substring(0, match.Index))); Run rVpLg = new Run(match.Groups["text"].Value); switch (renderSize) { case RenderSize.ExtraLarge: rVpLg.FontSize = 72; break; default: rVpLg.FontSize = 36; break; } rVpLg.FontWeight = FontWeights.Bold; inlines.Add(rVpLg); text = text.Substring(match.Index + match.Length); InlineUIContainer vpUIContainer = new InlineUIContainer(); vpUIContainer.BaselineAlignment = BaselineAlignment.Center; Image vp = new Image(); Caching.ImageRepository ir = Caching.ImageRepository.Acquire(); vp.Source = ir.GetBitmapImage("vplg", String.Empty); Caching.ImageRepository.Release(); switch (renderSize) { case RenderSize.ExtraLarge: vp.Height = 96; vp.Width = 96; break; default: vp.Height = 48; vp.Width = 48; break; } vpUIContainer.Child = vp; inlines.Add(vpUIContainer); } break; case "coin": if (textOnly) text = String.Format("{0}{1}¢{2}", text.Substring(0, match.Index), match.Groups["text"].Value, text.Substring(match.Index + match.Length)); else { if (!String.IsNullOrEmpty(text.Substring(0, match.Index))) inlines.Add(new Run(text.Substring(0, match.Index))); text = text.Substring(match.Index + match.Length); InlineUIContainer coinUIContainer = new InlineUIContainer(); coinUIContainer.BaselineAlignment = BaselineAlignment.Center; Canvas coinCanvas = new Canvas(); Image coin = new Image(); Caching.ImageRepository ir = Caching.ImageRepository.Acquire(); coin.Source = ir.GetBitmapImage("coin", String.Empty); switch (renderSize) { case RenderSize.Tiny: coinCanvas.Height = coin.Height = 14; coinCanvas.Width = coin.Width = 14; break; default: coinCanvas.Height = coin.Height = 18; coinCanvas.Width = coin.Width = 18; break; } Caching.ImageRepository.Release(); coinCanvas.Children.Add(coin); TextBlock tbNum = new TextBlock(); Run r = new Run(match.Groups["text"].Value); r.FontWeight = FontWeights.Bold; tbNum.Inlines.Add(r); Canvas.SetLeft(tbNum, 10 - 4 * match.Groups["text"].Value.Length); Canvas.SetTop(tbNum, 2); coinCanvas.Children.Add(tbNum); coinUIContainer.Child = coinCanvas; inlines.Add(coinUIContainer); } break; case "coinlg": if (textOnly) text = String.Format("<h>{0}{1}¢{2}</h>", text.Substring(0, match.Index), match.Groups["text"].Value, text.Substring(match.Index + match.Length)); else { if (!String.IsNullOrEmpty(text.Substring(0, match.Index))) inlines.Add(new Run(text.Substring(0, match.Index))); text = text.Substring(match.Index + match.Length); InlineUIContainer coinUIContainer = new InlineUIContainer(); coinUIContainer.BaselineAlignment = BaselineAlignment.Center; Canvas coinCanvas = new Canvas(); Image coin = new Image(); Caching.ImageRepository ir = Caching.ImageRepository.Acquire(); coin.Source = ir.GetBitmapImage("coinlg", String.Empty); Caching.ImageRepository.Release(); coinCanvas.Children.Add(coin); TextBlock tbNum = new TextBlock(); Run r = new Run(match.Groups["text"].Value); r.FontWeight = FontWeights.Bold; int blurRadius = 0; switch (renderSize) { case RenderSize.ExtraLarge: r.FontSize = 72; coinCanvas.Height = coin.Height = 96; coinCanvas.Width = coin.Width = 96; Canvas.SetLeft(tbNum, 28); blurRadius = 50; break; default: r.FontSize = 36; coinCanvas.Height = coin.Height = 48; coinCanvas.Width = coin.Width = 48; Canvas.SetLeft(tbNum, 14); blurRadius = 30; break; } tbNum.Inlines.Add(r); tbNum.Effect = Caching.DropShadowRepository.GetDSE(blurRadius, Color.FromRgb(192, 192, 192), 1d); coinCanvas.Children.Add(tbNum); coinUIContainer.Child = coinCanvas; inlines.Add(coinUIContainer); } break; case "potion": if (textOnly) text = String.Format("{0}{1}¤{2}", text.Substring(0, match.Index), match.Groups["text"].Value, text.Substring(match.Index + match.Length)); else { if (!String.IsNullOrEmpty(text.Substring(0, match.Index))) inlines.Add(new Run(text.Substring(0, match.Index))); if (match.Groups["text"].Value != "1") inlines.Add(new Run(match.Groups["text"].Value)); text = text.Substring(match.Index + match.Length); InlineUIContainer potionUIContainer = new InlineUIContainer(); potionUIContainer.BaselineAlignment = BaselineAlignment.Center; Image potion = new Image(); Caching.ImageRepository ir = Caching.ImageRepository.Acquire(); potion.Source = ir.GetBitmapImage("potion", String.Empty); switch (renderSize) { case RenderSize.Tiny: potion.Height = 14; potion.Width = 14; break; default: potion.Height = 18; potion.Width = 18; break; } Caching.ImageRepository.Release(); potionUIContainer.Child = potion; inlines.Add(potionUIContainer); } break; case "potionlg": if (textOnly) text = String.Format("<h>{0}{1}¤{2}</h>", text.Substring(0, match.Index), match.Groups["text"].Value, text.Substring(match.Index + match.Length)); else { if (!String.IsNullOrEmpty(text.Substring(0, match.Index))) inlines.Add(new Run(text.Substring(0, match.Index))); Run rPotionLg = new Run(match.Groups["text"].Value); switch (renderSize) { case RenderSize.ExtraLarge: rPotionLg.FontSize = 72; break; default: rPotionLg.FontSize = 36; break; } rPotionLg.FontWeight = FontWeights.Bold; inlines.Add(rPotionLg); text = text.Substring(match.Index + match.Length); InlineUIContainer potionUIContainer = new InlineUIContainer(); potionUIContainer.BaselineAlignment = BaselineAlignment.Center; Image potion = new Image(); Caching.ImageRepository ir = Caching.ImageRepository.Acquire(); potion.Source = ir.GetBitmapImage("potionlg", String.Empty); Caching.ImageRepository.Release(); switch (renderSize) { case RenderSize.ExtraLarge: potion.Height = 96; potion.Width = 96; break; default: potion.Height = 48; potion.Width = 48; break; } potionUIContainer.Child = potion; inlines.Add(potionUIContainer); } break; default: text = String.Empty; break; } match = tagMatch.Match(text); } if (!String.IsNullOrEmpty(text)) inlines.Add(new Run(text)); if (textBlockTemp != null) elements.Add(textBlockTemp); return elements; }
private void SetupCameraControl() { // Unregister if (_cameraControl != null) { SizeChanged -= OnSizeChanged; } // Get template part _cameraControl = (CameraControl)GetTemplateChild(CAMERACONTROL_NAME); // Bail if missing if (_cameraControl == null) { return; } SizeChanged += OnSizeChanged; // Camera setup _cameraControl.SetAsPerspective(RenderSize.ToVector2()); _cameraControl.Yaw = 0; _cameraControl.Pitch = 0; _cameraControl.PerspectiveDistance = 575; _cameraControl.Position = new Vector3(1920 / 2, 1080 / 2, 0); // ImageLoader _compositor = _cameraControl.CompositionCamera.CameraVisual.Compositor; _surfaceFactory = SurfaceFactory.GetSharedSurfaceFactoryForCompositor(_compositor); // Skybox container var halfSkyboxSize = _skyboxSize / 2; var negativeHalfSkyboxSize = -_skyboxSize / 2; _skyboxContainer = _compositor.CreateContainerVisual(); _skyboxContainer.CenterPoint = new Vector3(halfSkyboxSize, halfSkyboxSize, halfSkyboxSize); _skyboxContainer.AnchorPoint = new Vector2(halfSkyboxSize, halfSkyboxSize); _skyboxContainer.Offset = new Vector3(negativeHalfSkyboxSize, negativeHalfSkyboxSize, negativeHalfSkyboxSize); _skyboxContainer.RotationAxis = _rotationAxisY; _skyboxContainer.BorderMode = CompositionBorderMode.Hard; _skyboxContainer.Comment = "Skybox"; // Skybox sides SetupSkyboxSide(SkyboxSide.Top); SetupSkyboxSide(SkyboxSide.Left); SetupSkyboxSide(SkyboxSide.Right); SetupSkyboxSide(SkyboxSide.Bottom); SetupSkyboxSide(SkyboxSide.Front); SetupSkyboxSide(SkyboxSide.Back); // World root SpriteVisual treeRoot = _compositor.CreateSpriteVisual(); SpriteVisual worldRoot = _compositor.CreateSpriteVisual(); treeRoot.Comment = "TreeRoot"; worldRoot.Comment = "WorldRoot"; ElementCompositionPreview.SetElementChildVisual(_cameraControl, treeRoot); treeRoot.Children.InsertAtTop(worldRoot); worldRoot.Children.InsertAtTop(_skyboxContainer); if (AutoRotate) { // Animate for fun. Rotate(360, 100000); } }
/// <summary> /// Saves the image to disk , and returns the path to the image. /// </summary> public string GetRender(long typeId, RenderSize size) { const string relUri = "/Render"; const string ext = ".png"; return requestImage(relUri, typeId, (int) size, ext); }
/// <summary> /// Returns the render image. /// </summary> public byte[] GetRenderData(long typeId, RenderSize size) { return(GetRenderDataAsync(typeId, size).Result); }
/// <summary> /// Saves the image to disk , and returns the path to the image. /// </summary> public string GetRender(long typeId, RenderSize size, string path) { return GetRenderAsync(typeId, size, path).Result; }
/// <summary> /// Saves the image to disk , and returns the path to the image. /// </summary> public string GetRender(long typeId, RenderSize size, string path) { return(GetRenderAsync(typeId, size, path).Result); }