diff --git a/crates/cxx-qt-lib-headers/include/gui/qpainter.h b/crates/cxx-qt-lib-headers/include/gui/qpainter.h index dafa81bd8..46453156c 100644 --- a/crates/cxx-qt-lib-headers/include/gui/qpainter.h +++ b/crates/cxx-qt-lib-headers/include/gui/qpainter.h @@ -13,6 +13,7 @@ namespace rust { namespace cxxqtlib1 { +using QPainterCompositionMode = QPainter::CompositionMode; using QPainterRenderHint = QPainter::RenderHint; } // namespace cxxqtlib1 diff --git a/crates/cxx-qt-lib/src/gui/mod.rs b/crates/cxx-qt-lib/src/gui/mod.rs index 192cb0bfd..5254219b4 100644 --- a/crates/cxx-qt-lib/src/gui/mod.rs +++ b/crates/cxx-qt-lib/src/gui/mod.rs @@ -37,4 +37,4 @@ mod qpainterpath; pub use qpainterpath::QPainterPath; mod qpainter; -pub use qpainter::{QPainter, QPainterRenderHint}; +pub use qpainter::{QPainter, QPainterCompositionMode, QPainterRenderHint}; diff --git a/crates/cxx-qt-lib/src/gui/qpainter.rs b/crates/cxx-qt-lib/src/gui/qpainter.rs index 816112599..3e69417a6 100644 --- a/crates/cxx-qt-lib/src/gui/qpainter.rs +++ b/crates/cxx-qt-lib/src/gui/qpainter.rs @@ -15,6 +15,118 @@ mod ffi { type SizeMode = crate::SizeMode; } + /// Warning: Only a [QPainter](https://doc.qt.io/qt-6/qpainter.html) operating on a [QImage](https://doc.qt.io/qt-6/qimage.html) + /// fully supports all composition modes. The RasterOp modes are supported for X11 as described + /// in [compositionMode](https://doc.qt.io/qt-6/qpainter.html#compositionMode)(). + /// + /// Defines the modes supported for digital image compositing. Composition modes are used to specify + /// how the pixels in one image, the source, are merged with the pixel in another image, the destination. + /// Please note that the bitwise raster operation modes, denoted with a RasterOp prefix, + /// are only natively supported in the X11 and raster paint engines. This means that the only way to utilize + /// these modes on the Mac is via a QImage. The RasterOp denoted blend modes are not supported for pens + /// and brushes with alpha components. Also, turning on the QPainter::Antialiasing render hint will + /// effectively disable the RasterOp modes. + /// The most common type is SourceOver (often referred to as just alpha blending) where the source pixel + /// is blended on top of the destination pixel in such a way that the alpha component of the source + /// defines the translucency of the pixel. + /// Several composition modes require an alpha channel in the source or target images to have an effect. + /// For optimal performance the image format Format_ARGB32_Premultiplied is preferred. + /// When a composition mode is set it applies to all painting operator, pens, brushes, gradients and pixmap/image drawing. + #[repr(i32)] + #[namespace = "rust::cxxqtlib1"] + #[derive(Debug)] + enum QPainterCompositionMode { + /// This is the default mode. The alpha of the source is used to blend the pixel on top of the destination. + CompositionMode_SourceOver, + /// The alpha of the destination is used to blend it on top of the source pixels. This mode is the inverse of CompositionMode_SourceOver. + CompositionMode_DestinationOver, + /// The pixels in the destination are cleared (set to fully transparent) independent of the source. + CompositionMode_Clear, + /// The output is the source pixel. (This means a basic copy operation and is identical to SourceOver when the source pixel is opaque). + CompositionMode_Source, + /// The output is the destination pixel. This means that the blending has no effect. This mode is the inverse of CompositionMode_Source. + CompositionMode_Destination, + /// The output is the source, where the alpha is reduced by that of the destination. + CompositionMode_SourceIn, + /// The output is the destination, where the alpha is reduced by that of the source. This mode is the inverse of CompositionMode_SourceIn. + CompositionMode_DestinationIn, + /// The output is the source, where the alpha is reduced by the inverse of destination. + CompositionMode_SourceOut, + /// The output is the destination, where the alpha is reduced by the inverse of the source. This mode is the inverse of CompositionMode_SourceOut. + CompositionMode_DestinationOut, + /// 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. + CompositionMode_SourceAtop, + /// 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. + /// This mode is the inverse of CompositionMode_SourceAtop. + CompositionMode_DestinationAtop, + /// The source, whose alpha is reduced with the inverse of the destination alpha, is merged with the destination, whose alpha is reduced by the + /// inverse of the source alpha. CompositionMode_Xor is not the same as the bitwise Xor. + CompositionMode_Xor, + + //svg 1.2 blend modes + /// Both the alpha and color of the source and destination pixels are added together. + CompositionMode_Plus, + /// The output is the source color multiplied by the destination. Multiplying a color with white leaves + /// the color unchanged, while multiplying a color with black produces black. + CompositionMode_Multiply, + /// The source and destination colors are inverted and then multiplied. Screening a color with white produces + /// white, whereas screening a color with black leaves the color unchanged. + CompositionMode_Screen, + /// Multiplies or screens the colors depending on the destination color. The destination color is mixed with + /// the source color to reflect the lightness or darkness of the destination. + CompositionMode_Overlay, + /// The darker of the source and destination colors is selected. + CompositionMode_Darken, + /// The lighter of the source and destination colors is selected. + CompositionMode_Lighten, + /// The destination color is brightened to reflect the source color. + /// A black source color leaves the destination color unchanged. + CompositionMode_ColorDodge, + /// The destination color is darkened to reflect the source color. A white source color leaves the destination color unchanged. + CompositionMode_ColorBurn, + /// Multiplies or screens the colors depending on the source color. A light source color will lighten + /// the destination color, whereas a dark source color will darken the destination color. + CompositionMode_HardLight, + /// Darkens or lightens the colors depending on the source color. Similar to CompositionMode_HardLight. + CompositionMode_SoftLight, + /// Subtracts the darker of the colors from the lighter. Painting with white inverts the destination + /// color, whereas painting with black leaves the destination color unchanged. + CompositionMode_Difference, + /// Similar to CompositionMode_Difference, but with a lower contrast. Painting with white inverts + /// the destination color, whereas painting with black leaves the destination color unchanged. + CompositionMode_Exclusion, + + // ROPs + /// Does a bitwise OR operation on the source and destination pixels (src OR dst). + RasterOp_SourceOrDestination, + /// Does a bitwise AND operation on the source and destination pixels (src AND dst). + RasterOp_SourceAndDestination, + /// Does a bitwise XOR operation on the source and destination pixels (src XOR dst). + RasterOp_SourceXorDestination, + /// Does a bitwise NOR operation on the source and destination pixels ((NOT src) AND (NOT dst)). + RasterOp_NotSourceAndNotDestination, + /// Does a bitwise NAND operation on the source and destination pixels ((NOT src) OR (NOT dst)). + RasterOp_NotSourceOrNotDestination, + /// Does a bitwise operation where the source pixels are inverted and then XOR'ed with the destination ((NOT src) XOR dst). + RasterOp_NotSourceXorDestination, + /// Does a bitwise operation where the source pixels are inverted (NOT src). + RasterOp_NotSource, + ///Does a bitwise operation where the source is inverted and then AND'ed with the destination ((NOT src) AND dst). + RasterOp_NotSourceAndDestination, + /// Does a bitwise operation where the source is AND'ed with the inverted destination pixels (src AND (NOT dst)). + RasterOp_SourceAndNotDestination, + /// Does a bitwise operation where the source is inverted and then OR'ed with the destination ((NOT src) OR dst). + RasterOp_NotSourceOrDestination, + /// The pixels in the destination are cleared (set to 0) independent of the source + RasterOp_SourceOrNotDestination, + /// The pixels in the destination are set (set to 1) independent of the source. + RasterOp_ClearDestination, + /// Does a bitwise operation where the destination pixels are inverted (NOT dst). + RasterOp_SetDestination, + /// Does a bitwise operation where the source is OR'ed with the inverted destination pixels (src OR (NOT dst)). + RasterOp_NotDestination, + } + /// Renderhints are used to specify flags to QPainter that may or may not be respected by any given engine. #[repr(i32)] #[namespace = "rust::cxxqtlib1"] @@ -79,6 +191,10 @@ mod ffi { #[rust_name = "clip_path"] fn clipPath(self: &QPainter) -> QPainterPath; + /// Returns the current composition mode. + #[rust_name = "composition_mode"] + fn compositionMode(self: &QPainter) -> QPainterCompositionMode; + /// Draws the arc defined by the rectangle beginning at (x, y) with the specified width and height, /// and the given startAngle and spanAngle. #[rust_name = "draw_arc"] @@ -210,6 +326,10 @@ mod ffi { #[rust_name = "set_clip_rect"] fn setClipRect(self: Pin<&mut QPainter>, rectangle: &QRect, operation: ClipOperation); + /// Sets the composition mode to the given mode. + #[rust_name = "set_composition_mode"] + fn setCompositionMode(self: Pin<&mut QPainter>, mode: QPainterCompositionMode); + /// Sets the painter's font to the given font. #[rust_name = "set_font"] fn setFont(self: Pin<&mut QPainter>, font: &QFont); @@ -267,6 +387,7 @@ mod ffi { #[namespace = "rust::cxxqtlib1"] unsafe extern "C++" { include!("cxx-qt-lib/common.h"); + type QPainterCompositionMode; type QPainterRenderHint; @@ -276,7 +397,7 @@ mod ffi { } } -pub use ffi::{QPainter, QPainterRenderHint}; +pub use ffi::{QPainter, QPainterCompositionMode, QPainterRenderHint}; impl QPainter { /// Create a QPainter