22use core:: { cell:: RefCell , fmt, mem:: replace, ops:: ControlFlow } ;
33use std:: time:: Instant ;
44
5- use sdl2 :: {
5+ use sdl3 :: {
66 EventPump , IntegerOrSdlError , Sdl ,
77 event:: Event ,
88 keyboard:: Keycode ,
9- pixels:: PixelFormatEnum ,
9+ pixels:: PixelFormat ,
1010 render:: { Texture , TextureValueError , WindowCanvas } ,
1111 video:: { FullscreenType , Window as SdlWindow , WindowBuildError } ,
1212} ;
@@ -27,7 +27,7 @@ use super::{Frame, dims};
2727/// Helper trait to support different pixel format types.
2828pub trait PixelFmt : Copy + Default {
2929 type Pixel : AsRef < [ u8 ] > + Copy + Sized ;
30- const SDL_FMT : PixelFormatEnum ;
30+ const SDL_FMT : PixelFormat ;
3131
3232 fn encode < C : IntoPixel < Self :: Pixel , Self > > ( self , color : C ) -> Self :: Pixel {
3333 color. into_pixel_fmt ( self )
@@ -59,7 +59,7 @@ pub struct Builder<'title, PF> {
5959 pub title : & ' title str ,
6060 pub vsync : bool ,
6161 pub hidpi : bool ,
62- pub fs : FullscreenType ,
62+ pub fullscreen : bool ,
6363 pub pixfmt : PF ,
6464}
6565
@@ -98,8 +98,8 @@ impl<'t, PF: PixelFmt> Builder<'t, PF> {
9898 self
9999 }
100100 /// Sets the fullscreen state of the window.
101- pub fn fullscreen ( mut self , fs : FullscreenType ) -> Self {
102- self . fs = fs;
101+ pub fn fullscreen ( mut self , fs : bool ) -> Self {
102+ self . fullscreen = fs;
103103 self
104104 }
105105 /// Sets the framebuffer pixel format.
@@ -112,10 +112,10 @@ impl<'t, PF: PixelFmt> Builder<'t, PF> {
112112
113113 /// Creates the window.
114114 pub fn build ( self ) -> Result < Window < PF > , Error > {
115- let sdl = sdl2 :: init ( ) ?;
115+ let sdl = sdl3 :: init ( ) ?;
116116 let win = self . create_window ( & sdl) ?;
117117
118- self . set_mouse_mode ( & sdl) ;
118+ self . set_mouse_mode ( & sdl, & win ) ;
119119
120120 let canvas = self . create_canvas ( win) ?;
121121 let ev_pump = sdl. event_pump ( ) ?;
@@ -133,28 +133,34 @@ impl<'t, PF: PixelFmt> Builder<'t, PF> {
133133
134134 fn create_window ( & self , sdl : & Sdl ) -> Result < SdlWindow , Error > {
135135 let Self {
136- dims : ( w, h) , title, fs, hidpi, ..
136+ dims : ( w, h) ,
137+ title,
138+ fullscreen,
139+ hidpi,
140+ ..
137141 } = * self ;
138- let mut win = sdl. video ( ) ?. window ( title, w, h) ;
142+ let mut bld = sdl. video ( ) ?. window ( title, w, h) ;
139143 if hidpi {
140- win . allow_highdpi ( ) ;
144+ bld . high_pixel_density ( ) ;
141145 }
142- let mut win = win. build ( ) ?;
143- win. set_fullscreen ( fs) ?;
144- Ok ( win)
146+ if fullscreen {
147+ bld. fullscreen ( ) ;
148+ }
149+ Ok ( bld. build ( ) ?)
145150 }
146151
147152 fn create_canvas ( & self , w : SdlWindow ) -> Result < WindowCanvas , Error > {
148- let mut canvas = w. into_canvas ( ) ;
153+ let canvas = w. into_canvas ( ) ;
149154 if self . vsync {
150- canvas = canvas. present_vsync ( ) ;
155+ //let _ok = canvas.present();
156+ //TODO vsync? canvas = canvas.present_vsync();
151157 }
152- Ok ( canvas. accelerated ( ) . build ( ) ? )
158+ Ok ( canvas)
153159 }
154160
155- fn set_mouse_mode ( & self , sdl : & Sdl ) {
161+ fn set_mouse_mode ( & self , sdl : & Sdl , win : & SdlWindow ) {
156162 let m = sdl. mouse ( ) ;
157- m. set_relative_mouse_mode ( true ) ;
163+ m. set_relative_mouse_mode ( win , true ) ;
158164 m. capture ( true ) ;
159165 m. show_cursor ( true ) ;
160166 }
@@ -186,7 +192,7 @@ impl<PF: PixelFmt<Pixel = [u8; N]>, const N: usize> Window<PF> {
186192 F : FnMut ( & mut Frame < Self , & RefCell < Framebuf < PF > > > ) -> ControlFlow < ( ) > ,
187193 Color4 : IntoPixel < PF :: Pixel , PF > ,
188194 {
189- let dims @ ( w, h) = self . canvas . window ( ) . drawable_size ( ) ;
195+ let dims @ ( w, h) = self . canvas . window ( ) . size_in_pixels ( ) ;
190196
191197 let tc = self . canvas . texture_creator ( ) ;
192198 let mut tex = tc. create_texture_streaming ( PF :: SDL_FMT , w, h) ?;
@@ -256,15 +262,15 @@ impl<PF: PixelFmt<Pixel = [u8; N]>, const N: usize> Window<PF> {
256262
257263impl PixelFmt for Rgba8888 {
258264 type Pixel = [ u8 ; 4 ] ;
259- const SDL_FMT : PixelFormatEnum = PixelFormatEnum :: RGBA32 ;
265+ const SDL_FMT : PixelFormat = PixelFormat :: RGBA32 ;
260266}
261267impl PixelFmt for Rgb565 {
262268 type Pixel = [ u8 ; 2 ] ;
263- const SDL_FMT : PixelFormatEnum = PixelFormatEnum :: RGB565 ;
269+ const SDL_FMT : PixelFormat = PixelFormat :: RGB565 ;
264270}
265271impl PixelFmt for Rgba4444 {
266272 type Pixel = [ u8 ; 2 ] ;
267- const SDL_FMT : PixelFormatEnum = PixelFormatEnum :: RGBA4444 ;
273+ const SDL_FMT : PixelFormat = PixelFormat :: RGBA4444 ;
268274}
269275
270276impl < ' a , PF , const N : usize > Target for Framebuf < ' a , PF >
@@ -295,7 +301,7 @@ impl<PF: PixelFmt> Default for Builder<'_, PF> {
295301 dims : dims:: SVGA_800_600 ,
296302 title : "// retrofire application //" ,
297303 vsync : true ,
298- fs : FullscreenType :: Off ,
304+ fullscreen : false ,
299305 pixfmt : PF :: default ( ) ,
300306 hidpi : false ,
301307 }
@@ -320,7 +326,7 @@ macro_rules! impl_from_error {
320326
321327impl_from_error ! {
322328 String
323- sdl2 :: Error
329+ sdl3 :: Error
324330 WindowBuildError
325331 TextureValueError
326332 IntegerOrSdlError
0 commit comments