/// <summary> /// Creates a scroll bar with the specified orientation, value, extent, and maximum. /// </summary> /// <param name="orientation"></param> /// <param name="value"></param> /// <param name="extent">The size of the viewable area (a.k.a visible amount)</param> /// <param name="max"></param> public G2DScrollBar(GoblinEnums.Orientation orientation, int value, int extent, int max) : base() { if (value < 0) { throw new ArgumentException("value has to be greater than or equal to 0"); } if (extent > max) { throw new ArgumentException("extent must be smaller than max"); } this.orientation = orientation; this.extent = extent; upLeftButton = new G2DButton(); downRightButton = new G2DButton(); if (orientation == GoblinEnums.Orientation.Horizontal) { upLeftButton.ActionPerformedEvent += new ActionPerformed(DecrementUnit); downRightButton.ActionPerformedEvent += new ActionPerformed(IncrementUnit); } else { upLeftButton.ActionPerformedEvent += new ActionPerformed(IncrementUnit); downRightButton.ActionPerformedEvent += new ActionPerformed(DecrementUnit); } scrollBar = new G2DSlider(0, max - extent, value); scrollBar.Orientation = orientation; scrollBar.PaintTrack = false; scrollBar.SnapToTicks = true; scrollBar.BackgroundColor = Color.White; scrollBar.StateChangedEvent += new StateChanged(ValueChanged); buttonColor = Color.DarkBlue; unitIncrement = 1; blockIncrement = 1; scrollBar.MinorTickSpacing = blockIncrement; }
private void CreateControlPanel() { objectFrame = new G2DPanel(); objectFrame.Bounds = new Rectangle(670, State.Height - 200, 120, 190); objectFrame.Border = GoblinEnums.BorderFactory.LineBorder; objectFrame.BorderColor = Color.Gold; // Ranges from 0 (fully transparent) to 1 (fully opaque) objectFrame.Transparency = 0.5f; //Label for rotation G2DLabel label1 = new G2DLabel("Object Rotates along:"); label1.TextFont = textFont; label1.Bounds = new Rectangle(5, 5, 80, 20); // Create radio button for x-axis rotation. G2DRadioButton radioX = new G2DRadioButton("x-axis"); radioX.TextFont = textFont; radioX.Bounds = new Rectangle(5, 15, 80, 20); radioX.ActionPerformedEvent += new ActionPerformed(HandleActionPerformedAxisX); // Create radio button for y-axis rotation. G2DRadioButton radioY = new G2DRadioButton("y-axis"); radioY.TextFont = textFont; radioY.Bounds = new Rectangle(5, 30, 80, 20); radioY.ActionPerformedEvent += new ActionPerformed(HandleActionPerformedAxisY); // Create radio button for z-axis rotation. G2DRadioButton radioZ = new G2DRadioButton("z-axis"); radioZ.TextFont = textFont; radioZ.Bounds = new Rectangle(5, 45, 80, 20); radioZ.ActionPerformedEvent += new ActionPerformed(HandleActionPerformedAxisZ); //Create a ButtonGroup object which controls the radio button selections group1 = new ButtonGroup(); group1.Add(radioX); group1.Add(radioY); group1.Add(radioZ); //Label for rotation direction. G2DLabel label2 = new G2DLabel("Rotation Direction:"); label2.TextFont = textFont; label2.Bounds = new Rectangle(5, 65, 80, 20); // Create radio button for clockwise G2DRadioButton clockwise = new G2DRadioButton("Clockwise"); clockwise.TextFont = textFont; clockwise.Bounds = new Rectangle(5, 80, 80, 20); clockwise.ActionPerformedEvent += new ActionPerformed(HandleActionPerformedDirection); // Create radio button for counterclockwise. G2DRadioButton counterclockwise = new G2DRadioButton("Counterclockwise"); counterclockwise.TextFont = textFont; counterclockwise.Bounds = new Rectangle(5, 95, 80, 20); counterclockwise.ActionPerformedEvent += new ActionPerformed(HandleActionPerformedDirection); //Create a ButtonGroup object which controls the radio button selections. group2 = new ButtonGroup(); group2.Add(clockwise); group2.Add(counterclockwise); //Label for speed G2DLabel label3 = new G2DLabel("Rotation Speed:"); label3.TextFont = textFont; label3.Bounds = new Rectangle(5, 115, 80, 20); //Slider for speed of rotation slider = new G2DSlider(); slider.TextFont = textFont; slider.Bounds = new Rectangle(5, 145, 110, 20); slider.Maximum = 8; slider.Minimum = 0; slider.MajorTickSpacing = 0; slider.MinorTickSpacing = 1; slider.Value = 0; slider.PaintTicks = true; slider.PaintLabels = true; slider.StateChangedEvent += new StateChanged(HandleStateChangedSpeed); G2DButton reset = new G2DButton("Reset"); reset.Bounds = new Rectangle(5, 165, 55, 20); reset.TextFont = textFont; reset.ActionPerformedEvent += new ActionPerformed(HandleActionReset); G2DButton rotate = new G2DButton("Rotate"); rotate.Bounds = new Rectangle(65, 165, 50, 20); rotate.ActionPerformedEvent += new ActionPerformed(HandleActionRotate); rotate.TextFont = textFont; objectFrame.AddChild(label1); objectFrame.AddChild(radioX); objectFrame.AddChild(radioY); objectFrame.AddChild(radioZ); objectFrame.AddChild(label2); objectFrame.AddChild(clockwise); objectFrame.AddChild(counterclockwise); objectFrame.AddChild(label3); objectFrame.AddChild(slider); objectFrame.AddChild(reset); objectFrame.AddChild(rotate); scene.UIRenderer.Add2DComponent(objectFrame); }
private void CreateSolar2DGUI() { // Create the main panel which holds all other GUI components G2DPanel frame = new G2DPanel(); frame.Bounds = new Rectangle(10, State.Height - 170, 90, 160); frame.Border = GoblinEnums.BorderFactory.LineBorder; frame.BorderColor = Color.Gold; // Ranges from 0 (fully transparent) to 1 (fully opaque) frame.Transparency = 0.2f; //Label for the panel. G2DLabel label1 = new G2DLabel("Camera Control"); label1.TextFont = textFont2; label1.Bounds = new Rectangle(5, 2, 80, 15); //Label for the first slider. G2DLabel label2 = new G2DLabel("-4 x-axis 4"); label2.TextFont = textFont1; label2.Bounds = new Rectangle(5, 15, 80, 15); // Create a slider (moving camera along x axis). G2DSlider slider1 = new G2DSlider(); slider1.TextFont = textFont1; slider1.Bounds = new Rectangle(5, 40, 80, 15); slider1.Maximum = 4; slider1.Minimum = -4; slider1.MajorTickSpacing = 0; slider1.MinorTickSpacing = 1; slider1.Value = 0; slider1.PaintTicks = true; slider1.PaintLabels = true; slider1.StateChangedEvent += new StateChanged(HandleStateChanged1); //Label for the second slider G2DLabel label3 = new G2DLabel("-4 y-axis 4"); label3.TextFont = textFont1; label3.Bounds = new Rectangle(5, 65, 80, 15); // Create a slider (moving camera along y axis). G2DSlider slider2 = new G2DSlider(); slider2.TextFont = textFont1; slider2.Bounds = new Rectangle(5, 90, 80, 15); slider2.Maximum = 4; slider2.Minimum = -4; slider2.MajorTickSpacing = 0; slider2.MinorTickSpacing = 1; slider2.Value = 0; slider2.PaintTicks = true; slider2.PaintLabels = true; slider2.StateChangedEvent += new StateChanged(HandleStateChanged2); //Label for the third slider. G2DLabel label4 = new G2DLabel("-4 z-axis 4"); label4.TextFont = textFont1; label4.Bounds = new Rectangle(5, 115, 80, 15); // Create a slider (moving camera along z axis). G2DSlider slider3 = new G2DSlider(); slider3.TextFont = textFont1; slider3.Bounds = new Rectangle(5, 140, 80, 15); slider3.Maximum = 4; slider3.Minimum = -4; slider3.MajorTickSpacing = 0; slider3.MinorTickSpacing = 1; slider3.Value = 0; slider3.PaintTicks = true; slider3.PaintLabels = true; slider3.StateChangedEvent += new StateChanged(HandleStateChanged3); //Add labels and sliders to the frame frame.AddChild(label1); frame.AddChild(label2); frame.AddChild(label3); frame.AddChild(label4); frame.AddChild(slider1); frame.AddChild(slider2); frame.AddChild(slider3); //Render the frame and add the frame to the scene. scene.UIRenderer.Add2DComponent(frame); }
private void Create2DGUI() { // Create the main panel which holds all other GUI components G2DPanel frame = new G2DPanel(); frame.Bounds = new Rectangle(325, State.Height - 180, 150, 170); frame.Border = GoblinEnums.BorderFactory.LineBorder; frame.Transparency = 0.7f; // Ranges from 0 (fully transparent) to 1 (fully opaque) label = "User Interfaces"; // Loads the fonts used for rendering UI labels and slider labels uiFont = Content.Load<SpriteFont>("UIFont"); sliderFont = Content.Load<SpriteFont>("SliderFont"); // Create four Radio Buttons G2DRadioButton radio1 = new G2DRadioButton("User Interfaces"); radio1.TextFont = uiFont; radio1.Bounds = new Rectangle(10, 5, 80, 20); radio1.DoClick(); // make this radio button selected initially radio1.ActionPerformedEvent += new ActionPerformed(HandleActionPerformed); G2DRadioButton radio2 = new G2DRadioButton("Computer Graphics"); radio2.TextFont = uiFont; radio2.Bounds = new Rectangle(10, 25, 80, 20); radio2.ActionPerformedEvent += new ActionPerformed(HandleActionPerformed); G2DRadioButton radio3 = new G2DRadioButton("Augmented Reality"); radio3.TextFont = uiFont; radio3.Bounds = new Rectangle(10, 45, 80, 20); radio3.ActionPerformedEvent += new ActionPerformed(HandleActionPerformed); sliderRadio = new G2DRadioButton("Slider Control"); sliderRadio.TextFont = uiFont; sliderRadio.Bounds = new Rectangle(10, 65, 80, 20); sliderRadio.ActionPerformedEvent += new ActionPerformed(HandleActionPerformed); // Create a slider G2DSlider slider = new G2DSlider(); slider.TextFont = sliderFont; slider.Bounds = new Rectangle(5, 100, 140, 30); slider.Maximum = 40; slider.MajorTickSpacing = 20; slider.MinorTickSpacing = 5; slider.PaintTicks = true; slider.PaintLabels = true; slider.StateChangedEvent += new StateChanged(HandleStateChanged); // Create a ButtonGroup object which controls the radio // button selections ButtonGroup group = new ButtonGroup(); group.Add(radio1); group.Add(radio2); group.Add(radio3); group.Add(sliderRadio); // Create a Button G2DButton button = new G2DButton("I Love"); button.TextFont = uiFont; button.Bounds = new Rectangle(50, 145, 50, 20); button.ActionPerformedEvent += new ActionPerformed(HandleActionPerformed); // Add all of the components to the main panel frame.AddChild(radio1); frame.AddChild(radio2); frame.AddChild(radio3); frame.AddChild(sliderRadio); frame.AddChild(button); frame.AddChild(slider); scene.UIRenderer.Add2DComponent(frame); }
/// <summary> /// Creates a scroll bar with the specified orientation, value, extent, and maximum. /// </summary> /// <param name="orientation"></param> /// <param name="value"></param> /// <param name="extent">The size of the viewable area (a.k.a visible amount)</param> /// <param name="max"></param> public G2DScrollBar(GoblinEnums.Orientation orientation, int value, int extent, int max) : base() { if (value < 0) throw new ArgumentException("value has to be greater than or equal to 0"); if (extent > max) throw new ArgumentException("extent must be smaller than max"); this.orientation = orientation; this.extent = extent; upLeftButton = new G2DButton(); downRightButton = new G2DButton(); if (orientation == GoblinEnums.Orientation.Horizontal) { upLeftButton.ActionPerformedEvent += new ActionPerformed(DecrementUnit); downRightButton.ActionPerformedEvent += new ActionPerformed(IncrementUnit); } else { upLeftButton.ActionPerformedEvent += new ActionPerformed(IncrementUnit); downRightButton.ActionPerformedEvent += new ActionPerformed(DecrementUnit); } scrollBar = new G2DSlider(0, max - extent, value); scrollBar.Orientation = orientation; scrollBar.PaintTrack = false; scrollBar.SnapToTicks = true; scrollBar.BackgroundColor = Color.White; scrollBar.StateChangedEvent += new StateChanged(ValueChanged); buttonColor = Color.DarkBlue; unitIncrement = 1; blockIncrement = 1; scrollBar.MinorTickSpacing = blockIncrement; }