-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9f8e0f9
commit bd5eee7
Showing
29 changed files
with
173 additions
and
28 deletions.
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,10 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<OutputType>WinExe</OutputType> | ||
<AllowUnsafeBlocks>True</AllowUnsafeBlocks> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\..\..\..\thirtytwo\thirtytwo.csproj" /> | ||
</ItemGroup> | ||
</Project> |
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,77 @@ | ||
// Copyright (c) Jeremy W. Kuhne. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System.Drawing; | ||
using Windows; | ||
using Windows.Win32.Foundation; | ||
|
||
namespace AltWind; | ||
|
||
/// <summary> | ||
/// Sample from Programming Windows, 5th Edition. | ||
/// Original (c) Charles Petzold, 1998 | ||
/// Figure 5-21, Pages 171-173. | ||
/// </summary> | ||
internal static class Program | ||
{ | ||
[STAThread] | ||
private static void Main() | ||
{ | ||
Application.Run(new AltWind(), "Alternate and Winding Fill Modes"); | ||
} | ||
} | ||
|
||
public class AltWind : WindowClass | ||
{ | ||
private readonly Point[] _aptFigure = | ||
[ | ||
new(10, 70), | ||
new(50, 70), | ||
new(50, 10), | ||
new(90, 10), | ||
new(90, 50), | ||
new(30, 50), | ||
new(30, 90), | ||
new(70, 90), | ||
new(70, 30), | ||
new(10, 30) | ||
]; | ||
|
||
private int _cxClient, _cyClient; | ||
|
||
protected override LRESULT WindowProcedure(HWND window, MessageType message, WPARAM wParam, LPARAM lParam) | ||
{ | ||
switch (message) | ||
{ | ||
case MessageType.Size: | ||
_cxClient = lParam.LOWORD; | ||
_cyClient = lParam.HIWORD; | ||
return (LRESULT)0; | ||
case MessageType.Paint: | ||
Span<Point> apt = stackalloc Point[10]; | ||
using (DeviceContext dc = window.BeginPaint()) | ||
{ | ||
dc.SelectObject(StockBrush.Gray); | ||
for (int i = 0; i < 10; i++) | ||
{ | ||
apt[i].X = _cxClient * _aptFigure[i].X / 200; | ||
apt[i].Y = _cyClient * _aptFigure[i].Y / 100; | ||
} | ||
|
||
dc.SetPolyFillMode(PolyFillMode.Alternate); | ||
dc.Polygon(apt); | ||
|
||
for (int i = 0; i < 10; i++) | ||
{ | ||
apt[i].X += _cxClient / 2; | ||
} | ||
dc.SetPolyFillMode(PolyFillMode.Winding); | ||
dc.Polygon(apt); | ||
} | ||
|
||
return (LRESULT)0; | ||
} | ||
|
||
return base.WindowProcedure(window, message, wParam, lParam); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -10,69 +10,69 @@ namespace Windows; | |
public static unsafe partial class DeviceContextExtensions | ||
{ | ||
/// <inheritdoc cref="Interop.GetGraphicsMode(HDC)"/> | ||
public static GRAPHICS_MODE GetGraphicsMode<T>(this T deviceContext) | ||
public static GRAPHICS_MODE GetGraphicsMode<T>(this T context) | ||
where T : IHandle<HDC> | ||
{ | ||
GRAPHICS_MODE mode = (GRAPHICS_MODE)Interop.GetGraphicsMode(deviceContext.Handle); | ||
GC.KeepAlive(deviceContext.Wrapper); | ||
GRAPHICS_MODE mode = (GRAPHICS_MODE)Interop.GetGraphicsMode(context.Handle); | ||
GC.KeepAlive(context.Wrapper); | ||
return mode; | ||
} | ||
|
||
/// <inheritdoc cref="Interop.SetGraphicsMode(HDC, GRAPHICS_MODE)"/> | ||
public static GRAPHICS_MODE SetGraphicsMode<T>(this T deviceContext, GRAPHICS_MODE mode) | ||
public static GRAPHICS_MODE SetGraphicsMode<T>(this T context, GRAPHICS_MODE mode) | ||
where T : IHandle<HDC> | ||
{ | ||
mode = (GRAPHICS_MODE)Interop.SetGraphicsMode(deviceContext.Handle, mode); | ||
GC.KeepAlive(deviceContext.Wrapper); | ||
mode = (GRAPHICS_MODE)Interop.SetGraphicsMode(context.Handle, mode); | ||
GC.KeepAlive(context.Wrapper); | ||
return mode; | ||
} | ||
|
||
/// <inheritdoc cref="Interop.GetWorldTransform(HDC, XFORM*)"/> | ||
public static unsafe bool GetWorldTransform<T>(this T deviceContext, ref Matrix3x2 transform) | ||
public static unsafe bool GetWorldTransform<T>(this T context, ref Matrix3x2 transform) | ||
where T : IHandle<HDC> | ||
{ | ||
fixed (Matrix3x2* t = &transform) | ||
{ | ||
bool result = Interop.GetWorldTransform(deviceContext.Handle, (XFORM*)t); | ||
GC.KeepAlive(deviceContext.Wrapper); | ||
bool result = Interop.GetWorldTransform(context.Handle, (XFORM*)t); | ||
GC.KeepAlive(context.Wrapper); | ||
return result; | ||
} | ||
} | ||
|
||
/// <inheritdoc cref="Interop.SetWorldTransform(HDC, XFORM*)"/> | ||
public static unsafe bool SetWorldTransform<T>(this T deviceContext, ref Matrix3x2 transform) | ||
public static unsafe bool SetWorldTransform<T>(this T context, ref Matrix3x2 transform) | ||
where T : IHandle<HDC> | ||
{ | ||
fixed (Matrix3x2* t = &transform) | ||
{ | ||
bool result = Interop.SetWorldTransform(deviceContext.Handle, (XFORM*)t); | ||
GC.KeepAlive(deviceContext.Wrapper); | ||
bool result = Interop.SetWorldTransform(context.Handle, (XFORM*)t); | ||
GC.KeepAlive(context.Wrapper); | ||
return result; | ||
} | ||
} | ||
|
||
/// <inheritdoc cref="Interop.GetDeviceCaps(HDC, GET_DEVICE_CAPS_INDEX)"/> | ||
public static int GetDeviceCaps<T>(this T deviceContext, GET_DEVICE_CAPS_INDEX index) | ||
public static int GetDeviceCaps<T>(this T context, GET_DEVICE_CAPS_INDEX index) | ||
where T : IHandle<HDC> | ||
{ | ||
int result = Interop.GetDeviceCaps(deviceContext.Handle, index); | ||
GC.KeepAlive(deviceContext.Wrapper); | ||
int result = Interop.GetDeviceCaps(context.Handle, index); | ||
GC.KeepAlive(context.Wrapper); | ||
return result; | ||
} | ||
|
||
/// <summary> | ||
/// Converts the requested point size to height based on the DPI of the given device context. | ||
/// </summary> | ||
public static int FontPointSizeToHeight<T>(this T deviceContext, int pointSize) | ||
public static int FontPointSizeToHeight<T>(this T context, int pointSize) | ||
where T : IHandle<HDC> | ||
{ | ||
Application.EnsureDpiAwareness(); | ||
int result = Interop.MulDiv( | ||
pointSize, | ||
Interop.GetDeviceCaps(deviceContext.Handle, GET_DEVICE_CAPS_INDEX.LOGPIXELSY), | ||
Interop.GetDeviceCaps(context.Handle, GET_DEVICE_CAPS_INDEX.LOGPIXELSY), | ||
72); | ||
|
||
GC.KeepAlive(deviceContext.Wrapper); | ||
GC.KeepAlive(context.Wrapper); | ||
return result; | ||
} | ||
|
||
|
@@ -89,6 +89,28 @@ public static ObjectScope<T> SelectObject<T>(this T context, HGDIOBJ @object) | |
return type == OBJ_TYPE.OBJ_REGION ? default : new(handle, context); | ||
} | ||
|
||
public static PolyFillMode SetPolyFillMode<T>(this T context, PolyFillMode mode) | ||
where T : IHandle<HDC> | ||
{ | ||
PolyFillMode result = (PolyFillMode)Interop.SetPolyFillMode(context.Handle, (CREATE_POLYGON_RGN_MODE)mode); | ||
GC.KeepAlive(context.Wrapper); | ||
return result; | ||
} | ||
|
||
public static bool Polygon<T>(this T context, params Point[] points) | ||
where T: IHandle<HDC> => Polygon(context, points.AsSpan()); | ||
Check warning on line 101 in src/thirtytwo/DeviceContextExtensions.cs GitHub Actions / build
Check warning on line 101 in src/thirtytwo/DeviceContextExtensions.cs GitHub Actions / build
Check warning on line 101 in src/thirtytwo/DeviceContextExtensions.cs GitHub Actions / build
Check warning on line 101 in src/thirtytwo/DeviceContextExtensions.cs GitHub Actions / build
|
||
|
||
public static bool Polygon<T>(this T context, ReadOnlySpan<Point> points) | ||
where T : IHandle<HDC> | ||
{ | ||
fixed (Point* p = points) | ||
{ | ||
bool result = Interop.Polygon(context.Handle, p, points.Length); | ||
GC.KeepAlive(context.Wrapper); | ||
return result; | ||
} | ||
} | ||
|
||
public static unsafe (int Height, uint LengthDrawn, Rectangle Bounds) DrawText<T>( | ||
this T context, | ||
ReadOnlySpan<char> text, | ||
|
@@ -152,46 +174,46 @@ private static (int Height, uint LengthDrawn, Rectangle Bounds) DrawTextHelper<T | |
} | ||
|
||
public static void DrawIcon<TDeviceContext, TIcon>( | ||
this TDeviceContext deviceContext, | ||
this TDeviceContext context, | ||
TIcon icon, | ||
Point location, | ||
Size size = default, | ||
DI_FLAGS flags = DI_FLAGS.DI_NORMAL) | ||
where TDeviceContext : IHandle<HDC> | ||
where TIcon : IHandle<HICON> | ||
{ | ||
if (!Interop.DrawIconEx(deviceContext.Handle, location.X, location.Y, icon.Handle, size.Width, size.Height, 0, default, flags)) | ||
if (!Interop.DrawIconEx(context.Handle, location.X, location.Y, icon.Handle, size.Width, size.Height, 0, default, flags)) | ||
{ | ||
Error.ThrowLastError(); | ||
} | ||
|
||
GC.KeepAlive(deviceContext.Wrapper); | ||
GC.KeepAlive(context.Wrapper); | ||
GC.KeepAlive(icon.Wrapper); | ||
} | ||
|
||
public static DeviceContext CreateCompatibleDeviceContext<TDeviceContext>(this TDeviceContext deviceContext) | ||
public static DeviceContext CreateCompatibleDeviceContext<TDeviceContext>(this TDeviceContext context) | ||
where TDeviceContext : IHandle<HDC> | ||
{ | ||
HDC hdc = Interop.CreateCompatibleDC(deviceContext.Handle); | ||
HDC hdc = Interop.CreateCompatibleDC(context.Handle); | ||
if (hdc.IsNull) | ||
{ | ||
Error.ThrowLastError(); | ||
} | ||
|
||
GC.KeepAlive(deviceContext.Wrapper); | ||
GC.KeepAlive(context.Wrapper); | ||
return DeviceContext.Create(hdc, ownsHandle: true); | ||
} | ||
|
||
public static Bitmap CreateCompatibleBitmap<TDeviceContext>(this TDeviceContext deviceContext, Size size) | ||
public static Bitmap CreateCompatibleBitmap<TDeviceContext>(this TDeviceContext context, Size size) | ||
where TDeviceContext : IHandle<HDC> | ||
{ | ||
HBITMAP hbitmap = Interop.CreateCompatibleBitmap(deviceContext.Handle, size.Width, size.Height); | ||
HBITMAP hbitmap = Interop.CreateCompatibleBitmap(context.Handle, size.Width, size.Height); | ||
if (hbitmap.IsNull) | ||
{ | ||
Error.ThrowLastError(); | ||
} | ||
|
||
GC.KeepAlive(deviceContext.Wrapper); | ||
GC.KeepAlive(context.Wrapper); | ||
return Bitmap.Create(hbitmap, ownsHandle: true); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -286,3 +286,5 @@ WIN32_ERROR | |
WINDOWPOS | ||
WM_* | ||
XFORMCOORDS | ||
SetPolyFillMode | ||
Polygon |
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 7 additions & 1 deletion
8
src/thirtytwo/ControlType.cs → src/thirtytwo/WrapperEnums/PolyFillMode.cs
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 |
---|---|---|
@@ -1,4 +1,10 @@ | ||
// Copyright (c) Jeremy W. Kuhne. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
namespace Windows; | ||
namespace Windows; | ||
|
||
public enum PolyFillMode : uint | ||
{ | ||
Alternate = CREATE_POLYGON_RGN_MODE.ALTERNATE, | ||
Winding = CREATE_POLYGON_RGN_MODE.WINDING | ||
} |
File renamed without changes.
File renamed without changes.
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,12 @@ | ||
// Copyright (c) Jeremy W. Kuhne. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
namespace Windows; | ||
|
||
public enum StockPen : uint | ||
{ | ||
White = GET_STOCK_OBJECT_FLAGS.WHITE_PEN, | ||
Black = GET_STOCK_OBJECT_FLAGS.BLACK_PEN, | ||
Null = GET_STOCK_OBJECT_FLAGS.NULL_PEN, | ||
DeviceContext = GET_STOCK_OBJECT_FLAGS.DC_PEN | ||
} |
File renamed without changes.
File renamed without changes.
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