Example #1
0
        public FileBrowserWindow(GUISystem system, GUITheme theme, UDim2 size, string title,
                                 FileBrowserMode mode, string[] exts, FileBrowserCompleted callback)
            : base(system, size, title, theme)
        {
            this.mode     = mode;
            this.callback = callback;
            this.exts     = exts;

            BMPFont smallFont = theme.GetField <BMPFont>(null, "SmallFont", "Font");

            dirField            = new GUITextField(new UDim2(0, 0, 0, 20), new UDim2(1, -40, 0, 20), Environment.CurrentDirectory, TextAlign.Left, theme);
            dirField.Label.Font = smallFont;

            GUIButton goToDirBtn = new GUIButton(new UDim2(1, -40, 0, 20), new UDim2(0, 40, 0, 20), "Go", theme);

            goToDirBtn.OnMouseClick += (btn, mbtn) =>
            {
                ScanDir();
            };

            GUILabel fileNameLabel = new GUILabel(new UDim2(0, 0, 1, -40), new UDim2(1, -200, 0, 20), "File Name:", TextAlign.Left, theme);

            selectedFileLabel            = new GUITextField(new UDim2(0, 0, 1, -20), new UDim2(1, -200, 0, 20), "", TextAlign.Left, theme);
            selectedFileLabel.Label.Font = smallFont;
            GUIButton doneBtn = new GUIButton(new UDim2(1, -100, 1, -40), new UDim2(0, 100, 0, 40),
                                              mode == FileBrowserMode.OpenFile ? "Open" : "Save", TextAlign.Center, theme);

            doneBtn.OnMouseClick += (btn, mbtn) => { callback(this); Visible = false; };
            GUIButton cancelBtn = new GUIButton(new UDim2(1, -200, 1, -40), new UDim2(0, 100, 0, 40), "Cancel", TextAlign.Center, theme);

            cancelBtn.OnMouseClick += (btn, mbtn) => { Visible = false; };

            AddTopLevel(dirField, goToDirBtn, fileNameLabel, selectedFileLabel, doneBtn, cancelBtn);
            ScanDir();
        }
Example #2
0
        public GUICheckbox(UDim2 position, UDim2 size, string checkedText,
                           BMPFont font, Color textColor,
                           Image normalImg, Image hoverImg, Image activeImg)
        {
            Position = position;
            Size     = size;

            CapturesMouseClicks = true;
            Label = new GUILabel(UDim2.Zero, new UDim2(1f, 0, 1f, 0), checkedText, TextAlign.Center, font, textColor)
            {
                Parent = this, Visible = false
            };

            NormalImage = normalImg;
            HoverImage  = hoverImg;
            ActiveImage = activeImg;
        }
        GUITextField AddEditField(GUIFrame textFieldFrame, BMPFont font, string text, int y)
        {
            GUILabel lbl = new GUILabel(new UDim2(0, 0, 0.142f * y, 0), new UDim2(1f, 0, 0.142f, 0),
                                        text + ":", TextAlign.Left, Theme)
            {
                Parent = textFieldFrame, Font = font
            };
            GUITextField field = new GUITextField(new UDim2(0, 20, 0.142f * y, 4), new UDim2(1f, -20, 0.142f, -8),
                                                  "0", TextAlign.Center, Theme)
            {
                Parent = textFieldFrame
            };

            field.Label.Font = font;

            return(field);
        }
        public GUIButton(UDim2 position, UDim2 size, string text, TextAlign textAlign,
                         BMPFont font, Color textColor,
                         Image normalImg, Image hoverImg, Image activeImg, Image toggledImage)
        {
            Position = position;
            Size     = size;

            CapturesMouseClicks = true;
            Label = new GUILabel(UDim2.Zero, new UDim2(1f, 0, 1f, 0), text, textAlign, font, textColor)
            {
                Parent = this
            };

            NormalImage  = normalImg;
            HoverImage   = hoverImg;
            ActiveImage  = activeImg;
            ToggledImage = toggledImage;
        }
Example #5
0
        public GUILabel(UDim2 position, UDim2 size, string text, TextAlign textAlign,
                        BMPFont font, Color textColor, Color?shadowColor = null)
        {
            if (text == null)
            {
                throw new ArgumentNullException("text", "GUILabel expected string text, got null");
            }
            if (font == null)
            {
                throw new ArgumentNullException("font", "GUILabel requires a non-null font!");
            }

            Position        = position;
            Size            = size;
            Text            = text;
            TextAlign       = textAlign;
            Font            = font;
            TextColor       = textColor;
            TextShadowColor = shadowColor;
        }
 public GUITextField(UDim2 position, UDim2 size, string text, TextAlign textAlign,
                     BMPFont font, Color textColor,
                     Image normalImg, Image hoverImg, Image activeImg, Image toggledImg)
     : base(position, size, text, textAlign, font, textColor, normalImg, hoverImg, activeImg, toggledImg)
 {
 }
        public GUIColorPicker(UDim2 position, UDim2 size, GUITheme theme)
            : base(theme)
        {
            // Generate static textures if necessary
            GenerateHuePalette();
            GenerateAlphaTextures();

            // Generate dynamic palette
            hsvPalette = new Texture();
            hsvPalette.Bind();

            hsvPalette.SetMinMag(TextureMinFilter.Linear, TextureMagFilter.Linear);
            hsvPalette.SetWrapMode(TextureWrapMode.ClampToEdge, TextureWrapMode.ClampToEdge);

            // Pre-allocate some room
            hsvPalette.SetData(25, 100, PixelType.UnsignedByte, PixelFormat.Rgba, IntPtr.Zero);

            hsvPalette.Unbind();

            // Set properties
            Position = position;
            Size     = size;

            // Build layout
            // Left layout
            GUIFrame pickerFrame = new GUIFrame(UDim2.Zero, new UDim2(1f, -90, 1f, 0),
                                                Image.CreateBlank(Color.Transparent))
            {
                Parent = this
            };

            hsvPicker = new GUIHSVPalette(this,
                                          UDim2.Zero, new UDim2(1f, -70, 1f, 0),
                                          new Image(hsvPalette))
            {
                Parent = pickerFrame
            };

            alphaSlider = new GUIAlphaSlider(this,
                                             new UDim2(1f, -60, 0, 0), new UDim2(0, 25, 1f, 0),
                                             new Image(checkersTex), new Image(alphaSliderTex))
            {
                Parent = pickerFrame
            };

            hueSlider = new GUIHueSlider(this,
                                         new UDim2(1f, -25, 0, 0), new UDim2(0, 25, 1f, 0),
                                         new Image(huePalette))
            {
                Parent = pickerFrame
            };

            // Right layout
            GUIFrame editFrame = new GUIFrame(new UDim2(1f, -80, 0, 0), new UDim2(0, 80, 1f, 0),
                                              Image.CreateBlank(Color.Transparent))
            {
                Parent = this
            };

            colorPreview = new GUIFrame(new UDim2(1f, -60, 0, 0), new UDim2(0, 60, 0, 60), Image.Blank)
            {
                Parent = editFrame
            };

            GUIFrame textFieldFrame = new GUIFrame(new UDim2(0, 0, 0, 70), new UDim2(1f, 0, 1f, -70),
                                                   Image.CreateBlank(Color.Transparent))
            {
                Parent = editFrame
            };

            BMPFont smallFont = theme.GetField <BMPFont>(null, "SmallFont");

            hueTextField        = AddEditField(textFieldFrame, smallFont, "H", 0);
            saturationTextField = AddEditField(textFieldFrame, smallFont, "S", 1);
            valueTextField      = AddEditField(textFieldFrame, smallFont, "V", 2);
            redTextField        = AddEditField(textFieldFrame, smallFont, "R", 3);
            greenTextField      = AddEditField(textFieldFrame, smallFont, "G", 4);
            blueTextField       = AddEditField(textFieldFrame, smallFont, "B", 5);
            alphaTextField      = AddEditField(textFieldFrame, smallFont, "A", 6);

            alphaLabel = (GUILabel)textFieldFrame.Children[textFieldFrame.Children.Count - 2];

            #region OnTextChanged Event Handlers
            hueTextField.OnTextChanged += (field, text) =>
            {
                float hue;
                if (float.TryParse(text, out hue))
                {
                    hueSlider.SetHue(hue);
                }

                UpdateColor();
            };

            saturationTextField.OnTextChanged += (field, text) =>
            {
                float sat;
                if (float.TryParse(text, out sat))
                {
                    hsvPicker.SetSV(sat, hsvPicker.Value * 100);
                }

                UpdateColor();
            };

            valueTextField.OnTextChanged += (field, text) =>
            {
                float val;
                if (float.TryParse(text, out val))
                {
                    hsvPicker.SetSV(hsvPicker.Saturation * 100, val);
                }

                UpdateColor();
            };

            redTextField.OnTextChanged += (field, text) =>
            {
                float r;
                if (float.TryParse(text, out r))
                {
                    float h, s, v;
                    Maths.RGBToHSV((byte)MathHelper.Clamp(r, 0, 255), Color.G, Color.B, out h, out s, out v);
                    hueSlider.SetHue(h);
                    hsvPicker.SetSV(s * 100, v * 100);
                }

                SetHue(hueSlider.Hue);
                UpdateColor();
            };

            greenTextField.OnTextChanged += (field, text) =>
            {
                float g;
                if (float.TryParse(text, out g))
                {
                    float h, s, v;
                    Maths.RGBToHSV(Color.R, (byte)MathHelper.Clamp(g, 0, 255), Color.B, out h, out s, out v);
                    hueSlider.SetHue(h);
                    hsvPicker.SetSV(s * 100, v * 100);
                }

                SetHue(hueSlider.Hue);
                UpdateColor();
            };

            blueTextField.OnTextChanged += (field, text) =>
            {
                float b;
                if (float.TryParse(text, out b))
                {
                    float h, s, v;
                    Maths.RGBToHSV(Color.R, Color.G, (byte)MathHelper.Clamp(b, 0, 255), out h, out s, out v);
                    hueSlider.SetHue(h);
                    hsvPicker.SetSV(s * 100, v * 100);
                }

                SetHue(hueSlider.Hue);
                UpdateColor();
            };

            alphaTextField.OnTextChanged += (field, text) =>
            {
                float alpha;
                if (float.TryParse(text, out alpha))
                {
                    alphaSlider.SetAlpha((int)alpha);
                }

                UpdateColor();
            };
            #endregion

            // Setup defaults
            SetHue(0);
            UpdateColor();
        }