Пример #1
0
        public CheckBox GenerateCheckBoxButton(string label, ImageBuffer normalImage, ImageBuffer normalToPressedImage = null, ImageBuffer pressedImage = null, ImageBuffer pressedToNormalImage = null, string pressedLabel = null)
        {
            if (pressedImage == null)
            {
                pressedImage = normalImage;
            }
            if (pressedToNormalImage == null)
            {
                pressedToNormalImage = normalToPressedImage;
            }

            CheckBoxViewStates checkBoxButtonViewWidget = getCheckBoxButtonView(label, normalImage, normalToPressedImage, pressedImage, pressedToNormalImage, pressedLabel);

            //Override the width if requested
            if (this.FixedWidth != 0)
            {
                checkBoxButtonViewWidget.Width = this.FixedWidth;
            }

            CheckBox textImageCheckBoxButton = new CheckBox(0, 0, checkBoxButtonViewWidget);

            textImageCheckBoxButton.Margin  = new BorderDouble(0);
            textImageCheckBoxButton.Padding = new BorderDouble(0);

            return(textImageCheckBoxButton);
        }
        public ButtonsPage()
            : base("Radio and Check Buttons")
        {
            FlowLayoutWidget topToBottom = new FlowLayoutWidget(FlowDirection.TopToBottom);

            topToBottom.AddChild(new CheckBox("Simple Check Box"));

            CheckBoxViewStates fourStates = new CheckBoxViewStates(new TextWidget("normal"), new TextWidget("normal"),
                                                                   new TextWidget("switch n->p"),
                                                                   new TextWidget("pressed"), new TextWidget("pressed"),
                                                                   new TextWidget("switch p->n"),
                                                                   new TextWidget("disabled"));

            topToBottom.AddChild(new CheckBox(fourStates));

            GuiWidget normalPressed = new TextWidget("0 4state");

            normalPressed.BackgroundColor = RGBA_Bytes.Gray;
            GuiWidget downPressed = new TextWidget("1 4state");

            downPressed.BackgroundColor = RGBA_Bytes.Gray;

            GuiWidget normalHover = new TextWidget("0 4state");

            normalHover.BackgroundColor = RGBA_Bytes.Yellow;
            GuiWidget downHover = new TextWidget("1 4state");

            downHover.BackgroundColor = RGBA_Bytes.Yellow;

            CheckBoxViewStates fourStates2 = new CheckBoxViewStates(new TextWidget("0 4state"), normalHover, normalPressed, new TextWidget("1 4state"), downHover, downPressed, new TextWidget("disabled"));

            topToBottom.AddChild(new CheckBox(fourStates2));

            topToBottom.AddChild(new RadioButton("Simple Radio Button 1"));
            topToBottom.AddChild(new RadioButton("Simple Radio Button 2"));
            topToBottom.AddChild(new RadioButton(new RadioButtonViewText("Simple Radio Button 3")));
            topToBottom.AddChild(new RadioButton(new RadioButtonViewStates(new TextWidget("O - unchecked"), new TextWidget("O - unchecked hover"), new TextWidget("O - checking"), new TextWidget("X - checked"), new TextWidget("disabled"))));

            groupBox = new GroupBox("Radio Group");
            //groupBox.LocalBounds = new RectangleDouble(0, 0, 300, 150);
            groupBox.OriginRelativeParent = new Vector2(200, 350);
            FlowLayoutWidget topToBottomRadios = new FlowLayoutWidget(FlowDirection.TopToBottom);

            topToBottomRadios.AnchorAll();
            topToBottomRadios.AddChild(new RadioButton("Simple Radio Button 1"));
            topToBottomRadios.AddChild(new RadioButton("Simple Radio Button 2"));
            topToBottomRadios.AddChild(new RadioButton("Simple Radio Button 3"));
            topToBottomRadios.SetBoundsToEncloseChildren();
            groupBox.AddChild(topToBottomRadios);
            topToBottom.AddChild(groupBox);

            AddChild(topToBottom);

            topToBottom.VAnchor = UI.VAnchor.ParentTop;
        }
Пример #3
0
        private CheckBoxViewStates getCheckBoxButtonView(string label, string normalImageName = null, string normalToPressedImageName = null, string pressedImageName = null, string pressedToNormalImageName = null, string pressedLabel = null)
        {
            ImageBuffer normalImage          = new ImageBuffer();
            ImageBuffer pressedImage         = new ImageBuffer();
            ImageBuffer normalToPressedImage = new ImageBuffer();
            ImageBuffer pressedToNormalImage = new ImageBuffer();
            string      pressedText          = pressedLabel;

            if (pressedLabel == null)
            {
                pressedText = label;
            }

            if (normalToPressedImageName == null)
            {
                normalToPressedImageName = pressedImageName;
            }

            if (pressedImageName == null)
            {
                pressedImageName = normalToPressedImageName;
            }

            if (pressedToNormalImageName == null)
            {
                pressedToNormalImageName = normalImageName;
            }

            if (normalImageName != null)
            {
                StaticData.Instance.LoadIcon(normalImageName, normalImage);

                if (!ActiveTheme.Instance.IsDarkTheme && AllowThemeToAdjustImage)
                {
                    InvertLightness.DoInvertLightness(normalImage);
                }
            }

            if (pressedImageName != null)
            {
                StaticData.Instance.LoadIcon(pressedImageName, pressedImage);
                if (!ActiveTheme.Instance.IsDarkTheme && AllowThemeToAdjustImage)
                {
                    InvertLightness.DoInvertLightness(pressedImage);
                }
            }

            if (normalToPressedImageName != null)
            {
                StaticData.Instance.LoadIcon(normalToPressedImageName, normalToPressedImage);
                if (!ActiveTheme.Instance.IsDarkTheme && AllowThemeToAdjustImage)
                {
                    InvertLightness.DoInvertLightness(normalToPressedImage);
                }
            }

            if (pressedToNormalImageName != null)
            {
                StaticData.Instance.LoadIcon(pressedToNormalImageName, pressedToNormalImage);
                if (!ActiveTheme.Instance.IsDarkTheme && AllowThemeToAdjustImage)
                {
                    InvertLightness.DoInvertLightness(pressedToNormalImage);
                }
            }

            if (invertImageLocation)
            {
                flowDirection = FlowDirection.RightToLeft;
            }
            else
            {
                flowDirection = FlowDirection.LeftToRight;
            }

            //Create the multi-state button view
            GuiWidget normal                = new TextImageWidget(label, normalFillColor, normalBorderColor, normalTextColor, borderWidth, Margin, normalImage, flowDirection: flowDirection, fontSize: this.fontSize, height: this.FixedHeight);
            GuiWidget normalHover           = new TextImageWidget(label, hoverFillColor, normalBorderColor, hoverTextColor, borderWidth, Margin, normalImage, flowDirection: flowDirection, fontSize: this.fontSize, height: this.FixedHeight);
            GuiWidget switchNormalToPressed = new TextImageWidget(label, pressedFillColor, normalBorderColor, pressedTextColor, borderWidth, Margin, normalToPressedImage, flowDirection: flowDirection, fontSize: this.fontSize, height: this.FixedHeight);
            GuiWidget pressed               = new TextImageWidget(pressedText, pressedFillColor, pressedBorderColor, pressedTextColor, borderWidth, Margin, pressedImage, flowDirection: flowDirection, fontSize: this.fontSize, height: this.FixedHeight);
            GuiWidget pressedHover          = new TextImageWidget(label, hoverFillColor, pressedBorderColor, hoverTextColor, borderWidth, Margin, pressedImage, flowDirection: flowDirection, fontSize: this.fontSize, height: this.FixedHeight);
            GuiWidget switchPressedToNormal = new TextImageWidget(label, normalFillColor, pressedBorderColor, normalTextColor, borderWidth, Margin, pressedToNormalImage, flowDirection: flowDirection, fontSize: this.fontSize, height: this.FixedHeight);
            GuiWidget disabled              = new TextImageWidget(label, disabledFillColor, disabledBorderColor, disabledTextColor, borderWidth, Margin, normalImage, flowDirection: flowDirection, fontSize: this.fontSize, height: this.FixedHeight);

            CheckBoxViewStates checkBoxButtonViewWidget = new CheckBoxViewStates(normal, normalHover, switchNormalToPressed, pressed, pressedHover, switchPressedToNormal, disabled);

            return(checkBoxButtonViewWidget);
        }
        private CheckBoxViewStates getCheckBoxButtonView(string label, string normalImageName = null, string normalToPressedImageName = null, string pressedImageName = null, string pressedToNormalImageName = null)
        {
            ImageBuffer normalImage          = new ImageBuffer();
            ImageBuffer pressedImage         = new ImageBuffer();
            ImageBuffer normalToPressedImage = new ImageBuffer();
            ImageBuffer pressedToNormalImage = new ImageBuffer();

            if (normalImageName != null)
            {
                ImageBMPIO.LoadImageData(this.GetImageLocation(normalImageName), normalImage);
            }

            if (pressedImageName != null)
            {
                ImageBMPIO.LoadImageData(this.GetImageLocation(pressedImageName), pressedImage);
            }

            if (normalToPressedImageName != null)
            {
                ImageBMPIO.LoadImageData(this.GetImageLocation(normalToPressedImageName), normalToPressedImage);
            }

            if (pressedToNormalImageName != null)
            {
                ImageBMPIO.LoadImageData(this.GetImageLocation(pressedToNormalImageName), pressedToNormalImage);
            }

            if (normalToPressedImageName == null)
            {
                normalToPressedImage = pressedImage;
            }

            if (pressedImageName == null)
            {
                pressedImage = normalToPressedImage;
            }

            if (pressedToNormalImageName == null)
            {
                pressedToNormalImage = normalImage;
            }

            if (invertImageLocation)
            {
                flowDirection = FlowDirection.RightToLeft;
            }
            else
            {
                flowDirection = FlowDirection.LeftToRight;
            }

            //Create the multi-state button view
            GuiWidget normal                = new TextImageWidget(label, normalFillColor, normalBorderColor, normalTextColor, borderWidth, Margin, normalImage, flowDirection: flowDirection, fontSize: this.fontSize, height: this.FixedHeight);
            GuiWidget normalHover           = new TextImageWidget(label, hoverFillColor, normalBorderColor, hoverTextColor, borderWidth, Margin, normalImage, flowDirection: flowDirection, fontSize: this.fontSize, height: this.FixedHeight);
            GuiWidget switchNormalToPressed = new TextImageWidget(label, pressedFillColor, normalBorderColor, pressedTextColor, borderWidth, Margin, normalToPressedImage, flowDirection: flowDirection, fontSize: this.fontSize, height: this.FixedHeight);
            GuiWidget pressed               = new TextImageWidget(label, pressedFillColor, pressedBorderColor, pressedTextColor, borderWidth, Margin, pressedImage, flowDirection: flowDirection, fontSize: this.fontSize, height: this.FixedHeight);
            GuiWidget pressedHover          = new TextImageWidget(label, hoverFillColor, pressedBorderColor, hoverTextColor, borderWidth, Margin, pressedImage, flowDirection: flowDirection, fontSize: this.fontSize, height: this.FixedHeight);
            GuiWidget switchPressedToNormal = new TextImageWidget(label, normalFillColor, pressedBorderColor, normalTextColor, borderWidth, Margin, pressedToNormalImage, flowDirection: flowDirection, fontSize: this.fontSize, height: this.FixedHeight);
            GuiWidget disabled              = new TextImageWidget(label, disabledFillColor, disabledBorderColor, disabledTextColor, borderWidth, Margin, normalImage, flowDirection: flowDirection, fontSize: this.fontSize, height: this.FixedHeight);

            CheckBoxViewStates checkBoxButtonViewWidget = new CheckBoxViewStates(normal, normalHover, switchNormalToPressed, pressed, pressedHover, switchPressedToNormal, disabled);

            return(checkBoxButtonViewWidget);
        }