赞 | 68 |
VIP | 0 |
好人卡 | 0 |
积分 | 65 |
经验 | 0 |
最后登录 | 2023-7-2 |
在线时间 | 119 小时 |
Lv4.逐梦者
- 梦石
- 0
- 星屑
- 6483
- 在线时间
- 119 小时
- 注册时间
- 2020-1-8
- 帖子
- 234
|
加入我们,或者,欢迎回来。
您需要 登录 才可以下载或查看,没有帐号?注册会员
x
本帖最后由 RPGzh500223 于 2022-3-17 15:17 编辑
边学边练
<<-DOC 函数原型: int bitmapDrawScanH(int bitmap_obj_id, int color0_obj_id, int color1_obj_id) 函数作用: 以color0,color1进行HSL渐变,水平填充至bitmap的最后一行, 作为颜色源数据给相关需求调用。 使用示例: proc = Win32API.new('color.dll', 'bitmapDrawScanH', 'LLL', 'L') src_bitmap = Bitmap.new(180, 1) color0 = Color.new(255, 0, 0, 128) color1 = Color.new(0, 255, 0, 255) proc.call(src_bitmap.object_id, color0.object_id, color1.object_id) #src_bitmap.dispose 应用示例:见Bitmap#fill_ellipse3 函数原型: int bitmapFillTextH(int bitmap_obj_id, int color0_obj_id, int color1_obj_id) 函数作用: 初始化的bitmap,绘制文字后, 以color0,color1的HSL渐变,水平填充至绘制的字体。 使用示例: proc = Win32API.new('color.dll', 'bitmapFillTextH', 'LLL', 'L') src_bitmap = Bitmap.new(180, 32) src_bitmap.draw_text(0, 0, 180, 32, "文字测试") color0 = Color.new(255, 0, 0, 128) color1 = Color.new(0, 255, 0, 255) proc.call(src_bitmap.object_id, color0.object_id, color1.object_id) #src_bitmap.dispose 应用示例:见Bitmap#draw_text_ex 示意图: bitmap = Bitmap.new(640, 480) color0 = Color.new(255, 0, 0, 128) color1 = Color.new(0, 0, 255) bitmap.fill_ellipse3(320, 240, 300, 200, 0, Color.new(0,0,0), color0, color1) bitmap.draw_text_ex(200, 200, "文字测试", color0, color1) DOC class Bitmap DrawScanH = Win32API.new('color.dll', 'bitmapDrawScanH', 'LLL', 'L') FillTextH = Win32API.new('color.dll', 'bitmapFillTextH', 'LLL', 'L') #-------------------------------------------------------------------- # cx 椭圆中心点X 基本整型 # cy 椭圆中心点Y 基本整型 # ax 椭圆X半轴长度 无符号整型 # by 椭圆Y半轴长度 无符号整型 # mode 椭圆颜色填充方向(0:左->右;1:上->下) 无符号整型 # color 椭圆边框颜色 RMXP的Color实例对象 # fillB 椭圆填充的起始颜色 RMXP的Color实例对象 # fillE 椭圆填充的终止颜色 RMXP的Color实例对象 或 nil(单色填充) #-------------------------------------------------------------------- def fill_ellipse3(cx, cy, ax, by, mode, color, fillB, fillE=nil) if fillE if mode == 0 step = ax + ax + 1 src_rect = Rect.new(0, 0, 0, 0) else step = by + by + 1 end src = Bitmap.new(step, 1) DrawScanH.call(src.object_id, fillB.object_id, fillE.object_id) else mode = 1 if mode = 0 end ratio, w2 = ax.to_f / by, 0 (by).downto(1) do |y| w = (Math.sqrt((by + y) * (by - y)) * ratio).round if fillE if mode == 1 self.fill_rect(cx - w, cy - y, w + w, 1, src.get_pixel(by - y, 0)) self.fill_rect(cx - w, cy + y, w + w, 1, src.get_pixel(by + y, 0)) else src_rect.set(ax - w, 0, w + w, 1) self.blt(cx - w, cy - y, src, src_rect) self.blt(cx - w, cy + y, src, src_rect) end else self.fill_rect(cx - w, cy - y, w + w, 1, fillB) self.fill_rect(cx - w, cy + y, w + w, 1, fillB) end self.set_pixel(cx - w, cy - y, color) self.set_pixel(cx + w, cy - y, color) self.set_pixel(cx - w, cy + y, color) self.set_pixel(cx + w, cy + y, color) while w2 < w self.set_pixel(cx - w2, cy - y - 1, color) self.set_pixel(cx + w2, cy - y - 1, color) self.set_pixel(cx - w2, cy + y + 1, color) self.set_pixel(cx + w2, cy + y + 1, color) w2 += 1 end end if fillE if mode == 1 self.fill_rect(cx - ax, cy, ax + ax + 1, 1, src.get_pixel(by, 0)) else self.blt(cx - ax, cy, src, src.rect) end else self.fill_rect(cx - ax, cy, ax + ax + 1, 1, fillB) end self.set_pixel(cx - ax, cy, color) self.set_pixel(cx + ax, cy, color) src.dispose if src end def draw_text_ex(x, y, text, color0, color1) rect = self.text_size(text) temp = Bitmap.new(rect.width, rect.height) temp.draw_text(rect, text) FillTextH.call(temp.object_id, color0.object_id, color1.object_id) self.blt(x, y, temp, rect) temp.dispose end end
<<-DOC
函数原型:
int bitmapDrawScanH(int bitmap_obj_id, int color0_obj_id, int color1_obj_id)
函数作用:
以color0,color1进行HSL渐变,水平填充至bitmap的最后一行,
作为颜色源数据给相关需求调用。
使用示例:
proc = Win32API.new('color.dll', 'bitmapDrawScanH', 'LLL', 'L')
src_bitmap = Bitmap.new(180, 1)
color0 = Color.new(255, 0, 0, 128)
color1 = Color.new(0, 255, 0, 255)
proc.call(src_bitmap.object_id, color0.object_id, color1.object_id)
#src_bitmap.dispose
应用示例:见Bitmap#fill_ellipse3
函数原型:
int bitmapFillTextH(int bitmap_obj_id, int color0_obj_id, int color1_obj_id)
函数作用:
初始化的bitmap,绘制文字后,
以color0,color1的HSL渐变,水平填充至绘制的字体。
使用示例:
proc = Win32API.new('color.dll', 'bitmapFillTextH', 'LLL', 'L')
src_bitmap = Bitmap.new(180, 32)
src_bitmap.draw_text(0, 0, 180, 32, "文字测试")
color0 = Color.new(255, 0, 0, 128)
color1 = Color.new(0, 255, 0, 255)
proc.call(src_bitmap.object_id, color0.object_id, color1.object_id)
#src_bitmap.dispose
应用示例:见Bitmap#draw_text_ex
示意图:
bitmap = Bitmap.new(640, 480)
color0 = Color.new(255, 0, 0, 128)
color1 = Color.new(0, 0, 255)
bitmap.fill_ellipse3(320, 240, 300, 200, 0, Color.new(0,0,0), color0, color1)
bitmap.draw_text_ex(200, 200, "文字测试", color0, color1)
DOC
class Bitmap
DrawScanH = Win32API.new('color.dll', 'bitmapDrawScanH', 'LLL', 'L')
FillTextH = Win32API.new('color.dll', 'bitmapFillTextH', 'LLL', 'L')
#--------------------------------------------------------------------
# cx 椭圆中心点X 基本整型
# cy 椭圆中心点Y 基本整型
# ax 椭圆X半轴长度 无符号整型
# by 椭圆Y半轴长度 无符号整型
# mode 椭圆颜色填充方向(0:左->右;1:上->下) 无符号整型
# color 椭圆边框颜色 RMXP的Color实例对象
# fillB 椭圆填充的起始颜色 RMXP的Color实例对象
# fillE 椭圆填充的终止颜色 RMXP的Color实例对象 或 nil(单色填充)
#--------------------------------------------------------------------
def fill_ellipse3(cx, cy, ax, by, mode, color, fillB, fillE=nil)
if fillE
if mode == 0
step = ax + ax + 1
src_rect = Rect.new(0, 0, 0, 0)
else
step = by + by + 1
end
src = Bitmap.new(step, 1)
DrawScanH.call(src.object_id, fillB.object_id, fillE.object_id)
else
mode = 1 if mode = 0
end
ratio, w2 = ax.to_f / by, 0
(by).downto(1) do |y|
w = (Math.sqrt((by + y) * (by - y)) * ratio).round
if fillE
if mode == 1
self.fill_rect(cx - w, cy - y, w + w, 1, src.get_pixel(by - y, 0))
self.fill_rect(cx - w, cy + y, w + w, 1, src.get_pixel(by + y, 0))
else
src_rect.set(ax - w, 0, w + w, 1)
self.blt(cx - w, cy - y, src, src_rect)
self.blt(cx - w, cy + y, src, src_rect)
end
else
self.fill_rect(cx - w, cy - y, w + w, 1, fillB)
self.fill_rect(cx - w, cy + y, w + w, 1, fillB)
end
self.set_pixel(cx - w, cy - y, color)
self.set_pixel(cx + w, cy - y, color)
self.set_pixel(cx - w, cy + y, color)
self.set_pixel(cx + w, cy + y, color)
while w2 < w
self.set_pixel(cx - w2, cy - y - 1, color)
self.set_pixel(cx + w2, cy - y - 1, color)
self.set_pixel(cx - w2, cy + y + 1, color)
self.set_pixel(cx + w2, cy + y + 1, color)
w2 += 1
end
end
if fillE
if mode == 1
self.fill_rect(cx - ax, cy, ax + ax + 1, 1, src.get_pixel(by, 0))
else
self.blt(cx - ax, cy, src, src.rect)
end
else
self.fill_rect(cx - ax, cy, ax + ax + 1, 1, fillB)
end
self.set_pixel(cx - ax, cy, color)
self.set_pixel(cx + ax, cy, color)
src.dispose if src
end
def draw_text_ex(x, y, text, color0, color1)
rect = self.text_size(text)
temp = Bitmap.new(rect.width, rect.height)
temp.draw_text(rect, text)
FillTextH.call(temp.object_id, color0.object_id, color1.object_id)
self.blt(x, y, temp, rect)
temp.dispose
end
end
|
评分
-
查看全部评分
|