no mouse zoom
This commit is contained in:
parent
74525e08ac
commit
f07013ad8a
63
module.jai
63
module.jai
@ -188,7 +188,7 @@ draw_plot :: (key: string, size: Vector2, xdata: []float64, yarrays: [][]float64
|
||||
plot.pos.y += -mouse_delta.y * pixel_size_y / plot.zoom;
|
||||
}
|
||||
|
||||
if !fixed_bounds {
|
||||
if mouse_wheel_zoom && !fixed_bounds {
|
||||
plot.zoom += plot.zoom * (cast(float) mouse_wheel_delta * 0.1);
|
||||
|
||||
if plot.zoom < 0.01 {
|
||||
@ -287,9 +287,10 @@ free_old_plots :: () {
|
||||
}
|
||||
}
|
||||
|
||||
init :: (_win_width: s32, _win_height: s32) {
|
||||
init :: (_win_width: s32, _win_height: s32, _mouse_wheel_zoom : bool) {
|
||||
win_width = _win_width;
|
||||
win_height = _win_height;
|
||||
mouse_wheel_zoom = _mouse_wheel_zoom;
|
||||
|
||||
error := FT_Init_FreeType(*ftlib);
|
||||
if error {
|
||||
@ -351,6 +352,8 @@ primitives_rendered_this_frame : int;
|
||||
win_width : s32;
|
||||
win_height : s32;
|
||||
|
||||
mouse_wheel_zoom : bool;
|
||||
|
||||
PlotColors :: struct {
|
||||
background : Vector3;
|
||||
lines : Vector3;
|
||||
@ -521,40 +524,42 @@ draw_axis :: (using plot: Plot, style: PLOT_STYLE, colors: PlotColors) {
|
||||
array_add(*positions, .{0.0, xx (content_height )});
|
||||
array_add(*positions, .{0.0, 0.0});
|
||||
|
||||
x_ticks := 10;
|
||||
for 0..x_ticks {
|
||||
xpos : s64 = cast(s64) (cast(float) it / cast(float) x_ticks * cast(float) (content_width));
|
||||
xxx := (((cast(float) it / cast(float) x_ticks) - 0.5) / zoom) + 0.5;
|
||||
xxx = xxx * (xmax - (pos.x)) + (1 - xxx) * (xmin - (pos.x));
|
||||
if plot.xfloat.count > 0 {
|
||||
x_ticks := 10;
|
||||
for 0..x_ticks {
|
||||
xpos : s64 = cast(s64) (cast(float) it / cast(float) x_ticks * cast(float) (content_width));
|
||||
xxx := (((cast(float) it / cast(float) x_ticks) - 0.5) / zoom) + 0.5;
|
||||
xxx = xxx * (xmax - (pos.x)) + (1 - xxx) * (xmin - (pos.x));
|
||||
|
||||
array_add(*positions, .{cast(float) xpos, 0.0});
|
||||
array_add(*positions, .{cast(float) xpos, cast(float) (content_height )});
|
||||
array_add(*positions, .{cast(float) xpos, 0.0});
|
||||
array_add(*positions, .{cast(float) xpos, cast(float) (content_height )});
|
||||
|
||||
to_render := tprint("%", formatFloat(cast(float) xxx, trailing_width = 1, zero_removal = .NO));
|
||||
label_size := calculate_string_draw_size(*JetBrainsMonoRegular, to_render);
|
||||
to_render := tprint("%", formatFloat(cast(float) xxx, trailing_width = 1, zero_removal = .NO));
|
||||
label_size := calculate_string_draw_size(*JetBrainsMonoRegular, to_render);
|
||||
|
||||
if style == .TICK_MARKS {
|
||||
render_string(*JetBrainsMonoRegular, to_render,
|
||||
.{xpos + left_bearing - (label_size.x / 2.0), xx (plot.height - bottom_bearing + 4.0)},
|
||||
colors.text, plot.width, plot.height);
|
||||
if style == .TICK_MARKS {
|
||||
render_string(*JetBrainsMonoRegular, to_render,
|
||||
.{xpos + left_bearing - (label_size.x / 2.0), xx (plot.height - bottom_bearing + 4.0)},
|
||||
colors.text, plot.width, plot.height);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
y_ticks := 10;
|
||||
for 0..y_ticks {
|
||||
ypos : s64 = cast(s64) (cast(float) it / cast(float) y_ticks * (content_height ));
|
||||
yyy := ((0.5) - cast(float) it / cast(float) y_ticks) / zoom + 0.5;
|
||||
yyy = yyy * (ymax - pos.y) + (1 - yyy) * (ymin - pos.y);
|
||||
array_add(*positions, .{0.0, cast(float) ypos});
|
||||
array_add(*positions, .{cast(float) (content_width ), cast(float) ypos});
|
||||
y_ticks := 10;
|
||||
for 0..y_ticks {
|
||||
ypos : s64 = cast(s64) (cast(float) it / cast(float) y_ticks * (content_height ));
|
||||
yyy := ((0.5) - cast(float) it / cast(float) y_ticks) / zoom + 0.5;
|
||||
yyy = yyy * (ymax - pos.y) + (1 - yyy) * (ymin - pos.y);
|
||||
array_add(*positions, .{0.0, cast(float) ypos});
|
||||
array_add(*positions, .{cast(float) (content_width ), cast(float) ypos});
|
||||
|
||||
to_render := tprint("%", formatFloat(cast(float) yyy, trailing_width = 1, zero_removal = .NO));
|
||||
label_size := calculate_string_draw_size(*JetBrainsMonoRegular, to_render);
|
||||
to_render := tprint("%", formatFloat(cast(float) yyy, trailing_width = 1, zero_removal = .NO));
|
||||
label_size := calculate_string_draw_size(*JetBrainsMonoRegular, to_render);
|
||||
|
||||
if style == .TICK_MARKS {
|
||||
render_string(*JetBrainsMonoRegular, to_render,
|
||||
.{xx cast(s64) (left_bearing - label_size.x - 4.0), xx cast(s64) (ypos - label_size.y / 2.0)},
|
||||
colors.text, plot.width, plot.height);
|
||||
if style == .TICK_MARKS {
|
||||
render_string(*JetBrainsMonoRegular, to_render,
|
||||
.{xx cast(s64) (left_bearing - label_size.x - 4.0), xx cast(s64) (ypos - label_size.y / 2.0)},
|
||||
colors.text, plot.width, plot.height);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user