public MCBaseSprite CreateSpriteFromTextureName(string name, float anchorX = float.MinValue, float anchorY = float.MinValue) { string spriteName; //--------------------------------------------- //! テクスチャースの読み込み //--------------------------------------------- MCBaseTexture baseTx; if (!App.ImageMgr.GetTexture(name, out baseTx)) { baseTx = MCTexture.CreateTextureFromFile( App, name, name ); if (baseTx == null) { throw new Exception("スプライト作成で、テキストテクスチャ[" + name + "]からテクスチャ作成失敗しました。"); } } int w = baseTx.GetDesc().D2.Width; int h = baseTx.GetDesc().D2.Height; spriteName = CreateName(name, 0, 0, w, h, anchorX, anchorY); MCTexture tx = (MCTexture)baseTx; //--------------------------------------------- //! スプライト登録 //--------------------------------------------- MCBaseSprite spriteData; if (!App.SpriteMgr.GetSpriteData(spriteName, out spriteData)) { MCSprite sp; MCRect rc = new MCRect(); bool ret; rc.SetXYWH(0, 0, w, h); if (anchorX == float.MinValue && anchorY == float.MinValue) { sp = MCSprite.CreateSprite(App, spriteName, baseTx, rc, MC_SPRITE_ANCHOR.CENTER); } else { sp = MCSprite.CreateSprite(App, spriteName, baseTx, rc, MC_SPRITE_ANCHOR.CUSTOM, anchorX, anchorY); } if (sp == null) { throw new Exception("スプライト作成失敗[" + spriteName + "]既に登録されている名前か、それ以外です。"); } spriteData = sp; } m_spriteMgr.Add(spriteData, true); return(spriteData); }
/// <summary> /// 解放処理 /// </summary> protected override void OnDestroyDevice() { m_imageTx = null; m_backSprite = null; m_backDrawSprite = null; m_imageSprite = null; m_imageDrawSprite = null; m_defCamera = null; m_drawSprites.RegisterSpriteClear(); }
public MCBaseSprite CreatePrintScreenSprite(int x, int y, int w, int h, float anchorX = float.MinValue, float anchorY = float.MinValue) { //--------------------------------------------- //! テクスチャースの読み込み //--------------------------------------------- MCBaseTexture txISP; string str; if (!App.ImageMgr.GetTexture("PrintScreen", out txISP)) { str = "PrintScreenプライト取得に失敗しました。"; throw new Exception(str); } string spriteName = CreateName("PrintScreen", x, y, w, h, anchorX, anchorY); MCTexture txSP = (MCTexture)txISP; //--------------------------------------------- //! スプライト登録 //--------------------------------------------- MCBaseSprite spriteData; if (!App.SpriteMgr.GetSpriteData(spriteName, out spriteData)) { MCRect rc = new MCRect(); MCSprite sp; rc.SetXYWH(x, y, w, h); if (anchorX == float.MinValue && anchorY == float.MinValue) { sp = MCSprite.CreateSprite(App, spriteName, txISP, rc, MC_SPRITE_ANCHOR.CENTER); } else { sp = MCSprite.CreateSprite(App, spriteName, txISP, rc, MC_SPRITE_ANCHOR.CUSTOM, anchorX, anchorY); } if (sp == null) { throw new Exception("スプライト作成失敗[" + spriteName + "]既に登録されている名前か、それ以外です。"); } spriteData = sp; } else { throw new Exception("PrintScreenスプライト[" + spriteName + "]は既に存在します。"); } m_spriteMgr.Add(spriteData, true); return(spriteData); }
/// <summary> /// デバイスの作成 /// </summary> protected override void OnCrateDevice() { m_drawSprites = new SimpleDrawSpriteRegister(App); // 背景スプライトの作成 m_backSprite = (MCSprite)m_drawSprites.CreateSpriteFromTextureName("UtilSharpDX.Resources.256x256_bg.bmp", 0, 0); m_backDrawSprite = m_drawSprites.CreateDrawSprite(m_backSprite); m_backDrawSprite.Technique = (int)EffectID.Default; m_backDrawSprite.Effect = (int)DCRL.DEFAULT; m_backSprite.spl.EndU *= 128; m_backSprite.spl.EndV *= 128; m_backSprite.Width *= 128; m_backSprite.Height *= 128; m_defCamera = (MCTextureCamera)App.CameraMgr.Get4VCameraNo(0); }
/// <summary> /// スワップチェーンが変更された時に呼び出される /// </summary> /// <param name="device"></param> /// <param name="swapChain"></param> /// <param name="desc">変更後のスワップチェーン情報</param> public override void OnSwapChainResized(SharpDX.Direct3D11.Device device, SwapChain swapChain, SwapChainDescription desc) { if (!m_isCreated) { return; } int mx = (int)(System.Math.Max(desc.ModeDescription.Width, desc.ModeDescription.Height)); int r = 2; while ((r *= 2) < mx) { ; } if (r != m_mainTxLenght) { m_mainTxLenght = r; //===================================== // テクスチャー作成 if (m_hMainRT == null) { App.ImageMgr.GetTexture("2D_main_screen", out m_hMainRT); } if (m_hTx == null) { m_hTx = GetCreateRenderTargetTexture2D("2D_Technique", m_mainTxLenght, m_mainTxLenght); } else { m_hTx.ReSize2D(m_mainTxLenght, m_mainTxLenght); } if (m_hPrintSTx == null) { App.ImageMgr.GetTexture("PrintScreen", out m_hPrintSTx); } //===================================== // 通常スプライト作成 if (m_drawSprite == null) { MCRect rc = new MCRect(); rc.SetXYWH(0, 0, m_mainTxLenght, m_mainTxLenght); m_sprite = (MCSprite)m_spriteRegister.CreateSpriteFromTextureName("2D_Technique", rc.X, rc.Y, rc.Width, rc.Heith); m_drawSprite = m_spriteRegister.CreateDrawSprite(m_sprite); //===================================== // マップチップ用のスプライト作成 m_drawSprite.D2RenderType = (int)SPRITE_TYPE.DEFAULT; m_drawSprite.Position = new MCVector3( (float)System.Math.Ceiling(m_mainTxLenght * 0.5f), (float)System.Math.Ceiling(m_mainTxLenght * 0.5f), 0 ); } else { MCRect rc = new MCRect(); rc.SetXYWH(0, 0, m_mainTxLenght, m_mainTxLenght); m_sprite.ResetRect(rc); m_drawSprite.Position = new MCVector3( (float)System.Math.Ceiling(m_mainTxLenght * 0.5f), (float)System.Math.Ceiling(m_mainTxLenght * 0.5f), 0 ); } //===================================== // カメラの作成 if (m_isConstCoordinate) { if (m_hTxCamera == null) { CreateViewTextureCamera("FixedCameraSpriteD2Screen"); } } else { if (m_hTxCamera == null) { CreateViewTextureCamera("MCTexture"); } } if (m_hTxCamera != null) { MCTextureCamera hTmp = (MCTextureCamera)m_hTxCamera; hTmp.SetTextureSize(m_mainTxLenght, m_mainTxLenght); } // ビューポートの設定 m_aVP = new RawViewportF[] { new RawViewportF() { X = 0, Y = 0, Width = m_mainTxLenght, Height = m_mainTxLenght, MinDepth = 0, MaxDepth = 1.0f, } }; } }
public void Init(Application app) { sprite = null; draw = null; }
public SpriteASCII(Application app, MCSprite s, MCDrawSquareAmountSprite d) { App = app; sprite = s; draw = d; }
/// <summary> /// スワップチェーンが変更された時に呼び出される /// </summary> /// <param name="device"></param> /// <param name="swapChain"></param> /// <param name="desc">変更後のスワップチェーン情報</param> public override void OnSwapChainResized(SharpDX.Direct3D11.Device device, SwapChain swapChain, SwapChainDescription desc) { if (!m_isCreated) { return; } int mx = (int)(System.Math.Max(desc.ModeDescription.Width, desc.ModeDescription.Height)); int r = 2; while ((r *= 2) < mx) { ; } if (r != m_mainTxLenght) { m_mainTxLenght = r; //===================================== // テクスチャー作成 if (m_mainScreenTx == null) { m_mainScreenTx = GetCreateRenderTargetTexture2D("2D_main_screen", m_mainTxLenght, m_mainTxLenght); } else { m_mainScreenTx.ReSize2D(m_mainTxLenght, m_mainTxLenght); } //--------------------------------------- // メインスクリーン用常駐描画スプライト作成 //--------------------------------------- if (m_backSprite == null) { m_backSprite = (MCSprite)m_spriteRegister.CreateSpriteFromTextureName("2D_main_screen", 0, 0, m_mainTxLenght, m_mainTxLenght, 0, 0); } else { MCRect rc = new MCRect(); rc.SetXYWH(0, 0, m_mainTxLenght, m_mainTxLenght); m_backSprite.ResetRect(rc); } RawViewportF[] v; GetCurrentViewPort(out v); if (m_backDrawSprite == null) { m_backDrawSprite = m_spriteRegister.CreateDrawSprite(m_backSprite); m_backDrawSprite.Effect = (int)DCRL.DEF_SPRITE; m_backDrawSprite.Position = new MCVector3( (float)System.Math.Ceiling((m_mainTxLenght - v[0].Width) * -0.5f), (float)System.Math.Ceiling((m_mainTxLenght - v[0].Height) * 0.5f), 0 ); } else { m_backDrawSprite.Position = new MCVector3( (float)System.Math.Ceiling((m_mainTxLenght - v[0].Width) * -0.5f), (float)System.Math.Ceiling((m_mainTxLenght - v[0].Height) * 0.5f), 0 ); } //===================================== // カメラの作成 if (m_hTxCamera == null) { CreateTextureCamera("MCTexture", m_mainTxLenght, m_mainTxLenght); } else { MCTextureCamera hTmp = (MCTextureCamera)m_hTxCamera; hTmp.SetTextureSize(m_mainTxLenght, m_mainTxLenght); } } }
/// <summary> /// スワップチェーンが変更された時に呼び出される /// </summary> /// <param name="device"></param> /// <param name="swapChain"></param> /// <param name="desc">変更後のスワップチェーン情報</param> public override void OnSwapChainResized(SharpDX.Direct3D11.Device device, SwapChain swapChain, SwapChainDescription desc) { if (!m_isCreated) { return; } int mx = (int)(System.Math.Max(desc.ModeDescription.Width, desc.ModeDescription.Height)); int r = 2; while ((r *= 2) < mx) { ; } if (r != m_mainTxLenght) { m_mainTxLenght = r; //===================================== // テクスチャー作成 if (m_hTx == null) { MCPrintScreenTexture.Create(App, "2d_mapchip", m_mainTxLenght, m_mainTxLenght, out m_hTx); } else { m_hTx.ReSize2D(m_mainTxLenght, m_mainTxLenght); } RawViewportF[] v; GetCurrentViewPort(out v); if (m_drawSprite == null) { m_sprite = (MCSprite)m_spriteRegister.CreateSpriteFromTextureName("mapchip", 0, 0, m_mainTxLenght, m_mainTxLenght, 0, 0); m_drawSprite = m_spriteRegister.CreateDrawSprite(m_sprite); m_drawSprite.Effect = (int)DCRL.DEF_SPRITE; m_drawSprite.Position = new MCVector3( (float)System.Math.Ceiling((m_mainTxLenght - v[0].Width) * -0.5f), (float)System.Math.Ceiling((m_mainTxLenght - v[0].Height) * 0.5f), 0 ); } else { MCRect rc = new MCRect(); rc.SetXYWH(0, 0, m_mainTxLenght, m_mainTxLenght); m_sprite.ResetRect(rc); m_drawSprite.Position = new MCVector3( (float)System.Math.Ceiling((m_mainTxLenght - v[0].Width) * -0.5f), (float)System.Math.Ceiling((m_mainTxLenght - v[0].Height) * 0.5f), 0 ); } //===================================== // カメラの作成 if (m_hTxCamera == null) { CreateViewTextureCamera("MpachipCamera"); } else { MCTextureCamera hTmp = (MCTextureCamera)m_hTxCamera; hTmp.SetTextureSize(m_mainTxLenght, m_mainTxLenght); } } // ビューポートの設定 GetCurrentViewPort(out m_aVP); }