Add ClippingForm example

This commit is contained in:
haru-s 2023-03-18 01:29:27 +09:00
parent 25ffb85a66
commit 60a43bc864
13 changed files with 136 additions and 57 deletions

View file

@ -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.

16
examples/clippingform/.gitignore vendored Normal file
View file

@ -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

View file

@ -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"
}
]
}

View file

@ -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"
}
]
}

View file

@ -0,0 +1,2 @@
# Screen Shot
![screen shot](./image/screenshot.png "screen shot")

View file

@ -0,0 +1,12 @@
{
"folders": [
{
"path": "."
}
],
"settings": {
"d.projectImportPaths": [
"..\\..\\..\\dfl\\source"
]
}
}

View file

@ -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"]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 176 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8 KiB

View file

@ -0,0 +1,3 @@
set dmd_path=c:\d\dmd2\windows
set dmc_path=c:\dmc\dm
cmd

View file

@ -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());
}

View file

@ -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
{

View file

@ -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,