private static void DrawDebug(List<Actor> actors, SpriteBatch spriteBatch) { throw new NotImplementedException(); }
protected override void InitializeCore() { ShowDebug = true; //Debugger.Launch(); _spriteBatch = new GdxSpriteBatch(Context.GraphicsDevice); _skin = new Skin(Context.GraphicsDevice, "Data/uiskin.json"); _texture1 = new TextureContext(Context.GraphicsDevice, "Data/badlogicsmall.jpg", true); _texture2 = new TextureContext(Context.GraphicsDevice, "Data/badlogic.jpg", true); TextureRegion image = new TextureRegion(_texture1); TextureRegion imageFlipped = new TextureRegion(image); imageFlipped.Flip(true, true); TextureRegion image2 = new TextureRegion(_texture2); _stage = new Stage(Context.GraphicsDevice.Viewport.Width, Context.GraphicsDevice.Viewport.Height, true, Context.GraphicsDevice); Context.Input.Processor = _stage; ImageButtonStyle style = new ImageButtonStyle(_skin.Get <ButtonStyle>()) { ImageUp = new TextureRegionDrawable(image), ImageDown = new TextureRegionDrawable(imageFlipped), }; ImageButton iconButton = new ImageButton(style); Button buttonMulti = new TextButton("Multi\nLine\nToggle", _skin, "toggle") { IsToggle = true, }; Button imgButton = new Button(new Image(image), _skin); Button imgToggleButton = new Button(new Image(image), _skin, "toggle") { IsToggle = true, }; Label myLabel = new Label("This is some text.", _skin); myLabel.TextWrapping = true; Table t = new Table(); t.Row(); t.Add(myLabel); t.Layout(); CheckBox checkbox = new CheckBox("Check me", _skin); Slider slider = new Slider(0, 10, 1, false, _skin); TextField textField = new TextField("", _skin) { MessageText = "Click here!", }; SelectBox dropdown = new SelectBox(selectEntries, _skin); Image imageActor = new Image(image2); ScrollPane scrollPane = new ScrollPane(imageActor); MonoGdx.Scene2D.UI.List list = new MonoGdx.Scene2D.UI.List(listEntries, _skin); ScrollPane scrollPane2 = new ScrollPane(list, _skin); //scrollPane2.FlickScroll = false; SplitPane splitPane = new SplitPane(scrollPane, scrollPane2, false, _skin, "default-horizontal"); _fpsLabel = new Label("fps:", _skin); Label passwordLabel = new Label("Textfield in password mode: ", _skin); TextField passwordField = new TextField("", _skin) { MessageText = "password", PasswordCharacter = '*', IsPasswordMode = true, }; Window window = new Window("Dialog", _skin); window.SetPosition(0, 0); window.Defaults().SpaceBottom = 10; window.Row().Configure.Fill().ExpandX(); window.Add(iconButton); window.Add(buttonMulti); window.Add(imgButton); window.Add(imgToggleButton); window.Row(); window.Add(checkbox); window.Add(slider).Configure.MinWidth(100).FillX().Colspan(3); window.Row(); window.Add(dropdown).Configure.MinWidth(100).FillX(); window.Add(textField).Configure.MinWidth(100).ExpandX().FillX().Colspan(3); window.Row(); window.Add(splitPane).Configure.Fill().Expand().Colspan(4).MaxHeight(200); window.Row(); window.Add(passwordLabel).Configure.Colspan(2); window.Add(passwordField).Configure.MinWidth(100).ExpandX().FillX().Colspan(2); window.Pack(); /*textField.KeyUp += (field, c) => { * if (c == '\n') * field.OnscreenKeyboard.Show(false); * };*/ _stage.AddActor(window); MonoGdx.Scene2D.UI.List list2 = new MonoGdx.Scene2D.UI.List(listEntries, _skin); ScrollPane scrollPane22 = new ScrollPane(list2, _skin); Window window2 = new Window("ScrollPane", _skin); window2.SetPosition(300, 300); window2.Defaults().SpaceBottom = 10; window2.Row().Configure.Fill().ExpandX(); window2.Add(scrollPane22).Configure.MaxHeight(250).MaxWidth(150); window2.Pack(); _stage.AddActor(window2); }
protected override void InitializeCore() { ShowDebug = true; //Debugger.Launch(); _spriteBatch = new GdxSpriteBatch(Context.GraphicsDevice); _skin = new Skin(Context.GraphicsDevice, "Data/uiskin.json"); _texture1 = new TextureContext(Context.GraphicsDevice, "Data/badlogicsmall.jpg", true); _texture2 = new TextureContext(Context.GraphicsDevice, "Data/badlogic.jpg", true); TextureRegion image = new TextureRegion(_texture1); TextureRegion imageFlipped = new TextureRegion(image); imageFlipped.Flip(true, true); TextureRegion image2 = new TextureRegion(_texture2); _stage = new Stage(Context.GraphicsDevice.Viewport.Width, Context.GraphicsDevice.Viewport.Height, true, Context.GraphicsDevice); Context.Input.Processor = _stage; ImageButtonStyle style = new ImageButtonStyle(_skin.Get<ButtonStyle>()) { ImageUp = new TextureRegionDrawable(image), ImageDown = new TextureRegionDrawable(imageFlipped), }; ImageButton iconButton = new ImageButton(style); Button buttonMulti = new TextButton("Multi\nLine\nToggle", _skin, "toggle") { IsToggle = true, }; Button imgButton = new Button(new Image(image), _skin); Button imgToggleButton = new Button(new Image(image), _skin, "toggle") { IsToggle = true, }; Label myLabel = new Label("This is some text.", _skin); myLabel.TextWrapping = true; Table t = new Table(); t.Row(); t.Add(myLabel); t.Layout(); CheckBox checkbox = new CheckBox("Check me", _skin); Slider slider = new Slider(0, 10, 1, false, _skin); TextField textField = new TextField("", _skin) { MessageText = "Click here!", }; SelectBox dropdown = new SelectBox(selectEntries, _skin); Image imageActor = new Image(image2); ScrollPane scrollPane = new ScrollPane(imageActor); MonoGdx.Scene2D.UI.List list = new MonoGdx.Scene2D.UI.List(listEntries, _skin); ScrollPane scrollPane2 = new ScrollPane(list, _skin); //scrollPane2.FlickScroll = false; SplitPane splitPane = new SplitPane(scrollPane, scrollPane2, false, _skin, "default-horizontal"); _fpsLabel = new Label("fps:", _skin); Label passwordLabel = new Label("Textfield in password mode: ", _skin); TextField passwordField = new TextField("", _skin) { MessageText = "password", PasswordCharacter = '*', IsPasswordMode = true, }; Window window = new Window("Dialog", _skin); window.SetPosition(0, 0); window.Defaults().SpaceBottom = 10; window.Row().Configure.Fill().ExpandX(); window.Add(iconButton); window.Add(buttonMulti); window.Add(imgButton); window.Add(imgToggleButton); window.Row(); window.Add(checkbox); window.Add(slider).Configure.MinWidth(100).FillX().Colspan(3); window.Row(); window.Add(dropdown).Configure.MinWidth(100).FillX(); window.Add(textField).Configure.MinWidth(100).ExpandX().FillX().Colspan(3); window.Row(); window.Add(splitPane).Configure.Fill().Expand().Colspan(4).MaxHeight(200); window.Row(); window.Add(passwordLabel).Configure.Colspan(2); window.Add(passwordField).Configure.MinWidth(100).ExpandX().FillX().Colspan(2); window.Pack(); /*textField.KeyUp += (field, c) => { if (c == '\n') field.OnscreenKeyboard.Show(false); };*/ _stage.AddActor(window); MonoGdx.Scene2D.UI.List list2 = new MonoGdx.Scene2D.UI.List(listEntries, _skin); ScrollPane scrollPane22 = new ScrollPane(list2, _skin); Window window2 = new Window("ScrollPane", _skin); window2.SetPosition(300, 300); window2.Defaults().SpaceBottom = 10; window2.Row().Configure.Fill().ExpandX(); window2.Add(scrollPane22).Configure.MaxHeight(250).MaxWidth(150); window2.Pack(); _stage.AddActor(window2); }
private float NodeAt(List<TreeNode> nodes, float y, float rowY) { foreach (TreeNode node in nodes) { if (y >= rowY - node.Height - YSpacing && y < rowY) { _foundNode = node; return -1; } rowY -= node.Height + YSpacing; if (node.IsExpanded) { rowY = NodeAt(node.Children, y, rowY); if (rowY == -1) return -1; } } return rowY; }
private void SelectionChangeHandler(List<TreeNode> addedItems, List<TreeNode> removedItems) { OnSelectionChanged(removedItems, addedItems); }
private void Draw(GdxSpriteBatch spriteBatch, List<TreeNode> nodes, float indent) { ISceneDrawable plus = _style.Plus; ISceneDrawable minus = _style.Minus; float x = X; float y = Y; foreach (TreeNode node in nodes) { Actor actor = node.Actor; float iconY = 0; bool selected = _selectedNodes.Contains(node); if (selected && _style.Selection != null) _style.Selection.Draw(spriteBatch, x, y + actor.Y - YSpacing / 2, Width, node.Height + YSpacing); else if (node == OverNode && _style.Over != null) _style.Over.Draw(spriteBatch, x, y + actor.Y - YSpacing / 2, Width, node.Height + YSpacing); if (node.Icon != null) { ISceneDrawable icon = node.Icon; iconY = actor.Y + (float)Math.Round((node.Height - icon.MinHeight) / 2); spriteBatch.Color = actor.Color; icon.Draw(spriteBatch, x + node.Actor.X - IconSpacing - icon.MinWidth, y + iconY, icon.MinWidth, icon.MinHeight); spriteBatch.Color = Microsoft.Xna.Framework.Color.White; } if (node.Children.Count == 0) continue; ISceneDrawable expandIcon = node.IsExpanded ? minus : plus; if (selected) expandIcon = node.IsExpanded ? _style.MinusSelection ?? minus : _style.PlusSelection ?? plus; iconY = actor.Y + (float)Math.Round((node.Height - expandIcon.MinHeight) / 2); expandIcon.Draw(spriteBatch, x + indent - IconSpacing, y + iconY, expandIcon.MinWidth, expandIcon.MinHeight); if (node.IsExpanded) Draw(spriteBatch, node.Children, indent + _indentSpacing); } }
private float Layout(List<TreeNode> nodes, float indent, float y) { float ySpacing = YSpacing; float indentSpacing = _indentSpacing; ISceneDrawable plus = _style.Plus; ISceneDrawable minus = _style.Minus; foreach (TreeNode node in nodes) { Actor actor = node.Actor; float x = indent; if (node.Icon != null) x += node.Icon.MinWidth; y -= node.Height; node.Actor.SetPosition(x, y); y -= ySpacing; if (node.IsExpanded) y = Layout(node.Children, indent + indentSpacing, y); } return y; }
internal void SelectNodes(List<TreeNode> nodes, float low, float high) { float ySpacing = YSpacing; foreach (TreeNode node in nodes) { if (node.Actor.Y < low) break; if (!node.IsSelectable) continue; if (node.Actor.Y <= high) _selectionChanger.Select(node); if (node.IsExpanded) SelectNodes(node.Children, low, high); } }
private void ComputeSize(List<TreeNode> nodes, float indent) { float ySpacing = YSpacing; foreach (TreeNode node in nodes) { float rowWidth = indent + IconSpacing; Actor actor = node.Actor; if (actor is ILayout) { ILayout layout = actor as ILayout; rowWidth += layout.PrefWidth; node.Height = layout.PrefHeight; layout.Pack(); } else { rowWidth += actor.Width; node.Height = actor.Height; } if (node.Icon != null) { rowWidth += IconSpacing * 2 + node.Icon.MinWidth; node.Height = Math.Max(node.Height, node.Icon.MinHeight); } _prefWidth = Math.Max(_prefWidth, rowWidth); _prefHeight -= node.Height + YSpacing; if (node.IsExpanded) ComputeSize(node.Children, indent + _indentSpacing); } }
internal static TreeNode FindNode(List<TreeNode> nodes, object obj) { foreach (TreeNode node in nodes) { if (obj.Equals(node.Object)) return node; } foreach (TreeNode node in nodes) { TreeNode found = FindNode(node.Children, obj); if (found != null) return found; } return null; }
internal static bool FindExpandedObjects(List<TreeNode> nodes, IList objects) { bool expanded = false; foreach (TreeNode node in nodes) { if (node.IsExpanded && !FindExpandedObjects(node.Children, objects)) objects.Add(node.Object); } return expanded; // Always returns false? }
internal static void ExpandAll(List<TreeNode> nodes) { foreach (TreeNode node in nodes) node.ExpandAll(); }
internal static void CollapseAll(List<TreeNode> nodes) { foreach (TreeNode node in nodes) { node.IsExpanded = false; CollapseAll(node.Children); } }
public SelectList(SelectBox selectBox) : base(null, selectBox.Style.ScrollStyle) { _selectBox = selectBox; OverscrollX = false; OverscrollY = false; FadeScrollBars = false; _list = new List(new object[0], _selectBox.Style.ListStyle); Widget = _list; _list.SelectionChanged += (s, e) => { e.Stopped = true; }; _list.MouseMove += (s, e) => { Vector2 position = e.GetPosition(s); _list.SelectedIndex = Math.Min(_selectBox.Items.Length - 1, (int)((_list.Height - position.Y) / _list.ItemHeight)); e.Handled = true; }; }