@@ -53,6 +53,7 @@ namespace ImageList {
53
53
{ type : 'spinner' , name : 'spnPalette' , x : 68 , y : 72 , width : 100 , height : 14 , text : '0' , onDecrement : ( ) => onDecrementPalette ( ) , onIncrement : ( ) => onIncrementPalette ( ) } ,
54
54
{ type : 'label' , x : 16 , y : 92 , width : 50 , height : 14 , text : 'Start ID:' } ,
55
55
{ type : 'spinner' , name : 'spnStartId' , x : 68 , y : 90 , width : 100 , height : 14 , text : startId . toString ( ) , onClick : ( ) => onSelectId ( ) , onDecrement : ( ) => onDecrementId ( ) , onIncrement : ( ) => onIncrementId ( ) } ,
56
+ { type : 'custom' , name : 'imageChart' , x : 300 , y : 20 , width : 1200 , height : 96 , onDraw : function ( g ) { onDrawChart ( this , g ) ; } } ,
56
57
{ type : 'custom' , name : 'imageList' , x : 8 , y : 122 , width : 200 , height : 100 , onDraw : function ( g ) { onDrawImages ( this , g ) ; } }
57
58
] ,
58
59
onUpdate : ( ) => onUpdate ( )
@@ -123,6 +124,11 @@ namespace ImageList {
123
124
}
124
125
125
126
function onUpdate ( ) {
127
+ const imageChart = window . findWidget < CustomWidget > ( 'imageChart' ) ;
128
+ if ( imageChart ) {
129
+ imageChart . width = window . width - imageChart . x - 8 ;
130
+ }
131
+
126
132
const imageList = window . findWidget < CustomWidget > ( 'imageList' ) ;
127
133
if ( imageList ) {
128
134
imageList . width = window . width - ( imageList . x * 2 ) ;
@@ -157,6 +163,73 @@ namespace ImageList {
157
163
}
158
164
}
159
165
166
+ function onDrawChart ( widget : CustomWidget , g : GraphicsContext ) {
167
+ const clipWidth = widget . width - 2 ;
168
+ const clipHeight = widget . height - 2 ;
169
+
170
+ g . colour = 1 ;
171
+ g . well ( 0 , 0 , widget . width , widget . height ) ;
172
+ g . clip ( 1 , 1 , clipWidth , clipHeight ) ;
173
+
174
+ g . fill = 61 ;
175
+ g . clear ( ) ;
176
+
177
+ const allocatedRange = ui . imageManager . getPredefinedRange ( 'allocated' ) ;
178
+ if ( ! allocatedRange )
179
+ return ;
180
+
181
+ const end = allocatedRange . start + allocatedRange . count ;
182
+ const indexToX = ( index : number ) => Math . floor ( ( index / end ) * clipWidth ) ;
183
+
184
+ const rangeNames = [ 'g1' , 'g2' , 'csg' ] ;
185
+ const colours = [ 60 , 90 , 120 ] ;
186
+ const ranges = rangeNames . map ( x => ui . imageManager . getPredefinedRange ( x ) ) ;
187
+
188
+ // Range colours
189
+ for ( let i = 0 ; i < rangeNames . length ; i ++ ) {
190
+ const range = ranges [ i ] ;
191
+ if ( ! range )
192
+ continue ;
193
+
194
+ const x = indexToX ( range . start ) ;
195
+ const width = indexToX ( range . count ) ;
196
+
197
+ g . fill = colours [ i ] ;
198
+ g . rect ( x , 0 , width , clipHeight ) ;
199
+ }
200
+
201
+ // Range names
202
+ for ( let i = 0 ; i < rangeNames . length ; i ++ ) {
203
+ const range = ranges [ i ] ;
204
+ if ( ! range )
205
+ continue ;
206
+
207
+ const x = indexToX ( range . start ) ;
208
+ const width = indexToX ( range . count ) ;
209
+
210
+ const name = rangeNames [ i ] ;
211
+ const textSize = g . measureText ( name ) ;
212
+ g . text ( '{OUTLINE}{WHITE}' + name , x + ( ( width - textSize . width ) / 2 ) , clipHeight / 2 - 5 ) ;
213
+ }
214
+
215
+ // Free ranges
216
+ const freeRanges = ui . imageManager . getAvailableAllocationRanges ( ) ;
217
+ for ( const range of freeRanges ) {
218
+ const x = Math . floor ( ( range . start / end ) * clipWidth ) ;
219
+ const width = Math . floor ( ( range . count / end ) * clipWidth ) ;
220
+
221
+ g . fill = 20 ;
222
+ g . rect ( x , 0 , width , clipHeight ) ;
223
+ }
224
+
225
+ // Viewport
226
+ const viewX = indexToX ( startId ) ;
227
+ const viewSize = 8 ;
228
+ g . fill = 8 ;
229
+ g . stroke = 54 ;
230
+ g . rect ( viewX - ( viewSize / 2 ) , ( clipHeight / 4 ) - ( viewSize / 2 ) , viewSize , viewSize ) ;
231
+ }
232
+
160
233
function onDrawImages ( widget : CustomWidget , g : GraphicsContext ) {
161
234
const margin = 2 ;
162
235
const clipWidth = widget . width - 2 - margin ;
@@ -192,7 +265,12 @@ namespace ImageList {
192
265
lineHeight = Math . max ( lineHeight , output . height ) ;
193
266
}
194
267
id ++ ;
268
+
269
+ // Prevent continuous loop
270
+ if ( id > startId + 1000 )
271
+ break ;
195
272
}
273
+
196
274
nextId = secondLineId || startId + 1 ;
197
275
}
198
276
0 commit comments