mirror of
				https://github.com/Dadido3/noita-mapcap.git
				synced 2025-10-31 03:09:35 +00:00 
			
		
		
		
	- Modernise UI, and simplify its logic - Add UI graphics - Add modification.lua which contains everything to modify Noita settings - Add message.lua which handles messages for users - Add check.lua which checks things, triggers messages and suggest user actions - Remove ACTIONS category from settings - Add more live capturing parameters to settings - Restrict vector input fields in settings - Rename pixel-size setting to pixel-scale - Let GetRect return two vectors instead of RECT object - Add VirtualOffsetPixelPerfect and FullscreenMode field to Coords - Fix captureScreenshot when the outputPixelScale is 0 - Show runtime errors in UI via message.lua - Other small fixes
		
			
				
	
	
		
			57 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			Lua
		
	
	
	
	
	
			
		
		
	
	
			57 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			Lua
		
	
	
	
	
	
-- Copyright (c) 2019-2022 David Vogel
 | 
						|
--
 | 
						|
-- This software is released under the MIT License.
 | 
						|
-- https://opensource.org/licenses/MIT
 | 
						|
 | 
						|
local Vec2 = require("noita-api.vec2")
 | 
						|
 | 
						|
local ffi = require("ffi")
 | 
						|
 | 
						|
local ScreenCap = {}
 | 
						|
 | 
						|
local status, res = pcall(ffi.load, "mods/noita-mapcap/bin/capture-b/capture")
 | 
						|
if not status then
 | 
						|
	print(string.format("Error loading capture lib: %s", res))
 | 
						|
	return
 | 
						|
end
 | 
						|
 | 
						|
ffi.cdef([[
 | 
						|
	typedef long LONG;
 | 
						|
	typedef struct {
 | 
						|
		LONG left;
 | 
						|
		LONG top;
 | 
						|
		LONG right;
 | 
						|
		LONG bottom;
 | 
						|
	} RECT;
 | 
						|
 | 
						|
	bool GetRect(RECT* rect);
 | 
						|
	bool Capture(RECT* rect, int x, int y, int sx, int sy);
 | 
						|
]])
 | 
						|
 | 
						|
---Takes a screenshot of the client area of this process' active window.
 | 
						|
---@param topLeft Vec2 -- Screenshot rectangle's top left coordinate relative to the window's client area in screen pixels.
 | 
						|
---@param bottomRight Vec2 -- Screenshot rectangle's bottom right coordinate relative to the window's client area in screen pixels. The pixel is not included in the screenshot area.
 | 
						|
---@param topLeftOutput Vec2 -- The corresponding scaled world coordinates of the screenshot rectangles' top left corner.
 | 
						|
---@param finalDimensions Vec2|nil -- The final dimensions that the screenshot will be resized to. If set to zero, no resize will happen.
 | 
						|
---@return boolean
 | 
						|
function ScreenCap.Capture(topLeft, bottomRight, topLeftOutput, finalDimensions)
 | 
						|
	finalDimensions = finalDimensions or Vec2(0, 0)
 | 
						|
 | 
						|
	local rect = ffi.new("RECT", { math.floor(topLeft.x + 0.5), math.floor(topLeft.y + 0.5), math.floor(bottomRight.x + 0.5), math.floor(bottomRight.y + 0.5) })
 | 
						|
	return res.Capture(rect, math.floor(topLeftOutput.x + 0.5), math.floor(topLeftOutput.y + 0.5), math.floor(finalDimensions.x + 0.5), math.floor(finalDimensions.y + 0.5))
 | 
						|
end
 | 
						|
 | 
						|
---Returns the client rectangle of the "Main" window of this process in screen coordinates.
 | 
						|
---@return Vec2|nil topLeft
 | 
						|
---@return Vec2|nil bottomRight
 | 
						|
function ScreenCap.GetRect()
 | 
						|
	local rect = ffi.new("RECT")
 | 
						|
	if not res.GetRect(rect) then
 | 
						|
		return nil, nil
 | 
						|
	end
 | 
						|
 | 
						|
	return Vec2(rect.left, rect.top), Vec2(rect.right, rect.bottom)
 | 
						|
end
 | 
						|
 | 
						|
return ScreenCap
 |