forked from TiddoLangerak/tracegl
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode_view.js
More file actions
85 lines (64 loc) · 1.8 KB
/
code_view.js
File metadata and controls
85 lines (64 loc) · 1.8 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// | Code view |______________________________/
// |
// | (C) Mozilla Corp
// | licensed under MPL 2.0 http://www.mozilla.org/MPL/
// \____________________________________________/
define(function(require){
var fn = require("../core/fn")
var ui = require("../core/ui")
var ac = require("../core/acorn")
var ct = require("../core/controls")
var tm = require("../core/text_mix")
var ts = require("../core/text_shaders")
var gl = ui.gl
//| Styling
//\____________________________________________/
var ft1 = ui.gl.sfont(
navigator.platform.match(/Mac/)?
"12px Menlo":
"12px Lucida Console")
function codeView(g){
// background
var b = ui.rect({f:'t.codeBg'})
// scrollbars
b._v_ = ct.vScroll({h:'p.h - 10'})
b._h_ = ct.hScroll({w:'p.w - 10'})
b.set(g)
b.font = ft1
//| rendering
//\____________________________________________/
// shaders+-
b.sh = {
text: ui.gl.getShader(ts.codeText), // text
select: ui.gl.getShader(ts.selectRect), // selection
cursor: ui.rect.drawer({f:'t.codeCursor'}), // cursor
line: ui.rect.drawer({f:'t.codeLineBg'}), // linemark
lrShadow: ui.rect.drawer({f:'mix(vec4(0,0,0,0.2),vec4(0,0,0,0),c.x)'}), // dropshadow
topShadow: ui.rect.drawer({f:'mix(t.codeBg,vec4(0,0,0,0),c.y)'})
}
// mix in behaviors
tm.viewport(b)
tm.cursors(b)
tm.drawing(b)
// rendering
b.l = function(){
ui.view(b, b.vps.o)
if(!b._v_.pg) b.size()
// update line numbers
b.linesUpdate(ui.t.codeLine)
b.drawLineMarks()
b.drawLines()
ui.clip(b.vps.o.x + b.vps.gx, b.vps.o.y, b.vps.o.w - b.vps.gx, b.vps.o.h)
// draw if/else markers
b.drawSelection()
if(b.text){
b.drawText()
}
b.drawCursors()
ui.clip(b.vps.o.x, b.vps.o.y, b.vps.o.w, b.vps.o.h)
b.drawShadows()
}
return b
}
return codeView
})