Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to glutin 0.25 #252

Merged
merged 1 commit into from
Nov 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ conrod_core = { version = "0.71", features = [ "wasm-bindgen" ], optional = tru
glow = "0.6"

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
glutin = "0.21"
glutin = "0.25"

# We repeat all three targets instead of any(target_arch = "wasm32", target_arch = "asmjs")
# to avoid https://github.com/koute/stdweb/issues/135
Expand Down
6 changes: 3 additions & 3 deletions src/planar_camera/fixed_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ impl FixedView {

impl PlanarCamera for FixedView {
fn handle_event(&mut self, canvas: &Canvas, event: &WindowEvent) {
let hidpi = canvas.hidpi_factor();
let scale = canvas.scale_factor();

match *event {
WindowEvent::FramebufferSize(w, h) => {
let diag = Vector3::new(
2.0 * (hidpi as f32) / (w as f32),
2.0 * (hidpi as f32) / (h as f32),
2.0 * (scale as f32) / (w as f32),
2.0 * (scale as f32) / (h as f32),
1.0,
);
let inv_diag = Vector3::new(1.0 / diag.x, 1.0 / diag.y, 1.0);
Expand Down
6 changes: 3 additions & 3 deletions src/planar_camera/sidescroll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ impl Sidescroll {

impl PlanarCamera for Sidescroll {
fn handle_event(&mut self, canvas: &Canvas, event: &WindowEvent) {
let hidpi = 1.0; // canvas.hidpi_factor();
let scale = 1.0; // canvas.scale_factor();

match *event {
WindowEvent::CursorPos(x, y, _) => {
Expand All @@ -138,11 +138,11 @@ impl PlanarCamera for Sidescroll {
WindowEvent::Scroll(_, off, _) => self.handle_scroll(off as f32),
WindowEvent::FramebufferSize(w, h) => {
self.proj = Matrix3::new(
2.0 * (hidpi as f32) / (w as f32),
2.0 * (scale as f32) / (w as f32),
0.0,
0.0,
0.0,
2.0 * (hidpi as f32) / (h as f32),
2.0 * (scale as f32) / (h as f32),
0.0,
0.0,
0.0,
Expand Down
64 changes: 32 additions & 32 deletions src/renderer/conrod_renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,14 +174,14 @@ impl ConrodRenderer {
&mut self,
width: f32,
height: f32,
hidpi_factor: f32,
scale_factor: f32,
texture_map: &conrod::image::Map<(Rc<Texture>, (u32, u32))>,
) {
// NOTE: this seems necessary for WASM.
if !self.resized_once {
self.ui.handle_event(conrod::event::Input::Resize(
width as f64 / hidpi_factor as f64,
height as f64 / hidpi_factor as f64,
width as f64 / scale_factor as f64,
height as f64 / scale_factor as f64,
));
self.resized_once = true;
}
Expand All @@ -207,10 +207,10 @@ impl ConrodRenderer {

let rect_to_gl_rect = |rect: Rect| {
let (w, h) = rect.w_h();
let l = rect.left() as f32 * hidpi_factor + width / 2.0;
let b = rect.bottom() as f32 * hidpi_factor + height / 2.0;
let w = w as f32 * hidpi_factor;
let h = h as f32 * hidpi_factor;
let l = rect.left() as f32 * scale_factor + width / 2.0;
let b = rect.bottom() as f32 * scale_factor + height / 2.0;
let w = w as f32 * scale_factor;
let h = h as f32 * scale_factor;

(l.max(0.0), b.max(0.0), w.min(width), h.min(height))
};
Expand Down Expand Up @@ -360,26 +360,26 @@ impl ConrodRenderer {
let tr = (primitive.rect.x.end, primitive.rect.y.end);

vertices.extend_from_slice(&[
tl.0 as f32 * hidpi_factor,
tl.1 as f32 * hidpi_factor,
tl.0 as f32 * scale_factor,
tl.1 as f32 * scale_factor,
color.0,
color.1,
color.2,
color.3,
bl.0 as f32 * hidpi_factor,
bl.1 as f32 * hidpi_factor,
bl.0 as f32 * scale_factor,
bl.1 as f32 * scale_factor,
color.0,
color.1,
color.2,
color.3,
br.0 as f32 * hidpi_factor,
br.1 as f32 * hidpi_factor,
br.0 as f32 * scale_factor,
br.1 as f32 * scale_factor,
color.0,
color.1,
color.2,
color.3,
tr.0 as f32 * hidpi_factor,
tr.1 as f32 * hidpi_factor,
tr.0 as f32 * scale_factor,
tr.1 as f32 * scale_factor,
color.0,
color.1,
color.2,
Expand All @@ -398,20 +398,20 @@ impl ConrodRenderer {
let pts = triangle.points();

vertices.extend_from_slice(&[
pts[0][0] as f32 * hidpi_factor,
pts[0][1] as f32 * hidpi_factor,
pts[0][0] as f32 * scale_factor,
pts[0][1] as f32 * scale_factor,
color.0,
color.1,
color.2,
color.3,
pts[1][0] as f32 * hidpi_factor,
pts[1][1] as f32 * hidpi_factor,
pts[1][0] as f32 * scale_factor,
pts[1][1] as f32 * scale_factor,
color.0,
color.1,
color.2,
color.3,
pts[2][0] as f32 * hidpi_factor,
pts[2][1] as f32 * hidpi_factor,
pts[2][0] as f32 * scale_factor,
pts[2][1] as f32 * scale_factor,
color.0,
color.1,
color.2,
Expand All @@ -429,20 +429,20 @@ impl ConrodRenderer {
let ((a, ca), (b, cb), (c, cc)) =
(triangle.0[0], triangle.0[1], triangle.0[2]);
vertices.extend_from_slice(&[
a[0] as f32 * hidpi_factor,
a[1] as f32 * hidpi_factor,
a[0] as f32 * scale_factor,
a[1] as f32 * scale_factor,
ca.0,
ca.1,
ca.2,
ca.3,
b[0] as f32 * hidpi_factor,
b[1] as f32 * hidpi_factor,
b[0] as f32 * scale_factor,
b[1] as f32 * scale_factor,
cb.0,
cb.1,
cb.2,
cb.3,
c[0] as f32 * hidpi_factor,
c[1] as f32 * hidpi_factor,
c[0] as f32 * scale_factor,
c[1] as f32 * scale_factor,
cc.0,
cc.1,
cc.2,
Expand All @@ -465,10 +465,10 @@ impl ConrodRenderer {
texture: image_id,
};

let min_px = primitive.rect.x.start as f32 * hidpi_factor;
let min_py = primitive.rect.y.start as f32 * hidpi_factor;
let max_px = primitive.rect.x.end as f32 * hidpi_factor;
let max_py = primitive.rect.y.end as f32 * hidpi_factor;
let min_px = primitive.rect.x.start as f32 * scale_factor;
let min_py = primitive.rect.y.start as f32 * scale_factor;
let max_px = primitive.rect.x.end as f32 * scale_factor;
let max_py = primitive.rect.y.end as f32 * scale_factor;

let w = (texture.1).0 as f64;
let h = (texture.1).1 as f64;
Expand Down Expand Up @@ -534,7 +534,7 @@ impl ConrodRenderer {
/*
* Update the text image.
*/
let positioned_glyphs = text.positioned_glyphs(hidpi_factor);
let positioned_glyphs = text.positioned_glyphs(scale_factor);
for glyph in positioned_glyphs.iter() {
self.cache.queue_glyph(font_id.index(), glyph.clone());
}
Expand Down
8 changes: 4 additions & 4 deletions src/window/canvas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ impl Canvas {
self.canvas.cursor_pos()
}

/// The high-dpi factor.
pub fn hidpi_factor(&self) -> f64 {
self.canvas.hidpi_factor()
/// The scale factor.
pub fn scale_factor(&self) -> f64 {
self.canvas.scale_factor()
}

/// Set the window title.
Expand Down Expand Up @@ -160,7 +160,7 @@ pub(crate) trait AbstractCanvas {
fn swap_buffers(&mut self);
fn size(&self) -> (u32, u32);
fn cursor_pos(&self) -> Option<(f64, f64)>;
fn hidpi_factor(&self) -> f64;
fn scale_factor(&self) -> f64;

fn set_title(&mut self, title: &str);
fn set_icon(&mut self, icon: impl GenericImage<Pixel = impl Pixel<Subpixel = u8>>);
Expand Down
Loading