#============================================================================== # ■ Bitmap 追加定義 #------------------------------------------------------------------------------ # 製作:春日屋/春日 # URL :http://www.katch.ne.jp/kasugaya/ # Ver :1.00 # 更新:2007/07/06 # #  Bitmapクラスに数字キャッシュ機能を追加します。 #============================================================================== class Bitmap #-------------------------------------------------------------------------- # ● クラス変数定義 #-------------------------------------------------------------------------- @@num_cache = Array.new #-------------------------------------------------------------------------- # ● 数字キャッシュ初期化 #-------------------------------------------------------------------------- def Bitmap.init_num(id, stat=nil) b = Bitmap.new(1, 1) f = stat.instance_of?(String) a = Bitmap.new("Graphics/Pictures/" + stat) if f @@num_cache[id] = Array.new if @@num_cache[id] == nil # 生成ループ for n in 0..11 # 既にキャッシュが存在するなら解放 @@num_cache[id][n].dispose if @@num_cache[id][n] != nil if f # ファイルから w = a.rect.width / 12 h = a.rect.height @@num_cache[id][n] = Bitmap.new(w, h) @@num_cache[id][n].blt(0, 0, a, Rect.new(n*w, 0, w, h)) else # メソッドから case n when 10 s = "." when 11 s = "-" else s = n.to_s end r = b.text_size(s) w = stat != nil ? stat : r.width @@num_cache[id][n] = Bitmap.new(w, r.height) @@num_cache[id][n].draw_text(0, 0, w, r.height, s) end end end #-------------------------------------------------------------------------- # ● キャッシュ解放 #-------------------------------------------------------------------------- def Bitmap.dispose_num(id) if @@num_cache[id] != nil @@num_cache[i].each{|ary| ary.dispose } @@num_cache[id] = nil return true end return false end #-------------------------------------------------------------------------- # ● 全キャッシュ解放 #-------------------------------------------------------------------------- def Bitmap.dispose_num_all @@num_cache.each_index{|i| if @@num_cache[i] != nil @@num_cache[i].each{|ary| ary.dispose } @@num_cache[i] = nil end } end #-------------------------------------------------------------------------- # ● 数字キャッシュから描画 #-------------------------------------------------------------------------- def draw_cache_num(id, x, y, num) num = num.to_s num = num.scan(/./) for s in num case s when '.' n = 10 when '-' n = 11 else n = s.to_i end r = @@num_cache[id][n].rect self.blt(x, y, @@num_cache[id][n], r) x += r.width end end end