Ejemplo n.º 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Gizmo"/> class.
 /// </summary>
 /// <param name="device">The device.</param>
 /// <remarks></remarks>
 public Gizmo(Device device)
 {
     this.device = device;
     createMovementGizmo();
     this.device.RenderState.ZBufferEnable = true;
     font = new Microsoft.DirectX.Direct3D.Font(device, fnt);
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Gizmo"/> class.
 /// </summary>
 /// <param name="device">The device.</param>
 /// <remarks></remarks>
 public Gizmo(Device device)
 {
     this.device = device;
     createMovementGizmo();
     this.device.RenderState.ZBufferEnable = true;
     font = new Microsoft.DirectX.Direct3D.Font(device, fnt);
 }
Ejemplo n.º 3
0
 /// <summary>
 ///     Cambia la fuente del texto
 /// </summary>
 /// <param name="font">Fuente del sistema</param>
 public void changeFont(Font font)
 {
     if (D3dFont != null && !D3dFont.Disposed)
     {
         D3dFont.Dispose();
     }
     D3dFont = new Microsoft.DirectX.Direct3D.Font(D3DDevice.Instance.Device, font);
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Dispose the Direct3D font.
 /// </summary>
 protected virtual void DisposeFont()
 {
     if (D3Dfont != null)
     {
         D3Dfont.Dispose();
         D3Dfont = null;
     }
 }
Ejemplo n.º 5
0
        public override void Init(Device device)
        {
            base.Init(device);

            font = new Microsoft.DirectX.Direct3D.Font(device, fontType);
            // update dimensions
            if (dimensions.IsEmpty)
            {
                Rectangle strRect = font.MeasureString(null, text, DrawTextFormat.Left, clr);
                dimensions = new Size(strRect.Width, strRect.Height);
            }
        }
Ejemplo n.º 6
0
        public override void Init(Device device)
        {
            base.Init(device);

            font = new Microsoft.DirectX.Direct3D.Font(device, fontType);
            // update dimensions
            if (dimensions.IsEmpty)
            {
                Rectangle strRect = font.MeasureString(null, text, DrawTextFormat.Left, clr);
                dimensions = new Size(strRect.Width, strRect.Height);
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Called when the device resets
        /// </summary>
        /// <param name="sender">sender</param>
        /// <param name="e">args</param>
        private void m_device_DeviceReset(object sender, EventArgs e)
        {
            // set the projection matrix
            m_device.Transform.Projection = m_camera.Projection;
            m_device.Transform.World      = m_camera.World;

            // set the viewstate
            m_device.RenderState.CullMode      = Cull.None;
            m_device.RenderState.ZBufferEnable = true;

            m_debugFont = new Microsoft.DirectX.Direct3D.Font(m_device,
                                                              new Font(FontFamily.GenericSansSerif, 10.0f));

            m_axis.ReInitialize();
            //m_meshScene.ReInitialize();
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Overridden.  See <see cref="P3Node.ValidateVertices">P3Node.ValidateVertices</see>.
        /// </summary>
        public override void ValidateVertices(Device device)
        {
            if (fontChanged)
            {
                D3Dfont = new Direct3D.Font(device, Font);
            }

            if (textSprite == null)
            {
                textSprite = new Sprite(device);
            }

            D3Dfont.PreloadText(text);

            base.ValidateVertices(device);
        }
Ejemplo n.º 9
0
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         if (directxFont != null)
         {
             directxFont.Dispose();
             directxFont = null;
         }
         if (device != null)
         {
             device.Dispose();
             device = null;
         }
         base.Dispose(true);
     }
 }
Ejemplo n.º 10
0
        private void OnFontChanged(EventArgs e)
        {
            TextureValid = false;

            if (DXFont != null && !DXFont.Disposed)
            {
                DXFont.Dispose();
            }

            if (Font != null)
            {
                DXFont = new Microsoft.DirectX.Direct3D.Font(DXManager.Device, Font);
            }

            if (FontChanged != null)
            {
                FontChanged.Invoke(this, e);
            }
        }
        public TgcDrawText(Device d3dDevice, string fuente, int size, string MediaDir)
        {
            System.Drawing.Text.PrivateFontCollection privateFonts = new PrivateFontCollection();
            Font FUENTE_SIZE;

            if (fuente == "Rock it")
            {
                privateFonts.AddFontFile(MediaDir + "Font\\Rockit.ttf");
                FUENTE_SIZE = new Font(privateFonts.Families[0], size);
            }
            else
            {
                FUENTE_SIZE = new Font(fuente, size, FontStyle.Regular, GraphicsUnit.Pixel);
            }

            //Creo el Sprite
            TextSprite = new Sprite(d3dDevice);

            //Fuente
            dxFont = new Microsoft.DirectX.Direct3D.Font(d3dDevice, FUENTE_SIZE);
        }
Ejemplo n.º 12
0
        private bool initializeGraphics()
        {
            try
            {
                // Initialize the DirectX drawing
                initialized = true;
                PresentParameters presentParams = new PresentParameters();
                presentParams.Windowed           = true;
                presentParams.SwapEffect         = SwapEffect.Discard;
                presentParams.DeviceWindowHandle = this.Handle;

                device = new Device(0, DeviceType.Hardware,
                                    this,
                                    CreateFlags.SoftwareVertexProcessing,
                                    presentParams);

                // Set initial device parameters
                device.RenderState.CullMode = Cull.None;

                // Initialize the font
                Font systemFont = new System.Drawing.Font("Arial", 8f, FontStyle.Regular);
                drawingFont = new Microsoft.DirectX.Direct3D.Font(device, systemFont);

                // Set the timeseries device details
                foreach (oTimeseriesPlot plot in timeseriesPlots)
                {
                    plot.setDevice(device, drawingFont);
                }

                return(true);
            }
            catch (Exception ex)
            {
                initialized = false;

                //oConsole.printException(ex);
                return(false);
            }
        }
Ejemplo n.º 13
0
        protected override void Dispose(bool Disposing)
        {
            if (Disposing)
            {
                AutoSizeChanged = null;
                _AutoSize       = false;

                DrawFormatChanged = null;
                _DrawFormat       = DrawTextFormat.None;

                FontChanged = null;

                if (_Font != null)
                {
                    _Font.Dispose();
                }
                _Font = null;

                if (DXFont != null && !DXFont.Disposed)
                {
                    DXFont.Dispose();
                }
                DXFont = null;

                OutLineChanged = null;
                _OutLine       = false;

                OutLineColorChanged = null;
                _OutLineColor       = Color.Empty;

                TextChanged = null;
                Text        = null;
            }

            base.Dispose(Disposing);
        }
Ejemplo n.º 14
0
    /// <summary>
    /// Initialize the device objects. Load the texture or if it does not exist, create it.
    /// </summary>
    public void InitializeDeviceObjects()
    {
      BinaryFormatter b = new BinaryFormatter();
      Stream s = null;
      bool needsCreation = false;

      string strCache = String.Format(@"{0}\fonts\{1}_{2}.dds", GUIGraphicsContext.SkinCacheFolder, _fontName,
                                      _fontHeight);
      try
      {
        // If file does not exist
        //needsCreation = !File.Exists(strCache);
        if (!needsCreation)
        {
          try
          {
            ImageInformation info = new ImageInformation();
            _textureFont = TextureLoader.FromFile(GUIGraphicsContext.DX9Device,
                                                  strCache,
                                                  0, 0, //width/height
                                                  1, //miplevels
                                                  0,
                                                  Format.Unknown,
                                                  GUIGraphicsContext.GetTexturePoolType(),
                                                  Filter.None,
                                                  Filter.None,
                                                  0,
                                                  ref info);

            s = File.Open(strCache + ".bxml", FileMode.Open, FileAccess.Read);
            _textureCoords = (float[,])b.Deserialize(s);
            s.Close();
            _spacingPerChar = (int)_textureCoords[_EndCharacter - _StartCharacter, 0];
            _textureScale = _textureCoords[_EndCharacter - _StartCharacter + 1, 0];
            _textureHeight = info.Height;
            _textureWidth = info.Width;

            Log.Debug("  Loaded font:{0} height:{1} texture:{2}x{3} chars:[{4}-{5}] miplevels:{6}", _fontName,
                      _fontHeight,
                      _textureWidth, _textureHeight, _StartCharacter, _EndCharacter, _textureFont.LevelCount);
          }
          catch (InvalidDataException) // weird : should have been FileNotFoundException when file is missing ??
          {
            needsCreation = true;
          }
          catch (Exception)
          {
            // Deserialisation failed. Maybe the language changed or the font cache got manipulated.
            Log.Error("GUIFont: Failed to load font {0} from cache. Trying to recreate it...", _fontName);
            MediaPortal.Util.Utils.FileDelete(strCache);
            MediaPortal.Util.Utils.FileDelete(strCache + ".bxml");
            needsCreation = true;
          }
        }

        if (needsCreation)
        {
          Log.Debug("TextureLoader.CreateFile {0}", strCache);
          // Make sure directory exists
          try
          {
            Directory.CreateDirectory(String.Format(@"{0}\fonts\", GUIGraphicsContext.SkinCacheFolder));

            // Create bitmap with the fonts
            using (Bitmap bmp = CreateFontBitmap())
            {
              // Save bitmap to stream
              using (MemoryStream imageStream = new MemoryStream())
              {
                bmp.Save(imageStream, ImageFormat.Bmp);

                // Reset and load from steam
                imageStream.Position = 0;
                Format format = Format.Dxt3;
                if (GUIGraphicsContext.GetTexturePoolType() == Pool.Default)
                {
                  format = Format.Unknown;
                }
                ImageInformation info = new ImageInformation();
                _textureFont = TextureLoader.FromStream(GUIGraphicsContext.DX9Device,
                                                        imageStream, (int)imageStream.Length,
                                                        0, 0, //width/height
                                                        1, //miplevels
                                                        0,
                                                        format,
                                                        GUIGraphicsContext.GetTexturePoolType(),
                                                        Filter.None,
                                                        Filter.None,
                                                        0,
                                                        ref info);

                // Finally save texture and texture coords to disk
                TextureLoader.Save(strCache, ImageFileFormat.Dds, _textureFont);
                s = File.Open(strCache + ".bxml", FileMode.CreateNew, FileAccess.ReadWrite);
                b.Serialize(s, (object)_textureCoords);
                s.Close();
                Log.Debug("Saving font:{0} height:{1} texture:{2}x{3} chars:[{4}-{5}] miplevels:{6}", _fontName,
                          _fontHeight,
                          _textureWidth, _textureHeight, _StartCharacter, _EndCharacter, _textureFont.LevelCount);
              }
            }
          }
          catch (Exception) {}
        }

        try
        {
          _textureFont.Disposing -= new EventHandler(_textureFont_Disposing);
          _textureFont.Disposing += new EventHandler(_textureFont_Disposing);
          SetFontEgine();
          _d3dxFont = new Microsoft.DirectX.Direct3D.Font(GUIGraphicsContext.DX9Device, _systemFont);
        }
        catch (Exception)
        {
          Log.Error("GUIFont: Failed to D3D...");
        }
      }
      finally
      {
        if (s != null)
          s.SafeDispose();
      }
    }
Ejemplo n.º 15
0
        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);
        }
Ejemplo n.º 16
0
    /// <summary>
    /// Cleanup any resources being used.
    /// </summary>
    public void Dispose(object sender, EventArgs e)
    {
      lock (GUIFontManager.Renderlock)
      {
        if (_systemFont != null)
        {
          _systemFont.SafeDispose();
        }

        if (_d3dxFont != null)
        {
          _d3dxFont.SafeDispose();
        }
        _d3dxFont = null;

        if (_textureFont != null)
        {
          _textureFont.Disposing -= new EventHandler(_textureFont_Disposing);
          _textureFont.SafeDispose();
        }
        _textureFont = null;
        _systemFont = null;
        _textureCoords = null;
        if (_fontAdded)
        {
          //Log.Debug("GUIFont:Dispose({0}) fontengine: Remove font:{1}", _fontName, ID.ToString());
          if (ID >= 0)
          {
            DXNative.FontEngineRemoveFont(ID);
          }
        }
        _fontAdded = false;
      }
    }
Ejemplo n.º 17
0
		/// <summary>
		/// Overridden.  See <see cref="P3Node.ValidateVertices">P3Node.ValidateVertices</see>.
		/// </summary>
		public override void ValidateVertices(Device device) {
			if (fontChanged) {
				D3Dfont = new Direct3D.Font(device, Font);
			}

			if (textSprite == null) {
				textSprite = new Sprite(device);
			}

			D3Dfont.PreloadText(text);

			base.ValidateVertices (device);
		}
Ejemplo n.º 18
0
		/// <summary>
		/// Dispose the Direct3D font.
		/// </summary>
		protected virtual void DisposeFont() {
			if (D3Dfont != null) {
				D3Dfont.Dispose();
				D3Dfont = null;
			}
		}
Ejemplo n.º 19
0
        public bool InitMdx()
        {
            Dev = new Device(MdxRender.DeviceInfo.default_adapter, DeviceType.Hardware,
                             MdxRender.DeviceInfo.renderWin, MdxRender.DeviceInfo.flags, MdxRender.DeviceInfo.pp);

            MdxRender.SM    = new ShaderManager();
            MdxRender.MM    = new ModelManager();
            MdxRender.Input = new InputManager();
            SelectTool.InitializeHandleModel();
            SelectionBox.Initialize();
            ProjectManager.MapSpawns.InitDebug();
            ShaderBase.InitializeDebug();
            mapViewButton = new RenderButton();
            //mapViewButton.Width = MdxRender.DeviceInfo.renderWin.Width;
            //mapViewButton.Height = MdxRender.DeviceInfo.renderWin.Height;
            mapViewButton.Initialize(35, 35, 15, 40);

            //set up lights that don't work
            SetupLights();

            whiteMaterial         = new Material();
            whiteMaterial.Ambient = Color.White;
            whiteMaterial.Diffuse = Color.White;
            //whiteMaterial.Emissive = Color.White;

            //Set up texture filtering to get rid of blocky uglies
            MdxRender.Dev.SamplerState[0].MagFilter = TextureFilter.Linear;
            MdxRender.Dev.SamplerState[0].MinFilter = TextureFilter.Linear;
            MdxRender.Dev.SamplerState[0].MipFilter = TextureFilter.Linear;
            MdxRender.Dev.SamplerState[1].MagFilter = TextureFilter.Linear;
            MdxRender.Dev.SamplerState[1].MinFilter = TextureFilter.Linear;
            MdxRender.Dev.SamplerState[1].MipFilter = TextureFilter.Linear;
            MdxRender.Dev.SamplerState[2].MagFilter = TextureFilter.Linear;
            MdxRender.Dev.SamplerState[2].MinFilter = TextureFilter.Linear;
            MdxRender.Dev.SamplerState[2].MipFilter = TextureFilter.Linear;
            MdxRender.Dev.SamplerState[3].MagFilter = TextureFilter.Linear;
            MdxRender.Dev.SamplerState[3].MinFilter = TextureFilter.Linear;
            MdxRender.Dev.SamplerState[3].MipFilter = TextureFilter.Linear;
            MdxRender.Dev.SamplerState[4].MagFilter = TextureFilter.Linear;
            MdxRender.Dev.SamplerState[4].MinFilter = TextureFilter.Linear;
            MdxRender.Dev.SamplerState[4].MipFilter = TextureFilter.Linear;

            MdxRender.Dev.RenderState.AlphaFunction = Compare.GreaterEqual;
            MdxRender.Dev.SetRenderState(RenderStates.ReferenceAlpha, 0x80);
            //UpdateGammaCorrection();

            //disable vsync, might get some tearing
            MdxRender.Dev.PresentationParameters.PresentationInterval = PresentInterval.Immediate;

            MdxRender.lightmapDebugger          = new GrenLightmapDebug();
            MdxRender.Dev.RenderState.PointSize = 10.0f;

            MdxRender.Dev.RenderState.CullMode      = Cull.CounterClockwise;
            MdxRender.Dev.RenderState.ZBufferEnable = true;
            MdxRender.Dev.DeviceResizing           += new System.ComponentModel.CancelEventHandler(device_DeviceResizing);
            MdxRender.Dev.DeviceReset += new EventHandler(device_DeviceReset);

            //Device.IsUsingEventHandlers = false;

            // Initialize the font
            m_fontFPS  = new D3D.Font(Dev, new Font("Arial", 12, FontStyle.Bold));
            consoleFPS = new D3D.Font(Dev, new Font("Arial", 10, FontStyle.Bold));

            // Initialize the camera placement and orientation
            Camera = new Camera();
            Camera.SetLookAt(new Vector3(-18, 0, 0), new Vector3());

            PreviewManager.Debug_LoadTestMesh();
            m_ready = true;

            return(false);
        }
Ejemplo n.º 20
0
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         if (directxFont != null)
         {
             directxFont.Dispose();
             directxFont = null;
         }
         if (device != null)
         {
             device.Dispose();
             device = null;
         }
         base.Dispose(true);
     }
 }
Ejemplo n.º 21
0
        private bool initializeGraphics()
        {
            try
            {
                lock(this)
                {
                    // Initialize the DirectX drawing
                    initialized = true;
                    lastInitializeTime = DateTime.Now;
                    PresentParameters presentParams = new PresentParameters();
                    presentParams.Windowed = true;
                    presentParams.SwapEffect = SwapEffect.Discard;
                    presentParams.DeviceWindowHandle = this.Handle;

                    device = new Device(0,
                                        DeviceType.Hardware,
                                        this,
                                        CreateFlags.SoftwareVertexProcessing,
                                        presentParams);

                    // Set initial device parameters
                    device.RenderState.FillMode = FillMode.WireFrame;
                    device.RenderState.CullMode = Cull.None;

                    // Initialize the font
                    Font systemFont = new System.Drawing.Font("Arial", 8f, FontStyle.Regular);
                    directxFont = new Microsoft.DirectX.Direct3D.Font(device, systemFont);
                }

                return true;
            }
            catch (Exception ex)
            {
                initialized = false;
                //oConsole.printException(ex);
                return false;
            }
        }