forge
Explore
Log in

Don't you dare go Hollow

Drag the HSV wheel like every other picker

Browse files at this commit

f93a86c9081898beed301b43df8b999a1a8d73a1Ahmet Kaan GümüşParent: 2ad667f
  • feat
    • drag the HSV wheel like every other picker
Show full message
✨ feat(audio): drag the HSV wheel like every other picker

Press stays on the disk; moves sample hue/sat on the root the same
way a 4 px colour slider does. Glow stays a width; that is the stamp.
crates/app/src/main.rsmodified+7 -0
@@ -756,6 +756,11 @@ struct Player {
756 /// equalizer's drag, for the same reason: a 4 px bar is left by the pointer756 /// equalizer's drag, for the same reason: a 4 px bar is left by the pointer
757 /// on the first move and its own listeners then stop firing.757 /// on the first move and its own listeners then stop firing.
758 color_dragging: bool,758 color_dragging: bool,
759+ /// HSV wheel on CLIP: same 4 px reason as `color_dragging` — the pointer
760+ /// leaves the disk on the first move, so samples live on the root.
761+ viz_hs_dragging: bool,
762+ /// The wheel's box, recorded at prepaint for a drag's window position.
763+ viz_wheel: Rc<Cell<Bounds<Pixels>>>,
759 /// Each slider's box, recorded at prepaint: a mouse listener is handed the764 /// Each slider's box, recorded at prepaint: a mouse listener is handed the
760 /// window position only, so this is what a press and a drag are read against765 /// window position only, so this is what a press and a drag are read against
761 /// ([`frac_along`]). One per band, because the press picks the row it landed766 /// ([`frac_along`]). One per band, because the press picks the row it landed
@@ -1064,6 +1069,8 @@ fn main() {
1064 color_open: None,1069 color_open: None,
1065 color_band: 0,1070 color_band: 0,
1066 color_dragging: false,1071 color_dragging: false,
1072+ viz_hs_dragging: false,
1073+ viz_wheel: Rc::default(),
1067 color_bars: std::array::from_fn(|_| Rc::default()),1074 color_bars: std::array::from_fn(|_| Rc::default()),
1068 pending_color: None,1075 pending_color: None,
1069 transform_open: None,1076 transform_open: None,
crates/app/src/player/library.rsmodified+16 -0
@@ -242,6 +242,21 @@ impl Player {
242 });242 });
243 }243 }
244 244
245+ pub(crate) fn drag_viz_hs(&mut self, at: gpui::Point<Pixels>, cx: &mut Context<Self>) {
246+ let b = self.viz_wheel.get();
247+ let w = f32::from(b.size.width).max(1.);
248+ let h = f32::from(b.size.height).max(1.);
249+ let dx = f32::from(at.x - b.origin.x) - w / 2.;
250+ let dy = h / 2. - f32::from(at.y - b.origin.y);
251+ let radius = w.min(h) / 2.;
252+ let r = (dx * dx + dy * dy).sqrt() / radius;
253+ let sat = (r.clamp(0., 1.) * 255.).round() as u8;
254+ let ang = dx.atan2(dy).to_degrees();
255+ let hue_deg = (ang + 360.) % 360.;
256+ let hue = (hue_deg / 360. * 256.).round() as u16 as u8;
257+ self.set_viz_hs(hue, sat, cx);
258+ }
259+
245 pub(crate) fn set_viz_strands(&mut self, n: u8, cx: &mut Context<Self>) {260 pub(crate) fn set_viz_strands(&mut self, n: u8, cx: &mut Context<Self>) {
246 self.set_viz_paint_with(cx, |p| engine::decode::with_viz_paint_strands(p, n));261 self.set_viz_paint_with(cx, |p| engine::decode::with_viz_paint_strands(p, n));
247 }262 }
@@ -484,6 +499,7 @@ impl Player {
484 self.eq_dragging = false;499 self.eq_dragging = false;
485 self.speed_dragging = false;500 self.speed_dragging = false;
486 self.color_dragging = false;501 self.color_dragging = false;
502+ self.viz_hs_dragging = false;
487 self.pending_color = None;503 self.pending_color = None;
488 self.transform_dragging = false;504 self.transform_dragging = false;
489 self.pending_transform = None;505 self.pending_transform = None;
crates/app/src/player/timeline_edit.rsmodified+12 -0
@@ -2103,6 +2103,14 @@ impl Player {
2103 }2103 }
2104 return;2104 return;
2105 }2105 }
2106+ if self.viz_hs_dragging {
2107+ if event.pressed_button == Some(MouseButton::Left) {
2108+ self.drag_viz_hs(event.position, cx);
2109+ } else {
2110+ self.viz_hs_dragging = false;
2111+ }
2112+ return;
2113+ }
2106 // The transform card's sliders, [`Self::color_dragging`]'s own reason.2114 // The transform card's sliders, [`Self::color_dragging`]'s own reason.
2107 if self.transform_dragging {2115 if self.transform_dragging {
2108 if event.pressed_button == Some(MouseButton::Left) {2116 if event.pressed_button == Some(MouseButton::Left) {
@@ -2219,6 +2227,10 @@ impl Player {
2219 self.flush_drag(cx);2227 self.flush_drag(cx);
2220 return;2228 return;
2221 }2229 }
2230+ if std::mem::take(&mut self.viz_hs_dragging) {
2231+ self.drag_viz_hs(event.position, cx);
2232+ return;
2233+ }
2222 if std::mem::take(&mut self.transform_dragging) {2234 if std::mem::take(&mut self.transform_dragging) {
2223 self.drag_transform(event.position.x, false, cx);2235 self.drag_transform(event.position.x, false, cx);
2224 self.flush_drag(cx);2236 self.flush_drag(cx);
crates/app/src/ui/dock_stance.rsmodified+7 -22
@@ -1282,7 +1282,7 @@ fn viz_style_verbs(player: &Player, cx: &mut Context<Player>) -> impl IntoElemen
1282 engine::decode::VIZ_FAST,1282 engine::decode::VIZ_FAST,
1283 flags & engine::decode::VIZ_FAST != 0,1283 flags & engine::decode::VIZ_FAST != 0,
1284 ))1284 ))
1285- .child(viz_paint_knobs(paint, cx))1285+ .child(viz_paint_knobs(player, paint, cx))
1286 }1286 }
1287 1287
1288 fn viz_step(1288 fn viz_step(
@@ -1306,9 +1306,7 @@ fn viz_step(
1306 .child(glyph)1306 .child(glyph)
1307 }1307 }
1308 1308
1309-fn viz_color_wheel(paint: u32, cx: &mut Context<Player>) -> impl IntoElement {1309+fn viz_color_wheel(player: &Player, paint: u32, cx: &mut Context<Player>) -> impl IntoElement {
1310- let hit = std::rc::Rc::new(std::cell::Cell::new(Bounds::default()));
1311- let hit_click = hit.clone();
1312 div()1310 div()
1313 .id("dock-viz-hs")1311 .id("dock-viz-hs")
1314 .w(px(112.))1312 .w(px(112.))
@@ -1316,7 +1314,7 @@ fn viz_color_wheel(paint: u32, cx: &mut Context<Player>) -> impl IntoElement {
1316 .relative()1314 .relative()
1317 .cursor_pointer()1315 .cursor_pointer()
1318 .children(hitmap::control("dock-viz-hs", "Colour wheel", true))1316 .children(hitmap::control("dock-viz-hs", "Colour wheel", true))
1319- .child(bounds_probe(hit))1317+ .child(bounds_probe(player.viz_wheel.clone()))
1320 .child(1318 .child(
1321 canvas(1319 canvas(
1322 |_, _, _| (),1320 |_, _, _| (),
@@ -1375,26 +1373,13 @@ fn viz_color_wheel(paint: u32, cx: &mut Context<Player>) -> impl IntoElement {
1375 .on_mouse_down(1373 .on_mouse_down(
1376 MouseButton::Left,1374 MouseButton::Left,
1377 cx.listener(move |this, event: &MouseDownEvent, _, cx| {1375 cx.listener(move |this, event: &MouseDownEvent, _, cx| {
1378- let b = hit_click.get();1376+ this.viz_hs_dragging = true;
1379- let w = f32::from(b.size.width).max(1.);1377+ this.drag_viz_hs(event.position, cx);
1380- let h = f32::from(b.size.height).max(1.);
1381- let dx = f32::from(event.position.x - b.origin.x) - w / 2.;
1382- let dy = h / 2. - f32::from(event.position.y - b.origin.y);
1383- let radius = w.min(h) / 2.;
1384- let r = (dx * dx + dy * dy).sqrt() / radius;
1385- if r > 1.08 {
1386- return;
1387- }
1388- let sat = (r.clamp(0., 1.) * 255.).round() as u8;
1389- let ang = dx.atan2(dy).to_degrees();
1390- let hue_deg = (ang + 360.) % 360.;
1391- let hue = (hue_deg / 360. * 256.).round() as u16 as u8;
1392- this.set_viz_hs(hue, sat, cx);
1393 }),1378 }),
1394 )1379 )
1395 }1380 }
1396 1381
1397-fn viz_paint_knobs(paint: u32, cx: &mut Context<Player>) -> impl IntoElement {1382+fn viz_paint_knobs(player: &Player, paint: u32, cx: &mut Context<Player>) -> impl IntoElement {
1398 let strands = engine::decode::viz_strands_of(paint);1383 let strands = engine::decode::viz_strands_of(paint);
1399 let glow = engine::decode::viz_glow_of(paint);1384 let glow = engine::decode::viz_glow_of(paint);
1400 let style = label(type_scale::LABEL_ROW_PX, FontWeight::MEDIUM);1385 let style = label(type_scale::LABEL_ROW_PX, FontWeight::MEDIUM);
@@ -1416,7 +1401,7 @@ fn viz_paint_knobs(paint: u32, cx: &mut Context<Player>) -> impl IntoElement {
1416 .text_color(rgb(INK2()))1401 .text_color(rgb(INK2()))
1417 .child("Colour"),1402 .child("Colour"),
1418 )1403 )
1419- .child(viz_color_wheel(paint, cx)),1404+ .child(viz_color_wheel(player, paint, cx)),
1420 )1405 )
1421 .child(1406 .child(
1422 div()1407 div()