Exemplo n.º 1
0
		public WidgetFocus ()
		{
			var text = new TextEntry ();
			var check = new CheckBox ("CheckBox");
			var slider = new HSlider ();
			ListStore store = new ListStore (value);
			var list = new ListView (store);
			list.Columns.Add ("Value", value);
			list.HeadersVisible = false;
			for (int n=0; n<10; n++) {
				var r = store.AddRow ();
				store.SetValue (r, value, "Value " + n);
			}

			var btn1 = new Button ("TextEnty");
			var btn2 = new Button ("Checkbox");
			var btn3 = new Button ("Slider");
			var btn4 = new Button ("ListBox");
			var btn5 = new Button ("Button");

			btn1.Clicked += (sender, e) => text.SetFocus ();
			btn2.Clicked += (sender, e) => check.SetFocus ();
			btn3.Clicked += (sender, e) => slider.SetFocus ();
			btn4.Clicked += (sender, e) => list.SetFocus ();
			btn5.Clicked += (sender, e) => btn1.SetFocus ();

			var btnBox = new HBox ();
			btnBox.PackStart (btn1);
			btnBox.PackStart (btn2);
			btnBox.PackStart (btn3);
			btnBox.PackStart (btn4);
			btnBox.PackStart (btn5);

			var focusBox = new HBox ();
			var vbox = new VBox ();
			vbox.PackStart (text);
			vbox.PackStart (check);
			vbox.PackStart (slider);
			focusBox.PackStart (vbox);
			focusBox.PackStart (list, true);

			PackStart (btnBox);
			PackStart (focusBox, true);
		}
Exemplo n.º 2
0
		public DefaultColorSelectorBackend ()
		{
			HBox box = new HBox ();
			Table selBox = new Table ();
			hsBox = new HueBox ();
			hsBox.Light = 0.5;
			lightBox = new LightBox ();
			hsBox.SelectionChanged += delegate {
				lightBox.Hue = hsBox.SelectedColor.Hue;
				lightBox.Saturation = hsBox.SelectedColor.Saturation;
			};
			
			colorBox = new ColorSelectionBox () { MinHeight = 20 };
			
			selBox.Add (hsBox, 0, 0);
			selBox.Add (lightBox, 1, 0);
			
			box.PackStart (selBox);
			
			const int entryWidth = 40;
			VBox entryBox = new VBox ();
			Table entryTable = new Table ();
			
			entryTable.Add (new Label ("Color:"), 0, 0);
			entryTable.Add (colorBox, 1, 0, colspan:4);
			entryTable.Add (new HSeparator (), 0, 1, colspan:5);
			
			int r = 2;
			entryTable.Add (new Label ("Hue:"), 0, r);
			entryTable.Add (hueEntry = new SpinButton () { 
				MinWidth = entryWidth, MinimumValue = 0, MaximumValue = 360, Digits = 0, IncrementValue = 1 }, 1, r++);
			
			entryTable.Add (new Label ("Saturation:"), 0, r);
			entryTable.Add (satEntry = new SpinButton () { 
				MinWidth = entryWidth, MinimumValue = 0, MaximumValue = 100, Digits = 0, IncrementValue = 1 }, 1, r++);
			
			entryTable.Add (new Label ("Light:"), 0, r);
			entryTable.Add (lightEntry = new SpinButton () { 
				MinWidth = entryWidth, MinimumValue = 0, MaximumValue = 100, Digits = 0, IncrementValue = 1 }, 1, r++);
			
			r = 2;
			entryTable.Add (new Label ("Red:"), 3, r);
			entryTable.Add (redEntry = new SpinButton () { 
				MinWidth = entryWidth, MinimumValue = 0, MaximumValue = 255, Digits = 0, IncrementValue = 1 }, 4, r++);
			
			entryTable.Add (new Label ("Green:"), 3, r);
			entryTable.Add (greenEntry = new SpinButton () { 
				MinWidth = entryWidth, MinimumValue = 0, MaximumValue = 255, Digits = 0, IncrementValue = 1 }, 4, r++);
			
			entryTable.Add (new Label ("Blue:"), 3, r);
			entryTable.Add (blueEntry = new SpinButton () { 
				MinWidth = entryWidth, MinimumValue = 0, MaximumValue = 255, Digits = 0, IncrementValue = 1 }, 4, r++);
			
			Label label;
			entryTable.Add (alphaSeparator = new HSeparator (), 0, r++, colspan:5);
			entryTable.Add (label = new Label ("Opacity:"), 0, r);
			entryTable.Add (alphaSlider = new HSlider () {
				MinimumValue = 0, MaximumValue = 255,  }, 1, r, colspan: 3);
			entryTable.Add (alphaEntry = new SpinButton () { 
				MinWidth = entryWidth, MinimumValue = 0, MaximumValue = 255, Digits = 0, IncrementValue = 1 }, 4, r);
			
			alphaControls.Add (alphaSeparator);
			alphaControls.Add (label);
			alphaControls.Add (alphaEntry);
			
			entryBox.PackStart (entryTable);
			box.PackStart (entryBox);
			Content = box;
			
			hsBox.SelectionChanged += delegate {
				HandleColorBoxSelectionChanged ();
			};
			lightBox.SelectionChanged += delegate {
				HandleColorBoxSelectionChanged ();
			};
			
			hueEntry.ValueChanged += HandleHslChanged;
			satEntry.ValueChanged += HandleHslChanged;
			lightEntry.ValueChanged += HandleHslChanged;
			redEntry.ValueChanged += HandleRgbChanged;
			greenEntry.ValueChanged += HandleRgbChanged;
			blueEntry.ValueChanged += HandleRgbChanged;
			alphaEntry.ValueChanged += HandleAlphaChanged;
			alphaSlider.ValueChanged += HandleAlphaChanged;
			
			Color = Colors.White;
		}
Exemplo n.º 3
0
		public HorizontalSliderSample ()
		{
			var sl1 = new HSlider {
				MinimumValue = 0,
				MaximumValue = 2,
				StepIncrement = 0.05,
				SnapToTicks = true,
			};

			var lbl1 = new Label (sl1.Value.ToString ("F2"));

			sl1.ValueChanged += (sender, e) => {
				lbl1.Text = (sl1.Value).ToString ("F2");
			};

			var sl2 = new HSlider { 
				MinimumValue = -9, 
				MaximumValue = 0,
				StepIncrement = 2,
				SnapToTicks = true,
			};

			var lbl2 = new Label (sl2.Value.ToString ("F2"));

			sl2.ValueChanged += (sender, e) => {
				lbl2.Text = (sl2.Value).ToString ("F2");
			};

			var sl21 = new HSlider { 
				MinimumValue = 0, 
				MaximumValue = 9,
				StepIncrement = 2,
				SnapToTicks = true,
			};

			var lbl21 = new Label (sl21.Value.ToString ("F2"));

			sl21.ValueChanged += (sender, e) => {
				lbl21.Text = (sl21.Value).ToString ("F2");
			};

			var sl22 = new HSlider { 
				MinimumValue = -9, 
				MaximumValue = 9,
				StepIncrement = 2,
				SnapToTicks = true,
			};

			var lbl22 = new Label (sl22.Value.ToString ("F2"));

			sl22.ValueChanged += (sender, e) => {
				lbl22.Text = (sl22.Value).ToString ("F2");
			};


			var sl23 = new HSlider { 
				MinimumValue = -9, 
				MaximumValue = 9,
				StepIncrement = 1,
				SnapToTicks = true,
			};

			var lbl23 = new Label (sl23.Value.ToString ("F2"));

			sl23.ValueChanged += (sender, e) => {
				lbl23.Text = (sl23.Value).ToString ("F2");
			};

			var sl3 = new HSlider { 
				MinimumValue = -9, 
				MaximumValue = 9,
				StepIncrement = 2,
				SnapToTicks = false,
			};

			var lbl3 = new Label (sl3.Value.ToString ("F2"));

			sl3.ValueChanged += (sender, e) => {
				lbl3.Text = (sl2.Value = sl21.Value = sl22.Value = sl23.Value = sl3.Value).ToString ("F2");
			};

			var sl4 = new HSlider {
				MinimumValue = -1,
				MaximumValue = 1,
				StepIncrement = 0.05
			};

			var lbl4 = new Label (sl4.Value.ToString ("F"));
			lbl4.ExpandHorizontal = false;

			var sl4box = new VBox ();
			sl4box.PackStart (lbl4, false, hpos: WidgetPlacement.Start);
			sl4box.PackStart (sl4);

			sl4.ValueChanged += (sender, e) => {

				var offset = Math.Abs (sl4.Value) % sl4.StepIncrement;
				if (Math.Abs (offset) > double.Epsilon) {
					if (offset > sl4.StepIncrement / 2) {
						if (sl4.Value >= 0)
							sl4.Value += -offset + sl4.StepIncrement;
						else
							sl4.Value += offset - sl4.StepIncrement;
					}
					else
						if (sl4.Value >= 0)
							sl4.Value -= offset;
						else
							sl4.Value += offset;
				}

				lbl4.MarginLeft = sl4.SliderPosition - (lbl4.Size.Width / 2);
				if (lbl4.MarginLeft + lbl4.Size.Width > sl4.Size.Width)
					lbl4.MarginLeft = sl4.Size.Width - lbl4.Size.Width;
				if (lbl4.MarginLeft < 0)
					lbl4.MarginLeft = 0;

				lbl4.Text = (sl4.Value).ToString ("F2");
			};
			sl4.Value = sl4.MinimumValue;


			var sl4Labels = new HBox ();
			sl4Labels.PackStart (new Label ("-1"), true);
			sl4Labels.PackStart (new Label ("0") { TextAlignment = Alignment.Center }, true);
			sl4Labels.PackStart (new Label ("1") { TextAlignment = Alignment.End }, true);
			sl4box.PackStart (sl4Labels);

			Add (sl1, 0, 0, hexpand: true);
			Add (lbl1, 1, 0);
			Add (sl2, 0, 1, hexpand: true);
			Add (lbl2, 1, 1);
			Add (sl21, 0, 2, hexpand: true);
			Add (lbl21, 1, 2);
			Add (sl22, 0, 3, hexpand: true);
			Add (lbl22, 1, 3);
			Add (sl23, 0, 4, hexpand: true);
			Add (lbl23, 1, 4);
			Add (sl3, 0, 5, hexpand: true);
			Add (lbl3, 1, 5);
			Add (sl4box, 0, 6, hexpand: true);


		}
Exemplo n.º 4
0
        public DefaultColorSelectorBackend()
        {
            HBox  box    = new HBox();
            Table selBox = new Table();

            hsBox                   = new HueBox();
            hsBox.Light             = 0.5;
            lightBox                = new LightBox();
            hsBox.SelectionChanged += delegate {
                lightBox.Hue        = hsBox.SelectedColor.Hue;
                lightBox.Saturation = hsBox.SelectedColor.Saturation;
            };

            colorBox = new ColorSelectionBox()
            {
                MinHeight = 20
            };

            selBox.Add(hsBox, 0, 0);
            selBox.Add(lightBox, 1, 0);

            box.PackStart(selBox);

            const int entryWidth = 40;
            VBox      entryBox   = new VBox();
            Table     entryTable = new Table();

            entryTable.Add(new Label("Color:"), 0, 0);
            entryTable.Add(colorBox, 1, 0, colspan: 4);
            entryTable.Add(new HSeparator(), 0, 1, colspan: 5);

            int r = 2;

            entryTable.Add(new Label("Hue:"), 0, r);
            entryTable.Add(hueEntry = new SpinButton()
            {
                MinWidth = entryWidth, MinimumValue = 0, MaximumValue = 360, Digits = 0, IncrementValue = 1
            }, 1, r++);

            entryTable.Add(new Label("Saturation:"), 0, r);
            entryTable.Add(satEntry = new SpinButton()
            {
                MinWidth = entryWidth, MinimumValue = 0, MaximumValue = 100, Digits = 0, IncrementValue = 1
            }, 1, r++);

            entryTable.Add(new Label("Light:"), 0, r);
            entryTable.Add(lightEntry = new SpinButton()
            {
                MinWidth = entryWidth, MinimumValue = 0, MaximumValue = 100, Digits = 0, IncrementValue = 1
            }, 1, r++);

            r = 2;
            entryTable.Add(new Label("Red:"), 3, r);
            entryTable.Add(redEntry = new SpinButton()
            {
                MinWidth = entryWidth, MinimumValue = 0, MaximumValue = 255, Digits = 0, IncrementValue = 1
            }, 4, r++);

            entryTable.Add(new Label("Green:"), 3, r);
            entryTable.Add(greenEntry = new SpinButton()
            {
                MinWidth = entryWidth, MinimumValue = 0, MaximumValue = 255, Digits = 0, IncrementValue = 1
            }, 4, r++);

            entryTable.Add(new Label("Blue:"), 3, r);
            entryTable.Add(blueEntry = new SpinButton()
            {
                MinWidth = entryWidth, MinimumValue = 0, MaximumValue = 255, Digits = 0, IncrementValue = 1
            }, 4, r++);

            Label label;

            entryTable.Add(alphaSeparator = new HSeparator(), 0, r++, colspan: 5);
            entryTable.Add(label          = new Label("Opacity:"), 0, r);
            entryTable.Add(alphaSlider    = new HSlider()
            {
                MinimumValue = 0, MaximumValue = 255,
            }, 1, r, colspan: 3);
            entryTable.Add(alphaEntry = new SpinButton()
            {
                MinWidth = entryWidth, MinimumValue = 0, MaximumValue = 255, Digits = 0, IncrementValue = 1
            }, 4, r);

            alphaControls.Add(alphaSeparator);
            alphaControls.Add(label);
            alphaControls.Add(alphaEntry);

            entryBox.PackStart(entryTable);
            box.PackStart(entryBox);
            Content = box;

            hsBox.SelectionChanged += delegate {
                HandleColorBoxSelectionChanged();
            };
            lightBox.SelectionChanged += delegate {
                HandleColorBoxSelectionChanged();
            };

            hueEntry.ValueChanged    += HandleHslChanged;
            satEntry.ValueChanged    += HandleHslChanged;
            lightEntry.ValueChanged  += HandleHslChanged;
            redEntry.ValueChanged    += HandleRgbChanged;
            greenEntry.ValueChanged  += HandleRgbChanged;
            blueEntry.ValueChanged   += HandleRgbChanged;
            alphaEntry.ValueChanged  += HandleAlphaChanged;
            alphaSlider.ValueChanged += HandleAlphaChanged;

            Color = Colors.White;
        }
Exemplo n.º 5
0
        public ColorPopover(ColorPicker picker)
        {
            this.picker = picker;

            OriginalColor = picker.Color;

            var h = new HBox();
            var leftBox = new VBox();
            h.PackStart(leftBox);

            Content = h;

            {
                HBox box = new HBox();
                box.PackStart(new Label("R") { WidthRequest = 50 });
                box.PackStart(rSlider = new HSlider() { WidthRequest = 100, MinimumValue = 0, MaximumValue = 255 });
                box.PackStart(rText = new TextEntry() { WidthRequest = 50 });
                leftBox.PackStart(box);
            }
            {
                HBox box = new HBox();
                box.PackStart(new Label("G") { WidthRequest = 50 });
                box.PackStart(gSlider = new HSlider() { WidthRequest = 100, MinimumValue = 0, MaximumValue = 255 });
                box.PackStart(gText = new TextEntry() { WidthRequest = 50 });
                leftBox.PackStart(box);
            }
            {
                HBox box = new HBox();
                box.PackStart(new Label("B") { WidthRequest = 50 });
                box.PackStart(bSlider = new HSlider() { WidthRequest = 100, MinimumValue = 0, MaximumValue = 255 });
                box.PackStart(bText = new TextEntry() { WidthRequest = 50 });
                leftBox.PackStart(box);
            }
            {
                HBox box = new HBox();
                box.PackStart(new Label("Alpha") { WidthRequest = 50 });
                box.PackStart(aSlider = new HSlider() { WidthRequest = 100, MinimumValue = 0, MaximumValue = 255 });
                box.PackStart(aText = new TextEntry() { WidthRequest = 50 });
                leftBox.PackStart(box);
            }

            EventHandler setSlider = (s, e) => { if (enableEvents) SetColor(Color.FromBytes((byte)rSlider.Value, (byte)gSlider.Value, (byte)bSlider.Value, (byte)aSlider.Value), (Widget)s); };

            rSlider.ValueChanged += setSlider;
            gSlider.ValueChanged += setSlider;
            bSlider.ValueChanged += setSlider;
            aSlider.ValueChanged += setSlider;

            rText.Changed += (s, e) => { if (enableEvents) { byte i; if (byte.TryParse(rText.Text, out i)) SetColor(Color.FromBytes(i, (byte)gSlider.Value, (byte)bSlider.Value, (byte)aSlider.Value), rText); } };
            gText.Changed += (s, e) => { if (enableEvents) { byte i; if (byte.TryParse(gText.Text, out i)) SetColor(Color.FromBytes((byte)rSlider.Value, i, (byte)bSlider.Value, (byte)aSlider.Value), gText); } };
            bText.Changed += (s, e) => { if (enableEvents) { byte i; if (byte.TryParse(bText.Text, out i)) SetColor(Color.FromBytes((byte)rSlider.Value, (byte)gSlider.Value, i, (byte)aSlider.Value), bText); } };
            aText.Changed += (s, e) => { if (enableEvents) { byte i; if (byte.TryParse(aText.Text, out i)) SetColor(Color.FromBytes((byte)rSlider.Value, (byte)gSlider.Value, (byte)bSlider.Value, i), aText); } };

            {
                HBox box = new HBox();
                TextEntry text;
                hexText = text = new TextEntry();
                text.Changed += (s, e) =>
                {
                    if (enableEvents)
                    {
                        Color c;
                        if (App.TryParseColor(hexText.Text, out c))
                            SetColor(c, hexText);
                    }
                };
                box.PackStart(text);

                sourceText = text = new TextEntry();
                text.Changed += (s, e) =>
                {
                    if (enableEvents)
                    {
                        Color c;
                        if (App.TryParseColor(sourceText.Text, out c))
                            SetColor(c, sourceText);
                    }
                };
                box.PackStart(text);
                leftBox.PackStart(box);
            }

            {
                HBox box = new HBox();
                Button btn;
                btn = new Button(" Reset to Default ");
                btn.Clicked += (s, e) => { picker.Color = picker.DefaultColor; };
                box.PackEnd(btn);

                btn = new Button(" Discard Changes ");
                btn.Clicked += (s, e) => { picker.Color = OriginalColor; };
                box.PackEnd(btn);
                leftBox.PackStart(box);
            }
        }
Exemplo n.º 6
0
        public DefaultColorSelectorBackend()
        {
            HBox  box    = new HBox();
            Table selBox = new Table();

            hsBox                   = new HueBox();
            hsBox.Light             = 0.5;
            lightBox                = new LightBox();
            hsBox.SelectionChanged += delegate {
                lightBox.Hue        = hsBox.SelectedColor.Hue;
                lightBox.Saturation = hsBox.SelectedColor.Saturation;
            };

            colorBox = new ColorSelectionBox()
            {
                MinHeight = 20
            };

            selBox.Add(hsBox, 0, 0);
            selBox.Add(lightBox, 1, 0);

            box.PackStart(selBox);

            const int entryWidth = 40;
            VBox      entryBox   = new VBox();
            Table     entryTable = new Table();

            entryTable.Add(CreateLabel(Application.TranslationCatalog.GetString("Color:")), 0, 0);
            entryTable.Add(colorBox, 1, 0, colspan: 4);
            entryTable.Add(new HSeparator(), 0, 1, colspan: 5);

            int r        = 2;
            var hueLabel = CreateLabel();

            entryTable.Add(hueLabel, 0, r);
            entryTable.Add(hueEntry = new SpinButton()
            {
                MinWidth = entryWidth, MinimumValue = 0, MaximumValue = 360, Digits = 0, IncrementValue = 1
            }, 1, r++);
            SetupEntry(hueEntry, hueLabel, Application.TranslationCatalog.GetString("Hue"));

            var satLabel = CreateLabel();

            entryTable.Add(satLabel, 0, r);
            entryTable.Add(satEntry = new SpinButton()
            {
                MinWidth = entryWidth, MinimumValue = 0, MaximumValue = 100, Digits = 0, IncrementValue = 1
            }, 1, r++);
            SetupEntry(satEntry, satLabel, Application.TranslationCatalog.GetString("Saturation"));

            var lightLabel = CreateLabel();

            entryTable.Add(lightLabel, 0, r);
            entryTable.Add(lightEntry = new SpinButton()
            {
                MinWidth = entryWidth, MinimumValue = 0, MaximumValue = 100, Digits = 0, IncrementValue = 1
            }, 1, r++);
            SetupEntry(lightEntry, lightLabel, Application.TranslationCatalog.GetString("Light"));

            r = 2;
            var redLabel = CreateLabel();

            entryTable.Add(redLabel, 3, r);
            entryTable.Add(redEntry = new SpinButton()
            {
                MinWidth = entryWidth, MinimumValue = 0, MaximumValue = 255, Digits = 0, IncrementValue = 1
            }, 4, r++);
            SetupEntry(redEntry, redLabel, Application.TranslationCatalog.GetString("Red"));

            var greenLabel = CreateLabel();

            entryTable.Add(greenLabel, 3, r);
            entryTable.Add(greenEntry = new SpinButton()
            {
                MinWidth = entryWidth, MinimumValue = 0, MaximumValue = 255, Digits = 0, IncrementValue = 1
            }, 4, r++);
            SetupEntry(greenEntry, greenLabel, Application.TranslationCatalog.GetString("Green"));

            var blueLabel = CreateLabel();

            entryTable.Add(blueLabel, 3, r);
            entryTable.Add(blueEntry = new SpinButton()
            {
                MinWidth = entryWidth, MinimumValue = 0, MaximumValue = 255, Digits = 0, IncrementValue = 1
            }, 4, r++);
            SetupEntry(blueEntry, blueLabel, Application.TranslationCatalog.GetString("Blue"));

            entryTable.Add(alphaSeparator = new HSeparator(), 0, r++, colspan: 5);
            var alphaLabel = CreateLabel();

            entryTable.Add(alphaLabel, 0, r);
            entryTable.Add(alphaSlider = new HSlider()
            {
                MinimumValue = 0, MaximumValue = 255,
            }, 1, r, colspan: 3);
            entryTable.Add(alphaEntry = new SpinButton()
            {
                MinWidth = entryWidth, MinimumValue = 0, MaximumValue = 255, Digits = 0, IncrementValue = 1
            }, 4, r);
            SetupEntry(alphaEntry, alphaLabel, Application.TranslationCatalog.GetString("Opacity"));

            // Don't allow the slider to get keyboard focus, as it doesn't really work with the keyboard and the opacity
            // spin button takes its place
            alphaSlider.CanGetFocus      = false;
            alphaSlider.Accessible.Label = Application.TranslationCatalog.GetString("Opacity");

            alphaControls.Add(alphaSeparator);
            alphaControls.Add(alphaLabel);
            alphaControls.Add(alphaEntry);

            entryBox.PackStart(entryTable);
            box.PackStart(entryBox);
            Content = box;

            hsBox.SelectionChanged    += HandleColorBoxSelectionChanged;
            lightBox.SelectionChanged += HandleColorBoxSelectionChanged;

            hueEntry.ValueChanged    += HandleHslChanged;
            satEntry.ValueChanged    += HandleHslChanged;
            lightEntry.ValueChanged  += HandleHslChanged;
            redEntry.ValueChanged    += HandleRgbChanged;
            greenEntry.ValueChanged  += HandleRgbChanged;
            blueEntry.ValueChanged   += HandleRgbChanged;
            alphaEntry.ValueChanged  += HandleAlphaChanged;
            alphaSlider.ValueChanged += HandleAlphaChanged;

            Color = Colors.White;
        }