diff --git a/docs/API/GLFW/glfwSetWindowMonitor.md b/docs/API/GLFW/glfwSetWindowMonitor.md index ccd2cf4f..d8334dd4 100644 --- a/docs/API/GLFW/glfwSetWindowMonitor.md +++ b/docs/API/GLFW/glfwSetWindowMonitor.md @@ -2,7 +2,7 @@ Sets the mode, monitor, video mode and placement of a window. ```php -function glfwSetWindowMonitor(\GLFWwindow $window, \GLFWmonitor $monitor, int $xpos, int $ypos, int $width, int $height, int $refreshRate) : void +function glfwSetWindowMonitor(\GLFWwindow $window, ?\GLFWmonitor $monitor, int $xpos, int $ypos, int $width, int $height, int $refreshRate) : void ``` This function sets the monitor that the window uses for full screen mode or, @@ -28,7 +28,7 @@ arguments : 1. `\GLFWwindow` `$window` The window whose monitor, size or video mode to set. - 2. `\GLFWmonitor` `$monitor` The desired monitor, or `NULL` to set windowed + 2. `?\GLFWmonitor` `$monitor` The desired monitor, or `NULL` to set windowed mode. 3. `int` `$xpos` The desired x-coordinate of the upper-left corner of the content area. diff --git a/generator/build b/generator/build index d756449d..e1d7f70d 100755 --- a/generator/build +++ b/generator/build @@ -63,6 +63,7 @@ $gen->adjust(PHPGlfwAdjustments\GLFWSwapBuffersAdjustment::class); $gen->adjust(PHPGlfwAdjustments\GLFWCallbacksAdjustment::class); $gen->adjust(PHPGlfwAdjustments\GLFWCreateWindowAdjustment::class); $gen->adjust(PHPGlfwAdjustments\GLFWGetVideoModesAdjustment::class); +$gen->adjust(PHPGlfwAdjustments\GLFWSetWindowMonitorAdjustment::class); $gen->adjust(PHPGlfwAdjustments\GLShaderSourceAdjustment::class); $gen->adjust(PHPGlfwAdjustments\GLBufferDataAdjustment::class); $gen->adjust(PHPGlfwAdjustments\GLVertexAttribPointerAdjustment::class); diff --git a/generator/src/ExtArgument.php b/generator/src/ExtArgument.php index eff882f7..479bfe9f 100644 --- a/generator/src/ExtArgument.php +++ b/generator/src/ExtArgument.php @@ -121,6 +121,11 @@ public static function make(string $name, string $argumentType) : ExtArgument */ public bool $isParsed = true; + /** + * Is the argument nullable? can null be passed instead of the desired type? + */ + public bool $isNullable = false; + /** * Constrcutor * @param string $name The name of the argument diff --git a/generator/src/ExtArgument/InternalPtrObjectArgument.php b/generator/src/ExtArgument/InternalPtrObjectArgument.php index 6f7c349d..6b1ca55d 100644 --- a/generator/src/ExtArgument/InternalPtrObjectArgument.php +++ b/generator/src/ExtArgument/InternalPtrObjectArgument.php @@ -44,7 +44,7 @@ public function typeIsOfSameInternalSize() : bool public function getCharId() : string { $c = $this->charid; - if ($this->isOptional()) $c .= '!'; + if ($this->isOptional() || $this->isNullable) $c .= '!'; return $c; } @@ -78,7 +78,7 @@ public function getZendParameterParseArguments() : array */ public function getUsePrepCode() : string { - return $this->argInternalPtrObject->getInternalPtrFromZValDeclarationCode($this->name, $this->getZValName(), $this->defaultValue); + return $this->argInternalPtrObject->getInternalPtrFromZValDeclarationCode($this->name, $this->getZValName(), $this->defaultValue, $this->isNullable); } /** diff --git a/generator/src/ExtFunction.php b/generator/src/ExtFunction.php index 52791f04..3464e1a1 100644 --- a/generator/src/ExtFunction.php +++ b/generator/src/ExtFunction.php @@ -329,7 +329,7 @@ public function getPHPStubArgument(ExtArgument $arg, bool $allowDefaultValue = t { // IPO argument if ($arg->argumentType === ExtType::T_IPO) { - $buffer = ($arg->isOptional() ? '?' : '') . $arg->argInternalPtrObject->getPHPClassName() . ' ' . '$' . $arg->name; + $buffer = ($arg->isOptional() || $arg->isNullable ? '?' : '') . $arg->argInternalPtrObject->getPHPClassName() . ' ' . '$' . $arg->name; if ($arg->isOptional() && $allowDefaultValue) { $buffer .= ' = ' . $arg->defaultValue; @@ -339,7 +339,7 @@ public function getPHPStubArgument(ExtArgument $arg, bool $allowDefaultValue = t } // class entry argument elseif ($arg->argumentType === ExtType::T_CE && $arg instanceof CEObjectArgument) { - $buffer = ($arg->isOptional() ? '?' : '') . $arg->getPHPClassName() . ' ' . ($arg->explicitPassedByReference ? '&' : '') . '$' . $arg->name; + $buffer = ($arg->isOptional() || $arg->isNullable ? '?' : '') . $arg->getPHPClassName() . ' ' . ($arg->explicitPassedByReference ? '&' : '') . '$' . $arg->name; if ($arg->isOptional() && $allowDefaultValue) { $buffer .= ' = ' . $arg->defaultValue; diff --git a/generator/src/ExtInternalPtrObject.php b/generator/src/ExtInternalPtrObject.php index ac53f361..5162be5f 100644 --- a/generator/src/ExtInternalPtrObject.php +++ b/generator/src/ExtInternalPtrObject.php @@ -159,9 +159,9 @@ public function getObjectMinitHelperFunctionName() /** * Returns C code that declares the given varname of the internal type by resolving a zval potiner */ - public function getInternalPtrFromZValDeclarationCode(string $internalVarName, string $zvalVarName, ?string $defaultValue = null) : string + public function getInternalPtrFromZValDeclarationCode(string $internalVarName, string $zvalVarName, ?string $defaultValue = null, bool $isNullable = false) : string { - if ($defaultValue !== null) { + if ($defaultValue !== null || $isNullable) { $b = $this->type . ' ' . $internalVarName . ' = NULL;' . PHP_EOL; $b .= sprintf("if (%s != NULL && Z_TYPE_P(%s) == IS_OBJECT) {\n", $zvalVarName, $zvalVarName); $b .= sprintf(" %s = %s(%s);\n}", $internalVarName, $this->getInternalPtrFromZValPtrFunctionName(), $zvalVarName); diff --git a/generator/src/PHPGlfwAdjustments/GLFWSetWindowMonitorAdjustment.php b/generator/src/PHPGlfwAdjustments/GLFWSetWindowMonitorAdjustment.php new file mode 100644 index 00000000..561f6f82 --- /dev/null +++ b/generator/src/PHPGlfwAdjustments/GLFWSetWindowMonitorAdjustment.php @@ -0,0 +1,22 @@ +getFunctionByName('glfwSetWindowMonitor'); + + // monitor needs to be optional (nullable) if you want to force back + // windowed mode + $setMonitorFunc->arguments[1]->isNullable = true; + } +} \ No newline at end of file diff --git a/phpglfw.stub.php b/phpglfw.stub.php index e76c255a..af4e9095 100644 --- a/phpglfw.stub.php +++ b/phpglfw.stub.php @@ -2715,7 +2715,7 @@ function glfwHideWindow(GLFWwindow $window) : void {} function glfwFocusWindow(GLFWwindow $window) : void {} function glfwRequestWindowAttention(GLFWwindow $window) : void {} function glfwGetWindowMonitor(GLFWwindow $window) : GLFWmonitor {} - function glfwSetWindowMonitor(GLFWwindow $window, GLFWmonitor $monitor, int $xpos, int $ypos, int $width, int $height, int $refreshRate) : void {} + function glfwSetWindowMonitor(GLFWwindow $window, ?GLFWmonitor $monitor, int $xpos, int $ypos, int $width, int $height, int $refreshRate) : void {} function glfwGetWindowAttrib(GLFWwindow $window, int $attrib) : int {} function glfwSetWindowAttrib(GLFWwindow $window, int $attrib, int $value) : void {} function glfwSetWindowPosCallback(GLFWwindow $window, callable $callback) : void {} diff --git a/phpglfw_arginfo.h b/phpglfw_arginfo.h index e14780df..a4acea80 100644 --- a/phpglfw_arginfo.h +++ b/phpglfw_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: b0d79ff50f0ceba7e80a0de9e20cc3b5dfd7fa96 */ + * Stub hash: 5987166c03bdd5557449c93647771b2487551a2c */ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_glCullFace, 0, 1, IS_VOID, 0) ZEND_ARG_TYPE_INFO(0, mode, IS_LONG, 0) @@ -2051,7 +2051,7 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_glfwSetWindowMonitor, 0, 7, IS_VOID, 0) ZEND_ARG_OBJ_INFO(0, window, GLFWwindow, 0) - ZEND_ARG_OBJ_INFO(0, monitor, GLFWmonitor, 0) + ZEND_ARG_OBJ_INFO(0, monitor, GLFWmonitor, 1) ZEND_ARG_TYPE_INFO(0, xpos, IS_LONG, 0) ZEND_ARG_TYPE_INFO(0, ypos, IS_LONG, 0) ZEND_ARG_TYPE_INFO(0, width, IS_LONG, 0) diff --git a/phpglfw_functions.c b/phpglfw_functions.c index 4ad5e092..74c084d8 100644 --- a/phpglfw_functions.c +++ b/phpglfw_functions.c @@ -11337,11 +11337,14 @@ PHP_FUNCTION(glfwSetWindowMonitor) zend_long width; zend_long height; zend_long refreshRate; - if (zend_parse_parameters(ZEND_NUM_ARGS() , "OOlllll", &window_zval, phpglfw_glfwwindow_ce, &monitor_zval, phpglfw_glfwmonitor_ce, &xpos, &ypos, &width, &height, &refreshRate) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() , "OO!lllll", &window_zval, phpglfw_glfwwindow_ce, &monitor_zval, phpglfw_glfwmonitor_ce, &xpos, &ypos, &width, &height, &refreshRate) == FAILURE) { return; } GLFWwindow* window = phpglfw_glfwwindowptr_from_zval_ptr(window_zval); - GLFWmonitor* monitor = phpglfw_glfwmonitorptr_from_zval_ptr(monitor_zval); + GLFWmonitor* monitor = NULL; + if (monitor_zval != NULL && Z_TYPE_P(monitor_zval) == IS_OBJECT) { + monitor = phpglfw_glfwmonitorptr_from_zval_ptr(monitor_zval); + } glfwSetWindowMonitor(window, monitor, xpos, ypos, width, height, refreshRate); } diff --git a/stubs/phpglfw.php b/stubs/phpglfw.php index 784129ce..7b25745c 100644 --- a/stubs/phpglfw.php +++ b/stubs/phpglfw.php @@ -9495,7 +9495,7 @@ function glfwGetWindowMonitor(GLFWwindow $window) : GLFWmonitor {} * * @param GLFWwindow $window The window whose monitor, size or video mode to * set. - * @param GLFWmonitor $monitor The desired monitor, or `NULL` to set windowed + * @param ?GLFWmonitor $monitor The desired monitor, or `NULL` to set windowed * mode. * @param int $xpos The desired x-coordinate of the upper-left corner of the * content area. @@ -9510,7 +9510,7 @@ function glfwGetWindowMonitor(GLFWwindow $window) : GLFWmonitor {} * * @return void */ - function glfwSetWindowMonitor(GLFWwindow $window, GLFWmonitor $monitor, int $xpos, int $ypos, int $width, int $height, int $refreshRate) : void {} + function glfwSetWindowMonitor(GLFWwindow $window, ?GLFWmonitor $monitor, int $xpos, int $ypos, int $width, int $height, int $refreshRate) : void {} /** * Returns an attribute of the specified window.