赞 | 0 |
VIP | 8 |
好人卡 | 27 |
积分 | 55 |
经验 | 41413 |
最后登录 | 2012-10-21 |
在线时间 | 833 小时 |
Lv4.逐梦者 弓箭手?剑兰
- 梦石
- 0
- 星屑
- 5539
- 在线时间
- 833 小时
- 注册时间
- 2010-11-17
- 帖子
- 1140
|
最初我是常驻VX,于是我放出几个我写的出来:
1. zh,我电脑那个 dll 无效...= =RGE 的 Bitmap 结构特殊,不能用<高速Marshal Bitmap>,所以我改:- #==============================================================================
- # ■ Graphics
- #------------------------------------------------------------------------------
- # 进行有关全体图像处理的模块。
- # RGE 的 Graphics.snap_to_bitmap。(和 XP 版有分别)
- #==============================================================================
- module Graphics
- #--------------------------------------------------------------------------
- # ● API 函数
- #--------------------------------------------------------------------------
- CreateDC = Win32API.new("gdi32", "CreateDC", "pppl", "l")
- CreateCompatibleBitmap = Win32API.new("gdi32", "CreateCompatibleBitmap", "lll", "l")
- CreateCompatibleDC = Win32API.new("gdi32", "CreateCompatibleDC", "l", "l")
- SelectObject = Win32API.new("gdi32", "SelectObject", "ll", "l")
- BitBlt = Win32API.new("gdi32", "BitBlt", "lllllllll", "l")
- GetBitmapBits = Win32API.new("gdi32", "GetBitmapBits", "llp", "l")
- ScreenToClient = Win32API.new("user32", "ScreenToClient", "ip", "i")
- DeleteDC = Win32API.new("gdi32", "DeleteDC", "l", "l")
- DeleteObject = Win32API.new("gdi32", "DeleteObject", "l", "l")
- SRCCOPY = 0xCC0020
- RtlMoveMemory = Win32API.new("kernel32", "RtlMoveMemory", "ipi", "i")
- RtlMoveMemory_pi = Win32API.new("kernel32", "RtlMoveMemory", "pii", "i")
- HWnd = Win32API.new("user32", "GetActiveWindow", nil, 'l').call
- DwCount = (Frame.width * Frame.height * 4)# * 2
- @@lpBits = "\000" * DwCount
- #--------------------------------------------------------------------------
- # ● snap_to_bitmap (RGE版)
- #--------------------------------------------------------------------------
- def self.snap_to_bitmap
- hScrDC = CreateDC.call("DISPLAY", "", "", 0)
- hMemDC = CreateCompatibleDC.call(hScrDC)
- hBitmap = CreateCompatibleBitmap.call(hScrDC, width, height)
- hOldBitmap = SelectObject.call(hMemDC, hBitmap)
- win_pos = "\0\0\0\0\0\0\0\0"
- ScreenToClient.call(HWnd, win_pos)
- win_pos = win_pos.unpack("LL")
- BitBlt.call(hMemDC, win_pos[0], win_pos[1], width*2, height*2, hScrDC, 0, 0, SRCCOPY)
- hBitmap2 = SelectObject.call(hMemDC, hOldBitmap)
- GetBitmapBits.call(hBitmap2, DwCount, @@lpBits)
- # 释放所有东西
- DeleteDC.call(hScrDC)
- DeleteDC.call(hMemDC)
- DeleteObject.call(hBitmap)
- DeleteObject.call(hOldBitmap)
- DeleteObject.call(hBitmap2)
- rgbs = @@lpBits
- len = width * 4
- for y in 0...height
- break if 2 * y >= height - 1
- nth1 = y * len
- nth2 = (height - 1 - y) * len
- tStr = rgbs[nth1,len]
- rgbs[nth1, len] = rgbs[nth2, len]
- rgbs[nth2, len] = tStr
- end
- # 写 bmp 档案
- length = Frame.width * Frame.height
- file = File.open("cache.bmp", "wb")
- size = 54 + Frame.width * Frame.height * 4
- chunk1 = "BM" + [size].pack("L") + "\0\0\0\0\x36\0\0\0"
- chunk2 = "\x28\0\0\0" + [Frame.width, Frame.height].pack("L2") +
- "\1\0\x20\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
- file.write(chunk1 + chunk2 + rgbs)
- file.close
- # 读取以及删掉档案
- bitmap = Bitmap.new("cache.bmp")
- File.delete("cache.bmp")
- return bitmap
- end
- end
复制代码 Font 的阴影还没下手,绘画阴影方面主要交给Bitmap了。Font:- #==============================================================================
- # ■ Font
- #------------------------------------------------------------------------------
- # 兼容 RGE 而修改的 Font
- #==============================================================================
- class Font
- #--------------------------------------------------------------------------
- # ● 类变量
- #--------------------------------------------------------------------------
- @@default_shadow = true
- #--------------------------------------------------------------------------
- # ● 对象初始化
- #--------------------------------------------------------------------------
- alias font_init initialize
- def initialize
- font_init
- @shadow = @@default_shadow
- end
- #--------------------------------------------------------------------------
- # ● default_shadow
- #--------------------------------------------------------------------------
- def self.default_shadow
- return @@default_shadow
- end
- #--------------------------------------------------------------------------
- # ● default_shadow=
- #--------------------------------------------------------------------------
- def self.default_shadow=(bool)
- return if bool != true or bool != false
- @@default_shadow = bool
- end
- #--------------------------------------------------------------------------
- # ● shadow
- #--------------------------------------------------------------------------
- def shadow
- return @shadow
- end
- #--------------------------------------------------------------------------
- # ● shadow=
- #--------------------------------------------------------------------------
- def shadow=(bool)
- return if bool != true or bool != false
- @shadow = bool
- end
- end
复制代码 3.你那个clear_rect没有照顾clear_rect(x, y, width, height) 这种参数形式,还有字体阴影交给Bitmap:- #==============================================================================
- # ■ Bitmap
- #------------------------------------------------------------------------------
- # 兼容 RGE 而修改的 Bitmap
- #==============================================================================
- class Bitmap
- #--------------------------------------------------------------------------
- # ● 填满渐变色彩 (RGSS2)
- #--------------------------------------------------------------------------
- def gradient_fill_rect(*arg)
- arg = *arg
- case arg[0]
- when Rect
- x = arg[0].x
- y = arg[0].y
- width = arg[0].width
- height = arg[0].height
- color1 = arg[1]
- color2 = arg[2]
- vertical = arg[3]
- else
- x = arg[0]
- y = arg[1]
- width = arg[2]
- height = arg[3]
- color1 = arg[4]
- color2 = arg[5]
- vertical = arg[6]
- end
- vertical = false if vertical.nil?
- vertical == false ? step = width : step = height
- color = color1;step += 0.0
- key_re = (color2.red - color1.red) / step
- key_gr = (color2.green - color1.green) / step
- key_bl = (color2.blue - color1.blue) / step
- red = color.red;green = color.green;blue = color.blue
- x -= 1 unless vertical
- y -= 1 if vertical
- if vertical
- for i in 0...height
- y += 1
- red += key_re;green += key_gr;blue += key_bl
- color.red = red.to_i;color.green = green.to_i;color.blue = blue.to_i
- self.fill_rect(x, y, width, 1, color)
- end
- else
- for i in 0...width
- x += 1
- red += key_re;green += key_gr;blue += key_bl
- color.red = red.to_i;color.green = green.to_i;color.blue = blue.to_i
- self.fill_rect(x, y, 1, height, color)
- end
- end
- end
- #--------------------------------------------------------------------------
- # ● clear_rect (RGSS2)
- #--------------------------------------------------------------------------
- def clear_rect(*arg)
- arg = *arg
- case arg
- when Rect
- x = arg.x
- y = arg.y
- width = arg.width
- height = arg.height
- else
- x = arg[0]
- y = arg[1]
- width = arg[2]
- height = arg[3]
- end
- self.fill_rect(x, y, width, height, Color.new(0, 0, 0, 0))
- end
- #--------------------------------------------------------------------------
- # ● draw_text (RGSS2)
- #--------------------------------------------------------------------------
- alias shadow_draw_text draw_text
- def draw_text(*arg)
- arg = *arg
- case arg[0]
- when Rect
- x = arg[0].x
- y = arg[0].y
- width = arg[0].width
- height = arg[0].height
- str = arg[1]
- align = arg[2]
- else
- x = arg[0]
- y = arg[1]
- width = arg[2]
- height = arg[3]
- str = arg[4]
- align = arg[5]
- end
- align = 0 if align.nil?
- ocolor = self.font.color.clone
- self.font.color = Color.new(0, 0, 0, 128)
- if self.font.shadow
- shadow_draw_text(x + 0.5, y + 0.5, width, height, str, align)
- end
- self.font.color = ocolor
- shadow_draw_text(x, y, width, height, str, align)
- end
- end
复制代码 4.发现 Input 的按键和 VX 的有错,于是重写了:- #==============================================================================
- # ■ Input
- #------------------------------------------------------------------------------
- # RGE 本身的 Input 按键表和 VX 的按键有重复的严重问题。
- # 以后设定键盘就来这里了
- #==============================================================================
- module Input
- #--------------------------------------------------------------------------
- # ● KEY 可以自己设定 (根据键盘虚拟词表)
- #--------------------------------------------------------------------------
- LEFT = [0x25, 0x64]
- RIGHT = [0x27, 0x66]
- UP = [0x26, 0x68]
- DOWN = [0x28, 0x62]
-
- C = [0x5A, 0x0D, 0x20]
- B = [0x58, 0x60, 0x1B]
- A = [0x10]
- X = [0x41]
- Y = [0x53]
- Z = [0x44]
- L = [0x51]
- R = [0x57]
-
- Ctrl = [0x11]
- Alt = [0x12]
-
- F5 = [0x74]
- F6 = [0x75]
- F7 = [0x76]
- F8 = [0x77]
- F9 = [0x78]
- #--------------------------------------------------------------------------
- # ● 实例变量
- #--------------------------------------------------------------------------
- @Key_Repeat = {}
- @Key_Trigger = {}
- module_function
- #--------------------------------------------------------------------------
- # ● 按住?
- #--------------------------------------------------------------------------
- def press?(keys)
- return_list = []
- keys = [keys] if keys.is_a?(Numeric)
- for key in keys
- return_list.push KBoard::GetKeyState.call(key) & 0x8000 > 0
- end
- return true if return_list.include?(true)
- return false
- end
- #--------------------------------------------------------------------------
- # ● 持续被按住?
- #--------------------------------------------------------------------------
- def repeat?(keys)
- return_list = []
- keys = [keys] if keys.is_a?(Numeric)
- for key in keys
- if @Key_Repeat[key] != nil
- return_list.push @Key_Repeat[key]
- next
- end
- @Key_Repeat[key] = KBoard.repeat?(key)
- return_list.push @Key_Repeat[key]
- end
- return true if return_list.include?(true)
- return false
- end
- #--------------------------------------------------------------------------
- # ● 按下?
- #--------------------------------------------------------------------------
- def trigger?(keys)
- return_list = []
- keys = [keys] if keys.is_a?(Numeric)
- for key in keys
- if @Key_Trigger[key] != nil
- return_list.push @Key_Trigger[key]
- next
- end
- @Key_Trigger[key] = KBoard.trigger?(key)
- return_list.push @Key_Trigger[key]
- end
- return true if return_list.include?(true)
- return false
- end
- #==============================================================================
- # ■ KBoard
- #==============================================================================
- module KBoard
- #--------------------------------------------------------------------------
- # ● 实例变量
- #--------------------------------------------------------------------------
- @Key_Hash = {}
- @Key_Repeat = {}
-
- GetKeyState = Win32API.new("user32","GetAsyncKeyState","i","i")
- #--------------------------------------------------------------------------
- # ● 持续被按住?
- #--------------------------------------------------------------------------
- def self.repeat?(key)
- result = GetKeyState.call(key) & 0x8000
- if result > 0
- if @Key_Repeat[key].nil?
- @Key_Repeat[key] = 0
- return true
- end
- @Key_Repeat[key] += 1
- else
- @Key_Repeat[key] = nil
- @Key_Hash[key] = 0
- end
- if !@Key_Repeat[key].nil? and @Key_Repeat[key] > 4 # 4乃准确数字
- @Key_Repeat[key] = 0
- return true
- else
- return false
- end
- end
- #--------------------------------------------------------------------------
- # ● 按下?
- #--------------------------------------------------------------------------
- def self.trigger?(rkey)
- result = GetKeyState.call(rkey) & 0x8000
- return false if @Key_Hash[rkey] and result > 0
- @Key_Hash[rkey] = (result > 0 ? true : false)
- return @Key_Hash[rkey]
- end
- end
- end
- #==============================================================================
- # ■ Input
- #------------------------------------------------------------------------------
- # 目的是为了加快 update 的速度
- #==============================================================================
- class << Input
- #--------------------------------------------------------------------------
- # ● 更新?
- #--------------------------------------------------------------------------
- alias old_update update
- def update
- old_update
- @Key_Repeat.clear
- @Key_Trigger.clear
- end
- end
复制代码 |
评分
-
查看全部评分
|