private uint[] CreateTexture(int radius, ref short width, ref short height) { _texture?.Dispose(); int fixRadius = radius + 1; int mulRadius = fixRadius * 2; uint[] pixels = new uint[mulRadius * mulRadius]; width = (short)mulRadius; height = (short)mulRadius; for (int x = -fixRadius; x < fixRadius; x++) { int mulX = x * x; int posX = ((x + fixRadius) * mulRadius) + fixRadius; for (int y = -fixRadius; y < fixRadius; y++) { int r = (int)Math.Sqrt(mulX + (y * y)); uint pic = (uint)((r <= radius) ? ((radius - r) & 0xFF) : 0); int pos = posX + y; pixels[pos] = HuesHelper.RgbaToArgb(pic); } } return(pixels); }
public void SetColor(ushort hue, uint pol) { Hue = hue; (byte b, byte g, byte r, byte a) = HuesHelper.GetBGRA(HuesHelper.RgbaToArgb(pol)); _colorRGBA = new Color(a, b, g, r); if (_colorRGBA.A == 0) { _colorRGBA.A = 0xFF; } if (Texture == null || Texture.IsDisposed) { Texture = new SpriteTexture(1, 1); } Texture.SetData(new Color[1] { _colorRGBA }); }
public static void Create(int radius) { if (radius < Constants.MIN_CIRCLE_OF_TRANSPARENCY_RADIUS) { radius = Constants.MIN_CIRCLE_OF_TRANSPARENCY_RADIUS; } else if (radius > Constants.MAX_CIRCLE_OF_TRANSPARENCY_RADIUS) { radius = Constants.MAX_CIRCLE_OF_TRANSPARENCY_RADIUS; } if (_radius == radius && _texture != null && !_texture.IsDisposed) { return; } _radius = radius; _texture?.Dispose(); _texture = null; uint[] pixels = CreateCircleTexture(radius, ref _width, ref _height); for (int i = 0; i < pixels.Length; i++) { ref uint pixel = ref pixels[i]; if (pixel != 0) { pixel = HuesHelper.RgbaToArgb(pixel); //ushort value = (ushort)(pixel << 3); //if (value > 0xFF) // value = 0xFF; //pixel = (uint)((value << 24) | (value << 16) | (value << 8) | value); } }
public PopupMenuGump(PopupMenuData data) : base(0, 0) { CanMove = false; CanCloseWithRightClick = true; ResizePic pic = new ResizePic(0x0A3C) { Alpha = 0.25f }; Add(pic); int offsetY = 10; bool arrowAdded = false; int width = 0, height = 20; for (int i = 0; i < data.Items.Length; i++) { ref PopupMenuItem item = ref data.Items[i]; string text = ClilocLoader.Instance.GetString(item.Cliloc); ushort hue = item.Hue; if (item.ReplacedHue != 0) { uint h = HuesHelper.Color16To32(item.ReplacedHue); (byte b, byte g, byte r, byte a) = HuesHelper.GetBGRA(h); Color c = new Color(r, g, b, a); if (c.A == 0) { c.A = 0xFF; } FontsLoader.Instance.SetUseHTML(true, HuesHelper.RgbaToArgb(c.PackedValue)); } Label label = new Label(text, true, hue, font: 1) { X = 10, Y = offsetY }; FontsLoader.Instance.SetUseHTML(false); HitBox box = new HitBox(10, offsetY, label.Width, label.Height) { Tag = item.Index }; box.MouseUp += (sender, e) => { if (e.Button == MouseButtonType.Left) { HitBox l = (HitBox)sender; GameActions.ResponsePopupMenu(data.Serial, (ushort)l.Tag); Dispose(); } }; Add(box); Add(label); if ((item.Flags & 0x02) != 0 && !arrowAdded) { arrowAdded = true; // TODO: wat? Add ( new Button(0, 0x15E6, 0x15E2, 0x15E2) { X = 20, Y = offsetY } ); height += 20; } offsetY += label.Height; if (!arrowAdded) { height += label.Height; if (width < label.Width) { width = label.Width; } } }
public PopupMenuGump(PopupMenuData data) : base(0, 0) { CloseIfClickOutside = true; //ControlInfo.IsModal = true; //ControlInfo.ModalClickOutsideAreaClosesThisControl = true; CanMove = false; ResizePic pic = new ResizePic(0x0A3C) { Alpha = 0.25f }; Add(pic); int offsetY = 10; bool arrowAdded = false; int width = 0, height = 20; foreach (PopupMenuItem item in data.Items) { string text = UOFileManager.Cliloc.GetString(item.Cliloc); ushort hue = item.Hue; if (item.ReplacedHue != 0) { uint h = HuesHelper.Color16To32(item.ReplacedHue); (byte b, byte g, byte r, byte a) = HuesHelper.GetBGRA(h); Color c = new Color(r, g, b, a); if (c.A == 0) { c.A = 0xFF; } UOFileManager.Fonts.SetUseHTML(true, HuesHelper.RgbaToArgb(c.PackedValue)); } Label label = new Label(text, true, 0xFFFF, font: 1) { X = 10, Y = offsetY }; UOFileManager.Fonts.SetUseHTML(false); HitBox box = new HitBox(10, offsetY, label.Width, label.Height) { Tag = item.Index }; box.MouseUp += (sender, e) => { if (e.Button == MouseButton.Left) { HitBox l = (HitBox)sender; GameActions.ResponsePopupMenu(data.Serial, (ushort)l.Tag); Dispose(); } }; Add(box); Add(label); if ((item.Flags & 0x02) != 0 && !arrowAdded) { arrowAdded = true; // TODO: wat? Add(new Button(0, 0x15E6, 0x15E2, 0x15E2) { X = 20, Y = offsetY }); height += 20; } offsetY += label.Height; if (!arrowAdded) { height += label.Height; if (width < label.Width) { width = label.Width; } } } width += 20; if (height <= 10 || width <= 20) { Dispose(); } else { pic.Width = width; pic.Height = height; foreach (HitBox box in FindControls <HitBox>()) { box.Width = width - 20; } } }