public void RemoveComponent(IGuiComponent component) { if (_components.Contains(component)) { _components.Remove(component); } }
public void AddComponent(IGuiComponent component) { if (component == null) { return; } Vector2 newPosition = GetPosition(); foreach (IGuiComponent child in childComponents) { Size2 childSize = child.GetSize(); if (_orientation == Orientation.Horizontal) { newPosition.X += _margin + childSize.Width; } else { newPosition.Y += _margin + childSize.Height; } } component.SetPosition(newPosition); childComponents.Add(component); }
public void Unfocus(IGuiComponent newFocus = null) { if (Parent != null) { Parent.FocusChild = newFocus; } }
/// <summary> /// Removes focus for currently focused control. /// </summary> public void RemoveFocus() { if (_currentFocus == null) { return; } _currentFocus = null; }
protected void ClearFocus() { if (inner_focus != null) { inner_focus.Focus = false; inner_focus = null; } }
/// <summary> /// Removes focus for given control if control has focus. /// </summary> public void RemoveFocus(IGuiComponent remFocus) { if (_currentFocus != remFocus) { return; } _currentFocus = null; }
private void Add_Component_Button_Click(object sender, RoutedEventArgs e) { IGuiComponent element = CurrentlyChosenComponent.getNewInstance(); if (gridModifier.AddComponentForCurrentSelection((UIElement)element)) { ElementsCollection.Add(element); } }
//TODO Holy shit make this not complete crap. Oh man. /// <summary> /// Sets focus for a component. /// </summary> public void SetFocus(IGuiComponent newFocus) { if (_currentFocus != null) { RemoveFocus(); } _currentFocus = newFocus; newFocus.Focus = true; }
public void AddChild(IGuiComponent child) { if (child.Parent != null) { child.Parent.Children.Remove(child); } child.Parent = this; Children.Add(child); ComputeAbsoluteSizePosition(); }
/// <summary> /// Calls the custom Update Method for Components. This allows components to update ui elements if they implement the the needed method. /// </summary> public void ComponentUpdate(GuiComponentType componentType, params object[] args) { IGuiComponent firstOrDefault = (from IGuiComponent comp in _components where comp.ComponentClass == componentType select comp).FirstOrDefault(); if (firstOrDefault != null) { firstOrDefault.ComponentUpdate(args); } }
private void Remove_Component_Button_Click(object sender, RoutedEventArgs e) { try { IGuiComponent removedElement = ElementsCollection.Last <IGuiComponent>(); ElementsCollection.Remove(removedElement); gridModifier.RemoveComponent((UIElement)removedElement); } catch (InvalidOperationException ex) { System.Console.WriteLine("No element on the stack"); } }
//TODO Holy shit make this not complete crap. Oh man. /// <summary> /// Sets focus for a component. /// </summary> public void SetFocus(IGuiComponent newFocus) { if (_currentFocus != null) { _currentFocus.Focus = false; _currentFocus = newFocus; newFocus.Focus = true; } else { _currentFocus = newFocus; newFocus.Focus = true; } }
protected void SetFocus(IGuiComponent newFocus) { if (inner_focus != null) { inner_focus.Focus = false; inner_focus = newFocus; newFocus.Focus = true; } else { inner_focus = newFocus; newFocus.Focus = true; } }
/// <summary> /// Handles MouseWheelMove event. Sent to Focused component. Returns true if component accepted and handled the event. /// </summary> public virtual void MouseWheelMove(MouseWheelEventArgs e) { if (_console.IsVisible()) { _console.MouseWheelMove(e); } IGuiComponent inputTo = (from IGuiComponent comp in _components where comp.RecieveInput where comp.Focus select comp).FirstOrDefault(); if (inputTo != null) { inputTo.MouseWheelMove(e); } }
//The game states have to feed the UI Input!!! This is to allow more flexibility. //Maybe this should be handled in the main methods for input. But then the state wouldnt have power over //this and things like the chat might get difficult. //Other Notes: When a component returns true to an input event the loop stops and so only that control recieves the input. // That way we don't have all components reacting to one event. /// <summary> /// Handles MouseDown event. Returns true if a component accepted and handled the event. /// </summary> public virtual bool MouseDown(MouseButtonEventArgs e) { if (_console.IsVisible()) { if (_console.MouseDown(e)) { return(true); } } if (moveMode) { foreach (IGuiComponent comp in _components) { if (comp.ClientArea.Contains(e.X, e.Y)) { movingComp = comp; dragOffset = (new Vector2i(e.X, e.Y)) - new Vector2i(comp.ClientArea.Left, comp.ClientArea.Top); break; } } return(true); } else { IOrderedEnumerable <IGuiComponent> inputList = from IGuiComponent comp in _components where comp.RecieveInput orderby comp.ZDepth ascending orderby comp.IsVisible() descending //Invisible controls still recieve input but after everyone else. This is mostly for the inventory and other toggleable components. orderby comp.Focus descending select comp; foreach (IGuiComponent current in inputList) { if (current.MouseDown(e)) { SetFocus(current); return(true); } } return(false); } }
/// <summary> /// Handles MouseUp event. Returns true if a component accepted and handled the event. /// </summary> public virtual bool MouseUp(MouseButtonEventArgs e) { if (_console.IsVisible()) { if (_console.MouseUp(e)) { return(true); } } if (moveMode) { if (movingComp != null) { movingComp = null; } return(true); } else { IOrderedEnumerable <IGuiComponent> inputList = from IGuiComponent comp in _components where comp.RecieveInput orderby comp.ZDepth ascending orderby comp.IsVisible() descending //Invisible controls still recieve input but after everyone else. This is mostly for the inventory and other toggleable components. orderby comp.Focus descending select comp; if (inputList.Any(current => current.MouseUp(e))) { return(true); } if (DragInfo.IsActive) //Drag & dropped into nothing or invalid. Remove dragged obj. { DragInfo.Reset(); } return(false); } }
public void AddComponent(IGuiComponent component) { Components.Add(component); OnPropertyChanged("Components"); }
protected override void OnLoad(EventArgs e) { _graphicsDevice = new GraphicsDevice(this); VSync = VSyncMode.On; spriteBatch = new SpriteBatch(_graphicsDevice); GL.ClearColor(0.1f, 0.2f, 0.5f, 0.0f); GL.Enable(EnableCap.DepthTest); ContentManager content = new ContentManager(new ServiceProvider(), @"..\..\..\Content\"); content.RegisterTypeReader <BitmapFont>(new SpriteFontReader(Shaders.FontShader)); _font = content.Get <BitmapFont>(@"SourceCodePro16.meb").Content as BitmapFont; _graphicsDevice.DebugBatch.DefaultFont = _font; System.Drawing.Bitmap bmp = new System.Drawing.Bitmap("checkbox16on.png"); _checkBoxOn = Texture2D.Create(bmp); bmp = new System.Drawing.Bitmap("checkbox16off.png"); _checkBoxOff = Texture2D.Create(bmp); bmp = new System.Drawing.Bitmap("slider16.png"); _trackSprite = Texture2D.Create(bmp); bmp = new System.Drawing.Bitmap("sliderknob16.png"); _thumbSprite = Texture2D.Create(bmp); bmp = new System.Drawing.Bitmap("buttons.png"); Texture2D buttons = Texture2D.Create(bmp); bmp = new System.Drawing.Bitmap("disk.png"); Texture2D disk = Texture2D.Create(bmp); //projectionMatrix = Matrix4.CreateOrthographicOffCenter(0, _graphicsDevice.ViewPort.Width, _graphicsDevice.ViewPort.Height, 0, 0, 1); world = Matrix4.Scale(0.5f) * Matrix4.CreateTranslation(0, -1.5f, 0); _graphicsDevice.Camera = new GuiCamera(_graphicsDevice); _graphicsDevice.DebugBatch.ScreenCamera = _graphicsDevice.Camera; _graphicsDevice.DebugBatch.WorldCamera = _graphicsDevice.Camera; _guiRoot = new GuiComponent(_graphicsDevice.Width, _graphicsDevice.Height); // { Position = new Vector2(100, 100) }; _checkBox = new CheckBox("Test Check Box", new Binding(this, "Check"), new Sprite(_checkBoxOn, 0, 0, 0, 0), new Sprite(_checkBoxOff, 0, 0, 0, 0), _font); Label label = new Label("test label", _font); // { Position = new Vector2(0, 50)}; Sprite trackSprite = new Sprite(_trackSprite, 0, 0, 0, 0); Sprite thumbSprite = new Sprite(_thumbSprite, 0, 0, 0, 0); FloatValue = 0f; Slider slider = new Slider("Test slider: {0:0.00}", new Binding(this, "FloatValue"), 0f, 1f, trackSprite, thumbSprite, _font); SlicedSprite buttonNormal = new SlicedSprite(buttons, 0, 0, 30, 30, 2); SlicedSprite buttonHover = new SlicedSprite(buttons, 0, 32, 30, 30, 2); SlicedSprite buttonPressed = new SlicedSprite(buttons, 0, 64, 30, 30, 2); Button button = new Button("Button.", buttonNormal, buttonHover, buttonPressed, new Sprite(disk, 0, 0, 0, 0), _font); button.Click += (o, ev) => System.Diagnostics.Debug.WriteLine("Button Pressed!!!!"); StackPanel hpanel = new StackPanel(Dimension.Vertical); Panel panel = new Panel(Color4.Gray, 1f) { Color = new Color4(128, 128, 128, 63), Position = new Vector2(100, 100), Margin = 5 }; hpanel.AddChild(_checkBox); hpanel.AddChild(label); hpanel.AddChild(slider); hpanel.AddChild(button); panel.AddChild(hpanel); _guiRoot.AddChild(panel); //debugGuis.Add(button); Mouse.ButtonUp += new EventHandler <MouseButtonEventArgs>(OnButtonUp); Mouse.ButtonDown += new EventHandler <MouseButtonEventArgs>(OnButtonDown); Mouse.Move += new EventHandler <MouseMoveEventArgs>(OnMouseMove); _depthTexture = new Texture2D(800, 600, PixelInternalFormat.DepthComponent, PixelFormat.DepthComponent, PixelType.Float); _screenTexture = new Texture2D(800, 600); //_fbo = new FrameBuffer(_graphicsDevice, new Texture2D[] { _screenTexture }, _depthTexture); string vsSrc = @"#version 150 uniform mat4 WorldViewProj; in vec3 Position; in vec3 Color; in vec2 TexCoord; noperspective out vec2 fragTexCoord; void main() { fragTexCoord = TexCoord; gl_Position = WorldViewProj * vec4(Position, 1); } "; string fsSrc = @"#version 150 uniform sampler2D Texture; uniform vec4 Diffuse = vec4(1); noperspective in vec2 fragTexCoord; out vec4 finalColor; void main() { float n = 1.0; // camera z near float f = 100.0; // camera z far float z = texture(Texture, fragTexCoord).x; float d = (2.0 * n) / (f + n - z * (f - n)); finalColor = vec4(d,d,d,1); } "; wireframeShader = new Program(vsSrc, fsSrc); }
public void AddVisual(IGuiComponent component) { RenderComponent = component; }
public void AddComponent(IGuiComponent component) { _components.Add(component); }
public static SKSize GetSize(this IGuiComponent component) { return(new SKSize(component.Width, component.Height)); }