Skip to content

Commit 4505283

Browse files
committed
added text
1 parent a9e4d45 commit 4505283

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

source/knights_tour/src/main.rs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use sdl2::event::Event;
22
use sdl2::keyboard::Keycode;
33
use sdl2::rect::Rect;
44
use sdl2::surface::Surface;
5+
use sdl2::render::TextureQuery;
56

67
fn main() {
78
let width = 1280;
@@ -29,7 +30,6 @@ fn main() {
2930
.render("Hello, World!")
3031
.blended(sdl2::pixels::Color::RGB(255, 255, 255))
3132
.unwrap();
32-
3333

3434
let mut ksurf = Surface::load_bmp("knight.bmp").unwrap();
3535
ksurf
@@ -72,10 +72,12 @@ fn main() {
7272
for i in 0..8 {
7373
for z in 0..8 {
7474
board[i][z] = 0;
75-
rowx = 1;
76-
colx = 6;
7775
}
7876
}
77+
78+
rowx = 1;
79+
colx = 6;
80+
moves = 0;
7981
}
8082
Event::KeyDown {
8183
keycode: Some(Keycode::Space),
@@ -160,6 +162,25 @@ fn main() {
160162
}
161163
}
162164

165+
let menu_string = format!("Knights Tour - Moves: {}", moves);
166+
167+
let turn_surf = font
168+
.render(&format!("{}", menu_string))
169+
.blended(sdl2::pixels::Color::RGB(255, 255, 255))
170+
.unwrap();
171+
let turn_surf_text = tc.create_texture_from_surface(&turn_surf).unwrap();
172+
173+
let TextureQuery {
174+
width: wi,
175+
height: hi,
176+
..
177+
} = turn_surf_text.query();
178+
179+
can.copy(&turn_surf_text, None, Some(Rect::new(600, 250, wi, hi)))
180+
.expect("on copy");
181+
182+
183+
163184
can.present();
164185
}
165186
}

0 commit comments

Comments
 (0)