protected override void OnMouseClick(MouseEventArgs e) { if (ControlRect.Contains(e.Location)) { CollpaseOrExpand(); } base.OnMouseClick(e); }
public override void DrawGUI(ControlRect layout) { if (m_Inspector == null) { m_Inspector = new ImporterPropertiesImportTaskInspector(); } m_Inspector.Draw(SelfSerializedObject, layout); SelfSerializedObject.ApplyModifiedProperties(); }
private void ReferenceObjectGUI(ControlRect layout) { using (var check = new EditorGUI.ChangeCheckScope()) { EditorGUI.PropertyField(layout.Get(), m_ImporterReferenceSerializedProperty, new GUIContent("Importer Template"), false); if (check.changed) { m_ImportTask.m_AssetImporter = null; m_ImportTask.GatherProperties(); } } }
//(3). 创建两个函数 /// <summary> /// (3.1)记录窗体和其控件的初始位置和大小, /// </summary> /// <param name="mForm">窗体对象</param> public void ControllInitializeSize(Control mForm) { this.oldCtrl.Clear(); var cR = new ControlRect(mForm.Left, mForm.Top, mForm.Width, mForm.Height, mForm.Font.Size); this.oldCtrl.Add(mForm.GetType() + mForm.Name, cR); //第一个为"窗体本身",只加入一次即可 AddControl(mForm); //窗体内其余控件还可能嵌套控件(比如panel),要单独抽出,因为要递归调用 //this.WindowState = (System.Windows.Forms.FormWindowState)(2);//记录完控件的初始位置和大小后,再最大化 //0 - Normalize , 1 - Minimize,2- Maximize }
private void AddControl(Control ctrl) { foreach (Control c in ctrl.Controls) { ControlRect cR = GetControlRect(c); oldCtrl.Add(cR); if (c.Controls.Count > 0) { AddControl(c); } } }
/// <summary> /// 记录指定控件的信息 /// </summary> /// <param name="control"></param> private void RecordControlRect(Control control) { ControlRect cR = new ControlRect() { Name = control.Name, Left = control.Left, Top = control.Top, Width = control.Width, Height = control.Height, }; oldControl.Add(cR); }
public void Draw(SerializedProperty property, ControlRect layout) { if (m_ImporterReferenceSerializedProperty == null || m_PropertiesArraySerializedProperty == null) { List <string> propertyNames = new List <string> { "m_ImporterReference", "m_ConstrainProperties" }; List <SerializedProperty> properties = SerializationUtilities.FindPropertiesInClass(property, propertyNames); m_ImporterReferenceSerializedProperty = properties[0]; m_PropertiesArraySerializedProperty = properties[1]; if (m_ImporterReferenceSerializedProperty == null || m_PropertiesArraySerializedProperty == null) { Debug.LogError("Invalid properties for ImporterPropertiesModule"); return; } } if (m_Module == null) { AuditProfile profile = property.serializedObject.targetObject as AuditProfile; if (profile == null) { Debug.LogError("ImporterPropertiesModule must be apart of a profile Object"); return; } m_Module = profile.m_ImporterModule; } if (m_ImporterReferenceSerializedProperty != null) { using (var check = new EditorGUI.ChangeCheckScope()) { EditorGUI.PropertyField(layout.Get(), m_ImporterReferenceSerializedProperty, new GUIContent("Importer Template")); if (check.changed) { m_Module.m_AssetImporter = null; m_Module.GatherProperties(); } } } if (m_ImporterReferenceSerializedProperty.objectReferenceValue != null) { ConstrainToPropertiesArea(layout); } else { Rect r = layout.Get(25); EditorGUI.HelpBox(r, "No template Object to constrain properties on.", MessageType.Warning); } }
private void AddControl(Control ctl) { foreach (Control c in ctl.Controls) { //**放在这里,是先记录控件的子控件,后记录控件本身 //if (c.Controls.Count > 0) // AddControl(c);//窗体内其余控件还可能嵌套控件(比如panel),要单独抽出,因为要递归调用 var objCtrl = new ControlRect(c.Left, c.Top, c.Width, c.Height, c.Font.Size); this.oldCtrl.Add(c.GetType() + c.Name, objCtrl); //**放在这里,是先记录控件本身,后记录控件的子控件 if (c.Controls.Count > 0) { AddControl(c); //窗体内其余控件还可能嵌套控件(比如panel),要单独抽出,因为要递归调用 } } }
public DrawControl() { this.DoubleBuffered = true; InitializeComponent(); m_mainRect = new ControlRect(this, new Point(0, 0), Width, Height); m_mainRect.AddValidatedProperty("Color", SystemColors.Control); m_mainRect.Painters[0].Add(BasePainters.FillRect).Value["Color"] = m_mainRect.Property["Color"]; this.Resize += new EventHandler(DrawControl_Resize); this.Disposed += new EventHandler(DrawControl_Disposed); m_mainRect.OnInvalidate += new DrawRect.OnValidateHandler(m_mainRect_OnInvalidate); m_mainRect.OnChildMoved += new DrawRect.NotifyHandler(m_mainRect_OnChildMoved); InitializeRects(); }
private void ConstrainToPropertiesGUI(ControlRect layout) { layout.Space(10); EditorGUI.LabelField(layout.Get(), "Constrain to Properties:"); Rect boxAreaRect = layout.Get(Mathf.Max((m_ImportTask.PropertyCount * layout.layoutHeight) + 6, 20)); GUI.Box(boxAreaRect, GUIContent.none); ControlRect subLayout = new ControlRect(boxAreaRect.x + 3, boxAreaRect.y + 3, boxAreaRect.width - 6, layout.layoutHeight) { padding = 0 }; // list all of the displayNames for (int i = 0; i < m_ImportTask.PropertyCount; ++i) { EditorGUI.LabelField(subLayout.Get(), m_ImportTask.GetPropertyDisplayName(i)); } Rect layoutRect = layout.Get(); layoutRect.x = layoutRect.x + (layoutRect.width - 100); layoutRect.width = 100; if (GUI.Button(layoutRect, "Edit Selection")) { string[] propertyNamesForReference = GetPropertyNames(new SerializedObject(m_ImportTask.ReferenceAssetImporter)); m_ImportTask.GatherPropertiesIfNeeded(); GenericMenu menu = new GenericMenu(); foreach (string propertyName in propertyNamesForReference) { // we do not want UserData to be included. We are required to use this in order to save information about // how the Asset is imported, to generate a different hash for the cache server if (propertyName.Contains("m_UserData")) { continue; } bool isPropertySelected = m_ImportTask.m_ConstrainProperties.Contains(propertyName); string propertyDisplayName = m_ImportTask.GetPropertyDisplayName(propertyName); menu.AddItem(new GUIContent(propertyDisplayName), isPropertySelected, TogglePropertyConstraintSelected, propertyDisplayName); } menu.ShowAsContext(); } }
/// <summary> /// (3.2)控件自适应大小, /// </summary> /// <param name="mForm">控件对象</param> public void ControlAutoSize(Control mForm) { if (this.oldCtrl.Count == 0) { //*如果在窗体的Form1_Load中,记录控件原始的大小和位置,正常没有问题,但要加入皮肤就会出现问题,因为有些控件如dataGridView的的子控件还没有完成,个数少 //*要在窗体的Form1_SizeChanged中,第一次改变大小时,记录控件原始的大小和位置,这里所有控件的子控件都已经形成 this.oldCtrl.Clear(); var cR = new ControlRect(0, 0, mForm.PreferredSize.Width, mForm.PreferredSize.Height, mForm.Font.Size); this.oldCtrl.Add(mForm.GetType() + mForm.Name, cR); //第一个为"窗体本身",只加入一次即可 AddControl(mForm); //窗体内其余控件可能嵌套其它控件(比如panel),故单独抽出以便递归调用 } this._wScale = mForm.Width / (float)this.oldCtrl[mForm.GetType() + mForm.Name].Width; //新旧窗体之间的比例,与最早的旧窗体 this._hScale = mForm.Height / (float)this.oldCtrl[mForm.GetType() + mForm.Name].Height; //.Height; AutoScaleControl(mForm, this._wScale, this._hScale); //窗体内其余控件还可能嵌套控件(比如panel),要单独抽出,因为要递归调用 }
public virtual void DrawGUI(ControlRect layout) { var type = GetType(); var so = new SerializedObject(this); var p = so.GetIterator(); p.Next(true); while (p.Next(false)) { var prop = type.GetField(p.name, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly); if (prop != null) { EditorGUI.PropertyField(layout.Get(), p, false); } } so.ApplyModifiedProperties(); }
private void ConstrainToPropertiesArea(ControlRect layout) { layout.Space(10); EditorGUI.LabelField(layout.Get(), "Constrain to Properties:"); Rect boxAreaRect = layout.Get(Mathf.Max((m_Module.PropertyCount * layout.layoutHeight) + 6, 20)); GUI.Box(boxAreaRect, GUIContent.none); ControlRect subLayout = new ControlRect(boxAreaRect.x + 3, boxAreaRect.y + 3, boxAreaRect.width - 6, layout.layoutHeight) { padding = 0 }; // list all of the displayNames for (int i = 0; i < m_Module.PropertyCount; ++i) { EditorGUI.LabelField(subLayout.Get(), m_Module.GetPropertyDisplayName(i)); } Rect layoutRect = layout.Get(); layoutRect.x = layoutRect.x + (layoutRect.width - 100); layoutRect.width = 100; if (GUI.Button(layoutRect, "Edit Selection")) { string[] propertyNamesForReference = GetPropertyNames(new SerializedObject(m_Module.ReferenceAssetImporter)); m_Module.GatherPropertiesIfNeeded(); GenericMenu menu = new GenericMenu(); foreach (string propertyName in propertyNamesForReference) { bool isPropertySelected = m_Module.m_ConstrainProperties.Contains(propertyName); string propertyDisplayName = m_Module.GetPropertyDisplayName(propertyName); menu.AddItem(new GUIContent(propertyDisplayName), isPropertySelected, TogglePropertyConstraintSelected, propertyDisplayName); } menu.ShowAsContext(); } }
public void Draw(SerializedObject moduleObject, ControlRect layout) { if (m_ImportTask == null) { m_ImportTask = moduleObject.targetObject as ImporterPropertiesImportTask; if (m_ImportTask == null) { Debug.LogError("SerializedObject must be of type ImporterPropertiesImportTask"); return; } } if (m_ImporterReferenceSerializedProperty == null || m_ConstrainPropertiesSerializedProperty == null) { m_ImporterReferenceSerializedProperty = moduleObject.FindProperty("m_ImporterReference"); m_ConstrainPropertiesSerializedProperty = moduleObject.FindProperty("m_ConstrainProperties"); if (m_ImporterReferenceSerializedProperty == null || m_ConstrainPropertiesSerializedProperty == null) { Debug.LogError("Invalid properties for ImporterPropertiesImportTask"); return; } } if (m_ImporterReferenceSerializedProperty != null) { ReferenceObjectGUI(layout); } if (m_ImporterReferenceSerializedProperty.objectReferenceValue != null) { ConstrainToPropertiesGUI(layout); } else { Rect r = layout.Get(25); EditorGUI.HelpBox(r, "No template Object to constrain properties on.", MessageType.Warning); } }
protected override void OnMouseMove(MouseEventArgs e) { //鼠标在控制按钮区域 if (SplitterRectangle.Contains(e.Location)) { if (ControlRect.Contains(e.Location)) { //如果拆分器可移动,则鼠标在控制按钮范围内时临时关闭拆分器 if (!IsSplitterFixed) { IsSplitterFixed = true; _isSplitterFixed = false; } Cursor = Cursors.Hand; _mouseState = MouseState.Hover; Invalidate(ControlRect); } else { //如果拆分器为临时关闭,则开启拆分器 if (!_isSplitterFixed) { IsSplitterFixed = false; Cursor = Orientation == Orientation.Horizontal ? Cursors.HSplit : Cursors.VSplit; } else { Cursor = Cursors.Default; } _mouseState = MouseState.Normal; Invalidate(ControlRect); } } base.OnMouseMove(e); }
internal static void SetHandler(ControlRect rect, AnimeEvent animeEvent) { switch (animeEvent) { case AnimeEvent.MouseEnter: rect.MouseEnter += ctrlMouseEnter; break; case AnimeEvent.MouseLeave: rect.MouseLeave += ctrlMouseLeave; break; case AnimeEvent.Click: rect.Click += ctrlClick; break; case AnimeEvent.MouseDonw: rect.MouseDown += ctrlMouseDown; break; case AnimeEvent.MouseUp: rect.MouseUp += ctrlMouseUp; break; case AnimeEvent.DoubleClick: rect.DoubleClick += ctrlDoubleClick; break; case AnimeEvent.DragEnter: rect.DragEnter += ctrlDragEnter; break; case AnimeEvent.DragLeave: rect.DragLeave += ctrlDragLeave; break; case AnimeEvent.DragDrop: rect.DragDrop += ctrlDragDrop; break; case AnimeEvent.Enter: case AnimeEvent.GotFocus: rect.Enter += ctrlEnter; break; case AnimeEvent.Leave: case AnimeEvent.LostFocus: rect.Leave += ctrlLeave; break; case AnimeEvent.KeyDown: rect.KeyDown += ctrlKeyDown; break; case AnimeEvent.KeyUp: rect.KeyUp += ctrlKeyUp; break; case AnimeEvent.MouseWheel: rect.MouseWheel += ctrlMouseWheel; break; case AnimeEvent.TextChanged: //rect.TextChanged += ctrlTextChanged; break; case AnimeEvent.Visible: rect.VisibleChanged += ctrlVisibleChanged; break; case AnimeEvent.Enabled: case AnimeEvent.Disabled: rect.EnabledChanged += ctrlEnabledChanged; break; } }
protected override void InitializeControl() { base.InitializeControl(); m_container = new ControlRect(); m_container.Transparent = true; m_container.Alignment = RectAlignment.Fill; this.Add(m_container); m_HorizontalScrollHolder = new DrawRect(); m_HorizontalScrollHolder.Alignment = RectAlignment.Bottom; m_HorizontalScrollHolder.Size = new Size(14, 14); m_HorizontalScrollHolder.Transparent = true; var hcornerRect = new DrawRect(); hcornerRect.Name = "cornerRect"; hcornerRect.Size = new Size(14, 14); hcornerRect.Alignment = RectAlignment.Right; hcornerRect.Transparent = true; hcornerRect.Visible = false; var hp = hcornerRect.Painters[0].Add(BasePainters.FillRect, "cornerPaint"); hp.Value["Color"] = Property["Color"]; m_HorizontalScrollHolder.Add(hcornerRect); m_HorizontalScrollHolder.Visible = false; var hscroll = new DrawScroll(); hscroll.Name = "HorizontalScroll"; hscroll.Size = new Size(14, 14); hscroll.Value["Color"] = Property["Color"]; hscroll.Align = Orientation.Horizontal; hscroll.Alignment = RectAlignment.Fill; hscroll.Visible = true; hscroll.Value["Position"] = Property["ScrollHorizontalPos"]; m_HorizontalScrollHolder.Add(hscroll); this.Insert(0, m_HorizontalScrollHolder); m_VerticalScrollHolder = new DrawRect(); m_VerticalScrollHolder.Alignment = RectAlignment.Right; m_VerticalScrollHolder.Size = new Size(14, 14); m_VerticalScrollHolder.Transparent = true; var vcornerRect = new DrawRect(); vcornerRect.Name = "cornerRect"; vcornerRect.Size = new Size(14, 14); vcornerRect.Alignment = RectAlignment.Bottom; vcornerRect.Transparent = true; vcornerRect.Visible = false; var vp = vcornerRect.Painters[0].Add(BasePainters.FillRect, "cornerPaint"); vp.Value["Color"] = Property["Color"]; m_VerticalScrollHolder.Add(vcornerRect); m_VerticalScrollHolder.Visible = false; var vscroll = new DrawScroll(); vscroll.Name = "VerticalScroll"; vscroll.Size = new Size(14, 14); vscroll.Value["Color"] = Property["Color"]; vscroll.Align = Orientation.Vertical; vscroll.Alignment = RectAlignment.Fill; vscroll.Visible = true; vscroll.Value["Position"] = Property["ScrollVerticalPos"]; m_VerticalScrollHolder.Add(vscroll); this.Insert(0, m_VerticalScrollHolder); InitProperties(); m_container.Resize += new ItemChangeHandler(Scrollable_Resize); m_container.PostMouseWheel += new MouseEventHandler(Scrollable_MouseWheel); }
public override void OnInspectorGUI() { if (m_Profile == null) { m_Profile = (ImportDefinitionProfile)target; } Rect viewRect = GUILayoutUtility.GetRect(EditorGUIUtility.currentViewWidth - 23, 0); ControlRect layout = new ControlRect(viewRect.x, viewRect.y, viewRect.width); layout.Space(10); EditorGUI.PropertyField(layout.Get(), m_FolderOnly, new GUIContent("Lock to folder", "Include a filter to limit this profile to this profile only")); EditorGUI.PropertyField(layout.Get(), m_ProcessOnImport, new GUIContent("Process On Import")); EditorGUI.PropertyField(layout.Get(), m_SortIndex, new GUIContent("Sort Index")); layout.Space(10); EditorGUI.LabelField(layout.Get(), "Search Filter's"); List <Filter> filters = m_Profile.GetFilters(true); if (filters == null) { filters = new List <Filter>(); } int filterCount = filters.Count; if (m_FolderOnly.boolValue) { filterCount++; } Rect boxAreaRect = layout.Get((16 * filterCount) + (3 * filterCount) + 6); GUI.Box(boxAreaRect, GUIContent.none); ControlRect subLayout = new ControlRect(boxAreaRect.x + 3, boxAreaRect.y + 3, boxAreaRect.width - 6, 16); subLayout.padding = 3; int removeAt = -1; int size = m_FiltersListProperty.arraySize; if (m_FolderOnly.boolValue) { size++; } for (int i = 0; i < size; ++i) { Rect segmentRect = subLayout.Get(); segmentRect.x += 3; segmentRect.width -= 6; float segWidth = (segmentRect.width - segmentRect.height) / 3; segmentRect.width = segWidth - 3; float startX = segmentRect.x; if (m_FolderOnly.boolValue && i == size - 1) { EditorGUI.BeginDisabledGroup(true); EditorGUI.EnumPopup(segmentRect, Filter.ConditionTarget.Directory); segmentRect.x = startX + segWidth; EditorGUI.EnumPopup(segmentRect, Filter.Condition.StartsWith); segmentRect.x = startX + (segWidth * 2); EditorGUI.TextField(segmentRect, m_Profile.DirectoryPath); EditorGUI.EndDisabledGroup(); } else { SerializedProperty filterProperty = m_FiltersListProperty.GetArrayElementAtIndex(i); filterProperty.NextVisible(true); do { if (filterProperty.propertyType == SerializedPropertyType.Enum && filterProperty.name == "m_Target") { segmentRect.x = startX; EditorGUI.PropertyField(segmentRect, filterProperty, GUIContent.none); } else if (filterProperty.propertyType == SerializedPropertyType.Enum && filterProperty.name == "m_Condition") { segmentRect.x = startX + segWidth; EditorGUI.PropertyField(segmentRect, filterProperty, GUIContent.none); } else if (filterProperty.propertyType == SerializedPropertyType.String && filterProperty.name == "m_Wildcard") { segmentRect.x = startX + (segWidth * 2); EditorGUI.PropertyField(segmentRect, filterProperty, GUIContent.none); } } while(filterProperty.NextVisible(false)); segmentRect.x = startX + (segWidth * 3); segmentRect.width = segmentRect.height; if (GUI.Button(segmentRect, "-")) { removeAt = i; } } } if (removeAt >= 0) { m_FiltersListProperty.DeleteArrayElementAtIndex(removeAt); } Rect layoutRect = layout.Get(); layoutRect.x = layoutRect.x + (layoutRect.width - 40); layoutRect.width = 40; if (GUI.Button(layoutRect, "Add")) { m_FiltersListProperty.arraySize += 1; } layout.Space(20); EditorGUI.LabelField(layout.Get(), "", UnityEngine.GUI.skin.horizontalSlider); size = m_Tasks.arraySize; for (int i = 0; i < size; ++i) { if (m_ImportTaskFoldoutStates.Count - 1 < i) { m_ImportTaskFoldoutStates.Add(true); } SerializedProperty taskProperty = m_Tasks.GetArrayElementAtIndex(i); BaseImportTask importTask = taskProperty.objectReferenceValue as BaseImportTask; if (importTask == null) { continue; } if (i > 0) { layout.Space(10); } Rect headerRect = layout.Get(20); m_ImportTaskFoldoutStates[i] = EditorGUI.Foldout(headerRect, m_ImportTaskFoldoutStates[i], importTask.name, true); Event current = Event.current; if (headerRect.Contains(current.mousePosition)) { if ((current.type == EventType.MouseDown && current.button == 1) || current.type == EventType.ContextClick) { GenericMenu menu = new GenericMenu(); if (i == 0) { menu.AddDisabledItem(new GUIContent("Move Up")); } else { menu.AddItem(new GUIContent("Move Up"), false, MoveTaskUpCallback, i); } if (i == size - 1) { menu.AddDisabledItem(new GUIContent("Move Down")); } else { menu.AddItem(new GUIContent("Move Down"), false, MoveTaskDownCallback, i); } menu.AddSeparator(""); menu.AddItem(new GUIContent("Delete Import Task"), false, RemoveTaskCallback, i); menu.ShowAsContext(); current.Use(); } else if (current.type == EventType.MouseDown && current.button == 0) { m_ImportTaskFoldoutStates[i] = !m_ImportTaskFoldoutStates[i]; } } if (m_ImportTaskFoldoutStates[i]) { layout.BeginArea(5, 5); importTask.DrawGUI(layout); GUI.depth = GUI.depth - 1; GUI.Box(layout.EndArea(), ""); GUI.depth = GUI.depth + 1; } } if (size > 0) { EditorGUI.LabelField(layout.Get(), "", UnityEngine.GUI.skin.horizontalSlider); } layoutRect = layout.Get(); if (layoutRect.width > 120) { layoutRect.x = layoutRect.x + (layoutRect.width - 120); layoutRect.width = 120; } if (EditorGUI.DropdownButton(layoutRect, new GUIContent("Add Import Task", "Add new Task to this Definition."), FocusType.Keyboard)) { var menu = new GenericMenu(); for (int i = 0; i < m_ImportTaskTypes.Count; i++) { var type = m_ImportTaskTypes[i]; menu.AddItem(new GUIContent(type.Name, ""), false, OnAddImportTask, type); } menu.ShowAsContext(); } GUILayoutUtility.GetRect(viewRect.width, layoutRect.y + layoutRect.height); serializedObject.ApplyModifiedProperties(); }
private void button1_Click(object sender, EventArgs e) { var rect = TestControl.MainRect; rect.BorderSize = 5; rect.AnimeChildAlign = true; topRect = rect.Add(RectAlignment.Top, 20); topRect.AnimeAlign = true; topRect.AddValidatedProperty("Color", Color.Red); topRect.Painters[0].Add(BasePainters.FillRect).Value["Color"] = topRect.Property["Color"]; { var r2 = topRect.Add(RectAlignment.Right, 30); r2.AddValidatedProperty("Color", Color.Indigo); r2.Painters[0].Add(BasePainters.FillRect).Value["Color"] = r2.Property["Color"]; controlRect = topRect.Add(RectAlignment.Right, 60); TextBox txt = new TextBox(); TestControl.Controls.Add(txt); controlRect.Control = txt; r2 = topRect.Add(RectAlignment.Left, 30); r2.AddValidatedProperty("Color", Color.Aqua); r2.Painters[0].Add(BasePainters.FillRect).Value["Color"] = r2.Property["Color"]; r2 = topRect.Add(RectAlignment.Left, 30); r2.AddValidatedProperty("Color", Color.Green); r2.Painters[0].Add(BasePainters.FillRect).Value["Color"] = r2.Property["Color"]; yellowRect = topRect.Add(RectAlignment.Left, 30); yellowRect.AddValidatedProperty("Color", Color.Yellow); yellowRect.Painters[0].Add(BasePainters.FillRect).Value["Color"] = yellowRect.Property["Color"]; r2 = topRect.Add(RectAlignment.Left, 30); r2.AnimeAlign = true; r2.AddValidatedProperty("Color", Color.LightSteelBlue); r2.Painters[0].Add(BasePainters.FillRect).Value["Color"] = r2.Property["Color"]; } var r = rect.Add(RectAlignment.Bottom, 20); r.AddValidatedProperty("Color", Color.Green.BrightColor(40)); r.AddValidatedProperty("Color2", Color.Green); var p = r.Painters[0].Add(BasePainters.FillGradient); p.Value["Color"] = r.Property["Color"]; p.Value["Color2"] = r.Property["Color2"]; { var r2 = r.Add(RectAlignment.Left, 40); r2.AddValidatedProperty("Color", Color.Aqua); r2.Painters[0].Add(BasePainters.FillRect).Value["Color"] = r2.Property["Color"]; r2 = r.Add(RectAlignment.Left, 40); r2.AddValidatedProperty("Color", Color.Green); r2.Painters[0].Add(BasePainters.FillRect).Value["Color"] = r2.Property["Color"]; r2 = r.Add(RectAlignment.Left, 40); r2.AddValidatedProperty("Color", Color.Yellow); r2.Painters[0].Add(BasePainters.FillRect).Value["Color"] = r2.Property["Color"]; r2 = r.Add(RectAlignment.Left, 40); r2.AddValidatedProperty("Color", Color.LightSteelBlue); r2.Painters[0].Add(BasePainters.FillRect).Value["Color"] = r2.Property["Color"]; r2 = r.Add(RectAlignment.Right, 40); r2.AddValidatedProperty("Color", Color.Indigo); r2.Painters[0].Add(BasePainters.FillRect).Value["Color"] = r2.Property["Color"]; } r = rect.Add(RectAlignment.Left, 20); r.AddValidatedProperty("Color", Color.Blue); r.Painters[0].Add(BasePainters.FillRect).Value["Color"] = r.Property["Color"]; r = rect.Add(RectAlignment.Right, 20); r.AddValidatedProperty("Color", Color.Silver); r.AddValidatedProperty("Color2", Color.Gray); r.AddValidatedProperty("Direction", SimpleDirection.Horisontal); p = r.Painters[0].Add(BasePainters.FillGradient); p.Value["Color"] = r.Property["Color"]; p.Value["Color2"] = r.Property["Color2"]; p.Value["Direction"] = r.Property["Direction"]; r = rect.Add(RectAlignment.Right, 20); r.AddValidatedProperty("Color", Color.Maroon); r.AddValidatedProperty("Color2", Color.Maroon.BrightColor(40)); r.AddValidatedProperty("Direction", SimpleDirection.Horisontal); p = r.Painters[0].Add(BasePainters.FillGradient); p.Value["Color"] = r.Property["Color"]; p.Value["Color2"] = r.Property["Color2"]; p.Value["Direction"] = r.Property["Direction"]; backRect = rect.Add(RectAlignment.Fill, 0); backRect.BorderSize = 10; backRect.AddValidatedProperty("Color", Color.Sienna); backRect.AddValidatedProperty("BorderColor", Color.White); backRect.Painters[0].Add(BasePainters.FillRect).Value["Color"] = backRect.Property["Color"]; backRect.Painters[1].Add(BasePainters.Rect).Value["Color"] = backRect.Property["BorderColor"]; { var r2 = backRect.Add(RectAlignment.Fill, 0); r2.AddValidatedProperty("Color", Color.Green.BrightColor(60)); r2.Painters[0].Add(BasePainters.FillRect).Value["Color"] = r2.Property["Color"]; var locationRect = (ControlRect)r2.Add(new Point(70, 100), 80, 80); locationRect.Transparent = true; locationRect.BorderSize = 2; locationRect.AddValidatedProperty("Color", Color.Red.BrightColor(40).Transparent(40)); locationRect.AddValidatedProperty("BorderColor", Color.Brown.DarkColor(20)); locationRect.Painters[0].Add(BasePainters.FillRect).Value["Color"] = locationRect.Property["Color"]; locationRect.Painters[0].Add(BasePainters.Rect).Value["Color"] = locationRect.Property["BorderColor"]; locationRect.AnimeEvent(true).MouseEnter().Change("ContainerRect", new Rectangle(170, 100, 150, 150)); locationRect.AnimeEventQueue().MouseLeave().Wait(Speed.Slow).Change("ContainerRect", new Rectangle(70, 100, 80, 80)); } mouseRect = (ControlRect)rect.Add(new Point(80, 10), 60, 60); mouseRect.Alignment = RectAlignment.Custom; mouseRect.Transparent = true; mouseRect.AddValidatedProperty("Color", Color.Blue.Transparent(50)); mouseRect.Painters[0].Add(BasePainters.FillRect, "r1").Value["Color"] = mouseRect.Property["Color"]; mouseRect.BorderSize = 4; mouseRect.AddValidatedProperty("BorderColor", Color.Navy); mouseRect.Painters[0].Add(BasePainters.Rect, "r2").Value["Color"] = mouseRect.Property["BorderColor"]; mouseRect.AnimeEvent("color").MouseEnter().ChangeDec("Color", Color.Aqua.Transparent(20), Speed.Medium); mouseRect.AnimeEvent("size").MouseEnter().ChangeDec("Rect", new Rectangle(80, 10, 180, 180), Speed.Medium); mouseRect.AnimeEvent("color").MouseLeave().ChangeInc("Color", Color.Blue.Transparent(50), Speed.Medium); mouseRect.AnimeEvent("size").MouseLeave().ChangeDec("Rect", new Rectangle(80, 10, 60, 60), Speed.Medium); mouseRect.Painters["r2"].Value["CornerRadius"] = 2; mouseRect.Painters["r1"].Value["CornerRadius"] = 2; var ctrlRect = rect.Add(new Point(100, 100), 100, 20); var txt2 = new TextBox(); TestControl.Controls.Add(txt2); ctrlRect.Control = txt2; transparentRect = (ControlRect)rect.Add(new Point(40, 40), 80, 80); transparentRect.Alignment = RectAlignment.Custom; transparentRect.Transparent = true; transparentRect.BorderSize = 4; transparentRect.AddValidatedProperty("Color", Color.Green.Transparent(60)); transparentRect.AddValidatedProperty("BorderColor", Color.Green); transparentRect.Painters[0].Add(BasePainters.FillRect, "r1").Value["Color"] = transparentRect.Property["Color"]; transparentRect.Painters[0].Add(BasePainters.Rect, "r2").Value["Color"] = transparentRect.Property["BorderColor"]; transparentRect.Painters["r2"].Value["CornerRadius"] = 5; transparentRect.Painters["r1"].Value["CornerRadius"] = 5; transparentRect.AnimeEvent("color").MouseEnter().Change("Color", Color.Blue.Transparent(80), Speed.Medium); transparentRect.AnimeEvent("color").MouseLeave().Change("Color", Color.Green.Transparent(60), Speed.Medium); transparentRect.AnimeEvent("size").MouseEnter().ChangeDec("Rect", new Rectangle(40, 40, 160, 160), Speed.Medium); transparentRect.AnimeEvent("size").MouseLeave().ChangeDec("Rect", new Rectangle(40, 40, 80, 80), Speed.Medium); // transparentRect.MouseEnter += (s, arg) => { s.SetProperty("Size", new Size(160, 160)); }; // transparentRect.MouseLeave += (s, arg) => { s.SetProperty("Size", new Size(80, 80)); }; rect.Align(); //********** tabDrawControl ************************* tabDrawControl.TabStop = true; rect = tabDrawControl.MainRect; var cr = new ControlRect(new Point(40, 40), 100, 20); rect.Add(cr); cr.AddValidatedProperty("Color", Color.Red.BrightColor(40)); cr.AddValidatedProperty("BorderColor", Color.Maroon); cr.Painters[0].Add(BasePainters.FillRect).Value["Color"] = cr.Property["Color"]; cr.Painters[0].Add(BasePainters.Rect).Value["Color"] = cr.Property["BorderColor"]; cr.TabIndex = 0; cr.TabStop = true; cr.BorderSize = 2; cr.Enter += (s, arg) => { s.SetProperty("Color", Color.Red.BrightColor(80)); }; cr.Leave += (s, arg) => { s.SetProperty("Color", Color.Red.BrightColor(40)); }; cr = new ControlRect(new Point(40, 80), 100, 20); cr.Alignment = RectAlignment.Center; rect.Add(cr); cr.AddValidatedProperty("Color", Color.Green.BrightColor(40)); cr.AddValidatedProperty("BorderColor", Color.Green); cr.Painters[0].Add(BasePainters.FillRect).Value["Color"] = cr.Property["Color"]; cr.Painters[0].Add(BasePainters.Rect).Value["Color"] = cr.Property["BorderColor"]; cr.TabIndex = 1; cr.TabStop = true; cr.BorderSize = 2; cr.Enter += (s, arg) => { s.SetProperty("Color", Color.Green.BrightColor(80)); }; cr.Leave += (s, arg) => { s.SetProperty("Color", Color.Green.BrightColor(40)); }; cr = new ControlRect(new Point(40, 120), 100, 20); rect.Add(cr); cr.AddValidatedProperty("Color", Color.Blue.BrightColor(40)); cr.AddValidatedProperty("BorderColor", Color.Navy); cr.Painters[0].Add(BasePainters.FillRect).Value["Color"] = cr.Property["Color"]; cr.Painters[0].Add(BasePainters.Rect).Value["Color"] = cr.Property["BorderColor"]; cr.TabIndex = 2; cr.TabStop = true; cr.BorderSize = 2; cr.Enter += (s, arg) => { s.SetProperty("Color", Color.Blue.BrightColor(80)); }; cr.Leave += (s, arg) => { s.SetProperty("Color", Color.Blue.BrightColor(40)); }; var bt = new DrawButton(); drowBt = bt; bt.Pos = new Point(40, 160); bt.Size = new Size(100, 23); bt.TabIndex = 3; //bt.Color = Color.Aqua; bt.MouseOverColor = Color.Blue.BrightColor(70); bt.UseMouseOverColor = true; bt.BorderSize = 2; bt.CornerRadius = 2; bt.Gradient = true; bt.Transparent = true; bt.DrawFocus = true; bt.Switch = false; bt.Flat = false; bt.Text = "Test"; bt.TextColor = Color.Navy; rect.Add(bt); var scroll = new DrawScroll(); scroll.Size = new Size(14, 14); scroll.Alignment = RectAlignment.Right; scroll.Align = Orientation.Vertical; scroll.Color = Color.Blue.BrightColor(75); scroll.MaxPosition = 100; scroll.Property["Position"].AnyChanged += () => { bt.Text = scroll.Position + " %"; }; scroll.ScrollButtonAutoSize = true; //scroll.BorderSize = 1; rect.Add(scroll); var crTxt = new TextBox(); tabDrawControl.Controls.Add(crTxt); cr.Control = crTxt; crTxt.KeyDown += (s, arg) => { if (arg.KeyCode == Keys.Enter) { scroll.Position = int.Parse(crTxt.Text); } }; //--------- Scrollable Scrollable sRect = new Scrollable(); sRect.Alignment = RectAlignment.Fill; ScrollableContainer.MainRect.Add(sRect); sRect.ScrollHeight = 400; sRect.ScrollWidth = 400; sRect.Transparent = true; sRect.VirtualScroll = false; sRect.Container.Add(CreateSimple(new Point(50, 50), 80, 23, Color.Lime)); sRect.Container.Add(CreateSimple(new Point(100, 100), 80, 23, Color.Aqua)); sRect.Container.Add(CreateSimple(new Point(250, 250), 80, 23, Color.Yellow)); sRect.Container.Add(CreateSimple(new Point(300, 300), 80, 23, Color.Blue.BrightColor(30))); var top = CreateSimple(new Point(0, 0), 20, 20, Color.Orange); top.Alignment = RectAlignment.Top; sRect.Container.Add(top); var bottom = CreateSimple(new Point(0, 0), 20, 20, Color.Green); bottom.Alignment = RectAlignment.Bottom; sRect.Container.Add(bottom); var right = CreateSimple(new Point(0, 0), 20, 20, Color.Blue); right.Alignment = RectAlignment.Right; sRect.Container.Add(right); var left = CreateSimple(new Point(0, 0), 20, 20, Color.Silver); left.Alignment = RectAlignment.Left; sRect.Container.Add(left); }
public void Draw(SerializedObject moduleObject, ControlRect layout) { if (m_ImportTask == null) { m_ImportTask = moduleObject.targetObject as PreprocessorImportTask; if (m_ImportTask == null) { Debug.LogError("SerializedObject must be of type PreprocessorImportTask"); return; } } if (m_MethodSerializedProperty == null || m_DataSerializedProperty == null) { List <string> propertyNames = new List <string> { "m_MethodString", "m_Data" }; List <SerializedProperty> properties = SerializationUtilities.GetSerialisedPropertyCopiesForObject(moduleObject, propertyNames); m_MethodSerializedProperty = properties[0]; m_DataSerializedProperty = properties[1]; if (m_MethodSerializedProperty == null || m_DataSerializedProperty == null) { Debug.LogError("Invalid properties for PreprocessorImportTask"); return; } } List <ProcessorMethodInfo> methods = PreprocessorImplementorCache.Methods; GUIContent[] contents = new GUIContent[methods.Count + 1]; contents[0] = new GUIContent("None Selected"); int selectedMethod = 0; for (int i = 1; i < methods.Count + 1; ++i) { contents[i] = new GUIContent(methods[i - 1].TypeName); if (!string.IsNullOrEmpty(m_ImportTask.methodString)) { if (string.Equals(m_ImportTask.methodString, methods[i - 1].TypeName + ", " + methods[i - 1].AssemblyName)) { selectedMethod = i; } } } if (!string.IsNullOrEmpty(m_ImportTask.methodString) && selectedMethod == 0) { Debug.LogError("methodString not found in project : " + m_ImportTask.methodString); } EditorGUI.BeginChangeCheck(); selectedMethod = EditorGUI.Popup(layout.Get(), new GUIContent("Preprocessor methodString"), selectedMethod, contents); if (EditorGUI.EndChangeCheck()) { if (selectedMethod == 0) { m_MethodSerializedProperty.stringValue = ""; } else { int id = selectedMethod - 1; if (id >= 0) { m_MethodSerializedProperty.stringValue = methods[id].TypeName + ", " + methods[id].AssemblyName; m_ImportTask.m_ProcessorMethodInfo = null; } } } EditorGUI.PropertyField(layout.Get(), m_DataSerializedProperty); }
public override void OnInspectorGUI() { if (m_Profile == null) { m_Profile = (AuditProfile)target; } Rect viewRect = EditorGUILayout.GetControlRect(); ControlRect layout = new ControlRect(viewRect.x, viewRect.y, viewRect.width); layout.Space(10); EditorGUI.PropertyField(layout.Get(), m_ProcessOnImport, new GUIContent("Process On Import")); layout.Space(10); EditorGUI.LabelField(layout.Get(), "Search Filter's:"); if (m_Profile.m_Filters == null) { m_Profile.m_Filters = new List <Filter>(); } Rect boxAreaRect = layout.Get((16 * m_Profile.m_Filters.Count) + (3 * m_Profile.m_Filters.Count) + 6); GUI.Box(boxAreaRect, GUIContent.none); ControlRect subLayout = new ControlRect(boxAreaRect.x + 3, boxAreaRect.y + 3, boxAreaRect.width - 6, 16); subLayout.padding = 3; int removeAt = -1; for (int i = 0; i < filtersListProperty.arraySize; ++i) { Rect segmentRect = subLayout.Get(); segmentRect.x += 3; segmentRect.width -= 6; float segWidth = (segmentRect.width - segmentRect.height) / 3; segmentRect.width = segWidth - 3; float startX = segmentRect.x; // TODO how do you get properties for this without looping all??? SerializedProperty filterProperty = filtersListProperty.GetArrayElementAtIndex(i); filterProperty.NextVisible(true); do { if (filterProperty.propertyType == SerializedPropertyType.Enum && filterProperty.name == "m_Target") { segmentRect.x = startX; EditorGUI.PropertyField(segmentRect, filterProperty, GUIContent.none); } else if (filterProperty.propertyType == SerializedPropertyType.Enum && filterProperty.name == "m_Condition") { segmentRect.x = startX + segWidth; EditorGUI.PropertyField(segmentRect, filterProperty, GUIContent.none); } else if (filterProperty.propertyType == SerializedPropertyType.String && filterProperty.name == "m_Wildcard") { segmentRect.x = startX + (segWidth * 2); EditorGUI.PropertyField(segmentRect, filterProperty, GUIContent.none); } } while(filterProperty.NextVisible(false)); segmentRect.x = startX + (segWidth * 3); segmentRect.width = segmentRect.height; if (GUI.Button(segmentRect, "-")) { removeAt = i; } } if (removeAt >= 0) { filtersListProperty.DeleteArrayElementAtIndex(removeAt); } Rect layoutRect = layout.Get(); layoutRect.x = layoutRect.x + (layoutRect.width - 40); layoutRect.width = 40; if (GUI.Button(layoutRect, "Add")) { filtersListProperty.arraySize += 1; } layout.Space(20); // TODO do the rest as modules that can be added propertiesModuleInspector.Draw(importerModule, layout); serializedObject.ApplyModifiedProperties(); }
private void AutoScaleControl(Control mForm, float wScale, float hScale) { float ctrlLeft, ctrlTop, ctrlWidth, ctrlHeight; float ctrlFontSize, hSize, wSize; List <ControlRect> Ctrl = new List <ControlRect>(); foreach (Control c in mForm.Controls) { //在_oldCtrl 中查询出控件名称相同的控件,并返回对象 ControlRect shortDigits = _oldCtrl.Where((p) => p.name == c.Name).ToList().FirstOrDefault(); //获取左边框的长度 ctrlLeft = shortDigits.Left; //获取上边框的长度 ctrlTop = shortDigits.Top; //获取宽度 ctrlWidth = shortDigits.Width; //获取高度 ctrlHeight = shortDigits.Height; //获取字体大小 ctrlFontSize = shortDigits.Size; //通过获取的比率相乘计算出要显示的x,y轴 c.Left = (int)Math.Round((ctrlLeft * wScale)); if (c.Left < 0) { c.Left = 0; } c.Top = (int)Math.Round((ctrlTop * hScale)); if (c.Top < 0) { c.Top = 0; } //保存计算结果后的坐标和大小,当下次进行计算是使用该浮点型进行计算 //确保控件不会错乱 //设置高度和宽度 c.Width = (int)Math.Round((ctrlWidth * wScale)); c.Height = (int)Math.Round((ctrlHeight * hScale)); //通过比率获取放大或缩小后的字体大小并进行设置 wSize = ctrlFontSize * wScale; hSize = ctrlFontSize * hScale; if (hSize < 7) { hSize = 7; } if (wSize < 7) { wSize = 7; } c.Font = new Font(c.Font.Name, Math.Min(hSize, wSize), c.Font.Style, c.Font.Unit); _ctrlNo++; // 先缩放控件本身 再缩放子控件 if (c.Controls.Count > 0) { AutoScaleControl(c, wScale, hScale); } shortDigits.Top = ctrlTop * hScale; shortDigits.Left = ctrlTop * wScale; shortDigits.Width = ctrlTop * wScale; shortDigits.Height = ctrlTop * hScale; //Ctrl.Add(shortDigits); } }
private static extern int GetWindowRect(IntPtr hwnd, [Out] ControlRect lpRect);
/// <summary> /// Creates the graphics. This functin is automatically called when /// you use the Graphics property for the first time. /// </summary> protected void CreateScreenGraphics() { if (ScreenGraphics != null) { DestroyGraphics(false); } _ScreenDC = GetDC(IntPtr.Zero); // DeviceContext pro celou obrazovku (Screen) var controlHandle = OwnerControl.Handle; switch (Coordinates) { case CoordinateType.ControlClient: _ControlRegion = GetVisibleRgn(controlHandle); // VisibleRegion = co z controlu je viditelno SelectClipRgn(_ScreenDC, _ControlRegion); // Clip na ClientBounds & VisibleRegion Rectangle absClientBounds = ClientAbsoluteBounds; // Specialita starších Windows: if (VersionIs9xMe) { OffsetClipRgn(_ScreenDC, absClientBounds.X, absClientBounds.Y); } // Posunout souřadný systém: SetWindowOrgEx(_ScreenDC, -absClientBounds.X, -absClientBounds.Y, IntPtr.Zero); ScreenArea = absClientBounds; ScreenGraphics = Graphics.FromHdc(_ScreenDC); Rectangle clientClip = new Rectangle(0, 0, absClientBounds.Width, absClientBounds.Height); ScreenGraphics.IntersectClip(clientClip); break; case CoordinateType.ScreenControl: _ControlRegion = GetVisibleRgn(controlHandle); // obtain visible clipping region for the window SelectClipRgn(_ScreenDC, _ControlRegion); // clip the DC with the region _ControlRect = new ControlRect(); GetWindowRect(controlHandle, _ControlRect); ScreenArea = Rectangle.FromLTRB(_ControlRect.left, _ControlRect.top, _ControlRect.right, _ControlRect.bottom); // Specialita starších Windows: if (VersionIs9xMe) { OffsetClipRgn(_ScreenDC, _ControlRect.left, _ControlRect.top); } // Posunout souřadný systém: SetWindowOrgEx(_ScreenDC, -_ControlRect.left, -_ControlRect.top, IntPtr.Zero); ScreenGraphics = Graphics.FromHdc(_ScreenDC); break; case CoordinateType.AllScreen: ScreenGraphics = Graphics.FromHdc(_ScreenDC); ScreenArea = Rectangle.Truncate(ScreenGraphics.ClipBounds); break; } }