forked from adamredwoods/minib3d-monkey
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tpixmap.monkey
194 lines (114 loc) · 3.33 KB
/
tpixmap.monkey
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
''
'' TPixmap
'' for monkey
''
Import minib3d
Import minib3d.monkeyutility
Import mojo.data
'Import minib3d.monkeybuffer
Interface IPixmapManager
Method LoadPixmap:TPixmap(f$)
Method CreatePixmap:TPixmap(w:Int, h:Int, format:Int=PF_RGBA8888)
End
Interface IPreloadManager
Method AllocatePreLoad:Void(size:Int)
Method PreLoadData:Void(f$, id:Int)
Method SetPixmapFromID:Void(pixmap:TPixmap, id:Int, file:String)
Method SetPreloader:Void(preloader_class:TPixmapPreloader)
Method Update:Void()
End
Class TPixmap
Global manager:IPixmapManager ''Use this to Load & Create pixmaps, this is set by render driver
Global preloader:TPixmapPreloader
Field width:Int, height:Int
'' PreLoadPixmap(file$[])
'' -- returns 1 for finished load from given array
'' -- GetNumberLoaded() contains number of files loaded
Function PreLoadPixmap:Int(file$[])
Return preloader.PreLoad(file)
End
Function GetNumberLoaded:Int()
Return preloader.GetNumberLoaded()
End
Function LoadPixmap:TPixmap(f$)
Return manager.LoadPixmap(f)
End
Function CreatePixmap:TPixmap(w:Int, h:Int, format:Int=PF_RGBA8888)
Return manager.CreatePixmap(w,h,format)
End
Method ResizePixmap:TPixmap(neww:Int, newh:Int) Abstract
''averages pixels
Method ResizePixmapNoSmooth:TPixmap(neww:Int, newh:Int) Abstract
''no average, straight pixels better for fonts, details
''pixelation ok
Method MaskPixmap:Void(r:Int, g:Int, b:Int)
End
Method ApplyAlpha:Void( pixmap:TPixmap )
End
Method GetPixel:Int( x:Int, y:Int)
Return 0
End
Method SetPixel:Void(x:Int, y:Int, r:Int, g:Int, b:Int, a:Int=255)
End
End
Class TPixmapPreloader
Field manager:IPreloadManager
Field loading:Bool = False, loaded:Int = 0, total:Int =0
Field old_file:String[1]
Field cur_file:Int=0
'Field imagebuffer:IPixmapBuffer[]
Method New(m:IPreloadManager)
manager = m
manager.SetPreloader(Self)
End
Method CheckAllLoaded()
If loaded = total Then loading = False
End
Method GetNumberLoaded:Int()
Return loaded
End
Method IncLoader:Void()
loaded += 1
CheckAllLoaded()
End
Method PreLoad:Int(file$[])
If Not manager Then Error "**ERROR: no preload manager"
''use for async events
manager.Update()
'Print "loading "+Int(loading)+" "+old_file[0]+"="+file[0]
If file[0] <> old_file[0]
loaded = 0
cur_file = 0
loading = True
total = file.Length()
manager.AllocatePreLoad(total) 'New IBuffer[total]
old_file = file
Elseif ((Not loading) And (file[0] = old_file[0]))
Return 1
Endif
If cur_file >= total Then Return 0
If loading Then cur_file +=1
'Print "curfile "+cur_file
'imagebuffer[cur_file] = New TImageBuffer(Self)
''make sure the paths are correct --do this within tpixmap drivers
'Local new_file$ = FixDataPath()
'If Not new_file.StartsWith("monkey://") Then new_file = "monkey://data/"+new_file
'(New AsyncDataLoader(new_file, imagebuffer[cur_file])).Start()
manager.PreLoadData(file[cur_file-1], cur_file )
Return 0
End
Method GetPixmapPreLoad:Void(p:TPixmap, file$)
Local id:Int = GetID(file)
manager.SetPixmapFromID(p, id, file)
End
Method GetID:Int(file$)
If loaded = 0
Return 0
Else
For Local i:Int=0 To total-1
If file = old_file[i] Then Return (i+1)
Next
Endif
Return 0
End
End