public virtual LImage SetTileBackground(LImage image, bool isReturn) { if (image == null) { return(null); } int layerWidth = GetWidth(); int layerHeight = GetHeight(); int tileWidth = image.GetWidth(); int tileHeight = image.GetHeight(); LImage tempImage = LImage.CreateImage(layerWidth, layerHeight, false); LGraphics g = tempImage.GetLGraphics(); for (int x = 0; x < layerWidth; x += tileWidth) { for (int y = 0; y < layerHeight; y += tileHeight) { g.DrawImage(image, x, y); } } g.Dispose(); if (isReturn) { return(tempImage); } tempImage.SetFormat(Loon.Core.Graphics.Opengl.LTexture.Format.SPEED); SetBackground(tempImage.GetTexture()); if (tempImage != null) { tempImage.Dispose(); tempImage = null; } return(null); }
public static LTexture FilterColor(string res, LColor height, Loon.Core.Graphics.Opengl.LTexture.Format format) { uint color = height.GetRGB(); LImage tmp = LImage.CreateImage(res); LImage image = LImage.CreateImage(tmp.GetWidth(), tmp.GetHeight(), true); LGraphics g = image.GetLGraphics(); g.DrawImage(tmp, 0, 0); g.Dispose(); if (tmp != null) { tmp.Dispose(); tmp = null; } Color[] pixels = image.GetPixels(); int size = pixels.Length; for (int i = 0; i < size; i++) { if (pixels[i].PackedValue == color) { pixels[i].PackedValue = LSystem.TRANSPARENT; } } image.SetFormat(format); image.SetPixels(pixels, image.GetWidth(), image.GetHeight()); LTexture texture = image.GetTexture(); if (image != null) { image.Dispose(); image = null; } return(texture); }
public static LImage CreateFontImage(LFont font, LColor color, string text) { LImage image = LImage.CreateImage(font.StringWidth(text), font.GetHeight()); LGraphics g = image.GetLGraphics(); g.SetFont(font); g.DrawString(text, 0, 0, color); g.Dispose(); return(image); }
public static LImage DrawCropImage(LImage image, int x, int y, int objectWidth, int objectHeight) { LImage buffer = LImage.CreateImage(objectWidth, objectHeight, true); LGraphics g = buffer.GetLGraphics(); g.DrawImage(image, 0, 0, objectWidth, objectHeight, x, y, objectWidth, objectHeight); g.Dispose(); return(buffer); }
public static LImage OpenImage(string fileName, string resName) { byte[] buffer = null; try { buffer = LPKResource.OpenResource(fileName, resName); return(LImage.CreateImage(buffer)); } catch (Exception) { throw new Exception("File not found. ( " + resName + " )"); } }
public Menu() : base(128, 240) { // 设定menu层级高于MapLayer SetLayer(101); // 不锁定menu移动 SetLocked(false); SetLimitMove(false); // 锁定Actor拖拽 SetActorDrag(false); SetDelay(500); // 设定Menu背景 LImage image = LImage.CreateImage(this.GetWidth(), this.GetHeight(), true); LGraphics g = image.GetLGraphics(); g.SetColor(0, 0, 0, 125); g.FillRect(0, 0, GetWidth(), GetHeight()); g.SetColor(LColor.white); g.SetFont(15); g.DrawString("我是可拖拽菜单", 12, 25); g.Dispose(); SetBackground(image.GetTexture()); BulletTurret bulletTurret = new BulletTurret(); bulletTurret.SetLocation(18, 64); BombTurret bombTurret = new BombTurret(); bombTurret.SetLocation(78, 64); PoisonTurret poisonTurret = new PoisonTurret(); poisonTurret.SetLocation(18, 134); LaserTurret laserTurret = new LaserTurret(); laserTurret.SetLocation(78, 134); Button button = new Button(); button.SetLocation(27, 196); // 复合LPaper到Layer Add(bulletTurret); Add(bombTurret); Add(poisonTurret); Add(laserTurret); Add(button); }
public static LImage DrawClipImage(LImage image, int objectWidth, int objectHeight, int x1, int y1, int x2, int y2) { LImage buffer = LImage.CreateImage(objectWidth, objectHeight, true); LGraphics g = buffer.GetLGraphics(); g.DrawImage(image, 0, 0, objectWidth, objectHeight, x1, y1, x2 - x1, y2 - y1); g.Dispose(); return(buffer); }
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 CreateTexture(int width, int height, LColor c) { LImage image = LImage.CreateImage(width, height, false); LGraphics g = image.GetLGraphics(); g.SetColor(c); g.FillRect(0, 0, width, height); g.Dispose(); LTexture tex2d = image.GetTexture(); if (image != null) { image.Dispose(); image = null; } return(tex2d); }
public LImage GetImage(string name) { PackEntry entry = GetEntry(name); if (entry != null) { if (entry.image != null && !entry.image.IsClose()) { return(entry.image); } else if (entry.fileName != null) { return(LImage.CreateImage(entry.fileName)); } } return(null); }
public static LTexture GetRMXPDialog(string fileName, int width, int height) { if (lazyImages == null) { lazyImages = new Dictionary <string, LTexture>(10); } LImage dialog = LImage.CreateImage(fileName); int w = dialog.GetWidth(); Color[] pixels = dialog.GetPixels(); int index = -1; int count = 0; uint pixel; for (int i = 0; i < 5; i++) { pixel = pixels[(141 + i) + w * 12].PackedValue; if (index == -1) { index = (int)pixel; } if (index == pixel) { count++; } } if (count == 5) { return(GetRMXPDialog(dialog, width, height, 16, 5)); } else if (count == 1) { return(GetRMXPDialog(dialog, width, height, 27, 5)); } else if (count == 2) { return(GetRMXPDialog(dialog, width, height, 20, 5)); } else { return(GetRMXPDialog(dialog, width, height, 27, 5)); } }
public static LImage GetResize(LImage image, int w, int h) { if (image == null) { return(null); } if (image.width == w && image.height == h) { return(image); } LImage result = LImage.CreateImage(w, h, image.HasAlpha()); LGraphics g = result.GetLGraphics(); g.DrawImage(image, 0, 0, w, h, 0, 0, image.GetWidth(), image.GetHeight()); g.Dispose(); return(result); }
public static LTexture FilterLimitColor(string res, LColor start, LColor end, Loon.Core.Graphics.Opengl.LTexture.Format format) { int sred = start.R; int sgreen = start.G; int sblue = start.B; int ered = end.R; int egreen = end.G; int eblue = end.B; LImage tmp = LImage.CreateImage(res); LImage image = LImage.CreateImage(tmp.GetWidth(), tmp.GetHeight(), true); LGraphics g = image.GetLGraphics(); g.DrawImage(tmp, 0, 0); g.Dispose(); if (tmp != null) { tmp.Dispose(); tmp = null; } Color[] pixels = image.GetPixels(); int size = pixels.Length; for (int i = 0; i < size; i++) { Color pixel = pixels[i]; if ((pixel.R >= sred && pixel.G >= sgreen && pixel.B >= sblue) && (pixel.R <= ered && pixel.G <= egreen && pixel.B <= eblue)) { pixels[i].PackedValue = LSystem.TRANSPARENT; } } image.SetFormat(format); image.SetPixels(pixels, image.GetWidth(), image.GetHeight()); LTexture texture = image.GetTexture(); if (image != null) { image.Dispose(); image = null; } return(texture); }
public LTexture LoadBarColor(LColor c1, LColor c2, LColor c3) { if (colors.Count > 10) { lock (colors) { foreach (LTexture tex2d in colors.Values) { if (tex2d != null) { tex2d.Destroy(); } } colors.Clear(); } } int hash = 1; hash = LSystem.Unite(hash, c1.GetRGB()); hash = LSystem.Unite(hash, c2.GetRGB()); hash = LSystem.Unite(hash, c3.GetRGB()); LTexture texture = null; lock (colors) { texture = (LTexture)CollectionUtils.Get(colors, hash); } if (texture == null) { LImage image = LImage.CreateImage(8, 8, false); LGraphics g = image.GetLGraphics(); g.SetColor(c1); g.FillRect(0, 0, 4, 4); g.SetColor(c2); g.FillRect(4, 0, 4, 4); g.SetColor(c3); g.FillRect(0, 4, 4, 4); g.Dispose(); texture = image.GetTexture(); CollectionUtils.Put(colors, hash, texture); } return(this.texture = texture); }
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); }
public virtual void SetField2DBackground(Field2D field, Dictionary <object, object> pathMap, string fileName) { SetField2D(field); LImage background = null; if (fileName != null) { LImage tmp = LImage.CreateImage(fileName); background = SetTileBackground(tmp, true); if (tmp != null) { tmp.Dispose(); tmp = null; } } else { background = LImage.CreateImage(GetWidth(), GetHeight(), false); } int srcWidth = GetWidth(); int srcHeight = GetHeight(); //在C#环境下LGraphics采取像素渲染,得不到硬件加速,此处直接将像素操作方法粘过来了(虽然也快不了几毫秒……) int[] dstColors = background.GetIntPixels(); int[] srcColors = null; for (int i = 0; i < field.GetWidth(); i++) { for (int j = 0; j < field.GetHeight(); j++) { int index = field.GetType(j, i); object o = CollectionUtils.Get(pathMap, index); if (o != null) { if (o is LImage) { LImage img = (LImage)o; srcColors = img.GetIntPixels(); int w = img.Width; int h = img.Height; int y = field.TilesToHeightPixels(j); int x = field.TilesToWidthPixels(i); if (x < 0) { w += x; x = 0; } if (y < 0) { h += y; y = 0; } if (x + w > srcWidth) { w = srcWidth - x; } if (y + h > srcHeight) { h = srcHeight - y; } if (img.hasAlpha) { int findIndex = y * srcWidth + x; int drawIndex = 0; int moveFind = srcWidth - w; for (int col = 0; col < h; col++) { for (int row = 0; row < w;) { if (srcColors[drawIndex] != 0) { dstColors[findIndex] = srcColors[drawIndex]; } row++; findIndex++; drawIndex++; } findIndex += moveFind; } } else { for (int size = 0; size < h; size++) { System.Array.Copy(srcColors, size * w, dstColors, (y + size) * srcWidth + x, w); } } } else if (o is Actor) { AddObject(((Actor)o), field.TilesToWidthPixels(i), field.TilesToHeightPixels(j)); } } } } background.SetIntPixels(dstColors); background.SetFormat(Loon.Core.Graphics.Opengl.LTexture.Format.SPEED); SetBackground(background.GetTexture()); srcColors = null; dstColors = null; if (background != null) { background.Dispose(); background = null; } }
public virtual void SetTileBackground(string fileName) { SetTileBackground(LImage.CreateImage(fileName)); }
public PShadowEffect(LImage img, LImage back, int x, int y, int w, int h) { if (deasilTrans == null || widdershinTrans == null) { deasilTrans = new Color[max_pixel]; for (int i = 0; i < max_pixel; i++) { deasilTrans[i] = new Color(i, i, i); } int count = 0; widdershinTrans = new Color[max_pixel]; for (int i = 0; i < max_pixel; i++) { widdershinTrans[count++] = deasilTrans[i]; } } this.SetLocation(x, y); this.width = w; this.height = h; this.visible = true; LImage temp = null; if (back == null) { this.scaleWidth = width / 2; this.scaleHeight = height / 2; temp = GraphicsUtils.GetResize(img, scaleWidth, scaleHeight); this.image = LImage.CreateImage(scaleWidth, scaleHeight, true); this.finalDrawPixels = temp.GetPixels(); this.nowDrawPixels = (Color[])CollectionUtils.CopyOf(finalDrawPixels); if (temp != null) { temp.Dispose(); temp = null; } } else { this.scaleWidth = width / 2; this.scaleHeight = height / 2; temp = GraphicsUtils.GetResize(img, scaleWidth, scaleHeight); this.image = LImage.CreateImage(scaleWidth, scaleHeight, true); if (back.GetWidth() == scaleWidth && back.GetHeight() == scaleHeight) { this.finalBackgroundPixels = back.GetPixels(); this.backgroundPixels = (Color[])CollectionUtils .CopyOf(finalBackgroundPixels); } else { LImage tmp = GraphicsUtils.GetResize(back, scaleWidth, scaleHeight); this.finalBackgroundPixels = tmp.GetPixels(); if (tmp != null) { tmp.Dispose(); tmp = null; } this.backgroundPixels = (Color[])CollectionUtils .CopyOf(finalBackgroundPixels); } this.finalDrawPixels = temp.GetPixels(); this.nowDrawPixels = (Color[])CollectionUtils.CopyOf(finalDrawPixels); } this.SetBlackToWhite(flag); if (temp != null) { temp.Dispose(); temp = null; } if (img != null) { img.Dispose(); img = null; } if (back != null) { back.Dispose(); back = null; } }
public PShadowEffect(string fileName, LImage back, int x, int y, int w, int h) : this(LImage.CreateImage(fileName), back, x, y, w, h) { }
public LTexture(int width, int height, bool hasAlpha, Format format) : this(LImage.CreateImage(width, height, hasAlpha), format) { }
public PShadowEffect(string fileName, string backFile) : this(LImage.CreateImage(fileName), LImage.CreateImage(backFile), 0, 0, LSystem.screenRect.width, LSystem.screenRect.height) { }
public PShadowEffect(string fileName) : this(LImage.CreateImage(fileName)) { }
private LImage PackImage() { CheckPacked(); if (packing) { if (temps.IsEmpty()) { throw new InvalidOperationException("Nothing to Pack !"); } int maxWidth = 0; int maxHeight = 0; int totalArea = 0; for (int i = 0; i < temps.Size(); i++) { PackEntry entry = (PackEntry)temps.Get(i); int width = entry.image.GetWidth(); int height = entry.image.GetHeight(); if (width > maxWidth) { maxWidth = width; } if (height > maxHeight) { maxHeight = height; } totalArea += width * height; } Loon.Core.Geom.Point.Point2i size = new Loon.Core.Geom.Point.Point2i(CloseTwoPower(maxWidth), CloseTwoPower(maxHeight)); bool fitAll = false; loop : { while (!fitAll) { int area = size.x * size.y; if (area < totalArea) { NextSize(size); continue; } Node root = new Node(size.x, size.y); for (int i = 0; i < temps.Size(); i++) { PackEntry entry = (PackEntry)temps.Get(i); Node inserted = root.Insert(entry); if (inserted == null) { NextSize(size); goto loop; } } fitAll = true; } } int srcWidth = size.x; int srcHeight = size.y; //由于LGraphics操作较耗时,此处直接处理像素(其实也快不了几毫秒,未来将改写为C#混合C/C++) LImage image = LImage.CreateImage(srcWidth, srcHeight, useAlpha); int[] dstPixels = image.GetIntPixels(); int[] srcPixels = null; for (int i = 0; i < temps.Size(); i++) { PackEntry entry = (PackEntry)temps.Get(i); LImage img = entry.image; srcPixels = img.GetIntPixels(); int w = img.Width; int h = img.Height; int x = entry.bounds.left; int y = entry.bounds.top; if (x < 0) { w += x; x = 0; } if (y < 0) { h += y; y = 0; } if (x + w > srcWidth) { w = srcWidth - x; } if (y + h > srcHeight) { h = srcHeight - y; } if (img.hasAlpha) { int findIndex = y * srcWidth + x; int drawIndex = 0; int moveFind = srcWidth - w; for (int col = 0; col < h; col++) { for (int row = 0; row < w;) { if (srcPixels[drawIndex] != 0) { dstPixels[findIndex] = srcPixels[drawIndex]; } row++; findIndex++; drawIndex++; } findIndex += moveFind; } } else { for (int count = 0; count < h; count++) { System.Array.Copy(srcPixels, count * w, dstPixels, (y + count) * srcWidth + x, w); } } } image.SetIntPixels(dstPixels); srcPixels = null; dstPixels = null; packing = false; return(image); } return(null); }
public static LImage ToScreenCaptureTexturePixmap() { Texture2D screen = ToScreenCaptureTexture2D(); return(screen == null ? null : LImage.CreateImage(screen)); }
public LTexture(int width, int height, bool hasAlpha) : this(LImage.CreateImage(width, height, hasAlpha), Format.DEFAULT) { }
public static Polygon MakePolygon(string res) { return(MakePolygon(LImage.CreateImage(res))); }
public PShadowEffect(string fileName, string bacFile, int x, int y, int w, int h) : this(LImage.CreateImage(fileName), LImage.CreateImage(bacFile), x, y, w, h) { }
private void Make(LFont font, char[] customCharsArray) { if (charArray == null) { charArray = new IntObject[totalCharSet]; } if (customCharsArray != null && customCharsArray.Length > totalCharSet) { textureWidth *= 2; } try { LImage imgTemp = LImage.CreateImage(textureWidth, textureHeight, true); LGraphics g = imgTemp.GetLGraphics(); g.SetFont(font); int rowHeight = 0; int positionX = 0; int positionY = 0; int customCharsLength = (customCharsArray != null) ? customCharsArray.Length : 0; this.totalCharSet = customCharsLength == 0 ? totalCharSet : 0; StringBuilder sbr = new StringBuilder(totalCharSet); for (int i = 0; i < totalCharSet + customCharsLength; i++) { char ch = (i < totalCharSet) ? (char)i : customCharsArray[i - totalCharSet]; int charwidth = font.CharWidth(ch); if (charwidth <= 0) { charwidth = 1; } int charheight = font.GetHeight(); if (charheight <= 0) { charheight = font.GetSize(); } IntObject newIntObject = new IntObject(); newIntObject.width = charwidth; newIntObject.height = charheight; if (positionX + newIntObject.width >= textureWidth) { g.DrawString(sbr.ToString(), 0, positionY); sbr.Clear(); positionX = 0; positionY += rowHeight; rowHeight = 0; } newIntObject.storedX = positionX; newIntObject.storedY = positionY; if (newIntObject.height > fontHeight) { fontHeight = newIntObject.height; } if (newIntObject.height > rowHeight) { rowHeight = newIntObject.height; } sbr.Append(ch); positionX += newIntObject.width; if (i < totalCharSet) { charArray[i] = newIntObject; } else { CollectionUtils.Put(customChars, ch, newIntObject); } } if (sbr.Length > 0) { g.DrawString(sbr.ToString(), 0, positionY); sbr = null; } g.Dispose(); g = null; fontBatch = new LTextureBatch(imgTemp.GetTexture()); } catch (Exception ex) { Loon.Utils.Debugging.Log.Exception(ex); } }
public static LTexture ToScreenCaptureTexture() { Texture2D screen = ToScreenCaptureTexture2D(); return(screen == null ? null : LImage.CreateImage(screen).GetTexture()); }
public int PutImage(string res) { return(PutImage(res, LImage.CreateImage(res))); }