/ld27

To get this branch, use:
bzr branch http://9ix.org/bzr/ld27

« back to all changes in this revision

Viewing changes to zoetrope/debug/watch.lua

  • Committer: Josh C
  • Date: 2013-08-25 02:04:52 UTC
  • Revision ID: josh@9ix.org-20130825020452-py8fijli8m5te5gv
improve performance with (sketchy, experimental) sprite batches

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
DebugWatch = DebugInstrument:extend
2
 
{
3
 
        _watches = {},
4
 
        visible = false,
5
 
 
6
 
        onNew = function (self)
7
 
                self.title.text = 'Watch'
8
 
                self.labels = self:add(Text:new{ font = self.font })
9
 
                self.values = self:add(Text:new{ font = self.font })
10
 
                self.lineHeight = self.labels._fontObj:getHeight()
11
 
 
12
 
                debugger.watch = function (exp, label) self:addExpression(exp, label) end
13
 
        end,
14
 
 
15
 
        -- Method: addExpression
16
 
        -- Adds an expression to be watched.
17
 
        --
18
 
        -- Arguments:
19
 
        --              expression - expression to evaluate as a string
20
 
        --              label - string label, defaults to expression
21
 
 
22
 
        addExpression = function (self, expression, label)
23
 
                self.visible = true
24
 
                table.insert(self._watches, { label = label or expression,
25
 
                                                                          func = loadstring('return ' .. expression) })
26
 
        
27
 
                self.contentHeight = #self._watches * self.lineHeight + 2 * self.spacing
28
 
        end,
29
 
 
30
 
        onUpdate = function (self)
31
 
                self.labels.text = ''
32
 
                self.values.text = ''
33
 
 
34
 
                for _, watch in pairs(self._watches) do
35
 
                        local ok, value = pcall(watch.func)
36
 
                        if not ok then value = nil end
37
 
                        self.labels.text = self.labels.text .. watch.label .. '\n'
38
 
                        self.values.text = self.values.text .. tostring(value) .. '\n'
39
 
                end
40
 
        end,
41
 
 
42
 
        onResize = function (self, x, y, width, height)
43
 
                self.labels.y, self.values.y = y + self.spacing, y + self.spacing
44
 
                self.labels.height, self.values.height = height, height
45
 
 
46
 
                self.labels.x = x + self.spacing
47
 
                self.labels.width = width / 2 - self.spacing * 2
48
 
                
49
 
                self.values.x = self.labels.x + self.labels.width + self.spacing
50
 
                self.values.width = self.labels.width
51
 
        end
52
 
}