#_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_ #_/ ◆ Draw Shadowed and Framed Text - KGC_FrameShadowText ◆ #_/ ◇ Last Update: 2008/05/01 #_/ ◆ Written by TOMY #_/ ◆ Translation by Mr. Anonymous #_/ ◆ KGC Site: #_/ ◆ http://ytomy.sakura.ne.jp/ #_/ ◆ Translator's Blog: #_/ ◆ http://mraprojects.wordpress.com #_/----------------------------------------------------------------------------- #_/ Installation: Insert this script above main. #_/============================================================================= #_/ Provides methods for scripts to draw text with framed or dropped shadow. #_/ On its own, it does nothing. This is primarily a "scripter's tool". #_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_ =begin ----------------------------------- Methods ------------------------------------ /------------------------------- Class - Bitmap -------------------------------- | draw_frame_text(x, y, width, height, string[, align, frame_color]) | draw_frame_text(rect, string[, align, frame_color]) | | x, y : Drawing destination coordinates. [Integer] | width, height : Drawing size. [Integer] | rect : Drawing area. [Rect] | string : Drawn text output. [String] | align : Alightment. [Integer] | frame_color : Frame color. [Color] | | Draws a character string framed in 'frame_color'. | | draw_shadow_text(x, y, width, height, string[, align, frame_color]) | draw_shadow_text(rect, string[, align, frame_color]) | | x, y : Drawing destination coordinates. [Integer] | width, height : Drawing size. [Integer] | rect : Drawing area. [Rect] | string : Drawn text output. [String] | align : Alightment. [Integer] | frame_color : Frame color. [Color] | | Draws a character string which drops shadow to lower right. \______________________________________________________________________________ =end $imported = {} if $imported == nil $imported["FrameShadowText"] = true #============================================================================== # ■ Bitmap #============================================================================== class Bitmap #-------------------------------------------------------------------------- # ● Draw Framed Text # x, y, width, height, string[, align, frame_color] # rect, string[, align, frame_color] #-------------------------------------------------------------------------- def draw_frame_text(*args) # 引数判定 if args[0].is_a?(Rect) if args.size >= 2 && args.size <= 4 # 引数を処理用のローカル変数へコピー x, y = args[0].x, args[0].y width, height = args[0].width, args[0].height string = args[1] align = args[2].equal?(nil) ? 0 : args[2] frame_color = args[3].equal?(nil) ? Color.new(0, 0, 0) : args[3] else # 引数が不正ならエラーを吐く raise(ArgumentError, "Wrong number of arguments(#{args.size} of #{args.size < 2 ? 2 : 4})") return end else if args.size >= 5 && args.size <= 7 # 引数を処理用のローカル変数へコピー x, y, width, height = args string = args[4] align = args[5].equal?(nil) ? 0 : args[5] frame_color = args[6].equal?(nil) ? Color.new(0, 0, 0) : args[6] else # 引数が不正ならエラーを吐く raise(ArgumentError, "Wrong number of arguments(#{args.size} of #{args.size < 5 ? 5 : 7})") return end end # 元の色を保存 origin_color = font.color.dup # 縁取り font.color = frame_color draw_text(x - 1, y - 1, width, height, string, align) draw_text(x - 1, y + 1, width, height, string, align) draw_text(x + 1, y - 1, width, height, string, align) draw_text(x + 1, y + 1, width, height, string, align) # 元の色に戻す font.color = origin_color draw_text(x, y, width, height, string, align) end #-------------------------------------------------------------------------- # ● Draw Shadowed Text # x, y, width, height, string[, align, shadow_color] # rect, string[, align, shadow_color] #-------------------------------------------------------------------------- def draw_shadow_text(*args) # 引数判定 if args[0].is_a?(Rect) if args.size >= 2 && args.size <= 4 # 引数を処理用のローカル変数へコピー x, y = args[0].x, args[0].y width, height = args[0].width, args[0].height string = args[1] align = args[2].equal?(nil) ? 0 : args[2] shadow_color = args[3].equal?(nil) ? Color.new(0, 0, 0) : args[3] else # 引数が不正ならエラーを吐く raise(ArgumentError, "wrong number of arguments(#{args.size} of #{args.size < 2 ? 2 : 4})") return end else if args.size >= 5 && args.size <= 7 # 引数を処理用のローカル変数へコピー x, y, width, height = args string = args[4] align = args[5].equal?(nil) ? 0 : args[5] shadow_color = args[6].equal?(nil) ? Color.new(0, 0, 0) : args[6] else # 引数が不正ならエラーを吐く raise(ArgumentError, "wrong number of arguments(#{args.size} of #{args.size < 5 ? 5 : 7})") return end end # 元の色を保存 origin_color = font.color.dup # 影描画 font.color = shadow_color draw_text(x + 2, y + 2, width, height, string, align) # 元の色に戻す font.color = origin_color draw_text(x, y, width, height, string, align) end end