Skip to content

Commit

Permalink
remove shadows, update framebuffer
Browse files Browse the repository at this point in the history
  • Loading branch information
foxnne committed Dec 9, 2024
1 parent 83b8d8a commit ed52541
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 45 deletions.
38 changes: 26 additions & 12 deletions src/Pixi.zig
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ pub fn init(app: *App, core: *Core, app_mod: mach.Mod(App)) !void {
}

fn lateInit(app: *App, core: *Core) !void {
const window = core.windows.getValue(app.window);
var window = core.windows.getValue(app.window);
defer core.windows.setValue(app.window, window);

state.device = window.device;
state.queue = window.queue;
Expand All @@ -189,7 +190,7 @@ fn lateInit(app: *App, core: *Core) !void {
state.theme = try editor.Theme.loadFromFile(theme_path);

window_size = .{ @floatFromInt(window.width), @floatFromInt(window.height) };
framebuffer_size = .{ window_size[0], window_size[1] };
framebuffer_size = .{ @floatFromInt(window.framebuffer_width), @floatFromInt(window.framebuffer_height) };
content_scale = .{
framebuffer_size[0] / window_size[0],
framebuffer_size[1] / window_size[1],
Expand Down Expand Up @@ -255,7 +256,17 @@ fn lateInit(app: *App, core: *Core) !void {
state.fonts.fa_small_solid = io.fonts.?.addFontFromFileTTF(assets.root ++ "fonts/fa-solid-900.ttf", 10 * scale_factor, &fa_config, @ptrCast(ranges.ptr)).?;
state.fonts.fa_small_regular = io.fonts.?.addFontFromFileTTF(assets.root ++ "fonts/fa-regular-400.ttf", 10 * scale_factor, &fa_config, @ptrCast(ranges.ptr)).?;

//state.theme.init();
state.theme.init();

window.color = .{ .transparent = .{
.color = .{
.r = state.theme.foreground.value[0],
.g = state.theme.foreground.value[1],
.b = state.theme.foreground.value[2],
.a = 1.0,
},
.titlebar = true,
} };
}

pub fn updateMainThread(_: *App) !bool {
Expand Down Expand Up @@ -320,6 +331,15 @@ pub fn tick(app: *App, core: *Core) !void {
}
state.should_close = should_close;
},
.window_resize => |resize| {
const window = core.windows.getValue(app.window);
window_size = .{ @floatFromInt(resize.size.width), @floatFromInt(resize.size.width) };
framebuffer_size = .{ @floatFromInt(window.framebuffer_width), @floatFromInt(window.framebuffer_height) };
content_scale = .{
framebuffer_size[0] / window_size[0],
framebuffer_size[1] / window_size[1],
};
},
.window_open => {
try lateInit(app, core);
},
Expand All @@ -329,21 +349,15 @@ pub fn tick(app: *App, core: *Core) !void {
if (!state.should_close)
_ = imgui_mach.processEvent(event);
}
const window = core.windows.getValue(app.window);
_ = window; // autofix

try imgui_mach.newFrame();
imgui.newFrame();
state.delta_time = app.timer.lap();
state.total_time += state.delta_time;

const window = core.windows.getValue(app.window);

window_size = .{ @floatFromInt(window.width), @floatFromInt(window.height) };
framebuffer_size = .{ @floatFromInt(window.width), @floatFromInt(window.height) };
content_scale = .{
framebuffer_size[0] / window_size[0],
framebuffer_size[1] / window_size[1],
};
content_scale = .{ 1.0, 1.0 };
// content_scale = .{ 1.0, 1.0 };

try input.process();

Expand Down
66 changes: 33 additions & 33 deletions src/editor/artboard/artboard.zig
Original file line number Diff line number Diff line change
Expand Up @@ -89,23 +89,23 @@ pub fn draw(core: *Core) void {
const window_hovered: bool = imgui.isWindowHovered(imgui.HoveredFlags_ChildWindows);
const mouse_clicked: bool = pixi.state.mouse.anyButtonDown();

defer {
const shadow_color = pixi.math.Color.initFloats(0.0, 0.0, 0.0, pixi.state.settings.shadow_opacity).toU32();
// Draw a shadow fading from bottom to top
const pos = imgui.getWindowPos();
const width = imgui.getWindowWidth();

if (imgui.getWindowDrawList()) |draw_list| {
draw_list.addRectFilledMultiColor(
.{ .x = pos.x, .y = pos.y },
.{ .x = pos.x + width, .y = pos.y + pixi.state.settings.shadow_length },
shadow_color,
shadow_color,
0x0,
0x0,
);
}
}
// defer {
// const shadow_color = pixi.math.Color.initFloats(0.0, 0.0, 0.0, pixi.state.settings.shadow_opacity).toU32();
// // Draw a shadow fading from bottom to top
// const pos = imgui.getWindowPos();
// const width = imgui.getWindowWidth();

// if (imgui.getWindowDrawList()) |draw_list| {
// draw_list.addRectFilledMultiColor(
// .{ .x = pos.x, .y = pos.y },
// .{ .x = pos.x + width, .y = pos.y + pixi.state.settings.shadow_length },
// shadow_color,
// shadow_color,
// 0x0,
// 0x0,
// );
// }
// }

if (pixi.state.sidebar == .pack) {
drawCanvasPack();
Expand Down Expand Up @@ -263,22 +263,22 @@ pub fn draw(core: *Core) void {
}
}

{
const shadow_color = pixi.math.Color.initFloats(0.0, 0.0, 0.0, pixi.state.settings.shadow_opacity).toU32();
const pos = imgui.getWindowPos();
const height = imgui.getWindowHeight();

if (imgui.getWindowDrawList()) |draw_list|
// Draw a shadow fading from left to right
draw_list.addRectFilledMultiColor(
pos,
.{ .x = pos.x + pixi.state.settings.shadow_length, .y = height + pos.x },
shadow_color,
0x0,
shadow_color,
0x0,
);
}
// {
// const shadow_color = pixi.math.Color.initFloats(0.0, 0.0, 0.0, pixi.state.settings.shadow_opacity).toU32();
// const pos = imgui.getWindowPos();
// const height = imgui.getWindowHeight();

// if (imgui.getWindowDrawList()) |draw_list|
// // Draw a shadow fading from left to right
// draw_list.addRectFilledMultiColor(
// pos,
// .{ .x = pos.x + pixi.state.settings.shadow_length, .y = height + pos.x },
// shadow_color,
// 0x0,
// shadow_color,
// 0x0,
// );
// }
}
imgui.end();
}
Expand Down

0 comments on commit ed52541

Please sign in to comment.