/// <summary> /// Creates a new CluwneSprite with a key and a specific renderTarget /// </summary> /// <param name="key"> key </param> /// <param name="_renderImage"> RenderTarget to use </param> public CluwneSprite(string key, RenderTarget target) { Key = key; renderTarget = target; Position = new Vector2(X, Y); Size = new Vector2(Width, Height); }
public override void Draw(RenderTarget target, RenderStates states) { var sprite = sprites[type]; sprite.Position = new Vector2f(x, y); sprite.Rotation = rotation; target.Draw(sprite); }
public override void CreateScene() { TexturePtr mTexture = TextureManager.Singleton.CreateManual("RenderArea", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME, TextureType.TEX_TYPE_2D, 512, 512, 0, PixelFormat.PF_R8G8B8, (int)TextureUsage.TU_RENDERTARGET); rttTex = mTexture.GetBuffer().GetRenderTarget(); rttTex.IsAutoUpdated = false; { // Create the camera Camera camera2 = sceneMgr.CreateCamera("PlayerCam2"); camera2.Position = new Vector3(0, 0, 3); camera2.LookAt(new Vector3(0.0f, 0.0f, 0.0f)); camera2.NearClipDistance = 1; Viewport v = rttTex.AddViewport(camera2); MaterialPtr mat = MaterialManager.Singleton.GetByName("CgTutorials/RenderToTexture_Material"); mat.GetTechnique(0).GetPass(0).GetTextureUnitState(0).SetTextureName("RenderArea"); v.BackgroundColour = new ColourValue(0.0f, 0.3f, 0.2f, 0.0f); //v.SetClearEveryFrame(false); //v.OverlaysEnabled = false; rttTex.PreRenderTargetUpdate += new RenderTargetListener.PreRenderTargetUpdateHandler(RenderArea_PreRenderTargetUpdate); rttTex.PostRenderTargetUpdate += new RenderTargetListener.PostRenderTargetUpdateHandler(RenderArea_PostRenderTargetUpdate); } node1 = base.sceneMgr.RootSceneNode.CreateChildSceneNode("TutorialRender2TexNode1"); node2 = base.sceneMgr.RootSceneNode.CreateChildSceneNode("TutorialRender2TexNode2"); manualObj1 = sceneMgr.CreateManualObject("TutorialRender2TexObject1"); manualObj2 = sceneMgr.CreateManualObject("TutorialRender2TexObject2"); node1.AttachObject(DrawTriangle1(manualObj1)); node2.AttachObject(DrawTriangle2(manualObj2)); }
public override void Draw(RenderTarget r) { var text = ((int)(1000/EntityManager.FrameTime)).ToString () + " FPS"; DebugText = new Text(text, DebugText.Font) {Position = r.GetView ().Center - r.GetView ().Size/2, Color = DebugText.Color}; r.Draw (DebugText); }
/// <summary> /// Initializes a new instance of the <see cref="SFML"/> class. /// </summary> /// <param name="target">SFML render target.</param> public SFML(RenderTarget target) { m_Target = target; m_VertexCache = new Vertex[CacheSize]; m_RenderState = new RenderStates(BlendMode.Alpha); // somehow worked without this in previous SFML version (May 9th 2010) }
public BloomTest(RenderTexture target_tex, RenderTarget target) { _target = target; _bloom = new Shader(null, "bloom.glsl"); _texture = new RenderTexture((uint)GlobalProps.Width, (uint)GlobalProps.Height); _states.BlendMode = BlendMode.Alpha; _states.Shader = _bloom; _states.Transform = Transform.Identity; _states.Texture = target_tex.Texture; _bloom.SetParameter("referenceTex", Shader.CurrentTexture); _bloom.SetParameter("pixelWidth", 4); _bloom.SetParameter("pixelHeight", 4); int w = GlobalProps.Width, h = GlobalProps.Height; Vector2f v0 = new Vector2f(0, 0); Vector2f v1 = new Vector2f(w, 0); Vector2f v2 = new Vector2f(w, h); Vector2f v3 = new Vector2f(0, h); _verts = new Vertex[4]; _verts[0] = new Vertex(v0, Color.White, v0); _verts[1] = new Vertex(v1, Color.White, v1); _verts[2] = new Vertex(v2, Color.White, v2); _verts[3] = new Vertex(v3, Color.White, v3); }
/// <summary> /// Contains the shared constructor code /// </summary> /// <param name="target"></param> private Gui(RenderTarget target) { _renderer = new Gwen.Renderer.SFML(target); skin = new TexturedBase(_renderer, "DefaultSkin.png"); // load font. TODO: remove hardcoding using (var font = new Gwen.Font(_renderer, "OpenSans.ttf", 14)) { if (_renderer.LoadFont(font)) _renderer.FreeFont(font); else { font.FaceName = "Arial Unicode MS"; if (_renderer.LoadFont(font)) _renderer.FreeFont(font); else { font.FaceName = "Arial"; _renderer.LoadFont(font); } } skin.SetDefaultFont(font.FaceName, 14); } GuiCanvas = new Canvas(skin); GuiCanvas.SetSize((int)target.Size.X, (int)target.Size.Y); GuiCanvas.ShouldDrawBackground = false; GuiCanvas.BackgroundColor = System.Drawing.Color.Black; GuiCanvas.KeyboardInputEnabled = true; _input = new Gwen.Input.SFML(); _input.Initialize(GuiCanvas, target); }
public void Draw(RenderTarget target, RenderStates states) { target.Draw(background, states); foreach (Layer l in layers) { target.Draw(l, states); } }
public override void Draw(RenderTarget rt) { RectangleShape bgOverlay = new RectangleShape(new Vector2f(GameOptions.Width, GameOptions.Height)) { FillColor = Color.Black }; rt.Draw(bgOverlay); Text title = new Text("Game Over", Assets.LoadFont(Program.DefaultFont)) { Position = new Vector2f(GameOptions.Width / 2.0f, 48.0f), CharacterSize = 48, Color = Color.White }; title.Center(); title.Round(); rt.Draw(title); Text winnerTitle = new Text(GetWinnerText(), Assets.LoadFont(Program.DefaultFont)) { Position = new Vector2f(GameOptions.Width / 2.0f, GameOptions.Height / 2.0f), CharacterSize = 48, Color = Color.White }; winnerTitle.Center(); winnerTitle.Round(); rt.Draw(winnerTitle); base.Draw(rt); }
public override void Draw(RenderTarget rt) { RectangleShape overylay = new RectangleShape(new Vector2f(GameOptions.Width, GameOptions.Height)) { FillColor = new Color(0, 0, 0, 128) }; rt.Draw(overylay); RectangleShape window = new RectangleShape(new Vector2f(GameOptions.Width * (1.0f - PaddingHorizontal * 2.0f), GameOptions.Height * (1.0f - PaddingVertical * 2.0f))) { Position = new Vector2f(GameOptions.Width * PaddingHorizontal, GameOptions.Height * PaddingVertical), FillColor = Color.White, OutlineColor = Color.Black, OutlineThickness = 2.0f }; rt.Draw(window); Text labelSettings = new Text("Join by IP", Assets.LoadFont(Program.DefaultFont)) { Position = new Vector2f(GameOptions.Width / 2.0f, GameOptions.Height * PaddingVertical + 48.0f), Color = Color.Black, CharacterSize = 32 }; labelSettings.Center(); labelSettings.Round(); rt.Draw(labelSettings); base.Draw(rt); }
public void Draw(RenderTarget target, RenderStates states) { states.Transform.Combine(Transform); target.Draw(m_QuadArray, states); target.Draw(m_LineArray, states); }
public string GetHeader(RenderTarget target) { var jsQuery = new NameValueCollection(); jsQuery["file"] = "js"; var cssQuery = new NameValueCollection(); cssQuery["file"] = "css"; return string.Format(@" <script src=""{0}""></script> <link rel=""stylesheet"" href=""{1}"" type=""text/css"" /> <script type=""text/javascript""> (function($){{ $.telligent.evolution.ui.components.poll.configure({{deleteMessage:'{2}',voteMessage:'{3}',votingEndsMessage:'{4}',votingEndsResultsHiddenMessage:'{5}',votingEndedMessage:'{6}'}}); }}(jQuery)); </script> ", _callbackController.GetUrl(jsQuery), _callbackController.GetUrl(cssQuery), TEApi.Javascript.Encode(_translation.GetLanguageResourceValue("poll_vote_delete")), TEApi.Javascript.Encode(_translation.GetLanguageResourceValue("poll_vote")), TEApi.Javascript.Encode(_translation.GetLanguageResourceValue("poll_voting_ends")), TEApi.Javascript.Encode(_translation.GetLanguageResourceValue("poll_voting_ends_results_hidden")), TEApi.Javascript.Encode(_translation.GetLanguageResourceValue("poll_voting_ended")) ); }
protected internal override void Draw(RenderTarget renderTarget) { if (DrawSection) renderTarget.DrawBitmap(Bitmap, opacity, BitmapInterpolationMode.Linear, DestRect, SourceRect); else renderTarget.DrawBitmap(Bitmap, opacity, BitmapInterpolationMode.Linear, DestRect); }
public TextShape(RenderTarget initialRenderTarget, Random random, D2DFactory d2DFactory, D2DBitmap bitmap, DWriteFactory dwriteFactory) : base(initialRenderTarget, random, d2DFactory, bitmap) { this.dwriteFactory = dwriteFactory; layoutRect = RandomRect(CanvasWidth, CanvasHeight); NiceGabriola = Random.NextDouble() < 0.25 && dwriteFactory.SystemFontFamilyCollection.Contains("Gabriola"); TextFormat = dwriteFactory.CreateTextFormat( RandomFontFamily(), RandomFontSize(), RandomFontWeight(), RandomFontStyle(), RandomFontStretch(), System.Globalization.CultureInfo.CurrentUICulture); if (CoinFlip) TextFormat.LineSpacing = RandomLineSpacing(TextFormat.FontSize); Text = RandomString(Random.Next(1000, 1000)); FillBrush = RandomBrush(); RenderingParams = RandomRenderingParams(); if (CoinFlip) { Options = DrawTextOptions.None; if (CoinFlip) Options |= DrawTextOptions.Clip; if (CoinFlip) Options |= DrawTextOptions.NoSnap; } }
public override void Draw(RenderTarget window) { if (!IsVisible) return; Effect.Draw(window); }
public void Draw(RenderTarget target, RenderStates states) { body.FillColor = data.FillColor; target.Draw(body); target.Draw(text); }
/// <summary> /// Prepares the <see cref="SFML.Graphics.Sprite"/> used to draw to a <see cref="RenderTarget"/>. /// </summary> /// <param name="sprite">The <see cref="SFML.Graphics.Sprite"/> to prepare.</param> /// <param name="target">The <see cref="RenderTarget"/> begin drawn to.</param> protected override void PrepareDrawToTargetSprite(SFML.Graphics.Sprite sprite, RenderTarget target) { base.PrepareDrawToTargetSprite(sprite, target); // Always use alpha blending sprite.BlendMode = BlendMode.Multiply; }
public override void Draw(RenderTarget rt) { Text title = new Text("Oh no! Something went wrong!", Assets.LoadFont(Program.DefaultFont)) { Position = new Vector2f(GameOptions.Width / 2.0f, 48.0f), CharacterSize = 48, Color = Color.White }; title.Center(); title.Round(); rt.Draw(title); Text blackCardText = new Text(value, Assets.LoadFont(Program.DefaultFont)) { Position = new Vector2f(GameOptions.Width / 2.0f, GameOptions.Height / 2.0f), CharacterSize = 36, Color = Color.White }; blackCardText.Center(); blackCardText.Round(); rt.Draw(blackCardText); base.Draw(rt); }
/// <summary> /// Constructor /// </summary> /// <param name="device_">Graphics device to use to draw the widgets.</param> /// <param name="contentManager_">Content manager used ton loaad the textures and such.</param> public UIManager(RenderTarget target ) { myTarget = target; myPainter = new Painter(myTarget); myCursor = new Cursor(); }
public MeshShape(RenderTarget initialRenderTarget, Random random, D2DFactory d2DFactory, D2DBitmap bitmap) : base(initialRenderTarget, random, d2DFactory, bitmap) { FillBrush = RandomBrush(); mesh = CoinFlip ? MeshFromRandomGeometry() : MeshFromRandomTriangles(); }
public override void Draw(RenderTarget target, RenderStates states) { states.Transform *= Transform; graphic.Draw(target, states); base.Draw(target, states); }
public void Draw(RenderTarget window, Location offset) { rect.Rotation = -Rotation - 90; rect.Position = Location.Vec2f + offset.Vec2f; rect.Texture = texture; window.Draw(rect); }
public void Render(HDRSettings settings, RenderTarget input, RenderTarget output, RenderTarget bloom, RenderTarget lensFlares, RenderTarget luminance) { if (ShaderParams == null) { ShaderParams = new TonemapShaderParams(); Shader.GetUniformLocations(ShaderParams); } Backend.BeginPass(output, new Vector4(0.0f, 0.0f, 0.0f, 1.0f)); Textures[0] = input.Textures[0].Handle; Textures[1] = luminance.Textures[0].Handle; var activeTexture = 2; if (settings.EnableBloom) Textures[activeTexture++] = bloom.Textures[0].Handle; if (settings.EnableLensFlares) Textures[activeTexture++] = lensFlares.Textures[0].Handle; Backend.BeginInstance(Shader.Handle, Textures, samplers: Samplers); Backend.BindShaderVariable(ShaderParams.SamplerScene, 0); Backend.BindShaderVariable(ShaderParams.SamplerBloom, 2); Backend.BindShaderVariable(ShaderParams.SamplerLensFlares, 3); Backend.BindShaderVariable(ShaderParams.SamplerLuminance, 1); Backend.BindShaderVariable(ShaderParams.KeyValue, settings.KeyValue); Backend.BindShaderVariable(ShaderParams.EnableBloom, settings.EnableBloom ? 1 : 0); Backend.BindShaderVariable(ShaderParams.EnableLensFlares, settings.EnableLensFlares ? 1 : 0); Backend.DrawMesh(QuadMesh.MeshHandle); Backend.EndPass(); }
public override void Draw(RenderTarget window) { if (BackgroundShape != null) BackgroundShape.Draw(window); base.Draw(window); }
public static void execute() // executes the pipeline { if (win == null) return; Graphics.frame_index++; render_target = win; win.Clear(familiarize_color(back_color)); Statistics.sprites_drawn = 0; Statistics.sprites_discarded = 0; Pipeline.execute(); win.Display(); if (screenshot_signal) { bool found = false; int ctr = 0; string path = ""; while (!found) { path = XF.Application.root_path + "screenshot" + ctr + ".png"; found = !System.IO.File.Exists(path); ctr++; } SFML.Graphics.Image screenshot = new SFML.Graphics.Image(screen_w, screen_h); screenshot.CopyScreen(win) ; screenshot.SaveToFile(path); screenshot_signal = false; } }
protected internal override void Draw(RenderTarget renderTarget) { if (StrokeStyle != null) renderTarget.DrawLine(point0, point1, PenBrush, StrokeWidth, StrokeStyle); else renderTarget.DrawLine(point0, point1, PenBrush, StrokeWidth); }
public override void Draw(RenderTarget rt) { Vector2f actualPosition = Position + (Selected ? new Vector2f(0, -12.0f - 5.0f * GetSelectedIndex()) : new Vector2f()); // Draw card Sprite sprite = new Sprite(Assets.LoadTexture(Info.Type == CardType.White ? "CardWhite.png" : "CardBlack.png")); Size = new Vector2f(sprite.GetGlobalBounds().Width, sprite.GetGlobalBounds().Height); sprite.Position = actualPosition; sprite.Scale = Scale; rt.Draw(sprite); // Draw text Text text = GameUtility.Wrap(Info.Value, Assets.LoadFont("arialbd.ttf"), (uint)Math.Floor(24.0f * Scale.X), Math.Floor(207.0f * Scale.X)); text.Color = Info.Type == CardType.White ? Color.Black : Color.White; text.Position = actualPosition + new Vector2f(16.0f * Scale.X, 10.0f * Scale.Y); text.Round(); rt.Draw(text); // Draw decorations if (Info.PickCount > 1) { Sprite pickMultiple = new Sprite(Assets.LoadTexture(Info.PickCount == 2 ? "PickTwo.png" : "PickThree.png")) { Position = actualPosition + new Vector2f((241.0f - 56.0f - 10.0f - 4.0f) * Scale.X, (320.0f - 10.0f - 20.0f) * Scale.Y), Scale = Scale }; rt.Draw(pickMultiple); } }
public override void Draw(RenderTarget target, Vector2f position) { _icon.Position = position; target.Draw(_icon); if (_amount == 0) { var darken = new RectangleShape(new Vector2f(Hud.IconSize - Hud.IconBorderTwice, Hud.IconSize - Hud.IconBorderTwice)); darken.Origin = new Vector2f(Hud.IconSizeHalf - Hud.IconBorder, Hud.IconSizeHalf - Hud.IconBorder); darken.FillColor = new Color(0, 0, 0, 200); darken.Position = position; target.Draw(darken); } if (_time > 0) { var per = _time / BuildTime; var box = new RectangleShape(new Vector2f(per * (Hud.IconSize - Hud.IconBorderTwice), 8)); box.FillColor = new Color(0, 180, 0, 128); box.Position = position - new Vector2f(Hud.IconSizeHalf - Hud.IconBorder, Hud.IconSizeHalf - Hud.IconBorder); target.Draw(box); } _amountText.DisplayedString = _amount.ToString("G"); _amountText.Position = position + new Vector2f(Hud.IconSizeHalf - Hud.Padding, Hud.IconSizeHalf - Hud.Padding); var bounds = _amountText.GetLocalBounds(); _amountText.Origin = new Vector2f(bounds.Width + bounds.Left, bounds.Height + bounds.Top); target.Draw(_amountText); }
public void Draw(RenderTarget rt) { DateTime now = DateTime.Now; Text message = new Text("", myFont); message.CharacterSize = 14; int removeCount = 0; foreach(KeyValuePair<DateTime, String> pair in msgList){ message.DisplayedString += pair.Value + "\n"; if((now - pair.Key).TotalSeconds > messageLifeTime) removeCount++; } msgList.RemoveRange(0, removeCount); message.Position = new Vector2f(14, rt.Height - 54 - message.GetRect().Height); rt.Draw(message); if(writing){ Text display = new Text("say : " + toWrite + "_", myFont); display.CharacterSize = 14; display.Position = new Vector2f(14, rt.Height - 36 - display.GetRect().Height); rt.Draw(display); } }
public static SurfacePattern CreateTileBrush(TileBrush brush, Size targetSize) { var helper = new TileBrushImplHelper(brush, targetSize); if (!helper.IsValid) return null; using (var intermediate = new ImageSurface(Format.ARGB32, (int)helper.IntermediateSize.Width, (int)helper.IntermediateSize.Height)) using (var ctx = new RenderTarget(intermediate).CreateDrawingContext()) { helper.DrawIntermediate(ctx); var result = new SurfacePattern(intermediate); if ((brush.TileMode & TileMode.FlipXY) != 0) { // TODO: Currently always FlipXY as that's all cairo supports natively. // Support separate FlipX and FlipY by drawing flipped images to intermediate // surface. result.Extend = Extend.Reflect; } else { result.Extend = Extend.Repeat; } if (brush.TileMode != TileMode.None) { var matrix = result.Matrix; matrix.InitTranslate(-helper.DestinationRect.X, -helper.DestinationRect.Y); result.Matrix = matrix; } return result; } }
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> /// Draws the widget on the render target /// </summary> /// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public abstract void Draw(RenderTarget target, RenderStates states);
public override void Draw(RenderTarget target, RenderStates states) { sprite.Position = new Vector2f(X, Y); sprite.Rotation = rotation; target.Draw(sprite); }
/// <summary> /// Does the actual rendering. /// BeginDraw and EndDraw are already called by the caller. /// </summary> public abstract void Render(RenderTarget target);
/// <summary> /// Called when cached rendering is done. /// </summary> /// <param name="control">Control to be rendered.</param> public void FinishCacheTexture(Control.Base control) { m_Target = m_Stack.Pop(); }
protected RenderingBase(RenderTarget renderTarget) { _render = renderTarget; }
private RenderTarget CreateRenderTarget(Vector2i size, RenderTargetFormatParameters format, TextureSampleParameters?sampleParameters = null, string?name = null) { // Cache currently bound framebuffers // so if somebody creates a framebuffer while drawing it won't ruin everything. var boundDrawBuffer = GL.GetInteger(GetPName.DrawFramebufferBinding); var boundReadBuffer = GL.GetInteger(GetPName.ReadFramebufferBinding); // Generate FBO. var fbo = new GLHandle(GL.GenFramebuffer()); // Bind color attachment to FBO. GL.BindFramebuffer(FramebufferTarget.Framebuffer, fbo.Handle); ObjectLabelMaybe(ObjectLabelIdentifier.Framebuffer, fbo, name); var(width, height) = size; ClydeTexture textureObject; GLHandle depthStencilBuffer = default; // Color attachment. { var texture = new GLHandle(GL.GenTexture()); GL.BindTexture(TextureTarget.Texture2D, texture.Handle); ApplySampleParameters(sampleParameters); var internalFormat = format.ColorFormat switch { RenderTargetColorFormat.Rgba8 => PixelInternalFormat.Rgba8, RenderTargetColorFormat.Rgba16F => PixelInternalFormat.Rgba16f, RenderTargetColorFormat.Rgba8Srgb => PixelInternalFormat.Srgb8Alpha8, RenderTargetColorFormat.R11FG11FB10F => PixelInternalFormat.R11fG11fB10f, RenderTargetColorFormat.R32F => PixelInternalFormat.R32f, RenderTargetColorFormat.RG32F => PixelInternalFormat.Rg32f, RenderTargetColorFormat.R8 => PixelInternalFormat.R8, _ => throw new ArgumentOutOfRangeException(nameof(format.ColorFormat), format.ColorFormat, null) }; GL.TexImage2D(TextureTarget.Texture2D, 0, internalFormat, width, height, 0, PixelFormat.Red, PixelType.Byte, IntPtr.Zero); GL.FramebufferTexture(FramebufferTarget.Framebuffer, FramebufferAttachment.ColorAttachment0, texture.Handle, 0); textureObject = GenTexture(texture, size, name == null ? null : $"{name}-color"); } // Depth/stencil buffers. if (format.HasDepthStencil) { depthStencilBuffer = new GLHandle(GL.GenRenderbuffer()); GL.BindRenderbuffer(RenderbufferTarget.Renderbuffer, depthStencilBuffer.Handle); ObjectLabelMaybe(ObjectLabelIdentifier.Renderbuffer, depthStencilBuffer, name == null ? null : $"{name}-depth-stencil"); GL.RenderbufferStorage(RenderbufferTarget.Renderbuffer, RenderbufferStorage.Depth24Stencil8, width, height); GL.FramebufferRenderbuffer(FramebufferTarget.Framebuffer, FramebufferAttachment.DepthStencilAttachment, RenderbufferTarget.Renderbuffer, depthStencilBuffer.Handle); } // This should always pass but OpenGL makes it easy to check for once so let's. var status = GL.CheckFramebufferStatus(FramebufferTarget.Framebuffer); DebugTools.Assert(status == FramebufferErrorCode.FramebufferComplete, $"new framebuffer has bad status {status}"); // Re-bind previous framebuffers. GL.BindFramebuffer(FramebufferTarget.DrawFramebuffer, boundDrawBuffer); GL.BindFramebuffer(FramebufferTarget.ReadFramebuffer, boundReadBuffer); var handle = AllocRid(); var renderTarget = new RenderTarget(size, textureObject, fbo, this, handle, depthStencilBuffer); _renderTargets.Add(handle, renderTarget); return(renderTarget); }
/// <summary> /// Initializes a new instance of the <see cref="RenderTargetImageSource"/> struct. /// </summary> /// <param name="renderTarget">The render Target.</param> public RenderTargetImageSource(RenderTarget renderTarget) { RenderTarget = renderTarget; }
public static void setAdditionalRenderTarget(int index, RenderTarget _target) { _currentTarget[index] = _target; }
public void Draw(RenderTarget target, RenderStates states) { target.Draw(_playerSprite); }
internal GamePanel(GraphicsDevice graphicsDevice) { _renderTarget = AddDisposable(new RenderTarget(graphicsDevice)); }
public void Draw(RenderTarget target, RenderStates states) { base.Draw(target, new RenderStates(Texture)); }
public void OnRender(RenderTarget renderTarget) { }
/// <summary> /// Creates a Direct2D brush wrapper for a Avalonia brush. /// </summary> /// <param name="brush">The avalonia brush.</param> /// <param name="destinationSize">The size of the brush's target area.</param> /// <returns>The Direct2D brush wrapper.</returns> public BrushImpl CreateBrush(IBrush brush, Size destinationSize) { var solidColorBrush = brush as ISolidColorBrush; var linearGradientBrush = brush as ILinearGradientBrush; var radialGradientBrush = brush as IRadialGradientBrush; var conicGradientBrush = brush as IConicGradientBrush; var imageBrush = brush as IImageBrush; var visualBrush = brush as IVisualBrush; if (solidColorBrush != null) { return(new SolidColorBrushImpl(solidColorBrush, _deviceContext)); } else if (linearGradientBrush != null) { return(new LinearGradientBrushImpl(linearGradientBrush, _deviceContext, destinationSize)); } else if (radialGradientBrush != null) { return(new RadialGradientBrushImpl(radialGradientBrush, _deviceContext, destinationSize)); } else if (conicGradientBrush != null) { // there is no Direct2D implementation of Conic Gradients so use Radial as a stand-in return(new SolidColorBrushImpl(conicGradientBrush, _deviceContext)); } else if (imageBrush?.Source != null) { return(new ImageBrushImpl( imageBrush, _deviceContext, (BitmapImpl)imageBrush.Source.PlatformImpl.Item, destinationSize)); } else if (visualBrush != null) { if (_visualBrushRenderer != null) { var intermediateSize = _visualBrushRenderer.GetRenderTargetSize(visualBrush); if (intermediateSize.Width >= 1 && intermediateSize.Height >= 1) { // We need to ensure the size we're requesting is an integer pixel size, otherwise // D2D alters the DPI of the render target, which messes stuff up. PixelSize.FromSize // will do the rounding for us. var dpi = new Vector(_deviceContext.DotsPerInch.Width, _deviceContext.DotsPerInch.Height); var pixelSize = PixelSize.FromSizeWithDpi(intermediateSize, dpi); using (var intermediate = new BitmapRenderTarget( _deviceContext, CompatibleRenderTargetOptions.None, pixelSize.ToSizeWithDpi(dpi).ToSharpDX())) { using (var ctx = new RenderTarget(intermediate).CreateDrawingContext(_visualBrushRenderer)) { intermediate.Clear(null); _visualBrushRenderer.RenderVisualBrush(ctx, visualBrush); } return(new ImageBrushImpl( visualBrush, _deviceContext, new D2DBitmapImpl(intermediate.Bitmap), destinationSize)); } } } else { throw new NotSupportedException("No IVisualBrushRenderer was supplied to DrawingContextImpl."); } } return(new SolidColorBrushImpl(null, _deviceContext)); }
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> /// Draws the widget on the render target /// </summary> /// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public override void Draw(RenderTarget target, RenderStates states) { // Calculate the scale factor of the view float scaleViewX = target.Size.X / target.GetView().Size.X; float scaleViewY = target.Size.Y / target.GetView().Size.Y; Vector2f viewPosition = (target.GetView().Size / 2.0f) - target.GetView().Center; // Get the global position Vector2f topLeftPosition = states.Transform.TransformPoint(Position + viewPosition); Vector2f bottomRightPosition = states.Transform.TransformPoint(Position.X + m_ListBox.Size.X - (m_TextureArrowDownNormal.Size.X * ((float)(m_ListBox.ItemHeight) / m_TextureArrowDownNormal.Size.Y)) + viewPosition.X, Position.Y + m_ListBox.Size.Y + viewPosition.Y); // Adjust the transformation states.Transform *= Transform; // Remember the current transformation Transform oldTransform = states.Transform; // Draw left border RectangleShape border = new RectangleShape(new Vector2f(m_Borders.Left, m_ListBox.ItemHeight + m_Borders.Top)); border.Position = new Vector2f(-(float)m_Borders.Left, -(float)m_Borders.Top); border.FillColor = m_ListBox.BorderColor; target.Draw(border, states); // Draw top border border.Size = new Vector2f(m_ListBox.Size.X + m_Borders.Right, m_Borders.Top); border.Position = new Vector2f(0, -(float)m_Borders.Top); target.Draw(border, states); // Draw right border border.Size = new Vector2f(m_Borders.Right, m_ListBox.ItemHeight + m_Borders.Bottom); border.Position = new Vector2f(m_ListBox.Size.X, 0); target.Draw(border, states); // Draw bottom border border.Size = new Vector2f(m_ListBox.Size.X + m_Borders.Left, m_Borders.Bottom); border.Position = new Vector2f(-(float)m_Borders.Left, m_ListBox.ItemHeight); target.Draw(border, states); // Draw the combo box RectangleShape front = new RectangleShape(new Vector2f((float)(m_ListBox.Size.X), (float)(m_ListBox.ItemHeight))); front.FillColor = m_ListBox.BackgroundColor; target.Draw(front, states); // Create a text widget to draw it Text tempText = new Text("kg", m_ListBox.TextFont); tempText.CharacterSize = m_ListBox.ItemHeight; tempText.CharacterSize = (uint)(tempText.CharacterSize - tempText.GetLocalBounds().Top); tempText.Color = m_ListBox.TextColor; // Get the old clipping area int[] scissor = new int[4]; Gl.glGetIntegerv(Gl.GL_SCISSOR_BOX, scissor); // Calculate the clipping area int scissorLeft = System.Math.Max((int)(topLeftPosition.X * scaleViewX), scissor[0]); int scissorTop = System.Math.Max((int)(topLeftPosition.Y * scaleViewY), (int)(target.Size.Y) - scissor[1] - scissor[3]); int scissorRight = System.Math.Min((int)(bottomRightPosition.X * scaleViewX), scissor[0] + scissor[2]); int scissorBottom = System.Math.Min((int)(bottomRightPosition.Y * scaleViewY), (int)(target.Size.Y) - scissor[1]); // If the widget outside the window then don't draw anything if (scissorRight < scissorLeft) { scissorRight = scissorLeft; } else if (scissorBottom < scissorTop) { scissorTop = scissorBottom; } // Set the clipping area Gl.glScissor(scissorLeft, (int)(target.Size.Y - scissorBottom), scissorRight - scissorLeft, scissorBottom - scissorTop); // Draw the selected item states.Transform.Translate(2, (float)System.Math.Floor((m_ListBox.ItemHeight - tempText.GetLocalBounds().Height) / 2.0f - tempText.GetLocalBounds().Top)); tempText.DisplayedString = m_ListBox.GetSelectedItem(); target.Draw(tempText, states); // Reset the old clipping area Gl.glScissor(scissor[0], scissor[1], scissor[2], scissor[3]); // Reset the transformations states.Transform = oldTransform; // Set the arrow like it should (down when list box is invisible, up when it is visible) if (m_ListBox.Visible) { float scaleFactor = (float)(m_ListBox.ItemHeight) / m_TextureArrowUpNormal.Size.Y; states.Transform.Translate(m_ListBox.Size.X - m_TextureArrowUpNormal.Size.X * scaleFactor, 0); states.Transform.Scale(scaleFactor, scaleFactor); // Draw the arrow if (m_SeparateHoverImage) { if ((m_MouseHover) && ((m_WidgetPhase & (byte)WidgetPhase.Hover) != 0)) { target.Draw(m_TextureArrowUpHover.sprite, states); } else { target.Draw(m_TextureArrowUpNormal.sprite, states); } } else // There is no separate hover image { target.Draw(m_TextureArrowUpNormal.sprite, states); if ((m_MouseHover) && ((m_WidgetPhase & (byte)WidgetPhase.Focused) != 0)) { target.Draw(m_TextureArrowUpHover.sprite, states); } } } else { float scaleFactor = (float)(m_ListBox.ItemHeight) / m_TextureArrowDownNormal.Size.Y; states.Transform.Translate(m_ListBox.Size.X - m_TextureArrowDownNormal.Size.X * scaleFactor, 0); states.Transform.Scale(scaleFactor, scaleFactor); // Draw the arrow if (m_SeparateHoverImage) { if ((m_MouseHover) && ((m_WidgetPhase & (byte)WidgetPhase.Hover) != 0)) { target.Draw(m_TextureArrowDownHover.sprite, states); } else { target.Draw(m_TextureArrowDownNormal.sprite, states); } } else // There is no separate hover image { target.Draw(m_TextureArrowDownNormal.sprite, states); if ((m_MouseHover) && ((m_WidgetPhase & (byte)WidgetPhase.Hover) != 0)) { target.Draw(m_TextureArrowDownHover.sprite, states); } } } }
protected override void OnDraw() { RenderTarget.Clear(BackgroundColor); if (ParadigmStarted) { DrawHintAndInput(); var debug = Paradigm.Config.Test.Debug; var now = CurrentTime; var trial = _trial; var secsPassed = (now - trial?.StartTime) / 1000.0 ?? 0; /* Draw buttons */ foreach (var button in Buttons) { if (button == null) { continue; } var scheme = button.State < 0 ? null : _stimulationPatterns[button.State]; var actived = scheme != null && trial != null; if (button.BorderWidth > 0) { SharedBrush.Color = ButtonBorderColor; RenderTarget.FillRectangle(button.BorderRect, SharedBrush); } SharedBrush.Color = ButtonNormalColor; RenderTarget.FillRectangle(button.ContentRect, SharedBrush); if (actived) { var progress = (float)Math.Max(0, Math.Min(scheme.Sample(secsPassed), 1)); var color = Color.SmoothStep(ButtonNormalColor, ButtonFlashingColor, progress); // var radialGradientBrush = new D2D1.RadialGradientBrush(_renderTarget, new D2D1.RadialGradientBrushProperties // { // Center = button.Center, // RadiusX = button.Size.X / 2, // RadiusY = button.Size.Y / 2, // }, new D2D1.GradientStopCollection(_renderTarget, new[] // { // new D2D1.GradientStop // { // Position = 0, // Color = color // }, // new D2D1.GradientStop // { // Position = 0.6F, // Color = Color.SmoothStep(color, _buttonFlashingColor, 0.1F) // }, // new D2D1.GradientStop // { // Position = 1, // Color = _buttonNormalColor // }, // }, D2D1.ExtendMode.Clamp)); SharedBrush.Color = color; RenderTarget.FillRectangle(button.FlickerRect, SharedBrush); } else if (HintedButton == button) { SharedBrush.Color = ButtonHintColor; RenderTarget.FillRectangle(button.FlickerRect, SharedBrush); } if (button.Key.Name.IsNotEmpty()) { var brush = button == SelectedButton ? (SelectionFeedbackCorrect ? CorrectColorBrush : WrongColorBrush) : ForegroundBrush; RenderTarget.DrawText(button.Key.Name, ButtonLabelTextFormat, button.ContentRect, brush, D2D1.DrawTextOptions.None); } if (actived && button.FixationPointSize > 0) { SharedBrush.Color = ButtonFixationPointColor; RenderTarget.FillEllipse(button.FixationPoint, SharedBrush); } if (debug && scheme != null) { SharedBrush.Color = new Color(ForegroundColor.R, ForegroundColor.G, ForegroundColor.B, 0.6F); RenderTarget.DrawText(scheme.ToString(), _frequencyTextFormat, button.ContentRect, SharedBrush, D2D1.DrawTextOptions.None); } } } DrawCueAndSubtitle(); }
/// <summary> /// Grabs an image with the content of current render target /// </summary> public abstract ImageCapture CaptureRenderTarget(RenderTarget surface);
internal ImageAssetManager(string imagesFolder, IImageAssetDelegate @delegate, Dictionary <string, LottieImageAsset> imageAssets, RenderTarget context) { _imagesFolder = imagesFolder; _context = context; if (!string.IsNullOrEmpty(imagesFolder) && _imagesFolder[_imagesFolder.Length - 1] != '/') { _imagesFolder += '/'; } //if (!(callback is UIElement)) // TODO: Makes sense on UWP? //{ // Debug.WriteLine("LottieDrawable must be inside of a view for images to work.", L.TAG); // this.imageAssets = new Dictionary<string, LottieImageAsset>(); // return; //} _imageAssets = imageAssets; Delegate = @delegate; }
internal virtual Bitmap BitmapForId(RenderTarget renderTarget, string id) { lock (this) { if (!_imageAssets.TryGetValue(id, out var imageAsset)) { return(null); } else if (imageAsset.Bitmap != null) { return(imageAsset.Bitmap); } Bitmap bitmap; if (_delegate != null) { bitmap = _delegate.FetchBitmap(imageAsset); if (bitmap != null) { PutBitmap(id, bitmap); } return(bitmap); } var filename = imageAsset.FileName; if (filename.StartsWith("data:") && filename.IndexOf("base64,") > 0) { // Contents look like a base64 data URI, with the format data:image/png;base64,<data>. byte[] data; try { data = Convert.FromBase64String(filename.Substring(filename.IndexOf(',') + 1)); } catch (Exception e) { Debug.WriteLine($"data URL did not have corRectangleF base64 format. {e}", LottieLog.Tag); return(null); } bitmap = LoadFromBuffer(renderTarget, data); PutBitmap(id, bitmap); return(bitmap); } Stream @is; try { if (string.IsNullOrEmpty(_imagesFolder)) { throw new InvalidOperationException("You must set an images folder before loading an image. Set it with LottieDrawable.ImageAssetsFolder"); } @is = File.OpenRead(_imagesFolder + imageAsset.FileName); } catch (IOException e) { Debug.WriteLine($"Unable to open asset. {e}", LottieLog.Tag); return(null); } bitmap = LoadFromStream(renderTarget, @is); @is.Dispose(); PutBitmap(id, bitmap); return(bitmap); } }
public static Bitmap LoadFromBuffer(RenderTarget renderTarget, byte[] buffer) { // Loads from file using System.Drawing.Image using (var stream = new MemoryStream(buffer)) return(LoadFromStream(renderTarget, stream)); }
public bool HasSameContext(RenderTarget context) { return(context == null && _context == null || _context.Equals(context)); }
public virtual void Draw(RenderTarget target) { }
internal SpriteBatch(RenderTarget target) { renderTarget = target; }
public void Draw(RenderTarget target, RenderStates states) { target.Draw(_vertices, PrimitiveType.TrianglesStrip, states); }
public override void Draw(RenderTarget renderTarget) { renderTarget.Draw(sprite); }
protected override void OnRender(ChartControl chartControl, ChartScale chartScale) { base.OnRender(chartControl, chartScale); try { if (Bars == null) { return; } if (isRangeChart) { int actualRange = (int)Math.Round(Math.Max(Close.GetValueAt(CurrentBar) - Low.GetValueAt(CurrentBar), High.GetValueAt(CurrentBar) - Close.GetValueAt(CurrentBar)) / Bars.Instrument.MasterInstrument.TickSize); int rangeCount = BarsPeriod.Value - actualRange; // determine wiggle room in ticks int barRange = (int)Math.Round((High.GetValueAt(CurrentBar) - Low.GetValueAt(CurrentBar)) / Bars.Instrument.MasterInstrument.TickSize); int margin = (BarsPeriod.Value - barRange); // calc our rectangle properties double highPrice = High.GetValueAt(CurrentBar) + (margin * TickSize); double lowPrice = Low.GetValueAt(CurrentBar) - (margin * TickSize); int rangeHighY = (ChartPanel.Y + ChartPanel.H) - ((int)(((highPrice - ChartPanel.MinValue) / Math.Max(Math.Abs(ChartPanel.MaxValue - ChartPanel.MinValue), 1E-05)) * ChartPanel.H)) - 1; int rangeLowY = (ChartPanel.Y + ChartPanel.H) - ((int)(((lowPrice - ChartPanel.MinValue) / Math.Max(Math.Abs(ChartPanel.MaxValue - ChartPanel.MinValue), 1E-05)) * ChartPanel.H)) - 1; int height = rangeLowY - rangeHighY; int rangeX = ChartControl.GetXByBarIndex(ChartBars, CurrentBar) - (int)(ChartControl.Properties.BarDistance / 2); int width = (int)(ChartControl.Properties.BarDistance); switch (margin) { case 0: SharpDX.RectangleF PLBoundRect0 = new SharpDX.RectangleF(rangeX, rangeHighY, width + 1, height); RenderTarget.DrawRectangle(PLBoundRect0, dxmBrushes["LockedBrush"].DxBrush, 2f); break; case 1: SharpDX.RectangleF PLBoundRect1 = new SharpDX.RectangleF(rangeX, rangeHighY, width + 1, height); RenderTarget.DrawRectangle(PLBoundRect1, dxmBrushes["WarningBrush"].DxBrush, 2f); break; } if (ShowPrices) { int lineH = (int)ChartControl.Properties.LabelFont.TextFormatHeight; DrawString(highPrice.ToString("F" + digits), ChartControl.Properties.LabelFont, "ChartFontBrush", rangeX, rangeHighY - lineH); DrawString("R:" + rangeCount.ToString(), ChartControl.Properties.LabelFont, "ChartFontBrush", rangeX + width, rangeHighY); DrawString(lowPrice.ToString("F" + digits), ChartControl.Properties.LabelFont, "ChartFontBrush", rangeX, rangeLowY); DrawString("C:" + barRange.ToString(), ChartControl.Properties.LabelFont, "ChartFontBrush", rangeX + width, rangeLowY - lineH); } } else { // Create a TextLayout so we can use Metrics for MeasureString() SharpDX.DirectWrite.TextFormat textFormat = ChartControl.Properties.LabelFont.ToDirectWriteTextFormat(); SharpDX.DirectWrite.TextLayout textLayout = new SharpDX.DirectWrite.TextLayout(NinjaTrader.Core.Globals.DirectWriteFactory, noRangeMessage, textFormat, ChartPanel.X + ChartPanel.W, textFormat.FontSize, 1, true); DrawString(noRangeMessage, ChartControl.Properties.LabelFont, "ChartFontBrush", ChartPanel.X + ChartPanel.W - textLayout.Metrics.Width - 10, ChartPanel.Y + ChartPanel.H - textLayout.Metrics.Height - 10); } } catch (Exception ex) { Print(ex.ToString()); } }
public void BeginDraw() { RenderTarget.BeginDraw(); }
/// <summary> /// Initializes a new instance of the <see cref="SFML"/> class. /// </summary> /// <param name="target">SFML render target.</param> public SFML(RenderTarget target) { m_Target = target; m_VertexCache = new Vertex[CacheSize]; m_RenderState = new RenderStates(BlendMode.Alpha); // somehow worked without this in previous SFML version (May 9th 2010) }
/// <summary> /// Called to set the target up for rendering. /// </summary> /// <param name="control">Control to be rendered.</param> public void SetupCacheTexture(Control.Base control) { m_RealRT = m_Target; m_Stack.Push(m_Target); // save current RT m_Target = m_RT[control]; // make cache current RT }
internal void SetRenderTarget(RenderTarget target) { this.target = target; }
//methods public virtual void Draw(RenderTarget target, RenderStates states) { //target.Draw(); }