Эх сурвалжийг харах

wallet: make screen coords consistently use pixels everywhere

rsx 2 жил өмнө
parent
commit
2623d0e4cf

+ 8 - 10
bin/darkwallet/gui/__init__.py

@@ -56,9 +56,12 @@ def resize_box():
 
     mesh_id = api.lookup_node_id("/window/chatbox_layer/outline/box")
 
+    layer_w = get_property("/window/chatbox_layer", "rect_w")
+    layer_h = get_property("/window/chatbox_layer", "rect_h")
+
     # Lets add a poly - must be counterclockwise
-    x, y = 0.25, 0.25
-    w, h = 0.5, 0.5
+    x, y = layer_w * 0.25, layer_h * 0.25
+    w, h = layer_w * 0.50, layer_h * 0.50
     vert1 = vertex(x,     y,     1, 1, 1, 1, 0, 0)
     vert2 = vertex(x + w, y,     1, 1, 1, 1, 1, 0)
     vert3 = vertex(x,     y + h, 1, 1, 1, 1, 0, 1)
@@ -67,16 +70,11 @@ def resize_box():
     api.set_property_buffer(mesh_id, "faces", face(0, 2, 1) + face(1, 2, 3))
 
     # Second mesh
-    w = get_property("/window/chatbox_layer", "rect_w")
-    h = get_property("/window/chatbox_layer", "rect_h")
-    # in pixels
-    border_size = 5
-    bx, by = 5/w, 5/h
-
     mesh_id = api.lookup_node_id("/window/chatbox_layer/outline/inner_box")
 
-    x, y = 0.25 + bx, 0.25 + by
-    w, h = 0.50 - 2*bx, 0.50 - 2*by
+    x, y = x + 5, y + 5
+    w -= 10
+    h -= 10
     vert1 = vertex(x,     y,     0, 0, 0, 1, 0, 0)
     vert2 = vertex(x + w, y,     0, 0, 0, 1, 1, 0)
     vert3 = vertex(x,     y + h, 0, 0, 0, 1, 0, 1)

+ 3 - 5
bin/darkwallet/src/gfx.rs

@@ -232,18 +232,15 @@ impl Stage {
         glyph_pos: &GlyphPosition,
         color: [f32; 4],
     ) {
-        let (screen_width, screen_height) = window::screen_size();
         //let proj =
         //    glam::Mat4::from_translation(glam::Vec3::new(-1., 1., 0.)) *
         //    glam::Mat4::from_scale(glam::Vec3::new(2./screen_width, -2./screen_height, 1.));
         //let model = glam::Mat4::IDENTITY;
-        let model = *model *
-            glam::Mat4::from_scale(glam::Vec3::new(1. / screen_width, 1. / screen_height, 1.));
 
         let mut uniforms_data = [0u8; 128];
         let data: [u8; 64] = unsafe { std::mem::transmute_copy(proj) };
         uniforms_data[0..64].copy_from_slice(&data);
-        let data: [u8; 64] = unsafe { std::mem::transmute_copy(&model) };
+        let data: [u8; 64] = unsafe { std::mem::transmute_copy(model) };
         uniforms_data[64..].copy_from_slice(&data);
         assert_eq!(128, 2 * UniformType::Mat4.size());
 
@@ -496,10 +493,11 @@ impl EventHandler for Stage {
         self.ctx.begin_default_pass(clear);
         self.ctx.end_render_pass();
 
+        let (screen_width, screen_height) = window::screen_size();
         // This will make the top left (0, 0) and the bottom right (1, 1)
         // Default is (-1, 1) -> (1, -1)
         let proj = glam::Mat4::from_translation(glam::Vec3::new(-1., 1., 0.)) *
-            glam::Mat4::from_scale(glam::Vec3::new(2., -2., 1.));
+            glam::Mat4::from_scale(glam::Vec3::new(2./screen_width, -2./screen_height, 1.));
 
         // Reusable text layout
         let mut layout = Layout::new(CoordinateSystem::PositiveYDown);