@@ -1113,6 +1113,7 @@ pub struct WindowBuilder {
1113
1113
/// The window builder cannot be built on a non-main thread, so prevent cross-threaded moves and references.
1114
1114
/// `!Send` and `!Sync`,
1115
1115
subsystem : VideoSubsystem ,
1116
+ shaped : bool ,
1116
1117
}
1117
1118
1118
1119
impl WindowBuilder {
@@ -1127,6 +1128,7 @@ impl WindowBuilder {
1127
1128
window_flags : 0 ,
1128
1129
subsystem : v. clone ( ) ,
1129
1130
create_metal_view : false ,
1131
+ shaped : false ,
1130
1132
}
1131
1133
}
1132
1134
@@ -1148,14 +1150,25 @@ impl WindowBuilder {
1148
1150
let raw_width = self . width as c_int ;
1149
1151
let raw_height = self . height as c_int ;
1150
1152
unsafe {
1151
- let raw = sys:: SDL_CreateWindow (
1152
- title. as_ptr ( ) as * const c_char ,
1153
- to_ll_windowpos ( self . x ) ,
1154
- to_ll_windowpos ( self . y ) ,
1155
- raw_width,
1156
- raw_height,
1157
- self . window_flags ,
1158
- ) ;
1153
+ let raw = if self . shaped {
1154
+ sys:: SDL_CreateShapedWindow (
1155
+ title. as_ptr ( ) as * const c_char ,
1156
+ to_ll_windowpos ( self . x ) as u32 ,
1157
+ to_ll_windowpos ( self . y ) as u32 ,
1158
+ raw_width as u32 ,
1159
+ raw_height as u32 ,
1160
+ self . window_flags ,
1161
+ )
1162
+ } else {
1163
+ sys:: SDL_CreateWindow (
1164
+ title. as_ptr ( ) as * const c_char ,
1165
+ to_ll_windowpos ( self . x ) ,
1166
+ to_ll_windowpos ( self . y ) ,
1167
+ raw_width,
1168
+ raw_height,
1169
+ self . window_flags ,
1170
+ )
1171
+ } ;
1159
1172
1160
1173
if raw. is_null ( ) {
1161
1174
Err ( SdlError ( get_error ( ) ) )
@@ -1276,6 +1289,12 @@ impl WindowBuilder {
1276
1289
self . create_metal_view = true ;
1277
1290
self
1278
1291
}
1292
+
1293
+ /// Sets shaped state, to create via SDL_CreateShapedWindow instead of SDL_CreateWindow
1294
+ pub fn set_shaped ( & mut self ) -> & mut WindowBuilder {
1295
+ self . shaped = true ;
1296
+ self
1297
+ }
1279
1298
}
1280
1299
1281
1300
impl From < Window > for CanvasBuilder {
@@ -1533,6 +1552,30 @@ impl Window {
1533
1552
Ok ( ( ) )
1534
1553
}
1535
1554
1555
+ /// Set the shape of the window
1556
+ /// To be effective:
1557
+ /// - shaped must have been set using windows builder
1558
+ /// - binarizationCutoff: specify the cutoff value for the shape's alpha
1559
+ /// channel: At or above that cutoff value, a pixel is visible in the
1560
+ /// shape. Below that, it's not part of the shape.
1561
+ pub fn set_window_shape_alpha < S : AsRef < SurfaceRef > > (
1562
+ & mut self ,
1563
+ shape : S ,
1564
+ binarizationCutoff : u8 ,
1565
+ ) -> Result < ( ) , i32 > {
1566
+ let mode = sys:: WindowShapeMode :: ShapeModeBinarizeAlpha ;
1567
+ let parameters = sys:: SDL_WindowShapeParams { binarizationCutoff } ;
1568
+ let mut shape_mode = sys:: SDL_WindowShapeMode { mode, parameters } ;
1569
+ let result = unsafe {
1570
+ sys:: SDL_SetWindowShape ( self . context . raw , shape. as_ref ( ) . raw ( ) , & mut shape_mode)
1571
+ } ;
1572
+ if result == 0 {
1573
+ Ok ( ( ) )
1574
+ } else {
1575
+ Err ( result)
1576
+ }
1577
+ }
1578
+
1536
1579
#[ doc( alias = "SDL_GetWindowTitle" ) ]
1537
1580
pub fn title ( & self ) -> & str {
1538
1581
unsafe {
0 commit comments