core: window.color -> window.transparent, window.decorated, window.decoration_color
This commit is contained in:
parent
ff11fd6d4c
commit
c70b1817ee
3 changed files with 46 additions and 61 deletions
|
|
@ -32,6 +32,7 @@ pub fn init(
|
||||||
const window = try core.windows.new(.{
|
const window = try core.windows.new(.{
|
||||||
.title = "core-transparent-window",
|
.title = "core-transparent-window",
|
||||||
.vsync_mode = .double,
|
.vsync_mode = .double,
|
||||||
|
.transparent = true,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Store our render pipeline in our module's state, so we can access it later on.
|
// Store our render pipeline in our module's state, so we can access it later on.
|
||||||
|
|
@ -124,10 +125,10 @@ pub fn tick(app: *App, core: *mach.Core) void {
|
||||||
defer encoder.release();
|
defer encoder.release();
|
||||||
|
|
||||||
// Begin render pass
|
// Begin render pass
|
||||||
const sky_blue_background = gpu.Color{ .r = 0.0, .g = 0.0, .b = 0.0, .a = 0.0 };
|
const transparent_background = gpu.Color{ .r = 0.0, .g = 0.0, .b = 0.0, .a = 0.0 };
|
||||||
const color_attachments = [_]gpu.RenderPassColorAttachment{.{
|
const color_attachments = [_]gpu.RenderPassColorAttachment{.{
|
||||||
.view = back_buffer_view,
|
.view = back_buffer_view,
|
||||||
.clear_value = sky_blue_background,
|
.clear_value = transparent_background,
|
||||||
.load_op = .clear,
|
.load_op = .clear,
|
||||||
.store_op = .store,
|
.store_op = .store,
|
||||||
}};
|
}};
|
||||||
|
|
@ -172,7 +173,11 @@ pub fn tick(app: *App, core: *mach.Core) void {
|
||||||
const green = mach.math.lerp(0.2, 0.6, mach.math.clamp(app.color_time - 2.0, 0.0, 1.0));
|
const green = mach.math.lerp(0.2, 0.6, mach.math.clamp(app.color_time - 2.0, 0.0, 1.0));
|
||||||
const alpha = mach.math.lerp(0.3, 1.0, app.color_time / 4.0);
|
const alpha = mach.math.lerp(0.3, 1.0, app.color_time / 4.0);
|
||||||
|
|
||||||
core.windows.set(app.window, .color, .{ .transparent = .{ .color = .{ .r = red, .g = green, .b = blue, .a = alpha }, .titlebar = true } });
|
core.windows.set(
|
||||||
|
app.window,
|
||||||
|
.decoration_color,
|
||||||
|
.{ .r = red, .g = green, .b = blue, .a = alpha },
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn deinit(app: *App) void {
|
pub fn deinit(app: *App) void {
|
||||||
|
|
|
||||||
13
src/Core.zig
13
src/Core.zig
|
|
@ -74,8 +74,17 @@ windows: mach.Objects(
|
||||||
/// Target frames per second
|
/// Target frames per second
|
||||||
refresh_rate: u32 = 0,
|
refresh_rate: u32 = 0,
|
||||||
|
|
||||||
/// Color of the window background/titlebar
|
/// Titlebar/window decorations
|
||||||
color: WindowColor = .system,
|
decorated: bool = true,
|
||||||
|
|
||||||
|
/// Color of the window decorations, i.e. titlebar
|
||||||
|
/// if null, decoration is the system-determined color
|
||||||
|
decoration_color: ?gpu.Color = null,
|
||||||
|
|
||||||
|
/// Whether the window should be completely transparent
|
||||||
|
/// or not. On macOS, to achieve a fully transparent window
|
||||||
|
/// decoration_color must also be set fully transparent.
|
||||||
|
transparent: bool = false,
|
||||||
|
|
||||||
// GPU
|
// GPU
|
||||||
// When `native` is not null, the rest of the fields have been
|
// When `native` is not null, the rest of the fields have been
|
||||||
|
|
|
||||||
|
|
@ -70,36 +70,19 @@ pub fn tick(core: *Core) !void {
|
||||||
|
|
||||||
if (core_window.native) |native| {
|
if (core_window.native) |native| {
|
||||||
const native_window: *objc.app_kit.Window = native.window;
|
const native_window: *objc.app_kit.Window = native.window;
|
||||||
const native_view: *objc.mach.View = native.view;
|
|
||||||
|
|
||||||
if (core.windows.updated(window_id, .color)) {
|
if (core.windows.updated(window_id, .decoration_color)) {
|
||||||
switch (core_window.color) {
|
if (core_window.decoration_color) |decoration_color| {
|
||||||
.transparent => |wc| {
|
const color = objc.app_kit.Color.colorWithRed_green_blue_alpha(
|
||||||
const color = objc.app_kit.Color.colorWithRed_green_blue_alpha(
|
decoration_color.r,
|
||||||
wc.color.r,
|
decoration_color.g,
|
||||||
wc.color.g,
|
decoration_color.b,
|
||||||
wc.color.b,
|
decoration_color.a,
|
||||||
wc.color.a,
|
);
|
||||||
);
|
native_window.setBackgroundColor(color);
|
||||||
native_window.setBackgroundColor(color);
|
native_window.setTitlebarAppearsTransparent(true);
|
||||||
native_window.setTitlebarAppearsTransparent(true);
|
} else {
|
||||||
native_view.layer().setOpaque(false);
|
native_window.setTitlebarAppearsTransparent(false);
|
||||||
},
|
|
||||||
.solid => |wc| {
|
|
||||||
const color = objc.app_kit.Color.colorWithRed_green_blue_alpha(
|
|
||||||
wc.color.r,
|
|
||||||
wc.color.g,
|
|
||||||
wc.color.b,
|
|
||||||
wc.color.a,
|
|
||||||
);
|
|
||||||
native_window.setBackgroundColor(color);
|
|
||||||
native_window.setTitlebarAppearsTransparent(false);
|
|
||||||
native_view.layer().setOpaque(true);
|
|
||||||
},
|
|
||||||
.system => {
|
|
||||||
native_window.setTitlebarAppearsTransparent(false);
|
|
||||||
native_view.layer().setOpaque(true);
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -135,7 +118,7 @@ fn initWindow(
|
||||||
const layer = objc.quartz_core.MetalLayer.new();
|
const layer = objc.quartz_core.MetalLayer.new();
|
||||||
defer layer.release();
|
defer layer.release();
|
||||||
|
|
||||||
if (core_window.color == .transparent) layer.setOpaque(false);
|
if (core_window.transparent) layer.setOpaque(false);
|
||||||
|
|
||||||
metal_descriptor.* = .{
|
metal_descriptor.* = .{
|
||||||
.layer = layer,
|
.layer = layer,
|
||||||
|
|
@ -151,11 +134,11 @@ fn initWindow(
|
||||||
|
|
||||||
const window_style =
|
const window_style =
|
||||||
(if (core_window.display_mode == .fullscreen) objc.app_kit.WindowStyleMaskFullScreen else 0) |
|
(if (core_window.display_mode == .fullscreen) objc.app_kit.WindowStyleMaskFullScreen else 0) |
|
||||||
(if (core_window.display_mode == .windowed) objc.app_kit.WindowStyleMaskTitled else 0) |
|
(if (core_window.decorated) objc.app_kit.WindowStyleMaskTitled else 0) |
|
||||||
(if (core_window.display_mode == .windowed) objc.app_kit.WindowStyleMaskClosable else 0) |
|
(if (core_window.decorated) objc.app_kit.WindowStyleMaskClosable else 0) |
|
||||||
(if (core_window.display_mode == .windowed) objc.app_kit.WindowStyleMaskMiniaturizable else 0) |
|
(if (core_window.decorated) objc.app_kit.WindowStyleMaskMiniaturizable else 0) |
|
||||||
(if (core_window.display_mode == .windowed) objc.app_kit.WindowStyleMaskResizable else 0);
|
(if (core_window.decorated) objc.app_kit.WindowStyleMaskResizable else 0) |
|
||||||
// (if (core_window.display_mode == .windowed) objc.app_kit.WindowStyleMaskFullSizeContentView else 0);
|
(if (!core_window.decorated) objc.app_kit.WindowStyleMaskFullSizeContentView else 0);
|
||||||
|
|
||||||
const native_window_opt: ?*objc.app_kit.Window = objc.app_kit.Window.alloc().initWithContentRect_styleMask_backing_defer_screen(
|
const native_window_opt: ?*objc.app_kit.Window = objc.app_kit.Window.alloc().initWithContentRect_styleMask_backing_defer_screen(
|
||||||
rect,
|
rect,
|
||||||
|
|
@ -254,27 +237,15 @@ fn initWindow(
|
||||||
native_window.setIsVisible(true);
|
native_window.setIsVisible(true);
|
||||||
native_window.makeKeyAndOrderFront(null);
|
native_window.makeKeyAndOrderFront(null);
|
||||||
|
|
||||||
switch (core_window.color) {
|
if (core_window.decoration_color) |decoration_color| {
|
||||||
.transparent => |wc| {
|
const color = objc.app_kit.Color.colorWithRed_green_blue_alpha(
|
||||||
const color = objc.app_kit.Color.colorWithRed_green_blue_alpha(
|
decoration_color.r,
|
||||||
wc.color.r,
|
decoration_color.g,
|
||||||
wc.color.g,
|
decoration_color.b,
|
||||||
wc.color.b,
|
decoration_color.a,
|
||||||
wc.color.a,
|
);
|
||||||
);
|
native_window.setBackgroundColor(color);
|
||||||
native_window.setBackgroundColor(color);
|
native_window.setTitlebarAppearsTransparent(true);
|
||||||
native_window.setTitlebarAppearsTransparent(true);
|
|
||||||
},
|
|
||||||
.solid => |wc| {
|
|
||||||
const color = objc.app_kit.Color.colorWithRed_green_blue_alpha(
|
|
||||||
wc.color.r,
|
|
||||||
wc.color.g,
|
|
||||||
wc.color.b,
|
|
||||||
wc.color.a,
|
|
||||||
);
|
|
||||||
native_window.setBackgroundColor(color);
|
|
||||||
},
|
|
||||||
.system => {},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const string = objc.foundation.String.allocInit();
|
const string = objc.foundation.String.allocInit();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue