Skip to content

Commit c60040d

Browse files
Optimized drawing the menu bg
I made it so the menu background draws on every menu so that I don't have to paste it for every menu. On some menus menus like level complete or editor another bg gets drawn over it but it doesn't really matter.
1 parent c530b69 commit c60040d

File tree

1 file changed

+18
-144
lines changed

1 file changed

+18
-144
lines changed

src/main.rs

Lines changed: 18 additions & 144 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,26 +1261,26 @@ async fn main() {
12611261
// Drawing
12621262
clear_background(BLACK);
12631263

1264+
draw_texture_ex(
1265+
&default_bg_no_gradient,
1266+
-50.0,
1267+
-75.0,
1268+
Color::from_rgba(20, 20, 20, 255),
1269+
DrawTextureParams {
1270+
dest_size: Some(Vec2 {
1271+
x: default_bg_no_gradient.width() * screen_width() as f32 * 0.0008,
1272+
y: default_bg_no_gradient.height() * screen_width() as f32 * 0.0008
1273+
}),
1274+
source: None,
1275+
rotation: 0.0,
1276+
flip_x: false,
1277+
flip_y: false,
1278+
pivot: None
1279+
}
1280+
);
1281+
12641282
match game_state.0.get() {
12651283
GameState::Menu => {
1266-
draw_texture_ex(
1267-
&default_bg_no_gradient,
1268-
-50.0,
1269-
-75.0,
1270-
Color::from_rgba(20, 20, 20, 255),
1271-
DrawTextureParams {
1272-
dest_size: Some(Vec2 {
1273-
x: default_bg_no_gradient.width() * screen_width() as f32 * 0.0008,
1274-
y: default_bg_no_gradient.height() * screen_width() as f32 * 0.0008
1275-
}),
1276-
source: None,
1277-
rotation: 0.0,
1278-
flip_x: false,
1279-
flip_y: false,
1280-
pivot: None
1281-
}
1282-
);
1283-
12841284
draw_text_pro(
12851285
"Geometry Rays",
12861286
screen_width() as f32 / 2.0 - measure_text_ex("Geometry Rays", 40, &font) / 2.0,
@@ -1343,24 +1343,6 @@ async fn main() {
13431343
}
13441344

13451345
GameState::LevelSelect => {
1346-
draw_texture_ex(
1347-
&default_bg_no_gradient,
1348-
-50.0,
1349-
-75.0,
1350-
Color::from_rgba(20, 20, 20, 255),
1351-
DrawTextureParams {
1352-
dest_size: Some(Vec2 {
1353-
x: default_bg_no_gradient.width() * screen_width() as f32 * 0.0008,
1354-
y: default_bg_no_gradient.height() * screen_width() as f32 * 0.0008
1355-
}),
1356-
source: None,
1357-
rotation: 0.0,
1358-
flip_x: false,
1359-
flip_y: false,
1360-
pivot: None
1361-
}
1362-
);
1363-
13641346
draw_text_pro(
13651347
&format!("Creator: {}", &main_levels[current_level as usize].creator),
13661348
10.0,
@@ -1530,24 +1512,6 @@ async fn main() {
15301512
}
15311513

15321514
GameState::CreatorMenu => {
1533-
draw_texture_ex(
1534-
&default_bg_no_gradient,
1535-
-50.0,
1536-
-75.0,
1537-
Color::from_rgba(20, 20, 20, 255),
1538-
DrawTextureParams {
1539-
dest_size: Some(Vec2 {
1540-
x: default_bg_no_gradient.width() * screen_width() as f32 * 0.0008,
1541-
y: default_bg_no_gradient.height() * screen_width() as f32 * 0.0008
1542-
}),
1543-
source: None,
1544-
rotation: 0.0,
1545-
flip_x: false,
1546-
flip_y: false,
1547-
pivot: None
1548-
}
1549-
);
1550-
15511515
back_button.draw(false, None, 1.0, false, &font);
15521516
featured_button.draw(false, None, 1.0, false, &font);
15531517
create_button.draw(false, None, 1.0, false, &font);
@@ -1790,24 +1754,6 @@ async fn main() {
17901754
}
17911755

17921756
GameState::LevelSettings => {
1793-
draw_texture_ex(
1794-
&default_bg_no_gradient,
1795-
-50.0,
1796-
-75.0,
1797-
Color::from_rgba(20, 20, 20, 255),
1798-
DrawTextureParams {
1799-
dest_size: Some(Vec2 {
1800-
x: default_bg_no_gradient.width() * screen_width() as f32 * 0.0008,
1801-
y: default_bg_no_gradient.height() * screen_width() as f32 * 0.0008
1802-
}),
1803-
source: None,
1804-
rotation: 0.0,
1805-
flip_x: false,
1806-
flip_y: false,
1807-
pivot: None
1808-
}
1809-
);
1810-
18111757
draw_text_pro(
18121758
&main_levels[current_song_index as usize].name,
18131759
screen_width() / 2.0 - measure_text_ex(&main_levels[current_song_index as usize].name, 30, &font) / 2.0,
@@ -1838,24 +1784,6 @@ async fn main() {
18381784
}
18391785

18401786
GameState::SearchPage => {
1841-
draw_texture_ex(
1842-
&default_bg_no_gradient,
1843-
-50.0,
1844-
-75.0,
1845-
Color::from_rgba(20, 20, 20, 255),
1846-
DrawTextureParams {
1847-
dest_size: Some(Vec2 {
1848-
x: default_bg_no_gradient.width() * screen_width() as f32 * 0.0008,
1849-
y: default_bg_no_gradient.height() * screen_width() as f32 * 0.0008
1850-
}),
1851-
source: None,
1852-
rotation: 0.0,
1853-
flip_x: false,
1854-
flip_y: false,
1855-
pivot: None
1856-
}
1857-
);
1858-
18591787
if show_level_not_found {
18601788
draw_text_pro(
18611789
&level_download_response,
@@ -1873,24 +1801,6 @@ async fn main() {
18731801
}
18741802

18751803
GameState::LevelPage => {
1876-
draw_texture_ex(
1877-
&default_bg_no_gradient,
1878-
-50.0,
1879-
-75.0,
1880-
Color::from_rgba(20, 20, 20, 255),
1881-
DrawTextureParams {
1882-
dest_size: Some(Vec2 {
1883-
x: default_bg_no_gradient.width() * screen_width() as f32 * 0.0008,
1884-
y: default_bg_no_gradient.height() * screen_width() as f32 * 0.0008
1885-
}),
1886-
source: None,
1887-
rotation: 0.0,
1888-
flip_x: false,
1889-
flip_y: false,
1890-
pivot: None
1891-
}
1892-
);
1893-
18941804
draw_text_pro(
18951805
&online_level_name,
18961806
screen_width() / 2.0 - measure_text_ex(&online_level_name, 50, &font) / 2.0,
@@ -1984,24 +1894,6 @@ async fn main() {
19841894
}
19851895

19861896
GameState::AccountPage => {
1987-
draw_texture_ex(
1988-
&default_bg_no_gradient,
1989-
-50.0,
1990-
-75.0,
1991-
Color::from_rgba(20, 20, 20, 255),
1992-
DrawTextureParams {
1993-
dest_size: Some(Vec2 {
1994-
x: default_bg_no_gradient.width() * screen_width() as f32 * 0.0008,
1995-
y: default_bg_no_gradient.height() * screen_width() as f32 * 0.0008
1996-
}),
1997-
source: None,
1998-
rotation: 0.0,
1999-
flip_x: false,
2000-
flip_y: false,
2001-
pivot: None
2002-
}
2003-
);
2004-
20051897
draw_text_pro(
20061898
&login_response,
20071899
screen_width() / 2.0 - measure_text_ex(&login_response, 20, &font) / 2.0,
@@ -2018,24 +1910,6 @@ async fn main() {
20181910
}
20191911

20201912
GameState::LevelUpload => {
2021-
draw_texture_ex(
2022-
&default_bg_no_gradient,
2023-
-50.0,
2024-
-75.0,
2025-
Color::from_rgba(20, 20, 20, 255),
2026-
DrawTextureParams {
2027-
dest_size: Some(Vec2 {
2028-
x: default_bg_no_gradient.width() * screen_width() as f32 * 0.0008,
2029-
y: default_bg_no_gradient.height() * screen_width() as f32 * 0.0008
2030-
}),
2031-
source: None,
2032-
rotation: 0.0,
2033-
flip_x: false,
2034-
flip_y: false,
2035-
pivot: None
2036-
}
2037-
);
2038-
20391913
draw_text_pro(
20401914
&level_upload_response,
20411915
screen_width() / 2.0 - measure_text_ex(&level_upload_response, 20, &font) / 2.0,

0 commit comments

Comments
 (0)