mirror of
				https://github.com/LDDestroier/CC/
				synced 2025-10-30 23:12:59 +00:00 
			
		
		
		
	Set line as SHIFT+Click of pencil tool
You can now also use '[' and ']' to change the color.
This commit is contained in:
		
							
								
								
									
										95
									
								
								pain2.lua
									
									
									
									
									
								
							
							
						
						
									
										95
									
								
								pain2.lua
									
									
									
									
									
								
							| @@ -1,3 +1,26 @@ | |||||||
|  | --[[ | ||||||
|  |  | ||||||
|  |  8888888b.     d8888 8888888 888b    888  .d8888b. | ||||||
|  |  888   Y88b   d88888   888   8888b   888 d88P  Y88b | ||||||
|  |  888    888  d88P888   888   88888b  888        888 | ||||||
|  |  888   d88P d88P 888   888   888Y88b 888      .d88P | ||||||
|  |  8888888P' d88P  888   888   888 Y88b888  .od888P" | ||||||
|  |  888      d88P   888   888   888  Y88888 d88P" | ||||||
|  |  888     d8888888888   888   888   Y8888 888" | ||||||
|  |  888    d88P     888 8888888 888    Y888 888888888 | ||||||
|  |  | ||||||
|  | Download with: | ||||||
|  | 	wget https://github.com/LDDestroier/CC/raw/master/pain2.lua | ||||||
|  |  | ||||||
|  | To-do: | ||||||
|  | 	* Add more tools, such as Fill or Color Picker. | ||||||
|  | 	* Add an actual menu. | ||||||
|  | 	* Add a help screen, and don't make it as bland-looking as PAIN 1's. | ||||||
|  | 	* Add support for every possible image format under the sun. | ||||||
|  | 	* Add the ability to add/remove layers. | ||||||
|  |  | ||||||
|  | --]] | ||||||
|  |  | ||||||
| local pain = { | local pain = { | ||||||
| 	running = true,	-- if true, will run. otherwise, quit | 	running = true,	-- if true, will run. otherwise, quit | ||||||
| 	layer = 1,		-- current layer selected | 	layer = 1,		-- current layer selected | ||||||
| @@ -58,7 +81,31 @@ pain.control = { | |||||||
| 		key = keys.space, | 		key = keys.space, | ||||||
| 		holdDown = false, | 		holdDown = false, | ||||||
| 		modifiers = {}, | 		modifiers = {}, | ||||||
| 	} | 	}, | ||||||
|  | 	nextTextColor = { | ||||||
|  | 		key = keys.rightBracket, | ||||||
|  | 		holdDown = false, | ||||||
|  | 		modifiers = { | ||||||
|  | 			[keys.shift] = true | ||||||
|  | 		}, | ||||||
|  | 	}, | ||||||
|  | 	prevTextColor = { | ||||||
|  | 		key = keys.leftBracket, | ||||||
|  | 		holdDown = false, | ||||||
|  | 		modifiers = { | ||||||
|  | 			[keys.shift] = true | ||||||
|  | 		}, | ||||||
|  | 	}, | ||||||
|  | 	nextBackColor = { | ||||||
|  | 		key = keys.rightBracket, | ||||||
|  | 		holdDown = false, | ||||||
|  | 		modifiers = {}, | ||||||
|  | 	}, | ||||||
|  | 	prevBackColor = { | ||||||
|  | 		key = keys.leftBracket, | ||||||
|  | 		holdDown = false, | ||||||
|  | 		modifiers = {}, | ||||||
|  | 	}, | ||||||
| } | } | ||||||
|  |  | ||||||
| local checkControl = function(name) | local checkControl = function(name) | ||||||
| @@ -180,6 +227,8 @@ pain.nativePalette = { | |||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
|  | local hexColors = "0123456789abcdef" | ||||||
|  |  | ||||||
| -- load Windon't API | -- load Windon't API | ||||||
| -- if you're using ATOM, feel free to minimize this whole function | -- if you're using ATOM, feel free to minimize this whole function | ||||||
| local windont = require "windont" | local windont = require "windont" | ||||||
| @@ -326,6 +375,17 @@ pain.manip.setDotLine = function(canvas, x1, y1, x2, y2, char, text, back) | |||||||
| 	end | 	end | ||||||
| end | end | ||||||
|  |  | ||||||
|  | pain.manip.changePainColor = function(mode, amount, doLoop) | ||||||
|  | 	local cNum = hexColors:find(pain.color[mode]) | ||||||
|  | 	local sNum | ||||||
|  | 	if doLoop then | ||||||
|  | 		sNum = ((cNum + amount - 1) % 16) + 1 | ||||||
|  | 	else | ||||||
|  | 		sNum = math.min(math.max(cNum + amount, 1), 16) | ||||||
|  | 	end | ||||||
|  | 	pain.color[mode] = hexColors:sub(sNum, sNum) | ||||||
|  | end | ||||||
|  |  | ||||||
| local whitespace = { | local whitespace = { | ||||||
| 	["\009"] = true, | 	["\009"] = true, | ||||||
| 	["\010"] = true, | 	["\010"] = true, | ||||||
| @@ -358,6 +418,9 @@ tools.pencil = { | |||||||
| 		local mx, my, evt = initEvent[3], initEvent[4] | 		local mx, my, evt = initEvent[3], initEvent[4] | ||||||
| 		local oldX, oldY | 		local oldX, oldY | ||||||
| 		local mode = initEvent[2]	-- 1 = draw, 2 = erase | 		local mode = initEvent[2]	-- 1 = draw, 2 = erase | ||||||
|  | 		if keysDown[keys.shift] then | ||||||
|  | 			return tools.line.run(canvas, initEvent, toolInfo) | ||||||
|  | 		else | ||||||
| 			local setDot = function() | 			local setDot = function() | ||||||
| 				pain.manip.setDotLine( | 				pain.manip.setDotLine( | ||||||
| 					canvas, | 					canvas, | ||||||
| @@ -381,6 +444,7 @@ tools.pencil = { | |||||||
| 					setDot() | 					setDot() | ||||||
| 				end | 				end | ||||||
| 			end | 			end | ||||||
|  | 		end | ||||||
| 	end, | 	end, | ||||||
| 	options = {} | 	options = {} | ||||||
| } | } | ||||||
| @@ -551,7 +615,7 @@ local main = function() | |||||||
| 	pain.image[1] = newCanvas() | 	pain.image[1] = newCanvas() | ||||||
|  |  | ||||||
| 	local cTool = { | 	local cTool = { | ||||||
| 		name = "line", | 		name = "pencil", | ||||||
| 		lastEvent = nil, | 		lastEvent = nil, | ||||||
| 		active = false, | 		active = false, | ||||||
| 		coroutine = nil, | 		coroutine = nil, | ||||||
| @@ -634,6 +698,22 @@ local main = function() | |||||||
| 				canvas.meta.y = 1 | 				canvas.meta.y = 1 | ||||||
| 			end | 			end | ||||||
|  |  | ||||||
|  | 			if checkControl("nextTextColor") then | ||||||
|  | 				pain.manip.changePainColor("text", 1, false) | ||||||
|  | 			end | ||||||
|  |  | ||||||
|  | 			if checkControl("nextBackColor") then | ||||||
|  | 				pain.manip.changePainColor("back", 1, false) | ||||||
|  | 			end | ||||||
|  |  | ||||||
|  | 			if checkControl("prevTextColor") then | ||||||
|  | 				pain.manip.changePainColor("text", -1, false) | ||||||
|  | 			end | ||||||
|  |  | ||||||
|  | 			if checkControl("prevBackColor") then | ||||||
|  | 				pain.manip.changePainColor("back", -1, false) | ||||||
|  | 			end | ||||||
|  |  | ||||||
| 			resume({"refresh"}) | 			resume({"refresh"}) | ||||||
|  |  | ||||||
| 			if tCompleted.render then | 			if tCompleted.render then | ||||||
| @@ -645,17 +725,19 @@ local main = function() | |||||||
|  |  | ||||||
| 			if evt[1] == "term_resize" then | 			if evt[1] == "term_resize" then | ||||||
| 				scr_x, scr_y = term.getSize() | 				scr_x, scr_y = term.getSize() | ||||||
| 			elseif evt[1] == "key" then | 			elseif evt[1] == "key" or evt[1] == "key_up" then | ||||||
|  | 				if evt[1] == "key" then | ||||||
| 					if not evt[3] then | 					if not evt[3] then | ||||||
| 						keysDown[evt[2]] = 0 | 						keysDown[evt[2]] = 0 | ||||||
|  | 					end | ||||||
|  | 				elseif evt[1] == "key_up" then | ||||||
|  | 					keysDown[evt[2]] = nil | ||||||
|  | 				end | ||||||
| 				keysDown[keys.ctrl] = keysDown[keys.leftCtrl] or keysDown[keys.rightCtrl] | 				keysDown[keys.ctrl] = keysDown[keys.leftCtrl] or keysDown[keys.rightCtrl] | ||||||
| 				keysDown[keys.shift] = keysDown[keys.leftShift] or keysDown[keys.rightShift] | 				keysDown[keys.shift] = keysDown[keys.leftShift] or keysDown[keys.rightShift] | ||||||
| 				keysDown[keys.alt] = keysDown[keys.leftAlt] or keysDown[keys.rightAlt] | 				keysDown[keys.alt] = keysDown[keys.leftAlt] or keysDown[keys.rightAlt] | ||||||
| 				end |  | ||||||
| 			elseif evt[1] == "mouse_up" then | 			elseif evt[1] == "mouse_up" then | ||||||
| 				miceDown[evt[2]] = nil | 				miceDown[evt[2]] = nil | ||||||
| 			elseif evt[1] == "key_up" then |  | ||||||
| 				keysDown[evt[2]] = nil |  | ||||||
| 			elseif (evt[1] == "mouse_click" or evt[1] == "mouse_drag") then | 			elseif (evt[1] == "mouse_click" or evt[1] == "mouse_drag") then | ||||||
| 				miceDown[evt[2]] = {evt[3], evt[4]} | 				miceDown[evt[2]] = {evt[3], evt[4]} | ||||||
| 				if evt[1] == "mouse_click" then | 				if evt[1] == "mouse_click" then | ||||||
| @@ -682,5 +764,4 @@ local main = function() | |||||||
|  |  | ||||||
| end | end | ||||||
|  |  | ||||||
|  |  | ||||||
| main() | main() | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 LDDestroier
					LDDestroier