blob: c932a551c88ab23710af0ad19b18cee50bb75bbb (
plain)
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
|
io.stdout:setvbuf("no")
local texture_shader_source = [[
#VERTEX_SHADER
Vertex vert(Vertex v)
{
return v;
}
#END_VERTEX_SHADER
#FRAGMENT_SHADER
Color frag(Color c, Texture tex, Vertex v)
{
return c * texel(tex, v.uv);
}
#END_FRAGMENT_SHADER
]]
local texture_shader = nil
local JGUI = require("JGUI")
local panel = JGUI.newPanel("Panel")
panel:setSize(300, 300)
local button = JGUI.newButton("test")
button:setSize(200, 50)
button:setPosition(0, 0)
panel:add(button)
local b1 = jin.graphics.newBitmap("a.png")
local b2 = jin.graphics.newBitmap("b.png")
local bt1 = jin.graphics.newTexture(b1)
local bt2 = jin.graphics.newTexture(b2)
b1 = nil
b2 = nil
local bt = bt1
button.onClick = function()
print("click")
bt = bt2
end
button.onRelease = function()
bt = bt1
end
function jin.core.onLoad()
texture_shader = jin.graphics.newShader(texture_shader_source)
end
function jin.core.onEvent(e)
if e.type == "Quit" then
jin.core.stop()
end
if e.type == "KeyDown" and e.key == "Escape" then
jin.core.stop()
end
panel:onEvent(e)
end
local t = 0
local f = 0
function jin.core.onUpdate(dt)
panel:onUpdate(dt)
f = f + 1
t = t + dt
if t >= 1 then
print(f)
t = t - 1
f = 0
end
end
function jin.core.onDraw()
jin.graphics.setColor(255 * math.sin(t), 255 * math.cos(t), 255 * math.tan(t), 255)
jin.graphics.useShader(texture_shader)
-- jin.graphics.unbindCanvas()
jin.graphics.draw(bt, 0, button.y)
jin.graphics.unuseShader()
end
|