Strict Import "driver.bmx" Import BRL.Data Type TImage Extends TData Field width,height,flags Field mask_r,mask_g,mask_b Field handle_x#,handle_y# Field pixmaps:TPixmap[] Field frames:TImageFrame[] Field seqs[] Method DataType:TImageDataType() Return ImageDataType End Method Method Frame:TImageFrame( index ) If seqs[index]=GraphicsSeq Return frames[index] frames[index]=_max2dDriver.CreateFrameFromPixmap( Lock(index,True,False),flags ) If frames[index] seqs[index]=GraphicsSeq Else seqs[index]=0 Return frames[index] End Method Method Lock:TPixmap( index,read,write ) If write seqs[index]=0 frames[index]=Null EndIf If Not pixmaps[index] pixmaps[index]=CreatePixmap( width,height,PF_RGBA8888 ) EndIf Return pixmaps[index] End Method Method SetPixmap( index,pixmap:TPixmap ) If (flags & MASKEDIMAGE) And AlphaBitsPerPixel[pixmap.format]=0 pixmap=MaskPixmap( pixmap,mask_r,mask_g,mask_b ) EndIf pixmaps[index]=pixmap seqs[index]=0 frames[index]=Null End Method Function Create:TImage( width,height,frames,flags,mr,mg,mb ) Local t:TImage=New TImage t.width=width t.height=height t.flags=flags t.mask_r=mr t.mask_g=mg t.mask_b=mb t.pixmaps=New TPixmap[frames] t.frames=New TImageFrame[frames] t.seqs=New Int[frames] Return t End Function Function Load:TImage( url:Object,flags,mr,mg,mb ) Local pixmap:TPixmap=TPixmap(url) If Not pixmap pixmap=LoadPixmap(url) If Not pixmap Return Local t:TImage=Create( pixmap.width,pixmap.height,1,flags,mr,mg,mb ) t.SetPixmap 0,pixmap Return t End Function Function LoadAnim:TImage( url:Object,cell_width,cell_height,first,count,flags,mr,mg,mb ) Local pixmap:TPixmap=TPixmap(url) If Not pixmap pixmap=LoadPixmap(url) If Not pixmap Return Local x_cells=pixmap.width/cell_width Local y_cells=pixmap.height/cell_height If first+count>x_cells*y_cells Return Local t:TImage=Create( cell_width,cell_height,count,flags,mr,mg,mb ) For Local cell=first To first+count-1 Local x=cell Mod x_cells * cell_width Local y=cell / x_cells * cell_height Local window:TPixmap=pixmap.Window( x,y,cell_width,cell_height ) t.SetPixmap cell-first,window.Copy() Next Return t End Function End Type Type TImageDataType Extends TDataType Method Tag$() Return "brl.max2d.TImage" End Method Method ReadObject:Object( stream:TStream ) Local image:TImage=New TImage image.width=stream.ReadInt() image.height=stream.ReadInt() image.flags=stream.ReadInt() image.mask_r=stream.ReadInt() image.mask_g=stream.ReadInt() image.mask_b=stream.ReadInt() image.handle_x=stream.ReadFloat() image.handle_y=stream.ReadFloat() Local count=stream.ReadInt() image.pixmaps=New TPixmap[count] For Local i=0 Until count image.pixmaps[i]=TPixmap( stream.ReadObject() ) Next image.frames=New TImageFrame[count] image.seqs=New Int[count] End Method Method WriteObject( o:Object,stream:TStream ) Local image:TImage=TImage(o) stream.WriteInt image.width stream.WriteInt image.height stream.WriteInt image.flags stream.WriteInt image.mask_r stream.WriteInt image.mask_g stream.WriteInt image.mask_b stream.WriteFloat image.handle_x stream.WriteFloat image.handle_y stream.WriteInt image.pixmaps.length For Local pixmap:TPixmap=EachIn image.pixmaps stream.WriteObject pixmap Next End Method End Type Global ImageDataType:TImageDataType=New TImageDataType |