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

Build a crappy debugger #486

Merged
merged 2 commits into from
Jun 19, 2024
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
505 changes: 302 additions & 203 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion crates/gosub_css3/src/tokenizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use crate::unicode::{get_unicode_char, UnicodeChar};
use gosub_shared::byte_stream::Character::Ch;
use gosub_shared::byte_stream::{ByteStream, Character, Stream};
use std::fmt;
use std::usize;

pub type Number = f32;

Expand Down
46 changes: 45 additions & 1 deletion crates/gosub_render_backend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,22 @@ pub trait RenderBackend: Sized + Debug {
type Color: Color;
type Image: Image;
type Brush: Brush<Self>;
type Scene: Scene<Self>;

type ActiveWindowData<'a>;
type WindowData<'a>;

fn draw_rect(&mut self, data: &mut Self::WindowData<'_>, rect: &RenderRect<Self>);
fn draw_text(&mut self, data: &mut Self::WindowData<'_>, text: &RenderText<Self>);
fn apply_scene(
&mut self,
data: &mut Self::WindowData<'_>,
scene: &Self::Scene,
transform: Option<Self::Transform>,
);
fn reset(&mut self, data: &mut Self::WindowData<'_>);
// fn layer_push(&mut self, data: &mut Self::WindowData<'_>);
// fn layer_pop(&mut self, data: &mut Self::WindowData<'_>);

fn activate_window<'a>(
&mut self,
Expand Down Expand Up @@ -64,6 +73,15 @@ pub trait RenderBackend: Sized + Debug {
) -> Result<()>;
}

pub trait Scene<B: RenderBackend> {
fn draw_rect(&mut self, rect: &RenderRect<B>);
fn draw_text(&mut self, text: &RenderText<B>);
fn apply_scene(&mut self, scene: &B::Scene, transform: Option<B::Transform>);
fn reset(&mut self);

fn new(data: &mut B::WindowData<'_>) -> Self;
}

pub type FP = f32;
pub type Point = gosub_shared::types::Point<FP>;

Expand Down Expand Up @@ -525,6 +543,32 @@ pub trait Color {
Self::with_alpha(r, g, b, a)
}

fn tuple3(tup: (u8, u8, u8)) -> Self
where
Self: Sized,
{
Self::new(tup.0, tup.1, tup.2)
}

fn tuple4(tup: (u8, u8, u8, u8)) -> Self
where
Self: Sized,
{
Self::with_alpha(tup.0, tup.1, tup.2, tup.3)
}

fn alpha(self, a: u8) -> Self
where
Self: Sized,
{
Self::with_alpha(self.r(), self.g(), self.b(), a)
}

fn r(&self) -> u8;
fn g(&self) -> u8;
fn b(&self) -> u8;
fn a(&self) -> u8;

const WHITE: Self;
const BLACK: Self;
const RED: Self;
Expand All @@ -542,7 +586,7 @@ pub trait Image {
fn from_img(img: &image::DynamicImage) -> Self;
}

pub trait Brush<B: RenderBackend> {
pub trait Brush<B: RenderBackend>: Clone {
fn gradient(gradient: B::Gradient) -> Self;

fn color(color: B::Color) -> Self;
Expand Down
7 changes: 7 additions & 0 deletions crates/gosub_render_backend/src/svg.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use crate::RenderBackend;




pub trait SvgRenderer<B: RenderBackend> {
}
11 changes: 10 additions & 1 deletion crates/gosub_render_utils/src/position.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ use std::cmp::Ordering;
use rstar::{RTree, RTreeObject, AABB};
use taffy::{NodeId, PrintTree, TaffyTree};

struct Element {
#[derive(Debug)]
pub struct Element {
id: NodeId,
x: f32,
y: f32,
Expand Down Expand Up @@ -140,6 +141,14 @@ impl PositionTree {
.reduce(|a, b| if a.z_index >= b.z_index { a } else { b }) // >= because we just hope that the last-drawn element is last in the list
.map(|e| e.id)
}

pub fn get_node(&self, id: NodeId) -> Option<&Element> {
self.tree.iter().find(|e| e.id == id)
}

pub fn position(&self, id: NodeId) -> Option<(f32, f32)> {
self.get_node(id).map(|e| (e.x, e.y))
}
}

fn is_point_in_circle(circle_center: (f32, f32), circle_radius: f32, point: (f32, f32)) -> bool {
Expand Down
5 changes: 1 addition & 4 deletions crates/gosub_renderer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ gosub_styling = { path = "../gosub_styling" }
gosub_net = { path = "../gosub_net" }
gosub_render_backend = { path = "../gosub_render_backend" }
taffy = "0.5.1"
vello = "0.1.0"
winit = "0.29.15"
anyhow = "1.0.86"
wgpu = "0.19.3"
futures = "0.3.30"
slotmap = "1.0.7"
smallvec = "1.13.2"
Expand All @@ -30,4 +27,4 @@ dpi = "0.1.1"

[target.'cfg(target_arch = "wasm32")'.dependencies]
wasm-bindgen-futures = "0.4.42"
web-sys = "0.3.55"
web-sys = "0.3.55"
Loading
Loading