-- primitives for editing drawings Drawing = {} geom = require 'geom' require 'drawing_tests' -- All drawings span 100% of some conceptual 'page width' and divide it up -- into 256 parts. function Drawing.draw(line) local pmx,pmy = App.mouse_x(), App.mouse_y() if pmx < Margin_left+Line_width and pmy > line.y and pmy < line.y+Drawing.pixels(line.h) then love.graphics.setColor(0.75,0.75,0.75) love.graphics.rectangle('line', Margin_left,line.y, Line_width,Drawing.pixels(line.h)) if icon[Current_drawing_mode] then icon[Current_drawing_mode](Margin_left+Line_width-20, line.y+4) else icon[Previous_drawing_mode](Margin_left+Line_width-20, line.y+4) end if App.mouse_down(1) and love.keyboard.isDown('h') then draw_help_with_mouse_pressed(line) return end end if line.show_help then draw_help_without_mouse_pressed(line) return end local mx,my = Drawing.coord(pmx-Margin_left), Drawing.coord(pmy-line.y) for _,shape in ipairs(line.shapes) do assert(shape) if geom.on_shape(mx,my, line, shape) then love.graphics.setColor(1,0,0) else love.graphics.setColor(0,0,0) end Drawing.draw_shape(Margin_left,line.y, line, shape) end for i,p in ipairs(line.points) do if p.deleted == nil then if Drawing.near(p, mx,my) then love.graphics.setColor(1,0,0) love.graphics.circle('line', Drawing.pixels(p.x)+Margin_left,Drawing.pixels(p.y)+line.y, 4) else love.graphics.setColor(0,0,0) love.graphics.circle('fill', Drawing.pixels(p.x)+Margin_left,Drawing.pixels(p.y)+line.y, 2) end if p.name then -- TODO: clip local x,y = Drawing.pixels(p.x)+Margin_left+5, Drawing.pixels(p.y)+line.y+5 love.graphics.print(p.name, x,y) if Current_drawing_mode == 'name' and i == line.pending.target_point then -- create a faint red box for the name love.graphics.setColor(1,0,0,0.1) local name_text -- TODO: avoid computing name width on every repaint if p.name == '' then name_text = Em else name_text = App.newText(love.graphics.getFont(), p.name) end love.graphics.rectangle('fill', x,y, App.width(name_text), Line_height) end end end end love.graphics.setColor(0.75,0.75,0.75) Drawing.draw_pending_shape(Margin_left,line.y, line) end function Drawing.draw_shape(left,top, drawing, shape) if shape.mode == 'freehand' then local prev = nil for _,point in ipairs(shape.points) do if prev then love.graphics.line(Drawing.pixels(prev.x)+left,Drawing.pixels(prev.y)+top, Drawing.pixels(point.x)+left,Drawing.pixels(point.y)+top) end prev = point end elseif shape.mode == 'line' or shape.mode == 'manhattan' then local p1 = drawing.points[shape.p1] local p2 = drawing.points[shape.p2] love.graphics.line(Drawing.pixels(p1.x)+left,Drawing.pixels(p1.y)+top, Drawing.pixels(p2.x)+left,Drawing.pixels(p2.y)+top) elseif shape.mode == 'polygon' or shape.mode == 'rectangle' or shape.mode == 'square' then local prev = nil for _,point in ipairs(shape.vertices) do local curr = drawing.points[point] if prev then love.graphics.line(Drawing.pixels(prev.x)+left,Drawing.pixels(prev.y)+top, Drawing.pixels(curr.x)+left,Drawing.pixels(curr.y)+top) end prev = curr end -- close the loop local curr = drawing.points[shape.vertices[1]] love.graphics.line(Drawing.pixels(prev.x)+left,Drawing.pixels(prev.y)+top, Drawing.pixels(curr.x)+left,Drawing.pixels(curr.y)+top) elseif shape.mode == 'circle' then -- TODO: clip local center = drawing.points[shape.center] love.graphics.circle('line', Drawing.pixels(center.x)+left,Drawing.pixels(center.y)+top, Drawing.pixels(shape.radius)) elseif shape.mode == 'arc' then local center = drawing.points[shape.center] love.graphics.arc('line', 'open', Drawing.pixels(center.x)+left,Drawing.pixels(center.y)+top, Drawing.pixels(shape.radius), shape.start_angle, shape.end_angle, 360) elseif shape.mode == 'deleted' then -- ignore else print(shape.mode) assert(false) end end function Drawing.draw_pending_shape(left,top, drawing) local shape = drawing.pending if shape.mode == nil then -- nothing pending elseif shape.mode == 'freehand' then Drawing.draw_shape(left,top, drawing, shape) elseif shape.mode == 'line' then local mx,my = Drawing.coord(App.mouse_x()-left), Drawing.coord(App.mouse_y()-top) if mx < 0 or mx >= 256 or my < 0 or my >= drawing.h then return end local p1 = drawing.points[shape.p1] love.graphics.line(Drawing.pixels(p1.x)+left,Drawing.pixels(p1.y)+top, Drawing.pixels(mx)+left,Drawing.pixels(my)+top) elseif shape.mode == 'manhattan' then local mx,my = Drawing.coord(App.mouse_x()-left), Drawing.coord(App.mouse_y()-top) if mx < 0 or mx >= 256 or my < 0 or my >= drawing.h then return end local p1 = drawing.points[shape.p1] if math.abs(mx-p1.x) > math.abs(my-p1.y) then love.graphics.line(Drawing.pixels(p1.x)+left,Drawing.pixels(p1.y)+top, Drawing.pixels(mx)+left,Drawing.pixels(p1.y)+top) else love.graphics.line(Drawing.pixels(p1.x)+left,Drawing.pixels(p1.y)+top, Drawing.pixels(p1.x)+left,Drawing.pixels(my)+top) end elseif shape.mode == 'polygon' then -- don't close the loop on a pending polygon local prev = nil for _,point in ipairs(shape.vertices) do local curr = drawing.points[point] if prev then love.graphics.line(Drawing.pixels(prev.x)+left,Drawing.pixels(prev.y)+top, Drawing.pixels(curr.x)+left,Drawing.pixels(curr.y)+top) end prev = curr end love.graphics.line(Drawing.pixels(prev.x)+left,Drawing.pixels(prev.y)+top, App.mouse_x(),App.mouse_y()) elseif shape.mode == 'rectangle' then local pmx,pmy = App.mouse_x(), App.mouse_y() local first = drawing.points[shape.vertices[1]] if #shape.vertices == 1 then love.graphics.line(Drawing.pixels(first.x)+left,Drawing.pixels(first.y)+top, pmx,pmy) return end local second = drawing.points[shape.vertices[2]] local mx,my = Drawing.coord(pmx-left), Drawing.coord(pmy-top)
<html>
	<head>
		<title>dwm - dynamic window manager</title>
		<meta name="author" content="Anselm R. Garbe">
		<meta name="generator" content="ed">
		<meta name="copyright" content="(C)opyright 2006 by Anselm R. Garbe">
		<style type="text/css">
			body {
				color: #000000;
				font-family: sans-serif;
				margin: 20px 20px 20px 20px;
			}
		</style>
	</head>
	<body>
		<center>
			<img src="dwm.png"/><br />
			<h3>dynamic window manager</h3>
		</center>
		<h3>Description</h3>
		<p>
		dwm is a dynamic window manager for X11.
		</p>
		<h3>Philosophy</h3>
		<p>
		As founder and main developer of wmii I came to the conclusion that
		wmii is too clunky for my needs. I don't need so many funky features
		and all this hype about remote control through a 9P service, I only
		want to manage my windows in a simple, but dynamic way. wmii never got
		finished because I listened to users, who proposed arbitrary ideas I
		considered useful. This resulted in an extreme <a href="http://www.jwz.org/doc/cadt.html">CADT</a>
		development model, which was a mistake. Thus the philosophy of
		dwm is simply <i>to fit my needs</i> (maybe yours as well). That's it.
		</p>
		<h3>Differences to wmii</h3	
		<p>
		In contrast to wmii, dwm is only a window manager, and nothing else.
		Hence, it is much smaller, faster and simpler.
		</p>
		<ul>
			<li>
			dwm has no 9P support, no menu, no editable tagbars,
			no shell-based configuration and remote control and comes without
			any additional tools like printing the selection or warping the
			mouse.
			</li>
			<li>
			dwm is only a single binary, it's source code is intended to never
			exceed 2000 SLOC.
			</li>
			<li>
			dwm is customized through editing its source code, that makes it
			extremely fast and secure - it does not process any input data which
			hasn't been known at compile time, except window title names.
			</li>
			<li>
			dwm is based on tagging and dynamic window management (however simpler
			than wmii or larswm).
			</li>
			<li>
			dwm don't distinguishes between layers, there is no floating or
			managed layer. Wether the clients of currently selected tag are
			managed or not, you can re-arrange all clients on the fly. Popup-
			and fixed-size windows are treated unmanaged. 
			</li>
			<li>
			dwm uses 1-pixel borders to provide the maximum of screen real
			estate to clients. Small titlebars are only drawn in front of unfocused
			clients.
			</li>
			<li>
			dwm reads from <b>stdin</b> to print arbitrary status text (like the
			date, load, battery charge). That's much simpler than larsremote,
			wmiir and what not...
			</li>
			<li>
			Anselm <b>does not</b> want any feedback to dwm. If you ask for support,
			feature requests, or if you report bugs, they will be <b>ignored</b>
			with a high chance. dwm is only intended to fit Anselms needs.
			However you are free to download and distribute/relicense it, with the
			conditions of the <a href="http://wmii.de/cgi-bin/hgwebdir.cgi/dwm?f=f10eb1139362;file=LICENSE;style=raw">MIT/X Consortium license</a>.
			</li>
		</ul>
		<h3>Screenshot</h3>
		<p>
		<a href="http://wmii.de/shots/dwm-20060714.png">Click here for a screenshot</a> (20060714)
		</p>
		<h3>Development</h3>
		<p>
		dwm is actively developed in parallel to wmii. You can <a href="http://wmii.de/cgi-bin/hgwebdir.cgi/dwm">browse</a> its source code repository or get a copy using <a href="http://www.selenic.com/mercurial/">Mercurial</a> with following command:
		</p>
		<p>
		<code>hg clone http://wmii.de/cgi-bin/hgwebdir.cgi/dwm</code>
		</p>
		<h3>Download</h3>
		<ul>
			<li><a href="http://wmii.de/download/dwm-0.1.tar.gz">dwm 0.1</a> (12kb) (20060714)</li>
		</ul>
		<h3>Miscellaneous</h3>
		<p>
		You can purchase this <a href="https://www.spreadshirt.net/shop.php?op=article&article_id=3298632&view=403">tricot</a>
		if you like dwm and the dwm logo, which has been designed by Anselm.
		</p>
		<p><small>--Anselm (20060714)</small></p>
	</body>
</html>
drawing.show_help = true end end end function Drawing.complete_rectangle(firstx,firsty, secondx,secondy, x,y) if firstx == secondx then return x,secondy, x,firsty end if firsty == secondy then return secondx,y, firstx,y end local first_slope = (secondy-firsty)/(secondx-firstx) -- slope of second edge: -- -1/first_slope -- equation of line containing the second edge: -- y-secondy = -1/first_slope*(x-secondx) -- => 1/first_slope*x + y + (- secondy - secondx/first_slope) = 0 -- now we want to find the point on this line that's closest to the mouse pointer. -- https://en.wikipedia.org/wiki/Distance_from_a_point_to_a_line#Line_defined_by_an_equation local a = 1/first_slope local c = -secondy - secondx/first_slope local thirdx = ((x-a*y) - a*c) / (a*a + 1) local thirdy = (a*(-x + a*y) - c) / (a*a + 1) -- slope of third edge = first_slope -- equation of line containing third edge: -- y - thirdy = first_slope*(x-thirdx) -- => -first_slope*x + y + (-thirdy + thirdx*first_slope) = 0 -- now we want to find the point on this line that's closest to the first point local a = -first_slope local c = -thirdy + thirdx*first_slope local fourthx = ((firstx-a*firsty) - a*c) / (a*a + 1) local fourthy = (a*(-firstx + a*firsty) - c) / (a*a + 1) return thirdx,thirdy, fourthx,fourthy end function Drawing.complete_square(firstx,firsty, secondx,secondy, x,y) -- use x,y only to decide which side of the first edge to complete the square on local deltax = secondx-firstx local deltay = secondy-firsty local thirdx = secondx+deltay local thirdy = secondy-deltax if not geom.same_side(firstx,firsty, secondx,secondy, thirdx,thirdy, x,y) then deltax = -deltax deltay = -deltay thirdx = secondx+deltay thirdy = secondy-deltax end local fourthx = firstx+deltay local fourthy = firsty-deltax return thirdx,thirdy, fourthx,fourthy end function Drawing.current_drawing() local x, y = App.mouse_x(), App.mouse_y() for drawing_index,drawing in ipairs(Lines) do if drawing.mode == 'drawing' then if Drawing.in_drawing(drawing, x,y) then return drawing_index,drawing end end end return nil end function Drawing.select_shape_at_mouse() for _,drawing in ipairs(Lines) do if drawing.mode == 'drawing' then local x, y = App.mouse_x(), App.mouse_y() if Drawing.in_drawing(drawing, x,y) then local mx,my = Drawing.coord(x-Margin_left), Drawing.coord(y-drawing.y) for i,shape in ipairs(drawing.shapes) do assert(shape) if geom.on_shape(mx,my, drawing, shape) then return drawing,i,shape end end end end end end function Drawing.select_point_at_mouse() for drawing_index,drawing in ipairs(Lines) do if drawing.mode == 'drawing' then local x, y = App.mouse_x(), App.mouse_y() if Drawing.in_drawing(drawing, x,y) then local mx,my = Drawing.coord(x-Margin_left), Drawing.coord(y-drawing.y) for i,point in ipairs(drawing.points) do assert(point) if Drawing.near(point, mx,my) then return drawing_index,drawing,i,point end end end end end end function Drawing.select_drawing_at_mouse() for _,drawing in ipairs(Lines) do if drawing.mode == 'drawing' then local x, y = App.mouse_x(), App.mouse_y() if Drawing.in_drawing(drawing, x,y) then return drawing end end end end function Drawing.contains_point(shape, p) if shape.mode == 'freehand' then -- not supported elseif shape.mode == 'line' or shape.mode == 'manhattan' then return shape.p1 == p or shape.p2 == p elseif shape.mode == 'polygon' or shape.mode == 'rectangle' or shape.mode == 'square' then return table.find(shape.vertices, p) elseif shape.mode == 'circle' then return shape.center == p elseif shape.mode == 'arc' then return shape.center == p -- ugh, how to support angles elseif shape.mode == 'deleted' then -- already done else print(shape.mode) assert(false) end end function Drawing.convert_line(drawing, shape) -- Perhaps we should do a more sophisticated "simple linear regression" -- here: -- https://en.wikipedia.org/wiki/Linear_regression#Simple_and_multiple_linear_regression -- But this works well enough for close-to-linear strokes. assert(shape.mode == 'freehand') shape.mode = 'line' shape.p1 = insert_point(drawing.points, shape.points[1].x, shape.points[1].y) local n = #shape.points shape.p2 = insert_point(drawing.points, shape.points[n].x, shape.points[n].y) end -- turn a line either horizontal or vertical function Drawing.convert_horvert(drawing, shape) if shape.mode == 'freehand' then Drawing.convert_line(shape) end assert(shape.mode == 'line') local p1 = drawing.points[shape.p1] local p2 = drawing.points[shape.p2] if math.abs(p1.x-p2.x) > math.abs(p1.y-p2.y) then p2.y = p1.y else p2.x = p1.x end end function Drawing.smoothen(shape) assert(shape.mode == 'freehand') for _=1,7 do for i=2,#shape.points-1 do local a = shape.points[i-1] local b = shape.points[i] local c = shape.points[i+1] b.x = (a.x + b.x + c.x)/3 b.y = (a.y + b.y + c.y)/3 end end end function Drawing.insert_point(points, x,y) for i,point in ipairs(points) do if Drawing.near(point, x,y) then return i end end table.insert(points, {x=x, y=y}) return #points end function Drawing.near(point, x,y) local px,py = Drawing.pixels(x),Drawing.pixels(y) local cx,cy = Drawing.pixels(point.x), Drawing.pixels(point.y) return (cx-px)*(cx-px) + (cy-py)*(cy-py) < Margin_left end function Drawing.pixels(n) -- parts to pixels return math.floor(n*Line_width/256) end function Drawing.coord(n) -- pixels to parts return math.floor(n*256/Line_width) end function table.find(h, x) for k,v in pairs(h) do if v == x then return k end end end return Drawing