Skip to content

Commit

Permalink
tools: polish up the new palette chip animations and clipping
Browse files Browse the repository at this point in the history
  • Loading branch information
foxnne committed Jan 31, 2025
1 parent 9572dd3 commit 3822398
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/editor/explorer/tools.zig
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,9 @@ pub fn draw(editor: *Editor) !void {
const dist = @sqrt(dist_x * dist_x + dist_y * dist_y);

if (imgui.getWindowDrawList()) |draw_list| {
draw_list.pushClipRectFullScreen();
defer draw_list.popClipRect();

const radius = std.math.lerp(max_radius, min_radius, std.math.clamp(dist / (chip_width * 2.0), 0.0, 1.0));

draw_list.addCircleFilled(
Expand Down Expand Up @@ -276,9 +279,6 @@ pub fn draw(editor: *Editor) !void {
}

if (imgui.collapsingHeader(pixi.fa.palette ++ " Palettes", imgui.TreeNodeFlags_SpanFullWidth | imgui.TreeNodeFlags_DefaultOpen)) {
imgui.indent();
defer imgui.unindent();

imgui.setNextItemWidth(-1.0);
if (imgui.beginCombo("##PaletteCombo", if (editor.colors.palette) |palette| palette.name else "none", imgui.ComboFlags_HeightLargest)) {
defer imgui.endCombo();
Expand All @@ -301,11 +301,14 @@ pub fn draw(editor: *Editor) !void {
const shadow_max: imgui.Vec2 = .{ .x = shadow_min.x + @as(f32, @floatFromInt(columns)) * (chip_width + style.item_spacing.x) - style.item_spacing.x, .y = shadow_min.y + pixi.editor.settings.shadow_length };
const shadow_color = pixi.math.Color.initFloats(0.0, 0.0, 0.0, pixi.editor.settings.shadow_opacity * 4.0).toU32();
var scroll_y: f32 = 0.0;
var scroll_x: f32 = 0.0;

defer imgui.endChild(); // This can get cut off and causes a crash if begin child is not called because its off screen.
if (imgui.beginChild("PaletteColors", .{ .x = 0.0, .y = @max(content_region_avail, chip_width) }, imgui.ChildFlags_None, imgui.WindowFlags_ChildWindow)) {
if (editor.colors.palette) |palette| {
scroll_y = imgui.getScrollY();
scroll_x = imgui.getScrollX();

for (palette.colors, 0..) |color, i| {
imgui.pushIDInt(@as(c_int, @intCast(i)));

Expand All @@ -321,13 +324,23 @@ pub fn draw(editor: *Editor) !void {

{
const window_pos = imgui.getWindowPos();
const center: [2]f32 = .{ top_left.x + (chip_width / 2.0) + window_pos.x + imgui.getScrollX(), top_left.y + (chip_width / 2.0) + window_pos.y - imgui.getScrollY() };
const center: [2]f32 = .{ top_left.x + (chip_width / 2.0) + window_pos.x + scroll_x, top_left.y + (chip_width / 2.0) + window_pos.y - scroll_y };

const dist_x = @abs(imgui.getMousePos().x - center[0]);
const dist_y = @abs(imgui.getMousePos().y - center[1]);
const dist = @sqrt(dist_x * dist_x + dist_y * dist_y);

if (imgui.getWindowDrawList()) |draw_list| {
draw_list.pushClipRect(
.{ .x = window_pos.x - 24.0, .y = window_pos.y },
.{
.x = window_pos.x + imgui.getContentRegionAvail().x,
.y = window_pos.y + imgui.getWindowHeight(),
},
false,
);
defer draw_list.popClipRect();

const radius = std.math.lerp(max_radius, min_radius, std.math.clamp(dist / (chip_width * 2.0), 0.0, 1.0));

draw_list.addCircleFilled(.{ .x = center[0], .y = center[1] }, radius, pixi.math.Color.initBytes(color[0], color[1], color[2], color[3]).toU32(), 100);
Expand Down

0 comments on commit 3822398

Please sign in to comment.