public LTexture GetTexture() { if (_texture == null || _texture.isClose || isUpdate) { SetAutoDispose(false); LTexture tmp = _texture; _texture = new LTexture(GLLoader.GetTextureData(this), m_format); if (tmp != null) { tmp.Dispose(); tmp = null; } isUpdate = false; } return(_texture); }
public static SpriteFont Read(string resName) { try { List <RectBox> xGlyphs = new List <RectBox>(), xCropping = new List <RectBox>(); List <Char> xChars = new List <Char>(); int xSpacingV; float xSpacingH; List <float[]> xKerning = new List <float[]>(); ArrayByte arrays = new ArrayByte(Resources.OpenResource(resName), ArrayByte.BIG_ENDIAN); int size = arrays.ReadInt(); LImage image = LImage.CreateImage(arrays.ReadByteArray(size)); int count = arrays.ReadInt(); while (count-- > 0) { xGlyphs.Add(new RectBox(arrays.ReadInt(), arrays.ReadInt(), arrays.ReadInt(), arrays.ReadInt())); xCropping.Add(new RectBox(arrays.ReadInt(), arrays.ReadInt(), arrays.ReadInt(), arrays.ReadInt())); xChars.Add((char)arrays.ReadInt()); } xSpacingV = arrays.ReadInt(); xSpacingH = arrays.ReadFloat(); count = arrays.ReadInt(); while (count-- > 0) { xKerning.Add(new float[] { arrays.ReadFloat(), arrays.ReadFloat(), arrays.ReadFloat() }); } arrays.Dispose(); return(new SpriteFont(new LTexture(GLLoader.GetTextureData(image), Loon.Core.Graphics.Opengl.LTexture.Format.LINEAR), xGlyphs, xCropping, xChars, xSpacingV, xSpacingH, xKerning, 'A')); } catch (Exception e) { Loon.Utils.Debugging.Log.Exception(e); } return(null); }
public static LTexture LoadTex(string name) { VaildLoon(); LTexture texture = (LTexture)CollectionUtils.Get(texCaches, name); if (texture == null || texture.isClose) { try { LTextureData data = GLLoader.GetTextureData(ResourceManager.GetStream(name)); data.fileName = name; texture = new LTexture(data); texture.isExt = true; } catch (Exception ex) { Loon.Utils.Debug.Log.Exception(ex); } texCaches.Add(name, texture); } return(texture); }
public void DrawWidth(GLEx g, int x, int y) { try { if (drawTexWidth == null) { LImage img = LImage.CreateImage(width, height, true); LGraphics gl = img.GetLGraphics(); for (int i = 0; i < width; i++) { gl.SetColor( (start.GetRed() * (width - i)) / width + (end.GetRed() * i) / width, (start.GetGreen() * (width - i)) / width + (end.GetGreen() * i) / width, (start.GetBlue() * (width - i)) / width + (end.GetBlue() * i) / width, alpha); gl.DrawLine(i, 0, i, height); } drawTexWidth = new LTexture(GLLoader.GetTextureData(img), Loon.Core.Graphics.Opengl.LTexture.Format.SPEED); gl.Dispose(); gl = null; } g.DrawTexture(drawTexWidth, x, y); } catch (Exception) { for (int i = 0; i < width; i++) { g.SetColorValue( (start.GetRed() * (width - i)) / width + (end.GetRed() * i) / width, (start.GetGreen() * (width - i)) / width + (end.GetGreen() * i) / width, (start.GetBlue() * (width - i)) / width + (end.GetBlue() * i) / width, alpha); g.DrawLine(i + x, y, i + x, y + height); } } }
public void DrawHeight(GLEx g, int x, int y) { try { if (drawTexHeight == null) { LImage img = LImage.CreateImage(width, height, true); LGraphics gl = img.GetLGraphics(); for (int i = 0; i < height; i++) { gl.SetColor( (start.GetRed() * (height - i)) / height + (end.GetRed() * i) / height, (start.GetGreen() * (height - i)) / height + (end.GetGreen() * i) / height, (start.GetBlue() * (height - i)) / height + (end.GetBlue() * i) / height, alpha); gl.DrawLine(0, i, width, i); } drawTexHeight = new LTexture(GLLoader.GetTextureData(img), Loon.Core.Graphics.Opengl.LTexture.Format.SPEED); gl.Dispose(); gl = null; } g.DrawTexture(drawTexHeight, x, y); } catch (Exception) { for (int i = 0; i < height; i++) { g.SetColorValue( (start.GetRed() * (height - i)) / height + (end.GetRed() * i) / height, (start.GetGreen() * (height - i)) / height + (end.GetGreen() * i) / height, (start.GetBlue() * (height - i)) / height + (end.GetBlue() * i) / height, alpha); g.DrawLine(x, i + y, x + width, i + y); } } }
private void SetScreen(Screen screen, bool put) { if (currentControl != null && currentControl.IsOnLoadComplete()) { return; } lock (this) { if (screen == null) { this.isInstance = false; throw new RuntimeException( "Cannot create a [Screen] instance !"); } GLLoader.Destory(); if (!LSystem.isLogo) { if (currentControl != null) { SetTransition(screen.OnTransition()); } else { LTransition transition = screen.OnTransition(); if (transition == null) { switch (MathUtils.Random(0, 3)) { case 0: transition = LTransition.NewFadeIn(); break; case 1: transition = LTransition.NewArc(); break; case 2: transition = LTransition .NewSplitRandom(LColor.black); break; case 3: transition = LTransition .NewCrossRandom(LColor.black); break; } } SetTransition(transition); } } screen.SetOnLoadState(false); if (currentControl == null) { currentControl = screen; } else { lock (currentControl) { currentControl.Destroy(); currentControl = screen; } } this.isInstance = true; if (screen is EmulatorListener) { SetEmulatorListener((EmulatorListener)screen); } else { SetEmulatorListener(null); } screen.OnCreate(LSystem.screenRect.width, LSystem.screenRect.height); LSystem.CallScreenRunnable(new _LoadingScreen(this, screen)); if (put) { screens.AddLast(screen); } loading_Control = null; } }
private void InitDesktop() { if (desktop != null && sprites != null) { return; } this.desktop = new Desktop(this, GetWidth(), GetHeight()); this.sprites = new Sprites(GetWidth(), GetHeight()); if (dialog == null) { LImage tmp = LImage.CreateImage(GetWidth() - 20, GetHeight() / 2 - 20, true); LGraphics g = tmp.GetLGraphics(); g.SetColor(0, 0, 0, 125); g.FillRect(0, 0, tmp.GetWidth(), tmp.GetHeight()); g.Dispose(); g = null; dialog = new LTexture(GLLoader.GetTextureData(tmp)); if (tmp != null) { tmp.Dispose(); tmp = null; } } this.message = new LMessage(dialog, 0, 0); this.message.SetFontColor(LColor.white); int size = message.GetWidth() / (message.GetMessageFont().GetSize()); if (LSystem.scaleWidth != 1 || LSystem.scaleHeight != 1) { if (size % 2 != 0) { size = size + 2; } else { size = size + 3; } } else { if (size % 2 != 0) { size = size - 3; } else { size = size - 4; } } this.message.SetMessageLength(size); this.message.SetLocation((GetWidth() - message.GetWidth()) / 2, GetHeight() - message.GetHeight() - 10); this.message.SetVisible(false); this.select = new LSelect(dialog, 0, 0); this.select.SetLocation(message.X(), message.Y()); this.scrCG = new AVGCG(); this.desktop.Add(message); this.desktop.Add(select); this.select.SetVisible(false); }