Beispiel #1
1
		public ListBoxTextItem(string displayName, string itemValue)
			: base(displayName)
		{
			Padding = new BorderDouble(3);
			ItemValue = itemValue;
			MinimumSize = new Vector2(Width, Height);
		}
Beispiel #2
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 PerformancePannel(string name)
			: base(FlowDirection.TopToBottom)
		{
			this.Name = name;
			Margin = new BorderDouble(5);
			Padding = new BorderDouble(3);
			VAnchor |= VAnchor.ParentTop;

			if (pannels == null)
			{
				pannels = new PerformanceDisplayWidget();
				pannels.Selectable = false;
				pannels.HAnchor |= HAnchor.ParentLeft;
				pannels.VAnchor |= VAnchor.ParentTop;
				pannels.Visible = false; // start out not visible
										 //pannels.Visible = false; // start out not visible

				if (true) // only add this when doing testing
				{
					UiThread.RunOnIdle(() =>
					{
						if (PerformanceTimer.GetParentWindowFunction != null)
						{
							GuiWidget parentWindow = PerformanceTimer.GetParentWindowFunction();
							parentWindow.AddChild(pannels);
#if DEBUG
							parentWindow.KeyDown += ParentWindow_KeyDown;
							parentWindow.MouseDownInBounds += ParentWindow_MouseDown;
#endif
						}
					});
				}
			}

			// add in the column title
			{
				TextWidget titleWidget = new TextWidget(name, pointSize: 14)
				{
					BackgroundColor = new RGBA_Bytes(),
					TextColor = new RGBA_Bytes(20, 120, 20),
				};
				titleWidget.Printer.DrawFromHintedCache = true;
				AddChild(titleWidget);
			}

			AddChild(topToBottom);

			pannels.AddChild(this);

			BackgroundColor = new RGBA_Bytes(RGBA_Bytes.White, 180);
		}
        public GuiWidget GetBaudRateWidget()
        {
            FlowLayoutWidget baudRateContainer = new FlowLayoutWidget(FlowDirection.TopToBottom);

            baudRateContainer.Margin = new BorderDouble(0);

            List <string> baudRates = new List <string> {
                "115200", "250000"
            };
            BorderDouble baudRateMargin = new BorderDouble(3, 3, 5, 3);

            foreach (string baudRate in baudRates)
            {
                BaudRateRadioButton baudOption = new BaudRateRadioButton(baudRate);
                BaudRateButtonsList.Add(baudOption);
                baudOption.Margin    = baudRateMargin;
                baudOption.HAnchor   = HAnchor.ParentLeft;
                baudOption.TextColor = this.subContainerTextColor;
                if (this.ActivePrinter.BaudRate == baudRate)
                {
                    baudOption.Checked = true;
                }
                baudRateContainer.AddChild(baudOption);
            }

            otherBaudRateRadioButton           = new RadioButton(LocalizedString.Get("Other"));
            otherBaudRateRadioButton.Margin    = baudRateMargin;
            otherBaudRateRadioButton.TextColor = this.subContainerTextColor;

            baudRateContainer.AddChild(otherBaudRateRadioButton);

            //See if the baud rate of the current print is in the list of displayed rates,
            //flag the 'other' option if it is not and prefill the rate.
            otherBaudRateInput          = new MHTextEditWidget("");
            otherBaudRateInput.Visible  = false;
            otherBaudRateInput.HAnchor |= HAnchor.ParentLeftRight;

            if (this.ActivePrinter.BaudRate != null)
            {
                if (!baudRates.Contains(this.ActivePrinter.BaudRate.ToString()))
                {
                    otherBaudRateRadioButton.Checked = true;
                    otherBaudRateInput.Text          = this.ActivePrinter.BaudRate.ToString();
                    otherBaudRateInput.Visible       = true;
                }
            }

            baudRateContainer.AddChild(otherBaudRateInput);
            return(baudRateContainer);
        }
        private FlowLayoutWidget createPrinterBaudRateContainer()
        {
            FlowLayoutWidget container = new FlowLayoutWidget(FlowDirection.TopToBottom);

            container.Margin  = new BorderDouble(0);
            container.VAnchor = VAnchor.ParentBottomTop;
            BorderDouble elementMargin = new BorderDouble(top: 3);

            string baudRateLabelText     = "Baud Rate".Localize();
            string baudRateLabelTextFull = string.Format("{0}:", baudRateLabelText);

            TextWidget baudRateLabel = new TextWidget(baudRateLabelTextFull, 0, 0, 12);

            baudRateLabel.TextColor = ActiveTheme.Instance.PrimaryTextColor;
            baudRateLabel.Margin    = new BorderDouble(0, 0, 0, 10);
            baudRateLabel.HAnchor   = HAnchor.ParentLeftRight;

            baudRateWidget         = GetBaudRateWidget();
            baudRateWidget.HAnchor = HAnchor.ParentLeftRight;

            FlowLayoutWidget baudRateMessageContainer = new FlowLayoutWidget();

            baudRateMessageContainer.Margin  = elementMargin;
            baudRateMessageContainer.HAnchor = HAnchor.ParentLeftRight;

            printerBaudRateError           = new TextWidget("Select the baud rate.".Localize(), 0, 0, 10);
            printerBaudRateError.TextColor = ActiveTheme.Instance.PrimaryTextColor;
            printerBaudRateError.AutoExpandBoundsToText = true;

            printerBaudRateHelpLink         = linkButtonFactory.Generate("What's this?".Localize());
            printerBaudRateHelpLink.Margin  = new BorderDouble(left: 5);
            printerBaudRateHelpLink.VAnchor = VAnchor.ParentBottom;
            printerBaudRateHelpLink.Click  += printerBaudRateHelp_Click;

            printerBaudRateHelpMessage           = new TextWidget("The term 'Baud Rate' roughly means the speed at which\ndata is transmitted.  Baud rates may differ from printer to\nprinter. Refer to your printer manual for more info.\n\nTip: If you are uncertain - try 250000.".Localize(), 0, 0, 10);
            printerBaudRateHelpMessage.TextColor = ActiveTheme.Instance.PrimaryTextColor;
            printerBaudRateHelpMessage.Margin    = new BorderDouble(top: 10);
            printerBaudRateHelpMessage.Visible   = false;

            baudRateMessageContainer.AddChild(printerBaudRateError);
            baudRateMessageContainer.AddChild(printerBaudRateHelpLink);

            container.AddChild(baudRateLabel);
            container.AddChild(baudRateWidget);
            container.AddChild(baudRateMessageContainer);
            container.AddChild(printerBaudRateHelpMessage);

            container.HAnchor = HAnchor.ParentLeftRight;
            return(container);
        }
 public static void SetWindowTheme(Color textColor,
                                   int fontSize,
                                   Func <GuiWidget> getCloseButton,
                                   BorderDouble titleBarPadding,
                                   Color backgroundColor,
                                   Color borderColor)
 {
     SingleWindowProvider.textColor       = textColor;
     SingleWindowProvider.fontSize        = fontSize;
     SingleWindowProvider.getCloseButton  = getCloseButton;
     SingleWindowProvider.titleBarPadding = titleBarPadding;
     SingleWindowProvider.backgroundColor = backgroundColor;
     SingleWindowProvider.borderColor     = borderColor;
 }
        public PerformancePanel(string name)
            : base(FlowDirection.TopToBottom)
        {
            this.Name = name;
            Margin    = new BorderDouble(5);
            Padding   = new BorderDouble(3);
            VAnchor  |= VAnchor.ParentTop;

            if (panels == null)
            {
                panels            = new PerformanceDisplayWidget();
                panels.Selectable = false;
                panels.HAnchor   |= HAnchor.ParentLeft;
                panels.VAnchor   |= VAnchor.ParentTop;
                panels.Visible    = false; // start out not visible

                if (true)                  // only add this when doing testing
                {
                    UiThread.RunOnIdle(() =>
                    {
                        if (PerformanceTimer.GetParentWindowFunction != null)
                        {
                            GuiWidget parentWindow = PerformanceTimer.GetParentWindowFunction();
                            parentWindow.AddChild(panels);
#if DEBUG
                            parentWindow.KeyDown           += ParentWindow_KeyDown;
                            parentWindow.MouseDownInBounds += ParentWindow_MouseDown;
#endif
                        }
                    });
                }
            }

            // add in the column title
            {
                TextWidget titleWidget = new TextWidget(name, pointSize: 14)
                {
                    BackgroundColor = new RGBA_Bytes(),
                    TextColor       = new RGBA_Bytes(20, 120, 20),
                };
                titleWidget.Printer.DrawFromHintedCache = true;
                AddChild(titleWidget);
            }

            AddChild(topToBottom);

            panels.AddChild(this);

            BackgroundColor = new RGBA_Bytes(RGBA_Bytes.White, 180);
        }
Beispiel #8
0
        private void SetMenuItems(DropDownMenu dropDownMenu)
        {
            menuItems = new List <PrintItemAction>();

            menuItems.Add(new PrintItemAction()
            {
                Title  = "Send".Localize(),
                Action = (items, queueDataView) => sendButton_Click(null, null)
            });

            menuItems.Add(new PrintItemAction()
            {
                Title  = "Add To Library".Localize(),
                Action = (items, queueDataView) => addToLibraryButton_Click(null, null)
            });

            // Extension point for plugins to hook into selected item actions
            var pluginFinder = new PluginFinder <PrintItemMenuExtension>();

            foreach (var menuExtensionPlugin in pluginFinder.Plugins)
            {
                foreach (var menuItem in menuExtensionPlugin.GetMenuItems())
                {
                    menuItems.Add(menuItem);
                }
            }

            BorderDouble padding = dropDownMenu.MenuItemsPadding;

            //Add the menu items to the menu itself
            foreach (PrintItemAction item in menuItems)
            {
                if (item.Action == null)
                {
                    dropDownMenu.MenuItemsPadding = new BorderDouble(5, 0, padding.Right, 3);
                }
                else
                {
                    if (item.SingleItemOnly)
                    {
                        singleSelectionMenuItems.Add(item.Title);
                    }
                    dropDownMenu.MenuItemsPadding = new BorderDouble(10, 5, padding.Right, 5);
                }

                dropDownMenu.AddItem(item.Title);
            }

            dropDownMenu.Padding = padding;
        }
        public ViewControls2D()
        {
            if (UserSettings.Instance.IsTouchScreen)
            {
                buttonHeight = 40;
            }
            else
            {
                buttonHeight = 0;
            }

            TextImageButtonFactory iconTextImageButtonFactory = new TextImageButtonFactory();

            iconTextImageButtonFactory.AllowThemeToAdjustImage = false;
            iconTextImageButtonFactory.checkedBorderColor      = RGBA_Bytes.White;

            BackgroundColor = new RGBA_Bytes(0, 0, 0, 120);
            iconTextImageButtonFactory.FixedHeight = buttonHeight * GuiWidget.DeviceScale;
            iconTextImageButtonFactory.FixedWidth  = buttonHeight * GuiWidget.DeviceScale;

            string resetViewIconPath = Path.Combine("ViewTransformControls", "reset.png");

            resetViewButton             = iconTextImageButtonFactory.Generate("", StaticData.Instance.LoadIcon(resetViewIconPath, 32, 32).InvertLightness());
            resetViewButton.ToolTipText = "Reset View".Localize();
            AddChild(resetViewButton);
            resetViewButton.Click += (sender, e) =>
            {
                ResetView?.Invoke(this, null);
            };

            string translateIconPath = Path.Combine("ViewTransformControls", "translate.png");

            translateButton             = iconTextImageButtonFactory.GenerateRadioButton("", StaticData.Instance.LoadIcon(translateIconPath, 32, 32));
            translateButton.ToolTipText = "Move".Localize();
            translateButton.Margin      = new BorderDouble(3);
            AddChild(translateButton);

            string scaleIconPath = Path.Combine("ViewTransformControls", "scale.png");

            scaleButton             = iconTextImageButtonFactory.GenerateRadioButton("", StaticData.Instance.LoadIcon(scaleIconPath, 32, 32));
            scaleButton.ToolTipText = "Zoom".Localize();
            scaleButton.Margin      = new BorderDouble(3);
            AddChild(scaleButton);

            Margin   = new BorderDouble(5);
            HAnchor |= Agg.UI.HAnchor.ParentLeft;
            VAnchor  = Agg.UI.VAnchor.ParentTop;
            translateButton.Checked = true;
        }
Beispiel #10
0
        private FlowLayoutWidget CreateRightButtonPannel()
        {
            FlowLayoutWidget buttonRightPanel = new FlowLayoutWidget(FlowDirection.TopToBottom);

            buttonRightPanel.Width = 200;
            {
                BorderDouble buttonMargin = new BorderDouble(top: 3);

                expandModelOptions        = expandMenuOptionFactory.GenerateCheckBoxButton(new LocalizedString("Model").Translated, "icon_arrow_right_no_border_32x32.png", "icon_arrow_down_no_border_32x32.png");
                expandModelOptions.Margin = new BorderDouble(bottom: 2);
                buttonRightPanel.AddChild(expandModelOptions);
                expandModelOptions.Checked = true;

                modelOptionsContainer         = new FlowLayoutWidget(FlowDirection.TopToBottom);
                modelOptionsContainer.HAnchor = HAnchor.ParentLeftRight;
                //modelOptionsContainer.Visible = false;
                buttonRightPanel.AddChild(modelOptionsContainer);

                expandLayerOptions        = expandMenuOptionFactory.GenerateCheckBoxButton(new LocalizedString("Layer").Translated, "icon_arrow_right_no_border_32x32.png", "icon_arrow_down_no_border_32x32.png");
                expandLayerOptions.Margin = new BorderDouble(bottom: 2);
                //buttonRightPanel.AddChild(expandLayerOptions);

                layerOptionsContainer         = new FlowLayoutWidget(FlowDirection.TopToBottom);
                layerOptionsContainer.HAnchor = HAnchor.ParentLeftRight;
                layerOptionsContainer.Visible = false;
                buttonRightPanel.AddChild(layerOptionsContainer);

                expandDisplayOptions        = expandMenuOptionFactory.GenerateCheckBoxButton(new LocalizedString("Display").Translated, "icon_arrow_right_no_border_32x32.png", "icon_arrow_down_no_border_32x32.png");
                expandDisplayOptions.Margin = new BorderDouble(bottom: 2);
                buttonRightPanel.AddChild(expandDisplayOptions);
                expandDisplayOptions.Checked = true;

                displayOptionsContainer         = new FlowLayoutWidget(FlowDirection.TopToBottom);
                displayOptionsContainer.HAnchor = HAnchor.ParentLeftRight;
                //displayOptionsContainer.Visible = false;
                buttonRightPanel.AddChild(displayOptionsContainer);

                GuiWidget verticalSpacer = new GuiWidget();
                verticalSpacer.VAnchor = VAnchor.ParentBottomTop;
                buttonRightPanel.AddChild(verticalSpacer);
            }

            buttonRightPanel.Padding         = new BorderDouble(6, 6);
            buttonRightPanel.Margin          = new BorderDouble(0, 1);
            buttonRightPanel.BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor;
            buttonRightPanel.VAnchor         = VAnchor.ParentBottomTop;

            return(buttonRightPanel);
        }
        public ViewControls2D()
        {
            if (ActiveTheme.Instance.DisplayMode == ActiveTheme.ApplicationDisplayType.Touchscreen)
            {
                buttonHeight = 40;
            }
            else
            {
                buttonHeight = 0;
            }

            TextImageButtonFactory iconTextImageButtonFactory = new TextImageButtonFactory();

            iconTextImageButtonFactory.AllowThemeToAdjustImage = false;
            iconTextImageButtonFactory.checkedBorderColor      = RGBA_Bytes.White;

            BackgroundColor = new RGBA_Bytes(0, 0, 0, 120);
            iconTextImageButtonFactory.FixedHeight = buttonHeight;
            iconTextImageButtonFactory.FixedWidth  = buttonHeight;

            string resetViewIconPath = Path.Combine("ViewTransformControls", "reset.png");

            resetViewButton             = iconTextImageButtonFactory.Generate("", resetViewIconPath);
            resetViewButton.ToolTipText = "Reset View".Localize();
            AddChild(resetViewButton);
            resetViewButton.Click += (sender, e) =>
            {
                ResetView?.Invoke(this, null);
            };

            string translateIconPath = Path.Combine("ViewTransformControls", "translate.png");

            translateButton             = iconTextImageButtonFactory.GenerateRadioButton("", translateIconPath);
            translateButton.ToolTipText = "Move".Localize();
            translateButton.Margin      = new BorderDouble(3);
            AddChild(translateButton);

            string scaleIconPath = Path.Combine("ViewTransformControls", "scale.png");

            scaleButton             = iconTextImageButtonFactory.GenerateRadioButton("", scaleIconPath);
            scaleButton.ToolTipText = "Zoom".Localize();
            scaleButton.Margin      = new BorderDouble(3);
            AddChild(scaleButton);

            Margin   = new BorderDouble(5);
            HAnchor |= Agg.UI.HAnchor.ParentLeft;
            VAnchor  = Agg.UI.VAnchor.ParentTop;
            translateButton.Checked = true;
        }
        public WidescreenPanel()
            : base(FlowDirection.LeftToRight)
        {
            Name = "WidescreenPanel";
            AnchorAll();
            BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor;
            Padding         = new BorderDouble(4);

            // TODO: This hooks seems to invalidate most of the other ActivePrinterChanged subscribers as this destroys and recreates everything
            ActiveSliceSettings.ActivePrinterChanged.RegisterEvent((s, e) => ApplicationController.Instance.ReloadAll(null, null), ref unregisterEvents);

            PrinterConnectionAndCommunication.Instance.ActivePrintItemChanged.RegisterEvent(onActivePrintItemChanged, ref unregisterEvents);
            ApplicationController.Instance.ReloadAdvancedControlsPanelTrigger.RegisterEvent((s, e) => UiThread.RunOnIdle(ReloadAdvancedControlsPanel), ref unregisterEvents);
            this.BoundsChanged += onBoundsChanges;
        }
        public SetupStepConfigureConnection(ConnectionWizard connectionWizard) : base(connectionWizard)
        {
            BorderDouble elementMargin = new BorderDouble(top: 5);

            var continueMessage = new TextWidget("Would you like to connect to this printer now?", 0, 0, 12);

            continueMessage.AutoExpandBoundsToText = true;
            continueMessage.TextColor = ActiveTheme.Instance.PrimaryTextColor;
            continueMessage.HAnchor   = HAnchor.ParentLeftRight;
            continueMessage.Margin    = elementMargin;

            var continueMessageTwo = new TextWidget("You can always configure this later.", 0, 0, 10);

            continueMessageTwo.AutoExpandBoundsToText = true;
            continueMessageTwo.TextColor = ActiveTheme.Instance.PrimaryTextColor;
            continueMessageTwo.HAnchor   = HAnchor.ParentLeftRight;
            continueMessageTwo.Margin    = elementMargin;

            var printerErrorMessage = new TextWidget("", 0, 0, 10);

            printerErrorMessage.AutoExpandBoundsToText = true;
            printerErrorMessage.TextColor = RGBA_Bytes.Red;
            printerErrorMessage.HAnchor   = HAnchor.ParentLeftRight;
            printerErrorMessage.Margin    = elementMargin;

            var container = new FlowLayoutWidget(FlowDirection.TopToBottom);

            container.Margin = new BorderDouble(5);
            container.AddChild(continueMessage);
            container.AddChild(continueMessageTwo);
            container.AddChild(printerErrorMessage);
            container.HAnchor = HAnchor.ParentLeftRight;

            //Construct buttons
            var nextButton = textImageButtonFactory.Generate("Connect");

            nextButton.Click += (s, e) => base.connectionWizard.ChangeToSetupBaudOrComPortOne();

            var skipButton = textImageButtonFactory.Generate("Skip");

            skipButton.Click += (s, e) => SaveAndExit();

            //Add buttons to buttonContainer
            footerRow.AddChild(nextButton);
            footerRow.AddChild(skipButton);
            footerRow.AddChild(new HorizontalSpacer());
            footerRow.AddChild(cancelButton);
        }
		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));
		}
Beispiel #15
0
 public Tab(string tabName, GuiWidget normalWidget, GuiWidget hoverWidget, GuiWidget pressedWidget,
            TabPage tabPageControledByTab)
 {
     base.Name           = tabName;
     this.normalWidget   = normalWidget;
     this.hoverWidget    = hoverWidget;
     this.selectedWidget = pressedWidget;
     AddChild(normalWidget);
     AddChild(hoverWidget);
     hoverWidget.Visible = false;
     AddChild(pressedWidget);
     pressedWidget.Visible = false;
     Padding = new BorderDouble(5, 3, 20, 3);
     this.tabPageControledByTab = tabPageControledByTab;
     SetBoundsToEncloseChildren();
 }
Beispiel #16
0
        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));
        }
Beispiel #17
0
        public RadioButton GenerateRadioButton(string label, ImageBuffer iconImage)
        {
            BorderDouble internalMargin = 0;

            var nomalState    = new TextImageWidget(label, normalFillColor, normalBorderColor, normalTextColor, borderWidth, internalMargin, iconImage, fontSize: this.fontSize, height: this.FixedHeight, width: this.FixedWidth);
            var hoverState    = new TextImageWidget(label, hoverFillColor, hoverBorderColor, hoverTextColor, borderWidth, internalMargin, iconImage, fontSize: this.fontSize, height: this.FixedHeight, width: this.FixedWidth);
            var checkingState = new TextImageWidget(label, hoverFillColor, checkedBorderColor, hoverTextColor, borderWidth, internalMargin, iconImage, fontSize: this.fontSize, height: this.FixedHeight, width: this.FixedWidth);
            var checkedState  = new TextImageWidget(label, pressedFillColor, checkedBorderColor, pressedTextColor, borderWidth, internalMargin, iconImage, fontSize: this.fontSize, height: this.FixedHeight, width: this.FixedWidth);
            var disabledState = new TextImageWidget(label, disabledFillColor, disabledBorderColor, disabledTextColor, borderWidth, internalMargin, iconImage, fontSize: this.fontSize, height: this.FixedHeight, width: this.FixedWidth);

            var buttonView = new RadioButtonViewStates(nomalState, hoverState, checkingState, checkedState, disabledState);

            return(new RadioButton(buttonView)
            {
                Margin = Margin
            });
        }
        public PrintProgressBar()
        {
            MinimumSize     = new Vector2(0, 24);
            HAnchor         = HAnchor.ParentLeftRight;
            BackgroundColor = ActiveTheme.Instance.SecondaryAccentColor;
            Margin          = new BorderDouble(0);

            FlowLayoutWidget container = new FlowLayoutWidget(FlowDirection.LeftToRight);

            container.AnchorAll();
            container.Padding = new BorderDouble(6, 0);

            printTimeElapsed = new TextWidget("", pointSize: 11);
            printTimeElapsed.Printer.DrawFromHintedCache = true;
            printTimeElapsed.AutoExpandBoundsToText      = true;
            printTimeElapsed.VAnchor = Agg.UI.VAnchor.ParentCenter;


            printTimeRemaining = new TextWidget("", pointSize: 11);
            printTimeRemaining.Printer.DrawFromHintedCache = true;
            printTimeRemaining.AutoExpandBoundsToText      = true;
            printTimeRemaining.VAnchor = Agg.UI.VAnchor.ParentCenter;

            GuiWidget spacer = new GuiWidget();

            spacer.HAnchor = Agg.UI.HAnchor.ParentLeftRight;

            container.AddChild(printTimeElapsed);
            container.AddChild(spacer);
            container.AddChild(printTimeRemaining);

            AddChild(container);

            ClickWidget clickOverlay = new ClickWidget();

            clickOverlay.AnchorAll();
            clickOverlay.Click += onProgressBarClick;

            AddChild(clickOverlay);

            AddHandlers();
            SetThemedColors();
            UpdatePrintStatus();
            UiThread.RunOnIdle(OnIdle);
        }
Beispiel #19
0
        public MHTextEditWidget(string text = "", double x = 0, double y = 0, double pointSize = 12, double pixelWidth = 0, double pixelHeight = 0, bool multiLine = false, int tabIndex = 0, string messageWhenEmptyAndNotSelected = "", TypeFace typeFace = null)
        {
            Padding = new BorderDouble(3);
            actuallTextEditWidget             = new TextEditWidget(text, x, y, pointSize, pixelWidth, pixelHeight, multiLine, tabIndex: tabIndex, typeFace: typeFace);
            actuallTextEditWidget.HAnchor     = Agg.UI.HAnchor.ParentLeftRight;
            actuallTextEditWidget.MinimumSize = new Vector2(Math.Max(actuallTextEditWidget.MinimumSize.x, pixelWidth), Math.Max(actuallTextEditWidget.MinimumSize.y, pixelHeight));
            actuallTextEditWidget.VAnchor     = Agg.UI.VAnchor.ParentBottom;
            AddChild(actuallTextEditWidget);
            BackgroundColor = RGBA_Bytes.White;
            HAnchor         = HAnchor.FitToChildren;
            VAnchor         = VAnchor.FitToChildren;

            noContentFieldDescription         = new TextWidget(messageWhenEmptyAndNotSelected, textColor: RGBA_Bytes.Gray);
            noContentFieldDescription.VAnchor = VAnchor.ParentBottom;
            noContentFieldDescription.AutoExpandBoundsToText = true;
            AddChild(noContentFieldDescription);
            SetNoContentFieldDescriptionVisibility();
        }
        void SetMenuItems()
        {
            menuItems = new TupleList <string, Func <bool> >
            {
                { LocalizedString.Get("Add File"), importFile_Click },
                { LocalizedString.Get("Exit"), exit_Click },
            };

            BorderDouble padding = MenuDropList.MenuItemsPadding;

            //Add the menu items to the menu itself
            foreach (Tuple <string, Func <bool> > item in menuItems)
            {
                MenuDropList.MenuItemsPadding = new BorderDouble(8, 4, 8, 4);
                MenuDropList.AddItem(item.Item1, pointSize: 10);
            }
            MenuDropList.Padding = padding;
        }
Beispiel #21
0
 public MHNumberEdit(double startingValue,
                     double x            = 0, double y = 0, double pointSize = 12,
                     double pixelWidth   = 0, double pixelHeight     = 0,
                     bool allowNegatives = false, bool allowDecimals = false,
                     double minValue     = int.MinValue,
                     double maxValue     = int.MaxValue,
                     double increment    = 1,
                     int tabIndex        = 0)
 {
     Padding           = new BorderDouble(3);
     actuallNumberEdit = new NumberEdit(startingValue, x, y, pointSize, pixelWidth, pixelHeight,
                                        allowNegatives, allowDecimals, minValue, maxValue, increment, tabIndex);
     actuallNumberEdit.VAnchor = Agg.UI.VAnchor.ParentBottom;
     AddChild(actuallNumberEdit);
     BackgroundColor = RGBA_Bytes.White;
     HAnchor         = HAnchor.FitToChildren;
     VAnchor         = VAnchor.FitToChildren;
 }
Beispiel #22
0
        public ViewControlsToggle()
        {
            TextImageButtonFactory iconTextImageButtonFactory = new TextImageButtonFactory();

            iconTextImageButtonFactory.AllowThemeToAdjustImage = false;
            iconTextImageButtonFactory.checkedBorderColor      = RGBA_Bytes.White;

            BackgroundColor = new RGBA_Bytes(0, 0, 0, 120);

            iconTextImageButtonFactory.FixedHeight = buttonHeight;
            iconTextImageButtonFactory.FixedWidth  = buttonHeight;

            string translateIconPath = Path.Combine("ViewTransformControls", "2d.png");

            twoDimensionButton        = iconTextImageButtonFactory.GenerateRadioButton("", translateIconPath);
            twoDimensionButton.Margin = new BorderDouble(3);
            AddChild(twoDimensionButton);

            string scaleIconPath = Path.Combine("ViewTransformControls", "3d.png");

            threeDimensionButton        = iconTextImageButtonFactory.GenerateRadioButton("", scaleIconPath);
            threeDimensionButton.Margin = new BorderDouble(3);

            if (ActiveTheme.Instance.DisplayMode != ActiveTheme.ApplicationDisplayType.Touchscreen)
            {
                AddChild(threeDimensionButton);

                if (UserSettings.Instance.get("LayerViewDefault") == "3D Layer")
                {
                    threeDimensionButton.Checked = true;
                }
                else
                {
                    twoDimensionButton.Checked = true;
                }
            }
            else
            {
                twoDimensionButton.Checked = true;
            }
            Margin   = new BorderDouble(5, 5, 200, 5);
            HAnchor |= Agg.UI.HAnchor.ParentRight;
            VAnchor  = Agg.UI.VAnchor.ParentTop;
        }
Beispiel #23
0
        public UpdateControlView()
        {
            textImageButtonFactory.normalFillColor = RGBA_Bytes.Gray;
            textImageButtonFactory.normalTextColor = ActiveTheme.Instance.PrimaryTextColor;

            HAnchor         = HAnchor.ParentLeftRight;
            BackgroundColor = ActiveTheme.Instance.TransparentDarkOverlay;
            Padding         = new BorderDouble(6, 5);
            {
                updateStatusText = new TextWidget(string.Format(""), textColor: ActiveTheme.Instance.PrimaryTextColor);
                updateStatusText.AutoExpandBoundsToText = true;
                updateStatusText.VAnchor = VAnchor.ParentCenter;

                GuiWidget horizontalSpacer = new GuiWidget();
                horizontalSpacer.HAnchor = HAnchor.ParentLeftRight;

                checkUpdateLink         = textImageButtonFactory.Generate("Check for Update".Localize());
                checkUpdateLink.VAnchor = VAnchor.ParentCenter;
                checkUpdateLink.Click  += CheckForUpdate;
                checkUpdateLink.Visible = false;

                downloadUpdateLink         = textImageButtonFactory.Generate("Download Update".Localize());
                downloadUpdateLink.VAnchor = VAnchor.ParentCenter;
                downloadUpdateLink.Click  += DownloadUpdate;
                downloadUpdateLink.Visible = false;

                installUpdateLink         = textImageButtonFactory.Generate("Install Update".Localize());
                installUpdateLink.VAnchor = VAnchor.ParentCenter;
                installUpdateLink.Click  += InstallUpdate;
                installUpdateLink.Visible = false;

                AddChild(updateStatusText);
                AddChild(horizontalSpacer);
                AddChild(checkUpdateLink);
                AddChild(downloadUpdateLink);
                AddChild(installUpdateLink);
            }

            UpdateControlData.Instance.UpdateStatusChanged.RegisterEvent(UpdateStatusChanged, ref unregisterEvents);

            MinimumSize = new VectorMath.Vector2(0, 50);

            UpdateStatusChanged(null, null);
        }
        void SetMenuItems()
        {
            menuItems = new TupleList <string, Func <bool> >
            {
                { LocalizedString.Get("Getting Started"), gettingStarted_Click },
                { LocalizedString.Get("View Help"), help_Click },
                { LocalizedString.Get("About"), about_Click },
            };

            BorderDouble padding = MenuDropList.MenuItemsPadding;

            //Add the menu items to the menu itself
            foreach (Tuple <string, Func <bool> > item in menuItems)
            {
                MenuDropList.MenuItemsPadding = new BorderDouble(8, 4, 8, 4);
                MenuDropList.AddItem(item.Item1, pointSize: 10);
            }
            MenuDropList.Padding = padding;
        }
        private GuiWidget MakeColorButton(Color color, double buttonSize, BorderDouble buttonSpacing, Action <Color> colorChanged)
        {
            var button = new ColorButton(color)
            {
                Width  = buttonSize,
                Height = buttonSize,
                Margin = buttonSpacing
            };

            button.Click += (s, e) =>
            {
                UiThread.RunOnIdle(() =>
                {
                    colorChanged(button.BackgroundColor);
                });
            };

            return(button);
        }
        public MenuItem AddItem(string itemName, string itemValue = null, double pointSize = 12)
        {
            if (itemValue == null)
            {
                itemValue = itemName;
            }
            if (mainControlText.Text != "")
            {
                mainControlText.Margin = MenuItemsPadding;
            }

            BorderDouble currentPadding = MenuItemsPadding;

            if (UseLeftIcons)
            {
                currentPadding = new BorderDouble(MenuItemsPadding.Left + 20 + 3, MenuItemsPadding.Bottom, MenuItemsPadding.Right, MenuItemsPadding.Top);
            }

            MenuItem menuItem = new MenuItem(new MenuItemColorStatesView(itemName)
            {
                NormalBackgroundColor = MenuItemsBackgroundColor,
                OverBackgroundColor   = MenuItemsBackgroundHoverColor,

                NormalTextColor   = MenuItemsTextColor,
                OverTextColor     = MenuItemsTextHoverColor,
                DisabledTextColor = RGBA_Bytes.Gray,

                PointSize = pointSize,
                Padding   = currentPadding,
            }, itemValue);

            menuItem.Text = itemName;

            // MenuItem is a long lived object that is added and removed to new containers whenever the
            // menu is shown. To ensure that event registration is not duplicated, always remove before add
            menuItem.Selected -= MenuItem_Clicked;
            menuItem.Selected += MenuItem_Clicked;

            menuItem.Name = itemName + " Menu Item";
            MenuItems.Add(menuItem);

            return(menuItem);
        }
Beispiel #27
0
        void SetMenuItems()
        {
            menuItems = new TupleList <string, Func <bool> >
            {
                { LocalizedString.Get("Layout 1"), layout1_Click },
                { LocalizedString.Get("Layout 2"), layout2_Click },
                //{LocalizedString.Get("Layout 3"), layout3_Click},
            };

            BorderDouble padding = MenuDropList.MenuItemsPadding;

            //Add the menu items to the menu itself
            foreach (Tuple <string, Func <bool> > item in menuItems)
            {
                MenuDropList.MenuItemsPadding = new BorderDouble(8, 4, 8, 4) * TextWidget.GlobalPointSizeScaleRatio;
                MenuDropList.AddItem(item.Item1, pointSize: 10);
            }
            MenuDropList.Padding = padding;
        }
        FlowLayoutWidget CreateMacroActionEdit()
        {
            FlowLayoutWidget container = new FlowLayoutWidget(FlowDirection.TopToBottom);

            container.Margin = new BorderDouble(0, 5);
            BorderDouble elementMargin = new BorderDouble(top: 3);

            showInActionMenu = new CheckBox("Show In Action Menu".Localize())
            {
                TextColor = ActiveTheme.Instance.PrimaryTextColor,
                HAnchor   = HAnchor.ParentLeftRight,
                Margin    = new BorderDouble(0, 0, 0, 1),
                Checked   = windowController.ActiveMacro.ActionGroup,
            };

            container.AddChild(showInActionMenu);
            container.HAnchor = HAnchor.ParentLeftRight;
            return(container);
        }
Beispiel #29
0
        public ValueTag(string title, string value, BorderDouble padding, int notchSize, int p2, ThemeConfig theme, bool autoBorderColor = true)
            : base(ArrowDirection.Right, padding, notchSize, p2, autoBorderColor)
        {
            this.HAnchor       = HAnchor.Fit;
            this.VAnchor       = VAnchor.Fit;
            this.FlowDirection = FlowDirection.LeftToRight;
            this.TagColor      = theme.ResolveColor(AppContext.Theme.BackgroundColor, theme.AccentMimimalOverlay.WithAlpha(50));

            this.AddChild(
                new TextWidget(title, pointSize: theme.DefaultFontSize - 1, textColor: theme.TextColor)
            {
                Margin = new BorderDouble(right: 12)
            });

            this.AddChild(
                new TextWidget(value, pointSize: theme.DefaultFontSize - 1, textColor: theme.TextColor)
            {
                Margin = new BorderDouble(left: 5)
            });
        }
Beispiel #30
0
        public MenuBase(string menuName)
        {
            MenuDropList = new DropDownMenu(menuName.ToUpper(), Direction.Down, pointSize: 10);
            MenuDropList.MenuItemsPadding = new BorderDouble(0);
            MenuDropList.Margin           = new BorderDouble(0);
            MenuDropList.Padding          = new BorderDouble(0);
            MenuDropList.MenuItemsPadding = new BorderDouble(8, 4);            // 8, 6, 8, 6);

            MenuDropList.DrawDirectionalArrow = false;
            MenuDropList.MenuAsWideAsItems    = false;

            menuActions = new List <MenuItemAction>(GetMenuActions());
            BorderDouble padding = MenuDropList.MenuItemsPadding;

            //Add the menu items to the menu itself
            foreach (MenuItemAction item in menuActions)
            {
                if (item.Title.StartsWith("-----"))
                {
                    MenuDropList.AddHorizontalLine();
                }
                else
                {
                    MenuItem newItem = MenuDropList.AddItem(item.Title, pointSize: 11);
                    if (item.Action == null)
                    {
                        newItem.Enabled = false;
                    }
                }
            }
            MenuDropList.Padding = padding;

            AddChild(MenuDropList);
            this.Width   = GetChildrenBoundsIncludingMargins().Width;
            this.Height  = 22 * GuiWidget.DeviceScale;
            this.Margin  = new BorderDouble(0);
            this.Padding = new BorderDouble(0);
            this.VAnchor = Agg.UI.VAnchor.ParentCenter;
            this.MenuDropList.SelectionChanged += MenuDropList_SelectionChanged;
            this.MenuDropList.OpenOffset        = new Vector2(0, 0);
        }
Beispiel #31
0
        public void CenterBothOffsetBoundsTest(BorderDouble controlPadding, BorderDouble buttonMargin)
        {
            GuiWidget containerControl = new GuiWidget(200, 300);

            containerControl.Padding      = controlPadding;
            containerControl.DoubleBuffer = true;
            GuiWidget controlRectangle = new GuiWidget(100, 100);

            controlRectangle.BackgroundColor = RGBA_Bytes.Red;
            controlRectangle.Margin          = buttonMargin;
            double controlCenterX = controlPadding.Left + (containerControl.Width - controlPadding.Left - controlPadding.Right) / 2;
            double buttonX        = controlCenterX - (controlRectangle.Width + controlRectangle.Margin.Left + controlRectangle.Margin.Right) / 2 + controlRectangle.Margin.Left;
            double controlCenterY = controlPadding.Bottom + (containerControl.Height - controlPadding.Bottom - controlPadding.Top) / 2 + controlRectangle.Margin.Bottom;
            double buttonY        = controlCenterY - (controlRectangle.Height + controlRectangle.Margin.Bottom + controlRectangle.Margin.Top) / 2;

            controlRectangle.OriginRelativeParent = new VectorMath.Vector2(buttonX, buttonY);
            containerControl.AddChild(controlRectangle);
            containerControl.OnDraw(containerControl.NewGraphics2D());

            GuiWidget containerTest = new GuiWidget(200, 300);

            containerTest.Padding      = controlPadding;
            containerTest.DoubleBuffer = true;

            GuiWidget       testRectangle = new GuiWidget(100, 100);
            RectangleDouble offsetBounds  = testRectangle.LocalBounds;

            offsetBounds.Offset(-10, -10);
            testRectangle.LocalBounds     = offsetBounds;
            testRectangle.BackgroundColor = RGBA_Bytes.Red;
            testRectangle.Margin          = buttonMargin;
            testRectangle.VAnchor         = VAnchor.ParentCenter;
            testRectangle.HAnchor         = HAnchor.ParentCenter;
            containerTest.AddChild(testRectangle);

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

            Assert.IsTrue(containerControl.BackBuffer != null, "When we set a guiWidget to DoubleBuffer it needs to create one.");
            Assert.IsTrue(containerControl.BackBuffer == containerTest.BackBuffer, "The Anchored widget should be in the correct place.");
        }
Beispiel #32
0
        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);
                    }
                }
            }
        }
            public ColorToSpeedWidget(GuiWidget colorWidget, double speed)
                : base(FlowDirection.LeftToRight)
            {
                Margin = new BorderDouble(2);

                layerSpeed = "{0} mm/s".FormatWith(speed);

                colorWidget.Margin = new BorderDouble(left: 2);

                TextWidget speedTextBox = new TextWidget(layerSpeed, pointSize: 12);

                speedTextBox.TextColor = RGBA_Bytes.White;
                speedTextBox.VAnchor   = VAnchor.ParentCenter;
                speedTextBox.Margin    = new BorderDouble(5, 0);

                this.AddChild(colorWidget);
                this.AddChild(new HorizontalSpacer());
                this.AddChild(speedTextBox);

                this.HAnchor |= HAnchor.ParentLeftRight;
            }
Beispiel #34
0
        void SetMenuItems()
        {
            menuItems = new TupleList <string, Func <bool> >
            {
                { LocalizedString.Get("Getting Started"), gettingStarted_Click },
                { LocalizedString.Get("View Help"), help_Click },
                { LocalizedString.Get("Report a Bug"), bug_Click },
                { LocalizedString.Get("Release Notes"), notes_Click },
                { LocalizedString.Get("About MatterControl"), about_Click },
            };

            BorderDouble padding = MenuDropList.MenuItemsPadding;

            //Add the menu items to the menu itself
            foreach (Tuple <string, Func <bool> > item in menuItems)
            {
                MenuDropList.MenuItemsPadding = new BorderDouble(8, 4, 8, 4) * TextWidget.GlobalPointSizeScaleRatio;
                MenuDropList.AddItem(item.Item1, pointSize: 10);
            }
            MenuDropList.Padding = padding;
        }
Beispiel #35
0
		private GuiWidget CreateLeftToRightMiddleWidget(BorderDouble buttonMargin, double buttonSize, VAnchor vAnchor, RGBA_Bytes color)
		{
			GuiWidget middle = new GuiWidget(buttonSize / 2, buttonSize);
			middle.Margin = buttonMargin;
			middle.HAnchor = HAnchor.ParentLeftRight;
			middle.VAnchor = vAnchor;
			middle.BackgroundColor = color;
			return middle;
		}
Beispiel #36
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.");
		}
Beispiel #37
0
		public void NestedFlowWidgetsLeftToRightTest(BorderDouble controlPadding, BorderDouble buttonMargin)
		{
			GuiWidget containerControl = new GuiWidget(500, 300);
			containerControl.Padding = controlPadding;
			containerControl.DoubleBuffer = true;

			{
				Button buttonRight = new Button("buttonRight");
				Button buttonLeft = new Button("buttonLeft");
				buttonLeft.OriginRelativeParent = new VectorMath.Vector2(controlPadding.Left + buttonMargin.Left, buttonLeft.OriginRelativeParent.y);
				buttonRight.OriginRelativeParent = new VectorMath.Vector2(buttonLeft.BoundsRelativeToParent.Right + buttonMargin.Width, buttonRight.OriginRelativeParent.y);
				containerControl.AddChild(buttonRight);
				containerControl.AddChild(buttonLeft);
				containerControl.OnDraw(containerControl.NewGraphics2D());
			}

			GuiWidget containerTest = new GuiWidget(500, 300);
			containerTest.DoubleBuffer = true;
			{
				FlowLayoutWidget leftToRightFlowLayoutAll = new FlowLayoutWidget(FlowDirection.LeftToRight);
				leftToRightFlowLayoutAll.AnchorAll();
				leftToRightFlowLayoutAll.Padding = controlPadding;
				{
					FlowLayoutWidget leftToRightFlowLayoutLeft = new FlowLayoutWidget(FlowDirection.LeftToRight);
					Button buttonTop = new Button("buttonLeft");
					buttonTop.Margin = buttonMargin;
					leftToRightFlowLayoutLeft.AddChild(buttonTop);
					leftToRightFlowLayoutLeft.SetBoundsToEncloseChildren();
					leftToRightFlowLayoutAll.AddChild(leftToRightFlowLayoutLeft);
				}

				{
					FlowLayoutWidget leftToRightFlowLayoutRight = new FlowLayoutWidget(FlowDirection.LeftToRight);
					Button buttonBottom = new Button("buttonRight");
					buttonBottom.Margin = buttonMargin;
					leftToRightFlowLayoutRight.AddChild(buttonBottom);
					leftToRightFlowLayoutRight.SetBoundsToEncloseChildren();
					leftToRightFlowLayoutAll.AddChild(leftToRightFlowLayoutRight);
				}

				containerTest.AddChild(leftToRightFlowLayoutAll);
			}

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

			Assert.IsTrue(containerControl.BackBuffer != null, "When we set a guiWidget to DoubleBuffer it needs to create one.");
			Assert.IsTrue(containerControl.BackBuffer == containerTest.BackBuffer, "The Anchored widget should be in the correct place.");
		}
Beispiel #38
0
		public void NestedFlowWidgetsRightToLeftTest(BorderDouble controlPadding, BorderDouble buttonMargin)
		{
			GuiWidget containerControl = new GuiWidget(500, 300);
			containerControl.Padding = controlPadding;
			containerControl.DoubleBuffer = true;

			{
				Button buttonRight = new Button("buttonRight");
				Button buttonLeft = new Button("buttonLeft");
				buttonRight.OriginRelativeParent = new VectorMath.Vector2(containerControl.LocalBounds.Right - controlPadding.Right - buttonMargin.Right - buttonRight.Width, buttonRight.OriginRelativeParent.y + controlPadding.Bottom + buttonMargin.Bottom);
				buttonLeft.OriginRelativeParent = new VectorMath.Vector2(buttonRight.BoundsRelativeToParent.Left - buttonMargin.Width - buttonLeft.Width, buttonLeft.OriginRelativeParent.y + controlPadding.Bottom + buttonMargin.Bottom);
				containerControl.AddChild(buttonRight);
				containerControl.AddChild(buttonLeft);
				containerControl.OnDraw(containerControl.NewGraphics2D());
			}

			GuiWidget containerTest = new GuiWidget(500, 300);
			containerTest.DoubleBuffer = true;
			{
				FlowLayoutWidget rightToLeftFlowLayoutAll = new FlowLayoutWidget(FlowDirection.RightToLeft);
				rightToLeftFlowLayoutAll.AnchorAll();
				rightToLeftFlowLayoutAll.Padding = controlPadding;
				{
					FlowLayoutWidget rightToLeftFlowLayoutRight = new FlowLayoutWidget(FlowDirection.RightToLeft);
					Button buttonRight = new Button("buttonRight");
					buttonRight.Margin = buttonMargin;
					rightToLeftFlowLayoutRight.AddChild(buttonRight);
					rightToLeftFlowLayoutRight.SetBoundsToEncloseChildren();
					rightToLeftFlowLayoutRight.VAnchor = VAnchor.ParentBottom;
					rightToLeftFlowLayoutAll.AddChild(rightToLeftFlowLayoutRight);
				}

				{
					FlowLayoutWidget rightToLeftFlowLayoutLeft = new FlowLayoutWidget(FlowDirection.RightToLeft);
					Button buttonLeft = new Button("buttonLeft");
					buttonLeft.Margin = buttonMargin;
					rightToLeftFlowLayoutLeft.AddChild(buttonLeft);
					rightToLeftFlowLayoutLeft.SetBoundsToEncloseChildren();
					rightToLeftFlowLayoutLeft.VAnchor = VAnchor.ParentBottom;
					rightToLeftFlowLayoutAll.AddChild(rightToLeftFlowLayoutLeft);
				}

				containerTest.AddChild(rightToLeftFlowLayoutAll);
			}

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

			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, 50), "The test and control need to match.");
			Assert.IsTrue(containerControl.BackBuffer.Equals(containerTest.BackBuffer, 1), "The Anchored widget should be in the correct place.");
		}
Beispiel #39
0
		public void NestedFlowWidgetsTopToBottomTest(BorderDouble controlPadding, BorderDouble buttonMargin)
		{
			GuiWidget containerControl = new GuiWidget(300, 500);
			containerControl.Padding = controlPadding;
			containerControl.DoubleBuffer = true;

			{
				Button buttonTop = new Button("buttonTop");
				Button buttonBottom = new Button("buttonBottom");
				buttonTop.OriginRelativeParent = new VectorMath.Vector2(buttonTop.OriginRelativeParent.x, containerControl.LocalBounds.Top - buttonMargin.Top - controlPadding.Top - buttonTop.Height);
				buttonBottom.OriginRelativeParent = new VectorMath.Vector2(buttonBottom.OriginRelativeParent.x, buttonTop.BoundsRelativeToParent.Bottom - buttonBottom.Height - buttonMargin.Height);
				containerControl.AddChild(buttonTop);
				containerControl.AddChild(buttonBottom);
				containerControl.OnDraw(containerControl.NewGraphics2D());
			}

			GuiWidget containerTest = new GuiWidget(300, 500);
			containerTest.DoubleBuffer = true;
			{
				FlowLayoutWidget topToBottomFlowLayoutAll = new FlowLayoutWidget(FlowDirection.TopToBottom);
				topToBottomFlowLayoutAll.AnchorAll();
				topToBottomFlowLayoutAll.Padding = controlPadding;
				{
					FlowLayoutWidget topToBottomFlowLayoutTop = new FlowLayoutWidget(FlowDirection.TopToBottom);
					Button buttonTop = new Button("buttonTop");
					buttonTop.Margin = buttonMargin;
					topToBottomFlowLayoutTop.AddChild(buttonTop);
					topToBottomFlowLayoutTop.SetBoundsToEncloseChildren();
					topToBottomFlowLayoutAll.AddChild(topToBottomFlowLayoutTop);
				}

				{
					FlowLayoutWidget topToBottomFlowLayoutBottom = new FlowLayoutWidget(FlowDirection.TopToBottom);
					Button buttonBottom = new Button("buttonBottom");
					buttonBottom.Margin = buttonMargin;
					topToBottomFlowLayoutBottom.AddChild(buttonBottom);
					topToBottomFlowLayoutBottom.SetBoundsToEncloseChildren();
					topToBottomFlowLayoutAll.AddChild(topToBottomFlowLayoutBottom);
				}

				containerTest.AddChild(topToBottomFlowLayoutAll);
			}

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

			Assert.IsTrue(containerControl.BackBuffer != null, "When we set a guiWidget to DoubleBuffer it needs to create one.");
			Assert.IsTrue(containerControl.BackBuffer == containerTest.BackBuffer, "The Anchored widget should be in the correct place.");
		}
Beispiel #40
0
		public void HCenterHRightAndVCenterVTopTest(BorderDouble controlPadding, BorderDouble buttonMargin)
		{
			GuiWidget containerControl = new GuiWidget(200, 300);
			containerControl.Padding = controlPadding;
			containerControl.DoubleBuffer = true;
			Button controlButton1 = new Button("button1");
			controlButton1.OriginRelativeParent = new VectorMath.Vector2(
				controlPadding.Left + buttonMargin.Left + (containerControl.Width - (controlPadding.Left + controlPadding.Right)) / 2,
				controlPadding.Bottom + buttonMargin.Bottom + (containerControl.Height - (controlPadding.Bottom + controlPadding.Top)) / 2);
			controlButton1.LocalBounds = new RectangleDouble(
				controlButton1.LocalBounds.Left,
				controlButton1.LocalBounds.Bottom,
				controlButton1.LocalBounds.Left + containerControl.Width / 2 - (controlPadding.Left + controlPadding.Right) / 2 - (buttonMargin.Left + buttonMargin.Right),
				controlButton1.LocalBounds.Bottom + containerControl.Height / 2 - (controlPadding.Bottom + controlPadding.Top) / 2 - (buttonMargin.Bottom + buttonMargin.Top));
			containerControl.AddChild(controlButton1);
			containerControl.OnDraw(containerControl.NewGraphics2D());

			GuiWidget containerTest = new GuiWidget(200, 300);
			containerTest.Padding = controlPadding;
			containerTest.DoubleBuffer = true;

			Button testButton1 = new Button("button1");
			testButton1.Margin = buttonMargin;
			testButton1.VAnchor = VAnchor.ParentCenter | VAnchor.ParentTop;
			testButton1.HAnchor = HAnchor.ParentCenter | HAnchor.ParentRight;
			containerTest.AddChild(testButton1);

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

			Assert.IsTrue(containerControl.BackBuffer != null, "When we set a guiWidget to DoubleBuffer it needs to create one.");
			Assert.IsTrue(containerControl.BackBuffer == containerTest.BackBuffer, "The Anchored widget should be in the correct place.");
		}
		public RadioButton GenerateRadioButton(string label)
		{
			BorderDouble internalMargin = new BorderDouble(0);
			TextWidget nomalState = new TextWidget(label);
			TextWidget hoverState = new TextWidget(label);
			TextWidget checkingState = new TextWidget(label);
			TextWidget checkedState = new TextWidget(label);
			TextWidget disabledState = new TextWidget(label);
			RadioButtonViewStates checkBoxButtonViewWidget = new RadioButtonViewStates(nomalState, hoverState, checkingState, checkedState, disabledState);
			RadioButton radioButton = new RadioButton(checkBoxButtonViewWidget);
			radioButton.Margin = new BorderDouble();
			return radioButton;
		}
Beispiel #42
0
		public void NestedLayoutTopToBottomWithResizeTest(BorderDouble controlPadding, BorderDouble buttonMargin)
		{
			GuiWidget containerTest = new GuiWidget(300, 200);
			containerTest.Padding = controlPadding;
			containerTest.DoubleBuffer = true;
			containerTest.BackBuffer.NewGraphics2D().Clear(RGBA_Bytes.White);

			FlowLayoutWidget allButtons = new FlowLayoutWidget(FlowDirection.TopToBottom);
			{
				FlowLayoutWidget topButtonBar = new FlowLayoutWidget();
				{
					Button button1 = new Button("button1");
					button1.Margin = buttonMargin;
					topButtonBar.AddChild(button1);
				}
				allButtons.AddChild(topButtonBar);

				FlowLayoutWidget bottomButtonBar = new FlowLayoutWidget();
				{
					Button button2 = new Button("wide button2");
					button2.Margin = buttonMargin;
					bottomButtonBar.AddChild(button2);
				}
				allButtons.AddChild(bottomButtonBar);
			}
			containerTest.AddChild(allButtons);
			containerTest.OnDraw(containerTest.NewGraphics2D());
			ImageBuffer controlImage = new ImageBuffer(containerTest.BackBuffer, new BlenderBGRA());

			OutputImage(controlImage, "image-control.tga");

			RectangleDouble oldBounds = containerTest.LocalBounds;
			RectangleDouble newBounds = oldBounds;
			newBounds.Right += 10;
			containerTest.LocalBounds = newBounds;
			containerTest.BackBuffer.NewGraphics2D().Clear(RGBA_Bytes.White);
			containerTest.OnDraw(containerTest.NewGraphics2D());
			OutputImage(containerTest, "image-test.tga");

			containerTest.LocalBounds = oldBounds;
			containerTest.BackBuffer.NewGraphics2D().Clear(RGBA_Bytes.White);
			containerTest.OnDraw(containerTest.NewGraphics2D());
			OutputImage(containerTest, "image-test.tga");

			Assert.IsTrue(containerTest.BackBuffer != null, "When we set a guiWidget to DoubleBuffer it needs to create one.");
			Assert.IsTrue(containerTest.BackBuffer == controlImage, "The control should contain the same image after being scaled away and back to the same size.");
		}
Beispiel #43
0
		public void NestedLayoutTopToBottomTest(BorderDouble controlPadding, BorderDouble buttonMargin)
		{
			GuiWidget containerControl = new GuiWidget(300, 200);
			containerControl.DoubleBuffer = true;
			containerControl.BackBuffer.NewGraphics2D().Clear(RGBA_Bytes.White);
			{
				Button topButtonC = new Button("top button");
				Button bottomButtonC = new Button("bottom wide button");
				topButtonC.LocalBounds = new RectangleDouble(0, 0, bottomButtonC.LocalBounds.Width, 40);
				topButtonC.OriginRelativeParent = new Vector2(bottomButtonC.OriginRelativeParent.x + buttonMargin.Left, containerControl.Height - controlPadding.Top - topButtonC.Height - buttonMargin.Top);
				containerControl.AddChild(topButtonC);
				bottomButtonC.OriginRelativeParent = new Vector2(bottomButtonC.OriginRelativeParent.x + buttonMargin.Left, topButtonC.OriginRelativeParent.y - buttonMargin.Height - bottomButtonC.Height);
				containerControl.AddChild(bottomButtonC);
			}
			containerControl.OnDraw(containerControl.NewGraphics2D());

			GuiWidget containerTest = new GuiWidget(300, 200);
			containerTest.DoubleBuffer = true;
			containerTest.BackBuffer.NewGraphics2D().Clear(RGBA_Bytes.White);

			FlowLayoutWidget allButtons = new FlowLayoutWidget(FlowDirection.TopToBottom);
			allButtons.AnchorAll();
			Button topButtonT;
			Button bottomButtonT;
			FlowLayoutWidget topButtonBar;
			FlowLayoutWidget bottomButtonBar;
			allButtons.Padding = controlPadding;
			{
				bottomButtonT = new Button("bottom wide button");

				topButtonBar = new FlowLayoutWidget();
				{
					topButtonT = new Button("top button");
					topButtonT.LocalBounds = new RectangleDouble(0, 0, bottomButtonT.LocalBounds.Width, 40);
					topButtonT.Margin = buttonMargin;
					topButtonBar.AddChild(topButtonT);
				}
				allButtons.AddChild(topButtonBar);

				bottomButtonBar = new FlowLayoutWidget();
				{
					bottomButtonT.Margin = buttonMargin;
					bottomButtonBar.AddChild(bottomButtonT);
				}
				allButtons.AddChild(bottomButtonBar);
			}
			containerTest.AddChild(allButtons);
			containerTest.OnDraw(containerTest.NewGraphics2D());

			OutputImages(containerControl, containerTest);

			Assert.IsTrue(containerTest.BackBuffer != null, "When we set a guiWidget to DoubleBuffer it needs to create one.");
			Assert.IsTrue(containerTest.BackBuffer.Equals(containerControl.BackBuffer, 1), "The test should contain the same image as the control.");
		}
Beispiel #44
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.");
		}
Beispiel #45
0
		private GuiWidget CreateBottomToTopMiddleWidget(BorderDouble buttonMargin, double buttonSize, HAnchor hAnchor, RGBA_Bytes color)
		{
			GuiWidget middle = new GuiWidget(buttonSize, buttonSize / 2);
			middle.Margin = buttonMargin;
			middle.VAnchor = VAnchor.ParentBottomTop;
			middle.HAnchor = hAnchor;
			middle.BackgroundColor = color;
			return middle;
		}
Beispiel #46
0
		public void CenterBothTest(BorderDouble controlPadding, BorderDouble buttonMargin)
		{
			GuiWidget containerControl = new GuiWidget(200, 300);
			containerControl.Padding = controlPadding;
			containerControl.DoubleBuffer = true;
			Button controlButton1 = new Button("button1");
			controlButton1.Margin = buttonMargin;
			double controlCenterX = controlPadding.Left + (containerControl.Width - controlPadding.Left - controlPadding.Right) / 2;
			double buttonX = controlCenterX - (controlButton1.Width + controlButton1.Margin.Left + controlButton1.Margin.Right) / 2 + controlButton1.Margin.Left;
			double controlCenterY = controlPadding.Bottom + (containerControl.Height - controlPadding.Bottom - controlPadding.Top) / 2 + controlButton1.Margin.Bottom;
			double buttonY = controlCenterY - (controlButton1.Height + controlButton1.Margin.Bottom + controlButton1.Margin.Top) / 2;
			controlButton1.OriginRelativeParent = new VectorMath.Vector2(buttonX, buttonY);
			containerControl.AddChild(controlButton1);
			containerControl.OnDraw(containerControl.NewGraphics2D());

			GuiWidget containerTest = new GuiWidget(200, 300);
			containerTest.Padding = controlPadding;
			containerTest.DoubleBuffer = true;

			Button testButton1 = new Button("button1");
			testButton1.Margin = buttonMargin;
			testButton1.VAnchor = VAnchor.ParentCenter;
			testButton1.HAnchor = HAnchor.ParentCenter;
			containerTest.AddChild(testButton1);

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

			Assert.IsTrue(containerControl.BackBuffer != null, "When we set a guiWidget to DoubleBuffer it needs to create one.");
			OutputImages(containerControl, containerTest);
			Assert.IsTrue(containerControl.BackBuffer.Equals(containerTest.BackBuffer, 1), "The Anchored widget should be in the correct place.");
		}
Beispiel #47
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);
			}
		}
Beispiel #48
0
		public Tab(string tabName, GuiWidget normalWidget, GuiWidget hoverWidget, GuiWidget pressedWidget,
			TabPage tabPageControledByTab)
		{
			base.Name = tabName;
			this.normalWidget = normalWidget;
			this.hoverWidget = hoverWidget;
			this.selectedWidget = pressedWidget;
			AddChild(normalWidget);
			AddChild(hoverWidget);
			hoverWidget.Visible = false;
			AddChild(pressedWidget);
			pressedWidget.Visible = false;
			Padding = new BorderDouble(5, 3, 20, 3);
			this.tabPageControledByTab = tabPageControledByTab;
			SetBoundsToEncloseChildren();
		}
Beispiel #49
0
		private void LeftToRightAnchorLeftBottomTest(BorderDouble controlPadding, BorderDouble buttonMargin)
		{
			GuiWidget containerControl = new GuiWidget(300, 200);
			containerControl.DoubleBuffer = true;
			Button controlButton1 = new Button("buttonLeft");
			controlButton1.OriginRelativeParent = new VectorMath.Vector2(controlPadding.Left + buttonMargin.Left, controlButton1.OriginRelativeParent.y + controlPadding.Bottom + buttonMargin.Bottom);
			containerControl.AddChild(controlButton1);
			Button controlButton2 = new Button("buttonRight");
			controlButton2.OriginRelativeParent = new VectorMath.Vector2(controlPadding.Left + buttonMargin.Width + buttonMargin.Left + controlButton1.Width, controlButton2.OriginRelativeParent.y + controlPadding.Bottom + buttonMargin.Bottom);
			containerControl.AddChild(controlButton2);
			containerControl.OnDraw(containerControl.NewGraphics2D());

			GuiWidget containerTest = new GuiWidget(300, 200);
			FlowLayoutWidget flowLayout = new FlowLayoutWidget(FlowDirection.LeftToRight);
			flowLayout.AnchorAll();
			flowLayout.Padding = controlPadding;
			containerTest.DoubleBuffer = true;

			Button testButton1 = new Button("buttonLeft");
			testButton1.VAnchor = VAnchor.ParentBottom;
			testButton1.Margin = buttonMargin;
			flowLayout.AddChild(testButton1);

			Button testButton2 = new Button("buttonRight");
			testButton2.VAnchor = VAnchor.ParentBottom;
			testButton2.Margin = buttonMargin;
			flowLayout.AddChild(testButton2);

			containerTest.AddChild(flowLayout);

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

			Assert.IsTrue(containerControl.BackBuffer != null, "When we set a guiWidget to DoubleBuffer it needs to create one.");
			Assert.IsTrue(containerControl.BackBuffer == containerTest.BackBuffer, "The Anchored widget should be in the correct place.");

			// make sure it can resize without breaking
			RectangleDouble bounds = containerTest.LocalBounds;
			RectangleDouble newBounds = bounds;
			newBounds.Right += 10;
			containerTest.LocalBounds = newBounds;
			Assert.IsTrue(containerControl.BackBuffer != containerTest.BackBuffer, "The Anchored widget should not be the same size.");
			containerTest.LocalBounds = bounds;
			containerTest.OnDraw(containerTest.NewGraphics2D());
			OutputImages(containerControl, containerTest);
			Assert.IsTrue(containerControl.BackBuffer == containerTest.BackBuffer, "The Anchored widget should be in the correct place.");
		}
Beispiel #50
0
		public void CenterBothOffsetBoundsTest(BorderDouble controlPadding, BorderDouble buttonMargin)
		{
			GuiWidget containerControl = new GuiWidget(200, 300);
			containerControl.Padding = controlPadding;
			containerControl.DoubleBuffer = true;
			GuiWidget controlRectangle = new GuiWidget(100, 100);
			controlRectangle.BackgroundColor = RGBA_Bytes.Red;
			controlRectangle.Margin = buttonMargin;
			double controlCenterX = controlPadding.Left + (containerControl.Width - controlPadding.Left - controlPadding.Right) / 2;
			double buttonX = controlCenterX - (controlRectangle.Width + controlRectangle.Margin.Left + controlRectangle.Margin.Right) / 2 + controlRectangle.Margin.Left;
			double controlCenterY = controlPadding.Bottom + (containerControl.Height - controlPadding.Bottom - controlPadding.Top) / 2 + controlRectangle.Margin.Bottom;
			double buttonY = controlCenterY - (controlRectangle.Height + controlRectangle.Margin.Bottom + controlRectangle.Margin.Top) / 2;
			controlRectangle.OriginRelativeParent = new VectorMath.Vector2(buttonX, buttonY);
			containerControl.AddChild(controlRectangle);
			containerControl.OnDraw(containerControl.NewGraphics2D());

			GuiWidget containerTest = new GuiWidget(200, 300);
			containerTest.Padding = controlPadding;
			containerTest.DoubleBuffer = true;

			GuiWidget testRectangle = new GuiWidget(100, 100);
			RectangleDouble offsetBounds = testRectangle.LocalBounds;
			offsetBounds.Offset(-10, -10);
			testRectangle.LocalBounds = offsetBounds;
			testRectangle.BackgroundColor = RGBA_Bytes.Red;
			testRectangle.Margin = buttonMargin;
			testRectangle.VAnchor = VAnchor.ParentCenter;
			testRectangle.HAnchor = HAnchor.ParentCenter;
			containerTest.AddChild(testRectangle);

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

			Assert.IsTrue(containerControl.BackBuffer != null, "When we set a guiWidget to DoubleBuffer it needs to create one.");
			Assert.IsTrue(containerControl.BackBuffer == containerTest.BackBuffer, "The Anchored widget should be in the correct place.");
		}
Beispiel #51
0
		public void FlowTopBottomAnchorChildrenLeftRightTest(BorderDouble controlPadding, BorderDouble buttonMargin)
		{
			GuiWidget containerControl = new GuiWidget(300, 500);
			containerControl.DoubleBuffer = true;
			Button controlButtonWide = new Button("Button Wide Text");
			containerControl.AddChild(controlButtonWide);
			Button controlButton1 = new Button("button1");
			controlButton1.OriginRelativeParent = new VectorMath.Vector2(controlPadding.Left + buttonMargin.Left + controlButton1.OriginRelativeParent.x, controlPadding.Bottom + buttonMargin.Bottom);
			controlButtonWide.OriginRelativeParent = new VectorMath.Vector2(controlPadding.Left + buttonMargin.Left + controlButtonWide.OriginRelativeParent.x, controlButton1.BoundsRelativeToParent.Top + buttonMargin.Height);
			controlButton1.LocalBounds = controlButtonWide.LocalBounds;
			containerControl.AddChild(controlButton1);
			containerControl.OnDraw(containerControl.NewGraphics2D());

			GuiWidget containerTest = new GuiWidget(300, 500);
			FlowLayoutWidget flowLayout = new FlowLayoutWidget(FlowDirection.TopToBottom);
			flowLayout.Padding = controlPadding;
			containerTest.DoubleBuffer = true;

			Button testButtonWide = new Button("Button Wide Text");
			testButtonWide.HAnchor = HAnchor.ParentLeft;
			testButtonWide.Margin = buttonMargin;
			flowLayout.AddChild(testButtonWide);

			double correctHeightOfFlowLayout = testButtonWide.Height + flowLayout.Padding.Height + testButtonWide.Margin.Height;
			Assert.AreEqual(flowLayout.Height, correctHeightOfFlowLayout, .001);

			Button testButton1 = new Button("button1");
			testButton1.Margin = buttonMargin;
			testButton1.HAnchor = HAnchor.ParentLeft | HAnchor.ParentRight;
			flowLayout.AddChild(testButton1);

			correctHeightOfFlowLayout += testButton1.Height + testButton1.Margin.Height;
			Assert.AreEqual(flowLayout.Height, correctHeightOfFlowLayout, .001);

			flowLayout.HAnchor = HAnchor.ParentLeft;
			flowLayout.VAnchor = VAnchor.ParentBottom;
			containerTest.AddChild(flowLayout);

			Vector2 controlButton1Pos = controlButton1.OriginRelativeParent;
			Vector2 testButton1Pos = testButton1.TransformToScreenSpace(Vector2.Zero);

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

			Assert.IsTrue(containerControl.BackBuffer != null, "When we set a guiWidget to DoubleBuffer it needs to create one.");
			Assert.IsTrue(containerControl.BackBuffer.Equals(containerTest.BackBuffer, 1), "The Anchored widget should be in the correct place.");

			// make sure it can resize without breaking
			RectangleDouble bounds = containerTest.LocalBounds;
			RectangleDouble newBounds = bounds;
			newBounds.Right += 10;
			containerTest.LocalBounds = newBounds;
			Assert.IsTrue(containerControl.BackBuffer != containerTest.BackBuffer, "The Anchored widget should not be the same size.");
			containerTest.LocalBounds = bounds;
			containerTest.OnDraw(containerTest.NewGraphics2D());
			OutputImages(containerControl, containerTest);
			Assert.IsTrue(containerControl.BackBuffer.Equals(containerTest.BackBuffer, 1), "The Anchored widget should be in the correct place.");
		}