public StencilPicker(BlockStore blocks, IReadOnlyList <TileStencil> stencils, Vector2?size = null, Anchor anchor = Anchor.Center, Vector2?offset = null) : base(size ?? Vector2.Zero, skin: PanelSkin.Simple, anchor: anchor, offset: offset) { var stencilSprites = stencils.Select(s => s.ToSprite(blocks)).ToList(); var max = Vector2.Zero; max.X = stencilSprites.Max(s => s.Width); max.Y = stencilSprites.Max(s => s.Height); foreach (var stencil in stencils) { var sprite = stencil.ToSprite(blocks); var outline = new ColoredRectangle(max * 2, anchor: Anchor.AutoInline); outline.SpaceAfter = new Vector2(10f, 10f); outline.OutlineColor = Color.White; outline.OutlineWidth = 1; outline.FillColor = Color.CornflowerBlue; outline.SetStyleProperty("FillColor", new StyleProperty(Color.Red), EntityState.MouseHover); outline.OnClick += (e) => { this.OnStencilClick?.Invoke(this, stencil); }; var img = new SpriteImage(sprite, new Vector2(sprite.Width * 2, sprite.Height * 2), anchor: Anchor.Center); img.Padding = Vector2.Zero; img.Scale = 1f; img.Locked = true; outline.AddChild(img); this.AddChild(outline); } this.PanelOverflowBehavior = PanelOverflowBehavior.VerticalScroll; //this.Scrollbar.Max = 2048; }
//Idem PathAction avec des rectangles private void RectangleAction(SKTouchEventArgs e, SKColor color) { switch (e.ActionType) { case SKTouchAction.Pressed: var r = new ColoredRectangle { Color = color, Start = e.Location, End = e.Location, StrokeWidth = strokeWidth }; temporaryForms[e.Id] = r; break; case SKTouchAction.Moved: if (e.InContact && temporaryForms.ContainsKey(e.Id)) { r = (ColoredRectangle)temporaryForms[e.Id]; r.End = e.Location; } break; case SKTouchAction.Released: if (temporaryForms.ContainsKey(e.Id)) { forms.Add(temporaryForms[e.Id]); asyncClient.Send((ColoredRectangle)temporaryForms[e.Id]); temporaryForms.Remove(e.Id); } break; case SKTouchAction.Cancelled: temporaryForms.Remove(e.Id); break; } }
private List <object> DictToFormsList(JArray content) { List <object> forms = new List <object>(); foreach (JObject coloredForm in content) { Dictionary <string, object> pdict = JsonConvert.DeserializeObject <Dictionary <string, object> >(coloredForm.ToString()); Dictionary <string, string> formElement = JsonConvert.DeserializeObject <Dictionary <string, string> >(pdict["content"].ToString()); switch (pdict["type"]) { case "LINE": ColoredLine line = DictToLine(formElement); forms.Add(line); break; case "CIRCLE": ColoredCircle circle = DictToCircle(formElement); forms.Add(circle); break; case "PATH": ColoredPath path = DictToPath(formElement); forms.Add(path); break; case "RECTANGLE": ColoredRectangle rectangle = DictToRectangle(formElement); forms.Add(rectangle); break; } } return(forms); }
private void UpdateLastStateRectangle(long milliseconds) { if (_lastStateRectangle.IsEmpty) { return; } int currentRow = (int)(milliseconds / _millisecondsPerRow); double positionInRow = (milliseconds % _millisecondsPerRow) / (double)_millisecondsPerRow; double rectangleTop = currentRow * _rowHeight + _marginInRow; if (currentRow == _lastRow) { _lastStateRectangle.Width = positionInRow - _lastStateRectangle.X; InvalidateRectangle(_lastStateRectangle); } else { _lastStateRectangle.Width = 1.0 - _lastStateRectangle.X; // Spans to end of row InvalidateRectangle(_lastStateRectangle); _oldStateRectangles.Add(_lastStateRectangle); _lastStateRectangle = new ColoredRectangle( _lastStateRectangle.Color, 0.0, rectangleTop, positionInRow, _rectangleHeight); InvalidateRectangle(_lastStateRectangle); } _lastRow = currentRow; _lastPositionInRow = positionInRow; }
public void CreateAndDispose() { ColoredRectangle box = null; TestAppOnce.Start((Renderer r) => box = new ColoredRectangle(r, HalfScreenRect, Color.Red)); Assert.AreEqual(Color.Red, box.Color); box.Dispose(); }
public LogoGame(Renderer render, Time time, Window window) { box = new ColoredRectangle(render, Point.Half, Size.Half, Color.Red); this.time = time; this.window = window; window.BackgroundColor = Color.CornflowerBlue; }
static World() { _darken = new ColoredRectangle { Color = Color.FromNonPremultiplied(0, 0, 0, 130), Transform = new Transform2(new Size2(1920, 1080)) }; }
public void Clear() { _lastStateRectangle = ColoredRectangle.Empty; _oldStateRectangles.Clear(); _instantRectangles.Clear(); _lastPositionInRow = 0.0; _lastRow = 0; CreateBackgroundBars(); Invalidate(); }
public void AddDrawSetColorRemove() { ColoredRectangle box = null; TestAppOnce.Start((Renderer r) => { box = new ColoredRectangle(r, HalfScreenRect, Color.Red); r.Add(box); r.DrawRectangle(box.Rect, Color.Green); r.Remove(box); }); box.Dispose(); }
public HealthBar(int maxWidth) { MaxWidth = maxWidth; HealthRectangle = new ColoredRectangle() { Color = UiColors.HealthBar_Health, Transform = _MakeHealthTransform() }; DamageRectangle = new ColoredRectangle() { Color = UiColors.HealthBar_Damage, Transform = _MakeDamageTranform() }; }
private void CreateBackgroundBars() { _oldStateRectangles.Clear(); for (int i = 0; i < NumberOfRows; ++i) { ColoredRectangle bar = new ColoredRectangle( BarColor, 0.0, _rowHeight * (i + (1 - BarHeightPercentage) / 2.0), 1.0, _rowHeight * BarHeightPercentage); _oldStateRectangles.Add(bar); } }
private JObject Jsonify(ColoredRectangle rectangle) { string colourHash = rectangle.Color.ToString(); float strokeWidth = rectangle.StrokeWidth; float x1 = rectangle.Start.X; float x2 = rectangle.End.X; float y1 = rectangle.Start.Y; float y2 = rectangle.End.Y; string coordinates = x1.ToString() + " " + x2.ToString() + " " + y1.ToString() + " " + y2.ToString(); JObject json = new JObject(new JProperty("type", "RECTANGLE"), new JProperty("content", new JObject( new JProperty("colorHash", colourHash), new JProperty("coordinates", coordinates), new JProperty("strokeWidth", strokeWidth)))); return(json); }
//Evenement déclenché quand une nouvelle forme ou instruction est reçue par le client private void UpdateUi(Object o, UpdateUIEventArgs eventArgs) { lock (forms) { switch (eventArgs.Type) { case "PATH": ColoredPath coloredPath = eventArgs.Path; forms.Add(coloredPath); break; case "CIRCLE": ColoredCircle coloredCircle = eventArgs.Circle; forms.Add(coloredCircle); break; case "LINE": ColoredLine coloredLine = eventArgs.Line; forms.Add(coloredLine); break; case "RECTANGLE": ColoredRectangle coloredRectangle = eventArgs.Rectangle; forms.Add(coloredRectangle); break; case "CLEAR": forms.Clear(); break; case "SIZE": width = eventArgs.Width; height = eventArgs.Height; break; case "REQUEST_STATUS": asyncClient.RestoreWhiteboard(this.forms, eventArgs.client_id); break; case "RESTORE": forms = eventArgs.Forms; break; } View.InvalidateSurface(); } }
public SkyVisualNote([NotNull] VisualBeatmap beatmap, [NotNull] SkyNote baseNote, [NotNull] ArcVisualNote parent, [NotNull] StageMetrics metrics) : base(beatmap, baseNote) { _metrics = metrics; Parent = parent; PreviewY = beatmap.CalculateY(baseNote.Tick, metrics, metrics.FinishLineY); var graphicsDevice = beatmap.GraphicsDevice; _graphicsDevice = graphicsDevice; _vertexBuffer1 = new VertexBuffer(graphicsDevice, VertexPositionColorTexture.VertexDeclaration, 16, BufferUsage.WriteOnly); _indexBuffer1 = new IndexBuffer(graphicsDevice, IndexElementSize.SixteenBits, 24, BufferUsage.WriteOnly); _vertexBuffer2 = new VertexBuffer(graphicsDevice, VertexPositionColorTexture.VertexDeclaration, 8, BufferUsage.WriteOnly); _indexBuffer2 = new IndexBuffer(graphicsDevice, IndexElementSize.SixteenBits, 12, BufferUsage.WriteOnly); var indices1 = new ushort[] { // bottom, top 0, 1, 2, 2, 1, 3, 4, 5, 6, 6, 5, 7, // front, back 8, 9, 10, 10, 9, 11, 12, 13, 14, 14, 13, 15 }; _indexBuffer1.SetData(indices1); var indices2 = new ushort[] { 0, 1, 2, 2, 1, 3, 4, 5, 6, 6, 5, 7, }; _indexBuffer2.SetData(indices2); _shadowRectangle = new ColoredRectangle(graphicsDevice); }
public void AddRunEvent(RunEvent runEvent) { Monitor.Enter(this); UpdateLastStateRectangle(runEvent.TimeTracked); double rectangleTop = _lastStateRectangle.IsEmpty ? _marginInRow : _lastStateRectangle.Y; ColoredRectangle newRectangle = new ColoredRectangle( _behaviorColorAssigner.GetBehaviorColor(runEvent.Behavior), _lastPositionInRow, rectangleTop, 0, _rectangleHeight); if (runEvent.Behavior.Type == Behavior.BehaviorType.Instant) { // Half margin for Instant events newRectangle.Y -= _marginInRow / 2.0; newRectangle.Height += _marginInRow; newRectangle.X -= InstantEventWidthPercentage / 2.0; newRectangle.Width += InstantEventWidthPercentage; _instantRectangles.Add(newRectangle); } else { if (!_lastStateRectangle.IsEmpty) { _oldStateRectangles.Add(_lastStateRectangle); } _lastStateRectangle = newRectangle; } InvalidateRectangle(newRectangle); Monitor.Exit(this); }
private void InvalidateRectangle(ColoredRectangle rectangle) { Invalidate(rectangle.MapToArea(Size)); }
private void DrawColoredRectangle(ColoredRectangle rectangle, PaintEventArgs e) { Brush brush = new SolidBrush(rectangle.Color); e.Graphics.FillRectangle(brush, rectangle.MapToArea(Size)); }
protected void InitExamplesAndUI() { bool initExamples = true; // add previous example button previousExampleButton = new Button("Back", ButtonSkin.Default, Anchor.BottomCenter, new Vector2(300, 50)); previousExampleButton.OnClick = (Entity btn) => { this.PreviousExample(); }; UserInterface.Active.AddEntity(previousExampleButton); // add new scenario button nextExampleButton = new Button("New Scenario", ButtonSkin.Default, Anchor.TopCenter, new Vector2(300, 50)); nextExampleButton.OnClick = (Entity btn) => { this.NextExample(); }; // add new hero button nextExampleButton1 = new Button("Embark", ButtonSkin.Default, Anchor.BottomCenter, new Vector2(300, 50)); nextExampleButton1.OnClick = (Entity btn) => { this.NextExample(); }; spriteBatch.Begin(); foreach (Tile t in tileset) { t.Draw(spriteBatch); } spriteBatch.End(); // add exit button Button exitBtn = new Button("Exit", anchor: Anchor.BottomCenter, size: new Vector2(300, 50)); exitBtn.OnClick = (Entity entity) => { Exit(); }; if (initExamples) { { int PanelHeight = 400; Panel Panel = new Panel(new Vector2(500, PanelHeight + 2), PanelSkin.Simple, Anchor.Center); panels.Add(Panel); UserInterface.Active.AddEntity(Panel); Panel.AddChild(nextExampleButton); Panel.AddChild(exitBtn); { var btn = new Button("Credits", ButtonSkin.Default, Anchor.Center, new Vector2(300, 50)); btn.OnClick += (GeonBit.UI.Entities.Entity entity) => { GeonBit.UI.Utils.MessageBox.ShowMsgBox("Hello World!", "This is a simple message box. It doesn't say much, really."); }; Panel.AddChild(btn); } } { int panelWidth = 730; // create panel and add to list of panels and manager Panel panel = new Panel(new Vector2(panelWidth, 550)); panels.Add(panel); UserInterface.Active.AddEntity(panel); // add title and text panel.AddChild(new Header("Create New Character")); panel.AddChild(new HorizontalLine()); // create an internal panel to align components better - a row that covers the entire width split into 3 columns (left, center, right) // first the container panel Panel entitiesGroup = new Panel(new Vector2(0, 240), PanelSkin.None, Anchor.AutoCenter); entitiesGroup.Padding = Vector2.Zero; panel.AddChild(entitiesGroup); // now left side Panel leftPanel = new Panel(new Vector2(0.33f, 0), PanelSkin.None, Anchor.TopLeft); leftPanel.Padding = Vector2.Zero; entitiesGroup.AddChild(leftPanel); // right side Panel rightPanel = new Panel(new Vector2(0.33f, 0), PanelSkin.None, Anchor.TopRight); rightPanel.Padding = Vector2.Zero; entitiesGroup.AddChild(rightPanel); // center Panel centerPanel = new Panel(new Vector2(0.33f, 0), PanelSkin.None, Anchor.TopCenter); centerPanel.Padding = Vector2.Zero; entitiesGroup.AddChild(centerPanel); // create a character preview panel centerPanel.AddChild(new Label(@"Preview", Anchor.AutoCenter)); Panel charPreviewPanel = new Panel(new Vector2(180, 180), PanelSkin.Simple, Anchor.AutoCenter); charPreviewPanel.Padding = Vector2.Zero; centerPanel.AddChild(charPreviewPanel); // create preview pics of character Image previewImage = new Image(Content.Load <Texture2D>("example/warrior"), Vector2.Zero, anchor: Anchor.Center); Image previewImageColor = new Image(Content.Load <Texture2D>("example/warrior_color"), Vector2.Zero, anchor: Anchor.Center); Image previewImageSkin = new Image(Content.Load <Texture2D>("example/warrior_skin"), Vector2.Zero, anchor: Anchor.Center); charPreviewPanel.AddChild(previewImage); charPreviewPanel.AddChild(previewImageColor); charPreviewPanel.AddChild(previewImageSkin); // add skin tone slider Slider skin = new Slider(0, 10, new Vector2(0, -1), SliderSkin.Default, Anchor.Auto); skin.OnValueChange = (Entity entity) => { Slider slider = (Slider)entity; int alpha = (int)(slider.GetValueAsPercent() * 255); previewImageSkin.FillColor = new Color(60, 32, 25, alpha); }; skin.Value = 5; charPreviewPanel.AddChild(skin); // create the class selection list leftPanel.AddChild(new Label(@"Class", Anchor.AutoCenter)); SelectList classTypes = new SelectList(new Vector2(0, 208), Anchor.Auto); classTypes.AddItem("Warrior"); classTypes.AddItem("Mage"); classTypes.AddItem("Ranger"); classTypes.AddItem("Monk"); classTypes.SelectedIndex = 0; leftPanel.AddChild(classTypes); classTypes.OnValueChange = (Entity entity) => { string texture = ((SelectList)(entity)).SelectedValue.ToLower(); previewImage.Texture = Content.Load <Texture2D>("example/" + texture); previewImageColor.Texture = Content.Load <Texture2D>("example/" + texture + "_color"); previewImageSkin.Texture = Content.Load <Texture2D>("example/" + texture + "_skin"); }; // create color selection buttons rightPanel.AddChild(new Label(@"Color", Anchor.AutoCenter)); Color[] colors = { Color.White, Color.Red, Color.Green, Color.Blue, Color.Yellow, Color.Purple, Color.Cyan, Color.Brown }; int colorPickSize = 24; foreach (Color baseColor in colors) { rightPanel.AddChild(new LineSpace(0)); for (int i = 0; i < 8; ++i) { Color color = baseColor * (1.0f - (i * 2 / 16.0f)); color.A = 255; ColoredRectangle currColorButton = new ColoredRectangle(color, Vector2.One * colorPickSize, Anchor.AutoInline); currColorButton.Padding = currColorButton.SpaceAfter = currColorButton.SpaceBefore = Vector2.Zero; currColorButton.OnClick = (Entity entity) => { previewImageColor.FillColor = entity.FillColor; }; rightPanel.AddChild(currColorButton); } } panel.AddChild(nextExampleButton1); // add character name, last name, and age // first add the labels entitiesGroup.AddChild(new Label(@"Name: ", Anchor.AutoInline, size: new Vector2(0.4f, -1))); // now add the text inputs // first name TextInput firstName = new TextInput(false, new Vector2(0.4f, -1), anchor: Anchor.Auto); firstName.PlaceholderText = "Name"; firstName.Validators.Add(new TextValidatorEnglishCharsOnly(true)); firstName.Validators.Add(new OnlySingleSpaces()); firstName.Validators.Add(new TextValidatorMakeTitle()); entitiesGroup.AddChild(firstName); } { int PanelHeight = 400; Panel Panel = new Panel(new Vector2(500, PanelHeight + 2), PanelSkin.Simple, Anchor.BottomRight); panels.Add(Panel); UserInterface.Active.AddEntity(Panel); } // init panels and buttons UpdateAfterExapmleChange(); } // call base initialize base.Initialize(); }
/// <summary> /// Create the top bar with next / prev buttons etc, and init all UI example panels. /// </summary> protected void InitExamplesAndUI() { // create top panel int topPanelHeight = 65; Panel topPanel = new Panel(new Vector2(0, topPanelHeight + 2), PanelSkin.Simple, Anchor.TopCenter); topPanel.Padding = Vector2.Zero; UIManager.AddEntity(topPanel); // add previous example button previousExampleButton = new Button("<- Back", ButtonSkin.Default, Anchor.TopLeft, new Vector2(300, topPanelHeight)); previousExampleButton.OnClick = (Entity btn) => { this.PreviousExample(); }; topPanel.AddChild(previousExampleButton); // add next example button nextExampleButton = new Button("Next ->", ButtonSkin.Default, Anchor.TopRight, new Vector2(300, topPanelHeight)); nextExampleButton.OnClick = (Entity btn) => { this.NextExample(); }; topPanel.AddChild(nextExampleButton); // add show-get button Button showGitButton = new Button("Git Repo", ButtonSkin.Fancy, Anchor.TopCenter, new Vector2(280, topPanelHeight)); showGitButton.OnClick = (Entity btn) => { System.Diagnostics.Process.Start("https://github.com/RonenNess/GeonBit.UI"); }; topPanel.AddChild(showGitButton); // add exit button Button exitBtn = new Button("Exit", anchor: Anchor.BottomRight, size: new Vector2(200, -1)); exitBtn.OnClick = (Entity entity) => { System.Environment.Exit(1); }; UIManager.AddEntity(exitBtn); // events panel for debug Panel eventsPanel = new Panel(new Vector2(400, 500), PanelSkin.Simple, Anchor.CenterLeft, new Vector2(-10, 0)); eventsPanel.Visible = false; // events log (single-time events) eventsPanel.AddChild(new Label("Events Log:")); SelectList eventsLog = new SelectList(size: new Vector2(-1, 280)); eventsLog.ExtraSpaceBetweenLines = -8; eventsLog.ItemsScale = 0.5f; eventsLog.Locked = true; eventsPanel.AddChild(eventsLog); // current events (events that happen while something is true) eventsPanel.AddChild(new Label("Current Events:")); SelectList eventsNow = new SelectList(size: new Vector2(-1, 100)); eventsNow.ExtraSpaceBetweenLines = -8; eventsNow.ItemsScale = 0.5f; eventsNow.Locked = true; eventsPanel.AddChild(eventsNow); // add the events panel UIManager.AddEntity(eventsPanel); // whenever events log list size changes, make sure its not too long. if it is, trim it. eventsLog.OnListChange = (Entity entity) => { SelectList list = (SelectList)entity; if (list.Count > 100) { list.RemoveItem(0); } }; // listen to all global events - one timers UserInterface.OnClick = (Entity entity) => { eventsLog.AddItem("Click: " + entity.GetType().Name); eventsLog.scrollToEnd(); }; UserInterface.OnMouseDown = (Entity entity) => { eventsLog.AddItem("MouseDown: " + entity.GetType().Name); eventsLog.scrollToEnd(); }; UserInterface.OnMouseEnter = (Entity entity) => { eventsLog.AddItem("MouseEnter: " + entity.GetType().Name); eventsLog.scrollToEnd(); }; UserInterface.OnMouseLeave = (Entity entity) => { eventsLog.AddItem("MouseLeave: " + entity.GetType().Name); eventsLog.scrollToEnd(); }; UserInterface.OnMouseReleased = (Entity entity) => { eventsLog.AddItem("MouseReleased: " + entity.GetType().Name); eventsLog.scrollToEnd(); }; UserInterface.OnMouseWheelScroll = (Entity entity) => { eventsLog.AddItem("Scroll: " + entity.GetType().Name); eventsLog.scrollToEnd(); }; UserInterface.OnStartDrag = (Entity entity) => { eventsLog.AddItem("StartDrag: " + entity.GetType().Name); eventsLog.scrollToEnd(); }; UserInterface.OnStopDrag = (Entity entity) => { eventsLog.AddItem("StopDrag: " + entity.GetType().Name); eventsLog.scrollToEnd(); }; UserInterface.OnValueChange = (Entity entity) => { if (entity.Parent == eventsLog) { return; } eventsLog.AddItem("ValueChanged: " + entity.GetType().Name); eventsLog.scrollToEnd(); }; // clear the current events after every frame they were drawn eventsNow.AfterDraw = (Entity entity) => { eventsNow.ClearItems(); }; // listen to all global events - happening now UserInterface.WhileDragging = (Entity entity) => { eventsNow.AddItem("Dragging: " + entity.GetType().Name); eventsNow.scrollToEnd(); }; UserInterface.WhileMouseDown = (Entity entity) => { eventsNow.AddItem("MouseDown: " + entity.GetType().Name); eventsNow.scrollToEnd(); }; UserInterface.WhileMouseHover = (Entity entity) => { eventsNow.AddItem("MouseHover: " + entity.GetType().Name); eventsNow.scrollToEnd(); }; // add extra info button Button infoBtn = new Button(" Events", anchor: Anchor.BottomLeft, size: new Vector2(280, -1), offset: new Vector2(140, 0)); infoBtn.AddChild(new Icon(IconType.Scroll, Anchor.CenterLeft), true); infoBtn.OnClick = (Entity entity) => { eventsPanel.Visible = !eventsPanel.Visible; }; UIManager.AddEntity(infoBtn); // zoom in / out factor float zoominFactor = 0.05f; // scale show Paragraph scaleShow = new Paragraph("100%", Anchor.BottomLeft, offset: new Vector2(10, 70)); UIManager.AddEntity(scaleShow); // init zoom-out button Button zoomout = new Button("", ButtonSkin.Default, Anchor.BottomLeft, new Vector2(70, 70)); Icon zoomoutIcon = new Icon(IconType.ZoomOut, Anchor.Center, 0.75f); zoomout.AddChild(zoomoutIcon, true); zoomout.OnClick = (Entity btn) => { if (UserInterface.SCALE > 0.5f) { UserInterface.SCALE -= zoominFactor; } scaleShow.Text = ((int)System.Math.Round(UserInterface.SCALE * 100f)).ToString() + "%"; }; UIManager.AddEntity(zoomout); // init zoom-in button Button zoomin = new Button("", ButtonSkin.Default, Anchor.BottomLeft, new Vector2(70, 70), new Vector2(70, 0)); Icon zoominIcon = new Icon(IconType.ZoomIn, Anchor.Center, 0.75f); zoomin.AddChild(zoominIcon, true); zoomin.OnClick = (Entity btn) => { if (UserInterface.SCALE < 1.45f) { UserInterface.SCALE += zoominFactor; } scaleShow.Text = ((int)System.Math.Round(UserInterface.SCALE * 100f)).ToString() + "%"; }; UIManager.AddEntity(zoomin); // init all examples // example: welcome message { // create panel and add to list of panels and manager Panel panel = new Panel(new Vector2(500, 650)); panels.Add(panel); UIManager.AddEntity(panel); // add title and text Image title = new Image(Content.Load <Texture2D>("example/GeonBitUI-sm"), new Vector2(400, 240), anchor: Anchor.TopCenter, offset: new Vector2(0, -20)); title.ShadowColor = Color.Black; title.ShadowOffset = Vector2.One * -3; panel.AddChild(title); panel.AddChild(new Paragraph(@"Welcome to GeonBit UI! This UI is part of the GeonBit project. It provide a simple yet extensive UI for MonoGame based projects. To start the demo, please click the 'Next' button on the top navbar.")); } // example: featues list { // create panel and add to list of panels and manager Panel panel = new Panel(new Vector2(500, 640)); panels.Add(panel); UIManager.AddEntity(panel); // add title and text panel.AddChild(new Header("Widgets Types")); panel.AddChild(new HorizontalLine()); panel.AddChild(new Paragraph(@"GeonBit.UI implements the following widgets: - Paragraphs - Headers - Buttons - Panels - CheckBox - Radio buttons - Rectangles - Images & Icons - Select List - Dropdown - Panel Tabs - Sliders & Progressbars - Text input - And more... ")); } // example: basic concepts { // create panel and add to list of panels and manager Panel panel = new Panel(new Vector2(740, 680)); panels.Add(panel); UIManager.AddEntity(panel); // add title and text panel.AddChild(new Header("Basic Concepts")); panel.AddChild(new HorizontalLine()); panel.AddChild(new Paragraph(@"Panels are the basic containers of GeonBit.UI. They are like window forms. To position elements inside panels or other widgets, you set an anchor and offset. An anchor is a pre-defined position in parent element, like top-left corner, center, etc. and offset is just the distance from that point. Another thing to keep in mind is size; Most widgets come with a default size, but for those you need to set size for remember that setting size 0 will take full width / height. For example, size of X = 0, Y = 100 means the widget will be 100 pixels height and the width of its parent (minus the parent padding).")); } // example: anchors { // create panel and add to list of panels and manager Panel panel = new Panel(new Vector2(800, 650)); panels.Add(panel); UIManager.AddEntity(panel); // add title and text panel.AddChild(new Paragraph(@"Anchors help position elements. For example, this paragraph anchor is 'center'. The most common anchors are 'Auto' and 'AutoInline', which will place entities one after another automatically.", Anchor.Center, Color.White, 0.8f, new Vector2(320, 0))); panel.AddChild(new Header("Anchors", Anchor.TopCenter, new Vector2(0, 100))); panel.AddChild(new Paragraph("top-left", Anchor.TopLeft, Color.Yellow, 0.8f)); panel.AddChild(new Paragraph("top-center", Anchor.TopCenter, Color.Yellow, 0.8f)); panel.AddChild(new Paragraph("top-right", Anchor.TopRight, Color.Yellow, 0.8f)); panel.AddChild(new Paragraph("bottom-left", Anchor.BottomLeft, Color.Yellow, 0.8f)); panel.AddChild(new Paragraph("bottom-center", Anchor.BottomCenter, Color.Yellow, 0.8f)); panel.AddChild(new Paragraph("bottom-right", Anchor.BottomRight, Color.Yellow, 0.8f)); panel.AddChild(new Paragraph("center-left", Anchor.CenterLeft, Color.Yellow, 0.8f)); panel.AddChild(new Paragraph("center-right", Anchor.CenterRight, Color.Yellow, 0.8f)); } // example: buttons { // create panel and add to list of panels and manager Panel panel = new Panel(new Vector2(450, 700)); panels.Add(panel); UIManager.AddEntity(panel); // add title and text panel.AddChild(new Header("Buttons")); panel.AddChild(new HorizontalLine()); panel.AddChild(new Paragraph("GeonBit.UI comes with 3 button skins:")); // add default buttons panel.AddChild(new Button("Default", ButtonSkin.Default)); panel.AddChild(new Button("Alternative", ButtonSkin.Alternative)); panel.AddChild(new Button("Fancy", ButtonSkin.Fancy)); // custom button Button custom = new Button("Custom Skin", ButtonSkin.Default, size: new Vector2(0, 80)); custom.SetCustomSkin( Content.Load <Texture2D>("example/btn_default"), Content.Load <Texture2D>("example/btn_hover"), Content.Load <Texture2D>("example/btn_down")); panel.AddChild(custom); // toggle button panel.AddChild(new LineSpace()); panel.AddChild(new HorizontalLine()); panel.AddChild(new LineSpace()); panel.AddChild(new Paragraph("Note: buttons can also work in toggle mode:")); Button btn = new Button("Toggle Me!", ButtonSkin.Default); btn.ToggleMode = true; panel.AddChild(btn); } // example: checkboxes and radio buttons { // create panel and add to list of panels and manager Panel panel = new Panel(new Vector2(450, 570)); panels.Add(panel); UIManager.AddEntity(panel); // checkboxes example panel.AddChild(new Header("CheckBox")); panel.AddChild(new HorizontalLine()); panel.AddChild(new Paragraph("CheckBoxes example:")); panel.AddChild(new CheckBox("CheckBox 1")); panel.AddChild(new CheckBox("CheckBox 2")); // radio example panel.AddChild(new LineSpace(3)); panel.AddChild(new Header("Radio buttons")); panel.AddChild(new HorizontalLine()); panel.AddChild(new Paragraph("Radio buttons example:")); panel.AddChild(new RadioButton("Option 1")); panel.AddChild(new RadioButton("Option 2")); panel.AddChild(new RadioButton("Option 3")); } // example: panels { // create panel and add to list of panels and manager Panel panel = new Panel(new Vector2(450, 660)); panels.Add(panel); UIManager.AddEntity(panel); // title and text panel.AddChild(new Header("Panels")); panel.AddChild(new HorizontalLine()); panel.AddChild(new Paragraph("GeonBit.UI comes with 4 alternative panel skins:")); int panelHeight = 110; { Panel intPanel = new Panel(new Vector2(0, panelHeight), PanelSkin.Fancy, Anchor.Auto); intPanel.AddChild(new Paragraph("Fancy Panel", Anchor.Center)); panel.AddChild(intPanel); } { Panel intPanel = new Panel(new Vector2(0, panelHeight), PanelSkin.Golden, Anchor.Auto); intPanel.AddChild(new Paragraph("Golden Panel", Anchor.Center)); panel.AddChild(intPanel); } { Panel intPanel = new Panel(new Vector2(0, panelHeight), PanelSkin.Simple, Anchor.Auto); intPanel.AddChild(new Paragraph("Simple Panel", Anchor.Center)); panel.AddChild(intPanel); } { Panel intPanel = new Panel(new Vector2(0, panelHeight), PanelSkin.ListBackground, Anchor.Auto); intPanel.AddChild(new Paragraph("List Background", Anchor.Center)); panel.AddChild(intPanel); } } // example: draggable { // create panel and add to list of panels and manager Panel panel = new Panel(new Vector2(450, 690)); panel.Draggable = true; panels.Add(panel); UIManager.AddEntity(panel); // title and text panel.AddChild(new Header("Draggable")); panel.AddChild(new HorizontalLine()); panel.AddChild(new Paragraph("This panel can be dragged, try it out!")); panel.AddChild(new LineSpace()); panel.AddChild(new HorizontalLine()); panel.AddChild(new LineSpace()); Paragraph paragraph = new Paragraph("Note that any type of entity can become draggable. For example, try to drag this paragraph!"); paragraph.SetStyleProperty("FillColor", new StyleProperty(Color.Yellow)); paragraph.SetStyleProperty("FillColor", new StyleProperty(Color.Purple), EntityState.MouseHover); paragraph.Draggable = true; paragraph.LimitDraggingToParentBoundaries = false; panel.AddChild(paragraph); // internal panel with internal draggable Panel panelInt = new Panel(new Vector2(250, 250), PanelSkin.Golden, Anchor.AutoCenter); panelInt.Draggable = true; panelInt.AddChild(new Paragraph("This panel is draggable too, but limited to its parent boundaries.", Anchor.Center, Color.White, 0.85f)); panel.AddChild(panelInt); } // example: sliders { // create panel and add to list of panels and manager Panel panel = new Panel(new Vector2(450, 600)); panels.Add(panel); UIManager.AddEntity(panel); // sliders title panel.AddChild(new Header("Sliders")); panel.AddChild(new HorizontalLine()); panel.AddChild(new Paragraph("Sliders help pick numeric value in range:")); panel.AddChild(new Paragraph("\nDefault slider")); panel.AddChild(new Slider(0, 10, SliderSkin.Default)); panel.AddChild(new Paragraph("\nFancy slider")); panel.AddChild(new Slider(0, 10, SliderSkin.Fancy)); // progressbar title panel.AddChild(new LineSpace(3)); panel.AddChild(new Header("Progress bar")); panel.AddChild(new HorizontalLine()); panel.AddChild(new Paragraph("Works just like sliders:")); panel.AddChild(new ProgressBar(0, 10)); } // example: lists { // create panel and add to list of panels and manager Panel panel = new Panel(new Vector2(450, 480)); panels.Add(panel); UIManager.AddEntity(panel); // list title panel.AddChild(new Header("SelectList")); panel.AddChild(new HorizontalLine()); panel.AddChild(new Paragraph("SelectLists let you pick a value from a list of items:")); SelectList list = new SelectList(new Vector2(0, 250)); list.AddItem("Warrior"); list.AddItem("Mage"); list.AddItem("Ranger"); list.AddItem("Rogue"); list.AddItem("Paladin"); list.AddItem("Cleric"); list.AddItem("Warlock"); list.AddItem("Barbarian"); list.AddItem("Monk"); list.AddItem("Ranger"); panel.AddChild(list); } // example: lists skins { // create panel and add to list of panels and manager Panel panel = new Panel(new Vector2(450, 480)); panels.Add(panel); UIManager.AddEntity(panel); // list title panel.AddChild(new Header("SelectList - Skin")); panel.AddChild(new HorizontalLine()); panel.AddChild(new Paragraph("Just like panels, SelectList can also use alternative skins:")); SelectList list = new SelectList(new Vector2(0, 250), skin: PanelSkin.Golden); list.AddItem("Warrior"); list.AddItem("Mage"); list.AddItem("Ranger"); list.AddItem("Rogue"); list.AddItem("Paladin"); list.AddItem("Cleric"); list.AddItem("Warlock"); list.AddItem("Barbarian"); list.AddItem("Monk"); list.AddItem("Ranger"); panel.AddChild(list); } // example: dropdown { // create panel and add to list of panels and manager Panel panel = new Panel(new Vector2(450, 480)); panels.Add(panel); UIManager.AddEntity(panel); // dropdown title panel.AddChild(new Header("DropDown")); panel.AddChild(new HorizontalLine()); panel.AddChild(new Paragraph("DropDown is just like a list, but take less space since it hide the list when not used:")); DropDown drop = new DropDown(new Vector2(0, 280)); drop.AddItem("Warrior"); drop.AddItem("Mage"); drop.AddItem("Ranger"); drop.AddItem("Rogue"); drop.AddItem("Paladin"); drop.AddItem("Cleric"); drop.AddItem("Warlock"); drop.AddItem("Barbarian"); drop.AddItem("Monk"); drop.AddItem("Ranger"); panel.AddChild(drop); panel.AddChild(new Paragraph("And like list, we can set different skins:")); drop = new DropDown(new Vector2(0, 240), skin: PanelSkin.Golden); drop.AddItem("Warrior"); drop.AddItem("Mage"); drop.AddItem("Ranger"); panel.AddChild(drop); } // example: icons { // create panel and add to list of panels and manager Panel panel = new Panel(new Vector2(460, 670)); panels.Add(panel); UIManager.AddEntity(panel); // icons title panel.AddChild(new Header("Icons")); panel.AddChild(new HorizontalLine()); panel.AddChild(new Paragraph("GeonBit.UI comes with some built-in icons:")); foreach (IconType icon in System.Enum.GetValues(typeof(IconType))) { if (icon == IconType.None) { continue; } panel.AddChild(new Icon(icon, Anchor.AutoInline)); } panel.AddChild(new Paragraph("And you can also add an inventory-like frame:")); for (int i = 0; i < 6; ++i) { panel.AddChild(new Icon((IconType)i, Anchor.AutoInline, 1, true)); } } // example: text input { // create panel and add to list of panels and manager Panel panel = new Panel(new Vector2(450, 590)); panels.Add(panel); UIManager.AddEntity(panel); // text input example panel.AddChild(new Header("Text Input")); panel.AddChild(new HorizontalLine()); // inliner panel.AddChild(new Paragraph("Text input let you get free text from the user:"******"Insert text.."; panel.AddChild(text); // multiline panel.AddChild(new Paragraph("Text input can also be multiline, and use different panel skins:")); TextInput textMulti = new TextInput(true, new Vector2(0, 220), skin: PanelSkin.Golden); textMulti.PlaceholderText = @"Insert multiline text.."; panel.AddChild(textMulti); } // example: locked text input { // create panel and add to list of panels and manager Panel panel = new Panel(new Vector2(500, 590)); panels.Add(panel); UIManager.AddEntity(panel); // text input example panel.AddChild(new Header("Locked Text Input")); panel.AddChild(new HorizontalLine()); // inliner panel.AddChild(new Paragraph("A locked multiline text is a cool trick to create long, scrollable text:")); TextInput textMulti = new TextInput(true, new Vector2(0, 370)); textMulti.Locked = true; textMulti.TextParagraph.Scale = 0.6f; textMulti.Value = @"The Cleric, Priest, or Bishop is a character class in Dungeons & Dragons and other fantasy role-playing games. The cleric is a healer, usually a priest and a holy warrior, originally modeled on or inspired by the Military Orders. Clerics are usually members of religious orders, with the original intent being to portray soldiers of sacred orders who have magical abilities, although this role was later taken more clearly by the paladin. Most clerics have powers to heal wounds, protect their allies and sometimes resurrect the dead, as well as summon, manipulate and banish undead. A description of Priests and Priestesses from the Nethack guidebook: Priests and Priestesses are clerics militant, crusaders advancing the cause of righteousness with arms, armor, and arts thaumaturgic. Their ability to commune with deities via prayer occasionally extricates them from peril, but can also put them in it.[1] A common feature of clerics across many games is that they may not equip pointed weapons such as swords or daggers, and must use blunt weapons such as maces, war-hammers, shields or wand instead. This is based on a popular, but erroneous, interpretation of the depiction of Odo of Bayeux and accompanying text. They are also often limited in what types of armor they can wear, though usually not as restricted as mages. Related to the cleric is the paladin, who is typically a Lawful Good[citation needed] warrior often aligned with a religious order, and who uses their martial skills to advance its holy cause."; panel.AddChild(textMulti); } // example: panel tabs { // create panel and add to list of panels and manager Panel panel = new Panel(new Vector2(540, 480)); panels.Add(panel); UIManager.AddEntity(panel); // create panel tabs PanelTabs tabs = new PanelTabs(); panel.AddChild(tabs); // add first panel { PanelTabs.TabData tab = tabs.AddTab("Tab 1"); tab.panel.AddChild(new Header("PanelTabs")); tab.panel.AddChild(new HorizontalLine()); tab.panel.AddChild(new Paragraph(@"PanelTab creates a group of internal panels with toggle buttons to switch between them. Choose a tab in the buttons above for more info...")); } // add second panel { PanelTabs.TabData tab = tabs.AddTab("Tab 2"); tab.panel.AddChild(new Header("Tab 2")); tab.panel.AddChild(new HorizontalLine()); tab.panel.AddChild(new Paragraph(@"Awesome, you got to tab2! Maybe something interesting in tab3?")); } // add third panel { PanelTabs.TabData tab = tabs.AddTab("Tab 3"); tab.panel.AddChild(new Header("Nope.")); tab.panel.AddChild(new HorizontalLine()); tab.panel.AddChild(new Paragraph("Nothing to see here.")); } } // example: disabled { // create panel and add to list of panels and manager Panel panel = new Panel(new Vector2(480, 650)); panel.Disabled = true; panels.Add(panel); UIManager.AddEntity(panel); // disabled title panel.AddChild(new Header("Disabled")); panel.AddChild(new HorizontalLine()); panel.AddChild(new Paragraph("Entities can be disabled:")); // internal panel Panel panel2 = new Panel(Vector2.Zero, PanelSkin.None, Anchor.Auto); panel2.Padding = Vector2.Zero; panel.AddChild(panel2); panel2.AddChild(new Button("button")); for (int i = 0; i < 6; ++i) { panel2.AddChild(new Icon((IconType)i, Anchor.AutoInline, 1, true, new Vector2(12, 6))); } panel2.AddChild(new Paragraph("\nDisabled entities are drawn in black & white, and you cannot interact with them..")); SelectList list = new SelectList(new Vector2(0, 130)); list.AddItem("Warrior"); list.AddItem("Mage"); panel2.AddChild(list); panel2.AddChild(new CheckBox("disabled..")); } // example: Locked { // create panel and add to list of panels and manager Panel panel = new Panel(new Vector2(520, 680)); panels.Add(panel); UIManager.AddEntity(panel); // locked title panel.AddChild(new Header("Locked")); panel.AddChild(new HorizontalLine()); panel.AddChild(new Paragraph("Entities can also be locked:", Anchor.Auto)); Panel panel2 = new Panel(Vector2.Zero, PanelSkin.None, Anchor.Auto); panel2.Padding = Vector2.Zero; panel2.Locked = true; panel.AddChild(panel2); panel2.AddChild(new Button("button")); for (int i = 0; i < 6; ++i) { panel2.AddChild(new Icon((IconType)i, Anchor.AutoInline, 1, true, new Vector2(12, 6))); } panel2.AddChild(new Paragraph("\nLocked entities will not respond to input, but unlike disabled entities they are drawn normally, eg with colors:")); SelectList list = new SelectList(new Vector2(0, 130)); list.AddItem("Warrior"); list.AddItem("Mage"); panel2.AddChild(list); panel2.AddChild(new CheckBox("locked..")); } // example: Misc { // create panel and add to list of panels and manager Panel panel = new Panel(new Vector2(530, 650)); panels.Add(panel); UIManager.AddEntity(panel); // misc title panel.AddChild(new Header("Miscellaneous")); panel.AddChild(new HorizontalLine()); panel.AddChild(new Paragraph("Some cool tricks you can do:")); // button with icon Button btn = new Button("Button With Icon"); btn.ButtonParagraph.SetPosition(Anchor.CenterLeft, new Vector2(60, 0)); btn.AddChild(new Icon(IconType.Book, Anchor.CenterLeft), true); panel.AddChild(btn); // change progressbar color panel.AddChild(new Paragraph("Different PrograssBar colors:")); ProgressBar pb = new ProgressBar(); pb.ProgressFill.FillColor = Color.Red; panel.AddChild(pb); // paragraph style with mouse panel.AddChild(new LineSpace()); panel.AddChild(new HorizontalLine()); Paragraph paragraph = new Paragraph("Hover / click styling.."); paragraph.SetStyleProperty("FillColor", new StyleProperty(Color.Purple), EntityState.MouseDown); paragraph.SetStyleProperty("FillColor", new StyleProperty(Color.Red), EntityState.MouseHover); panel.AddChild(paragraph); panel.AddChild(new HorizontalLine()); // colored rectangle panel.AddChild(new Paragraph("Colored rectangle:")); ColoredRectangle rect = new ColoredRectangle(Color.Blue, Color.Red, 4, new Vector2(0, 40)); panel.AddChild(rect); panel.AddChild(new HorizontalLine()); // custom icons panel.AddChild(new Paragraph("Custom icons / images:")); Icon icon = new Icon(IconType.None, Anchor.AutoInline, 1, true, new Vector2(12, 10)); icon.Texture = Content.Load <Texture2D>("example/warrior"); panel.AddChild(icon); icon = new Icon(IconType.None, Anchor.AutoInline, 1, true, new Vector2(12, 10)); icon.Texture = Content.Load <Texture2D>("example/monk"); panel.AddChild(icon); icon = new Icon(IconType.None, Anchor.AutoInline, 1, true, new Vector2(12, 10)); icon.Texture = Content.Load <Texture2D>("example/mage"); panel.AddChild(icon); } // example: character build page - intro { // create panel and add to list of panels and manager Panel panel = new Panel(new Vector2(500, 380)); panels.Add(panel); UIManager.AddEntity(panel); // add title and text panel.AddChild(new Header("Final Example")); panel.AddChild(new HorizontalLine()); panel.AddChild(new Paragraph(@"The next example will show a fully-functional character creation page, that use different entities, events, etc. Click on 'Next' to see the character creation demo.")); } // example: character build page - final { int panelWidth = 730; // create panel and add to list of panels and manager Panel panel = new Panel(new Vector2(panelWidth, 570)); panels.Add(panel); UIManager.AddEntity(panel); // add title and text panel.AddChild(new Header("Create New Character")); panel.AddChild(new HorizontalLine()); // create an internal panel to align components better - a row that covers the entire width split into 3 columns (left, center, right) // first the container panel Panel entitiesGroup = new Panel(new Vector2(0, 240), PanelSkin.None, Anchor.AutoCenter); entitiesGroup.Padding = Vector2.Zero; panel.AddChild(entitiesGroup); // now left side Panel leftPanel = new Panel(new Vector2(0.33f, 0), PanelSkin.None, Anchor.TopLeft); leftPanel.Padding = Vector2.Zero; entitiesGroup.AddChild(leftPanel); // right side Panel rightPanel = new Panel(new Vector2(0.33f, 0), PanelSkin.None, Anchor.TopRight); rightPanel.Padding = Vector2.Zero; entitiesGroup.AddChild(rightPanel); // center Panel centerPanel = new Panel(new Vector2(0.33f, 0), PanelSkin.None, Anchor.TopCenter); centerPanel.Padding = Vector2.Zero; entitiesGroup.AddChild(centerPanel); // create a character preview panel centerPanel.AddChild(new Label(@"Preview", Anchor.AutoCenter)); Panel charPreviewPanel = new Panel(new Vector2(180, 180), PanelSkin.Simple, Anchor.AutoCenter); charPreviewPanel.Padding = Vector2.Zero; centerPanel.AddChild(charPreviewPanel); // create preview pics of character Image previewImage = new Image(Content.Load <Texture2D>("example/warrior"), Vector2.Zero, anchor: Anchor.Center); Image previewImageColor = new Image(Content.Load <Texture2D>("example/warrior_color"), Vector2.Zero, anchor: Anchor.Center); Image previewImageSkin = new Image(Content.Load <Texture2D>("example/warrior_skin"), Vector2.Zero, anchor: Anchor.Center); charPreviewPanel.AddChild(previewImage); charPreviewPanel.AddChild(previewImageColor); charPreviewPanel.AddChild(previewImageSkin); // add skin tone slider Slider skin = new Slider(0, 10, new Vector2(0, -1), SliderSkin.Default, Anchor.Auto); skin.OnValueChange = (Entity entity) => { Slider slider = (Slider)entity; int alpha = (int)(slider.GetValueAsPercent() * 255); previewImageSkin.FillColor = new Color(60, 32, 25, alpha); }; skin.Value = 5; charPreviewPanel.AddChild(skin); // create the class selection list leftPanel.AddChild(new Label(@"Class", Anchor.AutoCenter)); SelectList classTypes = new SelectList(new Vector2(0, 208), Anchor.Auto); classTypes.AddItem("Warrior"); classTypes.AddItem("Mage"); classTypes.AddItem("Ranger"); classTypes.AddItem("Monk"); classTypes.SelectedIndex = 0; leftPanel.AddChild(classTypes); classTypes.OnValueChange = (Entity entity) => { string texture = ((SelectList)(entity)).SelectedValue.ToLower(); previewImage.Texture = Content.Load <Texture2D>("example/" + texture); previewImageColor.Texture = Content.Load <Texture2D>("example/" + texture + "_color"); previewImageSkin.Texture = Content.Load <Texture2D>("example/" + texture + "_skin"); }; // create color selection buttons rightPanel.AddChild(new Label(@"Color", Anchor.AutoCenter)); Color[] colors = { Color.White, Color.Red, Color.Green, Color.Blue, Color.Yellow, Color.Purple, Color.Cyan, Color.Brown }; int colorPickSize = 24; foreach (Color baseColor in colors) { rightPanel.AddChild(new LineSpace()); for (int i = 0; i < 8; ++i) { Color color = baseColor * (1.0f - (i * 2 / 16.0f)); color.A = 255; ColoredRectangle currColorButton = new ColoredRectangle(color, Vector2.One * colorPickSize, Anchor.AutoInline); currColorButton.SpaceAfter = currColorButton.SpaceBefore = Vector2.Zero; currColorButton.OnClick = (Entity entity) => { previewImageColor.FillColor = entity.FillColor; }; rightPanel.AddChild(currColorButton); } } // gender selection (radio buttons) entitiesGroup.AddChild(new LineSpace()); entitiesGroup.AddChild(new RadioButton("Male", Anchor.Auto, new Vector2(180, 60), isChecked: true)); entitiesGroup.AddChild(new RadioButton("Female", Anchor.AutoInline, new Vector2(240, 60))); // hardcore mode Button hardcore = new Button("Hardcore", ButtonSkin.Fancy, Anchor.AutoInline, new Vector2(220, 60)); hardcore.ButtonParagraph.Scale = 0.8f; hardcore.ToggleMode = true; entitiesGroup.AddChild(hardcore); entitiesGroup.AddChild(new HorizontalLine()); // add character name, last name, and age // first add the labels entitiesGroup.AddChild(new Label(@"First Name: ", Anchor.AutoInline, size: new Vector2(0.4f, -1))); entitiesGroup.AddChild(new Label(@"Last Name: ", Anchor.AutoInline, size: new Vector2(0.4f, -1))); entitiesGroup.AddChild(new Label(@"Age: ", Anchor.AutoInline, size: new Vector2(0.2f, -1))); // now add the text inputs // first name TextInput firstName = new TextInput(false, new Vector2(0.4f, -1), anchor: Anchor.Auto); firstName.PlaceholderText = "Name"; firstName.Validators.Add(new TextValidatorEnglishCharsOnly()); firstName.Validators.Add(new TextValidatorMakeTitle()); entitiesGroup.AddChild(firstName); // last name TextInput lastName = new TextInput(false, new Vector2(0.4f, -1), anchor: Anchor.AutoInline); lastName.PlaceholderText = "Surname"; lastName.Validators.Add(new TextValidatorEnglishCharsOnly()); lastName.Validators.Add(new TextValidatorMakeTitle()); entitiesGroup.AddChild(lastName); // age TextInput age = new TextInput(false, new Vector2(0.2f, -1), anchor: Anchor.AutoInline); age.Validators.Add(new TextValidatorNumbersOnly(false, 0, 80)); age.Value = "20"; entitiesGroup.AddChild(age); } // example: epilogue { // create panel and add to list of panels and manager Panel panel = new Panel(new Vector2(500, 560)); panels.Add(panel); UIManager.AddEntity(panel); // add title and text panel.AddChild(new Header("End Of Examples")); panel.AddChild(new HorizontalLine()); panel.AddChild(new Paragraph(@"That's it for now! There is still much to learn about GeonBit.UI, but these examples were enough to get you going. To learn more, please visit the git repo, read the docs, or go through some source code. If you liked GeonBit.UI feel free to star the repo on GitHub. :)")); } // init panels and buttons UpdateAfterExapmleChange(); // once done init, clear events log eventsLog.ClearItems(); // call base initialize base.Initialize(); }
private void ReceivePackage(Object o, PacketReceivedEventArgs eventArgs) { Dictionary <string, object> pdict = JsonConvert.DeserializeObject <Dictionary <string, object> >(eventArgs.data); Dictionary <string, string> content;; UpdateUIEventArgs UiEventArgs; switch (pdict["type"]) { case "PATH": content = JsonConvert.DeserializeObject <Dictionary <string, string> >(pdict["content"].ToString()); ColoredPath path = DictToPath(content); UiEventArgs = new UpdateUIEventArgs { Type = "PATH", Path = path }; UpdateUIEventHandler.OnUpdateUI(this, UiEventArgs); break; case "CIRCLE": content = JsonConvert.DeserializeObject <Dictionary <string, string> >(pdict["content"].ToString()); ColoredCircle circle = DictToCircle(content); UiEventArgs = new UpdateUIEventArgs { Type = "CIRCLE", Circle = circle }; UpdateUIEventHandler.OnUpdateUI(this, UiEventArgs); break; case "LINE": content = JsonConvert.DeserializeObject <Dictionary <string, string> >(pdict["content"].ToString()); ColoredLine line = DictToLine(content); UiEventArgs = new UpdateUIEventArgs { Type = "LINE", Line = line }; UpdateUIEventHandler.OnUpdateUI(this, UiEventArgs); break; case "REQUEST_STATUS": //Called for the host, when a new client is requesting the whiteboard's current state content = JsonConvert.DeserializeObject <Dictionary <string, string> >(pdict["content"].ToString()); int id = int.Parse(content["id"]); //the id corresponds to the client's id from the server's perspective UiEventArgs = new UpdateUIEventArgs { Type = "REQUEST_STATUS", client_id = id }; UpdateUIEventHandler.OnUpdateUI(this, UiEventArgs); break; case "RECTANGLE": content = JsonConvert.DeserializeObject <Dictionary <string, string> >(pdict["content"].ToString()); ColoredRectangle rectangle = DictToRectangle(content); UiEventArgs = new UpdateUIEventArgs { Rectangle = rectangle, Type = "RECTANGLE" }; UpdateUIEventHandler.OnUpdateUI(this, UiEventArgs); break; case "SIZE": content = JsonConvert.DeserializeObject <Dictionary <string, string> >(pdict["content"].ToString()); float w = float.Parse(content["width"]); float h = float.Parse(content["height"]); UiEventArgs = new UpdateUIEventArgs { Width = w, Height = h, Type = "SIZE" }; UpdateUIEventHandler.OnUpdateUI(this, UiEventArgs); break; case "CLEAR": UiEventArgs = new UpdateUIEventArgs { Type = "CLEAR" }; UpdateUIEventHandler.OnUpdateUI(this, UiEventArgs); break; case "RESTORE": JArray jArray = JArray.Parse(pdict["content"].ToString()); List <object> forms = DictToFormsList(jArray); UiEventArgs = new UpdateUIEventArgs { Type = "RESTORE", Forms = forms }; UpdateUIEventHandler.OnUpdateUI(this, UiEventArgs); break; default: Console.WriteLine("error parsing received data: {0}", eventArgs.data); throw new ArgumentException(eventArgs.data); } }
public void Send(ColoredRectangle rectangle) { JObject json = Jsonify(rectangle); SendData(json); }