public IntVector2 centrePosition() { IntVector2 position = new IntVector2(); if (_boundingBox.valid && _boundingBox.use) { position.x = _boundingBox.w / 2 + _boundingBox.x; position.y = _boundingBox.h / 2 + _boundingBox.y; } else { if (_previewImage == null) { position.x = 0; position.y = 0; } else { position.x = _previewImage.width / 2; position.y = _previewImage.height / 2; } } return position; }
public void blendHSV(Image overlay, IntVector2 position, AlphaOption alphaOption, byte textureAlpha, BoundingBox boundingBox = null) { int minX, minY, maxX, maxY; setMinMax(out minX, out minY, out maxX, out maxY, boundingBox); for (int i = 0; i < overlay.width; ++i) { for (int j = 0; j < overlay.height; ++j) { int px = position.x + i; int py = position.y + j; if (px >= minX && px <= maxX && py >= minY && py <= maxY) { Color32 overlayColor = Utils.GetElement2D(overlay.pixels, i, j, overlay.width); if (overlayColor.a > 0) { Color32 oldColor = Utils.GetElement2D(pixels, px, py, width); RGB rgb1 = new RGB(oldColor); RGB rgb2 = new RGB(overlayColor); HSV hsv1 = rgb1.toHSV(); HSV hsv2 = rgb2.toHSV(); HSV hsv3 = hsv1.blend(hsv2, (float) overlayColor.a / 255f); RGB rgb3 = hsv3.toRGB(); pixels[px + py * width].r = Math.Min((byte) (rgb3.r * 255f), (byte) 255); pixels[px + py * width].g = Math.Min((byte) (rgb3.g * 255f), (byte) 255); pixels[px + py * width].b = Math.Min((byte) (rgb3.b * 255f), (byte) 255); if (alphaOption == AlphaOption.OVERWRITE) pixels[px + py * width].a = textureAlpha; } } } } }
public IntVector2(IntVector2 vector) { x = vector.x; y = vector.y; }
public void positionSelector(TextureEditGUI gui, ref IntVector2 position) { bool repeatOK = false; bool buttonPressed = false; int button = 0; int delta = 1; if ((Time.time - Global.LastRepeat) > Global.AutoRepeatGap) repeatOK = true; if (gui.speedSelection < 0 || gui.speedSelection > 1) gui.speedSelection = 0; if (gui.speedSelection == 1) { button = 4; delta = 10; } GUILayout.BeginVertical(GUI.skin.box, GUILayout.Width(120)); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); GUILayout.Label("Position"); GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); GUILayout.Space(3); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.RepeatButton(_posButtons[button], GUILayout.Width(25), GUILayout.Height(25))) { buttonPressed = true; Global.LastButtonPress = Time.time; if (repeatOK) position.y += delta; } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); GUILayout.Space(3); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.RepeatButton(_posButtons[button + 2], GUILayout.Width(25), GUILayout.Height(25))) { buttonPressed = true; Global.LastButtonPress = Time.time; if (repeatOK) position.x -= delta; } GUILayout.Space(5); if (GUILayout.Button("O", GUILayout.Width(25), GUILayout.Height(25))) { position = gui.centrePosition(); gui.setRemakePreview(); } GUILayout.Space(5); if (GUILayout.RepeatButton(_posButtons[button + 3], GUILayout.Width(25), GUILayout.Height(25))) { buttonPressed = true; Global.LastButtonPress = Time.time; if (repeatOK) position.x += delta; } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); GUILayout.Space(3); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.RepeatButton(_posButtons[button + 1], GUILayout.Width(25), GUILayout.Height(25))) { buttonPressed = true; Global.LastButtonPress = Time.time; if (repeatOK) position.y -= delta; } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); GUILayout.Space(3); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); gui.speedSelection = GUILayout.SelectionGrid(gui.speedSelection, _speedGrid, 2); GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); GUILayout.FlexibleSpace(); GUILayout.EndVertical(); if (buttonPressed && repeatOK) { Global.LastRepeat = Global.LastButtonPress; gui.setRemakePreview(); Global.AutoRepeatGap = Global.AutoRepeatGap * 0.8f; if (Global.AutoRepeatGap < 0.04f) Global.AutoRepeatGap = 0.04f; } }
public void blendImage(Image image, BlendMethod blendMethod, IntVector2 position, AlphaOption alphaOption, byte alpha, BoundingBox boundingBox = null) { switch (blendMethod) { case ASP.BlendMethod.HSV: blendHSV(image, position, alphaOption, alpha, boundingBox); break; case ASP.BlendMethod.RGB: blendRGB(image, position, alphaOption, alpha, boundingBox); break; case ASP.BlendMethod.PIXEL: default: overlay(image, position, alphaOption, alpha, boundingBox); break; } }
public void overlay(Image overlay, IntVector2 position, AlphaOption alphaOption, byte textureAlpha, BoundingBox boundingBox = null) { int minX, minY, maxX, maxY; setMinMax(out minX, out minY, out maxX, out maxY, boundingBox); for (int i = 0; i < overlay.width; ++i) { for (int j = 0; j < overlay.height; ++j) { int px = position.x + i; int py = position.y + j; if (px >= minX && px <= maxX && py >= minY && py <= maxY) { if (overlay.pixels[i + j * overlay.width].a > 127) { pixels[px + py * width].r = overlay.pixels[i + j * overlay.width].r; pixels[px + py * width].g = overlay.pixels[i + j * overlay.width].g; pixels[px + py * width].b = overlay.pixels[i + j * overlay.width].b; if (alphaOption == AlphaOption.OVERWRITE) pixels[px + py * width].a = textureAlpha; } } } } }
public void drawText(string text, BitmapFont font, IntVector2 position, Rotation rotation, Color32 color, bool mirror, AlphaOption alphaOption, byte textureAlpha, BlendMethod blendMethod, BoundingBox boundingBox = null) { if (Global.Debug2) Utils.Log("text {0}, x {1}, y {2}", text, position.x, position.y); IntVector2 charPos = new IntVector2(position); bool escapeMode = false; string textToWrite = string.Empty; if (mirror) textToWrite = ASP.Utils.Reverse(text); else textToWrite = text; foreach (char c in textToWrite) { if (c == '\\') { escapeMode = !escapeMode; } if (escapeMode) { if (c == 'n') { switch (rotation) { case Rotation.R90: charPos.x -= font.size; charPos.y = position.y; break; case Rotation.R270: charPos.x += font.size; charPos.y = position.y; break; case Rotation.R0: charPos.y -= font.size; charPos.x = position.x; break; case Rotation.R180: default: charPos.y += font.size; charPos.x = position.x; break; } } if (c != '\\') escapeMode = false; } else drawCharacter(c, font, ref charPos, rotation, color, mirror, alphaOption, textureAlpha, blendMethod, boundingBox); } }
public void drawText(string text, string fontName, int fontSize, IntVector2 position, Rotation rotation, Color32 color, bool mirror, AlphaOption alphaOption, byte textureAlpha, BlendMethod blendMethod, BoundingBox boundingBox = null) { BitmapFont font = BitmapFontCache.Instance.getFontByNameSize(fontName, fontSize); if (font == null) font = BitmapFontCache.Instance.fonts.First(); drawText(text, font, position, rotation, color, mirror, alphaOption, textureAlpha, blendMethod, boundingBox); }
public void drawCharacter(char c, BitmapFont font, ref IntVector2 position, Rotation rotation, Color32 color, bool mirror, AlphaOption alphaOption, byte textureAlpha, BlendMethod blendMethod, BoundingBox boundingBox = null) { if (Global.Debug3) Utils.Log("char {0}, x {1}, y {2}", c, position.x, position.y); ASP.BitmapChar charMap; IntVector2 cPos = new IntVector2(); if (font.characterMap.TryGetValue(c, out charMap) == false) { c = '?'; if (font.characterMap.TryGetValue(c, out charMap) == false) return; } Image charImage = new Image(charMap.image); charImage.recolor(Global.Black32, color, false, true); if (mirror) charImage.flipHorizontally(); switch (rotation) { case Rotation.R180: charImage.rotate180(); cPos.x = position.x - ((int)charMap.vx + (int)charMap.vw); cPos.y = position.y - (font.size + (int)charMap.vy); position.x -= (int) charMap.cw; break; case Rotation.R90: charImage.flipXY(true); cPos.x = position.x + (font.size + (int)charMap.vy + (int)charMap.vh); cPos.y = position.y - ((int)charMap.vx + (int)charMap.vw); position.y -= (int)charMap.cw; break; case Rotation.R270: charImage.flipXY(false); cPos.x = position.x - (font.size + (int)charMap.vy); cPos.y = position.y + (int)charMap.vx; position.y += (int)charMap.cw; break; case Rotation.R0: default: cPos.x = position.x + (int)charMap.vx; cPos.y = position.y + (font.size + (int)charMap.vy + (int)charMap.vh); position.x += (int)charMap.cw; break; } blendImage(charImage, blendMethod, cPos, alphaOption, textureAlpha, boundingBox); }
public void blendRGB(Image overlay, IntVector2 position, AlphaOption alphaOption, byte textureAlpha, BoundingBox boundingBox = null) { int minX, minY, maxX, maxY; setMinMax(out minX, out minY, out maxX, out maxY, boundingBox); for (int i = 0; i < overlay.width; ++i) { for (int j = 0; j < overlay.height; ++j) { int px = position.x + i; int py = position.y + j; if (px >= minX && px <= maxX && py >= minY && py <= maxY) { Color32 overlayColor = Utils.GetElement2D(overlay.pixels, i, j, overlay.width); if (overlayColor.a > 0) { Color32 oldColor = Utils.GetElement2D(pixels, px, py, width); Color32 newColor = Color32.Lerp(oldColor, overlayColor, (float) overlayColor.a / 255f); pixels[px + py * width].r = newColor.r; pixels[px + py * width].g = newColor.g; pixels[px + py * width].b = newColor.b; if (alphaOption == AlphaOption.OVERWRITE) pixels[px + py * width].a = textureAlpha; } } } } }