注册会员 登录
Project1 返回首页

QQEat https://rpg.blue/?326184 [收藏] [复制] [分享] [RSS] 这个人很懒,什么也没留下。

日志

【RM】Bitmap_不常用方法扩展

已有 314 次阅读2019-11-13 20:29

#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

鸡蛋

鲜花

评论 (0 个评论)

facelist doodle 涂鸦笔

您需要登录后才可以评论 登录 | 注册会员

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-3-29 19:40

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

返回顶部