Beispiel #1
0
        private void controlPropertyGrid_PropertyValueChanged(object s, PropertyValueChangedEventArgs e)
        {
            if (e.ChangedItem.Label == "Name")
            {
                var invalidName = false;
                var newName     = e.ChangedItem.Value.ToString();
                var nameRegex   = new Regex("[a-zA-Z_][a-zA-Z0-9_]*", RegexOptions.Compiled);
                if (!nameRegex.IsMatch(newName))
                {
                    MessageBox.Show("'" + newName + "' isn't a valid name!");
                    invalidName = true;
                }
                if (ControlManager.Instance().FindByName(newName, GuiControls.Control.FocusedControl) != null)
                {
                    MessageBox.Show("A control with this name already exists!");
                    invalidName = true;
                }
                if (invalidName)
                {
                    GuiControls.Control.FocusedControl.Name = e.OldValue.ToString();
                    controlPropertyGrid.Refresh();
                }
                else
                {
                    controlComboBox.RefreshItem(controlComboBox.SelectedItem);
                }
            }

            canvasPictureBox.Invalidate();
        }
Beispiel #2
0
        private void addTabPageToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var tempTabPage = new GuiControls.TabPage();

            tempTabPage.Text = tempTabPage.Name = "tabPage" + ControlManager.Instance().GetControlCountPlusOne(typeof(GuiControls.TabPage));
            (GuiControls.Control.FocusedControl as GuiControls.TabControl).AddTabPage(tempTabPage);
            AddControlToList(tempTabPage);
        }
Beispiel #3
0
        private void newToolStripMenuItem_Click(object sender, EventArgs e)
        {
            controlComboBox.Items.Clear();
            ControlManager.Instance().Clear();

            form      = new GuiControls.Form();
            form.Text = form.Name = "Form1";
            AddControlToList(form);
        }
Beispiel #4
0
        private void loadToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var ofd = new OpenFileDialog();

            ofd.DefaultExt = "xml";
            ofd.Filter     = "OSHGui File (*.xml)|*.xml";

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    var control = ControlSerializer.Deserialize(XElement.Load(ofd.FileName));
                    if (control is GuiControls.Form)
                    {
                        form          = control as GuiControls.Form;
                        form.DragEnd += control_DragEnd;

                        ControlManager.Instance().Clear();
                        ControlManager.Instance().RegisterControl(control);

                        form.RegisterInternalControls();

                        controlComboBox.Items.Clear();
                        controlComboBox.Items.AddRange(ControlManager.Instance().Controls.ToArray());
                        controlComboBox.SelectedItem = control;

                        foreach (var scalableControl in ControlManager.Instance().Controls.OfType <ScalableControl>())
                        {
                            if (scalableControl != form)
                            {
                                scalableControl.MouseDown += control_MouseDown;
                                scalableControl.MouseMove += control_MouseMove;
                                scalableControl.MouseUp   += control_MouseUp;
                                scalableControl.DragEnd   += control_DragEnd;
                            }
                        }

                        canvasPictureBox.Invalidate();
                    }
                    else
                    {
                        MessageBox.Show("Invalid file!");
                    }
                }
                catch (Exception serializeError)
                {
                    MessageBox.Show("Error while parsing " + Path.GetFileName(ofd.FileName) + "\n\n" + serializeError.Message, "OSHGui Parse Error");
                }
            }
        }
Beispiel #5
0
        private void RemoveControlFromList(GuiControls.Control control)
        {
            try
            {
                ControlManager.Instance().UnregisterControl(control);

                controlComboBox.Items.Remove(control);
                controlComboBox.SelectedIndex = 0;

                canvasPictureBox.Invalidate();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }
Beispiel #6
0
        private void AddControlToList(GuiControls.Control control)
        {
            try
            {
                control.Name = control.DefaultName + ControlManager.Instance().GetControlCountPlusOne(control.GetType());

                ControlManager.Instance().RegisterControl(control);

                controlComboBox.Items.Add(control);
                controlComboBox.SelectedItem = control;

                canvasPictureBox.Invalidate();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }
Beispiel #7
0
        public string GenerateHeaderCode()
        {
            var prefix = new string('\t', Options.Namespaces.Length);

            eventMethodList = new List <string>();

            var code = new StringBuilder();

            code.AppendLine("#pragma once\n");
            code.AppendLine("#include <OSHGui.hpp>");
            code.AppendLine(Options.XorStr ? "#include <XorStr.hpp>\n" : string.Empty);
            code.Append(GetNamespacesBegin());
            code.AppendLine(prefix + "class " + form.Name + " : public OSHGui::Form");
            code.AppendLine(prefix + "{");
            code.AppendLine(prefix + "public:");
            code.AppendLine(prefix + "\t" + form.Name + "();\n");
            code.AppendLine(prefix + "private:");
            code.AppendLine(prefix + "\tvoid InitializeComponent()");
            code.AppendLine(prefix + "\t{");
            code.AppendLine(prefix + "\t\tusing namespace OSHGui;");
            code.AppendLine(prefix + "\t\tusing namespace OSHGui::Misc;");
            code.AppendLine(prefix + "\t\tusing namespace OSHGui::Drawing;\n");

            foreach (var property in form.GetChangedProperties())
            {
                if (property.Value.UseForCpp && CheckValidProperty(property.Key))
                {
                    code.AppendLine(prefix + "\t\t" + TranslateProperties[property.Key] + "(" + GetCppString(property.Value.Value) + ");");
                }
            }

            foreach (var controlEvent in form.GetUsedEvents())
            {
                eventMethodList.Add(string.Format("void {0}({1});", controlEvent.Signature, string.Join(", ", controlEvent.Parameter)));

                string placeholder = "std::placeholders::_1";
                for (int i = 2; i < controlEvent.Parameter.Length + 1; ++i)
                {
                    placeholder += ", std::placeholders::_" + i;
                }
                code.AppendLine(prefix + "\t\tGet" + controlEvent.GetType().Name + "() += " + controlEvent.GetType().Name + "Handler(std::bind(&" + form.Name + "::" + controlEvent.Signature + ", this, " + placeholder + "));");
            }

            if (form.Controls.Count > 0)
            {
                var controlPrefix = prefix + "\t\t";
                code.AppendLine(string.Empty);
                foreach (Control control in form.Controls)
                {
                    code.Append(GenerateControlHeaderCode(control, controlPrefix));
                    code.AppendLine(controlPrefix + "AddControl(" + control.Name + ");\n");
                }
                code.Length -= 1;

                code.AppendLine(prefix + "\t}\n");
                foreach (Control control in ControlManager.Instance().Controls)
                {
                    if (control != form)
                    {
                        code.AppendLine(prefix + "\tOSHGui::" + control.GetType().Name + " *" + control.Name + ";");
                    }
                }
            }
            else
            {
                code.AppendLine(prefix + "\t}");
            }
            if (eventMethodList.Count > 0)
            {
                code.AppendLine();
                foreach (string method in eventMethodList)
                {
                    code.AppendLine(prefix + "\t" + method);
                }
            }

            code.AppendLine(prefix + "};");
            code.AppendLine(GetNamespacesEnd());

            return(code.ToString());
        }
Beispiel #8
0
        private void canvasPictureBox_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
        {
            if (GuiControls.Control.FocusedControl != null)
            {
                if (e.KeyCode == Keys.Delete)
                {
                    var removeControl = GuiControls.Control.FocusedControl;
                    var parent        = removeControl.RealParent ?? form;

                    RecursiveRemove(removeControl);

                    parent.Focus();

                    controlComboBox.SelectedIndex = 0;
                }
                else if (e.Control && e.KeyCode == Keys.C)
                {
                    if (GuiControls.Control.FocusedControl == form)
                    {
                        return;
                    }

                    var copiedControl = GuiControls.Control.FocusedControl.Copy();
                    Clipboard.SetData(
                        "OSHVisualGuiControl",
                        ControlSerializer.Serialize(copiedControl).ToString()
                        );
                }
                else if (e.Control && e.KeyCode == Keys.X)
                {
                    if (GuiControls.Control.FocusedControl == form)
                    {
                        return;
                    }

                    Clipboard.SetData(
                        "OSHVisualGuiControl",
                        ControlSerializer.Serialize(GuiControls.Control.FocusedControl).ToString()
                        );

                    RecursiveRemove(GuiControls.Control.FocusedControl);

                    controlComboBox.SelectedIndex = 0;
                }
                else if (e.Control && e.KeyCode == Keys.V)
                {
                    if (!Clipboard.ContainsData("OSHVisualGuiControl"))
                    {
                        return;
                    }

                    if (Clipboard.GetData("OSHVisualGuiControl") is string serializedControl)
                    {
                        var copiedControl = ControlSerializer.Deserialize(XElement.Parse(serializedControl));
                        if (copiedControl != null)
                        {
                            ContainerControl parent = null;
                            if (copiedControl is GuiControls.TabPage && !(GuiControls.Control.FocusedControl is GuiControls.TabControl))
                            {
                                MessageBox.Show("A TabPage needs to be inserted into a TabControl.");
                                return;
                            }
                            if (GuiControls.Control.FocusedControl is ContainerControl)
                            {
                                parent = GuiControls.Control.FocusedControl as ContainerControl;
                            }
                            else
                            {
                                parent = GuiControls.Control.FocusedControl.RealParent;
                            }

                            //check if name already exists
                            if (ControlManager.Instance().FindByName(copiedControl.Name, null) != null)
                            {
                                //then change the name
                                copiedControl.Name = copiedControl.DefaultName + ControlManager.Instance().GetControlCountPlusOne(copiedControl.GetType());
                                //and change the location
                                copiedControl.Location = copiedControl.Location.Add(new Point(10, 10));
                            }

                            parent.AddControl(copiedControl);

                            AddControlToList(copiedControl);
                            if (copiedControl is ContainerControl)
                            {
                                foreach (var control in (copiedControl as ContainerControl).PreOrderVisit())
                                {
                                    if (control is ScalableControl)
                                    {
                                        RegisterEvents(control);

                                        AddControlToList(control);
                                    }
                                }
                                controlComboBox.SelectedItem = copiedControl;
                            }

                            RegisterEvents(copiedControl);
                        }
                    }
                }
            }
        }
Beispiel #9
0
        private void canvasPictureBox_DragDrop(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(typeof(ControlType)))
            {
                var type = (ControlType)e.Data.GetData(typeof(ControlType));

                var cm = ControlManager.Instance();
                GuiControls.Control newControl = null;
                switch (type)
                {
                case ControlType.Button:
                    var button = new GuiControls.Button();
                    button.Text = button.Name = button.DefaultName + cm.GetControlCountPlusOne(typeof(GuiControls.Button));
                    newControl  = button;
                    break;

                case ControlType.CheckBox:
                    var checkBox = new GuiControls.CheckBox();
                    checkBox.Text = checkBox.Name = checkBox.DefaultName + cm.GetControlCountPlusOne(typeof(GuiControls.CheckBox));
                    newControl    = checkBox;
                    break;

                case ControlType.ColorBar:
                    var colorBar = new ColorBar();
                    colorBar.Name = colorBar.DefaultName + cm.GetControlCountPlusOne(typeof(ColorBar));
                    newControl    = colorBar;
                    break;

                case ControlType.ColorPicker:
                    var colorPicker = new GuiControls.ColorPicker();
                    colorPicker.Name = colorPicker.DefaultName + cm.GetControlCountPlusOne(typeof(GuiControls.ColorPicker));
                    newControl       = colorPicker;
                    break;

                case ControlType.ComboBox:
                    var comboBox = new GuiControls.ComboBox();
                    comboBox.Text = comboBox.Name = comboBox.DefaultName + cm.GetControlCountPlusOne(typeof(GuiControls.ComboBox));
                    newControl    = comboBox;
                    break;

                case ControlType.GroupBox:
                    var groupBox = new GuiControls.GroupBox();
                    groupBox.Text = groupBox.Name = groupBox.DefaultName + cm.GetControlCountPlusOne(typeof(GuiControls.GroupBox));
                    newControl    = groupBox;
                    break;

                case ControlType.Label:
                    var label = new GuiControls.Label();
                    label.Text = label.Name = label.DefaultName + cm.GetControlCountPlusOne(typeof(GuiControls.Label));
                    newControl = label;
                    break;

                case ControlType.LinkLabel:
                    var linkLabel = new GuiControls.LinkLabel();
                    linkLabel.Text = linkLabel.Name = linkLabel.DefaultName + cm.GetControlCountPlusOne(typeof(GuiControls.LinkLabel));
                    newControl     = linkLabel;
                    break;

                case ControlType.ListBox:
                    var listBox = new GuiControls.ListBox();
                    listBox.Name = listBox.DefaultName + cm.GetControlCountPlusOne(typeof(GuiControls.ListBox));
                    newControl   = listBox;
                    break;

                case ControlType.Panel:
                    var panel = new GuiControls.Panel();
                    panel.Name = panel.DefaultName + cm.GetControlCountPlusOne(typeof(GuiControls.Panel));
                    newControl = panel;
                    break;

                case ControlType.PictureBox:
                    var pictureBox = new GuiControls.PictureBox();
                    pictureBox.Name = pictureBox.DefaultName + cm.GetControlCountPlusOne(typeof(GuiControls.PictureBox));
                    newControl      = pictureBox;
                    break;

                case ControlType.ProgressBar:
                    var progressBar = new GuiControls.ProgressBar();
                    progressBar.Name = progressBar.DefaultName + cm.GetControlCountPlusOne(typeof(GuiControls.ProgressBar));
                    newControl       = progressBar;
                    break;

                case ControlType.RadioButton:
                    var radioButton = new GuiControls.RadioButton();
                    radioButton.Text = radioButton.Name = radioButton.DefaultName + cm.GetControlCountPlusOne(typeof(GuiControls.RadioButton));
                    newControl       = radioButton;
                    break;

                case ControlType.TabControl:
                    var tabControl = new GuiControls.TabControl();
                    tabControl.Name = tabControl.DefaultName + cm.GetControlCountPlusOne(typeof(GuiControls.TabControl));
                    var tempTabPage = new GuiControls.TabPage();
                    tempTabPage.Text = tempTabPage.Name = tempTabPage.DefaultName + cm.GetControlCountPlusOne(typeof(GuiControls.TabPage));
                    tabControl.AddTabPage(tempTabPage);
                    AddControlToList(tempTabPage);
                    newControl = tabControl;
                    break;

                case ControlType.TabPage:
                    var tabPage = new GuiControls.TabPage();
                    tabPage.Text = tabPage.Name = tabPage.DefaultName + cm.GetControlCountPlusOne(typeof(GuiControls.TabPage));
                    newControl   = tabPage;
                    break;

                case ControlType.TextBox:
                    var textBox = new GuiControls.TextBox();
                    textBox.Name = textBox.Text = textBox.DefaultName + cm.GetControlCountPlusOne(typeof(GuiControls.TextBox));
                    newControl   = textBox;
                    break;

                case ControlType.Timer:
                    var timer = new GuiControls.Timer();
                    timer.Name = timer.DefaultName + cm.GetControlCountPlusOne(typeof(GuiControls.Timer));
                    newControl = timer;
                    break;

                case ControlType.TrackBar:
                    var trackBar = new GuiControls.TrackBar();
                    trackBar.Name = trackBar.DefaultName + cm.GetControlCountPlusOne(typeof(GuiControls.TrackBar));
                    newControl    = trackBar;
                    break;

                case ControlType.HotkeyControl:
                    var hotkeyControl = new HotkeyControl();
                    hotkeyControl.Name = hotkeyControl.DefaultName + cm.GetControlCountPlusOne(typeof(HotkeyControl));
                    newControl         = hotkeyControl;
                    break;
                }
                if (newControl == null)
                {
                    return;
                }

                RegisterEvents(newControl);

                AddControlToList(newControl);

                var location = canvasPictureBox.PointToClient(new Point(e.X, e.Y));
                var parent   = FindContainerControlUnderMouse(location);
                newControl.Location = location.Substract(parent.ContainerAbsoluteLocation);
                parent.AddControl(newControl);
            }
        }