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 Evaluate(int pSpreadMax) { if (_FNUIFlashPlayer == null) { return; } try { FSpreadCount = pSpreadMax; if (FGoToFrame.IsChanged) { _FNUIFlashPlayer.GotoFrame(FGoToFrame[0]); } if (FQuality.IsChanged) { _FNUIFlashPlayer.SetQualityString(FQuality[0].ToString()); } if (FEnabledInput[0]) { Matrix4x4 world; if (FMouseX.IsChanged || FMouseY.IsChanged) { FTransformIn.GetRenderWorldMatrix(0, out world); var mouse = new Vector3D(FMouseX[0], FMouseY[0], 0); // getting the transformed stage mouse = !world * mouse; // scale to swf coordinates mouse.x = (mouse.x + 0.5) * _Width / 1.0; mouse.y = (-1 * mouse.y + 0.5) * _Height / 1.0; _FNUIFlashPlayer.UpdateMousePosition((int)mouse.x, (int)mouse.y); } if (FMouseLeftButton.IsChanged) { if (FMouseLeftButton[0]) { _FNUIFlashPlayer.UpdateMouseButton(0, true); } else { _FNUIFlashPlayer.UpdateMouseButton(0, false); } } if (FKeyCodeIn.IsChanged) { List <int> currentKeyState = new List <int>(); int count = FKeyCodeIn.SliceCount; for (int i = 0; i < count; i++) { int v = FKeyCodeIn[i]; if (v > 0) { currentKeyState.Add(v); } } count = FLastKeyState.Count; for (int i = 0; i < count; i++) { if (currentKeyState.IndexOf(FLastKeyState[i]) < 0) { _FNUIFlashPlayer.SendKey(false, FLastKeyState[i], 0); } } count = currentKeyState.Count; bool isShift = currentKeyState.IndexOf(16) >= 0; for (int i = 0; i < count; i++) { if (FLastKeyState.IndexOf(currentKeyState[i]) < 0) { int key = currentKeyState[i]; _FNUIFlashPlayer.SendKey(true, key, 0); //char if (!isShift && (key >= 65 && key <= 90)) { _FNUIFlashPlayer.SendChar(MapVirtualKey(key, 2) + 32, 0); } //Ä else if (key == 222) { if (isShift) { _FNUIFlashPlayer.SendChar(196, 0); } else { _FNUIFlashPlayer.SendChar(228, 0); } } //Ö else if (key == 192) { if (isShift) { _FNUIFlashPlayer.SendChar(214, 0); } else { _FNUIFlashPlayer.SendChar(246, 0); } } //Ü else if (key == 186) { if (isShift) { _FNUIFlashPlayer.SendChar(220, 0); } else { _FNUIFlashPlayer.SendChar(252, 0); } } //ß else if (key == 219) { _FNUIFlashPlayer.SendChar(223, 0); } else { _FNUIFlashPlayer.SendChar(MapVirtualKey(key, 2), 0); } } } FLastKeyState = currentKeyState; } } } 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(); } }