Skip to content

Commit 1f913bf

Browse files
author
Pavel Kovalenko
committed
Add new xrSdkControls library that will replace editor_controls.
1 parent 948a076 commit 1f913bf

File tree

8 files changed

+1232
-1
lines changed

8 files changed

+1232
-1
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace XRay.SdkControls
2+
{
3+
public interface IIncrementable
4+
{
5+
void Increment(float value);
6+
}
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace XRay.SdkControls
2+
{
3+
public interface IMouseListener
4+
{
5+
void OnDoubleClick(PropertyGrid grid);
6+
}
7+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace XRay.SdkControls
2+
{
3+
public interface IProperty
4+
{
5+
object GetValue();
6+
void SetValue(object value);
7+
}
8+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using Flobbster.Windows.Forms;
2+
3+
namespace XRay.SdkControls
4+
{
5+
public interface IPropertyContainer
6+
{
7+
IProperty GetProperty(PropertySpec description);
8+
}
9+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("SdkControls")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("GSC Game World")]
12+
[assembly: AssemblyProduct("SdkControls")]
13+
[assembly: AssemblyCopyright("Copyright © GSC Game World 2014")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("2258d216-962a-44c0-bda1-0d218f8ea792")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
using Flobbster.Windows.Forms;
2+
using Microsoft.Win32;
3+
using System;
4+
using System.ComponentModel;
5+
using System.Diagnostics;
6+
using System.Drawing;
7+
using System.Reflection;
8+
using System.Windows.Forms;
9+
10+
namespace XRay.SdkControls
11+
{
12+
public class PropertyGrid : System.Windows.Forms.PropertyGrid
13+
{
14+
private Control view;
15+
private Point prevLocation;
16+
17+
public PropertyGrid()
18+
{
19+
Initialize();
20+
SetupEventHandlers();
21+
}
22+
23+
private int GetSplitterWidth()
24+
{
25+
Type gridType = view.GetType();
26+
FieldInfo field = gridType.GetField("labelWidth", BindingFlags.NonPublic | BindingFlags.Instance);
27+
Object value = field.GetValue(view);
28+
return value is int ? (int)value : 0;
29+
}
30+
31+
public void Initialize()
32+
{
33+
foreach (Control control in Controls)
34+
{
35+
if (control.GetType().Name.ToUpper() == "PROPERTYGRIDVIEW")
36+
{
37+
view = control;
38+
break;
39+
}
40+
}
41+
}
42+
43+
public void OnChildControlMouseDoubleClick(object sender, MouseEventArgs e)
44+
{
45+
if (SelectedObject == null || SelectedGridItem == null)
46+
return;
47+
var descriptor_raw = SelectedGridItem.PropertyDescriptor;
48+
Debug.Assert(descriptor_raw != null);
49+
var descriptor = descriptor_raw as PropertyBag.PropertySpecDescriptor;
50+
var container = descriptor.bag as IPropertyContainer;
51+
IProperty property = container.GetProperty(descriptor.item);
52+
var mouseEvents = property as IMouseListener;
53+
if (mouseEvents == null)
54+
return;
55+
mouseEvents.OnDoubleClick(this);
56+
}
57+
58+
public void OnChildControlMouseMove(object sender, MouseEventArgs e)
59+
{
60+
if (e.Button != MouseButtons.Middle)
61+
{
62+
prevLocation = e.Location;
63+
return;
64+
}
65+
if (e.Location.X == prevLocation.X)
66+
return;
67+
if (SelectedObject == null)
68+
return;
69+
if (SelectedGridItem == null)
70+
return;
71+
PropertyDescriptor rawDescriptor = SelectedGridItem.PropertyDescriptor;
72+
if (rawDescriptor == null)
73+
return;
74+
var descriptor = rawDescriptor as PropertyBag.PropertySpecDescriptor;
75+
var container = descriptor.bag as IPropertyContainer;
76+
IProperty rawProperty = container.GetProperty(descriptor.item);
77+
Debug.Assert(rawProperty != null);
78+
var incrementable = rawProperty as IIncrementable;
79+
if (incrementable == null)
80+
return;
81+
incrementable.Increment(e.Location.X - prevLocation.X);
82+
Refresh();
83+
prevLocation = e.Location;
84+
}
85+
86+
public void OnChildControlMouseDown(object sender, MouseEventArgs e)
87+
{
88+
if (e.Button != MouseButtons.Middle)
89+
return;
90+
prevLocation = e.Location;
91+
}
92+
93+
public void SetupEventHandlers()
94+
{
95+
foreach (Control control in Controls)
96+
{
97+
control.MouseDoubleClick += OnChildControlMouseDoubleClick;
98+
control.MouseMove += OnChildControlMouseMove;
99+
control.MouseDown += OnChildControlMouseDown;
100+
}
101+
}
102+
103+
public void save(RegistryKey root, string key)
104+
{
105+
RegistryKey grid = root.CreateSubKey(key);
106+
grid.SetValue("Splitter", GetSplitterWidth());
107+
grid.Close();
108+
}
109+
110+
public void load(RegistryKey root, string key)
111+
{
112+
RegistryKey grid = root.OpenSubKey(key);
113+
if (grid == null)
114+
return;
115+
int position = GetRegValue(grid, "Splitter", GetSplitterWidth());
116+
grid.Close();
117+
Type grid_type = view.GetType();
118+
FieldInfo field = grid_type.GetField("labelWidth", BindingFlags.NonPublic | BindingFlags.Instance);
119+
field.SetValue(view, position);
120+
}
121+
122+
private static T GetRegValue<T>(RegistryKey key, string name, T defaultValue)
123+
{
124+
object value = key.GetValue(name);
125+
if (value == null)
126+
return defaultValue;
127+
return (T)value;
128+
}
129+
}
130+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<ImportGroup Label="PropertySheets">
5+
<Import Project="$(SolutionDir)Common.props" />
6+
</ImportGroup>
7+
<PropertyGroup>
8+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
9+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
10+
<ProjectGuid>{E9DC16A3-D0FA-4924-AF6E-F6FDF3EA0661}</ProjectGuid>
11+
<OutputType>Library</OutputType>
12+
<AppDesignerFolder>Properties</AppDesignerFolder>
13+
<RootNamespace>XRay.SdkControls</RootNamespace>
14+
<AssemblyName>xrSdkControls</AssemblyName>
15+
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
16+
<FileAlignment>512</FileAlignment>
17+
</PropertyGroup>
18+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
19+
<DebugSymbols>true</DebugSymbols>
20+
<DebugType>full</DebugType>
21+
<Optimize>false</Optimize>
22+
<OutputPath>$(xrBinDir)</OutputPath>
23+
<IntermediateOutputPath>$(xrIntDir)$(ProjectName)\</IntermediateOutputPath>
24+
<DefineConstants>DEBUG;TRACE</DefineConstants>
25+
<ErrorReport>prompt</ErrorReport>
26+
<WarningLevel>4</WarningLevel>
27+
</PropertyGroup>
28+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
29+
<DebugType>pdbonly</DebugType>
30+
<Optimize>true</Optimize>
31+
<OutputPath>$(xrBinDir)</OutputPath>
32+
<IntermediateOutputPath>$(xrIntDir)$(ProjectName)\</IntermediateOutputPath>
33+
<DefineConstants>TRACE</DefineConstants>
34+
<ErrorReport>prompt</ErrorReport>
35+
<WarningLevel>4</WarningLevel>
36+
</PropertyGroup>
37+
<ItemGroup>
38+
<Reference Include="Flobbster.Windows.Forms.PropertyGrid">
39+
<HintPath>$(xrSdkDir)binaries\Flobbster.Windows.Forms.PropertyGrid.dll</HintPath>
40+
</Reference>
41+
<Reference Include="System" />
42+
<Reference Include="System.Core" />
43+
<Reference Include="System.Drawing" />
44+
<Reference Include="System.Windows.Forms" />
45+
<Reference Include="System.Xml.Linq" />
46+
<Reference Include="System.Data.DataSetExtensions" />
47+
<Reference Include="Microsoft.CSharp" />
48+
<Reference Include="System.Data" />
49+
<Reference Include="System.Xml" />
50+
</ItemGroup>
51+
<ItemGroup>
52+
<Compile Include="PropertyGrid.cs">
53+
<SubType>Component</SubType>
54+
</Compile>
55+
<Compile Include="Properties\AssemblyInfo.cs" />
56+
<Compile Include="IPropertyContainer.cs" />
57+
<Compile Include="IIncrementable.cs" />
58+
<Compile Include="IMouseListener.cs" />
59+
<Compile Include="IProperty.cs" />
60+
</ItemGroup>
61+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
62+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
63+
Other similar extension points exist, see Microsoft.Common.targets.
64+
<Target Name="BeforeBuild">
65+
</Target>
66+
<Target Name="AfterBuild">
67+
</Target>
68+
-->
69+
</Project>

0 commit comments

Comments
 (0)