Fix vertex and cursor sandbox coords

This commit is contained in:
mars 2022-11-15 16:51:41 -07:00
parent 066430ccba
commit a648ef360e
1 changed files with 6 additions and 9 deletions

View File

@ -1,7 +1,7 @@
// Copyright (c) 2022 Marceline Cramer
// SPDX-License-Identifier: AGPL-3.0-or-later
use canary::{CursorEventKind, Panel, Runtime, Script};
use canary::{CursorEventKind, Panel, Runtime, Script, PX_PER_MM};
use eframe::egui;
use std::time::Instant;
@ -111,11 +111,8 @@ impl PanelWindow {
let (rect, response) = ui.allocate_at_least(size, sense);
if let Some(hover_pos) = response.hover_pos() {
let local = (hover_pos - rect.left_top()) / rect.size();
let norm = local * 2.0 - egui::vec2(1.0, 1.0);
let x = norm.x;
let y = -norm.y;
let pos = canary::Vec2 { x, y };
let local = (hover_pos - rect.left_top()) * PX_PER_MM;
let pos = canary::Vec2::new(local.x, local.y);
let kind = if response.drag_started() {
CursorEventKind::Select
@ -142,9 +139,9 @@ impl PanelWindow {
canary::DrawCommand::Mesh { vertices, indices } => {
for v in vertices.iter() {
use egui::epaint::Vertex;
let pos = egui::pos2(v.position.x, -v.position.y);
let pos = pos.to_vec2() / 2.0 + egui::vec2(0.5, 0.5);
let pos = rect.left_top() + pos * rect.size();
let pos = v.position / PX_PER_MM;
let pos = egui::pos2(pos.x, pos.y);
let pos = pos + rect.left_top().to_vec2();
let (r, g, b, a) = v.color.to_rgba_unmultiplied();
let color = egui::Color32::from_rgba_unmultiplied(r, g, b, a);
let v = Vertex { pos, uv, color };