Example #1
0
        public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, System.IServiceProvider provider, object value)
        {
            if (provider == null)
            {
                return(value);
            }

            IWindowsFormsEditorService edSvc = provider.GetService(typeof(IWindowsFormsEditorService)) as IWindowsFormsEditorService;

            if (edSvc == null)
            {
                return(value);
            }

            MultilineTextBox textBox = new MultilineTextBox();

            textBox.BorderStyle = BorderStyle.None;
            textBox.Size        = new System.Drawing.Size(150, 80);
            textBox.Text        = value == null ? string.Empty : value.ToString();

            edSvc.DropDownControl(textBox);

            if (!textBox.Cancelled)
            {
                value = textBox.Text;
            }

            textBox.Dispose();

            return(value);
        }
        protected override void TestFixtureSetUp()
        {
            recorderApplication = Application.Attach(Process.Start("Recorder.exe"));
            dashboard           = recorderApplication.GetWindow("DashBoard", InitializeOption.NoCache);
            ListBox desktopApplications = dashboard.Get <ListBox>("applications");

            ListItem selectedApplication = desktopApplications.SelectedItem;

            if (selectedApplication.Text.Equals(application.Name))
            {
                selectedApplication.DoubleClick();
            }
            else
            {
                desktopApplications.Select(application.Name);
            }

            string text = dashboard.Get <ListBox>("windows").SelectedItemText;

            Assert.AreEqual("Form1", text);

            dashboard.Get <RadioButton>("core").Click();
            dashboard.Get <Button>("record").Click();
            editor = dashboard.Get <MultilineTextBox>("codeEditor");
        }
Example #3
0
        /// <summary>
        /// Called when graphics resources need to be loaded.
        ///
        /// Use this for the usage of :
        /// - creation of the internal embedded controls.
        /// - setting of the variables and resources in this control
        /// - to load any game-specific graphics resources
        /// - take over the config width and height and use it into State
        /// - overriding how this item looks like , by settings its texture or theme
        ///
        /// Call base.LoadContent before you do your override code, this will cause :
        /// - State.SourceRectangle to be reset to the Config.Size
        /// </summary>
        public override void LoadContent()
        {
            // do the basic stuff
            base.LoadContent();

            // update state by using config
            this.UpdateDrawPositionByConfigAndParent();
            this.UpdateDrawSizeByConfig();
            this.UpdateDrawSourceRectangleByConfig();

            // create the text to show
            this.textBox = new MultilineTextBox(this.Name + "-Text")
            {
                Config =
                {
                    Width     = this.Config.Width,
                    Height    = this.Config.Height,
                    PositionX =                  0,
                    PositionY = 0
                },
                ConfigFont = "Fonts\\LucidaConsole"
            };
            this.AddControl(this.textBox);

            // create the background
            this.CurrentTextureName = this.Manager.ImageCompositor.CreateRectangleTexture(
                this.Name + "-Background",
                (int)this.Config.Width,
                (int)this.Config.Height,
                1,
                Theme.ContainerFillColor,
                Theme.BorderColor);
        }
Example #4
0
            public TextPad(ControlBase parent)
                : base(parent)
            {
                StartPosition = StartPosition.CenterParent;
                Size          = new Size(400, 300);
                Padding       = new Padding(1, 0, 1, 1);
                Title         = "TextPad";

                DockLayout layout = new DockLayout(this);

                layout.Dock = Dock.Fill;

                MenuStrip menuStrip = new MenuStrip(layout);

                menuStrip.Dock = Dock.Top;
                MenuItem fileMenu = menuStrip.AddItem("File");

                fileMenu.Menu.AddItem("Open...", String.Empty, "Ctrl+O").SetAction((s, a) => OnOpen(s, a));
                fileMenu.Menu.AddItem("Save", String.Empty, "Ctrl+S").SetAction((s, a) => OnSave(s, a));
                fileMenu.Menu.AddItem("Save As...").SetAction((s, a) => OnSaveAs(s, a));
                fileMenu.Menu.AddItem("Quit", String.Empty, "Ctrl+Q").SetAction((s, a) => Close());

                m_Font          = Skin.DefaultFont.Copy();
                m_Font.FaceName = "Courier New";

                StatusBar statusBar = new StatusBar(layout);

                statusBar.Dock = Dock.Bottom;

                Label length = new Label(statusBar);

                length.Margin = new Margin(5, 0, 5, 0);

                Label label = new Label(statusBar);

                label.Margin = new Margin(5, 0, 5, 0);
                label.Text   = "Length:";

                Label lines = new Label(statusBar);

                lines.Margin = new Margin(5, 0, 5, 0);

                label        = new Label(statusBar);
                label.Margin = new Margin(5, 0, 5, 0);
                label.Text   = "Lines:";

                m_TextBox      = new MultilineTextBox(layout);
                m_TextBox.Dock = Dock.Fill;
                m_TextBox.ShouldDrawBackground = false;
                m_TextBox.Font         = m_Font;
                m_TextBox.TextChanged += (sender, arguments) => { lines.Text = m_TextBox.TotalLines.ToString(); length.Text = m_TextBox.Text.Length.ToString(); };
                m_TextBox.Text         = "";

                m_Path = null;
            }
Example #5
0
        public override void LoadContent()
        {
            base.LoadContent();

            // label
            var y = (float)Theme.ControlLargeSpacing + Theme.ControlHeight;

            this.Label = new Label("MyLabel")
            {
                Config =
                {
                    PositionX = Theme.ControlLargeSpacing,
                    PositionY = y,
                },
                ConfigText = "Test label ff",
                ConfigHorizontalAlignment = HorizontalAlignment.Left,
                ConfigVerticalAlignment   = VerticalAlignment.Center
            };
            this.AddControl(this.Label);

            // text-box
            y            = y + this.Label.Config.Height + Theme.ControlSmallSpacing;
            this.TextBox = new TextBox("MyTextBox")
            {
                Config =
                {
                    PositionX = Theme.ControlLargeSpacing,
                    PositionY = y,
                },
                Text = "My text control",
            };
            this.AddControl(this.TextBox);

            // multi-line text-box
            y = y + this.TextBox.Config.Height + Theme.ControlSmallSpacing;
            var multilineTextBox = new MultilineTextBox("MyMultiLineTextBox")
            {
                Config =
                {
                    PositionX = Theme.ControlLargeSpacing,
                    PositionY = y,
                },
                ConfigText = "This is test text.\nTo see if this is working.\nIf you see this.\nAll is working.\n"
            };

            this.AddControl(multilineTextBox);

            Config.Width  = this.Label.Config.Width + (Theme.ControlLargeSpacing * 4);
            Config.Height = multilineTextBox.Config.PositionY + (multilineTextBox.Config.Height * 4) + Theme.ControlLargeSpacing;
        }
        internal static String GetAppendText(this MultilineTextBox textbox, String message, bool appendNewLine = true)
        {
            if (textbox.Text.Length == 0)
            {
                return(message);
            }
            var hasText               = !String.IsNullOrEmpty(textbox.Text);
            var prevText              = hasText ? textbox.Text : String.Empty;
            var lastString            = hasText ? prevText.Substring(prevText.Length - 1) : null;
            var prevTextEndsInSpace   = !hasText || lastString == null ? false : lastString.Equals(" ");
            var prevTextEndsInNewLine = !hasText ? false : lastString == null ? true : lastString == Environment.NewLine || lastString == "";
            var newText               = String.Format("{0}{1}", hasText ? String.Empty : appendNewLine ? Environment.NewLine : prevTextEndsInSpace ? "" : prevTextEndsInNewLine ? "" : " ", message);

            return(newText);
        }
Example #7
0
        public XsdWriting(ControlBase parent)
            : base(parent)
        {
            Control.Layout.GridLayout layout = new Control.Layout.GridLayout(this);
            layout.VerticalAlignment = VerticalAlignment.Top;
            layout.VerticalAlignment = VerticalAlignment.Stretch;

            layout.SetColumnWidths(Control.Layout.GridLayout.Fill);
            layout.SetRowHeights(30.0f, Control.Layout.GridLayout.Fill);

            Control.Button button1 = new Control.Button(layout);
            button1.Text                = "Write Xsd File ";
            button1.Clicked            += WriteXsd;
            button1.Width               = 100;
            button1.HorizontalAlignment = HorizontalAlignment.Left;
            xsdContent = new Control.MultilineTextBox(layout);
        }
Example #8
0
        public NotesPage(string name, string title, int x, int y, int width, int height, Texture2D tabTexture, Rectangle tabSourceRect, ITranslationHelper translation) :
            base(name, title, x, y, width, height, tabTexture, tabSourceRect, translation)
        {
            _textBox = new MultilineTextBox(
                new Rectangle(xPositionOnScreen + 30, yPositionOnScreen + 32, width - 60, height - 64),
                null,
                null,
                Game1.dialogueFont,
                Game1.textColor)
            {
                RawText = DeluxeJournalMod.Instance?.GetNotes() ?? ""
            };

            gamepadCursorArea = new ClickableComponent(new Rectangle(_textBox.Bounds.Right - 16, _textBox.Bounds.Bottom - 16, 16, 16), "")
            {
                myID           = 0,
                leftNeighborID = CUSTOM_SNAP_BEHAVIOR,
                fullyImmutable = true
            };
        }
Example #9
0
        public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, System.IServiceProvider provider, object value)
        {
            if (provider == null)
                return value;

            IWindowsFormsEditorService edSvc = provider.GetService( typeof(IWindowsFormsEditorService) ) as IWindowsFormsEditorService;

            if (edSvc == null)
                return value;

            MultilineTextBox textBox = new MultilineTextBox();
            textBox.BorderStyle = BorderStyle.None;
            textBox.Size = new System.Drawing.Size(150,80);
            textBox.Text = value == null ? string.Empty : value.ToString();

            edSvc.DropDownControl(textBox);

            if (!textBox.Cancelled)
                value = textBox.Text;

            textBox.Dispose();

            return value;
        }
Example #10
0
        /// <summary>
        /// This is the Event handler for "CalculateBMIButton" that performs the calculations for both imperical measurements
        /// and metric measurements.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>

        private void CalculateBMIButton_Click(object sender, EventArgs e)
        {
            Weight = double.Parse(MyWeightTextBox.Text);
            Height = double.Parse(MyHeightTextBox.Text);

            if (MetricRadioButton.Checked == true)
            {
                Result = Weight / (Height * Height);
            }
            if (ImperialRadioButton.Checked == true)
            {
                Result = (Weight * 703) / (Height * Height);
            }

            MultilineTextBox.Multiline = true;
            MultilineTextBox.Clear();
            MultilineTextBox.Text += "BMI SCALE   || RESULT" + Environment.NewLine;
            MultilineTextBox.Text += "Underweight  || less than 18.5" + Environment.NewLine;
            MultilineTextBox.Text += "Normal           || between 18.5 and 24.9" + Environment.NewLine;
            MultilineTextBox.Text += "Overweight    || between 25 and 29.9" + Environment.NewLine;
            MultilineTextBox.Text += "Obese            || 30 or greater" + Environment.NewLine;

            ResultTextBox.Text = string.Format("{0}", Result);
        }
Example #11
0
        public void CreateComponents()
        {
            /***** Main Tab Control *****/
            tc_main = new TabControl(this);
            tc_main.SetPosition(15, 12);
            tc_main.SetSize(625, 389);

            /***** Call List Tab *****/
            // base container
            base_calls = new Base(this);
            base_calls.SetPosition(0, 0);
            base_calls.SetSize(617, 358);

            // calls listbox
            list_calls = new ListBox(base_calls);
            list_calls.SetPosition(0, 18);
            list_calls.SetSize(613, 333);

            // "Unit" label
            lbl_c_unit      = new Label(base_calls);
            lbl_c_unit.Text = "Unit";
            lbl_c_unit.SetPosition(3, 1);
            lbl_c_unit.SetSize(26, 13);

            // "Time" label
            lbl_c_time      = new Label(base_calls);
            lbl_c_time.Text = "Time";
            lbl_c_time.SetPosition(50, 1);
            lbl_c_time.SetSize(30, 13);

            // "Status" label
            lbl_c_status      = new Label(base_calls);
            lbl_c_status.Text = "Status";
            lbl_c_status.SetPosition(120, 1);
            lbl_c_status.SetSize(37, 13);

            // "Call" label
            lbl_c_call      = new Label(base_calls);
            lbl_c_call.Text = "Call";
            lbl_c_call.SetPosition(230, 1);
            lbl_c_call.SetSize(24, 13);

            /***** Active Call Tab *****/
            // base container
            base_active = new Base(this);
            base_active.SetPosition(0, 0);
            base_active.SetSize(617, 358);

            // "ID No." label
            lbl_a_id      = new Label(base_active);
            lbl_a_id.Text = "ID No.";
            lbl_a_id.SetPosition(26, 6);
            lbl_a_id.SetSize(38, 13);
            // "ID No." textbox
            out_id = new TextBox(base_active);
            out_id.SetPosition(70, 3);
            out_id.SetSize(306, 20);
            out_id.KeyboardInputEnabled = false;

            // "Time" label
            lbl_a_time      = new Label(base_active);
            lbl_a_time.Text = "Time";
            lbl_a_time.SetPosition(422, 7);
            lbl_a_time.SetSize(30, 13);
            // "Time" date textbox
            out_date = new TextBox(base_active);
            out_date.SetPosition(455, 3);
            out_date.SetSize(66, 20);
            out_date.KeyboardInputEnabled = false;
            // "Time" time textbox
            out_time = new TextBox(base_active);
            out_time.SetPosition(527, 3);
            out_time.SetSize(66, 20);
            out_time.KeyboardInputEnabled = false;

            // "Situation" label
            lbl_a_call      = new Label(base_active);
            lbl_a_call.Text = "Situation";
            lbl_a_call.SetPosition(17, 33);
            lbl_a_call.SetSize(48, 13);
            // "Situation" textbox
            out_call = new TextBox(base_active);
            out_call.SetPosition(70, 29);
            out_call.SetSize(523, 20);
            out_call.KeyboardInputEnabled = false;

            // "Location" label
            lbl_a_loc      = new Label(base_active);
            lbl_a_loc.Text = "Location";
            lbl_a_loc.SetPosition(18, 58);
            lbl_a_loc.SetSize(48, 13);
            // "Location" textbox
            out_loc = new TextBox(base_active);
            out_loc.SetPosition(70, 55);
            out_loc.SetSize(523, 20);
            out_loc.KeyboardInputEnabled = false;

            // "Status" label
            lbl_a_stat      = new Label(base_active);
            lbl_a_stat.Text = "Status";
            lbl_a_stat.SetPosition(27, 84);
            lbl_a_stat.SetSize(37, 13);
            // "Status" textbox
            out_stat = new TextBox(base_active);
            out_stat.SetPosition(70, 81);
            out_stat.SetSize(106, 20);
            out_stat.KeyboardInputEnabled = false;

            // "Unit" label
            lbl_a_unit      = new Label(base_active);
            lbl_a_unit.Text = "Unit";
            lbl_a_unit.SetPosition(258, 84);
            lbl_a_unit.SetSize(26, 13);
            // "Unit" textbox
            out_unit = new TextBox(base_active);
            out_unit.SetPosition(290, 81);
            out_unit.SetSize(86, 20);
            out_unit.KeyboardInputEnabled = false;

            // "Response" label
            lbl_a_resp      = new Label(base_active);
            lbl_a_resp.Text = "Response";
            lbl_a_resp.SetPosition(454, 84);
            lbl_a_resp.SetSize(55, 13);
            // "Response" textbox
            out_resp = new TextBox(base_active);
            out_resp.SetPosition(514, 81);
            out_resp.SetSize(79, 20);
            out_resp.KeyboardInputEnabled = false;

            // "Comments" label
            lbl_a_desc      = new Label(base_active);
            lbl_a_desc.Text = "Comments";
            lbl_a_desc.SetPosition(8, 113);
            lbl_a_desc.SetSize(56, 13);
            // "Comments" textbox
            out_desc = new MultilineTextBox(base_active);
            out_desc.SetPosition(70, 110);
            out_desc.SetSize(523, 103);
            out_desc.KeyboardInputEnabled = false;

            // "Persons" label
            lbl_a_peds      = new Label(base_active);
            lbl_a_peds.Text = "Persons";
            lbl_a_peds.SetPosition(19, 226);
            lbl_a_peds.SetSize(45, 13);
            // "Persons" textbox
            out_peds = new MultilineTextBox(base_active);
            out_peds.SetPosition(70, 226);
            out_peds.SetSize(523, 57);
            out_peds.KeyboardInputEnabled = false;

            // "Vehicles" label
            lbl_a_vehs      = new Label(base_active);
            lbl_a_vehs.Text = "Vehicles";
            lbl_a_vehs.SetPosition(19, 298);
            lbl_a_vehs.SetSize(47, 13);
            // "Vehicles" textbox
            out_vehs = new MultilineTextBox(base_active);
            out_vehs.SetPosition(70, 295);
            out_vehs.SetSize(523, 57);
            out_vehs.KeyboardInputEnabled = false;

            // Add tabs and their corresponding containers
            // Active Call tab is hidden when no callout is active
            if (Globals.ActiveCallout != null)
            {
                tc_main.AddPage("Active Call", base_active);
            }
            else
            {
                base_active.Hide();
            }
            tc_main.AddPage("Call List", base_calls);

            List <CalloutData> mActiveCalls = (from CalloutData x in Globals.CallQueue orderby x.TimeReceived descending select x).ToList();

            foreach (CalloutData x in mActiveCalls)
            {
                list_calls.AddRow(String.Format("{0}{1}{2}{3}", x.PrimaryUnit.PadRight(12), x.TimeReceived.ToLocalTime().ToString("HH:mm").PadRight(21), x.Status.ToFriendlyString().PadRight(31), x.Name.ToUpper()));
            }
        }
        public void ParseWidgets(IContainer ParentWidget, Dictionary <string, object> Data)
        {
            foreach (string name in Data.Keys)
            {
                if (!(Data[name] is JObject))
                {
                    throw new Exception($"Expected an Object, but got {Data[name].GetType().Name} in key '{name}' inside 'widgets'");
                }
                Dictionary <string, object> config = ((JObject)Data[name]).ToObject <Dictionary <string, object> >();
                if (!config.ContainsKey("type"))
                {
                    throw new Exception($"Widget definition must contain a 'type' key in widget '{name}'");
                }
                if (!(config["type"] is string))
                {
                    throw new Exception($"Widget type must be a string.");
                }
                Widget w    = null;
                string type = (string)config["type"];
                switch (type)
                {
                case "container":
                    w = new Container(ParentWidget);
                    break;

                case "label":
                    w = new DynamicLabel(ParentWidget);
                    break;

                case "numeric":
                    w = new NumericBox(ParentWidget);
                    break;

                case "textbox":
                    w = new TextBox(ParentWidget);
                    break;

                case "button":
                    w = new Button(ParentWidget);
                    break;

                case "dropdown":
                    w = new DropdownBox(ParentWidget);
                    break;

                case "checkbox":
                    w = new CheckBox(ParentWidget);
                    break;

                case "radiobox":
                    w = new RadioBox(ParentWidget);
                    break;

                case "switch_picker":
                    w = new GameSwitchBox(ParentWidget);
                    break;

                case "variable_picker":
                    w = new GameVariableBox(ParentWidget);
                    break;

                case "multitextbox":
                    w = new MultilineTextBox(ParentWidget);
                    break;

                case "multilabel":
                    w = new MultilineDynamicLabel(ParentWidget);
                    break;

                default:
                    throw new Exception($"Unknown widget type '{type}' in widget '{name}'");
                }
                if (WidgetLookup.ContainsKey(name))
                {
                    throw new Exception($"Two or more widgets with the same were found: '{name}'");
                }
                WidgetLookup.Add(name, w);
                int                X            = 0;
                int                Y            = 0;
                int                Width        = -1;
                int                Height       = -1;
                string             text         = null;
                int                wvalue       = 0;
                int?               min_value    = null;
                int?               max_value    = null;
                Font               font         = null;
                List <ListItem>    items        = null;
                int                idx          = -1;
                bool               enabled      = true;
                List <ClickAction> clickactions = new List <ClickAction>();
                foreach (string key in config.Keys)
                {
                    if (key == "type")
                    {
                        continue;
                    }
                    object value = config[key];
                    switch (key)
                    {
                    case "x":
                        EnsureType(typeof(long), value, "x");
                        X = Convert.ToInt32(value);
                        break;

                    case "y":
                        EnsureType(typeof(long), value, "y");
                        Y = Convert.ToInt32(value);
                        break;

                    case "width":
                        EnsureType(typeof(long), value, "width");
                        Width = Convert.ToInt32(value);
                        if (Width < 1)
                        {
                            throw new Exception($"Widget width ({Width}) must be greater than 0.");
                        }
                        break;

                    case "height":
                        EnsureType(typeof(long), value, "height");
                        Height = Convert.ToInt32(value);
                        if (Height < 1)
                        {
                            throw new Exception($"Widget height ({Height}) must be greater than 0.");
                        }
                        break;

                    case "font":
                        if (type != "label" && type != "textbox" && type != "button" && type != "dropdown" &&
                            type != "checkbox" && type != "radiobox" && type != "multitextbox" && type != "multilabel")
                        {
                            throw new Exception($"Widget type ({type}) can not contain a 'font' field.");
                        }
                        if (value is string)
                        {
                            if (!Fonts.ContainsKey((string)value))
                            {
                                throw new Exception($"Undefined font name '{(string) value}");
                            }
                            font = Fonts[(string)value];
                        }
                        else if (value is JObject)
                        {
                            font = ParseFont(((JObject)value).ToObject <Dictionary <string, object> >());
                        }
                        else
                        {
                            throw new Exception($"Expected a String or Object, but got {value.GetType().Name} in 'font'");
                        }
                        break;

                    case "value":
                        if (type != "numeric")
                        {
                            throw new Exception($"Widget type ({type}) can not contain a 'value' field.");
                        }
                        EnsureType(typeof(long), value, "value");
                        wvalue = Convert.ToInt32(value);
                        break;

                    case "min_value":
                        if (type != "numeric")
                        {
                            throw new Exception($"Widget type ({type}) can not contain a 'min_value' field.");
                        }
                        EnsureType(typeof(long), value, "min_value");
                        min_value = Convert.ToInt32(value);
                        break;

                    case "max_value":
                        if (type != "numeric")
                        {
                            throw new Exception($"Widget type ({type}) can not contain a 'max_value' field.");
                        }
                        EnsureType(typeof(long), value, "max_value");
                        max_value = Convert.ToInt32(value);
                        break;

                    case "text":
                        if (type != "label" && type != "textbox" && type != "button" && type != "checkbox" &&
                            type != "radiobox" && type != "multitextbox" && type != "multilabel")
                        {
                            throw new Exception($"Widget type ({type}) can not contain a 'text' field.");
                        }
                        EnsureType(typeof(string), value, "text");
                        text = (string)value;
                        break;

                    case "items":
                        if (type != "dropdown")
                        {
                            throw new Exception($"Widget type ({type}) can not contain an 'items' field.");
                        }
                        if (!(value is JArray))
                        {
                            throw new Exception($"Expected an Array, but got {value.GetType().Name} in key 'items'");
                        }
                        List <object> ary = ((JArray)value).ToObject <List <object> >();
                        items = new List <ListItem>();
                        foreach (object o in ary)
                        {
                            EnsureType(typeof(string), o, "items");
                            items.Add(new ListItem((string)o));
                        }
                        break;

                    case "index":
                        if (type != "dropdown")
                        {
                            throw new Exception($"Widget type ({type}) can not contain an 'index' field.");
                        }
                        EnsureType(typeof(long), value, "index");
                        idx = Convert.ToInt32(value);
                        if (idx < 0)
                        {
                            throw new Exception($"Index field must be greater than or equal to 0.");
                        }
                        break;

                    case "enabled":
                        if (type != "label" && type != "dropdown" && type != "switch_picker" && type != "variable_picker" &&
                            type != "checkbox" && type != "radiobox" && type != "textbox" && type != "numeric" &&
                            type != "button" && type != "multilabel")
                        {
                            throw new Exception($"Widget type ({type}) can not contain an 'enabled' field.");
                        }
                        EnsureType(typeof(bool), value, "enabled");
                        enabled = Convert.ToBoolean(value);
                        break;

                    case "widgets":
                        if (!(value is JObject))
                        {
                            throw new Exception($"Expected an Object, but got a {value.GetType().Name} in key 'widgets'");
                        }
                        ParseWidgets(w, ((JObject)value).ToObject <Dictionary <string, object> >());
                        break;

                    case "clicked":
                        if (type != "radiobox" && type != "dropdown")
                        {
                            throw new Exception($"Widget type ({type}) can not contain a 'clicked' field.");
                        }
                        if (!(value is JArray))
                        {
                            throw new Exception($"Expected an Array, but got {value.GetType().Name} in key 'clicked'");
                        }
                        List <object> clickdata = ((JArray)value).ToObject <List <object> >();
                        for (int i = 0; i < clickdata.Count; i++)
                        {
                            object action = clickdata[i];
                            if (!(action is JObject))
                            {
                                throw new Exception($"Expected an Object, but got {action.GetType().Name} in key 'clicked', element {i}");
                            }
                            Dictionary <string, object> actionobject = ((JObject)action).ToObject <Dictionary <string, object> >();
                            if (!actionobject.ContainsKey("action"))
                            {
                                throw new Exception($"Click definition in 'clicked', element {i} must contain an 'action' key.");
                            }
                            string        actiontype      = null;
                            List <object> actionparams    = new List <object>();
                            string        actioncondition = null;
                            foreach (string actionkey in actionobject.Keys)
                            {
                                object actionvalue = actionobject[actionkey];
                                switch (actionkey)
                                {
                                case "action":
                                    EnsureType(typeof(string), actionvalue, "action");
                                    actiontype = (string)actionvalue;
                                    if (actiontype != "enable" && actiontype != "disable" && actiontype != "check" && actiontype != "uncheck" &&
                                        actiontype != "set")
                                    {
                                        throw new Exception($"Unknown action type '{actiontype}'.");
                                    }
                                    break;

                                case "parameter":
                                    if (!(actionvalue is string) && !(actionvalue is JArray))
                                    {
                                        throw new Exception($"Expected a string or Array, but got {actionvalue.GetType().Name} in key 'parameter'.");
                                    }
                                    if (actionvalue is string)
                                    {
                                        actionparams.Add((string)actionvalue);
                                    }
                                    else
                                    {
                                        List <object> paramlist = ((JArray)actionvalue).ToObject <List <object> >();
                                        foreach (object paramvalue in paramlist)
                                        {
                                            actionparams.Add(paramvalue);
                                        }
                                    }
                                    break;

                                case "condition":
                                    EnsureType(typeof(string), actionvalue, "condition");
                                    actioncondition = (string)actionvalue;
                                    break;

                                default:
                                    throw new Exception($"Unknown key '{actionkey}' inside 'clicked' definition");
                                }
                            }
                            clickactions.Add(new ClickAction(actiontype, actionparams, actioncondition));
                        }
                        break;

                    default:
                        throw new Exception($"Unknown key '{key}' inside widget definition");
                    }
                }
                EnabledLookup.Add(name, enabled);
                w.SetPosition(X, Y);
                if (Width != -1 && Height != -1)
                {
                    w.SetSize(Width, Height);
                }
                else if (Width != -1)
                {
                    w.SetWidth(Width);
                }
                else if (Height != -1)
                {
                    w.SetHeight(Height);
                }
                if (type == "label")
                {
                    if (!string.IsNullOrEmpty(text))
                    {
                        ((DynamicLabel)w).SetText(text);
                    }
                    if (font != null)
                    {
                        ((DynamicLabel)w).SetFont(font);
                    }
                    //((DynamicLabel) w).SetParser(this);
                    ((DynamicLabel)w).SetColors(ConditionParser.Colors);
                    ((DynamicLabel)w).SetEnabled(enabled);
                }
                if (type == "multilabel")
                {
                    if (!string.IsNullOrEmpty(text))
                    {
                        ((MultilineDynamicLabel)w).SetText(text);
                    }
                    if (font != null)
                    {
                        ((MultilineDynamicLabel)w).SetFont(font);
                    }
                    //((MultilineDynamicLabel) w).SetParser(this);
                    ((MultilineDynamicLabel)w).SetColors(ConditionParser.Colors);
                    ((MultilineDynamicLabel)w).SetEnabled(enabled);
                }
                if (type == "textbox")
                {
                    if (!string.IsNullOrEmpty(text))
                    {
                        ((TextBox)w).SetInitialText(text);
                    }
                    if (font != null)
                    {
                        ((TextBox)w).TextArea.SetFont(font);
                    }
                    ((TextBox)w).OnTextChanged += Save;
                }
                if (type == "numeric")
                {
                    ((NumericBox)w).SetValue(wvalue);
                    if (min_value != null)
                    {
                        ((NumericBox)w).MinValue = (int)min_value;
                    }
                    if (max_value != null)
                    {
                        ((NumericBox)w).MaxValue = (int)max_value;
                    }
                    ((NumericBox)w).OnValueChanged += Save;
                }
                if (type == "button")
                {
                    if (!string.IsNullOrEmpty(text))
                    {
                        ((Button)w).SetText(text);
                    }
                    if (font != null)
                    {
                        ((Button)w).SetFont(font);
                    }
                }
                if (type == "dropdown")
                {
                    if (items == null && idx != -1 || items != null && idx >= items.Count)
                    {
                        throw new Exception($"Index cannot be greater than or equal to the total item size.");
                    }
                    if (items != null)
                    {
                        ((DropdownBox)w).SetItems(items);
                    }
                    if (idx != -1)
                    {
                        ((DropdownBox)w).SetSelectedIndex(idx);
                    }
                    if (font != null)
                    {
                        ((DropdownBox)w).SetFont(font);
                    }
                    ((DropdownBox)w).OnSelectionChanged += Save;
                    ((DropdownBox)w).OnSelectionChanged += delegate(BaseEventArgs e)
                    {
                        EvaluateAction(clickactions);
                    };
                }
                if (type == "checkbox")
                {
                    if (font != null)
                    {
                        ((CheckBox)w).SetFont(font);
                    }
                    if (!string.IsNullOrEmpty(text))
                    {
                        ((CheckBox)w).SetText(text);
                    }
                }
                if (type == "radiobox")
                {
                    if (font != null)
                    {
                        ((RadioBox)w).SetFont(font);
                    }
                    if (!string.IsNullOrEmpty(text))
                    {
                        ((RadioBox)w).SetText(text);
                    }
                    ((RadioBox)w).OnCheckChanged += delegate(BaseEventArgs e)
                    {
                        if (((RadioBox)w).Checked)
                        {
                            EvaluateAction(clickactions);
                        }
                    };
                }
                if (type == "switch_picker")
                {
                    ((GameSwitchBox)w).OnSwitchChanged += Save;
                }
                if (type == "variable_picker")
                {
                    ((GameVariableBox)w).OnVariableChanged += Save;
                }
                if (type == "multitextbox")
                {
                    if (font != null)
                    {
                        ((MultilineTextBox)w).SetFont(font);
                    }
                    if (!string.IsNullOrEmpty(text))
                    {
                        ((MultilineTextBox)w).SetText(text);
                    }
                }
                SetWidgetEnabled(w, enabled);
            }
        }
Example #13
0
        public TextBoxTest(ControlBase parent)
            : base(parent)
        {
            m_Font1          = Skin.DefaultFont.Copy();
            m_Font1.FaceName = "Courier New"; // fixed width font!

            m_Font2          = Skin.DefaultFont.Copy();
            m_Font2.FaceName = "Times New Roman";
            m_Font2.Size    *= 3;

            m_Font3       = Skin.DefaultFont.Copy();
            m_Font3.Size += 5;

            VerticalLayout vlayout = new VerticalLayout(this);
            {
                DockLayout dockLayout = new DockLayout(vlayout);
                {
                    VerticalLayout vlayout2 = new VerticalLayout(dockLayout);
                    vlayout2.Dock  = Dock.Left;
                    vlayout2.Width = 200;
                    {
                        /* Vanilla Textbox */
                        {
                            TextBox textbox = new TextBox(vlayout2);
                            textbox.Margin = Margin.Five;
                            textbox.SetText("Type something here");
                            textbox.TextChanged   += OnEdit;
                            textbox.SubmitPressed += OnSubmit;
                        }

                        {
                            TextBoxPassword textbox = new TextBoxPassword(vlayout2);
                            textbox.Margin = Margin.Five;
                            //textbox.MaskCharacter = '@';
                            textbox.SetText("secret");
                            textbox.TextChanged += OnEdit;
                        }

                        {
                            TextBox textbox = new TextBox(vlayout2);
                            textbox.Margin = Margin.Five;
                            textbox.SetText("Select All Text On Focus");
                            textbox.SelectAllOnFocus = true;
                        }

                        {
                            TextBox textbox = new TextBox(vlayout2);
                            textbox.Margin = Margin.Five;
                            textbox.SetText("Different Coloured Text, for some reason");
                            textbox.TextColor = Color.Green;
                        }

                        {
                            TextBox textbox = new TextBoxNumeric(vlayout2);
                            textbox.Margin = Margin.Five;
                            textbox.SetText("200456698");
                            textbox.TextColor = Color.Red;
                        }
                    }

                    /* Multiline Textbox */
                    {
                        MultilineTextBox textbox = new MultilineTextBox(dockLayout);
                        textbox.Dock       = Dock.Fill;
                        textbox.Margin     = Margin.Five;
                        textbox.Font       = m_Font1;
                        textbox.AcceptTabs = true;
                        textbox.SetText("In olden times when wishing still helped one, there lived a king whose daughters were all beautiful,\nbut the youngest was so beautiful that the sun itself, which has seen so much, \nwas astonished whenever it shone in her face. \nClose by the king's castle lay a great dark forest, \nand under an old lime-tree in the forest was a well, and when the day was very warm, \nthe king's child went out into the forest and sat down by the side of the cool fountain, \nand when she was bored she took a golden ball, and threw it up on high and caught it, \nand this ball was her favorite plaything.");
                    }
                    {
                        Button pad = new Button(dockLayout);
                        pad.Dock     = Dock.Right;
                        pad.Margin   = Margin.Five;
                        pad.Text     = "Pad";
                        pad.Clicked += (s, a) => new TextPad(this);
                    }
                }

                {
                    TextBox textbox = new TextBox(vlayout);
                    textbox.Margin = Margin.Five;
                    textbox.SetText("In olden times when wishing still helped one, there lived a king whose daughters were all beautiful, but the youngest was so beautiful that the sun itself, which has seen so much, was astonished whenever it shone in her face. Close by the king's castle lay a great dark forest, and under an old lime-tree in the forest was a well, and when the day was very warm, the king's child went out into the forest and sat down by the side of the cool fountain, and when she was bored she took a golden ball, and threw it up on high and caught it, and this ball was her favorite plaything.");
                    textbox.TextColor = Color.Black;
                    textbox.Font      = m_Font3;
                }

                {
                    TextBox textbox = new TextBox(vlayout);
                    textbox.Margin = Margin.Five;
                    textbox.Width  = 150;
                    textbox.HorizontalAlignment = HorizontalAlignment.Right;
                    textbox.SetText("あおい うみから やってきた");
                    textbox.TextColor = Color.Black;
                    textbox.Font      = m_Font3;
                }

                {
                    TextBox textbox = new TextBox(vlayout);
                    textbox.Margin = Margin.Five;
                    textbox.HorizontalAlignment = HorizontalAlignment.Left;
                    textbox.FitToText           = "Fit the text";
                    textbox.SetText("FitToText");
                    textbox.TextColor = Color.Black;
                    textbox.Font      = m_Font3;
                }

                {
                    TextBox textbox = new TextBox(vlayout);
                    textbox.Margin = Margin.Five;
                    textbox.HorizontalAlignment = HorizontalAlignment.Left;
                    textbox.Width = 200;
                    textbox.SetText("Width = 200");
                    textbox.TextColor = Color.Black;
                    textbox.Font      = m_Font3;
                }

                {
                    TextBox textbox = new TextBox(vlayout);
                    textbox.Margin = Margin.Five;
                    textbox.SetText("Different Font");
                    textbox.Font = m_Font2;
                }
            }
        }