@@ -4,6 +4,21 @@ local cursor = require('plugin.hwcursor')
4
4
local hidden = false
5
5
cursor .initPlugin ()
6
6
7
+ -- New in this version
8
+
9
+ -- Call cursor.loadCursor the first time with the path to the cursor
10
+ -- and store the return value, which is a pointer to the cursor resource (preload step)
11
+
12
+ -- Call cursor.loadCursor the second time with the previously returned pointer
13
+ -- to actually set the cursor (usage step)
14
+
15
+ -- Cursors must be preloaded before being used
16
+ local cursors = {
17
+ cursor1 = cursor .loadCursor (system .pathForFile (' cursor1.cur' )), -- Bigger than normal
18
+ cursor2 = cursor .loadCursor (system .pathForFile (' cursor2.ani' )), -- Regular size
19
+ cursor3 = cursor .loadCursor (system .pathForFile (' cursor3.ani' )) -- Huge (256x256)
20
+ }
21
+
7
22
display .newText (
8
23
{
9
24
x = display .contentCenterX ,
@@ -37,7 +52,8 @@ widget.newButton(
37
52
x = display .contentCenterX ,
38
53
y = display .contentCenterY - 50 ,
39
54
label = ' Custom cursor 1' ,
40
- onRelease = function () cursor .loadCursor (system .pathForFile (' cursor1.cur' )) end ,
55
+ -- Set cursor using stored pointer
56
+ onRelease = function () cursor .loadCursor (cursors .cursor1 ) end ,
41
57
labelColor = { default = { 1 , 1 , 1 }, over = { 0 , 0 , 0 , 0.5 } },
42
58
fillColor = { default = { 1 , 0.2 , 0.5 , 0.7 }, over = { 1 , 0.2 , 0.5 , 1 } }
43
59
}
@@ -51,7 +67,8 @@ widget.newButton(
51
67
x = display .contentCenterX ,
52
68
y = display .contentCenterY ,
53
69
label = ' Custom cursor 2' ,
54
- onRelease = function () cursor .loadCursor (system .pathForFile (' cursor2.ani' )) end ,
70
+ -- Set cursor using stored pointer
71
+ onRelease = function () cursor .loadCursor (cursors .cursor2 ) end ,
55
72
labelColor = { default = { 1 , 1 , 1 }, over = { 0 , 0 , 0 , 0.5 } },
56
73
fillColor = { default = { 1 , 0.2 , 0.5 , 0.7 }, over = { 1 , 0.2 , 0.5 , 1 } }
57
74
}
@@ -65,7 +82,8 @@ widget.newButton(
65
82
x = display .contentCenterX ,
66
83
y = display .contentCenterY + 50 ,
67
84
label = ' Custom cursor 3' ,
68
- onRelease = function () cursor .loadCursor (system .pathForFile (' cursor3.ani' )) end ,
85
+ -- Set cursor using stored pointer
86
+ onRelease = function () cursor .loadCursor (cursors .cursor3 ) end ,
69
87
labelColor = { default = { 1 , 1 , 1 }, over = { 0 , 0 , 0 , 0.5 } },
70
88
fillColor = { default = { 1 , 0.2 , 0.5 , 0.7 }, over = { 1 , 0.2 , 0.5 , 1 } }
71
89
}
@@ -101,7 +119,11 @@ widget.newButton(
101
119
y = display .contentCenterY + 150 ,
102
120
label = ' Exit application' ,
103
121
onRelease = function ()
104
- cursor .resetCursor ()
122
+ -- Destroy all cursors before exiting
123
+ for k , v in pairs (cursors ) do
124
+ cursor .destroyCursor (v )
125
+ cursors [k ] = nil
126
+ end
105
127
cursor .freePlugin ()
106
128
native .requestExit ()
107
129
end ,
@@ -110,6 +132,59 @@ widget.newButton(
110
132
}
111
133
)
112
134
135
+ --[[
136
+ widget.newButton(
137
+ {
138
+ width = 200,
139
+ height = 30,
140
+ shape = 'roundedRect',
141
+ x = display.contentCenterX,
142
+ y = display.contentCenterY + 200,
143
+ label = 'Destroy cursor 1',
144
+ onRelease = function()
145
+ cursor.destroyCursor(cursors.cursor1)
146
+ cursors.cursor1 = nil
147
+ end,
148
+ labelColor = { default = { 1, 1, 1 }, over = { 0, 0, 0, 0.5 } },
149
+ fillColor = { default = { 1, 0.2, 0.5, 0.7 }, over = { 1, 0.2, 0.5, 1 } }
150
+ }
151
+ )
152
+
153
+ widget.newButton(
154
+ {
155
+ width = 200,
156
+ height = 30,
157
+ shape = 'roundedRect',
158
+ x = display.contentCenterX,
159
+ y = display.contentCenterY + 250,
160
+ label = 'Destroy cursor 2',
161
+ onRelease = function()
162
+ cursor.destroyCursor(cursors.cursor2)
163
+ cursors.cursor2 = nil
164
+ end,
165
+ labelColor = { default = { 1, 1, 1 }, over = { 0, 0, 0, 0.5 } },
166
+ fillColor = { default = { 1, 0.2, 0.5, 0.7 }, over = { 1, 0.2, 0.5, 1 } }
167
+ }
168
+ )
169
+
170
+ widget.newButton(
171
+ {
172
+ width = 200,
173
+ height = 30,
174
+ shape = 'roundedRect',
175
+ x = display.contentCenterX,
176
+ y = display.contentCenterY + 300,
177
+ label = 'Destroy cursor 3',
178
+ onRelease = function()
179
+ cursor.destroyCursor(cursors.cursor3)
180
+ cursors.cursor3 = nil
181
+ end,
182
+ labelColor = { default = { 1, 1, 1 }, over = { 0, 0, 0, 0.5 } },
183
+ fillColor = { default = { 1, 0.2, 0.5, 0.7 }, over = { 1, 0.2, 0.5, 1 } }
184
+ }
185
+ )
186
+ ]] --
187
+
113
188
Runtime :addEventListener (' key' ,
114
189
function (event )
115
190
if event .phase == ' up' then
0 commit comments