2021-07-18 17:47:07 -07:00
//! Window type and related functions
const std = @import ( " std " ) ;
2021-07-20 21:28:00 -07:00
const testing = std . testing ;
const mem = std . mem ;
2021-07-18 17:47:07 -07:00
const c = @import ( " c.zig " ) . c ;
glfw: window hints rework (#71)
* glfw: make comments into doc comments
* glfw: Publicize Window.CursorPos, Window.Size, Window.Pos, and Window.FrameSize
* glfw: Make enum value name the same format as other enum value names
* glfw: Window hints rework patch
* glfw: Relegate `Window.hint` to testing; move it down to just above the tests to reflect this, add doc comment line
* glfw: handle error `Error.InvalidEnum` explicitly, for clear error message in this unlikely edge case
* glfw: instate `Hint.context_no_error` as a hint, as it actually is specified to be a Window creation hint by the docs, and affirm removal of `Hint.context_revision`, which isn't.
The docs don't seem to specify a default value for `Hints.context_no_error` to take on, so we could set it based on `std.debug.runtime_safety` like this.
* glfw: default `context_no_error` to `false`, and added a note of caution about its usage as suggested.
* glfw: Inline enum values of `ClientApi`, `ContextCreationApi`, `ContextRobustness`, `ContextReleaseBehavior`, and `OpenGlProfile` from consts.zig, and remove the now unused constants (replaced by aformentioned enum values).
* glfw: Reference `Window.Hint` enum instead of `Window.Hints` struct to ensure fields are the same
* glfw: add comment explaining default values of `Window.Hints`
* glfw: change `OpenGlProfile` to `OpenGLProfile` based on established naming convention
* glfw: Update actual declaration of `OpenGLProfile`
* glfw: call `Window.defaultHints` after window creation, not before
* glfw: remove 'consts.zig', and move `dont_care` directly into 'main.zig'; fix anything referencing it.
* glfw: put `Window.defaultHints` into defer statement to handle cleanup in all paths
* glfw: move `Hint.focused` to match position of `Hints.focused`
* glfw: do 'zig fmt glfw/src'
* glfw: Cull `Window.Hint` comments, polish remaining; match order entirely according to current GLFW docs
* glfw: Change `Window.Hints.*Api` to `Window.Hints.*API`
Co-authored-by: Stephen Gutekanst <stephen@hexops.com>
2021-11-16 02:41:16 +01:00
const glfw = @import ( " main.zig " ) ;
2021-07-18 17:47:07 -07:00
const Error = @import ( " errors.zig " ) . Error ;
const getError = @import ( " errors.zig " ) . getError ;
2021-07-20 21:28:00 -07:00
const Image = @import ( " Image.zig " ) ;
2021-07-18 21:35:52 -07:00
const Monitor = @import ( " Monitor.zig " ) ;
2021-10-23 12:34:59 -07:00
const Cursor = @import ( " Cursor.zig " ) ;
2021-10-24 15:23:20 +02:00
const Key = @import ( " key.zig " ) . Key ;
2021-10-29 21:22:19 -07:00
const Action = @import ( " action.zig " ) . Action ;
2021-10-30 12:50:39 -07:00
const Mods = @import ( " mod.zig " ) . Mods ;
2021-10-30 15:35:04 -07:00
const MouseButton = @import ( " mouse_button.zig " ) . MouseButton ;
2021-07-18 17:47:07 -07:00
2021-11-21 20:15:16 +01:00
const internal_debug = @import ( " internal_debug.zig " ) ;
2021-07-18 17:47:07 -07:00
const Window = @This ( ) ;
2021-07-18 21:35:52 -07:00
handle : * c . GLFWwindow ,
2021-10-18 00:02:57 -07:00
/// Returns a Zig GLFW window from an underlying C GLFW window handle.
///
/// Note that the Zig GLFW library stores a custom user pointer in order to make callbacks nicer,
/// see glfw.Window.InternalUserPointer.
2021-11-21 20:15:16 +01:00
pub inline fn from ( handle : * c . GLFWwindow ) mem . Allocator . Error ! Window {
internal_debug . assertInitialized ( ) ;
2021-10-18 00:02:57 -07:00
const ptr = c . glfwGetWindowUserPointer ( handle ) ;
if ( ptr = = null ) {
const internal = try std . heap . c_allocator . create ( InternalUserPointer ) ;
c . glfwSetWindowUserPointer ( handle , @ptrCast ( * c_void , internal ) ) ;
2021-11-21 20:15:16 +01:00
getError ( ) catch unreachable ; // Only error 'GLFW_NOT_INITIALIZED' is impossible
2021-10-18 00:02:57 -07:00
}
return Window { . handle = handle } ;
}
/// The actual type which is stored by the Zig GLFW library in glfwSetWindowUserPointer.
///
/// This is used to internally carry function callbacks with nicer Zig interfaces.
pub const InternalUserPointer = struct {
/// The actual user pointer that the user of the library wished to set via setUserPointer.
user_pointer : ? * c_void ,
// Callbacks to be invoked by wrapper functions.
setPosCallback : ? fn ( window : Window , xpos : isize , ypos : isize ) void ,
2021-10-18 00:08:25 -07:00
setSizeCallback : ? fn ( window : Window , width : isize , height : isize ) void ,
2021-10-18 00:15:14 -07:00
setCloseCallback : ? fn ( window : Window ) void ,
2021-10-18 00:23:33 -07:00
setRefreshCallback : ? fn ( window : Window ) void ,
2021-10-18 00:33:28 -07:00
setFocusCallback : ? fn ( window : Window , focused : bool ) void ,
2021-10-18 00:39:31 -07:00
setIconifyCallback : ? fn ( window : Window , iconified : bool ) void ,
2021-10-18 00:41:45 -07:00
setMaximizeCallback : ? fn ( window : Window , maximized : bool ) void ,
2021-10-18 00:50:28 -07:00
setFramebufferSizeCallback : ? fn ( window : Window , width : isize , height : isize ) void ,
2021-10-18 00:58:18 -07:00
setContentScaleCallback : ? fn ( window : Window , xscale : f32 , yscale : f32 ) void ,
2021-10-30 14:10:31 -07:00
setKeyCallback : ? fn ( window : Window , key : Key , scancode : isize , action : Action , mods : Mods ) void ,
2021-10-23 12:12:13 -07:00
setCharCallback : ? fn ( window : Window , codepoint : u21 ) void ,
2021-10-30 15:35:04 -07:00
setMouseButtonCallback : ? fn ( window : Window , button : MouseButton , action : Action , mods : Mods ) void ,
2021-10-23 12:25:57 -07:00
setCursorPosCallback : ? fn ( window : Window , xpos : f64 , ypos : f64 ) void ,
setCursorEnterCallback : ? fn ( window : Window , entered : bool ) void ,
setScrollCallback : ? fn ( window : Window , xoffset : f64 , yoffset : f64 ) void ,
2021-11-11 09:42:49 +00:00
setDropCallback : ? fn ( window : Window , paths : [ ] [ * : 0 ] const u8 ) void ,
2021-10-18 00:02:57 -07:00
} ;
2021-07-18 17:47:07 -07:00
/// Resets all window hints to their default values.
///
/// This function resets all window hints to their default values.
///
/// Possible errors include glfw.Error.NotInitialized.
///
/// @thread_safety This function must only be called from the main thread.
///
/// see also: window_hints, glfw.Window.hint, glfw.Window.hintString
2021-11-21 20:15:16 +01:00
// TODO: Remove error stub
inline fn defaultHints ( ) error { } ! void {
internal_debug . assertInitialized ( ) ;
2021-07-18 17:47:07 -07:00
c . glfwDefaultWindowHints ( ) ;
2021-11-21 20:15:16 +01:00
getError ( ) catch unreachable ; // Only error 'GLFW_NOT_INITIALIZED' is impossible
2021-07-18 17:47:07 -07:00
}
2021-10-30 14:31:06 -07:00
/// Window hints
glfw: window hints rework (#71)
* glfw: make comments into doc comments
* glfw: Publicize Window.CursorPos, Window.Size, Window.Pos, and Window.FrameSize
* glfw: Make enum value name the same format as other enum value names
* glfw: Window hints rework patch
* glfw: Relegate `Window.hint` to testing; move it down to just above the tests to reflect this, add doc comment line
* glfw: handle error `Error.InvalidEnum` explicitly, for clear error message in this unlikely edge case
* glfw: instate `Hint.context_no_error` as a hint, as it actually is specified to be a Window creation hint by the docs, and affirm removal of `Hint.context_revision`, which isn't.
The docs don't seem to specify a default value for `Hints.context_no_error` to take on, so we could set it based on `std.debug.runtime_safety` like this.
* glfw: default `context_no_error` to `false`, and added a note of caution about its usage as suggested.
* glfw: Inline enum values of `ClientApi`, `ContextCreationApi`, `ContextRobustness`, `ContextReleaseBehavior`, and `OpenGlProfile` from consts.zig, and remove the now unused constants (replaced by aformentioned enum values).
* glfw: Reference `Window.Hint` enum instead of `Window.Hints` struct to ensure fields are the same
* glfw: add comment explaining default values of `Window.Hints`
* glfw: change `OpenGlProfile` to `OpenGLProfile` based on established naming convention
* glfw: Update actual declaration of `OpenGLProfile`
* glfw: call `Window.defaultHints` after window creation, not before
* glfw: remove 'consts.zig', and move `dont_care` directly into 'main.zig'; fix anything referencing it.
* glfw: put `Window.defaultHints` into defer statement to handle cleanup in all paths
* glfw: move `Hint.focused` to match position of `Hints.focused`
* glfw: do 'zig fmt glfw/src'
* glfw: Cull `Window.Hint` comments, polish remaining; match order entirely according to current GLFW docs
* glfw: Change `Window.Hints.*Api` to `Window.Hints.*API`
Co-authored-by: Stephen Gutekanst <stephen@hexops.com>
2021-11-16 02:41:16 +01:00
const Hint = enum ( c_int ) {
2021-10-30 14:31:06 -07:00
resizable = c . GLFW_RESIZABLE ,
visible = c . GLFW_VISIBLE ,
decorated = c . GLFW_DECORATED ,
glfw: window hints rework (#71)
* glfw: make comments into doc comments
* glfw: Publicize Window.CursorPos, Window.Size, Window.Pos, and Window.FrameSize
* glfw: Make enum value name the same format as other enum value names
* glfw: Window hints rework patch
* glfw: Relegate `Window.hint` to testing; move it down to just above the tests to reflect this, add doc comment line
* glfw: handle error `Error.InvalidEnum` explicitly, for clear error message in this unlikely edge case
* glfw: instate `Hint.context_no_error` as a hint, as it actually is specified to be a Window creation hint by the docs, and affirm removal of `Hint.context_revision`, which isn't.
The docs don't seem to specify a default value for `Hints.context_no_error` to take on, so we could set it based on `std.debug.runtime_safety` like this.
* glfw: default `context_no_error` to `false`, and added a note of caution about its usage as suggested.
* glfw: Inline enum values of `ClientApi`, `ContextCreationApi`, `ContextRobustness`, `ContextReleaseBehavior`, and `OpenGlProfile` from consts.zig, and remove the now unused constants (replaced by aformentioned enum values).
* glfw: Reference `Window.Hint` enum instead of `Window.Hints` struct to ensure fields are the same
* glfw: add comment explaining default values of `Window.Hints`
* glfw: change `OpenGlProfile` to `OpenGLProfile` based on established naming convention
* glfw: Update actual declaration of `OpenGLProfile`
* glfw: call `Window.defaultHints` after window creation, not before
* glfw: remove 'consts.zig', and move `dont_care` directly into 'main.zig'; fix anything referencing it.
* glfw: put `Window.defaultHints` into defer statement to handle cleanup in all paths
* glfw: move `Hint.focused` to match position of `Hints.focused`
* glfw: do 'zig fmt glfw/src'
* glfw: Cull `Window.Hint` comments, polish remaining; match order entirely according to current GLFW docs
* glfw: Change `Window.Hints.*Api` to `Window.Hints.*API`
Co-authored-by: Stephen Gutekanst <stephen@hexops.com>
2021-11-16 02:41:16 +01:00
focused = c . GLFW_FOCUSED ,
2021-10-30 14:31:06 -07:00
auto_iconify = c . GLFW_AUTO_ICONIFY ,
floating = c . GLFW_FLOATING ,
maximized = c . GLFW_MAXIMIZED ,
2021-11-11 17:06:26 +01:00
center_cursor = c . GLFW_CENTER_CURSOR ,
2021-10-30 14:31:06 -07:00
transparent_framebuffer = c . GLFW_TRANSPARENT_FRAMEBUFFER ,
focus_on_show = c . GLFW_FOCUS_ON_SHOW ,
glfw: window hints rework (#71)
* glfw: make comments into doc comments
* glfw: Publicize Window.CursorPos, Window.Size, Window.Pos, and Window.FrameSize
* glfw: Make enum value name the same format as other enum value names
* glfw: Window hints rework patch
* glfw: Relegate `Window.hint` to testing; move it down to just above the tests to reflect this, add doc comment line
* glfw: handle error `Error.InvalidEnum` explicitly, for clear error message in this unlikely edge case
* glfw: instate `Hint.context_no_error` as a hint, as it actually is specified to be a Window creation hint by the docs, and affirm removal of `Hint.context_revision`, which isn't.
The docs don't seem to specify a default value for `Hints.context_no_error` to take on, so we could set it based on `std.debug.runtime_safety` like this.
* glfw: default `context_no_error` to `false`, and added a note of caution about its usage as suggested.
* glfw: Inline enum values of `ClientApi`, `ContextCreationApi`, `ContextRobustness`, `ContextReleaseBehavior`, and `OpenGlProfile` from consts.zig, and remove the now unused constants (replaced by aformentioned enum values).
* glfw: Reference `Window.Hint` enum instead of `Window.Hints` struct to ensure fields are the same
* glfw: add comment explaining default values of `Window.Hints`
* glfw: change `OpenGlProfile` to `OpenGLProfile` based on established naming convention
* glfw: Update actual declaration of `OpenGLProfile`
* glfw: call `Window.defaultHints` after window creation, not before
* glfw: remove 'consts.zig', and move `dont_care` directly into 'main.zig'; fix anything referencing it.
* glfw: put `Window.defaultHints` into defer statement to handle cleanup in all paths
* glfw: move `Hint.focused` to match position of `Hints.focused`
* glfw: do 'zig fmt glfw/src'
* glfw: Cull `Window.Hint` comments, polish remaining; match order entirely according to current GLFW docs
* glfw: Change `Window.Hints.*Api` to `Window.Hints.*API`
Co-authored-by: Stephen Gutekanst <stephen@hexops.com>
2021-11-16 02:41:16 +01:00
scale_to_monitor = c . GLFW_SCALE_TO_MONITOR ,
2021-10-30 14:31:06 -07:00
glfw: window hints rework (#71)
* glfw: make comments into doc comments
* glfw: Publicize Window.CursorPos, Window.Size, Window.Pos, and Window.FrameSize
* glfw: Make enum value name the same format as other enum value names
* glfw: Window hints rework patch
* glfw: Relegate `Window.hint` to testing; move it down to just above the tests to reflect this, add doc comment line
* glfw: handle error `Error.InvalidEnum` explicitly, for clear error message in this unlikely edge case
* glfw: instate `Hint.context_no_error` as a hint, as it actually is specified to be a Window creation hint by the docs, and affirm removal of `Hint.context_revision`, which isn't.
The docs don't seem to specify a default value for `Hints.context_no_error` to take on, so we could set it based on `std.debug.runtime_safety` like this.
* glfw: default `context_no_error` to `false`, and added a note of caution about its usage as suggested.
* glfw: Inline enum values of `ClientApi`, `ContextCreationApi`, `ContextRobustness`, `ContextReleaseBehavior`, and `OpenGlProfile` from consts.zig, and remove the now unused constants (replaced by aformentioned enum values).
* glfw: Reference `Window.Hint` enum instead of `Window.Hints` struct to ensure fields are the same
* glfw: add comment explaining default values of `Window.Hints`
* glfw: change `OpenGlProfile` to `OpenGLProfile` based on established naming convention
* glfw: Update actual declaration of `OpenGLProfile`
* glfw: call `Window.defaultHints` after window creation, not before
* glfw: remove 'consts.zig', and move `dont_care` directly into 'main.zig'; fix anything referencing it.
* glfw: put `Window.defaultHints` into defer statement to handle cleanup in all paths
* glfw: move `Hint.focused` to match position of `Hints.focused`
* glfw: do 'zig fmt glfw/src'
* glfw: Cull `Window.Hint` comments, polish remaining; match order entirely according to current GLFW docs
* glfw: Change `Window.Hints.*Api` to `Window.Hints.*API`
Co-authored-by: Stephen Gutekanst <stephen@hexops.com>
2021-11-16 02:41:16 +01:00
/// Framebuffer hints
2021-10-30 14:31:06 -07:00
red_bits = c . GLFW_RED_BITS ,
green_bits = c . GLFW_GREEN_BITS ,
blue_bits = c . GLFW_BLUE_BITS ,
alpha_bits = c . GLFW_ALPHA_BITS ,
depth_bits = c . GLFW_DEPTH_BITS ,
stencil_bits = c . GLFW_STENCIL_BITS ,
accum_red_bits = c . GLFW_ACCUM_RED_BITS ,
accum_green_bits = c . GLFW_ACCUM_GREEN_BITS ,
accum_blue_bits = c . GLFW_ACCUM_BLUE_BITS ,
accum_alpha_bits = c . GLFW_ACCUM_ALPHA_BITS ,
aux_buffers = c . GLFW_AUX_BUFFERS ,
glfw: window hints rework (#71)
* glfw: make comments into doc comments
* glfw: Publicize Window.CursorPos, Window.Size, Window.Pos, and Window.FrameSize
* glfw: Make enum value name the same format as other enum value names
* glfw: Window hints rework patch
* glfw: Relegate `Window.hint` to testing; move it down to just above the tests to reflect this, add doc comment line
* glfw: handle error `Error.InvalidEnum` explicitly, for clear error message in this unlikely edge case
* glfw: instate `Hint.context_no_error` as a hint, as it actually is specified to be a Window creation hint by the docs, and affirm removal of `Hint.context_revision`, which isn't.
The docs don't seem to specify a default value for `Hints.context_no_error` to take on, so we could set it based on `std.debug.runtime_safety` like this.
* glfw: default `context_no_error` to `false`, and added a note of caution about its usage as suggested.
* glfw: Inline enum values of `ClientApi`, `ContextCreationApi`, `ContextRobustness`, `ContextReleaseBehavior`, and `OpenGlProfile` from consts.zig, and remove the now unused constants (replaced by aformentioned enum values).
* glfw: Reference `Window.Hint` enum instead of `Window.Hints` struct to ensure fields are the same
* glfw: add comment explaining default values of `Window.Hints`
* glfw: change `OpenGlProfile` to `OpenGLProfile` based on established naming convention
* glfw: Update actual declaration of `OpenGLProfile`
* glfw: call `Window.defaultHints` after window creation, not before
* glfw: remove 'consts.zig', and move `dont_care` directly into 'main.zig'; fix anything referencing it.
* glfw: put `Window.defaultHints` into defer statement to handle cleanup in all paths
* glfw: move `Hint.focused` to match position of `Hints.focused`
* glfw: do 'zig fmt glfw/src'
* glfw: Cull `Window.Hint` comments, polish remaining; match order entirely according to current GLFW docs
* glfw: Change `Window.Hints.*Api` to `Window.Hints.*API`
Co-authored-by: Stephen Gutekanst <stephen@hexops.com>
2021-11-16 02:41:16 +01:00
/// Framebuffer MSAA samples
2021-10-30 14:31:06 -07:00
samples = c . GLFW_SAMPLES ,
glfw: window hints rework (#71)
* glfw: make comments into doc comments
* glfw: Publicize Window.CursorPos, Window.Size, Window.Pos, and Window.FrameSize
* glfw: Make enum value name the same format as other enum value names
* glfw: Window hints rework patch
* glfw: Relegate `Window.hint` to testing; move it down to just above the tests to reflect this, add doc comment line
* glfw: handle error `Error.InvalidEnum` explicitly, for clear error message in this unlikely edge case
* glfw: instate `Hint.context_no_error` as a hint, as it actually is specified to be a Window creation hint by the docs, and affirm removal of `Hint.context_revision`, which isn't.
The docs don't seem to specify a default value for `Hints.context_no_error` to take on, so we could set it based on `std.debug.runtime_safety` like this.
* glfw: default `context_no_error` to `false`, and added a note of caution about its usage as suggested.
* glfw: Inline enum values of `ClientApi`, `ContextCreationApi`, `ContextRobustness`, `ContextReleaseBehavior`, and `OpenGlProfile` from consts.zig, and remove the now unused constants (replaced by aformentioned enum values).
* glfw: Reference `Window.Hint` enum instead of `Window.Hints` struct to ensure fields are the same
* glfw: add comment explaining default values of `Window.Hints`
* glfw: change `OpenGlProfile` to `OpenGLProfile` based on established naming convention
* glfw: Update actual declaration of `OpenGLProfile`
* glfw: call `Window.defaultHints` after window creation, not before
* glfw: remove 'consts.zig', and move `dont_care` directly into 'main.zig'; fix anything referencing it.
* glfw: put `Window.defaultHints` into defer statement to handle cleanup in all paths
* glfw: move `Hint.focused` to match position of `Hints.focused`
* glfw: do 'zig fmt glfw/src'
* glfw: Cull `Window.Hint` comments, polish remaining; match order entirely according to current GLFW docs
* glfw: Change `Window.Hints.*Api` to `Window.Hints.*API`
Co-authored-by: Stephen Gutekanst <stephen@hexops.com>
2021-11-16 02:41:16 +01:00
/// Monitor refresh rate
2021-10-30 14:31:06 -07:00
refresh_rate = c . GLFW_REFRESH_RATE ,
glfw: window hints rework (#71)
* glfw: make comments into doc comments
* glfw: Publicize Window.CursorPos, Window.Size, Window.Pos, and Window.FrameSize
* glfw: Make enum value name the same format as other enum value names
* glfw: Window hints rework patch
* glfw: Relegate `Window.hint` to testing; move it down to just above the tests to reflect this, add doc comment line
* glfw: handle error `Error.InvalidEnum` explicitly, for clear error message in this unlikely edge case
* glfw: instate `Hint.context_no_error` as a hint, as it actually is specified to be a Window creation hint by the docs, and affirm removal of `Hint.context_revision`, which isn't.
The docs don't seem to specify a default value for `Hints.context_no_error` to take on, so we could set it based on `std.debug.runtime_safety` like this.
* glfw: default `context_no_error` to `false`, and added a note of caution about its usage as suggested.
* glfw: Inline enum values of `ClientApi`, `ContextCreationApi`, `ContextRobustness`, `ContextReleaseBehavior`, and `OpenGlProfile` from consts.zig, and remove the now unused constants (replaced by aformentioned enum values).
* glfw: Reference `Window.Hint` enum instead of `Window.Hints` struct to ensure fields are the same
* glfw: add comment explaining default values of `Window.Hints`
* glfw: change `OpenGlProfile` to `OpenGLProfile` based on established naming convention
* glfw: Update actual declaration of `OpenGLProfile`
* glfw: call `Window.defaultHints` after window creation, not before
* glfw: remove 'consts.zig', and move `dont_care` directly into 'main.zig'; fix anything referencing it.
* glfw: put `Window.defaultHints` into defer statement to handle cleanup in all paths
* glfw: move `Hint.focused` to match position of `Hints.focused`
* glfw: do 'zig fmt glfw/src'
* glfw: Cull `Window.Hint` comments, polish remaining; match order entirely according to current GLFW docs
* glfw: Change `Window.Hints.*Api` to `Window.Hints.*API`
Co-authored-by: Stephen Gutekanst <stephen@hexops.com>
2021-11-16 02:41:16 +01:00
/// OpenGL stereoscopic rendering
stereo = c . GLFW_STEREO ,
/// Framebuffer sRGB
srgb_capable = c . GLFW_SRGB_CAPABLE ,
/// Framebuffer double buffering
2021-10-30 14:31:06 -07:00
doublebuffer = c . GLFW_DOUBLEBUFFER ,
client_api = c . GLFW_CLIENT_API ,
glfw: window hints rework (#71)
* glfw: make comments into doc comments
* glfw: Publicize Window.CursorPos, Window.Size, Window.Pos, and Window.FrameSize
* glfw: Make enum value name the same format as other enum value names
* glfw: Window hints rework patch
* glfw: Relegate `Window.hint` to testing; move it down to just above the tests to reflect this, add doc comment line
* glfw: handle error `Error.InvalidEnum` explicitly, for clear error message in this unlikely edge case
* glfw: instate `Hint.context_no_error` as a hint, as it actually is specified to be a Window creation hint by the docs, and affirm removal of `Hint.context_revision`, which isn't.
The docs don't seem to specify a default value for `Hints.context_no_error` to take on, so we could set it based on `std.debug.runtime_safety` like this.
* glfw: default `context_no_error` to `false`, and added a note of caution about its usage as suggested.
* glfw: Inline enum values of `ClientApi`, `ContextCreationApi`, `ContextRobustness`, `ContextReleaseBehavior`, and `OpenGlProfile` from consts.zig, and remove the now unused constants (replaced by aformentioned enum values).
* glfw: Reference `Window.Hint` enum instead of `Window.Hints` struct to ensure fields are the same
* glfw: add comment explaining default values of `Window.Hints`
* glfw: change `OpenGlProfile` to `OpenGLProfile` based on established naming convention
* glfw: Update actual declaration of `OpenGLProfile`
* glfw: call `Window.defaultHints` after window creation, not before
* glfw: remove 'consts.zig', and move `dont_care` directly into 'main.zig'; fix anything referencing it.
* glfw: put `Window.defaultHints` into defer statement to handle cleanup in all paths
* glfw: move `Hint.focused` to match position of `Hints.focused`
* glfw: do 'zig fmt glfw/src'
* glfw: Cull `Window.Hint` comments, polish remaining; match order entirely according to current GLFW docs
* glfw: Change `Window.Hints.*Api` to `Window.Hints.*API`
Co-authored-by: Stephen Gutekanst <stephen@hexops.com>
2021-11-16 02:41:16 +01:00
context_creation_api = c . GLFW_CONTEXT_CREATION_API ,
2021-10-30 14:31:06 -07:00
context_version_major = c . GLFW_CONTEXT_VERSION_MAJOR ,
context_version_minor = c . GLFW_CONTEXT_VERSION_MINOR ,
context_robustness = c . GLFW_CONTEXT_ROBUSTNESS ,
glfw: window hints rework (#71)
* glfw: make comments into doc comments
* glfw: Publicize Window.CursorPos, Window.Size, Window.Pos, and Window.FrameSize
* glfw: Make enum value name the same format as other enum value names
* glfw: Window hints rework patch
* glfw: Relegate `Window.hint` to testing; move it down to just above the tests to reflect this, add doc comment line
* glfw: handle error `Error.InvalidEnum` explicitly, for clear error message in this unlikely edge case
* glfw: instate `Hint.context_no_error` as a hint, as it actually is specified to be a Window creation hint by the docs, and affirm removal of `Hint.context_revision`, which isn't.
The docs don't seem to specify a default value for `Hints.context_no_error` to take on, so we could set it based on `std.debug.runtime_safety` like this.
* glfw: default `context_no_error` to `false`, and added a note of caution about its usage as suggested.
* glfw: Inline enum values of `ClientApi`, `ContextCreationApi`, `ContextRobustness`, `ContextReleaseBehavior`, and `OpenGlProfile` from consts.zig, and remove the now unused constants (replaced by aformentioned enum values).
* glfw: Reference `Window.Hint` enum instead of `Window.Hints` struct to ensure fields are the same
* glfw: add comment explaining default values of `Window.Hints`
* glfw: change `OpenGlProfile` to `OpenGLProfile` based on established naming convention
* glfw: Update actual declaration of `OpenGLProfile`
* glfw: call `Window.defaultHints` after window creation, not before
* glfw: remove 'consts.zig', and move `dont_care` directly into 'main.zig'; fix anything referencing it.
* glfw: put `Window.defaultHints` into defer statement to handle cleanup in all paths
* glfw: move `Hint.focused` to match position of `Hints.focused`
* glfw: do 'zig fmt glfw/src'
* glfw: Cull `Window.Hint` comments, polish remaining; match order entirely according to current GLFW docs
* glfw: Change `Window.Hints.*Api` to `Window.Hints.*API`
Co-authored-by: Stephen Gutekanst <stephen@hexops.com>
2021-11-16 02:41:16 +01:00
context_release_behavior = c . GLFW_CONTEXT_RELEASE_BEHAVIOR ,
context_no_error = c . GLFW_CONTEXT_NO_ERROR ,
2021-10-30 14:31:06 -07:00
opengl_forward_compat = c . GLFW_OPENGL_FORWARD_COMPAT ,
opengl_debug_context = c . GLFW_OPENGL_DEBUG_CONTEXT ,
opengl_profile = c . GLFW_OPENGL_PROFILE ,
/// macOS specific
cocoa_retina_framebuffer = c . GLFW_COCOA_RETINA_FRAMEBUFFER ,
/// macOS specific
cocoa_frame_name = c . GLFW_COCOA_FRAME_NAME ,
/// macOS specific
cocoa_graphics_switching = c . GLFW_COCOA_GRAPHICS_SWITCHING ,
/// X11 specific
x11_class_name = c . GLFW_X11_CLASS_NAME ,
/// X11 specific
x11_instance_name = c . GLFW_X11_INSTANCE_NAME ,
} ;
glfw: window hints rework (#71)
* glfw: make comments into doc comments
* glfw: Publicize Window.CursorPos, Window.Size, Window.Pos, and Window.FrameSize
* glfw: Make enum value name the same format as other enum value names
* glfw: Window hints rework patch
* glfw: Relegate `Window.hint` to testing; move it down to just above the tests to reflect this, add doc comment line
* glfw: handle error `Error.InvalidEnum` explicitly, for clear error message in this unlikely edge case
* glfw: instate `Hint.context_no_error` as a hint, as it actually is specified to be a Window creation hint by the docs, and affirm removal of `Hint.context_revision`, which isn't.
The docs don't seem to specify a default value for `Hints.context_no_error` to take on, so we could set it based on `std.debug.runtime_safety` like this.
* glfw: default `context_no_error` to `false`, and added a note of caution about its usage as suggested.
* glfw: Inline enum values of `ClientApi`, `ContextCreationApi`, `ContextRobustness`, `ContextReleaseBehavior`, and `OpenGlProfile` from consts.zig, and remove the now unused constants (replaced by aformentioned enum values).
* glfw: Reference `Window.Hint` enum instead of `Window.Hints` struct to ensure fields are the same
* glfw: add comment explaining default values of `Window.Hints`
* glfw: change `OpenGlProfile` to `OpenGLProfile` based on established naming convention
* glfw: Update actual declaration of `OpenGLProfile`
* glfw: call `Window.defaultHints` after window creation, not before
* glfw: remove 'consts.zig', and move `dont_care` directly into 'main.zig'; fix anything referencing it.
* glfw: put `Window.defaultHints` into defer statement to handle cleanup in all paths
* glfw: move `Hint.focused` to match position of `Hints.focused`
* glfw: do 'zig fmt glfw/src'
* glfw: Cull `Window.Hint` comments, polish remaining; match order entirely according to current GLFW docs
* glfw: Change `Window.Hints.*Api` to `Window.Hints.*API`
Co-authored-by: Stephen Gutekanst <stephen@hexops.com>
2021-11-16 02:41:16 +01:00
/// Window hints
pub const Hints = struct {
// Note: The defaults here are directly from the GLFW source of the glfwDefaultWindowHints function
resizable : bool = true ,
visible : bool = true ,
decorated : bool = true ,
focused : bool = true ,
auto_iconify : bool = true ,
floating : bool = false ,
maximized : bool = false ,
center_cursor : bool = true ,
transparent_framebuffer : bool = false ,
focus_on_show : bool = true ,
scale_to_monitor : bool = false ,
/// Framebuffer hints
red_bits : c_int = 8 ,
green_bits : c_int = 8 ,
blue_bits : c_int = 8 ,
alpha_bits : c_int = 8 ,
depth_bits : c_int = 24 ,
stencil_bits : c_int = 8 ,
accum_red_bits : c_int = 0 ,
accum_green_bits : c_int = 0 ,
accum_blue_bits : c_int = 0 ,
accum_alpha_bits : c_int = 0 ,
aux_buffers : c_int = 0 ,
/// Framebuffer MSAA samples
samples : c_int = 0 ,
/// Monitor refresh rate
refresh_rate : c_int = glfw . dont_care ,
/// OpenGL stereoscopic rendering
stereo : bool = false ,
/// Framebuffer sRGB
srgb_capable : bool = false ,
/// Framebuffer double buffering
doublebuffer : bool = true ,
client_api : ClientAPI = . opengl_api ,
context_creation_api : ContextCreationAPI = . native_context_api ,
context_version_major : c_int = 1 ,
context_version_minor : c_int = 0 ,
context_robustness : ContextRobustness = . no_robustness ,
context_release_behavior : ContextReleaseBehavior = . any_release_behavior ,
/// Note: disables the context creating errors,
/// instead turning them into undefined behavior.
context_no_error : bool = false ,
opengl_forward_compat : bool = false ,
opengl_debug_context : bool = false ,
opengl_profile : OpenGLProfile = . opengl_any_profile ,
2021-10-18 22:19:25 +02:00
glfw: window hints rework (#71)
* glfw: make comments into doc comments
* glfw: Publicize Window.CursorPos, Window.Size, Window.Pos, and Window.FrameSize
* glfw: Make enum value name the same format as other enum value names
* glfw: Window hints rework patch
* glfw: Relegate `Window.hint` to testing; move it down to just above the tests to reflect this, add doc comment line
* glfw: handle error `Error.InvalidEnum` explicitly, for clear error message in this unlikely edge case
* glfw: instate `Hint.context_no_error` as a hint, as it actually is specified to be a Window creation hint by the docs, and affirm removal of `Hint.context_revision`, which isn't.
The docs don't seem to specify a default value for `Hints.context_no_error` to take on, so we could set it based on `std.debug.runtime_safety` like this.
* glfw: default `context_no_error` to `false`, and added a note of caution about its usage as suggested.
* glfw: Inline enum values of `ClientApi`, `ContextCreationApi`, `ContextRobustness`, `ContextReleaseBehavior`, and `OpenGlProfile` from consts.zig, and remove the now unused constants (replaced by aformentioned enum values).
* glfw: Reference `Window.Hint` enum instead of `Window.Hints` struct to ensure fields are the same
* glfw: add comment explaining default values of `Window.Hints`
* glfw: change `OpenGlProfile` to `OpenGLProfile` based on established naming convention
* glfw: Update actual declaration of `OpenGLProfile`
* glfw: call `Window.defaultHints` after window creation, not before
* glfw: remove 'consts.zig', and move `dont_care` directly into 'main.zig'; fix anything referencing it.
* glfw: put `Window.defaultHints` into defer statement to handle cleanup in all paths
* glfw: move `Hint.focused` to match position of `Hints.focused`
* glfw: do 'zig fmt glfw/src'
* glfw: Cull `Window.Hint` comments, polish remaining; match order entirely according to current GLFW docs
* glfw: Change `Window.Hints.*Api` to `Window.Hints.*API`
Co-authored-by: Stephen Gutekanst <stephen@hexops.com>
2021-11-16 02:41:16 +01:00
/// macOS specific
cocoa_retina_framebuffer : bool = true ,
/// macOS specific
cocoa_frame_name : [ : 0 ] const u8 = " " ,
/// macOS specific
cocoa_graphics_switching : bool = false ,
/// X11 specific
x11_class_name : [ : 0 ] const u8 = " " ,
/// X11 specific
x11_instance_name : [ : 0 ] const u8 = " " ,
pub const ClientAPI = enum ( c_int ) {
opengl_api = c . GLFW_OPENGL_API ,
opengl_es_api = c . GLFW_OPENGL_ES_API ,
no_api = c . GLFW_NO_API ,
} ;
pub const ContextCreationAPI = enum ( c_int ) {
native_context_api = c . GLFW_NATIVE_CONTEXT_API ,
egl_context_api = c . GLFW_EGL_CONTEXT_API ,
osmesa_context_api = c . GLFW_OSMESA_CONTEXT_API ,
} ;
pub const ContextRobustness = enum ( c_int ) {
no_robustness = c . GLFW_NO_ROBUSTNESS ,
no_reset_notification = c . GLFW_NO_RESET_NOTIFICATION ,
lose_context_on_reset = c . GLFW_LOSE_CONTEXT_ON_RESET ,
} ;
pub const ContextReleaseBehavior = enum ( c_int ) {
any_release_behavior = c . GLFW_ANY_RELEASE_BEHAVIOR ,
release_behavior_flush = c . GLFW_RELEASE_BEHAVIOR_FLUSH ,
release_behavior_none = c . GLFW_RELEASE_BEHAVIOR_NONE ,
} ;
pub const OpenGLProfile = enum ( c_int ) {
opengl_any_profile = c . GLFW_OPENGL_ANY_PROFILE ,
opengl_compat_profile = c . GLFW_OPENGL_COMPAT_PROFILE ,
opengl_core_profile = c . GLFW_OPENGL_CORE_PROFILE ,
} ;
2021-11-21 20:15:16 +01:00
// TODO: Remove error stub
fn set ( hints : Hints ) error { } ! void {
internal_debug . assertInitialized ( ) ;
glfw: window hints rework (#71)
* glfw: make comments into doc comments
* glfw: Publicize Window.CursorPos, Window.Size, Window.Pos, and Window.FrameSize
* glfw: Make enum value name the same format as other enum value names
* glfw: Window hints rework patch
* glfw: Relegate `Window.hint` to testing; move it down to just above the tests to reflect this, add doc comment line
* glfw: handle error `Error.InvalidEnum` explicitly, for clear error message in this unlikely edge case
* glfw: instate `Hint.context_no_error` as a hint, as it actually is specified to be a Window creation hint by the docs, and affirm removal of `Hint.context_revision`, which isn't.
The docs don't seem to specify a default value for `Hints.context_no_error` to take on, so we could set it based on `std.debug.runtime_safety` like this.
* glfw: default `context_no_error` to `false`, and added a note of caution about its usage as suggested.
* glfw: Inline enum values of `ClientApi`, `ContextCreationApi`, `ContextRobustness`, `ContextReleaseBehavior`, and `OpenGlProfile` from consts.zig, and remove the now unused constants (replaced by aformentioned enum values).
* glfw: Reference `Window.Hint` enum instead of `Window.Hints` struct to ensure fields are the same
* glfw: add comment explaining default values of `Window.Hints`
* glfw: change `OpenGlProfile` to `OpenGLProfile` based on established naming convention
* glfw: Update actual declaration of `OpenGLProfile`
* glfw: call `Window.defaultHints` after window creation, not before
* glfw: remove 'consts.zig', and move `dont_care` directly into 'main.zig'; fix anything referencing it.
* glfw: put `Window.defaultHints` into defer statement to handle cleanup in all paths
* glfw: move `Hint.focused` to match position of `Hints.focused`
* glfw: do 'zig fmt glfw/src'
* glfw: Cull `Window.Hint` comments, polish remaining; match order entirely according to current GLFW docs
* glfw: Change `Window.Hints.*Api` to `Window.Hints.*API`
Co-authored-by: Stephen Gutekanst <stephen@hexops.com>
2021-11-16 02:41:16 +01:00
inline for ( comptime std . meta . fieldNames ( Hint ) ) | field_name | {
const hint_tag = @enumToInt ( @field ( Hint , field_name ) ) ;
const hint_value = @field ( hints , field_name ) ;
switch ( @TypeOf ( hint_value ) ) {
bool = > c . glfwWindowHint ( hint_tag , @boolToInt ( hint_value ) ) ,
c_int = > c . glfwWindowHint ( hint_tag , hint_value ) ,
ClientAPI ,
ContextCreationAPI ,
ContextRobustness ,
ContextReleaseBehavior ,
OpenGLProfile ,
= > c . glfwWindowHint ( hint_tag , @enumToInt ( hint_value ) ) ,
[ : 0 ] const u8 = > c . glfwWindowHintString ( hint_tag , hint_value . ptr ) ,
else = > unreachable ,
2021-10-18 22:19:25 +02:00
}
2021-10-30 14:31:06 -07:00
2021-11-21 20:15:16 +01:00
getError ( ) catch | err | return switch ( err ) {
glfw: window hints rework (#71)
* glfw: make comments into doc comments
* glfw: Publicize Window.CursorPos, Window.Size, Window.Pos, and Window.FrameSize
* glfw: Make enum value name the same format as other enum value names
* glfw: Window hints rework patch
* glfw: Relegate `Window.hint` to testing; move it down to just above the tests to reflect this, add doc comment line
* glfw: handle error `Error.InvalidEnum` explicitly, for clear error message in this unlikely edge case
* glfw: instate `Hint.context_no_error` as a hint, as it actually is specified to be a Window creation hint by the docs, and affirm removal of `Hint.context_revision`, which isn't.
The docs don't seem to specify a default value for `Hints.context_no_error` to take on, so we could set it based on `std.debug.runtime_safety` like this.
* glfw: default `context_no_error` to `false`, and added a note of caution about its usage as suggested.
* glfw: Inline enum values of `ClientApi`, `ContextCreationApi`, `ContextRobustness`, `ContextReleaseBehavior`, and `OpenGlProfile` from consts.zig, and remove the now unused constants (replaced by aformentioned enum values).
* glfw: Reference `Window.Hint` enum instead of `Window.Hints` struct to ensure fields are the same
* glfw: add comment explaining default values of `Window.Hints`
* glfw: change `OpenGlProfile` to `OpenGLProfile` based on established naming convention
* glfw: Update actual declaration of `OpenGLProfile`
* glfw: call `Window.defaultHints` after window creation, not before
* glfw: remove 'consts.zig', and move `dont_care` directly into 'main.zig'; fix anything referencing it.
* glfw: put `Window.defaultHints` into defer statement to handle cleanup in all paths
* glfw: move `Hint.focused` to match position of `Hints.focused`
* glfw: do 'zig fmt glfw/src'
* glfw: Cull `Window.Hint` comments, polish remaining; match order entirely according to current GLFW docs
* glfw: Change `Window.Hints.*Api` to `Window.Hints.*API`
Co-authored-by: Stephen Gutekanst <stephen@hexops.com>
2021-11-16 02:41:16 +01:00
Error . InvalidEnum = > unreachable , // should not be possible, given that only values defined within this struct are possible.
else = > unreachable ,
} ;
}
2021-10-18 22:19:25 +02:00
}
glfw: window hints rework (#71)
* glfw: make comments into doc comments
* glfw: Publicize Window.CursorPos, Window.Size, Window.Pos, and Window.FrameSize
* glfw: Make enum value name the same format as other enum value names
* glfw: Window hints rework patch
* glfw: Relegate `Window.hint` to testing; move it down to just above the tests to reflect this, add doc comment line
* glfw: handle error `Error.InvalidEnum` explicitly, for clear error message in this unlikely edge case
* glfw: instate `Hint.context_no_error` as a hint, as it actually is specified to be a Window creation hint by the docs, and affirm removal of `Hint.context_revision`, which isn't.
The docs don't seem to specify a default value for `Hints.context_no_error` to take on, so we could set it based on `std.debug.runtime_safety` like this.
* glfw: default `context_no_error` to `false`, and added a note of caution about its usage as suggested.
* glfw: Inline enum values of `ClientApi`, `ContextCreationApi`, `ContextRobustness`, `ContextReleaseBehavior`, and `OpenGlProfile` from consts.zig, and remove the now unused constants (replaced by aformentioned enum values).
* glfw: Reference `Window.Hint` enum instead of `Window.Hints` struct to ensure fields are the same
* glfw: add comment explaining default values of `Window.Hints`
* glfw: change `OpenGlProfile` to `OpenGLProfile` based on established naming convention
* glfw: Update actual declaration of `OpenGLProfile`
* glfw: call `Window.defaultHints` after window creation, not before
* glfw: remove 'consts.zig', and move `dont_care` directly into 'main.zig'; fix anything referencing it.
* glfw: put `Window.defaultHints` into defer statement to handle cleanup in all paths
* glfw: move `Hint.focused` to match position of `Hints.focused`
* glfw: do 'zig fmt glfw/src'
* glfw: Cull `Window.Hint` comments, polish remaining; match order entirely according to current GLFW docs
* glfw: Change `Window.Hints.*Api` to `Window.Hints.*API`
Co-authored-by: Stephen Gutekanst <stephen@hexops.com>
2021-11-16 02:41:16 +01:00
} ;
2021-07-18 20:33:04 -07:00
2021-07-18 21:35:52 -07:00
/// Creates a window and its associated context.
///
/// This function creates a window and its associated OpenGL or OpenGL ES context. Most of the
/// options controlling how the window and its context should be created are specified with window
/// hints using `glfw.Window.hint`.
///
/// Successful creation does not change which context is current. Before you can use the newly
/// created context, you need to make it current using `glfw.Window.makeContextCurrent`. For
/// information about the `share` parameter, see context_sharing.
///
/// The created window, framebuffer and context may differ from what you requested, as not all
/// parameters and hints are hard constraints. This includes the size of the window, especially for
/// full screen windows. To query the actual attributes of the created window, framebuffer and
/// context, see glfw.Window.getAttrib, glfw.Window.getSize and glfw.window.getFramebufferSize.
///
/// To create a full screen window, you need to specify the monitor the window will cover. If no
/// monitor is specified, the window will be windowed mode. Unless you have a way for the user to
/// choose a specific monitor, it is recommended that you pick the primary monitor. For more
/// information on how to query connected monitors, see @ref monitor_monitors.
///
/// For full screen windows, the specified size becomes the resolution of the window's _desired
/// video mode_. As long as a full screen window is not iconified, the supported video mode most
/// closely matching the desired video mode is set for the specified monitor. For more information
/// about full screen windows, including the creation of so called _windowed full screen_ or
/// _borderless full screen_ windows, see window_windowed_full_screen.
///
/// Once you have created the window, you can switch it between windowed and full screen mode with
/// glfw.Window.setMonitor. This will not affect its OpenGL or OpenGL ES context.
///
/// By default, newly created windows use the placement recommended by the window system. To create
/// the window at a specific position, make it initially invisible using the glfw.version window
/// hint, set its position and then show it.
///
/// As long as at least one full screen window is not iconified, the screensaver is prohibited from
/// starting.
///
/// Window systems put limits on window sizes. Very large or very small window dimensions may be
/// overridden by the window system on creation. Check the actual size after creation.
///
/// The swap interval is not set during window creation and the initial value may vary depending on
/// driver settings and defaults.
///
/// Possible errors include glfw.Error.NotInitialized, glfw.Error.InvalidEnum, glfw.Error.InvalidValue,
/// glfw.Error.APIUnavailable, glfw.Error.VersionUnavailable, glfw.Error.FormatUnavailable and
/// glfw.Error.PlatformError.
///
/// Parameters are as follows:
///
/// * `width` The desired width, in screen coordinates, of the window.
/// * `height` The desired height, in screen coordinates, of the window.
/// * `title` The initial, UTF-8 encoded window title.
/// * `monitor` The monitor to use for full screen mode, or `null` for windowed mode.
/// * `share` The window whose context to share resources with, or `null` to not share resources.
///
/// win32: Window creation will fail if the Microsoft GDI software OpenGL implementation is the
/// only one available.
///
/// win32: If the executable has an icon resource named `GLFW_ICON`, it will be set as the initial
/// icon for the window. If no such icon is present, the `IDI_APPLICATION` icon will be used
/// instead. To set a different icon, see glfw.Window.setIcon.
///
/// win32: The context to share resources with must not be current on any other thread.
///
/// macos: The OS only supports forward-compatible core profile contexts for OpenGL versions 3.2
/// and later. Before creating an OpenGL context of version 3.2 or later you must set the
/// `glfw.opengl_forward_compat` and `glfw.opengl_profile` hints accordingly. OpenGL 3.0 and 3.1
/// contexts are not supported at all on macOS.
///
/// macos: The GLFW window has no icon, as it is not a document window, but the dock icon will be
/// the same as the application bundle's icon. For more information on bundles, see the
/// [Bundle Programming Guide](https://developer.apple.com/library/mac/documentation/CoreFoundation/Conceptual/CFBundles/)
/// in the Mac Developer Library.
///
/// macos: The first time a window is created the menu bar is created. If GLFW finds a `MainMenu.nib`
/// it is loaded and assumed to contain a menu bar. Otherwise a minimal menu bar is created
/// manually with common commands like Hide, Quit and About. The About entry opens a minimal about
/// dialog with information from the application's bundle. Menu bar creation can be disabled
/// entirely with the glfw.cocoa_menubar init hint.
///
/// macos: On OS X 10.10 and later the window frame will not be rendered at full resolution on
/// Retina displays unless the glfw.cocoa_retina_framebuffer hint is true (1) and the `NSHighResolutionCapable`
/// key is enabled in the application bundle's `Info.plist`. For more information, see
/// [High Resolution Guidelines for OS X](https://developer.apple.com/library/mac/documentation/GraphicsAnimation/Conceptual/HighResolutionOSX/Explained/Explained.html)
/// in the Mac Developer Library. The GLFW test and example programs use a custom `Info.plist`
/// template for this, which can be found as `CMake/MacOSXBundleInfo.plist.in` in the source tree.
///
/// macos: When activating frame autosaving with glfw.cocoa_frame_name, the specified window size
/// and position may be overridden by previously saved values.
///
/// x11: Some window managers will not respect the placement of initially hidden windows.
///
/// x11: Due to the asynchronous nature of X11, it may take a moment for a window to reach its
/// requested state. This means you may not be able to query the final size, position or other
/// attributes directly after window creation.
///
/// x11: The class part of the `WM_CLASS` window property will by default be set to the window title
/// passed to this function. The instance part will use the contents of the `RESOURCE_NAME`
/// environment variable, if present and not empty, or fall back to the window title. Set the glfw.x11_class_name
/// and glfw.x11_instance_name window hints to override this.
///
/// wayland: Compositors should implement the xdg-decoration protocol for GLFW to decorate the
/// window properly. If this protocol isn't supported, or if the compositor prefers client-side
/// decorations, a very simple fallback frame will be drawn using the wp_viewporter protocol. A
/// compositor can still emit close, maximize or fullscreen events, using for instance a keybind
/// mechanism. If neither of these protocols is supported, the window won't be decorated.
///
/// wayland: A full screen window will not attempt to change the mode, no matter what the
/// requested size or refresh rate.
///
/// wayland: Screensaver inhibition requires the idle-inhibit protocol to be implemented in the
/// user's compositor.
///
/// @thread_safety This function must only be called from the main thread.
///
/// see also: window_creation, glfw.Window.destroy
2021-11-11 09:42:49 +00:00
pub inline fn create ( width : usize , height : usize , title : [ * : 0 ] const u8 , monitor : ? Monitor , share : ? Window , hints : Hints ) Error ! Window {
2021-11-21 20:15:16 +01:00
internal_debug . assertInitialized ( ) ;
2021-11-20 20:42:52 +01:00
const ignore_hints_struct = if ( comptime @import ( " builtin " ) . is_test ) testing_ignore_window_hints_struct else false ;
if ( ! ignore_hints_struct ) try hints . set ( ) ;
defer if ( ! ignore_hints_struct ) defaultHints ( ) catch unreachable ; // this should be unreachable, being that this should be caught in the previous call to `Hints.set`.
glfw: window hints rework (#71)
* glfw: make comments into doc comments
* glfw: Publicize Window.CursorPos, Window.Size, Window.Pos, and Window.FrameSize
* glfw: Make enum value name the same format as other enum value names
* glfw: Window hints rework patch
* glfw: Relegate `Window.hint` to testing; move it down to just above the tests to reflect this, add doc comment line
* glfw: handle error `Error.InvalidEnum` explicitly, for clear error message in this unlikely edge case
* glfw: instate `Hint.context_no_error` as a hint, as it actually is specified to be a Window creation hint by the docs, and affirm removal of `Hint.context_revision`, which isn't.
The docs don't seem to specify a default value for `Hints.context_no_error` to take on, so we could set it based on `std.debug.runtime_safety` like this.
* glfw: default `context_no_error` to `false`, and added a note of caution about its usage as suggested.
* glfw: Inline enum values of `ClientApi`, `ContextCreationApi`, `ContextRobustness`, `ContextReleaseBehavior`, and `OpenGlProfile` from consts.zig, and remove the now unused constants (replaced by aformentioned enum values).
* glfw: Reference `Window.Hint` enum instead of `Window.Hints` struct to ensure fields are the same
* glfw: add comment explaining default values of `Window.Hints`
* glfw: change `OpenGlProfile` to `OpenGLProfile` based on established naming convention
* glfw: Update actual declaration of `OpenGLProfile`
* glfw: call `Window.defaultHints` after window creation, not before
* glfw: remove 'consts.zig', and move `dont_care` directly into 'main.zig'; fix anything referencing it.
* glfw: put `Window.defaultHints` into defer statement to handle cleanup in all paths
* glfw: move `Hint.focused` to match position of `Hints.focused`
* glfw: do 'zig fmt glfw/src'
* glfw: Cull `Window.Hint` comments, polish remaining; match order entirely according to current GLFW docs
* glfw: Change `Window.Hints.*Api` to `Window.Hints.*API`
Co-authored-by: Stephen Gutekanst <stephen@hexops.com>
2021-11-16 02:41:16 +01:00
2021-07-18 21:35:52 -07:00
const handle = c . glfwCreateWindow (
@intCast ( c_int , width ) ,
@intCast ( c_int , height ) ,
& title [ 0 ] ,
if ( monitor ) | m | m . handle else null ,
if ( share ) | w | w . handle else null ,
) ;
2021-11-21 20:15:16 +01:00
// TODO: Consider all the possible errors here, and whether they are actually possible
2021-07-18 21:35:52 -07:00
try getError ( ) ;
glfw: window hints rework (#71)
* glfw: make comments into doc comments
* glfw: Publicize Window.CursorPos, Window.Size, Window.Pos, and Window.FrameSize
* glfw: Make enum value name the same format as other enum value names
* glfw: Window hints rework patch
* glfw: Relegate `Window.hint` to testing; move it down to just above the tests to reflect this, add doc comment line
* glfw: handle error `Error.InvalidEnum` explicitly, for clear error message in this unlikely edge case
* glfw: instate `Hint.context_no_error` as a hint, as it actually is specified to be a Window creation hint by the docs, and affirm removal of `Hint.context_revision`, which isn't.
The docs don't seem to specify a default value for `Hints.context_no_error` to take on, so we could set it based on `std.debug.runtime_safety` like this.
* glfw: default `context_no_error` to `false`, and added a note of caution about its usage as suggested.
* glfw: Inline enum values of `ClientApi`, `ContextCreationApi`, `ContextRobustness`, `ContextReleaseBehavior`, and `OpenGlProfile` from consts.zig, and remove the now unused constants (replaced by aformentioned enum values).
* glfw: Reference `Window.Hint` enum instead of `Window.Hints` struct to ensure fields are the same
* glfw: add comment explaining default values of `Window.Hints`
* glfw: change `OpenGlProfile` to `OpenGLProfile` based on established naming convention
* glfw: Update actual declaration of `OpenGLProfile`
* glfw: call `Window.defaultHints` after window creation, not before
* glfw: remove 'consts.zig', and move `dont_care` directly into 'main.zig'; fix anything referencing it.
* glfw: put `Window.defaultHints` into defer statement to handle cleanup in all paths
* glfw: move `Hint.focused` to match position of `Hints.focused`
* glfw: do 'zig fmt glfw/src'
* glfw: Cull `Window.Hint` comments, polish remaining; match order entirely according to current GLFW docs
* glfw: Change `Window.Hints.*Api` to `Window.Hints.*API`
Co-authored-by: Stephen Gutekanst <stephen@hexops.com>
2021-11-16 02:41:16 +01:00
2021-10-18 00:02:57 -07:00
return from ( handle . ? ) ;
2021-07-18 21:35:52 -07:00
}
2021-11-20 20:42:52 +01:00
var testing_ignore_window_hints_struct = if ( @import ( " builtin " ) . is_test ) false else @as ( void , { } ) ;
2021-07-18 21:41:21 -07:00
/// Destroys the specified window and its context.
///
/// This function destroys the specified window and its context. On calling this function, no
/// further callbacks will be called for that window.
///
/// If the context of the specified window is current on the main thread, it is detached before
/// being destroyed.
///
/// note: The context of the specified window must not be current on any other thread when this
/// function is called.
///
/// @reentrancy This function must not be called from a callback.
///
/// @thread_safety This function must only be called from the main thread.
///
/// see also: window_creation, glfw.Window.create
2021-07-18 22:04:03 -07:00
pub inline fn destroy ( self : Window ) void {
2021-11-21 20:15:16 +01:00
internal_debug . assertInitialized ( ) ;
2021-10-18 00:02:57 -07:00
const internal = self . getInternal ( ) ;
2021-07-18 21:41:21 -07:00
c . glfwDestroyWindow ( self . handle ) ;
2021-10-18 00:02:57 -07:00
std . heap . c_allocator . destroy ( internal ) ;
2021-07-18 21:41:21 -07:00
// Technically, glfwDestroyWindow could produce errors including glfw.Error.NotInitialized and
// glfw.Error.PlatformError. But how would anybody handle them? By creating a new window to
// warn the user? That seems user-hostile. Also, `defer try window.destroy()` isn't possible in
// Zig, so by returning an error we'd make it harder to destroy the window properly. So we differ
// from GLFW here: we discard any potential error from this operation.
2021-11-21 20:15:16 +01:00
getError ( ) catch | err | return switch ( err ) {
Error . PlatformError = > { } , // TODO: Consider this error, and whether it can be guaranteed to not occur somehow
else = > unreachable ,
} ;
2021-07-18 21:41:21 -07:00
}
2021-07-18 21:57:46 -07:00
/// Checks the close flag of the specified window.
///
/// This function returns the value of the close flag of the specified window.
///
/// @thread_safety This function may be called from any thread. Access is not synchronized.
///
/// see also: window_close
2021-07-18 22:04:03 -07:00
pub inline fn shouldClose ( self : Window ) bool {
2021-11-21 20:15:16 +01:00
internal_debug . assertInitialized ( ) ;
2021-07-18 21:57:46 -07:00
const flag = c . glfwWindowShouldClose ( self . handle ) ;
2021-11-21 20:15:16 +01:00
getError ( ) catch unreachable ; // Only error 'GLFW_NOT_INITIALIZED' is impossible
2021-07-18 21:57:46 -07:00
return flag = = c . GLFW_TRUE ;
}
2021-07-18 22:01:18 -07:00
/// Sets the close flag of the specified window.
///
/// This function sets the value of the close flag of the specified window. This can be used to
/// override the user's attempt to close the window, or to signal that it should be closed.
///
/// Possible errors include glfw.Error.NotInitialized.
///
/// @thread_safety This function may be called from any thread. Access is not
/// synchronized.
///
/// see also: window_close
2021-11-21 20:15:16 +01:00
// TODO: Remove error stub
pub inline fn setShouldClose ( self : Window , value : bool ) error { } ! void {
internal_debug . assertInitialized ( ) ;
2021-07-18 22:01:18 -07:00
const boolean = if ( value ) c . GLFW_TRUE else c . GLFW_FALSE ;
c . glfwSetWindowShouldClose ( self . handle , boolean ) ;
2021-11-21 20:15:16 +01:00
getError ( ) catch unreachable ; // Only error 'GLFW_NOT_INITIALIZED' is impossible
2021-07-18 22:01:18 -07:00
}
2021-07-19 19:09:53 -07:00
/// Sets the UTF-8 encoded title of the specified window.
///
/// This function sets the window title, encoded as UTF-8, of the specified window.
///
/// Possible errors include glfw.Error.NotInitialized and glfw.Error.PlatformError.
///
/// macos: The window title will not be updated until the next time you process events.
///
/// @thread_safety This function must only be called from the main thread.
///
/// see also: window_title
2021-11-21 20:15:16 +01:00
pub inline fn setTitle ( self : Window , title : [ * : 0 ] const u8 ) error { PlatformError } ! void {
internal_debug . assertInitialized ( ) ;
2021-07-19 19:09:53 -07:00
c . glfwSetWindowTitle ( self . handle , title ) ;
2021-11-21 20:15:16 +01:00
getError ( ) catch | err | return switch ( err ) {
Error . PlatformError = > err ,
else = > unreachable ,
} ;
2021-07-19 19:09:53 -07:00
}
2021-07-20 21:28:00 -07:00
/// Sets the icon for the specified window.
///
/// This function sets the icon of the specified window. If passed an array of candidate images,
/// those of or closest to the sizes desired by the system are selected. If no images are
/// specified, the window reverts to its default icon.
///
/// The pixels are 32-bit, little-endian, non-premultiplied RGBA, i.e. eight bits per channel with
/// the red channel first. They are arranged canonically as packed sequential rows, starting from
/// the top-left corner.
///
/// The desired image sizes varies depending on platform and system settings. The selected images
/// will be rescaled as needed. Good sizes include 16x16, 32x32 and 48x48.
///
/// Possible errors include glfw.Error.NotInitialized and glfw.Error.PlatformError.
///
/// @pointer_lifetime The specified image data is copied before this function returns.
///
/// macos: The GLFW window has no icon, as it is not a document window, so this function does
/// nothing. The dock icon will be the same as the application bundle's icon. For more information
/// on bundles, see the [Bundle Programming Guide](https://developer.apple.com/library/mac/documentation/CoreFoundation/Conceptual/CFBundles/)
/// in the Mac Developer Library.
///
/// wayland: There is no existing protocol to change an icon, the window will thus inherit the one
/// defined in the application's desktop file. This function always emits glfw.Error.PlatformError.
///
/// @thread_safety This function must only be called from the main thread.
///
/// see also: window_icon
2021-11-21 20:15:16 +01:00
pub inline fn setIcon ( self : Window , allocator : * mem . Allocator , images : ? [ ] Image ) ( mem . Allocator . Error | | error { PlatformError } ) ! void {
internal_debug . assertInitialized ( ) ;
2021-07-20 21:28:00 -07:00
if ( images ) | im | {
const tmp = try allocator . alloc ( c . GLFWimage , im . len ) ;
defer allocator . free ( tmp ) ;
for ( im ) | img , index | tmp [ index ] = img . toC ( ) ;
c . glfwSetWindowIcon ( self . handle , @intCast ( c_int , im . len ) , & tmp [ 0 ] ) ;
} else c . glfwSetWindowIcon ( self . handle , 0 , null ) ;
2021-11-21 20:15:16 +01:00
getError ( ) catch | err | return switch ( err ) {
Error . PlatformError = > err ,
else = > unreachable ,
} ;
2021-07-20 21:28:00 -07:00
}
2021-11-11 14:54:55 +01:00
pub const Pos = struct {
2021-10-21 23:48:53 -07:00
x : usize ,
y : usize ,
2021-07-23 13:56:28 -07:00
} ;
/// Retrieves the position of the content area of the specified window.
///
/// This function retrieves the position, in screen coordinates, of the upper-left corner of the
// content area of the specified window.
///
/// Possible errors include glfw.Error.NotInitialized and glfw.Error.PlatformError.
///
/// wayland: There is no way for an application to retrieve the global position of its windows,
/// this function will always emit glfw.Error.PlatformError.
///
/// @thread_safety This function must only be called from the main thread.
///
/// see also: window_pos glfw.Window.setPos
2021-11-21 20:15:16 +01:00
pub inline fn getPos ( self : Window ) error { PlatformError } ! Pos {
internal_debug . assertInitialized ( ) ;
2021-07-23 13:56:28 -07:00
var x : c_int = 0 ;
var y : c_int = 0 ;
c . glfwGetWindowPos ( self . handle , & x , & y ) ;
2021-11-21 20:15:16 +01:00
getError ( ) catch | err | return switch ( err ) {
Error . PlatformError = > err ,
else = > unreachable ,
} ;
2021-10-21 23:48:53 -07:00
return Pos { . x = @intCast ( usize , x ) , . y = @intCast ( usize , y ) } ;
2021-07-23 13:56:28 -07:00
}
2021-07-23 14:08:42 -07:00
/// Sets the position of the content area of the specified window.
///
/// This function sets the position, in screen coordinates, of the upper-left corner of the content
/// area of the specified windowed mode window. If the window is a full screen window, this
/// function does nothing.
///
/// __Do not use this function__ to move an already visible window unless you have very good
/// reasons for doing so, as it will confuse and annoy the user.
///
/// The window manager may put limits on what positions are allowed. GLFW cannot and should not
/// override these limits.
///
/// Possible errors include glfw.Error.NotInitialized and glfw.Error.PlatformError.
///
/// wayland: There is no way for an application to set the global position of its windows, this
/// function will always emit glfw.Error.PlatformError.
///
/// @thread_safety This function must only be called from the main thread.
///
/// see also: window_pos, glfw.Window.getPos
2021-11-21 20:15:16 +01:00
pub inline fn setPos ( self : Window , pos : Pos ) error { PlatformError } ! void {
internal_debug . assertInitialized ( ) ;
2021-07-23 14:08:42 -07:00
c . glfwSetWindowPos ( self . handle , @intCast ( c_int , pos . x ) , @intCast ( c_int , pos . y ) ) ;
2021-11-21 20:15:16 +01:00
getError ( ) catch | err | return switch ( err ) {
Error . PlatformError = > err ,
else = > unreachable ,
} ;
2021-07-23 14:08:42 -07:00
}
2021-11-11 14:54:55 +01:00
pub const Size = struct {
2021-07-23 14:18:34 -07:00
width : usize ,
height : usize ,
} ;
/// Retrieves the size of the content area of the specified window.
///
/// This function retrieves the size, in screen coordinates, of the content area of the specified
/// window. If you wish to retrieve the size of the framebuffer of the window in pixels, see
/// glfw.Window.getFramebufferSize.
///
/// Possible errors include glfw.Error.NotInitialized and glfw.Error.PlatformError.
///
/// @thread_safety This function must only be called from the main thread.
///
/// see also: window_size, glfw.Window.setSize
2021-11-21 20:15:16 +01:00
pub inline fn getSize ( self : Window ) error { PlatformError } ! Size {
internal_debug . assertInitialized ( ) ;
2021-07-23 14:18:34 -07:00
var width : c_int = 0 ;
var height : c_int = 0 ;
c . glfwGetWindowSize ( self . handle , & width , & height ) ;
2021-11-21 20:15:16 +01:00
getError ( ) catch | err | return switch ( err ) {
Error . PlatformError = > err ,
else = > unreachable ,
} ;
2021-07-23 14:18:34 -07:00
return Size { . width = @intCast ( usize , width ) , . height = @intCast ( usize , height ) } ;
}
2021-07-23 15:02:13 -07:00
/// Sets the size of the content area of the specified window.
///
/// This function sets the size, in screen coordinates, of the content area of the specified window.
///
/// For full screen windows, this function updates the resolution of its desired video mode and
/// switches to the video mode closest to it, without affecting the window's context. As the
/// context is unaffected, the bit depths of the framebuffer remain unchanged.
///
/// If you wish to update the refresh rate of the desired video mode in addition to its resolution,
/// see glfw.Window.setMonitor.
///
/// The window manager may put limits on what sizes are allowed. GLFW cannot and should not
/// override these limits.
///
/// Possible errors include glfw.Error.NotInitialized and glfw.Error.PlatformError.
///
/// wayland: A full screen window will not attempt to change the mode, no matter what the requested
/// size.
///
/// @thread_safety This function must only be called from the main thread.
///
/// see also: window_size, glfw.Window.getSize, glfw.Window.SetMonitor
2021-11-21 20:15:16 +01:00
pub inline fn setSize ( self : Window , size : Size ) error { PlatformError } ! void {
internal_debug . assertInitialized ( ) ;
2021-07-23 15:02:13 -07:00
c . glfwSetWindowSize ( self . handle , @intCast ( c_int , size . width ) , @intCast ( c_int , size . height ) ) ;
2021-11-21 20:15:16 +01:00
getError ( ) catch | err | return switch ( err ) {
Error . PlatformError = > err ,
else = > unreachable ,
} ;
2021-07-23 15:02:13 -07:00
}
2021-07-23 14:29:14 -07:00
/// Sets the size limits of the specified window's content area.
///
/// This function sets the size limits of the content area of the specified window. If the window
/// is full screen, the size limits only take effect/ once it is made windowed. If the window is not
/// resizable, this function does nothing.
///
/// The size limits are applied immediately to a windowed mode window and may cause it to be resized.
///
/// The maximum dimensions must be greater than or equal to the minimum dimensions. glfw.dont_care
/// may be used for any width/height parameter.
///
/// Possible errors include glfw.Error.NotInitialized, glfw.Error.InvalidValue and glfw.Error.PlatformError.
///
/// If you set size limits and an aspect ratio that conflict, the results are undefined.
///
/// wayland: The size limits will not be applied until the window is actually resized, either by
/// the user or by the compositor.
///
/// @thread_safety This function must only be called from the main thread.
///
/// see also: window_sizelimits, glfw.Window.setAspectRatio
2021-11-21 20:15:16 +01:00
pub inline fn setSizeLimits ( self : Window , min : Size , max : Size ) error { InvalidValue , PlatformError } ! void {
internal_debug . assertInitialized ( ) ;
2021-07-23 14:29:14 -07:00
c . glfwSetWindowSizeLimits (
self . handle ,
@intCast ( c_int , min . width ) ,
@intCast ( c_int , min . height ) ,
@intCast ( c_int , max . width ) ,
@intCast ( c_int , max . height ) ,
) ;
2021-11-21 20:15:16 +01:00
getError ( ) catch | err | return switch ( err ) {
Error . InvalidValue ,
Error . PlatformError ,
= > err ,
else = > unreachable ,
} ;
2021-07-23 14:29:14 -07:00
}
2021-07-23 14:43:04 -07:00
/// Sets the aspect ratio of the specified window.
///
/// This function sets the required aspect ratio of the content area of the specified window. If
/// the window is full screen, the aspect ratio only takes effect once it is made windowed. If the
/// window is not resizable, this function does nothing.
///
/// The aspect ratio is specified as a numerator and a denominator and both values must be greater
/// than zero. For example, the common 16:9 aspect ratio is specified as 16 and 9, respectively.
///
/// If the numerator AND denominator is set to `glfw.dont_care` then the aspect ratio limit is
/// disabled.
///
/// The aspect ratio is applied immediately to a windowed mode window and may cause it to be
/// resized.
///
/// Possible errors include glfw.Error.NotInitialized, glfw.Error.InvalidValue and
/// glfw.Error.PlatformError.
///
/// If you set size limits and an aspect ratio that conflict, the results are undefined.
///
/// wayland: The aspect ratio will not be applied until the window is actually resized, either by
/// the user or by the compositor.
///
/// @thread_safety This function must only be called from the main thread.
///
/// see also: window_sizelimits, glfw.Window.setSizeLimits
2021-11-21 20:15:16 +01:00
pub inline fn setAspectRatio ( self : Window , numerator : usize , denominator : usize ) error { InvalidValue , PlatformError } ! void {
internal_debug . assertInitialized ( ) ;
2021-07-23 14:43:04 -07:00
c . glfwSetWindowAspectRatio ( self . handle , @intCast ( c_int , numerator ) , @intCast ( c_int , denominator ) ) ;
2021-11-21 20:15:16 +01:00
getError ( ) catch | err | return switch ( err ) {
Error . InvalidValue ,
Error . PlatformError ,
= > err ,
else = > unreachable ,
} ;
2021-07-23 14:43:04 -07:00
}
2021-07-23 17:35:33 -07:00
/// Retrieves the size of the framebuffer of the specified window.
///
/// This function retrieves the size, in pixels, of the framebuffer of the specified window. If you
/// wish to retrieve the size of the window in screen coordinates, see @ref glfwGetWindowSize.
///
/// Possible errors include glfw.Error.NotInitialized and glfw.Error.PlatformError.
///
/// @thread_safety This function must only be called from the main thread.
///
/// see also: window_fbsize, glfwWindow.setFramebufferSizeCallback
2021-11-21 20:15:16 +01:00
pub inline fn getFramebufferSize ( self : Window ) error { PlatformError } ! Size {
internal_debug . assertInitialized ( ) ;
2021-07-23 17:35:33 -07:00
var width : c_int = 0 ;
var height : c_int = 0 ;
c . glfwGetFramebufferSize ( self . handle , & width , & height ) ;
2021-11-21 20:15:16 +01:00
getError ( ) catch | err | return switch ( err ) {
Error . PlatformError = > err ,
else = > unreachable ,
} ;
2021-07-23 17:35:33 -07:00
return Size { . width = @intCast ( usize , width ) , . height = @intCast ( usize , height ) } ;
}
2021-11-11 14:54:55 +01:00
pub const FrameSize = struct {
2021-07-23 17:43:24 -07:00
left : usize ,
top : usize ,
right : usize ,
bottom : usize ,
} ;
/// Retrieves the size of the frame of the window.
///
/// This function retrieves the size, in screen coordinates, of each edge of the frame of the
/// specified window. This size includes the title bar, if the window has one. The size of the
/// frame may vary depending on the window-related hints used to create it.
///
/// Because this function retrieves the size of each window frame edge and not the offset along a
/// particular coordinate axis, the retrieved values will always be zero or positive.
///
/// Possible errors include glfw.Error.NotInitialized and glfw.Error.PlatformError.
///
/// @thread_safety This function must only be called from the main thread.
///
/// see also: window_size
2021-11-21 20:15:16 +01:00
pub inline fn getFrameSize ( self : Window ) error { PlatformError } ! FrameSize {
internal_debug . assertInitialized ( ) ;
2021-07-23 17:43:24 -07:00
var left : c_int = 0 ;
var top : c_int = 0 ;
var right : c_int = 0 ;
var bottom : c_int = 0 ;
c . glfwGetWindowFrameSize ( self . handle , & left , & top , & right , & bottom ) ;
2021-11-21 20:15:16 +01:00
getError ( ) catch | err | return switch ( err ) {
Error . PlatformError = > err ,
else = > unreachable ,
} ;
2021-07-23 17:43:24 -07:00
return FrameSize {
. left = @intCast ( usize , left ) ,
. top = @intCast ( usize , top ) ,
. right = @intCast ( usize , right ) ,
. bottom = @intCast ( usize , bottom ) ,
} ;
}
2021-07-25 19:34:09 -07:00
pub const ContentScale = struct {
x_scale : f32 ,
y_scale : f32 ,
} ;
/// Retrieves the content scale for the specified window.
///
/// This function retrieves the content scale for the specified window. The content scale is the
/// ratio between the current DPI and the platform's default DPI. This is especially important for
/// text and any UI elements. If the pixel dimensions of your UI scaled by this look appropriate on
/// your machine then it should appear at a reasonable size on other machines regardless of their
/// DPI and scaling settings. This relies on the system DPI and scaling settings being somewhat
/// correct.
///
/// On systems where each monitors can have its own content scale, the window content scale will
/// depend on which monitor the system considers the window to be on.
///
/// Possible errors include glfw.Error.NotInitialized and glfw.Error.PlatformError.
///
/// @thread_safety This function must only be called from the main thread.
///
/// see also: window_scale, glfwSetWindowContentScaleCallback, glfwGetMonitorContentScale
2021-11-21 20:15:16 +01:00
pub inline fn getContentScale ( self : Window ) error { PlatformError } ! ContentScale {
internal_debug . assertInitialized ( ) ;
2021-07-25 19:34:09 -07:00
var x_scale : f32 = 0 ;
var y_scale : f32 = 0 ;
c . glfwGetWindowContentScale ( self . handle , & x_scale , & y_scale ) ;
2021-11-21 20:15:16 +01:00
getError ( ) catch | err | return switch ( err ) {
Error . PlatformError = > err ,
else = > unreachable ,
} ;
2021-07-25 19:34:09 -07:00
return ContentScale { . x_scale = x_scale , . y_scale = y_scale } ;
}
2021-07-25 19:36:41 -07:00
/// Returns the opacity of the whole window.
///
/// This function returns the opacity of the window, including any decorations.
///
/// The opacity (or alpha) value is a positive finite number between zero and one, where zero is
/// fully transparent and one is fully opaque. If the system does not support whole window
/// transparency, this function always returns one.
///
/// The initial opacity value for newly created windows is one.
///
/// Possible errors include glfw.Error.NotInitialized and glfw.Error.PlatformError.
///
/// @thread_safety This function must only be called from the main thread.
///
/// see also: window_transparency, glfw.Window.setOpacity
2021-11-21 20:15:16 +01:00
pub inline fn getOpacity ( self : Window ) error { PlatformError } ! f32 {
internal_debug . assertInitialized ( ) ;
2021-07-25 19:36:41 -07:00
const opacity = c . glfwGetWindowOpacity ( self . handle ) ;
2021-11-21 20:15:16 +01:00
getError ( ) catch | err | return switch ( err ) {
Error . PlatformError = > err ,
else = > unreachable ,
} ;
2021-07-25 19:36:41 -07:00
return opacity ;
}
2021-07-25 19:38:06 -07:00
/// Sets the opacity of the whole window.
///
/// This function sets the opacity of the window, including any decorations.
///
/// The opacity (or alpha) value is a positive finite number between zero and one, where zero is
/// fully transparent and one is fully opaque.
///
/// The initial opacity value for newly created windows is one.
///
/// A window created with framebuffer transparency may not use whole window transparency. The
/// results of doing this are undefined.
///
/// Possible errors include glfw.Error.NotInitialized and glfw.Error.PlatformError.
///
/// @thread_safety This function must only be called from the main thread.
///
/// see also: window_transparency, glfw.Window.getOpacity
2021-11-21 20:15:16 +01:00
pub inline fn setOpacity ( self : Window , opacity : f32 ) error { PlatformError } ! void {
internal_debug . assertInitialized ( ) ;
2021-07-25 19:38:06 -07:00
c . glfwSetWindowOpacity ( self . handle , opacity ) ;
2021-11-21 20:15:16 +01:00
getError ( ) catch | err | return switch ( err ) {
Error . PlatformError = > err ,
else = > unreachable ,
} ;
2021-07-25 19:38:06 -07:00
}
2021-07-25 19:44:04 -07:00
/// Iconifies the specified window.
///
/// This function iconifies (minimizes) the specified window if it was previously restored. If the
/// window is already iconified, this function does nothing.
///
/// If the specified window is a full screen window, the original monitor resolution is restored
/// until the window is restored.
///
/// Possible errors include glfw.Error.NotInitialized and glfw.Error.PlatformError.
///
/// wayland: There is no concept of iconification in wl_shell, this function will emit
/// glfw.Error.PlatformError when using this deprecated protocol.
///
/// @thread_safety This function must only be called from the main thread.
///
/// see also: window_iconify, glfw.Window.restore, glfw.Window.maximize
2021-11-21 20:15:16 +01:00
pub inline fn iconify ( self : Window ) error { PlatformError } ! void {
internal_debug . assertInitialized ( ) ;
2021-07-25 19:44:04 -07:00
c . glfwIconifyWindow ( self . handle ) ;
2021-11-21 20:15:16 +01:00
getError ( ) catch | err | return switch ( err ) {
Error . PlatformError = > err ,
else = > unreachable ,
} ;
2021-07-25 19:44:04 -07:00
}
2021-10-16 14:00:37 -07:00
/// Restores the specified window.
///
/// This function restores the specified window if it was previously iconified (minimized) or
/// maximized. If the window is already restored, this function does nothing.
///
/// If the specified window is a full screen window, the resolution chosen for the window is
/// restored on the selected monitor.
///
/// Possible errors include glfw.Error.NotInitialized and glfw.Error.PlatformError.
///
/// @thread_safety This function must only be called from the main thread.
///
/// see also: window_iconify, glfw.Window.iconify, glfw.Window.maximize
2021-11-21 20:15:16 +01:00
pub inline fn restore ( self : Window ) error { PlatformError } ! void {
internal_debug . assertInitialized ( ) ;
2021-10-16 14:00:37 -07:00
c . glfwRestoreWindow ( self . handle ) ;
2021-11-21 20:15:16 +01:00
getError ( ) catch | err | return switch ( err ) {
Error . PlatformError = > err ,
else = > unreachable ,
} ;
2021-10-16 14:00:37 -07:00
}
2021-10-16 14:05:54 -07:00
/// Maximizes the specified window.
///
/// This function maximizes the specified window if it was previously not maximized. If the window
/// is already maximized, this function does nothing.
///
/// If the specified window is a full screen window, this function does nothing.
///
/// Possible errors include glfw.Error.NotInitialized and glfw.Error.PlatformError.
///
/// @thread_safety This function must only be called from the main thread.
///
/// see also: window_iconify, glfw.Window.iconify, glfw.Window.restore
2021-11-21 20:15:16 +01:00
pub inline fn maximize ( self : Window ) error { PlatformError } ! void {
internal_debug . assertInitialized ( ) ;
2021-10-16 14:05:54 -07:00
c . glfwMaximizeWindow ( self . handle ) ;
2021-11-21 20:15:16 +01:00
getError ( ) catch | err | return switch ( err ) {
Error . PlatformError = > err ,
else = > unreachable ,
} ;
2021-10-16 14:05:54 -07:00
}
2021-10-16 14:09:06 -07:00
/// Makes the specified window visible.
///
/// This function makes the specified window visible if it was previously hidden. If the window is
/// already visible or is in full screen mode, this function does nothing.
///
/// By default, windowed mode windows are focused when shown Set the glfw.focus_on_show window hint
/// to change this behavior for all newly created windows, or change the
/// behavior for an existing window with glfw.Window.setAttrib.
///
/// Possible errors include glfw.Error.NotInitialized and glfw.Error.PlatformError.
///
/// @thread_safety This function must only be called from the main thread.
///
/// see also: window_hide, glfw.Window.hide
2021-11-21 20:15:16 +01:00
pub inline fn show ( self : Window ) error { PlatformError } ! void {
internal_debug . assertInitialized ( ) ;
2021-10-16 14:09:06 -07:00
c . glfwShowWindow ( self . handle ) ;
2021-11-21 20:15:16 +01:00
getError ( ) catch | err | return switch ( err ) {
Error . PlatformError = > err ,
else = > unreachable ,
} ;
2021-10-16 14:09:06 -07:00
}
2021-10-16 14:12:13 -07:00
/// Hides the specified window.
///
/// This function hides the specified window if it was previously visible. If the window is already
/// hidden or is in full screen mode, this function does nothing.
///
/// Possible errors include glfw.Error.NotInitialized and glfw.Error.PlatformError.
///
/// @thread_safety This function must only be called from the main thread.
///
/// see also: window_hide, glfw.Window.show
2021-11-21 20:15:16 +01:00
pub inline fn hide ( self : Window ) error { PlatformError } ! void {
internal_debug . assertInitialized ( ) ;
2021-10-16 14:12:13 -07:00
c . glfwHideWindow ( self . handle ) ;
2021-11-21 20:15:16 +01:00
getError ( ) catch | err | return switch ( err ) {
Error . PlatformError = > err ,
else = > unreachable ,
} ;
2021-10-16 14:12:13 -07:00
}
2021-10-16 14:16:11 -07:00
/// Brings the specified window to front and sets input focus.
///
/// This function brings the specified window to front and sets input focus. The window should
/// already be visible and not iconified.
///
/// By default, both windowed and full screen mode windows are focused when initially created. Set
/// the glfw.focused to disable this behavior.
///
/// Also by default, windowed mode windows are focused when shown with glfw.Window.show. Set the
/// glfw.focus_on_show to disable this behavior.
///
/// __Do not use this function__ to steal focus from other applications unless you are certain that
/// is what the user wants. Focus stealing can be extremely disruptive.
///
/// For a less disruptive way of getting the user's attention, see [attention requests (window_attention).
///
/// Possible errors include glfw.Error.NotInitialized and glfw.Error.PlatformError.
///
/// wayland: It is not possible for an application to bring its windows
/// to front, this function will always emit glfw.Error.PlatformError.
///
/// @thread_safety This function must only be called from the main thread.
///
/// see also: window_focus, window_attention
2021-11-21 20:15:16 +01:00
pub inline fn focus ( self : Window ) error { PlatformError } ! void {
internal_debug . assertInitialized ( ) ;
2021-10-16 14:16:11 -07:00
c . glfwFocusWindow ( self . handle ) ;
2021-11-21 20:15:16 +01:00
getError ( ) catch | err | return switch ( err ) {
Error . PlatformError = > err ,
else = > unreachable ,
} ;
2021-10-16 14:16:11 -07:00
}
2021-10-16 14:22:51 -07:00
/// Requests user attention to the specified window.
///
/// This function requests user attention to the specified window. On platforms where this is not
/// supported, attention is requested to the application as a whole.
///
/// Once the user has given attention, usually by focusing the window or application, the system will end the request automatically.
///
/// Possible errors include glfw.Error.NotInitialized and glfw.Error.PlatformError.
///
/// macos: Attention is requested to the application as a whole, not the
/// specific window.
///
/// @thread_safety This function must only be called from the main thread.
///
/// see also: window_attention
2021-11-21 20:15:16 +01:00
pub inline fn requestAttention ( self : Window ) error { PlatformError } ! void {
internal_debug . assertInitialized ( ) ;
2021-10-16 14:22:51 -07:00
c . glfwRequestWindowAttention ( self . handle ) ;
2021-11-21 20:15:16 +01:00
getError ( ) catch | err | return switch ( err ) {
Error . PlatformError = > err ,
else = > unreachable ,
} ;
2021-10-16 14:22:51 -07:00
}
2021-10-16 18:05:29 -07:00
/// Swaps the front and back buffers of the specified window.
///
/// This function swaps the front and back buffers of the specified window when rendering with
/// OpenGL or OpenGL ES. If the swap interval is greater than zero, the GPU driver waits the
/// specified number of screen updates before swapping the buffers.
///
/// The specified window must have an OpenGL or OpenGL ES context. Specifying a window without a
/// context will generate Error.NoWindowContext.
///
/// This function does not apply to Vulkan. If you are rendering with Vulkan, see `vkQueuePresentKHR`
/// instead.
///
/// @param[in] window The window whose buffers to swap.
///
/// Possible errors include glfw.Error.NotInitialized, glfw.Error.NoWindowContext and glfw.Error.PlatformError.
///
/// __EGL:__ The context of the specified window must be current on the calling thread.
///
/// @thread_safety This function may be called from any thread.
///
/// see also: buffer_swap, glfwSwapInterval
2021-11-21 20:15:16 +01:00
pub inline fn swapBuffers ( self : Window ) error { NoWindowContext , PlatformError } ! void {
internal_debug . assertInitialized ( ) ;
2021-10-16 18:05:29 -07:00
c . glfwSwapBuffers ( self . handle ) ;
2021-11-21 20:15:16 +01:00
getError ( ) catch | err | return switch ( err ) {
Error . NoWindowContext ,
Error . PlatformError ,
= > err ,
else = > unreachable ,
} ;
2021-10-16 18:05:29 -07:00
}
2021-10-16 14:47:55 -07:00
2021-10-18 01:03:11 -07:00
/// Returns the monitor that the window uses for full screen mode.
///
/// This function returns the handle of the monitor that the specified window is in full screen on.
///
/// @return The monitor, or null if the window is in windowed mode.
///
/// Possible errors include glfw.Error.NotInitialized.
///
/// @thread_safety This function must only be called from the main thread.
///
/// see also: window_monitor, glfw.Window.setMonitor
2021-11-21 20:15:16 +01:00
// TODO: Remove error stub
pub inline fn getMonitor ( self : Window ) error { } ! ? Monitor {
internal_debug . assertInitialized ( ) ;
2021-10-18 01:03:11 -07:00
const monitor = c . glfwGetWindowMonitor ( self . handle ) ;
2021-11-21 20:15:16 +01:00
getError ( ) catch unreachable ; // Only error 'GLFW_NOT_INITIALIZED' is impossible
2021-10-18 01:03:11 -07:00
if ( monitor ) | m | return Monitor { . handle = m } ;
return null ;
}
2021-10-16 14:47:55 -07:00
2021-10-17 22:42:16 -07:00
/// Sets the mode, monitor, video mode and placement of a window.
///
/// This function sets the monitor that the window uses for full screen mode or, if the monitor is
/// null, makes it windowed mode.
///
/// When setting a monitor, this function updates the width, height and refresh rate of the desired
/// video mode and switches to the video mode closest to it. The window position is ignored when
/// setting a monitor.
///
/// When the monitor is null, the position, width and height are used to place the window content
/// area. The refresh rate is ignored when no monitor is specified.
///
/// If you only wish to update the resolution of a full screen window or the size of a windowed
/// mode window, see @ref glfwSetWindowSize.
///
/// When a window transitions from full screen to windowed mode, this function restores any
/// previous window settings such as whether it is decorated, floating, resizable, has size or
/// aspect ratio limits, etc.
///
/// @param[in] window The window whose monitor, size or video mode to set.
/// @param[in] monitor The desired monitor, or null to set windowed mode.
/// @param[in] xpos The desired x-coordinate of the upper-left corner of the content area.
/// @param[in] ypos The desired y-coordinate of the upper-left corner of the content area.
/// @param[in] width The desired with, in screen coordinates, of the content area or video mode.
/// @param[in] height The desired height, in screen coordinates, of the content area or video mode.
/// @param[in] refreshRate The desired refresh rate, in Hz, of the video mode, or `glfw.dont_care`.
///
/// Possible errors include glfw.Error.NotInitialized and glfw.Error.PlatformError.
///
/// The OpenGL or OpenGL ES context will not be destroyed or otherwise affected by any resizing or
/// mode switching, although you may need to update your viewport if the framebuffer size has
/// changed.
///
/// wayland: The desired window position is ignored, as there is no way for an application to set
/// this property.
///
/// wayland: Setting the window to full screen will not attempt to change the mode, no matter what
/// the requested size or refresh rate.
///
/// @thread_safety This function must only be called from the main thread.
///
/// see also: window_monitor, window_full_screen, glfw.Window.getMonitor, glfw.Window.setSize
2021-11-21 20:15:16 +01:00
pub inline fn setMonitor ( self : Window , monitor : ? Monitor , xpos : isize , ypos : isize , width : isize , height : isize , refresh_rate : isize ) error { PlatformError } ! void {
internal_debug . assertInitialized ( ) ;
2021-10-17 22:42:16 -07:00
c . glfwSetWindowMonitor (
self . handle ,
if ( monitor ) | m | m . handle else null ,
@intCast ( c_int , xpos ) ,
@intCast ( c_int , ypos ) ,
@intCast ( c_int , width ) ,
@intCast ( c_int , height ) ,
@intCast ( c_int , refresh_rate ) ,
) ;
2021-11-21 20:15:16 +01:00
getError ( ) catch | err | return switch ( err ) {
Error . PlatformError = > err ,
else = > unreachable ,
} ;
2021-10-17 22:42:16 -07:00
}
2021-10-30 14:38:56 -07:00
/// Window attributes
pub const Attrib = enum ( c_int ) {
iconified = c . GLFW_ICONIFIED ,
resizable = c . GLFW_RESIZABLE ,
visible = c . GLFW_VISIBLE ,
decorated = c . GLFW_DECORATED ,
2021-11-17 12:20:56 +01:00
focused = c . GLFW_FOCUSED ,
2021-10-30 14:38:56 -07:00
auto_iconify = c . GLFW_AUTO_ICONIFY ,
floating = c . GLFW_FLOATING ,
maximized = c . GLFW_MAXIMIZED ,
transparent_framebuffer = c . GLFW_TRANSPARENT_FRAMEBUFFER ,
hovered = c . GLFW_HOVERED ,
focus_on_show = c . GLFW_FOCUS_ON_SHOW ,
client_api = c . GLFW_CLIENT_API ,
2021-11-17 14:03:41 +01:00
context_creation_api = c . GLFW_CONTEXT_CREATION_API ,
2021-10-30 14:38:56 -07:00
context_version_major = c . GLFW_CONTEXT_VERSION_MAJOR ,
context_version_minor = c . GLFW_CONTEXT_VERSION_MINOR ,
context_revision = c . GLFW_CONTEXT_REVISION ,
2021-11-17 14:03:41 +01:00
2021-10-30 14:38:56 -07:00
context_robustness = c . GLFW_CONTEXT_ROBUSTNESS ,
2021-11-17 14:03:41 +01:00
context_release_behavior = c . GLFW_CONTEXT_RELEASE_BEHAVIOR ,
context_no_error = c . GLFW_CONTEXT_NO_ERROR ,
2021-10-30 14:38:56 -07:00
opengl_forward_compat = c . GLFW_OPENGL_FORWARD_COMPAT ,
opengl_debug_context = c . GLFW_OPENGL_DEBUG_CONTEXT ,
opengl_profile = c . GLFW_OPENGL_PROFILE ,
} ;
2021-10-17 22:48:41 -07:00
/// Returns an attribute of the specified window.
///
/// This function returns the value of an attribute of the specified window or its OpenGL or OpenGL
/// ES context.
///
/// @param[in] attrib The window attribute (see window_attribs) whose value to return.
/// @return The value of the attribute, or zero if an error occurred.
///
/// Possible errors include glfw.Error.NotInitialized, glfw.Error.InvalidEnum and glfw.Error.PlatformError.
///
/// Framebuffer related hints are not window attributes. See window_attribs_fb for more information.
///
/// Zero is a valid value for many window and context related attributes so you cannot use a return
/// value of zero as an indication of errors. However, this function should not fail as long as it
/// is passed valid arguments and the library has been initialized.
///
/// @thread_safety This function must only be called from the main thread.
///
/// see also: window_attribs, glfw.Window.setAttrib
2021-11-21 20:15:16 +01:00
pub inline fn getAttrib ( self : Window , attrib : Attrib ) error { InvalidEnum , PlatformError } ! isize {
internal_debug . assertInitialized ( ) ;
2021-10-30 14:38:56 -07:00
const v = c . glfwGetWindowAttrib ( self . handle , @enumToInt ( attrib ) ) ;
2021-11-21 20:15:16 +01:00
getError ( ) catch | err | return switch ( err ) {
Error . InvalidEnum ,
Error . PlatformError ,
= > err ,
else = > unreachable ,
} ;
2021-10-17 22:48:41 -07:00
return v ;
}
2021-10-16 14:47:55 -07:00
2021-10-17 22:52:51 -07:00
/// Sets an attribute of the specified window.
///
/// This function sets the value of an attribute of the specified window.
///
/// The supported attributes are glfw.decorated, glfw.resizable, glfw.floating, glfw.auto_iconify,
/// glfw.focus_on_show.
///
/// Some of these attributes are ignored for full screen windows. The new value will take effect
/// if the window is later made windowed.
///
/// Some of these attributes are ignored for windowed mode windows. The new value will take effect
/// if the window is later made full screen.
///
/// @param[in] attrib A supported window attribute.
///
/// Possible errors include glfw.Error.NotInitialized, glfw.Error.InvalidEnum, glfw.Error.InvalidValue and glfw.Error.PlatformError.
///
/// Calling glfw.Window.getAttrib will always return the latest
/// value, even if that value is ignored by the current mode of the window.
///
/// @thread_safety This function must only be called from the main thread.
///
/// see also: window_attribs, glfw.Window.getAttrib
///
2021-11-21 20:15:16 +01:00
// TODO: Maybe enhance type-safety here to avoid 'InvalidEnum' and 'InvalidValue' at runtime alltogether?
pub inline fn setAttrib ( self : Window , attrib : Attrib , value : bool ) error { InvalidEnum , InvalidValue , PlatformError } ! void {
internal_debug . assertInitialized ( ) ;
2021-10-30 14:38:56 -07:00
c . glfwSetWindowAttrib ( self . handle , @enumToInt ( attrib ) , if ( value ) c . GLFW_TRUE else c . GLFW_FALSE ) ;
2021-11-21 20:15:16 +01:00
getError ( ) catch | err | return switch ( err ) {
Error . InvalidEnum ,
Error . InvalidValue ,
Error . PlatformError ,
= > err ,
else = > unreachable ,
} ;
2021-10-17 22:52:51 -07:00
}
2021-10-16 14:47:55 -07:00
2021-10-18 00:02:57 -07:00
pub inline fn getInternal ( self : Window ) * InternalUserPointer {
2021-11-21 20:15:16 +01:00
internal_debug . assertInitialized ( ) ;
2021-10-18 00:02:57 -07:00
const ptr = c . glfwGetWindowUserPointer ( self . handle ) ;
if ( ptr ) | p | return @ptrCast ( * InternalUserPointer , @alignCast ( @alignOf ( * InternalUserPointer ) , p ) ) ;
@panic ( " expected GLFW window user pointer to be *glfw.Window.InternalUserPointer, found null " ) ;
}
2021-10-17 23:04:43 -07:00
/// Sets the user pointer of the specified window.
///
/// This function sets the user-defined pointer of the specified window. The current value is
/// retained until the window is destroyed. The initial value is null.
///
/// @thread_safety This function may be called from any thread. Access is not synchronized.
///
/// see also: window_userptr, glfw.Window.getUserPointer
2021-11-21 20:15:16 +01:00
// TODO: Review this function signature
2021-10-17 23:04:43 -07:00
pub inline fn setUserPointer ( self : Window , Type : anytype , pointer : Type ) void {
2021-11-21 20:15:16 +01:00
internal_debug . assertInitialized ( ) ;
2021-10-18 00:02:57 -07:00
var internal = self . getInternal ( ) ;
internal . user_pointer = @ptrCast ( * c_void , pointer ) ;
2021-10-17 23:04:43 -07:00
}
2021-10-17 23:10:51 -07:00
/// Returns the user pointer of the specified window.
///
/// This function returns the current value of the user-defined pointer of the specified window.
/// The initial value is null.
///
/// @thread_safety This function may be called from any thread. Access is not synchronized.
///
/// see also: window_userptr, glfw.Window.setUserPointer
2021-11-21 20:15:16 +01:00
// TODO: Review this function signature
2021-10-17 23:10:51 -07:00
pub inline fn getUserPointer ( self : Window , Type : anytype ) ? Type {
2021-11-21 20:15:16 +01:00
internal_debug . assertInitialized ( ) ;
2021-10-18 00:02:57 -07:00
var internal = self . getInternal ( ) ;
if ( internal . user_pointer ) | p | return @ptrCast ( Type , @alignCast ( @alignOf ( Type ) , p ) ) ;
2021-10-17 23:10:51 -07:00
return null ;
}
2021-10-16 14:47:55 -07:00
2021-10-18 00:02:57 -07:00
fn setPosCallbackWrapper ( handle : ? * c . GLFWwindow , xpos : c_int , ypos : c_int ) callconv ( . C ) void {
2021-11-21 20:15:16 +01:00
internal_debug . assertInitialized ( ) ;
2021-10-18 00:02:57 -07:00
const window = from ( handle . ? ) catch unreachable ;
const internal = window . getInternal ( ) ;
internal . setPosCallback . ? ( window , @intCast ( isize , xpos ) , @intCast ( isize , ypos ) ) ;
}
2021-10-16 14:47:55 -07:00
2021-10-18 00:02:57 -07:00
/// Sets the position callback for the specified window.
///
/// This function sets the position callback of the specified window, which is called when the
/// window is moved. The callback is provided with the position, in screen coordinates, of the
/// upper-left corner of the content area of the window.
///
/// @param[in] callback The new callback, or null to remove the currently set callback.
///
/// @callback_param `window` the window that moved.
/// @callback_param `xpos` the new x-coordinate, in screen coordinates, of the upper-left corner of
/// the content area of the window.
/// @callback_param `ypos` the new y-coordinate, in screen coordinates, of the upper-left corner of
/// the content area of the window.
///
/// wayland: This callback will never be called, as there is no way for an application to know its
/// global position.
///
/// @thread_safety This function must only be called from the main thread.
///
/// see also: window_pos
pub inline fn setPosCallback ( self : Window , callback : ? fn ( window : Window , xpos : isize , ypos : isize ) void ) void {
2021-11-21 20:15:16 +01:00
internal_debug . assertInitialized ( ) ;
2021-10-18 00:02:57 -07:00
var internal = self . getInternal ( ) ;
internal . setPosCallback = callback ;
_ = c . glfwSetWindowPosCallback ( self . handle , if ( callback ! = null ) setPosCallbackWrapper else null ) ;
2021-11-21 20:15:16 +01:00
getError ( ) catch unreachable ; // Only error 'GLFW_NOT_INITIALIZED' is impossible
2021-10-18 00:02:57 -07:00
}
2021-10-18 00:08:25 -07:00
fn setSizeCallbackWrapper ( handle : ? * c . GLFWwindow , width : c_int , height : c_int ) callconv ( . C ) void {
2021-11-21 20:15:16 +01:00
internal_debug . assertInitialized ( ) ;
2021-10-18 00:08:25 -07:00
const window = from ( handle . ? ) catch unreachable ;
const internal = window . getInternal ( ) ;
internal . setSizeCallback . ? ( window , @intCast ( isize , width ) , @intCast ( isize , height ) ) ;
}
2021-10-16 14:47:55 -07:00
2021-10-18 00:08:25 -07:00
/// Sets the size callback for the specified window.
///
/// This function sets the size callback of the specified window, which is called when the window
/// is resized. The callback is provided with the size, in screen coordinates, of the content area
/// of the window.
///
/// @callback_param `window` the window that was resized.
/// @callback_param `width` the new width, in screen coordinates, of the window.
/// @callback_param `height` the new height, in screen coordinates, of the window.
///
/// @thread_safety This function must only be called from the main thread.
///
/// see also: window_size
pub inline fn setSizeCallback ( self : Window , callback : ? fn ( window : Window , width : isize , height : isize ) void ) void {
2021-11-21 20:15:16 +01:00
internal_debug . assertInitialized ( ) ;
2021-10-18 00:08:25 -07:00
var internal = self . getInternal ( ) ;
internal . setSizeCallback = callback ;
_ = c . glfwSetWindowSizeCallback ( self . handle , if ( callback ! = null ) setSizeCallbackWrapper else null ) ;
2021-11-21 20:15:16 +01:00
getError ( ) catch unreachable ; // Only error 'GLFW_NOT_INITIALIZED' is impossible
2021-10-18 00:08:25 -07:00
}
2021-10-18 00:15:14 -07:00
fn setCloseCallbackWrapper ( handle : ? * c . GLFWwindow ) callconv ( . C ) void {
2021-11-21 20:15:16 +01:00
internal_debug . assertInitialized ( ) ;
2021-10-18 00:15:14 -07:00
const window = from ( handle . ? ) catch unreachable ;
const internal = window . getInternal ( ) ;
internal . setCloseCallback . ? ( window ) ;
}
2021-10-16 14:47:55 -07:00
2021-10-18 00:15:14 -07:00
/// Sets the close callback for the specified window.
///
/// This function sets the close callback of the specified window, which is called when the user
/// attempts to close the window, for example by clicking the close widget in the title bar.
///
/// The close flag is set before this callback is called, but you can modify it at any time with
/// glfw.Window.setShouldClose.
///
/// The close callback is not triggered by glfw.Window.destroy.
///
/// @param[in] window The window whose callback to set.
/// @param[in] callback The new callback, or null to remove the currently set callback.
///
/// @callback_param `window` the window that the user attempted to close.
///
/// macos: Selecting Quit from the application menu will trigger the close callback for all
/// windows.
///
/// @thread_safety This function must only be called from the main thread.
///
/// see also: window_close
pub inline fn setCloseCallback ( self : Window , callback : ? fn ( window : Window ) void ) void {
2021-11-21 20:15:16 +01:00
internal_debug . assertInitialized ( ) ;
2021-10-18 00:15:14 -07:00
var internal = self . getInternal ( ) ;
internal . setCloseCallback = callback ;
_ = c . glfwSetWindowCloseCallback ( self . handle , if ( callback ! = null ) setCloseCallbackWrapper else null ) ;
2021-11-21 20:15:16 +01:00
getError ( ) catch unreachable ; // Only error 'GLFW_NOT_INITIALIZED' is impossible
2021-10-18 00:15:14 -07:00
}
2021-10-18 00:23:33 -07:00
fn setRefreshCallbackWrapper ( handle : ? * c . GLFWwindow ) callconv ( . C ) void {
const window = from ( handle . ? ) catch unreachable ;
const internal = window . getInternal ( ) ;
internal . setRefreshCallback . ? ( window ) ;
}
2021-10-16 14:47:55 -07:00
2021-11-21 20:15:16 +01:00
// TODO: Something's off about this comment?
2021-10-16 14:47:55 -07:00
// /// Sets the refresh callback for the specified window.
// ///
// /// This function sets the refresh callback of the specified window, which is
// /// called when the content area of the window needs to be redrawn, for example
// /// if the window has been exposed after having been covered by another window.
// ///
// /// On compositing window systems such as Aero, Compiz, Aqua or Wayland, where
// /// the window contents are saved off-screen, this callback may be called only
// /// very infrequently or never at all.
// ///
// /// @param[in] window The window whose callback to set.
// /// @param[in] callback The new callback, or null to remove the currently set
// /// callback.
// ///
2021-10-18 00:23:33 -07:00
// /// @callback_param `window` the window whose content needs to be refreshed.
2021-10-16 14:47:55 -07:00
// ///
// /// @thread_safety This function must only be called from the main thread.
// ///
// /// see also: window_refresh
// GLFWAPI GLFWwindowrefreshfun glfwSetWindowRefreshCallback(GLFWwindow* window, GLFWwindowrefreshfun callback);
2021-10-18 00:23:33 -07:00
pub inline fn setRefreshCallback ( self : Window , callback : ? fn ( window : Window ) void ) void {
2021-11-21 20:15:16 +01:00
internal_debug . assertInitialized ( ) ;
2021-10-18 00:23:33 -07:00
var internal = self . getInternal ( ) ;
2021-10-18 00:33:28 -07:00
internal . setRefreshCallback = callback ;
2021-10-18 00:23:33 -07:00
_ = c . glfwSetWindowRefreshCallback ( self . handle , if ( callback ! = null ) setRefreshCallbackWrapper else null ) ;
2021-11-21 20:15:16 +01:00
getError ( ) catch unreachable ; // Only error 'GLFW_NOT_INITIALIZED' is impossible
2021-10-18 00:23:33 -07:00
}
2021-10-18 00:33:28 -07:00
fn setFocusCallbackWrapper ( handle : ? * c . GLFWwindow , focused : c_int ) callconv ( . C ) void {
2021-11-21 20:15:16 +01:00
internal_debug . assertInitialized ( ) ;
2021-10-18 00:33:28 -07:00
const window = from ( handle . ? ) catch unreachable ;
const internal = window . getInternal ( ) ;
internal . setFocusCallback . ? ( window , if ( focused = = c . GLFW_TRUE ) true else false ) ;
}
2021-10-16 14:47:55 -07:00
2021-10-18 00:33:28 -07:00
/// Sets the focus callback for the specified window.
///
/// This function sets the focus callback of the specified window, which is
/// called when the window gains or loses input focus.
///
/// After the focus callback is called for a window that lost input focus,
/// synthetic key and mouse button release events will be generated for all such
/// that had been pressed. For more information, see @ref glfwSetKeyCallback
/// and @ref glfwSetMouseButtonCallback.
///
/// @param[in] window The window whose callback to set.
/// @param[in] callback The new callback, or null to remove the currently set
/// callback.
///
/// @callback_param `window` the window whose input focus has changed.
/// @callback_param `focused` `true` if the window was given input focus, or `false` if it lost it.
///
/// @thread_safety This function must only be called from the main thread.
///
/// see also: window_focus
pub inline fn setFocusCallback ( self : Window , callback : ? fn ( window : Window , focused : bool ) void ) void {
2021-11-21 20:15:16 +01:00
internal_debug . assertInitialized ( ) ;
2021-10-18 00:33:28 -07:00
var internal = self . getInternal ( ) ;
internal . setFocusCallback = callback ;
_ = c . glfwSetWindowFocusCallback ( self . handle , if ( callback ! = null ) setFocusCallbackWrapper else null ) ;
2021-11-21 20:15:16 +01:00
getError ( ) catch unreachable ; // Only error 'GLFW_NOT_INITIALIZED' is impossible
2021-10-18 00:33:28 -07:00
}
2021-10-18 00:39:31 -07:00
fn setIconifyCallbackWrapper ( handle : ? * c . GLFWwindow , iconified : c_int ) callconv ( . C ) void {
2021-11-21 20:15:16 +01:00
internal_debug . assertInitialized ( ) ;
2021-10-18 00:39:31 -07:00
const window = from ( handle . ? ) catch unreachable ;
const internal = window . getInternal ( ) ;
internal . setIconifyCallback . ? ( window , if ( iconified = = c . GLFW_TRUE ) true else false ) ;
}
2021-10-16 14:47:55 -07:00
2021-10-18 00:39:31 -07:00
/// Sets the iconify callback for the specified window.
///
/// This function sets the iconification callback of the specified window, which
/// is called when the window is iconified or restored.
///
/// @param[in] window The window whose callback to set.
/// @param[in] callback The new callback, or null to remove the currently set
/// callback.
///
/// @callback_param `window` the window which was iconified or restored.
/// @callback_param `iconified` `true` if the window was iconified, or `false` if it was restored.
///
/// wayland: The wl_shell protocol has no concept of iconification,
/// this callback will never be called when using this deprecated protocol.
///
/// @thread_safety This function must only be called from the main thread.
///
/// see also: window_iconify
pub inline fn setIconifyCallback ( self : Window , callback : ? fn ( window : Window , iconified : bool ) void ) void {
2021-11-21 20:15:16 +01:00
internal_debug . assertInitialized ( ) ;
2021-10-18 00:39:31 -07:00
var internal = self . getInternal ( ) ;
internal . setIconifyCallback = callback ;
_ = c . glfwSetWindowIconifyCallback ( self . handle , if ( callback ! = null ) setIconifyCallbackWrapper else null ) ;
2021-11-21 20:15:16 +01:00
getError ( ) catch unreachable ; // Only error 'GLFW_NOT_INITIALIZED' is impossible
2021-10-18 00:39:31 -07:00
}
2021-10-18 00:41:45 -07:00
fn setMaximizeCallbackWrapper ( handle : ? * c . GLFWwindow , maximized : c_int ) callconv ( . C ) void {
2021-11-21 20:15:16 +01:00
internal_debug . assertInitialized ( ) ;
2021-10-18 00:41:45 -07:00
const window = from ( handle . ? ) catch unreachable ;
const internal = window . getInternal ( ) ;
internal . setMaximizeCallback . ? ( window , if ( maximized = = c . GLFW_TRUE ) true else false ) ;
}
2021-10-16 14:47:55 -07:00
2021-10-18 00:41:45 -07:00
/// Sets the maximize callback for the specified window.
///
/// This function sets the maximization callback of the specified window, which
/// is called when the window is maximized or restored.
///
/// @param[in] window The window whose callback to set.
/// @param[in] callback The new callback, or null to remove the currently set
/// callback.
///
/// @callback_param `window` the window which was maximized or restored.
/// @callback_param `maximized` `true` if the window was maximized, or `false` if it was restored.
///
/// @thread_safety This function must only be called from the main thread.
///
/// see also: window_maximize
2021-10-16 14:47:55 -07:00
// GLFWAPI GLFWwindowmaximizefun glfwSetWindowMaximizeCallback(GLFWwindow* window, GLFWwindowmaximizefun callback);
2021-10-18 00:41:45 -07:00
pub inline fn setMaximizeCallback ( self : Window , callback : ? fn ( window : Window , maximized : bool ) void ) void {
2021-11-21 20:15:16 +01:00
internal_debug . assertInitialized ( ) ;
2021-10-18 00:41:45 -07:00
var internal = self . getInternal ( ) ;
internal . setMaximizeCallback = callback ;
_ = c . glfwSetWindowMaximizeCallback ( self . handle , if ( callback ! = null ) setMaximizeCallbackWrapper else null ) ;
2021-11-21 20:15:16 +01:00
getError ( ) catch unreachable ; // Only error 'GLFW_NOT_INITIALIZED' is impossible
2021-10-18 00:41:45 -07:00
}
2021-10-18 00:50:28 -07:00
fn setFramebufferSizeCallbackWrapper ( handle : ? * c . GLFWwindow , width : c_int , height : c_int ) callconv ( . C ) void {
2021-11-21 20:15:16 +01:00
internal_debug . assertInitialized ( ) ;
2021-10-18 00:50:28 -07:00
const window = from ( handle . ? ) catch unreachable ;
const internal = window . getInternal ( ) ;
internal . setFramebufferSizeCallback . ? ( window , @intCast ( isize , width ) , @intCast ( isize , height ) ) ;
}
2021-10-16 14:47:55 -07:00
2021-10-18 00:50:28 -07:00
/// Sets the framebuffer resize callback for the specified window.
///
/// This function sets the framebuffer resize callback of the specified window,
/// which is called when the framebuffer of the specified window is resized.
///
/// @param[in] window The window whose callback to set.
/// @param[in] callback The new callback, or null to remove the currently set
/// callback.
///
/// @callback_param `window` the window whose framebuffer was resized.
/// @callback_param `width` the new width, in pixels, of the framebuffer.
/// @callback_param `height` the new height, in pixels, of the framebuffer.
///
/// @thread_safety This function must only be called from the main thread.
///
/// see also: window_fbsize
pub inline fn setFramebufferSizeCallback ( self : Window , callback : ? fn ( window : Window , width : isize , height : isize ) void ) void {
2021-11-21 20:15:16 +01:00
internal_debug . assertInitialized ( ) ;
2021-10-18 00:50:28 -07:00
var internal = self . getInternal ( ) ;
internal . setFramebufferSizeCallback = callback ;
_ = c . glfwSetFramebufferSizeCallback ( self . handle , if ( callback ! = null ) setFramebufferSizeCallbackWrapper else null ) ;
2021-11-21 20:15:16 +01:00
getError ( ) catch unreachable ; // Only error 'GLFW_NOT_INITIALIZED' is impossible
2021-10-18 00:50:28 -07:00
}
2021-10-18 00:58:18 -07:00
fn setContentScaleCallbackWrapper ( handle : ? * c . GLFWwindow , xscale : f32 , yscale : f32 ) callconv ( . C ) void {
2021-11-21 20:15:16 +01:00
internal_debug . assertInitialized ( ) ;
2021-10-18 00:58:18 -07:00
const window = from ( handle . ? ) catch unreachable ;
const internal = window . getInternal ( ) ;
internal . setContentScaleCallback . ? ( window , xscale , yscale ) ;
}
2021-10-16 14:47:55 -07:00
2021-10-18 00:58:18 -07:00
/// Sets the window content scale callback for the specified window.
///
/// This function sets the window content scale callback of the specified window,
/// which is called when the content scale of the specified window changes.
///
/// @param[in] window The window whose callback to set.
/// @param[in] callback The new callback, or null to remove the currently set
/// callback.
///
/// @callback_param `window` the window whose content scale changed.
/// @callback_param `xscale` the new x-axis content scale of the window.
/// @callback_param `yscale` the new y-axis content scale of the window.
///
/// @thread_safety This function must only be called from the main thread.
///
/// see also: window_scale, glfw.Window.getContentScale
pub inline fn setContentScaleCallback ( self : Window , callback : ? fn ( window : Window , xscale : f32 , yscale : f32 ) void ) void {
2021-11-21 20:15:16 +01:00
internal_debug . assertInitialized ( ) ;
2021-10-18 00:58:18 -07:00
var internal = self . getInternal ( ) ;
internal . setContentScaleCallback = callback ;
_ = c . glfwSetWindowContentScaleCallback ( self . handle , if ( callback ! = null ) setContentScaleCallbackWrapper else null ) ;
2021-11-21 20:15:16 +01:00
getError ( ) catch unreachable ; // Only error 'GLFW_NOT_INITIALIZED' is impossible
2021-10-18 00:58:18 -07:00
}
2021-10-16 14:47:55 -07:00
2021-10-30 19:17:09 -07:00
pub const InputMode = enum ( c_int ) {
cursor = c . GLFW_CURSOR ,
sticky_keys = c . GLFW_STICKY_KEYS ,
sticky_mouse_buttons = c . GLFW_STICKY_MOUSE_BUTTONS ,
lock_key_mods = c . GLFW_LOCK_KEY_MODS ,
raw_mouse_motion = c . GLFW_RAW_MOUSE_MOTION ,
} ;
/// A cursor input mode to be supplied to `glfw.Window.setInputModeCursor`
pub const InputModeCursor = enum ( c_int ) {
/// Makes the cursor visible and behaving normally.
normal = c . GLFW_CURSOR_NORMAL ,
/// Makes the cursor invisible when it is over the content area of the window but does not
/// restrict it from leaving.
hidden = c . GLFW_CURSOR_HIDDEN ,
/// Hides and grabs the cursor, providing virtual and unlimited cursor movement. This is useful
/// for implementing for example 3D camera controls.
disabled = c . GLFW_CURSOR_DISABLED ,
} ;
/// Sets the input mode of the cursor, whether it should behave normally, be hidden, or grabbed.
2021-11-21 20:15:16 +01:00
pub inline fn setInputModeCursor ( self : Window , value : InputModeCursor ) error { InvalidEnum , PlatformError } ! void {
2021-10-30 19:26:10 -07:00
return self . setInputMode ( InputMode . cursor , value ) ;
2021-10-30 19:17:09 -07:00
}
2021-10-30 19:26:10 -07:00
/// Gets the current input mode of the cursor.
2021-10-30 19:17:09 -07:00
pub inline fn getInputModeCursor ( self : Window ) InputModeCursor {
2021-10-30 19:26:10 -07:00
return @intToEnum ( InputModeCursor , self . getInputMode ( InputMode . cursor ) ) ;
}
/// Sets the input mode of sticky keys, if enabled a key press will ensure that `glfw.Window.getKey`
2021-10-30 19:30:53 -07:00
/// return `.press` the next time it is called even if the key had been released before the call.
2021-10-30 19:26:10 -07:00
///
/// This is useful when you are only interested in whether keys have been pressed but not when or
/// in which order.
2021-11-21 20:15:16 +01:00
pub inline fn setInputModeStickyKeys ( self : Window , enabled : bool ) error { InvalidEnum , PlatformError } ! void {
2021-10-30 19:26:10 -07:00
return self . setInputMode ( InputMode . sticky_keys , enabled ) ;
}
/// Tells if the sticky keys input mode is enabled.
pub inline fn getInputModeStickyKeys ( self : Window ) bool {
return self . getInputMode ( InputMode . sticky_keys ) = = 1 ;
2021-10-30 19:17:09 -07:00
}
2021-10-30 19:30:53 -07:00
/// Sets the input mode of sticky mouse buttons, if enabled a mouse button press will ensure that
/// `glfw.Window.getMouseButton` return `.press` the next time it is called even if the button had
/// been released before the call.
///
/// This is useful when you are only interested in whether buttons have been pressed but not when
/// or in which order.
2021-11-21 20:15:16 +01:00
pub inline fn setInputModeStickyMouseButtons ( self : Window , enabled : bool ) error { InvalidEnum , PlatformError } ! void {
2021-10-30 19:30:53 -07:00
return self . setInputMode ( InputMode . sticky_mouse_buttons , enabled ) ;
}
/// Tells if the sticky mouse buttons input mode is enabled.
pub inline fn getInputModeStickyMouseButtons ( self : Window ) bool {
return self . getInputMode ( InputMode . sticky_mouse_buttons ) = = 1 ;
}
2021-10-30 19:36:00 -07:00
/// Sets the input mode of locking key modifiers, if enabled callbacks that receive modifier bits
/// will also have the glfw.mod.caps_lock bit set when the event was generated with Caps Lock on,
/// and the glfw.mod.num_lock bit when Num Lock was on.
pub inline fn setInputModeLockKeyMods ( self : Window , enabled : bool ) Error ! void {
return self . setInputMode ( InputMode . lock_key_mods , enabled ) ;
}
2021-10-30 19:45:41 -07:00
/// Tells if the locking key modifiers input mode is enabled.
2021-10-30 19:36:00 -07:00
pub inline fn getInputModeLockKeyMods ( self : Window ) bool {
return self . getInputMode ( InputMode . lock_key_mods ) = = 1 ;
}
2021-10-30 19:45:41 -07:00
/// Sets whether the raw mouse motion input mode is enabled, if enabled unscaled and unaccelerated
/// mouse motion events will be sent, otherwise standard mouse motion events respecting the user's
/// OS settings will be sent.
///
/// If raw motion is not supported, attempting to set this will emit glfw.Error.PlatformError. Call
/// glfw.rawMouseMotionSupported to check for support.
pub inline fn setInputModeRawMouseMotion ( self : Window , enabled : bool ) Error ! void {
return self . setInputMode ( InputMode . raw_mouse_motion , enabled ) ;
}
/// Tells if the raw mouse motion input mode is enabled.
pub inline fn getInputModeRawMouseMotion ( self : Window ) bool {
return self . getInputMode ( InputMode . raw_mouse_motion ) = = 1 ;
}
2021-10-23 13:36:36 -07:00
/// Returns the value of an input option for the specified window.
///
2021-10-30 19:17:09 -07:00
/// Consider using one of the following variants instead, if applicable, as they'll give you a
/// typed return value:
///
/// * `glfw.Window.getInputModeCursor`
2021-10-30 19:26:10 -07:00
/// * `glfw.Window.getInputModeStickyKeys`
2021-10-30 19:30:53 -07:00
/// * `glfw.Window.getInputModeStickyMouseButtons`
2021-10-30 19:36:00 -07:00
/// * `glfw.Window.getInputModeLockKeyMods`
2021-10-30 19:45:41 -07:00
/// * `glfw.Window.getInputModeRawMouseMotion`
2021-10-30 19:17:09 -07:00
///
2021-10-23 13:36:36 -07:00
/// This function returns the value of an input option for the specified window. The mode must be
2021-10-30 19:26:10 -07:00
/// one of the `glfw.Window.InputMode` enumerations.
2021-10-23 13:36:36 -07:00
///
2021-10-30 19:17:09 -07:00
/// Boolean values, such as for `glfw.Window.InputMode.raw_mouse_motion`, are returned as integers.
/// You may convert to a boolean using `== 1`.
2021-10-23 13:36:36 -07:00
///
/// @thread_safety This function must only be called from the main thread.
///
2021-10-30 19:17:09 -07:00
/// see also: glfw.Window.setInputMode
2021-10-30 19:26:10 -07:00
pub inline fn getInputMode ( self : Window , mode : InputMode ) isize {
2021-11-21 20:15:16 +01:00
internal_debug . assertInitialized ( ) ;
2021-10-30 19:26:10 -07:00
const value = c . glfwGetInputMode ( self . handle , @enumToInt ( mode ) ) ;
2021-10-23 13:36:36 -07:00
2021-11-21 20:15:16 +01:00
// Possible errors include glfw.Error.InvalidEnum.
getError ( ) catch @panic ( " unexpected error getting input mode, invalid enum " ) ;
2021-10-23 13:36:36 -07:00
return @intCast ( isize , value ) ;
}
2021-10-21 23:48:53 -07:00
2021-10-23 13:31:58 -07:00
/// Sets an input option for the specified window.
///
2021-10-30 19:17:09 -07:00
/// Consider using one of the following variants instead, if applicable, as they'll guide you to
/// the right input value via enumerations:
2021-10-23 13:31:58 -07:00
///
2021-10-30 19:17:09 -07:00
/// * `glfw.Window.setInputModeCursor`
2021-10-30 19:26:10 -07:00
/// * `glfw.Window.setInputModeStickyKeys`
2021-10-30 19:30:53 -07:00
/// * `glfw.Window.setInputModeStickyMouseButtons`
2021-10-30 19:36:00 -07:00
/// * `glfw.Window.setInputModeLockKeyMods`
2021-10-30 19:45:41 -07:00
/// * `glfw.Window.setInputModeRawMouseMotion`
2021-10-23 13:31:58 -07:00
///
2021-10-30 19:26:10 -07:00
/// @param[in] mode One of the `glfw.Window.InputMode` enumerations.
2021-10-23 13:31:58 -07:00
/// @param[in] value The new value of the specified input mode.
///
/// Possible errors include glfw.Error.NotInitialized, glfw.Error.InvalidEnum and glfw.Error.PlatformError.
///
/// @thread_safety This function must only be called from the main thread.
///
2021-10-30 19:17:09 -07:00
/// see also: glfw.Window.getInputMode
2021-11-21 20:15:16 +01:00
pub inline fn setInputMode ( self : Window , mode : InputMode , value : anytype ) error { InvalidEnum , PlatformError } ! void {
internal_debug . assertInitialized ( ) ;
2021-10-23 13:31:58 -07:00
switch ( @typeInfo ( @TypeOf ( value ) ) ) {
2021-10-30 19:26:10 -07:00
. Enum = > c . glfwSetInputMode ( self . handle , @enumToInt ( mode ) , @enumToInt ( value ) ) ,
. Int , . ComptimeInt = > c . glfwSetInputMode ( self . handle , @enumToInt ( mode ) , @intCast ( c_int , value ) ) ,
. Bool = > c . glfwSetInputMode ( self . handle , @enumToInt ( mode ) , @intCast ( c_int , @boolToInt ( value ) ) ) ,
2021-10-23 13:31:58 -07:00
else = > @compileError ( " expected a int or bool, got " + + @typeName ( @TypeOf ( value ) ) ) ,
}
2021-11-21 20:15:16 +01:00
getError ( ) catch | err | return switch ( err ) {
Error . InvalidEnum ,
Error . PlatformError ,
= > err ,
else = > unreachable ,
} ;
2021-10-23 13:31:58 -07:00
}
2021-10-21 23:48:53 -07:00
2021-10-23 13:13:30 -07:00
/// Returns the last reported press state of a keyboard key for the specified window.
///
/// This function returns the last press state reported for the specified key to the specified
/// window. The returned state is one of `true` (pressed) or `false` (released). The higher-level
2021-10-29 21:22:19 -07:00
/// action `glfw.Action.repeat` is only reported to the key callback.
2021-10-23 13:13:30 -07:00
///
2021-10-29 21:22:19 -07:00
/// If the `glfw.sticky_keys` input mode is enabled, this function returns `glfw.Action.press` the
/// first time you call it for a key that was pressed, even if that key has already been released.
2021-10-23 13:13:30 -07:00
///
/// The key functions deal with physical keys, with key tokens (see keys) named after their use on
/// the standard US keyboard layout. If you want to input text, use the Unicode character callback
/// instead.
///
/// The modifier key bit masks (see mods) are not key tokens and cannot be used with this function.
///
/// __Do not use this function__ to implement text input, use glfw.Window.setCharCallback instead.
///
/// @param[in] window The desired window.
/// @param[in] key The desired keyboard key (see keys). `glfw.key.unknown` is not a valid key for
/// this function.
///
/// Possible errors include glfw.Error.NotInitialized and glfw.Error.InvalidEnum.
///
/// @thread_safety This function must only be called from the main thread.
///
/// see also: input_key
2021-11-21 20:15:16 +01:00
pub inline fn getKey ( self : Window , key : Key ) error { InvalidEnum } ! Action {
internal_debug . assertInitialized ( ) ;
2021-10-24 15:23:20 +02:00
const state = c . glfwGetKey ( self . handle , @enumToInt ( key ) ) ;
2021-11-21 20:15:16 +01:00
getError ( ) catch | err | return switch ( err ) {
Error . InvalidEnum = > err ,
else = > unreachable ,
} ;
2021-10-29 21:22:19 -07:00
return @intToEnum ( Action , state ) ;
2021-10-23 13:13:30 -07:00
}
2021-10-21 23:48:53 -07:00
2021-10-23 13:06:18 -07:00
/// Returns the last reported state of a mouse button for the specified window.
///
/// This function returns whether the specified mouse button is pressed or not.
///
/// If the glfw.sticky_mouse_buttons input mode is enabled, this function returns `true` the first
/// time you call it for a mouse button that was pressed, even if that mouse button has already been
/// released.
///
/// @param[in] button The desired mouse button.
/// @return One of `true` (if pressed) or `false` (if released)
///
/// Possible errors include glfw.Error.NotInitialized and glfw.Error.InvalidEnum.
///
/// @thread_safety This function must only be called from the main thread.
///
/// see also: input_mouse_button
2021-11-21 20:15:16 +01:00
pub inline fn getMouseButton ( self : Window , button : MouseButton ) error { InvalidEnum } ! Action {
internal_debug . assertInitialized ( ) ;
2021-10-30 15:35:04 -07:00
const state = c . glfwGetMouseButton ( self . handle , @enumToInt ( button ) ) ;
2021-11-21 20:15:16 +01:00
getError ( ) catch | err | return switch ( err ) {
Error . InvalidEnum = > err ,
else = > unreachable ,
} ;
2021-10-29 21:22:19 -07:00
return @intToEnum ( Action , state ) ;
2021-10-23 13:06:18 -07:00
}
2021-10-21 23:48:53 -07:00
2021-11-11 14:54:55 +01:00
pub const CursorPos = struct {
2021-10-23 12:45:49 -07:00
xpos : f64 ,
ypos : f64 ,
} ;
/// Retrieves the position of the cursor relative to the content area of the window.
///
/// This function returns the position of the cursor, in screen coordinates, relative to the
/// upper-left corner of the content area of the specified window.
///
/// If the cursor is disabled (with `glfw.cursor_disabled`) then the cursor position is unbounded
/// and limited only by the minimum and maximum values of a `f64`.
///
/// The coordinate can be converted to their integer equivalents with the `floor` function. Casting
/// directly to an integer type works for positive coordinates, but fails for negative ones.
///
/// Any or all of the position arguments may be null. If an error occurs, all non-null position
/// arguments will be set to zero.
///
/// @param[in] window The desired window.
/// @param[out] xpos Where to store the cursor x-coordinate, relative to the left edge of the
/// content area, or null.
/// @param[out] ypos Where to store the cursor y-coordinate, relative to the to top edge of the
/// content area, or null.
///
/// Possible errors include glfw.Error.NotInitialized and glfw.Error.PlatformError.
///
/// @thread_safety This function must only be called from the main thread.
///
/// see also: cursor_pos, glfw.Window.setCursorPos
2021-11-21 20:15:16 +01:00
pub inline fn getCursorPos ( self : Window ) error { PlatformError } ! CursorPos {
internal_debug . assertInitialized ( ) ;
2021-10-23 12:45:49 -07:00
var pos : CursorPos = undefined ;
c . glfwGetCursorPos ( self . handle , & pos . xpos , & pos . ypos ) ;
2021-11-21 20:15:16 +01:00
getError ( ) catch | err | return switch ( err ) {
Error . PlatformError = > err ,
else = > unreachable ,
} ;
2021-10-23 12:45:49 -07:00
return pos ;
}
2021-10-21 23:48:53 -07:00
2021-10-23 12:41:38 -07:00
/// Sets the position of the cursor, relative to the content area of the window.
///
/// This function sets the position, in screen coordinates, of the cursor relative to the upper-left
/// corner of the content area of the specified window. The window must have input focus. If the
/// window does not have input focus when this function is called, it fails silently.
///
/// __Do not use this function__ to implement things like camera controls. GLFW already provides the
/// `glfw.cursor_disabled` cursor mode that hides the cursor, transparently re-centers it and
/// provides unconstrained cursor motion. See glfw.Window.setInputMode for more information.
///
/// If the cursor mode is `glfw.cursor_disabled` then the cursor position is unconstrained and
/// limited only by the minimum and maximum values of a `double`.
///
/// @param[in] window The desired window.
/// @param[in] xpos The desired x-coordinate, relative to the left edge of the content area.
/// @param[in] ypos The desired y-coordinate, relative to the top edge of the content area.
///
/// Possible errors include glfw.Error.NotInitialized and glfw.Error.PlatformError.
///
/// wayland: This function will only work when the cursor mode is `glfw.cursor_disabled`, otherwise
/// it will do nothing.
///
/// @thread_safety This function must only be called from the main thread.
///
2021-10-23 12:45:49 -07:00
/// see also: cursor_pos, glfw.Window.getCursorPos
2021-11-21 20:15:16 +01:00
pub inline fn setCursorPos ( self : Window , xpos : f64 , ypos : f64 ) error { PlatformError } ! void {
internal_debug . assertInitialized ( ) ;
2021-10-23 12:41:38 -07:00
c . glfwSetCursorPos ( self . handle , xpos , ypos ) ;
2021-11-21 20:15:16 +01:00
getError ( ) catch | err | return switch ( err ) {
Error . PlatformError = > err ,
else = > unreachable ,
} ;
2021-10-23 12:41:38 -07:00
}
2021-10-21 23:48:53 -07:00
2021-10-23 12:34:59 -07:00
/// Sets the cursor for the window.
///
/// This function sets the cursor image to be used when the cursor is over the content area of the
/// specified window. The set cursor will only be visible when the cursor mode (see cursor_mode) of
/// the window is `glfw.Cursor.normal`.
///
/// On some platforms, the set cursor may not be visible unless the window also has input focus.
///
/// @param[in] cursor The cursor to set, or null to switch back to the default arrow cursor.
///
/// Possible errors include glfw.Error.NotInitialized and glfw.Error.PlatformError.
///
/// @thread_safety This function must only be called from the main thread.
///
/// see also: cursor_object
2021-11-21 20:15:16 +01:00
pub inline fn setCursor ( self : Window , cursor : Cursor ) error { PlatformError } ! void {
internal_debug . assertInitialized ( ) ;
2021-10-23 12:34:59 -07:00
c . glfwSetCursor ( self . handle , cursor . ptr ) ;
2021-11-21 20:15:16 +01:00
getError ( ) catch | err | return switch ( err ) {
Error . PlatformError = > err ,
else = > unreachable ,
} ;
2021-10-23 12:34:59 -07:00
}
2021-10-21 23:48:53 -07:00
2021-10-23 12:25:57 -07:00
fn setKeyCallbackWrapper ( handle : ? * c . GLFWwindow , key : c_int , scancode : c_int , action : c_int , mods : c_int ) callconv ( . C ) void {
const window = from ( handle . ? ) catch unreachable ;
const internal = window . getInternal ( ) ;
2021-10-30 14:10:31 -07:00
internal . setKeyCallback . ? ( window , @intToEnum ( Key , key ) , @intCast ( isize , scancode ) , @intToEnum ( Action , action ) , Mods . fromInt ( mods ) ) ;
2021-10-23 12:25:57 -07:00
}
/// Sets the key callback.
///
/// This function sets the key callback of the specified window, which is called when a key is
/// pressed, repeated or released.
///
/// The key functions deal with physical keys, with layout independent key tokens (see keys) named
/// after their values in the standard US keyboard layout. If you want to input text, use the
/// character callback (see glfw.Window.setCharCallback) instead.
///
/// When a window loses input focus, it will generate synthetic key release events for all pressed
/// keys. You can tell these events from user-generated events by the fact that the synthetic ones
/// are generated after the focus loss event has been processed, i.e. after the window focus
/// callback (see glfw.Window.setFocusCallback) has been called.
///
/// The scancode of a key is specific to that platform or sometimes even to that machine. Scancodes
/// are intended to allow users to bind keys that don't have a GLFW key token. Such keys have `key`
/// set to `glfw.key.unknown`, their state is not saved and so it cannot be queried with
/// glfw.Window.getKey.
///
/// Sometimes GLFW needs to generate synthetic key events, in which case the scancode may be zero.
///
/// @param[in] window The window whose callback to set.
/// @param[in] callback The new key callback, or null to remove the currently set callback.
///
/// @callback_param[in] window The window that received the event.
/// @callback_param[in] key The keyboard key (see keys) that was pressed or released.
/// @callback_param[in] scancode The system-specific scancode of the key.
2021-10-29 21:22:19 -07:00
/// @callback_param[in] action `glfw.Action.press`, `glfw.Action.release` or `glfw.Action.repeat`.
/// Future releases may add more actions.
2021-10-23 12:25:57 -07:00
/// @callback_param[in] mods Bit field describing which modifier keys (see mods) were held down.
///
/// @thread_safety This function must only be called from the main thread.
///
/// see also: input_key
2021-10-30 14:10:31 -07:00
pub inline fn setKeyCallback ( self : Window , callback : ? fn ( window : Window , key : Key , scancode : isize , action : Action , mods : Mods ) void ) void {
2021-11-21 20:15:16 +01:00
internal_debug . assertInitialized ( ) ;
2021-10-23 12:25:57 -07:00
var internal = self . getInternal ( ) ;
internal . setKeyCallback = callback ;
_ = c . glfwSetKeyCallback ( self . handle , if ( callback ! = null ) setKeyCallbackWrapper else null ) ;
2021-11-21 20:15:16 +01:00
getError ( ) catch unreachable ; // Only error 'GLFW_NOT_INITIALIZED' is impossible
2021-10-23 12:25:57 -07:00
}
2021-10-21 23:48:53 -07:00
2021-10-23 12:12:13 -07:00
fn setCharCallbackWrapper ( handle : ? * c . GLFWwindow , codepoint : c_uint ) callconv ( . C ) void {
const window = from ( handle . ? ) catch unreachable ;
const internal = window . getInternal ( ) ;
internal . setCharCallback . ? ( window , @intCast ( u21 , codepoint ) ) ;
}
/// Sets the Unicode character callback.
///
/// This function sets the character callback of the specified window, which is called when a
/// Unicode character is input.
///
/// The character callback is intended for Unicode text input. As it deals with characters, it is
/// keyboard layout dependent, whereas the key callback (see glfw.Window.setKeyCallback) is not.
/// Characters do not map 1:1 to physical keys, as a key may produce zero, one or more characters.
/// If you want to know whether a specific physical key was pressed or released, see the key
/// callback instead.
///
/// The character callback behaves as system text input normally does and will not be called if
/// modifier keys are held down that would prevent normal text input on that platform, for example a
/// Super (Command) key on macOS or Alt key on Windows.
///
/// @param[in] window The window whose callback to set.
/// @param[in] callback The new callback, or null to remove the currently set callback.
///
/// @callback_param[in] window The window that received the event.
/// @callback_param[in] codepoint The Unicode code point of the character.
///
/// @thread_safety This function must only be called from the main thread.
///
/// see also: input_char
pub inline fn setCharCallback ( self : Window , callback : ? fn ( window : Window , codepoint : u21 ) void ) void {
2021-11-21 20:15:16 +01:00
internal_debug . assertInitialized ( ) ;
2021-10-23 12:12:13 -07:00
var internal = self . getInternal ( ) ;
internal . setCharCallback = callback ;
_ = c . glfwSetCharCallback ( self . handle , if ( callback ! = null ) setCharCallbackWrapper else null ) ;
2021-11-21 20:15:16 +01:00
getError ( ) catch unreachable ; // Only error 'GLFW_NOT_INITIALIZED' is impossible
2021-10-23 12:12:13 -07:00
}
2021-10-21 23:48:53 -07:00
2021-10-23 12:01:13 -07:00
fn setMouseButtonCallbackWrapper ( handle : ? * c . GLFWwindow , button : c_int , action : c_int , mods : c_int ) callconv ( . C ) void {
const window = from ( handle . ? ) catch unreachable ;
const internal = window . getInternal ( ) ;
2021-10-30 15:35:04 -07:00
internal . setMouseButtonCallback . ? ( window , @intToEnum ( MouseButton , button ) , @intToEnum ( Action , action ) , Mods . fromInt ( mods ) ) ;
2021-10-23 12:01:13 -07:00
}
/// Sets the mouse button callback.
///
/// This function sets the mouse button callback of the specified window, which is called when a
/// mouse button is pressed or released.
///
/// When a window loses input focus, it will generate synthetic mouse button release events for all
/// pressed mouse buttons. You can tell these events from user-generated events by the fact that the
/// synthetic ones are generated after the focus loss event has been processed, i.e. after the
/// window focus callback (see glfw.Window.setFocusCallback) has been called.
///
/// @param[in] window The window whose callback to set.
/// @param[in] callback The new callback, or null to remove the currently set callback.
///
/// @callback_param[in] window The window that received the event.
/// @callback_param[in] button The mouse button that was pressed or released.
2021-10-29 21:22:19 -07:00
/// @callback_param[in] action One of `glfw.Action.press` or `glfw.Action.release`. Future releases
/// may add more actions.
2021-10-23 12:01:13 -07:00
/// @callback_param[in] mods Bit field describing which modifier keys (see mods) were held down.
///
/// @thread_safety This function must only be called from the main thread.
///
/// see also: input_mouse_button
2021-10-30 15:35:04 -07:00
pub inline fn setMouseButtonCallback ( self : Window , callback : ? fn ( window : Window , button : MouseButton , action : Action , mods : Mods ) void ) void {
2021-11-21 20:15:16 +01:00
internal_debug . assertInitialized ( ) ;
2021-10-23 12:01:13 -07:00
var internal = self . getInternal ( ) ;
internal . setMouseButtonCallback = callback ;
_ = c . glfwSetMouseButtonCallback ( self . handle , if ( callback ! = null ) setMouseButtonCallbackWrapper else null ) ;
2021-11-21 20:15:16 +01:00
getError ( ) catch unreachable ; // Only error 'GLFW_NOT_INITIALIZED' is impossible
2021-10-23 12:01:13 -07:00
}
2021-10-21 23:48:53 -07:00
2021-10-23 11:46:58 -07:00
fn setCursorPosCallbackWrapper ( handle : ? * c . GLFWwindow , xpos : f64 , ypos : f64 ) callconv ( . C ) void {
const window = from ( handle . ? ) catch unreachable ;
const internal = window . getInternal ( ) ;
internal . setCursorPosCallback . ? ( window , xpos , ypos ) ;
}
/// Sets the cursor position callback.
///
/// This function sets the cursor position callback of the specified window, which is called when
/// the cursor is moved. The callback is provided with the position, in screen coordinates, relative
/// to the upper-left corner of the content area of the window.
///
/// @param[in] callback The new callback, or null to remove the currently set callback.
///
/// @callback_param[in] window The window that received the event.
/// @callback_param[in] xpos The new cursor x-coordinate, relative to the left edge of the content
/// area.
/// callback_@param[in] ypos The new cursor y-coordinate, relative to the top edge of the content
/// area.
///
/// @thread_safety This function must only be called from the main thread.
///
/// see also: cursor_pos
pub inline fn setCursorPosCallback ( self : Window , callback : ? fn ( window : Window , xpos : f64 , ypos : f64 ) void ) void {
2021-11-21 20:15:16 +01:00
internal_debug . assertInitialized ( ) ;
2021-10-23 11:46:58 -07:00
var internal = self . getInternal ( ) ;
internal . setCursorPosCallback = callback ;
_ = c . glfwSetCursorPosCallback ( self . handle , if ( callback ! = null ) setCursorPosCallbackWrapper else null ) ;
2021-11-21 20:15:16 +01:00
getError ( ) catch unreachable ; // Only error 'GLFW_NOT_INITIALIZED' is impossible
2021-10-23 11:46:58 -07:00
}
2021-10-21 23:48:53 -07:00
2021-10-23 11:42:26 -07:00
fn setCursorEnterCallbackWrapper ( handle : ? * c . GLFWwindow , entered : c_int ) callconv ( . C ) void {
const window = from ( handle . ? ) catch unreachable ;
const internal = window . getInternal ( ) ;
internal . setCursorEnterCallback . ? ( window , entered = = c . GLFW_TRUE ) ;
}
/// Sets the cursor enter/leave callback.
///
/// This function sets the cursor boundary crossing callback of the specified window, which is
/// called when the cursor enters or leaves the content area of the window.
///
/// @param[in] callback The new callback, or null to remove the currently set callback.
///
/// @callback_param[in] window The window that received the event.
/// @callback_param[in] entered `true` if the cursor entered the window's content area, or `false`
/// if it left it.
///
/// @thread_safety This function must only be called from the main thread.
///
/// see also: cursor_enter
pub inline fn setCursorEnterCallback ( self : Window , callback : ? fn ( window : Window , entered : bool ) void ) void {
2021-11-21 20:15:16 +01:00
internal_debug . assertInitialized ( ) ;
2021-10-23 11:42:26 -07:00
var internal = self . getInternal ( ) ;
internal . setCursorEnterCallback = callback ;
_ = c . glfwSetCursorEnterCallback ( self . handle , if ( callback ! = null ) setCursorEnterCallbackWrapper else null ) ;
2021-11-21 20:15:16 +01:00
getError ( ) catch unreachable ; // Only error 'GLFW_NOT_INITIALIZED' is impossible
2021-10-23 11:42:26 -07:00
}
2021-10-21 23:48:53 -07:00
2021-10-23 11:37:36 -07:00
fn setScrollCallbackWrapper ( handle : ? * c . GLFWwindow , xoffset : f64 , yoffset : f64 ) callconv ( . C ) void {
const window = from ( handle . ? ) catch unreachable ;
const internal = window . getInternal ( ) ;
internal . setScrollCallback . ? ( window , xoffset , yoffset ) ;
}
/// Sets the scroll callback.
///
/// This function sets the scroll callback of the specified window, which is called when a scrolling
/// device is used, such as a mouse wheel or scrolling area of a touchpad.
///
/// The scroll callback receives all scrolling input, like that from a mouse wheel or a touchpad
/// scrolling area.
///
/// @param[in] window The window whose callback to set.
/// @param[in] callback The new scroll callback, or null to remove the currently set callback.
///
/// @callback_param[in] window The window that received the event.
/// @callback_param[in] xoffset The scroll offset along the x-axis.
/// @callback_param[in] yoffset The scroll offset along the y-axis.
///
/// @thread_safety This function must only be called from the main thread.
///
/// see also: scrolling
pub inline fn setScrollCallback ( self : Window , callback : ? fn ( window : Window , xoffset : f64 , yoffset : f64 ) void ) void {
2021-11-21 20:15:16 +01:00
internal_debug . assertInitialized ( ) ;
2021-10-23 11:37:36 -07:00
var internal = self . getInternal ( ) ;
internal . setScrollCallback = callback ;
_ = c . glfwSetScrollCallback ( self . handle , if ( callback ! = null ) setScrollCallbackWrapper else null ) ;
2021-11-21 20:15:16 +01:00
getError ( ) catch unreachable ; // Only error 'GLFW_NOT_INITIALIZED' is impossible
2021-10-23 11:37:36 -07:00
}
2021-10-21 23:48:53 -07:00
2021-10-23 10:49:28 -07:00
fn setDropCallbackWrapper ( handle : ? * c . GLFWwindow , path_count : c_int , paths : [ * c ] [ * c ] const u8 ) callconv ( . C ) void {
const window = from ( handle . ? ) catch unreachable ;
const internal = window . getInternal ( ) ;
2021-11-11 09:42:49 +00:00
internal . setDropCallback . ? ( window , @ptrCast ( [ * ] [ * : 0 ] const u8 , paths ) [ 0 . . @intCast ( usize , path_count ) ] ) ;
2021-10-23 10:49:28 -07:00
}
/// Sets the path drop callback.
///
/// This function sets the path drop callback of the specified window, which is called when one or
/// more dragged paths are dropped on the window.
///
/// Because the path array and its strings may have been generated specifically for that event, they
/// are not guaranteed to be valid after the callback has returned. If you wish to use them after
/// the callback returns, you need to make a deep copy.
///
/// @param[in] callback The new file drop callback, or null to remove the currently set callback.
///
/// @callback_param[in] window The window that received the event.
/// @callback_param[in] path_count The number of dropped paths.
/// @callback_param[in] paths The UTF-8 encoded file and/or directory path names.
///
/// @callback_pointer_lifetime The path array and its strings are valid until the callback function
/// returns.
///
/// Possible errors include glfw.Error.NotInitialized.
///
/// wayland: File drop is currently unimplemented.
///
/// @thread_safety This function must only be called from the main thread.
///
/// see also: path_drop
2021-11-21 20:15:16 +01:00
// TODO: Remove error stub
pub inline fn setDropCallback ( self : Window , callback : ? fn ( window : Window , paths : [ ] [ * : 0 ] const u8 ) void ) error { } ! void {
internal_debug . assertInitialized ( ) ;
2021-10-23 10:49:28 -07:00
var internal = self . getInternal ( ) ;
internal . setDropCallback = callback ;
_ = c . glfwSetDropCallback ( self . handle , if ( callback ! = null ) setDropCallbackWrapper else null ) ;
2021-11-21 20:15:16 +01:00
getError ( ) catch unreachable ; // Only error 'GLFW_NOT_INITIALIZED' is impossible
2021-10-23 10:49:28 -07:00
}
2021-10-21 23:48:53 -07:00
glfw: window hints rework (#71)
* glfw: make comments into doc comments
* glfw: Publicize Window.CursorPos, Window.Size, Window.Pos, and Window.FrameSize
* glfw: Make enum value name the same format as other enum value names
* glfw: Window hints rework patch
* glfw: Relegate `Window.hint` to testing; move it down to just above the tests to reflect this, add doc comment line
* glfw: handle error `Error.InvalidEnum` explicitly, for clear error message in this unlikely edge case
* glfw: instate `Hint.context_no_error` as a hint, as it actually is specified to be a Window creation hint by the docs, and affirm removal of `Hint.context_revision`, which isn't.
The docs don't seem to specify a default value for `Hints.context_no_error` to take on, so we could set it based on `std.debug.runtime_safety` like this.
* glfw: default `context_no_error` to `false`, and added a note of caution about its usage as suggested.
* glfw: Inline enum values of `ClientApi`, `ContextCreationApi`, `ContextRobustness`, `ContextReleaseBehavior`, and `OpenGlProfile` from consts.zig, and remove the now unused constants (replaced by aformentioned enum values).
* glfw: Reference `Window.Hint` enum instead of `Window.Hints` struct to ensure fields are the same
* glfw: add comment explaining default values of `Window.Hints`
* glfw: change `OpenGlProfile` to `OpenGLProfile` based on established naming convention
* glfw: Update actual declaration of `OpenGLProfile`
* glfw: call `Window.defaultHints` after window creation, not before
* glfw: remove 'consts.zig', and move `dont_care` directly into 'main.zig'; fix anything referencing it.
* glfw: put `Window.defaultHints` into defer statement to handle cleanup in all paths
* glfw: move `Hint.focused` to match position of `Hints.focused`
* glfw: do 'zig fmt glfw/src'
* glfw: Cull `Window.Hint` comments, polish remaining; match order entirely according to current GLFW docs
* glfw: Change `Window.Hints.*Api` to `Window.Hints.*API`
Co-authored-by: Stephen Gutekanst <stephen@hexops.com>
2021-11-16 02:41:16 +01:00
/// For testing purposes only; see glfw.Window.Hints and glfw.Window.create for the public API.
/// Sets the specified window hint to the desired value.
///
/// This function sets hints for the next call to glfw.Window.create. The hints, once set, retain
/// their values until changed by a call to this function or glfw.window.defaultHints, or until the
/// library is terminated.
///
/// This function does not check whether the specified hint values are valid. If you set hints to
/// invalid values this will instead be reported by the next call to glfw.createWindow.
///
/// Some hints are platform specific. These may be set on any platform but they will only affect
/// their specific platform. Other platforms will ignore them.
///
/// Possible errors include glfw.Error.NotInitialized and glfw.Error.InvalidEnum.
///
/// @pointer_lifetime in the event that value is of a str type, the specified string is copied before this function returns.
///
/// @thread_safety This function must only be called from the main thread.
///
/// see also: window_hints, glfw.Window.defaultHints
inline fn hint ( h : Hint , value : anytype ) Error ! void {
const value_type = @TypeOf ( value ) ;
const value_type_info : std . builtin . TypeInfo = @typeInfo ( value_type ) ;
switch ( value_type_info ) {
. Int , . ComptimeInt = > {
c . glfwWindowHint ( @enumToInt ( h ) , @intCast ( c_int , value ) ) ;
} ,
. Bool = > {
const int_value = @boolToInt ( value ) ;
c . glfwWindowHint ( @enumToInt ( h ) , @intCast ( c_int , int_value ) ) ;
} ,
. Enum = > {
const int_value = @enumToInt ( value ) ;
c . glfwWindowHint ( @enumToInt ( h ) , @intCast ( c_int , int_value ) ) ;
} ,
. Array = > | arr_type | {
if ( arr_type . child ! = u8 ) {
@compileError ( " expected array of u8, got " + + @typeName ( arr_type ) ) ;
}
c . glfwWindowHintString ( @enumToInt ( h ) , & value [ 0 ] ) ;
} ,
. Pointer = > | pointer_info | {
const pointed_type = @typeInfo ( pointer_info . child ) ;
switch ( pointed_type ) {
. Array = > | arr_type | {
if ( arr_type . child ! = u8 ) {
@compileError ( " expected pointer to array of u8, got " + + @typeName ( arr_type ) ) ;
}
} ,
else = > @compileError ( " expected pointer to array, got " + + @typeName ( pointed_type ) ) ,
}
c . glfwWindowHintString ( @enumToInt ( h ) , & value [ 0 ] ) ;
} ,
else = > {
@compileError ( " expected a int, bool, enum, array, or pointer, got " + + @typeName ( value_type ) ) ;
} ,
}
try getError ( ) ;
}
2021-07-18 17:47:07 -07:00
test " defaultHints " {
2021-11-10 11:38:43 +01:00
try glfw . init ( . { } ) ;
2021-07-18 17:47:07 -07:00
defer glfw . terminate ( ) ;
try defaultHints ( ) ;
}
2021-07-18 20:01:16 -07:00
2021-10-18 22:19:25 +02:00
test " hint comptime int " {
2021-11-10 11:38:43 +01:00
try glfw . init ( . { } ) ;
2021-07-18 20:01:16 -07:00
defer glfw . terminate ( ) ;
2021-10-30 14:31:06 -07:00
try hint ( . focused , 1 ) ;
2021-07-18 20:01:16 -07:00
try defaultHints ( ) ;
}
2021-07-18 20:33:04 -07:00
2021-10-18 22:19:25 +02:00
test " hint int " {
2021-11-10 11:38:43 +01:00
try glfw . init ( . { } ) ;
2021-10-18 22:19:25 +02:00
defer glfw . terminate ( ) ;
var focused : i32 = 1 ;
2021-10-30 14:31:06 -07:00
try hint ( . focused , focused ) ;
2021-10-18 22:19:25 +02:00
try defaultHints ( ) ;
}
test " hint bool " {
2021-11-10 11:38:43 +01:00
try glfw . init ( . { } ) ;
2021-10-18 22:19:25 +02:00
defer glfw . terminate ( ) ;
2021-10-30 14:31:06 -07:00
try hint ( . focused , true ) ;
2021-10-18 22:19:25 +02:00
try defaultHints ( ) ;
}
test " hint enum(u1) " {
2021-11-10 11:38:43 +01:00
try glfw . init ( . { } ) ;
2021-10-18 22:19:25 +02:00
defer glfw . terminate ( ) ;
const MyEnum = enum ( u1 ) {
@ " true " = 1 ,
@ " false " = 0 ,
} ;
2021-10-30 14:31:06 -07:00
try hint ( . focused , MyEnum . @ " true " ) ;
2021-10-18 22:19:25 +02:00
try defaultHints ( ) ;
}
test " hint enum(i32) " {
2021-11-10 11:38:43 +01:00
try glfw . init ( . { } ) ;
2021-10-18 22:19:25 +02:00
defer glfw . terminate ( ) ;
const MyEnum = enum ( i32 ) {
@ " true " = 1 ,
@ " false " = 0 ,
} ;
2021-10-30 14:31:06 -07:00
try hint ( . focused , MyEnum . @ " true " ) ;
2021-10-18 22:19:25 +02:00
try defaultHints ( ) ;
}
test " hint array str " {
2021-11-10 11:38:43 +01:00
try glfw . init ( . { } ) ;
2021-10-18 22:19:25 +02:00
defer glfw . terminate ( ) ;
const str_arr = [ _ ] u8 { 'm' , 'y' , 'c' , 'l' , 'a' , 's' , 's' } ;
2021-10-30 14:31:06 -07:00
try hint ( . x11_class_name , str_arr ) ;
2021-10-18 22:19:25 +02:00
try defaultHints ( ) ;
}
test " hint pointer str " {
2021-11-10 11:38:43 +01:00
try glfw . init ( . { } ) ;
2021-07-18 20:33:04 -07:00
defer glfw . terminate ( ) ;
2021-10-30 14:31:06 -07:00
try hint ( . x11_class_name , " myclass " ) ;
2021-07-18 20:33:04 -07:00
}
2021-07-18 21:35:52 -07:00
test " createWindow " {
2021-11-10 11:38:43 +01:00
try glfw . init ( . { } ) ;
2021-07-18 21:35:52 -07:00
defer glfw . terminate ( ) ;
glfw: window hints rework (#71)
* glfw: make comments into doc comments
* glfw: Publicize Window.CursorPos, Window.Size, Window.Pos, and Window.FrameSize
* glfw: Make enum value name the same format as other enum value names
* glfw: Window hints rework patch
* glfw: Relegate `Window.hint` to testing; move it down to just above the tests to reflect this, add doc comment line
* glfw: handle error `Error.InvalidEnum` explicitly, for clear error message in this unlikely edge case
* glfw: instate `Hint.context_no_error` as a hint, as it actually is specified to be a Window creation hint by the docs, and affirm removal of `Hint.context_revision`, which isn't.
The docs don't seem to specify a default value for `Hints.context_no_error` to take on, so we could set it based on `std.debug.runtime_safety` like this.
* glfw: default `context_no_error` to `false`, and added a note of caution about its usage as suggested.
* glfw: Inline enum values of `ClientApi`, `ContextCreationApi`, `ContextRobustness`, `ContextReleaseBehavior`, and `OpenGlProfile` from consts.zig, and remove the now unused constants (replaced by aformentioned enum values).
* glfw: Reference `Window.Hint` enum instead of `Window.Hints` struct to ensure fields are the same
* glfw: add comment explaining default values of `Window.Hints`
* glfw: change `OpenGlProfile` to `OpenGLProfile` based on established naming convention
* glfw: Update actual declaration of `OpenGLProfile`
* glfw: call `Window.defaultHints` after window creation, not before
* glfw: remove 'consts.zig', and move `dont_care` directly into 'main.zig'; fix anything referencing it.
* glfw: put `Window.defaultHints` into defer statement to handle cleanup in all paths
* glfw: move `Hint.focused` to match position of `Hints.focused`
* glfw: do 'zig fmt glfw/src'
* glfw: Cull `Window.Hint` comments, polish remaining; match order entirely according to current GLFW docs
* glfw: Change `Window.Hints.*Api` to `Window.Hints.*API`
Co-authored-by: Stephen Gutekanst <stephen@hexops.com>
2021-11-16 02:41:16 +01:00
const window = glfw . Window . create ( 640 , 480 , " Hello, Zig! " , null , null , . { } ) catch | err | {
2021-07-18 21:35:52 -07:00
// return without fail, because most of our CI environments are headless / we cannot open
// windows on them.
std . debug . print ( " note: failed to create window: {} \n " , . { err } ) ;
return ;
} ;
2021-07-18 21:41:21 -07:00
defer window . destroy ( ) ;
2021-07-18 21:35:52 -07:00
}
2021-07-18 22:01:18 -07:00
test " setShouldClose " {
2021-11-10 11:38:43 +01:00
try glfw . init ( . { } ) ;
2021-07-18 22:01:18 -07:00
defer glfw . terminate ( ) ;
glfw: window hints rework (#71)
* glfw: make comments into doc comments
* glfw: Publicize Window.CursorPos, Window.Size, Window.Pos, and Window.FrameSize
* glfw: Make enum value name the same format as other enum value names
* glfw: Window hints rework patch
* glfw: Relegate `Window.hint` to testing; move it down to just above the tests to reflect this, add doc comment line
* glfw: handle error `Error.InvalidEnum` explicitly, for clear error message in this unlikely edge case
* glfw: instate `Hint.context_no_error` as a hint, as it actually is specified to be a Window creation hint by the docs, and affirm removal of `Hint.context_revision`, which isn't.
The docs don't seem to specify a default value for `Hints.context_no_error` to take on, so we could set it based on `std.debug.runtime_safety` like this.
* glfw: default `context_no_error` to `false`, and added a note of caution about its usage as suggested.
* glfw: Inline enum values of `ClientApi`, `ContextCreationApi`, `ContextRobustness`, `ContextReleaseBehavior`, and `OpenGlProfile` from consts.zig, and remove the now unused constants (replaced by aformentioned enum values).
* glfw: Reference `Window.Hint` enum instead of `Window.Hints` struct to ensure fields are the same
* glfw: add comment explaining default values of `Window.Hints`
* glfw: change `OpenGlProfile` to `OpenGLProfile` based on established naming convention
* glfw: Update actual declaration of `OpenGLProfile`
* glfw: call `Window.defaultHints` after window creation, not before
* glfw: remove 'consts.zig', and move `dont_care` directly into 'main.zig'; fix anything referencing it.
* glfw: put `Window.defaultHints` into defer statement to handle cleanup in all paths
* glfw: move `Hint.focused` to match position of `Hints.focused`
* glfw: do 'zig fmt glfw/src'
* glfw: Cull `Window.Hint` comments, polish remaining; match order entirely according to current GLFW docs
* glfw: Change `Window.Hints.*Api` to `Window.Hints.*API`
Co-authored-by: Stephen Gutekanst <stephen@hexops.com>
2021-11-16 02:41:16 +01:00
const window = glfw . Window . create ( 640 , 480 , " Hello, Zig! " , null , null , . { } ) catch | err | {
2021-07-18 22:01:18 -07:00
// return without fail, because most of our CI environments are headless / we cannot open
// windows on them.
std . debug . print ( " note: failed to create window: {} \n " , . { err } ) ;
return ;
} ;
try window . setShouldClose ( true ) ;
defer window . destroy ( ) ;
}
2021-07-19 19:09:53 -07:00
test " setTitle " {
2021-11-10 11:38:43 +01:00
try glfw . init ( . { } ) ;
2021-07-19 19:09:53 -07:00
defer glfw . terminate ( ) ;
glfw: window hints rework (#71)
* glfw: make comments into doc comments
* glfw: Publicize Window.CursorPos, Window.Size, Window.Pos, and Window.FrameSize
* glfw: Make enum value name the same format as other enum value names
* glfw: Window hints rework patch
* glfw: Relegate `Window.hint` to testing; move it down to just above the tests to reflect this, add doc comment line
* glfw: handle error `Error.InvalidEnum` explicitly, for clear error message in this unlikely edge case
* glfw: instate `Hint.context_no_error` as a hint, as it actually is specified to be a Window creation hint by the docs, and affirm removal of `Hint.context_revision`, which isn't.
The docs don't seem to specify a default value for `Hints.context_no_error` to take on, so we could set it based on `std.debug.runtime_safety` like this.
* glfw: default `context_no_error` to `false`, and added a note of caution about its usage as suggested.
* glfw: Inline enum values of `ClientApi`, `ContextCreationApi`, `ContextRobustness`, `ContextReleaseBehavior`, and `OpenGlProfile` from consts.zig, and remove the now unused constants (replaced by aformentioned enum values).
* glfw: Reference `Window.Hint` enum instead of `Window.Hints` struct to ensure fields are the same
* glfw: add comment explaining default values of `Window.Hints`
* glfw: change `OpenGlProfile` to `OpenGLProfile` based on established naming convention
* glfw: Update actual declaration of `OpenGLProfile`
* glfw: call `Window.defaultHints` after window creation, not before
* glfw: remove 'consts.zig', and move `dont_care` directly into 'main.zig'; fix anything referencing it.
* glfw: put `Window.defaultHints` into defer statement to handle cleanup in all paths
* glfw: move `Hint.focused` to match position of `Hints.focused`
* glfw: do 'zig fmt glfw/src'
* glfw: Cull `Window.Hint` comments, polish remaining; match order entirely according to current GLFW docs
* glfw: Change `Window.Hints.*Api` to `Window.Hints.*API`
Co-authored-by: Stephen Gutekanst <stephen@hexops.com>
2021-11-16 02:41:16 +01:00
const window = glfw . Window . create ( 640 , 480 , " Hello, Zig! " , null , null , . { } ) catch | err | {
2021-07-19 19:09:53 -07:00
// return without fail, because most of our CI environments are headless / we cannot open
// windows on them.
std . debug . print ( " note: failed to create window: {} \n " , . { err } ) ;
return ;
} ;
defer window . destroy ( ) ;
try window . setTitle ( " Updated title! " ) ;
}
2021-07-20 21:28:00 -07:00
2021-10-31 11:50:09 -07:00
test " setIcon " {
const allocator = testing . allocator ;
2021-11-10 11:38:43 +01:00
try glfw . init ( . { } ) ;
2021-10-31 11:50:09 -07:00
defer glfw . terminate ( ) ;
glfw: window hints rework (#71)
* glfw: make comments into doc comments
* glfw: Publicize Window.CursorPos, Window.Size, Window.Pos, and Window.FrameSize
* glfw: Make enum value name the same format as other enum value names
* glfw: Window hints rework patch
* glfw: Relegate `Window.hint` to testing; move it down to just above the tests to reflect this, add doc comment line
* glfw: handle error `Error.InvalidEnum` explicitly, for clear error message in this unlikely edge case
* glfw: instate `Hint.context_no_error` as a hint, as it actually is specified to be a Window creation hint by the docs, and affirm removal of `Hint.context_revision`, which isn't.
The docs don't seem to specify a default value for `Hints.context_no_error` to take on, so we could set it based on `std.debug.runtime_safety` like this.
* glfw: default `context_no_error` to `false`, and added a note of caution about its usage as suggested.
* glfw: Inline enum values of `ClientApi`, `ContextCreationApi`, `ContextRobustness`, `ContextReleaseBehavior`, and `OpenGlProfile` from consts.zig, and remove the now unused constants (replaced by aformentioned enum values).
* glfw: Reference `Window.Hint` enum instead of `Window.Hints` struct to ensure fields are the same
* glfw: add comment explaining default values of `Window.Hints`
* glfw: change `OpenGlProfile` to `OpenGLProfile` based on established naming convention
* glfw: Update actual declaration of `OpenGLProfile`
* glfw: call `Window.defaultHints` after window creation, not before
* glfw: remove 'consts.zig', and move `dont_care` directly into 'main.zig'; fix anything referencing it.
* glfw: put `Window.defaultHints` into defer statement to handle cleanup in all paths
* glfw: move `Hint.focused` to match position of `Hints.focused`
* glfw: do 'zig fmt glfw/src'
* glfw: Cull `Window.Hint` comments, polish remaining; match order entirely according to current GLFW docs
* glfw: Change `Window.Hints.*Api` to `Window.Hints.*API`
Co-authored-by: Stephen Gutekanst <stephen@hexops.com>
2021-11-16 02:41:16 +01:00
const window = glfw . Window . create ( 640 , 480 , " Hello, Zig! " , null , null , . { } ) catch | err | {
2021-10-31 11:50:09 -07:00
// return without fail, because most of our CI environments are headless / we cannot open
// windows on them.
std . debug . print ( " note: failed to create window: {} \n " , . { err } ) ;
return ;
} ;
defer window . destroy ( ) ;
// Create an all-red icon image.
var width : usize = 48 ;
var height : usize = 48 ;
const icon = try Image . init ( allocator , width , height , width * height * 4 ) ;
var x : usize = 0 ;
var y : usize = 0 ;
while ( y < = height ) : ( y + = 1 ) {
while ( x < = width ) : ( x + = 1 ) {
icon . pixels [ ( x * y * 4 ) + 0 ] = 255 ; // red
icon . pixels [ ( x * y * 4 ) + 1 ] = 0 ; // green
icon . pixels [ ( x * y * 4 ) + 2 ] = 0 ; // blue
icon . pixels [ ( x * y * 4 ) + 3 ] = 255 ; // alpha
}
}
window . setIcon ( allocator , & [ _ ] Image { icon } ) catch | err | std . debug . print ( " can't set window icon, wayland maybe? error={} \n " , . { err } ) ;
icon . deinit ( allocator ) ; // glfw copies it.
}
2021-07-23 13:56:28 -07:00
test " getPos " {
2021-11-10 11:38:43 +01:00
try glfw . init ( . { } ) ;
2021-07-23 13:56:28 -07:00
defer glfw . terminate ( ) ;
glfw: window hints rework (#71)
* glfw: make comments into doc comments
* glfw: Publicize Window.CursorPos, Window.Size, Window.Pos, and Window.FrameSize
* glfw: Make enum value name the same format as other enum value names
* glfw: Window hints rework patch
* glfw: Relegate `Window.hint` to testing; move it down to just above the tests to reflect this, add doc comment line
* glfw: handle error `Error.InvalidEnum` explicitly, for clear error message in this unlikely edge case
* glfw: instate `Hint.context_no_error` as a hint, as it actually is specified to be a Window creation hint by the docs, and affirm removal of `Hint.context_revision`, which isn't.
The docs don't seem to specify a default value for `Hints.context_no_error` to take on, so we could set it based on `std.debug.runtime_safety` like this.
* glfw: default `context_no_error` to `false`, and added a note of caution about its usage as suggested.
* glfw: Inline enum values of `ClientApi`, `ContextCreationApi`, `ContextRobustness`, `ContextReleaseBehavior`, and `OpenGlProfile` from consts.zig, and remove the now unused constants (replaced by aformentioned enum values).
* glfw: Reference `Window.Hint` enum instead of `Window.Hints` struct to ensure fields are the same
* glfw: add comment explaining default values of `Window.Hints`
* glfw: change `OpenGlProfile` to `OpenGLProfile` based on established naming convention
* glfw: Update actual declaration of `OpenGLProfile`
* glfw: call `Window.defaultHints` after window creation, not before
* glfw: remove 'consts.zig', and move `dont_care` directly into 'main.zig'; fix anything referencing it.
* glfw: put `Window.defaultHints` into defer statement to handle cleanup in all paths
* glfw: move `Hint.focused` to match position of `Hints.focused`
* glfw: do 'zig fmt glfw/src'
* glfw: Cull `Window.Hint` comments, polish remaining; match order entirely according to current GLFW docs
* glfw: Change `Window.Hints.*Api` to `Window.Hints.*API`
Co-authored-by: Stephen Gutekanst <stephen@hexops.com>
2021-11-16 02:41:16 +01:00
const window = glfw . Window . create ( 640 , 480 , " Hello, Zig! " , null , null , . { } ) catch | err | {
2021-07-23 13:56:28 -07:00
// return without fail, because most of our CI environments are headless / we cannot open
// windows on them.
std . debug . print ( " note: failed to create window: {} \n " , . { err } ) ;
return ;
} ;
defer window . destroy ( ) ;
2021-07-23 14:05:54 -07:00
_ = window . getPos ( ) catch | err | std . debug . print ( " can't get window position, wayland maybe? error={} \n " , . { err } ) ;
2021-07-23 13:56:28 -07:00
}
2021-07-23 14:08:42 -07:00
test " setPos " {
2021-11-10 11:38:43 +01:00
try glfw . init ( . { } ) ;
2021-07-23 14:08:42 -07:00
defer glfw . terminate ( ) ;
glfw: window hints rework (#71)
* glfw: make comments into doc comments
* glfw: Publicize Window.CursorPos, Window.Size, Window.Pos, and Window.FrameSize
* glfw: Make enum value name the same format as other enum value names
* glfw: Window hints rework patch
* glfw: Relegate `Window.hint` to testing; move it down to just above the tests to reflect this, add doc comment line
* glfw: handle error `Error.InvalidEnum` explicitly, for clear error message in this unlikely edge case
* glfw: instate `Hint.context_no_error` as a hint, as it actually is specified to be a Window creation hint by the docs, and affirm removal of `Hint.context_revision`, which isn't.
The docs don't seem to specify a default value for `Hints.context_no_error` to take on, so we could set it based on `std.debug.runtime_safety` like this.
* glfw: default `context_no_error` to `false`, and added a note of caution about its usage as suggested.
* glfw: Inline enum values of `ClientApi`, `ContextCreationApi`, `ContextRobustness`, `ContextReleaseBehavior`, and `OpenGlProfile` from consts.zig, and remove the now unused constants (replaced by aformentioned enum values).
* glfw: Reference `Window.Hint` enum instead of `Window.Hints` struct to ensure fields are the same
* glfw: add comment explaining default values of `Window.Hints`
* glfw: change `OpenGlProfile` to `OpenGLProfile` based on established naming convention
* glfw: Update actual declaration of `OpenGLProfile`
* glfw: call `Window.defaultHints` after window creation, not before
* glfw: remove 'consts.zig', and move `dont_care` directly into 'main.zig'; fix anything referencing it.
* glfw: put `Window.defaultHints` into defer statement to handle cleanup in all paths
* glfw: move `Hint.focused` to match position of `Hints.focused`
* glfw: do 'zig fmt glfw/src'
* glfw: Cull `Window.Hint` comments, polish remaining; match order entirely according to current GLFW docs
* glfw: Change `Window.Hints.*Api` to `Window.Hints.*API`
Co-authored-by: Stephen Gutekanst <stephen@hexops.com>
2021-11-16 02:41:16 +01:00
const window = glfw . Window . create ( 640 , 480 , " Hello, Zig! " , null , null , . { } ) catch | err | {
2021-07-23 14:08:42 -07:00
// return without fail, because most of our CI environments are headless / we cannot open
// windows on them.
std . debug . print ( " note: failed to create window: {} \n " , . { err } ) ;
return ;
} ;
defer window . destroy ( ) ;
_ = window . setPos ( . { . x = 0 , . y = 0 } ) catch | err | std . debug . print ( " can't set window position, wayland maybe? error={} \n " , . { err } ) ;
}
2021-07-23 14:18:34 -07:00
test " getSize " {
2021-11-10 11:38:43 +01:00
try glfw . init ( . { } ) ;
2021-07-23 14:18:34 -07:00
defer glfw . terminate ( ) ;
glfw: window hints rework (#71)
* glfw: make comments into doc comments
* glfw: Publicize Window.CursorPos, Window.Size, Window.Pos, and Window.FrameSize
* glfw: Make enum value name the same format as other enum value names
* glfw: Window hints rework patch
* glfw: Relegate `Window.hint` to testing; move it down to just above the tests to reflect this, add doc comment line
* glfw: handle error `Error.InvalidEnum` explicitly, for clear error message in this unlikely edge case
* glfw: instate `Hint.context_no_error` as a hint, as it actually is specified to be a Window creation hint by the docs, and affirm removal of `Hint.context_revision`, which isn't.
The docs don't seem to specify a default value for `Hints.context_no_error` to take on, so we could set it based on `std.debug.runtime_safety` like this.
* glfw: default `context_no_error` to `false`, and added a note of caution about its usage as suggested.
* glfw: Inline enum values of `ClientApi`, `ContextCreationApi`, `ContextRobustness`, `ContextReleaseBehavior`, and `OpenGlProfile` from consts.zig, and remove the now unused constants (replaced by aformentioned enum values).
* glfw: Reference `Window.Hint` enum instead of `Window.Hints` struct to ensure fields are the same
* glfw: add comment explaining default values of `Window.Hints`
* glfw: change `OpenGlProfile` to `OpenGLProfile` based on established naming convention
* glfw: Update actual declaration of `OpenGLProfile`
* glfw: call `Window.defaultHints` after window creation, not before
* glfw: remove 'consts.zig', and move `dont_care` directly into 'main.zig'; fix anything referencing it.
* glfw: put `Window.defaultHints` into defer statement to handle cleanup in all paths
* glfw: move `Hint.focused` to match position of `Hints.focused`
* glfw: do 'zig fmt glfw/src'
* glfw: Cull `Window.Hint` comments, polish remaining; match order entirely according to current GLFW docs
* glfw: Change `Window.Hints.*Api` to `Window.Hints.*API`
Co-authored-by: Stephen Gutekanst <stephen@hexops.com>
2021-11-16 02:41:16 +01:00
const window = glfw . Window . create ( 640 , 480 , " Hello, Zig! " , null , null , . { } ) catch | err | {
2021-07-23 14:18:34 -07:00
// return without fail, because most of our CI environments are headless / we cannot open
// windows on them.
std . debug . print ( " note: failed to create window: {} \n " , . { err } ) ;
return ;
} ;
defer window . destroy ( ) ;
_ = try window . getSize ( ) ;
}
2021-07-23 14:29:14 -07:00
2021-07-23 15:02:13 -07:00
test " setSize " {
2021-11-10 11:38:43 +01:00
try glfw . init ( . { } ) ;
2021-07-23 15:02:13 -07:00
defer glfw . terminate ( ) ;
glfw: window hints rework (#71)
* glfw: make comments into doc comments
* glfw: Publicize Window.CursorPos, Window.Size, Window.Pos, and Window.FrameSize
* glfw: Make enum value name the same format as other enum value names
* glfw: Window hints rework patch
* glfw: Relegate `Window.hint` to testing; move it down to just above the tests to reflect this, add doc comment line
* glfw: handle error `Error.InvalidEnum` explicitly, for clear error message in this unlikely edge case
* glfw: instate `Hint.context_no_error` as a hint, as it actually is specified to be a Window creation hint by the docs, and affirm removal of `Hint.context_revision`, which isn't.
The docs don't seem to specify a default value for `Hints.context_no_error` to take on, so we could set it based on `std.debug.runtime_safety` like this.
* glfw: default `context_no_error` to `false`, and added a note of caution about its usage as suggested.
* glfw: Inline enum values of `ClientApi`, `ContextCreationApi`, `ContextRobustness`, `ContextReleaseBehavior`, and `OpenGlProfile` from consts.zig, and remove the now unused constants (replaced by aformentioned enum values).
* glfw: Reference `Window.Hint` enum instead of `Window.Hints` struct to ensure fields are the same
* glfw: add comment explaining default values of `Window.Hints`
* glfw: change `OpenGlProfile` to `OpenGLProfile` based on established naming convention
* glfw: Update actual declaration of `OpenGLProfile`
* glfw: call `Window.defaultHints` after window creation, not before
* glfw: remove 'consts.zig', and move `dont_care` directly into 'main.zig'; fix anything referencing it.
* glfw: put `Window.defaultHints` into defer statement to handle cleanup in all paths
* glfw: move `Hint.focused` to match position of `Hints.focused`
* glfw: do 'zig fmt glfw/src'
* glfw: Cull `Window.Hint` comments, polish remaining; match order entirely according to current GLFW docs
* glfw: Change `Window.Hints.*Api` to `Window.Hints.*API`
Co-authored-by: Stephen Gutekanst <stephen@hexops.com>
2021-11-16 02:41:16 +01:00
const window = glfw . Window . create ( 640 , 480 , " Hello, Zig! " , null , null , . { } ) catch | err | {
2021-07-23 15:02:13 -07:00
// return without fail, because most of our CI environments are headless / we cannot open
// windows on them.
std . debug . print ( " note: failed to create window: {} \n " , . { err } ) ;
return ;
} ;
defer window . destroy ( ) ;
_ = try window . setSize ( . { . width = 640 , . height = 480 } ) ;
}
2021-07-23 14:29:14 -07:00
test " setSizeLimits " {
2021-11-10 11:38:43 +01:00
try glfw . init ( . { } ) ;
2021-07-23 14:29:14 -07:00
defer glfw . terminate ( ) ;
glfw: window hints rework (#71)
* glfw: make comments into doc comments
* glfw: Publicize Window.CursorPos, Window.Size, Window.Pos, and Window.FrameSize
* glfw: Make enum value name the same format as other enum value names
* glfw: Window hints rework patch
* glfw: Relegate `Window.hint` to testing; move it down to just above the tests to reflect this, add doc comment line
* glfw: handle error `Error.InvalidEnum` explicitly, for clear error message in this unlikely edge case
* glfw: instate `Hint.context_no_error` as a hint, as it actually is specified to be a Window creation hint by the docs, and affirm removal of `Hint.context_revision`, which isn't.
The docs don't seem to specify a default value for `Hints.context_no_error` to take on, so we could set it based on `std.debug.runtime_safety` like this.
* glfw: default `context_no_error` to `false`, and added a note of caution about its usage as suggested.
* glfw: Inline enum values of `ClientApi`, `ContextCreationApi`, `ContextRobustness`, `ContextReleaseBehavior`, and `OpenGlProfile` from consts.zig, and remove the now unused constants (replaced by aformentioned enum values).
* glfw: Reference `Window.Hint` enum instead of `Window.Hints` struct to ensure fields are the same
* glfw: add comment explaining default values of `Window.Hints`
* glfw: change `OpenGlProfile` to `OpenGLProfile` based on established naming convention
* glfw: Update actual declaration of `OpenGLProfile`
* glfw: call `Window.defaultHints` after window creation, not before
* glfw: remove 'consts.zig', and move `dont_care` directly into 'main.zig'; fix anything referencing it.
* glfw: put `Window.defaultHints` into defer statement to handle cleanup in all paths
* glfw: move `Hint.focused` to match position of `Hints.focused`
* glfw: do 'zig fmt glfw/src'
* glfw: Cull `Window.Hint` comments, polish remaining; match order entirely according to current GLFW docs
* glfw: Change `Window.Hints.*Api` to `Window.Hints.*API`
Co-authored-by: Stephen Gutekanst <stephen@hexops.com>
2021-11-16 02:41:16 +01:00
const window = glfw . Window . create ( 640 , 480 , " Hello, Zig! " , null , null , . { } ) catch | err | {
2021-07-23 14:29:14 -07:00
// return without fail, because most of our CI environments are headless / we cannot open
// windows on them.
std . debug . print ( " note: failed to create window: {} \n " , . { err } ) ;
return ;
} ;
defer window . destroy ( ) ;
try window . setSizeLimits (
. { . width = 720 , . height = 480 } ,
. { . width = 1080 , . height = 1920 } ,
) ;
}
2021-07-23 14:43:04 -07:00
test " setAspectRatio " {
2021-11-10 11:38:43 +01:00
try glfw . init ( . { } ) ;
2021-07-23 14:43:04 -07:00
defer glfw . terminate ( ) ;
glfw: window hints rework (#71)
* glfw: make comments into doc comments
* glfw: Publicize Window.CursorPos, Window.Size, Window.Pos, and Window.FrameSize
* glfw: Make enum value name the same format as other enum value names
* glfw: Window hints rework patch
* glfw: Relegate `Window.hint` to testing; move it down to just above the tests to reflect this, add doc comment line
* glfw: handle error `Error.InvalidEnum` explicitly, for clear error message in this unlikely edge case
* glfw: instate `Hint.context_no_error` as a hint, as it actually is specified to be a Window creation hint by the docs, and affirm removal of `Hint.context_revision`, which isn't.
The docs don't seem to specify a default value for `Hints.context_no_error` to take on, so we could set it based on `std.debug.runtime_safety` like this.
* glfw: default `context_no_error` to `false`, and added a note of caution about its usage as suggested.
* glfw: Inline enum values of `ClientApi`, `ContextCreationApi`, `ContextRobustness`, `ContextReleaseBehavior`, and `OpenGlProfile` from consts.zig, and remove the now unused constants (replaced by aformentioned enum values).
* glfw: Reference `Window.Hint` enum instead of `Window.Hints` struct to ensure fields are the same
* glfw: add comment explaining default values of `Window.Hints`
* glfw: change `OpenGlProfile` to `OpenGLProfile` based on established naming convention
* glfw: Update actual declaration of `OpenGLProfile`
* glfw: call `Window.defaultHints` after window creation, not before
* glfw: remove 'consts.zig', and move `dont_care` directly into 'main.zig'; fix anything referencing it.
* glfw: put `Window.defaultHints` into defer statement to handle cleanup in all paths
* glfw: move `Hint.focused` to match position of `Hints.focused`
* glfw: do 'zig fmt glfw/src'
* glfw: Cull `Window.Hint` comments, polish remaining; match order entirely according to current GLFW docs
* glfw: Change `Window.Hints.*Api` to `Window.Hints.*API`
Co-authored-by: Stephen Gutekanst <stephen@hexops.com>
2021-11-16 02:41:16 +01:00
const window = glfw . Window . create ( 640 , 480 , " Hello, Zig! " , null , null , . { } ) catch | err | {
2021-07-23 14:43:04 -07:00
// return without fail, because most of our CI environments are headless / we cannot open
// windows on them.
std . debug . print ( " note: failed to create window: {} \n " , . { err } ) ;
return ;
} ;
defer window . destroy ( ) ;
try window . setAspectRatio ( 4 , 3 ) ;
}
2021-07-23 17:35:33 -07:00
test " getFramebufferSize " {
2021-11-10 11:38:43 +01:00
try glfw . init ( . { } ) ;
2021-07-23 17:35:33 -07:00
defer glfw . terminate ( ) ;
glfw: window hints rework (#71)
* glfw: make comments into doc comments
* glfw: Publicize Window.CursorPos, Window.Size, Window.Pos, and Window.FrameSize
* glfw: Make enum value name the same format as other enum value names
* glfw: Window hints rework patch
* glfw: Relegate `Window.hint` to testing; move it down to just above the tests to reflect this, add doc comment line
* glfw: handle error `Error.InvalidEnum` explicitly, for clear error message in this unlikely edge case
* glfw: instate `Hint.context_no_error` as a hint, as it actually is specified to be a Window creation hint by the docs, and affirm removal of `Hint.context_revision`, which isn't.
The docs don't seem to specify a default value for `Hints.context_no_error` to take on, so we could set it based on `std.debug.runtime_safety` like this.
* glfw: default `context_no_error` to `false`, and added a note of caution about its usage as suggested.
* glfw: Inline enum values of `ClientApi`, `ContextCreationApi`, `ContextRobustness`, `ContextReleaseBehavior`, and `OpenGlProfile` from consts.zig, and remove the now unused constants (replaced by aformentioned enum values).
* glfw: Reference `Window.Hint` enum instead of `Window.Hints` struct to ensure fields are the same
* glfw: add comment explaining default values of `Window.Hints`
* glfw: change `OpenGlProfile` to `OpenGLProfile` based on established naming convention
* glfw: Update actual declaration of `OpenGLProfile`
* glfw: call `Window.defaultHints` after window creation, not before
* glfw: remove 'consts.zig', and move `dont_care` directly into 'main.zig'; fix anything referencing it.
* glfw: put `Window.defaultHints` into defer statement to handle cleanup in all paths
* glfw: move `Hint.focused` to match position of `Hints.focused`
* glfw: do 'zig fmt glfw/src'
* glfw: Cull `Window.Hint` comments, polish remaining; match order entirely according to current GLFW docs
* glfw: Change `Window.Hints.*Api` to `Window.Hints.*API`
Co-authored-by: Stephen Gutekanst <stephen@hexops.com>
2021-11-16 02:41:16 +01:00
const window = glfw . Window . create ( 640 , 480 , " Hello, Zig! " , null , null , . { } ) catch | err | {
2021-07-23 17:35:33 -07:00
// return without fail, because most of our CI environments are headless / we cannot open
// windows on them.
std . debug . print ( " note: failed to create window: {} \n " , . { err } ) ;
return ;
} ;
defer window . destroy ( ) ;
_ = try window . getFramebufferSize ( ) ;
}
2021-07-23 17:43:24 -07:00
test " getFrameSize " {
2021-11-10 11:38:43 +01:00
try glfw . init ( . { } ) ;
2021-07-23 17:43:24 -07:00
defer glfw . terminate ( ) ;
glfw: window hints rework (#71)
* glfw: make comments into doc comments
* glfw: Publicize Window.CursorPos, Window.Size, Window.Pos, and Window.FrameSize
* glfw: Make enum value name the same format as other enum value names
* glfw: Window hints rework patch
* glfw: Relegate `Window.hint` to testing; move it down to just above the tests to reflect this, add doc comment line
* glfw: handle error `Error.InvalidEnum` explicitly, for clear error message in this unlikely edge case
* glfw: instate `Hint.context_no_error` as a hint, as it actually is specified to be a Window creation hint by the docs, and affirm removal of `Hint.context_revision`, which isn't.
The docs don't seem to specify a default value for `Hints.context_no_error` to take on, so we could set it based on `std.debug.runtime_safety` like this.
* glfw: default `context_no_error` to `false`, and added a note of caution about its usage as suggested.
* glfw: Inline enum values of `ClientApi`, `ContextCreationApi`, `ContextRobustness`, `ContextReleaseBehavior`, and `OpenGlProfile` from consts.zig, and remove the now unused constants (replaced by aformentioned enum values).
* glfw: Reference `Window.Hint` enum instead of `Window.Hints` struct to ensure fields are the same
* glfw: add comment explaining default values of `Window.Hints`
* glfw: change `OpenGlProfile` to `OpenGLProfile` based on established naming convention
* glfw: Update actual declaration of `OpenGLProfile`
* glfw: call `Window.defaultHints` after window creation, not before
* glfw: remove 'consts.zig', and move `dont_care` directly into 'main.zig'; fix anything referencing it.
* glfw: put `Window.defaultHints` into defer statement to handle cleanup in all paths
* glfw: move `Hint.focused` to match position of `Hints.focused`
* glfw: do 'zig fmt glfw/src'
* glfw: Cull `Window.Hint` comments, polish remaining; match order entirely according to current GLFW docs
* glfw: Change `Window.Hints.*Api` to `Window.Hints.*API`
Co-authored-by: Stephen Gutekanst <stephen@hexops.com>
2021-11-16 02:41:16 +01:00
const window = glfw . Window . create ( 640 , 480 , " Hello, Zig! " , null , null , . { } ) catch | err | {
2021-07-23 17:43:24 -07:00
// return without fail, because most of our CI environments are headless / we cannot open
// windows on them.
std . debug . print ( " note: failed to create window: {} \n " , . { err } ) ;
return ;
} ;
defer window . destroy ( ) ;
_ = try window . getFrameSize ( ) ;
}
2021-07-25 19:34:09 -07:00
test " getContentScale " {
2021-11-10 11:38:43 +01:00
try glfw . init ( . { } ) ;
2021-07-25 19:34:09 -07:00
defer glfw . terminate ( ) ;
glfw: window hints rework (#71)
* glfw: make comments into doc comments
* glfw: Publicize Window.CursorPos, Window.Size, Window.Pos, and Window.FrameSize
* glfw: Make enum value name the same format as other enum value names
* glfw: Window hints rework patch
* glfw: Relegate `Window.hint` to testing; move it down to just above the tests to reflect this, add doc comment line
* glfw: handle error `Error.InvalidEnum` explicitly, for clear error message in this unlikely edge case
* glfw: instate `Hint.context_no_error` as a hint, as it actually is specified to be a Window creation hint by the docs, and affirm removal of `Hint.context_revision`, which isn't.
The docs don't seem to specify a default value for `Hints.context_no_error` to take on, so we could set it based on `std.debug.runtime_safety` like this.
* glfw: default `context_no_error` to `false`, and added a note of caution about its usage as suggested.
* glfw: Inline enum values of `ClientApi`, `ContextCreationApi`, `ContextRobustness`, `ContextReleaseBehavior`, and `OpenGlProfile` from consts.zig, and remove the now unused constants (replaced by aformentioned enum values).
* glfw: Reference `Window.Hint` enum instead of `Window.Hints` struct to ensure fields are the same
* glfw: add comment explaining default values of `Window.Hints`
* glfw: change `OpenGlProfile` to `OpenGLProfile` based on established naming convention
* glfw: Update actual declaration of `OpenGLProfile`
* glfw: call `Window.defaultHints` after window creation, not before
* glfw: remove 'consts.zig', and move `dont_care` directly into 'main.zig'; fix anything referencing it.
* glfw: put `Window.defaultHints` into defer statement to handle cleanup in all paths
* glfw: move `Hint.focused` to match position of `Hints.focused`
* glfw: do 'zig fmt glfw/src'
* glfw: Cull `Window.Hint` comments, polish remaining; match order entirely according to current GLFW docs
* glfw: Change `Window.Hints.*Api` to `Window.Hints.*API`
Co-authored-by: Stephen Gutekanst <stephen@hexops.com>
2021-11-16 02:41:16 +01:00
const window = glfw . Window . create ( 640 , 480 , " Hello, Zig! " , null , null , . { } ) catch | err | {
2021-07-25 19:34:09 -07:00
// return without fail, because most of our CI environments are headless / we cannot open
// windows on them.
std . debug . print ( " note: failed to create window: {} \n " , . { err } ) ;
return ;
} ;
defer window . destroy ( ) ;
_ = try window . getContentScale ( ) ;
}
2021-07-25 19:36:41 -07:00
test " getOpacity " {
2021-11-10 11:38:43 +01:00
try glfw . init ( . { } ) ;
2021-07-25 19:36:41 -07:00
defer glfw . terminate ( ) ;
glfw: window hints rework (#71)
* glfw: make comments into doc comments
* glfw: Publicize Window.CursorPos, Window.Size, Window.Pos, and Window.FrameSize
* glfw: Make enum value name the same format as other enum value names
* glfw: Window hints rework patch
* glfw: Relegate `Window.hint` to testing; move it down to just above the tests to reflect this, add doc comment line
* glfw: handle error `Error.InvalidEnum` explicitly, for clear error message in this unlikely edge case
* glfw: instate `Hint.context_no_error` as a hint, as it actually is specified to be a Window creation hint by the docs, and affirm removal of `Hint.context_revision`, which isn't.
The docs don't seem to specify a default value for `Hints.context_no_error` to take on, so we could set it based on `std.debug.runtime_safety` like this.
* glfw: default `context_no_error` to `false`, and added a note of caution about its usage as suggested.
* glfw: Inline enum values of `ClientApi`, `ContextCreationApi`, `ContextRobustness`, `ContextReleaseBehavior`, and `OpenGlProfile` from consts.zig, and remove the now unused constants (replaced by aformentioned enum values).
* glfw: Reference `Window.Hint` enum instead of `Window.Hints` struct to ensure fields are the same
* glfw: add comment explaining default values of `Window.Hints`
* glfw: change `OpenGlProfile` to `OpenGLProfile` based on established naming convention
* glfw: Update actual declaration of `OpenGLProfile`
* glfw: call `Window.defaultHints` after window creation, not before
* glfw: remove 'consts.zig', and move `dont_care` directly into 'main.zig'; fix anything referencing it.
* glfw: put `Window.defaultHints` into defer statement to handle cleanup in all paths
* glfw: move `Hint.focused` to match position of `Hints.focused`
* glfw: do 'zig fmt glfw/src'
* glfw: Cull `Window.Hint` comments, polish remaining; match order entirely according to current GLFW docs
* glfw: Change `Window.Hints.*Api` to `Window.Hints.*API`
Co-authored-by: Stephen Gutekanst <stephen@hexops.com>
2021-11-16 02:41:16 +01:00
const window = glfw . Window . create ( 640 , 480 , " Hello, Zig! " , null , null , . { } ) catch | err | {
2021-07-25 19:36:41 -07:00
// return without fail, because most of our CI environments are headless / we cannot open
// windows on them.
std . debug . print ( " note: failed to create window: {} \n " , . { err } ) ;
return ;
} ;
defer window . destroy ( ) ;
_ = try window . getOpacity ( ) ;
}
2021-07-25 19:44:04 -07:00
test " iconify " {
2021-11-10 11:38:43 +01:00
try glfw . init ( . { } ) ;
2021-07-25 19:44:04 -07:00
defer glfw . terminate ( ) ;
glfw: window hints rework (#71)
* glfw: make comments into doc comments
* glfw: Publicize Window.CursorPos, Window.Size, Window.Pos, and Window.FrameSize
* glfw: Make enum value name the same format as other enum value names
* glfw: Window hints rework patch
* glfw: Relegate `Window.hint` to testing; move it down to just above the tests to reflect this, add doc comment line
* glfw: handle error `Error.InvalidEnum` explicitly, for clear error message in this unlikely edge case
* glfw: instate `Hint.context_no_error` as a hint, as it actually is specified to be a Window creation hint by the docs, and affirm removal of `Hint.context_revision`, which isn't.
The docs don't seem to specify a default value for `Hints.context_no_error` to take on, so we could set it based on `std.debug.runtime_safety` like this.
* glfw: default `context_no_error` to `false`, and added a note of caution about its usage as suggested.
* glfw: Inline enum values of `ClientApi`, `ContextCreationApi`, `ContextRobustness`, `ContextReleaseBehavior`, and `OpenGlProfile` from consts.zig, and remove the now unused constants (replaced by aformentioned enum values).
* glfw: Reference `Window.Hint` enum instead of `Window.Hints` struct to ensure fields are the same
* glfw: add comment explaining default values of `Window.Hints`
* glfw: change `OpenGlProfile` to `OpenGLProfile` based on established naming convention
* glfw: Update actual declaration of `OpenGLProfile`
* glfw: call `Window.defaultHints` after window creation, not before
* glfw: remove 'consts.zig', and move `dont_care` directly into 'main.zig'; fix anything referencing it.
* glfw: put `Window.defaultHints` into defer statement to handle cleanup in all paths
* glfw: move `Hint.focused` to match position of `Hints.focused`
* glfw: do 'zig fmt glfw/src'
* glfw: Cull `Window.Hint` comments, polish remaining; match order entirely according to current GLFW docs
* glfw: Change `Window.Hints.*Api` to `Window.Hints.*API`
Co-authored-by: Stephen Gutekanst <stephen@hexops.com>
2021-11-16 02:41:16 +01:00
const window = glfw . Window . create ( 640 , 480 , " Hello, Zig! " , null , null , . { } ) catch | err | {
2021-07-25 19:44:04 -07:00
// return without fail, because most of our CI environments are headless / we cannot open
// windows on them.
std . debug . print ( " note: failed to create window: {} \n " , . { err } ) ;
return ;
} ;
defer window . destroy ( ) ;
_ = window . iconify ( ) catch | err | std . debug . print ( " can't iconify window, wayland maybe? error={} \n " , . { err } ) ;
}
2021-10-16 14:00:37 -07:00
test " restore " {
2021-11-10 11:38:43 +01:00
try glfw . init ( . { } ) ;
2021-10-16 14:00:37 -07:00
defer glfw . terminate ( ) ;
glfw: window hints rework (#71)
* glfw: make comments into doc comments
* glfw: Publicize Window.CursorPos, Window.Size, Window.Pos, and Window.FrameSize
* glfw: Make enum value name the same format as other enum value names
* glfw: Window hints rework patch
* glfw: Relegate `Window.hint` to testing; move it down to just above the tests to reflect this, add doc comment line
* glfw: handle error `Error.InvalidEnum` explicitly, for clear error message in this unlikely edge case
* glfw: instate `Hint.context_no_error` as a hint, as it actually is specified to be a Window creation hint by the docs, and affirm removal of `Hint.context_revision`, which isn't.
The docs don't seem to specify a default value for `Hints.context_no_error` to take on, so we could set it based on `std.debug.runtime_safety` like this.
* glfw: default `context_no_error` to `false`, and added a note of caution about its usage as suggested.
* glfw: Inline enum values of `ClientApi`, `ContextCreationApi`, `ContextRobustness`, `ContextReleaseBehavior`, and `OpenGlProfile` from consts.zig, and remove the now unused constants (replaced by aformentioned enum values).
* glfw: Reference `Window.Hint` enum instead of `Window.Hints` struct to ensure fields are the same
* glfw: add comment explaining default values of `Window.Hints`
* glfw: change `OpenGlProfile` to `OpenGLProfile` based on established naming convention
* glfw: Update actual declaration of `OpenGLProfile`
* glfw: call `Window.defaultHints` after window creation, not before
* glfw: remove 'consts.zig', and move `dont_care` directly into 'main.zig'; fix anything referencing it.
* glfw: put `Window.defaultHints` into defer statement to handle cleanup in all paths
* glfw: move `Hint.focused` to match position of `Hints.focused`
* glfw: do 'zig fmt glfw/src'
* glfw: Cull `Window.Hint` comments, polish remaining; match order entirely according to current GLFW docs
* glfw: Change `Window.Hints.*Api` to `Window.Hints.*API`
Co-authored-by: Stephen Gutekanst <stephen@hexops.com>
2021-11-16 02:41:16 +01:00
const window = glfw . Window . create ( 640 , 480 , " Hello, Zig! " , null , null , . { } ) catch | err | {
2021-10-16 14:00:37 -07:00
// return without fail, because most of our CI environments are headless / we cannot open
// windows on them.
std . debug . print ( " note: failed to create window: {} \n " , . { err } ) ;
return ;
} ;
defer window . destroy ( ) ;
_ = window . restore ( ) catch | err | std . debug . print ( " can't restore window, not supported by OS maybe? error={} \n " , . { err } ) ;
}
2021-10-16 14:05:54 -07:00
test " maximize " {
2021-11-10 11:38:43 +01:00
try glfw . init ( . { } ) ;
2021-10-16 14:05:54 -07:00
defer glfw . terminate ( ) ;
glfw: window hints rework (#71)
* glfw: make comments into doc comments
* glfw: Publicize Window.CursorPos, Window.Size, Window.Pos, and Window.FrameSize
* glfw: Make enum value name the same format as other enum value names
* glfw: Window hints rework patch
* glfw: Relegate `Window.hint` to testing; move it down to just above the tests to reflect this, add doc comment line
* glfw: handle error `Error.InvalidEnum` explicitly, for clear error message in this unlikely edge case
* glfw: instate `Hint.context_no_error` as a hint, as it actually is specified to be a Window creation hint by the docs, and affirm removal of `Hint.context_revision`, which isn't.
The docs don't seem to specify a default value for `Hints.context_no_error` to take on, so we could set it based on `std.debug.runtime_safety` like this.
* glfw: default `context_no_error` to `false`, and added a note of caution about its usage as suggested.
* glfw: Inline enum values of `ClientApi`, `ContextCreationApi`, `ContextRobustness`, `ContextReleaseBehavior`, and `OpenGlProfile` from consts.zig, and remove the now unused constants (replaced by aformentioned enum values).
* glfw: Reference `Window.Hint` enum instead of `Window.Hints` struct to ensure fields are the same
* glfw: add comment explaining default values of `Window.Hints`
* glfw: change `OpenGlProfile` to `OpenGLProfile` based on established naming convention
* glfw: Update actual declaration of `OpenGLProfile`
* glfw: call `Window.defaultHints` after window creation, not before
* glfw: remove 'consts.zig', and move `dont_care` directly into 'main.zig'; fix anything referencing it.
* glfw: put `Window.defaultHints` into defer statement to handle cleanup in all paths
* glfw: move `Hint.focused` to match position of `Hints.focused`
* glfw: do 'zig fmt glfw/src'
* glfw: Cull `Window.Hint` comments, polish remaining; match order entirely according to current GLFW docs
* glfw: Change `Window.Hints.*Api` to `Window.Hints.*API`
Co-authored-by: Stephen Gutekanst <stephen@hexops.com>
2021-11-16 02:41:16 +01:00
const window = glfw . Window . create ( 640 , 480 , " Hello, Zig! " , null , null , . { } ) catch | err | {
2021-10-16 14:05:54 -07:00
// return without fail, because most of our CI environments are headless / we cannot open
// windows on them.
std . debug . print ( " note: failed to create window: {} \n " , . { err } ) ;
return ;
} ;
defer window . destroy ( ) ;
_ = window . maximize ( ) catch | err | std . debug . print ( " can't maximize window, not supported by OS maybe? error={} \n " , . { err } ) ;
}
2021-10-16 14:09:06 -07:00
test " show " {
2021-11-10 11:38:43 +01:00
try glfw . init ( . { } ) ;
2021-10-16 14:09:06 -07:00
defer glfw . terminate ( ) ;
glfw: window hints rework (#71)
* glfw: make comments into doc comments
* glfw: Publicize Window.CursorPos, Window.Size, Window.Pos, and Window.FrameSize
* glfw: Make enum value name the same format as other enum value names
* glfw: Window hints rework patch
* glfw: Relegate `Window.hint` to testing; move it down to just above the tests to reflect this, add doc comment line
* glfw: handle error `Error.InvalidEnum` explicitly, for clear error message in this unlikely edge case
* glfw: instate `Hint.context_no_error` as a hint, as it actually is specified to be a Window creation hint by the docs, and affirm removal of `Hint.context_revision`, which isn't.
The docs don't seem to specify a default value for `Hints.context_no_error` to take on, so we could set it based on `std.debug.runtime_safety` like this.
* glfw: default `context_no_error` to `false`, and added a note of caution about its usage as suggested.
* glfw: Inline enum values of `ClientApi`, `ContextCreationApi`, `ContextRobustness`, `ContextReleaseBehavior`, and `OpenGlProfile` from consts.zig, and remove the now unused constants (replaced by aformentioned enum values).
* glfw: Reference `Window.Hint` enum instead of `Window.Hints` struct to ensure fields are the same
* glfw: add comment explaining default values of `Window.Hints`
* glfw: change `OpenGlProfile` to `OpenGLProfile` based on established naming convention
* glfw: Update actual declaration of `OpenGLProfile`
* glfw: call `Window.defaultHints` after window creation, not before
* glfw: remove 'consts.zig', and move `dont_care` directly into 'main.zig'; fix anything referencing it.
* glfw: put `Window.defaultHints` into defer statement to handle cleanup in all paths
* glfw: move `Hint.focused` to match position of `Hints.focused`
* glfw: do 'zig fmt glfw/src'
* glfw: Cull `Window.Hint` comments, polish remaining; match order entirely according to current GLFW docs
* glfw: Change `Window.Hints.*Api` to `Window.Hints.*API`
Co-authored-by: Stephen Gutekanst <stephen@hexops.com>
2021-11-16 02:41:16 +01:00
const window = glfw . Window . create ( 640 , 480 , " Hello, Zig! " , null , null , . { } ) catch | err | {
2021-10-16 14:09:06 -07:00
// return without fail, because most of our CI environments are headless / we cannot open
// windows on them.
std . debug . print ( " note: failed to create window: {} \n " , . { err } ) ;
return ;
} ;
defer window . destroy ( ) ;
_ = window . show ( ) catch | err | std . debug . print ( " can't show window, not supported by OS maybe? error={} \n " , . { err } ) ;
}
2021-10-16 14:12:13 -07:00
test " hide " {
2021-11-10 11:38:43 +01:00
try glfw . init ( . { } ) ;
2021-10-16 14:12:13 -07:00
defer glfw . terminate ( ) ;
glfw: window hints rework (#71)
* glfw: make comments into doc comments
* glfw: Publicize Window.CursorPos, Window.Size, Window.Pos, and Window.FrameSize
* glfw: Make enum value name the same format as other enum value names
* glfw: Window hints rework patch
* glfw: Relegate `Window.hint` to testing; move it down to just above the tests to reflect this, add doc comment line
* glfw: handle error `Error.InvalidEnum` explicitly, for clear error message in this unlikely edge case
* glfw: instate `Hint.context_no_error` as a hint, as it actually is specified to be a Window creation hint by the docs, and affirm removal of `Hint.context_revision`, which isn't.
The docs don't seem to specify a default value for `Hints.context_no_error` to take on, so we could set it based on `std.debug.runtime_safety` like this.
* glfw: default `context_no_error` to `false`, and added a note of caution about its usage as suggested.
* glfw: Inline enum values of `ClientApi`, `ContextCreationApi`, `ContextRobustness`, `ContextReleaseBehavior`, and `OpenGlProfile` from consts.zig, and remove the now unused constants (replaced by aformentioned enum values).
* glfw: Reference `Window.Hint` enum instead of `Window.Hints` struct to ensure fields are the same
* glfw: add comment explaining default values of `Window.Hints`
* glfw: change `OpenGlProfile` to `OpenGLProfile` based on established naming convention
* glfw: Update actual declaration of `OpenGLProfile`
* glfw: call `Window.defaultHints` after window creation, not before
* glfw: remove 'consts.zig', and move `dont_care` directly into 'main.zig'; fix anything referencing it.
* glfw: put `Window.defaultHints` into defer statement to handle cleanup in all paths
* glfw: move `Hint.focused` to match position of `Hints.focused`
* glfw: do 'zig fmt glfw/src'
* glfw: Cull `Window.Hint` comments, polish remaining; match order entirely according to current GLFW docs
* glfw: Change `Window.Hints.*Api` to `Window.Hints.*API`
Co-authored-by: Stephen Gutekanst <stephen@hexops.com>
2021-11-16 02:41:16 +01:00
const window = glfw . Window . create ( 640 , 480 , " Hello, Zig! " , null , null , . { } ) catch | err | {
2021-10-16 14:12:13 -07:00
// return without fail, because most of our CI environments are headless / we cannot open
// windows on them.
std . debug . print ( " note: failed to create window: {} \n " , . { err } ) ;
return ;
} ;
defer window . destroy ( ) ;
_ = window . hide ( ) catch | err | std . debug . print ( " can't hide window, not supported by OS maybe? error={} \n " , . { err } ) ;
}
2021-10-16 14:16:11 -07:00
test " focus " {
2021-11-10 11:38:43 +01:00
try glfw . init ( . { } ) ;
2021-10-16 14:16:11 -07:00
defer glfw . terminate ( ) ;
glfw: window hints rework (#71)
* glfw: make comments into doc comments
* glfw: Publicize Window.CursorPos, Window.Size, Window.Pos, and Window.FrameSize
* glfw: Make enum value name the same format as other enum value names
* glfw: Window hints rework patch
* glfw: Relegate `Window.hint` to testing; move it down to just above the tests to reflect this, add doc comment line
* glfw: handle error `Error.InvalidEnum` explicitly, for clear error message in this unlikely edge case
* glfw: instate `Hint.context_no_error` as a hint, as it actually is specified to be a Window creation hint by the docs, and affirm removal of `Hint.context_revision`, which isn't.
The docs don't seem to specify a default value for `Hints.context_no_error` to take on, so we could set it based on `std.debug.runtime_safety` like this.
* glfw: default `context_no_error` to `false`, and added a note of caution about its usage as suggested.
* glfw: Inline enum values of `ClientApi`, `ContextCreationApi`, `ContextRobustness`, `ContextReleaseBehavior`, and `OpenGlProfile` from consts.zig, and remove the now unused constants (replaced by aformentioned enum values).
* glfw: Reference `Window.Hint` enum instead of `Window.Hints` struct to ensure fields are the same
* glfw: add comment explaining default values of `Window.Hints`
* glfw: change `OpenGlProfile` to `OpenGLProfile` based on established naming convention
* glfw: Update actual declaration of `OpenGLProfile`
* glfw: call `Window.defaultHints` after window creation, not before
* glfw: remove 'consts.zig', and move `dont_care` directly into 'main.zig'; fix anything referencing it.
* glfw: put `Window.defaultHints` into defer statement to handle cleanup in all paths
* glfw: move `Hint.focused` to match position of `Hints.focused`
* glfw: do 'zig fmt glfw/src'
* glfw: Cull `Window.Hint` comments, polish remaining; match order entirely according to current GLFW docs
* glfw: Change `Window.Hints.*Api` to `Window.Hints.*API`
Co-authored-by: Stephen Gutekanst <stephen@hexops.com>
2021-11-16 02:41:16 +01:00
const window = glfw . Window . create ( 640 , 480 , " Hello, Zig! " , null , null , . { } ) catch | err | {
2021-10-16 14:16:11 -07:00
// return without fail, because most of our CI environments are headless / we cannot open
// windows on them.
std . debug . print ( " note: failed to create window: {} \n " , . { err } ) ;
return ;
} ;
defer window . destroy ( ) ;
_ = window . focus ( ) catch | err | std . debug . print ( " can't focus window, wayland maybe? error={} \n " , . { err } ) ;
}
2021-10-16 14:22:51 -07:00
test " requestAttention " {
2021-11-10 11:38:43 +01:00
try glfw . init ( . { } ) ;
2021-10-16 14:22:51 -07:00
defer glfw . terminate ( ) ;
glfw: window hints rework (#71)
* glfw: make comments into doc comments
* glfw: Publicize Window.CursorPos, Window.Size, Window.Pos, and Window.FrameSize
* glfw: Make enum value name the same format as other enum value names
* glfw: Window hints rework patch
* glfw: Relegate `Window.hint` to testing; move it down to just above the tests to reflect this, add doc comment line
* glfw: handle error `Error.InvalidEnum` explicitly, for clear error message in this unlikely edge case
* glfw: instate `Hint.context_no_error` as a hint, as it actually is specified to be a Window creation hint by the docs, and affirm removal of `Hint.context_revision`, which isn't.
The docs don't seem to specify a default value for `Hints.context_no_error` to take on, so we could set it based on `std.debug.runtime_safety` like this.
* glfw: default `context_no_error` to `false`, and added a note of caution about its usage as suggested.
* glfw: Inline enum values of `ClientApi`, `ContextCreationApi`, `ContextRobustness`, `ContextReleaseBehavior`, and `OpenGlProfile` from consts.zig, and remove the now unused constants (replaced by aformentioned enum values).
* glfw: Reference `Window.Hint` enum instead of `Window.Hints` struct to ensure fields are the same
* glfw: add comment explaining default values of `Window.Hints`
* glfw: change `OpenGlProfile` to `OpenGLProfile` based on established naming convention
* glfw: Update actual declaration of `OpenGLProfile`
* glfw: call `Window.defaultHints` after window creation, not before
* glfw: remove 'consts.zig', and move `dont_care` directly into 'main.zig'; fix anything referencing it.
* glfw: put `Window.defaultHints` into defer statement to handle cleanup in all paths
* glfw: move `Hint.focused` to match position of `Hints.focused`
* glfw: do 'zig fmt glfw/src'
* glfw: Cull `Window.Hint` comments, polish remaining; match order entirely according to current GLFW docs
* glfw: Change `Window.Hints.*Api` to `Window.Hints.*API`
Co-authored-by: Stephen Gutekanst <stephen@hexops.com>
2021-11-16 02:41:16 +01:00
const window = glfw . Window . create ( 640 , 480 , " Hello, Zig! " , null , null , . { } ) catch | err | {
2021-10-16 14:22:51 -07:00
// return without fail, because most of our CI environments are headless / we cannot open
// windows on them.
std . debug . print ( " note: failed to create window: {} \n " , . { err } ) ;
return ;
} ;
defer window . destroy ( ) ;
_ = window . requestAttention ( ) catch | err | std . debug . print ( " can't request attention for window, not supported by OS maybe? error={} \n " , . { err } ) ;
}
2021-10-16 18:05:29 -07:00
test " swapBuffers " {
2021-11-10 11:38:43 +01:00
try glfw . init ( . { } ) ;
2021-10-16 18:05:29 -07:00
defer glfw . terminate ( ) ;
glfw: window hints rework (#71)
* glfw: make comments into doc comments
* glfw: Publicize Window.CursorPos, Window.Size, Window.Pos, and Window.FrameSize
* glfw: Make enum value name the same format as other enum value names
* glfw: Window hints rework patch
* glfw: Relegate `Window.hint` to testing; move it down to just above the tests to reflect this, add doc comment line
* glfw: handle error `Error.InvalidEnum` explicitly, for clear error message in this unlikely edge case
* glfw: instate `Hint.context_no_error` as a hint, as it actually is specified to be a Window creation hint by the docs, and affirm removal of `Hint.context_revision`, which isn't.
The docs don't seem to specify a default value for `Hints.context_no_error` to take on, so we could set it based on `std.debug.runtime_safety` like this.
* glfw: default `context_no_error` to `false`, and added a note of caution about its usage as suggested.
* glfw: Inline enum values of `ClientApi`, `ContextCreationApi`, `ContextRobustness`, `ContextReleaseBehavior`, and `OpenGlProfile` from consts.zig, and remove the now unused constants (replaced by aformentioned enum values).
* glfw: Reference `Window.Hint` enum instead of `Window.Hints` struct to ensure fields are the same
* glfw: add comment explaining default values of `Window.Hints`
* glfw: change `OpenGlProfile` to `OpenGLProfile` based on established naming convention
* glfw: Update actual declaration of `OpenGLProfile`
* glfw: call `Window.defaultHints` after window creation, not before
* glfw: remove 'consts.zig', and move `dont_care` directly into 'main.zig'; fix anything referencing it.
* glfw: put `Window.defaultHints` into defer statement to handle cleanup in all paths
* glfw: move `Hint.focused` to match position of `Hints.focused`
* glfw: do 'zig fmt glfw/src'
* glfw: Cull `Window.Hint` comments, polish remaining; match order entirely according to current GLFW docs
* glfw: Change `Window.Hints.*Api` to `Window.Hints.*API`
Co-authored-by: Stephen Gutekanst <stephen@hexops.com>
2021-11-16 02:41:16 +01:00
const window = glfw . Window . create ( 640 , 480 , " Hello, Zig! " , null , null , . { } ) catch | err | {
2021-10-16 18:05:29 -07:00
// return without fail, because most of our CI environments are headless / we cannot open
// windows on them.
std . debug . print ( " note: failed to create window: {} \n " , . { err } ) ;
return ;
} ;
defer window . destroy ( ) ;
_ = try window . swapBuffers ( ) ;
}
2021-10-17 22:42:16 -07:00
2021-10-18 01:03:11 -07:00
test " getMonitor " {
2021-11-10 11:38:43 +01:00
try glfw . init ( . { } ) ;
2021-10-18 01:03:11 -07:00
defer glfw . terminate ( ) ;
glfw: window hints rework (#71)
* glfw: make comments into doc comments
* glfw: Publicize Window.CursorPos, Window.Size, Window.Pos, and Window.FrameSize
* glfw: Make enum value name the same format as other enum value names
* glfw: Window hints rework patch
* glfw: Relegate `Window.hint` to testing; move it down to just above the tests to reflect this, add doc comment line
* glfw: handle error `Error.InvalidEnum` explicitly, for clear error message in this unlikely edge case
* glfw: instate `Hint.context_no_error` as a hint, as it actually is specified to be a Window creation hint by the docs, and affirm removal of `Hint.context_revision`, which isn't.
The docs don't seem to specify a default value for `Hints.context_no_error` to take on, so we could set it based on `std.debug.runtime_safety` like this.
* glfw: default `context_no_error` to `false`, and added a note of caution about its usage as suggested.
* glfw: Inline enum values of `ClientApi`, `ContextCreationApi`, `ContextRobustness`, `ContextReleaseBehavior`, and `OpenGlProfile` from consts.zig, and remove the now unused constants (replaced by aformentioned enum values).
* glfw: Reference `Window.Hint` enum instead of `Window.Hints` struct to ensure fields are the same
* glfw: add comment explaining default values of `Window.Hints`
* glfw: change `OpenGlProfile` to `OpenGLProfile` based on established naming convention
* glfw: Update actual declaration of `OpenGLProfile`
* glfw: call `Window.defaultHints` after window creation, not before
* glfw: remove 'consts.zig', and move `dont_care` directly into 'main.zig'; fix anything referencing it.
* glfw: put `Window.defaultHints` into defer statement to handle cleanup in all paths
* glfw: move `Hint.focused` to match position of `Hints.focused`
* glfw: do 'zig fmt glfw/src'
* glfw: Cull `Window.Hint` comments, polish remaining; match order entirely according to current GLFW docs
* glfw: Change `Window.Hints.*Api` to `Window.Hints.*API`
Co-authored-by: Stephen Gutekanst <stephen@hexops.com>
2021-11-16 02:41:16 +01:00
const window = glfw . Window . create ( 640 , 480 , " Hello, Zig! " , null , null , . { } ) catch | err | {
2021-10-18 01:03:11 -07:00
// return without fail, because most of our CI environments are headless / we cannot open
// windows on them.
std . debug . print ( " note: failed to create window: {} \n " , . { err } ) ;
return ;
} ;
defer window . destroy ( ) ;
_ = window . getMonitor ( ) catch | err | std . debug . print ( " can't get monitor, not supported by OS maybe? error={} \n " , . { err } ) ;
}
2021-10-17 22:42:16 -07:00
test " setMonitor " {
2021-11-10 11:38:43 +01:00
try glfw . init ( . { } ) ;
2021-10-17 22:42:16 -07:00
defer glfw . terminate ( ) ;
glfw: window hints rework (#71)
* glfw: make comments into doc comments
* glfw: Publicize Window.CursorPos, Window.Size, Window.Pos, and Window.FrameSize
* glfw: Make enum value name the same format as other enum value names
* glfw: Window hints rework patch
* glfw: Relegate `Window.hint` to testing; move it down to just above the tests to reflect this, add doc comment line
* glfw: handle error `Error.InvalidEnum` explicitly, for clear error message in this unlikely edge case
* glfw: instate `Hint.context_no_error` as a hint, as it actually is specified to be a Window creation hint by the docs, and affirm removal of `Hint.context_revision`, which isn't.
The docs don't seem to specify a default value for `Hints.context_no_error` to take on, so we could set it based on `std.debug.runtime_safety` like this.
* glfw: default `context_no_error` to `false`, and added a note of caution about its usage as suggested.
* glfw: Inline enum values of `ClientApi`, `ContextCreationApi`, `ContextRobustness`, `ContextReleaseBehavior`, and `OpenGlProfile` from consts.zig, and remove the now unused constants (replaced by aformentioned enum values).
* glfw: Reference `Window.Hint` enum instead of `Window.Hints` struct to ensure fields are the same
* glfw: add comment explaining default values of `Window.Hints`
* glfw: change `OpenGlProfile` to `OpenGLProfile` based on established naming convention
* glfw: Update actual declaration of `OpenGLProfile`
* glfw: call `Window.defaultHints` after window creation, not before
* glfw: remove 'consts.zig', and move `dont_care` directly into 'main.zig'; fix anything referencing it.
* glfw: put `Window.defaultHints` into defer statement to handle cleanup in all paths
* glfw: move `Hint.focused` to match position of `Hints.focused`
* glfw: do 'zig fmt glfw/src'
* glfw: Cull `Window.Hint` comments, polish remaining; match order entirely according to current GLFW docs
* glfw: Change `Window.Hints.*Api` to `Window.Hints.*API`
Co-authored-by: Stephen Gutekanst <stephen@hexops.com>
2021-11-16 02:41:16 +01:00
const window = glfw . Window . create ( 640 , 480 , " Hello, Zig! " , null , null , . { } ) catch | err | {
2021-10-17 22:42:16 -07:00
// return without fail, because most of our CI environments are headless / we cannot open
// windows on them.
std . debug . print ( " note: failed to create window: {} \n " , . { err } ) ;
return ;
} ;
defer window . destroy ( ) ;
window . setMonitor ( null , 10 , 10 , 640 , 480 , 60 ) catch | err | std . debug . print ( " can't set monitor, not supported by OS maybe? error={} \n " , . { err } ) ;
}
2021-10-17 22:48:41 -07:00
test " getAttrib " {
2021-11-10 11:38:43 +01:00
try glfw . init ( . { } ) ;
2021-10-17 22:48:41 -07:00
defer glfw . terminate ( ) ;
glfw: window hints rework (#71)
* glfw: make comments into doc comments
* glfw: Publicize Window.CursorPos, Window.Size, Window.Pos, and Window.FrameSize
* glfw: Make enum value name the same format as other enum value names
* glfw: Window hints rework patch
* glfw: Relegate `Window.hint` to testing; move it down to just above the tests to reflect this, add doc comment line
* glfw: handle error `Error.InvalidEnum` explicitly, for clear error message in this unlikely edge case
* glfw: instate `Hint.context_no_error` as a hint, as it actually is specified to be a Window creation hint by the docs, and affirm removal of `Hint.context_revision`, which isn't.
The docs don't seem to specify a default value for `Hints.context_no_error` to take on, so we could set it based on `std.debug.runtime_safety` like this.
* glfw: default `context_no_error` to `false`, and added a note of caution about its usage as suggested.
* glfw: Inline enum values of `ClientApi`, `ContextCreationApi`, `ContextRobustness`, `ContextReleaseBehavior`, and `OpenGlProfile` from consts.zig, and remove the now unused constants (replaced by aformentioned enum values).
* glfw: Reference `Window.Hint` enum instead of `Window.Hints` struct to ensure fields are the same
* glfw: add comment explaining default values of `Window.Hints`
* glfw: change `OpenGlProfile` to `OpenGLProfile` based on established naming convention
* glfw: Update actual declaration of `OpenGLProfile`
* glfw: call `Window.defaultHints` after window creation, not before
* glfw: remove 'consts.zig', and move `dont_care` directly into 'main.zig'; fix anything referencing it.
* glfw: put `Window.defaultHints` into defer statement to handle cleanup in all paths
* glfw: move `Hint.focused` to match position of `Hints.focused`
* glfw: do 'zig fmt glfw/src'
* glfw: Cull `Window.Hint` comments, polish remaining; match order entirely according to current GLFW docs
* glfw: Change `Window.Hints.*Api` to `Window.Hints.*API`
Co-authored-by: Stephen Gutekanst <stephen@hexops.com>
2021-11-16 02:41:16 +01:00
const window = glfw . Window . create ( 640 , 480 , " Hello, Zig! " , null , null , . { } ) catch | err | {
2021-10-17 22:48:41 -07:00
// return without fail, because most of our CI environments are headless / we cannot open
// windows on them.
std . debug . print ( " note: failed to create window: {} \n " , . { err } ) ;
return ;
} ;
defer window . destroy ( ) ;
2021-10-30 14:38:56 -07:00
_ = window . getAttrib ( . focused ) catch | err | std . debug . print ( " can't check if window is focused, not supported by OS maybe? error={} \n " , . { err } ) ;
2021-10-17 22:48:41 -07:00
}
2021-10-17 22:52:51 -07:00
test " setAttrib " {
2021-11-10 11:38:43 +01:00
try glfw . init ( . { } ) ;
2021-10-17 22:52:51 -07:00
defer glfw . terminate ( ) ;
glfw: window hints rework (#71)
* glfw: make comments into doc comments
* glfw: Publicize Window.CursorPos, Window.Size, Window.Pos, and Window.FrameSize
* glfw: Make enum value name the same format as other enum value names
* glfw: Window hints rework patch
* glfw: Relegate `Window.hint` to testing; move it down to just above the tests to reflect this, add doc comment line
* glfw: handle error `Error.InvalidEnum` explicitly, for clear error message in this unlikely edge case
* glfw: instate `Hint.context_no_error` as a hint, as it actually is specified to be a Window creation hint by the docs, and affirm removal of `Hint.context_revision`, which isn't.
The docs don't seem to specify a default value for `Hints.context_no_error` to take on, so we could set it based on `std.debug.runtime_safety` like this.
* glfw: default `context_no_error` to `false`, and added a note of caution about its usage as suggested.
* glfw: Inline enum values of `ClientApi`, `ContextCreationApi`, `ContextRobustness`, `ContextReleaseBehavior`, and `OpenGlProfile` from consts.zig, and remove the now unused constants (replaced by aformentioned enum values).
* glfw: Reference `Window.Hint` enum instead of `Window.Hints` struct to ensure fields are the same
* glfw: add comment explaining default values of `Window.Hints`
* glfw: change `OpenGlProfile` to `OpenGLProfile` based on established naming convention
* glfw: Update actual declaration of `OpenGLProfile`
* glfw: call `Window.defaultHints` after window creation, not before
* glfw: remove 'consts.zig', and move `dont_care` directly into 'main.zig'; fix anything referencing it.
* glfw: put `Window.defaultHints` into defer statement to handle cleanup in all paths
* glfw: move `Hint.focused` to match position of `Hints.focused`
* glfw: do 'zig fmt glfw/src'
* glfw: Cull `Window.Hint` comments, polish remaining; match order entirely according to current GLFW docs
* glfw: Change `Window.Hints.*Api` to `Window.Hints.*API`
Co-authored-by: Stephen Gutekanst <stephen@hexops.com>
2021-11-16 02:41:16 +01:00
const window = glfw . Window . create ( 640 , 480 , " Hello, Zig! " , null , null , . { } ) catch | err | {
2021-10-17 22:52:51 -07:00
// return without fail, because most of our CI environments are headless / we cannot open
// windows on them.
std . debug . print ( " note: failed to create window: {} \n " , . { err } ) ;
return ;
} ;
defer window . destroy ( ) ;
2021-10-30 14:38:56 -07:00
window . setAttrib ( . decorated , false ) catch | err | std . debug . print ( " can't remove window decorations, not supported by OS maybe? error={} \n " , . { err } ) ;
2021-10-17 22:52:51 -07:00
}
2021-10-17 23:04:43 -07:00
test " setUserPointer " {
2021-11-10 11:38:43 +01:00
try glfw . init ( . { } ) ;
2021-10-17 23:04:43 -07:00
defer glfw . terminate ( ) ;
glfw: window hints rework (#71)
* glfw: make comments into doc comments
* glfw: Publicize Window.CursorPos, Window.Size, Window.Pos, and Window.FrameSize
* glfw: Make enum value name the same format as other enum value names
* glfw: Window hints rework patch
* glfw: Relegate `Window.hint` to testing; move it down to just above the tests to reflect this, add doc comment line
* glfw: handle error `Error.InvalidEnum` explicitly, for clear error message in this unlikely edge case
* glfw: instate `Hint.context_no_error` as a hint, as it actually is specified to be a Window creation hint by the docs, and affirm removal of `Hint.context_revision`, which isn't.
The docs don't seem to specify a default value for `Hints.context_no_error` to take on, so we could set it based on `std.debug.runtime_safety` like this.
* glfw: default `context_no_error` to `false`, and added a note of caution about its usage as suggested.
* glfw: Inline enum values of `ClientApi`, `ContextCreationApi`, `ContextRobustness`, `ContextReleaseBehavior`, and `OpenGlProfile` from consts.zig, and remove the now unused constants (replaced by aformentioned enum values).
* glfw: Reference `Window.Hint` enum instead of `Window.Hints` struct to ensure fields are the same
* glfw: add comment explaining default values of `Window.Hints`
* glfw: change `OpenGlProfile` to `OpenGLProfile` based on established naming convention
* glfw: Update actual declaration of `OpenGLProfile`
* glfw: call `Window.defaultHints` after window creation, not before
* glfw: remove 'consts.zig', and move `dont_care` directly into 'main.zig'; fix anything referencing it.
* glfw: put `Window.defaultHints` into defer statement to handle cleanup in all paths
* glfw: move `Hint.focused` to match position of `Hints.focused`
* glfw: do 'zig fmt glfw/src'
* glfw: Cull `Window.Hint` comments, polish remaining; match order entirely according to current GLFW docs
* glfw: Change `Window.Hints.*Api` to `Window.Hints.*API`
Co-authored-by: Stephen Gutekanst <stephen@hexops.com>
2021-11-16 02:41:16 +01:00
const window = glfw . Window . create ( 640 , 480 , " Hello, Zig! " , null , null , . { } ) catch | err | {
2021-10-17 23:04:43 -07:00
// return without fail, because most of our CI environments are headless / we cannot open
// windows on them.
std . debug . print ( " note: failed to create window: {} \n " , . { err } ) ;
return ;
} ;
defer window . destroy ( ) ;
const T = struct { name : [ ] const u8 } ;
var my_value = T { . name = " my window! " } ;
window . setUserPointer ( * T , & my_value ) ;
}
2021-10-17 23:10:51 -07:00
test " getUserPointer " {
2021-11-10 11:38:43 +01:00
try glfw . init ( . { } ) ;
2021-10-17 23:10:51 -07:00
defer glfw . terminate ( ) ;
glfw: window hints rework (#71)
* glfw: make comments into doc comments
* glfw: Publicize Window.CursorPos, Window.Size, Window.Pos, and Window.FrameSize
* glfw: Make enum value name the same format as other enum value names
* glfw: Window hints rework patch
* glfw: Relegate `Window.hint` to testing; move it down to just above the tests to reflect this, add doc comment line
* glfw: handle error `Error.InvalidEnum` explicitly, for clear error message in this unlikely edge case
* glfw: instate `Hint.context_no_error` as a hint, as it actually is specified to be a Window creation hint by the docs, and affirm removal of `Hint.context_revision`, which isn't.
The docs don't seem to specify a default value for `Hints.context_no_error` to take on, so we could set it based on `std.debug.runtime_safety` like this.
* glfw: default `context_no_error` to `false`, and added a note of caution about its usage as suggested.
* glfw: Inline enum values of `ClientApi`, `ContextCreationApi`, `ContextRobustness`, `ContextReleaseBehavior`, and `OpenGlProfile` from consts.zig, and remove the now unused constants (replaced by aformentioned enum values).
* glfw: Reference `Window.Hint` enum instead of `Window.Hints` struct to ensure fields are the same
* glfw: add comment explaining default values of `Window.Hints`
* glfw: change `OpenGlProfile` to `OpenGLProfile` based on established naming convention
* glfw: Update actual declaration of `OpenGLProfile`
* glfw: call `Window.defaultHints` after window creation, not before
* glfw: remove 'consts.zig', and move `dont_care` directly into 'main.zig'; fix anything referencing it.
* glfw: put `Window.defaultHints` into defer statement to handle cleanup in all paths
* glfw: move `Hint.focused` to match position of `Hints.focused`
* glfw: do 'zig fmt glfw/src'
* glfw: Cull `Window.Hint` comments, polish remaining; match order entirely according to current GLFW docs
* glfw: Change `Window.Hints.*Api` to `Window.Hints.*API`
Co-authored-by: Stephen Gutekanst <stephen@hexops.com>
2021-11-16 02:41:16 +01:00
const window = glfw . Window . create ( 640 , 480 , " Hello, Zig! " , null , null , . { } ) catch | err | {
2021-10-17 23:10:51 -07:00
// return without fail, because most of our CI environments are headless / we cannot open
// windows on them.
std . debug . print ( " note: failed to create window: {} \n " , . { err } ) ;
return ;
} ;
defer window . destroy ( ) ;
const T = struct { name : [ ] const u8 } ;
var my_value = T { . name = " my window! " } ;
window . setUserPointer ( * T , & my_value ) ;
const got = window . getUserPointer ( * T ) ;
std . debug . assert ( & my_value = = got ) ;
}
2021-10-18 00:02:57 -07:00
test " setPosCallback " {
2021-11-10 11:38:43 +01:00
try glfw . init ( . { } ) ;
2021-10-18 00:02:57 -07:00
defer glfw . terminate ( ) ;
glfw: window hints rework (#71)
* glfw: make comments into doc comments
* glfw: Publicize Window.CursorPos, Window.Size, Window.Pos, and Window.FrameSize
* glfw: Make enum value name the same format as other enum value names
* glfw: Window hints rework patch
* glfw: Relegate `Window.hint` to testing; move it down to just above the tests to reflect this, add doc comment line
* glfw: handle error `Error.InvalidEnum` explicitly, for clear error message in this unlikely edge case
* glfw: instate `Hint.context_no_error` as a hint, as it actually is specified to be a Window creation hint by the docs, and affirm removal of `Hint.context_revision`, which isn't.
The docs don't seem to specify a default value for `Hints.context_no_error` to take on, so we could set it based on `std.debug.runtime_safety` like this.
* glfw: default `context_no_error` to `false`, and added a note of caution about its usage as suggested.
* glfw: Inline enum values of `ClientApi`, `ContextCreationApi`, `ContextRobustness`, `ContextReleaseBehavior`, and `OpenGlProfile` from consts.zig, and remove the now unused constants (replaced by aformentioned enum values).
* glfw: Reference `Window.Hint` enum instead of `Window.Hints` struct to ensure fields are the same
* glfw: add comment explaining default values of `Window.Hints`
* glfw: change `OpenGlProfile` to `OpenGLProfile` based on established naming convention
* glfw: Update actual declaration of `OpenGLProfile`
* glfw: call `Window.defaultHints` after window creation, not before
* glfw: remove 'consts.zig', and move `dont_care` directly into 'main.zig'; fix anything referencing it.
* glfw: put `Window.defaultHints` into defer statement to handle cleanup in all paths
* glfw: move `Hint.focused` to match position of `Hints.focused`
* glfw: do 'zig fmt glfw/src'
* glfw: Cull `Window.Hint` comments, polish remaining; match order entirely according to current GLFW docs
* glfw: Change `Window.Hints.*Api` to `Window.Hints.*API`
Co-authored-by: Stephen Gutekanst <stephen@hexops.com>
2021-11-16 02:41:16 +01:00
const window = glfw . Window . create ( 640 , 480 , " Hello, Zig! " , null , null , . { } ) catch | err | {
2021-10-18 00:02:57 -07:00
// return without fail, because most of our CI environments are headless / we cannot open
// windows on them.
std . debug . print ( " note: failed to create window: {} \n " , . { err } ) ;
return ;
} ;
defer window . destroy ( ) ;
window . setPosCallback ( ( struct {
fn callback ( _window : Window , xpos : isize , ypos : isize ) void {
_ = _window ;
_ = xpos ;
_ = ypos ;
}
} ) . callback ) ;
}
2021-10-18 00:08:25 -07:00
test " setSizeCallback " {
2021-11-10 11:38:43 +01:00
try glfw . init ( . { } ) ;
2021-10-18 00:08:25 -07:00
defer glfw . terminate ( ) ;
glfw: window hints rework (#71)
* glfw: make comments into doc comments
* glfw: Publicize Window.CursorPos, Window.Size, Window.Pos, and Window.FrameSize
* glfw: Make enum value name the same format as other enum value names
* glfw: Window hints rework patch
* glfw: Relegate `Window.hint` to testing; move it down to just above the tests to reflect this, add doc comment line
* glfw: handle error `Error.InvalidEnum` explicitly, for clear error message in this unlikely edge case
* glfw: instate `Hint.context_no_error` as a hint, as it actually is specified to be a Window creation hint by the docs, and affirm removal of `Hint.context_revision`, which isn't.
The docs don't seem to specify a default value for `Hints.context_no_error` to take on, so we could set it based on `std.debug.runtime_safety` like this.
* glfw: default `context_no_error` to `false`, and added a note of caution about its usage as suggested.
* glfw: Inline enum values of `ClientApi`, `ContextCreationApi`, `ContextRobustness`, `ContextReleaseBehavior`, and `OpenGlProfile` from consts.zig, and remove the now unused constants (replaced by aformentioned enum values).
* glfw: Reference `Window.Hint` enum instead of `Window.Hints` struct to ensure fields are the same
* glfw: add comment explaining default values of `Window.Hints`
* glfw: change `OpenGlProfile` to `OpenGLProfile` based on established naming convention
* glfw: Update actual declaration of `OpenGLProfile`
* glfw: call `Window.defaultHints` after window creation, not before
* glfw: remove 'consts.zig', and move `dont_care` directly into 'main.zig'; fix anything referencing it.
* glfw: put `Window.defaultHints` into defer statement to handle cleanup in all paths
* glfw: move `Hint.focused` to match position of `Hints.focused`
* glfw: do 'zig fmt glfw/src'
* glfw: Cull `Window.Hint` comments, polish remaining; match order entirely according to current GLFW docs
* glfw: Change `Window.Hints.*Api` to `Window.Hints.*API`
Co-authored-by: Stephen Gutekanst <stephen@hexops.com>
2021-11-16 02:41:16 +01:00
const window = glfw . Window . create ( 640 , 480 , " Hello, Zig! " , null , null , . { } ) catch | err | {
2021-10-18 00:08:25 -07:00
// return without fail, because most of our CI environments are headless / we cannot open
// windows on them.
std . debug . print ( " note: failed to create window: {} \n " , . { err } ) ;
return ;
} ;
defer window . destroy ( ) ;
window . setSizeCallback ( ( struct {
fn callback ( _window : Window , width : isize , height : isize ) void {
_ = _window ;
_ = width ;
_ = height ;
}
} ) . callback ) ;
}
2021-10-18 00:15:14 -07:00
test " setCloseCallback " {
2021-11-10 11:38:43 +01:00
try glfw . init ( . { } ) ;
2021-10-18 00:15:14 -07:00
defer glfw . terminate ( ) ;
glfw: window hints rework (#71)
* glfw: make comments into doc comments
* glfw: Publicize Window.CursorPos, Window.Size, Window.Pos, and Window.FrameSize
* glfw: Make enum value name the same format as other enum value names
* glfw: Window hints rework patch
* glfw: Relegate `Window.hint` to testing; move it down to just above the tests to reflect this, add doc comment line
* glfw: handle error `Error.InvalidEnum` explicitly, for clear error message in this unlikely edge case
* glfw: instate `Hint.context_no_error` as a hint, as it actually is specified to be a Window creation hint by the docs, and affirm removal of `Hint.context_revision`, which isn't.
The docs don't seem to specify a default value for `Hints.context_no_error` to take on, so we could set it based on `std.debug.runtime_safety` like this.
* glfw: default `context_no_error` to `false`, and added a note of caution about its usage as suggested.
* glfw: Inline enum values of `ClientApi`, `ContextCreationApi`, `ContextRobustness`, `ContextReleaseBehavior`, and `OpenGlProfile` from consts.zig, and remove the now unused constants (replaced by aformentioned enum values).
* glfw: Reference `Window.Hint` enum instead of `Window.Hints` struct to ensure fields are the same
* glfw: add comment explaining default values of `Window.Hints`
* glfw: change `OpenGlProfile` to `OpenGLProfile` based on established naming convention
* glfw: Update actual declaration of `OpenGLProfile`
* glfw: call `Window.defaultHints` after window creation, not before
* glfw: remove 'consts.zig', and move `dont_care` directly into 'main.zig'; fix anything referencing it.
* glfw: put `Window.defaultHints` into defer statement to handle cleanup in all paths
* glfw: move `Hint.focused` to match position of `Hints.focused`
* glfw: do 'zig fmt glfw/src'
* glfw: Cull `Window.Hint` comments, polish remaining; match order entirely according to current GLFW docs
* glfw: Change `Window.Hints.*Api` to `Window.Hints.*API`
Co-authored-by: Stephen Gutekanst <stephen@hexops.com>
2021-11-16 02:41:16 +01:00
const window = glfw . Window . create ( 640 , 480 , " Hello, Zig! " , null , null , . { } ) catch | err | {
2021-10-18 00:15:14 -07:00
// return without fail, because most of our CI environments are headless / we cannot open
// windows on them.
std . debug . print ( " note: failed to create window: {} \n " , . { err } ) ;
return ;
} ;
defer window . destroy ( ) ;
window . setCloseCallback ( ( struct {
fn callback ( _window : Window ) void {
_ = _window ;
}
} ) . callback ) ;
}
2021-10-18 00:23:33 -07:00
test " setRefreshCallback " {
2021-11-10 11:38:43 +01:00
try glfw . init ( . { } ) ;
2021-10-18 00:23:33 -07:00
defer glfw . terminate ( ) ;
glfw: window hints rework (#71)
* glfw: make comments into doc comments
* glfw: Publicize Window.CursorPos, Window.Size, Window.Pos, and Window.FrameSize
* glfw: Make enum value name the same format as other enum value names
* glfw: Window hints rework patch
* glfw: Relegate `Window.hint` to testing; move it down to just above the tests to reflect this, add doc comment line
* glfw: handle error `Error.InvalidEnum` explicitly, for clear error message in this unlikely edge case
* glfw: instate `Hint.context_no_error` as a hint, as it actually is specified to be a Window creation hint by the docs, and affirm removal of `Hint.context_revision`, which isn't.
The docs don't seem to specify a default value for `Hints.context_no_error` to take on, so we could set it based on `std.debug.runtime_safety` like this.
* glfw: default `context_no_error` to `false`, and added a note of caution about its usage as suggested.
* glfw: Inline enum values of `ClientApi`, `ContextCreationApi`, `ContextRobustness`, `ContextReleaseBehavior`, and `OpenGlProfile` from consts.zig, and remove the now unused constants (replaced by aformentioned enum values).
* glfw: Reference `Window.Hint` enum instead of `Window.Hints` struct to ensure fields are the same
* glfw: add comment explaining default values of `Window.Hints`
* glfw: change `OpenGlProfile` to `OpenGLProfile` based on established naming convention
* glfw: Update actual declaration of `OpenGLProfile`
* glfw: call `Window.defaultHints` after window creation, not before
* glfw: remove 'consts.zig', and move `dont_care` directly into 'main.zig'; fix anything referencing it.
* glfw: put `Window.defaultHints` into defer statement to handle cleanup in all paths
* glfw: move `Hint.focused` to match position of `Hints.focused`
* glfw: do 'zig fmt glfw/src'
* glfw: Cull `Window.Hint` comments, polish remaining; match order entirely according to current GLFW docs
* glfw: Change `Window.Hints.*Api` to `Window.Hints.*API`
Co-authored-by: Stephen Gutekanst <stephen@hexops.com>
2021-11-16 02:41:16 +01:00
const window = glfw . Window . create ( 640 , 480 , " Hello, Zig! " , null , null , . { } ) catch | err | {
2021-10-18 00:23:33 -07:00
// return without fail, because most of our CI environments are headless / we cannot open
// windows on them.
std . debug . print ( " note: failed to create window: {} \n " , . { err } ) ;
return ;
} ;
defer window . destroy ( ) ;
window . setRefreshCallback ( ( struct {
fn callback ( _window : Window ) void {
_ = _window ;
}
} ) . callback ) ;
}
2021-10-18 00:33:28 -07:00
test " setFocusCallback " {
2021-11-10 11:38:43 +01:00
try glfw . init ( . { } ) ;
2021-10-18 00:33:28 -07:00
defer glfw . terminate ( ) ;
glfw: window hints rework (#71)
* glfw: make comments into doc comments
* glfw: Publicize Window.CursorPos, Window.Size, Window.Pos, and Window.FrameSize
* glfw: Make enum value name the same format as other enum value names
* glfw: Window hints rework patch
* glfw: Relegate `Window.hint` to testing; move it down to just above the tests to reflect this, add doc comment line
* glfw: handle error `Error.InvalidEnum` explicitly, for clear error message in this unlikely edge case
* glfw: instate `Hint.context_no_error` as a hint, as it actually is specified to be a Window creation hint by the docs, and affirm removal of `Hint.context_revision`, which isn't.
The docs don't seem to specify a default value for `Hints.context_no_error` to take on, so we could set it based on `std.debug.runtime_safety` like this.
* glfw: default `context_no_error` to `false`, and added a note of caution about its usage as suggested.
* glfw: Inline enum values of `ClientApi`, `ContextCreationApi`, `ContextRobustness`, `ContextReleaseBehavior`, and `OpenGlProfile` from consts.zig, and remove the now unused constants (replaced by aformentioned enum values).
* glfw: Reference `Window.Hint` enum instead of `Window.Hints` struct to ensure fields are the same
* glfw: add comment explaining default values of `Window.Hints`
* glfw: change `OpenGlProfile` to `OpenGLProfile` based on established naming convention
* glfw: Update actual declaration of `OpenGLProfile`
* glfw: call `Window.defaultHints` after window creation, not before
* glfw: remove 'consts.zig', and move `dont_care` directly into 'main.zig'; fix anything referencing it.
* glfw: put `Window.defaultHints` into defer statement to handle cleanup in all paths
* glfw: move `Hint.focused` to match position of `Hints.focused`
* glfw: do 'zig fmt glfw/src'
* glfw: Cull `Window.Hint` comments, polish remaining; match order entirely according to current GLFW docs
* glfw: Change `Window.Hints.*Api` to `Window.Hints.*API`
Co-authored-by: Stephen Gutekanst <stephen@hexops.com>
2021-11-16 02:41:16 +01:00
const window = glfw . Window . create ( 640 , 480 , " Hello, Zig! " , null , null , . { } ) catch | err | {
2021-10-18 00:33:28 -07:00
// return without fail, because most of our CI environments are headless / we cannot open
// windows on them.
std . debug . print ( " note: failed to create window: {} \n " , . { err } ) ;
return ;
} ;
defer window . destroy ( ) ;
window . setFocusCallback ( ( struct {
fn callback ( _window : Window , focused : bool ) void {
_ = _window ;
_ = focused ;
}
} ) . callback ) ;
}
2021-10-18 00:39:31 -07:00
test " setIconifyCallback " {
2021-11-10 11:38:43 +01:00
try glfw . init ( . { } ) ;
2021-10-18 00:39:31 -07:00
defer glfw . terminate ( ) ;
glfw: window hints rework (#71)
* glfw: make comments into doc comments
* glfw: Publicize Window.CursorPos, Window.Size, Window.Pos, and Window.FrameSize
* glfw: Make enum value name the same format as other enum value names
* glfw: Window hints rework patch
* glfw: Relegate `Window.hint` to testing; move it down to just above the tests to reflect this, add doc comment line
* glfw: handle error `Error.InvalidEnum` explicitly, for clear error message in this unlikely edge case
* glfw: instate `Hint.context_no_error` as a hint, as it actually is specified to be a Window creation hint by the docs, and affirm removal of `Hint.context_revision`, which isn't.
The docs don't seem to specify a default value for `Hints.context_no_error` to take on, so we could set it based on `std.debug.runtime_safety` like this.
* glfw: default `context_no_error` to `false`, and added a note of caution about its usage as suggested.
* glfw: Inline enum values of `ClientApi`, `ContextCreationApi`, `ContextRobustness`, `ContextReleaseBehavior`, and `OpenGlProfile` from consts.zig, and remove the now unused constants (replaced by aformentioned enum values).
* glfw: Reference `Window.Hint` enum instead of `Window.Hints` struct to ensure fields are the same
* glfw: add comment explaining default values of `Window.Hints`
* glfw: change `OpenGlProfile` to `OpenGLProfile` based on established naming convention
* glfw: Update actual declaration of `OpenGLProfile`
* glfw: call `Window.defaultHints` after window creation, not before
* glfw: remove 'consts.zig', and move `dont_care` directly into 'main.zig'; fix anything referencing it.
* glfw: put `Window.defaultHints` into defer statement to handle cleanup in all paths
* glfw: move `Hint.focused` to match position of `Hints.focused`
* glfw: do 'zig fmt glfw/src'
* glfw: Cull `Window.Hint` comments, polish remaining; match order entirely according to current GLFW docs
* glfw: Change `Window.Hints.*Api` to `Window.Hints.*API`
Co-authored-by: Stephen Gutekanst <stephen@hexops.com>
2021-11-16 02:41:16 +01:00
const window = glfw . Window . create ( 640 , 480 , " Hello, Zig! " , null , null , . { } ) catch | err | {
2021-10-18 00:39:31 -07:00
// return without fail, because most of our CI environments are headless / we cannot open
// windows on them.
std . debug . print ( " note: failed to create window: {} \n " , . { err } ) ;
return ;
} ;
defer window . destroy ( ) ;
window . setIconifyCallback ( ( struct {
fn callback ( _window : Window , iconified : bool ) void {
_ = _window ;
_ = iconified ;
}
} ) . callback ) ;
}
2021-10-18 00:41:45 -07:00
test " setMaximizeCallback " {
2021-11-10 11:38:43 +01:00
try glfw . init ( . { } ) ;
2021-10-18 00:41:45 -07:00
defer glfw . terminate ( ) ;
glfw: window hints rework (#71)
* glfw: make comments into doc comments
* glfw: Publicize Window.CursorPos, Window.Size, Window.Pos, and Window.FrameSize
* glfw: Make enum value name the same format as other enum value names
* glfw: Window hints rework patch
* glfw: Relegate `Window.hint` to testing; move it down to just above the tests to reflect this, add doc comment line
* glfw: handle error `Error.InvalidEnum` explicitly, for clear error message in this unlikely edge case
* glfw: instate `Hint.context_no_error` as a hint, as it actually is specified to be a Window creation hint by the docs, and affirm removal of `Hint.context_revision`, which isn't.
The docs don't seem to specify a default value for `Hints.context_no_error` to take on, so we could set it based on `std.debug.runtime_safety` like this.
* glfw: default `context_no_error` to `false`, and added a note of caution about its usage as suggested.
* glfw: Inline enum values of `ClientApi`, `ContextCreationApi`, `ContextRobustness`, `ContextReleaseBehavior`, and `OpenGlProfile` from consts.zig, and remove the now unused constants (replaced by aformentioned enum values).
* glfw: Reference `Window.Hint` enum instead of `Window.Hints` struct to ensure fields are the same
* glfw: add comment explaining default values of `Window.Hints`
* glfw: change `OpenGlProfile` to `OpenGLProfile` based on established naming convention
* glfw: Update actual declaration of `OpenGLProfile`
* glfw: call `Window.defaultHints` after window creation, not before
* glfw: remove 'consts.zig', and move `dont_care` directly into 'main.zig'; fix anything referencing it.
* glfw: put `Window.defaultHints` into defer statement to handle cleanup in all paths
* glfw: move `Hint.focused` to match position of `Hints.focused`
* glfw: do 'zig fmt glfw/src'
* glfw: Cull `Window.Hint` comments, polish remaining; match order entirely according to current GLFW docs
* glfw: Change `Window.Hints.*Api` to `Window.Hints.*API`
Co-authored-by: Stephen Gutekanst <stephen@hexops.com>
2021-11-16 02:41:16 +01:00
const window = glfw . Window . create ( 640 , 480 , " Hello, Zig! " , null , null , . { } ) catch | err | {
2021-10-18 00:41:45 -07:00
// return without fail, because most of our CI environments are headless / we cannot open
// windows on them.
std . debug . print ( " note: failed to create window: {} \n " , . { err } ) ;
return ;
} ;
defer window . destroy ( ) ;
window . setMaximizeCallback ( ( struct {
fn callback ( _window : Window , maximized : bool ) void {
_ = _window ;
_ = maximized ;
}
} ) . callback ) ;
}
2021-10-18 00:50:28 -07:00
test " setFramebufferSizeCallback " {
2021-11-10 11:38:43 +01:00
try glfw . init ( . { } ) ;
2021-10-18 00:50:28 -07:00
defer glfw . terminate ( ) ;
glfw: window hints rework (#71)
* glfw: make comments into doc comments
* glfw: Publicize Window.CursorPos, Window.Size, Window.Pos, and Window.FrameSize
* glfw: Make enum value name the same format as other enum value names
* glfw: Window hints rework patch
* glfw: Relegate `Window.hint` to testing; move it down to just above the tests to reflect this, add doc comment line
* glfw: handle error `Error.InvalidEnum` explicitly, for clear error message in this unlikely edge case
* glfw: instate `Hint.context_no_error` as a hint, as it actually is specified to be a Window creation hint by the docs, and affirm removal of `Hint.context_revision`, which isn't.
The docs don't seem to specify a default value for `Hints.context_no_error` to take on, so we could set it based on `std.debug.runtime_safety` like this.
* glfw: default `context_no_error` to `false`, and added a note of caution about its usage as suggested.
* glfw: Inline enum values of `ClientApi`, `ContextCreationApi`, `ContextRobustness`, `ContextReleaseBehavior`, and `OpenGlProfile` from consts.zig, and remove the now unused constants (replaced by aformentioned enum values).
* glfw: Reference `Window.Hint` enum instead of `Window.Hints` struct to ensure fields are the same
* glfw: add comment explaining default values of `Window.Hints`
* glfw: change `OpenGlProfile` to `OpenGLProfile` based on established naming convention
* glfw: Update actual declaration of `OpenGLProfile`
* glfw: call `Window.defaultHints` after window creation, not before
* glfw: remove 'consts.zig', and move `dont_care` directly into 'main.zig'; fix anything referencing it.
* glfw: put `Window.defaultHints` into defer statement to handle cleanup in all paths
* glfw: move `Hint.focused` to match position of `Hints.focused`
* glfw: do 'zig fmt glfw/src'
* glfw: Cull `Window.Hint` comments, polish remaining; match order entirely according to current GLFW docs
* glfw: Change `Window.Hints.*Api` to `Window.Hints.*API`
Co-authored-by: Stephen Gutekanst <stephen@hexops.com>
2021-11-16 02:41:16 +01:00
const window = glfw . Window . create ( 640 , 480 , " Hello, Zig! " , null , null , . { } ) catch | err | {
2021-10-18 00:50:28 -07:00
// return without fail, because most of our CI environments are headless / we cannot open
// windows on them.
std . debug . print ( " note: failed to create window: {} \n " , . { err } ) ;
return ;
} ;
defer window . destroy ( ) ;
window . setFramebufferSizeCallback ( ( struct {
fn callback ( _window : Window , width : isize , height : isize ) void {
_ = _window ;
_ = width ;
_ = height ;
}
} ) . callback ) ;
}
2021-10-18 00:58:18 -07:00
test " setContentScaleCallback " {
2021-11-10 11:38:43 +01:00
try glfw . init ( . { } ) ;
2021-10-18 00:58:18 -07:00
defer glfw . terminate ( ) ;
glfw: window hints rework (#71)
* glfw: make comments into doc comments
* glfw: Publicize Window.CursorPos, Window.Size, Window.Pos, and Window.FrameSize
* glfw: Make enum value name the same format as other enum value names
* glfw: Window hints rework patch
* glfw: Relegate `Window.hint` to testing; move it down to just above the tests to reflect this, add doc comment line
* glfw: handle error `Error.InvalidEnum` explicitly, for clear error message in this unlikely edge case
* glfw: instate `Hint.context_no_error` as a hint, as it actually is specified to be a Window creation hint by the docs, and affirm removal of `Hint.context_revision`, which isn't.
The docs don't seem to specify a default value for `Hints.context_no_error` to take on, so we could set it based on `std.debug.runtime_safety` like this.
* glfw: default `context_no_error` to `false`, and added a note of caution about its usage as suggested.
* glfw: Inline enum values of `ClientApi`, `ContextCreationApi`, `ContextRobustness`, `ContextReleaseBehavior`, and `OpenGlProfile` from consts.zig, and remove the now unused constants (replaced by aformentioned enum values).
* glfw: Reference `Window.Hint` enum instead of `Window.Hints` struct to ensure fields are the same
* glfw: add comment explaining default values of `Window.Hints`
* glfw: change `OpenGlProfile` to `OpenGLProfile` based on established naming convention
* glfw: Update actual declaration of `OpenGLProfile`
* glfw: call `Window.defaultHints` after window creation, not before
* glfw: remove 'consts.zig', and move `dont_care` directly into 'main.zig'; fix anything referencing it.
* glfw: put `Window.defaultHints` into defer statement to handle cleanup in all paths
* glfw: move `Hint.focused` to match position of `Hints.focused`
* glfw: do 'zig fmt glfw/src'
* glfw: Cull `Window.Hint` comments, polish remaining; match order entirely according to current GLFW docs
* glfw: Change `Window.Hints.*Api` to `Window.Hints.*API`
Co-authored-by: Stephen Gutekanst <stephen@hexops.com>
2021-11-16 02:41:16 +01:00
const window = glfw . Window . create ( 640 , 480 , " Hello, Zig! " , null , null , . { } ) catch | err | {
2021-10-18 00:58:18 -07:00
// return without fail, because most of our CI environments are headless / we cannot open
// windows on them.
std . debug . print ( " note: failed to create window: {} \n " , . { err } ) ;
return ;
} ;
defer window . destroy ( ) ;
window . setContentScaleCallback ( ( struct {
fn callback ( _window : Window , xscale : f32 , yscale : f32 ) void {
_ = _window ;
_ = xscale ;
_ = yscale ;
}
} ) . callback ) ;
}
2021-10-23 10:49:28 -07:00
test " setDropCallback " {
2021-11-10 11:38:43 +01:00
try glfw . init ( . { } ) ;
2021-10-23 10:49:28 -07:00
defer glfw . terminate ( ) ;
glfw: window hints rework (#71)
* glfw: make comments into doc comments
* glfw: Publicize Window.CursorPos, Window.Size, Window.Pos, and Window.FrameSize
* glfw: Make enum value name the same format as other enum value names
* glfw: Window hints rework patch
* glfw: Relegate `Window.hint` to testing; move it down to just above the tests to reflect this, add doc comment line
* glfw: handle error `Error.InvalidEnum` explicitly, for clear error message in this unlikely edge case
* glfw: instate `Hint.context_no_error` as a hint, as it actually is specified to be a Window creation hint by the docs, and affirm removal of `Hint.context_revision`, which isn't.
The docs don't seem to specify a default value for `Hints.context_no_error` to take on, so we could set it based on `std.debug.runtime_safety` like this.
* glfw: default `context_no_error` to `false`, and added a note of caution about its usage as suggested.
* glfw: Inline enum values of `ClientApi`, `ContextCreationApi`, `ContextRobustness`, `ContextReleaseBehavior`, and `OpenGlProfile` from consts.zig, and remove the now unused constants (replaced by aformentioned enum values).
* glfw: Reference `Window.Hint` enum instead of `Window.Hints` struct to ensure fields are the same
* glfw: add comment explaining default values of `Window.Hints`
* glfw: change `OpenGlProfile` to `OpenGLProfile` based on established naming convention
* glfw: Update actual declaration of `OpenGLProfile`
* glfw: call `Window.defaultHints` after window creation, not before
* glfw: remove 'consts.zig', and move `dont_care` directly into 'main.zig'; fix anything referencing it.
* glfw: put `Window.defaultHints` into defer statement to handle cleanup in all paths
* glfw: move `Hint.focused` to match position of `Hints.focused`
* glfw: do 'zig fmt glfw/src'
* glfw: Cull `Window.Hint` comments, polish remaining; match order entirely according to current GLFW docs
* glfw: Change `Window.Hints.*Api` to `Window.Hints.*API`
Co-authored-by: Stephen Gutekanst <stephen@hexops.com>
2021-11-16 02:41:16 +01:00
const window = glfw . Window . create ( 640 , 480 , " Hello, Zig! " , null , null , . { } ) catch | err | {
2021-10-23 10:49:28 -07:00
// return without fail, because most of our CI environments are headless / we cannot open
// windows on them.
std . debug . print ( " note: failed to create window: {} \n " , . { err } ) ;
return ;
} ;
defer window . destroy ( ) ;
window . setDropCallback ( ( struct {
2021-11-11 09:42:49 +00:00
fn callback ( _window : Window , paths : [ ] [ * : 0 ] const u8 ) void {
2021-10-23 10:49:28 -07:00
_ = _window ;
_ = paths ;
}
} ) . callback ) catch | err | std . debug . print ( " can't set window drop callback, not supported by OS maybe? error={} \n " , . { err } ) ;
}
2021-10-23 11:37:36 -07:00
2021-10-30 19:17:09 -07:00
test " getInputModeCursor " {
2021-11-10 11:38:43 +01:00
try glfw . init ( . { } ) ;
2021-10-30 19:17:09 -07:00
defer glfw . terminate ( ) ;
glfw: window hints rework (#71)
* glfw: make comments into doc comments
* glfw: Publicize Window.CursorPos, Window.Size, Window.Pos, and Window.FrameSize
* glfw: Make enum value name the same format as other enum value names
* glfw: Window hints rework patch
* glfw: Relegate `Window.hint` to testing; move it down to just above the tests to reflect this, add doc comment line
* glfw: handle error `Error.InvalidEnum` explicitly, for clear error message in this unlikely edge case
* glfw: instate `Hint.context_no_error` as a hint, as it actually is specified to be a Window creation hint by the docs, and affirm removal of `Hint.context_revision`, which isn't.
The docs don't seem to specify a default value for `Hints.context_no_error` to take on, so we could set it based on `std.debug.runtime_safety` like this.
* glfw: default `context_no_error` to `false`, and added a note of caution about its usage as suggested.
* glfw: Inline enum values of `ClientApi`, `ContextCreationApi`, `ContextRobustness`, `ContextReleaseBehavior`, and `OpenGlProfile` from consts.zig, and remove the now unused constants (replaced by aformentioned enum values).
* glfw: Reference `Window.Hint` enum instead of `Window.Hints` struct to ensure fields are the same
* glfw: add comment explaining default values of `Window.Hints`
* glfw: change `OpenGlProfile` to `OpenGLProfile` based on established naming convention
* glfw: Update actual declaration of `OpenGLProfile`
* glfw: call `Window.defaultHints` after window creation, not before
* glfw: remove 'consts.zig', and move `dont_care` directly into 'main.zig'; fix anything referencing it.
* glfw: put `Window.defaultHints` into defer statement to handle cleanup in all paths
* glfw: move `Hint.focused` to match position of `Hints.focused`
* glfw: do 'zig fmt glfw/src'
* glfw: Cull `Window.Hint` comments, polish remaining; match order entirely according to current GLFW docs
* glfw: Change `Window.Hints.*Api` to `Window.Hints.*API`
Co-authored-by: Stephen Gutekanst <stephen@hexops.com>
2021-11-16 02:41:16 +01:00
const window = glfw . Window . create ( 640 , 480 , " Hello, Zig! " , null , null , . { } ) catch | err | {
2021-10-30 19:17:09 -07:00
// return without fail, because most of our CI environments are headless / we cannot open
// windows on them.
std . debug . print ( " note: failed to create window: {} \n " , . { err } ) ;
return ;
} ;
defer window . destroy ( ) ;
_ = window . getInputModeCursor ( ) ;
}
test " setInputModeCursor " {
2021-11-10 11:38:43 +01:00
try glfw . init ( . { } ) ;
2021-10-30 19:17:09 -07:00
defer glfw . terminate ( ) ;
glfw: window hints rework (#71)
* glfw: make comments into doc comments
* glfw: Publicize Window.CursorPos, Window.Size, Window.Pos, and Window.FrameSize
* glfw: Make enum value name the same format as other enum value names
* glfw: Window hints rework patch
* glfw: Relegate `Window.hint` to testing; move it down to just above the tests to reflect this, add doc comment line
* glfw: handle error `Error.InvalidEnum` explicitly, for clear error message in this unlikely edge case
* glfw: instate `Hint.context_no_error` as a hint, as it actually is specified to be a Window creation hint by the docs, and affirm removal of `Hint.context_revision`, which isn't.
The docs don't seem to specify a default value for `Hints.context_no_error` to take on, so we could set it based on `std.debug.runtime_safety` like this.
* glfw: default `context_no_error` to `false`, and added a note of caution about its usage as suggested.
* glfw: Inline enum values of `ClientApi`, `ContextCreationApi`, `ContextRobustness`, `ContextReleaseBehavior`, and `OpenGlProfile` from consts.zig, and remove the now unused constants (replaced by aformentioned enum values).
* glfw: Reference `Window.Hint` enum instead of `Window.Hints` struct to ensure fields are the same
* glfw: add comment explaining default values of `Window.Hints`
* glfw: change `OpenGlProfile` to `OpenGLProfile` based on established naming convention
* glfw: Update actual declaration of `OpenGLProfile`
* glfw: call `Window.defaultHints` after window creation, not before
* glfw: remove 'consts.zig', and move `dont_care` directly into 'main.zig'; fix anything referencing it.
* glfw: put `Window.defaultHints` into defer statement to handle cleanup in all paths
* glfw: move `Hint.focused` to match position of `Hints.focused`
* glfw: do 'zig fmt glfw/src'
* glfw: Cull `Window.Hint` comments, polish remaining; match order entirely according to current GLFW docs
* glfw: Change `Window.Hints.*Api` to `Window.Hints.*API`
Co-authored-by: Stephen Gutekanst <stephen@hexops.com>
2021-11-16 02:41:16 +01:00
const window = glfw . Window . create ( 640 , 480 , " Hello, Zig! " , null , null , . { } ) catch | err | {
2021-10-30 19:17:09 -07:00
// return without fail, because most of our CI environments are headless / we cannot open
// windows on them.
std . debug . print ( " note: failed to create window: {} \n " , . { err } ) ;
return ;
} ;
defer window . destroy ( ) ;
window . setInputModeCursor ( . hidden ) catch | err | std . debug . print ( " failed to set input mode, not supported? error={} \n " , . { err } ) ;
}
2021-10-30 19:26:10 -07:00
test " getInputModeStickyKeys " {
2021-11-10 11:38:43 +01:00
try glfw . init ( . { } ) ;
2021-10-30 19:26:10 -07:00
defer glfw . terminate ( ) ;
glfw: window hints rework (#71)
* glfw: make comments into doc comments
* glfw: Publicize Window.CursorPos, Window.Size, Window.Pos, and Window.FrameSize
* glfw: Make enum value name the same format as other enum value names
* glfw: Window hints rework patch
* glfw: Relegate `Window.hint` to testing; move it down to just above the tests to reflect this, add doc comment line
* glfw: handle error `Error.InvalidEnum` explicitly, for clear error message in this unlikely edge case
* glfw: instate `Hint.context_no_error` as a hint, as it actually is specified to be a Window creation hint by the docs, and affirm removal of `Hint.context_revision`, which isn't.
The docs don't seem to specify a default value for `Hints.context_no_error` to take on, so we could set it based on `std.debug.runtime_safety` like this.
* glfw: default `context_no_error` to `false`, and added a note of caution about its usage as suggested.
* glfw: Inline enum values of `ClientApi`, `ContextCreationApi`, `ContextRobustness`, `ContextReleaseBehavior`, and `OpenGlProfile` from consts.zig, and remove the now unused constants (replaced by aformentioned enum values).
* glfw: Reference `Window.Hint` enum instead of `Window.Hints` struct to ensure fields are the same
* glfw: add comment explaining default values of `Window.Hints`
* glfw: change `OpenGlProfile` to `OpenGLProfile` based on established naming convention
* glfw: Update actual declaration of `OpenGLProfile`
* glfw: call `Window.defaultHints` after window creation, not before
* glfw: remove 'consts.zig', and move `dont_care` directly into 'main.zig'; fix anything referencing it.
* glfw: put `Window.defaultHints` into defer statement to handle cleanup in all paths
* glfw: move `Hint.focused` to match position of `Hints.focused`
* glfw: do 'zig fmt glfw/src'
* glfw: Cull `Window.Hint` comments, polish remaining; match order entirely according to current GLFW docs
* glfw: Change `Window.Hints.*Api` to `Window.Hints.*API`
Co-authored-by: Stephen Gutekanst <stephen@hexops.com>
2021-11-16 02:41:16 +01:00
const window = glfw . Window . create ( 640 , 480 , " Hello, Zig! " , null , null , . { } ) catch | err | {
2021-10-30 19:26:10 -07:00
// return without fail, because most of our CI environments are headless / we cannot open
// windows on them.
std . debug . print ( " note: failed to create window: {} \n " , . { err } ) ;
return ;
} ;
defer window . destroy ( ) ;
_ = window . getInputModeStickyKeys ( ) ;
}
test " setInputModeStickyKeys " {
2021-11-10 11:38:43 +01:00
try glfw . init ( . { } ) ;
2021-10-30 19:26:10 -07:00
defer glfw . terminate ( ) ;
glfw: window hints rework (#71)
* glfw: make comments into doc comments
* glfw: Publicize Window.CursorPos, Window.Size, Window.Pos, and Window.FrameSize
* glfw: Make enum value name the same format as other enum value names
* glfw: Window hints rework patch
* glfw: Relegate `Window.hint` to testing; move it down to just above the tests to reflect this, add doc comment line
* glfw: handle error `Error.InvalidEnum` explicitly, for clear error message in this unlikely edge case
* glfw: instate `Hint.context_no_error` as a hint, as it actually is specified to be a Window creation hint by the docs, and affirm removal of `Hint.context_revision`, which isn't.
The docs don't seem to specify a default value for `Hints.context_no_error` to take on, so we could set it based on `std.debug.runtime_safety` like this.
* glfw: default `context_no_error` to `false`, and added a note of caution about its usage as suggested.
* glfw: Inline enum values of `ClientApi`, `ContextCreationApi`, `ContextRobustness`, `ContextReleaseBehavior`, and `OpenGlProfile` from consts.zig, and remove the now unused constants (replaced by aformentioned enum values).
* glfw: Reference `Window.Hint` enum instead of `Window.Hints` struct to ensure fields are the same
* glfw: add comment explaining default values of `Window.Hints`
* glfw: change `OpenGlProfile` to `OpenGLProfile` based on established naming convention
* glfw: Update actual declaration of `OpenGLProfile`
* glfw: call `Window.defaultHints` after window creation, not before
* glfw: remove 'consts.zig', and move `dont_care` directly into 'main.zig'; fix anything referencing it.
* glfw: put `Window.defaultHints` into defer statement to handle cleanup in all paths
* glfw: move `Hint.focused` to match position of `Hints.focused`
* glfw: do 'zig fmt glfw/src'
* glfw: Cull `Window.Hint` comments, polish remaining; match order entirely according to current GLFW docs
* glfw: Change `Window.Hints.*Api` to `Window.Hints.*API`
Co-authored-by: Stephen Gutekanst <stephen@hexops.com>
2021-11-16 02:41:16 +01:00
const window = glfw . Window . create ( 640 , 480 , " Hello, Zig! " , null , null , . { } ) catch | err | {
2021-10-30 19:26:10 -07:00
// return without fail, because most of our CI environments are headless / we cannot open
// windows on them.
std . debug . print ( " note: failed to create window: {} \n " , . { err } ) ;
return ;
} ;
defer window . destroy ( ) ;
window . setInputModeStickyKeys ( false ) catch | err | std . debug . print ( " failed to set input mode, not supported? error={} \n " , . { err } ) ;
}
2021-10-30 19:30:53 -07:00
test " getInputModeStickyMouseButtons " {
2021-11-10 11:38:43 +01:00
try glfw . init ( . { } ) ;
2021-10-30 19:30:53 -07:00
defer glfw . terminate ( ) ;
glfw: window hints rework (#71)
* glfw: make comments into doc comments
* glfw: Publicize Window.CursorPos, Window.Size, Window.Pos, and Window.FrameSize
* glfw: Make enum value name the same format as other enum value names
* glfw: Window hints rework patch
* glfw: Relegate `Window.hint` to testing; move it down to just above the tests to reflect this, add doc comment line
* glfw: handle error `Error.InvalidEnum` explicitly, for clear error message in this unlikely edge case
* glfw: instate `Hint.context_no_error` as a hint, as it actually is specified to be a Window creation hint by the docs, and affirm removal of `Hint.context_revision`, which isn't.
The docs don't seem to specify a default value for `Hints.context_no_error` to take on, so we could set it based on `std.debug.runtime_safety` like this.
* glfw: default `context_no_error` to `false`, and added a note of caution about its usage as suggested.
* glfw: Inline enum values of `ClientApi`, `ContextCreationApi`, `ContextRobustness`, `ContextReleaseBehavior`, and `OpenGlProfile` from consts.zig, and remove the now unused constants (replaced by aformentioned enum values).
* glfw: Reference `Window.Hint` enum instead of `Window.Hints` struct to ensure fields are the same
* glfw: add comment explaining default values of `Window.Hints`
* glfw: change `OpenGlProfile` to `OpenGLProfile` based on established naming convention
* glfw: Update actual declaration of `OpenGLProfile`
* glfw: call `Window.defaultHints` after window creation, not before
* glfw: remove 'consts.zig', and move `dont_care` directly into 'main.zig'; fix anything referencing it.
* glfw: put `Window.defaultHints` into defer statement to handle cleanup in all paths
* glfw: move `Hint.focused` to match position of `Hints.focused`
* glfw: do 'zig fmt glfw/src'
* glfw: Cull `Window.Hint` comments, polish remaining; match order entirely according to current GLFW docs
* glfw: Change `Window.Hints.*Api` to `Window.Hints.*API`
Co-authored-by: Stephen Gutekanst <stephen@hexops.com>
2021-11-16 02:41:16 +01:00
const window = glfw . Window . create ( 640 , 480 , " Hello, Zig! " , null , null , . { } ) catch | err | {
2021-10-30 19:30:53 -07:00
// return without fail, because most of our CI environments are headless / we cannot open
// windows on them.
std . debug . print ( " note: failed to create window: {} \n " , . { err } ) ;
return ;
} ;
defer window . destroy ( ) ;
_ = window . getInputModeStickyMouseButtons ( ) ;
}
test " setInputModeStickyMouseButtons " {
2021-11-10 11:38:43 +01:00
try glfw . init ( . { } ) ;
2021-10-30 19:30:53 -07:00
defer glfw . terminate ( ) ;
glfw: window hints rework (#71)
* glfw: make comments into doc comments
* glfw: Publicize Window.CursorPos, Window.Size, Window.Pos, and Window.FrameSize
* glfw: Make enum value name the same format as other enum value names
* glfw: Window hints rework patch
* glfw: Relegate `Window.hint` to testing; move it down to just above the tests to reflect this, add doc comment line
* glfw: handle error `Error.InvalidEnum` explicitly, for clear error message in this unlikely edge case
* glfw: instate `Hint.context_no_error` as a hint, as it actually is specified to be a Window creation hint by the docs, and affirm removal of `Hint.context_revision`, which isn't.
The docs don't seem to specify a default value for `Hints.context_no_error` to take on, so we could set it based on `std.debug.runtime_safety` like this.
* glfw: default `context_no_error` to `false`, and added a note of caution about its usage as suggested.
* glfw: Inline enum values of `ClientApi`, `ContextCreationApi`, `ContextRobustness`, `ContextReleaseBehavior`, and `OpenGlProfile` from consts.zig, and remove the now unused constants (replaced by aformentioned enum values).
* glfw: Reference `Window.Hint` enum instead of `Window.Hints` struct to ensure fields are the same
* glfw: add comment explaining default values of `Window.Hints`
* glfw: change `OpenGlProfile` to `OpenGLProfile` based on established naming convention
* glfw: Update actual declaration of `OpenGLProfile`
* glfw: call `Window.defaultHints` after window creation, not before
* glfw: remove 'consts.zig', and move `dont_care` directly into 'main.zig'; fix anything referencing it.
* glfw: put `Window.defaultHints` into defer statement to handle cleanup in all paths
* glfw: move `Hint.focused` to match position of `Hints.focused`
* glfw: do 'zig fmt glfw/src'
* glfw: Cull `Window.Hint` comments, polish remaining; match order entirely according to current GLFW docs
* glfw: Change `Window.Hints.*Api` to `Window.Hints.*API`
Co-authored-by: Stephen Gutekanst <stephen@hexops.com>
2021-11-16 02:41:16 +01:00
const window = glfw . Window . create ( 640 , 480 , " Hello, Zig! " , null , null , . { } ) catch | err | {
2021-10-30 19:30:53 -07:00
// return without fail, because most of our CI environments are headless / we cannot open
// windows on them.
std . debug . print ( " note: failed to create window: {} \n " , . { err } ) ;
return ;
} ;
defer window . destroy ( ) ;
window . setInputModeStickyMouseButtons ( false ) catch | err | std . debug . print ( " failed to set input mode, not supported? error={} \n " , . { err } ) ;
}
2021-10-30 19:36:00 -07:00
test " getInputModeLockKeyMods " {
2021-11-10 11:38:43 +01:00
try glfw . init ( . { } ) ;
2021-10-30 19:36:00 -07:00
defer glfw . terminate ( ) ;
glfw: window hints rework (#71)
* glfw: make comments into doc comments
* glfw: Publicize Window.CursorPos, Window.Size, Window.Pos, and Window.FrameSize
* glfw: Make enum value name the same format as other enum value names
* glfw: Window hints rework patch
* glfw: Relegate `Window.hint` to testing; move it down to just above the tests to reflect this, add doc comment line
* glfw: handle error `Error.InvalidEnum` explicitly, for clear error message in this unlikely edge case
* glfw: instate `Hint.context_no_error` as a hint, as it actually is specified to be a Window creation hint by the docs, and affirm removal of `Hint.context_revision`, which isn't.
The docs don't seem to specify a default value for `Hints.context_no_error` to take on, so we could set it based on `std.debug.runtime_safety` like this.
* glfw: default `context_no_error` to `false`, and added a note of caution about its usage as suggested.
* glfw: Inline enum values of `ClientApi`, `ContextCreationApi`, `ContextRobustness`, `ContextReleaseBehavior`, and `OpenGlProfile` from consts.zig, and remove the now unused constants (replaced by aformentioned enum values).
* glfw: Reference `Window.Hint` enum instead of `Window.Hints` struct to ensure fields are the same
* glfw: add comment explaining default values of `Window.Hints`
* glfw: change `OpenGlProfile` to `OpenGLProfile` based on established naming convention
* glfw: Update actual declaration of `OpenGLProfile`
* glfw: call `Window.defaultHints` after window creation, not before
* glfw: remove 'consts.zig', and move `dont_care` directly into 'main.zig'; fix anything referencing it.
* glfw: put `Window.defaultHints` into defer statement to handle cleanup in all paths
* glfw: move `Hint.focused` to match position of `Hints.focused`
* glfw: do 'zig fmt glfw/src'
* glfw: Cull `Window.Hint` comments, polish remaining; match order entirely according to current GLFW docs
* glfw: Change `Window.Hints.*Api` to `Window.Hints.*API`
Co-authored-by: Stephen Gutekanst <stephen@hexops.com>
2021-11-16 02:41:16 +01:00
const window = glfw . Window . create ( 640 , 480 , " Hello, Zig! " , null , null , . { } ) catch | err | {
2021-10-30 19:36:00 -07:00
// return without fail, because most of our CI environments are headless / we cannot open
// windows on them.
std . debug . print ( " note: failed to create window: {} \n " , . { err } ) ;
return ;
} ;
defer window . destroy ( ) ;
_ = window . getInputModeLockKeyMods ( ) ;
}
test " setInputModeLockKeyMods " {
2021-11-10 11:38:43 +01:00
try glfw . init ( . { } ) ;
2021-10-30 19:36:00 -07:00
defer glfw . terminate ( ) ;
glfw: window hints rework (#71)
* glfw: make comments into doc comments
* glfw: Publicize Window.CursorPos, Window.Size, Window.Pos, and Window.FrameSize
* glfw: Make enum value name the same format as other enum value names
* glfw: Window hints rework patch
* glfw: Relegate `Window.hint` to testing; move it down to just above the tests to reflect this, add doc comment line
* glfw: handle error `Error.InvalidEnum` explicitly, for clear error message in this unlikely edge case
* glfw: instate `Hint.context_no_error` as a hint, as it actually is specified to be a Window creation hint by the docs, and affirm removal of `Hint.context_revision`, which isn't.
The docs don't seem to specify a default value for `Hints.context_no_error` to take on, so we could set it based on `std.debug.runtime_safety` like this.
* glfw: default `context_no_error` to `false`, and added a note of caution about its usage as suggested.
* glfw: Inline enum values of `ClientApi`, `ContextCreationApi`, `ContextRobustness`, `ContextReleaseBehavior`, and `OpenGlProfile` from consts.zig, and remove the now unused constants (replaced by aformentioned enum values).
* glfw: Reference `Window.Hint` enum instead of `Window.Hints` struct to ensure fields are the same
* glfw: add comment explaining default values of `Window.Hints`
* glfw: change `OpenGlProfile` to `OpenGLProfile` based on established naming convention
* glfw: Update actual declaration of `OpenGLProfile`
* glfw: call `Window.defaultHints` after window creation, not before
* glfw: remove 'consts.zig', and move `dont_care` directly into 'main.zig'; fix anything referencing it.
* glfw: put `Window.defaultHints` into defer statement to handle cleanup in all paths
* glfw: move `Hint.focused` to match position of `Hints.focused`
* glfw: do 'zig fmt glfw/src'
* glfw: Cull `Window.Hint` comments, polish remaining; match order entirely according to current GLFW docs
* glfw: Change `Window.Hints.*Api` to `Window.Hints.*API`
Co-authored-by: Stephen Gutekanst <stephen@hexops.com>
2021-11-16 02:41:16 +01:00
const window = glfw . Window . create ( 640 , 480 , " Hello, Zig! " , null , null , . { } ) catch | err | {
2021-10-30 19:36:00 -07:00
// return without fail, because most of our CI environments are headless / we cannot open
// windows on them.
std . debug . print ( " note: failed to create window: {} \n " , . { err } ) ;
return ;
} ;
defer window . destroy ( ) ;
window . setInputModeLockKeyMods ( false ) catch | err | std . debug . print ( " failed to set input mode, not supported? error={} \n " , . { err } ) ;
}
2021-10-30 19:45:41 -07:00
test " getInputModeRawMouseMotion " {
2021-11-10 11:38:43 +01:00
try glfw . init ( . { } ) ;
2021-10-30 19:45:41 -07:00
defer glfw . terminate ( ) ;
glfw: window hints rework (#71)
* glfw: make comments into doc comments
* glfw: Publicize Window.CursorPos, Window.Size, Window.Pos, and Window.FrameSize
* glfw: Make enum value name the same format as other enum value names
* glfw: Window hints rework patch
* glfw: Relegate `Window.hint` to testing; move it down to just above the tests to reflect this, add doc comment line
* glfw: handle error `Error.InvalidEnum` explicitly, for clear error message in this unlikely edge case
* glfw: instate `Hint.context_no_error` as a hint, as it actually is specified to be a Window creation hint by the docs, and affirm removal of `Hint.context_revision`, which isn't.
The docs don't seem to specify a default value for `Hints.context_no_error` to take on, so we could set it based on `std.debug.runtime_safety` like this.
* glfw: default `context_no_error` to `false`, and added a note of caution about its usage as suggested.
* glfw: Inline enum values of `ClientApi`, `ContextCreationApi`, `ContextRobustness`, `ContextReleaseBehavior`, and `OpenGlProfile` from consts.zig, and remove the now unused constants (replaced by aformentioned enum values).
* glfw: Reference `Window.Hint` enum instead of `Window.Hints` struct to ensure fields are the same
* glfw: add comment explaining default values of `Window.Hints`
* glfw: change `OpenGlProfile` to `OpenGLProfile` based on established naming convention
* glfw: Update actual declaration of `OpenGLProfile`
* glfw: call `Window.defaultHints` after window creation, not before
* glfw: remove 'consts.zig', and move `dont_care` directly into 'main.zig'; fix anything referencing it.
* glfw: put `Window.defaultHints` into defer statement to handle cleanup in all paths
* glfw: move `Hint.focused` to match position of `Hints.focused`
* glfw: do 'zig fmt glfw/src'
* glfw: Cull `Window.Hint` comments, polish remaining; match order entirely according to current GLFW docs
* glfw: Change `Window.Hints.*Api` to `Window.Hints.*API`
Co-authored-by: Stephen Gutekanst <stephen@hexops.com>
2021-11-16 02:41:16 +01:00
const window = glfw . Window . create ( 640 , 480 , " Hello, Zig! " , null , null , . { } ) catch | err | {
2021-10-30 19:45:41 -07:00
// return without fail, because most of our CI environments are headless / we cannot open
// windows on them.
std . debug . print ( " note: failed to create window: {} \n " , . { err } ) ;
return ;
} ;
defer window . destroy ( ) ;
_ = window . getInputModeRawMouseMotion ( ) ;
}
test " setInputModeRawMouseMotion " {
2021-11-10 11:38:43 +01:00
try glfw . init ( . { } ) ;
2021-10-30 19:45:41 -07:00
defer glfw . terminate ( ) ;
glfw: window hints rework (#71)
* glfw: make comments into doc comments
* glfw: Publicize Window.CursorPos, Window.Size, Window.Pos, and Window.FrameSize
* glfw: Make enum value name the same format as other enum value names
* glfw: Window hints rework patch
* glfw: Relegate `Window.hint` to testing; move it down to just above the tests to reflect this, add doc comment line
* glfw: handle error `Error.InvalidEnum` explicitly, for clear error message in this unlikely edge case
* glfw: instate `Hint.context_no_error` as a hint, as it actually is specified to be a Window creation hint by the docs, and affirm removal of `Hint.context_revision`, which isn't.
The docs don't seem to specify a default value for `Hints.context_no_error` to take on, so we could set it based on `std.debug.runtime_safety` like this.
* glfw: default `context_no_error` to `false`, and added a note of caution about its usage as suggested.
* glfw: Inline enum values of `ClientApi`, `ContextCreationApi`, `ContextRobustness`, `ContextReleaseBehavior`, and `OpenGlProfile` from consts.zig, and remove the now unused constants (replaced by aformentioned enum values).
* glfw: Reference `Window.Hint` enum instead of `Window.Hints` struct to ensure fields are the same
* glfw: add comment explaining default values of `Window.Hints`
* glfw: change `OpenGlProfile` to `OpenGLProfile` based on established naming convention
* glfw: Update actual declaration of `OpenGLProfile`
* glfw: call `Window.defaultHints` after window creation, not before
* glfw: remove 'consts.zig', and move `dont_care` directly into 'main.zig'; fix anything referencing it.
* glfw: put `Window.defaultHints` into defer statement to handle cleanup in all paths
* glfw: move `Hint.focused` to match position of `Hints.focused`
* glfw: do 'zig fmt glfw/src'
* glfw: Cull `Window.Hint` comments, polish remaining; match order entirely according to current GLFW docs
* glfw: Change `Window.Hints.*Api` to `Window.Hints.*API`
Co-authored-by: Stephen Gutekanst <stephen@hexops.com>
2021-11-16 02:41:16 +01:00
const window = glfw . Window . create ( 640 , 480 , " Hello, Zig! " , null , null , . { } ) catch | err | {
2021-10-30 19:45:41 -07:00
// return without fail, because most of our CI environments are headless / we cannot open
// windows on them.
std . debug . print ( " note: failed to create window: {} \n " , . { err } ) ;
return ;
} ;
defer window . destroy ( ) ;
window . setInputModeRawMouseMotion ( false ) catch | err | std . debug . print ( " failed to set input mode, not supported? error={} \n " , . { err } ) ;
}
2021-10-23 13:36:36 -07:00
test " getInputMode " {
2021-11-10 11:38:43 +01:00
try glfw . init ( . { } ) ;
2021-10-23 13:36:36 -07:00
defer glfw . terminate ( ) ;
glfw: window hints rework (#71)
* glfw: make comments into doc comments
* glfw: Publicize Window.CursorPos, Window.Size, Window.Pos, and Window.FrameSize
* glfw: Make enum value name the same format as other enum value names
* glfw: Window hints rework patch
* glfw: Relegate `Window.hint` to testing; move it down to just above the tests to reflect this, add doc comment line
* glfw: handle error `Error.InvalidEnum` explicitly, for clear error message in this unlikely edge case
* glfw: instate `Hint.context_no_error` as a hint, as it actually is specified to be a Window creation hint by the docs, and affirm removal of `Hint.context_revision`, which isn't.
The docs don't seem to specify a default value for `Hints.context_no_error` to take on, so we could set it based on `std.debug.runtime_safety` like this.
* glfw: default `context_no_error` to `false`, and added a note of caution about its usage as suggested.
* glfw: Inline enum values of `ClientApi`, `ContextCreationApi`, `ContextRobustness`, `ContextReleaseBehavior`, and `OpenGlProfile` from consts.zig, and remove the now unused constants (replaced by aformentioned enum values).
* glfw: Reference `Window.Hint` enum instead of `Window.Hints` struct to ensure fields are the same
* glfw: add comment explaining default values of `Window.Hints`
* glfw: change `OpenGlProfile` to `OpenGLProfile` based on established naming convention
* glfw: Update actual declaration of `OpenGLProfile`
* glfw: call `Window.defaultHints` after window creation, not before
* glfw: remove 'consts.zig', and move `dont_care` directly into 'main.zig'; fix anything referencing it.
* glfw: put `Window.defaultHints` into defer statement to handle cleanup in all paths
* glfw: move `Hint.focused` to match position of `Hints.focused`
* glfw: do 'zig fmt glfw/src'
* glfw: Cull `Window.Hint` comments, polish remaining; match order entirely according to current GLFW docs
* glfw: Change `Window.Hints.*Api` to `Window.Hints.*API`
Co-authored-by: Stephen Gutekanst <stephen@hexops.com>
2021-11-16 02:41:16 +01:00
const window = glfw . Window . create ( 640 , 480 , " Hello, Zig! " , null , null , . { } ) catch | err | {
2021-10-23 13:36:36 -07:00
// return without fail, because most of our CI environments are headless / we cannot open
// windows on them.
std . debug . print ( " note: failed to create window: {} \n " , . { err } ) ;
return ;
} ;
defer window . destroy ( ) ;
2021-10-30 19:26:10 -07:00
_ = window . getInputMode ( glfw . Window . InputMode . raw_mouse_motion ) = = 1 ;
2021-10-23 13:36:36 -07:00
}
2021-10-23 13:31:58 -07:00
test " setInputMode " {
2021-11-10 11:38:43 +01:00
try glfw . init ( . { } ) ;
2021-10-23 13:31:58 -07:00
defer glfw . terminate ( ) ;
glfw: window hints rework (#71)
* glfw: make comments into doc comments
* glfw: Publicize Window.CursorPos, Window.Size, Window.Pos, and Window.FrameSize
* glfw: Make enum value name the same format as other enum value names
* glfw: Window hints rework patch
* glfw: Relegate `Window.hint` to testing; move it down to just above the tests to reflect this, add doc comment line
* glfw: handle error `Error.InvalidEnum` explicitly, for clear error message in this unlikely edge case
* glfw: instate `Hint.context_no_error` as a hint, as it actually is specified to be a Window creation hint by the docs, and affirm removal of `Hint.context_revision`, which isn't.
The docs don't seem to specify a default value for `Hints.context_no_error` to take on, so we could set it based on `std.debug.runtime_safety` like this.
* glfw: default `context_no_error` to `false`, and added a note of caution about its usage as suggested.
* glfw: Inline enum values of `ClientApi`, `ContextCreationApi`, `ContextRobustness`, `ContextReleaseBehavior`, and `OpenGlProfile` from consts.zig, and remove the now unused constants (replaced by aformentioned enum values).
* glfw: Reference `Window.Hint` enum instead of `Window.Hints` struct to ensure fields are the same
* glfw: add comment explaining default values of `Window.Hints`
* glfw: change `OpenGlProfile` to `OpenGLProfile` based on established naming convention
* glfw: Update actual declaration of `OpenGLProfile`
* glfw: call `Window.defaultHints` after window creation, not before
* glfw: remove 'consts.zig', and move `dont_care` directly into 'main.zig'; fix anything referencing it.
* glfw: put `Window.defaultHints` into defer statement to handle cleanup in all paths
* glfw: move `Hint.focused` to match position of `Hints.focused`
* glfw: do 'zig fmt glfw/src'
* glfw: Cull `Window.Hint` comments, polish remaining; match order entirely according to current GLFW docs
* glfw: Change `Window.Hints.*Api` to `Window.Hints.*API`
Co-authored-by: Stephen Gutekanst <stephen@hexops.com>
2021-11-16 02:41:16 +01:00
const window = glfw . Window . create ( 640 , 480 , " Hello, Zig! " , null , null , . { } ) catch | err | {
2021-10-23 13:31:58 -07:00
// return without fail, because most of our CI environments are headless / we cannot open
// windows on them.
std . debug . print ( " note: failed to create window: {} \n " , . { err } ) ;
return ;
} ;
defer window . destroy ( ) ;
// Boolean values.
2021-10-30 19:26:10 -07:00
window . setInputMode ( glfw . Window . InputMode . sticky_mouse_buttons , true ) catch | err | std . debug . print ( " failed to set input mode, not supported? error={} \n " , . { err } ) ;
2021-10-23 13:31:58 -07:00
// Integer values.
2021-10-30 19:26:10 -07:00
window . setInputMode ( glfw . Window . InputMode . cursor , glfw . Window . InputModeCursor . hidden ) catch | err | std . debug . print ( " failed to set input mode, not supported? error={} \n " , . { err } ) ;
2021-10-23 13:31:58 -07:00
}
2021-10-23 13:13:30 -07:00
test " getKey " {
2021-11-10 11:38:43 +01:00
try glfw . init ( . { } ) ;
2021-10-23 13:13:30 -07:00
defer glfw . terminate ( ) ;
glfw: window hints rework (#71)
* glfw: make comments into doc comments
* glfw: Publicize Window.CursorPos, Window.Size, Window.Pos, and Window.FrameSize
* glfw: Make enum value name the same format as other enum value names
* glfw: Window hints rework patch
* glfw: Relegate `Window.hint` to testing; move it down to just above the tests to reflect this, add doc comment line
* glfw: handle error `Error.InvalidEnum` explicitly, for clear error message in this unlikely edge case
* glfw: instate `Hint.context_no_error` as a hint, as it actually is specified to be a Window creation hint by the docs, and affirm removal of `Hint.context_revision`, which isn't.
The docs don't seem to specify a default value for `Hints.context_no_error` to take on, so we could set it based on `std.debug.runtime_safety` like this.
* glfw: default `context_no_error` to `false`, and added a note of caution about its usage as suggested.
* glfw: Inline enum values of `ClientApi`, `ContextCreationApi`, `ContextRobustness`, `ContextReleaseBehavior`, and `OpenGlProfile` from consts.zig, and remove the now unused constants (replaced by aformentioned enum values).
* glfw: Reference `Window.Hint` enum instead of `Window.Hints` struct to ensure fields are the same
* glfw: add comment explaining default values of `Window.Hints`
* glfw: change `OpenGlProfile` to `OpenGLProfile` based on established naming convention
* glfw: Update actual declaration of `OpenGLProfile`
* glfw: call `Window.defaultHints` after window creation, not before
* glfw: remove 'consts.zig', and move `dont_care` directly into 'main.zig'; fix anything referencing it.
* glfw: put `Window.defaultHints` into defer statement to handle cleanup in all paths
* glfw: move `Hint.focused` to match position of `Hints.focused`
* glfw: do 'zig fmt glfw/src'
* glfw: Cull `Window.Hint` comments, polish remaining; match order entirely according to current GLFW docs
* glfw: Change `Window.Hints.*Api` to `Window.Hints.*API`
Co-authored-by: Stephen Gutekanst <stephen@hexops.com>
2021-11-16 02:41:16 +01:00
const window = glfw . Window . create ( 640 , 480 , " Hello, Zig! " , null , null , . { } ) catch | err | {
2021-10-23 13:13:30 -07:00
// return without fail, because most of our CI environments are headless / we cannot open
// windows on them.
std . debug . print ( " note: failed to create window: {} \n " , . { err } ) ;
return ;
} ;
defer window . destroy ( ) ;
2021-10-24 15:23:20 +02:00
_ = try window . getKey ( glfw . Key . escape ) ;
2021-10-23 13:13:30 -07:00
}
2021-10-23 13:06:18 -07:00
test " getMouseButton " {
2021-11-10 11:38:43 +01:00
try glfw . init ( . { } ) ;
2021-10-23 13:06:18 -07:00
defer glfw . terminate ( ) ;
glfw: window hints rework (#71)
* glfw: make comments into doc comments
* glfw: Publicize Window.CursorPos, Window.Size, Window.Pos, and Window.FrameSize
* glfw: Make enum value name the same format as other enum value names
* glfw: Window hints rework patch
* glfw: Relegate `Window.hint` to testing; move it down to just above the tests to reflect this, add doc comment line
* glfw: handle error `Error.InvalidEnum` explicitly, for clear error message in this unlikely edge case
* glfw: instate `Hint.context_no_error` as a hint, as it actually is specified to be a Window creation hint by the docs, and affirm removal of `Hint.context_revision`, which isn't.
The docs don't seem to specify a default value for `Hints.context_no_error` to take on, so we could set it based on `std.debug.runtime_safety` like this.
* glfw: default `context_no_error` to `false`, and added a note of caution about its usage as suggested.
* glfw: Inline enum values of `ClientApi`, `ContextCreationApi`, `ContextRobustness`, `ContextReleaseBehavior`, and `OpenGlProfile` from consts.zig, and remove the now unused constants (replaced by aformentioned enum values).
* glfw: Reference `Window.Hint` enum instead of `Window.Hints` struct to ensure fields are the same
* glfw: add comment explaining default values of `Window.Hints`
* glfw: change `OpenGlProfile` to `OpenGLProfile` based on established naming convention
* glfw: Update actual declaration of `OpenGLProfile`
* glfw: call `Window.defaultHints` after window creation, not before
* glfw: remove 'consts.zig', and move `dont_care` directly into 'main.zig'; fix anything referencing it.
* glfw: put `Window.defaultHints` into defer statement to handle cleanup in all paths
* glfw: move `Hint.focused` to match position of `Hints.focused`
* glfw: do 'zig fmt glfw/src'
* glfw: Cull `Window.Hint` comments, polish remaining; match order entirely according to current GLFW docs
* glfw: Change `Window.Hints.*Api` to `Window.Hints.*API`
Co-authored-by: Stephen Gutekanst <stephen@hexops.com>
2021-11-16 02:41:16 +01:00
const window = glfw . Window . create ( 640 , 480 , " Hello, Zig! " , null , null , . { } ) catch | err | {
2021-10-23 13:06:18 -07:00
// return without fail, because most of our CI environments are headless / we cannot open
// windows on them.
std . debug . print ( " note: failed to create window: {} \n " , . { err } ) ;
return ;
} ;
defer window . destroy ( ) ;
2021-10-30 15:35:04 -07:00
_ = try window . getMouseButton ( . left ) ;
2021-10-23 13:06:18 -07:00
}
2021-10-23 12:45:49 -07:00
test " getCursorPos " {
2021-11-10 11:38:43 +01:00
try glfw . init ( . { } ) ;
2021-10-23 12:45:49 -07:00
defer glfw . terminate ( ) ;
glfw: window hints rework (#71)
* glfw: make comments into doc comments
* glfw: Publicize Window.CursorPos, Window.Size, Window.Pos, and Window.FrameSize
* glfw: Make enum value name the same format as other enum value names
* glfw: Window hints rework patch
* glfw: Relegate `Window.hint` to testing; move it down to just above the tests to reflect this, add doc comment line
* glfw: handle error `Error.InvalidEnum` explicitly, for clear error message in this unlikely edge case
* glfw: instate `Hint.context_no_error` as a hint, as it actually is specified to be a Window creation hint by the docs, and affirm removal of `Hint.context_revision`, which isn't.
The docs don't seem to specify a default value for `Hints.context_no_error` to take on, so we could set it based on `std.debug.runtime_safety` like this.
* glfw: default `context_no_error` to `false`, and added a note of caution about its usage as suggested.
* glfw: Inline enum values of `ClientApi`, `ContextCreationApi`, `ContextRobustness`, `ContextReleaseBehavior`, and `OpenGlProfile` from consts.zig, and remove the now unused constants (replaced by aformentioned enum values).
* glfw: Reference `Window.Hint` enum instead of `Window.Hints` struct to ensure fields are the same
* glfw: add comment explaining default values of `Window.Hints`
* glfw: change `OpenGlProfile` to `OpenGLProfile` based on established naming convention
* glfw: Update actual declaration of `OpenGLProfile`
* glfw: call `Window.defaultHints` after window creation, not before
* glfw: remove 'consts.zig', and move `dont_care` directly into 'main.zig'; fix anything referencing it.
* glfw: put `Window.defaultHints` into defer statement to handle cleanup in all paths
* glfw: move `Hint.focused` to match position of `Hints.focused`
* glfw: do 'zig fmt glfw/src'
* glfw: Cull `Window.Hint` comments, polish remaining; match order entirely according to current GLFW docs
* glfw: Change `Window.Hints.*Api` to `Window.Hints.*API`
Co-authored-by: Stephen Gutekanst <stephen@hexops.com>
2021-11-16 02:41:16 +01:00
const window = glfw . Window . create ( 640 , 480 , " Hello, Zig! " , null , null , . { } ) catch | err | {
2021-10-23 12:45:49 -07:00
// return without fail, because most of our CI environments are headless / we cannot open
// windows on them.
std . debug . print ( " note: failed to create window: {} \n " , . { err } ) ;
return ;
} ;
defer window . destroy ( ) ;
_ = window . getCursorPos ( ) catch | err | std . debug . print ( " failed to get cursor pos, not supported? error={} \n " , . { err } ) ;
}
2021-10-23 12:41:38 -07:00
test " setCursorPos " {
2021-11-10 11:38:43 +01:00
try glfw . init ( . { } ) ;
2021-10-23 12:41:38 -07:00
defer glfw . terminate ( ) ;
glfw: window hints rework (#71)
* glfw: make comments into doc comments
* glfw: Publicize Window.CursorPos, Window.Size, Window.Pos, and Window.FrameSize
* glfw: Make enum value name the same format as other enum value names
* glfw: Window hints rework patch
* glfw: Relegate `Window.hint` to testing; move it down to just above the tests to reflect this, add doc comment line
* glfw: handle error `Error.InvalidEnum` explicitly, for clear error message in this unlikely edge case
* glfw: instate `Hint.context_no_error` as a hint, as it actually is specified to be a Window creation hint by the docs, and affirm removal of `Hint.context_revision`, which isn't.
The docs don't seem to specify a default value for `Hints.context_no_error` to take on, so we could set it based on `std.debug.runtime_safety` like this.
* glfw: default `context_no_error` to `false`, and added a note of caution about its usage as suggested.
* glfw: Inline enum values of `ClientApi`, `ContextCreationApi`, `ContextRobustness`, `ContextReleaseBehavior`, and `OpenGlProfile` from consts.zig, and remove the now unused constants (replaced by aformentioned enum values).
* glfw: Reference `Window.Hint` enum instead of `Window.Hints` struct to ensure fields are the same
* glfw: add comment explaining default values of `Window.Hints`
* glfw: change `OpenGlProfile` to `OpenGLProfile` based on established naming convention
* glfw: Update actual declaration of `OpenGLProfile`
* glfw: call `Window.defaultHints` after window creation, not before
* glfw: remove 'consts.zig', and move `dont_care` directly into 'main.zig'; fix anything referencing it.
* glfw: put `Window.defaultHints` into defer statement to handle cleanup in all paths
* glfw: move `Hint.focused` to match position of `Hints.focused`
* glfw: do 'zig fmt glfw/src'
* glfw: Cull `Window.Hint` comments, polish remaining; match order entirely according to current GLFW docs
* glfw: Change `Window.Hints.*Api` to `Window.Hints.*API`
Co-authored-by: Stephen Gutekanst <stephen@hexops.com>
2021-11-16 02:41:16 +01:00
const window = glfw . Window . create ( 640 , 480 , " Hello, Zig! " , null , null , . { } ) catch | err | {
2021-10-23 12:41:38 -07:00
// return without fail, because most of our CI environments are headless / we cannot open
// windows on them.
std . debug . print ( " note: failed to create window: {} \n " , . { err } ) ;
return ;
} ;
defer window . destroy ( ) ;
window . setCursorPos ( 0 , 0 ) catch | err | std . debug . print ( " failed to set cursor pos, not supported? error={} \n " , . { err } ) ;
}
test " setCursor " {
2021-11-10 11:38:43 +01:00
try glfw . init ( . { } ) ;
2021-10-23 12:34:59 -07:00
defer glfw . terminate ( ) ;
glfw: window hints rework (#71)
* glfw: make comments into doc comments
* glfw: Publicize Window.CursorPos, Window.Size, Window.Pos, and Window.FrameSize
* glfw: Make enum value name the same format as other enum value names
* glfw: Window hints rework patch
* glfw: Relegate `Window.hint` to testing; move it down to just above the tests to reflect this, add doc comment line
* glfw: handle error `Error.InvalidEnum` explicitly, for clear error message in this unlikely edge case
* glfw: instate `Hint.context_no_error` as a hint, as it actually is specified to be a Window creation hint by the docs, and affirm removal of `Hint.context_revision`, which isn't.
The docs don't seem to specify a default value for `Hints.context_no_error` to take on, so we could set it based on `std.debug.runtime_safety` like this.
* glfw: default `context_no_error` to `false`, and added a note of caution about its usage as suggested.
* glfw: Inline enum values of `ClientApi`, `ContextCreationApi`, `ContextRobustness`, `ContextReleaseBehavior`, and `OpenGlProfile` from consts.zig, and remove the now unused constants (replaced by aformentioned enum values).
* glfw: Reference `Window.Hint` enum instead of `Window.Hints` struct to ensure fields are the same
* glfw: add comment explaining default values of `Window.Hints`
* glfw: change `OpenGlProfile` to `OpenGLProfile` based on established naming convention
* glfw: Update actual declaration of `OpenGLProfile`
* glfw: call `Window.defaultHints` after window creation, not before
* glfw: remove 'consts.zig', and move `dont_care` directly into 'main.zig'; fix anything referencing it.
* glfw: put `Window.defaultHints` into defer statement to handle cleanup in all paths
* glfw: move `Hint.focused` to match position of `Hints.focused`
* glfw: do 'zig fmt glfw/src'
* glfw: Cull `Window.Hint` comments, polish remaining; match order entirely according to current GLFW docs
* glfw: Change `Window.Hints.*Api` to `Window.Hints.*API`
Co-authored-by: Stephen Gutekanst <stephen@hexops.com>
2021-11-16 02:41:16 +01:00
const window = glfw . Window . create ( 640 , 480 , " Hello, Zig! " , null , null , . { } ) catch | err | {
2021-10-23 12:34:59 -07:00
// return without fail, because most of our CI environments are headless / we cannot open
// windows on them.
std . debug . print ( " note: failed to create window: {} \n " , . { err } ) ;
return ;
} ;
defer window . destroy ( ) ;
const cursor = glfw . Cursor . createStandard ( . ibeam ) catch | err | {
std . debug . print ( " failed to create cursor, custom cursors not supported? error={} \n " , . { err } ) ;
return ;
} ;
defer cursor . destroy ( ) ;
window . setCursor ( cursor ) catch | err | std . debug . print ( " failed to set cursor, custom cursors not supported? error={} \n " , . { err } ) ;
}
2021-10-23 12:29:25 -07:00
test " setKeyCallback " {
2021-11-10 11:38:43 +01:00
try glfw . init ( . { } ) ;
2021-10-23 11:37:36 -07:00
defer glfw . terminate ( ) ;
glfw: window hints rework (#71)
* glfw: make comments into doc comments
* glfw: Publicize Window.CursorPos, Window.Size, Window.Pos, and Window.FrameSize
* glfw: Make enum value name the same format as other enum value names
* glfw: Window hints rework patch
* glfw: Relegate `Window.hint` to testing; move it down to just above the tests to reflect this, add doc comment line
* glfw: handle error `Error.InvalidEnum` explicitly, for clear error message in this unlikely edge case
* glfw: instate `Hint.context_no_error` as a hint, as it actually is specified to be a Window creation hint by the docs, and affirm removal of `Hint.context_revision`, which isn't.
The docs don't seem to specify a default value for `Hints.context_no_error` to take on, so we could set it based on `std.debug.runtime_safety` like this.
* glfw: default `context_no_error` to `false`, and added a note of caution about its usage as suggested.
* glfw: Inline enum values of `ClientApi`, `ContextCreationApi`, `ContextRobustness`, `ContextReleaseBehavior`, and `OpenGlProfile` from consts.zig, and remove the now unused constants (replaced by aformentioned enum values).
* glfw: Reference `Window.Hint` enum instead of `Window.Hints` struct to ensure fields are the same
* glfw: add comment explaining default values of `Window.Hints`
* glfw: change `OpenGlProfile` to `OpenGLProfile` based on established naming convention
* glfw: Update actual declaration of `OpenGLProfile`
* glfw: call `Window.defaultHints` after window creation, not before
* glfw: remove 'consts.zig', and move `dont_care` directly into 'main.zig'; fix anything referencing it.
* glfw: put `Window.defaultHints` into defer statement to handle cleanup in all paths
* glfw: move `Hint.focused` to match position of `Hints.focused`
* glfw: do 'zig fmt glfw/src'
* glfw: Cull `Window.Hint` comments, polish remaining; match order entirely according to current GLFW docs
* glfw: Change `Window.Hints.*Api` to `Window.Hints.*API`
Co-authored-by: Stephen Gutekanst <stephen@hexops.com>
2021-11-16 02:41:16 +01:00
const window = glfw . Window . create ( 640 , 480 , " Hello, Zig! " , null , null , . { } ) catch | err | {
2021-10-23 11:37:36 -07:00
// return without fail, because most of our CI environments are headless / we cannot open
// windows on them.
std . debug . print ( " note: failed to create window: {} \n " , . { err } ) ;
return ;
} ;
defer window . destroy ( ) ;
2021-10-23 12:29:25 -07:00
window . setKeyCallback ( ( struct {
2021-10-30 14:10:31 -07:00
fn callback ( _window : Window , key : Key , scancode : isize , action : Action , mods : Mods ) void {
2021-10-23 11:37:36 -07:00
_ = _window ;
2021-10-23 12:29:25 -07:00
_ = key ;
_ = scancode ;
_ = action ;
_ = mods ;
2021-10-23 11:37:36 -07:00
}
} ) . callback ) ;
}
2021-10-23 11:42:26 -07:00
2021-10-23 12:29:25 -07:00
test " setCharCallback " {
2021-11-10 11:38:43 +01:00
try glfw . init ( . { } ) ;
2021-10-23 11:42:26 -07:00
defer glfw . terminate ( ) ;
glfw: window hints rework (#71)
* glfw: make comments into doc comments
* glfw: Publicize Window.CursorPos, Window.Size, Window.Pos, and Window.FrameSize
* glfw: Make enum value name the same format as other enum value names
* glfw: Window hints rework patch
* glfw: Relegate `Window.hint` to testing; move it down to just above the tests to reflect this, add doc comment line
* glfw: handle error `Error.InvalidEnum` explicitly, for clear error message in this unlikely edge case
* glfw: instate `Hint.context_no_error` as a hint, as it actually is specified to be a Window creation hint by the docs, and affirm removal of `Hint.context_revision`, which isn't.
The docs don't seem to specify a default value for `Hints.context_no_error` to take on, so we could set it based on `std.debug.runtime_safety` like this.
* glfw: default `context_no_error` to `false`, and added a note of caution about its usage as suggested.
* glfw: Inline enum values of `ClientApi`, `ContextCreationApi`, `ContextRobustness`, `ContextReleaseBehavior`, and `OpenGlProfile` from consts.zig, and remove the now unused constants (replaced by aformentioned enum values).
* glfw: Reference `Window.Hint` enum instead of `Window.Hints` struct to ensure fields are the same
* glfw: add comment explaining default values of `Window.Hints`
* glfw: change `OpenGlProfile` to `OpenGLProfile` based on established naming convention
* glfw: Update actual declaration of `OpenGLProfile`
* glfw: call `Window.defaultHints` after window creation, not before
* glfw: remove 'consts.zig', and move `dont_care` directly into 'main.zig'; fix anything referencing it.
* glfw: put `Window.defaultHints` into defer statement to handle cleanup in all paths
* glfw: move `Hint.focused` to match position of `Hints.focused`
* glfw: do 'zig fmt glfw/src'
* glfw: Cull `Window.Hint` comments, polish remaining; match order entirely according to current GLFW docs
* glfw: Change `Window.Hints.*Api` to `Window.Hints.*API`
Co-authored-by: Stephen Gutekanst <stephen@hexops.com>
2021-11-16 02:41:16 +01:00
const window = glfw . Window . create ( 640 , 480 , " Hello, Zig! " , null , null , . { } ) catch | err | {
2021-10-23 11:42:26 -07:00
// return without fail, because most of our CI environments are headless / we cannot open
// windows on them.
std . debug . print ( " note: failed to create window: {} \n " , . { err } ) ;
return ;
} ;
defer window . destroy ( ) ;
2021-10-23 12:29:25 -07:00
window . setCharCallback ( ( struct {
fn callback ( _window : Window , codepoint : u21 ) void {
2021-10-23 11:42:26 -07:00
_ = _window ;
2021-10-23 12:29:25 -07:00
_ = codepoint ;
2021-10-23 11:42:26 -07:00
}
} ) . callback ) ;
}
2021-10-23 11:46:58 -07:00
2021-10-23 12:29:25 -07:00
test " setMouseButtonCallback " {
2021-11-10 11:38:43 +01:00
try glfw . init ( . { } ) ;
2021-10-23 11:46:58 -07:00
defer glfw . terminate ( ) ;
glfw: window hints rework (#71)
* glfw: make comments into doc comments
* glfw: Publicize Window.CursorPos, Window.Size, Window.Pos, and Window.FrameSize
* glfw: Make enum value name the same format as other enum value names
* glfw: Window hints rework patch
* glfw: Relegate `Window.hint` to testing; move it down to just above the tests to reflect this, add doc comment line
* glfw: handle error `Error.InvalidEnum` explicitly, for clear error message in this unlikely edge case
* glfw: instate `Hint.context_no_error` as a hint, as it actually is specified to be a Window creation hint by the docs, and affirm removal of `Hint.context_revision`, which isn't.
The docs don't seem to specify a default value for `Hints.context_no_error` to take on, so we could set it based on `std.debug.runtime_safety` like this.
* glfw: default `context_no_error` to `false`, and added a note of caution about its usage as suggested.
* glfw: Inline enum values of `ClientApi`, `ContextCreationApi`, `ContextRobustness`, `ContextReleaseBehavior`, and `OpenGlProfile` from consts.zig, and remove the now unused constants (replaced by aformentioned enum values).
* glfw: Reference `Window.Hint` enum instead of `Window.Hints` struct to ensure fields are the same
* glfw: add comment explaining default values of `Window.Hints`
* glfw: change `OpenGlProfile` to `OpenGLProfile` based on established naming convention
* glfw: Update actual declaration of `OpenGLProfile`
* glfw: call `Window.defaultHints` after window creation, not before
* glfw: remove 'consts.zig', and move `dont_care` directly into 'main.zig'; fix anything referencing it.
* glfw: put `Window.defaultHints` into defer statement to handle cleanup in all paths
* glfw: move `Hint.focused` to match position of `Hints.focused`
* glfw: do 'zig fmt glfw/src'
* glfw: Cull `Window.Hint` comments, polish remaining; match order entirely according to current GLFW docs
* glfw: Change `Window.Hints.*Api` to `Window.Hints.*API`
Co-authored-by: Stephen Gutekanst <stephen@hexops.com>
2021-11-16 02:41:16 +01:00
const window = glfw . Window . create ( 640 , 480 , " Hello, Zig! " , null , null , . { } ) catch | err | {
2021-10-23 11:46:58 -07:00
// return without fail, because most of our CI environments are headless / we cannot open
// windows on them.
std . debug . print ( " note: failed to create window: {} \n " , . { err } ) ;
return ;
} ;
defer window . destroy ( ) ;
2021-10-23 12:29:25 -07:00
window . setMouseButtonCallback ( ( struct {
2021-10-30 15:35:04 -07:00
fn callback ( _window : Window , button : MouseButton , action : Action , mods : Mods ) void {
2021-10-23 11:46:58 -07:00
_ = _window ;
2021-10-23 12:29:25 -07:00
_ = button ;
_ = action ;
_ = mods ;
2021-10-23 11:46:58 -07:00
}
} ) . callback ) ;
}
2021-10-23 12:01:13 -07:00
2021-10-23 12:29:25 -07:00
test " setCursorPosCallback " {
2021-11-10 11:38:43 +01:00
try glfw . init ( . { } ) ;
2021-10-23 12:01:13 -07:00
defer glfw . terminate ( ) ;
glfw: window hints rework (#71)
* glfw: make comments into doc comments
* glfw: Publicize Window.CursorPos, Window.Size, Window.Pos, and Window.FrameSize
* glfw: Make enum value name the same format as other enum value names
* glfw: Window hints rework patch
* glfw: Relegate `Window.hint` to testing; move it down to just above the tests to reflect this, add doc comment line
* glfw: handle error `Error.InvalidEnum` explicitly, for clear error message in this unlikely edge case
* glfw: instate `Hint.context_no_error` as a hint, as it actually is specified to be a Window creation hint by the docs, and affirm removal of `Hint.context_revision`, which isn't.
The docs don't seem to specify a default value for `Hints.context_no_error` to take on, so we could set it based on `std.debug.runtime_safety` like this.
* glfw: default `context_no_error` to `false`, and added a note of caution about its usage as suggested.
* glfw: Inline enum values of `ClientApi`, `ContextCreationApi`, `ContextRobustness`, `ContextReleaseBehavior`, and `OpenGlProfile` from consts.zig, and remove the now unused constants (replaced by aformentioned enum values).
* glfw: Reference `Window.Hint` enum instead of `Window.Hints` struct to ensure fields are the same
* glfw: add comment explaining default values of `Window.Hints`
* glfw: change `OpenGlProfile` to `OpenGLProfile` based on established naming convention
* glfw: Update actual declaration of `OpenGLProfile`
* glfw: call `Window.defaultHints` after window creation, not before
* glfw: remove 'consts.zig', and move `dont_care` directly into 'main.zig'; fix anything referencing it.
* glfw: put `Window.defaultHints` into defer statement to handle cleanup in all paths
* glfw: move `Hint.focused` to match position of `Hints.focused`
* glfw: do 'zig fmt glfw/src'
* glfw: Cull `Window.Hint` comments, polish remaining; match order entirely according to current GLFW docs
* glfw: Change `Window.Hints.*Api` to `Window.Hints.*API`
Co-authored-by: Stephen Gutekanst <stephen@hexops.com>
2021-11-16 02:41:16 +01:00
const window = glfw . Window . create ( 640 , 480 , " Hello, Zig! " , null , null , . { } ) catch | err | {
2021-10-23 12:01:13 -07:00
// return without fail, because most of our CI environments are headless / we cannot open
// windows on them.
std . debug . print ( " note: failed to create window: {} \n " , . { err } ) ;
return ;
} ;
defer window . destroy ( ) ;
2021-10-23 12:29:25 -07:00
window . setCursorPosCallback ( ( struct {
fn callback ( _window : Window , xpos : f64 , ypos : f64 ) void {
2021-10-23 12:01:13 -07:00
_ = _window ;
2021-10-23 12:29:25 -07:00
_ = xpos ;
_ = ypos ;
2021-10-23 12:01:13 -07:00
}
} ) . callback ) ;
}
2021-10-23 12:12:13 -07:00
2021-10-23 12:29:25 -07:00
test " setCursorEnterCallback " {
2021-11-10 11:38:43 +01:00
try glfw . init ( . { } ) ;
2021-10-23 12:12:13 -07:00
defer glfw . terminate ( ) ;
glfw: window hints rework (#71)
* glfw: make comments into doc comments
* glfw: Publicize Window.CursorPos, Window.Size, Window.Pos, and Window.FrameSize
* glfw: Make enum value name the same format as other enum value names
* glfw: Window hints rework patch
* glfw: Relegate `Window.hint` to testing; move it down to just above the tests to reflect this, add doc comment line
* glfw: handle error `Error.InvalidEnum` explicitly, for clear error message in this unlikely edge case
* glfw: instate `Hint.context_no_error` as a hint, as it actually is specified to be a Window creation hint by the docs, and affirm removal of `Hint.context_revision`, which isn't.
The docs don't seem to specify a default value for `Hints.context_no_error` to take on, so we could set it based on `std.debug.runtime_safety` like this.
* glfw: default `context_no_error` to `false`, and added a note of caution about its usage as suggested.
* glfw: Inline enum values of `ClientApi`, `ContextCreationApi`, `ContextRobustness`, `ContextReleaseBehavior`, and `OpenGlProfile` from consts.zig, and remove the now unused constants (replaced by aformentioned enum values).
* glfw: Reference `Window.Hint` enum instead of `Window.Hints` struct to ensure fields are the same
* glfw: add comment explaining default values of `Window.Hints`
* glfw: change `OpenGlProfile` to `OpenGLProfile` based on established naming convention
* glfw: Update actual declaration of `OpenGLProfile`
* glfw: call `Window.defaultHints` after window creation, not before
* glfw: remove 'consts.zig', and move `dont_care` directly into 'main.zig'; fix anything referencing it.
* glfw: put `Window.defaultHints` into defer statement to handle cleanup in all paths
* glfw: move `Hint.focused` to match position of `Hints.focused`
* glfw: do 'zig fmt glfw/src'
* glfw: Cull `Window.Hint` comments, polish remaining; match order entirely according to current GLFW docs
* glfw: Change `Window.Hints.*Api` to `Window.Hints.*API`
Co-authored-by: Stephen Gutekanst <stephen@hexops.com>
2021-11-16 02:41:16 +01:00
const window = glfw . Window . create ( 640 , 480 , " Hello, Zig! " , null , null , . { } ) catch | err | {
2021-10-23 12:12:13 -07:00
// return without fail, because most of our CI environments are headless / we cannot open
// windows on them.
std . debug . print ( " note: failed to create window: {} \n " , . { err } ) ;
return ;
} ;
defer window . destroy ( ) ;
2021-10-23 12:29:25 -07:00
window . setCursorEnterCallback ( ( struct {
fn callback ( _window : Window , entered : bool ) void {
2021-10-23 12:12:13 -07:00
_ = _window ;
2021-10-23 12:29:25 -07:00
_ = entered ;
2021-10-23 12:12:13 -07:00
}
} ) . callback ) ;
}
2021-10-23 12:25:57 -07:00
2021-10-23 12:29:25 -07:00
test " setScrollCallback " {
2021-11-10 11:38:43 +01:00
try glfw . init ( . { } ) ;
2021-10-23 12:25:57 -07:00
defer glfw . terminate ( ) ;
glfw: window hints rework (#71)
* glfw: make comments into doc comments
* glfw: Publicize Window.CursorPos, Window.Size, Window.Pos, and Window.FrameSize
* glfw: Make enum value name the same format as other enum value names
* glfw: Window hints rework patch
* glfw: Relegate `Window.hint` to testing; move it down to just above the tests to reflect this, add doc comment line
* glfw: handle error `Error.InvalidEnum` explicitly, for clear error message in this unlikely edge case
* glfw: instate `Hint.context_no_error` as a hint, as it actually is specified to be a Window creation hint by the docs, and affirm removal of `Hint.context_revision`, which isn't.
The docs don't seem to specify a default value for `Hints.context_no_error` to take on, so we could set it based on `std.debug.runtime_safety` like this.
* glfw: default `context_no_error` to `false`, and added a note of caution about its usage as suggested.
* glfw: Inline enum values of `ClientApi`, `ContextCreationApi`, `ContextRobustness`, `ContextReleaseBehavior`, and `OpenGlProfile` from consts.zig, and remove the now unused constants (replaced by aformentioned enum values).
* glfw: Reference `Window.Hint` enum instead of `Window.Hints` struct to ensure fields are the same
* glfw: add comment explaining default values of `Window.Hints`
* glfw: change `OpenGlProfile` to `OpenGLProfile` based on established naming convention
* glfw: Update actual declaration of `OpenGLProfile`
* glfw: call `Window.defaultHints` after window creation, not before
* glfw: remove 'consts.zig', and move `dont_care` directly into 'main.zig'; fix anything referencing it.
* glfw: put `Window.defaultHints` into defer statement to handle cleanup in all paths
* glfw: move `Hint.focused` to match position of `Hints.focused`
* glfw: do 'zig fmt glfw/src'
* glfw: Cull `Window.Hint` comments, polish remaining; match order entirely according to current GLFW docs
* glfw: Change `Window.Hints.*Api` to `Window.Hints.*API`
Co-authored-by: Stephen Gutekanst <stephen@hexops.com>
2021-11-16 02:41:16 +01:00
const window = glfw . Window . create ( 640 , 480 , " Hello, Zig! " , null , null , . { } ) catch | err | {
2021-10-23 12:25:57 -07:00
// return without fail, because most of our CI environments are headless / we cannot open
// windows on them.
std . debug . print ( " note: failed to create window: {} \n " , . { err } ) ;
return ;
} ;
defer window . destroy ( ) ;
2021-10-23 12:29:25 -07:00
window . setScrollCallback ( ( struct {
fn callback ( _window : Window , xoffset : f64 , yoffset : f64 ) void {
2021-10-23 12:25:57 -07:00
_ = _window ;
2021-10-23 12:29:25 -07:00
_ = xoffset ;
_ = yoffset ;
2021-10-23 12:25:57 -07:00
}
} ) . callback ) ;
}
2021-11-20 20:42:52 +01:00
test " hint-attribute default value parity " {
try glfw . init ( . { } ) ;
defer glfw . terminate ( ) ;
testing_ignore_window_hints_struct = true ;
const window_a = Window . create ( 640 , 480 , " Hello, Zig! " , null , null , undefined ) catch | err | {
// return without fail, because most of our CI environments are headless / we cannot open
// windows on them.
std . debug . print ( " note: failed to create window_a: {} \n " , . { err } ) ;
return ;
} ;
defer window_a . destroy ( ) ;
testing_ignore_window_hints_struct = false ;
const window_b = Window . create ( 640 , 480 , " Hello, Zig! " , null , null , . { } ) catch | err | {
// return without fail, because most of our CI environments are headless / we cannot open
// windows on them.
std . debug . print ( " note: failed to create window_b: {} \n " , . { err } ) ;
return ;
} ;
defer window_b . destroy ( ) ;
inline for ( comptime std . enums . values ( Window . Hint ) ) | hint_tag | {
if ( @hasField ( Window . Attrib , @tagName ( hint_tag ) ) ) {
const attrib_tag = @field ( Window . Attrib , @tagName ( hint_tag ) ) ;
switch ( attrib_tag ) {
. resizable ,
. visible ,
. decorated ,
. auto_iconify ,
. floating ,
. maximized ,
. transparent_framebuffer ,
. focus_on_show ,
. client_api ,
. context_creation_api ,
. context_version_major ,
. context_version_minor ,
. context_robustness ,
. context_release_behavior ,
. context_no_error , // Note: at the time of writing this, GLFW does not list the default value for this hint in the documentation
. opengl_forward_compat ,
. opengl_debug_context ,
. opengl_profile ,
= > {
const expected = window_a . getAttrib ( attrib_tag ) catch | err | {
std . debug . print ( " Failed to get attribute '{}' value from window_a with error '{}'. \n " , . { attrib_tag , err } ) ;
return ;
} ;
const actual = window_b . getAttrib ( attrib_tag ) catch | err | {
std . debug . print ( " Failed to get attribute '{}' value from window_b with error '{}'. \n " , . { attrib_tag , err } ) ;
return ;
} ;
testing . expectEqual ( expected , actual ) catch | err | {
std . debug . print ( " On attribute '{}'. \n " , . { hint_tag } ) ;
return err ;
} ;
} ,
// This attribute is based on a check for which window is currently in focus,
// and the default value, as of writing this comment, is 'true', which means
// that first window_a takes focus, and then window_b takes focus, meaning
// that we can't actually test for the default value.
. focused = > continue ,
. iconified ,
. hovered ,
. context_revision ,
= > unreachable ,
}
}
// Future: we could consider hint values that can't be retrieved via attributes:
// center_cursor
// scale_to_monitor
// red_bits
// green_bits
// blue_bits
// alpha_bits
// depth_bits
// stencil_bits
// accum_red_bits
// accum_green_bits
// accum_blue_bits
// accum_alpha_bits
// aux_buffers
// samples
// refresh_rate
// stereo
// srgb_capable
// doublebuffer
// platform specific, and thus not considered:
// cocoa_retina_framebuffer
// cocoa_frame_name
// cocoa_graphics_switching
}
}