mirror of
				https://github.com/LDDestroier/CC/
				synced 2025-10-31 07:22:59 +00:00 
			
		
		
		
	Update windont.lua
This commit is contained in:
		
							
								
								
									
										162
									
								
								windont.lua
									
									
									
									
									
								
							
							
						
						
									
										162
									
								
								windont.lua
									
									
									
									
									
								
							| @@ -18,7 +18,7 @@ local getTime = function() | |||||||
| end | end | ||||||
|  |  | ||||||
| local windont = { | local windont = { | ||||||
| 	baseTerm = term.current(), | 	baseTerm = term.current(),				-- default base terminal for all windows | ||||||
| 	config = { | 	config = { | ||||||
| 		defaultTextColor = "0",				-- default text color (what " " corresponds to in term.blit's second argument) | 		defaultTextColor = "0",				-- default text color (what " " corresponds to in term.blit's second argument) | ||||||
| 		defaultBackColor = "f",				-- default background color (what " " corresponds to in term.blit's third argument) | 		defaultBackColor = "f",				-- default background color (what " " corresponds to in term.blit's third argument) | ||||||
| @@ -49,9 +49,9 @@ end | |||||||
|  |  | ||||||
| windont.render = function(...) | windont.render = function(...) | ||||||
| 	local windows = {...} | 	local windows = {...} | ||||||
| 	local bT = windont.baseTerm | 	local bT | ||||||
| 	local scr_x, scr_y = bT.getSize() |  | ||||||
| 	local screenBuffer = {{}, {}, {}} | 	local screenBuffer = {{}, {}, {}} | ||||||
|  | 	local scr_x, scr_y | ||||||
| 	local blitList = {}	-- list of blit commands per line | 	local blitList = {}	-- list of blit commands per line | ||||||
| 	local c	= 1 		-- current blitList entry | 	local c	= 1 		-- current blitList entry | ||||||
|  |  | ||||||
| @@ -65,79 +65,90 @@ windont.render = function(...) | |||||||
| 	local buffer					-- each window's buffer | 	local buffer					-- each window's buffer | ||||||
| 	local newChar, newText, newBack	-- if the transformation function declares a new dot, this is it | 	local newChar, newText, newBack	-- if the transformation function declares a new dot, this is it | ||||||
|  |  | ||||||
| 	for y = 1, scr_y do | 	local baseTerms = {} | ||||||
| 		screenBuffer[1][y] = {} | 	for i = 1, #windows do | ||||||
| 		screenBuffer[2][y] = {} | 		baseTerms[windows[i].meta.baseTerm] = baseTerms[windows[i].meta.baseTerm] or {} | ||||||
| 		screenBuffer[3][y] = {} | 		baseTerms[windows[i].meta.baseTerm][i] = true | ||||||
| 		blitList = {} | 	end | ||||||
| 		c = 1 |  | ||||||
| 		for x = 1, scr_x do |  | ||||||
| 			for i = #windows, 1, -1 do |  | ||||||
| 				newChar, newText, newBack = nil |  | ||||||
| 				if windows[i].meta.visible then |  | ||||||
| 					buffer = windows[i].meta.buffer |  | ||||||
| 					cx = x - windows[i].meta.x + 1 |  | ||||||
| 					cy = y - windows[i].meta.y + 1 |  | ||||||
| 					char_cx, text_cx, back_cx = cx, cx, cx |  | ||||||
| 					char_cy, text_cy, back_cy = cy, cy, cy |  | ||||||
|  |  | ||||||
| 					-- try char transformation | 	for bT, bT_list in pairs(baseTerms) do | ||||||
| 					if windows[i].meta.charTransformation then | 		scr_x, scr_y = bT.getSize() | ||||||
| 						char_cx, char_cy, newChar = windows[i].meta.charTransformation(cx, cy, windows[i].meta) | 		for y = 1, scr_y do | ||||||
| 						if char_cx ~= math.floor(char_cx) or char_cy ~= math.floor(char_cy) then | 			screenBuffer[1][y] = {} | ||||||
| 							newChar = " " | 			screenBuffer[2][y] = {} | ||||||
|  | 			screenBuffer[3][y] = {} | ||||||
|  | 			blitList = {} | ||||||
|  | 			c = 1 | ||||||
|  | 			for x = 1, scr_x do | ||||||
|  | 				for i = #windows, 1, -1 do | ||||||
|  | 					if bT_list[i] then | ||||||
|  | 						newChar, newText, newBack = nil | ||||||
|  | 						if windows[i].meta.visible then | ||||||
|  | 							buffer = windows[i].meta.buffer | ||||||
|  | 							cx = x - windows[i].meta.x + 1 | ||||||
|  | 							cy = y - windows[i].meta.y + 1 | ||||||
|  | 							char_cx, text_cx, back_cx = cx, cx, cx | ||||||
|  | 							char_cy, text_cy, back_cy = cy, cy, cy | ||||||
|  |  | ||||||
|  | 							-- try char transformation | ||||||
|  | 							if windows[i].meta.charTransformation then | ||||||
|  | 								char_cx, char_cy, newChar = windows[i].meta.charTransformation(cx, cy, windows[i].meta) | ||||||
|  | 								if char_cx ~= math.floor(char_cx) or char_cy ~= math.floor(char_cy) then | ||||||
|  | 									newChar = " " | ||||||
|  | 								end | ||||||
|  | 								char_cx = math.floor(char_cx) | ||||||
|  | 								char_cy = math.floor(char_cy) | ||||||
|  | 							end | ||||||
|  |  | ||||||
|  | 							-- try text transformation | ||||||
|  | 							if windows[i].meta.textTransformation then | ||||||
|  | 								text_cx, text_cy, newText = windows[i].meta.textTransformation(cx, cy, windows[i].meta) | ||||||
|  | 								text_cx = math.floor(text_cx) | ||||||
|  | 								text_cy = math.floor(text_cy) | ||||||
|  | 							end | ||||||
|  |  | ||||||
|  | 							-- try back transformation | ||||||
|  | 							if windows[i].meta.backTransformation then | ||||||
|  | 								back_cx, back_cy, newBack = windows[i].meta.backTransformation(cx, cy, windows[i].meta) | ||||||
|  | 								back_cx = math.floor(back_cx) | ||||||
|  | 								back_cy = math.floor(back_cy) | ||||||
|  | 							end | ||||||
|  |  | ||||||
|  | 							if check(buffer, char_cx, char_cy) or check(buffer, text_cx, text_cy) or check(buffer, back_cx, back_cy) then | ||||||
|  | 								screenBuffer[1][y][x] = newChar or check(buffer, char_cx, char_cy   ) and (buffer[1][char_cy][char_cx]) or screenBuffer[1][y][x] | ||||||
|  | 								screenBuffer[2][y][x] = newText or check(buffer, text_cx, text_cy, 2) and (buffer[2][text_cy][text_cx]) or screenBuffer[3][y][x] | ||||||
|  | 								screenBuffer[3][y][x] = newBack or check(buffer, back_cx, back_cy, 3) and (buffer[3][back_cy][back_cx]) or screenBuffer[3][y][x] | ||||||
|  | 							end | ||||||
| 						end | 						end | ||||||
| 						char_cx = math.floor(char_cx) |  | ||||||
| 						char_cy = math.floor(char_cy) |  | ||||||
| 					end | 					end | ||||||
|  | 				end | ||||||
|  |  | ||||||
| 					-- try text transformation | 				if windont.config.clearScreen then | ||||||
| 					if windows[i].meta.textTransformation then | 					screenBuffer[1][y][x] = screenBuffer[1][y][x] or " " | ||||||
| 						text_cx, text_cy, newText = windows[i].meta.textTransformation(cx, cy, windows[i].meta) | 				end | ||||||
| 						text_cx = math.floor(text_cx) | 				screenBuffer[2][y][x] = screenBuffer[2][y][x] or windont.config.defaultBackColor	-- intentionally not the default text color | ||||||
| 						text_cy = math.floor(text_cy) | 				screenBuffer[3][y][x] = screenBuffer[3][y][x] or windont.config.defaultBackColor | ||||||
| 					end |  | ||||||
|  |  | ||||||
| 					-- try back transformation | 				if check(screenBuffer, x, y) then | ||||||
| 					if windows[i].meta.backTransformation then | 					if check(screenBuffer, x - 1, y) then | ||||||
| 						back_cx, back_cy, newBack = windows[i].meta.backTransformation(cx, cy, windows[i].meta) | 						blitList[c][1] = blitList[c][1] .. screenBuffer[1][y][x] | ||||||
| 						back_cx = math.floor(back_cx) | 						blitList[c][2] = blitList[c][2] .. screenBuffer[2][y][x] | ||||||
| 						back_cy = math.floor(back_cy) | 						blitList[c][3] = blitList[c][3] .. screenBuffer[3][y][x] | ||||||
| 					end | 					else | ||||||
|  | 						c = x | ||||||
| 					if check(buffer, char_cx, char_cy) or check(buffer, text_cx, text_cy) or check(buffer, back_cx, back_cy) then | 						blitList[c] = { | ||||||
| 						screenBuffer[1][y][x] = newChar or check(buffer, char_cx, char_cy   ) and (buffer[1][char_cy][char_cx]) or screenBuffer[1][y][x] | 							screenBuffer[1][y][x], | ||||||
| 						screenBuffer[2][y][x] = newText or check(buffer, text_cx, text_cy, 2) and (buffer[2][text_cy][text_cx]) or screenBuffer[3][y][x] | 							screenBuffer[2][y][x], | ||||||
| 						screenBuffer[3][y][x] = newBack or check(buffer, back_cx, back_cy, 3) and (buffer[3][back_cy][back_cx]) or screenBuffer[3][y][x] | 							screenBuffer[3][y][x] | ||||||
|  | 						} | ||||||
| 					end | 					end | ||||||
| 				end | 				end | ||||||
| 			end | 			end | ||||||
|  | 			for k,v in pairs(blitList) do | ||||||
| 			if windont.config.clearScreen then | 				bT.setCursorPos(k, y) | ||||||
| 				screenBuffer[1][y][x] = screenBuffer[1][y][x] or " " | 				bT.blit(v[1], v[2], v[3]) | ||||||
|  | 				AMNT_OF_BLITS = AMNT_OF_BLITS + 1 | ||||||
| 			end | 			end | ||||||
| 			screenBuffer[2][y][x] = screenBuffer[2][y][x] or windont.config.defaultBackColor	-- intentionally not the default text color |  | ||||||
| 			screenBuffer[3][y][x] = screenBuffer[3][y][x] or windont.config.defaultBackColor |  | ||||||
|  |  | ||||||
| 			if check(screenBuffer, x, y) then |  | ||||||
| 				if check(screenBuffer, x - 1, y) then |  | ||||||
| 					blitList[c][1] = blitList[c][1] .. screenBuffer[1][y][x] |  | ||||||
| 					blitList[c][2] = blitList[c][2] .. screenBuffer[2][y][x] |  | ||||||
| 					blitList[c][3] = blitList[c][3] .. screenBuffer[3][y][x] |  | ||||||
| 				else |  | ||||||
| 					c = x |  | ||||||
| 					blitList[c] = { |  | ||||||
| 						screenBuffer[1][y][x], |  | ||||||
| 						screenBuffer[2][y][x], |  | ||||||
| 						screenBuffer[3][y][x] |  | ||||||
| 					} |  | ||||||
| 				end |  | ||||||
| 			end |  | ||||||
| 		end |  | ||||||
| 		for k,v in pairs(blitList) do |  | ||||||
| 			bT.setCursorPos(k, y) |  | ||||||
| 			bT.blit(v[1], v[2], v[3]) |  | ||||||
| 			AMNT_OF_BLITS = AMNT_OF_BLITS + 1 |  | ||||||
| 		end | 		end | ||||||
| 	end | 	end | ||||||
|  |  | ||||||
| @@ -165,17 +176,16 @@ windont.newWindow = function( x, y, width, height, misc ) | |||||||
| 	assert(width > 0, "width must be above zero") | 	assert(width > 0, "width must be above zero") | ||||||
| 	assert(height > 0, "height must be above zero") | 	assert(height > 0, "height must be above zero") | ||||||
|  |  | ||||||
| 	local bT = windont.baseTerm |  | ||||||
|  |  | ||||||
| 	local output = {} | 	local output = {} | ||||||
| 	misc = misc or {} | 	misc = misc or {} | ||||||
| 	local meta = { | 	local meta = { | ||||||
| 		x = x or 1,							-- x position of the window | 		x = x or 1,						-- x position of the window | ||||||
| 		y = y or 1,							-- y position of the window | 		y = y or 1,						-- y position of the window | ||||||
| 		width = width,						-- width of the buffer | 		width = width,						-- width of the buffer | ||||||
| 		height = height,					-- height of the buffer | 		height = height,					-- height of the buffer | ||||||
| 		buffer = {},						-- stores contents of terminal in buffer[1][y][x] format | 		buffer = {},						-- stores contents of terminal in buffer[1][y][x] format | ||||||
| 		renderBuddies = {},					-- renders any other window objects stored here after rendering here | 		renderBuddies = {},					-- renders any other window objects stored here after rendering here | ||||||
|  | 		baseTerm = misc.baseTerm or windont.baseTerm,		-- base terminal for which this window draws on | ||||||
|  |  | ||||||
| 		charTransformation = nil,			-- function that transforms the characters of the window | 		charTransformation = nil,			-- function that transforms the characters of the window | ||||||
| 		textTransformation = nil,			-- function that transforms the text colors of the window | 		textTransformation = nil,			-- function that transforms the text colors of the window | ||||||
| @@ -187,10 +197,10 @@ windont.newWindow = function( x, y, width, height, misc ) | |||||||
| 		textColor = misc.textColor or windont.config.defaultTextColor,	-- current text color | 		textColor = misc.textColor or windont.config.defaultTextColor,	-- current text color | ||||||
| 		backColor = misc.backColor or windont.config.defaultBackColor,	-- current background color | 		backColor = misc.backColor or windont.config.defaultBackColor,	-- current background color | ||||||
|  |  | ||||||
| 		blink = true,					-- cursor blink | 		blink = true,				-- cursor blink | ||||||
| 		isColor = bT.isColor(),			-- if true, then it's an advanced computer | 		isColor = term.isColor(),		-- if true, then it's an advanced computer | ||||||
| 		alwaysRender = false,			-- render after every terminal operation | 		alwaysRender = false,			-- render after every terminal operation | ||||||
| 		visible = true,					-- if false, don't render ever | 		visible = true,				-- if false, don't render ever | ||||||
|  |  | ||||||
| 		-- make a new buffer (optionally uses an existing buffer as a reference) | 		-- make a new buffer (optionally uses an existing buffer as a reference) | ||||||
| 		newBuffer = function(width, height, char, text, back, drawAtop) | 		newBuffer = function(width, height, char, text, back, drawAtop) | ||||||
| @@ -209,6 +219,8 @@ windont.newWindow = function( x, y, width, height, misc ) | |||||||
| 		end | 		end | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | 	bT = meta.baseTerm | ||||||
|  |  | ||||||
| 	-- initialize the buffer | 	-- initialize the buffer | ||||||
| 	meta.buffer = meta.newBuffer(meta.width, meta.height, " ", meta.textColor, meta.backColor) | 	meta.buffer = meta.newBuffer(meta.width, meta.height, " ", meta.textColor, meta.backColor) | ||||||
|  |  | ||||||
| @@ -347,7 +359,7 @@ windont.newWindow = function( x, y, width, height, misc ) | |||||||
| 	end | 	end | ||||||
|  |  | ||||||
| 	output.getSize = function() | 	output.getSize = function() | ||||||
| 		return height, width | 		return width, height | ||||||
| 	end | 	end | ||||||
|  |  | ||||||
| 	output.isColor = function() | 	output.isColor = function() | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 LDDestroier
					LDDestroier