Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ The app has some simple hotkeys:
| <kbd>x</kbd> | WINDOWS ONLY Toggle Window Fallthrough 3D |
| <kbd>l</kbd> | Window-Level |
| <kbd>d</kbd> | Toggle Decorations (not all OSes) |
| <kbd>b</kbd> | Toggle Border (3d only) |
| <kbd>t</kbd> | Toggle Transparency (returning to fully transparent is not supported) |
| <kbd>r</kbd> | Toggle Rotating shape (3d only) |
| <kbd>spacebar</kbd> | Takes a screenshot && versions the current `.wgsl` |
Expand Down
9 changes: 7 additions & 2 deletions src/plugin.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::camera::PanOrbitCameraPlugin;
use crate::{camera::PanOrbitCameraPlugin, utils::{ShadplayWindowBorder, toggle_border}};
use bevy::{
input::keyboard::KeyboardInput, log::tracing_subscriber::util::SubscriberInitExt, prelude::*,
sprite_render::Material2dPlugin, window::WindowResized,
Expand All @@ -22,13 +22,15 @@ impl Plugin for ShadPlayPlugin {
.insert_resource(MonitorsSpecs::default())
.insert_resource(TexHandleQueue::default())
.insert_resource(ShadplayWindowDims::default())
.insert_resource(ShadplayWindowBorder::default())
.insert_resource(ShapeOptions::default())
.insert_resource(TransparencySet(true))
.insert_resource(Rotating(false))
.add_plugins(PanOrbitCameraPlugin)
//events:
.add_message::<UserAddedTexture>()
.add_message::<DragNDropShader>()
.add_message::<ShadplayWindowBorder>()
// 3D
.add_systems(OnEnter(AppState::ThreeD), setup_3d)
.add_systems(OnExit(AppState::ThreeD), cleanup_3d)
Expand Down Expand Up @@ -72,9 +74,12 @@ impl Plugin for ShadPlayPlugin {
(
// utils::max_mon_res, // We're currently not using the maximum resolution of the primary monitor.
update_mouse_pos,
toggle_border
.run_if(in_state(AppState::TwoD))
.run_if(on_message::<KeyboardInput>),
size_quad
.run_if(in_state(AppState::TwoD))
.run_if(on_message::<WindowResized>),
.run_if(on_message::<WindowResized>.or(on_message::<ShadplayWindowBorder>)),
swap_2d_tex_from_idx.run_if(on_message::<KeyboardInput>),
),
);
Expand Down
50 changes: 49 additions & 1 deletion src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,35 @@ impl ShadplayWindowDims {
}
}

/// Resource and Message: Used for toggling on/off border for the 2d shader.
#[derive(Resource, Message, Debug, Clone)]
pub struct ShadplayWindowBorder {
pub enabled: bool,
pub thickness: Vec2
}

impl ShadplayWindowBorder {
/// Get border thickness in __%__
///
/// If `enabled` is `false` will return __x__ = `1.00`, __y__ = `1.00`
pub fn thickness(&self) -> Vec2 {
if !self.enabled {
return Vec2::new(1.00, 1.00);
}

1.00 - self.thickness
}
}

impl Default for ShadplayWindowBorder {
fn default() -> Self {
Self {
enabled: true,
thickness: Vec2::new(0.05, 0.05)
}
}
}

/// Resource: All the shapes we have the option of displaying. 3d Only.
#[allow(clippy::type_complexity)]
#[derive(Resource, Default)]
Expand Down Expand Up @@ -429,25 +458,44 @@ pub fn size_quad(
windows: Query<&Window>,
mut query: Query<&mut Transform, With<BillBoardQuad>>,
mut msd: ResMut<ShadplayWindowDims>,
border: Res<ShadplayWindowBorder>,
// monitors: Res<MonitorsSpecs>,
) {
let win = windows
.single()
.expect("Should be impossible to NOT get a window");

let (width, height) = (win.width(), win.height());
let (border_w, border_h) = (border.thickness().x, border.thickness().y);

query.iter_mut().for_each(|mut transform| {
*msd = ShadplayWindowDims(Vec2 {
x: width,
y: height,
});

transform.scale = Vec3::new(width * 0.95, height * 0.95, 1.0);
transform.scale = Vec3::new(width * border_w, height * border_h, 1.0);
info!("Window Resized, resizing quad");
});
}

/// System: Runs only when in [`AppState::TwoD`]
///
/// Used for toggling on/off the window border.
///
/// Press `b` when in 2D mode to toggle the window border.
pub fn toggle_border(
mut border: ResMut<ShadplayWindowBorder>,
input: Res<ButtonInput<KeyCode>>,
mut fire_event: MessageWriter<ShadplayWindowBorder>
) {
if input.just_pressed(KeyCode::KeyB) {
info!("Toggling window border");
border.enabled = !border.enabled;
fire_event.write(border.clone());
}
}

// Monitor Maximum Res.
pub fn max_mon_res(
window_query: Query<Entity, With<Window>>,
Expand Down