Code: |
#=== #Classe Yuki::Bar #Objet permettant de créer des barres simples depuis un bitmap d'origine #--- #Crée Par Nagato Yuki (Nuri Yuri) #Projet intialisé le 29/01/2012 à 11:12:38 suite au sujet : #http://www.rpg-maker.fr/index.php?page=forum&id=19856 #Première release le 29/01/2012 à 12:37:33 #Dernière modification le 10/02/2012 #=== module Yuki class Bar #=== #Initialisation #bmp : Bitmap contenant la barre et le contenu #bh : Hauteur de la barre en pixels #uw : Longueur du contenu se trouvant sous la barre dans le bitmap #cx : Position x du contenu dans la barre #cy : Position y du contenu dans la barre #cw : Longueur du contenur dans la barre #viewport : Viewport utilisé dans le sprite, ne peut être mis en réinitialisation #ty : false => barre collé avec une copie d'un pixel du contenur # true => barre collé avec le contenu coupé jusqu'à l'avancement #=== def initialize(bmp,bh,uw,cx,cy,cw,ty=false,viewport=nil) raise("Erreur, le bitmap fourni n'est pas de la bonne classe.") if bmp.class != Bitmap @sp_bar=Sprite.new(viewport) unless @sp_bar @sp_bar.bitmap=bmp @sp_cnt=Sprite.new(viewport) unless @sp_cnt @sp_bar.src_rect.height= @bh=bh.to_i #Bar Height @uw=uw.to_i #Cnu Width @cx=cx.to_i #Cnt x @cy=cy.to_i #Cnt y @cw=cw.to_i #Cnt Width @av=0 #Avancement @am=1 #Avancement Max @ty=ty #Type @sp_cnt.bitmap.dispose if @sp_cnt.bitmap @sp_cnt.bitmap=Bitmap.new(@cw,@sp_bar.bitmap.height-@bh) @src_rect ? @src_rect.set(0,@bh,1,@sp_cnt.bitmap.height) : @src_rect=Rect.new(0,@bh,1,@sp_cnt.bitmap.height) @dest_rect ? @dest_rect.set(0,0,1,@sp_cnt.bitmap.height) : @dest_rect=Rect.new(0,0,1,@sp_cnt.bitmap.height) self.oy=self.ox=0;self.zoom_x=self.zoom_y=1;self.angle=0; @disposed=false refresh() end def refresh() return if @disposed av_prc=@av.to_f/@am if @ty @src_rect.width=(av_prc*@uw).to_i else @src_rect.x=(av_prc*@uw).to_i @src_rect.x=@uw-1 if @src_rect.x>=@uw end @dest_rect.width=(av_prc*@cw).to_i @sp_cnt.bitmap.clear @sp_cnt.bitmap.stretch_blt(@dest_rect,@sp_bar.bitmap,@src_rect) end def x() return @sp_bar.x end def y() return @sp_bar.y end def z() return @sp_bar.z end def ox() return @sp_bar.ox end def oy() return @sp_bar.oy end def angle() return @sp_bar.angle end def zoom_x() return @sp_bar.zoom_x end def zoom_y() return @sp_bar.zoom_y end def disposed?() return @disposed end def mirror() return @sp_cnt.mirror end def opacity() return @sp_bar.opacity end def color() return @sp_bar.color end def tone() return @sp_bar.tone end def visible() return @sp_bar.visible end def viewport() return @sp_bar.viewport end def pos() return @av end def max_pos() return @am end def x=(v) @sp_cnt.x=@sp_bar.x=v end def y=(v) @sp_cnt.y=@sp_bar.y=v end def z=(v) @sp_bar.z=v @sp_cnt.z=v+1 end def ox=(v) @sp_bar.ox=v @sp_cnt.ox=v-@cx end def oy=(v) @sp_bar.oy=v @sp_cnt.oy=v-@cy end def angle=(v) @sp_bar.angle=@sp_cnt.angle=v end def zoom_x=(v) @sp_bar.zoom_x=@sp_cnt.zoom_x=v end def zoom_y=(v) @sp_bar.zoom_y=@sp_cnt.zoom_y=v end def mirror=(v) @sp_cnt.mirror=v end #Fait lemirror que pour le contenu. def opacity=(v) @sp_bar.opacity=@sp_cnt.opacity=v end def color=(v) @sp_bar.color=@sp_cnt.color=v end def tone=(v) @sp_bar.tone=@sp_cnt.tone=v end def visible=(v) @sp_bar.visible=@sp_cnt.visible=v end def pos=(v) @av=v.abs.to_i end #Position de dans l'avacement ex 50 pour 50/255 def max_pos=(v) @am=v.abs.to_i if v!=0 end #Position maximale pour l'avancement ex 255 pour 50/255 #=== #Réinitialisation #Permet de réutiliser la barre avec un bitmap différent. #=== def reinitialize(bmp,bh,uw,cx,cy,cw,ty=false) initialize(bmp,bh,uw,cx,cy,cw,ty) end def dispose() @disposed=true @sp_bar.dispose @sp_bar=nil @sp_cnt.bitmap.dispose @sp_cnt.dispose @sp_cnt=nil end end end |
Code: |
#=begin #Zone de test. Graphics.transition(1) $bar=Yuki::Bar.new(Bitmap.new("0.png"),6,12,12,1,39,false) $bar.x=200 $bar.y=200 $bar.zoom_x=4 $bar.zoom_y=4 $bar.z=1024 $bar.max_pos=100 101.times do |i| $bar.pos=i $bar.refresh() Graphics.update end Graphics.wait(100) $bar.mirror=true $bar.reinitialize(Bitmap.new("2.png"),6,39,12,1,39,true) $bar.max_pos=100 101.times do |i| $bar.pos=i $bar.refresh() Graphics.update end #$bar.pos=0 $bar.refresh #$bar.visible=false Graphics.wait(100) $bar.dispose #=end |