/// <summary> /// Create an auto-layout image. /// </summary> /// <param name="filePath">file path of the image to display. The path should be relative to current dir or absolute.</param> public static void Image(string filePath) { GUIContext g = GetCurrentContext(); Window window = GetCurrentWindow(); if (window.SkipItems) { return; } var id = window.GetID(filePath); // style var style = GUIStyle.Basic; style.PushBorder(1.0); // rect var texture = TextureUtil.GetTexture(filePath); Size size = style.CalcSize(texture, GUIState.Normal); var rect = window.GetRect(id); // render DrawList d = window.DrawList; style.PushBorderColor(Color.Black);//+4 d.DrawBoxModel(rect, texture, style); style.PopStyle(4 + 4); }
/// <summary> /// Create an image. /// </summary> /// <param name="rect">position and size</param> /// <param name="filePath">file path of the image. The path should be relative to current dir or absolute.</param> public static void Image(Rect rect, string filePath) { GUIContext g = GetCurrentContext(); Window window = GetCurrentWindow(); if (window.SkipItems) { return; } // style apply var style = GUIStyle.Basic; style.PushBorder(1.0);//+4 // rect rect = window.GetRect(rect); // render var texture = TextureUtil.GetTexture(filePath); DrawList d = window.DrawList; style.PushBorderColor(Color.Black);//+4 d.DrawBoxModel(rect, texture, style); style.PopStyle(4 + 4); }
public static bool ImageButton(string filePath, Size size, Point uv0, Point uv1) { Window window = GetCurrentWindow(); if (window.SkipItems) { return(false); } var id = window.GetID(filePath); // style var style = GUIStyle.Basic; style.Save(); style.ApplySkin(GUIControlName.Button); // rect var texture = TextureUtil.GetTexture(filePath); if (size == Size.Empty) { size = style.CalcSize(texture, GUIState.Normal); } var rect = window.GetRect(id); if (rect == Layout.StackLayout.DummyRect) { style.Restore(); return(false); } // interact bool hovered, held; bool pressed = GUIBehavior.ButtonBehavior(rect, id, out hovered, out held, 0); // render style.PushUV(uv0, uv1); var d = window.DrawList; var state = (hovered && held) ? GUIState.Active : hovered ? GUIState.Hover : GUIState.Normal; d.DrawBoxModel(rect, texture, style, state); style.Restore(); return(pressed); }
public static bool ImageButton(string filePath, Size size, Vector offset) { var window = GetCurrentWindow(); if (window.SkipItems) { return(false); } //get or create the root node var id = window.GetID(filePath); var container = window.RenderTree.CurrentContainer; var node = container.GetNodeById(id); if (node == null) { //create node node = new Node(id, $"Button<{filePath}>"); node.UseBoxModel = true; node.RuleSet.Replace(GUISkin.Current[GUIControlName.Button]); node.RuleSet.ObjectPosition = (offset.X, offset.Y); node.AttachLayoutEntry(size); } container.AppendChild(node); node.ActiveSelf = true; // rect node.Rect = window.GetRect(id); // interact var pressed = GUIBehavior.ButtonBehavior(node.Rect, node.Id, out var hovered, out var held); node.State = (hovered && held) ? GUIState.Active : hovered ? GUIState.Hover : GUIState.Normal; // last item state window.TempData.LastItemState = node.State; // draw using (var dc = node.RenderOpen()) { var texture = TextureUtil.GetTexture(filePath); dc.DrawBoxModel(texture, node.RuleSet, node.Rect); } return(pressed); }
public static bool ImageButton(string filePath) { var texture = TextureUtil.GetTexture(filePath); return(ImageButton(filePath, texture.Size, Vector.Zero)); }