Beispiel #1
0
        /// <summary>
        /// Creates a UIButton element.
        /// </summary>
        /// <param name="game">XNA Game that owns this element.</param>
        /// <param name="controller">UIController associated with the state machine for this element.</param>
        /// <param name="positionX">Element position X-coordinate (relative or screen coordinate).</param>
        /// <param name="positionY">Element position Y-coordinate (relative or screen coordinate).</param>
        /// <param name="width">Desired width of the element in pixels.</param>
        /// <param name="height">Desired height of the element in pixels.</param>
        /// <param name="parent">The containing UIElement for this button (optional).</param>
        /// <remarks>If parent is not null (x,y) position coordinates are expected to be relative to the parent,
        /// otherwise they are interpreted as screen coordinates.</remarks>
        public UIButton(Game game, UIController controller, float positionX, float positionY, int width, int height, UIElement parent)
            : base(game, controller, null, new Vector2(positionX, positionY), width, height, parent)
        {
            buttonStateMachine = new ButtonStateMachine(controller, (int)width, (int)height);
            buttonStateMachine.Click += OnButtonClick;

            base.StateMachine = buttonStateMachine;
            StateMachine.Tag = this;
        }
Beispiel #2
0
 /// <summary>
 /// Create a UIContainer with the specified parameters.
 /// </summary>
 /// <param name="game">Game to which the element belongs.</param>
 /// <param name="controller">UIController associated with this element.</param>
 /// <param name="texture"></param>
 /// <param name="position"></param>
 /// <param name="width"></param>
 /// <param name="height"></param>
 /// <param name="parent"></param>
 public UIContainer(Game game,
                    UIController controller,
                    string texture,
                    Vector2? position, int width, int height, UIElement parent)
     : base(game, controller, texture, position, width, height, parent)
 {
     nullStateMachine = new NullStateMachine(controller, width, height);
     StateMachine = nullStateMachine;
     StateMachine.Tag = this;
 }
        /// <summary>
        /// Initializes the <strong><see cref="UIElementStateMachine"/></strong> objects.
        /// </summary>
        /// <param name="controller">The controller for this <strong>UIElementStateMachine</strong> object.</param>
        /// <param name="numberOfPixelsInHorizontalAxis">
        /// The number of pixels that this control occupies horizontally. 
        /// For more information, see 
        /// <strong><see cref="P:CoreInteractionFramework.UIElementStateMachine.NumberOfPixelsInHorizontalAxis">NumberOfPixelsInHorizontalAxis</see></strong>.
        /// </param>
        /// <param name="numberOfPixelsInVerticalAxis">
        /// The number of pixels that this control occupies vertically. 
        /// For more information, see 
        /// <strong><see cref="P:CoreInteractionFramework.UIElementStateMachine.NumberOfPixelsInVerticalAxis">NumberOfPixelsInVerticalAxis</see></strong>.
        /// </param>
        protected UIElementStateMachine(UIController controller, int numberOfPixelsInHorizontalAxis, int numberOfPixelsInVerticalAxis)
        {
            if (controller == null)
                throw SurfaceCoreFrameworkExceptions.ArgumentNullException("controller");

            this.numberOfPixelsInHorizontalAxis = numberOfPixelsInHorizontalAxis;
            this.numberOfPixelsInVerticalAxis = numberOfPixelsInVerticalAxis;

            this.controller = controller;

            this.controller.ResetState += new EventHandler(OnResetState);
        }
Beispiel #4
0
        /// <summary>
        /// A parameterized public constructor for the MeshCanvas class.
        /// </summary>
        /// <param name="game">The game that to which this UIElement belongs.</param>
        /// <param name="controller">The UIController that will route touch events this UIElement's state machine.</param>
        /// <param name="texture">The name of a file containing the texture to use for this UIElement.</param>
        /// <param name="width">The desired width of this UIElement in pixels.</param>
        /// <param name="height">The desired height of this UIElemnt in pixels.</param>
        public MeshCanvas(Game game, UIController controller, string texture, int width, int height)
            : base(game, controller, texture, null, width, height, null)
        {
            IgnoreTextureSize = true;

            viewPort = new ScrollViewerStateMachine(controller, width, height);

            // Add a little elasticity so it's apparent when boundary of
            // the ScrollViewer is reached.
            viewPort.HorizontalElasticity = 0.03f;
            viewPort.VerticalElasticity = 0.03f;

            StateMachine = viewPort;
            StateMachine.Tag = this;

            viewPort.TouchDown += OnContactDown;
        }
Beispiel #5
0
 /// <summary>
 /// Creates a ScrollBar HUD element with the specified parameters.
 /// </summary>
 public ScrollBar(Game game, UIController controller, Vector2? position, float length,
                  ListBoxStateMachine listBox,
                  ScrollBarStateMachine scrollBar, UIElement parent)
     : base(game, controller, null, position,
            scrollBar.NumberOfPixelsInHorizontalAxis,
            scrollBar.NumberOfPixelsInVerticalAxis,
            parent)
 {
     if (scrollBar.Orientation != Orientation.Horizontal)
     {
         throw new InvalidOperationException(Properties.Resources.ScrollBarStateMachineShouldBeHorizontal);
     }
     this.listBox = listBox;
     StateMachine = scrollBar;
     StateMachine.Tag = this;
     StateMachine.MaximumFlickVelocity = MaximumFlickVelocity;
     scrollBarLength = length;
 }
 /// <summary>
 /// Creates an initialized instance of a
 /// <strong><see cref="ScrollBarStateMachine"/></strong> object with the specified parameters.
 /// </summary>
 /// <param name="controller">The <strong>UIController</strong> object that dispatches hit testing.</param>
 /// <param name="numberOfPixelsInHorizontalAxis">
 /// The number of pixels that this control occupies horizontally. 
 /// For more information, see 
 /// <strong><see cref="P:CoreInteractionFramework.UIElementStateMachine.NumberOfPixelsInHorizontalAxis">NumberOfPixelsInHorizontalAxis</see></strong>.
 /// </param>
 /// <param name="numberOfPixelsInVerticalAxis">
 /// The number of pixels that this control occupies vertically. 
 /// For more information, see 
 /// <strong><see cref="P:CoreInteractionFramework.UIElementStateMachine.NumberOfPixelsInVerticalAxis">NumberOfPixelsInVerticalAxis</see></strong>.
 /// </param>
 public ScrollBarStateMachine(UIController controller, int numberOfPixelsInHorizontalAxis, int numberOfPixelsInVerticalAxis)
     : base(controller, numberOfPixelsInHorizontalAxis, numberOfPixelsInVerticalAxis)
 {
     stopwatch = Stopwatch.StartNew();
 }
Beispiel #7
0
        /// <summary>
        /// Private contructor invoked by overloaded base contructors to build the UIElement.
        /// </summary>
        /// <param name="game"></param>
        /// <param name="controller"></param>
        /// <param name="textureFile"></param>
        /// <param name="texture"></param>
        /// <param name="position">Position of the UIElement (relative or screen coordinates)</param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="parent"></param>
        private UIElement(Game game,
                          UIController controller,
                          string textureFile, Texture2D texture,
                          Vector2? position,
                          int width, int height,
                          UIElement parent)
            : base(game)
        {
            // Should only set one or the other, not both.
            Debug.Assert(textureFile == null || texture == null);

            this.controller = controller;
            this.textureSourceFile = textureFile;
            this.texture = texture;
            this.width = width;
            this.height = height;
            this.parent = parent;

            instanceCount++;
            Name = "UIElement " + instanceCount.ToString(CultureInfo.InvariantCulture);

            if (parent != null)
            {
                // Inherit some properties from the parent (containing) UIElement.
                currentOrientation = parent.currentOrientation;
                screenTransform = parent.ScreenTransform;
                spriteBlendState = parent.SpriteBlendState;
                spriteSortMode = parent.spriteSortMode;

                // Draw children in front of parents.
                layerDepth = parent.layerDepth * 0.9f;

                // Position is a relative to parent's Center.
                if (position != null)
                {
                    relativePosition = Vector2.Clamp(position.Value,
                                                     new Vector2(-0.5f, -0.5f),
                                                     new Vector2(0.5f, 0.5f));
                    Vector2 center = parent.Center;
                    float x = center.X + relativePosition.X * parent.Width;
                    float y = center.Y + relativePosition.Y * parent.Height;
                    Center = new Vector2(x, y);
                }

                // Add this to parent's liest of children.
                parent.AddChild(this);
            }
            else
            {
                // Position is in screen coordinates.
                if (position != null)
                {
                    Center = position.Value;
                }
            }
        }
Beispiel #8
0
 /// <summary>
 /// Base constructor for UIElement.  Only derived classes may call the base constructor.
 /// </summary>
 /// <param name="game"></param>
 /// <param name="controller"></param>
 /// <param name="position"></param>
 /// <param name="width"></param>
 /// <param name="height"></param>
 /// <param name="parent"></param>
 protected UIElement(Game game,
                     UIController controller,
                     Vector2? position,
                     int width, int height,
                     UIElement parent)
     : this(game, controller, null, null, position, width, height, parent)
 {
     // Empty.
 }
 //==========================================================//
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="passedColor">The color of the item.</param>
 /// <param name="passedParent">The item's parent XnaScatterView.</param>
 public XnaScatterViewItem(UIController controller, string contentImage, XnaScatterView passedParent)
     :base(controller, 1, 1 )
 {
     textureSourceFile = contentImage;
     parent = passedParent;
 }
 /// <summary>
 /// Creates a TextilesStatemachine.
 /// </summary>
 /// <param name="controller">The UIController for this state machine.</param>
 /// <param name="textiles">The UIElement encapsulating this state machine.</param>
 public TextilesStateMachine(UIController controller, Textiles textiles)
     : base(controller, 0, 0)
 {
     this.textiles = textiles;
 }
Beispiel #11
0
        /// <summary>
        /// Creates a Listbox UIElement that may or may not have a parent UIElement.
        /// </summary>
        /// <param name="game">XNA Game that contains this ListBox</param>
        /// <param name="contoller">UIController to associate with the ListBoxStateMachine.</param>
        /// <param name="x">X-coordinate of elements position (relative or screen).</param>
        /// <param name="y">Y-coordinate of elements position (relative or screen).</param>
        /// <param name="width">Width of the ListBox in pixels.</param>
        /// <param name="height">Height of the ListBox in pixels.</param>
        /// <param name="parent">UIElement that contains the Listbox.</param>
        /// <param name="textiles">Textiles UIElement controlled by this list box</param>
        public ListBox(Game game, UIController contoller, float x, float y, int width, int height,
                       UIElement parent, Textiles textiles)
            : base(game, contoller, new Vector2(x, y), width, height, parent)
        {
            listBoxStateMachine = new ListBoxStateMachine(Controller, (int)width, (int)height)
                                      {
                                          SelectionMode = SelectionMode.Single,
                                          Orientation = Orientation.Horizontal,
                                          HorizontalElasticity = 0.0f,
                                          VerticalElasticity = 0.0f,
                                          HorizontalViewportSize = 1f,
                                          VerticalViewportSize = 1f,
                                      };

            StateMachine = listBoxStateMachine;
            StateMachine.Tag = this;

            this.textiles = textiles;

            listBoxStateMachine.ItemStateChanged += OnItemStateChanged;

            iconScale = new Vector2((float)iconWidth / itemWidth, (float)iconHeight / itemHeight);

            UIContainer container = parent as UIContainer;
            if (container != null)
            {
                // Create the scrollbar and position it below the listbox.
                int offset = Convert.ToInt32(Top - parent.Top + Height);
                Vector2 position = UIElement.CenterHorizontal(offset, scrollBarBackgroundHeight, container);

                ScrollBar = new ScrollBar(parent, position, width, listBoxStateMachine,
                                          listBoxStateMachine.HorizontalScrollBarStateMachine);

                // Create the Maximze/Minimize button and position it above the listbox.
                offset = Convert.ToInt32(Top - parent.Top - buttonHeight);
                position = UIElement.CenterHorizontal(offset, (float) buttonHeight, Parent);
                minMaxButton = new Button(parent, position, buttonWidth, buttonHeight);
                minMaxButton.Name = "button";
                minMaxButton.AutoScaleTexture = false;
            }
            else
            {
                throw new InvalidOperationException(Properties.Resources.ListBoxShouldBeInUIContainer);
            }
        }
Beispiel #12
0
 /// <summary>
 /// Creates an initialized instance of a
 /// <strong><see cref="T:CoreInteractionFramework.ButtonStateMachine" /></strong> object.
 /// </summary>
 /// <param name="controller">A <strong>UIController</strong> object with buffered contacts and successfully
 /// hit testing contacts.</param>
 /// <param name="numberOfPixelsInHorizontalAxis">
 /// The number of pixels that this control occupies horizontally. 
 /// For more information, see 
 /// <strong><see cref="P:CoreInteractionFramework.UIElementStateMachine.NumberOfPixelsInHorizontalAxis">
 /// NumberOfPixelsInHorizontalAxis</see></strong>.
 /// </param>
 /// <param name="numberOfPixelsInVerticalAxis">
 /// The number of pixels that this control occupies vertically. 
 /// For more information, see <strong><see cref="P:CoreInteractionFramework.UIElementStateMachine.NumberOfPixelsInVerticalAxis">
 /// NumberOfPixelsInVerticalAxis</see></strong>.
 /// </param>
 /// <remarks>The <strong><see cref="T:CoreInteractionFramework.UIElementStateMachine" /></strong> base 
 /// class takes the same <strong>UIController</strong> object and pixel parameters as the 
 /// <strong>ButtonStateMachine</strong> object.
 /// </remarks>
 public ButtonStateMachine(UIController controller, int numberOfPixelsInHorizontalAxis, int numberOfPixelsInVerticalAxis)
     : base(controller, numberOfPixelsInHorizontalAxis, numberOfPixelsInVerticalAxis)
 {
 }
 /// <summary>
 /// Creates a new <strong><see cref="ScrollViewerStateMachine"/></strong> instance
 /// with the specified parameters.
 /// </summary>
 /// <param name="controller">The <strong>UIController</strong> object that dispatches hit testing.</param>
 /// <param name="numberOfPixelsInHorizontalAxis">
 /// The number of pixels that this control occupies horizontally. 
 /// For more information, see 
 /// <strong><see cref="P:CoreInteractionFramework.UIElementStateMachine.NumberOfPixelsInHorizontalAxis">NumberOfPixelsInHorizontalAxis</see></strong>.
 /// </param>
 /// <param name="numberOfPixelsInVerticalAxis">
 /// The number of pixels that this control occupies vertically. 
 /// For more information, see 
 /// <strong><see cref="P:CoreInteractionFramework.UIElementStateMachine.NumberOfPixelsInVerticalAxis">NumberOfPixelsInVerticalAxis</see></strong>.
 /// </param>
 public ScrollViewerStateMachine(UIController controller, int numberOfPixelsInHorizontalAxis, int numberOfPixelsInVerticalAxis)
     : base(controller, numberOfPixelsInHorizontalAxis, numberOfPixelsInVerticalAxis)
 {
     scrollAdapter = new ScrollAdapter(controller, this);
     scrollAdapter.ViewportChanged += new EventHandler(OnViewportChanged);
 }
Beispiel #14
0
        //
        // The following virtual methods from the Game class have been overridden:
        //
        //    Initialize, LoadContent, Update, Draw, UnLoadContent
        //
        // The following methods are also available for override, but are not overridden
        // at this time:
        //
        //    BeginRun, BeginDraw, EndDraw, EndRun, OnActivated, OnDeactivated, OnExiting
        //

        /// <summary>
        /// Allows the app to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            IsMouseVisible = true; // easier for debugging not to "lose" mouse
            SetWindowOnSurface();
            InitializeSurfaceInput();

            // Make sure things are aware of the window size.
            UpdateViewportSettings();
            Window.ClientSizeChanged += OnClientSizeChanged;

            // Create the UIController for the StateMachines.
            controller = new UIController(touchTarget, HitTestCallback);

            PopulateGame();

            // Initialize UIElements which are not in Game.Components
            // and are not children of another UIElement.
            textiles.Initialize();

            // Subscribe to surface window availability events
            ApplicationServices.WindowInteractive += OnWindowInteractive;
            ApplicationServices.WindowNoninteractive += OnWindowNoninteractive;
            ApplicationServices.WindowUnavailable += OnWindowUnavailable;

            base.Initialize();
        }
 /// <summary>
 /// Creates a NullStateMachine.
 /// </summary>
 /// <param name="controller">The UIcontroller assocatiated with this state machine.</param>
 /// <param name="width">Number of pixels in horizontal axis.</param>
 /// <param name="height">Number of pixels in vertical axis</param>
 public NullStateMachine(UIController controller, int width, int height)
     : base(controller, width, height)
 {
     // Empty.
 }
Beispiel #16
0
        /// <summary>
        /// Creates a Textiles UIElement.
        /// </summary>
        /// <param name="game"></param>
        /// <param name="controller"></param>
        /// <param name="touchTarget"></param>
        public Textiles(Game game,
                        UIController controller)
            : base(game, controller, null, null, 0, 0, null)
        {
            textileComponent = new TextileManipulationComponent(game);
            game.Components.Add(textileComponent);

            StateMachine = new TextilesStateMachine(controller, this) { Tag = this };
        }
Beispiel #17
0
        /// <summary>
        /// Creates a new ScrollViewerStateMachine.
        /// </summary>
        /// <param name="controller">The UIController which dispatches hit testing.</param>
        /// <param name="elementToScroll">The element which is scrolling.</param>
        public ScrollAdapter(UIController controller, UIElementStateMachine elementToScroll)
        {
            // By default scrolling should be allowed in both directions.
            Orientation = Orientation.Both;

            this.elementToScroll = elementToScroll;

            // Handle the ScrollBars for this ScrollViewer.
            horizontalScrollBarStateMachine = 
                new ScrollBarStateMachine(controller, elementToScroll.NumberOfPixelsInHorizontalAxis, 0);
            horizontalScrollBarStateMachine.Orientation = Orientation.Horizontal;

            verticalScrollBarStateMachine = 
                new ScrollBarStateMachine(controller, 0, elementToScroll.NumberOfPixelsInVerticalAxis);
            verticalScrollBarStateMachine.Orientation = Orientation.Vertical;

            // Default to 1 (full size).
            HorizontalViewportSize = 1;
            VerticalViewportSize = 1;
          
            horizontalScrollBarStateMachine.ValueChanged += OnHorizontalScrollBarStateMachineValueChanged;
            horizontalScrollBarStateMachine.ThumbChanged += OnHorizontalScrollBarStateMachineThumbChanged;
            horizontalScrollBarStateMachine.NumberOfPixelsInHorizontalAxisChanged +=
                HorizontalScrollBarStateMachineNumberOfPixelsInHorizontalAxisChanged;

            verticalScrollBarStateMachine.ValueChanged += OnVerticalScrollBarStateMachineValueChanged;
            verticalScrollBarStateMachine.ThumbChanged += OnVerticalScrollBarStateMachineThumbChanged;
            verticalScrollBarStateMachine.NumberOfPixelsInVerticalAxisChanged +=
                VerticalScrollBarStateMachineNumberOfPixelsInVerticalAxisChanged;

            // Manipulations should only cause translations, not rotations or scaling.
            manipulationProcessor =
                new ManipulationProcessor2D(Manipulations2D.TranslateX | Manipulations2D.TranslateY);
            manipulationProcessor.Completed += OnAffine2DManipulationCompleted;
            stopwatch = Stopwatch.StartNew();
        }
Beispiel #18
0
        /// <summary>
        /// Allows the app to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            IsMouseVisible = true; // easier for debugging not to "lose" mouse
            SetWindowOnSurface();
            InitializeSurfaceInput();

            controller = new UIController(touchTarget, HitTestCallback);

            // Set the application's orientation based on the orientation at launch
            currentOrientation = ApplicationServices.InitialOrientation;

            // Subscribe to surface window availability events
            ApplicationServices.WindowInteractive += OnWindowInteractive;
            ApplicationServices.WindowNoninteractive += OnWindowNoninteractive;
            ApplicationServices.WindowUnavailable += OnWindowUnavailable;

            // Create a rotation matrix to orient the screen so it is viewed correctly,
            // when the user orientation is 180 degress different.
            Matrix rotation = Matrix.CreateRotationZ(MathHelper.ToRadians(180));
            Matrix translation = Matrix.CreateTranslation(graphics.GraphicsDevice.Viewport.Width,
                                                          graphics.GraphicsDevice.Viewport.Height, 0);
            Matrix inverted = rotation * translation;

            PopulateGameWorld();

            if (currentOrientation == UserOrientation.Top)
            {
                screenTransform = inverted;
            }
            scatterView.Transform = screenTransform;

            base.Initialize();
        }
Beispiel #19
0
        /// <summary>
        /// Creates an initialized instance of a
        /// <strong><see cref="ListBoxStateMachine"/></strong> object with the specified parameters.
        /// </summary>
        /// <param name="controller">The <strong>UIController</strong> object that dispatches hit testing.</param>
        /// <param name="numberOfPixelsInHorizontalAxis">
        /// The number of pixels that this control occupies horizontally.
        /// For more information, see <strong><see cref="P:CoreInteractionFramework.UIElementStateMachine.NumberOfPixelsInHorizontalAxis">
        /// NumberOfPixelsInHorizontalAxis</see></strong>.
        /// </param>
        /// <param name="numberOfPixelsInVerticalAxis">
        /// The number of pixels that this control occupies vertically.
        /// For more information, see <strong><see cref="P:CoreInteractionFramework.UIElementStateMachine.NumberOfPixelsInVerticalAxis">
        /// NumberOfPixelsInVerticalAxis</see></strong>.
        /// </param>
        public ListBoxStateMachine(UIController controller,
                                   int numberOfPixelsInHorizontalAxis,
                                   int numberOfPixelsInVerticalAxis)
            : base(controller, numberOfPixelsInHorizontalAxis, numberOfPixelsInVerticalAxis)
        {
            scrollAdapter = new ScrollAdapter(controller, this);
            scrollAdapter.ViewportChanged += OnScrollAdapterViewportChanged;

            ListBoxMode = ListBoxMode.Selection;

            // Create container objects.
            items = new ListBoxStateMachineItemCollection(this);
            selectedItems = new ListBoxStateMachineItemCollection(this);
            contactTargetEventContactIds = new Dictionary<int, ContactTargetEvent>();
            capturedItemContactIds = new Dictionary<int, ListBoxStateMachineItem>();

            items.ListBoxItemRemoved += OnListBoxItemRemoved;
            items.ListBoxItemAdded += OnListBoxItemAdded;

            selectedItems.ListBoxItemAdded += OnSelectedItemsListBoxItemAdded;
            selectedItems.ListBoxItemRemoved += OnSelectedItemsListBoxItemRemoved;
        }
Beispiel #20
0
        //==========================================================//
        /// <summary>
        /// Constructor. Sets allowed manipulations and creates the manipulation processor.
        /// </summary>
        public XnaScatterView(UIController controller, string backgroundImage, int top, int bottom, int left, int right)
            : base(controller, right - left, bottom - top)
        {
            textureSourceFile = backgroundImage;
            transformedCenter = new Vector2(0, 0);

            topBoundary = top;
            bottomBoundary = bottom;
            leftBoundary = left;
            rightBoundary = right;

            Manipulations2D supportedManipulations =
                Manipulations2D.TranslateX | Manipulations2D.TranslateY | Manipulations2D.Scale;

            manipulationProcessor = new ManipulationProcessor2D(supportedManipulations);
            manipulationProcessor.Delta += OnAffine2DDelta;
        }