using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using ShiftUI; using System.Drawing; using System.Diagnostics; using System.Reflection; namespace ShiftUI_Designer { public class MyAwesomeSkin : ShiftUI.ShiftOS.Skin { public MyAwesomeSkin() { base.ButtonBackColor_Pressed = Color.Red; } } class Program { static void Main(string[] args) { Application.LoadSkin(new MyAwesomeSkin()); Application.EnableVisualStyles(); Application.Run(new FormSelectionForm()); Console.WriteLine("This executed after Run."); } } public static class Helpers { public static void Debug(this Form host, string message) { Console.WriteLine("<{0}> [ShiftUI/{1}] {2}", DateTime.Now.ToString(), host.Text, message); } } public class MainEditorForm : Form { private Panel resize_se = null; private Panel resize_e = null; private Panel resize_s = null; private Panel resize_sw = null; private Panel resize_w = null; public void LoadFormFromClass(Form form) { var t = form.GetType(); var init_method = t.GetMethod("InitializeComponent"); if (init_method != null) { init_method.Invoke(form, null); } TopLevels.Add(form); current_form = form; PopulateTree(); DrawForm(); this.Show(); } public enum ResizeLocation { South = 0, SouthEast = 1, East = 2, NorthEast = 3, North = 4, NorthWest = 5, West = 6, SouthWest = 7 } public void Select(Widget widget) { if (widget != null) { if(widget is Form && current_form != widget as Form) { current_form = widget as Form; DrawForm(); Select(current_form); } if (widget != current_form.Body) { properties.SelectedObject = widget; resizing_widget = widget; resize_w?.Parent?.Widgets.Remove(resize_w); resize_w = null; resize_sw?.Parent?.Widgets.Remove(resize_sw); resize_sw = null; resize_se?.Parent?.Widgets.Remove(resize_se); resize_se = null; resize_s?.Parent?.Widgets.Remove(resize_s); resize_s = null; resize_e?.Parent?.Widgets.Remove(resize_e); resize_e = null; SetupResizeBorder(widget); } else { Select(current_form); } } else { resize_w?.Hide(); resize_sw?.Hide(); resize_s?.Hide(); resize_se?.Hide(); resize_e?.Hide(); } } public void SetupResizeBorder(Widget widget) { if (!(widget is Form)) { SetupMoveHandle(ref resize_sw, ResizeLocation.NorthWest); } SetupResizeHandle(ref resize_se, ResizeLocation.SouthEast); SetupResizeHandle(ref resize_e, ResizeLocation.East); SetupResizeHandle(ref resize_s, ResizeLocation.South); } Point last_mouse_location = Point.Empty; bool dragging = false; private Widget resizing_widget = null; public void SetupMoveHandle(ref Panel handle, ResizeLocation loc) { bool updown = false; bool leftright = false; properties.SelectedObject = resizing_widget; if (handle == null) { handle = new Panel(); body.Widgets.Add(handle); handle.BackColor = Color.Black; handle.Size = new Size(16, 16); handle.MouseDown += (o, a) => { if (a.Button == MouseButtons.Left) { last_mouse_location = a.Location; dragging = true; } }; handle.MouseUp += (o, a) => { dragging = false; }; handle.MouseMove += (o, a) => { if (dragging == true) { var mouse_loc = a.Location; int y_distance = mouse_loc.Y - last_mouse_location.Y; int x_distance = mouse_loc.X - last_mouse_location.X; if (updown == true) { resizing_widget.Top += y_distance; form_preview.Refresh(); } if (leftright == true) { resizing_widget.Left += x_distance; form_preview.Refresh(); } SetupResizeBorder(resizing_widget); } }; } bool ex = false; var wloc = Point.Empty; try { wloc = resizing_widget.Parent.PointToScreen(resizing_widget.Location); } catch { ex = true; wloc = body.PointToScreen(resizing_widget.Location); //Must be a top-level widget. } wloc = body.PointToClient(wloc); switch (loc) { case ResizeLocation.NorthWest: handle.Left = wloc.X - handle.Width; handle.Top = wloc.Y - handle.Height; updown = true; leftright = true; break; } handle.BringToFront(); handle.Show(); handle.Refresh(); body.Refresh(); } public void SetupResizeHandle(ref Panel handle, ResizeLocation loc) { bool updown = false; bool leftright = false; properties.SelectedObject = resizing_widget; if (handle == null) { handle = new Panel(); body.Widgets.Add(handle); handle.BackColor = Color.Black; handle.Size = new Size(16, 16); handle.MouseDown += (o, a) => { if (a.Button == MouseButtons.Left) { last_mouse_location = a.Location; dragging = true; } }; handle.MouseUp += (o, a) => { dragging = false; }; handle.MouseMove += (o, a) => { if (dragging == true) { var mouse_loc = a.Location; int y_distance = mouse_loc.Y - last_mouse_location.Y; int x_distance = mouse_loc.X - last_mouse_location.X; if (updown == true) { resizing_widget.Height += y_distance; form_preview.Refresh(); } if (leftright == true) { resizing_widget.Width += x_distance; form_preview.Refresh(); } SetupResizeBorder(resizing_widget); } }; } bool ex = false; var wloc = Point.Empty; try { wloc = resizing_widget.Parent.PointToScreen(resizing_widget.Location); } catch { ex = true; wloc = body.PointToScreen(resizing_widget.Location); //Must be a top-level widget. } wloc = body.PointToClient(wloc); switch ((int)loc) { case 0: handle.Left = wloc.X + ((resizing_widget.Width - handle.Width) / 2); handle.Top = wloc.Y + resizing_widget.Height; updown = true; break; case 1: handle.Left = wloc.X + resizing_widget.Width + 5; handle.Top = wloc.Y + resizing_widget.Height + 5; updown = true; leftright = true; break; case 2: handle.Left = wloc.X + resizing_widget.Width; handle.Top = wloc.Y + ((resizing_widget.Height - handle.Height) / 2); leftright = true; break; case 3: handle.Left = wloc.X + resizing_widget.Width; handle.Top = wloc.Y + (resizing_widget.Top - handle.Top); leftright = true; updown = true; break; } handle.BringToFront(); handle.Show(); handle.Refresh(); body.Refresh(); } private Panel form_preview; private Form current_form; public void DrawForm() { if (form_preview == null) { form_preview = new Panel(); body.Widgets.Add(form_preview); } if (current_form != null) { current_form.FormClosing += (o, a) => { a.Cancel = true; }; current_form.SizeChanged += (o, a) => { form_preview.Size = current_form.Size; }; current_form.Body.WidgetAdded += (o, a) => { SetupWidget(a.Widget); }; form_preview.Widgets.Clear(); form_preview.Location = new Point(5, 5); form_preview.Size = current_form.Size; Widget[] widgets = new Widget[current_form.Widgets.Count]; current_form.Widgets.CopyTo(widgets, 0); Widget[] borderwidgets = new Widget[current_form.BorderWidgets.Length]; current_form.BorderWidgets.CopyTo(borderwidgets, 0); foreach (var widget in borderwidgets) { form_preview.Widgets.Add(widget); widget.Show(); SetupWidget(widget); } foreach (var widget in widgets) { if (!borderwidgets.Contains(widget)) { form_preview.Widgets.Add(widget); widget.Show(); if (widget == current_form.Body) widget.BringToFront(); SetupWidget(widget); } } form_preview.Show(); } } public void SetupWidget(Widget widget) { if (string.IsNullOrEmpty(widget.Name)) { widget.MouseDown += (o, a) => { Select(current_form); current_parent = current_form; }; } else { widget.MouseDown += (o, a) => { Select(widget); current_parent = widget; }; } //give the widget the Container context menu widget.ContextMenuStrip = container_menu; foreach(Widget w in widget.Widgets) { SetupWidget(w); } } public List