Skip to content

Commit

Permalink
Checkpoiint #1: Abstracted Tiltable functionality into TiltableForm
Browse files Browse the repository at this point in the history
  • Loading branch information
pgeerkens committed Apr 4, 2019
1 parent 0c335cb commit e450e49
Show file tree
Hide file tree
Showing 5 changed files with 313 additions and 5 deletions.
14 changes: 9 additions & 5 deletions HexgridPanel/HexgridPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,15 @@ public enum MapOrientation {
public partial class HexgridPanel : TiltAwareScrollableControl, ISupportInitialize {
/// <summary>Creates a new instance of HexgridScrollable.</summary>
public HexgridPanel() {
RefreshCmd = new RelayCommand(o => { if (o != null) { SetMapDirty(); } Refresh(); } );
DataContext = new HexgridViewModel(this);
SetScaleList (new float[] {0.297F, 0.354F, 0.420F, 0.500F, 0.594F, 0.707F, 0.841F, 1.00F, 1.189F, 1.414F, 1.684F, 2.000F});

InitializeComponent();
RefreshCmd = new RelayCommand(o => { if (o != null) { SetMapDirty(); } Refresh(); } );
DataContext = new HexgridViewModel(this);
SetScaleList (new float[] {
0.250F, 0.297F, 0.354F, 0.420F,
0.500F, 0.594F, 0.707F, 0.841F,
1.000F, 1.189F, 1.414F, 1.684F,
2.000F});

InitializeComponent();
}

/// <summary>Signals the object that initialization is starting.</summary>
Expand Down
9 changes: 9 additions & 0 deletions HexgridPanel/HexgridPanel.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,12 @@
<Compile Include="HexgridBufferedPanelForm.Designer.cs">
<DependentUpon>HexgridBufferedPanelForm.cs</DependentUpon>
</Compile>
<Compile Include="TiltableForm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="TiltableForm.Designer.cs">
<DependentUpon>TiltableForm.cs</DependentUpon>
</Compile>
<Compile Include="HexgridPanelForm.cs">
<SubType>Form</SubType>
</Compile>
Expand Down Expand Up @@ -268,6 +274,9 @@
<EmbeddedResource Include="Example\StatusBarToolStrip.resx">
<DependentUpon>StatusBarToolStrip.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="TiltableForm.resx">
<DependentUpon>TiltableForm.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="WinForms\ExceptionDialog.en-US.resx">
<DependentUpon>ExceptionDialog.cs</DependentUpon>
</EmbeddedResource>
Expand Down
67 changes: 67 additions & 0 deletions HexgridPanel/TiltableForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

108 changes: 108 additions & 0 deletions HexgridPanel/TiltableForm.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
#region The MIT License - Copyright (C) 2012-2019 Pieter Geerkens
/////////////////////////////////////////////////////////////////////////////////////////
// PG Software Solutions - Hex-Grid Utilities
/////////////////////////////////////////////////////////////////////////////////////////
// The MIT License:
// ----------------
//
// Copyright (c) 2012-2019 Pieter Geerkens (email: pgeerkens@users.noreply.github.com)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify,
// merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to the following
// conditions:
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
/////////////////////////////////////////////////////////////////////////////////////////
#endregion
using System;
using System.Linq;
using System.Security.Permissions;
using System.Windows.Forms;

using PGNapoleonics.HexUtilities;
using PGNapoleonics.HexUtilities.Common;
using PGNapoleonics.HexgridPanel.WinForms;

namespace PGNapoleonics.HexgridPanel {
using HexSize = System.Drawing.Size;
using MapGridDisplay = MapDisplay<IHex>;

public partial class TiltableForm: Form, IMessageFilter {
public TiltableForm() {
InitializeComponent();
Application.AddMessageFilter(this);
}

protected MapGridDisplay MapBoard;
protected CustomCoords CustomCoords;

#region Event handlers
protected virtual void HexgridPanel_ScaleChange(object sender,EventArgs e) => OnResizeEnd(e);

protected virtual void HexgridPanel_MouseMove(object sender, MouseEventArgs e) { }

protected virtual void HexgridPanelForm_Load(object sender, EventArgs e) {
if (HexgridPanel == null) return;
HexgridPanel.ScaleIndex = HexgridPanel.Scales
.Select((f,i) => new {value=f, index=i})
.Where(s => s.value==1.0F)
.Select(s => s.index).FirstOrDefault();
var padding = ToolStripContainer.ContentPanel.Padding;
Size = HexgridPanel.MapSizePixels + new HexSize(21,93)
+ new HexSize(padding.Left+padding.Right, padding.Top+padding.Bottom);
}

protected void PanelBoard_GoalHexChange(object sender, HexEventArgs e)
=> RefreshAfter(()=>{MapBoard.GoalHex = e.Coords;} );

protected void PanelBoard_StartHexChange(object sender, HexEventArgs e)
=> RefreshAfter(()=>{MapBoard.StartHex = e.Coords;} );

protected void PanelBoard_HotSpotHexChange(object sender, HexEventArgs e)
=> RefreshAfter(()=>{MapBoard.HotspotHex = e.Coords;} );

protected void RefreshAfter(Action action) { action?.Invoke(); HexgridPanel.Refresh(); }
#endregion

#region IMessageFilter implementation
/// <summary>Redirect WM_MouseWheel messages to window under mouse.</summary>
/// <remarks>Redirect WM_MouseWheel messages to window under mouse (rather than
/// that with focus) with adjusted delta.
/// <a href="http://www.flounder.com/virtual_screen_coordinates.htm">Virtual Screen Coordinates</a>
/// Dont forget to add this to constructor:
/// Application.AddMessageFilter(this);
///</remarks>
/// <param name="m">The Windows Message to filter and/or process.</param>
/// <returns>Success (true) or failure (false) to OS.</returns>
[PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
public bool PreFilterMessage(ref Message m) {
if ((WM)m.Msg != WM.MouseHWheel && (WM)m.Msg != WM.MouseWheel) return false;

var hWnd = NativeMethods.WindowFromPoint(WindowsMouseInput.GetPointLParam(m.LParam));
var ctl = FromChildHandle(hWnd);
if (hWnd != IntPtr.Zero && hWnd != m.HWnd && ctl != null) {
switch ((WM)m.Msg) {
case WM.MouseHWheel:
case WM.MouseWheel:
Tracing.ScrollEvents.Trace(true, $" - {Name}.WM.{(WM)m.Msg}: ");
return (NativeMethods.SendMessage(hWnd, m.Msg, m.WParam, m.LParam) == IntPtr.Zero);
default: break;
}
}
return false;
}
#endregion
}
}
120 changes: 120 additions & 0 deletions HexgridPanel/TiltableForm.resx
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

0 comments on commit e450e49

Please sign in to comment.