Skip to content

Commit dcc3d52

Browse files
authored
Add QPainterCompositionMode enum + method (KDAB#875)
* Add QPainterCompositionMode enum + method * Add comment about X11 + CompositionMode * Remove unused includes
1 parent 6e4fee9 commit dcc3d52

File tree

3 files changed

+124
-2
lines changed

3 files changed

+124
-2
lines changed

crates/cxx-qt-lib-headers/include/gui/qpainter.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
namespace rust {
1515
namespace cxxqtlib1 {
16+
using QPainterCompositionMode = QPainter::CompositionMode;
1617
using QPainterRenderHint = QPainter::RenderHint;
1718

1819
} // namespace cxxqtlib1

crates/cxx-qt-lib/src/gui/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@ mod qpainterpath;
3737
pub use qpainterpath::QPainterPath;
3838

3939
mod qpainter;
40-
pub use qpainter::{QPainter, QPainterRenderHint};
40+
pub use qpainter::{QPainter, QPainterCompositionMode, QPainterRenderHint};

crates/cxx-qt-lib/src/gui/qpainter.rs

Lines changed: 122 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,118 @@ mod ffi {
1515
type SizeMode = crate::SizeMode;
1616
}
1717

18+
/// Warning: Only a [QPainter](https://doc.qt.io/qt-6/qpainter.html) operating on a [QImage](https://doc.qt.io/qt-6/qimage.html)
19+
/// fully supports all composition modes. The RasterOp modes are supported for X11 as described
20+
/// in [compositionMode](https://doc.qt.io/qt-6/qpainter.html#compositionMode)().
21+
///
22+
/// Defines the modes supported for digital image compositing. Composition modes are used to specify
23+
/// how the pixels in one image, the source, are merged with the pixel in another image, the destination.
24+
/// Please note that the bitwise raster operation modes, denoted with a RasterOp prefix,
25+
/// are only natively supported in the X11 and raster paint engines. This means that the only way to utilize
26+
/// these modes on the Mac is via a QImage. The RasterOp denoted blend modes are not supported for pens
27+
/// and brushes with alpha components. Also, turning on the QPainter::Antialiasing render hint will
28+
/// effectively disable the RasterOp modes.
29+
/// The most common type is SourceOver (often referred to as just alpha blending) where the source pixel
30+
/// is blended on top of the destination pixel in such a way that the alpha component of the source
31+
/// defines the translucency of the pixel.
32+
/// Several composition modes require an alpha channel in the source or target images to have an effect.
33+
/// For optimal performance the image format Format_ARGB32_Premultiplied is preferred.
34+
/// When a composition mode is set it applies to all painting operator, pens, brushes, gradients and pixmap/image drawing.
35+
#[repr(i32)]
36+
#[namespace = "rust::cxxqtlib1"]
37+
#[derive(Debug)]
38+
enum QPainterCompositionMode {
39+
/// This is the default mode. The alpha of the source is used to blend the pixel on top of the destination.
40+
CompositionMode_SourceOver,
41+
/// The alpha of the destination is used to blend it on top of the source pixels. This mode is the inverse of CompositionMode_SourceOver.
42+
CompositionMode_DestinationOver,
43+
/// The pixels in the destination are cleared (set to fully transparent) independent of the source.
44+
CompositionMode_Clear,
45+
/// The output is the source pixel. (This means a basic copy operation and is identical to SourceOver when the source pixel is opaque).
46+
CompositionMode_Source,
47+
/// The output is the destination pixel. This means that the blending has no effect. This mode is the inverse of CompositionMode_Source.
48+
CompositionMode_Destination,
49+
/// The output is the source, where the alpha is reduced by that of the destination.
50+
CompositionMode_SourceIn,
51+
/// The output is the destination, where the alpha is reduced by that of the source. This mode is the inverse of CompositionMode_SourceIn.
52+
CompositionMode_DestinationIn,
53+
/// The output is the source, where the alpha is reduced by the inverse of destination.
54+
CompositionMode_SourceOut,
55+
/// The output is the destination, where the alpha is reduced by the inverse of the source. This mode is the inverse of CompositionMode_SourceOut.
56+
CompositionMode_DestinationOut,
57+
/// The source pixel is blended on top of the destination, with the alpha of the source pixel reduced by the alpha of the destination pixel.
58+
CompositionMode_SourceAtop,
59+
/// The destination pixel is blended on top of the source, with the alpha of the destination pixel is reduced by the alpha of the destination pixel.
60+
/// This mode is the inverse of CompositionMode_SourceAtop.
61+
CompositionMode_DestinationAtop,
62+
/// The source, whose alpha is reduced with the inverse of the destination alpha, is merged with the destination, whose alpha is reduced by the
63+
/// inverse of the source alpha. CompositionMode_Xor is not the same as the bitwise Xor.
64+
CompositionMode_Xor,
65+
66+
//svg 1.2 blend modes
67+
/// Both the alpha and color of the source and destination pixels are added together.
68+
CompositionMode_Plus,
69+
/// The output is the source color multiplied by the destination. Multiplying a color with white leaves
70+
/// the color unchanged, while multiplying a color with black produces black.
71+
CompositionMode_Multiply,
72+
/// The source and destination colors are inverted and then multiplied. Screening a color with white produces
73+
/// white, whereas screening a color with black leaves the color unchanged.
74+
CompositionMode_Screen,
75+
/// Multiplies or screens the colors depending on the destination color. The destination color is mixed with
76+
/// the source color to reflect the lightness or darkness of the destination.
77+
CompositionMode_Overlay,
78+
/// The darker of the source and destination colors is selected.
79+
CompositionMode_Darken,
80+
/// The lighter of the source and destination colors is selected.
81+
CompositionMode_Lighten,
82+
/// The destination color is brightened to reflect the source color.
83+
/// A black source color leaves the destination color unchanged.
84+
CompositionMode_ColorDodge,
85+
/// The destination color is darkened to reflect the source color. A white source color leaves the destination color unchanged.
86+
CompositionMode_ColorBurn,
87+
/// Multiplies or screens the colors depending on the source color. A light source color will lighten
88+
/// the destination color, whereas a dark source color will darken the destination color.
89+
CompositionMode_HardLight,
90+
/// Darkens or lightens the colors depending on the source color. Similar to CompositionMode_HardLight.
91+
CompositionMode_SoftLight,
92+
/// Subtracts the darker of the colors from the lighter. Painting with white inverts the destination
93+
/// color, whereas painting with black leaves the destination color unchanged.
94+
CompositionMode_Difference,
95+
/// Similar to CompositionMode_Difference, but with a lower contrast. Painting with white inverts
96+
/// the destination color, whereas painting with black leaves the destination color unchanged.
97+
CompositionMode_Exclusion,
98+
99+
// ROPs
100+
/// Does a bitwise OR operation on the source and destination pixels (src OR dst).
101+
RasterOp_SourceOrDestination,
102+
/// Does a bitwise AND operation on the source and destination pixels (src AND dst).
103+
RasterOp_SourceAndDestination,
104+
/// Does a bitwise XOR operation on the source and destination pixels (src XOR dst).
105+
RasterOp_SourceXorDestination,
106+
/// Does a bitwise NOR operation on the source and destination pixels ((NOT src) AND (NOT dst)).
107+
RasterOp_NotSourceAndNotDestination,
108+
/// Does a bitwise NAND operation on the source and destination pixels ((NOT src) OR (NOT dst)).
109+
RasterOp_NotSourceOrNotDestination,
110+
/// Does a bitwise operation where the source pixels are inverted and then XOR'ed with the destination ((NOT src) XOR dst).
111+
RasterOp_NotSourceXorDestination,
112+
/// Does a bitwise operation where the source pixels are inverted (NOT src).
113+
RasterOp_NotSource,
114+
///Does a bitwise operation where the source is inverted and then AND'ed with the destination ((NOT src) AND dst).
115+
RasterOp_NotSourceAndDestination,
116+
/// Does a bitwise operation where the source is AND'ed with the inverted destination pixels (src AND (NOT dst)).
117+
RasterOp_SourceAndNotDestination,
118+
/// Does a bitwise operation where the source is inverted and then OR'ed with the destination ((NOT src) OR dst).
119+
RasterOp_NotSourceOrDestination,
120+
/// The pixels in the destination are cleared (set to 0) independent of the source
121+
RasterOp_SourceOrNotDestination,
122+
/// The pixels in the destination are set (set to 1) independent of the source.
123+
RasterOp_ClearDestination,
124+
/// Does a bitwise operation where the destination pixels are inverted (NOT dst).
125+
RasterOp_SetDestination,
126+
/// Does a bitwise operation where the source is OR'ed with the inverted destination pixels (src OR (NOT dst)).
127+
RasterOp_NotDestination,
128+
}
129+
18130
/// Renderhints are used to specify flags to QPainter that may or may not be respected by any given engine.
19131
#[repr(i32)]
20132
#[namespace = "rust::cxxqtlib1"]
@@ -79,6 +191,10 @@ mod ffi {
79191
#[rust_name = "clip_path"]
80192
fn clipPath(self: &QPainter) -> QPainterPath;
81193

194+
/// Returns the current composition mode.
195+
#[rust_name = "composition_mode"]
196+
fn compositionMode(self: &QPainter) -> QPainterCompositionMode;
197+
82198
/// Draws the arc defined by the rectangle beginning at (x, y) with the specified width and height,
83199
/// and the given startAngle and spanAngle.
84200
#[rust_name = "draw_arc"]
@@ -210,6 +326,10 @@ mod ffi {
210326
#[rust_name = "set_clip_rect"]
211327
fn setClipRect(self: Pin<&mut QPainter>, rectangle: &QRect, operation: ClipOperation);
212328

329+
/// Sets the composition mode to the given mode.
330+
#[rust_name = "set_composition_mode"]
331+
fn setCompositionMode(self: Pin<&mut QPainter>, mode: QPainterCompositionMode);
332+
213333
/// Sets the painter's font to the given font.
214334
#[rust_name = "set_font"]
215335
fn setFont(self: Pin<&mut QPainter>, font: &QFont);
@@ -267,6 +387,7 @@ mod ffi {
267387
#[namespace = "rust::cxxqtlib1"]
268388
unsafe extern "C++" {
269389
include!("cxx-qt-lib/common.h");
390+
type QPainterCompositionMode;
270391

271392
type QPainterRenderHint;
272393

@@ -276,7 +397,7 @@ mod ffi {
276397
}
277398
}
278399

279-
pub use ffi::{QPainter, QPainterRenderHint};
400+
pub use ffi::{QPainter, QPainterCompositionMode, QPainterRenderHint};
280401

281402
impl QPainter {
282403
/// Create a QPainter

0 commit comments

Comments
 (0)