1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
| module Video
findWindow = Win32API.new('user32', 'FindWindow', 'pp', 'i')
GetMessage = Win32API.new('user32', 'GetMessage', 'piii', 'i')
TranslateMessage = Win32API.new('user32', 'TranslateMessage', 'p', 'i')
DispatchMessage = Win32API.new('user32', 'DispatchMessage', 'p', 'i')
SendInput = Win32API.new('user32', 'SendInput', 'ipi', 'i')
MultiByteToWideChar = Win32API.new('kernel32', 'MultiByteToWideChar', 'iipipi', 'i')
WideCharToMultiByte = Win32API.new('kernel32', 'WideCharToMultiByte', 'iipipipp', 'i')
GetShortPathName = Win32API.new('kernel32', 'GetShortPathName', 'ppi', 'i')
MciSendString = Win32API.new('winmm', 'mciSendString', 'ppii', 'i')
HWnd = findWindow.call('RGSS Player', 0)
def self.play(path, cancelable = true, stretch = true)
buffer, do_exit = ' '*28, false
MultiByteToWideChar.call(65001, 0, path, -1, utf16="\0"*520, 260) # utf8 => utf16
WideCharToMultiByte.call(0, 0, utf16, -1, ansi="\0"*260, 260, 0, 0) # utf16 => CP_ACP
size = GetShortPathName.call(ansi, shortpath="\0"*260, 260)
shortpath = shortpath[0, size]
MciSendString.call("open \"#{shortpath}\" alias VIDEO type AVIVideo style Child parent #{HWnd}", 0, 0, 0)
MciSendString.call('where VIDEO source', buffer, 28, 0)
src_rect = buffer.split(' ').map! {|s| s.to_i}
return if src_rect.size < 4
if stretch
ratio = src_rect[2] / src_rect[3].to_f
src_rect[2], src_rect[3] = 640, (640 / ratio).to_i
src_rect[3], src_rect[2] = 480, (480 * ratio).to_i if src_rect[3] > 480
end
src_rect[0], src_rect[1] = (640-src_rect[2])/2, (480-src_rect[3])/2
background = Sprite.new
background.bitmap = Bitmap.new(1, 1)
background.bitmap.set_pixel(0, 0, Color.new(0,0,0))
background.zoom_x, background.zoom_y, background.z = 640, 480, 9999
Graphics.update
MciSendString.call('put VIDEO window at 0 0 1 1', 0, 0, 0) # manip pour eviter un bug en plein ecran
MciSendString.call('play VIDEO', 0, 0, 0)
MciSendString.call("put VIDEO window at #{src_rect.join(' ')}", 0, 0, 0)
begin
loop do
GetMessage.call(buffer, HWnd, 0, 0)
TranslateMessage.call(buffer)
DispatchMessage.call(buffer)
case buffer.unpack('@4L').first
when 0x0012 #WM_QUIT
do_exit = true
break
when 0x0104 #WM_SYSKEYDOWN
if buffer.unpack('@8L').first == 0x0D #VK_RETURN
SendInput.call(1, [1,0x0D,0,0,0,0].pack('LSSLLLx8'), 28)
Graphics.update
Input.update
end
else
Input.update
break if cancelable and Input.trigger?(Input::C)
MciSendString.call('status VIDEO mode', buffer, 28, 0)
break if buffer !~ /^playing/
end
end
rescue Hangup
retry
end
MciSendString.call('stop VIDEO', 0, 0, 0)
MciSendString.call('close VIDEO', 0, 0, 0)
background.bitmap.dispose
background.dispose
exit if do_exit
end
end |