#============================================================================== # ■ 文字列キャッシュ Ver.1.0.1 by Claimh #------------------------------------------------------------------------------ # ・文字をキャッシュ化することでdraw_textによる動作が重くなることを防ぎます。 # ・縁文字にも対応済み # draw_edging_textメソッドを導入しておく必要があります。 #------------------------------------------------------------------------------ # ◇メソッド仕様説明 #------------------------------------------------------------------------------ # draw_cache_textdraw_cache_text(x, y, width, height, text, align = 0) # [説明] 通常のテキスト表示をします。(draw_textと同等) # [引数] # x : X座標表示開始位置 # y : Y座標表示開始位置 # width : 文字列表示幅 # height : 文字列表示高さ # text : 表示文字列 # align : 文字揃え位置(0:左揃え 1:中央揃え 2:右揃え) # ※alignは省略可能(省略時は左揃え) #------------------------------------------------------------------------------ # draw_edging_cache_text(x, y, width, height, text, align = 0) # [説明] 縁文字でテキスト表示をします。(draw_edging_textと同等) # [引数] # x : X座標表示開始位置 # y : Y座標表示開始位置 # width : 文字列表示幅 # height : 文字列表示高さ # text : 表示文字列 # align : 文字揃え位置(0:左揃え 1:中央揃え 2:右揃え) # ※alignは省略可能(省略時は左揃え) #============================================================================== #============================================================================== # ■ RPG::Cache #============================================================================== module RPG module Cache #-------------------------------------------------------------------------- # ● 文字Bitmapキャッシュ #-------------------------------------------------------------------------- def self.draw_text( width, height, text, font = Font.default_name, size = Font.default_size, bold = Font.default_bold, italic = Font.default_italic, color = Font.default_color, edging = false ) # 文字情報からキャッシュIndexを生成 cache_index = "text_" + width.to_s + height.to_s + text # フォントは複数指定可能なのでそれら全てを保持 # ※各フォントの適用可否は判定しない font_text = "" for i in 0...font.size font_text += font[i].to_s end cache_index += font_text + size.to_s + bold.to_s + italic.to_s cache_index += color.red.to_s + color.blue.to_s + color.green.to_s + color.alpha.to_s # キャッシュ上にBitmapがない場合はBitmapを生成し、キャッシュに入れる if @cache[cache_index].nil? or @cache[cache_index].disposed? bitmap = Bitmap.new(width, height) bitmap.font.name = font bitmap.font.size = size bitmap.font.bold = bold bitmap.font.italic = italic bitmap.font.color = color # 縁文字の場合 if edging # 縁文字描画 bitmap.draw_edging_text(0, 0, width, height, text, 0) else bitmap.draw_text(0, 0, width, height, text, 0) end @cache[cache_index] = bitmap end return @cache[cache_index] end end end #============================================================================== # ■ Bitmap 拡張ライブラリ #============================================================================== class Bitmap #---------------------------------------------------------------------------- # ● キャッシュから文字列bitmapをブロック転送 #---------------------------------------------------------------------------- def blt_cache(x, y, width, height, text, align, edging) cache_bitmap = RPG::Cache.draw_text( width, height, text, self.font.name, self.font.size, self.font.bold, self.font.italic, self.font.color, edging ) # alignによる表示位置計算 x_plus = uncache_align_exe(width, text, align) # Bitmapのブロック転送 blt(x + x_plus , y , cache_bitmap, Rect.new(0, 0, width, height)) end #---------------------------------------------------------------------------- # ● 文字表示開始位置の決定(キャッシュする必要のないalignへの対応) # 0:左揃え 1:中央揃え 2:右揃え #---------------------------------------------------------------------------- def uncache_align_exe(width, text, align) recter = self.text_size(text) case align when 0 # 左揃え x_index = 0 when 1 # 中央揃え x_index = (width / 2) - recter.width / 2 when 2 # 右揃え x_index = width - recter.width else p "Bitmap.align_exe : align指定ミス" exit end return x_index end #---------------------------------------------------------------------------- # ● テキスト表示(キャッシュ機構対応) #---------------------------------------------------------------------------- def draw_cache_text(x, y, width, height, text, align = 0) blt_cache(x, y, width, height, text, align, false) end #---------------------------------------------------------------------------- # ● 縁文字テキスト表示(キャッシュ機構対応) #---------------------------------------------------------------------------- def draw_edging_cache_text(x, y, width, height, text, align = 0) blt_cache(x, y, width, height, text, align, true) end #---------------------------------------------------------------------------- # ● テキスト表示(キャッシュ機構対応:簡易版) #---------------------------------------------------------------------------- def draw_eazy_cache_text(x, y, text) t_rect = text_size(text) blt_cache(x, y, t_rect.width, t_rect.height, text, 0, false) end #---------------------------------------------------------------------------- # ● 縁文字テキスト表示(キャッシュ機構対応:簡易版) #---------------------------------------------------------------------------- def draw_eazy_edging_cache_text(x, y, text) t_rect = text_size(text) blt_cache(x, y, t_rect.width, t_rect.height, text, 0, true) end end