mirror of
https://github.com/Rayerd/dfl.git
synced 2025-04-26 04:59:55 +03:00
Add ClippingForm example
This commit is contained in:
parent
25ffb85a66
commit
60a43bc864
13 changed files with 136 additions and 57 deletions
|
@ -13,6 +13,7 @@ DFL is a Win32 windowing library for the D language.
|
|||

|
||||

|
||||

|
||||

|
||||
|
||||
## Recent major features
|
||||
- DUB is available for DFL.
|
||||
|
|
16
examples/clippingform/.gitignore
vendored
Normal file
16
examples/clippingform/.gitignore
vendored
Normal 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
|
13
examples/clippingform/.vscode/launch.json
vendored
Normal file
13
examples/clippingform/.vscode/launch.json
vendored
Normal 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"
|
||||
}
|
||||
]
|
||||
}
|
20
examples/clippingform/.vscode/tasks.json
vendored
Normal file
20
examples/clippingform/.vscode/tasks.json
vendored
Normal 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"
|
||||
}
|
||||
]
|
||||
}
|
2
examples/clippingform/README.md
Normal file
2
examples/clippingform/README.md
Normal file
|
@ -0,0 +1,2 @@
|
|||
# Screen Shot
|
||||

|
12
examples/clippingform/clippingform.code-workspace
Normal file
12
examples/clippingform/clippingform.code-workspace
Normal file
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"folders": [
|
||||
{
|
||||
"path": "."
|
||||
}
|
||||
],
|
||||
"settings": {
|
||||
"d.projectImportPaths": [
|
||||
"..\\..\\..\\dfl\\source"
|
||||
]
|
||||
}
|
||||
}
|
16
examples/clippingform/dub.json
Normal file
16
examples/clippingform/dub.json
Normal 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"]
|
||||
}
|
BIN
examples/clippingform/image/clipping.bmp
Normal file
BIN
examples/clippingform/image/clipping.bmp
Normal file
Binary file not shown.
After Width: | Height: | Size: 176 KiB |
BIN
examples/clippingform/image/screenshot.png
Normal file
BIN
examples/clippingform/image/screenshot.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 8 KiB |
3
examples/clippingform/shell.bat
Normal file
3
examples/clippingform/shell.bat
Normal file
|
@ -0,0 +1,3 @@
|
|||
set dmd_path=c:\d\dmd2\windows
|
||||
set dmc_path=c:\dmc\dm
|
||||
cmd
|
34
examples/clippingform/source/clippingform_sample.d
Normal file
34
examples/clippingform/source/clippingform_sample.d
Normal 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());
|
||||
}
|
|
@ -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
|
||||
{
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue