-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzoompos.lua
executable file
·162 lines (110 loc) · 3.41 KB
/
zoompos.lua
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
local exitQuad = {x=4*64, y=1*64, w=64, h=64}
local unzoom8Quad = {x=3*64, y=1*64, w=64, h=64}
local zoom8Quad = {x=0, y=320, w=64, h=64}
--there is a technical zoom (scrsx, scrsy) that scales ui canvas to screen,
--but when blitting to ui canvas, sometimes we want to zoom in out the canvas ( result of this screen )
applicativezoom=1.0
--dbg
--applicativezoom=0.5
local screenPos = createbrushbox(100,100,200,200,true)
local function exitZP()
print('exit zp ')
--copy offset
offsetcvs.x=screenPos.x
offsetcvs.y=screenPos.y
--copy zoom
applicativezoom=1.0
--why only change app zoom in this case?
if screenPos.w~=screenPos.texture:getWidth() then
applicativezoom=screenPos.w/screenPos.texture:getWidth()
end
toPaintMode()
end
function resetZoom()
print('reset zoom')
bbresetzoom(screenPos)
screenPos.x=offsetcvs.x
screenPos.y=offsetcvs.y
end
function zoom8()
bbzoomset(screenPos,2.)
end
function unzoom8()
bbzoomset(screenPos,0.5)
end
--local wToBSS = createpicbutton(uiw-64,uih-64,buttonsPic,toBrushSourceSelection,exitQuad)
--local wStamp = createpicbutton(uiw-64,0,buttonsPic,stampSelection,exitQuad)
local widgets={}
createZPButtons=function()
widgets={}
local wExitZP = createpicbutton(0,0,buttonsPic,exitZP,exitQuad,buttonZoom)
local wZoom8 = createpicbutton(0,uih-64*buttonZoom,buttonsPic,zoom8,zoom8Quad,buttonZoom)
local wreset = createpicbutton(uiw-64*buttonZoom,uih-128*buttonZoom,buttonsPic,resetZoom,unzoom8Quad,buttonZoom)
local wUnzoom8 = createpicbutton(uiw-64*buttonZoom,uih-64*buttonZoom,buttonsPic,unzoom8,unzoom8Quad,buttonZoom)
table.insert(widgets,wExitZP)
table.insert(widgets,wUnzoom8)
table.insert(widgets,wZoom8)
-- table.insert(widgets,wToBSS)
table.insert(widgets,wreset)
-- table.insert(widgets,wStamp)
table.insert(widgets,screenPos )
end
local function rendertouicanvas()
love.graphics.setCanvas(ui)
love.graphics.clear(0.5,0.5,0.5,1.0)
love.graphics.setColor(1.,1.,1.,1.0)
love.graphics.rectangle('fill',screenPos.x,screenPos.y,screenPos.w,screenPos.h)
renderWidgets(widgets)
msgToCvs()
displayHoverMsg()
--love.graphics.print()
love.graphics.setCanvas()
end
local function zoomPosDraw()
rendertouicanvas()
--this is the background image of our paint
love.graphics.clear(.5,.5,.5,1.0)
--love.graphics.clear(1.,1.,1.,1.0)
love.graphics.setColor(1.0,1.0,1.0,1.0)
love.graphics.draw(ui,0,0,0,scrsx,scrsy)
end
local function zoomPosUpdate()
if npress==true then
-- print('bs click')
-- addMsg('bs click')
consumed=consumeClick(widgets)
-- print('consumed '..tostring(consumed))brushScreenbrushScreen
if consumed==true
then
return
end
npress=false
end
end
--zoom dezoom with keyboard
zoomPosKey=function(key, code, isrepeat)
if key=='up' then
bbzoomset(screenPos,0.5)
end
if key =='down' then
bbzoomset(screenPos,2.)
end
end
function toZoomPos()
createZPButtons()
uiResize=createZPButtons
bbsettexture(screenPos,frames[currentIdx].pic)
--TODO zoom should be copied from global
screenPos.x=offsetcvs.x
screenPos.y=offsetcvs.y
--this should be done auto in bbsettexture, if no quad passed
screenPos.w=conf.cvsw
screenPos.initw=conf.cvsw
screenPos.h=conf.cvsh
screenPos.inith=conf.cvsh
--WIP to check and update
-- bbzoomset(screenPos,applicativezoom)
keyFunc = zoomPosKey
drawFunc=zoomPosDraw
updateFunc=zoomPosUpdate
end