#encoding:utf-8
#==============================================================================
# ■ Bitmap 不常用扩展 By_QQEat
#------------------------------------------------------------------------------
#
# 说明:不定时更新 Bitmap 中一些不常用的功能..
# 更新:2019.11.13
#
# 方法:
# # src为背景图, 其余两个参数传Range类型, 表示可缩放区域
# draw9pitch(src, x_range, y_range)
#
#==============================================================================
class Bitmap
#--------------------------------------------------------------------------
# ● draw9pitch
#--------------------------------------------------------------------------
def draw9pitch(src, x_range, y_range)
xf, xl = x_range.first, x_range.last
yf, yl = y_range.first, y_range.last
xe, ye = src.width-xl, src.height-yl
blt(0,0, src, Rect.new(0, 0, xf, yf)) # 左上
blt(width-xe,0, src, Rect.new(xl, 0, xe, yf)) # 右上
blt(0,height-ye, src, Rect.new(0, yl, xf, ye)) # 左下
blt(width-xe,height-ye, src, Rect.new(xl, yl, xe, ye)) # 右下
# 上水平中间
yf.times do |i|
stretch_blt(Rect.new(xf, i, width-xf-xe, 1), src, Rect.new(xf, i, xl-xf, 1))
end
# 下水平中间
(ye+1).times do |i|
stretch_blt(Rect.new(xf, height-i, width-xf-xe, 1), src, Rect.new(xf, src.height-i, xl-xf, 1))
end
# 左垂直中间
xf.times do |i|
stretch_blt(Rect.new(i, yf, 1, height-yf-ye), src, Rect.new(i, yf, 1, yl-yf))
end
# 右垂直中间
(xe+1).times do |i|
stretch_blt(Rect.new(width-i, yf, 1, height-yf-ye), src, Rect.new(src.width-i, yf, 1, yl-yf))
end
# 中心
stretch_blt(Rect.new(xf, yf, width-xf-xe, height-yf-ye), src, Rect.new(xf, yf, 1, 1))
end
end