summaryrefslogtreecommitdiff
path: root/pixel-client/src/render
diff options
context:
space:
mode:
Diffstat (limited to 'pixel-client/src/render')
-rw-r--r--pixel-client/src/render/font.rs5
-rw-r--r--pixel-client/src/render/misc.rs2
-rw-r--r--pixel-client/src/render/mod.rs9
-rw-r--r--pixel-client/src/render/sprite.rs10
4 files changed, 23 insertions, 3 deletions
diff --git a/pixel-client/src/render/font.rs b/pixel-client/src/render/font.rs
index ff4abade..392c1d66 100644
--- a/pixel-client/src/render/font.rs
+++ b/pixel-client/src/render/font.rs
@@ -25,8 +25,9 @@ impl FontTextures {
}
impl<'a> Renderer<'a> {
- pub fn draw_text(&mut self, position: Vec2, text: &str) {
+ pub fn draw_text(&mut self, position: Vec2, text: &str) -> Vec2 {
let mut cursor = position;
+ let mut line_height = 0f32;
for c in text.chars() {
if (c as u32) < 128 {
let r = self.font_textures.glyphs[c as usize];
@@ -37,7 +38,9 @@ impl<'a> Renderer<'a> {
None,
));
cursor.x += r.width() as f32;
+ line_height = line_height.max(r.height() as f32)
}
}
+ cursor + Vec2::Y * line_height
}
}
diff --git a/pixel-client/src/render/misc.rs b/pixel-client/src/render/misc.rs
index 05cde8e4..2197b89c 100644
--- a/pixel-client/src/render/misc.rs
+++ b/pixel-client/src/render/misc.rs
@@ -24,6 +24,7 @@ pub struct MiscTextures {
pub customer: Sprite,
pub interact_target: Sprite,
pub solid: Rect,
+ pub clouds: Rect,
}
impl MiscTextures {
@@ -37,6 +38,7 @@ impl MiscTextures {
10.,
),
solid: *layout.get("solid+a").unwrap(),
+ clouds: *layout.get("clouds+a").unwrap(),
}
}
}
diff --git a/pixel-client/src/render/mod.rs b/pixel-client/src/render/mod.rs
index 9b3132f9..74c282f3 100644
--- a/pixel-client/src/render/mod.rs
+++ b/pixel-client/src/render/mod.rs
@@ -21,6 +21,7 @@ pub mod sprite;
use font::FontTextures;
use hurrycurry_protocol::glam::Vec2;
+use misc::MiscTextures;
use sdl2::{
pixels::PixelFormatEnum,
rect::{FRect, Rect},
@@ -34,8 +35,10 @@ pub struct Renderer<'a> {
metadata: AtlasLayout,
font_textures: FontTextures,
+ pub misc_textures: MiscTextures,
pub size: Vec2,
+ pub ui_size: Vec2,
texture: Texture<'a>,
world_scale: Vec2,
@@ -109,6 +112,8 @@ impl<'a> Renderer<'a> {
Self {
ui_scale: Vec2::ZERO,
+ ui_size: Vec2::ZERO,
+ misc_textures: MiscTextures::init(&atlas_layout),
texture,
font_textures: FontTextures::init(&atlas_layout),
size: Vec2::ONE,
@@ -123,6 +128,10 @@ impl<'a> Renderer<'a> {
self.world_offset = offset;
self.world_scale = Vec2::new(32., 24.) * scale;
}
+ pub fn set_ui_view(&mut self, scale: f32) {
+ self.ui_scale = Vec2::splat(scale);
+ self.ui_size = self.size / self.ui_scale;
+ }
pub fn get_world_scale(&self) -> Vec2 {
self.world_scale
}
diff --git a/pixel-client/src/render/sprite.rs b/pixel-client/src/render/sprite.rs
index 084e277e..292a99ab 100644
--- a/pixel-client/src/render/sprite.rs
+++ b/pixel-client/src/render/sprite.rs
@@ -65,14 +65,20 @@ pub struct SpriteDraw {
}
impl SpriteDraw {
- pub fn overlay(src: Rect, pos: Vec2, size: Vec2, tint: Option<[u8; 4]>) -> Self {
+ pub fn screen(src: Rect, z_order: i32, pos: Vec2, size: Vec2, tint: Option<[u8; 4]>) -> Self {
Self {
dst: FRect::new(pos.x, pos.y, size.x, size.y),
src,
tint: tint.unwrap_or([0xff; 4]),
- z_order: i32::MAX,
+ z_order,
}
}
+ pub fn overlay(src: Rect, pos: Vec2, size: Vec2, tint: Option<[u8; 4]>) -> Self {
+ SpriteDraw::screen(src, i32::MAX, pos, size, tint)
+ }
+ pub fn underlay(src: Rect, pos: Vec2, size: Vec2, tint: Option<[u8; 4]>) -> Self {
+ SpriteDraw::screen(src, i32::MIN, pos, size, tint)
+ }
pub fn alpha(mut self, alpha: f32) -> Self {
self.tint[3] = (alpha.clamp(0., 1.) * 255.) as u8;
self