fix graph minimap
This commit is contained in:
parent
fa4fb2009f
commit
dc3e66cfdc
118
src/app.zig
118
src/app.zig
@ -240,7 +240,7 @@ pub fn tick(self: *App) !void {
|
|||||||
|
|
||||||
{
|
{
|
||||||
const sample_count: f32 = @floatFromInt(channel.samples.owned.len);
|
const sample_count: f32 = @floatFromInt(channel.samples.owned.len);
|
||||||
const min_visible_samples = sample_count*0.02;
|
const min_visible_samples = 1; // sample_count*0.02;
|
||||||
|
|
||||||
const minimap_box = self.ui.newBoxFromString("Minimap");
|
const minimap_box = self.ui.newBoxFromString("Minimap");
|
||||||
minimap_box.background = rl.Color.dark_purple;
|
minimap_box.background = rl.Color.dark_purple;
|
||||||
@ -252,73 +252,93 @@ pub fn tick(self: *App) !void {
|
|||||||
|
|
||||||
const minimap_rect = minimap_box.computedRect();
|
const minimap_rect = minimap_box.computedRect();
|
||||||
|
|
||||||
|
|
||||||
|
const middle_box = self.ui.newBoxFromString("Middle knob");
|
||||||
{
|
{
|
||||||
const middle_box = self.ui.newBoxFromString("Middle knob");
|
|
||||||
middle_box.flags.insert(.clickable);
|
middle_box.flags.insert(.clickable);
|
||||||
middle_box.flags.insert(.draggable_x);
|
middle_box.flags.insert(.draggable_x);
|
||||||
middle_box.background = rl.Color.ray_white;
|
middle_box.background = rl.Color.black.alpha(0.5);
|
||||||
middle_box.size.y = UI.Size.pixels(32, 1);
|
middle_box.size.y = UI.Size.pixels(32, 1);
|
||||||
|
|
||||||
const signal = self.ui.signalFromBox(middle_box);
|
|
||||||
if (signal.dragged()) {
|
|
||||||
|
|
||||||
var samples_moved = signal.drag.x / minimap_rect.width * sample_count;
|
|
||||||
|
|
||||||
samples_moved = clamp(samples_moved, -channel.view_rect.from, sample_count - channel.view_rect.to);
|
|
||||||
|
|
||||||
channel.view_rect.from += samples_moved;
|
|
||||||
channel.view_rect.to += samples_moved;
|
|
||||||
}
|
|
||||||
|
|
||||||
middle_box.setFixedX(minimap_rect.width * channel.view_rect.from / sample_count + 4);
|
|
||||||
middle_box.setFixedWidth(minimap_rect.width * (channel.view_rect.to - channel.view_rect.from) / sample_count - 8);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const left_knob_box = self.ui.newBoxFromString("Left knob");
|
||||||
{
|
{
|
||||||
const left_knob_box = self.ui.newBoxFromString("Left knob");
|
|
||||||
left_knob_box.flags.insert(.clickable);
|
left_knob_box.flags.insert(.clickable);
|
||||||
left_knob_box.flags.insert(.draggable_x);
|
left_knob_box.flags.insert(.draggable_x);
|
||||||
left_knob_box.background = rl.Color.ray_white;
|
left_knob_box.background = rl.Color.black.alpha(0.5);
|
||||||
left_knob_box.size.x = UI.Size.pixels(8, 1);
|
left_knob_box.size.x = UI.Size.pixels(8, 1);
|
||||||
left_knob_box.size.y = UI.Size.pixels(32, 1);
|
left_knob_box.size.y = UI.Size.pixels(32, 1);
|
||||||
|
|
||||||
const left_signal = self.ui.signalFromBox(left_knob_box);
|
|
||||||
if (left_signal.dragged()) {
|
|
||||||
channel.view_rect.from += remap(
|
|
||||||
f32,
|
|
||||||
0, minimap_rect.width,
|
|
||||||
0, sample_count,
|
|
||||||
left_signal.drag.x
|
|
||||||
);
|
|
||||||
|
|
||||||
channel.view_rect.from = clamp(channel.view_rect.from, 0, channel.view_rect.to-min_visible_samples);
|
|
||||||
}
|
|
||||||
|
|
||||||
left_knob_box.setFixedX(minimap_rect.width * channel.view_rect.from / sample_count - left_knob_box.persistent.size.x/2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const right_knob_box = self.ui.newBoxFromString("Right knob");
|
||||||
{
|
{
|
||||||
const right_knob_box = self.ui.newBoxFromString("Right knobaaa");
|
|
||||||
right_knob_box.flags.insert(.clickable);
|
right_knob_box.flags.insert(.clickable);
|
||||||
right_knob_box.flags.insert(.draggable_x);
|
right_knob_box.flags.insert(.draggable_x);
|
||||||
right_knob_box.background = rl.Color.ray_white;
|
right_knob_box.background = rl.Color.black.alpha(0.5);
|
||||||
right_knob_box.size.x = UI.Size.pixels(8, 1);
|
right_knob_box.size.x = UI.Size.pixels(8, 1);
|
||||||
right_knob_box.size.y = UI.Size.pixels(32, 1);
|
right_knob_box.size.y = UI.Size.pixels(32, 1);
|
||||||
|
|
||||||
const right_signal = self.ui.signalFromBox(right_knob_box);
|
|
||||||
if (right_signal.dragged()) {
|
|
||||||
channel.view_rect.to += remap(
|
|
||||||
f32,
|
|
||||||
0, minimap_rect.width,
|
|
||||||
0, sample_count,
|
|
||||||
right_signal.drag.x
|
|
||||||
);
|
|
||||||
|
|
||||||
channel.view_rect.to = clamp(channel.view_rect.to, channel.view_rect.from+min_visible_samples, sample_count);
|
|
||||||
}
|
|
||||||
|
|
||||||
right_knob_box.setFixedX(minimap_rect.width * channel.view_rect.to / sample_count - right_knob_box.persistent.size.x/2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const left_knob_size = left_knob_box.persistent.size.x;
|
||||||
|
const right_knob_size = right_knob_box.persistent.size.x;
|
||||||
|
|
||||||
|
const left_signal = self.ui.signalFromBox(left_knob_box);
|
||||||
|
if (left_signal.dragged()) {
|
||||||
|
channel.view_rect.from += remap(
|
||||||
|
f32,
|
||||||
|
0, minimap_rect.width,
|
||||||
|
0, sample_count,
|
||||||
|
left_signal.drag.x
|
||||||
|
);
|
||||||
|
|
||||||
|
channel.view_rect.from = clamp(channel.view_rect.from, 0, channel.view_rect.to-min_visible_samples);
|
||||||
|
}
|
||||||
|
|
||||||
|
const right_signal = self.ui.signalFromBox(right_knob_box);
|
||||||
|
if (right_signal.dragged()) {
|
||||||
|
channel.view_rect.to += remap(
|
||||||
|
f32,
|
||||||
|
0, minimap_rect.width,
|
||||||
|
0, sample_count,
|
||||||
|
right_signal.drag.x
|
||||||
|
);
|
||||||
|
|
||||||
|
channel.view_rect.to = clamp(channel.view_rect.to, channel.view_rect.from+min_visible_samples, sample_count);
|
||||||
|
}
|
||||||
|
|
||||||
|
const middle_signal = self.ui.signalFromBox(middle_box);
|
||||||
|
if (middle_signal.dragged()) {
|
||||||
|
var samples_moved = middle_signal.drag.x / minimap_rect.width * sample_count;
|
||||||
|
|
||||||
|
samples_moved = clamp(samples_moved, -channel.view_rect.from, sample_count - channel.view_rect.to);
|
||||||
|
|
||||||
|
channel.view_rect.from += samples_moved;
|
||||||
|
channel.view_rect.to += samples_moved;
|
||||||
|
}
|
||||||
|
|
||||||
|
left_knob_box.setFixedX(remap(f32,
|
||||||
|
0, sample_count,
|
||||||
|
0, minimap_rect.width - left_knob_size - right_knob_size,
|
||||||
|
channel.view_rect.from
|
||||||
|
));
|
||||||
|
|
||||||
|
right_knob_box.setFixedX(remap(f32,
|
||||||
|
0, sample_count,
|
||||||
|
left_knob_size, minimap_rect.width - right_knob_size,
|
||||||
|
channel.view_rect.to
|
||||||
|
));
|
||||||
|
|
||||||
|
middle_box.setFixedX(remap(f32,
|
||||||
|
0, sample_count,
|
||||||
|
left_knob_size, minimap_rect.width - right_knob_size,
|
||||||
|
channel.view_rect.from
|
||||||
|
));
|
||||||
|
middle_box.setFixedWidth(remap(f32,
|
||||||
|
0, sample_count,
|
||||||
|
0, minimap_rect.width - right_knob_size - left_knob_size,
|
||||||
|
channel.view_rect.to - channel.view_rect.from
|
||||||
|
));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user