public void Update() { if (_texture == null) { _texture = new Texture2D(1, 1, TextureFormat.Alpha8, false); _texture.hideFlags = HideFlags.HideInInspector | HideFlags.DontSave; _texture.filterMode = FilterMode.Point; _texture.wrapMode = TextureWrapMode.Clamp; //Debug.Log("Texture2D creation: " + _texture.GetNativeTextureID()); } int textureID = _texture.GetNativeTextureID(); SysFont.QueueTexture(_text, FontName, _fontSize, _isBold, _isItalic, _alignment, _isMultiLine, _maxWidthPixels, _maxHeightPixels, textureID); _textWidthPixels = SysFont.GetTextWidth(textureID); _textHeightPixels = SysFont.GetTextHeight(textureID); _widthPixels = SysFont.GetTextureWidth(textureID); _heightPixels = SysFont.GetTextureHeight(textureID); SysFont.UpdateQueuedTexture(textureID); _lastText = _text; _lastFontName = FontName; _lastFontSize = _fontSize; _lastIsBold = _isBold; _lastIsItalic = _isItalic; _lastAlignment = _alignment; _lastIsMultiLine = _isMultiLine; _lastMaxWidthPixels = _maxWidthPixels; _lastMaxHeightPixels = _maxHeightPixels; }
protected void OnDestroy() { material = null; SysFont.SafeDestroy(_createdMaterial); if (_texture != null) { _texture.Destroy(); _texture = null; } }
public void Destroy() { if (_texture != null) { //Debug.Log("Texture2D destruction: " + _texture.GetNativeTextureID()); if (_texture != null) { SysFont.DequeueTexture(_texture.GetNativeTextureID()); SysFont.SafeDestroy(_texture); _texture = null; } } }
public Memory(int width, int height) { DisplayMode = DisplayMode.Text; TextBuffer = new TextBuffer(width, height); SysFont = new SysFont(); DisplayBuffer = new DisplayBuffer(width, height); Pallete = new Pallete(); InputBuffer = new InputBuffer(); SpriteBuffer = new SpriteBuffer(); CodeBuffer = string.Empty; }
public void Destroy() { if (_texture != null) { if (_textureId != 0) { //Debug.Log("Texture2D destruction: " + _textureId); SysFont.DequeueTexture(_textureId); _textureId = 0; } SysFont.SafeDestroy(_texture); _texture = null; } }
public bool Update() { if (_texture == null) { _texture = new Texture2D(1, 1, TextureFormat.Alpha8, false); _texture.hideFlags = HideFlags.HideInInspector | HideFlags.DontSave; _texture.filterMode = FilterMode.Point; _texture.wrapMode = TextureWrapMode.Clamp; _texture.Apply(false, true); _textureId = 0; } if (_textureId == 0) { _textureId = _texture.GetNativeTextureID(); if (_textureId == 0) { // texture not ready, it may happen on multi-threaded rendering return(false); } //Debug.Log("Texture2D creation: " + _textureId); } SysFont.QueueTexture(_text, FontName, _fontSize, _isBold, _isItalic, _alignment, _isMultiLine, _maxWidthPixels, _maxHeightPixels, _textureId); _textWidthPixels = SysFont.GetTextWidth(_textureId); _textHeightPixels = SysFont.GetTextHeight(_textureId); _widthPixels = SysFont.GetTextureWidth(_textureId); _heightPixels = SysFont.GetTextureHeight(_textureId); SysFont.UpdateQueuedTexture(_textureId); _lastText = _text; _lastFontName = FontName; _lastFontSize = _fontSize; _lastIsBold = _isBold; _lastIsItalic = _isItalic; _lastAlignment = _alignment; _lastIsMultiLine = _isMultiLine; _lastMaxWidthPixels = _maxWidthPixels; _lastMaxHeightPixels = _maxHeightPixels; _lastScaleSize = _scaleSize; return(true); }
} // end of RefreshRT() /// <summary> /// Renders the buttons label onto the button textures. /// /// </summary> /// <param name="buttonIndex"></param> /// <returns>True if label fits, false if it's too big.</returns> static bool RenderLabelButton(int buttonIndex) { bool fits = true; string line1 = buttons[buttonIndex].Label; string line2 = null; UI2D.Shared.GetFont Font = UI2D.Shared.GetGameFont24; int margin = 8; int width = 128 - 2 * margin; Vector2 size1 = Font().MeasureString(line1); Vector2 size2 = Vector2.Zero; // Need to split into 2 lines? if (size1.X > width * splitThreshold) { SplitString(Font, buttons[buttonIndex].Label, out line1, out line2); if (line2 != null) { size1 = Font().MeasureString(line1); size2 = Font().MeasureString(line2); } } // Calc position. This assumes a single line. Vector2 pos = new Vector2(margin + buttonIndex * GUIButton.DefaultSize.X, (int)((GUIButton.DefaultSize.Y - size1.Y) / 2.0f)); // Adjust if we've got 2 lines. if (line2 != null) { pos.Y -= (int)(Font().LineSpacing / 2.0f); } SysFont.StartBatch(null); { fits &= RenderLine(Font, pos, line1, size1, width); if (line2 != null) { pos.Y += Font().LineSpacing; fits &= RenderLine(Font, pos, line2, size2, width); } } SysFont.EndBatch(); return(fits); } // end of LabelButton()
public Vector3 GetAdvance(object parameters, object font, char c) { //return Vector3.zero; FontSelector fs = font as FontSelector; Parameters cp = parameters as Parameters; if (cp.fixedWidth) { return(new Vector3(1, 0, 0)); } else { Texture2D _texture = new Texture2D(1, 1, TextureFormat.Alpha8, false); _texture.hideFlags = HideFlags.HideInInspector | HideFlags.DontSave; _texture.filterMode = FilterMode.Point; _texture.wrapMode = TextureWrapMode.Clamp; int textureID = _texture.GetNativeTextureID(); SysFont.QueueTexture("" + c, #if UNITY_ANDROID fs.AndroidFontName #else #if UNITY_IPHONE fs.AppleFontName #else ((string)font) #endif #endif , 12, false, //_isBold, false, //_isItalic, SysFont.Alignment.Left, //_alignment, false, 2048, 2048, textureID ); int _textWidthPixels = SysFont.GetTextWidth(textureID); // int _textHeightPixels = SysFont.GetTextHeight(textureID); GameObject.Destroy(_texture); return(new Vector3(_textWidthPixels * cp.scale, 0, 0)); } }
public static void Unload() { Subtitle.Dispose(); Title.Dispose(); Splash.Dispose(); MapSheet.Dispose(); MiniHP.Dispose(); HPMenu.Dispose(); Buttons.Dispose(); Shadows.Dispose(); Darkness.Dispose(); BattleFactors.Dispose(); Strip.Dispose(); Cursor.Dispose(); Arrows.Dispose(); PicBorder.Dispose(); MenuBorder.Dispose(); MenuBG.Dispose(); tileCache.Clear(); objectCache.Clear(); bgCache.Clear(); itemCache.Clear(); iconCache.Clear(); vfxCache.Clear(); portraitCache.Clear(); spriteCache.Clear(); DivTex.Dispose(); EXPFont.Dispose(); HealFont.Dispose(); DamageFont.Dispose(); DungeonFont.Dispose(); TextFont.Dispose(); SysFont.Dispose(); Pixel.Dispose(); defaultTex.Dispose(); Loaded = false; //Notify script engine LuaEngine.Instance.OnGraphicsUnload(); }
protected void OnDestroy() { if (_texture != null) { _texture.Destroy(); _texture = null; } SysFont.SafeDestroy(_mesh); SysFont.SafeDestroy(_createdMaterial); _createdMaterial = null; _material = null; _vertices = null; _uv = null; _triangles = null; _mesh = null; _filter = null; _renderer = null; }
/// <summary> /// This is called when the game should draw itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Draw(GameTime gameTime) { BubbleTimer.DrawTime = gameTime.ElapsedGameTime.Milliseconds; GraphicsDevice.Clear(Color.Black); spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, SamplerState.LinearWrap, null, null); //DepthStencilState.Default //spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearWrap, DepthStencilState.Default, null); FlowManager.Draw(gameTime); if (BubbleTimer.ShowTime) { TQMG.Color(255, 255, 255); SysFont.DrawText($"Update: {BubbleTimer.UpdateTime}ms/{1000 / BubbleTimer.UpdateTime}fps; Draw: {BubbleTimer.DrawTime}ms/{1000 / BubbleTimer.DrawTime}fps", 5, 5); } spriteBatch.End(); base.Draw(gameTime); }
} // end of LabelButton() /// <summary> /// Returns true if line fits with reasonable compression. False if compressed too much. /// </summary> /// <param name="Font"></param> /// <param name="pos"></param> /// <param name="line"></param> /// <param name="size"></param> /// <param name="width"></param> /// <returns></returns> static bool RenderLine(UI2D.Shared.GetFont Font, Vector2 pos, string line, Vector2 size, int width) { Vector2 scale = Vector2.One; if (size.X > width) { // Need to compress. scale.X = width / size.X; } else { // No compression, just center. pos.X += (int)((width - size.X) / 2.0f); } RectangleF rect = new RectangleF(pos.X, pos.Y, width, 96); SysFont.DrawString(line, pos, rect, Font().systemFont, Color.Black, scale, outlineColor: Color.White, outlineWidth: 1.5f); pos.Y += GUIButton.DefaultSize.Y; rect.Y += GUIButton.DefaultSize.Y; SysFont.DrawString(line, pos, rect, Font().systemFont, Color.Black, scale, outlineColor: Color.White, outlineWidth: 1.5f); return(scale.X > 0.5f); } // end of RenderLine()
public TTFTextTexturePortion ComputeGlyphBitmap(object parameters, object font, char c) { SysFontTexture tex = new SysFontTexture(); FontSelector fs = (FontSelector)GetFontSelectorFromFontName((string)font); tex.AndroidFontName = fs.AndroidFontName; tex.AppleFontName = fs.AppleFontName; tex.Update(); Texture2D _texture = new Texture2D(1, 1, TextureFormat.Alpha8, false); //Texture2D _texture = new Texture2D(64, 64, TextureFormat.RGBA32, false); _texture.hideFlags = HideFlags.HideInInspector | HideFlags.DontSave; _texture.filterMode = FilterMode.Point; _texture.wrapMode = TextureWrapMode.Clamp; int textureID = _texture.GetNativeTextureID(); SysFont.QueueTexture("" + c, #if UNITY_ANDROID fs.AndroidFontName #else #if UNITY_IPHONE fs.AppleFontName #else ((string)font) #endif #endif , 12, false, //_isBold, false, //_isItalic, SysFont.Alignment.Left, //_alignment, false, 2048, 2048, textureID ); int _textWidthPixels = SysFont.GetTextWidth(textureID); int _textHeightPixels = SysFont.GetTextHeight(textureID); SysFont.UpdateQueuedTexture(textureID); Debug.Log("."); Parameters cp = parameters as Parameters; Material m = null; if (cp != null) { Shader shader = Shader.Find(cp.shaderName); if (shader == null) { shader = Shader.Find("Mobile/Diffuse"); } if (shader == null) { shader = Shader.Find("Diffuse"); } m = new Material(shader); m.color = new Color(cp.red, cp.green, cp.blue, cp.alpha); m.mainTexture = _texture; } else { Shader shader = Shader.Find("SysFont/Unlit Transparent"); if (shader == null) { shader = Shader.Find("Mobile/Diffuse"); } if (shader == null) { shader = Shader.Find("Diffuse"); } m = new Material(shader); m.color = Color.black; m.mainTexture = _texture; } TTFTextTexturePortion p = new TTFTextTexturePortion( m, 0, 0, 1, 1, _textWidthPixels * cp.scale, _textHeightPixels * cp.scale, 0, 0, true ); return(p); }
public Home(int rows, int cols) { _font = new SysFont(); Resize(rows, cols); }
} // end of UpdateTextColor() /// <summary> /// Render our UI to the screen, but only if now is appropriate. /// </summary> public static void Render() { // In mouse mode, don't render undo/redo icons if pickers are active. bool mouseEdit = inGame.CurrentUpdateMode == UpdateMode.MouseEdit && !InGame.inGame.touchEditUpdateObj.PickersActive; if ((inGame.CurrentUpdateMode == UpdateMode.ToolMenu || mouseEdit) && HaveAnything) { GraphicsDevice device = BokuGame.bokuGame.GraphicsDevice; // Calc position for undo/redo text. int x = 0; int y = (int)(BokuGame.ScreenSize.Y * 0.66f); int buttonSize = 40; UI2D.Shared.GetFont Font = UI2D.Shared.GetGameFont18Bold; SpriteBatch batch = UI2D.Shared.SpriteBatch; // Handle small screens. if (BokuGame.ScreenSize.Y < 720) { Font = UI2D.Shared.GetGameFont15_75; buttonSize = (int)(buttonSize * 0.8f); } if (HaveReDo) { ScreenSpaceQuad quad = ScreenSpaceQuad.GetInstance(); Texture2D texture = GamePadInput.ActiveMode == GamePadInput.InputMode.GamePad ? ButtonTextures.YButton : ButtonTextures.Redo; quad.Render(texture, Vector4.One, new Vector2(x, y), new Vector2(buttonSize), @"TexturedRegularAlpha"); redoHitBox.Set(new Vector2(x, y), new Vector2(x, y) + new Vector2(buttonSize - 12)); } else { redoHitBox.Set(Vector2.Zero, Vector2.Zero); } if (HaveUnDo) { ScreenSpaceQuad quad = ScreenSpaceQuad.GetInstance(); Texture2D texture = GamePadInput.ActiveMode == GamePadInput.InputMode.GamePad ? ButtonTextures.XButton : ButtonTextures.Undo; quad.Render(texture, Vector4.One, new Vector2(x, y + buttonSize - 12), new Vector2(buttonSize), @"TexturedRegularAlpha"); undoHitBox.Set(new Vector2(x, y + buttonSize - 12), new Vector2(x, y + buttonSize - 12) + new Vector2(buttonSize - 12)); } else { undoHitBox.Set(Vector2.Zero, Vector2.Zero); } Color darkGrey = new Color(10, 10, 10); #if NETFX_CORE batch.Begin(); if (HaveReDo) { string str = Strings.Localize("undoStack.redo") + "(" + NumReDo.ToString() + ")"; TextHelper.DrawStringWithShadow(Font, batch, x + buttonSize - 12, y - 4, str, redoTextColor, darkGrey, false); Vector2 max = redoHitBox.Max; max.X += Font().MeasureString(str).X; redoHitBox.Set(redoHitBox.Min, max); } if (HaveUnDo) { string str = Strings.Localize("undoStack.undo") + "(" + NumUnDo.ToString() + ")"; TextHelper.DrawStringWithShadow(Font, batch, x + buttonSize - 12, y + buttonSize - 16, str, undoTextColor, darkGrey, false); Vector2 max = undoHitBox.Max; max.X += Font().MeasureString(str).X; undoHitBox.Set(undoHitBox.Min, max); } batch.End(); #else SysFont.StartBatch(null); if (HaveReDo) { string str = Strings.Localize("undoStack.redo") + "(" + NumReDo.ToString() + ")"; SysFont.DrawString(str, new Vector2(x + buttonSize - 12, y - 4), new RectangleF(), Font().systemFont, redoTextColor, outlineColor: Color.Black, outlineWidth: 1.5f); Vector2 max = redoHitBox.Max; max.X += Font().MeasureString(str).X; redoHitBox.Set(redoHitBox.Min, max); } if (HaveUnDo) { string str = Strings.Localize("undoStack.undo") + "(" + NumUnDo.ToString() + ")"; SysFont.DrawString(str, new Vector2(x + buttonSize - 12, y + buttonSize - 16), new RectangleF(), Font().systemFont, undoTextColor, outlineColor: Color.Black, outlineWidth: 1.5f); Vector2 max = undoHitBox.Max; max.X += Font().MeasureString(str).X; undoHitBox.Set(undoHitBox.Min, max); } SysFont.EndBatch(); #endif } }