Provides basic logical UI component functionality.
Esempio n. 1
0
 /// <summary>
 /// Measures the element, returning the size (in pixels) it would occupy if
 /// rendered with the specified renderer.
 /// </summary>
 /// <param name="renderer">The renderer.</param>
 /// <param name="element">The element.</param>
 /// <returns>The size of the element (in pixels).</returns>
 public virtual Vector2 Measure(UserInterfaceRenderer renderer, Element element)
 {
     return renderer.MeasureString(element.Label);
 }
Esempio n. 2
0
 /// <summary>
 /// Renders the element using the specified renderer.
 /// </summary>
 /// <param name="renderer">The renderer.</param>
 /// <param name="element">The element.</param>
 /// <param name="x">The X coordinate (in pixels) of the upper left corner of the region the element should be rendered to.</param>
 /// <param name="y">The Y coordinate (in pixels) of the upper left corner of the region the element should be rendered to.</param>
 /// <param name="width">The width (in pixels) of the region the element should be rendered to.</param>
 /// <param name="height">The height (in pixels) of the region the element should be rendered to.</param>
 public virtual void Render(UserInterfaceRenderer renderer, Element element, int x, int y, int width, int height)
 {
     //Color4 color = new Color4(1.0f, 1.0f, 1.0f);
     //renderer.RenderRectangle(x, y, width, height, color);
     renderer.RenderString(element.Label, x, y, new Color4(1.0f, 0.0f, 0.0f));
 }
Esempio n. 3
0
        /// <summary>
        /// Runs the sample.
        /// </summary>
        public void Run()
        {
            _configuration = OnConfigure();
            _form = CreateForm(_configuration);

            currentFormWindowState = _form.WindowState;

            bool isFormClosed = false;
            bool formIsResizing = false;

            _form.MouseClick += HandleMouseClick;
            _form.KeyDown += HandleKeyDown;
            _form.KeyUp += HandleKeyUp;
            _form.MouseDown += HandleMouseDown;
            _form.MouseUp += HandleMouseUp;
            _form.MouseMove += HandleMouseMove;
            _form.MouseWheel += HandleMouseMove;

            _form.Resize += (o, args) =>
            {
                if (_form.WindowState != currentFormWindowState)
                {
                    HandleResize(o, args);
                }

                currentFormWindowState = _form.WindowState;
            };

            _form.ResizeBegin += (o, args) => { formIsResizing = true; };
            _form.ResizeEnd += (o, args) =>
            {
                formIsResizing = false;
                HandleResize(o, args);
            };

            _form.Closed += (o, args) => { isFormClosed = true; };

            userInterface = new UserInterface();
            var stats = new Element();
            stats.SetBinding("Label", framesPerSecond);
            userInterface.Container.Add(stats);

            arcBall.SetWindow(_form.ClientSize.Width, _form.ClientSize.Height);

            var settings = new DeviceSettings9
            {
                AdapterOrdinal = 0,
                CreationFlags = CreateFlags.HardwareVertexProcessing,
                Width = WindowWidth,
                Height = WindowHeight
            };

            InitializeDevice(settings);

            OnInitialize();
            this.renderList.ForEach(x => x.Init());

            OnResourceLoad();

            clock.Start();
            MessagePump.Run(_form, () =>
            {
                if (isFormClosed)
                {
                    return;
                }

                Update();
                if (!formIsResizing)
                {
                    Render(false);
                }
            });

            OnResourceUnload();
        }