Exemple #1
0
			internal SwitchView(double width, double height, bool startValue, 
				RGBA_Bytes backgroundColor, RGBA_Bytes interiorColor, RGBA_Bytes thumbColor, RGBA_Bytes exteriorColor)
			{
				this.startValue = startValue;
				switchWidth = width;
				switchHeight = height;
				thumbHeight = height;
				thumbWidth = width / 4;
				InteriorColor = interiorColor;
				ExteriorColor = exteriorColor;
				ThumbColor = thumbColor;
				LocalBounds = new RectangleDouble(0, 0, width, height);
			}
		public RadioButtonGroup(Vector2 location, Vector2 size)
			: base(FlowDirection.TopToBottom)
		{
			Margin = new BorderDouble();
			Padding = new BorderDouble(5);

			LocalBounds = new RectangleDouble(0, 0, size.x, size.y);
			OriginRelativeParent = location;
			radioButtons = new List<RadioButton>();

			backgroundColor = (new RGBA_Floats(1.0, 1.0, 0.9));
			borderColor = (new RGBA_Floats(0.0, 0.0, 0.0));
			textColor = (new RGBA_Floats(0.0, 0.0, 0.0));
			inactiveColor = (new RGBA_Floats(0.0, 0.0, 0.0));
			activeColor = (new RGBA_Floats(0.4, 0.0, 0.0));
		}
		public spline_ctrl(Vector2 location, Vector2 size, int num_pnt)
			: base(location, false)
		{
			LocalBounds = new RectangleDouble(0, 0, size.x, size.y);
			m_curve_pnt = new PathStorage();
			m_curve_poly = new Stroke(m_curve_pnt);
			m_ellipse = new Ellipse();

			m_background_color = new RGBA_Bytes(1.0, 1.0, 0.9);
			m_border_color = new RGBA_Bytes(0.0, 0.0, 0.0);
			m_curve_color = new RGBA_Bytes(0.0, 0.0, 0.0);
			m_inactive_pnt_color = new RGBA_Bytes(0.0, 0.0, 0.0);
			m_active_pnt_color = new RGBA_Bytes(1.0, 0.0, 0.0);

			m_num_pnt = (num_pnt);
			m_border_width = (1.0);
			m_border_extra = (0.0);
			m_curve_width = (1.0);
			m_point_size = (3.0);
			m_curve_poly = new Stroke(m_curve_pnt);
			m_idx = (0);
			m_vertex = (0);
			m_active_pnt = (-1);
			m_move_pnt = (-1);
			m_pdx = (0.0);
			m_pdy = (0.0);
			if (m_num_pnt < 4) m_num_pnt = 4;
			if (m_num_pnt > 32) m_num_pnt = 32;

			for (int i = 0; i < m_num_pnt; i++)
			{
				m_xp[i] = (double)(i) / (double)(m_num_pnt - 1);
				m_yp[i] = 0.5;
			}
			calc_spline_box();
			update_spline();
			{
				m_spline.init((int)m_num_pnt, m_xp, m_yp);
				for (int i = 0; i < 256; i++)
				{
					m_spline_values[i] = m_spline.get((double)(i) / 255.0);
					if (m_spline_values[i] < 0.0) m_spline_values[i] = 0.0;
					if (m_spline_values[i] > 1.0) m_spline_values[i] = 1.0;
					m_spline_values8[i] = (byte)(m_spline_values[i] * 255.0);
				}
			}
		}
Exemple #4
0
		public WindowWidget(RectangleDouble InBounds)
		{
			int sizeOfDragBar = 20;

			BackgroundColor = RGBA_Bytes.White;

			OriginRelativeParent = new Vector2(InBounds.Left, InBounds.Bottom);
			LocalBounds = new RectangleDouble(0, 0, InBounds.Width, InBounds.Height);

			DragBarColor = RGBA_Bytes.LightGray;
			dragBar = new TitleBarWidget(new RectangleDouble(0, InBounds.Height - sizeOfDragBar, InBounds.Width, InBounds.Height));
			//dragBar.DebugShowBounds = true;
			base.AddChild(dragBar);

			//clientArea.DebugShowBounds = true;
			base.AddChild(clientArea);
		}
Exemple #5
0
		private void CalculateChildrenBounds()
		{
			if (Children.Count > 0)
			{
				RectangleDouble boundsOfChildren = new RectangleDouble(double.MaxValue, double.MaxValue, double.MinValue, double.MinValue);
				foreach (GuiWidget widget in Children)
				{
					boundsOfChildren.ExpandToInclude(widget.BoundsRelativeToParent);
					boundsOfChildren.Left = Math.Min(boundsOfChildren.Left, widget.BoundsRelativeToParent.Left);
					boundsOfChildren.Bottom = Math.Min(boundsOfChildren.Bottom, widget.BoundsRelativeToParent.Bottom);
					boundsOfChildren.Right = Math.Max(boundsOfChildren.Right, widget.BoundsRelativeToParent.Right);
					boundsOfChildren.Top = Math.Max(boundsOfChildren.Top, widget.BoundsRelativeToParent.Top);
				}

				LocalBounds = boundsOfChildren;
			}
		}
        public void DoFitToChildrenVertical(GuiWidget widgetToAdjustBounds, ref bool sizeWasChanged)
        {
            if (widgetToAdjustBounds.VAnchorIsSet(VAnchor.Fit))
            {
                double heightToMatchParent = 0;
                if (widgetToAdjustBounds.Parent != null)
                {
                    Vector2 newOriginRelParent;
                    if (!GetOriginAndHeightForChild(widgetToAdjustBounds.Parent, widgetToAdjustBounds, out newOriginRelParent, out heightToMatchParent).adjustHeight)
                    {
                        // we don't need to adjust anything for the parent so make sure this is not applied below.
                        heightToMatchParent = 0;
                    }
                }

                // get the bounds
                RectangleDouble adjustBounds = widgetToAdjustBounds.LocalBounds;
                // get the bounds to enclose its children
                RectangleDouble childrenEnclosingBounds = widgetToAdjustBounds.GetMinimumBoundsToEncloseChildren(true);
                // fix the v size to enclose the children
                adjustBounds.Bottom = childrenEnclosingBounds.Bottom;
                adjustBounds.Top    = Math.Max(childrenEnclosingBounds.Bottom + heightToMatchParent, childrenEnclosingBounds.Top);
                if (widgetToAdjustBounds.LocalBounds != adjustBounds)
                {
                    if (widgetToAdjustBounds.VAnchorIsSet(VAnchor.Stretch))
                    {
                        if (widgetToAdjustBounds.LocalBounds.Height < adjustBounds.Height)
                        {
                            widgetToAdjustBounds.LocalBounds = adjustBounds;
                            sizeWasChanged = true;
                        }
                    }
                    else
                    {
                        // push the new size in
                        widgetToAdjustBounds.LocalBounds = adjustBounds;
                        sizeWasChanged = true;
                    }
                }
            }
        }
        private static void AssertBorderWhereExpected(Regions region, BorderDouble border, IImageByte imageBuffer)
        {
            RectangleDouble borderBounds = RectangleDouble.ZeroIntersection;

            switch (region)
            {
            case  Regions.Left:
                borderBounds = new RectangleDouble(0, 0, border.Left, imageBuffer.Height);
                break;

            case Regions.Bottom:
                borderBounds = new RectangleDouble(0, 0, imageBuffer.Width, border.Bottom);
                break;

            case Regions.Right:
                borderBounds = new RectangleDouble(imageBuffer.Width - border.Right, 0, imageBuffer.Width, imageBuffer.Height);
                break;

            case Regions.Top:
                borderBounds = new RectangleDouble(0, imageBuffer.Height - border.Top, imageBuffer.Width, imageBuffer.Height);
                break;
            }

            for (int x = 0; x < imageBuffer.Width; x++)
            {
                for (int y = 0; y < imageBuffer.Height; y++)
                {
                    var pixel = imageBuffer.GetPixel(x, y);

                    bool shouldBeRed = borderBounds.Contains(new Point2D(x + .5, y + .5));
                    if (shouldBeRed)
                    {
                        Assert.AreEqual(Color.Red, pixel);
                    }
                    else
                    {
                        Assert.AreNotEqual(Color.Red, pixel);
                    }
                }
            }
        }
Exemple #8
0
        public override void OnMouseMove(MouseEventArgs mouseEvent)
        {
            bool oldValue = SwitchState;

            if (mouseDownOnToggle)
            {
                mouseMoveOnToggle = true;
                RectangleDouble switchBounds  = GetSwitchBounds();
                Vector2         mousePosition = mouseEvent.Position;
                SwitchState = switchBounds.XCenter < mousePosition.x;
                if (oldValue != SwitchState)
                {
                    if (SwitchStateChanged != null)
                    {
                        SwitchStateChanged(this, mouseEvent);
                    }
                    Invalidate();
                }
            }
            base.OnMouseMove(mouseEvent);
        }
        public static Vector2 EnsureInPrintBounds(PrinterConfig printer, Vector2 probePosition)
        {
            // check that the position is within the printing area and if not move it back in
            if (printer.Settings.Helpers.UseZProbe())
            {
                var probeOffset2D        = new Vector2(printer.Settings.GetValue <Vector3>(SettingsKey.probe_offset));
                var actualNozzlePosition = probePosition - probeOffset2D;

                // clamp this to the bed bounds
                Vector2 bedSize     = printer.Settings.GetValue <Vector2>(SettingsKey.bed_size);
                Vector2 printCenter = printer.Settings.GetValue <Vector2>(SettingsKey.print_center);
                var     bedBounds   = new RectangleDouble(printCenter - bedSize / 2, printCenter + bedSize / 2);
                bedBounds.Inflate(-1);
                Vector2 adjustedPosition = bedBounds.Clamp(actualNozzlePosition);

                // and push it back into the probePosition
                probePosition = adjustedPosition + probeOffset2D;
            }

            return(probePosition);
        }
Exemple #10
0
        public ProbePositionsWidget(PrinterConfig printer, List <Vector2> probePoints, ThemeConfig theme)
        {
            this.probePoints     = probePoints;
            this.printer         = printer;
            this.VAnchor         = VAnchor.Absolute;
            this.theme           = theme;
            this.BackgroundColor = theme.BedBackgroundColor;

            opaqueMinimumAccent = theme.ResolveColor(theme.BackgroundColor, theme.AccentMimimalOverlay);
            opaqueAccent        = theme.ResolveColor(theme.BackgroundColor, theme.AccentMimimalOverlay.WithAlpha(140));

            circleText = theme.TextColor;
            lightText  = circleText.WithAlpha(100);

            bedTextColor         = theme.PrinterBedTextColor;
            bedCircleColor       = theme.ResolveColor(theme.BedColor, bedTextColor.WithAlpha(50));
            simpleBedCircleColor = theme.ResolveColor(theme.BedColor, bedTextColor.WithAlpha(180));

            bedBounds   = printer.Settings.BedBounds;
            circularBed = printer.Settings.GetValue <BedShape>(SettingsKey.bed_shape) == BedShape.Circular;
        }
Exemple #11
0
        public RayTraceWidget(int width = 200, int height = 200)
        {
            trackballTumbleWidget = new TrackballTumbleWidget();
            trackballTumbleWidget.DoOpenGlDrawing          = false;
            trackballTumbleWidget.DrawRotationHelperCircle = false;
            //trackballTumbleWidget.DrawGlContent += trackballTumbleWidget_DrawGlContent;
            trackballTumbleWidget.TransformState = TrackBallController.MouseDownType.Rotation;

            AddChild(trackballTumbleWidget);

            totalTime.Start();

            CreateScene();
            LocalBounds = new RectangleDouble(0, 0, width, height);

            trackballTumbleWidget.TrackBallController.Scale = .03;

            trackballTumbleWidget.TrackBallController.Rotate(Quaternion.FromEulerAngles(new Vector3(0, 0, MathHelper.Tau / 16)));
            trackballTumbleWidget.TrackBallController.Rotate(Quaternion.FromEulerAngles(new Vector3(-MathHelper.Tau * .19, 0, 0)));
            trackballTumbleWidget.AnchorAll();
        }
Exemple #12
0
        private void EnsureEditControlIsVisible(object sender, EventArgs e)
        {
            hadFocusWidget = sender as TextEditWidget;
            // remember where we were
            oldVAnchor = content.VAnchor;
            oldOrigin  = content.OriginRelativeParent;

            // test if the text widget is visible
            RectangleDouble textWidgetScreenBounds = TextWidgetScreenBounds();
            int             topOfKeyboard          = KeyboardHeight;

            if (textWidgetScreenBounds.Bottom < topOfKeyboard)
            {
                IsActive = true;

                // make sure the screen is not resizing vertically
                content.VAnchor = VAnchor.AbsolutePosition;
                // move the screen up so we can see the bottom of the text widget
                content.OriginRelativeParent = new Vector2(0, topOfKeyboard - textWidgetScreenBounds.Bottom + 10);
            }
        }
        private void RecalculateBounds()
        {
            needToRecalculateBounds = false;
            return;

#if false
            double          extraForControlPoints = m_point_radius * 1.3;
            RectangleDouble newBounds             = new RectangleDouble(double.MaxValue, double.MaxValue, double.MinValue, double.MinValue);
            for (int i = 0; i < m_num_points; i++)
            {
                newBounds.Left   = Math.Min(GetXN(i) - extraForControlPoints, newBounds.Left);
                newBounds.Right  = Math.Max(GetXN(i) + extraForControlPoints, newBounds.Right);
                newBounds.Bottom = Math.Min(GetYN(i) - extraForControlPoints, newBounds.Bottom);
                newBounds.Top    = Math.Max(GetYN(i) + extraForControlPoints, newBounds.Top);
            }

            Invalidate();
            LocalBounds = newBounds;
            Invalidate();
#endif
        }
        public override void OnMouseDown(MouseEventArgs mouseEvent)
        {
            firstValueOnMouseDown  = FirstValue;
            secondValueOnMouseDown = SecondValue;
            Vector2         mousePos          = mouseEvent.Position;
            RectangleDouble firstThumbBounds  = GetFirstThumbHitBounds();
            RectangleDouble secondThumbBounds = GetSecondThumbHitBounds();

            if (firstThumbBounds.Contains(mousePos))
            {
                if (Orientation == Orientation.Horizontal)
                {
                    mouseDownOffsetFromFirstThumbCenter = mousePos.x - PositionPixelsFromFirstValue;
                }
                else
                {
                    mouseDownOffsetFromFirstThumbCenter = mousePos.y - PositionPixelsFromFirstValue;
                }
                downOnFirstThumb = true;
            }
            else if (secondThumbBounds.Contains(mousePos))
            {
                if (Orientation == Orientation.Horizontal)
                {
                    mouseDownOffsetFromSecondThumbCenter = mousePos.x - PositionPixelsFromSecondValue;
                }
                else
                {
                    mouseDownOffsetFromSecondThumbCenter = mousePos.y - PositionPixelsFromSecondValue;
                }
                downOnSecondThumb = true;
            }
            else // let's check if we are on the track
            {
                //Ignore track hits
            }


            base.OnMouseDown(mouseEvent);
        }
        public override void OnDraw(Graphics2D graphics2D)
        {
            GuiWidget parentButton = Parent;

            RectangleDouble Bounds = LocalBounds;

            RoundedRect rectBorder = new RoundedRect(Bounds, BorderRadius);

            if (parentButton.Enabled == true)
            {
                graphics2D.Render(rectBorder, new Color(0, 0, 0));
            }
            else
            {
                graphics2D.Render(rectBorder, new Color(128, 128, 128));
            }

            RectangleDouble insideBounds = Bounds;

            insideBounds.Inflate(-BorderWidth);

            RoundedRect rectInside  = new RoundedRect(insideBounds, Math.Max(BorderRadius - BorderWidth, 0));
            Color       insideColor = new Color(1.0, 1.0, 1.0);

            if (parentButton.FirstWidgetUnderMouse)
            {
                if (parentButton.MouseDownOnWidget)
                {
                    insideColor = DefaultViewFactory.DefaultBlue;
                }
                else
                {
                    insideColor = DefaultViewFactory.DefaultBlue.ToColorF().Blend(ColorF.White, .75).ToColor();
                }
            }

            graphics2D.Render(rectInside, insideColor);

            base.OnDraw(graphics2D);
        }
Exemple #16
0
        private void UpdateScrollBar()
        {
            switch (Show)
            {
            case ShowState.WhenRequired:
                if (ParentScrollWidget.ScrollArea.Height > ParentScrollWidget.Height)
                {
                    goto case ShowState.Always;
                }
                else
                {
                    goto case ShowState.Never;
                }

            case ShowState.Always:
                // make sure we can see it
                Visible = true;
                // fix the bounds of the scroll bar background
                LocalBounds            = new RectangleDouble(0, 0, ScrollBarWidth, ParentScrollWidget.Height);
                background.LocalBounds = LocalBounds;

                // this is for vertical scroll bar
                thumb.LocalBounds = new RectangleDouble(0, 0, ScrollBarWidth, ThumbHeight);

                Vector2 scrollRatioFromTop0To1 = ParentScrollWidget.ScrollRatioFromTop0To1;
                double  notThumbHeight         = ParentScrollWidget.Height - ThumbHeight;
                thumb.OriginRelativeParent = new Vector2(0, notThumbHeight * scrollRatioFromTop0To1.y);

                ParentScrollWidget.ScrollArea.Padding = new BorderDouble(0, 0, ScrollBar.ScrollBarWidth, 0);

                break;

            case ShowState.Never:
                Visible = false;

                ParentScrollWidget.ScrollArea.Padding = new BorderDouble(0, 0, 0, 0);

                break;
            }
        }
Exemple #17
0
        public ImageSequenceWidget(int width, int height)
        {
            LocalBounds = new RectangleDouble(0, 0, width, height);

            animation.DrawTarget = this;
            animation.Update    += (s, updateEvent) =>
            {
                var currentImageIndex = ImageSequence.GetImageIndexByTime(currentTime);

                currentTime += updateEvent.SecondsPassed;
                while (ImageSequence.Time > 0 &&
                       currentTime > ImageSequence.Time)
                {
                    currentTime -= ImageSequence.Time;
                }

                var newImageIndex = ImageSequence.GetImageIndexByTime(currentTime);
                updateEvent.ShouldDraw = currentImageIndex != newImageIndex;
            };

            RunAnimation = true;
        }
        public override void OnDraw(Graphics2D graphics2D)
        {
            if (borderColor.Alpha0To255 > 0)
            {
                RectangleDouble boarderRectangle = LocalBounds;
                boarderRectangle.Inflate(-borderWidth / 2);
                RoundedRect rectBorder = new RoundedRect(boarderRectangle, this.borderRadius);

                graphics2D.Render(new Stroke(rectBorder, borderWidth), borderColor);
            }

            if (this.fillColor.Alpha0To255 > 0)
            {
                RectangleDouble insideBounds = LocalBounds;
                insideBounds.Inflate(-this.borderWidth);
                RoundedRect rectInside = new RoundedRect(insideBounds, Math.Max(this.borderRadius - this.borderWidth, 0));

                graphics2D.Render(rectInside, this.fillColor);
            }

            base.OnDraw(graphics2D);
        }
        void DoChangePanel(object state)
        {
            // remember which tab we were on
            int topTabIndex = this.advancedControlsTabControl.SelectedTabIndex;

            // remove the advance control and replace it with new ones build for the selected printer
            int advancedControlsWidgetIndex = Panel2.GetChildIndex(this.advancedControlsTabControl);

            Panel2.RemoveChild(advancedControlsWidgetIndex);
            this.advancedControlsTabControl = CreateNewAdvancedControlsTab(sliceSettingsUiState);
            Panel2.AddChild(this.advancedControlsTabControl, advancedControlsWidgetIndex);

            // set the selected tab back to the one it was before we replace the control
            this.advancedControlsTabControl.SelectTab(topTabIndex);

            // This is a hack to make the pannel remain on the screen.  It would be great to debug it and understand
            // why it does not work without this code in here.
            RectangleDouble localBounds = this.LocalBounds;

            this.LocalBounds = new RectangleDouble(0, 0, this.LocalBounds.Width - 1, 10);
            this.LocalBounds = localBounds;
        }
Exemple #20
0
        public RayTraceWidget(int width = 200, int height = 200)
        {
            world = new WorldView(width, height);

            trackballTumbleWidget = new TrackballTumbleWidget(world, this);
            //trackballTumbleWidget.DrawGlContent += trackballTumbleWidget_DrawGlContent;
            trackballTumbleWidget.TransformState = TrackBallTransformType.Rotation;

            AddChild(trackballTumbleWidget);

            totalTime.Start();

            CreateScene();
            LocalBounds = new RectangleDouble(0, 0, width, height);

            world.Scale = .03;

            world.Rotate(Quaternion.FromEulerAngles(new Vector3(0, 0, MathHelper.Tau / 16)));
            world.Rotate(Quaternion.FromEulerAngles(new Vector3(-MathHelper.Tau * .19, 0, 0)));

            trackballTumbleWidget.AnchorAll();
        }
Exemple #21
0
        private static ScreenRectangle SystemWindowToScreen(RectangleDouble rectOnScreen, SystemWindow containingWindow)
        {
            ScreenRectangle screenPosition = new ScreenRectangle()
            {
                Left   = (int)rectOnScreen.Left,
                Top    = (int)rectOnScreen.Top,
                Right  = (int)rectOnScreen.Right,
                Bottom = (int)rectOnScreen.Bottom,
            };

            screenPosition.Top    = (int)containingWindow.Height - screenPosition.Top;
            screenPosition.Bottom = (int)containingWindow.Height - screenPosition.Bottom;

            WidgetForWindowsFormsAbstract mappingWidget = containingWindow.Parent as WidgetForWindowsFormsAbstract;

            screenPosition.Left   += mappingWidget.WindowsFormsWindow.Location.X;
            screenPosition.Top    += (mappingWidget.WindowsFormsWindow.Location.Y + mappingWidget.WindowsFormsWindow.TitleBarHeight);
            screenPosition.Right  += mappingWidget.WindowsFormsWindow.Location.X;
            screenPosition.Bottom += (mappingWidget.WindowsFormsWindow.Location.Y + mappingWidget.WindowsFormsWindow.TitleBarHeight);

            return(screenPosition);
        }
Exemple #22
0
        public MainMenu(RectangleDouble bounds)
        {
            BoundsRelativeToParent = bounds;

            ImageSequence startButtonSequence = (ImageSequence)DataAssetCache.Instance.GetAsset(typeof(ImageSequence), "MainMenuStartButton");
            Button        StartGameButton     = new Button(400, 310, new ButtonViewThreeImage(startButtonSequence.GetImageByIndex(0), startButtonSequence.GetImageByIndex(1), startButtonSequence.GetImageByIndex(2)));

            AddChild(StartGameButton);
            StartGameButton.Click += OnStartGameButton;

            ImageSequence creditsButtonSequence = (ImageSequence)DataAssetCache.Instance.GetAsset(typeof(ImageSequence), "MainMenuCreditsButton");
            Button        creditsGameButton     = new Button(400, 230, new ButtonViewThreeImage(creditsButtonSequence.GetImageByIndex(0), creditsButtonSequence.GetImageByIndex(1), creditsButtonSequence.GetImageByIndex(2)));

            AddChild(creditsGameButton);
            creditsGameButton.Click += OnShowCreditsButton;

            ImageSequence exitButtonSequence = (ImageSequence)DataAssetCache.Instance.GetAsset(typeof(ImageSequence), "MainMenuExitButton");
            Button        exitGameButton     = new Button(400, 170, new ButtonViewThreeImage(exitButtonSequence.GetImageByIndex(0), exitButtonSequence.GetImageByIndex(1), exitButtonSequence.GetImageByIndex(2)));

            AddChild(exitGameButton);
            exitGameButton.Click += OnExitGameButton;
        }
        public static ScreenRectangle SystemWindowToScreen(RectangleDouble rectOnScreen, SystemWindow containingWindow)
        {
            ScreenRectangle screenPosition = new ScreenRectangle()
            {
                Left   = (int)rectOnScreen.Left,
                Top    = (int)rectOnScreen.Top,
                Right  = (int)rectOnScreen.Right,
                Bottom = (int)rectOnScreen.Bottom,
            };

            screenPosition.Top    = (int)containingWindow.Height - screenPosition.Top;
            screenPosition.Bottom = (int)containingWindow.Height - screenPosition.Bottom;

            AbstractOsMappingWidget mappingWidget = containingWindow.Parent as AbstractOsMappingWidget;

            screenPosition.Left   += mappingWidget.DesktopPosition.x;
            screenPosition.Top    += (mappingWidget.DesktopPosition.y + mappingWidget.TitleBarHeight);
            screenPosition.Right  += mappingWidget.DesktopPosition.x;
            screenPosition.Bottom += (mappingWidget.DesktopPosition.y + mappingWidget.TitleBarHeight);

            return(screenPosition);
        }
Exemple #24
0
        public override void OnDraw(Graphics2D graphics2D)
        {
            if (this.libraryDataView.EditMode && !this.IsViewHelperItem)
            {
                this.selectionCheckBox.Checked     = this.IsSelectedItem;
                selectionCheckBoxContainer.Visible = true;
                rightButtonOverlay.Visible         = false;
            }
            else
            {
                selectionCheckBoxContainer.Visible = false;
            }

            base.OnDraw(graphics2D);

            if (this.IsSelectedItem && !this.IsViewHelperItem)
            {
                this.BackgroundColor             = ActiveTheme.Instance.PrimaryAccentColor;
                this.partLabel.TextColor         = RGBA_Bytes.White;
                this.selectionCheckBox.TextColor = RGBA_Bytes.White;
            }
            else if (this.IsHoverItem)
            {
                RectangleDouble Bounds     = LocalBounds;
                RoundedRect     rectBorder = new RoundedRect(Bounds, 0);

                this.BackgroundColor             = RGBA_Bytes.White;
                this.partLabel.TextColor         = RGBA_Bytes.Black;
                this.selectionCheckBox.TextColor = RGBA_Bytes.Black;

                graphics2D.Render(new Stroke(rectBorder, 3), ActiveTheme.Instance.SecondaryAccentColor);
            }
            else
            {
                this.BackgroundColor             = new RGBA_Bytes(255, 255, 255, 255);
                this.partLabel.TextColor         = RGBA_Bytes.Black;
                this.selectionCheckBox.TextColor = RGBA_Bytes.Black;
            }
        }
Exemple #25
0
        private void FixOriginYIfTopToBottom(GuiWidget parent)
        {
            if (parent.VAnchorIsSet(VAnchor.Fit) && FlowDirection == UI.FlowDirection.TopToBottom)
            {
                RectangleDouble encloseChildrenRect = parent.GetMinimumBoundsToEncloseChildren();

                foreach (GuiWidget child in parent.Children)
                {
                    if (parent.HasBeenClosed)
                    {
                        return;
                    }

                    if (child.Visible == false)
                    {
                        continue;
                    }

                    child.OriginRelativeParent = new Vector2(child.OriginRelativeParent.X, child.OriginRelativeParent.Y - encloseChildrenRect.Bottom);
                }
            }
        }
        public override void Show()
        {
            // Center the window if specified on the SystemWindow
            if (mainWindowsFormsWindow != WindowsFormsWindow && childSystemWindow.CenterInParent)
            {
                Rectangle       desktopBounds = mainWindowsFormsWindow.DesktopBounds;
                RectangleDouble newItemBounds = childSystemWindow.LocalBounds;

                windowsFormsWindow.Left = desktopBounds.X + desktopBounds.Width / 2 - (int)newItemBounds.Width / 2;
                windowsFormsWindow.Top  = desktopBounds.Y + desktopBounds.Height / 2 - (int)newItemBounds.Height / 2 - TitleBarHeight / 2;
            }

            if (mainWindowsFormsWindow != WindowsFormsWindow &&
                childSystemWindow.AlwaysOnTopOfMain)
            {
                WindowsFormsWindow.Show(mainWindowsFormsWindow);
            }
            else
            {
                WindowsFormsWindow.Show();
            }
        }
Exemple #27
0
        private void FixOriginXIfRightToLeft(GuiWidget parent)
        {
            if (parent.HAnchorIsSet(HAnchor.Fit) && FlowDirection == UI.FlowDirection.RightToLeft)
            {
                RectangleDouble encloseChildrenRect = parent.GetMinimumBoundsToEncloseChildren();

                foreach (GuiWidget child in parent.Children)
                {
                    if (parent.HasBeenClosed)
                    {
                        return;
                    }

                    if (child.Visible == false)
                    {
                        continue;
                    }

                    child.OriginRelativeParent = new Vector2(child.OriginRelativeParent.X - encloseChildrenRect.Left, child.OriginRelativeParent.Y);
                }
            }
        }
Exemple #28
0
        public override void OnParentChanged(EventArgs e)
        {
            Button parentButton = (Button)Parent;

            RectangleInt imageBounds = normalImage.GetBounds();

            parentButton.OriginRelativeParent += new Vector2(imageBounds.Left, imageBounds.Bottom);

            RectangleDouble bounds = parentButton.LocalBounds;

            bounds.Right            += imageBounds.Width;
            bounds.Top              += imageBounds.Height;
            this.LocalBounds         = bounds;
            parentButton.LocalBounds = bounds;

            parentButton.MouseEnter += redrawButtonIfRequired;
            parentButton.MouseDown  += redrawButtonIfRequired;
            parentButton.MouseUp    += redrawButtonIfRequired;
            parentButton.MouseLeave += new EventHandler(parentButton_MouseLeave);

            base.OnParentChanged(null);
        }
Exemple #29
0
        public override void OnDraw(Graphics2D graphics2D)
        {
            Button parentButton = (Button)Parent;

            RectangleDouble Bounds = LocalBounds;

            RoundedRect rectBorder = new RoundedRect(Bounds, BorderRadius);

            if (parentButton.Enabled == true)
            {
                graphics2D.Render(rectBorder, new RGBA_Bytes(0, 0, 0));
            }
            else
            {
                graphics2D.Render(rectBorder, new RGBA_Bytes(128, 128, 128));
            }
            RectangleDouble insideBounds = Bounds;

            insideBounds.Inflate(-BorderWidth);
            RoundedRect rectInside  = new RoundedRect(insideBounds, Math.Max(BorderRadius - BorderWidth, 0));
            RGBA_Bytes  insideColor = new RGBA_Bytes(1.0, 1.0, 1.0);

            if (parentButton.FirstWidgetUnderMouse)
            {
                if (parentButton.MouseDownOnButton)
                {
                    insideColor = DefaultViewFactory.DefaultBlue;
                }
                else
                {
                    insideColor = DefaultViewFactory.DefaultBlue.GetAsRGBA_Floats().Blend(RGBA_Floats.White, .75).GetAsRGBA_Bytes();
                }
            }

            graphics2D.Render(rectInside, insideColor);

            base.OnDraw(graphics2D);
        }
Exemple #30
0
        private void UpdateScrollBar()
        {
            switch (Show)
            {
            case ShowState.WhenRequired:
                if (ParentScrollWidget.ScrollArea.Height > ParentScrollWidget.Height)
                {
                    goto case ShowState.Always;
                }
                else
                {
                    goto case ShowState.Never;
                }

            case ShowState.Always:
                // make sure we can see it
                Visible = true;
                // fix the bounds of the scroll bar background
                LocalBounds            = new RectangleDouble(0, 0, ScrollBarWidth, ParentScrollWidget.Height);
                background.LocalBounds = LocalBounds;

                // On hover, grow the thumb bounds by the given value
                int growAmount = (mouseInBounds) ? 0 : ScrollBar.GrowThumbBy;
                thumb.LocalBounds = new RectangleDouble(growAmount, 0, ScrollBarWidth - growAmount, ThumbHeight);

                Vector2 scrollRatioFromTop0To1 = ParentScrollWidget.ScrollRatioFromTop0To1;
                double  notThumbHeight         = ParentScrollWidget.Height - ThumbHeight;
                thumb.OriginRelativeParent = new Vector2(0, notThumbHeight * scrollRatioFromTop0To1.Y);
                break;

            case ShowState.Never:
                Visible = false;
                break;
            }

            // HACK: Workaround to fix problems with initial positioning - set padding on ScrollArea to force layout
            this.ParentScrollWidget.ScrollArea.Padding = 0;
        }
Exemple #31
0
        public override RectangleDouble GetBounds()
        {
            RectangleDouble bounds = new RectangleDouble(double.MaxValue, double.MaxValue, double.MinValue, double.MinValue);

#if !MULTI_THREAD
            foreach (PrinterMachineInstruction state in GCodeCommandQueue)
            {
                bounds.Left   = Math.Min(state.Position.x, bounds.Left);
                bounds.Right  = Math.Max(state.Position.x, bounds.Right);
                bounds.Bottom = Math.Min(state.Position.y, bounds.Bottom);
                bounds.Top    = Math.Max(state.Position.y, bounds.Top);
            }
#else
            Parallel.For <RectangleDouble>(
                0,
                GCodeCommandQueue.Count,
                () => new RectangleDouble(double.MaxValue, double.MaxValue, double.MinValue, double.MinValue),
                (int index, ParallelLoopState loop, RectangleDouble subtotal) =>
            {
                PrinterMachineInstruction state = GCodeCommandQueue[index];
                subtotal.Left   = Math.Min(state.Position.x, subtotal.Left);
                subtotal.Right  = Math.Max(state.Position.x, subtotal.Right);
                subtotal.Bottom = Math.Min(state.Position.y, subtotal.Bottom);
                subtotal.Top    = Math.Max(state.Position.y, subtotal.Top);

                return(subtotal);
            },
                (x) =>
            {
                bounds.Left   = Math.Min(x.Left, bounds.Left);
                bounds.Right  = Math.Max(x.Right, bounds.Right);
                bounds.Bottom = Math.Min(x.Bottom, bounds.Bottom);
                bounds.Top    = Math.Max(x.Top, bounds.Top);
            }
                );
#endif
            return(bounds);
        }
Exemple #32
0
        public void DoDrawAfterChildren(Graphics2D graphics2D)
        {
            RoundedRect track = new RoundedRect(GetTrackBounds(), 0);
            Vector2     ValuePrintPosition;

            if (sliderAttachedTo.Orientation == Orientation.Horizontal)
            {
                ValuePrintPosition = new Vector2(sliderAttachedTo.TotalWidthInPixels / 2, -TrackHeight - 12);
            }
            else
            {
                ValuePrintPosition = new Vector2(0, -TrackHeight - 12);
            }

            // draw the track
            graphics2D.Render(track, TrackColor);

            // now do the thumb
            RectangleDouble thumbBounds  = sliderAttachedTo.GetThumbHitBounds();
            RoundedRect     thumbOutside = new RoundedRect(thumbBounds, 0);

            graphics2D.Render(thumbOutside, RGBA_Floats.GetTweenColor(ThumbColor.GetAsRGBA_Floats(), RGBA_Floats.Black.GetAsRGBA_Floats(), .2).GetAsRGBA_Bytes());
        }
        public bool MoveToByName(string widgetName, double secondsToWait = 0, SearchRegion searchRegion = null, Point2D offset = default(Point2D), ClickOrigin origin = ClickOrigin.Center)
        {
            SystemWindow containingWindow;
            GuiWidget    widgetToClick = GetWidgetByName(widgetName, out containingWindow, secondsToWait, searchRegion);

            if (widgetToClick != null)
            {
                RectangleDouble childBounds = widgetToClick.TransformToParentSpace(containingWindow, widgetToClick.LocalBounds);

                if (origin == ClickOrigin.Center)
                {
                    offset.x += (int)childBounds.Width / 2;
                    offset.y += (int)childBounds.Height / 2;
                }

                Point2D screenPosition = SystemWindowToScreen(new Point2D(childBounds.Left + offset.x, childBounds.Bottom + offset.y), containingWindow);
                SetMouseCursorPosition(screenPosition.x, screenPosition.y);

                return(true);
            }

            return(false);
        }
        public override void OnDraw(Agg.Graphics2D graphics2D)
        {
            RectangleDouble Bounds     = LocalBounds;
            RoundedRect     rectBorder = new RoundedRect(Bounds, this.borderRadius);

            graphics2D.Render(rectBorder, borderColor);

            RectangleDouble insideBounds = Bounds;

            insideBounds.Inflate(-this.borderWidth);
            RoundedRect rectInside = new RoundedRect(insideBounds, Math.Max(this.borderRadius - this.borderWidth, 0));

            graphics2D.Render(rectInside, this.fillColor);

            if (this.isUnderlined)
            {
                //Printer.TypeFaceStyle.DoUnderline = true;
                RectangleDouble underline = new RectangleDouble(LocalBounds.Left, LocalBounds.Bottom, LocalBounds.Right, LocalBounds.Bottom);
                graphics2D.Rectangle(underline, buttonText.TextColor);
            }

            base.OnDraw(graphics2D);
        }
Exemple #35
0
        private void RemovePanelsAndCreateEmpties()
        {
            CloseAllChildren();

            ColumnOne = new FlowLayoutWidget(FlowDirection.TopToBottom);
            ColumnTwo = new FlowLayoutWidget(FlowDirection.TopToBottom);

            AddChild(ColumnOne);
            leftBorderLine = new GuiWidget()
            {
                VAnchor = VAnchor.ParentBottomTop
            };
            leftBorderLine.Width       = 15;
            leftBorderLine.BeforeDraw += (widget, graphics2D) =>
            {
                RectangleDouble bounds = ((GuiWidget)widget).LocalBounds;
                bounds.Left  += 3;
                bounds.Right -= 8;
                graphics2D.graphics2D.FillRectangle(bounds, new RGBA_Bytes(160, 160, 160));
            };
            AddChild(leftBorderLine);
            AddChild(ColumnTwo);
        }
Exemple #36
0
		public RoundedRect(double left, double bottom, double right, double top, double radius)
		{
			bounds = new RectangleDouble(left, bottom, right, top);
			leftBottomRadius.x = radius;
			leftBottomRadius.y = radius;
			rightBottomRadius.x = radius;
			rightBottomRadius.y = radius;
			rightTopRadius.x = radius;
			rightTopRadius.y = radius;
			leftTopRadius.x = radius;
			leftTopRadius.y = radius;

			if (left > right)
			{
				bounds.Left = right;
				bounds.Right = left;
			}

			if (bottom > top)
			{
				bounds.Bottom = top;
				bounds.Top = bottom;
			}
		}
Exemple #37
0
		protected virtual bool CurrentScreenClipping(out RectangleDouble screenClippingRect)
		{
			if (screenClipping.NeedRebuild)
			{
				DrawCount++;
				screenClipping.screenClippingRect = TransformToScreenSpace(LocalBounds);

				if (Parent != null)
				{
					RectangleDouble screenParentClipping;
					if (Parent.CurrentScreenClipping(out screenParentClipping))
					{
						RectangleDouble intersectionRect = new RectangleDouble();
						if (intersectionRect.IntersectRectangles(screenClipping.screenClippingRect, screenParentClipping))
						{
							screenClipping.screenClippingRect = intersectionRect;
							screenClipping.visibleAfterClipping = true;
						}
						else
						{
							// this rect is clipped away by the parent rect so return false.
							screenClipping.visibleAfterClipping = false;
						}
					}
					else
					{
						// the parent is completely clipped away, so this is too.
						screenClipping.visibleAfterClipping = false;
					}
				}
				screenClipping.NeedRebuild = false;
			}

			screenClippingRect = screenClipping.screenClippingRect;
			return screenClipping.visibleAfterClipping;
		}
Exemple #38
0
		private static void DrawBorderBounds(Graphics2D graphics2D, RectangleDouble bounds, BorderDouble border, RGBA_Bytes color)
		{
			if (border.Width != 0
				|| border.Height != 0)
			{
				PathStorage borderPath = new PathStorage();
				borderPath.MoveTo(bounds.Left, bounds.Bottom);
				borderPath.LineTo(bounds.Left, bounds.Top);
				borderPath.LineTo(bounds.Right, bounds.Top);
				borderPath.LineTo(bounds.Right, bounds.Bottom);
				borderPath.LineTo(bounds.Left, bounds.Bottom);

				borderPath.MoveTo(bounds.Left + border.Left, bounds.Bottom + border.Bottom);
				borderPath.LineTo(bounds.Right - border.Right, bounds.Bottom + border.Bottom);
				borderPath.LineTo(bounds.Right - border.Right, bounds.Top - border.Top);
				borderPath.LineTo(bounds.Left + border.Left, bounds.Top - border.Top);
				borderPath.LineTo(bounds.Left + border.Left, bounds.Bottom + border.Bottom);
				graphics2D.Render(borderPath, color);
			}
		}
Exemple #39
0
		public virtual void Invalidate(RectangleDouble rectToInvalidate)
		{
			isCurrentlyInvalid = true;
			if (Parent != null)
			{
				rectToInvalidate.Offset(OriginRelativeParent);
				Parent.Invalidate(rectToInvalidate);
			}

			if (Invalidated != null)
			{
				Invalidated(this, new InvalidateEventArgs(rectToInvalidate));
			}
		}
Exemple #40
0
		public void SetBoundsRelativeToParent(RectangleInt newBounds)
		{
			RectangleDouble bounds = new RectangleDouble(newBounds.Left, newBounds.Bottom, newBounds.Right, newBounds.Top);

			BoundsRelativeToParent = bounds;
		}
Exemple #41
0
		private void RecalculateBounds()
		{
			needToRecalculateBounds = false;
			return;

#if false
            double extraForControlPoints = m_point_radius * 1.3;
            RectangleDouble newBounds = new RectangleDouble(double.MaxValue, double.MaxValue, double.MinValue, double.MinValue);
            for (int i = 0; i < m_num_points; i++)
            {
                newBounds.Left = Math.Min(GetXN(i) - extraForControlPoints, newBounds.Left);
                newBounds.Right = Math.Max(GetXN(i) + extraForControlPoints, newBounds.Right);
                newBounds.Bottom = Math.Min(GetYN(i) - extraForControlPoints, newBounds.Bottom);
                newBounds.Top = Math.Max(GetYN(i) + extraForControlPoints, newBounds.Top);
            }

            Invalidate();
            LocalBounds = newBounds;
            Invalidate();
#endif
		}
Exemple #42
0
		public GuiWidget(double width, double height, SizeLimitsToSet sizeLimits = SizeLimitsToSet.Minimum)
			: this(HAnchor.AbsolutePosition, VAnchor.AbsolutePosition)
		{
			screenClipping = new ScreenClipping(this);
			if ((sizeLimits & SizeLimitsToSet.Minimum) == SizeLimitsToSet.Minimum)
			{
				MinimumSize = new Vector2(width, height);
			}
			if ((sizeLimits & SizeLimitsToSet.Maximum) == SizeLimitsToSet.Maximum)
			{
				MaximumSize = new Vector2(width, height);
			}
			LocalBounds = new RectangleDouble(0, 0, width, height);
		}
Exemple #43
0
		public void LeftRightWithAnchorLeftRightChildTest(BorderDouble controlPadding, BorderDouble buttonMargin)
		{
			double buttonSize = 40;
			GuiWidget containerControl = new GuiWidget(buttonSize * 8, buttonSize * 3);
			containerControl.Padding = controlPadding;
			containerControl.DoubleBuffer = true;

			RectangleDouble[] eightControlRectangles = new RectangleDouble[8];
			RGBA_Bytes[] eightColors = new RGBA_Bytes[] { RGBA_Bytes.Red, RGBA_Bytes.Orange, RGBA_Bytes.Yellow, RGBA_Bytes.YellowGreen, RGBA_Bytes.Green, RGBA_Bytes.Blue, RGBA_Bytes.Indigo, RGBA_Bytes.Violet };
			{
				double currentleft = controlPadding.Left + buttonMargin.Left;
				double buttonHeightWithMargin = buttonSize + buttonMargin.Height;
				double scalledWidth = (containerControl.Width - controlPadding.Width - buttonMargin.Width * 8 - buttonSize * 2) / 6;
				// the left unsized rect
				eightControlRectangles[0] = new RectangleDouble(
						currentleft,
						0,
						currentleft + buttonSize,
						buttonSize);

				// a bottom anchor
				currentleft += buttonSize + buttonMargin.Width;
				double bottomAnchorY = controlPadding.Bottom + buttonMargin.Bottom;
				eightControlRectangles[1] = new RectangleDouble(currentleft, bottomAnchorY, currentleft + scalledWidth, bottomAnchorY + buttonSize);

				// center anchor
				double centerYOfContainer = controlPadding.Bottom + (containerControl.Height - controlPadding.Height) / 2;
				currentleft += scalledWidth + buttonMargin.Width;
				eightControlRectangles[2] = new RectangleDouble(currentleft, centerYOfContainer - buttonHeightWithMargin / 2 + buttonMargin.Bottom, currentleft + scalledWidth, centerYOfContainer + buttonHeightWithMargin / 2 - buttonMargin.Top);

				// top anchor
				double topAnchorY = containerControl.Height - controlPadding.Top - buttonMargin.Top;
				currentleft += scalledWidth + buttonMargin.Width;
				eightControlRectangles[3] = new RectangleDouble(currentleft, topAnchorY - buttonSize, currentleft + scalledWidth, topAnchorY);

				// bottom center anchor
				currentleft += scalledWidth + buttonMargin.Width;
				eightControlRectangles[4] = new RectangleDouble(currentleft, bottomAnchorY, currentleft + scalledWidth, centerYOfContainer - buttonMargin.Top);

				// center top anchor
				currentleft += scalledWidth + buttonMargin.Width;
				eightControlRectangles[5] = new RectangleDouble(currentleft, centerYOfContainer + buttonMargin.Bottom, currentleft + scalledWidth, topAnchorY);

				// bottom top anchor
				currentleft += scalledWidth + buttonMargin.Width;
				eightControlRectangles[6] = new RectangleDouble(currentleft, bottomAnchorY, currentleft + scalledWidth, topAnchorY);

				// right anchor
				currentleft += scalledWidth + buttonMargin.Width;
				eightControlRectangles[7] = new RectangleDouble(currentleft, 0, currentleft + buttonSize, buttonSize);

				Graphics2D graphics = containerControl.NewGraphics2D();
				for (int i = 0; i < 8; i++)
				{
					graphics.FillRectangle(eightControlRectangles[i], eightColors[i]);
				}
			}

			GuiWidget containerTest = new GuiWidget(containerControl.Width, containerControl.Height);
			FlowLayoutWidget leftToRightFlowLayoutAll = new FlowLayoutWidget(FlowDirection.LeftToRight);
			containerTest.DoubleBuffer = true;
			{
				leftToRightFlowLayoutAll.AnchorAll();
				leftToRightFlowLayoutAll.Padding = controlPadding;
				{
					GuiWidget left = new GuiWidget(buttonSize, buttonSize);
					left.BackgroundColor = RGBA_Bytes.Red;
					left.Margin = buttonMargin;
					leftToRightFlowLayoutAll.AddChild(left);

					leftToRightFlowLayoutAll.AddChild(CreateLeftToRightMiddleWidget(buttonMargin, buttonSize, VAnchor.ParentBottom, RGBA_Bytes.Orange));
					leftToRightFlowLayoutAll.AddChild(CreateLeftToRightMiddleWidget(buttonMargin, buttonSize, VAnchor.ParentCenter, RGBA_Bytes.Yellow));
					leftToRightFlowLayoutAll.AddChild(CreateLeftToRightMiddleWidget(buttonMargin, buttonSize, VAnchor.ParentTop, RGBA_Bytes.YellowGreen));
					leftToRightFlowLayoutAll.AddChild(CreateLeftToRightMiddleWidget(buttonMargin, buttonSize, VAnchor.ParentBottomCenter, RGBA_Bytes.Green));
					leftToRightFlowLayoutAll.AddChild(CreateLeftToRightMiddleWidget(buttonMargin, buttonSize, VAnchor.ParentCenterTop, RGBA_Bytes.Blue));
					leftToRightFlowLayoutAll.AddChild(CreateLeftToRightMiddleWidget(buttonMargin, buttonSize, VAnchor.ParentBottomTop, RGBA_Bytes.Indigo));

					GuiWidget right = new GuiWidget(buttonSize, buttonSize);
					right.BackgroundColor = RGBA_Bytes.Violet;
					right.Margin = buttonMargin;
					leftToRightFlowLayoutAll.AddChild(right);
				}

				containerTest.AddChild(leftToRightFlowLayoutAll);
			}

			containerTest.OnDraw(containerTest.NewGraphics2D());
			OutputImages(containerControl, containerTest);

			for (int i = 0; i < 8; i++)
			{
				Assert.IsTrue(eightControlRectangles[i] == leftToRightFlowLayoutAll.Children[i].BoundsRelativeToParent);
			}

			Assert.IsTrue(containerControl.BackBuffer != null, "When we set a guiWidget to DoubleBuffer it needs to create one.");

			// we use a least squares match because the erase background that is setting the widgets is integer pixel based and the fill rectangle is not.
			Assert.IsTrue(containerControl.BackBuffer.FindLeastSquaresMatch(containerTest.BackBuffer, 0), "The test and control need to match.");
		}
Exemple #44
0
		/// <summary>
		/// This will create a new ImageBuffer that references the same memory as the image that you took the sub image from.
		/// It will modify the original main image when you draw to it.
		/// </summary>
		/// <param name="imageContainingSubImage"></param>
		/// <param name="subImageBounds"></param>
		/// <returns></returns>
		public static ImageBuffer NewSubImageReference(IImageByte imageContainingSubImage, RectangleDouble subImageBounds)
		{
			ImageBuffer subImage = new ImageBuffer();
			if (subImageBounds.Left < 0 || subImageBounds.Bottom < 0 || subImageBounds.Right > imageContainingSubImage.Width || subImageBounds.Top > imageContainingSubImage.Height
				|| subImageBounds.Left >= subImageBounds.Right || subImageBounds.Bottom >= subImageBounds.Top)
			{
				throw new ArgumentException("The subImageBounds must be on the image and valid.");
			}
			int left = Math.Max(0, (int)Math.Floor(subImageBounds.Left));
			int bottom = Math.Max(0, (int)Math.Floor(subImageBounds.Bottom));
			int width = Math.Min(imageContainingSubImage.Width - left, (int)subImageBounds.Width);
			int height = Math.Min(imageContainingSubImage.Height - bottom, (int)subImageBounds.Height);
			int bufferOffsetToFirstPixel = imageContainingSubImage.GetBufferOffsetXY(left, bottom);
			subImage.AttachBuffer(imageContainingSubImage.GetBuffer(), bufferOffsetToFirstPixel, width, height, imageContainingSubImage.StrideInBytes(), imageContainingSubImage.BitDepth, imageContainingSubImage.GetBytesBetweenPixelsInclusive());
			subImage.SetRecieveBlender(imageContainingSubImage.GetRecieveBlender());

			return subImage;
		}
Exemple #45
0
		private RectangleDouble GetTrackBounds()
		{
			RectangleDouble trackBounds;
			if (sliderAttachedTo.Orientation == Orientation.Horizontal)
			{
				trackBounds = new RectangleDouble(0, -TrackHeight / 2, sliderAttachedTo.TotalWidthInPixels, TrackHeight / 2);
			}
			else
			{
				trackBounds = new RectangleDouble(-TrackHeight / 2, 0, TrackHeight / 2, sliderAttachedTo.TotalWidthInPixels);
			}
			return trackBounds;
		}
		public override void Invalidate(RectangleDouble rectToInvalidate)
		{
			rectToInvalidate.IntersectWithRectangle(LocalBounds);

			//rectToInvalidate = new rect_d(0, 0, Width, Height);

			Rectangle windowsRectToInvalidate = GetRectangleFromRectD(rectToInvalidate);
			if (WindowsFormsWindow != null)
			{
				WindowsFormsWindow.RequestInvalidate(windowsRectToInvalidate);
			}
		}
Exemple #47
0
		public ListBox(RectangleDouble bounds)
		{
			AutoScroll = true;
			LocalBounds = new RectangleDouble(0, 0, bounds.Width, bounds.Height);
			topToBottomItemList = new FlowLayoutWidget(FlowDirection.TopToBottom);
			topToBottomItemList.HAnchor = UI.HAnchor.ParentLeft | UI.HAnchor.FitToChildren;
			base.AddChild(topToBottomItemList);
		}
Exemple #48
0
			private RectangleDouble GetThumbBounds()
			{
				RectangleDouble thumbBounds;
				if (startValue)
				{
					thumbBounds = new RectangleDouble(switchWidth - thumbWidth, 0, switchWidth, thumbHeight);
				}
				else
				{
					thumbBounds = new RectangleDouble(0, 0, thumbWidth, thumbHeight);
				}

				return thumbBounds;
			}
Exemple #49
0
		public RectangleDouble TransformToParentSpace(GuiWidget parentToGetRelativeTo, RectangleDouble rectangleToTransform)
		{
			GuiWidget widgetToTransformBy = this;
			while (widgetToTransformBy != null
				&& widgetToTransformBy != parentToGetRelativeTo)
			{
				rectangleToTransform.Offset(widgetToTransformBy.OriginRelativeParent);
				widgetToTransformBy = widgetToTransformBy.Parent;
			}

			return rectangleToTransform;
		}
		public override void Invalidate(RectangleDouble rectToInvalidate)
		{
			base.Invalidate(rectToInvalidate);
		}
Exemple #51
0
		public RectangleDouble TransformToScreenSpace(RectangleDouble rectangleToTransform)
		{
			GuiWidget prevGUIWidget = this;
			while (prevGUIWidget != null)
			{
				rectangleToTransform.Offset(prevGUIWidget.OriginRelativeParent);
				prevGUIWidget = prevGUIWidget.Parent;
			}

			return rectangleToTransform;
		}
Exemple #52
0
		public void transform(ref RectangleDouble rectToTransform)
		{
			transform(ref rectToTransform.Left, ref rectToTransform.Bottom);
			transform(ref rectToTransform.Right, ref rectToTransform.Top);
		}
Exemple #53
0
		public RectangleDouble GetChildrenBoundsIncludingMargins(bool considerChildAnchor = false)
		{
			RectangleDouble boundsOfAllChildrenIncludingMargin = new RectangleDouble();

			if (this.CountVisibleChildren() > 0)
			{
				Vector2 minSize = Vector2.Zero;
				boundsOfAllChildrenIncludingMargin = RectangleDouble.ZeroIntersection;
				bool foundHBounds = false;
				bool foundVBounds = false;
				foreach (GuiWidget child in Children)
				{
					if (child.Visible == false)
					{
						continue;
					}

					if (considerChildAnchor)
					{
						minSize.x = Math.Max(child.Width + child.Margin.Width, minSize.x);
						minSize.y = Math.Max(child.Height + child.Margin.Height, minSize.y);

						RectangleDouble childBoundsWithMargin = child.BoundsRelativeToParent;
						childBoundsWithMargin.Inflate(child.Margin);

						if (!child.HAnchorIsFloating)
						{
							foundHBounds = true;
							// it can't move so make sure our horizontal bounds enclose it
							if (boundsOfAllChildrenIncludingMargin.Right < childBoundsWithMargin.Right)
							{
								boundsOfAllChildrenIncludingMargin.Right = childBoundsWithMargin.Right;
							}

							if (boundsOfAllChildrenIncludingMargin.Left > childBoundsWithMargin.Left)
							{
								boundsOfAllChildrenIncludingMargin.Left = childBoundsWithMargin.Left;
							}
						}

						if (!child.VAnchorIsFloating)
						{
							foundVBounds = true;
							// it can't move so make sure our vertical bounds enclose it
							if (boundsOfAllChildrenIncludingMargin.Top < childBoundsWithMargin.Top)
							{
								boundsOfAllChildrenIncludingMargin.Top = childBoundsWithMargin.Top;
							}

							if (boundsOfAllChildrenIncludingMargin.Bottom > childBoundsWithMargin.Bottom)
							{
								boundsOfAllChildrenIncludingMargin.Bottom = childBoundsWithMargin.Bottom;
							}
						}
					}
					else
					{
						RectangleDouble childBoundsWithMargin = child.BoundsRelativeToParent;
						childBoundsWithMargin.Inflate(child.Margin);
						boundsOfAllChildrenIncludingMargin.ExpandToInclude(childBoundsWithMargin);
					}
				}

				if (considerChildAnchor)
				{
					if (foundHBounds)
					{
						boundsOfAllChildrenIncludingMargin.Right = boundsOfAllChildrenIncludingMargin.Left + Math.Max(boundsOfAllChildrenIncludingMargin.Width, minSize.x);
					}
					else
					{
						boundsOfAllChildrenIncludingMargin.Left = 0;
						boundsOfAllChildrenIncludingMargin.Right = minSize.x;
					}

					if (foundVBounds)
					{
						boundsOfAllChildrenIncludingMargin.Top = boundsOfAllChildrenIncludingMargin.Bottom + Math.Max(boundsOfAllChildrenIncludingMargin.Height, minSize.y);
					}
					else
					{
						boundsOfAllChildrenIncludingMargin.Bottom = 0;
						boundsOfAllChildrenIncludingMargin.Top = minSize.y;
					}
				}
			}

			return boundsOfAllChildrenIncludingMargin;
		}
Exemple #54
0
		public void TestGetHashCode()
		{
			{
				RGBA_Bytes a = new RGBA_Bytes(10, 11, 12);
				RGBA_Bytes b = new RGBA_Bytes(10, 11, 12);
				Assert.IsTrue(a.GetHashCode() == b.GetHashCode());
			}
			{
				RGBA_Floats a = new RGBA_Floats(10, 11, 12);
				RGBA_Floats b = new RGBA_Floats(10, 11, 12);
				Assert.IsTrue(a.GetHashCode() == b.GetHashCode());
			}
			{
				BorderDouble a = new BorderDouble(10, 11, 12, 13);
				BorderDouble b = new BorderDouble(10, 11, 12, 13);
				Assert.IsTrue(a.GetHashCode() == b.GetHashCode());
			}
			{
				Point2D a = new Point2D(10, 11);
				Point2D b = new Point2D(10, 11);
				Assert.IsTrue(a.GetHashCode() == b.GetHashCode());
			}
			{
				RectangleDouble a = new RectangleDouble(10, 11, 12, 13);
				RectangleDouble b = new RectangleDouble(10, 11, 12, 13);
				Assert.IsTrue(a.GetHashCode() == b.GetHashCode());
			}
			{
				RectangleInt a = new RectangleInt(10, 11, 12, 13);
				RectangleInt b = new RectangleInt(10, 11, 12, 13);
				Assert.IsTrue(a.GetHashCode() == b.GetHashCode());
			}
		}
		public Rectangle GetRectangleFromRectD(RectangleDouble rectD)
		{
			Rectangle windowsRect = new Rectangle(
				(int)System.Math.Floor(rectD.Left),
				(int)System.Math.Floor(Height - rectD.Top),
				(int)System.Math.Ceiling(rectD.Width),
				(int)System.Math.Ceiling(rectD.Height));

			return windowsRect;
		}
		public gamma_ctrl(Vector2 position, Vector2 size)
			: base(position, false)
		{
			Vector2 location = position;// Vector2.Zero;
			LocalBounds = new RectangleDouble(0, 0, size.x, size.y);

			m_border_width = (2.0);
			m_border_extra = (0.0);
			m_curve_width = (2.0);
			m_grid_width = (0.2);
			m_text_thickness = (1.5);
			m_point_size = (5.0);
			m_text_height = (9.0);

			double x2 = location.x + size.x;
			double y2 = location.y + size.y;
			m_xc1 = location.x;
			m_yc1 = location.y;
			m_xc2 = (x2);
			m_yc2 = (y2 - m_text_height * 2.0);
			m_xt1 = location.x;
			m_yt1 = (y2 - m_text_height * 2.0);
			m_xt2 = (x2);
			m_yt2 = (y2);

			m_curve_poly = new Stroke(m_gamma_spline);
			m_text_poly = new Stroke(m_text);
			m_idx = (0);
			m_vertex = (0);
			m_p1_active = (true);
			m_mouse_point = (0);
			m_pdx = (0.0);
			m_pdy = (0.0);
			calc_spline_box();

			m_background_color = new RGBA_Bytes(1.0, 1.0, 0.9);
			m_border_color = new RGBA_Bytes(0.0, 0.0, 0.0);
			m_curve_color = new RGBA_Bytes(0.0, 0.0, 0.0);
			m_grid_color = new RGBA_Bytes(0.2, 0.2, 0.0);
			m_inactive_pnt_color = new RGBA_Bytes(0.0, 0.0, 0.0);
			m_active_pnt_color = new RGBA_Bytes(1.0, 0.0, 0.0);
			m_text_color = new RGBA_Bytes(0.0, 0.0, 0.0);

			m_colors[0] = m_curve_color;
			m_colors[1] = m_grid_color;
			m_colors[2] = m_inactive_pnt_color;
			m_colors[3] = m_active_pnt_color;
			m_colors[4] = m_text_color;
		}
Exemple #57
0
		private void UpdateScrollBar()
		{
			switch (Show)
			{
				case ShowState.WhenRequired:
					if (ParentScrollWidget.ScrollArea.Height > ParentScrollWidget.Height)
					{
						goto case ShowState.Always;
					}
					else
					{
						goto case ShowState.Never;
					}

				case ShowState.Always:
					// make sure we can see it
					Visible = true;
					// fix the bounds of the scroll bar background
					LocalBounds = new RectangleDouble(0, 0, ScrollBarWidth, ParentScrollWidget.Height);
					background.LocalBounds = LocalBounds;

					// this is for vertical scroll bar
					thumb.LocalBounds = new RectangleDouble(0, 0, ScrollBarWidth, ThumbHeight);

					Vector2 scrollRatioFromTop0To1 = ParentScrollWidget.ScrollRatioFromTop0To1;
					double notThumbHeight = ParentScrollWidget.Height - ThumbHeight;
					thumb.OriginRelativeParent = new Vector2(0, notThumbHeight * scrollRatioFromTop0To1.y);

					ParentScrollWidget.ScrollArea.Padding = new BorderDouble(0, 0, ScrollBar.ScrollBarWidth, 0);

					break;

				case ShowState.Never:
					Visible = false;

					ParentScrollWidget.ScrollArea.Padding = new BorderDouble(0, 0, 0, 0);

					break;
			}
		}
		public override void OnDraw(Graphics2D graphics2D)
		{
			RectangleDouble backgroundRect = new RectangleDouble(LocalBounds.Left - m_border_extra,
				LocalBounds.Bottom - m_border_extra,
				LocalBounds.Right + m_border_extra,
				LocalBounds.Top + m_border_extra);
			graphics2D.FillRectangle(backgroundRect, m_background_color);

			PathStorage border = new PathStorage();
			border.LineTo(LocalBounds.Left, LocalBounds.Bottom);
			border.LineTo(LocalBounds.Right, LocalBounds.Bottom);
			border.LineTo(LocalBounds.Right, LocalBounds.Top);
			border.LineTo(LocalBounds.Left, LocalBounds.Top);
			border.LineTo(LocalBounds.Left + m_border_width, LocalBounds.Bottom + m_border_width);
			border.LineTo(LocalBounds.Left + m_border_width, LocalBounds.Top - m_border_width);
			border.LineTo(LocalBounds.Right - m_border_width, LocalBounds.Top - m_border_width);
			border.LineTo(LocalBounds.Right - m_border_width, LocalBounds.Bottom + m_border_width);

			graphics2D.Render(border, m_border_color);

			rewind(0);
			graphics2D.Render(this, m_curve_color);
			rewind(1);
			graphics2D.Render(this, m_grid_color);
			rewind(2);
			graphics2D.Render(this, m_inactive_pnt_color);
			rewind(3);
			graphics2D.Render(this, m_active_pnt_color);
			rewind(4);
			graphics2D.Render(this, m_text_color);

			base.OnDraw(graphics2D);
		}
Exemple #59
0
			private RectangleDouble GetSwitchBounds()
			{
				RectangleDouble switchBounds;
				switchBounds = new RectangleDouble(0, 0, switchWidth, switchHeight);
				return switchBounds;
			}
Exemple #60
0
		public void TopBottomWithAnchorBottomTopChildTest(BorderDouble controlPadding, BorderDouble buttonMargin)
		{
			double buttonSize = 40;
			GuiWidget containerControl = new GuiWidget(buttonSize * 3, buttonSize * 8);
			containerControl.Padding = controlPadding;
			containerControl.DoubleBuffer = true;

			RectangleDouble[] eightControlRectangles = new RectangleDouble[8];
			RGBA_Bytes[] eightColors = new RGBA_Bytes[] { RGBA_Bytes.Red, RGBA_Bytes.Orange, RGBA_Bytes.Yellow, RGBA_Bytes.YellowGreen, RGBA_Bytes.Green, RGBA_Bytes.Blue, RGBA_Bytes.Indigo, RGBA_Bytes.Violet };
			{
				double currentBottom = containerControl.Height - controlPadding.Top - buttonMargin.Top - buttonSize;
				double buttonWidthWithMargin = buttonSize + buttonMargin.Width;
				double scalledHeight = (containerControl.Height - controlPadding.Height - buttonMargin.Height * 8 - buttonSize * 2) / 6;
				// the bottom unsized rect
				eightControlRectangles[0] = new RectangleDouble(
						0,
						currentBottom,
						buttonSize,
						currentBottom + buttonSize);

				// left anchor
				currentBottom -= scalledHeight + buttonMargin.Height;
				double leftAnchorX = controlPadding.Left + buttonMargin.Left;
				eightControlRectangles[1] = new RectangleDouble(leftAnchorX, currentBottom, leftAnchorX + buttonSize, currentBottom + scalledHeight);

				// center anchor
				double centerXOfContainer = controlPadding.Left + (containerControl.Width - controlPadding.Width) / 2;
				currentBottom -= scalledHeight + buttonMargin.Height;
				eightControlRectangles[2] = new RectangleDouble(centerXOfContainer - buttonWidthWithMargin / 2 + buttonMargin.Left, currentBottom, centerXOfContainer + buttonWidthWithMargin / 2 - buttonMargin.Right, currentBottom + scalledHeight);

				// right anchor
				double rightAnchorX = containerControl.Width - controlPadding.Right - buttonMargin.Right;
				currentBottom -= scalledHeight + buttonMargin.Height;
				eightControlRectangles[3] = new RectangleDouble(rightAnchorX - buttonSize, currentBottom, rightAnchorX, currentBottom + scalledHeight);

				// left center anchor
				currentBottom -= scalledHeight + buttonMargin.Height;
				eightControlRectangles[4] = new RectangleDouble(leftAnchorX, currentBottom, centerXOfContainer - buttonMargin.Right, currentBottom + scalledHeight);

				// center right anchor
				currentBottom -= scalledHeight + buttonMargin.Height;
				eightControlRectangles[5] = new RectangleDouble(centerXOfContainer + buttonMargin.Left, currentBottom, rightAnchorX, currentBottom + scalledHeight);

				// left right anchor
				currentBottom -= scalledHeight + buttonMargin.Height;
				eightControlRectangles[6] = new RectangleDouble(leftAnchorX, currentBottom, rightAnchorX, currentBottom + scalledHeight);

				// top anchor
				currentBottom -= buttonSize + buttonMargin.Height;
				eightControlRectangles[7] = new RectangleDouble(0, currentBottom, buttonSize, currentBottom + buttonSize);

				Graphics2D graphics = containerControl.NewGraphics2D();
				for (int i = 0; i < 8; i++)
				{
					graphics.FillRectangle(eightControlRectangles[i], eightColors[i]);
				}
			}

			GuiWidget containerTest = new GuiWidget(containerControl.Width, containerControl.Height);
			FlowLayoutWidget bottomToTopFlowLayoutAll = new FlowLayoutWidget(FlowDirection.TopToBottom);
			containerTest.DoubleBuffer = true;
			{
				bottomToTopFlowLayoutAll.AnchorAll();
				bottomToTopFlowLayoutAll.Padding = controlPadding;
				{
					GuiWidget top = new GuiWidget(buttonSize, buttonSize);
					top.BackgroundColor = RGBA_Bytes.Red;
					top.Margin = buttonMargin;
					bottomToTopFlowLayoutAll.AddChild(top);

					bottomToTopFlowLayoutAll.AddChild(CreateBottomToTopMiddleWidget(buttonMargin, buttonSize, HAnchor.ParentLeft, RGBA_Bytes.Orange));
					bottomToTopFlowLayoutAll.AddChild(CreateBottomToTopMiddleWidget(buttonMargin, buttonSize, HAnchor.ParentCenter, RGBA_Bytes.Yellow));
					bottomToTopFlowLayoutAll.AddChild(CreateBottomToTopMiddleWidget(buttonMargin, buttonSize, HAnchor.ParentRight, RGBA_Bytes.YellowGreen));
					bottomToTopFlowLayoutAll.AddChild(CreateBottomToTopMiddleWidget(buttonMargin, buttonSize, HAnchor.ParentLeftCenter, RGBA_Bytes.Green));
					bottomToTopFlowLayoutAll.AddChild(CreateBottomToTopMiddleWidget(buttonMargin, buttonSize, HAnchor.ParentCenterRight, RGBA_Bytes.Blue));
					bottomToTopFlowLayoutAll.AddChild(CreateBottomToTopMiddleWidget(buttonMargin, buttonSize, HAnchor.ParentLeftRight, RGBA_Bytes.Indigo));

					GuiWidget bottom = new GuiWidget(buttonSize, buttonSize);
					bottom.BackgroundColor = RGBA_Bytes.Violet;
					bottom.Margin = buttonMargin;
					bottomToTopFlowLayoutAll.AddChild(bottom);
				}

				containerTest.AddChild(bottomToTopFlowLayoutAll);
			}

			containerTest.OnDraw(containerTest.NewGraphics2D());
			OutputImages(containerControl, containerTest);

			for (int i = 0; i < 8; i++)
			{
				Assert.IsTrue(eightControlRectangles[i].Equals(bottomToTopFlowLayoutAll.Children[i].BoundsRelativeToParent, .001));
			}

			Assert.IsTrue(containerControl.BackBuffer != null, "When we set a guiWidget to DoubleBuffer it needs to create one.");

			// we use a least squares match because the erase background that is setting the widgets is integer pixel based and the fill rectangle is not.
			Assert.IsTrue(containerControl.BackBuffer.FindLeastSquaresMatch(containerTest.BackBuffer, 0), "The test and control need to match.");
		}