Skip to content

bjornbytes/lovr-window

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

48 Commits
 
 
 
 
 
 

Repository files navigation

lovr-window

A window module for LÖVR.

Usage

This library requires glfw3.dll 3.4+ version

First of all you need to add some new parameters in your lovr.conf()

Just append this parameters next to window related code:

-- additional window parameters
t.window.fullscreentype = "desktop"	-- Choose between "desktop" fullscreen or "exclusive" fullscreen mode (string)
t.window.x = nil			-- The x-coordinate of the window's position in the specified display (number)
t.window.y = nil			-- The y-coordinate of the window's position in the specified display (number)
t.window.minwidth = 1			-- Minimum window width if the window is resizable (number)
t.window.minheight = 1			-- Minimum window height if the window is resizable (number)
t.window.display = 1			-- Index of the monitor to show the window in (number)
t.window.centered = false		-- Align window on the center of the monitor (boolean)
t.window.topmost = false		-- Show window on top (boolean)
t.window.borderless = false		-- Remove all border visuals from the window (boolean)
t.window.resizable = false		-- Let the window be user-resizable (boolean)
t.window.opacity = 1			-- Window opacity value (number)

conf = t.window

After setting up your config function you can require window module and use it

lovr.window = require 'lovr-window'

function lovr.load()
	-- print all window parameters into console
	local width, height, mode = lovr.window.getMode()
	for k,v in pairs(mode) do
		print(k, v)
	end
	
	-- sets window opacity, resolution and title
	lovr.window.setMode(1280, 720, {title = "Hello, Window!", resizable = true, opacity = 0.5})
end

function lovr.maximized( v, w,h )
	print(v and "maximized" or "restored")
end

function lovr.dragdrop( paths )
	for i=1, #paths do
		--prints all file/directory paths dropped on the window
		print(paths[i])
	end
end

function lovr.windowmoved( x,y )
	print("Current window position:", x,y)
end

API

Functions
Function Description
window.getDisplayDimensions( index ) Gets the width and height of the desktop
window.getDisplayCount() Gets the number of connected monitors
window.getDisplayName( index ) Gets the name of a display
window.getFullscreen() Gets whether the window is fullscreen
window.getIcon() Gets the window icon
window.getMode() Gets the display mode and properties of the window
window.getOpacity() Returns opacity value of the Window
window.getPosition() Gets the position of the window on the screen
window.getTitle() Gets the window title
window.isVisible() Checks if the game window is visible
window.maximize() Makes the window as large as possible
window.minimize() Minimizes the window to the system's task bar / dock
window.requestAttention() Causes the window to request the attention of the user if it is not in the foreground
window.restore() Restores the size and position of the window if it was minimized or maximized
window.setFullscreen(fullscreen[, fstype]) Enters or exits fullscreen
window.setIcon( source ) Sets the window icon
window.setMode( width, height[, flags]) Sets the display mode and properties of the window
window.setOpacity( value ) Sets opacity value of the Window
window.setPosition( x,y ) Sets the position of the window on the screen
window.setTitle( title ) Sets the window title
window.focus() Sets focus on the window
window.visible( state ) Makes the window visible / invisible
Callbacks
Callback Description
lovr.maximized( state, w,h ) Called when the window is maximized/restored
lovr.windowmoved( x,y ) Callback function triggered when the window is moved
lovr.dragdrop( paths ) Callback function triggered when a file/directory is dragged and dropped onto the window

Documentation

getDisplayDimensions()

Function
width, height = window.getDisplayDimensions( index )
Arguments

number index

Returns

number width
number height

getDisplayCount()

Function
count = window.getDisplayCount()
Arguments

None.

Returns

number count

getDisplayName()

Function
name = window.getDisplayName( index )
Arguments

number index

Returns

string name

getFullscreen()

Function
fullscreen, fullscreentype = window.getFullscreen()
Arguments

None.

Returns

boolean fullscreen
string fullscreentype

getIcon()

Function
icon = window.getIcon()
Arguments

None.

Returns

Image icon

getMode()

Function
width, height, flags = window.getMode()
Arguments

None.

Returns

number width
number height
table flags

getOpacity()

Function
opacity = window.getOpacity()
Arguments

None.

Returns

number opacity

getPosition()

Function
x,y = window.getPosition()
Arguments

None.

Returns

number x
number y

getTitle()

Function
title = window.getTitle()
Arguments

None.

Returns

string title

isVisible()

Function
visible = window.isVisible()
Arguments

None.

Returns

boolean visible

maximize()

Function
window.maximize()
Arguments

None.

Returns

Nothing.

minimize()

Function
window.minimize()
Arguments

None.

Returns

Nothing.

requestAttention()

Function
window.requestAttention()
Arguments

None.

Returns

Nothing.

restore()

Function
window.restore()
Arguments

None.

Returns

Nothing.

setFullscreen()

Function
window.setFullscreen(fullscreen, fullscreentype)
Arguments

boolean fullscreen
string fullscreentype

Returns

Nothing.

setIcon()

Function
window.setIcon(source)
Arguments

Image source

Returns

Nothing.

Usage
local image_icon = lovr.data.newImage("/icon1.png", false)
window.setIcon(image_icon)

window.setIcon("/icon2.png") -- or you can set image from jpg/png file

setMode()

Function
window.setMode(width, height, flags)
Arguments

number width
number height
table flags

Returns

Nothing.

Usage
window.setMode(1600, 900) -- sets window size to 1600x900 pixels

flags = {
	fullscreen = true,
	fullscreentype = "exclusive",
	display = 2
}
lovr.window.setMode(1920, 1080, flags) -- sets window to fullscreen mode on display 2

setOpacity()

Function
window.setOpacity(value)
Arguments

number value

Returns

Nothing.

setPosition()

Function
window.setPosition(x,y)
Arguments

number x
number y

Returns

Nothing.

setTitle()

Function
window.setTitle(title)
Arguments

string title

Returns

Nothing.

focus()

Function
window.focus()
Arguments

None.

Returns

Nothing.

visible()

Function
window.visible(state)
Arguments

boolean state

Returns

Nothing.

maximized()

Function
lovr.maximized( state, width,height )
Arguments

boolean state
number width
number height

Returns

Nothing.

Usage
function lovr.maximized( v, w,h )
	print(v and "maximized" or "restored")
end

windowmoved()

Function
lovr.windowmoved( x,y )
Arguments

number x
number y

Returns

Nothing.

Usage
function lovr.windowmoved( x,y )
	print("Current window position:", x,y)
end

dragdrop()

Function
lovr.dragdrop( paths )
Arguments

table paths

Returns

Nothing.

Usage
function lovr.dragdrop( paths )
	for i=1, #paths do
		--print all file/directory paths dropped on the window
		print(paths[i])
	end
end

About

A window module for LÖVR

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Lua 100.0%