diff --git a/README.md b/README.md index 0030aef..ea28a0e 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,7 @@ DFL is a Win32 windowing library for the D language. ![screen shot](./examples/tooltip/image/screenshot.png "screen shot") ![screen shot](./examples/progressbar/image/screenshot3.png "screen shot") ![screen shot](./examples/clipboard/image/screenshot.png "screen shot") +![screen shot](./examples/clippingform/image/screenshot.png "screen shot") ## Recent major features - DUB is available for DFL. diff --git a/examples/clippingform/.gitignore b/examples/clippingform/.gitignore new file mode 100644 index 0000000..60a5f2a --- /dev/null +++ b/examples/clippingform/.gitignore @@ -0,0 +1,16 @@ +.dub +docs.json +__dummy.html +docs/ +/hello_dfl +hello_dfl.so +hello_dfl.dylib +hello_dfl.dll +hello_dfl.a +hello_dfl.lib +hello_dfl-test-* +*.exe +*.pdb +*.o +*.obj +*.lst diff --git a/examples/clippingform/.vscode/launch.json b/examples/clippingform/.vscode/launch.json new file mode 100644 index 0000000..6ccc1fa --- /dev/null +++ b/examples/clippingform/.vscode/launch.json @@ -0,0 +1,13 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "C++ Launch (Windows) clippingform", + "type": "cppvsdbg", + "request": "launch", + "cwd": "${workspaceRoot}", + "program": "./bin/clippingform_sample.exe", + "console": "internalConsole" + } + ] +} \ No newline at end of file diff --git a/examples/clippingform/.vscode/tasks.json b/examples/clippingform/.vscode/tasks.json new file mode 100644 index 0000000..b7eda52 --- /dev/null +++ b/examples/clippingform/.vscode/tasks.json @@ -0,0 +1,20 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "type": "dub", + "run": false, + "cwd": ".", + "compiler": "$current", + "archType": "$current", + "buildType": "$current", + "configuration": "$current", + "problemMatcher": [ + "$dmd" + ], + "group": "build", + "label": "dub: Build clippingform_sample", + "detail": "dub build --compiler=dmd.EXE -a=x86_64 -b=debug -c=application" + } + ] +} \ No newline at end of file diff --git a/examples/clippingform/README.md b/examples/clippingform/README.md new file mode 100644 index 0000000..b1a86ca --- /dev/null +++ b/examples/clippingform/README.md @@ -0,0 +1,2 @@ +# Screen Shot +![screen shot](./image/screenshot.png "screen shot") diff --git a/examples/clippingform/clippingform.code-workspace b/examples/clippingform/clippingform.code-workspace new file mode 100644 index 0000000..7e696bc --- /dev/null +++ b/examples/clippingform/clippingform.code-workspace @@ -0,0 +1,12 @@ +{ + "folders": [ + { + "path": "." + } + ], + "settings": { + "d.projectImportPaths": [ + "..\\..\\..\\dfl\\source" + ] + } +} \ No newline at end of file diff --git a/examples/clippingform/dub.json b/examples/clippingform/dub.json new file mode 100644 index 0000000..95d8658 --- /dev/null +++ b/examples/clippingform/dub.json @@ -0,0 +1,16 @@ +{ + "authors": ["haru-s"], + "copyright": "Copyright (C) 2023 haru-s", + "description": "DFL sample code.", + "name": "clippingform_sample", + "targetType": "executable", + "targetPath": "bin", + "dependencies": { + "dfl": { + "path": "../../../dfl" + } + }, + "lflags-windows-x86_omf-dmd": ["/exet:nt/su:windows:6.0"], + "lflags-windows-x86_mscoff-dmd": ["/SUBSYSTEM:WINDOWS", "/ENTRY:mainCRTStartup"], + "lflags-windows-x86_64-dmd": ["/SUBSYSTEM:WINDOWS", "/ENTRY:mainCRTStartup"] +} \ No newline at end of file diff --git a/examples/clippingform/image/clipping.bmp b/examples/clippingform/image/clipping.bmp new file mode 100644 index 0000000..6a0c7ed Binary files /dev/null and b/examples/clippingform/image/clipping.bmp differ diff --git a/examples/clippingform/image/screenshot.png b/examples/clippingform/image/screenshot.png new file mode 100644 index 0000000..3c92cdf Binary files /dev/null and b/examples/clippingform/image/screenshot.png differ diff --git a/examples/clippingform/shell.bat b/examples/clippingform/shell.bat new file mode 100644 index 0000000..49ab56b --- /dev/null +++ b/examples/clippingform/shell.bat @@ -0,0 +1,3 @@ +set dmd_path=c:\d\dmd2\windows +set dmc_path=c:\dmc\dm +cmd diff --git a/examples/clippingform/source/clippingform_sample.d b/examples/clippingform/source/clippingform_sample.d new file mode 100644 index 0000000..c733f6a --- /dev/null +++ b/examples/clippingform/source/clippingform_sample.d @@ -0,0 +1,34 @@ +import dfl; + +version(Have_dfl) // For DUB. +{ +} +else +{ + pragma(lib, "dfl.lib"); +} + +class MainForm : ClippingForm +{ + private Image _image; + + public this() + { + this.text = "Clipping Form example"; + this.size = Size(300, 200); + this.clipping = new Bitmap(r".\image\clipping.bmp"); // White is transparent. + this.click ~= (Control c, EventArgs e) { + this.close(); + }; + } +} + +static this() +{ + Application.enableVisualStyles(); +} + +void main() +{ + Application.run(new MainForm()); +} diff --git a/source/dfl/clippingform.d b/source/dfl/clippingform.d index ea766e2..e371d56 100644 --- a/source/dfl/clippingform.d +++ b/source/dfl/clippingform.d @@ -1,44 +1,9 @@ module dfl.clippingform; -private import dfl.all, dfl.internal.winapi; +private import dfl.all; private import dfl.internal.dlib : toI32; private import core.memory; - -private extern (Windows) -{ - struct RGNDATAHEADER - { - DWORD dwSize; - DWORD iType; - DWORD nCount; - DWORD nRgnSize; - RECT rcBound; - } - - struct RGNDATA - { - RGNDATAHEADER rdh; - ubyte[1] Buffer; - } - - struct XFORM - { - FLOAT eM11; - FLOAT eM12; - FLOAT eM21; - FLOAT eM22; - FLOAT eDx; - FLOAT eDy; - } - - enum {RDH_RECTANGLES = 1} - enum {BI_RGB = 0} - enum {DIB_RGB_COLORS = 0} - - HRGN ExtCreateRegion(void*, DWORD, RGNDATA*); - int GetDIBits(HDC, HBITMAP, UINT, UINT, PVOID, LPBITMAPINFO, UINT); -} - +private import core.sys.windows.windows; /// struct RegionRects @@ -48,19 +13,16 @@ private: size_t _capacity = 0; size_t _width = 0; size_t _height = 0; + public: - - - const @property - size_t width() + @property size_t width() const { return _width; } /// - const @property - size_t height() + @property size_t height() const { return _height; } @@ -115,8 +77,7 @@ public: /// - @property - Region region() + @property Region region() { if (_rgn is null) return null; with (_rgn.rdh) @@ -167,6 +128,7 @@ public: add(sx, y-1, x-1, y); } } + DeleteDC(hDC); return region; } @@ -199,40 +161,40 @@ public: /// -class ClippingForm: Form +class ClippingForm : Form { private: - Image m_Image; - RegionRects m_RegionRects; + Image _image; + RegionRects _regionRects; + protected: override void createParams(ref CreateParams cp) { super.createParams(cp); cp.style = WS_EX_TOPMOST | WS_EX_TOOLWINDOW; } + public: - - /// @property Image clipping() { - return m_Image; + return _image; } /// ditto @property void clipping(Image img) { - m_Image = img; + _image = img; } /// override void onHandleCreated(EventArgs ea) { - if (m_Image) + if (_image) { - region = m_RegionRects.create(m_Image); + region = _regionRects.create(_image); } super.onHandleCreated(ea); } @@ -241,9 +203,9 @@ public: /// override void onPaint(PaintEventArgs pea) { - if (m_Image) + if (_image) { - m_Image.draw(pea.graphics, Point(0,0)); + _image.draw(pea.graphics, Point(0,0)); } else { diff --git a/source/dfl/package.d b/source/dfl/package.d index 3f46054..2e87027 100644 --- a/source/dfl/package.d +++ b/source/dfl/package.d @@ -6,7 +6,7 @@ module dfl; public import dfl.base, dfl.menu, dfl.control, dfl.usercontrol, - dfl.form, dfl.drawing, dfl.panel, dfl.event, + dfl.form, dfl.drawing, dfl.panel, dfl.event, dfl.clippingform, dfl.application, dfl.button, dfl.socket, dfl.timer, dfl.environment, dfl.label, dfl.textboxbase, dfl.textbox, dfl.listbox, dfl.splitter, dfl.groupbox, dfl.messagebox,