-
-
Notifications
You must be signed in to change notification settings - Fork 466
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new xrSdkControls library that will replace editor_controls.
- Loading branch information
Pavel Kovalenko
committed
Oct 18, 2014
1 parent
948a076
commit 1f913bf
Showing
8 changed files
with
1,232 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace XRay.SdkControls | ||
{ | ||
public interface IIncrementable | ||
{ | ||
void Increment(float value); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace XRay.SdkControls | ||
{ | ||
public interface IMouseListener | ||
{ | ||
void OnDoubleClick(PropertyGrid grid); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace XRay.SdkControls | ||
{ | ||
public interface IProperty | ||
{ | ||
object GetValue(); | ||
void SetValue(object value); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using Flobbster.Windows.Forms; | ||
|
||
namespace XRay.SdkControls | ||
{ | ||
public interface IPropertyContainer | ||
{ | ||
IProperty GetProperty(PropertySpec description); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
|
||
// General Information about an assembly is controlled through the following | ||
// set of attributes. Change these attribute values to modify the information | ||
// associated with an assembly. | ||
[assembly: AssemblyTitle("SdkControls")] | ||
[assembly: AssemblyDescription("")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("GSC Game World")] | ||
[assembly: AssemblyProduct("SdkControls")] | ||
[assembly: AssemblyCopyright("Copyright © GSC Game World 2014")] | ||
[assembly: AssemblyTrademark("")] | ||
[assembly: AssemblyCulture("")] | ||
|
||
// Setting ComVisible to false makes the types in this assembly not visible | ||
// to COM components. If you need to access a type in this assembly from | ||
// COM, set the ComVisible attribute to true on that type. | ||
[assembly: ComVisible(false)] | ||
|
||
// The following GUID is for the ID of the typelib if this project is exposed to COM | ||
[assembly: Guid("2258d216-962a-44c0-bda1-0d218f8ea792")] | ||
|
||
// Version information for an assembly consists of the following four values: | ||
// | ||
// Major Version | ||
// Minor Version | ||
// Build Number | ||
// Revision | ||
// | ||
// You can specify all the values or you can default the Build and Revision Numbers | ||
// by using the '*' as shown below: | ||
// [assembly: AssemblyVersion("1.0.*")] | ||
[assembly: AssemblyVersion("1.0.0.0")] | ||
[assembly: AssemblyFileVersion("1.0.0.0")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
using Flobbster.Windows.Forms; | ||
using Microsoft.Win32; | ||
using System; | ||
using System.ComponentModel; | ||
using System.Diagnostics; | ||
using System.Drawing; | ||
using System.Reflection; | ||
using System.Windows.Forms; | ||
|
||
namespace XRay.SdkControls | ||
{ | ||
public class PropertyGrid : System.Windows.Forms.PropertyGrid | ||
{ | ||
private Control view; | ||
private Point prevLocation; | ||
|
||
public PropertyGrid() | ||
{ | ||
Initialize(); | ||
SetupEventHandlers(); | ||
} | ||
|
||
private int GetSplitterWidth() | ||
{ | ||
Type gridType = view.GetType(); | ||
FieldInfo field = gridType.GetField("labelWidth", BindingFlags.NonPublic | BindingFlags.Instance); | ||
Object value = field.GetValue(view); | ||
return value is int ? (int)value : 0; | ||
} | ||
|
||
public void Initialize() | ||
{ | ||
foreach (Control control in Controls) | ||
{ | ||
if (control.GetType().Name.ToUpper() == "PROPERTYGRIDVIEW") | ||
{ | ||
view = control; | ||
break; | ||
} | ||
} | ||
} | ||
|
||
public void OnChildControlMouseDoubleClick(object sender, MouseEventArgs e) | ||
{ | ||
if (SelectedObject == null || SelectedGridItem == null) | ||
return; | ||
var descriptor_raw = SelectedGridItem.PropertyDescriptor; | ||
Debug.Assert(descriptor_raw != null); | ||
var descriptor = descriptor_raw as PropertyBag.PropertySpecDescriptor; | ||
var container = descriptor.bag as IPropertyContainer; | ||
IProperty property = container.GetProperty(descriptor.item); | ||
var mouseEvents = property as IMouseListener; | ||
if (mouseEvents == null) | ||
return; | ||
mouseEvents.OnDoubleClick(this); | ||
} | ||
|
||
public void OnChildControlMouseMove(object sender, MouseEventArgs e) | ||
{ | ||
if (e.Button != MouseButtons.Middle) | ||
{ | ||
prevLocation = e.Location; | ||
return; | ||
} | ||
if (e.Location.X == prevLocation.X) | ||
return; | ||
if (SelectedObject == null) | ||
return; | ||
if (SelectedGridItem == null) | ||
return; | ||
PropertyDescriptor rawDescriptor = SelectedGridItem.PropertyDescriptor; | ||
if (rawDescriptor == null) | ||
return; | ||
var descriptor = rawDescriptor as PropertyBag.PropertySpecDescriptor; | ||
var container = descriptor.bag as IPropertyContainer; | ||
IProperty rawProperty = container.GetProperty(descriptor.item); | ||
Debug.Assert(rawProperty != null); | ||
var incrementable = rawProperty as IIncrementable; | ||
if (incrementable == null) | ||
return; | ||
incrementable.Increment(e.Location.X - prevLocation.X); | ||
Refresh(); | ||
prevLocation = e.Location; | ||
} | ||
|
||
public void OnChildControlMouseDown(object sender, MouseEventArgs e) | ||
{ | ||
if (e.Button != MouseButtons.Middle) | ||
return; | ||
prevLocation = e.Location; | ||
} | ||
|
||
public void SetupEventHandlers() | ||
{ | ||
foreach (Control control in Controls) | ||
{ | ||
control.MouseDoubleClick += OnChildControlMouseDoubleClick; | ||
control.MouseMove += OnChildControlMouseMove; | ||
control.MouseDown += OnChildControlMouseDown; | ||
} | ||
} | ||
|
||
public void save(RegistryKey root, string key) | ||
{ | ||
RegistryKey grid = root.CreateSubKey(key); | ||
grid.SetValue("Splitter", GetSplitterWidth()); | ||
grid.Close(); | ||
} | ||
|
||
public void load(RegistryKey root, string key) | ||
{ | ||
RegistryKey grid = root.OpenSubKey(key); | ||
if (grid == null) | ||
return; | ||
int position = GetRegValue(grid, "Splitter", GetSplitterWidth()); | ||
grid.Close(); | ||
Type grid_type = view.GetType(); | ||
FieldInfo field = grid_type.GetField("labelWidth", BindingFlags.NonPublic | BindingFlags.Instance); | ||
field.SetValue(view, position); | ||
} | ||
|
||
private static T GetRegValue<T>(RegistryKey key, string name, T defaultValue) | ||
{ | ||
object value = key.GetValue(name); | ||
if (value == null) | ||
return defaultValue; | ||
return (T)value; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||
<ImportGroup Label="PropertySheets"> | ||
<Import Project="$(SolutionDir)Common.props" /> | ||
</ImportGroup> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProjectGuid>{E9DC16A3-D0FA-4924-AF6E-F6FDF3EA0661}</ProjectGuid> | ||
<OutputType>Library</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>XRay.SdkControls</RootNamespace> | ||
<AssemblyName>xrSdkControls</AssemblyName> | ||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>$(xrBinDir)</OutputPath> | ||
<IntermediateOutputPath>$(xrIntDir)$(ProjectName)\</IntermediateOutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>$(xrBinDir)</OutputPath> | ||
<IntermediateOutputPath>$(xrIntDir)$(ProjectName)\</IntermediateOutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="Flobbster.Windows.Forms.PropertyGrid"> | ||
<HintPath>$(xrSdkDir)binaries\Flobbster.Windows.Forms.PropertyGrid.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.Drawing" /> | ||
<Reference Include="System.Windows.Forms" /> | ||
<Reference Include="System.Xml.Linq" /> | ||
<Reference Include="System.Data.DataSetExtensions" /> | ||
<Reference Include="Microsoft.CSharp" /> | ||
<Reference Include="System.Data" /> | ||
<Reference Include="System.Xml" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="PropertyGrid.cs"> | ||
<SubType>Component</SubType> | ||
</Compile> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
<Compile Include="IPropertyContainer.cs" /> | ||
<Compile Include="IIncrementable.cs" /> | ||
<Compile Include="IMouseListener.cs" /> | ||
<Compile Include="IProperty.cs" /> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. | ||
Other similar extension points exist, see Microsoft.Common.targets. | ||
<Target Name="BeforeBuild"> | ||
</Target> | ||
<Target Name="AfterBuild"> | ||
</Target> | ||
--> | ||
</Project> |
Oops, something went wrong.