keyboard shift mode
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use glam::{Vec2, Vec3};
|
use glam::{Vec2, Vec3, Vec4};
|
||||||
use vulkano::{
|
use vulkano::{
|
||||||
command_buffer::CommandBufferUsage,
|
command_buffer::CommandBufferUsage,
|
||||||
format::Format,
|
format::Format,
|
||||||
@@ -9,7 +9,7 @@ use vulkano::{
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
backend::{
|
backend::{
|
||||||
input::{InteractionHandler, PointerHit},
|
input::{InteractionHandler, PointerHit, PointerMode},
|
||||||
overlay::{OverlayBackend, OverlayRenderer},
|
overlay::{OverlayBackend, OverlayRenderer},
|
||||||
},
|
},
|
||||||
graphics::{WlxCommandBuffer, WlxGraphics, WlxPass, WlxPipeline, WlxPipelineLegacy},
|
graphics::{WlxCommandBuffer, WlxGraphics, WlxPass, WlxPipeline, WlxPipelineLegacy},
|
||||||
@@ -370,7 +370,7 @@ impl<D, S> InteractionHandler for Canvas<D, S> {
|
|||||||
if pressed {
|
if pressed {
|
||||||
if let Some(ref mut f) = c.on_press {
|
if let Some(ref mut f) = c.on_press {
|
||||||
self.pressed_controls[hit.pointer] = Some(idx);
|
self.pressed_controls[hit.pointer] = Some(idx);
|
||||||
f(c, &mut self.canvas.data, app);
|
f(c, &mut self.canvas.data, app, hit.mode);
|
||||||
}
|
}
|
||||||
} else if let Some(ref mut f) = c.on_release {
|
} else if let Some(ref mut f) = c.on_release {
|
||||||
self.pressed_controls[hit.pointer] = None;
|
self.pressed_controls[hit.pointer] = None;
|
||||||
@@ -435,12 +435,18 @@ impl<D, S> OverlayRenderer for Canvas<D, S> {
|
|||||||
for (i, c) in self.controls.iter_mut().enumerate() {
|
for (i, c) in self.controls.iter_mut().enumerate() {
|
||||||
if let Some(render) = c.on_render_hl {
|
if let Some(render) = c.on_render_hl {
|
||||||
if let Some(test) = c.test_highlight {
|
if let Some(test) = c.test_highlight {
|
||||||
if test(c, &mut self.canvas.data, app) {
|
if let Some(hl_color) = test(c, &mut self.canvas.data, app) {
|
||||||
render(c, &self.canvas, app, &mut cmd_buffer, true);
|
render(c, &self.canvas, app, &mut cmd_buffer, hl_color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if self.hover_controls.contains(&Some(i)) {
|
if self.hover_controls.contains(&Some(i)) {
|
||||||
render(c, &self.canvas, app, &mut cmd_buffer, false);
|
render(
|
||||||
|
c,
|
||||||
|
&self.canvas,
|
||||||
|
app,
|
||||||
|
&mut cmd_buffer,
|
||||||
|
Vec4::new(1., 1., 1., 0.3),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -484,12 +490,12 @@ pub struct Control<D, S> {
|
|||||||
dirty: bool,
|
dirty: bool,
|
||||||
|
|
||||||
pub on_update: Option<fn(&mut Self, &mut D, &mut AppState)>,
|
pub on_update: Option<fn(&mut Self, &mut D, &mut AppState)>,
|
||||||
pub on_press: Option<fn(&mut Self, &mut D, &mut AppState)>,
|
pub on_press: Option<fn(&mut Self, &mut D, &mut AppState, PointerMode)>,
|
||||||
pub on_release: Option<fn(&mut Self, &mut D, &mut AppState)>,
|
pub on_release: Option<fn(&mut Self, &mut D, &mut AppState)>,
|
||||||
pub test_highlight: Option<fn(&Self, &mut D, &mut AppState) -> bool>,
|
pub test_highlight: Option<fn(&Self, &mut D, &mut AppState) -> Option<Vec4>>,
|
||||||
|
|
||||||
on_render_bg: Option<fn(&Self, &CanvasData<D>, &mut AppState, &mut WlxCommandBuffer)>,
|
on_render_bg: Option<fn(&Self, &CanvasData<D>, &mut AppState, &mut WlxCommandBuffer)>,
|
||||||
on_render_hl: Option<fn(&Self, &CanvasData<D>, &mut AppState, &mut WlxCommandBuffer, bool)>,
|
on_render_hl: Option<fn(&Self, &CanvasData<D>, &mut AppState, &mut WlxCommandBuffer, Vec4)>,
|
||||||
on_render_fg: Option<fn(&Self, &CanvasData<D>, &mut AppState, &mut WlxCommandBuffer)>,
|
on_render_fg: Option<fn(&Self, &CanvasData<D>, &mut AppState, &mut WlxCommandBuffer)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -562,7 +568,7 @@ impl<D, S> Control<D, S> {
|
|||||||
canvas: &CanvasData<D>,
|
canvas: &CanvasData<D>,
|
||||||
_: &mut AppState,
|
_: &mut AppState,
|
||||||
cmd_buffer: &mut WlxCommandBuffer,
|
cmd_buffer: &mut WlxCommandBuffer,
|
||||||
strong: bool,
|
color: Vec4,
|
||||||
) {
|
) {
|
||||||
let vertex_buffer = canvas.graphics.upload_verts(
|
let vertex_buffer = canvas.graphics.upload_verts(
|
||||||
canvas.width as _,
|
canvas.width as _,
|
||||||
@@ -572,10 +578,11 @@ impl<D, S> Control<D, S> {
|
|||||||
self.rect.w,
|
self.rect.w,
|
||||||
self.rect.h,
|
self.rect.h,
|
||||||
);
|
);
|
||||||
|
|
||||||
let set0 = canvas
|
let set0 = canvas
|
||||||
.pipeline_bg_color
|
.pipeline_bg_color
|
||||||
.uniform_buffer(0, vec![1.0, 1.0, 1.0, if strong { 0.5 } else { 0.3 }]); //FIXME why is
|
.uniform_buffer(0, color.to_array().to_vec());
|
||||||
//this green
|
|
||||||
let pass = canvas.pipeline_bg_color.create_pass(
|
let pass = canvas.pipeline_bg_color.create_pass(
|
||||||
[canvas.width as _, canvas.height as _],
|
[canvas.width as _, canvas.height as _],
|
||||||
vertex_buffer.clone(),
|
vertex_buffer.clone(),
|
||||||
|
|||||||
@@ -7,13 +7,16 @@ use std::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
backend::overlay::{OverlayData, OverlayState},
|
backend::{
|
||||||
|
input::PointerMode,
|
||||||
|
overlay::{OverlayData, OverlayState},
|
||||||
|
},
|
||||||
config,
|
config,
|
||||||
gui::{color_parse, CanvasBuilder, Control},
|
gui::{color_parse, CanvasBuilder, Control},
|
||||||
hid::{KeyModifier, VirtualKey, ALT, CTRL, KEYS_TO_MODS, META, SHIFT, SUPER},
|
hid::{KeyModifier, VirtualKey, ALT, CTRL, KEYS_TO_MODS, META, SHIFT, SUPER},
|
||||||
state::{AppSession, AppState},
|
state::{AppSession, AppState},
|
||||||
};
|
};
|
||||||
use glam::{vec2, vec3a, Affine2};
|
use glam::{vec2, vec3a, Affine2, Vec4};
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use rodio::{Decoder, OutputStream, OutputStreamHandle, Source};
|
use rodio::{Decoder, OutputStream, OutputStreamHandle, Source};
|
||||||
@@ -130,10 +133,17 @@ fn key_press(
|
|||||||
control: &mut Control<KeyboardData, KeyButtonData>,
|
control: &mut Control<KeyboardData, KeyButtonData>,
|
||||||
data: &mut KeyboardData,
|
data: &mut KeyboardData,
|
||||||
app: &mut AppState,
|
app: &mut AppState,
|
||||||
|
mode: PointerMode,
|
||||||
) {
|
) {
|
||||||
match control.state.as_mut() {
|
match control.state.as_mut() {
|
||||||
Some(KeyButtonData::Key { vk, pressed }) => {
|
Some(KeyButtonData::Key { vk, pressed }) => {
|
||||||
data.key_click(&app.session);
|
data.key_click(&app.session);
|
||||||
|
|
||||||
|
if let PointerMode::Right = mode {
|
||||||
|
data.modifiers = data.modifiers | SHIFT;
|
||||||
|
app.hid_provider.set_modifiers(data.modifiers);
|
||||||
|
}
|
||||||
|
|
||||||
app.hid_provider.send_key(*vk as _, true);
|
app.hid_provider.send_key(*vk as _, true);
|
||||||
*pressed = true;
|
*pressed = true;
|
||||||
}
|
}
|
||||||
@@ -190,15 +200,23 @@ fn key_release(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static PRESS_COLOR: Vec4 = Vec4::new(1.0, 1.0, 1.0, 0.5);
|
||||||
|
|
||||||
fn test_highlight(
|
fn test_highlight(
|
||||||
control: &Control<KeyboardData, KeyButtonData>,
|
control: &Control<KeyboardData, KeyButtonData>,
|
||||||
data: &mut KeyboardData,
|
data: &mut KeyboardData,
|
||||||
_app: &mut AppState,
|
_app: &mut AppState,
|
||||||
) -> bool {
|
) -> Option<Vec4> {
|
||||||
match control.state.as_ref() {
|
let pressed = match control.state.as_ref() {
|
||||||
Some(KeyButtonData::Key { pressed, .. }) => *pressed,
|
Some(KeyButtonData::Key { pressed, .. }) => *pressed,
|
||||||
Some(KeyButtonData::Modifier { modifier, .. }) => data.modifiers & *modifier != 0,
|
Some(KeyButtonData::Modifier { modifier, .. }) => data.modifiers & *modifier != 0,
|
||||||
_ => false,
|
_ => false,
|
||||||
|
};
|
||||||
|
|
||||||
|
if pressed {
|
||||||
|
Some(PRESS_COLOR)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -55,12 +55,12 @@ where
|
|||||||
canvas.fg_color = color_parse("#353535");
|
canvas.fg_color = color_parse("#353535");
|
||||||
|
|
||||||
let vol_up = canvas.button(327., 116., 46., 32., "+".into());
|
let vol_up = canvas.button(327., 116., 46., 32., "+".into());
|
||||||
vol_up.on_press = Some(|_control, _data, _app| {
|
vol_up.on_press = Some(|_control, _data, _app, _| {
|
||||||
println!("Volume up!"); //TODO
|
println!("Volume up!"); //TODO
|
||||||
});
|
});
|
||||||
|
|
||||||
let vol_dn = canvas.button(327., 52., 46., 32., "-".into());
|
let vol_dn = canvas.button(327., 52., 46., 32., "-".into());
|
||||||
vol_dn.on_press = Some(|_control, _data, _app| {
|
vol_dn.on_press = Some(|_control, _data, _app, _| {
|
||||||
println!("Volume down!"); //TODO
|
println!("Volume down!"); //TODO
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -68,7 +68,7 @@ where
|
|||||||
canvas.fg_color = color_parse("#353535");
|
canvas.fg_color = color_parse("#353535");
|
||||||
|
|
||||||
let settings = canvas.button(2., 162., 36., 36., "☰".into());
|
let settings = canvas.button(2., 162., 36., 36., "☰".into());
|
||||||
settings.on_press = Some(|_control, _data, _app| {
|
settings.on_press = Some(|_control, _data, _app, _| {
|
||||||
println!("Settings!"); //TODO
|
println!("Settings!"); //TODO
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -85,7 +85,7 @@ where
|
|||||||
scr_idx: 0,
|
scr_idx: 0,
|
||||||
});
|
});
|
||||||
|
|
||||||
keyboard.on_press = Some(|control, _data, _app| {
|
keyboard.on_press = Some(|control, _data, _app, _| {
|
||||||
if let Some(state) = control.state.as_mut() {
|
if let Some(state) = control.state.as_mut() {
|
||||||
state.pressed_at = Instant::now();
|
state.pressed_at = Instant::now();
|
||||||
}
|
}
|
||||||
@@ -131,7 +131,7 @@ where
|
|||||||
scr_idx: screen.state.id,
|
scr_idx: screen.state.id,
|
||||||
});
|
});
|
||||||
|
|
||||||
button.on_press = Some(|control, _data, _app| {
|
button.on_press = Some(|control, _data, _app, _| {
|
||||||
if let Some(state) = control.state.as_mut() {
|
if let Some(state) = control.state.as_mut() {
|
||||||
state.pressed_at = Instant::now();
|
state.pressed_at = Instant::now();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user