Software experiment course of Shandong University - Ebiten - source code analysis of 2D game library based on go language - learn the window drawing file window in Ebiten go 2021SC@SDUSC

Posted by reeferd on Tue, 04 Jan 2022 13:38:47 +0100

2021SC@SDUSC

catalogue

1, WindowSize() function

2, SetWindowSize() function

3, WindowSizeLimits() function

4, IsWindowFloating() function

5, SetWindowFloating() function

6, Maximize window() function

7, SetWindowClosingHandled() function

1, WindowSize() function

The code is as follows:

func WindowSize() (int, int) {
	if w := uiDriver().Window(); w != nil {
		return w.Size()
	}
	return 0, 0
}

WindowSize() returns the size of the window on the desktop.
WindowSize() returns (0,0) on other environments.
In full screen mode, WindowSize() returns the original window size.

2, SetWindowSize() function

The code is as follows:

func SetWindowSize(width, height int) {
	if width <= 0 || height <= 0 {
		panic("ebiten: width and height must be positive")
	}
	if w := uiDriver().Window(); w != nil {
		w.SetSize(width, height)
	}
}

SetWindowSize() sets the window size on the desktop.
SetWindowSize() has no effect on other environments.
In full screen mode, SetWindowSize() sets the original window size.
SetWindowSize() panics if the width or height is not a positive number.
The SetWindowSize() function is concurrent and secure.

3, WindowSizeLimits() function

The code is as follows:

func WindowSizeLimits() (minw, minh, maxw, maxh int) {
	if w := uiDriver().Window(); w != nil {
		return w.SizeLimits()
	}
	return -1, -1, -1, -1
}

WindowSizeLimits() returns the window size limit on the desktop.
If a negative value is returned, the size is unlimited.

4, IsWindowFloating() function

The code is as follows:

func IsWindowFloating() bool {
	if w := uiDriver().Window(); w != nil {
		return w.IsFloating()
	}
	return false
}



5, SetWindowFloating() function

The code is as follows:

func SetWindowFloating(float bool) {
	if w := uiDriver().Window(); w != nil {
		w.SetFloating(float)
	}
}

SetWindowFloating() sets whether the window is always displayed above all other windows.
SetWindowFloating() has no effect on browsers or mobile phones.
When the window is completely shielded by the macOS desktop, SetWindowFloating() has no effect on the macOS instead of setting the full screen
The SetWindowFloating() function is concurrent and secure.

6, Maximize window() function

The code is as follows:

func MaximizeWindow() {
	if !IsWindowResizable() {
		panic("ebiten: a window to maximize must be resizable")
	}
	if w := uiDriver().Window(); w != nil {
		w.Maximize()
	}
}

Maximize window() maximizes the window.
Maximize window() panics when the window is not resizable.
MaximizeWindow() has no effect on browsers or mobile phones.
The MaximizeWindow() function is concurrent and secure.

7, SetWindowClosingHandled() function

The code is as follows:

func SetWindowClosingHandled(handled bool) {
	if w := uiDriver().Window(); w != nil {
		w.SetClosingHandled(handled)
	}
}

SetWindowClosingHandled() sets whether to process window closing on the desktop. The default state is false.
If the processing window is closed, the window will not be closed immediately. At this time, the game can know whether the window needs to be closed. When it is determined that it needs to be closed, the window starts to close.
In this case, the window does not close automatically.
To end the game, you must return a fault in the closing interface of the game.
SetWindowClosingHandled() can only work on the desktop and does nothing on other platforms.
The SetWindowClosingHandled() function is concurrent and secure.

Topics: Go Back-end