예제 #1
0
파일: Widget.cs 프로젝트: Ziple/NOubliezPas
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="manager_">Gui manager to associate the widget with.</param>
        /// <param name="parent_">widget's parent</param>
        public Widget(UIManager manager_, Widget parent_)
        {
            if (manager_ == null)
                throw new Exception("The manager is null");

            myManager = manager_;
            Parent = parent_;

            // notify the wm that this widget type exists.
            Manager.RegisterWidgetType("Widget", null);
        }
예제 #2
0
        /// <summary>
        /// Returns the maximum size that can use a chikld without any parent resizing.
        /// Must be implemented by widgets like layouts, frames etc...
        /// </summary>
        /// <param name="child">Child willing to resize</param>
        /// <returns>Maximum size that can occupy the child.</returns>
        public override Vector2f GetMaxSizeForChild(Widget child)
        {
            float maxSizeY = Size.Y;
            foreach (Widget widget in Widgets)
            {
                if (widget.Visible && widget != child)
                    maxSizeY -= widget.Size.Y;
            }

            return new Vector2f(Size.X, maxSizeY);
        }
예제 #3
0
파일: Layout.cs 프로젝트: Ziple/NOubliezPas
        /// <summary>
        /// Adds a widget at the end.
        /// When you add a widget to a layout, it's Position will be changed
        /// to fit with the one the layout want to assign to it.
        /// </summary>
        public void Add(Widget obj)
        {
            obj.Parent = this;
            widgets.Add(obj);

            // No need to update size if the widget isn't visible.
            if (obj.Visible)
            {
                updateSize();
                updatePositions();
            }
        }
예제 #4
0
파일: Label.cs 프로젝트: Ziple/NOubliezPas
        public BasicLabel(UIManager manager_, Widget parent_, DCFont font, TextStyle style, Color color, string str, uint size = 30 )
            : base(manager_, parent_)
        {
            Manager.RegisterWidgetType("BasicLabel", "Widget");

            myFont = font;
            myText = str;
            myTextSize = size;
            myStyle = style;
            myTextColor = color;
            updateSize();
        }
예제 #5
0
        /// <summary>
        /// If possible, gives the focus to the specified widget.
        /// It's possible that the widget that owned previously the focus
        /// REFUSE to give the focus to the one you want to give it.
        /// It's also possible that the desired receiver REFUSES
        /// to get the focus.
        /// If you pass a null reference in focusReceiver, then no one
        /// widget will get the focus from this player.
        /// </summary>
        /// <param name="index">Associated player to the focus.</param>
        /// <param name="focusReceiver">New receiver of the focus.</param>
        /// <returns>True if the widget received the focus, false otherwise.</returns>
        public bool SetFocus(Widget focusReceiver)
        {
            FocusChangedEvent evt = new FocusChangedEvent(FocusChangedEvent.FocusStateChange.LostFocus);

            Widget oldFocusedWidget = myFocusedWidget;

            // the old owner of the focus can refuse the lost of the focus.
            if (oldFocusedWidget != null)
            {
                oldFocusedWidget.OnEvent(evt);

                if (evt.Accepted)
                {
                    oldFocusedWidget.OnFocusChangedEvent(evt);

                    if (evt.Accepted)
                        myFocusedWidget = null;
                }
            }

            // the old owner is ready to loose focus
            // or there is no old owner.
            if (evt.Accepted && focusReceiver != null)
            {
                if (HasFocus(focusReceiver) == false)
                {
                    // the focus receiver doesn't have the focus from another player.
                    evt.StateChange = FocusChangedEvent.FocusStateChange.GainedFocus;

                    focusReceiver.OnEvent(evt);

                    if (evt.Accepted)
                    {
                        focusReceiver.OnFocusChangedEvent(evt);
                        if (evt.Accepted)
                        {
                            //the widget has accepted the focus.
                            myFocusedWidget = focusReceiver;
                        }
                    }
                }
                else
                    evt.Accepted = false;//the receiver has the focus from another player.
            }

            return evt.Accepted;
        }
예제 #6
0
 /// <summary>
 /// Must be called by a widget if it doesn't have any parent.
 /// Will affect the style of the widget by applying the default style to it.
 /// </summary>
 /// <param name="widget"></param>
 public void ManageWidget(Widget widget)
 {
     if (widget != null)
         myManagedWidgets.Add(widget);
 }
예제 #7
0
파일: Widget.cs 프로젝트: Ziple/NOubliezPas
 /// <summary>
 /// Called when the child has finished its resize operation.
 /// </summary>
 /// <param name="child"></param>
 /// <param name="size"></param>
 public virtual void EndChildResize(Widget child, Vector2f size)
 {
 }
예제 #8
0
파일: Widget.cs 프로젝트: Ziple/NOubliezPas
 /// <summary>
 /// Called by the child to notice that it wants
 /// to change its size or Visibility.
 /// </summary>
 /// <param name="child">Child willing to resize.</param>
 /// <param name="requestedSize">Size the child wants in the widget.</param>
 /// <returns>True if resizement granted, false otherwise.</returns>
 public bool ResizeForChild(Widget child, Vector2f requestedSize)
 {
     // May be position of the child widget has changed
     // and we just want to update the parent accordingly
     // so we musn't check if requestedSize is the same as before
     // in the view to NOT froward properly the event.
     ChildResizeEvent ev = new ChildResizeEvent(child, requestedSize);
     OnEvent(ev);
     if (ev.Accepted)
     {
         OnChildResizeEvent(ev);
         if (ev.Accepted)
         {
             // We actually need to resize.
             if (ev.NecessaryParentSize.X > Size.X || ev.NecessaryParentSize.Y > Size.Y)
             {
                 // Tries to resize to the given size.
                 Vector2f newSize = Resize(ev.NecessaryParentSize);
                 // Check if we resized enough to place the widget in...
                 if (newSize.X < ev.NecessaryParentSize.X || newSize.Y < ev.NecessaryParentSize.Y)
                     return false;
             }
             return true;
         }
     }
     return false;
 }
예제 #9
0
파일: Label.cs 프로젝트: Ziple/NOubliezPas
 public Label(UIManager manager_, Widget parent_, DCFont font, string str, uint size = 30 )
     : base(manager_, parent_)
 {
     Manager.RegisterWidgetType("Label", "Widget");
     myCharacterSize = size;
     Font = font;
     Text = str;
 }
예제 #10
0
 public HorizontalSpacer(UIManager manager_, Widget parent_)
     : base(manager_, parent_)
 {
     Manager.RegisterWidgetType("HorizontalSpacer", "Widget");
 }
예제 #11
0
        /// <summary>
        /// Place the widget as much as possible on the top of the rendering stack.
        /// </summary>
        /// <param name="widget">Widget to push on top of the rendering stack.</param>
        void PushWidgetOnTop(Widget widget)
        {
            if (myManagedWidgets.Contains(widget) && myManagedWidgets.Count > 1 )
            {
                int index = myManagedWidgets.FindIndex(delegate(Widget widget_) { return widget_ == widget; });
                myManagedWidgets.RemoveAt(index);

                RenderingOrderChangedEvent evt = new RenderingOrderChangedEvent(RenderingOrderChangedEvent.RenderingOrderChange.RenderedLater);

                //now we must find a new place for this poor widget ;)
                for (int i = myManagedWidgets.Count - 1; i >= 0; i--)
                {
                    evt.Accepted = true;
                    myManagedWidgets[i].OnEvent(evt);

                    if (evt.Accepted)
                    {
                        myManagedWidgets[i].OnRenderingOrderChangedEvent(evt);

                        if (evt.Accepted)
                        {
                            myManagedWidgets.Insert(i + 1, widget);
                            break;
                        }
                    }
                }
            }
        }
예제 #12
0
파일: Layout.cs 프로젝트: Ziple/NOubliezPas
        /// <summary>
        /// Adds a widget at the specified index.
        /// When you insert a widget to a layout, it's Position will be changed
        /// to fit with the one the layout want to assign to it.
        /// </summary>
        public void Insert(Int32 index, Widget obj)
        {
            obj.Parent = this;
            widgets.Insert(index, obj);

            // No need to update size if the widget isn't visible.
            if (obj.Visible)
            {
                updateSize();
                updatePositions();
            }
        }
예제 #13
0
 /// <summary>
 /// Detailed constructor.
 /// </summary>
 /// <param name="manager_"></param>
 /// <param name="parent_"></param>
 /// <param name="imagePart"></param>
 public Caption(UIManager manager_, Widget parent_, ImagePart imagePart )
     : base(manager_, parent_)
 {
     Manager.RegisterWidgetType("Caption", "Widget");
     ImagePart = imagePart;
 }
예제 #14
0
 /// <summary>
 /// Default construtor too.
 /// </summary>
 /// <param name="manager_"></param>
 /// <param name="parent_"></param>
 public Caption(UIManager manager_, Widget parent_)
     : base(manager_, parent_)
 {
     Manager.RegisterWidgetType("Caption", "Widget");
 }
예제 #15
0
파일: Widget.cs 프로젝트: Ziple/NOubliezPas
 /// <summary>
 /// Method that must be implemented if you have a widget that contains widgets.
 /// This method compute the new widget size so that the child widget can be
 /// resized.
 /// </summary>
 /// <param name="child">Child widget requesting the resizement.</param>
 /// <param name="requestedSize">Size requested by the widget.</param>
 /// <returns></returns>
 protected virtual Vector2f _computeNewSizeForChild(Widget child, Vector2f requestedSize)
 {
     return new Vector2f(0f,0f);
 }
예제 #16
0
파일: Widget.cs 프로젝트: Ziple/NOubliezPas
 /// <summary>
 /// Remove a widget from the children list.
 /// </summary>
 /// <param name="widget">child to remove.</param>
 protected void RemoveChild(Widget widget)
 {
     myChildrenWidgets.Remove(widget);
 }
예제 #17
0
파일: Widget.cs 프로젝트: Ziple/NOubliezPas
 /// <summary>
 /// Add a widget to the children list.
 /// </summary>
 /// <param name="widget">child to add</param>
 protected void AddChild(Widget widget)
 {
     myChildrenWidgets.Add(widget);
 }
예제 #18
0
 /// <summary>
 /// Must be called if a widget gain a parent.
 /// </summary>
 /// <param name="widget"></param>
 public void UnmanageWidget(Widget widget)
 {
     if (myManagedWidgets.Contains(widget))
         myManagedWidgets.Remove(widget);
 }
예제 #19
0
        /// <summary>
        /// Update all the managed widgets according to the input devices states.
        /// </summary>
        /// <param name="gameTime">game time reference</param>
        public void Update(Stopwatch gameTime)
        {
            /// Dispatch the hovering events.
            Widget receiver = PickWidget(myCursor.Position);
            if (myHoveredWidget != receiver)
            {
                if (myHoveredWidget != null)
                {
                    HoverEndEvent evt = new HoverEndEvent();

                    // the old owner of the focus can refuse the lost of the focus.
                    myHoveredWidget.OnEvent(evt);

                    if (evt.Accepted)
                        myHoveredWidget.OnHoverEndEvent(evt);
                }

                myHoveredWidget = receiver;
                if (receiver != null)
                {
                    HoverEvent evt = new HoverEvent();

                    // the old owner of the focus can refuse the lost of the focus.
                    receiver.OnEvent(evt);

                    if (evt.Accepted)
                        receiver.OnHoverEvent(evt);
                }
            }

            foreach (Widget widget in myManagedWidgets)
            {
                UpdateEvent raisedEvent = new UpdateEvent(gameTime);
                widget.OnEvent(raisedEvent);

                if (raisedEvent.Accepted)
                    widget.OnUpdate(raisedEvent);
            }
        }
예제 #20
0
파일: Layout.cs 프로젝트: Ziple/NOubliezPas
        /// <summary>Removes the widget from the layout.</summary>
        public void Remove(Widget obj)
        {
            obj.Parent = null;
            widgets.Remove(obj);

            // No need to update size if the widget wasn't visible.
            if (obj.Visible)
            {
                updateSize();
                updatePositions();
            }
        }
예제 #21
0
 public VerticalSpacer(UIManager manager_, Widget parent_)
     : base(manager_, parent_)
 {
     Manager.RegisterWidgetType("VerticalSpacer", "Widget");
 }
예제 #22
0
파일: Layout.cs 프로젝트: Ziple/NOubliezPas
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="manager_"></param>
 /// <param name="parent_"></param>
 public Layout(UIManager manager_, Widget parent_)
     : base(manager_, parent_)
 {
     Manager.RegisterWidgetType("Layout", "Widget");
 }
예제 #23
0
 public HorizontalSpacer(UIManager manager_, Widget parent_, float length )
     : base(manager_, parent_)
 {
     Manager.RegisterWidgetType("HorizontalSpacer", "Widget");
     Length = length;
 }
예제 #24
0
 public VerticalLayout(UIManager manager_, Widget parent_)
     : base(manager_, parent_)
 {
     Manager.RegisterWidgetType("VerticalLayout", "Layout");
 }
예제 #25
0
파일: Label.cs 프로젝트: Ziple/NOubliezPas
 public BasicLabel(UIManager manager_, Widget parent_)
     : base(manager_, parent_)
 {
     Manager.RegisterWidgetType("BasicLabel", "Widget");
 }
예제 #26
0
파일: Widget.cs 프로젝트: Ziple/NOubliezPas
 /// <summary>
 /// Returns the maximum size that can use a chikld without any parent resizing.
 /// Must be implemented by widgets like layouts, frames etc...
 /// </summary>
 /// <param name="child">Child willing to resize</param>
 /// <returns>Maximum size that can occupy the child.</returns>
 public virtual Vector2f GetMaxSizeForChild(Widget child)
 {
     return new Vector2f(0f, 0f);
 }
예제 #27
0
        /// <summary>
        /// Method that must be implemented if you have a widget that contains widgets.
        /// This method compute the new widget size so that the child widget can be
        /// resized.
        /// </summary>
        /// <param name="child">Child widget requesting the resizement.</param>
        /// <param name="requestedSize">Size requested by the widget.</param>
        /// <returns></returns>
        protected override Vector2f _computeNewSizeForChild(Widget child, Vector2f requestedSize)
        {
            Vector2f size = new Vector2f(0f, 0f);

            foreach (Widget widg in Widgets)
            {
                if (child == widg)
                {
                    size.Y += requestedSize.Y;
                    size.X = requestedSize.X > size.X ? requestedSize.X : size.X;
                }
                else
                {
                    size.Y += widg.Size.Y;
                    size.X = widg.Size.X > size.X ? widg.Size.X : size.X;
                }
            }
            return size;
        }
예제 #28
0
파일: Layout.cs 프로젝트: Ziple/NOubliezPas
 public override void EndChildResize(Widget child, Vector2f size)
 {
     base.EndChildResize(child, size);
     updatePositions();
 }
예제 #29
0
 /// <summary>
 /// Tells wether or not this widget has the focus.
 /// </summary>
 /// <param name="widget">Widget to test.</param>
 /// <returns>True if the widget has the focus, false otherwise.</returns>
 public bool HasFocus(Widget widget)
 {
     return myFocusedWidget == widget;
 }
예제 #30
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="manager_"></param>
 /// <param name="parent_"></param>
 public HorizontalLayout(UIManager manager_, Widget parent_)
     : base(manager_, parent_)
 {
     Manager.RegisterWidgetType("HorizontalLayout", "Layout");
 }