//**************************************************************** // Painting - Methods for painting a PText. //**************************************************************** /// <summary> /// Overridden. See <see cref="PNode.Paint">PNode.Paint</see>. /// </summary> protected override void Paint(UMD.HCIL.Piccolo.Util.PPaintContext paintContext) { base.Paint(paintContext); Device device = (paintContext as P3PaintContext).Device; PMatrix currMatrix = (paintContext as P3PaintContext).Transform; // Scale the matrix down to display font units float scale = displayFontSize / font.Size; currMatrix.ScaleBy(scale, X, Y); float[] piccoloMatrixElements = currMatrix.Elements; if (!currMatrix.IsIdentity) { Matrix m = new Matrix(); m.M11 = piccoloMatrixElements[0]; m.M12 = piccoloMatrixElements[1]; m.M21 = piccoloMatrixElements[2]; m.M22 = piccoloMatrixElements[3]; m.M41 = piccoloMatrixElements[4]; m.M42 = piccoloMatrixElements[5]; m.M33 = 1; m.M44 = 1; textSprite.Transform = m; } textSprite.Begin(SpriteFlags.None); DrawTextFormat D3DAlignment = P3Util.GetD3DAlignment(stringFormat.Alignment); // Calculate the rectangle with no padding, in actual font units scale = 1 / scale; int totHzPadding = currLeftPadding + currRightPadding; int totVtPadding = currTopPadding + currBottomPadding; Rectangle dstRect = new Rectangle((int)(Bounds.X + currLeftPadding * scale), (int)(Bounds.Y + currTopPadding * scale), (int)((Bounds.Width - totHzPadding) * scale), (int)((Bounds.Height - totVtPadding) * scale)); // Wrap the string ourselves, instead of letting the draw method do it, since we want to make // sure it's consistent with our own MeasureString method. String str = P3Util.WrapString(textSprite, D3Dfont, Text, dstRect.Width, (TextBrush as SolidBrush).Color); D3Dfont.DrawText(textSprite, str, dstRect, D3DAlignment, (TextBrush as SolidBrush).Color); textSprite.End(); }
public override void Draw() { font.DrawText(null, text, new Rectangle(origin, dimensions), DrawTextFormat.Left, clr); }
protected override bool CreateTexture() { if (string.IsNullOrEmpty(Text) || !Main.This.Created) { return(false); } if (DXFont == null || DXFont.Disposed) { if (Font != null) { DXFont = new Microsoft.DirectX.Direct3D.Font(DXManager.Device, Font); } else { return(false); } } if (AutoSize) { Size = DXFont.MeasureString(null, Text, DrawFormat, ForeColor).Size; if (OutLine && Size != Size.Empty) { Size = new Size(Size.Width + 2, Size.Height + 2); } } if (Size == Size.Empty) { return(false); } if (ControlTexture != null && !ControlTexture.Disposed) { ControlTexture.Dispose(); } ControlTexture = new Texture(DXManager.Device, Size.Width, Size.Height, 0, Usage.RenderTarget, Format.A8R8G8B8, Pool.Default); ControlTexture.Disposing += ControlTexture_Disposing; Surface OldSurface = DXManager.CurrentSurface; DXManager.SetSurface(ControlTexture.GetSurfaceLevel(0)); DXManager.Device.Clear(ClearFlags.Target, BackColor, 0, 0); Point TempPoint = Point.Empty; if (OutLine) { TempPoint.X = 1; TempPoint.Y = 0; if (DrawFormat == DrawTextFormat.None) { DXFont.DrawText(null, Text, TempPoint, OutLineColor); } else { DXFont.DrawText(null, Text, new Rectangle(TempPoint, Size), DrawFormat, OutLineColor); } TempPoint.X = 0; TempPoint.Y = 1; if (DrawFormat == DrawTextFormat.None) { DXFont.DrawText(null, Text, TempPoint, OutLineColor); } else { DXFont.DrawText(null, Text, new Rectangle(TempPoint, Size), DrawFormat, OutLineColor); } TempPoint.X = 2; TempPoint.Y = 1; if (DrawFormat == DrawTextFormat.None) { DXFont.DrawText(null, Text, TempPoint, OutLineColor); } else { DXFont.DrawText(null, Text, new Rectangle(TempPoint, Size), DrawFormat, OutLineColor); } TempPoint.X = 1; TempPoint.Y = 2; if (DrawFormat == DrawTextFormat.None) { DXFont.DrawText(null, Text, TempPoint, OutLineColor); } else { DXFont.DrawText(null, Text, new Rectangle(TempPoint, Size), DrawFormat, OutLineColor); } TempPoint = new Point(1, 1); } if (DrawFormat == DrawTextFormat.None) { DXFont.DrawText(null, Text, TempPoint, ForeColor); } else { DXFont.DrawText(null, Text, new Rectangle(TempPoint, Size), DrawFormat, ForeColor); } DXManager.SetSurface(OldSurface); TextureValid = true; return(true); }
/// <summary> /// The draw. /// </summary> /// <param name="scale">The scale.</param> /// <remarks></remarks> public void draw(float scale) { // Store current world matrix Matrix mat = device.Transform.World; // Set the world matrix to our desires for our gizmo device.Transform.World = Matrix.Scaling(scale, scale, scale) * mat; FillMode oldFill = device.RenderState.FillMode; device.RenderState.FillMode = FillMode.Solid; Cull oldCull = device.RenderState.CullMode; device.RenderState.CullMode = Cull.None; CustomVertex.PositionColored[] vertices = new CustomVertex.PositionColored[18]; Color c1 = Color.Red; Color c2 = Color.Red; Color c3 = Color.Red; if (this.selectedAxis == axis.X) { c1 = Color.Yellow; } if (this.selectedAxis == axis.XY) { c1 = Color.Yellow; c2 = Color.Yellow; } if (this.selectedAxis == axis.XZ) { c1 = Color.Yellow; c3 = Color.Yellow; } vertices[0].Color = c1.ToArgb(); vertices[1].Color = c1.ToArgb(); vertices[2].Color = c2.ToArgb(); vertices[3].Color = c2.ToArgb(); vertices[4].Color = c3.ToArgb(); vertices[5].Color = c3.ToArgb(); vertices[0].Position = new Vector3(0f, 0f, 0f); vertices[1].Position = new Vector3(10f, 0f, 0f); vertices[2].Position = new Vector3(5f, 0f, 0f); vertices[3].Position = new Vector3(5f, 5f, 0f); vertices[4].Position = new Vector3(5f, 0f, 0f); vertices[5].Position = new Vector3(5f, 0f, 5f); Vector3 pos = new Vector3(13f, 1f, 0f); Vector3 plot2d = Vector3.Project( pos, this.device.Viewport, device.Transform.Projection, device.Transform.View, device.Transform.World); // Need to render in 3D for ZBuffer removal font.DrawText(null, "x", new Point((int)plot2d.X, (int)plot2d.Y), c1); c1 = Color.Green; c2 = Color.Green; c3 = Color.Green; if (this.selectedAxis == axis.Y) { c1 = Color.Yellow; } if (this.selectedAxis == axis.XY) { c1 = Color.Yellow; c2 = Color.Yellow; } if (this.selectedAxis == axis.YZ) { c1 = Color.Yellow; c3 = Color.Yellow; } vertices[6].Color = c1.ToArgb(); vertices[7].Color = c1.ToArgb(); vertices[8].Color = c2.ToArgb(); vertices[9].Color = c2.ToArgb(); vertices[10].Color = c3.ToArgb(); vertices[11].Color = c3.ToArgb(); vertices[6].Position = new Vector3(0f, 0f, 0f); vertices[7].Position = new Vector3(0f, 10f, 0f); vertices[8].Position = new Vector3(0f, 5f, 0f); vertices[9].Position = new Vector3(5f, 5f, 0f); vertices[10].Position = new Vector3(0f, 5f, 0f); vertices[11].Position = new Vector3(0f, 5f, 5f); pos = new Vector3(1f, 13f, 0f); plot2d = Vector3.Project( pos, this.device.Viewport, device.Transform.Projection, device.Transform.View, device.Transform.World); font.DrawText(null, "y", new Point((int)plot2d.X, (int)plot2d.Y), c1); c1 = Color.Blue; c2 = Color.Blue; c3 = Color.Blue; if (this.selectedAxis == axis.Z) { c1 = Color.Yellow; } if (this.selectedAxis == axis.XZ) { c1 = Color.Yellow; c2 = Color.Yellow; } if (this.selectedAxis == axis.YZ) { c1 = Color.Yellow; c3 = Color.Yellow; } vertices[12].Color = c1.ToArgb(); vertices[13].Color = c1.ToArgb(); vertices[14].Color = c2.ToArgb(); vertices[15].Color = c2.ToArgb(); vertices[16].Color = c3.ToArgb(); vertices[17].Color = c3.ToArgb(); vertices[12].Position = new Vector3(0f, 0f, 0f); vertices[13].Position = new Vector3(0f, 0f, 10f); vertices[14].Position = new Vector3(0f, 0f, 5f); vertices[15].Position = new Vector3(5f, 0f, 5f); vertices[16].Position = new Vector3(0f, 0f, 5f); vertices[17].Position = new Vector3(0f, 5f, 5f); pos = new Vector3(1f, 0f, 13f); plot2d = Vector3.Project( pos, this.device.Viewport, device.Transform.Projection, device.Transform.View, device.Transform.World); font.DrawText(null, "z", new Point((int)plot2d.X, (int)plot2d.Y), c1); device.VertexFormat = CustomVertex.PositionColored.Format; device.DrawUserPrimitives(PrimitiveType.LineList, 9, vertices); #region Drawing axis cones this.gizmo.DrawSubset(0); // X-Axis this.gizmo.DrawSubset(1); // Y-Axis this.gizmo.DrawSubset(2); // Z-Axis #endregion this.gizmo.DrawSubset(3); // Z-Axis this.gizmo.DrawSubset(4); // Z-Axis this.gizmo.DrawSubset(5); // Z-Axis /* * for (int i = 3; i < 9; i++) * this.gizmo.DrawSubset(i); */ // Restore previous world matrix device.RenderState.FillMode = oldFill; device.RenderState.CullMode = oldCull; device.Transform.World = mat; this.scale = scale; }
/// <summary> /// Dibujar un texto en la posición indicada, con el color indicado. /// Utilizar la fuente default del Framework. /// </summary> /// <param name="text">Texto a dibujar</param> /// <param name="x">Posición X de la pantalla</param> /// <param name="y">Posición Y de la pantalla</param> /// <param name="color">Color del texto</param> public void drawText(string text, int x, int y, Color color) { TextSprite.Begin(SpriteFlags.AlphaBlend); dxFont.DrawText(TextSprite, text, x, y, color); TextSprite.End(); }
public void DrawScene() { if (m_ready) { m_FPS.BeginFrame(); if (MdxRender.DeviceInfo.bDeviceLost) { AttemptRecovery(); } else { try { MdxRender.Dev.Clear(ClearFlags.ZBuffer | ClearFlags.Target, ClearColor, 1.0f, 0); MdxRender.Dev.Transform.View = Camera.GetViewMatrix(); MdxRender.Dev.Transform.World = Matrix.Identity; //todo: preview vs bsp mode if (PreviewManager.Mode != PreviewMode.ProjectMode) { MdxRender.SetZbufRange(0.01f, 300.0f); UpdateViewTransform(); } else { SetZbufRange(30.0f, 100000.0f); UpdateViewTransform(); } MdxRender.Dev.BeginScene(); if (!m_isPaused) { MdxRender.Dev.Material = whiteMaterial; //The beef of the matter if (PreviewManager.Mode != PreviewMode.ProjectMode) { PreviewManager.RenderActivePreview(); //mapViewButton.DrawButton(true); } else { #region DrawProject MdxRender.Dev.Material = whiteMaterial; MdxRender.Dev.RenderState.DiffuseMaterialSource = ColorSource.Material; MdxRender.Dev.RenderState.SpecularMaterialSource = ColorSource.Material; MdxRender.Dev.RenderState.SpecularEnable = false; //Render the skybox if we are in map view mode if (MdxRender.SkyBox != null) { //turn lighting off for skybox //MdxRender.Dev.RenderState.Lighting = false; //turn off fog or you won't be able to see the skybox through it if (MdxRender.FogEnabled) { MdxRender.Dev.SetRenderState(RenderStates.FogEnable, false); } //disable z-writing for the skybox since it is behind everything //and to get rid of that stupid clipping artifact MdxRender.Dev.RenderState.ZBufferWriteEnable = false; SkyBox.Render(); MdxRender.Dev.RenderState.ZBufferWriteEnable = true; //turn fog back on if (MdxRender.FogEnabled) { MdxRender.Dev.SetRenderState(RenderStates.FogEnable, true); } } else { //turn off fog when we are in model preview mode MdxRender.Dev.SetRenderState(RenderStates.FogEnable, false); } //draw the map BSP if (Halo1_Bsp != null) { MdxRender.Dev.RenderState.Lighting = true; Halo1_Bsp.DrawBsp(); TagBsp.Debug_RenderNearestNeighborVerts(); MdxRender.lightmapDebugger.Render(); //Halo1_Bsp.DrawWireframeBsp(); //MdxRender.Dev.RenderState.FillMode = FillMode.Solid; } //turn on lighting for scenery MdxRender.Dev.RenderState.Lighting = true; MdxRender.SM.DisableBlend(); //this necessary? //draw all ye map objects //MdxRender.Dev.RenderState.DiffuseMaterialSource = ColorSource.Material; //MdxRender.Dev.RenderState.SpecularMaterialSource = ColorSource.Material; //MdxRender.Dev.RenderState.SpecularEnable = true; ProjectManager.MapSpawns.Render(); #endregion if (m_showFPS) { DrawFPS(); } } } else { m_fontFPS.DrawText(null, "Rendering Paused", 3, 3, Color.White); Thread.Sleep(250); } } catch (Exception e) { Trace.WriteLine("Error during DrawScene(): " + e.Message); } finally { try { MdxRender.Dev.EndScene(); MdxRender.Dev.Present(); //SwapChain sc = MdxRender.Dev.GetSwapChain(0); //sc.Present(Present.LinearContent); } catch (DeviceLostException) { MdxRender.DeviceInfo.bDeviceLost = true; Trace.WriteLine("Device was lost."); } catch (Exception e) { Trace.WriteLine("Error during Device.Present(): " + e.Message); } } } m_FPS.EndFrame(); } }