Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(12)

Side by Side Diff: resources/slides.lua

Issue 688363003: add textblobs to lua (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: add virtual destructor to fix warning Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « include/utils/SkTextBox.h ('k') | src/utils/SkLua.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 gShowBounds = false
1 2
2 gPath = "/skia/trunk/resources/" 3 gPath = "/skia/trunk/resources/"
3 4
4 function load_file(file) 5 function load_file(file)
5 local prev_path = package.path 6 local prev_path = package.path
6 package.path = package.path .. ";" .. gPath .. file .. ".lua" 7 package.path = package.path .. ";" .. gPath .. file .. ".lua"
7 require(file) 8 require(file)
8 package.path = prev_path 9 package.path = prev_path
9 end 10 end
10 11
(...skipping 19 matching lines...) Expand all
30 if 0 == indent then 31 if 0 == indent then
31 return 32 return
32 end 33 end
33 local ps = paint:getTextSize() 34 local ps = paint:getTextSize()
34 local cx = x - ps * .8 35 local cx = x - ps * .8
35 local cy = y - ps * .4 36 local cy = y - ps * .4
36 local radius = ps * .2 37 local radius = ps * .2
37 canvas:drawCircle(cx, cy, radius, paint) 38 canvas:drawCircle(cx, cy, radius, paint)
38 end 39 end
39 40
41 function stroke_rect(canvas, rect, color)
42 local paint = Sk.newPaint()
43 paint:setStroke(true);
44 paint:setColor(color)
45 canvas:drawRect(rect, paint)
46 end
47
40 function drawSlide(canvas, slide, master_template) 48 function drawSlide(canvas, slide, master_template)
41 template = master_template.slide -- need to sniff the slide to know if we' re title or slide 49 template = master_template.slide -- need to sniff the slide to know if we' re title or slide
42 50
43 local x = template.margin_x 51 local x = template.margin_x
44 local y = template.margin_y 52 local y = template.margin_y
45 local scale = 1.25 53 local scale = 1.25
46 54
47 if slide.blockstyle == "code" then 55 if slide.blockstyle == "code" then
48 local paint = master_template.codePaint 56 local paint = master_template.codePaint
49 local fm = paint:getFontMetrics() 57 local fm = paint:getFontMetrics()
50 local height = #slide * (fm.descent - fm.ascent) 58 local height = #slide * (fm.descent - fm.ascent)
51 y = (480 - height) / 2 59 y = (480 - height) / 2
52 for i = 1, #slide do 60 for i = 1, #slide do
53 local node = slide[i] 61 local node = slide[i]
54 y = y - fm.ascent * scale 62 y = y - fm.ascent * scale
55 canvas:drawText(node.text, x, y, paint) 63 canvas:drawText(node.text, x, y, paint)
56 y = y + fm.descent * scale 64 y = y + fm.descent * scale
57 end 65 end
58 return 66 return
59 end 67 end
60 68
61 for i = 1, #slide do 69 for i = 1, #slide do
62 local node = slide[i] 70 local node = slide[i]
63 local paint = template[node.indent + 1].paint 71 local paint = template[node.indent + 1].paint
64 local extra_dy = template[node.indent + 1].extra_dy 72 local extra_dy = template[node.indent + 1].extra_dy
65 local fm = paint:getFontMetrics() 73 local fm = paint:getFontMetrics()
66 local x_offset = -fm.ascent * node.indent * 1.25 74 local x_offset = -fm.ascent * node.indent * 1.25
67 75
68 y = y - fm.ascent * scale 76 local bounds = make_rect(x + x_offset, y, 620, 640)
69 draw_bullet(canvas, x + x_offset, y, paint, node.indent) 77 local blob, newBottom = Sk.newTextBlob(node.text, bounds, paint)
70 canvas:drawText(node.text, x + x_offset, y, paint) 78 draw_bullet(canvas, x + x_offset, y - fm.ascent, paint, node.indent)
71 y = y + fm.descent * scale + extra_dy 79 canvas:drawTextBlob(blob, 0, 0, paint)
80 y = newBottom + paint:getTextSize() * .5
81
82 if gShowBounds then
83 bounds.bottom = newBottom
84 stroke_rect(canvas, bounds, {a=1,r=0,g=1,b=0})
85 stroke_rect(canvas, blob:bounds(), {a=1,r=1,g=0,b=0})
86 end
87
72 end 88 end
73 end 89 end
74 90
75 -------------------------------------------------------------------------------- ------ 91 -------------------------------------------------------------------------------- ------
76 function make_tmpl(paint, extra_dy) 92 function make_tmpl(paint, extra_dy)
77 return { paint = paint, extra_dy = extra_dy } 93 return { paint = paint, extra_dy = extra_dy }
78 end 94 end
79 95
80 function SkiaPoint_make_template() 96 function SkiaPoint_make_template()
81 local title = { 97 local title = {
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 return false 314 return false
299 end 315 end
300 316
301 local keyProcs = { 317 local keyProcs = {
302 n = next_slide, 318 n = next_slide,
303 p = prev_slide, 319 p = prev_slide,
304 r = spawn_rotate_animation, 320 r = spawn_rotate_animation,
305 s = spawn_scale_animation, 321 s = spawn_scale_animation,
306 ["="] = function () scale_text_delta(gTemplate, 1) end, 322 ["="] = function () scale_text_delta(gTemplate, 1) end,
307 ["-"] = function () scale_text_delta(gTemplate, -1) end, 323 ["-"] = function () scale_text_delta(gTemplate, -1) end,
324
325 b = function () gShowBounds = not gShowBounds end,
308 } 326 }
309 327
310 function onCharHandler(uni) 328 function onCharHandler(uni)
311 local proc = keyProcs[uni] 329 local proc = keyProcs[uni]
312 if proc then 330 if proc then
313 proc() 331 proc()
314 return true 332 return true
315 end 333 end
316 return false 334 return false
317 end 335 end
OLDNEW
« no previous file with comments | « include/utils/SkTextBox.h ('k') | src/utils/SkLua.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698