diff --git a/0002-vx b/0002-vx new file mode 100644 index 0000000..065d2c5 --- /dev/null +++ b/0002-vx @@ -0,0 +1,4 @@ +vx = function(sx) + -- turn surface coordinates into viewport coordinates + return scale(sx-Viewport.x) +end diff --git a/0003-scale b/0003-scale new file mode 100644 index 0000000..22e97bb --- /dev/null +++ b/0003-scale @@ -0,0 +1,3 @@ +scale = function(d) + return d*Viewport.zoom +end \ No newline at end of file diff --git a/0004-vy b/0004-vy new file mode 100644 index 0000000..8e4e23e --- /dev/null +++ b/0004-vy @@ -0,0 +1,4 @@ +vy = function(sy) + -- turn surface coordinates into viewport coordinates + return scale(sy-Viewport.y) +end diff --git a/0007-to_text b/0007-to_text index 4e5997d..3eb81e5 100644 --- a/0007-to_text +++ b/0007-to_text @@ -1,12 +1,11 @@ to_text = function(x,y) - local sx, sy = x/Viewport.zoom + Viewport.x, y/Viewport.zoom + Viewport.y for _,node in ipairs(Surface) do if node.type == 'text' then - if sx >= node.x and node.w and sx < node.x + node.w then - if sy >= node.y and node.h and sy < node.y + node.h then + if x >= vx(node.x) and node.w and x < vx(node.x + node.w) then + if y >= vy(node.y) and node.h and y < vy(node.y + node.h) then return node end end end end -end +end \ No newline at end of file diff --git a/0008-Viewport b/0008-Viewport index 770f1e8..0dc66df 100644 --- a/0008-Viewport +++ b/0008-Viewport @@ -1 +1 @@ -Viewport = {x=-50, y=-50, w=800,h=600, zoom=0.4} +Viewport = {x=-50, y=-50, w=800,h=600, zoom=1.0} \ No newline at end of file diff --git a/0010-initialize_editor b/0010-initialize_editor index ca6e7ef..004b576 100644 --- a/0010-initialize_editor +++ b/0010-initialize_editor @@ -1,8 +1,10 @@ initialize_editor = function(obj) if obj.w then -- use an editor to wrap the text - obj.editor = edit.initialize_state(obj.y, obj.x, obj.x+obj.w, 20, math.floor(20*1.3)) + local scaled_fontsize = scale(20) + local scaled_lineheight = math.floor(scaled_fontsize*1.3) + obj.editor = edit.initialize_state(vy(obj.y), math.floor(vx(obj.x)), math.ceil(vx(obj.x+obj.w)), scaled_fontsize, scaled_lineheight) obj.editor.lines = load_array(obj.data) Text.redraw_all(obj.editor) end -end +end \ No newline at end of file diff --git a/0011-box_height b/0011-box_height index 38259d2..794a812 100644 --- a/0011-box_height +++ b/0011-box_height @@ -1,16 +1,16 @@ box_height = function(node) - -- return the height of a text editor node (explicit width). The result is scaled. - local count = 0 + -- return the height of a text editor node (explicit width). The result is unscaled. + local y = 0 for i=1,#node.editor.lines do local line = node.editor.lines[i] if node.editor.line_cache[i] == nil then node.editor.line_cache[i] = {} end + node.editor.line_cache[i].fragments = nil node.editor.line_cache[i].screen_line_starting_pos = nil Text.populate_screen_line_starting_pos(node.editor, i) - count = count + #node.editor.line_cache[i].screen_line_starting_pos + y = y + node.editor.line_height*#node.editor.line_cache[i].screen_line_starting_pos Text.clear_screen_line_cache(node.editor, i) end - print(count, '*', node.editor.line_height, '=', count*node.editor.line_height) - return count*node.editor.line_height/Viewport.zoom + return y end diff --git a/0012-on.initialize b/0012-on.initialize index 9ef6039..44a5989 100644 --- a/0012-on.initialize +++ b/0012-on.initialize @@ -1,4 +1,3 @@ on.initialize = function() - love.graphics.setFont(love.graphics.newFont(20)) A() -end +end \ No newline at end of file diff --git a/0019-B b/0019-B index 891b0fc..7e7d0c7 100644 --- a/0019-B +++ b/0019-B @@ -1,2 +1,25 @@ B = function() + -- recompute various aspects based on the current viewport settings + for _,obj in ipairs(Surface) do + if obj.type == 'line' then + obj.zdata = {} + for i=1,#obj.data,2 do + table.insert(obj.zdata, vx(obj.data[i])) + table.insert(obj.zdata, vy(obj.data[i+1])) + end + elseif obj.type == 'bezier' then + zdata = {} + for i=1,#obj.data,2 do + table.insert(zdata, vx(obj.data[i])) + table.insert(zdata, vy(obj.data[i+1])) + end + obj.zdata = love.math.newBezierCurve(zdata):render() + elseif obj.type == 'text' then + if obj.w then + update_editor_box(obj) + else + obj.text = love.graphics.newText(love.graphics.getFont(), obj.data) + end + end + end end diff --git a/0020-Page b/0020-Page index 767b025..33c7966 100644 --- a/0020-Page +++ b/0020-Page @@ -9,68 +9,37 @@ Page = { doc='prose goes here, on the left half of the window', margin=Margin_left, data={ -'1', -'2', -'3', -'4', -'5', -'6', -'7', -'8', -'9', -'10', -'11', -'12', -'13', -'14', -'15', -'16', -'17', -'18', -'19', -'20', -'21', -'22', -'23', -'24', -'25', -'26', -'27', -'28', -'29', -'30', -'31', -'32', -'33', -'34', -'35', -'36', -'37', -'38', -'39', -'40', -'41', -'42', -'43', -'44', -'45', -'46', -'47', -'48', -'49', -'50', -'51', -'52', -'53', -'54', -'55', -'56', -'57', -'58', -'59', -'60', + "Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.", + '1', + '2', + '3', + 'mno', + 'Acb', + 'g', + 'hij', + 'klm', + 'nop', }, width=400, bg={r=1,g=1,b=0} }, + -- a table on the right + { type='rows', name='searches', margin=50, data={ + { type='text', data={''},}, + { type='cols', data={ + { type='text', data={'search:'},}, + { type='text', name='search', bg={r=0.8,g=0.8,b=0.8}, data={''}, width=90,}, + }}, + { type='text', data={'table:'},}, + { type='cols', bg={r=0.8,g=0.8,b=0.8}, data={ + { type='rows', width=90, data={ + {type='text', data={'abc'},}, + {type='text', data={'abc'},}, + }}, + { type='rows', width=90, data={ + {type='text', data={'def'},}, + {type='text', data={'def'},}, + }}, + }}, + }}, }, -} +} \ No newline at end of file diff --git a/0026-on.draw b/0026-on.draw index 3bfbc3a..d569a9a 100644 --- a/0026-on.draw +++ b/0026-on.draw @@ -1,32 +1,22 @@ on.draw = function() - -- vx = x, vy = y - love.graphics.translate(-Viewport.x, -Viewport.y) - -- vx = x-Viewport.x, vy = y-Viewport.y - love.graphics.scale(Viewport.zoom) - -- vx = (x-Viewport.x)*Viewport.zoom, vy = (y-Viewport.y)*Viewport.zoom - love.graphics.setColor(0,0,0) - love.graphics.line(0, 0, 0, 1000000) - love.graphics.line(0, 0, 1000000, 0) - for i=1,100 do - love.graphics.print(tostring(i), 0, i*1000) - end + love.graphics.setColor(1,0,0) for _,obj in ipairs(Surface) do love.graphics.setColor(obj.r or 0, obj.g or 0, obj.b or 0) if obj.type == 'rectangle' then - love.graphics.rectangle(obj.drawmode or 'fill', obj.x,obj.y, obj.w,obj.h, obj.rx or 0,obj.ry or obj.rx or 0) + love.graphics.rectangle(obj.drawmode or 'fill', vx(obj.x),vy(obj.y), scale(obj.w),scale(obj.h), scale(obj.rx or 0),scale(obj.ry or obj.rx or 0)) elseif obj.type == 'line' then - love.graphics.line(unpack(obj.data)) + love.graphics.line(unpack(obj.zdata)) elseif obj.type == 'circle' then - love.graphics.circle(obj.drawmode or 'fill', obj.x, obj.y, obj.radius) + love.graphics.circle(obj.drawmode or 'fill', vx(obj.x), vy(obj.y), scale(obj.radius)) elseif obj.type == 'arc' then - love.graphics.arc(obj.drawmode or 'line', obj.arctype or 'open', obj.x, obj.y, obj.radius, obj.angle1, obj.angle2, obj.segments) + love.graphics.arc(obj.drawmode or 'line', obj.arctype or 'open', vx(obj.x), vy(obj.y), scale(obj.radius), obj.angle1, obj.angle2, obj.segments) elseif obj.type == 'ellipse' then - love.graphics.ellipse(obj.drawmode or 'fill', obj.x, obj.y, obj.radiusx, obj.radiusy) + love.graphics.ellipse(obj.drawmode or 'fill', vx(obj.x), vy(obj.y), scale(obj.radiusx), scale(obj.radiusy)) elseif obj.type == 'bezier' then - love.graphics.line(unpack(obj.data)) + love.graphics.line(unpack(obj.zdata)) elseif obj.type == 'text' then if obj.w == nil then - love.graphics.draw(obj.text, obj.x, obj.y) + love.graphics.draw(obj.text, vx(obj.x), vy(obj.y)) else edit.draw(obj.editor, obj.fg or {r=0,g=0,b=0}, not obj.show_cursor) end diff --git a/0027-Surface b/0027-Surface index 9a7cf0d..4c79c0f 100644 --- a/0027-Surface +++ b/0027-Surface @@ -1,2 +1,12 @@ Surface = { -} + -- test data + {type='line', data={0,-1000, 0,1000}}, + {type='line', data={-10000,0, 10000,0}}, + {type='text', data={'0'}, x=-20,y=-30}, + {type='rectangle', x=50,y=50, w=20,h=80, r=1,g=0,b=0}, + {type='text', data={'abc', 'def'}, x=150, y=50, w=50,h=50, fg={r=0,g=0.4, b=0.9}}, + {type='circle', x=300,y=200, radius=40, r=1,g=0,b=1}, + {type='arc', x=0,y=0, radius=50, angle1=0, angle2=math.pi*2/3}, + {type='ellipse', x=100,y=100, radiusx=10, radiusy=50}, + {type='bezier', data={25,25, 25,125, 75,25, 125,25}}, +} \ No newline at end of file diff --git a/0028-A b/0028-A index a340b80..c501e0b 100644 --- a/0028-A +++ b/0028-A @@ -1,10 +1,17 @@ A = function() - print('A') - local red = false - for x=-1000,2000,300 do - for y=-10000,10000,200 do - add_thick_line({type='line', data={x,y, x+200,y+200, x,y+400}, r=red and 1 or 0,g=red and 0 or 0.5,b=0}, 10) - red = not red - end - end + love.graphics.setFont(love.graphics.newFont(scale(20))) -- editor objects implicitly depend on current font + -- translate Page to Surface + while #Surface > 3 do table.remove(Surface) end -- HACK + local red = false + for x=-1000,2000,300 do + for y=-10000,10000,200 do + add_thick_line({type='line', data={x,y, x+200,y+200, x,y+400}, r=red and 1 or 0,g=red and 0 or 0.5,b=0}, 10) + red = not red + end + end + compute_layout(Page, Page.x,Page.y, Surface) + compute_layout(Page2, Page2.x,Page2.y, Surface) + -- continue the pipeline + B() + -- TODO: ugly that we're manipulating editor objects twice end diff --git a/0029-Page2 b/0029-Page2 new file mode 100644 index 0000000..61735e5 --- /dev/null +++ b/0029-Page2 @@ -0,0 +1,9 @@ +Page2 = { + x=500, y=300, + -- page + type='text', + data={ +"Call me Ishmael. Some years ago--never mind how long precisely--having little or no money in my purse, and nothing particular to interest me on shore, I thought I would sail about a little and see the watery part of the world. It is a way I have of driving off the spleen and regulating the circulation. Whenever I find myself growing grim about the mouth; whenever it is a damp, drizzly November in my soul; whenever I find myself involuntarily pausing before coffin warehouses, and bringing up the rear of every funeral I meet; and especially whenever my hypos get such an upper hand of me, that it requires a strong moral principle to prevent me from deliberately stepping into the street, and methodically knocking people's hats off--then, I account it high time to get to sea as soon as I can. This is my substitute for pistol and ball. With a philosophical flourish Cato throws himself upon his sword; I quietly take to the ship. There is nothing surprising in this. If they but knew it, almost all men in their degree, some time or other, cherish very nearly the same feelings towards the ocean with me." + }, + width=400, bg={r=0,g=0.8,b=0} +} \ No newline at end of file diff --git a/0030-update_editor_box b/0030-update_editor_box index f901212..5808946 100644 --- a/0030-update_editor_box +++ b/0030-update_editor_box @@ -5,9 +5,9 @@ update_editor_box = function(node) node.editor.screen_top1.line = 1 node.editor.screen_top1.pos = 1 end - node.editor.top = node.y + node.editor.top = vy(node.y) else - node.editor.screen_top1, node.editor.top = schema1_of_y(node.editor, scale(Viewport.y-node.y)) + node.editor.screen_top1, node.editor.top = schema1_of_y(node.editor, Viewport.y-node.y) end node.editor.left = math.floor(vx(node.x)) node.editor.right = math.ceil(vx(node.x+node.w))