mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Scaling of ingame text rasterization to match final size
Former-commit-id: 9f9e900afef2400af35d579e66ba95097e169b87
This commit is contained in:
parent
a128abc925
commit
24a14b083f
@ -24,6 +24,7 @@ use small_window::{SmallWindow, SmallWindowType};
|
||||
|
||||
use crate::{
|
||||
render::{Consts, Globals, Renderer},
|
||||
scene::camera::Camera,
|
||||
settings::{ControlSettings, Settings},
|
||||
ui::{Ingame, Ingameable, ScaleMode, Ui},
|
||||
window::{Event as WinEvent, Key, Window},
|
||||
@ -342,15 +343,6 @@ impl Hud {
|
||||
.set(bar_id, ui_widgets);
|
||||
}
|
||||
}
|
||||
// test
|
||||
Text::new("Squarefection")
|
||||
.font_size(20)
|
||||
.color(TEXT_COLOR)
|
||||
.font_id(self.fonts.opensans)
|
||||
.x_y(0.0, 0.0)
|
||||
.position_ingame([0.0, 25.0, 25.0].into())
|
||||
.resolution(20.0)
|
||||
.set(self.ids.temp, ui_widgets);
|
||||
|
||||
// Display debug window.
|
||||
if self.show.debug {
|
||||
@ -682,12 +674,15 @@ impl Hud {
|
||||
client: &Client,
|
||||
global_state: &mut GlobalState,
|
||||
debug_info: DebugInfo,
|
||||
camera: &Camera,
|
||||
) -> Vec<Event> {
|
||||
if let Some(maybe_id) = self.to_focus.take() {
|
||||
self.ui.focus_widget(maybe_id);
|
||||
}
|
||||
let events = self.update_layout(client, global_state, debug_info);
|
||||
self.ui.maintain(&mut global_state.window.renderer_mut());
|
||||
let (view_mat, _, _) = camera.compute_dependents(client);
|
||||
let fov = camera.get_fov();
|
||||
self.ui.maintain(&mut global_state.window.renderer_mut(), Some((view_mat, fov)));
|
||||
events
|
||||
}
|
||||
|
||||
|
@ -1081,7 +1081,7 @@ impl CharSelectionUi {
|
||||
|
||||
pub fn maintain(&mut self, renderer: &mut Renderer) -> Vec<Event> {
|
||||
let events = self.update_layout();
|
||||
self.ui.maintain(renderer);
|
||||
self.ui.maintain(renderer, None);
|
||||
events
|
||||
}
|
||||
|
||||
|
@ -508,7 +508,7 @@ impl MainMenuUi {
|
||||
|
||||
pub fn maintain(&mut self, global_state: &mut GlobalState) -> Vec<Event> {
|
||||
let events = self.update_layout(global_state);
|
||||
self.ui.maintain(global_state.window.renderer_mut());
|
||||
self.ui.maintain(global_state.window.renderer_mut(), None);
|
||||
events
|
||||
}
|
||||
|
||||
|
@ -150,4 +150,9 @@ impl Camera {
|
||||
pub fn get_orientation(&self) -> Vec3<f32> {
|
||||
self.ori
|
||||
}
|
||||
|
||||
/// Get the field of view of the camera in radians.
|
||||
pub fn get_fov(&self) -> f32 {
|
||||
self.fov
|
||||
}
|
||||
}
|
||||
|
@ -182,6 +182,7 @@ impl PlayState for SessionState {
|
||||
tps: clock.get_tps(),
|
||||
ping_ms: self.client.borrow().get_ping_ms(),
|
||||
},
|
||||
&self.scene.camera(),
|
||||
);
|
||||
// Maintain the UI.
|
||||
for event in hud_events {
|
||||
@ -214,6 +215,7 @@ impl PlayState for SessionState {
|
||||
}
|
||||
}
|
||||
}
|
||||
{}
|
||||
|
||||
// Render the session.
|
||||
self.render(global_state.window.renderer_mut());
|
||||
|
@ -17,8 +17,8 @@ pub struct Cache {
|
||||
impl Cache {
|
||||
pub fn new(renderer: &mut Renderer) -> Result<Self, Error> {
|
||||
let (w, h) = renderer.get_resolution().into_tuple();
|
||||
const SCALE_TOLERANCE: f32 = 0.1;
|
||||
const POSITION_TOLERANCE: f32 = 0.1;
|
||||
const SCALE_TOLERANCE: f32 = 0.3;
|
||||
const POSITION_TOLERANCE: f32 = 0.5;
|
||||
|
||||
let graphic_cache_dims = Vec2::new(w * 4, h * 4);
|
||||
Ok(Self {
|
||||
|
@ -23,6 +23,7 @@ use crate::{
|
||||
create_ui_quad, create_ui_tri, Consts, DynamicModel, Globals, Mesh, RenderError, Renderer,
|
||||
UiLocals, UiMode, UiPipeline,
|
||||
},
|
||||
scene::camera::Camera,
|
||||
window::Window,
|
||||
Error,
|
||||
};
|
||||
@ -205,7 +206,7 @@ impl Ui {
|
||||
self.ui.widget_input(id)
|
||||
}
|
||||
|
||||
pub fn maintain(&mut self, renderer: &mut Renderer) {
|
||||
pub fn maintain(&mut self, renderer: &mut Renderer, mats: Option<(Mat4<f32>, f32)>) {
|
||||
// Regenerate draw commands and associated models only if the ui changed
|
||||
let mut primitives = match self.ui.draw_if_changed() {
|
||||
Some(primitives) => primitives,
|
||||
@ -229,6 +230,7 @@ impl Ui {
|
||||
let mut current_scissor = window_scissor;
|
||||
|
||||
let mut in_world = None;
|
||||
// TODO: maybe mutate an ingame scale factor instead of this, depends on if we want them to scale with other ui scaling or not
|
||||
let mut p_scale_factor = self.scale.scale_factor_physical();
|
||||
|
||||
// Switches to the `Plain` state and completes the previous `Command` if not already in the
|
||||
@ -301,8 +303,14 @@ impl Ui {
|
||||
}
|
||||
Some((n, res)) => match kind {
|
||||
// Other types don't need to be drawn in the game
|
||||
PrimitiveKind::Other(_) => (),
|
||||
_ => in_world = Some((n - 1, res)),
|
||||
PrimitiveKind::Other(_) => {}
|
||||
_ => {
|
||||
in_world = Some((n - 1, res));
|
||||
// Skip
|
||||
if p_scale_factor < 0.5 {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
},
|
||||
None => {}
|
||||
}
|
||||
@ -526,7 +534,25 @@ impl Ui {
|
||||
)));
|
||||
|
||||
in_world = Some((parameters.num, parameters.res));
|
||||
p_scale_factor = 1.0;
|
||||
// Calculate the scale factor to pixels at this 3d point using the camera.
|
||||
p_scale_factor = match mats {
|
||||
Some((view_mat, fov)) => {
|
||||
let pos_in_view = view_mat * Vec4::from_point(parameters.pos);
|
||||
let scale_factor = self.ui.win_w as f64
|
||||
/ (-2.0
|
||||
* pos_in_view.z as f64
|
||||
* (0.5 * fov as f64).tan()
|
||||
* parameters.res as f64);
|
||||
// Don't draw really small ingame elements or those behind the camera
|
||||
if scale_factor > 0.1 {
|
||||
scale_factor.min(2.0).max(0.5)
|
||||
} else {
|
||||
// TODO: use a flag or option instead of this
|
||||
-1.0
|
||||
}
|
||||
}
|
||||
None => 1.0,
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {} // TODO: Add this.
|
||||
|
Loading…
Reference in New Issue
Block a user