public void Render(IDXLayerIO ForPin, Device OnDevice) { //concerning the cut characters in some fonts, especially when rendered italic see: //http://www.gamedev.net/community/forums/topic.asp?topic_id=441338 //seems to be an official bug and we'd need to write our very own font rendering to fix that if (!FEnabledInput[0]) { return; } //from the docs: D3DXSPRITE_OBJECTSPACE -> The world, view, and projection transforms are not modified. //for view and projection transforms this is exactly what we want: it allows placing the text within the //same world as all the other objects. however we don't want to work in object space but in world space //that's why we need to to set the world transform to a neutral value: identity OnDevice.SetTransform(TransformState.World, Matrix.Identity); FTransformIn.SetRenderSpace(); //set states that are defined via upstream nodes FRenderStatePin.SetSliceStates(0); DeviceHelpers dh = FDeviceHelpers[OnDevice]; dh.Sprite.Begin(SpriteFlags.ObjectSpace | SpriteFlags.DoNotAddRefTexture); try { int normalize = FNormalizeInput[0].Index; Matrix preScale = Matrix.Scaling(1, -1, 1); Matrix world; string text; Rectangle tmpRect = new Rectangle(0, 0, 0, 0); int hAlign, vAlign; float x, y; int width, height; for (int i = 0; i < FSpreadMax; i++) { var font = CreateFont(OnDevice, i); text = FTextInput[i]; if (string.IsNullOrEmpty(text)) { continue; } DrawTextFormat format = DrawTextFormat.NoClip | DrawTextFormat.ExpandTabs; hAlign = FHorizontalAlignInput[i].Index; switch (hAlign) { case 0: format |= DrawTextFormat.Left; break; case 1: format |= DrawTextFormat.Center; break; case 2: format |= DrawTextFormat.Right; break; } vAlign = FVerticalAlignInput[i].Index; switch (vAlign) { case 0: format |= DrawTextFormat.Top; break; case 1: format |= DrawTextFormat.VerticalCenter; break; case 2: format |= DrawTextFormat.Bottom; break; } switch (FTextRenderingModeInput[i].Index) { case 0: format |= DrawTextFormat.SingleLine; break; case 2: format |= DrawTextFormat.WordBreak; break; } tmpRect = new Rectangle(0, 0, FWidth[i], 0); font.MeasureString(dh.Sprite, text, format, ref tmpRect); width = tmpRect.Width; height = tmpRect.Height; FSizeOutput[i] = new Vector2D(width, height); switch (normalize) { case 1: preScale = Matrix.Scaling(1f / width, -1f / width, 1); break; //"width" means that the texture width will have no influence on the width of the sprite. Width will be always 1. case 2: preScale = Matrix.Scaling(1f / height, -1f / height, 1); break; //"height" means that the texture height will have no influence on the height of the sprite. Height will be always 1. case 3: preScale = Matrix.Scaling(1f / width, -1f / height, 1); break; //"on" means that the particle will always be a unit quad. independant of texture size } FTransformIn.GetRenderWorldMatrix(i, out world); dh.Sprite.Transform = preScale * world; switch (vAlign) { case 1: y = height / 2; break; case 2: y = height; break; default: y = 0; break; } if (FShowBrush[i]) { switch (hAlign) { case 1: x = width / 2; break; case 2: x = width; break; default: x = 0; break; } dh.Sprite.Draw(dh.Texture, new Rectangle(0, 0, width, height), new Vector3(x, y, -0.001f), null, new Color4(FBrushColor[i].Color.ToArgb())); } width = FWidth[i]; switch (hAlign) { case 1: x = width / 2; break; case 2: x = width; break; default: x = 0; break; } font.DrawString(dh.Sprite, text, new Rectangle((int)-x, (int)-y, width, height), format, (Color)FColorInput[i]); } } catch (Exception e) { Logger.Log(e); } finally { dh.Sprite.End(); } }
public void Render(IDXLayerIO ForPin, Device tDevice) { //Called by the PluginHost everytime the plugin is supposed to render itself. //This is called from the PluginHost from within DirectX BeginScene/EndScene, //therefore the plugin shouldn't be doing much here other than some drawing calls. if (_FNUIFlashPlayer == null || FSprites.Count < 1) { return; } if (FEnabledInput[0]) { _FNUIFlashPlayer.DisableFlashRendering(false); } else { _FNUIFlashPlayer.DisableFlashRendering(true); return; } try { tDevice.SetTransform(TransformState.World, Matrix.Identity); Sprite tSprite = FSprites[tDevice]; FTransformIn.SetRenderSpace(); FRenderStatePin.SetSliceStates(0); tSprite.Begin(SpriteFlags.DoNotAddRefTexture | SpriteFlags.ObjectSpace); Matrix4x4 tTransformMatrix; for (int i = 0; i < FSpreadCount; i++) { FTransformIn.GetRenderWorldMatrix(i, out tTransformMatrix); tSprite.Transform = (VMath.Scale(1.0 / _Width, -1.0 / _Height, 1) * tTransformMatrix).ToSlimDXMatrix(); int t = _FNUIFlashPlayer.GetTexture().ToInt32(); if (t == 0) { if (_Texture1 != null) { tSprite.Draw(_Texture1, new Rectangle(0, 0, _Width, _Height), new Vector3(_Width / 2, _Height / 2, -0.001f), new Vector3(0, 0, 0), new Color4(Color.White.ToArgb())); } } else { if (_Texture2 != null) { tSprite.Draw(_Texture2, new Rectangle(0, 0, _Width, _Height), new Vector3(_Width / 2, _Height / 2, -0.001f), new Vector3(0, 0, 0), new Color4(Color.White.ToArgb())); } } _FNUIFlashPlayer.ReleaseTexture(); } tSprite.End(); } catch { } }
public void Render(IDXLayerIO ForPin, Device OnDevice) { //concerning the cut characters in some fonts, especially when rendered italic see: //http://www.gamedev.net/community/forums/topic.asp?topic_id=441338 //seems to be an official bug and we'd need to write our very own font rendering to fix that if (!FEnabledInput[0]) { return; } //from the docs: D3DXSPRITE_OBJECTSPACE -> The world, view, and projection transforms are not modified. //for view and projection transforms this is exactly what we want: it allows placing the text within the //same world as all the other objects. however we don't want to work in object space but in world space //that's why we need to to set the world transform to a neutral value: identity OnDevice.SetTransform(TransformState.World, Matrix.Identity); DeviceFont df = FDeviceFonts[OnDevice]; FTransformIn.SetRenderSpace(); //set states that are defined via upstream nodes FRenderStatePin.SetSliceStates(0); try { df.Sprite.Begin(SpriteFlags.ObjectSpace | SpriteFlags.DoNotAddRefTexture); int size = FSizeInput[0]; int normalize = FNormalizeInput[0].Index; Matrix4x4 preScale = VMath.Scale(1, -1, 1); switch (normalize) { case 0: preScale = VMath.Scale(1, -1, 1); break; //"off" means that text will be in pixels } Matrix4x4 world; string text; // RGBAColor textColor, brushColor; Rectangle tmpRect = new Rectangle(0, 0, 0, 0); int hAlign, wAlign; // double showBrush, w, h; float x, y; for (int i = 0; i < FSpreadMax; i++) { text = FTextInput[i]; if (string.IsNullOrEmpty(text)) { continue; } if (FCharEncoding[i] == "UTF8") { byte[] utf8bytes = Encoding.Default.GetBytes(text); text = Encoding.UTF8.GetString(utf8bytes); } DrawTextFormat dtf = DrawTextFormat.NoClip | DrawTextFormat.ExpandTabs; hAlign = FHorizontalAlignInput[i].Index; switch (hAlign) { case 0: dtf |= DrawTextFormat.Left; break; case 1: dtf |= DrawTextFormat.Center; break; case 2: dtf |= DrawTextFormat.Right; break; } wAlign = FVerticalAlignInput[i].Index; switch (wAlign) { case 0: dtf |= DrawTextFormat.Top; break; case 1: dtf |= DrawTextFormat.VerticalCenter; break; case 2: dtf |= DrawTextFormat.Bottom; break; } switch (FTextRenderingModeInput[i].Index) { case 0: dtf |= DrawTextFormat.SingleLine; break; case 2: dtf |= DrawTextFormat.WordBreak; break; } Vector2D rect = FRectInput[i] * size * 10; tmpRect.Width = (int)rect.x; tmpRect.Height = (int)rect.y; df.Font.MeasureString(df.Sprite, text, dtf, ref tmpRect); FSizeOutput[i] = new Vector2D(tmpRect.Width, tmpRect.Height); FTransformIn.GetRenderWorldMatrix(i, out world); switch (normalize) { case 1: preScale = VMath.Scale(1f / tmpRect.Width, -1f / tmpRect.Width, 1); break; //"width" means that the texture width will have no influence on the width of the sprite. Width will be always 1. case 2: preScale = VMath.Scale(1f / tmpRect.Height, -1f / tmpRect.Height, 1); break; //"height" means that the texture height will have no influence on the height of the sprite. Height will be always 1. case 3: preScale = VMath.Scale(1f / tmpRect.Width, -1f / tmpRect.Height, 1); break; //"on" means that the particle will always be a unit quad. independant of texture size } df.Sprite.Transform = (preScale * world).ToSlimDXMatrix(); if (FShowBrush[i]) { x = tmpRect.Width / 2; y = tmpRect.Height / 2; if (hAlign == 0) { x -= x; } else if (hAlign == 2) { x += x; } if (wAlign == 0) { y -= y; } else if (wAlign == 2) { y += y; } /*workaround for slimdx(august09) * Matrix4x4 spriteBugWorkaround = VMath.Translate(-x, -y, 0.001); * df.Sprite.Transform = VSlimDXUtils.Matrix4x4ToSlimDXMatrix(spriteBugWorkaround * preScale * world); * df.Sprite.Draw(df.Texture, new Rectangle(0, 0, tmpRect.Width, tmpRect.Height), new Color4(brushColor.Color)); * df.Sprite.Transform = VSlimDXUtils.Matrix4x4ToSlimDXMatrix(preScale * world); * workaround end*/ df.Sprite.Draw(df.Texture, new Rectangle(0, 0, tmpRect.Width, tmpRect.Height), new Vector3(x, y, -0.001f), null, new Color4(FBrushColor[i].Color.ToArgb())); } df.Font.DrawString(df.Sprite, text, new Rectangle((int)-rect.x / 2, (int)-rect.y / 2, (int)rect.x, (int)rect.y), dtf, (Color)FColorInput[i]); } } catch (Exception e) { Logger.Log(e); } finally { df.Sprite.End(); } }