• R/O
  • SSH
  • HTTPS

dxruby: Commit


Commit MetaInfo

Revisión189 (tree)
Tiempo2010-06-02 22:05:26
Autormirichi

Log Message

1.0.8 tags(つけわすれ)

Cambiar Resumen

Diferencia incremental

--- tags/1.0.8/dxruby.c (nonexistent)
+++ tags/1.0.8/dxruby.c (revision 189)
@@ -0,0 +1,7184 @@
1+/*
2+###################################
3+#
4+# dxruby.c Ver. 1.0.8
5+#
6+###################################
7+*/
8+#define DXRUBY_VERSION "1.0.8"
9+
10+#undef DIRECTINPUT_VERSION
11+#define DIRECTINPUT_VERSION (0x0800) /* DirectInputバージョン定義 */
12+#define WINVER 0x0500 // バージョン定義 Windows2000以上
13+#define _WIN32_WINNT WINVER
14+
15+#include "ruby.h"
16+#include <stdlib.h>
17+#include <mmsystem.h>
18+#include <tchar.h>
19+#include <d3dx9.h>
20+#include <dmusici.h>
21+#include <dinput.h>
22+#include <memory.h>
23+#include <math.h>
24+//#include <DShow.h>
25+
26+#ifndef RSTRING_PTR
27+# define RSTRING_PTR(s) (RSTRING(s)->ptr)
28+#endif
29+#ifndef RSTRING_LEN
30+# define RSTRING_LEN(s) (RSTRING(s)->len)
31+#endif
32+
33+#ifndef RARRAY_PTR
34+# define RARRAY_PTR(s) (RARRAY(s)->ptr)
35+#endif
36+#ifndef RARRAY_LEN
37+# define RARRAY_LEN(s) (RARRAY(s)->len)
38+#endif
39+
40+#define RELEASE( x ) if( x ) { x->lpVtbl->Release( x ); x = NULL; }
41+
42+#define PADMAX 2
43+
44+#define P_LEFT 0
45+#define P_RIGHT 1
46+#define P_UP 2
47+#define P_DOWN 3
48+#define P_BUTTON0 4
49+#define P_BUTTON1 5
50+#define P_BUTTON2 6
51+#define P_BUTTON3 7
52+#define P_BUTTON4 8
53+#define P_BUTTON5 9
54+#define P_BUTTON6 10
55+#define P_BUTTON7 11
56+#define P_BUTTON8 12
57+#define P_BUTTON9 13
58+#define P_BUTTON10 14
59+#define P_BUTTON11 15
60+#define P_BUTTON12 16
61+#define P_BUTTON13 17
62+#define P_BUTTON14 18
63+#define P_BUTTON15 19
64+#define M_LBUTTON 0
65+#define M_RBUTTON 1
66+#define M_MBUTTON 2
67+#define FORMAT_JPEG D3DXIFF_JPG
68+#define FORMAT_JPG D3DXIFF_JPG
69+#define FORMAT_PNG D3DXIFF_PNG
70+#define FORMAT_BMP D3DXIFF_BMP
71+#define FORMAT_DDS D3DXIFF_DDS
72+#define WAVE_RECT 0
73+#define WAVE_SIN 1
74+#define WAVE_SAW 2
75+#define WAVE_TRI 3
76+
77+//#define WM_GRAPH_NOTIFY (WM_APP + 1) /* IMediaEventExのメッセージ */
78+
79+static VALUE mDXRuby; /* DXRubyモジュール */
80+static VALUE mWindow; /* ウィンドウモジュール */
81+static VALUE mInput; /* インプットモジュール */
82+static VALUE cImage; /* イメージクラス */
83+static VALUE cSound; /* サウンドクラス */
84+static VALUE cFont; /* フォントクラス */
85+static VALUE cSoundEffect; /* 生成効果音クラス */
86+static VALUE eDXRubyError; /* 例外 */
87+static VALUE cDXRubyInternalMark; /* 内部処理用 */
88+static VALUE oDXRubyInternalMark; /* 内部処理用 */
89+
90+/* グローバル変数たち */
91+static HINSTANCE g_hInstance = NULL; /* アプリケーションインスタンス */
92+static HANDLE g_hWind = NULL; /* ウィンドウハンドル */
93+static LPDIRECT3D9 g_pD3D = NULL; /* Direct3Dインターフェイス */
94+static LPDIRECT3DDEVICE9 g_pD3DDevice = NULL; /* Direct3DDeviceインターフェイス */
95+static D3DPRESENT_PARAMETERS g_D3DPP; /* D3DDeviceの設定 */
96+static LPD3DXSPRITE g_pD3DXSprite = NULL; /* スプライト */
97+
98+static LPDIRECTINPUT8 g_pDInput = NULL; /* DirectInput */
99+static LPDIRECTINPUTDEVICE8 g_pDIDKeyBoard = NULL; /* DirectInputのキーボードデバイス */
100+static LPDIRECTINPUTDEVICE8 g_pDIDJoyPad[PADMAX]; /* DirectInputのパッドデバイス */
101+static BYTE g_diKeyState[256]; /* DirectInputでのキーボード入力用バッファ */
102+static BYTE g_diKeyStateOld[256]; /* DirectInputでのキーボード入力用バッファ1フレーム前 */
103+static BYTE g_diKeyCount[256]; /* DirectInputでのキーボード入力用カウンタ */
104+static BYTE g_diKeyConfig[256]; /* DirectInputでのキーボード・パッド割り当て */
105+static BYTE g_diKeyWait[256]; /* オートリピートウェイト時間 */
106+static BYTE g_diKeyInterval[256]; /* オートリピート間隔 */
107+static int g_JoystickCount = 0;
108+static BYTE g_byMouseState_L, g_byMouseStateOld_L;
109+static BYTE g_byMouseState_M, g_byMouseStateOld_M;
110+static BYTE g_byMouseState_R, g_byMouseStateOld_R;
111+
112+
113+static IDirectMusicPerformance8 *g_pDMPerformance = NULL; /* DirectMusicPerformance8インターフェイス */
114+static IDirectMusicLoader8 *g_pDMLoader = NULL; /* ローダー */
115+static LPDIRECTSOUND8 g_pDSound = NULL; /* DirectSoundインターフェイス */
116+static int g_iRefDM = 0; /* DirectMusicパフォーマンスの参照カウント */
117+static int g_iRefDS = 0; /* DirectSoundの参照カウント */
118+static int g_iRefAll = 1; /* インターフェースの参照カウント */
119+
120+//static IGraphBuilder *g_pGraphBuilder = NULL; /* IGraphBuilderインターフェイス */
121+//static IMediaControl *g_pMediaControl = NULL; /* IMediaControlインターフェイス */
122+//static IVideoWindow *g_pVideoWindow = NULL; /* IVideoWindowインターフェイス */
123+//static IMediaEventEx *g_pMediaEventEx = NULL; /* IMediaEventExインターフェイス */
124+//static int g_PlayingMovie = 0; /* 動画再生中フラグ */
125+
126+
127+/* ゲーム調整用 */
128+static int g_bActive = 0;
129+
130+/* フレーム調整用 */
131+static __int64 g_OneSecondCount = 0; /* 一秒間にカウンタが数える数 */
132+static int g_isPerformanceCounter = 0; /* パフォーマンスカウンタがあったら1 */
133+static __int64 g_OldTime = 0; /* 前回のフレームが終わった時間 */
134+static __int64 g_OneFrameCount = 0; /* 1フレームの処理にかかった時間 */
135+static __int64 g_DrawTime = 0; /* 描画にかかった時間 */
136+
137+/* ウィンドウ情報構造体 */
138+static struct DXRubyWindowInfo {
139+ int x; /* x座標 */
140+ int y; /* y座標 */
141+ int width; /* 幅 */
142+ int height; /* 高さ */
143+ int windowed; /* ウィンドウモード時にQtrue */
144+ int created; /* ウィンドウを作成したらQtrue */
145+ float scale; /* ウィンドウのサイズ倍率 */
146+ int RefreshRate; /* リフレッシュレート */
147+ int enablemouse; /* マウスを表示するかどうか */
148+ int mousewheelpos; /* マウスホイールの位置 */
149+ int fps; /* fps */
150+ int fpscheck; /* 現在のfps */
151+ int frameskip; /* コマ落ち制御フラグ */
152+ int r; /* 背景クリア色 赤成分 */
153+ int g; /* 背景クリア色 緑成分 */
154+ int b; /* 背景クリア色 青成分 */
155+ int minfilter; /* 縮小フィルタ */
156+ int magfilter; /* 拡大フィルタ */
157+ HANDLE hIcon; /* ウィンドウアイコンハンドル */
158+ int loop; /* Window.loopされてたら1 */
159+ int requestclose; /* ウィンドウが閉じられたら1 */
160+} g_WindowInfo;
161+
162+/* テクスチャデータ */
163+struct DXRubyTexture {
164+ LPDIRECT3DTEXTURE9 pD3DTexture; /* スプライトに使うテクスチャ */
165+ int width;
166+ int height;
167+ int refcount;
168+};
169+
170+/* フォントデータ */
171+struct DXRubyFont {
172+ LPD3DXFONT pD3DXFont; /* フォントオブジェクト */
173+ HFONT hFont; /* Image描画に使うフォント */
174+ int size; /* フォントサイズ */
175+};
176+
177+/* フォントデータ */
178+struct DXRubyFontSprite {
179+ struct DXRubyFont *font; /* スプライトに使うフォント */
180+ int color; /* フォントの色 */
181+ char str[0]; /* 文字列オブジェクト */
182+};
183+
184+/* スプライトデータ */
185+struct DXRubySprite {
186+ void *image; /* 描画するイメージオブジェクトもしくはフォント */
187+ int x; /* 描画位置 x */
188+ int y; /* 描画位置 y */
189+ float angle; /* 回転角度 */
190+ float scalex; /* 横拡大率 */
191+ float scaley; /* 縦拡大率 */
192+ float centerx; /* 回転時の中心 x */
193+ float centery; /* 回転時の中心 y */
194+ unsigned char alpha; /* アルファ(透明)値 */
195+ unsigned char blendflag :3; /* 半透明(000)、加算合成1(100)、加算合成2(101)、減算合成1(110)、減算合成2(111)のフラグ */
196+ unsigned char fontflag :1; /* フォントなら1 */
197+ unsigned char vpflag :1; /* ビューポートなら1 */
198+ unsigned char reserve1 :3; /* 予約2 */
199+ char reserve2; /* 予約3 */
200+ char reserve3; /* 予約4 */
201+ VALUE value;
202+};
203+
204+/* Viewport */
205+struct DXRubyViewport {
206+ D3DVIEWPORT9 viewport;
207+};
208+
209+/* Imageオブジェクトの中身 */
210+struct DXRubyImage {
211+ struct DXRubyTexture *texture;
212+ float x; /* x始点位置 */
213+ float y; /* y始点位置 */
214+ float width; /* イメージの幅 */
215+ float height;/* イメージの高さ */
216+};
217+
218+/* Soundオブジェクト */
219+struct DXRubySound {
220+ IDirectMusicAudioPath8 *pDMDefAudioPath; /* デフォルトオーディオパス */
221+ IDirectMusicSegment8 *pDMSegment; /* セグメント */
222+ int start;
223+ int loopstart;
224+ int loopend;
225+ int loopcount;
226+ int midwavflag; /* midは0、wavは1 */
227+};
228+
229+/* SoundEffectオブジェクト */
230+struct DXRubySoundEffect {
231+ LPDIRECTSOUNDBUFFER pDSBuffer; /* バッファ */
232+};
233+
234+/* Pad情報 */
235+static struct DXRubyPadInfo {
236+ int right;
237+ int left;
238+ int up;
239+ int down;
240+ LPDIRECTINPUTDEVICE8 pDIDJoyPad; /* DirectInputのパッドデバイス */
241+} g_PadInfo[PADMAX];
242+
243+/* Pad状態 */
244+static struct DXRubyPadState {
245+ char button[20];
246+ int PadConfig[20];
247+ int count[20];
248+ int wait[20];
249+ int interval[20];
250+} g_PadState[PADMAX], g_PadStateOld[PADMAX];
251+
252+/* スプライト配列 */
253+static struct DXRubySpriteList {
254+ float z; /* スプライトのZ座標 */
255+ struct DXRubySprite *sprite; /* スプライト構造体へのポインタ */
256+} *g_SpriteList;
257+static int g_SpriteCount; /* スプライトの登録数 */
258+static int g_SpriteAllocateCount; /* スプライト配列のメモリ確保数 */
259+static struct DXRubySprite *g_SpriteStruct;
260+
261+/* 色 */
262+struct DXRubyColor {
263+ unsigned char blue;
264+ unsigned char green;
265+ unsigned char red;
266+ unsigned char alpha;
267+};
268+
269+/* シンボル */
270+static VALUE symbol_blend = Qundef;
271+static VALUE symbol_angle = Qundef;
272+static VALUE symbol_alpha = Qundef;
273+static VALUE symbol_scalex = Qundef;
274+static VALUE symbol_scaley = Qundef;
275+static VALUE symbol_centerx = Qundef;
276+static VALUE symbol_centery = Qundef;
277+static VALUE symbol_z = Qundef;
278+static VALUE symbol_color = Qundef;
279+static VALUE symbol_add = Qundef;
280+static VALUE symbol_add2 = Qundef;
281+static VALUE symbol_sub = Qundef;
282+static VALUE symbol_sub2 = Qundef;
283+static VALUE symbol_italic = Qundef;
284+static VALUE symbol_weight = Qundef;
285+
286+/* キーのオートリピート用 */
287+//static int g_iInputWait;
288+//static int g_iInterval;
289+
290+/* プロトタイプ宣言 */
291+static void InitWindow( void );
292+static void InitDXGraphics( void );
293+static void InitDirectInput( void );
294+LRESULT CALLBACK MainWndProc( HWND hWnd,UINT msg,UINT wParam,LONG lParam );
295+static void InitSync( void );
296+static __int64 GetSystemCounter( void );
297+static void Window_DirectXRelease( void );
298+static struct DXRubyTexture *Image_textureload( char *filename, D3DXIMAGE_INFO *psrcinfo );
299+static void Input_SetConfig( int number, int pad, int key );
300+static void ChangeSize( void );
301+static void inputupdate( void);
302+static VALUE Input_update( VALUE );
303+static VALUE Window_update( VALUE );
304+static VALUE Window_sync( VALUE );
305+static VALUE Window_create( VALUE );
306+static void AllocSpriteList( void );
307+static void SortSpriteList( void );
308+
309+static void release_Image( struct DXRubyImage* image );
310+static void release_Font( struct DXRubyFont* font );
311+
312+/*********************************************************************
313+ * Windowモジュール
314+ * ウィンドウの管理・描画を行う。
315+ *********************************************************************/
316+
317+/*--------------------------------------------------------------------
318+ ウィンドウの生成と初期化
319+ ---------------------------------------------------------------------*/
320+static VALUE Window_create( VALUE obj )
321+{
322+ HRESULT hr;
323+ RECT rect;
324+
325+ if( g_WindowInfo.created == Qtrue )
326+ {
327+ rb_raise( eDXRubyError, "ウィンドウ作成後に実行することはできません - Window_create" );
328+ }
329+
330+ /* ウィンドウのサイズ設定 */
331+ rect.top = 0;
332+ rect.left = 0;
333+ rect.right = g_WindowInfo.width * g_WindowInfo.scale;
334+ rect.bottom = g_WindowInfo.height * g_WindowInfo.scale;
335+
336+ /* ウィンドウのサイズ修正 */
337+ if( g_WindowInfo.windowed == Qnil || g_WindowInfo.windowed == Qfalse )
338+ { /* フルスクリーン */
339+ SetWindowLong( g_hWind, GWL_STYLE, WS_POPUP );
340+ SetWindowPos( g_hWind, HWND_TOP, 0, 0, g_WindowInfo.width, g_WindowInfo.height, SWP_NOZORDER);
341+ }
342+ else
343+ { /* ウィンドウモード */
344+ SetWindowLong( g_hWind, GWL_STYLE, WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX);
345+ AdjustWindowRect( &rect, WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX, FALSE );
346+
347+ /* 幅と高さ計算 */
348+ rect.right = rect.right - rect.left;
349+ rect.bottom = rect.bottom - rect.top;
350+
351+ /* ウィンドウ移動/サイズ設定 */
352+ if( g_WindowInfo.x == CW_USEDEFAULT )
353+ { /* 位置がデフォルトの場合 */
354+ SetWindowPos( g_hWind, HWND_TOP, 0, 0, rect.right, rect.bottom, SWP_NOZORDER | SWP_NOMOVE);
355+ }
356+ else
357+ { /* 位置指定の場合 */
358+ SetWindowPos( g_hWind, HWND_TOP, g_WindowInfo.x, g_WindowInfo.y, rect.right, rect.bottom, SWP_NOZORDER );
359+ }
360+ }
361+
362+ /* DirectXのスクリーンサイズ変更 */
363+ ChangeSize();
364+
365+ /* ウィンドウ表示 */
366+ ShowWindow( g_hWind, SW_SHOWNORMAL );
367+ UpdateWindow( g_hWind );
368+
369+ /* シーンのクリア */
370+ g_pD3DDevice->lpVtbl->Clear( g_pD3DDevice, 0, NULL, D3DCLEAR_TARGET,
371+ D3DCOLOR_XRGB( g_WindowInfo.r, g_WindowInfo.g, g_WindowInfo.b ), 0, 0 );
372+ g_pD3DDevice->lpVtbl->Present( g_pD3DDevice, NULL, NULL, NULL, NULL );
373+
374+ /* フレーム調整処理初期化 */
375+ InitSync();
376+
377+ g_WindowInfo.created = Qtrue;
378+
379+ return obj;
380+}
381+
382+
383+/*--------------------------------------------------------------------
384+ (内部関数)スクリーンサイズ変更
385+ ---------------------------------------------------------------------*/
386+static void ChangeSize( void )
387+{
388+ D3DVIEWPORT9 vp;
389+ HRESULT hr;
390+
391+
392+ g_D3DPP.BackBufferWidth = g_WindowInfo.width;
393+ g_D3DPP.BackBufferHeight = g_WindowInfo.height;
394+
395+ if( g_WindowInfo.windowed == Qnil || g_WindowInfo.windowed == Qfalse )
396+ {
397+ /* フルスクリーン時(32bitColor/60Hz固定) */
398+ g_D3DPP.BackBufferFormat = D3DFMT_X8R8G8B8;
399+ g_D3DPP.Windowed = FALSE;
400+ g_D3DPP.FullScreen_RefreshRateInHz = 60;
401+ g_D3DPP.PresentationInterval = D3DPRESENT_INTERVAL_ONE;
402+ g_WindowInfo.RefreshRate = 60;
403+ }
404+ else
405+ {
406+ /* ウィンドウモード時 */
407+ g_D3DPP.BackBufferFormat = D3DFMT_UNKNOWN;
408+ g_D3DPP.Windowed = TRUE;
409+ g_D3DPP.FullScreen_RefreshRateInHz = 0;
410+ g_D3DPP.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
411+ g_WindowInfo.RefreshRate = 0;
412+ }
413+
414+ /* スプライトをロストさせる */
415+ if( g_pD3DXSprite )
416+ {
417+ g_pD3DXSprite->lpVtbl->OnLostDevice( g_pD3DXSprite );
418+ }
419+
420+ /* 設定変更 */
421+ hr = g_pD3DDevice->lpVtbl->Reset( g_pD3DDevice, &g_D3DPP );
422+ if( FAILED( hr ) )
423+ {
424+ rb_raise( eDXRubyError, "設定に失敗しました - Reset" );
425+ }
426+
427+ /* スプライト復帰 */
428+ if( g_pD3DXSprite )
429+ {
430+ g_pD3DXSprite->lpVtbl->OnResetDevice( g_pD3DXSprite );
431+ }
432+
433+ /* ビューポートの設定 */
434+ vp.X = 0;
435+ vp.Y = 0;
436+ vp.Width = g_D3DPP.BackBufferWidth;
437+ vp.Height = g_D3DPP.BackBufferHeight;
438+ vp.MinZ = 0.0f;
439+ vp.MaxZ = 1.0f;
440+
441+ hr = g_pD3DDevice->lpVtbl->SetViewport( g_pD3DDevice, &vp );
442+
443+ if( FAILED( hr ) )
444+ {
445+ rb_raise( eDXRubyError, "設定に失敗しました - SetViewport" );
446+ }
447+}
448+
449+
450+/*--------------------------------------------------------------------
451+ Windowsのメッセージループ
452+ ---------------------------------------------------------------------*/
453+static VALUE Window_loop( VALUE obj )
454+{
455+ MSG msg;
456+ msg.message = WM_NULL;
457+
458+ if( g_WindowInfo.created == Qtrue )
459+ {
460+ rb_raise( eDXRubyError, "ウィンドウ作成後に実行することはできません - Window_loop" );
461+ }
462+
463+ g_WindowInfo.loop = 0;
464+ Window_create( obj );
465+
466+ /* メッセージループ */
467+ /* WM_QUITが届くまでメッセージ処理をし続ける */
468+ /* メッセージが無い時はブロックをyieldする */
469+ while( msg.message != WM_QUIT )
470+ {
471+ if( PeekMessage( &msg, 0, 0, 0, PM_REMOVE ) != 0)
472+ {
473+ /* メッセージがある時 */
474+ TranslateMessage( &msg );
475+ DispatchMessage( &msg );
476+ }
477+ else
478+ {
479+ /* メッセージが無い時 */
480+ /* 入力状態更新 */
481+ inputupdate();
482+ /* ブロック実行 */
483+ rb_yield( obj );
484+ /* fps調整 */
485+ Window_sync( obj );
486+ /* 描画 */
487+ Window_update( obj );
488+ }
489+ }
490+
491+ return Qtrue;
492+}
493+
494+
495+/*--------------------------------------------------------------------
496+ (内部関数)ウィンドウプロシージャ
497+ ---------------------------------------------------------------------*/
498+LRESULT CALLBACK MainWndProc( HWND hWnd, UINT msg, UINT wParam, LONG lParam )
499+{
500+ RECT rect;
501+
502+ switch( msg )
503+ {
504+ /* ウィンドウアクティブ/非アクティブ化 */
505+ case WM_ACTIVATE:
506+ g_bActive = (LOWORD(wParam) != 0);
507+ break;
508+ case WM_CLOSE:
509+ /* 自前ループの場合は無条件でキャセルする */
510+ if( g_WindowInfo.loop == 1 )
511+ {
512+ g_WindowInfo.requestclose = 1;
513+ return 0;
514+ }
515+ break;
516+ /* ウィンドウ破棄 */
517+ case WM_DESTROY:
518+ /* ウインドウを閉じる */
519+ PostQuitMessage( 0 );
520+ g_hWind = NULL;
521+ return 0;
522+
523+// case WM_GRAPH_NOTIFY:
524+// {
525+// long evCode;
526+// LONG param1, param2;
527+// while( SUCCEEDED( g_pMediaEventEx->lpVtbl->GetEvent( g_pMediaEventEx, &evCode, &param1, &param2, 0 )))
528+// {
529+// g_pMediaEventEx->lpVtbl->FreeEventParams( g_pMediaEventEx, evCode, param1, param2 );
530+//
531+// switch (evCode) {
532+// case EC_COMPLETE:
533+// // 再生終了
534+// g_PlayingMovie = 0;
535+// break;
536+// }
537+// }
538+// break;
539+// }
540+
541+ case WM_MOUSEWHEEL:
542+ g_WindowInfo.mousewheelpos += (short)HIWORD(wParam);
543+ break;
544+/*
545+ case WM_SETCURSOR:
546+ if( g_pD3DDevice )
547+ {
548+ if( LOWORD( lParam ) == HTCLIENT ) // クライアント領域のみ
549+ {
550+ if( g_WindowInfo.enablemouse == Qfalse )
551+ {
552+ SetCursor( NULL ); // ウインドウの標準カーソルを消す
553+ return TRUE; // 設定を終えたことを通知
554+ }
555+ }
556+ }
557+ break;
558+*/
559+ }
560+
561+ /* デフォルト処理 */
562+ return DefWindowProc( hWnd, msg, wParam, lParam );
563+}
564+
565+
566+/*--------------------------------------------------------------------
567+ 画面クリア色指定
568+ ---------------------------------------------------------------------*/
569+static VALUE Window_getbgcolor( VALUE obj )
570+{
571+ return rb_ary_new3( 3, INT2FIX( g_WindowInfo.r ), INT2FIX( g_WindowInfo.g ), INT2FIX( g_WindowInfo.b ) );
572+}
573+
574+
575+/*--------------------------------------------------------------------
576+ 画面クリア色指定
577+ ---------------------------------------------------------------------*/
578+static VALUE Window_setbgcolor( VALUE obj, VALUE array )
579+{
580+ Check_Type(array, T_ARRAY);
581+
582+ if( RARRAY_LEN(array) == 4 )
583+ {
584+ g_WindowInfo.r = NUM2INT( rb_ary_entry(array, 1) );
585+ g_WindowInfo.g = NUM2INT( rb_ary_entry(array, 2) );
586+ g_WindowInfo.b = NUM2INT( rb_ary_entry(array, 3) );
587+ }
588+ else
589+ {
590+ g_WindowInfo.r = NUM2INT( rb_ary_entry(array, 0) );
591+ g_WindowInfo.g = NUM2INT( rb_ary_entry(array, 1) );
592+ g_WindowInfo.b = NUM2INT( rb_ary_entry(array, 2) );
593+ }
594+
595+ return obj;
596+}
597+
598+
599+/*--------------------------------------------------------------------
600+ 描画設定(通常描画)
601+ ---------------------------------------------------------------------*/
602+static VALUE Window_draw( int argc, VALUE *argv, VALUE obj )
603+{
604+ struct DXRubyImage *image;
605+
606+ if( argc < 3 ) rb_raise(rb_eArgError, "wrong number of arguments (%d for %d)", argc, 3);
607+
608+ AllocSpriteList();
609+
610+ /* 引数のイメージオブジェクトから中身を取り出す */
611+ if( TYPE( argv[2] ) != T_DATA ) rb_raise(rb_eTypeError, "wrong argument type %s (expected DXRuby::Image)", rb_obj_classname( argv[2] ));
612+ image = (struct DXRubyImage *)DATA_PTR( argv[2] );
613+ if (RDATA(argv[2])->dfree != (RUBY_DATA_FUNC)release_Image)
614+ {
615+ rb_raise(rb_eTypeError, "wrong argument type %s (expected DXRuby::Image)", rb_obj_classname( argv[2] ));
616+ }
617+
618+ /* DXRubySpriteオブジェクト設定 */
619+ g_SpriteStruct[g_SpriteCount].image = image;
620+ g_SpriteStruct[g_SpriteCount].x = NUM2INT( argv[0] );
621+ g_SpriteStruct[g_SpriteCount].y = NUM2INT( argv[1] );
622+ g_SpriteStruct[g_SpriteCount].angle = 0.0f;
623+ g_SpriteStruct[g_SpriteCount].scalex = 1.0f;
624+ g_SpriteStruct[g_SpriteCount].scaley = 1.0f;
625+ g_SpriteStruct[g_SpriteCount].alpha = 0xff;
626+ g_SpriteStruct[g_SpriteCount].centerx = image->width / 2;
627+ g_SpriteStruct[g_SpriteCount].centery = image->height / 2;
628+ g_SpriteStruct[g_SpriteCount].blendflag = 0;
629+ g_SpriteStruct[g_SpriteCount].fontflag = 0;
630+ g_SpriteStruct[g_SpriteCount].vpflag = 0;
631+ g_SpriteStruct[g_SpriteCount].value = argv[2];
632+
633+ /* リストデータに追加 */
634+ g_SpriteList[g_SpriteCount].sprite = &g_SpriteStruct[g_SpriteCount];
635+ g_SpriteList[g_SpriteCount].z = argc < 4 || argv[3] == Qnil ? 0.0f : NUM2DBL( argv[3] );
636+ g_SpriteCount++;
637+
638+ return obj;
639+}
640+
641+
642+/*--------------------------------------------------------------------
643+ 描画設定(拡大縮小描画)
644+ ---------------------------------------------------------------------*/
645+static VALUE Window_drawScale( int argc, VALUE *argv, VALUE obj )
646+{
647+ struct DXRubyImage *image;
648+
649+ if( argc < 5 ) rb_raise(rb_eArgError, "wrong number of arguments (%d for %d)", argc, 5);
650+
651+ AllocSpriteList();
652+
653+ /* 引数のイメージオブジェクトから中身を取り出す */
654+ if( TYPE( argv[2] ) != T_DATA ) rb_raise(rb_eTypeError, "wrong argument type %s (expected DXRuby::Image)", rb_obj_classname( argv[2] ));
655+ image = (struct DXRubyImage *)DATA_PTR( argv[2] );
656+ if (RDATA(argv[2])->dfree != (RUBY_DATA_FUNC)release_Image)
657+ {
658+ rb_raise(rb_eTypeError, "wrong argument type %s (expected DXRuby::Image)", rb_obj_classname( argv[2] ));
659+ }
660+
661+ /* DXRubySpriteオブジェクト設定 */
662+ g_SpriteStruct[g_SpriteCount].image = image;
663+ g_SpriteStruct[g_SpriteCount].x = NUM2INT( argv[0] );
664+ g_SpriteStruct[g_SpriteCount].y = NUM2INT( argv[1] );
665+ g_SpriteStruct[g_SpriteCount].angle = 0.0f;
666+ g_SpriteStruct[g_SpriteCount].scalex = NUM2DBL( argv[3] );
667+ g_SpriteStruct[g_SpriteCount].scaley = NUM2DBL( argv[4] );
668+ g_SpriteStruct[g_SpriteCount].centerx = argc < 6 || argv[5] == Qnil ? image->width / 2 : NUM2DBL( argv[5] );
669+ g_SpriteStruct[g_SpriteCount].centery = argc < 7 || argv[6] == Qnil ? image->height / 2 : NUM2DBL( argv[6] );
670+ g_SpriteStruct[g_SpriteCount].alpha = 0xff;
671+ g_SpriteStruct[g_SpriteCount].blendflag = 0;
672+ g_SpriteStruct[g_SpriteCount].fontflag = 0;
673+ g_SpriteStruct[g_SpriteCount].vpflag = 0;
674+ g_SpriteStruct[g_SpriteCount].value = argv[2];
675+
676+ /* リストデータに追加 */
677+ g_SpriteList[g_SpriteCount].sprite = &g_SpriteStruct[g_SpriteCount];
678+ g_SpriteList[g_SpriteCount].z = argc < 8 || argv[7] == Qnil ? 0.0f : NUM2DBL( argv[7] );
679+ g_SpriteCount++;
680+
681+ return obj;
682+}
683+
684+
685+/*--------------------------------------------------------------------
686+ 描画設定(回転描画)
687+ ---------------------------------------------------------------------*/
688+static VALUE Window_drawRot( int argc, VALUE *argv, VALUE obj )
689+{
690+ struct DXRubyImage *image;
691+
692+ if( argc < 4 ) rb_raise(rb_eArgError, "wrong number of arguments (%d for %d)", argc, 4);
693+
694+ AllocSpriteList();
695+
696+ /* 引数のイメージオブジェクトから中身を取り出す */
697+ if( TYPE( argv[2] ) != T_DATA ) rb_raise(rb_eTypeError, "wrong argument type %s (expected DXRuby::Image)", rb_obj_classname( argv[2] ));
698+ image = (struct DXRubyImage *)DATA_PTR( argv[2] );
699+ if (RDATA(argv[2])->dfree != (RUBY_DATA_FUNC)release_Image)
700+ {
701+ rb_raise(rb_eTypeError, "wrong argument type %s (expected DXRuby::Image)", rb_obj_classname( argv[2] ));
702+ }
703+
704+ /* DXRubySpriteオブジェクト設定 */
705+ g_SpriteStruct[g_SpriteCount].image = image;
706+ g_SpriteStruct[g_SpriteCount].x = NUM2INT( argv[0] );
707+ g_SpriteStruct[g_SpriteCount].y = NUM2INT( argv[1] );
708+ g_SpriteStruct[g_SpriteCount].angle = NUM2DBL( argv[3] );
709+ g_SpriteStruct[g_SpriteCount].scalex = 1.0f;
710+ g_SpriteStruct[g_SpriteCount].scaley = 1.0f;
711+ g_SpriteStruct[g_SpriteCount].alpha = 0xff;
712+ g_SpriteStruct[g_SpriteCount].blendflag = 0;
713+ g_SpriteStruct[g_SpriteCount].centerx = argc < 5 || argv[4] == Qnil ? image->width / 2 : NUM2DBL( argv[4] );
714+ g_SpriteStruct[g_SpriteCount].centery = argc < 6 || argv[5] == Qnil ? image->height / 2 : NUM2DBL( argv[5] );
715+ g_SpriteStruct[g_SpriteCount].fontflag = 0;
716+ g_SpriteStruct[g_SpriteCount].vpflag = 0;
717+ g_SpriteStruct[g_SpriteCount].value = argv[2];
718+
719+ /* リストデータに追加 */
720+ g_SpriteList[g_SpriteCount].sprite = &g_SpriteStruct[g_SpriteCount];
721+ g_SpriteList[g_SpriteCount].z = argc < 7 || argv[6] == Qnil ? 0.0f : NUM2DBL( argv[6] );
722+ g_SpriteCount++;
723+
724+ return obj;
725+}
726+
727+
728+/*--------------------------------------------------------------------
729+ 描画設定(半透明描画)
730+ ---------------------------------------------------------------------*/
731+static VALUE Window_drawAlpha( int argc, VALUE *argv, VALUE obj )
732+{
733+ struct DXRubyImage *image;
734+
735+ if( argc < 4 ) rb_raise(rb_eArgError, "wrong number of arguments (%d for %d)", argc, 4);
736+
737+ AllocSpriteList();
738+
739+ /* 引数のイメージオブジェクトから中身を取り出す */
740+ if( TYPE( argv[2] ) != T_DATA ) rb_raise(rb_eTypeError, "wrong argument type %s (expected DXRuby::Image)", rb_obj_classname( argv[2] ));
741+ image = (struct DXRubyImage *)DATA_PTR( argv[2] );
742+ if (RDATA(argv[2])->dfree != (RUBY_DATA_FUNC)release_Image)
743+ {
744+ rb_raise(rb_eTypeError, "wrong argument type %s (expected DXRuby::Image)", rb_obj_classname( argv[2] ));
745+ }
746+
747+ /* DXRubySpriteオブジェクト設定 */
748+ g_SpriteStruct[g_SpriteCount].image = image;
749+ g_SpriteStruct[g_SpriteCount].x = NUM2INT( argv[0] );
750+ g_SpriteStruct[g_SpriteCount].y = NUM2INT( argv[1] );
751+ g_SpriteStruct[g_SpriteCount].angle = 0.0f;
752+ g_SpriteStruct[g_SpriteCount].scalex = 1.0f;
753+ g_SpriteStruct[g_SpriteCount].scaley = 1.0f;
754+ g_SpriteStruct[g_SpriteCount].alpha = NUM2INT( argv[3] );
755+ g_SpriteStruct[g_SpriteCount].blendflag = 0;
756+ g_SpriteStruct[g_SpriteCount].centerx = image->width / 2;
757+ g_SpriteStruct[g_SpriteCount].centery = image->height / 2;
758+ g_SpriteStruct[g_SpriteCount].fontflag = 0;
759+ g_SpriteStruct[g_SpriteCount].vpflag = 0;
760+ g_SpriteStruct[g_SpriteCount].value = argv[2];
761+
762+ /* リストデータに追加 */
763+ g_SpriteList[g_SpriteCount].sprite = &g_SpriteStruct[g_SpriteCount];
764+ g_SpriteList[g_SpriteCount].z = argc < 5 || argv[4] == Qnil ? 0.0f : NUM2DBL( argv[4] );
765+ g_SpriteCount++;
766+
767+ return obj;
768+}
769+
770+
771+/*--------------------------------------------------------------------
772+ 描画設定(加算合成描画)
773+ ---------------------------------------------------------------------*/
774+static VALUE Window_drawAdd( int argc, VALUE *argv, VALUE obj )
775+{
776+ struct DXRubyImage *image;
777+
778+ if( argc < 3 ) rb_raise(rb_eArgError, "wrong number of arguments (%d for %d)", argc, 3);
779+
780+ AllocSpriteList();
781+
782+ /* 引数のイメージオブジェクトから中身を取り出す */
783+ if( TYPE( argv[2] ) != T_DATA ) rb_raise(rb_eTypeError, "wrong argument type %s (expected DXRuby::Image)", rb_obj_classname( argv[2] ));
784+ image = (struct DXRubyImage *)DATA_PTR( argv[2] );
785+ if (RDATA(argv[2])->dfree != (RUBY_DATA_FUNC)release_Image)
786+ {
787+ rb_raise(rb_eTypeError, "wrong argument type %s (expected DXRuby::Image)", rb_obj_classname( argv[2] ));
788+ }
789+
790+ /* DXRubySpriteオブジェクト設定 */
791+ g_SpriteStruct[g_SpriteCount].image = image;
792+ g_SpriteStruct[g_SpriteCount].x = NUM2INT( argv[0] );
793+ g_SpriteStruct[g_SpriteCount].y = NUM2INT( argv[1] );
794+ g_SpriteStruct[g_SpriteCount].angle = 0.0f;
795+ g_SpriteStruct[g_SpriteCount].scalex = 1.0f;
796+ g_SpriteStruct[g_SpriteCount].scaley = 1.0f;
797+ g_SpriteStruct[g_SpriteCount].alpha = 0xff;
798+ g_SpriteStruct[g_SpriteCount].blendflag = 4;
799+ g_SpriteStruct[g_SpriteCount].centerx = image->width / 2;
800+ g_SpriteStruct[g_SpriteCount].centery = image->height / 2;
801+ g_SpriteStruct[g_SpriteCount].fontflag = 0;
802+ g_SpriteStruct[g_SpriteCount].vpflag = 0;
803+ g_SpriteStruct[g_SpriteCount].value = argv[2];
804+
805+ /* リストデータに追加 */
806+ g_SpriteList[g_SpriteCount].sprite = &g_SpriteStruct[g_SpriteCount];
807+ g_SpriteList[g_SpriteCount].z = argc < 4 || argv[3] == Qnil ? 0.0f : NUM2DBL( argv[3] );
808+ g_SpriteCount++;
809+
810+ return obj;
811+}
812+
813+
814+/*--------------------------------------------------------------------
815+ 描画設定(減算合成描画)
816+ ---------------------------------------------------------------------*/
817+static VALUE Window_drawSub( int argc, VALUE *argv, VALUE obj )
818+{
819+ struct DXRubyImage *image;
820+
821+ if( argc < 3 ) rb_raise(rb_eArgError, "wrong number of arguments (%d for %d)", argc, 3);
822+
823+ AllocSpriteList();
824+
825+ /* 引数のイメージオブジェクトから中身を取り出す */
826+ if( TYPE( argv[2] ) != T_DATA ) rb_raise(rb_eTypeError, "wrong argument type %s (expected DXRuby::Image)", rb_obj_classname( argv[2] ));
827+ image = (struct DXRubyImage *)DATA_PTR( argv[2] );
828+ if (RDATA(argv[2])->dfree != (RUBY_DATA_FUNC)release_Image)
829+ {
830+ rb_raise(rb_eTypeError, "wrong argument type %s (expected DXRuby::Image)", rb_obj_classname( argv[2] ));
831+ }
832+
833+ /* DXRubySpriteオブジェクト設定 */
834+ g_SpriteStruct[g_SpriteCount].image = image;
835+ g_SpriteStruct[g_SpriteCount].x = NUM2INT( argv[0] );
836+ g_SpriteStruct[g_SpriteCount].y = NUM2INT( argv[1] );
837+ g_SpriteStruct[g_SpriteCount].angle = 0.0f;
838+ g_SpriteStruct[g_SpriteCount].scalex = 1.0f;
839+ g_SpriteStruct[g_SpriteCount].scaley = 1.0f;
840+ g_SpriteStruct[g_SpriteCount].alpha = 0xff;
841+ g_SpriteStruct[g_SpriteCount].blendflag = 6;
842+ g_SpriteStruct[g_SpriteCount].centerx = image->width / 2;
843+ g_SpriteStruct[g_SpriteCount].centery = image->height / 2;
844+ g_SpriteStruct[g_SpriteCount].fontflag = 0;
845+ g_SpriteStruct[g_SpriteCount].vpflag = 0;
846+ g_SpriteStruct[g_SpriteCount].value = argv[2];
847+
848+ /* リストデータに追加 */
849+ g_SpriteList[g_SpriteCount].sprite = &g_SpriteStruct[g_SpriteCount];
850+ g_SpriteList[g_SpriteCount].z = argc < 4 || argv[3] == Qnil ? 0.0f : NUM2DBL( argv[3] );
851+ g_SpriteCount++;
852+
853+ return obj;
854+}
855+
856+
857+/*--------------------------------------------------------------------
858+ 描画設定(フルオプション)
859+ ---------------------------------------------------------------------*/
860+static VALUE Window_drawEx( int argc, VALUE *argv, VALUE obj )
861+{
862+ struct DXRubyImage *image;
863+ VALUE x, y, z, data, angle, scalex, scaley, alpha, centerx, centery, blend, add;
864+ VALUE option;
865+
866+ if( argc < 3 ) rb_raise(rb_eArgError, "wrong number of arguments (%d for %d)", argc, 3);
867+
868+ if( argc < 4 || argv[3] == Qnil )
869+ {
870+ option = rb_hash_new();
871+ }
872+ else
873+ {
874+ Check_Type( argv[3], T_HASH );
875+ option = argv[3];
876+ }
877+
878+ AllocSpriteList();
879+
880+ blend = rb_hash_lookup( option, symbol_blend );
881+ angle = rb_hash_lookup( option, symbol_angle );
882+ alpha = rb_hash_lookup( option, symbol_alpha );
883+ scalex = rb_hash_lookup( option, symbol_scalex );
884+ scaley = rb_hash_lookup( option, symbol_scaley );
885+ centerx = rb_hash_lookup( option, symbol_centerx );
886+ centery = rb_hash_lookup( option, symbol_centery );
887+ z = rb_hash_lookup( option, symbol_z );
888+
889+ /* 引数のイメージオブジェクトから中身を取り出す */
890+ if( TYPE( argv[2] ) != T_DATA ) rb_raise(rb_eTypeError, "wrong argument type %s (expected DXRuby::Image)", rb_obj_classname( argv[2] ));
891+ image = (struct DXRubyImage *)DATA_PTR( argv[2] );
892+ if (RDATA(argv[2])->dfree != (RUBY_DATA_FUNC)release_Image)
893+ {
894+ rb_raise(rb_eTypeError, "wrong argument type %s (expected DXRuby::Image)", rb_obj_classname( argv[2] ));
895+ }
896+
897+ /* DXRubySpriteオブジェクト設定 */
898+ g_SpriteStruct[g_SpriteCount].image = image;
899+ g_SpriteStruct[g_SpriteCount].x = NUM2INT( argv[0] );
900+ g_SpriteStruct[g_SpriteCount].y = NUM2INT( argv[1] );
901+ g_SpriteStruct[g_SpriteCount].angle = (angle == Qnil ? 0.0f : NUM2DBL( angle ));
902+ g_SpriteStruct[g_SpriteCount].scalex = (scalex == Qnil ? 1.0f : NUM2DBL( scalex ));
903+ g_SpriteStruct[g_SpriteCount].scaley = (scaley == Qnil ? 1.0f : NUM2DBL( scaley ));
904+ g_SpriteStruct[g_SpriteCount].centerx = (centerx == Qnil ? image->width / 2 : NUM2DBL( centerx ));
905+ g_SpriteStruct[g_SpriteCount].centery = (centery == Qnil ? image->height / 2 : NUM2DBL( centery ));
906+ g_SpriteStruct[g_SpriteCount].alpha = (alpha == Qnil ? 0xff : NUM2INT( alpha ));
907+ g_SpriteStruct[g_SpriteCount].blendflag = (blend == symbol_add ? 4 :
908+ (blend == symbol_add2 ? 5 :
909+ (blend == symbol_sub ? 6 :
910+ (blend == symbol_sub2 ? 7 : 0))));
911+ g_SpriteStruct[g_SpriteCount].fontflag = 0;
912+ g_SpriteStruct[g_SpriteCount].vpflag = 0;
913+ g_SpriteStruct[g_SpriteCount].value = argv[2];
914+
915+ /* リストデータに追加 */
916+ g_SpriteList[g_SpriteCount].sprite = &g_SpriteStruct[g_SpriteCount];
917+ g_SpriteList[g_SpriteCount].z = z == Qnil ? 0.0f : NUM2DBL( z );
918+ g_SpriteCount++;
919+
920+ return obj;
921+}
922+
923+
924+/*--------------------------------------------------------------------
925+ フォント描画
926+ ---------------------------------------------------------------------*/
927+static VALUE Window_drawFont( int argc, VALUE *argv, VALUE obj )
928+{
929+ struct DXRubySprite *spr;
930+ struct DXRubyFont *font;
931+ VALUE color;
932+ int cr, cg, cb;
933+ VALUE z, angle, scalex, scaley, alpha, centerx, centery, blend, add;
934+ VALUE option;
935+ struct DXRubyFontSprite *fontsprite;
936+
937+ if( argc < 4 ) rb_raise(rb_eArgError, "wrong number of arguments (%d for %d)", argc, 4);
938+
939+ Check_Type(argv[2], T_STRING);
940+
941+ if( argc < 5 || argv[4] == Qnil )
942+ {
943+ option = rb_hash_new();
944+ }
945+ else
946+ {
947+ Check_Type( argv[4], T_HASH );
948+ option = argv[4];
949+ }
950+
951+ blend = rb_hash_lookup( option, symbol_blend );
952+ angle = rb_hash_lookup( option, symbol_angle );
953+ alpha = rb_hash_lookup( option, symbol_alpha );
954+ scalex = rb_hash_lookup( option, symbol_scalex );
955+ scaley = rb_hash_lookup( option, symbol_scaley );
956+ centerx = rb_hash_lookup( option, symbol_centerx );
957+ centery = rb_hash_lookup( option, symbol_centery );
958+ z = rb_hash_lookup( option, symbol_z );
959+ color = rb_hash_lookup( option, symbol_color );
960+
961+ AllocSpriteList();
962+
963+ /* 引数のフォントオブジェクトから中身を取り出す */
964+ Data_Get_Struct( argv[3], struct DXRubyFont, font );
965+ if (RDATA(argv[3])->dfree != (RUBY_DATA_FUNC)release_Font)
966+ {
967+ rb_raise(rb_eTypeError, "wrong argument type %s (expected DXRuby::Font)", rb_obj_classname( argv[3] ));
968+ }
969+
970+ fontsprite = malloc( sizeof(struct DXRubyFontSprite) + RSTRING_LEN(argv[2]) + 2 );
971+ if( fontsprite == NULL )
972+ {
973+ rb_raise( eDXRubyError, "フォント用メモリの確保に失敗しました" );
974+ }
975+ /* DXRubySpriteオブジェクト設定 */
976+ g_SpriteStruct[g_SpriteCount].image = fontsprite;
977+ g_SpriteStruct[g_SpriteCount].x = NUM2INT( argv[0] );
978+ g_SpriteStruct[g_SpriteCount].y = NUM2INT( argv[1] );
979+ g_SpriteStruct[g_SpriteCount].angle = (angle == Qnil ? 0.0f : NUM2DBL( angle ));
980+ g_SpriteStruct[g_SpriteCount].scalex = (scalex == Qnil ? 1.0f : NUM2DBL( scalex ));
981+ g_SpriteStruct[g_SpriteCount].scaley = (scaley == Qnil ? 1.0f : NUM2DBL( scaley ));
982+ g_SpriteStruct[g_SpriteCount].centerx = (centerx == Qnil ? 0.0f : NUM2DBL( centerx ));;
983+ g_SpriteStruct[g_SpriteCount].centery = (centery == Qnil ? 0.0f : NUM2DBL( centery ));;
984+ g_SpriteStruct[g_SpriteCount].alpha = (alpha == Qnil ? 0xff : NUM2INT( alpha ));
985+ g_SpriteStruct[g_SpriteCount].blendflag = (blend == symbol_add ? 4 :
986+ (blend == symbol_add2 ? 5 :
987+ (blend == symbol_sub ? 6 :
988+ (blend == symbol_sub2 ? 7 : 0))));
989+ g_SpriteStruct[g_SpriteCount].fontflag = 1;
990+ g_SpriteStruct[g_SpriteCount].vpflag = 0;
991+ g_SpriteStruct[g_SpriteCount].value = argv[3];
992+
993+ lstrcpy(fontsprite->str, RSTRING_PTR(argv[2])); /* 文字列の保存 */
994+ fontsprite->str[RSTRING_LEN(argv[2])] = ' '; /* イタリック対策にスペース追加 */
995+ fontsprite->str[RSTRING_LEN(argv[2])+1] = 0;
996+
997+ if( color != Qnil )
998+ {
999+ Check_Type(color, T_ARRAY);
1000+ if( RARRAY_LEN(color) == 4 )
1001+ {
1002+ g_SpriteStruct[g_SpriteCount].alpha = NUM2INT(rb_ary_entry(color, 0));
1003+ cr = NUM2INT(rb_ary_entry(color, 1));
1004+ cg = NUM2INT(rb_ary_entry(color, 2));
1005+ cb = NUM2INT(rb_ary_entry(color, 3));
1006+ }
1007+ else
1008+ {
1009+ cr = NUM2INT(rb_ary_entry(color, 0));
1010+ cg = NUM2INT(rb_ary_entry(color, 1));
1011+ cb = NUM2INT(rb_ary_entry(color, 2));
1012+ }
1013+ }
1014+ else
1015+ {
1016+ cr = 255;
1017+ cg = 255;
1018+ cb = 255;
1019+ }
1020+ fontsprite->color = D3DCOLOR_XRGB(cr, cg, cb);
1021+ fontsprite->font = font;
1022+
1023+ /* リストデータに追加 */
1024+ g_SpriteList[g_SpriteCount].sprite = &g_SpriteStruct[g_SpriteCount];
1025+ g_SpriteList[g_SpriteCount].z = z == Qnil ? 0.0f : NUM2DBL( z );
1026+ g_SpriteCount++;
1027+
1028+ return obj;
1029+}
1030+
1031+
1032+/*--------------------------------------------------------------------
1033+ ビューポート設定
1034+ ---------------------------------------------------------------------*/
1035+static VALUE Window_setViewport( int argc, VALUE *argv, VALUE obj )
1036+{
1037+ struct DXRubyViewport *vp;
1038+
1039+ if( argc < 4 ) rb_raise(rb_eArgError, "wrong number of arguments (%d for %d)", argc, 4);
1040+
1041+ AllocSpriteList();
1042+
1043+ if( NUM2INT(argv[0]) < 0 || NUM2INT(argv[1]) < 0 || NUM2INT(argv[2]) < 0 || NUM2INT(argv[3]) < 0 ||
1044+ NUM2INT(argv[0]) + NUM2INT(argv[2]) > g_WindowInfo.width || NUM2INT(argv[1]) + NUM2INT(argv[3]) > g_WindowInfo.height)
1045+ {
1046+ rb_raise(rb_eArgError, "範囲の指定が異常です - setViewport");
1047+ }
1048+
1049+ vp = malloc( sizeof(struct DXRubyViewport) );
1050+
1051+ vp->viewport.X = NUM2INT( argv[0] );
1052+ vp->viewport.Y = NUM2INT( argv[1] );
1053+ vp->viewport.Width = NUM2INT( argv[2] );
1054+ vp->viewport.Height = NUM2INT( argv[3] );
1055+ vp->viewport.MinZ = 0.0f;
1056+ vp->viewport.MaxZ = 1.0f;
1057+
1058+ /* DXRubySpriteオブジェクト設定 */
1059+ g_SpriteStruct[g_SpriteCount].image = vp;
1060+ g_SpriteStruct[g_SpriteCount].x = 0;
1061+ g_SpriteStruct[g_SpriteCount].y = 0;
1062+ g_SpriteStruct[g_SpriteCount].angle = 0.0f;
1063+ g_SpriteStruct[g_SpriteCount].scalex = 0.0f;
1064+ g_SpriteStruct[g_SpriteCount].scaley = 0.0f;
1065+ g_SpriteStruct[g_SpriteCount].alpha = 0;
1066+ g_SpriteStruct[g_SpriteCount].centerx = 0;
1067+ g_SpriteStruct[g_SpriteCount].centery = 0;
1068+ g_SpriteStruct[g_SpriteCount].blendflag = 0;
1069+ g_SpriteStruct[g_SpriteCount].fontflag = 0;
1070+ g_SpriteStruct[g_SpriteCount].vpflag = 1;
1071+
1072+ /* リストデータに追加 */
1073+ g_SpriteList[g_SpriteCount].sprite = &g_SpriteStruct[g_SpriteCount];
1074+ g_SpriteList[g_SpriteCount].z = argc < 5 || argv[4] == Qnil ? 0.0f : NUM2DBL( argv[4] );
1075+ g_SpriteCount++;
1076+
1077+ return obj;
1078+}
1079+
1080+
1081+/*--------------------------------------------------------------------
1082+ マップ描画
1083+ ---------------------------------------------------------------------*/
1084+static VALUE Window_drawTile( int argc, VALUE *argv, VALUE klass )
1085+{
1086+ VALUE vstartx, vstarty, vz;
1087+ VALUE *arr1;
1088+ VALUE *arr2;
1089+ VALUE *mapdata;
1090+ VALUE vdata1, vdata2;
1091+ VALUE vbasex, vbasey, vmap, vmapdata, vsizex, vsizey;
1092+ int basex, basey, sizex, sizey;
1093+ int startx, starty;
1094+ float z;
1095+ int i, j, x, y;
1096+ int width, height;
1097+ struct DXRubyImage *image;
1098+
1099+ rb_scan_args( argc, argv, "81", &vbasex, &vbasey, &vmap, &vmapdata, &vstartx, &vstarty, &vsizex, &vsizey, &vz );
1100+
1101+ basex = NUM2INT( vbasex );
1102+ basey = NUM2INT( vbasey );
1103+ sizex = NUM2INT( vsizex );
1104+ sizey = NUM2INT( vsizey );
1105+
1106+ Check_Type(vmap, T_ARRAY);
1107+ Check_Type(vmapdata, T_ARRAY);
1108+
1109+ if( RARRAY_LEN( vmap ) == 0 )
1110+ {
1111+ return Qnil;
1112+ }
1113+
1114+ arr1 = RARRAY_PTR( vmap );
1115+ mapdata = RARRAY_PTR( vmapdata );
1116+
1117+ startx = NUM2INT( vstartx );
1118+ starty = NUM2INT( vstarty );
1119+ z = vz == Qnil ? 0.0f : NUM2DBL( vz );
1120+
1121+ /* イメージ配列が全部イメージかどうかをチェックしとく */
1122+ for( i = 0; i < RARRAY_LEN(vmapdata); i++ )
1123+ {
1124+ if( TYPE( mapdata[i] ) != T_DATA ) rb_raise(rb_eTypeError, "wrong argument type %s (expected DXRuby::Image)", rb_obj_classname( mapdata[i] ));
1125+ image = (struct DXRubyImage *)DATA_PTR( mapdata[i] );
1126+ if( RDATA( mapdata[i] )->dfree != (RUBY_DATA_FUNC)release_Image )
1127+ {
1128+ rb_raise(rb_eTypeError, "wrong argument type %s (expected DXRuby::Image)", rb_obj_classname( mapdata[i] ));
1129+ }
1130+ }
1131+
1132+ /* 幅と高さ取得 */
1133+ width = NUM2INT( rb_funcall(RARRAY_PTR(vmapdata)[0], rb_intern("width"), 0) );
1134+ height = NUM2INT( rb_funcall(RARRAY_PTR(vmapdata)[0], rb_intern("height"), 0) );
1135+
1136+ y = basey - ((starty % height) < 0 ? height + (starty % height) : (starty % height));
1137+ /* 描画 */
1138+ for( i = starty % height < 0 ? -1 : 0; i < sizey + (starty % height <= 0 ? 0 : 1); i++ )
1139+ {
1140+ int my;
1141+
1142+ if( i + starty / height < 0 )
1143+ {
1144+ my = (((i + starty / height) % RARRAY_LEN( vmap )) + RARRAY_LEN( vmap )) % RARRAY_LEN( vmap );
1145+ }
1146+ else
1147+ {
1148+ my = (i + starty / height) % RARRAY_LEN( vmap );
1149+ }
1150+
1151+ Check_Type(arr1[my], T_ARRAY);
1152+
1153+ if( RARRAY_LEN( arr1[my] ) == 0 )
1154+ {
1155+ continue;
1156+ }
1157+
1158+ arr2 = RARRAY_PTR( arr1[my] );
1159+
1160+ x = basex - ((startx % width) < 0 ? width + (startx % width) : (startx % width));
1161+
1162+ for( j = startx % width < 0 ? -1 : 0; j < sizex + (startx % width <= 0 ? 0 : 1); j++ )
1163+ {
1164+ int mx;
1165+ int index;
1166+
1167+ if( j + startx / width < 0 )
1168+ {
1169+ mx = (((j + startx / width) % RARRAY_LEN( arr1[my] )) + RARRAY_LEN( arr1[my] )) % RARRAY_LEN( arr1[my] );
1170+ }
1171+ else
1172+ {
1173+ mx = (j + startx / width) % RARRAY_LEN( arr1[my] );
1174+ }
1175+
1176+ if( arr2[mx] != Qnil )
1177+ {
1178+ index = NUM2INT( arr2[mx] );
1179+
1180+ if( index >= RARRAY_LEN( vmapdata ) ) rb_raise(eDXRubyError, "マップチップ番号がイメージ配列の範囲を超えています - Window_drawTile");
1181+
1182+ /* イメージオブジェクトから中身を取り出す */
1183+ image = (struct DXRubyImage *)DATA_PTR( mapdata[index] );
1184+
1185+ AllocSpriteList();
1186+
1187+ /* DXRubySpriteオブジェクト設定 */
1188+ g_SpriteStruct[g_SpriteCount].image = image;
1189+ g_SpriteStruct[g_SpriteCount].x = x;
1190+ g_SpriteStruct[g_SpriteCount].y = y;
1191+ g_SpriteStruct[g_SpriteCount].angle = 0.0f;
1192+ g_SpriteStruct[g_SpriteCount].scalex = 1.0f;
1193+ g_SpriteStruct[g_SpriteCount].scaley = 1.0f;
1194+ g_SpriteStruct[g_SpriteCount].alpha = 0xff;
1195+ g_SpriteStruct[g_SpriteCount].centerx = image->width / 2;
1196+ g_SpriteStruct[g_SpriteCount].centery = image->height / 2;
1197+ g_SpriteStruct[g_SpriteCount].blendflag = 0;
1198+ g_SpriteStruct[g_SpriteCount].fontflag = 0;
1199+ g_SpriteStruct[g_SpriteCount].vpflag = 0;
1200+ g_SpriteStruct[g_SpriteCount].value = mapdata[index];
1201+
1202+ /* リストデータに追加 */
1203+ g_SpriteList[g_SpriteCount].sprite = &g_SpriteStruct[g_SpriteCount];
1204+ g_SpriteList[g_SpriteCount].z = z;
1205+ g_SpriteCount++;
1206+ }
1207+
1208+ x = x + width;
1209+ }
1210+ y = y + height;
1211+ }
1212+
1213+ return Qnil;
1214+}
1215+
1216+
1217+typedef struct tag_dx_TLVERTEX {
1218+ float x, y, z, rhw;
1219+ D3DCOLOR color;
1220+ float tu, tv;
1221+}TLVERTX, *LPTLVERTEX;
1222+
1223+/*--------------------------------------------------------------------
1224+ (内部関数)画面更新
1225+ ---------------------------------------------------------------------*/
1226+static VALUE Window_update( VALUE obj )
1227+{
1228+ HRESULT hr;
1229+ static int max;
1230+ __int64 drawStartCounter;
1231+
1232+ while( 1 )
1233+ {
1234+ hr = g_pD3DDevice->lpVtbl->TestCooperativeLevel( g_pD3DDevice );
1235+ if( FAILED( hr ) )
1236+ {
1237+ if( hr == D3DERR_DEVICELOST ) /* デバイスはロスト状態である */
1238+ {
1239+ MSG msg;
1240+ if( PeekMessage( &msg, 0, 0, 0, PM_REMOVE ) != 0)
1241+ {
1242+ /* メッセージがある時 */
1243+ TranslateMessage( &msg );
1244+ DispatchMessage( &msg );
1245+ }
1246+ Sleep( 100 );
1247+ continue;
1248+ }
1249+ else if( hr == D3DERR_DEVICENOTRESET ) /* デバイスはロスト状態であるがリセット可能である */
1250+ {
1251+ /* ここへ来た時はデバイスがリセット可能状態である */
1252+ /* スプライトをロストさせる */
1253+ if( g_pD3DXSprite )
1254+ {
1255+ g_pD3DXSprite->lpVtbl->OnLostDevice( g_pD3DXSprite );
1256+ }
1257+
1258+ hr = g_pD3DDevice->lpVtbl->Reset( g_pD3DDevice, &g_D3DPP ); /* 復元を試みる */
1259+ if( FAILED( hr ) )
1260+ {
1261+ if( hr == D3DERR_DEVICELOST )
1262+ {
1263+ return obj; /* またロストした */
1264+ }
1265+ rb_raise( eDXRubyError, "DirectX APIの呼び出しに失敗しました - Reset" );
1266+ }
1267+
1268+ if( g_pD3DXSprite ) /* スプライト復帰 */
1269+ {
1270+ g_pD3DXSprite->lpVtbl->OnResetDevice( g_pD3DXSprite );
1271+ }
1272+ break;
1273+ }
1274+ else /* DirectXの内部エラー */
1275+ {
1276+ rb_raise( eDXRubyError, "DirectX APIの内部エラーが発生しました - TestCooperativeLevel" );
1277+ }
1278+ }
1279+ else
1280+ {
1281+ break;
1282+ }
1283+ }
1284+
1285+ drawStartCounter = GetSystemCounter();
1286+
1287+// /* 動画再生中 */
1288+// if( g_PlayingMovie == 1 )
1289+// {
1290+// return obj;
1291+// }
1292+ /* 描画対象が1つも無ければ描画処理そのものを行わない */
1293+ if( g_SpriteCount == 0 )
1294+ {
1295+ /* シーンの表示 */
1296+ if( g_WindowInfo.windowed == Qnil || g_WindowInfo.windowed == Qfalse )
1297+ {
1298+ g_DrawTime = 0;
1299+ g_OldTime += g_OneSecondCount / g_WindowInfo.RefreshRate;
1300+ }
1301+ else
1302+ {
1303+ g_pD3DDevice->lpVtbl->Present( g_pD3DDevice, NULL, NULL, NULL, NULL );
1304+ }
1305+ return obj;
1306+ }
1307+
1308+ /* シーンのクリア */
1309+ g_pD3DDevice->lpVtbl->Clear( g_pD3DDevice, 0, NULL, D3DCLEAR_TARGET,
1310+ D3DCOLOR_XRGB( g_WindowInfo.r, g_WindowInfo.g, g_WindowInfo.b ), 0, 0 );
1311+
1312+ /* シーンの描画開始 */
1313+ if( SUCCEEDED( g_pD3DDevice->lpVtbl->BeginScene( g_pD3DDevice ) ) )
1314+ {
1315+ int i;
1316+ int oldflag = 0;
1317+
1318+ /* スプライトの描画開始 */
1319+ g_pD3DXSprite->lpVtbl->Begin( g_pD3DXSprite, D3DXSPRITE_ALPHABLEND );
1320+
1321+ /* 拡大縮小フィルタ設定 */
1322+ g_pD3DDevice->lpVtbl->SetSamplerState(g_pD3DDevice, 0, D3DSAMP_MINFILTER,
1323+ g_WindowInfo.minfilter);
1324+ g_pD3DDevice->lpVtbl->SetSamplerState(g_pD3DDevice, 0, D3DSAMP_MAGFILTER,
1325+ g_WindowInfo.magfilter);
1326+
1327+ /* スプライトのz順ソート */
1328+ SortSpriteList();
1329+
1330+ /* スプライトリストに登録されたもののうちスプライトを順に描画 */
1331+ for( i = 0; i < g_SpriteCount; i++ )
1332+ {
1333+ float angle;
1334+ struct DXRubySprite *temp;
1335+
1336+ temp = g_SpriteList[i].sprite;
1337+
1338+ if( temp->vpflag == 1 )
1339+ {
1340+ D3DMATRIX matrix, matrix_t;
1341+ D3DVIEWPORT9 vp = ((struct DXRubyViewport *)temp->image)->viewport;
1342+
1343+ g_pD3DXSprite->lpVtbl->End( g_pD3DXSprite );
1344+ g_pD3DDevice->lpVtbl->EndScene( g_pD3DDevice );
1345+
1346+ matrix._11 = 1;matrix._12 = 0;matrix._13 = 0;matrix._14 = 0;
1347+ matrix._21 = 0;matrix._22 = -1;matrix._23 = 0;matrix._24 = 0;
1348+ matrix._31 = 0;matrix._32 = 0;matrix._33 = 1;matrix._34 = 0;
1349+ matrix._41 = 0;matrix._42 = 0;matrix._43 = 0;matrix._44 = 1;
1350+ g_pD3DDevice->lpVtbl->SetTransform( g_pD3DDevice, D3DTS_WORLDMATRIX(0), &matrix);
1351+ D3DXMatrixTranslation( &matrix_t, (float)-(vp.X + vp.Width)/2, (float)(vp.Y + vp.Height)/2, 0 );
1352+ D3DXMatrixScaling ( &matrix, (float)g_WindowInfo.width/vp.Width, (float)g_WindowInfo.height/vp.Height, 1 );
1353+ D3DXMatrixMultiply ( &matrix , &matrix_t, &matrix );
1354+ g_pD3DDevice->lpVtbl->SetTransform( g_pD3DDevice, D3DTS_VIEW, &matrix);
1355+ matrix._11 = 2.0f/g_WindowInfo.width;
1356+ matrix._12 = matrix._13 = matrix._14 = 0;
1357+ matrix._22 = 2.0f/g_WindowInfo.height;
1358+ matrix._21 = matrix._23 = matrix._24 = 0;
1359+ matrix._31 = matrix._32 = 0;matrix._33 = 0; matrix._34 = 0;
1360+ matrix._41 = matrix._42 = 0;matrix._43 = 1;matrix._44 = 1;
1361+ g_pD3DDevice->lpVtbl->SetTransform( g_pD3DDevice, D3DTS_PROJECTION, &matrix);
1362+ g_pD3DDevice->lpVtbl->SetViewport( g_pD3DDevice, &((struct DXRubyViewport *)temp->image)->viewport );
1363+ free( temp->image );
1364+
1365+ g_pD3DDevice->lpVtbl->BeginScene( g_pD3DDevice );
1366+ g_pD3DXSprite->lpVtbl->Begin( g_pD3DXSprite, D3DXSPRITE_ALPHABLEND );
1367+
1368+ continue;
1369+ }
1370+
1371+ if( temp->blendflag != oldflag )
1372+ {
1373+ switch( temp->blendflag )
1374+ {
1375+ case 0: /* 半透明合成 */
1376+ g_pD3DDevice->lpVtbl->SetRenderState(g_pD3DDevice, D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
1377+ g_pD3DDevice->lpVtbl->SetRenderState(g_pD3DDevice, D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
1378+ break;
1379+ case 4: /* 加算合成1の設定 */
1380+ g_pD3DDevice->lpVtbl->SetRenderState(g_pD3DDevice, D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
1381+ g_pD3DDevice->lpVtbl->SetRenderState(g_pD3DDevice, D3DRS_DESTBLEND, D3DBLEND_ONE);
1382+ break;
1383+ case 5: /* 加算合成2の設定 */
1384+ g_pD3DDevice->lpVtbl->SetRenderState(g_pD3DDevice, D3DRS_SRCBLEND, D3DBLEND_ONE);
1385+ g_pD3DDevice->lpVtbl->SetRenderState(g_pD3DDevice, D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
1386+ break;
1387+ case 6: /* 減算合成1の設定 */
1388+ g_pD3DDevice->lpVtbl->SetRenderState(g_pD3DDevice, D3DRS_SRCBLEND, D3DBLEND_ZERO);
1389+ g_pD3DDevice->lpVtbl->SetRenderState(g_pD3DDevice, D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
1390+ break;
1391+ case 7: /* 減算合成2の設定 */
1392+ g_pD3DDevice->lpVtbl->SetRenderState(g_pD3DDevice, D3DRS_SRCBLEND, D3DBLEND_ZERO);
1393+ g_pD3DDevice->lpVtbl->SetRenderState(g_pD3DDevice, D3DRS_DESTBLEND, D3DBLEND_INVSRCCOLOR);
1394+ break;
1395+ }
1396+ }
1397+
1398+ oldflag = temp->blendflag;
1399+
1400+ angle = 3.141592653589793115997963468544185161590576171875f / 180.0f * temp->angle;
1401+
1402+ if( temp->fontflag == 0)
1403+ {
1404+ TLVERTX VertexDataTbl[6];
1405+ struct DXRubyImage *image = temp->image;
1406+ float sina = sin(angle);
1407+ float cosa = cos(angle);
1408+ float data1x = temp->scalex * cosa;
1409+ float data2x = temp->scalex * sina;
1410+ float data1y = temp->scaley * sina;
1411+ float data2y = temp->scaley * cosa;
1412+ float tu1 = (image->x) / image->texture->width;
1413+ float tu2 = (image->x + image->width) / image->texture->width;
1414+ float tv1 = (image->y) / image->texture->height;
1415+ float tv2 = (image->y + image->height) / image->texture->height;
1416+ float centerx = -temp->centerx;
1417+ float centery = -temp->centery;
1418+ float width = image->width;
1419+ float height = image->height;
1420+ float basex = temp->x - centerx;
1421+ float basey = temp->y - centery;
1422+
1423+ /* 頂点1 */
1424+ VertexDataTbl[0].x = centerx * data1x - centery * data1y + basex - 0.5f;
1425+ VertexDataTbl[0].y = centerx * data2x + centery * data2y + basey - 0.5f;
1426+ /* 頂点2 */
1427+ VertexDataTbl[1].x = VertexDataTbl[3].x = (centerx+width) * data1x - centery * data1y + basex - 0.5f;
1428+ VertexDataTbl[1].y = VertexDataTbl[3].y = (centerx+width) * data2x + centery * data2y + basey - 0.5f;
1429+ /* 頂点3 */
1430+ VertexDataTbl[4].x = (centerx+width) * data1x - (centery+height) * data1y + basex - 0.5f;
1431+ VertexDataTbl[4].y = (centerx+width) * data2x + (centery+height) * data2y + basey - 0.5f;
1432+ /* 頂点4 */
1433+ VertexDataTbl[2].x = VertexDataTbl[5].x = centerx * data1x - (centery+height) * data1y + basex - 0.5f;
1434+ VertexDataTbl[2].y = VertexDataTbl[5].y = centerx * data2x + (centery+height) * data2y + basey - 0.5f;
1435+ /* 頂点色 */
1436+ VertexDataTbl[0].color =
1437+ VertexDataTbl[1].color =
1438+ VertexDataTbl[2].color =
1439+ VertexDataTbl[3].color =
1440+ VertexDataTbl[4].color =
1441+ VertexDataTbl[5].color = D3DCOLOR_ARGB(temp->alpha,255,255,255);
1442+ /* Z座標 */
1443+ VertexDataTbl[0].z =
1444+ VertexDataTbl[1].z =
1445+ VertexDataTbl[2].z =
1446+ VertexDataTbl[3].z =
1447+ VertexDataTbl[4].z =
1448+ VertexDataTbl[5].z = 0.0f;
1449+ /* rhw */
1450+ VertexDataTbl[0].rhw =
1451+ VertexDataTbl[1].rhw =
1452+ VertexDataTbl[2].rhw =
1453+ VertexDataTbl[3].rhw =
1454+ VertexDataTbl[4].rhw =
1455+ VertexDataTbl[5].rhw = 1.0f;
1456+ /* テクスチャ座標 */
1457+ VertexDataTbl[0].tu = VertexDataTbl[5].tu = VertexDataTbl[2].tu = tu1;
1458+ VertexDataTbl[0].tv = VertexDataTbl[1].tv = VertexDataTbl[3].tv = tv1;
1459+ VertexDataTbl[1].tu = VertexDataTbl[3].tu = VertexDataTbl[4].tu = tu2;
1460+ VertexDataTbl[4].tv = VertexDataTbl[5].tv = VertexDataTbl[2].tv = tv2;
1461+
1462+ /* テクスチャをセット */
1463+ g_pD3DDevice->lpVtbl->SetTexture(g_pD3DDevice, 0, (IDirect3DBaseTexture9*)image->texture->pD3DTexture);
1464+
1465+ /* デバイスに使用する頂点フォーマットをセット */
1466+ g_pD3DDevice->lpVtbl->SetFVF(g_pD3DDevice, D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1);
1467+
1468+ /* 描画 */
1469+ g_pD3DDevice->lpVtbl->DrawPrimitiveUP(g_pD3DDevice, D3DPT_TRIANGLELIST, 2, VertexDataTbl, sizeof(TLVERTX));
1470+ }
1471+ else
1472+ {
1473+ D3DVECTOR vector;
1474+ D3DXMATRIX matrix;
1475+ D3DXMATRIX matrix_t;
1476+ RECT rect;
1477+
1478+ /* 回転及び拡大縮小 */
1479+ D3DXMatrixScaling ( &matrix_t, temp->scalex, temp->scaley, 1 );
1480+ D3DXMatrixRotationZ ( &matrix , angle );
1481+ D3DXMatrixMultiply ( &matrix , &matrix_t, &matrix );
1482+
1483+ /* 平行移動 */
1484+ D3DXMatrixTranslation( &matrix_t, (float)temp->x + temp->centerx, (float)temp->y + temp->centery, 0 );
1485+ D3DXMatrixMultiply ( &matrix , &matrix, &matrix_t );
1486+
1487+ g_pD3DXSprite->lpVtbl->SetTransform( g_pD3DXSprite, &matrix );
1488+
1489+ rect.left = -temp->centerx;
1490+ rect.top = -temp->centery;
1491+ rect.right = temp->centerx;
1492+ rect.bottom = temp->centery;
1493+ ((struct DXRubyFontSprite *)temp->image)->font->pD3DXFont->lpVtbl->DrawText(((struct DXRubyFontSprite *)temp->image)->font->pD3DXFont, g_pD3DXSprite,
1494+ ((struct DXRubyFontSprite *)temp->image)->str,
1495+ -1,
1496+ &rect,
1497+ DT_LEFT | DT_NOCLIP,
1498+ ((int)temp->alpha << 24) | ((struct DXRubyFontSprite *)temp->image)->color & 0x00ffffff);
1499+ g_pD3DXSprite->lpVtbl->Flush( g_pD3DXSprite );
1500+ free( temp->image );
1501+ }
1502+ }
1503+
1504+ /* スプライトの描画終了 */
1505+ g_pD3DXSprite->lpVtbl->End( g_pD3DXSprite );
1506+
1507+ /* シーンの描画終了 */
1508+ g_pD3DDevice->lpVtbl->EndScene( g_pD3DDevice );
1509+ }
1510+
1511+ if( g_WindowInfo.windowed == Qnil || g_WindowInfo.windowed == Qfalse )
1512+ {
1513+ g_DrawTime = GetSystemCounter() - drawStartCounter;
1514+ }
1515+
1516+ /* シーンの表示 */
1517+ hr = g_pD3DDevice->lpVtbl->Present( g_pD3DDevice, NULL, NULL, NULL, NULL );
1518+
1519+ if( g_WindowInfo.windowed == Qnil || g_WindowInfo.windowed == Qfalse )
1520+ {
1521+ g_OldTime = GetSystemCounter();
1522+ }
1523+
1524+ g_SpriteCount = 0;
1525+ return obj;
1526+}
1527+
1528+
1529+/*--------------------------------------------------------------------
1530+ (内部関数)フレーム調整
1531+ ---------------------------------------------------------------------*/
1532+static VALUE Window_sync( VALUE obj )
1533+{
1534+ __int64 NowTime;
1535+ __int64 WaitTime;
1536+ static __int64 BeforeSecond = 0;
1537+ static int fps = 0;
1538+ static int skip = 0;
1539+
1540+ NowTime = GetSystemCounter();
1541+
1542+ /* ウィンドウモード時 */
1543+ if( g_WindowInfo.windowed != Qnil && g_WindowInfo.windowed != Qfalse )
1544+ {
1545+ g_OneFrameCount = NowTime - g_OldTime;
1546+ if ( g_WindowInfo.fps > 0 ) /* fps指定がnil or 0の時はWait処理しない */
1547+ {
1548+ __int64 SleepTime;
1549+
1550+ WaitTime = g_OneSecondCount / g_WindowInfo.fps;
1551+
1552+ /* もう既に前回から1フレーム分の時間が経っていたら */
1553+ if( g_OldTime + WaitTime < NowTime && skip == 0 )
1554+ {
1555+ /* コマ落ち制御しない場合 */
1556+ if( g_WindowInfo.frameskip == Qfalse )
1557+ {
1558+ fps++;
1559+ g_OldTime = NowTime;
1560+ }
1561+ else /* する場合 */
1562+ {
1563+ /* 今回はウェイトも描画もしない */
1564+ skip++;
1565+ g_SpriteCount = 0;
1566+ g_OldTime = g_OldTime + WaitTime;
1567+ }
1568+ }
1569+ else
1570+ {
1571+ /* 前回描画を飛ばしたのに今回も間に合ってない場合 */
1572+ if( g_OldTime + WaitTime < NowTime && skip == 1 )
1573+ {
1574+ /* 諦めて処理落ち */
1575+ g_OldTime = NowTime;
1576+ }
1577+ else
1578+ {
1579+ __int64 TempTime;
1580+ /* おおまかな時間をSleepで待つ */
1581+ TempTime = GetSystemCounter();
1582+ SleepTime = (WaitTime - (TempTime - g_OldTime)) * 1000 / g_OneSecondCount;
1583+ if( SleepTime > 2 )
1584+ {
1585+ Sleep( (unsigned long)(SleepTime - 2) );
1586+ }
1587+
1588+ TempTime = GetSystemCounter();
1589+
1590+ /* ループで厳密に処理をする */
1591+ for ( ; ; )
1592+ {
1593+ TempTime = GetSystemCounter();
1594+ if( g_OldTime + WaitTime < TempTime )
1595+ {
1596+ break;
1597+ }
1598+ }
1599+ g_OldTime = g_OldTime + WaitTime;
1600+ }
1601+ skip = 0;
1602+ fps++;
1603+ }
1604+ }
1605+ else
1606+ {
1607+ g_OldTime = NowTime;
1608+ fps++;
1609+ }
1610+
1611+ /* FPS値設定 */
1612+ if( (NowTime - BeforeSecond) >= g_OneSecondCount )
1613+ {
1614+ BeforeSecond = NowTime;
1615+ g_WindowInfo.fpscheck = fps;
1616+ fps = 0;
1617+ }
1618+ }
1619+ else
1620+ {
1621+ g_OneFrameCount = NowTime - g_OldTime + g_DrawTime;
1622+ WaitTime = g_OneSecondCount / g_WindowInfo.RefreshRate;
1623+
1624+ /* もう既に前回から1フレーム分の時間が経っていたら */
1625+ if( g_OldTime + WaitTime - g_DrawTime < NowTime && skip == 0 )
1626+ {
1627+ /* 今回はウェイトも描画もしない */
1628+ skip++;
1629+ g_SpriteCount = 0;
1630+// g_OldTime = NowTime;
1631+ return obj;
1632+ }
1633+
1634+ skip = 0;
1635+
1636+// g_OldTime = g_OldTime + WaitTime;
1637+ fps++;
1638+
1639+ /* FPS値設定 */
1640+ if( (NowTime - BeforeSecond) >= g_OneSecondCount )
1641+ {
1642+ BeforeSecond = NowTime;
1643+ g_WindowInfo.fpscheck = fps;
1644+ fps = 0;
1645+ }
1646+ }
1647+
1648+ return obj;
1649+}
1650+/*--------------------------------------------------------------------
1651+ (内部関数)フレーム調整用カウンタ値取得
1652+ ---------------------------------------------------------------------*/
1653+static __int64 GetSystemCounter( void )
1654+{
1655+ __int64 time;
1656+
1657+ if( g_isPerformanceCounter == 1 )
1658+ {
1659+ QueryPerformanceCounter( (LARGE_INTEGER *)&time );
1660+ return time;
1661+ }
1662+ else
1663+ {
1664+ return timeGetTime();
1665+ }
1666+}
1667+
1668+
1669+/*--------------------------------------------------------------------
1670+ ウィンドウのモード(ウィンドウ/全画面)を設定する。
1671+ ---------------------------------------------------------------------*/
1672+static VALUE Window_setwindowed( VALUE obj, VALUE windowed )
1673+{
1674+ g_WindowInfo.windowed = windowed;
1675+
1676+ if( g_WindowInfo.created == Qtrue )
1677+ {
1678+ g_WindowInfo.created = Qfalse;
1679+ Window_create( obj );
1680+ }
1681+
1682+ return g_WindowInfo.windowed;
1683+}
1684+
1685+
1686+/*--------------------------------------------------------------------
1687+ ウィンドウのモード(ウィンドウ/全画面)を取得する。
1688+ ---------------------------------------------------------------------*/
1689+static VALUE Window_getwindowed( VALUE obj )
1690+{
1691+ return g_WindowInfo.windowed;
1692+}
1693+
1694+
1695+/*--------------------------------------------------------------------
1696+ ウィンドウの位置(x座標)を設定する。
1697+ ---------------------------------------------------------------------*/
1698+static VALUE Window_setx( VALUE obj, VALUE x )
1699+{
1700+ if( g_WindowInfo.created == Qtrue )
1701+ {
1702+ rb_raise( eDXRubyError, "ウィンドウ作成後に設定を変更することはできません - Window_setx" );
1703+ }
1704+
1705+ g_WindowInfo.x = NUM2INT( x );
1706+ return x;
1707+}
1708+
1709+
1710+/*--------------------------------------------------------------------
1711+ ウィンドウの位置(y座標)を設定する。
1712+ ---------------------------------------------------------------------*/
1713+static VALUE Window_sety( VALUE obj , VALUE y )
1714+{
1715+ if( g_WindowInfo.created == Qtrue )
1716+ {
1717+ rb_raise( eDXRubyError, "ウィンドウ作成後に設定を変更することはできません - Window_sety" );
1718+ }
1719+
1720+ g_WindowInfo.y = NUM2INT( y );
1721+ return y;
1722+}
1723+
1724+
1725+/*--------------------------------------------------------------------
1726+ ウィンドウのサイズ(幅)を設定する。
1727+ ---------------------------------------------------------------------*/
1728+static VALUE Window_setwidth( VALUE obj, VALUE vwidth )
1729+{
1730+ int width;
1731+
1732+ if( g_WindowInfo.created == Qtrue )
1733+ {
1734+ rb_raise( eDXRubyError, "ウィンドウ作成後に設定を変更することはできません - Window_setwidth" );
1735+ }
1736+
1737+ width = NUM2INT( vwidth );
1738+ if( width < 0 )
1739+ {
1740+ width = 0;
1741+ }
1742+
1743+ g_WindowInfo.width = width;
1744+ return vwidth;
1745+}
1746+
1747+
1748+/*--------------------------------------------------------------------
1749+ ウィンドウのサイズ(高さ)を設定する。
1750+ ---------------------------------------------------------------------*/
1751+static VALUE Window_setheight( VALUE obj , VALUE vheight)
1752+{
1753+ int height;
1754+
1755+ if( g_WindowInfo.created == Qtrue )
1756+ {
1757+ rb_raise( eDXRubyError, "ウィンドウ作成後に設定を変更することはできません - Window_setheight" );
1758+ }
1759+
1760+ height = NUM2INT( vheight );
1761+ if( height < 0 )
1762+ {
1763+ height = 0;
1764+ }
1765+
1766+ g_WindowInfo.height = height;
1767+ return vheight;
1768+}
1769+
1770+
1771+/*--------------------------------------------------------------------
1772+ ウィンドウの位置(x座標)を返す。
1773+ ---------------------------------------------------------------------*/
1774+static VALUE Window_x( VALUE obj )
1775+{
1776+ return INT2FIX( g_WindowInfo.x );
1777+}
1778+
1779+
1780+/*--------------------------------------------------------------------
1781+ ウィンドウの位置(y座標)を返す。
1782+ ---------------------------------------------------------------------*/
1783+static VALUE Window_y( VALUE obj )
1784+{
1785+ return INT2FIX( g_WindowInfo.y );
1786+}
1787+
1788+
1789+/*--------------------------------------------------------------------
1790+ ウィンドウのサイズ(幅)を返す。
1791+ ---------------------------------------------------------------------*/
1792+static VALUE Window_width( VALUE obj )
1793+{
1794+ return INT2FIX( g_WindowInfo.width );
1795+}
1796+
1797+
1798+/*--------------------------------------------------------------------
1799+ ウィンドウのサイズ(高さ)を返す。
1800+ ---------------------------------------------------------------------*/
1801+static VALUE Window_height( VALUE obj )
1802+{
1803+ return INT2FIX( g_WindowInfo.height );
1804+}
1805+
1806+
1807+/*--------------------------------------------------------------------
1808+ ウィンドウタイトル取得
1809+ ---------------------------------------------------------------------*/
1810+static VALUE Window_getCaption( VALUE obj )
1811+{
1812+ char buf[256];
1813+
1814+ GetWindowText( g_hWind, buf, 256 );
1815+
1816+ return rb_str_new2( buf );
1817+}
1818+
1819+
1820+/*--------------------------------------------------------------------
1821+ ウィンドウタイトル設定
1822+ ---------------------------------------------------------------------*/
1823+static VALUE Window_setCaption( VALUE obj, VALUE caption )
1824+{
1825+ Check_Type(caption, T_STRING);
1826+
1827+ SetWindowText( g_hWind, RSTRING_PTR( caption ) );
1828+
1829+ return caption;
1830+}
1831+
1832+
1833+/*--------------------------------------------------------------------
1834+ ウィンドウのサイズ倍率を取得する
1835+ ---------------------------------------------------------------------*/
1836+static VALUE Window_getScale( VALUE obj )
1837+{
1838+ return rb_float_new( g_WindowInfo.scale );
1839+}
1840+
1841+
1842+/*--------------------------------------------------------------------
1843+ ウィンドウのサイズ倍率を設定する
1844+ ---------------------------------------------------------------------*/
1845+static VALUE Window_setScale( VALUE obj, VALUE scale )
1846+{
1847+ g_WindowInfo.scale = NUM2DBL(scale);
1848+
1849+ return scale;
1850+}
1851+
1852+
1853+/*--------------------------------------------------------------------
1854+ fps値を設定する
1855+ ---------------------------------------------------------------------*/
1856+static VALUE Window_getrealfps( VALUE obj )
1857+{
1858+ return INT2FIX( g_WindowInfo.fpscheck );
1859+}
1860+
1861+
1862+/*--------------------------------------------------------------------
1863+ fps値を取得する
1864+ ---------------------------------------------------------------------*/
1865+static VALUE Window_getfps( VALUE obj )
1866+{
1867+ return INT2FIX( g_WindowInfo.fpscheck );
1868+}
1869+
1870+
1871+/*--------------------------------------------------------------------
1872+ fps値を設定する
1873+ ---------------------------------------------------------------------*/
1874+static VALUE Window_setfps( VALUE obj, VALUE fps )
1875+{
1876+ g_WindowInfo.fps = fps == Qnil ? 0 : NUM2INT(fps);
1877+
1878+ return fps;
1879+}
1880+
1881+
1882+/*--------------------------------------------------------------------
1883+ 縮小フィルタ取得
1884+ ---------------------------------------------------------------------*/
1885+static VALUE Window_getMinFilter( VALUE obj )
1886+{
1887+ return INT2FIX( g_WindowInfo.minfilter );
1888+}
1889+
1890+
1891+/*--------------------------------------------------------------------
1892+ 縮小フィルタ設定
1893+ ---------------------------------------------------------------------*/
1894+static VALUE Window_setMinFilter( VALUE obj, VALUE minfilter )
1895+{
1896+ g_WindowInfo.minfilter = FIX2INT( minfilter );
1897+ return minfilter;
1898+}
1899+
1900+
1901+/*--------------------------------------------------------------------
1902+ 拡大フィルタ取得
1903+ ---------------------------------------------------------------------*/
1904+static VALUE Window_getMagFilter( VALUE obj )
1905+{
1906+ return INT2FIX( g_WindowInfo.minfilter );
1907+}
1908+
1909+
1910+/*--------------------------------------------------------------------
1911+ 拡大フィルタ設定
1912+ ---------------------------------------------------------------------*/
1913+static VALUE Window_setMagFilter( VALUE obj, VALUE magfilter )
1914+{
1915+ g_WindowInfo.magfilter = FIX2INT( magfilter );
1916+ return magfilter;
1917+}
1918+
1919+
1920+/*--------------------------------------------------------------------
1921+ 1フレームの処理負荷を%で取得する
1922+ ---------------------------------------------------------------------*/
1923+static VALUE Window_getload( VALUE obj )
1924+{
1925+ if( g_WindowInfo.fps == 0 )
1926+ {
1927+ return INT2FIX( 0 );
1928+ }
1929+ return rb_float_new( (double) ( (double)g_OneFrameCount * 100.0 / ((double)g_OneSecondCount / (double)g_WindowInfo.fps )) );
1930+}
1931+
1932+
1933+/*--------------------------------------------------------------------
1934+ ウィンドウハンドルを取得する
1935+ ---------------------------------------------------------------------*/
1936+static VALUE Window_gethWnd( VALUE obj )
1937+{
1938+ return INT2NUM( (int)g_hWind );
1939+}
1940+
1941+
1942+/*--------------------------------------------------------------------
1943+ フレームスキップon/offを取得する
1944+ ---------------------------------------------------------------------*/
1945+static VALUE Window_getframeskip( VALUE obj )
1946+{
1947+ return g_WindowInfo.frameskip;
1948+}
1949+
1950+
1951+/*--------------------------------------------------------------------
1952+ フレームスキップon/offを設定する
1953+ ---------------------------------------------------------------------*/
1954+static VALUE Window_setframeskip( VALUE obj, VALUE skip )
1955+{
1956+ g_WindowInfo.frameskip = (skip == Qnil || skip == Qfalse) ? Qfalse : Qtrue;
1957+
1958+ return skip;
1959+}
1960+
1961+
1962+/*--------------------------------------------------------------------
1963+ ウィンドウアイコンを設定する
1964+ ---------------------------------------------------------------------*/
1965+static VALUE Window_loadIcon( VALUE obj, VALUE filename )
1966+{
1967+ Check_Type( filename, T_STRING );
1968+ g_WindowInfo.hIcon = LoadImage( 0, RSTRING_PTR(filename), IMAGE_ICON, 16, 16, LR_DEFAULTSIZE|LR_LOADFROMFILE );
1969+ if( g_WindowInfo.hIcon == NULL )
1970+ {
1971+ rb_raise( eDXRubyError, "アイコン画像ファイルのロードに失敗しました - Window_loadIcon" );
1972+ }
1973+
1974+ SendMessage(g_hWind, WM_SETICON, (WPARAM)ICON_SMALL, (LPARAM)g_WindowInfo.hIcon);
1975+
1976+ return Qnil;
1977+}
1978+
1979+
1980+/*--------------------------------------------------------------------
1981+ ファイルオープンダイアログを表示する
1982+ ---------------------------------------------------------------------*/
1983+static VALUE Window_openDialog(VALUE obj, VALUE vfilter, VALUE vtitle)
1984+{
1985+ OPENFILENAME OFN;
1986+ char buf[MAX_PATH*2];
1987+ VALUE filter;
1988+ buf[0] = 0;
1989+
1990+ Check_Type(vfilter, T_ARRAY);
1991+ Check_Type(vtitle, T_STRING);
1992+
1993+ ZeroMemory(&OFN,sizeof(OPENFILENAME));
1994+ OFN.lStructSize = sizeof(OPENFILENAME);
1995+ OFN.hwndOwner = g_hWind;
1996+
1997+ OFN.lpstrFilter = "すべてのファイル (*.*)\0*.*\0\0";
1998+ filter = rb_ary_join( vfilter, rb_str_new( "\0", 1 ) );
1999+ filter = rb_str_cat( filter, "\0", 1 );
2000+ OFN.lpstrFilter = RSTRING_PTR(filter);
2001+ OFN.lpstrFile = buf;
2002+ OFN.nMaxFile = MAX_PATH*2;
2003+ OFN.Flags = OFN_FILEMUSTEXIST;
2004+ OFN.lpstrTitle = RSTRING_PTR(vtitle);
2005+ OFN.lpstrDefExt = 0;
2006+ if( !GetOpenFileName(&OFN) )
2007+ {
2008+ return Qnil;
2009+ }
2010+
2011+ return rb_str_new2( buf );
2012+}
2013+
2014+
2015+/*--------------------------------------------------------------------
2016+ ファイルセーブダイアログを表示する
2017+ ---------------------------------------------------------------------*/
2018+static VALUE Window_saveDialog(VALUE obj, VALUE vfilter, VALUE vtitle)
2019+{
2020+ OPENFILENAME OFN;
2021+ char buf[MAX_PATH*2];
2022+ VALUE filter;
2023+ buf[0] = 0;
2024+
2025+ Check_Type(vfilter, T_ARRAY);
2026+ Check_Type(vtitle, T_STRING);
2027+
2028+ ZeroMemory(&OFN,sizeof(OPENFILENAME));
2029+ OFN.lStructSize = sizeof(OPENFILENAME);
2030+ OFN.hwndOwner = g_hWind;
2031+
2032+ OFN.lpstrFilter = "すべてのファイル (*.*)\0*.*\0\0";
2033+ filter = rb_ary_join( vfilter, rb_str_new( "\0", 1 ) );
2034+ filter = rb_str_cat( filter, "\0", 1 );
2035+ OFN.lpstrFilter = RSTRING_PTR(filter);
2036+ OFN.lpstrFile = buf;
2037+ OFN.nMaxFile = MAX_PATH*2;
2038+ OFN.Flags = OFN_CREATEPROMPT | OFN_OVERWRITEPROMPT;
2039+ OFN.lpstrTitle = RSTRING_PTR(vtitle);
2040+ OFN.lpstrDefExt = 0;
2041+ if( !GetSaveFileName(&OFN) )
2042+ {
2043+ return Qnil;
2044+ }
2045+
2046+ return rb_str_new2( buf );
2047+}
2048+
2049+
2050+/*--------------------------------------------------------------------
2051+ 終了時に実行する
2052+ ---------------------------------------------------------------------*/
2053+static VALUE Window_shutdown( VALUE obj )
2054+{
2055+ /* アイコンリソース解放 */
2056+ if( g_WindowInfo.hIcon != 0 )
2057+ {
2058+ DestroyIcon(g_WindowInfo.hIcon);
2059+ }
2060+
2061+ /* マウス状態復元 */
2062+ if( g_WindowInfo.enablemouse == Qfalse )
2063+ {
2064+ int c;
2065+ c = ShowCursor( TRUE );
2066+ while( c < 0 ) c = ShowCursor( TRUE );
2067+ }
2068+
2069+ /* リスト解放 */
2070+ g_SpriteCount = 0;
2071+
2072+// /* 動画再生用インターフェイスの解放 */
2073+// if( g_pGraphBuilder != NULL )
2074+// {
2075+// g_pMediaControl->lpVtbl->Stop( g_pMediaControl );
2076+// RELEASE( g_pMediaEventEx );
2077+// RELEASE( g_pVideoWindow );
2078+// RELEASE( g_pMediaControl );
2079+// RELEASE( g_pGraphBuilder );
2080+// }
2081+
2082+ /* DirectX解放 */
2083+ Window_DirectXRelease();
2084+
2085+ /* ウインドウ・クラスの登録解除 */
2086+ UnregisterClass( "DXRuby", g_hInstance );
2087+
2088+ /* フレーム調整の後始末 */
2089+ timeEndPeriod( 1 );
2090+
2091+ g_iRefAll--;
2092+ if( g_iRefAll == 0 )
2093+ {
2094+ CoUninitialize();
2095+ }
2096+
2097+ return obj;
2098+}
2099+
2100+
2101+/*--------------------------------------------------------------------
2102+ DirectXオブジェクトを解放する
2103+ ---------------------------------------------------------------------*/
2104+void Window_DirectXRelease()
2105+{
2106+ int i;
2107+ HRESULT hr;
2108+
2109+ /* スプライトオブジェクトの使用終了 */
2110+ if( g_pD3DXSprite )
2111+ {
2112+ g_pD3DXSprite->lpVtbl->OnLostDevice( g_pD3DXSprite );
2113+ }
2114+
2115+ /* スプライトオブジェクト破棄 */
2116+ RELEASE( g_pD3DXSprite );
2117+
2118+ for( i = 0 ; i < g_JoystickCount; i++ )
2119+ {
2120+ /* DirectInputDevice(JoyPad)オブジェクトの使用終了 */
2121+ if( g_pDIDJoyPad[i] )
2122+ {
2123+ g_pDIDJoyPad[i]->lpVtbl->Unacquire( g_pDIDJoyPad[i] );
2124+ }
2125+
2126+ /* DirectInputDevide(JoyPad)オブジェクトの破棄 */
2127+ RELEASE( g_pDIDJoyPad[i] );
2128+ }
2129+
2130+ /* DirectInputDevice(Keyboard)オブジェクトの使用終了 */
2131+ if( g_pDIDKeyBoard )
2132+ {
2133+ g_pDIDKeyBoard->lpVtbl->Unacquire( g_pDIDKeyBoard );
2134+ }
2135+
2136+ /* DirectInputDevide(Keyboard)オブジェクトの破棄 */
2137+ RELEASE( g_pDIDKeyBoard );
2138+
2139+ /* DirectInputオブジェクトの破棄 */
2140+ RELEASE( g_pDInput );
2141+
2142+ /* Direct3D Deviceオブジェクトの破棄 */
2143+ RELEASE( g_pD3DDevice );
2144+
2145+ /* Direct3Dオブジェクトの破棄 */
2146+ RELEASE( g_pD3D );
2147+}
2148+
2149+
2150+/*--------------------------------------------------------------------
2151+ スクリーンショットを撮る
2152+ ---------------------------------------------------------------------*/
2153+static VALUE Window_getScreenShot( int argc, VALUE *argv, VALUE obj )
2154+{
2155+ HRESULT hr;
2156+ D3DDISPLAYMODE dmode;
2157+ LPDIRECT3DSURFACE9 pSurface;
2158+ RECT rect;
2159+ VALUE filename, format;
2160+
2161+ rb_scan_args( argc, argv, "11", &filename, &format );
2162+
2163+ Check_Type( filename, T_STRING );
2164+
2165+ /* 現在のディスプレイのフォーマットなどを取得 */
2166+ hr = g_pD3D->lpVtbl->GetAdapterDisplayMode(g_pD3D, D3DADAPTER_DEFAULT, &dmode);
2167+ if( FAILED( hr ) )
2168+ {
2169+ rb_raise( eDXRubyError, "キャプチャに失敗しました - GetAdapterDisplayMode" );
2170+ }
2171+
2172+ /* キャプチャ用サーフェス作成 */
2173+ hr = g_pD3DDevice->lpVtbl->CreateOffscreenPlainSurface(g_pD3DDevice,
2174+ dmode.Width,
2175+ dmode.Height,
2176+ D3DFMT_A8R8G8B8,
2177+ D3DPOOL_SCRATCH, &pSurface, NULL);
2178+ if( FAILED( hr ) )
2179+ {
2180+ rb_raise( eDXRubyError, "キャプチャに失敗しました - CreateOffscreenPlainSurface" );
2181+ }
2182+ /* キャプチャ */
2183+ hr = g_pD3DDevice->lpVtbl->GetFrontBufferData(g_pD3DDevice, 0, pSurface);
2184+ if( FAILED( hr ) )
2185+ {
2186+ RELEASE(pSurface);
2187+ rb_raise( eDXRubyError, "キャプチャに失敗しました - GetFrontBufferData" );
2188+ }
2189+
2190+ /* サーフェスの保存 */
2191+ if( g_D3DPP.Windowed )
2192+ {
2193+ POINT p = { 0, 0 };
2194+ ClientToScreen(g_hWind , &p);
2195+ rect.left = p.x; rect.top = p.y;
2196+ p.x = g_D3DPP.BackBufferWidth * g_WindowInfo.scale;
2197+ p.y = g_D3DPP.BackBufferHeight * g_WindowInfo.scale;
2198+ ClientToScreen(g_hWind, &p);
2199+ rect.right = p.x; rect.bottom = p.y;
2200+ }
2201+ hr = D3DXSaveSurfaceToFile(
2202+ RSTRING_PTR( filename ), /* 保存ファイル名 */
2203+ format == Qnil ? D3DXIFF_JPG : FIX2INT( format ), /* ファイルフォーマット */
2204+ pSurface, /* 保存するサーフェス */
2205+ NULL, /* パレット */
2206+ g_D3DPP.Windowed ? &rect : NULL); /* 保存領域 */
2207+ RELEASE(pSurface);
2208+ if( FAILED( hr ) )
2209+ {
2210+ rb_raise( eDXRubyError, "キャプチャに失敗しました - D3DXSaveSurfaceToFile" );
2211+ }
2212+
2213+ return obj;
2214+}
2215+
2216+
2217+///*--------------------------------------------------------------------
2218+// 動画を再生する
2219+// ---------------------------------------------------------------------*/
2220+//static VALUE Window_playMovie( VALUE obj, VALUE vfilename )
2221+//{
2222+// HRESULT hr;
2223+// WCHAR filename [ MAX_PATH ] ;
2224+//
2225+// Check_Type( vfilename, T_STRING );
2226+// MultiByteToWideChar ( CP_ACP, 0, RSTRING_PTR(vfilename), -1, filename, MAX_PATH );
2227+//
2228+// // IGraphBuilderインターフェイスの取得
2229+// hr = CoCreateInstance( &CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, &IID_IGraphBuilder, (void **)(&g_pGraphBuilder) );
2230+//
2231+// if( FAILED( hr ) )
2232+// {
2233+// rb_raise( eDXRubyError, "IGraphBuilderインターフェイスの取得に失敗しました - Window_playMovie" );
2234+// }
2235+//
2236+// // IMediaControlインターフェイスの取得
2237+// hr = g_pGraphBuilder->lpVtbl->QueryInterface( g_pGraphBuilder, &IID_IMediaControl, (void**)(&g_pMediaControl) );
2238+// if( FAILED( hr ) )
2239+// {
2240+// rb_raise( eDXRubyError, "IMediaControlインターフェイスの取得に失敗しました - Window_playMovie" );
2241+// }
2242+//
2243+// hr = g_pGraphBuilder->lpVtbl->QueryInterface( g_pGraphBuilder, &IID_IVideoWindow, (LPVOID *)&g_pVideoWindow );
2244+// if( FAILED( hr ) )
2245+// {
2246+// rb_raise( eDXRubyError, "IVideoWindowインターフェイスの取得に失敗しました - Window_playMovie" );
2247+// }
2248+//
2249+// hr = g_pGraphBuilder->lpVtbl->RenderFile( g_pGraphBuilder, filename, NULL );
2250+// if( FAILED( hr ) )
2251+// {
2252+// rb_raise( eDXRubyError, "ファイルの読み込みに失敗しました - Window_playMovie" );
2253+// }
2254+//
2255+// g_pVideoWindow->lpVtbl->put_Owner( g_pVideoWindow, (OAHWND)g_hWind );
2256+// g_pVideoWindow->lpVtbl->put_WindowStyle( g_pVideoWindow, WS_CHILD|WS_CLIPSIBLINGS );
2257+// g_pVideoWindow->lpVtbl->SetWindowPosition( g_pVideoWindow,0, 0, g_WindowInfo.width, g_WindowInfo.height );
2258+//
2259+// // メディア再生
2260+// hr = g_pMediaControl->lpVtbl->Run( g_pMediaControl );
2261+// if( FAILED( hr ) )
2262+// {
2263+// rb_raise( eDXRubyError, "再生に失敗しました - Window_playMovie" );
2264+// }
2265+//
2266+// g_PlayingMovie = 1;
2267+//// g_pMediaControl->lpVtbl->Stop( g_pMediaControl );
2268+// return obj;
2269+//}
2270+
2271+
2272+
2273+/*********************************************************************
2274+ * Imageクラス
2275+ *
2276+ * 描画用の画像を保持するクラス。
2277+ * ファイル名を渡してloadすると読み込まれ、Window::drawに渡して描画する。
2278+ *********************************************************************/
2279+
2280+/*--------------------------------------------------------------------
2281+ 参照されなくなったときにGCから呼ばれる関数
2282+ ---------------------------------------------------------------------*/
2283+static void release_Image( struct DXRubyImage* image )
2284+{
2285+ /* テクスチャオブジェクトの開放 */
2286+ if( image )
2287+ {
2288+ if( image->texture )
2289+ {
2290+ image->texture->refcount--;
2291+ if( image->texture->refcount == 0 )
2292+ {
2293+ RELEASE( image->texture->pD3DTexture );
2294+ free( image->texture );
2295+ }
2296+ }
2297+ free( image );
2298+ image = NULL;
2299+
2300+ g_iRefAll--;
2301+ if( g_iRefAll == 0 )
2302+ {
2303+ CoUninitialize();
2304+ }
2305+ }
2306+}
2307+
2308+
2309+/*--------------------------------------------------------------------
2310+ Imgaeクラスのallocate。メモリを確保する為にinitialize前に呼ばれる。
2311+ ---------------------------------------------------------------------*/
2312+static VALUE Image_allocate( VALUE klass )
2313+{
2314+ VALUE obj;
2315+ struct DXRubyImage *image;
2316+
2317+ /* DXRubyImageのメモリ取得&Imageオブジェクト生成 */
2318+ image = malloc(sizeof(struct DXRubyImage));
2319+ if( image == NULL ) rb_raise( eDXRubyError, "メモリの取得に失敗しました - Image_allocate" );
2320+ obj = Data_Wrap_Struct(klass, 0, release_Image, image);
2321+
2322+ /* とりあえずテクスチャオブジェクトはNULLにしておく */
2323+ image->texture = NULL;
2324+
2325+ return obj;
2326+}
2327+
2328+
2329+/*--------------------------------------------------------------------
2330+ イメージのデータ設定(内部処理用box描画)
2331+ ---------------------------------------------------------------------*/
2332+static void fill( int x1, int y1, int x2, int y2, int col, struct DXRubyImage *image )
2333+{
2334+ D3DLOCKED_RECT texrect;
2335+ int x, y;
2336+ RECT rect;
2337+ int *p;
2338+
2339+ rect.left = x1 + image->x;
2340+ rect.top = y1 + image->y;
2341+ rect.right = x2 + image->x + 1;
2342+ rect.bottom = y2 + image->y + 1;
2343+ image->texture->pD3DTexture->lpVtbl->LockRect( image->texture->pD3DTexture, 0, &texrect, &rect, 0 );
2344+ for( y = 0; y <= y2 - y1; y++ )
2345+ {
2346+ p = (int*)((char *)texrect.pBits + y * texrect.Pitch);
2347+ for( x = 0; x <= x2 - x1; x++ )
2348+ {
2349+ *(p++) = col;
2350+ }
2351+ }
2352+ image->texture->pD3DTexture->lpVtbl->UnlockRect( image->texture->pD3DTexture, 0 );
2353+ return;
2354+}
2355+
2356+
2357+/*--------------------------------------------------------------------
2358+ 配列から色取得
2359+ ---------------------------------------------------------------------*/
2360+static int array2color( VALUE color )
2361+{
2362+ int col;
2363+
2364+ Check_Type(color, T_ARRAY);
2365+ if( RARRAY_LEN( color ) < 3 ) rb_raise( eDXRubyError, "配列から色の取得に失敗しました - getcolor" );
2366+
2367+ if( RARRAY_LEN( color ) == 3 )
2368+ {
2369+ col = D3DCOLOR_ARGB(255, NUM2INT(rb_ary_entry(color, 0)), NUM2INT(rb_ary_entry(color, 1)), NUM2INT(rb_ary_entry(color, 2)));
2370+ }
2371+ else
2372+ {
2373+ col = D3DCOLOR_ARGB(NUM2INT(rb_ary_entry(color, 0)), NUM2INT(rb_ary_entry(color, 1)),
2374+ NUM2INT(rb_ary_entry(color, 2)), NUM2INT(rb_ary_entry(color, 3)));
2375+ }
2376+ return col;
2377+}
2378+
2379+
2380+/*--------------------------------------------------------------------
2381+ ImgaeクラスのInitialize
2382+ ---------------------------------------------------------------------*/
2383+static VALUE Image_initialize( int argc, VALUE *argv, VALUE obj )
2384+{
2385+ struct DXRubyImage *image;
2386+ struct DXRubyTexture *texture;
2387+ HRESULT hr;
2388+ D3DSURFACE_DESC desc;
2389+ VALUE vwidth, vheight, vary;
2390+ int col = 0, width, height;
2391+
2392+ g_iRefAll++;
2393+
2394+ rb_scan_args( argc, argv, "21", &vwidth, &vheight, &vary );
2395+
2396+ width = NUM2INT( vwidth );
2397+ height = NUM2INT( vheight );
2398+
2399+ if( width <= 0 || height <= 0 )
2400+ {
2401+ rb_raise( eDXRubyError, "Imageオブジェクトの作成に失敗しました - Image_initialize" );
2402+ }
2403+
2404+ if( vary != Qnil )
2405+ {
2406+ Check_Type( vary, T_ARRAY );
2407+ col = array2color( vary );
2408+ }
2409+
2410+ /* テクスチャメモリ取得 */
2411+ texture = (struct DXRubyTexture *)malloc( sizeof( struct DXRubyTexture ) );
2412+
2413+ if( texture == NULL )
2414+ {
2415+ rb_raise( eDXRubyError, "画像用メモリの取得に失敗しました - Image_initialize" );
2416+ }
2417+
2418+ /* テクスチャオブジェクトを作成する */
2419+ hr = D3DXCreateTexture( g_pD3DDevice, width, height,
2420+ 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED,
2421+ &texture->pD3DTexture);
2422+
2423+ if( FAILED( hr ) )
2424+ {
2425+ rb_raise( eDXRubyError, "テクスチャの作成に失敗しました - Image_initialize" );
2426+ }
2427+
2428+ texture->refcount = 1;
2429+
2430+ texture->pD3DTexture->lpVtbl->GetLevelDesc(texture->pD3DTexture, 0, &desc );
2431+ texture->width = desc.Width;
2432+ texture->height = desc.Height;
2433+
2434+ /* Imageオブジェクト設定 */
2435+ Data_Get_Struct( obj, struct DXRubyImage, image );
2436+
2437+ image->texture = texture;
2438+ image->x = 0;
2439+ image->y = 0;
2440+ image->width = width;
2441+ image->height = height;
2442+
2443+ fill( 0, 0, width - 1, height - 1, col, image );
2444+
2445+ return obj;
2446+}
2447+
2448+
2449+/*--------------------------------------------------------------------
2450+ Imgaeクラスのload
2451+ ---------------------------------------------------------------------*/
2452+static VALUE Image_load( int argc, VALUE *argv, VALUE klass )
2453+{
2454+ struct DXRubyImage *image;
2455+ struct DXRubyTexture *texture;
2456+ D3DXIMAGE_INFO srcinfo;
2457+ D3DSURFACE_DESC desc;
2458+ HRESULT hr;
2459+ VALUE filename, vx, vy, vwidth, vheight, obj;
2460+ int x, y, width, height;
2461+
2462+ /* デバイスオブジェクトの初期化チェック */
2463+ if( g_pD3DDevice == NULL )
2464+ {
2465+ rb_raise( eDXRubyError, "DirectX Graphicsが初期化されていません" );
2466+ }
2467+
2468+ rb_scan_args( argc, argv, "14", &filename, &vx, &vy, &vwidth, &vheight );
2469+
2470+ Check_Type(filename, T_STRING);
2471+
2472+ /* ファイル情報取得 */
2473+ hr = D3DXGetImageInfoFromFile( RSTRING_PTR( filename ), &srcinfo );
2474+
2475+ if( FAILED( hr ) )
2476+ {
2477+ rb_raise( eDXRubyError, "ファイルの読み込みに失敗しました - %s", RSTRING_PTR( filename ) );
2478+ }
2479+
2480+ if( vx == Qnil )
2481+ {
2482+ x = 0;
2483+ y = 0;
2484+ width = srcinfo.Width;
2485+ height = srcinfo.Height;
2486+ }
2487+ else
2488+ {
2489+ x = NUM2INT( vx );
2490+ y = vy == Qnil ? 0 : NUM2INT( vy );
2491+ if( x < 0 || x >= srcinfo.Width || y < 0 || y >= srcinfo.Height )
2492+ {
2493+ rb_raise( eDXRubyError, "画像の原点位置が異常値です(x=%d,y=%d, tex_width=%d,tex_height=%d) - Image_load", x, y, srcinfo.Width, srcinfo.Height );
2494+ }
2495+ width = vwidth == Qnil ? srcinfo.Width - x : NUM2INT( vwidth );
2496+ height = vheight == Qnil ? srcinfo.Height - y : NUM2INT( vheight );
2497+ if( srcinfo.Width - x < width || x + width > srcinfo.Width || srcinfo.Height - y < height || y + height > srcinfo.Height ||
2498+ width < 0 || height < 0 )
2499+ {
2500+ rb_raise( eDXRubyError, "画像のサイズが異常値です - Image_load" );
2501+ }
2502+ }
2503+
2504+ /* テクスチャロード */
2505+ texture = Image_textureload( RSTRING_PTR( filename ), &srcinfo );
2506+ texture->refcount = 1;
2507+
2508+ texture->pD3DTexture->lpVtbl->GetLevelDesc(texture->pD3DTexture, 0, &desc );
2509+ texture->width = desc.Width;
2510+ texture->height = desc.Height;
2511+
2512+ /* Imageオブジェクト設定 */
2513+ image = malloc(sizeof(struct DXRubyImage));
2514+ if( image == NULL ) rb_raise( eDXRubyError, "メモリの取得に失敗しました - Image_load" );
2515+ obj = Data_Wrap_Struct(cImage, 0, release_Image, image);
2516+
2517+ image->texture = texture;
2518+ image->x = x;
2519+ image->y = y;
2520+ image->width = width;
2521+ image->height = height;
2522+
2523+ g_iRefAll++;
2524+
2525+ return obj;
2526+}
2527+
2528+
2529+/*--------------------------------------------------------------------
2530+ ImgaeクラスのloadFromFileInMemory
2531+ ---------------------------------------------------------------------*/
2532+static VALUE Image_loadFromFileInMemory( VALUE klass, VALUE vstring )
2533+{
2534+ struct DXRubyImage *image;
2535+ struct DXRubyTexture *texture;
2536+ D3DXIMAGE_INFO srcinfo;
2537+ D3DSURFACE_DESC desc;
2538+ HRESULT hr;
2539+ VALUE obj;
2540+ int size, x, y, width, height;
2541+
2542+ /* デバイスオブジェクトの初期化チェック */
2543+ if( g_pD3DDevice == NULL )
2544+ {
2545+ rb_raise( eDXRubyError, "DirectX Graphicsが初期化されていません" );
2546+ }
2547+
2548+ Check_Type(vstring, T_STRING);
2549+ size = RSTRING_LEN( vstring );
2550+
2551+ /* ファイル情報取得 */
2552+ hr = D3DXGetImageInfoFromFileInMemory( RSTRING_PTR( vstring ), size, &srcinfo );
2553+
2554+ if( FAILED( hr ) )
2555+ {
2556+ rb_raise( eDXRubyError, "イメージデータの読み込みに失敗しました - Image_loadFromFileInMemory" );
2557+ }
2558+
2559+ /* テクスチャメモリ取得 */
2560+ texture = (struct DXRubyTexture *)malloc( sizeof( struct DXRubyTexture ) );
2561+
2562+ if( texture == NULL )
2563+ {
2564+ rb_raise( eDXRubyError, "画像用メモリの取得に失敗しました - Image_loadFromFileInMemory" );
2565+ }
2566+
2567+ /* ファイルを読み込んでテクスチャオブジェクトを作成する */
2568+ hr = D3DXCreateTextureFromFileInMemoryEx( g_pD3DDevice, RSTRING_PTR( vstring ), size, srcinfo.Width, srcinfo.Height, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED,
2569+ D3DX_DEFAULT, D3DX_DEFAULT, 0,
2570+ 0, 0, &texture->pD3DTexture);
2571+
2572+ if( FAILED( hr ) )
2573+ {
2574+ rb_raise( eDXRubyError, "イメージデータの読み込みに失敗しました - Image_loadFromFileInMemory" );
2575+ }
2576+
2577+ texture->refcount = 1;
2578+
2579+ texture->pD3DTexture->lpVtbl->GetLevelDesc(texture->pD3DTexture, 0, &desc );
2580+ texture->width = desc.Width;
2581+ texture->height = desc.Height;
2582+
2583+ /* Imageオブジェクト設定 */
2584+ image = malloc(sizeof(struct DXRubyImage));
2585+ if( image == NULL ) rb_raise( eDXRubyError, "メモリの取得に失敗しました - Image_loadFromFileInMemory" );
2586+ obj = Data_Wrap_Struct(cImage, 0, release_Image, image);
2587+
2588+ image->texture = texture;
2589+ image->x = 0;
2590+ image->y = 0;
2591+ image->width = srcinfo.Width;
2592+ image->height = srcinfo.Height;
2593+
2594+ g_iRefAll++;
2595+
2596+ return obj;
2597+}
2598+
2599+
2600+/*--------------------------------------------------------------------
2601+ Imgaeオブジェクトの分割作成
2602+ ---------------------------------------------------------------------*/
2603+static VALUE Image_loadToArray( VALUE klass, VALUE filename, VALUE vx, VALUE vy )
2604+{
2605+ struct DXRubyImage *image;
2606+ struct DXRubyTexture *texture;
2607+ int i, j, x, y;
2608+ VALUE obj;
2609+ VALUE array;
2610+ D3DXIMAGE_INFO srcinfo;
2611+ D3DSURFACE_DESC desc;
2612+ HRESULT hr;
2613+
2614+ Check_Type(filename, T_STRING);
2615+ x = NUM2INT( vx );
2616+ y = NUM2INT( vy );
2617+
2618+ if( x <= 0 || y <= 0 ) rb_raise( eDXRubyError, "画像の数指定が異常値です(x=%d,y=%d) - Image_loadToArray", x, y );
2619+
2620+ /* ファイル情報取得 */
2621+ hr = D3DXGetImageInfoFromFile( RSTRING_PTR( filename ), &srcinfo );
2622+
2623+ if( FAILED( hr ) )
2624+ {
2625+ rb_raise( eDXRubyError, "ファイルの読み込みに失敗しました - %s", RSTRING_PTR( filename ) );
2626+ }
2627+
2628+ /* テクスチャロード */
2629+ texture = Image_textureload( RSTRING_PTR( filename ), &srcinfo );
2630+ texture->refcount = x * y;
2631+
2632+ texture->pD3DTexture->lpVtbl->GetLevelDesc(texture->pD3DTexture, 0, &desc );
2633+ texture->width = desc.Width;
2634+ texture->height = desc.Height;
2635+
2636+ /* Ruby配列作成 */
2637+ array = rb_ary_new();
2638+
2639+ for( i = 0; i < y; i++ )
2640+ {
2641+ for( j = 0; j < x; j++ )
2642+ {
2643+ /* DXRubyImageのメモリ取得&Imageオブジェクト生成 */
2644+ image = malloc(sizeof(struct DXRubyImage));
2645+ if( image == NULL ) rb_raise( eDXRubyError, "メモリの取得に失敗しました - Image_loadToArray" );
2646+ obj = Data_Wrap_Struct(cImage, 0, release_Image, image);
2647+
2648+ image->texture = texture;
2649+ image->x = j * srcinfo.Width / x;
2650+ image->y = i * srcinfo.Height / y;
2651+ image->width = srcinfo.Width / x;
2652+ image->height = srcinfo.Height / y;
2653+
2654+ rb_ary_push(array, obj);
2655+ g_iRefAll++;
2656+ }
2657+ }
2658+
2659+ return array;
2660+}
2661+
2662+
2663+/*--------------------------------------------------------------------
2664+ Textureロード
2665+ ---------------------------------------------------------------------*/
2666+static struct DXRubyTexture *Image_textureload( char *filename, D3DXIMAGE_INFO *psrcinfo)
2667+{
2668+ HRESULT hr;
2669+ struct DXRubyTexture *texture;
2670+
2671+ /* テクスチャメモリ取得 */
2672+ texture = (struct DXRubyTexture *)malloc( sizeof( struct DXRubyTexture ) );
2673+
2674+ if( texture == NULL )
2675+ {
2676+ rb_raise( eDXRubyError, "画像用メモリの取得に失敗しました - Image_textureload" );
2677+ }
2678+
2679+ /* ファイルを読み込んでテクスチャオブジェクトを作成する */
2680+ hr = D3DXCreateTextureFromFileEx( g_pD3DDevice, filename,psrcinfo->Width, psrcinfo->Height, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED,
2681+ D3DX_DEFAULT, D3DX_DEFAULT, 0,
2682+ 0, 0, &texture->pD3DTexture);
2683+
2684+ if( FAILED( hr ) )
2685+ {
2686+ rb_raise( eDXRubyError, "ファイルの読み込みに失敗しました - %s", filename );
2687+ }
2688+
2689+ return texture;
2690+}
2691+
2692+
2693+/*--------------------------------------------------------------------
2694+ 配列からイメージを作る
2695+ ---------------------------------------------------------------------*/
2696+static VALUE Image_createFromArray( VALUE klass, VALUE vwidth, VALUE vheight, VALUE array )
2697+{
2698+ struct DXRubyImage *image;
2699+ struct DXRubyTexture *texture;
2700+ HRESULT hr;
2701+ int i, j, x, y;
2702+ D3DLOCKED_RECT LockedRect;
2703+ VALUE obj;
2704+ int width, height;
2705+ D3DSURFACE_DESC desc;
2706+
2707+ /* デバイスオブジェクトの初期化チェック */
2708+ if( g_pD3DDevice == NULL )
2709+ {
2710+ rb_raise( eDXRubyError, "DirectX Graphicsが初期化されていません" );
2711+ }
2712+
2713+ width = NUM2INT( vwidth );
2714+ height = NUM2INT( vheight );
2715+ Check_Type(array, T_ARRAY);
2716+
2717+ if( width <= 0 || height <= 0 ) rb_raise( eDXRubyError, "画像のサイズ指定が異常値です(width=%d,height=%d) - Image_loadToArray", width, height );
2718+
2719+ /* テクスチャメモリ取得 */
2720+ texture = (struct DXRubyTexture *)malloc( sizeof( struct DXRubyTexture ) );
2721+ if( texture == NULL )
2722+ {
2723+ rb_raise( eDXRubyError, "画像用メモリの取得に失敗しました - Image_textureload" );
2724+ }
2725+
2726+ /* テクスチャサイズ割り出し */
2727+ for( x = 1; x < width; x = x * 2 );
2728+ for( y = 1; y < height; y = y * 2 );
2729+
2730+ /* テクスチャオブジェクトを作成する */
2731+ hr = D3DXCreateTexture( g_pD3DDevice, x, y,
2732+ 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED,
2733+ &texture->pD3DTexture);
2734+ if( FAILED( hr ) )
2735+ {
2736+ rb_raise( eDXRubyError, "テクスチャの作成に失敗しました - Image_initialize" );
2737+ }
2738+
2739+ /* テクスチャロック */
2740+ hr = texture->pD3DTexture->lpVtbl->LockRect( texture->pD3DTexture, 0, &LockedRect, NULL, 0 );
2741+ if( FAILED( hr ) )
2742+ {
2743+ rb_raise( eDXRubyError, "サーフェイスのロックに失敗しました - LockRect" );
2744+ }
2745+
2746+ /* 書き込み */
2747+ for( i = 0; i < height; i++ )
2748+ {
2749+ for( j = 0; j < width * 4; j += 4 )
2750+ {
2751+ int a1 = NUM2INT(rb_ary_entry(array, j + i * width * 4));
2752+ int a2 = NUM2INT(rb_ary_entry(array, j + i * width * 4 + 1));
2753+ int a3 = NUM2INT(rb_ary_entry(array, j + i * width * 4 + 2));
2754+ int a4 = NUM2INT(rb_ary_entry(array, j + i * width * 4 + 3));
2755+ *((int*)((char *)LockedRect.pBits + j + i * LockedRect.Pitch)) = D3DCOLOR_ARGB(a1, a2, a3, a4);
2756+ }
2757+ }
2758+
2759+ /* テクスチャアンロック */
2760+ texture->pD3DTexture->lpVtbl->UnlockRect( texture->pD3DTexture, 0 );
2761+
2762+ texture->refcount = 1;
2763+ texture->pD3DTexture->lpVtbl->GetLevelDesc( texture->pD3DTexture, 0, &desc );
2764+ texture->width = desc.Width;
2765+ texture->height = desc.Height;
2766+
2767+ /* DXRubyImageのメモリ取得&Imageオブジェクト生成 */
2768+ image = malloc(sizeof(struct DXRubyImage));
2769+ if( image == NULL ) rb_raise( eDXRubyError, "メモリの取得に失敗しました - Image_createFromArray" );
2770+ obj = Data_Wrap_Struct(cImage, 0, release_Image, image);
2771+
2772+ image->texture = texture;
2773+ image->x = 0;
2774+ image->y = 0;
2775+ image->width = width;
2776+ image->height = height;
2777+
2778+ g_iRefAll++;
2779+
2780+ return obj;
2781+}
2782+
2783+
2784+/*--------------------------------------------------------------------
2785+ Imgaeオブジェクトのslice
2786+ ---------------------------------------------------------------------*/
2787+static VALUE Image_slice_instance( int argc, VALUE *argv, VALUE vsrcimage )
2788+{
2789+ struct DXRubyImage *srcimage;
2790+ struct DXRubyImage *image;
2791+ struct DXRubyTexture *texture;
2792+ D3DXIMAGE_INFO srcinfo;
2793+ HRESULT hr;
2794+ VALUE vx, vy, vwidth, vheight, obj;
2795+ int x, y, width, height;
2796+
2797+ rb_scan_args( argc, argv, "04", &vx, &vy, &vwidth, &vheight );
2798+
2799+ Data_Get_Struct( vsrcimage, struct DXRubyImage, srcimage );
2800+
2801+ if( vx == Qnil )
2802+ {
2803+ x = 0;
2804+ y = 0;
2805+ width = srcimage->width;
2806+ height = srcimage->height;
2807+ }
2808+ else
2809+ {
2810+ x = NUM2INT( vx );
2811+ y = vy == Qnil ? 0 : NUM2INT( vy );
2812+ if( x < 0 || x >= srcimage->width || y < 0 || y >= srcimage->height )
2813+ {
2814+ rb_raise( eDXRubyError, "画像の原点位置が異常値です(x=%d,y=%d, tex_width=%d,tex_height=%d) - Image_slice", x, y, srcimage->width, srcimage->height );
2815+ }
2816+ width = vwidth == Qnil ? srcimage->width - x : NUM2INT( vwidth );
2817+ height = vheight == Qnil ? srcimage->height - y : NUM2INT( vheight );
2818+ if( srcimage->width - x < width || x + width > srcimage->width || srcimage->height - y < height || y + height > srcimage->height ||
2819+ width < 0 || height < 0 )
2820+ {
2821+ rb_raise( eDXRubyError, "画像のサイズが異常値です - Image_slice" );
2822+ }
2823+ }
2824+
2825+ /* テクスチャロード */
2826+ texture = srcimage->texture;
2827+ texture->refcount += 1;
2828+
2829+ /* Imageオブジェクト設定 */
2830+ image = malloc(sizeof(struct DXRubyImage));
2831+ if( image == NULL ) rb_raise( eDXRubyError, "メモリの取得に失敗しました - Image_slice" );
2832+ obj = Data_Wrap_Struct(cImage, 0, release_Image, image);
2833+
2834+ image->texture = texture;
2835+ image->x = x + srcimage->x;
2836+ image->y = y + srcimage->y;
2837+ image->width = width;
2838+ image->height = height;
2839+
2840+ g_iRefAll++;
2841+
2842+ return obj;
2843+}
2844+
2845+
2846+/*--------------------------------------------------------------------
2847+ イメージのデータ取得
2848+ ---------------------------------------------------------------------*/
2849+static VALUE Image_getPixel( VALUE obj, VALUE vx, VALUE vy )
2850+{
2851+ struct DXRubyImage *image;
2852+ VALUE ary[4];
2853+ struct DXRubyColor a;
2854+ D3DLOCKED_RECT texrect;
2855+ int x, y;
2856+ RECT rect;
2857+
2858+ x = NUM2INT( vx );
2859+ y = NUM2INT( vy );
2860+
2861+ Data_Get_Struct( obj, struct DXRubyImage, image );
2862+
2863+ if( x < 0 || x >= image->width || y < 0 || y >= image->height )
2864+ {
2865+ ary[0] = ary[1] = ary[2] = ary[3] = INT2FIX( 0 );
2866+ return rb_ary_new4( 4, ary );
2867+ }
2868+
2869+ rect.left = x + image->x;
2870+ rect.top = y + image->y;
2871+ rect.right = x + image->x + 1;
2872+ rect.bottom = y + image->y + 1;
2873+ image->texture->pD3DTexture->lpVtbl->LockRect( image->texture->pD3DTexture, 0, &texrect, &rect, D3DLOCK_READONLY );
2874+
2875+ a = *(struct DXRubyColor *)texrect.pBits;
2876+
2877+ image->texture->pD3DTexture->lpVtbl->UnlockRect( image->texture->pD3DTexture, 0 );
2878+
2879+ ary[0] = INT2FIX( a.alpha );
2880+ ary[1] = INT2FIX( a.red );
2881+ ary[2] = INT2FIX( a.green );
2882+ ary[3] = INT2FIX( a.blue );
2883+
2884+ return rb_ary_new4( 4, ary );
2885+}
2886+
2887+
2888+/*--------------------------------------------------------------------
2889+ イメージのデータ設定
2890+ ---------------------------------------------------------------------*/
2891+static VALUE Image_setPixel( VALUE obj, VALUE vx, VALUE vy, VALUE color )
2892+{
2893+ struct DXRubyImage *image;
2894+ int a1, a2, a3, a4;
2895+ D3DLOCKED_RECT texrect;
2896+ int x, y;
2897+ RECT rect;
2898+
2899+ x = NUM2INT( vx );
2900+ y = NUM2INT( vy );
2901+ Check_Type(color, T_ARRAY);
2902+
2903+ Data_Get_Struct( obj, struct DXRubyImage, image );
2904+
2905+ if( x < 0 || x >= image->width || y < 0 || y >= image->height )
2906+ {
2907+ return obj;
2908+ }
2909+
2910+ rect.left = x + image->x;
2911+ rect.top = y + image->y;
2912+ rect.right = x + image->x + 1;
2913+ rect.bottom = y + image->y + 1;
2914+ image->texture->pD3DTexture->lpVtbl->LockRect( image->texture->pD3DTexture, 0, &texrect, &rect, 0 );
2915+
2916+ *((int*)((char *)texrect.pBits)) = array2color( color );
2917+
2918+ image->texture->pD3DTexture->lpVtbl->UnlockRect( image->texture->pD3DTexture, 0 );
2919+
2920+ return obj;
2921+}
2922+
2923+
2924+/*--------------------------------------------------------------------
2925+ イメージの色比較
2926+ ---------------------------------------------------------------------*/
2927+static VALUE Image_compare( VALUE obj, VALUE vx, VALUE vy, VALUE color )
2928+{
2929+ struct DXRubyImage *image;
2930+ DWORD a;
2931+ D3DLOCKED_RECT texrect;
2932+ int x, y, col;
2933+ int a1, a2, a3, a4;
2934+ RECT rect;
2935+
2936+ x = NUM2INT( vx );
2937+ y = NUM2INT( vy );
2938+ Check_Type(color, T_ARRAY);
2939+
2940+ Data_Get_Struct( obj, struct DXRubyImage, image );
2941+
2942+ if( x < 0 || x >= image->width || y < 0 || y >= image->height )
2943+ {
2944+ return INT2FIX( 0 );
2945+ }
2946+
2947+ col = array2color( color );
2948+
2949+ rect.left = x + image->x;
2950+ rect.top = y + image->y;
2951+ rect.right = x + image->x + 1;
2952+ rect.bottom = y + image->y + 1;
2953+ image->texture->pD3DTexture->lpVtbl->LockRect( image->texture->pD3DTexture, 0, &texrect, &rect, D3DLOCK_READONLY );
2954+
2955+ a = *(LPDWORD)texrect.pBits;
2956+
2957+ image->texture->pD3DTexture->lpVtbl->UnlockRect( image->texture->pD3DTexture, 0 );
2958+
2959+ if( RARRAY_LEN( color ) == 3 )
2960+ {
2961+
2962+ if( (a & 0x00ffffff) == ((DWORD)col & 0x00ffffff) )
2963+ {
2964+ return Qtrue;
2965+ }
2966+ else
2967+ {
2968+ return Qfalse;
2969+ }
2970+ }
2971+ else
2972+ {
2973+ if( a == (DWORD)col )
2974+ {
2975+ return Qtrue;
2976+ }
2977+ else
2978+ {
2979+ return Qfalse;
2980+ }
2981+ }
2982+}
2983+
2984+
2985+/*--------------------------------------------------------------------
2986+ イメージのデータ設定(box描画塗りつぶさない)
2987+ ---------------------------------------------------------------------*/
2988+static VALUE Image_box( VALUE obj, VALUE vx1, VALUE vy1, VALUE vx2, VALUE vy2, VALUE color )
2989+{
2990+ struct DXRubyImage *image;
2991+ D3DLOCKED_RECT texrect;
2992+ int x, y, x1, y1, x2, y2;
2993+ int col;
2994+ RECT rect;
2995+
2996+ Data_Get_Struct( obj, struct DXRubyImage, image );
2997+
2998+ x1 = NUM2INT( vx1 );
2999+ y1 = NUM2INT( vy1 );
3000+ x2 = NUM2INT( vx2 );
3001+ y2 = NUM2INT( vy2 );
3002+
3003+ /* 左上から右下の指定に修正 */
3004+ if( x1 > x2 )
3005+ {
3006+ x = x2;
3007+ x2 = x1;
3008+ x1 = x;
3009+ }
3010+ if( y1 > y2 )
3011+ {
3012+ y = y2;
3013+ y2 = y1;
3014+ y1 = y;
3015+ }
3016+
3017+ /* 範囲外の指定は無視 */
3018+ if( x1 > image->width - 1 || x2 < 0 || y1 > image->height - 1 || y2 < 0)
3019+ {
3020+ return obj;
3021+ }
3022+
3023+ /* クリップ */
3024+ if( x1 < 0 )
3025+ {
3026+ x1 = 0;
3027+ }
3028+ if( x2 > image->width - 1 )
3029+ {
3030+ x2 = image->width - 1;
3031+ }
3032+ if( y1 < 0 )
3033+ {
3034+ y1 = 0;
3035+ }
3036+ if( y2 > image->height - 1 )
3037+ {
3038+ y2 = image->height - 1;
3039+ }
3040+
3041+ Check_Type(color, T_ARRAY);
3042+ col = array2color( color );
3043+
3044+ rect.left = x1 + image->x;
3045+ rect.top = y1 + image->y;
3046+ rect.right = x2 + image->x + 1;
3047+ rect.bottom = y2 + image->y + 1;
3048+ image->texture->pD3DTexture->lpVtbl->LockRect( image->texture->pD3DTexture, 0, &texrect, &rect, 0 );
3049+ for( y = 0; y <= y2 - y1; y++ )
3050+ {
3051+ *((int*)((char *)texrect.pBits + y * texrect.Pitch)) = col;
3052+ *((int*)((char *)texrect.pBits + (x2 - x1)* 4 + y * texrect.Pitch)) = col;
3053+ }
3054+ for( x = 0; x <= x2 - x1; x++ )
3055+ {
3056+ *((int*)((char *)texrect.pBits + x * 4)) = col;
3057+ *((int*)((char *)texrect.pBits + x * 4 + (y2 - y1) * texrect.Pitch)) = col;
3058+ }
3059+ image->texture->pD3DTexture->lpVtbl->UnlockRect( image->texture->pD3DTexture, 0 );
3060+
3061+ return obj;
3062+}
3063+
3064+
3065+/*--------------------------------------------------------------------
3066+ イメージのデータ設定(box描画塗りつぶす)
3067+ ---------------------------------------------------------------------*/
3068+static VALUE Image_boxFill( VALUE obj, VALUE vx1, VALUE vy1, VALUE vx2, VALUE vy2, VALUE color )
3069+{
3070+ struct DXRubyImage *image;
3071+ int x, y, x1, y1, x2, y2;
3072+ int col;
3073+
3074+ Data_Get_Struct( obj, struct DXRubyImage, image );
3075+
3076+ x1 = NUM2INT( vx1 );
3077+ y1 = NUM2INT( vy1 );
3078+ x2 = NUM2INT( vx2 );
3079+ y2 = NUM2INT( vy2 );
3080+
3081+ /* 左上から右下の指定に修正 */
3082+ if( x1 > x2 )
3083+ {
3084+ x = x2;
3085+ x2 = x1;
3086+ x1 = x;
3087+ }
3088+ if( y1 > y2 )
3089+ {
3090+ y = y2;
3091+ y2 = y1;
3092+ y1 = y;
3093+ }
3094+
3095+ /* 範囲外の指定は無視 */
3096+ if( x1 > image->width - 1 || x2 < 0 || y1 > image->height - 1 || y2 < 0)
3097+ {
3098+ return obj;
3099+ }
3100+
3101+ /* クリップ */
3102+ if( x1 < 0 )
3103+ {
3104+ x1 = 0;
3105+ }
3106+ if( x2 > image->width - 1 )
3107+ {
3108+ x2 = image->width - 1;
3109+ }
3110+ if( y1 < 0 )
3111+ {
3112+ y1 = 0;
3113+ }
3114+ if( y2 > image->height - 1 )
3115+ {
3116+ y2 = image->height - 1;
3117+ }
3118+
3119+ Check_Type(color, T_ARRAY);
3120+ col = array2color( color );
3121+
3122+ fill( x1, y1, x2, y2, col, image );
3123+
3124+ return obj;
3125+}
3126+
3127+
3128+/*--------------------------------------------------------------------
3129+ イメージのデータ設定(全部塗りつぶす)
3130+ ---------------------------------------------------------------------*/
3131+static VALUE Image_fill( VALUE obj, VALUE color )
3132+{
3133+ struct DXRubyImage *image;
3134+ int col;
3135+
3136+ Data_Get_Struct( obj, struct DXRubyImage, image );
3137+
3138+ Check_Type(color, T_ARRAY);
3139+ col = array2color( color );
3140+
3141+ fill( 0, 0, image->width-1, image->height-1, col, image );
3142+
3143+ return obj;
3144+}
3145+
3146+
3147+/*--------------------------------------------------------------------
3148+ イメージのカラーキー設定。実体は指定色を透明に。
3149+ ---------------------------------------------------------------------*/
3150+static VALUE Image_setColorKey( VALUE obj, VALUE color )
3151+{
3152+ struct DXRubyImage *image;
3153+ int col;
3154+ D3DLOCKED_RECT texrect;
3155+ int x, y;
3156+ RECT rect;
3157+ int *p;
3158+
3159+ Data_Get_Struct( obj, struct DXRubyImage, image );
3160+
3161+ Check_Type(color, T_ARRAY);
3162+ col = array2color( color ) & 0x00ffffff;
3163+
3164+ rect.left = image->x;
3165+ rect.top = image->y;
3166+ rect.right = image->x + image->width;
3167+ rect.bottom = image->y + image->height;
3168+ image->texture->pD3DTexture->lpVtbl->LockRect( image->texture->pD3DTexture, 0, &texrect, &rect, 0 );
3169+ for( y = 0; y < image->height; y++ )
3170+ {
3171+ p = (int*)((char *)texrect.pBits + y * texrect.Pitch);
3172+ for( x = 0; x < image->width; x++ )
3173+ {
3174+ if( (*p & 0x00ffffff) == col )
3175+ {
3176+// *((int*)((char *)texrect.pBits + x * 4 + y * texrect.Pitch)) = col;
3177+ *p = col;
3178+ }
3179+ p++;
3180+ }
3181+ }
3182+ image->texture->pD3DTexture->lpVtbl->UnlockRect( image->texture->pD3DTexture, 0 );
3183+
3184+ return obj;
3185+}
3186+
3187+
3188+/*--------------------------------------------------------------------
3189+ イメージのデータ設定(circle用のline描画)
3190+ ---------------------------------------------------------------------*/
3191+static void Image_circle_line( int x1, int x2, int y, RECT *rect, int col, D3DLOCKED_RECT *texrect )
3192+{
3193+ int x;
3194+ int *p;
3195+
3196+ if( y < 0 || y >= rect->bottom - rect->top )
3197+ {
3198+ return;
3199+ }
3200+
3201+ /* クリップ */
3202+ if( x1 < 0 )
3203+ {
3204+ x1 = 0;
3205+ }
3206+ if( x2 > rect->right - rect->left - 1 )
3207+ {
3208+ x2 = rect->right - rect->left - 1;
3209+ }
3210+ if( x1 > x2 )
3211+ {
3212+ return;
3213+ }
3214+
3215+ p = (int*)((char *)texrect->pBits + y * texrect->Pitch + x1 * 4);
3216+ for( x = 0; x <= x2 - x1; x++ )
3217+ {
3218+ *(p++) = col;
3219+ }
3220+}
3221+
3222+
3223+/*--------------------------------------------------------------------
3224+ イメージのデータ設定(circle描画塗りつぶす)
3225+ ---------------------------------------------------------------------*/
3226+static VALUE Image_circleFill( VALUE obj, VALUE vx0, VALUE vy0, VALUE vr, VALUE color )
3227+{
3228+ struct DXRubyImage *image;
3229+ int x0, y0, r, F, x, y;
3230+ int col;
3231+ D3DLOCKED_RECT texrect;
3232+ RECT rect;
3233+ HRESULT hr;
3234+ int tempx, tempy;
3235+
3236+ Data_Get_Struct( obj, struct DXRubyImage, image );
3237+
3238+ x0 = NUM2INT( vx0 );
3239+ y0 = NUM2INT( vy0 );
3240+ r = NUM2INT( vr );
3241+
3242+ Check_Type(color, T_ARRAY);
3243+ col = array2color( color );
3244+
3245+ rect.left = x0 < r ? image->x : x0 + image->x - r;
3246+ rect.top = y0 < r ? image->y : y0 + image->y - r;
3247+ rect.right = x0 + r >= image->width ? image->x + image->width : x0 + image->x + r + 1;
3248+ rect.bottom = y0 + r >= image->height ? image->y + image->height : y0 + image->y + r + 1;
3249+ if( rect.left >= rect.right || rect.top >= rect.bottom )
3250+ {
3251+ return obj;
3252+ }
3253+
3254+ hr = image->texture->pD3DTexture->lpVtbl->LockRect( image->texture->pD3DTexture, 0, &texrect, &rect, 0 );
3255+
3256+ x = r;
3257+ y = 0;
3258+ F = -2 * r + 3;
3259+
3260+ tempx = x0 - rect.left + (int)image->x;
3261+ tempy = y0 - rect.top + (int)image->y;
3262+ while ( x >= y )
3263+ {
3264+ Image_circle_line( tempx - x, tempx + x, tempy + y, &rect, col, &texrect );
3265+ Image_circle_line( tempx - x, tempx + x, tempy - y, &rect, col, &texrect );
3266+ Image_circle_line( tempx - y, tempx + y, tempy + x, &rect, col, &texrect );
3267+ Image_circle_line( tempx - y, tempx + y, tempy - x, &rect, col, &texrect );
3268+ if ( F >= 0 )
3269+ {
3270+ x--;
3271+ F -= 4 * x;
3272+ }
3273+ y++;
3274+ F += 4 * y + 2;
3275+ }
3276+
3277+ image->texture->pD3DTexture->lpVtbl->UnlockRect( image->texture->pD3DTexture, 0 );
3278+
3279+ return obj;
3280+}
3281+
3282+
3283+/*--------------------------------------------------------------------
3284+ イメージのデータ設定(内部処理用pixel描画)
3285+ ---------------------------------------------------------------------*/
3286+static void Image_circle_pixel( int x, int y, RECT *rect, int col, D3DLOCKED_RECT *texrect )
3287+{
3288+ if( x < 0 || x >= rect->right - rect->left || y < 0 || y >= rect->bottom - rect->top )
3289+ {
3290+ return;
3291+ }
3292+
3293+ *((int*)((char *)texrect->pBits + x * 4 + y * texrect->Pitch)) = col;
3294+
3295+ return;
3296+}
3297+
3298+
3299+/*--------------------------------------------------------------------
3300+ イメージのデータ設定(circle描画塗りつぶさない)
3301+ ---------------------------------------------------------------------*/
3302+static VALUE Image_circle( VALUE obj, VALUE vx0, VALUE vy0, VALUE vr, VALUE color )
3303+{
3304+ struct DXRubyImage *image;
3305+ D3DLOCKED_RECT texrect;
3306+ int x0, y0, r, F, x, y;
3307+ int col;
3308+ RECT rect;
3309+
3310+ Data_Get_Struct( obj, struct DXRubyImage, image );
3311+
3312+ x0 = NUM2INT( vx0 );
3313+ y0 = NUM2INT( vy0 );
3314+ r = NUM2INT( vr );
3315+
3316+ Check_Type(color, T_ARRAY);
3317+ col = array2color( color );
3318+
3319+ rect.left = x0 < r ? image->x : x0 + image->x - r;
3320+ rect.top = y0 < r ? image->y : y0 + image->y - r;
3321+ rect.right = x0 + r >= image->width ? image->x + image->width : x0 + image->x + r + 1;
3322+ rect.bottom = y0 + r >= image->height ? image->y + image->height : y0 + image->y + r + 1;
3323+ if( rect.left >= rect.right || rect.top >= rect.bottom )
3324+ {
3325+ return obj;
3326+ }
3327+
3328+ image->texture->pD3DTexture->lpVtbl->LockRect( image->texture->pD3DTexture, 0, &texrect, &rect, 0 );
3329+
3330+ x = r;
3331+ y = 0;
3332+ F = -2 * r + 3;
3333+
3334+ while ( x >= y )
3335+ {
3336+ int tempx = x0 - rect.left + (int)image->x;
3337+ int tempy = y0 - rect.top + (int)image->y;
3338+ Image_circle_pixel( tempx + x, tempy + y, &rect, col, &texrect );
3339+ Image_circle_pixel( tempx - x, tempy + y, &rect, col, &texrect );
3340+ Image_circle_pixel( tempx + x, tempy - y, &rect, col, &texrect );
3341+ Image_circle_pixel( tempx - x, tempy - y, &rect, col, &texrect );
3342+ Image_circle_pixel( tempx + y, tempy + x, &rect, col, &texrect );
3343+ Image_circle_pixel( tempx - y, tempy + x, &rect, col, &texrect );
3344+ Image_circle_pixel( tempx + y, tempy - x, &rect, col, &texrect );
3345+ Image_circle_pixel( tempx - y, tempy - x, &rect, col, &texrect );
3346+ if ( F >= 0 )
3347+ {
3348+ x--;
3349+ F -= 4 * x;
3350+ }
3351+ y++;
3352+ F += 4 * y + 2;
3353+ }
3354+
3355+ image->texture->pD3DTexture->lpVtbl->UnlockRect( image->texture->pD3DTexture, 0 );
3356+
3357+ return obj;
3358+}
3359+
3360+
3361+/*--------------------------------------------------------------------
3362+ イメージのデータ設定(line描画)
3363+ ---------------------------------------------------------------------*/
3364+static VALUE Image_line( VALUE obj, VALUE vx1, VALUE vy1, VALUE vx2, VALUE vy2, VALUE color )
3365+{
3366+ struct DXRubyImage *image;
3367+ D3DLOCKED_RECT texrect;
3368+ int x1, y1, x2, y2, xp, yp;
3369+ int col;
3370+ int c, d, dx, dy, i;
3371+ RECT rect;
3372+
3373+ Data_Get_Struct( obj, struct DXRubyImage, image );
3374+
3375+ x1 = NUM2INT( vx1 );
3376+ y1 = NUM2INT( vy1 );
3377+ x2 = NUM2INT( vx2 );
3378+ y2 = NUM2INT( vy2 );
3379+
3380+ Check_Type(color, T_ARRAY);
3381+ col = array2color( color );
3382+
3383+ rect.left = (x1 < x2 ? x1 : x2) < image->x ? image->x : (x1 < x2 ? x1 : x2);
3384+ rect.top = (y1 < y2 ? y1 : y2) < image->y ? image->y : (y1 < y2 ? y1 : y2);
3385+ rect.right = (x1 > x2 ? x1 : x2) >= image->width ? image->x + image->width : image->x + (x1 > x2 ? x1 : x2) + 1;
3386+ rect.bottom = (y1 > y2 ? y1 : y2) >= image->height ? image->y + image->height : image->y + (y1 > y2 ? y1 : y2) + 1;
3387+ if( rect.left >= rect.right || rect.top >= rect.bottom )
3388+ {
3389+ return obj;
3390+ }
3391+
3392+ x1 = x1 - rect.left + image->x;
3393+ x2 = x2 - rect.left + image->x;
3394+ y1 = y1 - rect.top + image->y;
3395+ y2 = y2 - rect.top + image->y;
3396+
3397+ image->texture->pD3DTexture->lpVtbl->LockRect( image->texture->pD3DTexture, 0, &texrect, &rect, 0 );
3398+
3399+ dx = x2 > x1 ? x2 - x1 : x1 - x2;
3400+ dy = y2 > y1 ? y2 - y1 : y1 - y2;
3401+
3402+ /* ブレゼンハムアルゴリズムによる線分描画 */
3403+ if( dx < dy )
3404+ {
3405+ xp = x1 < x2 ? 1 : -1;
3406+ d = y1 < y2 ? 1 : -1;
3407+ c = dy / 2;
3408+ for( i = 0; i <= dy; i++ )
3409+ {
3410+ if( x1 >= 0 && x1 < (int)rect.right - rect.left && y1 >= 0 && y1 < (int)rect.bottom - rect.top )
3411+ {
3412+ *((int*)((char *)texrect.pBits + x1 * 4 + y1 * texrect.Pitch)) = col;
3413+ }
3414+ y1 = y1 + d;
3415+ c = c + dx;
3416+ if( c >= dy )
3417+ {
3418+ c = c - dy;
3419+ x1 = x1 + xp;
3420+ }
3421+ }
3422+ }
3423+ else
3424+ {
3425+ yp = y1 < y2 ? 1 : -1;
3426+ d = x1 < x2 ? 1 : -1;
3427+ c = dx / 2;
3428+ for( i = 0; i <= dx; i++ )
3429+ {
3430+ if( x1 >= 0 && x1 < (int)rect.right - rect.left && y1 >= 0 && y1 < (int)rect.bottom - rect.top )
3431+ {
3432+ *((int*)((char *)texrect.pBits + x1 * 4 + y1 * texrect.Pitch)) = col;
3433+ }
3434+ x1 = x1 + d;
3435+ c = c + dy;
3436+ if( c >= dx )
3437+ {
3438+ c = c - dx;
3439+ y1 = y1 + yp;
3440+ }
3441+ }
3442+ }
3443+
3444+ image->texture->pD3DTexture->lpVtbl->UnlockRect( image->texture->pD3DTexture, 0 );
3445+
3446+ return obj;
3447+}
3448+
3449+
3450+/*--------------------------------------------------------------------
3451+ イメージオブジェクト間データ転送
3452+ ---------------------------------------------------------------------*/
3453+static VALUE Image_copyRect( int argc, VALUE *argv, VALUE obj )
3454+{
3455+ struct DXRubyImage *srcimage;
3456+ struct DXRubyImage *dstimage;
3457+ D3DLOCKED_RECT srctrect;
3458+ D3DLOCKED_RECT dsttrect;
3459+ VALUE vx, vy, data, vx1, vy1, vwidth, vheight;
3460+ int x, y, x1, y1, width, height;
3461+ int i, j;
3462+ RECT srcrect;
3463+ RECT dstrect;
3464+ int *psrc;
3465+ int *pdst;
3466+
3467+ rb_scan_args( argc, argv, "34", &vx, &vy, &data, &vx1, &vy1, &vwidth, &vheight );
3468+
3469+ Data_Get_Struct( obj, struct DXRubyImage, dstimage );
3470+ Data_Get_Struct( data, struct DXRubyImage, srcimage );
3471+
3472+ if( dstimage == srcimage ) rb_raise( eDXRubyError, "描画元と先に同じImageオブジェクトが指定されています - Image_copyRect" );
3473+
3474+ x = NUM2INT( vx );
3475+ y = NUM2INT( vy );
3476+ x1 = vx1 == Qnil ? 0 : NUM2INT( vx1 );
3477+ y1 = vy1 == Qnil ? 0 : NUM2INT( vy1 );
3478+ width = vwidth == Qnil ? srcimage->width - x1 : NUM2INT( vwidth );
3479+ height = vheight == Qnil ? srcimage->height - y1 : NUM2INT( vheight );
3480+
3481+ /* 画像のクリッピング */
3482+ if( x < 0 )
3483+ {
3484+ x1 -= x;
3485+ width -= x;
3486+ x = 0;
3487+ }
3488+ if( y < 0 )
3489+ {
3490+ y1 -= y;
3491+ height -= y;
3492+ y = 0;
3493+ }
3494+ if( x1 < 0 )
3495+ {
3496+ x -=x1;
3497+ width -= x1;
3498+ x1 = 0;
3499+ }
3500+ if( y1 < 0 )
3501+ {
3502+ y -=y1;
3503+ height -= y1;
3504+ y1 = 0;
3505+ }
3506+ if( x + width > dstimage->width )
3507+ {
3508+ width -= x + width - dstimage->width;
3509+ }
3510+ if( y + height > dstimage->height )
3511+ {
3512+ height -= y + height - dstimage->height;
3513+ }
3514+ if( x1 + width > srcimage->width )
3515+ {
3516+ width -= x1 + width - srcimage->width;
3517+ }
3518+ if( y1 + height > srcimage->height )
3519+ {
3520+ height -= y1 + height - srcimage->height;
3521+ }
3522+
3523+ /* 範囲外 */
3524+ if( x >= dstimage->width || y >= dstimage->height || x1 >= srcimage->width || y1 >= srcimage->height ||
3525+ width < 0 || height < 0 )
3526+ {
3527+ return obj;
3528+ }
3529+
3530+ dstrect.left = x + dstimage->x;
3531+ dstrect.top = y + dstimage->y;
3532+ dstrect.right = x + dstimage->x + width;
3533+ dstrect.bottom = y + dstimage->y + height;
3534+ srcrect.left = x1 + srcimage->x;
3535+ srcrect.top = y1 + srcimage->y;
3536+ srcrect.right = x1 + srcimage->x + width;
3537+ srcrect.bottom = y1 + srcimage->y + height;
3538+
3539+ dstimage->texture->pD3DTexture->lpVtbl->LockRect( dstimage->texture->pD3DTexture, 0, &dsttrect, &dstrect, 0 );
3540+ srcimage->texture->pD3DTexture->lpVtbl->LockRect( srcimage->texture->pD3DTexture, 0, &srctrect, &srcrect, D3DLOCK_READONLY );
3541+
3542+ for( i = 0; i < height; i++)
3543+ {
3544+ psrc = (int*)((char *)srctrect.pBits + i * srctrect.Pitch);
3545+ pdst = (int*)((char *)dsttrect.pBits + i * dsttrect.Pitch);
3546+ for( j = 0; j < width; j++)
3547+ {
3548+ *(pdst++) = *(psrc++);
3549+ }
3550+ }
3551+
3552+ dstimage->texture->pD3DTexture->lpVtbl->UnlockRect( dstimage->texture->pD3DTexture, 0 );
3553+ srcimage->texture->pD3DTexture->lpVtbl->UnlockRect( srcimage->texture->pD3DTexture, 0 );
3554+
3555+ return obj;
3556+}
3557+
3558+
3559+/*--------------------------------------------------------------------
3560+ イメージオブジェクトdup
3561+ ---------------------------------------------------------------------*/
3562+static VALUE Image_dup( VALUE self )
3563+{
3564+ struct DXRubyImage *srcimage;
3565+ struct DXRubyImage *dstimage;
3566+ struct DXRubyTexture *texture;
3567+ D3DLOCKED_RECT srctrect;
3568+ D3DLOCKED_RECT dsttrect;
3569+ int i, j;
3570+ RECT srcrect;
3571+ RECT dstrect;
3572+ VALUE obj;
3573+ HRESULT hr;
3574+ D3DSURFACE_DESC desc;
3575+ int *psrc;
3576+ int *pdst;
3577+
3578+ Data_Get_Struct( self, struct DXRubyImage, srcimage );
3579+
3580+ /* Imageオブジェクト作成 */
3581+ dstimage = malloc(sizeof(struct DXRubyImage));
3582+ if( dstimage == NULL ) rb_raise( eDXRubyError, "メモリの取得に失敗しました - Image_dup" );
3583+ obj = Data_Wrap_Struct(cImage, 0, release_Image, dstimage);
3584+
3585+ g_iRefAll++;
3586+
3587+ /* テクスチャメモリ取得 */
3588+ texture = (struct DXRubyTexture *)malloc( sizeof( struct DXRubyTexture ) );
3589+ if( texture == NULL )
3590+ {
3591+ rb_raise( eDXRubyError, "画像用メモリの取得に失敗しました - Image_dup" );
3592+ }
3593+
3594+ /* テクスチャオブジェクトを作成する */
3595+ hr = D3DXCreateTexture( g_pD3DDevice, srcimage->width, srcimage->height,
3596+ 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED,
3597+ &texture->pD3DTexture);
3598+ if( FAILED( hr ) )
3599+ {
3600+ rb_raise( eDXRubyError, "テクスチャの作成に失敗しました - Image_dup" );
3601+ }
3602+
3603+ texture->refcount = 1;
3604+
3605+ texture->pD3DTexture->lpVtbl->GetLevelDesc(texture->pD3DTexture, 0, &desc );
3606+ texture->width = desc.Width;
3607+ texture->height = desc.Height;
3608+
3609+ dstimage->texture = texture;
3610+ dstimage->x = 0;
3611+ dstimage->y = 0;
3612+ dstimage->width = srcimage->width;
3613+ dstimage->height =srcimage-> height;
3614+
3615+ /* イメージコピー */
3616+ dstrect.left = 0;
3617+ dstrect.top = 0;
3618+ dstrect.right = srcimage->width;
3619+ dstrect.bottom = srcimage->height;
3620+ srcrect.left = srcimage->x;
3621+ srcrect.top = srcimage->y;
3622+ srcrect.right = srcimage->x + srcimage->width;
3623+ srcrect.bottom = srcimage->y + srcimage->height;
3624+
3625+ dstimage->texture->pD3DTexture->lpVtbl->LockRect( dstimage->texture->pD3DTexture, 0, &dsttrect, &dstrect, 0 );
3626+ srcimage->texture->pD3DTexture->lpVtbl->LockRect( srcimage->texture->pD3DTexture, 0, &srctrect, &srcrect, D3DLOCK_READONLY );
3627+
3628+ for( i = 0; i < srcimage->height; i++)
3629+ {
3630+ psrc = (int*)((char *)srctrect.pBits + i * srctrect.Pitch);
3631+ pdst = (int*)((char *)dsttrect.pBits + i * dsttrect.Pitch);
3632+ for( j = 0; j < srcimage->width; j++)
3633+ {
3634+ *(pdst++) = *(psrc++);
3635+ }
3636+ }
3637+
3638+ dstimage->texture->pD3DTexture->lpVtbl->UnlockRect( dstimage->texture->pD3DTexture, 0 );
3639+ srcimage->texture->pD3DTexture->lpVtbl->UnlockRect( srcimage->texture->pD3DTexture, 0 );
3640+
3641+ return obj;
3642+}
3643+
3644+
3645+/*--------------------------------------------------------------------
3646+ イメージオブジェクト間αつきデータ転送
3647+ ---------------------------------------------------------------------*/
3648+static VALUE Image_draw( int argc, VALUE *argv, VALUE obj )
3649+{
3650+ struct DXRubyImage *srcimage;
3651+ struct DXRubyImage *dstimage;
3652+ D3DLOCKED_RECT srctrect;
3653+ D3DLOCKED_RECT dsttrect;
3654+ VALUE vx, vy, data, vx1, vy1, vwidth, vheight;
3655+ int x, y, x1, y1, width, height;
3656+ int i, j;
3657+ RECT srcrect;
3658+ RECT dstrect;
3659+ int *psrc;
3660+ int *pdst;
3661+
3662+ rb_scan_args( argc, argv, "34", &vx, &vy, &data, &vx1, &vy1, &vwidth, &vheight );
3663+
3664+ Data_Get_Struct( obj, struct DXRubyImage, dstimage );
3665+ Data_Get_Struct( data, struct DXRubyImage, srcimage );
3666+
3667+ if( dstimage == srcimage ) rb_raise( eDXRubyError, "描画元と先に同じImageオブジェクトが指定されています - Image_draw" );
3668+
3669+ x = NUM2INT( vx );
3670+ y = NUM2INT( vy );
3671+ x1 = vx1 == Qnil ? 0 : NUM2INT( vx1 );
3672+ y1 = vy1 == Qnil ? 0 : NUM2INT( vy1 );
3673+ width = vwidth == Qnil ? srcimage->width - x1 : NUM2INT( vwidth );
3674+ height = vheight == Qnil ? srcimage->height - y1 : NUM2INT( vheight );
3675+
3676+ /* 画像のクリッピング */
3677+ if( x < 0 )
3678+ {
3679+ x1 -= x;
3680+ width -= x;
3681+ x = 0;
3682+ }
3683+ if( y < 0 )
3684+ {
3685+ y1 -= y;
3686+ height -= y;
3687+ y = 0;
3688+ }
3689+ if( x1 < 0 )
3690+ {
3691+ x -=x1;
3692+ width -= x1;
3693+ x1 = 0;
3694+ }
3695+ if( y1 < 0 )
3696+ {
3697+ y -=y1;
3698+ height -= y1;
3699+ y1 = 0;
3700+ }
3701+ if( x + width > dstimage->width )
3702+ {
3703+ width -= x + width - dstimage->width;
3704+ }
3705+ if( y + height > dstimage->height )
3706+ {
3707+ height -= y + height - dstimage->height;
3708+ }
3709+ if( x1 + width > srcimage->width )
3710+ {
3711+ width -= x1 + width - srcimage->width;
3712+ }
3713+ if( y1 + height > srcimage->height )
3714+ {
3715+ height -= y1 + height - srcimage->height;
3716+ }
3717+
3718+ /* 範囲外 */
3719+ if( x >= dstimage->width || y >= dstimage->height || x1 >= srcimage->width || y1 >= srcimage->height ||
3720+ width < 0 || height < 0 )
3721+ {
3722+ return obj;
3723+ }
3724+
3725+ dstrect.left = x + dstimage->x;
3726+ dstrect.top = y + dstimage->y;
3727+ dstrect.right = x + dstimage->x + width;
3728+ dstrect.bottom = y + dstimage->y + height;
3729+ srcrect.left = x1 + srcimage->x;
3730+ srcrect.top = y1 + srcimage->y;
3731+ srcrect.right = x1 + srcimage->x + width;
3732+ srcrect.bottom = y1 + srcimage->y + height;
3733+
3734+ dstimage->texture->pD3DTexture->lpVtbl->LockRect( dstimage->texture->pD3DTexture, 0, &dsttrect, &dstrect, 0 );
3735+ srcimage->texture->pD3DTexture->lpVtbl->LockRect( srcimage->texture->pD3DTexture, 0, &srctrect, &srcrect, D3DLOCK_READONLY );
3736+
3737+ for( i = 0; i < height; i++)
3738+ {
3739+ psrc = (int*)((char *)srctrect.pBits + i * srctrect.Pitch);
3740+ pdst = (int*)((char *)dsttrect.pBits + i * dsttrect.Pitch);
3741+ for( j = 0; j < width; j++)
3742+ {
3743+ struct DXRubyColor s = *((struct DXRubyColor*)(psrc));
3744+
3745+ if( s.alpha == 255 )
3746+ {
3747+ *((struct DXRubyColor*)(pdst)) = s;
3748+ }
3749+ else if( s.alpha != 0 )
3750+ {
3751+ struct DXRubyColor d = *((struct DXRubyColor*)(pdst));
3752+
3753+ s.red = ((int)s.red * (int)s.alpha * 255 + (int)d.red * (int)d.alpha * (255 - (int)s.alpha) ) / 255 / 255;
3754+ s.green = ((int)s.green * (int)s.alpha * 255 + (int)d.green * (int)d.alpha * (255 - (int)s.alpha) ) / 255 / 255;
3755+ s.blue = ((int)s.blue * (int)s.alpha * 255 + (int)d.blue * (int)d.alpha * (255 - (int)s.alpha) ) / 255 / 255;
3756+
3757+ if( d.alpha > s.alpha)
3758+ {
3759+ s.alpha = d.alpha;
3760+ }
3761+
3762+ *((struct DXRubyColor*)(pdst)) = s;
3763+ }
3764+ psrc++;
3765+ pdst++;
3766+ }
3767+ }
3768+
3769+ dstimage->texture->pD3DTexture->lpVtbl->UnlockRect( dstimage->texture->pD3DTexture, 0 );
3770+ srcimage->texture->pD3DTexture->lpVtbl->UnlockRect( srcimage->texture->pD3DTexture, 0 );
3771+
3772+ return obj;
3773+}
3774+
3775+
3776+/*--------------------------------------------------------------------
3777+ イメージにフォント描画
3778+ ---------------------------------------------------------------------*/
3779+static VALUE Image_drawFont( int argc, VALUE *argv, VALUE obj )
3780+{
3781+ struct DXRubyFont *font;
3782+ struct DXRubyImage *image;
3783+ VALUE vx, vy, vcolor, str, data;
3784+ int cr, cg, cb, x, y;
3785+ LPDIRECT3DSURFACE9 pD3DSurface;
3786+ HDC hDC;
3787+ RECT rc;
3788+ HRESULT hr;
3789+ D3DLOCKED_RECT srctrect;
3790+ D3DLOCKED_RECT dsttrect;
3791+ int i, j;
3792+ int h;
3793+ RECT srcrect;
3794+ RECT dstrect;
3795+ int *psrc;
3796+ int *pdst;
3797+
3798+ /* 引数取得 */
3799+ rb_scan_args( argc, argv, "41", &vx, &vy, &str, &data, &vcolor);
3800+
3801+ Check_Type(str, T_STRING);
3802+
3803+ /* 引数のフォントオブジェクトから中身を取り出す */
3804+ Data_Get_Struct( obj, struct DXRubyImage, image );
3805+ Data_Get_Struct( data, struct DXRubyFont, font );
3806+ if (RDATA(data)->dfree != (RUBY_DATA_FUNC)release_Font)
3807+ {
3808+ rb_raise(rb_eTypeError, "wrong argument type %s (expected DXRuby::Font)", rb_obj_classname( data ));
3809+ }
3810+
3811+ x = NUM2INT( vx );
3812+ y = NUM2INT( vy );
3813+ if( vcolor != Qnil )
3814+ {
3815+ Check_Type(vcolor, T_ARRAY);
3816+ if( RARRAY_LEN(vcolor) == 4 )
3817+ {
3818+ cr = NUM2INT(rb_ary_entry(vcolor, 1));
3819+ cg = NUM2INT(rb_ary_entry(vcolor, 2));
3820+ cb = NUM2INT(rb_ary_entry(vcolor, 3));
3821+ }
3822+ else
3823+ {
3824+ cr = NUM2INT(rb_ary_entry(vcolor, 0));
3825+ cg = NUM2INT(rb_ary_entry(vcolor, 1));
3826+ cb = NUM2INT(rb_ary_entry(vcolor, 2));
3827+ }
3828+ }
3829+ else
3830+ {
3831+ cr = 255;
3832+ cg = 255;
3833+ cb = 255;
3834+ }
3835+
3836+ if( x >= image->width || y >= image->height )
3837+ {
3838+ return obj;
3839+ }
3840+
3841+ /* オフスクリーンサーフェイスに文字描画 */
3842+ hr = g_pD3DDevice->lpVtbl->CreateOffscreenPlainSurface ( g_pD3DDevice, image->width, image->height
3843+ , D3DFMT_X8R8G8B8, D3DPOOL_SYSTEMMEM, &pD3DSurface, NULL );
3844+ if( FAILED( hr ) )
3845+ {
3846+ rb_raise( eDXRubyError, "サーフェイスの生成に失敗しました - CreateOffscreenPlainSurface" );
3847+ }
3848+ hr = pD3DSurface->lpVtbl->GetDC( pD3DSurface, &hDC );
3849+ if( FAILED( hr ) )
3850+ {
3851+ rb_raise( eDXRubyError, "DCの取得に失敗しました - GetDC" );
3852+ }
3853+ SelectObject( hDC, font->hFont );
3854+ SetRect( &rc, x, y, x + 1, y + 1 );
3855+ SetTextColor( hDC, RGB( 255, 255, 255 ) );
3856+ SetBkColor( hDC, RGB( 0, 0, 0 ) );
3857+ h = DrawText( hDC, RSTRING_PTR(str), -1, &rc, DT_LEFT | DT_NOCLIP | DT_NOPREFIX | DT_NOFULLWIDTHCHARBREAK);
3858+ pD3DSurface->lpVtbl->ReleaseDC( pD3DSurface, hDC );
3859+
3860+ if( y + h < 0 )
3861+ {
3862+ RELEASE( pD3DSurface );
3863+ return obj;
3864+ }
3865+
3866+ /* Imageオブジェクトに転送 */
3867+ if( x < 0 )
3868+ {
3869+ x = 0;
3870+ }
3871+ if( y < 0 )
3872+ {
3873+ h += y;
3874+ y = 0;
3875+ }
3876+
3877+ srcrect.left = x;
3878+ srcrect.top = y;
3879+ srcrect.right = image->width;
3880+ srcrect.bottom = image->height < y + h ? image->height : y + h;
3881+ dstrect.left = x + image->x;
3882+ dstrect.top = y + image->y;
3883+ dstrect.right = image->x + image->width;
3884+ dstrect.bottom = image->y + (image->height < y + h ? image->height : y + h);
3885+
3886+ image->texture->pD3DTexture->lpVtbl->LockRect( image->texture->pD3DTexture, 0, &dsttrect, &dstrect, 0 );
3887+ pD3DSurface->lpVtbl->LockRect( pD3DSurface, &srctrect, &srcrect, D3DLOCK_READONLY );
3888+
3889+ for( i = 0; i < srcrect.bottom - srcrect.top; i++)
3890+ {
3891+ psrc = (int*)((char *)srctrect.pBits + i * srctrect.Pitch);
3892+ pdst = (int*)((char *)dsttrect.pBits + i * dsttrect.Pitch);
3893+ for( j = 0; j < srcrect.right - srcrect.left; j++)
3894+ {
3895+ struct DXRubyColor s = *((struct DXRubyColor*)(psrc));
3896+
3897+ if( s.red == 255 )
3898+ {
3899+ *((int *)(pdst)) = D3DCOLOR_ARGB(0xff, cr, cg, cb);
3900+ }
3901+ else if( s.red != 0 )
3902+ {
3903+ struct DXRubyColor d = *((struct DXRubyColor*)(pdst));
3904+ struct DXRubyColor data;
3905+
3906+ data.alpha = s.red > d.alpha ? s.red : d.alpha;
3907+ data.red = ((int)s.red * cr * 255 + (int)d.red * (int)d.alpha * (255 - (int)s.red) ) / 255 / 255;
3908+ data.green = ((int)s.red * cg * 255 + (int)d.green * (int)d.alpha * (255 - (int)s.red) ) / 255 / 255;
3909+ data.blue = ((int)s.red * cb * 255 + (int)d.blue * (int)d.alpha * (255 - (int)s.red) ) / 255 / 255;
3910+
3911+ *((struct DXRubyColor*)(pdst)) = data;
3912+ }
3913+ psrc++;
3914+ pdst++;
3915+ }
3916+ }
3917+
3918+ image->texture->pD3DTexture->lpVtbl->UnlockRect( image->texture->pD3DTexture, 0 );
3919+ pD3DSurface->lpVtbl->UnlockRect( pD3DSurface );
3920+
3921+ RELEASE( pD3DSurface );
3922+ return obj;
3923+}
3924+
3925+
3926+/*--------------------------------------------------------------------
3927+ イメージをファイルに保存する。
3928+ ---------------------------------------------------------------------*/
3929+static VALUE Image_save( int argc, VALUE *argv, VALUE obj )
3930+{
3931+ HRESULT hr;
3932+ struct DXRubyImage *image;
3933+ VALUE filename, format;
3934+
3935+ rb_scan_args( argc, argv, "11", &filename, &format );
3936+
3937+ Data_Get_Struct( obj, struct DXRubyImage, image );
3938+
3939+ hr = D3DXSaveTextureToFile(
3940+ RSTRING_PTR( filename ), /* 保存ファイル名 */
3941+ format == Qnil ? D3DXIFF_JPG : FIX2INT( format ), /* ファイルフォーマット */
3942+ (IDirect3DBaseTexture9*)image->texture->pD3DTexture,/* 保存するサーフェス */
3943+ NULL); /* パレット */
3944+ if( FAILED( hr ) )
3945+ {
3946+ rb_raise( eDXRubyError, "ファイルの保存に失敗しました - Image_save" );
3947+ }
3948+
3949+ return obj;
3950+}
3951+
3952+
3953+/*--------------------------------------------------------------------
3954+ イメージの開始位置xを返す。
3955+ ---------------------------------------------------------------------*/
3956+static VALUE Image_getX( VALUE obj )
3957+{
3958+ struct DXRubyImage *image;
3959+
3960+ Data_Get_Struct( obj, struct DXRubyImage, image );
3961+
3962+ return INT2FIX( image->x );
3963+}
3964+
3965+
3966+/*--------------------------------------------------------------------
3967+ イメージの開始位置yを返す。
3968+ ---------------------------------------------------------------------*/
3969+static VALUE Image_getY( VALUE obj )
3970+{
3971+ struct DXRubyImage *image;
3972+
3973+ Data_Get_Struct( obj, struct DXRubyImage, image );
3974+
3975+ return INT2FIX( image->y );
3976+}
3977+
3978+
3979+/*--------------------------------------------------------------------
3980+ イメージのサイズ(幅)を返す。
3981+ ---------------------------------------------------------------------*/
3982+static VALUE Image_getWidth( VALUE obj )
3983+{
3984+ struct DXRubyImage *image;
3985+
3986+ Data_Get_Struct( obj, struct DXRubyImage, image );
3987+
3988+ return INT2FIX( image->width );
3989+}
3990+
3991+
3992+/*--------------------------------------------------------------------
3993+ イメージのサイズ(高さ)を返す。
3994+ ---------------------------------------------------------------------*/
3995+static VALUE Image_getHeight( VALUE obj )
3996+{
3997+ struct DXRubyImage *image;
3998+
3999+ Data_Get_Struct( obj, struct DXRubyImage, image );
4000+
4001+ return INT2FIX( image->height );
4002+}
4003+
4004+
4005+/*--------------------------------------------------------------------
4006+ イメージの開始位置xを設定する。
4007+ ---------------------------------------------------------------------*/
4008+static VALUE Image_setX( VALUE obj, VALUE x )
4009+{
4010+ struct DXRubyImage *image;
4011+
4012+ Data_Get_Struct( obj, struct DXRubyImage, image );
4013+ image->x = NUM2INT( x );
4014+
4015+ return x;
4016+}
4017+
4018+
4019+/*--------------------------------------------------------------------
4020+ イメージの開始位置yを設定する。
4021+ ---------------------------------------------------------------------*/
4022+static VALUE Image_setY( VALUE obj, VALUE y )
4023+{
4024+ struct DXRubyImage *image;
4025+
4026+ Data_Get_Struct( obj, struct DXRubyImage, image );
4027+ image->y = NUM2INT( y );
4028+
4029+ return y;
4030+}
4031+
4032+
4033+/*--------------------------------------------------------------------
4034+ イメージのサイズ(幅)を設定する。
4035+ ---------------------------------------------------------------------*/
4036+static VALUE Image_setWidth( VALUE obj, VALUE width )
4037+{
4038+ struct DXRubyImage *image;
4039+
4040+ Data_Get_Struct( obj, struct DXRubyImage, image );
4041+ image->width = NUM2INT( width );
4042+
4043+ return width;
4044+}
4045+
4046+
4047+/*--------------------------------------------------------------------
4048+ イメージのサイズ(高さ)を設定する。
4049+ ---------------------------------------------------------------------*/
4050+static VALUE Image_setHeight( VALUE obj, VALUE height )
4051+{
4052+ struct DXRubyImage *image;
4053+
4054+ Data_Get_Struct( obj, struct DXRubyImage, image );
4055+ image->height = NUM2INT( height );
4056+
4057+ return height;
4058+}
4059+
4060+
4061+
4062+/*********************************************************************
4063+ * Soundクラス
4064+ *
4065+ * DirectMusicを使用して音を鳴らす。
4066+ * とりあえず音を出そうと頑張っている。
4067+ *********************************************************************/
4068+
4069+/*--------------------------------------------------------------------
4070+ 参照されなくなったときにGCから呼ばれる関数
4071+ ---------------------------------------------------------------------*/
4072+static void release_Sound( struct DXRubySound* sound )
4073+{
4074+ HRESULT hr;
4075+
4076+ /* サウンドオブジェクトの開放 */
4077+ if( sound )
4078+ {
4079+ /* バンド解放 */
4080+ if ( sound->pDMSegment != NULL )
4081+ {
4082+ hr = sound->pDMSegment->lpVtbl->Unload( sound->pDMSegment, (IUnknown* )sound->pDMDefAudioPath );
4083+ if( FAILED( hr ) )
4084+ {
4085+ rb_raise( eDXRubyError, "バンドの解放に失敗しました - Unload" );
4086+ }
4087+ /* セグメントを開放 */
4088+ RELEASE( sound->pDMSegment );
4089+ }
4090+
4091+ /* デフォルトオーディオパスを開放 */
4092+ RELEASE( sound->pDMDefAudioPath );
4093+
4094+ g_iRefDM--;
4095+
4096+ if( g_iRefDM <= 0 )
4097+ {
4098+ /* 演奏停止 */
4099+ if ( g_pDMPerformance )
4100+ {
4101+ hr = g_pDMPerformance->lpVtbl->Stop( g_pDMPerformance, NULL, NULL, 0, 0 );
4102+ if ( FAILED( hr ) )
4103+ {
4104+ rb_raise( eDXRubyError, "パフォーマンスの終了に失敗しました - Stop" );
4105+ }
4106+ }
4107+ g_pDMPerformance->lpVtbl->CloseDown( g_pDMPerformance );
4108+ RELEASE(g_pDMPerformance);
4109+
4110+ /* ローダを開放 */
4111+ RELEASE(g_pDMLoader);
4112+ }
4113+
4114+ free( sound );
4115+ sound = NULL;
4116+
4117+ g_iRefAll--;
4118+ if( g_iRefAll == 0 )
4119+ {
4120+ CoUninitialize();
4121+ }
4122+ }
4123+}
4124+
4125+
4126+/*--------------------------------------------------------------------
4127+ Soundクラスのallocate。メモリを確保する為にinitialize前に呼ばれる。
4128+ ---------------------------------------------------------------------*/
4129+static VALUE Sound_allocate( VALUE klass )
4130+{
4131+ VALUE obj;
4132+ struct DXRubySound *sound;
4133+
4134+ /* DXRubyImageのメモリ取得&Imageオブジェクト生成 */
4135+ sound = malloc(sizeof(struct DXRubySound));
4136+ if( sound == NULL ) rb_raise( eDXRubyError, "メモリの取得に失敗しました - Sound_allocate" );
4137+ obj = Data_Wrap_Struct(klass, 0, release_Sound, sound);
4138+
4139+ /* とりあえずサウンドオブジェクトはNULLにしておく */
4140+ sound->pDMSegment = NULL;
4141+
4142+ return obj;
4143+}
4144+
4145+
4146+/*--------------------------------------------------------------------
4147+ Soundクラスのinitialize。ファイルをロードする。
4148+ ---------------------------------------------------------------------*/
4149+static VALUE Sound_initialize( VALUE obj, VALUE filename )
4150+{
4151+ HRESULT hr;
4152+ WCHAR wstrFileName[MAX_PATH];
4153+ struct DXRubySound *sound;
4154+ CHAR strPath[MAX_PATH];
4155+ DWORD i;
4156+ WCHAR wstrSearchPath[MAX_PATH];
4157+
4158+ g_iRefAll++;
4159+
4160+ Check_Type(filename, T_STRING);
4161+
4162+ if( g_iRefDM == 0 )
4163+ {
4164+ /* パフォーマンスの作成 */
4165+ hr = CoCreateInstance( &CLSID_DirectMusicPerformance, NULL,
4166+ CLSCTX_INPROC_SERVER, &IID_IDirectMusicPerformance8,
4167+ (void**)&g_pDMPerformance );
4168+ if( FAILED( hr ) )
4169+ {
4170+ rb_raise( eDXRubyError, "DirectMusicの初期化に失敗しました - CoCreateInstance" );
4171+ }
4172+
4173+ /* パフォーマンスの初期化 */
4174+ hr = g_pDMPerformance->lpVtbl->InitAudio( g_pDMPerformance,
4175+ NULL, /* IDirectMusicインターフェイスは不要 */
4176+ NULL, /* IDirectSoundインターフェイスは不要 */
4177+ g_hWind, /* ウィンドウのハンドル */
4178+ DMUS_APATH_SHARED_STEREOPLUSREVERB, /* デフォルトのオーディオパス・タイプ */
4179+ 64, /* パフォーマンス・チャンネルの数 */
4180+ DMUS_AUDIOF_ALL, /* シンセサイザの機能 */
4181+ NULL ); /* オーディオ・パラメータにはデフォルトを使用 */
4182+ if( FAILED( hr ) )
4183+ {
4184+ rb_raise( eDXRubyError, "DirectMusicの初期化に失敗しました - InitAudio" );
4185+ }
4186+
4187+ /* ローダーの作成 */
4188+ hr = CoCreateInstance( &CLSID_DirectMusicLoader, NULL,
4189+ CLSCTX_INPROC_SERVER, &IID_IDirectMusicLoader8,
4190+ (void**)&g_pDMLoader );
4191+ if( FAILED( hr ) )
4192+ {
4193+ rb_raise( eDXRubyError, "DirectMusicの初期化に失敗しました - CoCreateInstance" );
4194+ }
4195+
4196+ /* ローダーの初期化(検索パスをカレント・ディレクトリに設定) */
4197+ i = GetCurrentDirectory( MAX_PATH, strPath );
4198+ if ( i == 0 || MAX_PATH < i )
4199+ {
4200+ rb_raise( eDXRubyError, "カレント・ディレクトリの取得に失敗 - GetCurrentDirectory" );
4201+ }
4202+
4203+ /* マルチ・バイト文字をUNICODEに変換 */
4204+ MultiByteToWideChar( CP_ACP, 0, strPath, -1, wstrSearchPath, MAX_PATH );
4205+
4206+ /* ローダーに検索パスを設定 */
4207+ hr = g_pDMLoader->lpVtbl->SetSearchDirectory( g_pDMLoader, &GUID_DirectMusicAllTypes,
4208+ wstrSearchPath, FALSE );
4209+ if( FAILED( hr ) )
4210+ {
4211+ rb_raise( eDXRubyError, "検索パスの設定に失敗 - SetSearchDirectory" );
4212+ }
4213+ }
4214+ g_iRefDM++;
4215+
4216+ /* サウンドオブジェクト取得 */
4217+ Data_Get_Struct( obj, struct DXRubySound, sound );
4218+
4219+ /* オーディオ・パス作成 */
4220+ hr = g_pDMPerformance->lpVtbl->CreateStandardAudioPath( g_pDMPerformance,
4221+ DMUS_APATH_DYNAMIC_STEREO, /* パスの種類。 */
4222+ 64, /* パフォーマンス チャンネルの数。 */
4223+ TRUE, /* ここでアクティブになる。 */
4224+ &sound->pDMDefAudioPath ); /* オーディオパスを受け取るポインタ。 */
4225+
4226+ if ( FAILED( hr ) )
4227+ {
4228+ rb_raise( eDXRubyError, "オーディオパスの作成に失敗しました - CreateStandardAudioPath" );
4229+ }
4230+
4231+ /* ファイルロード */
4232+ MultiByteToWideChar( CP_ACP, 0, RSTRING_PTR( filename ), -1, wstrFileName, MAX_PATH );
4233+ hr = g_pDMLoader->lpVtbl->LoadObjectFromFile( g_pDMLoader, &CLSID_DirectMusicSegment,
4234+ &IID_IDirectMusicSegment8,
4235+ wstrFileName,
4236+ (LPVOID*)&sound->pDMSegment );
4237+ if( FAILED( hr ) )
4238+ {
4239+ sound->pDMSegment = NULL;
4240+ rb_raise( eDXRubyError, "ファイルのロードに失敗しました - LoadObjectFromFile" );
4241+ }
4242+
4243+ sound->start = 0;
4244+ sound->loopstart = 0;
4245+ sound->loopend = 0;
4246+
4247+ /* MIDIの場合 */
4248+ if( strstr( RSTRING_PTR( filename ), ".mid" ) != NULL )
4249+ {
4250+ hr = sound->pDMSegment->lpVtbl->SetParam( sound->pDMSegment, &GUID_StandardMIDIFile,
4251+ 0xFFFFFFFF, 0, 0, NULL);
4252+ if( FAILED( hr ) )
4253+ {
4254+ rb_raise( eDXRubyError, "ファイルのロードに失敗しました - SetParam" );
4255+ }
4256+ sound->loopcount = DMUS_SEG_REPEAT_INFINITE;
4257+ sound->midwavflag = 0;
4258+ /* ループ回数設定 */
4259+ hr = sound->pDMSegment->lpVtbl->SetRepeats( sound->pDMSegment, sound->loopcount );
4260+
4261+ if( FAILED( hr ) )
4262+ {
4263+ rb_raise( eDXRubyError, "ループ回数の設定に失敗しました - SetRepeats" );
4264+ }
4265+ }
4266+ else
4267+ {
4268+ sound->loopcount = 1;
4269+ sound->midwavflag = 1;
4270+ }
4271+
4272+ /* バンドダウンロード */
4273+ hr = sound->pDMSegment->lpVtbl->Download( sound->pDMSegment, (IUnknown* )sound->pDMDefAudioPath );
4274+
4275+ if( FAILED( hr ) )
4276+ {
4277+ rb_raise( eDXRubyError, "バンドのロードに失敗しました - Download" );
4278+ }
4279+
4280+
4281+ /* 音量設定 */
4282+ hr = sound->pDMDefAudioPath->lpVtbl->SetVolume( sound->pDMDefAudioPath, 230 * 9600 / 255 - 9600 , 0 );
4283+
4284+ if( FAILED( hr ) )
4285+ {
4286+ rb_raise( eDXRubyError, "音量の設定に失敗しました - SetVolume" );
4287+ }
4288+
4289+ return obj;
4290+}
4291+
4292+
4293+/*--------------------------------------------------------------------
4294+ 開始位置を設定する
4295+ ---------------------------------------------------------------------*/
4296+static VALUE Sound_setStart( VALUE obj, VALUE vstart )
4297+{
4298+ HRESULT hr;
4299+ struct DXRubySound *sound;
4300+
4301+ Data_Get_Struct( obj, struct DXRubySound, sound );
4302+ sound->start = NUM2INT( vstart );
4303+
4304+ if( sound->midwavflag == 1 && sound->start > 0 ) /* wavの場合 */
4305+ {
4306+ hr = sound->pDMSegment->lpVtbl->SetLength( sound->pDMSegment, sound->start * DMUS_PPQ / 768 + 1 );
4307+ if( FAILED( hr ) )
4308+ {
4309+ rb_raise( eDXRubyError, "セグメント開始位置の設定に失敗しました - SetLength" );
4310+ }
4311+ }
4312+
4313+ /* セグメント再生スタート位置設定 */
4314+ hr = sound->pDMSegment->lpVtbl->SetStartPoint( sound->pDMSegment, sound->start * DMUS_PPQ / 768 );
4315+
4316+ if( FAILED( hr ) )
4317+ {
4318+ rb_raise( eDXRubyError, "セグメント開始位置の設定に失敗しました - SetStartPoint" );
4319+ }
4320+
4321+ return obj;
4322+}
4323+
4324+
4325+/*--------------------------------------------------------------------
4326+ ループ開始位置を設定する
4327+ ---------------------------------------------------------------------*/
4328+static VALUE Sound_setLoopStart( VALUE obj, VALUE vloopstart )
4329+{
4330+ HRESULT hr;
4331+ struct DXRubySound *sound;
4332+
4333+ Data_Get_Struct( obj, struct DXRubySound, sound );
4334+ sound->loopstart = NUM2INT( vloopstart );
4335+
4336+ if( sound->midwavflag == 1 )
4337+ {
4338+ rb_raise( eDXRubyError, "WAVデータにループ開始位置は設定できません - Sound_loopStart=" );
4339+ }
4340+
4341+ if( sound->loopstart <= sound->loopend )
4342+ {
4343+ /* ループ範囲設定 */
4344+ hr = sound->pDMSegment->lpVtbl->SetLoopPoints( sound->pDMSegment, sound->loopstart * DMUS_PPQ / 768
4345+ , sound->loopend * DMUS_PPQ / 768 );
4346+ if( FAILED( hr ) )
4347+ {
4348+ rb_raise( eDXRubyError, "ループ範囲の設定に失敗しました - SetLoopPoints" );
4349+ }
4350+ }
4351+ else
4352+ {
4353+ /* ループ範囲設定 */
4354+ hr = sound->pDMSegment->lpVtbl->SetLoopPoints( sound->pDMSegment, 0, 0 );
4355+
4356+ if( FAILED( hr ) )
4357+ {
4358+ rb_raise( eDXRubyError, "ループ範囲の設定に失敗しました - SetLoopPoints" );
4359+ }
4360+ }
4361+
4362+ return obj;
4363+}
4364+
4365+
4366+/*--------------------------------------------------------------------
4367+ ループ終了位置を設定する
4368+ ---------------------------------------------------------------------*/
4369+static VALUE Sound_setLoopEnd( VALUE obj, VALUE vloopend )
4370+{
4371+ HRESULT hr;
4372+ struct DXRubySound *sound;
4373+
4374+ Data_Get_Struct( obj, struct DXRubySound, sound );
4375+ sound->loopend = NUM2INT( vloopend );
4376+
4377+ if( sound->midwavflag == 1 )
4378+ {
4379+ rb_raise( eDXRubyError, "WAVデータにループ終了位置は設定できません - Sound_loopEnd=" );
4380+ }
4381+
4382+ if( sound->loopstart <= sound->loopend )
4383+ {
4384+ /* ループ範囲設定 */
4385+ hr = sound->pDMSegment->lpVtbl->SetLoopPoints( sound->pDMSegment, sound->loopstart * DMUS_PPQ / 768
4386+ , sound->loopend * DMUS_PPQ / 768 );
4387+ if( FAILED( hr ) )
4388+ {
4389+ rb_raise( eDXRubyError, "ループ範囲の設定に失敗しました - SetLoopPoints" );
4390+ }
4391+ }
4392+ else
4393+ {
4394+ /* ループ範囲設定 */
4395+ hr = sound->pDMSegment->lpVtbl->SetLoopPoints( sound->pDMSegment, 0, 0 );
4396+
4397+ if( FAILED( hr ) )
4398+ {
4399+ rb_raise( eDXRubyError, "ループ範囲の設定に失敗しました - SetLoopPoints" );
4400+ }
4401+ }
4402+
4403+
4404+ return obj;
4405+}
4406+
4407+
4408+/*--------------------------------------------------------------------
4409+ ループ回数を設定する
4410+ ---------------------------------------------------------------------*/
4411+static VALUE Sound_setLoopCount( VALUE obj, VALUE vloopcount )
4412+{
4413+ HRESULT hr;
4414+ struct DXRubySound *sound;
4415+
4416+ Data_Get_Struct( obj, struct DXRubySound, sound );
4417+ sound->loopcount = NUM2INT( vloopcount );
4418+
4419+ /* ループ回数設定 */
4420+ hr = sound->pDMSegment->lpVtbl->SetRepeats( sound->pDMSegment, sound->loopcount );
4421+
4422+ if( FAILED( hr ) )
4423+ {
4424+ rb_raise( eDXRubyError, "ループ回数の設定に失敗しました - SetRepeats" );
4425+ }
4426+
4427+ return obj;
4428+}
4429+
4430+
4431+/*--------------------------------------------------------------------
4432+ 音量を設定する
4433+ ---------------------------------------------------------------------*/
4434+static VALUE Sound_setVolume( int argc, VALUE *argv, VALUE obj )
4435+{
4436+ HRESULT hr;
4437+ struct DXRubySound *sound;
4438+ VALUE vvolume, vtime;
4439+ int volume, time;
4440+
4441+ rb_scan_args( argc, argv, "11", &vvolume, &vtime );
4442+
4443+ time = vtime == Qnil ? 0 : NUM2INT( vtime );
4444+ volume = NUM2INT( vvolume ) > 255 ? 255 : NUM2INT( vvolume );
4445+ Data_Get_Struct( obj, struct DXRubySound, sound );
4446+
4447+ /* 音量設定 */
4448+ hr = sound->pDMDefAudioPath->lpVtbl->SetVolume( sound->pDMDefAudioPath, volume * 9600 / 255 - 9600, time );
4449+
4450+ if( FAILED( hr ) )
4451+ {
4452+ rb_raise( eDXRubyError, "音量の設定に失敗しました - SetVolume" );
4453+ }
4454+
4455+ return obj;
4456+}
4457+
4458+
4459+/*--------------------------------------------------------------------
4460+ 音を鳴らす
4461+ ---------------------------------------------------------------------*/
4462+static VALUE Sound_play( VALUE obj )
4463+{
4464+ HRESULT hr;
4465+ struct DXRubySound *sound;
4466+
4467+ Data_Get_Struct( obj, struct DXRubySound, sound );
4468+
4469+ /* 再生 */
4470+ if( sound->midwavflag == 0 )
4471+ {
4472+ hr = g_pDMPerformance->lpVtbl->PlaySegmentEx( g_pDMPerformance, (IUnknown* )sound->pDMSegment, NULL, NULL,
4473+ DMUS_SEGF_CONTROL, 0, NULL, NULL, (IUnknown* )sound->pDMDefAudioPath );
4474+ }
4475+ else
4476+ {
4477+ hr = g_pDMPerformance->lpVtbl->PlaySegmentEx( g_pDMPerformance, (IUnknown* )sound->pDMSegment, NULL, NULL,
4478+ DMUS_SEGF_SECONDARY, 0, NULL, NULL, (IUnknown* )sound->pDMDefAudioPath );
4479+ }
4480+ if( FAILED( hr ) )
4481+ {
4482+ rb_raise( eDXRubyError, "音の再生に失敗しました - PlaySegmentEx" );
4483+ }
4484+
4485+ return obj;
4486+}
4487+
4488+
4489+/*--------------------------------------------------------------------
4490+ 音を止める
4491+ ---------------------------------------------------------------------*/
4492+static VALUE Sound_stop( VALUE obj )
4493+{
4494+ HRESULT hr;
4495+ struct DXRubySound *sound;
4496+
4497+ Data_Get_Struct( obj, struct DXRubySound, sound );
4498+
4499+ /* 再生 */
4500+ hr = g_pDMPerformance->lpVtbl->StopEx( g_pDMPerformance, (IUnknown* )sound->pDMSegment, 0, 0 );
4501+
4502+ if( FAILED( hr ) )
4503+ {
4504+ rb_raise( eDXRubyError, "音の停止に失敗しました - StopEx" );
4505+ }
4506+
4507+ return obj;
4508+
4509+}
4510+
4511+
4512+/*********************************************************************
4513+ * SoundEffectクラス
4514+ *
4515+ * DirectSoundを使用して音を鳴らす。
4516+ * とりあえず音を出そうと頑張っている。
4517+ *********************************************************************/
4518+
4519+/*--------------------------------------------------------------------
4520+ 参照されなくなったときにGCから呼ばれる関数
4521+ ---------------------------------------------------------------------*/
4522+static void release_SoundEffect( struct DXRubySoundEffect* soundeffect )
4523+{
4524+ /* サウンドオブジェクトの開放 */
4525+ if( soundeffect )
4526+ {
4527+ /* サウンドバッファを開放 */
4528+ RELEASE( soundeffect->pDSBuffer );
4529+
4530+ g_iRefDS--;
4531+
4532+ if( g_iRefDS == 0 )
4533+ {
4534+ RELEASE( g_pDSound );
4535+ }
4536+
4537+ free( soundeffect );
4538+ soundeffect = NULL;
4539+
4540+ g_iRefAll--;
4541+ if( g_iRefAll == 0 )
4542+ {
4543+ CoUninitialize();
4544+ }
4545+ }
4546+}
4547+
4548+
4549+/*--------------------------------------------------------------------
4550+ SoundEffectクラスのallocate。メモリを確保する為にinitialize前に呼ばれる。
4551+ ---------------------------------------------------------------------*/
4552+static VALUE SoundEffect_allocate( VALUE klass )
4553+{
4554+ VALUE obj;
4555+ struct DXRubySoundEffect *soundeffect;
4556+
4557+ /* DXRubySoundEffectのメモリ取得&SoundEffectオブジェクト生成 */
4558+ soundeffect = malloc(sizeof(struct DXRubySoundEffect));
4559+ if( soundeffect == NULL ) rb_raise( eDXRubyError, "メモリの取得に失敗しました - SoundEffect_allocate" );
4560+ obj = Data_Wrap_Struct(klass, 0, release_SoundEffect, soundeffect);
4561+
4562+ /* とりあえずサウンドオブジェクトはNULLにしておく */
4563+ soundeffect->pDSBuffer = NULL;
4564+
4565+ return obj;
4566+}
4567+
4568+
4569+static short calcwave(int type, double vol, double count, double p)
4570+{
4571+ switch( type )
4572+ {
4573+ case 1: /* サイン波 */
4574+ return (sin( (3.141592653589793115997963468544185161590576171875f * 2) * (double)count / (double)p )) * (double)vol * 128;
4575+ break;
4576+ case 2: /* ノコギリ波 */
4577+ return ((double)count / (double)p - 0.5) * (double)vol * 256;
4578+ break;
4579+ case 3: /* 三角波 */
4580+ if( count < p / 4 ) /* 1/4 */
4581+ {
4582+ return (double)count / ((double)p / 4) * (double)vol * 128;
4583+ }
4584+ else if( count < p / 2 ) /* 2/4 */
4585+ {
4586+ return ((double)p / 2 - (double)count) / ((double)p / 4) * (double)vol * 128;
4587+ }
4588+ else if( count < p * 3 / 4 ) /* 3/4 */
4589+ {
4590+ return -((double)count - (double)p / 2)/ ((double)p / 4) * (double)vol * 128;
4591+ }
4592+ else /* 最後 */
4593+ {
4594+ return -((double)p - (double)count) / ((double)p / 4) * (double)vol * 128;
4595+ }
4596+ break;
4597+ case 0: /* 矩形波 */
4598+ default: /* デフォルト */
4599+ if( count < p / 2 ) /* 前半 */
4600+ {
4601+ return vol * 128;
4602+ }
4603+ else /* 後半 */
4604+ {
4605+ return -vol * 128;
4606+ }
4607+ break;
4608+ }
4609+}
4610+/*--------------------------------------------------------------------
4611+ SoundEffectクラスのinitialize。波形を生成する。
4612+ ---------------------------------------------------------------------*/
4613+static VALUE SoundEffect_initialize( int argc, VALUE *argv, VALUE obj )
4614+{
4615+ HRESULT hr;
4616+ struct DXRubySoundEffect *soundeffect;
4617+ DSBUFFERDESC desc;
4618+ WAVEFORMATEX pcmwf;
4619+ int i;
4620+ short *pointer, *pointer2;
4621+ DWORD size, size2;
4622+ VALUE vf;
4623+ double count;
4624+ int vol;
4625+ double f;
4626+ VALUE vsize, vtype, vresolution;
4627+ int type, resolution;
4628+
4629+ g_iRefAll++;
4630+
4631+ rb_scan_args( argc, argv, "12", &vsize, &vtype, &vresolution );
4632+
4633+ type = vtype == Qnil ? 0 : NUM2INT( vtype );
4634+ resolution = vresolution == Qnil ? 1000 : (NUM2INT( vresolution ) > 44100 ? 44100 : NUM2INT( vresolution ));
4635+
4636+ /* DirectSoundオブジェクトの作成 */
4637+ if( g_iRefDS == 0 )
4638+ {
4639+ hr = DirectSoundCreate8( &DSDEVID_DefaultPlayback, &g_pDSound, NULL );
4640+ if( FAILED( hr ) )
4641+ {
4642+ rb_raise( eDXRubyError, "DirectSoundの初期化に失敗しました - DirectSoundCreate8" );
4643+ }
4644+
4645+ hr = g_pDSound->lpVtbl->SetCooperativeLevel( g_pDSound, g_hWind, DSSCL_PRIORITY );
4646+ if( FAILED( hr ) )
4647+ {
4648+ rb_raise( eDXRubyError, "DirectSoundの初期化に失敗しました - SetCooperativeLevel" );
4649+ }
4650+ }
4651+ g_iRefDS++;
4652+
4653+ /* サウンドオブジェクト作成 */
4654+ Data_Get_Struct( obj, struct DXRubySoundEffect, soundeffect );
4655+
4656+ /* サウンドバッファ作成 */
4657+ pcmwf.wFormatTag = WAVE_FORMAT_PCM;
4658+ pcmwf.nChannels = 1;
4659+ pcmwf.nSamplesPerSec = 44100 * 2;
4660+ pcmwf.wBitsPerSample = 16;
4661+ pcmwf.nBlockAlign = pcmwf.nChannels * pcmwf.wBitsPerSample / 8;
4662+ pcmwf.nAvgBytesPerSec = pcmwf.nSamplesPerSec * pcmwf.nBlockAlign;
4663+ pcmwf.cbSize = 0;
4664+
4665+ desc.dwSize = sizeof(desc);
4666+ desc.dwFlags = DSBCAPS_GLOBALFOCUS;
4667+ desc.dwBufferBytes = pcmwf.nAvgBytesPerSec / 100 * NUM2INT(vsize) / 10;
4668+ desc.dwReserved = 0;
4669+ desc.lpwfxFormat = &pcmwf;
4670+ desc.guid3DAlgorithm = DS3DALG_DEFAULT;
4671+
4672+ hr = g_pDSound->lpVtbl->CreateSoundBuffer( g_pDSound, &desc, &soundeffect->pDSBuffer, NULL );
4673+
4674+ if( FAILED( hr ) )
4675+ {
4676+ rb_raise( eDXRubyError, "サウンドバッファの作成に失敗しました - CreateSoundBuffer" );
4677+ }
4678+
4679+ /* ロック */
4680+ hr = soundeffect->pDSBuffer->lpVtbl->Lock( soundeffect->pDSBuffer, 0, 0, &pointer, &size, &pointer2, &size2, DSBLOCK_ENTIREBUFFER );
4681+ if( FAILED( hr ) || size2 != 0 )
4682+ {
4683+ rb_raise( eDXRubyError, "サウンドバッファのロックに失敗しました - Lock" );
4684+ }
4685+
4686+ /* 音バッファ初期化 */
4687+ for( i = 0; i < desc.dwBufferBytes / (pcmwf.wBitsPerSample / 8); i++ )
4688+ {
4689+ pointer[i] = 0;
4690+ }
4691+
4692+ count = 0;
4693+
4694+ /* 波形生成 */
4695+ for( i = 0; i < desc.dwBufferBytes / (pcmwf.wBitsPerSample / 8); i++ )
4696+ {
4697+ /* 指定時間単位でブロックを呼び出す */
4698+ if ( i % (pcmwf.nSamplesPerSec / resolution) == 0 )
4699+ {
4700+ vf = rb_yield( obj );
4701+ if( TYPE( vf ) != T_ARRAY )
4702+ {
4703+ soundeffect->pDSBuffer->lpVtbl->Unlock( soundeffect->pDSBuffer, pointer, size, pointer2, size2 );
4704+ rb_raise(rb_eTypeError, "not valid value - SoundEffect_initialize");
4705+ break;
4706+ }
4707+ switch (TYPE( rb_ary_entry(vf, 0) )) {
4708+ case T_FIXNUM:
4709+ case T_FLOAT:
4710+ f = NUM2DBL( rb_ary_entry(vf, 0) );
4711+ break;
4712+ default:
4713+ soundeffect->pDSBuffer->lpVtbl->Unlock( soundeffect->pDSBuffer, pointer, size, pointer2, size2 );
4714+ rb_raise(rb_eTypeError, "not valid value - SoundEffect_initialize");
4715+ break;
4716+ }
4717+ switch (TYPE( rb_ary_entry(vf, 1) )) {
4718+ case T_FIXNUM:
4719+ case T_FLOAT:
4720+ vol = NUM2DBL(rb_ary_entry(vf, 1));
4721+ break;
4722+ default:
4723+ soundeffect->pDSBuffer->lpVtbl->Unlock( soundeffect->pDSBuffer, pointer, size, pointer2, size2 );
4724+ rb_raise(rb_eTypeError, "not valid value - SoundEffect_initialize");
4725+ break;
4726+ }
4727+ /* 最大/最低周波数と最大ボリュームの制限 */
4728+ f = f > pcmwf.nSamplesPerSec / 2.0f ? pcmwf.nSamplesPerSec / 2.0f : f;
4729+ f = f < 20 ? 20 : f;
4730+ vol = vol > 255 ? 255 : vol;
4731+ vol = vol < 0 ? 0 : vol;
4732+ }
4733+ count = count + f;
4734+ if( count >= pcmwf.nSamplesPerSec )
4735+ {
4736+ count = count - pcmwf.nSamplesPerSec;
4737+ }
4738+ pointer[i] = calcwave(type, vol, count, pcmwf.nSamplesPerSec);
4739+ }
4740+
4741+ /* アンロック */
4742+ hr = soundeffect->pDSBuffer->lpVtbl->Unlock( soundeffect->pDSBuffer, pointer, size, pointer2, size2 );
4743+ if( FAILED( hr ) )
4744+ {
4745+ rb_raise( eDXRubyError, "サウンドバッファのロックに失敗しました - Lock" );
4746+ }
4747+
4748+ return obj;
4749+
4750+}
4751+
4752+
4753+/*--------------------------------------------------------------------
4754+ 波形を合成する。
4755+ ---------------------------------------------------------------------*/
4756+static VALUE SoundEffect_add( int argc, VALUE *argv, VALUE obj )
4757+{
4758+ HRESULT hr;
4759+ struct DXRubySoundEffect *soundeffect;
4760+ DSBUFFERDESC desc;
4761+ WAVEFORMATEX pcmwf;
4762+ int i;
4763+ short *pointer, *pointer2;
4764+ DWORD size, size2;
4765+ VALUE vf, vtype, vresolution;
4766+ double count;
4767+ int vol;
4768+ double f;
4769+ int type, resolution;
4770+ int data;
4771+
4772+ rb_scan_args( argc, argv, "02", &vtype, &vresolution );
4773+
4774+ type = vtype == Qnil ? 0 : NUM2INT( vtype );
4775+ resolution = vresolution == Qnil ? 1000 : (NUM2INT( vresolution ) > 44100 ? 44100 : NUM2INT( vresolution ));
4776+
4777+ /* サウンドオブジェクト取得 */
4778+ Data_Get_Struct( obj, struct DXRubySoundEffect, soundeffect );
4779+
4780+ /* ロック */
4781+ hr = soundeffect->pDSBuffer->lpVtbl->Lock( soundeffect->pDSBuffer, 0, 0, &pointer, &size, &pointer2, &size2, DSBLOCK_ENTIREBUFFER );
4782+ if( FAILED( hr ) || size2 != 0 )
4783+ {
4784+ rb_raise( eDXRubyError, "サウンドバッファのロックに失敗しました - Lock" );
4785+ }
4786+
4787+ pcmwf.nChannels = 1;
4788+ pcmwf.nSamplesPerSec = 44100 * 2;
4789+ pcmwf.wBitsPerSample = 16;
4790+ pcmwf.nBlockAlign = pcmwf.nChannels * pcmwf.wBitsPerSample / 8;
4791+ pcmwf.nAvgBytesPerSec = pcmwf.nSamplesPerSec * pcmwf.nBlockAlign;
4792+ desc.dwBufferBytes = size;
4793+
4794+ count = 0;
4795+
4796+ /* 波形生成 */
4797+ for( i = 0; i < desc.dwBufferBytes / (pcmwf.wBitsPerSample / 8); i++ )
4798+ {
4799+ /* 指定時間単位でブロックを呼び出す */
4800+ if ( i % (pcmwf.nSamplesPerSec / resolution) == 0 )
4801+ {
4802+ vf = rb_yield( obj );
4803+ if( TYPE( vf ) != T_ARRAY )
4804+ {
4805+ soundeffect->pDSBuffer->lpVtbl->Unlock( soundeffect->pDSBuffer, pointer, size, pointer2, size2 );
4806+ rb_raise(rb_eTypeError, "not valid value - SoundEffect_initialize");
4807+ break;
4808+ }
4809+ switch (TYPE( rb_ary_entry(vf, 0) )) {
4810+ case T_FIXNUM:
4811+ case T_FLOAT:
4812+ f = NUM2DBL( rb_ary_entry(vf, 0) );
4813+ break;
4814+ default:
4815+ soundeffect->pDSBuffer->lpVtbl->Unlock( soundeffect->pDSBuffer, pointer, size, pointer2, size2 );
4816+ rb_raise(rb_eTypeError, "not valid value - SoundEffect_initialize");
4817+ break;
4818+ }
4819+ switch (TYPE( rb_ary_entry(vf, 1) )) {
4820+ case T_FIXNUM:
4821+ case T_FLOAT:
4822+ vol = NUM2DBL(rb_ary_entry(vf, 1));
4823+ break;
4824+ default:
4825+ soundeffect->pDSBuffer->lpVtbl->Unlock( soundeffect->pDSBuffer, pointer, size, pointer2, size2 );
4826+ rb_raise(rb_eTypeError, "not valid value - SoundEffect_initialize");
4827+ break;
4828+ }
4829+ /* 最大/最低周波数と最大ボリュームの制限 */
4830+ f = f > pcmwf.nSamplesPerSec / 2.0f ? pcmwf.nSamplesPerSec / 2.0f : f;
4831+ f = f < 20 ? 20 : f;
4832+ vol = vol > 255 ? 255 : vol;
4833+ vol = vol < 0 ? 0 : vol;
4834+ }
4835+ count = count + f;
4836+ if( count >= pcmwf.nSamplesPerSec )
4837+ {
4838+ count = count - pcmwf.nSamplesPerSec;
4839+ }
4840+
4841+ data = calcwave(type, vol, count, pcmwf.nSamplesPerSec);
4842+
4843+ if( data + (int)pointer[i] > 32767 )
4844+ {
4845+ pointer[i] = 32767;
4846+ }
4847+ else if( data + (int)pointer[i] < -32768 )
4848+ {
4849+ pointer[i] = -32768;
4850+ }
4851+ else
4852+ {
4853+ pointer[i] += data;
4854+ }
4855+ }
4856+
4857+ /* アンロック */
4858+ hr = soundeffect->pDSBuffer->lpVtbl->Unlock( soundeffect->pDSBuffer, pointer, size, pointer2, size2 );
4859+ if( FAILED( hr ) )
4860+ {
4861+ rb_raise( eDXRubyError, "サウンドバッファのロックに失敗しました - Lock" );
4862+ }
4863+
4864+ return obj;
4865+
4866+}
4867+
4868+
4869+/*--------------------------------------------------------------------
4870+ 音を鳴らす
4871+ ---------------------------------------------------------------------*/
4872+static VALUE SoundEffect_play( VALUE obj )
4873+{
4874+ HRESULT hr;
4875+ struct DXRubySoundEffect *soundeffect;
4876+
4877+ Data_Get_Struct( obj, struct DXRubySoundEffect, soundeffect );
4878+
4879+ /* とめる */
4880+ hr = soundeffect->pDSBuffer->lpVtbl->Stop( soundeffect->pDSBuffer );
4881+ if( FAILED( hr ) )
4882+ {
4883+ rb_raise( eDXRubyError, "音の再生に失敗しました - SoundEffect_play" );
4884+ }
4885+
4886+ hr = soundeffect->pDSBuffer->lpVtbl->SetCurrentPosition( soundeffect->pDSBuffer, 0 );
4887+ if( FAILED( hr ) )
4888+ {
4889+ rb_raise( eDXRubyError, "音の再生に失敗しました - SoundEffect_play" );
4890+ }
4891+
4892+ /* 再生 */
4893+ hr = soundeffect->pDSBuffer->lpVtbl->Play( soundeffect->pDSBuffer, 0, 0, 0 );
4894+ if( FAILED( hr ) )
4895+ {
4896+ rb_raise( eDXRubyError, "音の再生に失敗しました - SoundEffect_play" );
4897+ }
4898+ return obj;
4899+}
4900+
4901+
4902+/*--------------------------------------------------------------------
4903+ 音を止める
4904+ ---------------------------------------------------------------------*/
4905+static VALUE SoundEffect_stop( VALUE obj )
4906+{
4907+ HRESULT hr;
4908+ struct DXRubySoundEffect *soundeffect;
4909+
4910+ Data_Get_Struct( obj, struct DXRubySoundEffect, soundeffect );
4911+
4912+ /* とめる */
4913+ hr = soundeffect->pDSBuffer->lpVtbl->Stop( soundeffect->pDSBuffer );
4914+ if( FAILED( hr ) )
4915+ {
4916+ rb_raise( eDXRubyError, "音の停止に失敗しました - Stop" );
4917+ }
4918+
4919+ return obj;
4920+}
4921+
4922+
4923+
4924+/*********************************************************************
4925+ * Inputモジュール
4926+ *
4927+ * DirectInputを使用してキーボード・パッドの入力を行う。
4928+ *********************************************************************/
4929+
4930+/*--------------------------------------------------------------------
4931+ Windowsメッセージ処理込みの入力更新
4932+ ---------------------------------------------------------------------*/
4933+static VALUE Input_update( VALUE obj )
4934+{
4935+ MSG msg;
4936+ msg.message = WM_NULL;
4937+ g_WindowInfo.loop = 1;
4938+
4939+ /* メッセージループ */
4940+ /* メッセージがなくなるまで処理をし続ける */
4941+ /* メッセージが無い時はブロックをyieldする */
4942+ while (1)
4943+ {
4944+ if( PeekMessage( &msg, 0, 0, 0, PM_REMOVE ) != 0)
4945+ {
4946+ /* メッセージがある時 */
4947+ TranslateMessage( &msg );
4948+ DispatchMessage( &msg );
4949+ }
4950+ else
4951+ {
4952+ break;
4953+ }
4954+ }
4955+
4956+ if( g_WindowInfo.requestclose == 1 )
4957+ {
4958+ g_WindowInfo.requestclose = 0;
4959+ return Qtrue;
4960+ }
4961+
4962+ /* メッセージが無い時 */
4963+ /* 入力状態更新 */
4964+ inputupdate();
4965+
4966+ return Qfalse;
4967+}
4968+
4969+
4970+/*--------------------------------------------------------------------
4971+ Inputモジュールの入力処理
4972+ ---------------------------------------------------------------------*/
4973+static void inputupdate( void )
4974+{
4975+ int i, j;
4976+ DIJOYSTATE paddata;
4977+
4978+ /* フォーカスがはずれた場合、キーとパッド、マウスボタンの入力を受け付けなくする */
4979+ if( g_bActive == 0 )
4980+ {
4981+ /* キーボードのデータをクリアする */
4982+ ZeroMemory( &g_diKeyState, sizeof(g_diKeyState) );
4983+ ZeroMemory( &g_diKeyStateOld, sizeof(g_diKeyStateOld) );
4984+
4985+ /* パッドデータをクリアする */
4986+ for( i = 0; i < g_JoystickCount; i++ )
4987+ {
4988+ for( j = 0; j < 20; j++ )
4989+ {
4990+ g_PadStateOld[i].button[j] = g_PadState[i].button[j];
4991+ g_PadState[i].button[j] = 0;
4992+ }
4993+ }
4994+
4995+ /* マウスボタンのデータをクリアする */
4996+ g_byMouseStateOld_L = g_byMouseState_L;
4997+ g_byMouseStateOld_M = g_byMouseState_M;
4998+ g_byMouseStateOld_R = g_byMouseState_R;
4999+ g_byMouseState_L = 0;
5000+ g_byMouseState_M = 0;
5001+ g_byMouseState_R = 0;
5002+
5003+ return;
5004+ }
5005+
5006+ /* デバイスアクセス権を再取得する */
5007+ g_pDIDKeyBoard->lpVtbl->Acquire( g_pDIDKeyBoard );
5008+
5009+ for( i = 0; i < g_JoystickCount; i++ )
5010+ {
5011+ g_pDIDJoyPad[i]->lpVtbl->Poll( g_pDIDJoyPad[i] );
5012+ g_pDIDJoyPad[i]->lpVtbl->Acquire( g_pDIDJoyPad[i] );
5013+ }
5014+
5015+ /* キーボードの直接データを取得する */
5016+ memcpy( g_diKeyStateOld, g_diKeyState, sizeof(g_diKeyState) );
5017+ g_pDIDKeyBoard->lpVtbl->GetDeviceState( g_pDIDKeyBoard, 256, g_diKeyState );
5018+
5019+ /* ゲームパッドのデータを取得する */
5020+ for( i = 0; i < g_JoystickCount; i++ )
5021+ {
5022+ int j;
5023+
5024+ g_pDIDJoyPad[i]->lpVtbl->GetDeviceState( g_pDIDJoyPad[i], sizeof(DIJOYSTATE), &paddata );
5025+
5026+ for( j = 0; j < 20; j++ )
5027+ {
5028+ g_PadStateOld[i].button[j] = g_PadState[i].button[j];
5029+ g_PadState[i].button[j] = 0;
5030+ }
5031+
5032+ /* 左 */
5033+ if( paddata.lX < g_PadInfo[i].left )
5034+ {
5035+ g_PadState[i].button[P_LEFT] = 1;
5036+ }
5037+ /* 右 */
5038+ else if( paddata.lX > g_PadInfo[i].right )
5039+ {
5040+ g_PadState[i].button[P_RIGHT] = 1;
5041+ }
5042+
5043+ /* 上 */
5044+ if( paddata.lY < g_PadInfo[i].up )
5045+ {
5046+ g_PadState[i].button[P_UP] = 1;
5047+ }
5048+ /* 下 */
5049+ else if( paddata.lY > g_PadInfo[i].down )
5050+ {
5051+ g_PadState[i].button[P_DOWN] = 1;
5052+ }
5053+
5054+ /* ボタン状態 */
5055+ for( j = 0; j < 16; j++)
5056+ {
5057+ g_PadState[i].button[j + 4] = paddata.rgbButtons[j] >> 7;
5058+ }
5059+ }
5060+
5061+ /* マウスボタンの状態 */
5062+ g_byMouseStateOld_L = g_byMouseState_L;
5063+ g_byMouseStateOld_M = g_byMouseState_M;
5064+ g_byMouseStateOld_R = g_byMouseState_R;
5065+ g_byMouseState_L = GetKeyState( VK_LBUTTON );
5066+ g_byMouseState_M = GetKeyState( VK_MBUTTON );
5067+ g_byMouseState_R = GetKeyState( VK_RBUTTON );
5068+
5069+ return;
5070+}
5071+
5072+
5073+/*--------------------------------------------------------------------
5074+ Inputモジュールのデータ取得
5075+
5076+ 横方向の入力をxの増分で返す
5077+ ---------------------------------------------------------------------*/
5078+static VALUE Input_x( int argc, VALUE *argv, VALUE obj )
5079+{
5080+ int x = 0;
5081+ VALUE vnumber;
5082+ int number;
5083+
5084+ rb_scan_args( argc, argv, "01", &vnumber);
5085+
5086+ number = (vnumber == Qnil ? 0 : NUM2INT( vnumber ));
5087+
5088+ if( number < 0 || number >= PADMAX )
5089+ {
5090+ rb_raise( eDXRubyError, "値が範囲外です。 - Input_x" );
5091+ }
5092+
5093+ /* ひだり */
5094+ if( g_diKeyState[g_PadState[number].PadConfig[P_LEFT]] & 0x80 || g_PadState[number].button[P_LEFT] == 1 )
5095+ {
5096+ x = x - 1;
5097+ }
5098+
5099+ /* みぎ */
5100+ if( g_diKeyState[g_PadState[number].PadConfig[P_RIGHT]] & 0x80 || g_PadState[number].button[P_RIGHT] == 1 )
5101+ {
5102+ x = x + 1;
5103+ }
5104+
5105+ return INT2FIX( x );
5106+}
5107+
5108+
5109+/*--------------------------------------------------------------------
5110+ Inputモジュールのデータ取得
5111+
5112+ 縦方向の入力をyの増分で返す
5113+ ---------------------------------------------------------------------*/
5114+static VALUE Input_y( int argc, VALUE *argv, VALUE obj )
5115+{
5116+ int y = 0;
5117+ VALUE vnumber;
5118+ int number;
5119+
5120+ rb_scan_args( argc, argv, "01", &vnumber);
5121+
5122+ number = (vnumber == Qnil ? 0 : NUM2INT( vnumber ));
5123+
5124+ if( number < 0 || number >= PADMAX )
5125+ {
5126+ rb_raise( eDXRubyError, "値が範囲外です。 - Input_y" );
5127+ }
5128+
5129+
5130+ /* うえ */
5131+ if( g_diKeyState[g_PadState[number].PadConfig[P_UP]] & 0x80 || g_PadState[number].button[P_UP] == 1 )
5132+ {
5133+ y = y - 1;
5134+ }
5135+
5136+ /* した */
5137+ if( g_diKeyState[g_PadState[number].PadConfig[P_DOWN]] & 0x80 || g_PadState[number].button[P_DOWN] == 1 )
5138+ {
5139+ y = y + 1;
5140+ }
5141+
5142+ return INT2FIX( y );
5143+}
5144+
5145+
5146+/*--------------------------------------------------------------------
5147+ Inputモジュールのデータ取得
5148+
5149+ 押されていたらtrueになる。引数はキーコード。
5150+ ---------------------------------------------------------------------*/
5151+static VALUE Input_keyDown( VALUE obj , VALUE vkey )
5152+{
5153+ int key, padbutton = 0;
5154+
5155+ key = NUM2INT( vkey );
5156+ if( key < 0 || key >= 256 )
5157+ {
5158+ rb_raise( eDXRubyError, "値が範囲外です。 - Input_keyDown" );
5159+ }
5160+
5161+ if( g_diKeyConfig[key] != -1 && g_PadState[g_diKeyConfig[key] / 20].button[g_diKeyConfig[key] % 20] == 1 )
5162+ {
5163+ padbutton = 1;
5164+ }
5165+
5166+ if( g_diKeyState[key] & 0x80 || padbutton == 1)
5167+ {
5168+ return Qtrue;
5169+ }
5170+
5171+ return Qfalse;
5172+}
5173+
5174+
5175+/*--------------------------------------------------------------------
5176+ Inputモジュールのデータ取得
5177+
5178+ 押した瞬間だけtrueになる。引数はキーコード。
5179+ ---------------------------------------------------------------------*/
5180+static VALUE Input_keyPush( VALUE obj , VALUE vkey )
5181+{
5182+ int key, padbutton = 0, padbuttonold = 0;
5183+
5184+ key = NUM2INT( vkey );
5185+ if( key < 0 || key >= 256 )
5186+ {
5187+ rb_raise( eDXRubyError, "値が範囲外です。 - Input_keyPush" );
5188+ }
5189+
5190+ if( g_diKeyConfig[key] != -1 )
5191+ {
5192+ if( g_PadState[g_diKeyConfig[key] / 20].button[g_diKeyConfig[key] % 20] == 1 )
5193+ {
5194+ padbutton = 1;
5195+ }
5196+ if( g_PadStateOld[g_diKeyConfig[key] / 20].button[g_diKeyConfig[key] % 20] == 1 )
5197+ {
5198+ padbuttonold = 1;
5199+ }
5200+ }
5201+
5202+ if( (g_diKeyState[key] & 0x80) || padbutton == 1 ) /* 入力されている */
5203+ {
5204+ if( !(g_diKeyStateOld[key] & 0x80) && padbuttonold == 0 ) /* 前回OFFである */
5205+ {
5206+ g_diKeyCount[key] = 0; /* カウント初期化 */
5207+ return Qtrue; /* なにはともあれTrue */
5208+ }
5209+ else /* 前回ONだった */
5210+ {
5211+ g_diKeyCount[key]++; /* カウント */
5212+ if( g_diKeyWait[key] <= g_diKeyCount[key] ) /* ウェイトタイムを超えたか */
5213+ {
5214+ if( g_diKeyInterval[key] != 0 &&
5215+ (g_diKeyCount[key] - g_diKeyWait[key]) % g_diKeyInterval[key] == 0 ) /* インターバルタイムごとに */
5216+ {
5217+ return Qtrue; /* True */
5218+ }
5219+ }
5220+ }
5221+ }
5222+
5223+ return Qfalse;
5224+}
5225+
5226+
5227+/*--------------------------------------------------------------------
5228+ Inputモジュールのデータ取得
5229+
5230+ 押されていたらtrueになる。引数はボタン番号。
5231+ ---------------------------------------------------------------------*/
5232+static VALUE Input_padDown( int argc, VALUE *argv, VALUE obj )
5233+{
5234+ VALUE vnumber, vbutton;
5235+ int number, button, key = 0;
5236+
5237+ rb_scan_args( argc, argv, "11", &vbutton, &vnumber);
5238+
5239+ button = NUM2INT( vbutton );
5240+ number = (vnumber == Qnil ? 0 : NUM2INT( vnumber ));
5241+
5242+ if( number < 0 || button < 0 || number >= PADMAX || button >= 20 )
5243+ {
5244+ rb_raise( eDXRubyError, "値が範囲外です。 - Input_padDown" );
5245+ }
5246+
5247+ if( g_PadState[number].PadConfig[button] != -1 && g_diKeyState[g_PadState[number].PadConfig[button]] & 0x80 )
5248+ {
5249+ key = 1;
5250+ }
5251+
5252+ if( key == 1 || g_PadState[number].button[button] == 1 )
5253+ {
5254+ return Qtrue;
5255+ }
5256+
5257+ return Qfalse;
5258+}
5259+
5260+
5261+/*--------------------------------------------------------------------
5262+ Inputモジュールのデータ取得
5263+
5264+ 押した瞬間だけtrueになる。引数はボタン番号。
5265+ ---------------------------------------------------------------------*/
5266+static VALUE Input_padPush( int argc, VALUE *argv, VALUE obj )
5267+{
5268+ VALUE vnumber, vbutton;
5269+ int number, button, key = 0, keyold = 0;
5270+
5271+ rb_scan_args( argc, argv, "11", &vbutton, &vnumber);
5272+
5273+ button = NUM2INT( vbutton );
5274+ number = (vnumber == Qnil ? 0 : NUM2INT( vnumber ));
5275+
5276+ if( number < 0 || button < 0 || number >= PADMAX || button >= 20 )
5277+ {
5278+ rb_raise( eDXRubyError, "値が範囲外です。 - Input_padPush" );
5279+ }
5280+
5281+ if( g_PadState[number].PadConfig[button] != -1 )
5282+ {
5283+ if( g_diKeyState[g_PadState[number].PadConfig[button]] & 0x80 )
5284+ {
5285+ key = 1;
5286+ }
5287+ if( g_diKeyStateOld[g_PadState[number].PadConfig[button]] & 0x80 )
5288+ {
5289+ keyold = 1;
5290+ }
5291+ }
5292+
5293+ if( key == 1 || g_PadState[number].button[button] == 1 ) /* 入力されている */
5294+ {
5295+ if( keyold == 0 && g_PadStateOld[number].button[button] == 0 ) /* 前回OFFである */
5296+ {
5297+ g_PadState[number].count[button] = 0; /* カウント初期化 */
5298+ return Qtrue; /* なにはともあれTrue */
5299+ }
5300+ else /* 前回ONだった */
5301+ {
5302+ g_PadState[number].count[button]++; /* カウント */
5303+ if( g_PadState[number].wait[button] <= g_PadState[number].count[button] ) /* ウェイトタイムを超えたか */
5304+ {
5305+ if( g_PadState[number].interval[button] != 0 &&
5306+ (g_PadState[number].count[button] - g_PadState[number].wait[button])
5307+ % g_PadState[number].interval[button] == 0 ) /* インターバルタイムごとに */
5308+ {
5309+ return Qtrue; /* True */
5310+ }
5311+ }
5312+ }
5313+ }
5314+
5315+ return Qfalse;
5316+}
5317+
5318+
5319+/*--------------------------------------------------------------------
5320+ パッドとキーの対応を設定する
5321+ ---------------------------------------------------------------------*/
5322+static void Input_SetConfig( int number, int pad, int key )
5323+{
5324+ int i, j;
5325+
5326+ if( pad == -1 ) /* キーに対するパッド割り当て解除処理 */
5327+ {
5328+ g_diKeyConfig[key] = -1;
5329+ for( i = 0; i < PADMAX; i++)
5330+ {
5331+ for( j = 0; j < 20; j++)
5332+ {
5333+ if( g_PadState[i].PadConfig[j] == key )
5334+ {
5335+ g_PadState[i].PadConfig[j] = -1;
5336+ }
5337+ }
5338+ }
5339+ }
5340+ else if( key == -1 || key == 0 ) /* パッドに対するキー割り当て解除処理 */
5341+ {
5342+ g_PadState[number].PadConfig[pad] = -1;
5343+ for( i = 0; i < 256; i++)
5344+ {
5345+ if( g_diKeyConfig[i] == pad )
5346+ {
5347+ g_diKeyConfig[i] = -1;
5348+ }
5349+ }
5350+ }
5351+ else /* 割り当て処理 */
5352+ {
5353+ g_PadState[number].PadConfig[pad] = key;
5354+ g_diKeyConfig[key] = number * 20 + pad;
5355+ }
5356+}
5357+
5358+static VALUE Input_setconfig( int argc, VALUE *argv, VALUE obj )
5359+{
5360+ VALUE vnumber, vpad, vkey;
5361+ int number, pad, key;
5362+
5363+ rb_scan_args( argc, argv, "21", &vpad, &vkey, &vnumber);
5364+
5365+ number = (vnumber == Qnil ? 0 : NUM2INT( vnumber ));
5366+ pad = (vpad == Qnil ? -1 : NUM2INT( vpad ));
5367+ key = (vkey == Qnil ? -1 : NUM2INT( vkey ));
5368+
5369+ if( number < 0 || pad < -1 || key < -1 || number >= PADMAX || pad >= 20 || key >= 256 )
5370+ {
5371+ rb_raise( eDXRubyError, "値が範囲外です。 - Input_setconfig" );
5372+ }
5373+
5374+ if( pad != -1 || key != -1 )
5375+ {
5376+ Input_SetConfig( number, pad, key );
5377+ }
5378+
5379+ return obj;
5380+}
5381+
5382+
5383+/*--------------------------------------------------------------------
5384+ マウスホイールの状態を返す
5385+ ---------------------------------------------------------------------*/
5386+static VALUE Input_getmousewheelpos( VALUE obj )
5387+{
5388+ return INT2FIX(g_WindowInfo.mousewheelpos);
5389+}
5390+
5391+
5392+/*--------------------------------------------------------------------
5393+ マウスホイールの状態を設定する
5394+ ---------------------------------------------------------------------*/
5395+static VALUE Input_setmousewheelpos( VALUE obj, VALUE wheelpos )
5396+{
5397+ g_WindowInfo.mousewheelpos = NUM2INT( wheelpos );
5398+
5399+ return obj;
5400+}
5401+
5402+
5403+/*--------------------------------------------------------------------
5404+ マウスのボタン状態を返す
5405+ ---------------------------------------------------------------------*/
5406+static VALUE Input_mouseDown( VALUE obj, VALUE button )
5407+{
5408+
5409+ switch( NUM2INT( button ) )
5410+ {
5411+ case M_LBUTTON:
5412+ if( g_byMouseState_L & 0x80 )
5413+ {
5414+ return Qtrue;
5415+ }
5416+ else
5417+ {
5418+ return Qfalse;
5419+ }
5420+
5421+ case M_RBUTTON:
5422+ if( g_byMouseState_R & 0x80 )
5423+ {
5424+ return Qtrue;
5425+ }
5426+ else
5427+ {
5428+ return Qfalse;
5429+ }
5430+
5431+ case M_MBUTTON:
5432+ if( g_byMouseState_M & 0x80 )
5433+ {
5434+ return Qtrue;
5435+ }
5436+ else
5437+ {
5438+ return Qfalse;
5439+ }
5440+ }
5441+
5442+ return Qnil;
5443+}
5444+
5445+
5446+/*--------------------------------------------------------------------
5447+ マウスのボタン状態を返す
5448+ ---------------------------------------------------------------------*/
5449+static VALUE Input_mousePush( VALUE obj, VALUE button )
5450+{
5451+
5452+ switch( NUM2INT( button ) )
5453+ {
5454+ case M_LBUTTON:
5455+ if( (g_byMouseState_L & 0x80) && !(g_byMouseStateOld_L & 0x80) )
5456+ {
5457+ return Qtrue;
5458+ }
5459+ else
5460+ {
5461+ return Qfalse;
5462+ }
5463+
5464+ case M_RBUTTON:
5465+ if( g_byMouseState_R & 0x80 && !(g_byMouseStateOld_R & 0x80) )
5466+ {
5467+ return Qtrue;
5468+ }
5469+ else
5470+ {
5471+ return Qfalse;
5472+ }
5473+
5474+ case M_MBUTTON:
5475+ if( g_byMouseState_M & 0x80 && !(g_byMouseStateOld_M & 0x80) )
5476+ {
5477+ return Qtrue;
5478+ }
5479+ else
5480+ {
5481+ return Qfalse;
5482+ }
5483+ }
5484+
5485+ return Qnil;
5486+}
5487+
5488+
5489+/*--------------------------------------------------------------------
5490+ マウスカーソルの位置を返す
5491+ ---------------------------------------------------------------------*/
5492+static VALUE Input_getmouseposx( VALUE obj )
5493+{
5494+ POINT cursor;
5495+
5496+ GetCursorPos( &cursor );
5497+ ScreenToClient( g_hWind, &cursor );
5498+ return INT2FIX( cursor.x );
5499+}
5500+
5501+
5502+/*--------------------------------------------------------------------
5503+ マウスカーソルの位置を返す
5504+ ---------------------------------------------------------------------*/
5505+static VALUE Input_getmouseposy( VALUE obj )
5506+{
5507+ POINT cursor;
5508+
5509+ GetCursorPos( &cursor );
5510+ ScreenToClient( g_hWind, &cursor );
5511+
5512+ return INT2FIX( cursor.y );
5513+}
5514+
5515+
5516+/*--------------------------------------------------------------------
5517+ マウスカーソルの位置を設定する
5518+ ---------------------------------------------------------------------*/
5519+static VALUE Input_setmousepos( VALUE klass, VALUE vx, VALUE vy )
5520+{
5521+ POINT cursor;
5522+
5523+ cursor.x = NUM2INT( vx );
5524+ cursor.y = NUM2INT( vy );
5525+ ClientToScreen( g_hWind, &cursor );
5526+ SetCursorPos( cursor.x, cursor.y );
5527+
5528+ return Qnil;
5529+}
5530+
5531+
5532+/*--------------------------------------------------------------------
5533+ マウス描画するかどうかの設定
5534+ ---------------------------------------------------------------------*/
5535+static VALUE Input_enablemouse( VALUE obj, VALUE draw )
5536+{
5537+ VALUE flag = Qfalse;
5538+ int c;
5539+
5540+ if( draw != Qnil && draw != Qfalse )
5541+ {
5542+ flag = Qtrue;
5543+ }
5544+
5545+ if( flag == Qtrue )
5546+ {
5547+ c = ShowCursor( TRUE );
5548+ while( c < 0 ) c = ShowCursor( TRUE );
5549+ }
5550+ else
5551+ {
5552+ c = ShowCursor( FALSE );
5553+ while( c >= 0 ) c = ShowCursor( FALSE );
5554+ }
5555+
5556+ g_WindowInfo.enablemouse = flag;
5557+
5558+ return draw;
5559+}
5560+
5561+
5562+/*--------------------------------------------------------------------
5563+ Inputモジュールの全キーオートリピート状態設定
5564+ ---------------------------------------------------------------------*/
5565+static VALUE Input_setrepeat( VALUE obj , VALUE vwait, VALUE vinterval )
5566+{
5567+ int wait, interval, i, j;
5568+
5569+ wait = NUM2INT( vwait );
5570+ interval = NUM2INT( vinterval );
5571+
5572+ for( i = 0; i < 256; i++)
5573+ {
5574+ g_diKeyWait[i] = wait;
5575+ g_diKeyInterval[i] = interval;
5576+ }
5577+
5578+ for( i = 0; i < PADMAX; i++)
5579+ {
5580+ for( j = 0; j < 20; j++)
5581+ {
5582+ g_PadState[i].wait[j] = wait;
5583+ g_PadState[i].interval[j] = interval;
5584+ }
5585+ }
5586+
5587+ return obj;
5588+}
5589+
5590+
5591+/*--------------------------------------------------------------------
5592+ Inputモジュールのキーオートリピート状態設定
5593+ ---------------------------------------------------------------------*/
5594+static VALUE Input_setkeyrepeat( VALUE obj , VALUE vkey, VALUE vwait, VALUE vinterval )
5595+{
5596+ int key, wait, interval;
5597+
5598+ key = NUM2INT( vkey );
5599+ wait = NUM2INT( vwait );
5600+ interval = NUM2INT( vinterval );
5601+
5602+ if( key < 0 || key >= 256 || wait < 0 || interval < 0 )
5603+ {
5604+ rb_raise( eDXRubyError, "値が範囲外です。 - Input_setKeyRepeat" );
5605+ }
5606+
5607+ g_diKeyWait[key] = wait;
5608+ g_diKeyInterval[key] = interval;
5609+
5610+ return obj;
5611+}
5612+
5613+
5614+/*--------------------------------------------------------------------
5615+ Inputモジュールのパッドオートリピート状態設定
5616+ ---------------------------------------------------------------------*/
5617+static VALUE Input_setpadrepeat( int argc, VALUE *argv, VALUE obj )
5618+{
5619+ VALUE vpad, vwait, vinterval, vnumber;
5620+ int pad, wait, interval, number;
5621+
5622+ rb_scan_args( argc, argv, "31", &vpad, &vwait, &vinterval, &vnumber );
5623+
5624+ pad = NUM2INT( vpad );
5625+ wait = NUM2INT( vwait );
5626+ interval = NUM2INT( vinterval );
5627+ number = (vnumber == Qnil ? 0 : NUM2INT( vnumber ));
5628+
5629+ if( number < 0 || pad < 0 || number >= PADMAX || pad >= 20 ||
5630+ wait < 0 || interval < 0 )
5631+ {
5632+ rb_raise( eDXRubyError, "値が範囲外です。 - Input_setPadRepeat" );
5633+ }
5634+
5635+ g_PadState[number].wait[pad] = wait;
5636+ g_PadState[number].interval[pad] = interval;
5637+
5638+ return obj;
5639+}
5640+
5641+
5642+/*--------------------------------------------------------------------
5643+ Inputモジュールのデータ取得
5644+
5645+ 押されているキーの配列を返す。
5646+ ---------------------------------------------------------------------*/
5647+static VALUE Input_getKeys( VALUE obj )
5648+{
5649+ int i, j;
5650+ VALUE buf[256];
5651+
5652+ for( i = 0, j = 0; i < 256; i++ )
5653+ {
5654+ if( g_diKeyState[i] & 0x80 ) /* 入力されている */
5655+ {
5656+ buf[j++] = INT2FIX( i );
5657+ }
5658+ }
5659+
5660+ return rb_ary_new4( j, buf );
5661+}
5662+
5663+
5664+/*--------------------------------------------------------------------
5665+ Inputモジュールのデータ取得
5666+
5667+ 押されているパッドの配列を返す。
5668+ ---------------------------------------------------------------------*/
5669+static VALUE Input_getPads( int argc, VALUE *argv, VALUE obj )
5670+{
5671+ int i, j, number;
5672+ VALUE buf[20];
5673+ VALUE vnumber;
5674+
5675+ rb_scan_args( argc, argv, "01", &vnumber);
5676+
5677+ number = vnumber == Qnil ? 0 : NUM2INT( vnumber );
5678+
5679+ for( i = 0, j = 0; i < 20; i++ )
5680+ {
5681+ if( g_PadState[number].button[i] == 1 )
5682+ {
5683+ buf[j++] = INT2FIX( i );
5684+ }
5685+ }
5686+
5687+ return rb_ary_new4( j, buf );
5688+}
5689+
5690+
5691+
5692+/*********************************************************************
5693+ * Fontクラス
5694+ *
5695+ * D3DXFontインターフェースを使用してフォントを描画する。
5696+ * スプライト描画に混ぜ込むことでとりあえず実装。
5697+ *********************************************************************/
5698+/*--------------------------------------------------------------------
5699+ 参照されなくなったときにGCから呼ばれる関数
5700+ ---------------------------------------------------------------------*/
5701+static void release_Font( struct DXRubyFont* font )
5702+{
5703+ /* フォントオブジェクトの開放 */
5704+ if( font )
5705+ {
5706+ RELEASE( font->pD3DXFont );
5707+ if( font->hFont != NULL )
5708+ {
5709+ DeleteObject( font->hFont );
5710+ }
5711+ free( font );
5712+ font = NULL;
5713+
5714+ g_iRefAll--;
5715+ if( g_iRefAll == 0 )
5716+ {
5717+ CoUninitialize();
5718+ }
5719+ }
5720+}
5721+
5722+
5723+/*--------------------------------------------------------------------
5724+ Fontクラスのallocate。メモリを確保する為にinitialize前に呼ばれる。
5725+ ---------------------------------------------------------------------*/
5726+static VALUE Font_allocate( VALUE klass )
5727+{
5728+ VALUE obj;
5729+ struct DXRubyFont *font;
5730+
5731+ /* DXRubyFontのメモリ取得&Fontオブジェクト生成 */
5732+ font = malloc( sizeof(struct DXRubyFont) );
5733+ if( font == NULL ) rb_raise( eDXRubyError, "メモリの取得に失敗しました - Font_allocate" );
5734+ font->pD3DXFont = NULL;
5735+ font->hFont = NULL;
5736+ return Data_Wrap_Struct(klass, 0, release_Font, font);
5737+}
5738+
5739+
5740+/*--------------------------------------------------------------------
5741+ FontクラスのInitialize
5742+ ---------------------------------------------------------------------*/
5743+static VALUE Font_initialize( int argc, VALUE *argv, VALUE obj )
5744+{
5745+ struct DXRubyFont *font;
5746+ HRESULT hr;
5747+ D3DXFONT_DESC desc;
5748+ VALUE size, fontname, option, hash, vweight, vitalic;
5749+ LOGFONT logfont;
5750+ int weight, italic;
5751+
5752+ g_iRefAll++;
5753+
5754+ /* デバイスオブジェクトの初期化チェック */
5755+ if( g_pD3DDevice == NULL )
5756+ {
5757+ rb_raise( eDXRubyError, "DirectX Graphicsが初期化されていません" );
5758+ }
5759+
5760+ rb_scan_args( argc, argv, "12", &size, &fontname, &hash );
5761+
5762+ if( hash == Qnil )
5763+ {
5764+ option = rb_hash_new();
5765+ }
5766+ else
5767+ {
5768+ Check_Type( hash, T_HASH );
5769+ option = hash;
5770+ }
5771+
5772+ vweight = rb_hash_lookup( option, symbol_weight );
5773+ vitalic = rb_hash_lookup( option, symbol_italic );
5774+
5775+ if( vweight == Qnil || vweight == Qfalse )
5776+ {
5777+ weight = 400;
5778+ }
5779+ else if( vweight == Qtrue )
5780+ {
5781+ weight = 1000;
5782+ }
5783+ else
5784+ {
5785+ weight = NUM2INT( vweight );
5786+ }
5787+
5788+ if( vitalic == Qnil || vitalic == Qfalse )
5789+ {
5790+ italic = FALSE;
5791+ }
5792+ else
5793+ {
5794+ italic = TRUE;
5795+ }
5796+
5797+ desc.Height = NUM2INT( size );
5798+ desc.Width = 0;
5799+ desc.Weight = weight;
5800+ desc.MipLevels = 0;
5801+ desc.Italic = italic;
5802+ desc.CharSet = DEFAULT_CHARSET;
5803+ desc.OutputPrecision = 0;
5804+ desc.Quality = DEFAULT_QUALITY;
5805+ desc.PitchAndFamily = DEFAULT_PITCH || FF_DONTCARE;
5806+
5807+ ZeroMemory( &logfont, sizeof(logfont) );
5808+ logfont.lfHeight = NUM2INT( size );
5809+ logfont.lfWidth = 0;
5810+ logfont.lfWeight = weight;
5811+ logfont.lfItalic = italic;
5812+ logfont.lfCharSet = DEFAULT_CHARSET;
5813+ logfont.lfQuality = ANTIALIASED_QUALITY;
5814+ if( fontname == Qnil )
5815+ {
5816+ lstrcpy(desc.FaceName, "");
5817+ lstrcpy(logfont.lfFaceName, "");
5818+ }
5819+ else
5820+ {
5821+ Check_Type(fontname, T_STRING);
5822+ lstrcpy(desc.FaceName, RSTRING_PTR( fontname ));
5823+ lstrcpy(logfont.lfFaceName, RSTRING_PTR( fontname ));
5824+ }
5825+
5826+ /* フォントオブジェクト取り出し */
5827+ Data_Get_Struct( obj, struct DXRubyFont, font );
5828+
5829+ hr = D3DXCreateFontIndirect( g_pD3DDevice, &desc, &font->pD3DXFont );
5830+
5831+ if( FAILED( hr ) )
5832+ {
5833+ rb_raise( eDXRubyError, "フォントの作成に失敗しました - D3DXCreateFontIndirect" );
5834+ }
5835+
5836+ font->hFont = CreateFontIndirect( &logfont );
5837+
5838+ if( font->hFont == NULL )
5839+ {
5840+ rb_raise( eDXRubyError, "フォントの作成に失敗しました - CreateFontIndirect" );
5841+ }
5842+
5843+ font->size = NUM2INT( size );
5844+
5845+ return obj;
5846+}
5847+
5848+
5849+/*--------------------------------------------------------------------
5850+ Fontクラスのinstall
5851+ ---------------------------------------------------------------------*/
5852+static VALUE Font_install( VALUE klass, VALUE vstr )
5853+{
5854+ int result;
5855+ Check_Type( vstr, T_STRING );
5856+
5857+ result = AddFontResourceEx( RSTRING_PTR( vstr ), 0x10, 0 );
5858+ if( result == 0 )
5859+ {
5860+ rb_raise( eDXRubyError, "フォントのインストールに失敗しました - Font_install" );
5861+ }
5862+
5863+ return INT2FIX( result );
5864+}
5865+
5866+
5867+/*--------------------------------------------------------------------
5868+ フォントの幅を取得する
5869+ ---------------------------------------------------------------------*/
5870+static VALUE Font_getWidth( VALUE obj, VALUE str )
5871+{
5872+ HDC hDC;
5873+ struct DXRubyFont *font;
5874+ RECT rc;
5875+
5876+ /* フォントオブジェクト取り出し */
5877+ Data_Get_Struct( obj, struct DXRubyFont, font );
5878+
5879+ hDC = GetDC( g_hWind );
5880+ if( hDC == NULL )
5881+ {
5882+ rb_raise( eDXRubyError, "DCの取得に失敗しました - GetDC" );
5883+ }
5884+
5885+ SelectObject( hDC, font->hFont );
5886+ SetRect( &rc, 0, 0, 1, 1 );
5887+ DrawText( hDC, RSTRING_PTR( str ), -1, &rc, DT_LEFT | DT_NOCLIP | DT_NOPREFIX | DT_CALCRECT | DT_SINGLELINE);
5888+ ReleaseDC( g_hWind, hDC );
5889+
5890+ return INT2FIX( rc.right );
5891+}
5892+
5893+
5894+/*--------------------------------------------------------------------
5895+ フォントのサイズを取得する
5896+ ---------------------------------------------------------------------*/
5897+static VALUE Font_getSize( VALUE obj )
5898+{
5899+ HDC hDC;
5900+ struct DXRubyFont *font;
5901+ RECT rc;
5902+
5903+ /* フォントオブジェクト取り出し */
5904+ Data_Get_Struct( obj, struct DXRubyFont, font );
5905+
5906+ return INT2FIX( font->size );
5907+}
5908+
5909+
5910+/*********************************************************************
5911+ * DXRubyInternalMarkクラス
5912+ *
5913+ * Window.draw系でImageオブジェクトを束縛しないとGCに回収されるのでその対策
5914+ *********************************************************************/
5915+/*--------------------------------------------------------------------
5916+ DXRubyInternalMarkのmark関数
5917+ ---------------------------------------------------------------------*/
5918+static void DXRubyInternalMark_mark( VALUE klass )
5919+{
5920+ int i;
5921+
5922+ for( i = 0; i < g_SpriteCount; i++ )
5923+ {
5924+ rb_gc_mark( g_SpriteList[i].sprite->value );
5925+ }
5926+}
5927+
5928+
5929+/*
5930+***************************************************************
5931+*
5932+* Global functions
5933+*
5934+***************************************************************/
5935+
5936+void Init_dxruby()
5937+{
5938+ HRESULT hr;
5939+ int i, j;
5940+
5941+ hr = CoInitialize(NULL);
5942+
5943+ if( FAILED( hr ) )
5944+ {
5945+ rb_raise( eDXRubyError, "COMの初期化に失敗しました - CoInitialize" );
5946+ }
5947+
5948+ /* インスタンスハンドル取得 */
5949+ g_hInstance = (HINSTANCE)GetModuleHandle( NULL );
5950+
5951+ /* DXRubyモジュール登録 */
5952+ mDXRuby = rb_define_module( "DXRuby" );
5953+
5954+ /* Windowモジュール登録 */
5955+ mWindow = rb_define_module_under( mDXRuby, "Window" );
5956+
5957+ /* Windowモジュールにメソッド登録 */
5958+ rb_define_singleton_method( mWindow, "loop" , Window_loop , 0 );
5959+ rb_define_singleton_method( mWindow, "draw" , Window_draw , -1 );
5960+ rb_define_singleton_method( mWindow, "draw_scale", Window_drawScale , -1 );
5961+ rb_define_singleton_method( mWindow, "drawScale", Window_drawScale , -1 );
5962+ rb_define_singleton_method( mWindow, "draw_rot" , Window_drawRot , -1 );
5963+ rb_define_singleton_method( mWindow, "drawRot" , Window_drawRot , -1 );
5964+ rb_define_singleton_method( mWindow, "draw_alpha", Window_drawAlpha , -1 );
5965+ rb_define_singleton_method( mWindow, "drawAlpha", Window_drawAlpha , -1 );
5966+ rb_define_singleton_method( mWindow, "draw_add" , Window_drawAdd , -1 );
5967+ rb_define_singleton_method( mWindow, "drawAdd" , Window_drawAdd , -1 );
5968+ rb_define_singleton_method( mWindow, "draw_sub" , Window_drawSub , -1 );
5969+ rb_define_singleton_method( mWindow, "drawSub" , Window_drawSub , -1 );
5970+ rb_define_singleton_method( mWindow, "draw_ex" , Window_drawEx , -1 );
5971+ rb_define_singleton_method( mWindow, "drawEx" , Window_drawEx , -1 );
5972+ rb_define_singleton_method( mWindow, "draw_font", Window_drawFont , -1 );
5973+ rb_define_singleton_method( mWindow, "drawFont" , Window_drawFont , -1 );
5974+ rb_define_singleton_method( mWindow, "draw_tile", Window_drawTile , -1 );
5975+ rb_define_singleton_method( mWindow, "drawTile" , Window_drawTile , -1 );
5976+ rb_define_singleton_method( mWindow, "set_viewport" , Window_setViewport , -1 );
5977+ rb_define_singleton_method( mWindow, "setViewport" , Window_setViewport , -1 );
5978+ rb_define_singleton_method( mWindow, "x" , Window_x , 0 );
5979+ rb_define_singleton_method( mWindow, "x=" , Window_setx , 1 );
5980+ rb_define_singleton_method( mWindow, "y" , Window_y , 0 );
5981+ rb_define_singleton_method( mWindow, "y=" , Window_sety , 1 );
5982+ rb_define_singleton_method( mWindow, "width" , Window_width , 0 );
5983+ rb_define_singleton_method( mWindow, "width=" , Window_setwidth , 1 );
5984+ rb_define_singleton_method( mWindow, "height" , Window_height , 0 );
5985+ rb_define_singleton_method( mWindow, "height=" , Window_setheight , 1 );
5986+ rb_define_singleton_method( mWindow, "caption" , Window_getCaption , 0 );
5987+ rb_define_singleton_method( mWindow, "caption=" , Window_setCaption , 1 );
5988+ rb_define_singleton_method( mWindow, "scale" , Window_getScale , 0 );
5989+ rb_define_singleton_method( mWindow, "scale=" , Window_setScale , 1 );
5990+ rb_define_singleton_method( mWindow, "windowed?", Window_getwindowed, 0 );
5991+ rb_define_singleton_method( mWindow, "windowed=", Window_setwindowed, 1 );
5992+ rb_define_singleton_method( mWindow, "real_fps" , Window_getrealfps , 0 );
5993+ rb_define_singleton_method( mWindow, "fps" , Window_getfps , 0 );
5994+ rb_define_singleton_method( mWindow, "fps=" , Window_setfps , 1 );
5995+ rb_define_singleton_method( mWindow, "frameskip?" , Window_getframeskip, 0 );
5996+ rb_define_singleton_method( mWindow, "frameskip=" , Window_setframeskip, 1 );
5997+ rb_define_singleton_method( mWindow, "bgcolor" , Window_getbgcolor , 0 );
5998+ rb_define_singleton_method( mWindow, "bgcolor=" , Window_setbgcolor , 1 );
5999+ rb_define_singleton_method( mWindow, "min_filter" , Window_getMinFilter , 0 );
6000+ rb_define_singleton_method( mWindow, "minFilter" , Window_getMinFilter , 0 );
6001+ rb_define_singleton_method( mWindow, "min_filter=" , Window_setMinFilter , 1 );
6002+ rb_define_singleton_method( mWindow, "minFilter=" , Window_setMinFilter , 1 );
6003+ rb_define_singleton_method( mWindow, "mag_filter" , Window_getMagFilter , 0 );
6004+ rb_define_singleton_method( mWindow, "magFilter" , Window_getMagFilter , 0 );
6005+ rb_define_singleton_method( mWindow, "mag_filter=" , Window_setMagFilter , 1 );
6006+ rb_define_singleton_method( mWindow, "magFilter=" , Window_setMagFilter , 1 );
6007+ rb_define_singleton_method( mWindow, "get_load" , Window_getload, 0 );
6008+ rb_define_singleton_method( mWindow, "getLoad" , Window_getload, 0 );
6009+ rb_define_singleton_method( mWindow, "open_filename", Window_openDialog, 2 );
6010+ rb_define_singleton_method( mWindow, "openFilename" , Window_openDialog, 2 );
6011+ rb_define_singleton_method( mWindow, "save_filename", Window_saveDialog, 2 );
6012+ rb_define_singleton_method( mWindow, "saveFilename" , Window_saveDialog, 2 );
6013+ rb_define_singleton_method( mWindow, "get_screen_shot", Window_getScreenShot, -1 );
6014+ rb_define_singleton_method( mWindow, "getScreenShot", Window_getScreenShot, -1 );
6015+ rb_define_singleton_method( mWindow, "create" , Window_create , 0 );
6016+ rb_define_singleton_method( mWindow, "update" , Window_update , 0 );
6017+ rb_define_singleton_method( mWindow, "sync" , Window_sync , 0 );
6018+ rb_define_singleton_method( mWindow, "hWnd" , Window_gethWnd, 0 );
6019+ rb_define_singleton_method( mWindow, "load_icon" , Window_loadIcon, 1 );
6020+ rb_define_singleton_method( mWindow, "loadIcon" , Window_loadIcon, 1 );
6021+// rb_define_singleton_method( mWindow, "playMovie" , Window_playMovie, 1 );
6022+
6023+
6024+ /* Imageクラス定義 */
6025+ cImage = rb_define_class_under( mDXRuby, "Image", rb_cObject );
6026+
6027+ /* Imageクラスにクラスメソッド登録*/
6028+ rb_define_singleton_method(cImage, "load", Image_load, -1);
6029+ rb_define_singleton_method(cImage, "load_to_array", Image_loadToArray, 3);
6030+ rb_define_singleton_method(cImage, "loadToArray", Image_loadToArray, 3);
6031+ rb_define_singleton_method(cImage, "create_from_array", Image_createFromArray, 3);
6032+ rb_define_singleton_method(cImage, "createFromArray", Image_createFromArray, 3);
6033+ rb_define_singleton_method(cImage, "load_from_file_in_memory", Image_loadFromFileInMemory, 1);
6034+ rb_define_singleton_method(cImage, "loadFromFileInMemory", Image_loadFromFileInMemory, 1);
6035+
6036+
6037+ /* Imageクラスにメソッド登録*/
6038+ rb_define_private_method( cImage, "initialize", Image_initialize, -1 );
6039+ rb_define_method( cImage, "width" , Image_getWidth , 0 );
6040+ rb_define_method( cImage, "height" , Image_getHeight , 0 );
6041+ rb_define_method( cImage, "width=" , Image_setWidth , 1 );
6042+ rb_define_method( cImage, "height=" , Image_setHeight , 1 );
6043+ rb_define_method( cImage, "x" , Image_getX , 0 );
6044+ rb_define_method( cImage, "y" , Image_getY , 0 );
6045+ rb_define_method( cImage, "x=" , Image_setX , 1 );
6046+ rb_define_method( cImage, "y=" , Image_setY , 1 );
6047+ rb_define_method( cImage, "texture_x" , Image_getX , 0 );
6048+ rb_define_method( cImage, "texture_y" , Image_getY , 0 );
6049+ rb_define_method( cImage, "texture_x=", Image_setX , 1 );
6050+ rb_define_method( cImage, "texture_y=", Image_setY , 1 );
6051+ rb_define_method( cImage, "[]=" , Image_setPixel , 3 );
6052+ rb_define_method( cImage, "[]" , Image_getPixel , 2 );
6053+ rb_define_method( cImage, "box" , Image_box , 5 );
6054+ rb_define_method( cImage, "box_fill" , Image_boxFill , 5 );
6055+ rb_define_method( cImage, "boxFill" , Image_boxFill , 5 );
6056+ rb_define_method( cImage, "fill" , Image_fill , 1 );
6057+ rb_define_method( cImage, "line" , Image_line , 5 );
6058+ rb_define_method( cImage, "circle" , Image_circle , 4 );
6059+ rb_define_method( cImage, "circle_fill", Image_circleFill, 4 );
6060+ rb_define_method( cImage, "circleFill", Image_circleFill, 4 );
6061+ rb_define_method( cImage, "compare" , Image_compare , 3 );
6062+ rb_define_method( cImage, "copy_rect" , Image_copyRect , -1 );
6063+ rb_define_method( cImage, "copyRect" , Image_copyRect , -1 );
6064+ rb_define_method( cImage, "draw" , Image_draw , -1 );
6065+ rb_define_method( cImage, "draw_text" , Image_drawFont , -1 );
6066+ rb_define_method( cImage, "draw_font" , Image_drawFont , -1 );
6067+ rb_define_method( cImage, "drawFont" , Image_drawFont , -1 );
6068+ rb_define_method( cImage, "save" , Image_save , -1 );
6069+ rb_define_method( cImage, "slice" , Image_slice_instance, -1);
6070+ rb_define_method( cImage, "dup" , Image_dup , 0 );
6071+ rb_define_method( cImage, "clone" , Image_dup , 0 );
6072+ rb_define_method( cImage, "set_color_key", Image_setColorKey , 1 );
6073+ rb_define_method( cImage, "setColorKey", Image_setColorKey , 1 );
6074+
6075+ /* Imageオブジェクトを生成した時にinitializeの前に呼ばれるメモリ割り当て関数登録 */
6076+ rb_define_alloc_func( cImage, Image_allocate );
6077+
6078+
6079+ /* Inputモジュール登録 */
6080+ mInput = rb_define_module_under( mDXRuby, "Input" );
6081+
6082+ /* Inputモジュールにメソッド登録 */
6083+ rb_define_singleton_method( mInput, "x" , Input_x , -1 );
6084+ rb_define_singleton_method( mInput, "y" , Input_y , -1 );
6085+ rb_define_singleton_method( mInput, "set_mouse_pos" , Input_setmousepos , 2 );
6086+ rb_define_singleton_method( mInput, "setMousePos" , Input_setmousepos , 2 );
6087+ rb_define_singleton_method( mInput, "mouse_pos_x" , Input_getmouseposx , 0 );
6088+ rb_define_singleton_method( mInput, "mousePosX" , Input_getmouseposx , 0 );
6089+ rb_define_singleton_method( mInput, "mouse_pos_y" , Input_getmouseposy , 0 );
6090+ rb_define_singleton_method( mInput, "mousePosY" , Input_getmouseposy , 0 );
6091+ rb_define_singleton_method( mInput, "key_down?" , Input_keyDown , 1 );
6092+ rb_define_singleton_method( mInput, "keyDown?" , Input_keyDown , 1 );
6093+ rb_define_singleton_method( mInput, "key_push?" , Input_keyPush , 1 );
6094+ rb_define_singleton_method( mInput, "keyPush?" , Input_keyPush , 1 );
6095+ rb_define_singleton_method( mInput, "pad_down?" , Input_padDown , -1 );
6096+ rb_define_singleton_method( mInput, "padDown?" , Input_padDown , -1 );
6097+ rb_define_singleton_method( mInput, "pad_push?" , Input_padPush , -1 );
6098+ rb_define_singleton_method( mInput, "padPush?" , Input_padPush , -1 );
6099+ rb_define_singleton_method( mInput, "mouse_down?" , Input_mouseDown , 1 );
6100+ rb_define_singleton_method( mInput, "mouseDown?" , Input_mouseDown , 1 );
6101+ rb_define_singleton_method( mInput, "mouse_push?" , Input_mousePush , 1 );
6102+ rb_define_singleton_method( mInput, "mousePush?" , Input_mousePush , 1 );
6103+ rb_define_singleton_method( mInput, "mouse_enable=" , Input_enablemouse , 1 );
6104+ rb_define_singleton_method( mInput, "mouseEnable=" , Input_enablemouse , 1 );
6105+ rb_define_singleton_method( mInput, "mouse_wheel_pos", Input_getmousewheelpos, 0 );
6106+ rb_define_singleton_method( mInput, "mouseWheelPos" , Input_getmousewheelpos, 0 );
6107+ rb_define_singleton_method( mInput, "mouse_wheel_pos=", Input_setmousewheelpos, 1 );
6108+ rb_define_singleton_method( mInput, "mouseWheelPos=" , Input_setmousewheelpos, 1 );
6109+ rb_define_singleton_method( mInput, "set_config" , Input_setconfig , -1 );
6110+ rb_define_singleton_method( mInput, "setConfig" , Input_setconfig , -1 );
6111+ rb_define_singleton_method( mInput, "set_repeat" , Input_setrepeat , 2 );
6112+ rb_define_singleton_method( mInput, "setRepeat" , Input_setrepeat , 2 );
6113+ rb_define_singleton_method( mInput, "update" , Input_update , 0 );
6114+ rb_define_singleton_method( mInput, "set_key_repeat" , Input_setkeyrepeat , 3 );
6115+ rb_define_singleton_method( mInput, "setKeyRepeat" , Input_setkeyrepeat , 3 );
6116+ rb_define_singleton_method( mInput, "set_pad_repeat" , Input_setpadrepeat , -1 );
6117+ rb_define_singleton_method( mInput, "setPadRepeat" , Input_setpadrepeat , -1 );
6118+ rb_define_singleton_method( mInput, "keys" , Input_getKeys , 0 );
6119+ rb_define_singleton_method( mInput, "pads" , Input_getPads , -1 );
6120+
6121+
6122+ /* Fontクラス登録 */
6123+ cFont = rb_define_class_under( mDXRuby, "Font", rb_cObject );
6124+
6125+ /* Fontクラスにクラスメソッド登録*/
6126+ rb_define_singleton_method(cFont, "install", Font_install, 1);
6127+
6128+ /* Fontクラスにメソッド登録*/
6129+ rb_define_private_method( cFont, "initialize", Font_initialize, -1 );
6130+ rb_define_method( cFont, "get_width" , Font_getWidth , 1 );
6131+ rb_define_method( cFont, "getWidth" , Font_getWidth , 1 );
6132+ rb_define_method( cFont, "size" , Font_getSize , 0 );
6133+
6134+ /* Fontオブジェクトを生成した時にinitializeの前に呼ばれるメモリ割り当て関数登録 */
6135+ rb_define_alloc_func( cFont, Font_allocate );
6136+
6137+
6138+ /* Soundクラス定義 */
6139+ cSound = rb_define_class_under( mDXRuby, "Sound", rb_cObject );
6140+
6141+ /* Soundクラスにメソッド登録*/
6142+ rb_define_private_method( cSound, "initialize" , Sound_initialize , 1 );
6143+ rb_define_method( cSound, "play" , Sound_play , 0 );
6144+ rb_define_method( cSound, "stop" , Sound_stop , 0 );
6145+ rb_define_method( cSound, "set_volume" , Sound_setVolume , -1 );
6146+ rb_define_method( cSound, "setVolume" , Sound_setVolume , -1 );
6147+ rb_define_method( cSound, "start=" , Sound_setStart , 1 );
6148+ rb_define_method( cSound, "loop_start=" , Sound_setLoopStart , 1 );
6149+ rb_define_method( cSound, "loopStart=" , Sound_setLoopStart , 1 );
6150+ rb_define_method( cSound, "loop_end=" , Sound_setLoopEnd , 1 );
6151+ rb_define_method( cSound, "loopEnd=" , Sound_setLoopEnd , 1 );
6152+ rb_define_method( cSound, "loop_count=" , Sound_setLoopCount , 1 );
6153+ rb_define_method( cSound, "loopCount=" , Sound_setLoopCount , 1 );
6154+
6155+ /* Soundオブジェクトを生成した時にinitializeの前に呼ばれるメモリ割り当て関数登録 */
6156+ rb_define_alloc_func( cSound, Sound_allocate );
6157+
6158+
6159+ /* SoundEffectクラス定義 */
6160+ cSoundEffect = rb_define_class_under( mDXRuby, "SoundEffect", rb_cObject );
6161+
6162+ /* SoundEffectクラスにメソッド登録*/
6163+ rb_define_private_method( cSoundEffect, "initialize", SoundEffect_initialize, -1 );
6164+ rb_define_method( cSoundEffect, "play" , SoundEffect_play , 0 );
6165+ rb_define_method( cSoundEffect, "stop" , SoundEffect_stop , 0 );
6166+ rb_define_method( cSoundEffect, "add" , SoundEffect_add , -1 );
6167+
6168+ /* SoundEffectオブジェクトを生成した時にinitializeの前に呼ばれるメモリ割り当て関数登録 */
6169+ rb_define_alloc_func( cSoundEffect, SoundEffect_allocate );
6170+
6171+
6172+ /* DXRubyInternalMarkクラス定義 */
6173+ cDXRubyInternalMark = rb_define_class_under( mDXRuby, "DXRubyInternalMark", rb_cObject );
6174+ oDXRubyInternalMark = Data_Wrap_Struct(cDXRubyInternalMark, DXRubyInternalMark_mark, 0, 0);
6175+ rb_global_variable( &oDXRubyInternalMark );
6176+
6177+
6178+ /* キーボードのスキャンコード定数設定 */
6179+ rb_define_const( mDXRuby, "K_ESCAPE" , INT2FIX(DIK_ESCAPE) );
6180+ rb_define_const( mDXRuby, "K_1" , INT2FIX(DIK_1) );
6181+ rb_define_const( mDXRuby, "K_2" , INT2FIX(DIK_2) );
6182+ rb_define_const( mDXRuby, "K_3" , INT2FIX(DIK_3) );
6183+ rb_define_const( mDXRuby, "K_4" , INT2FIX(DIK_4) );
6184+ rb_define_const( mDXRuby, "K_5" , INT2FIX(DIK_5) );
6185+ rb_define_const( mDXRuby, "K_6" , INT2FIX(DIK_6) );
6186+ rb_define_const( mDXRuby, "K_7" , INT2FIX(DIK_7) );
6187+ rb_define_const( mDXRuby, "K_8" , INT2FIX(DIK_8) );
6188+ rb_define_const( mDXRuby, "K_9" , INT2FIX(DIK_9) );
6189+ rb_define_const( mDXRuby, "K_0" , INT2FIX(DIK_0) );
6190+ rb_define_const( mDXRuby, "K_MINUS" , INT2FIX(DIK_MINUS) );
6191+ rb_define_const( mDXRuby, "K_EQUALS" , INT2FIX(DIK_EQUALS) );
6192+ rb_define_const( mDXRuby, "K_BACK" , INT2FIX(DIK_BACK) );
6193+ rb_define_const( mDXRuby, "K_TAB" , INT2FIX(DIK_TAB) );
6194+ rb_define_const( mDXRuby, "K_Q" , INT2FIX(DIK_Q) );
6195+ rb_define_const( mDXRuby, "K_W" , INT2FIX(DIK_W) );
6196+ rb_define_const( mDXRuby, "K_E" , INT2FIX(DIK_E) );
6197+ rb_define_const( mDXRuby, "K_R" , INT2FIX(DIK_R) );
6198+ rb_define_const( mDXRuby, "K_T" , INT2FIX(DIK_T) );
6199+ rb_define_const( mDXRuby, "K_Y" , INT2FIX(DIK_Y) );
6200+ rb_define_const( mDXRuby, "K_U" , INT2FIX(DIK_U) );
6201+ rb_define_const( mDXRuby, "K_I" , INT2FIX(DIK_I) );
6202+ rb_define_const( mDXRuby, "K_O" , INT2FIX(DIK_O) );
6203+ rb_define_const( mDXRuby, "K_P" , INT2FIX(DIK_P) );
6204+ rb_define_const( mDXRuby, "K_LBRACKET" , INT2FIX(DIK_LBRACKET) );
6205+ rb_define_const( mDXRuby, "K_RBRACKET" , INT2FIX(DIK_RBRACKET) );
6206+ rb_define_const( mDXRuby, "K_RETURN" , INT2FIX(DIK_RETURN) );
6207+ rb_define_const( mDXRuby, "K_LCONTROL" , INT2FIX(DIK_LCONTROL) );
6208+ rb_define_const( mDXRuby, "K_A" , INT2FIX(DIK_A) );
6209+ rb_define_const( mDXRuby, "K_S" , INT2FIX(DIK_S) );
6210+ rb_define_const( mDXRuby, "K_D" , INT2FIX(DIK_D) );
6211+ rb_define_const( mDXRuby, "K_F" , INT2FIX(DIK_F) );
6212+ rb_define_const( mDXRuby, "K_G" , INT2FIX(DIK_G) );
6213+ rb_define_const( mDXRuby, "K_H" , INT2FIX(DIK_H) );
6214+ rb_define_const( mDXRuby, "K_J" , INT2FIX(DIK_J) );
6215+ rb_define_const( mDXRuby, "K_K" , INT2FIX(DIK_K) );
6216+ rb_define_const( mDXRuby, "K_L" , INT2FIX(DIK_L) );
6217+ rb_define_const( mDXRuby, "K_SEMICOLON" , INT2FIX(DIK_SEMICOLON) );
6218+ rb_define_const( mDXRuby, "K_APOSTROPHE" , INT2FIX(DIK_APOSTROPHE) );
6219+ rb_define_const( mDXRuby, "K_GRAVE" , INT2FIX(DIK_GRAVE) );
6220+ rb_define_const( mDXRuby, "K_LSHIFT" , INT2FIX(DIK_LSHIFT) );
6221+ rb_define_const( mDXRuby, "K_BACKSLASH" , INT2FIX(DIK_BACKSLASH) );
6222+ rb_define_const( mDXRuby, "K_Z" , INT2FIX(DIK_Z) );
6223+ rb_define_const( mDXRuby, "K_X" , INT2FIX(DIK_X) );
6224+ rb_define_const( mDXRuby, "K_C" , INT2FIX(DIK_C) );
6225+ rb_define_const( mDXRuby, "K_V" , INT2FIX(DIK_V) );
6226+ rb_define_const( mDXRuby, "K_B" , INT2FIX(DIK_B) );
6227+ rb_define_const( mDXRuby, "K_N" , INT2FIX(DIK_N) );
6228+ rb_define_const( mDXRuby, "K_M" , INT2FIX(DIK_M) );
6229+ rb_define_const( mDXRuby, "K_COMMA" , INT2FIX(DIK_COMMA) );
6230+ rb_define_const( mDXRuby, "K_PERIOD" , INT2FIX(DIK_PERIOD) );
6231+ rb_define_const( mDXRuby, "K_SLASH" , INT2FIX(DIK_SLASH) );
6232+ rb_define_const( mDXRuby, "K_RSHIFT" , INT2FIX(DIK_RSHIFT) );
6233+ rb_define_const( mDXRuby, "K_MULTIPLY" , INT2FIX(DIK_MULTIPLY) );
6234+ rb_define_const( mDXRuby, "K_LMENU" , INT2FIX(DIK_LMENU) );
6235+ rb_define_const( mDXRuby, "K_SPACE" , INT2FIX(DIK_SPACE) );
6236+ rb_define_const( mDXRuby, "K_CAPITAL" , INT2FIX(DIK_CAPITAL) );
6237+ rb_define_const( mDXRuby, "K_F1" , INT2FIX(DIK_F1) );
6238+ rb_define_const( mDXRuby, "K_F2" , INT2FIX(DIK_F2) );
6239+ rb_define_const( mDXRuby, "K_F3" , INT2FIX(DIK_F3) );
6240+ rb_define_const( mDXRuby, "K_F4" , INT2FIX(DIK_F4) );
6241+ rb_define_const( mDXRuby, "K_F5" , INT2FIX(DIK_F5) );
6242+ rb_define_const( mDXRuby, "K_F6" , INT2FIX(DIK_F6) );
6243+ rb_define_const( mDXRuby, "K_F7" , INT2FIX(DIK_F7) );
6244+ rb_define_const( mDXRuby, "K_F8" , INT2FIX(DIK_F8) );
6245+ rb_define_const( mDXRuby, "K_F9" , INT2FIX(DIK_F9) );
6246+ rb_define_const( mDXRuby, "K_F10" , INT2FIX(DIK_F10) );
6247+ rb_define_const( mDXRuby, "K_NUMLOCK" , INT2FIX(DIK_NUMLOCK) );
6248+ rb_define_const( mDXRuby, "K_SCROLL" , INT2FIX(DIK_SCROLL) );
6249+ rb_define_const( mDXRuby, "K_NUMPAD7" , INT2FIX(DIK_NUMPAD7) );
6250+ rb_define_const( mDXRuby, "K_NUMPAD8" , INT2FIX(DIK_NUMPAD8) );
6251+ rb_define_const( mDXRuby, "K_NUMPAD9" , INT2FIX(DIK_NUMPAD9) );
6252+ rb_define_const( mDXRuby, "K_SUBTRACT" , INT2FIX(DIK_SUBTRACT) );
6253+ rb_define_const( mDXRuby, "K_NUMPAD4" , INT2FIX(DIK_NUMPAD4) );
6254+ rb_define_const( mDXRuby, "K_NUMPAD5" , INT2FIX(DIK_NUMPAD5) );
6255+ rb_define_const( mDXRuby, "K_NUMPAD6" , INT2FIX(DIK_NUMPAD6) );
6256+ rb_define_const( mDXRuby, "K_ADD" , INT2FIX(DIK_ADD) );
6257+ rb_define_const( mDXRuby, "K_NUMPAD1" , INT2FIX(DIK_NUMPAD1) );
6258+ rb_define_const( mDXRuby, "K_NUMPAD2" , INT2FIX(DIK_NUMPAD2) );
6259+ rb_define_const( mDXRuby, "K_NUMPAD3" , INT2FIX(DIK_NUMPAD3) );
6260+ rb_define_const( mDXRuby, "K_NUMPAD0" , INT2FIX(DIK_NUMPAD0) );
6261+ rb_define_const( mDXRuby, "K_DECIMAL" , INT2FIX(DIK_DECIMAL) );
6262+ rb_define_const( mDXRuby, "K_OEM_102" , INT2FIX(DIK_OEM_102) );
6263+ rb_define_const( mDXRuby, "K_F11" , INT2FIX(DIK_F11) );
6264+ rb_define_const( mDXRuby, "K_F12" , INT2FIX(DIK_F12) );
6265+ rb_define_const( mDXRuby, "K_F13" , INT2FIX(DIK_F13) );
6266+ rb_define_const( mDXRuby, "K_F14" , INT2FIX(DIK_F14) );
6267+ rb_define_const( mDXRuby, "K_F15" , INT2FIX(DIK_F15) );
6268+ rb_define_const( mDXRuby, "K_KANA" , INT2FIX(DIK_KANA) );
6269+ rb_define_const( mDXRuby, "K_ABNT_C1" , INT2FIX(DIK_ABNT_C1) );
6270+ rb_define_const( mDXRuby, "K_CONVERT" , INT2FIX(DIK_CONVERT) );
6271+ rb_define_const( mDXRuby, "K_NOCONVERT" , INT2FIX(DIK_NOCONVERT) );
6272+ rb_define_const( mDXRuby, "K_YEN" , INT2FIX(DIK_YEN) );
6273+ rb_define_const( mDXRuby, "K_ABNT_C2" , INT2FIX(DIK_ABNT_C2) );
6274+ rb_define_const( mDXRuby, "K_NUMPADEQUALS", INT2FIX(DIK_NUMPADEQUALS) );
6275+ rb_define_const( mDXRuby, "K_PREVTRACK" , INT2FIX(DIK_PREVTRACK) );
6276+ rb_define_const( mDXRuby, "K_AT" , INT2FIX(DIK_AT) );
6277+ rb_define_const( mDXRuby, "K_COLON" , INT2FIX(DIK_COLON) );
6278+ rb_define_const( mDXRuby, "K_UNDERLINE" , INT2FIX(DIK_UNDERLINE) );
6279+ rb_define_const( mDXRuby, "K_KANJI" , INT2FIX(DIK_KANJI) );
6280+ rb_define_const( mDXRuby, "K_STOP" , INT2FIX(DIK_STOP) );
6281+ rb_define_const( mDXRuby, "K_AX" , INT2FIX(DIK_AX) );
6282+ rb_define_const( mDXRuby, "K_UNLABELED" , INT2FIX(DIK_UNLABELED) );
6283+ rb_define_const( mDXRuby, "K_NEXTTRACK" , INT2FIX(DIK_NEXTTRACK) );
6284+ rb_define_const( mDXRuby, "K_NUMPADENTER", INT2FIX(DIK_NUMPADENTER) );
6285+ rb_define_const( mDXRuby, "K_RCONTROL" , INT2FIX(DIK_RCONTROL) );
6286+ rb_define_const( mDXRuby, "K_MUTE" , INT2FIX(DIK_MUTE) );
6287+ rb_define_const( mDXRuby, "K_CALCULATOR" , INT2FIX(DIK_CALCULATOR) );
6288+ rb_define_const( mDXRuby, "K_PLAYPAUSE" , INT2FIX(DIK_PLAYPAUSE) );
6289+ rb_define_const( mDXRuby, "K_MEDIASTOP" , INT2FIX(DIK_MEDIASTOP) );
6290+ rb_define_const( mDXRuby, "K_VOLUMEDOWN" , INT2FIX(DIK_VOLUMEDOWN) );
6291+ rb_define_const( mDXRuby, "K_VOLUMEUP" , INT2FIX(DIK_VOLUMEUP) );
6292+ rb_define_const( mDXRuby, "K_WEBHOME" , INT2FIX(DIK_WEBHOME) );
6293+ rb_define_const( mDXRuby, "K_NUMPADCOMMA", INT2FIX(DIK_NUMPADCOMMA) );
6294+ rb_define_const( mDXRuby, "K_DIVIDE" , INT2FIX(DIK_DIVIDE) );
6295+ rb_define_const( mDXRuby, "K_SYSRQ" , INT2FIX(DIK_SYSRQ) );
6296+ rb_define_const( mDXRuby, "K_RMENU" , INT2FIX(DIK_RMENU) );
6297+ rb_define_const( mDXRuby, "K_PAUSE" , INT2FIX(DIK_PAUSE) );
6298+ rb_define_const( mDXRuby, "K_HOME" , INT2FIX(DIK_HOME) );
6299+ rb_define_const( mDXRuby, "K_UP" , INT2FIX(DIK_UP) );
6300+ rb_define_const( mDXRuby, "K_PRIOR" , INT2FIX(DIK_PRIOR) );
6301+ rb_define_const( mDXRuby, "K_LEFT" , INT2FIX(DIK_LEFT) );
6302+ rb_define_const( mDXRuby, "K_RIGHT" , INT2FIX(DIK_RIGHT) );
6303+ rb_define_const( mDXRuby, "K_END" , INT2FIX(DIK_END) );
6304+ rb_define_const( mDXRuby, "K_DOWN" , INT2FIX(DIK_DOWN) );
6305+ rb_define_const( mDXRuby, "K_NEXT" , INT2FIX(DIK_NEXT) );
6306+ rb_define_const( mDXRuby, "K_INSERT" , INT2FIX(DIK_INSERT) );
6307+ rb_define_const( mDXRuby, "K_DELETE" , INT2FIX(DIK_DELETE) );
6308+ rb_define_const( mDXRuby, "K_LWIN" , INT2FIX(DIK_LWIN) );
6309+ rb_define_const( mDXRuby, "K_RWIN" , INT2FIX(DIK_RWIN) );
6310+ rb_define_const( mDXRuby, "K_APPS" , INT2FIX(DIK_APPS) );
6311+ rb_define_const( mDXRuby, "K_POWER" , INT2FIX(DIK_POWER) );
6312+ rb_define_const( mDXRuby, "K_SLEEP" , INT2FIX(DIK_SLEEP) );
6313+ rb_define_const( mDXRuby, "K_WAKE" , INT2FIX(DIK_WAKE) );
6314+ rb_define_const( mDXRuby, "K_WEBSEARCH" , INT2FIX(DIK_WEBSEARCH) );
6315+ rb_define_const( mDXRuby, "K_WEBFAVORITES", INT2FIX(DIK_WEBFAVORITES) );
6316+ rb_define_const( mDXRuby, "K_WEBREFRESH" , INT2FIX(DIK_WEBREFRESH) );
6317+ rb_define_const( mDXRuby, "K_WEBSTOP" , INT2FIX(DIK_WEBSTOP) );
6318+ rb_define_const( mDXRuby, "K_WEBFORWARD" , INT2FIX(DIK_WEBFORWARD) );
6319+ rb_define_const( mDXRuby, "K_WEBBACK" , INT2FIX(DIK_WEBBACK) );
6320+ rb_define_const( mDXRuby, "K_MYCOMPUTER" , INT2FIX(DIK_MYCOMPUTER) );
6321+ rb_define_const( mDXRuby, "K_MAIL" , INT2FIX(DIK_MAIL) );
6322+ rb_define_const( mDXRuby, "K_MEDIASELECT", INT2FIX(DIK_MEDIASELECT) );
6323+ rb_define_const( mDXRuby, "K_BACKSPACE" , INT2FIX(DIK_BACK) );
6324+ rb_define_const( mDXRuby, "K_NUMPADSTAR" , INT2FIX(DIK_MULTIPLY) );
6325+ rb_define_const( mDXRuby, "K_LALT" , INT2FIX(DIK_LMENU) );
6326+ rb_define_const( mDXRuby, "K_CAPSLOCK" , INT2FIX(DIK_CAPITAL) );
6327+ rb_define_const( mDXRuby, "K_NUMPADMINUS", INT2FIX(DIK_SUBTRACT) );
6328+ rb_define_const( mDXRuby, "K_NUMPADPLUS" , INT2FIX(DIK_ADD) );
6329+ rb_define_const( mDXRuby, "K_NUMPADPERIOD", INT2FIX(DIK_DECIMAL) );
6330+ rb_define_const( mDXRuby, "K_NUMPADSLASH", INT2FIX(DIK_DIVIDE) );
6331+ rb_define_const( mDXRuby, "K_RALT" , INT2FIX(DIK_RMENU) );
6332+ rb_define_const( mDXRuby, "K_UPARROW" , INT2FIX(DIK_UP) );
6333+ rb_define_const( mDXRuby, "K_PGUP" , INT2FIX(DIK_PRIOR) );
6334+ rb_define_const( mDXRuby, "K_LEFTARROW" , INT2FIX(DIK_LEFT) );
6335+ rb_define_const( mDXRuby, "K_RIGHTARROW" , INT2FIX(DIK_RIGHT) );
6336+ rb_define_const( mDXRuby, "K_DOWNARROW" , INT2FIX(DIK_DOWN) );
6337+ rb_define_const( mDXRuby, "K_PGDN" , INT2FIX(DIK_NEXT) );
6338+
6339+ rb_define_const( mDXRuby, "P_UP" , INT2FIX(P_UP) );
6340+ rb_define_const( mDXRuby, "P_LEFT" , INT2FIX(P_LEFT) );
6341+ rb_define_const( mDXRuby, "P_RIGHT" , INT2FIX(P_RIGHT) );
6342+ rb_define_const( mDXRuby, "P_DOWN" , INT2FIX(P_DOWN) );
6343+ rb_define_const( mDXRuby, "P_BUTTON0" , INT2FIX(P_BUTTON0) );
6344+ rb_define_const( mDXRuby, "P_BUTTON1" , INT2FIX(P_BUTTON1) );
6345+ rb_define_const( mDXRuby, "P_BUTTON2" , INT2FIX(P_BUTTON2) );
6346+ rb_define_const( mDXRuby, "P_BUTTON3" , INT2FIX(P_BUTTON3) );
6347+ rb_define_const( mDXRuby, "P_BUTTON4" , INT2FIX(P_BUTTON4) );
6348+ rb_define_const( mDXRuby, "P_BUTTON5" , INT2FIX(P_BUTTON5) );
6349+ rb_define_const( mDXRuby, "P_BUTTON6" , INT2FIX(P_BUTTON6) );
6350+ rb_define_const( mDXRuby, "P_BUTTON7" , INT2FIX(P_BUTTON7) );
6351+ rb_define_const( mDXRuby, "P_BUTTON8" , INT2FIX(P_BUTTON8) );
6352+ rb_define_const( mDXRuby, "P_BUTTON9" , INT2FIX(P_BUTTON9) );
6353+ rb_define_const( mDXRuby, "P_BUTTON10" , INT2FIX(P_BUTTON10) );
6354+ rb_define_const( mDXRuby, "P_BUTTON11" , INT2FIX(P_BUTTON11) );
6355+ rb_define_const( mDXRuby, "P_BUTTON12" , INT2FIX(P_BUTTON12) );
6356+ rb_define_const( mDXRuby, "P_BUTTON13" , INT2FIX(P_BUTTON13) );
6357+ rb_define_const( mDXRuby, "P_BUTTON14" , INT2FIX(P_BUTTON14) );
6358+ rb_define_const( mDXRuby, "P_BUTTON15" , INT2FIX(P_BUTTON15) );
6359+
6360+ rb_define_const( mDXRuby, "M_LBUTTON" , INT2FIX(M_LBUTTON) );
6361+ rb_define_const( mDXRuby, "M_RBUTTON" , INT2FIX(M_RBUTTON) );
6362+ rb_define_const( mDXRuby, "M_MBUTTON" , INT2FIX(M_MBUTTON) );
6363+
6364+ rb_define_const( mDXRuby, "FORMAT_JPEG" , INT2FIX(FORMAT_JPEG));
6365+ rb_define_const( mDXRuby, "FORMAT_JPG" , INT2FIX(FORMAT_JPG) );
6366+// rb_define_const( mDXRuby, "FORMAT_PNG" , INT2FIX(FORMAT_PNG) );
6367+ rb_define_const( mDXRuby, "FORMAT_BMP" , INT2FIX(FORMAT_BMP) );
6368+ rb_define_const( mDXRuby, "FORMAT_DDS" , INT2FIX(FORMAT_DDS) );
6369+
6370+ rb_define_const( mDXRuby, "WAVE_SIN" , INT2FIX(WAVE_SIN) );
6371+ rb_define_const( mDXRuby, "WAVE_SAW" , INT2FIX(WAVE_SAW) );
6372+ rb_define_const( mDXRuby, "WAVE_TRI" , INT2FIX(WAVE_TRI) );
6373+ rb_define_const( mDXRuby, "WAVE_RECT" , INT2FIX(WAVE_RECT) );
6374+
6375+ rb_define_const( mDXRuby, "TEXF_POINT" , INT2FIX(D3DTEXF_POINT) );
6376+ rb_define_const( mDXRuby, "TEXF_LINEAR" , INT2FIX(D3DTEXF_LINEAR) );
6377+ rb_define_const( mDXRuby, "TEXF_GAUSSIANQUAD", INT2FIX(D3DTEXF_GAUSSIANQUAD) );
6378+
6379+ /* 例外定義 */
6380+ eDXRubyError = rb_define_class_under( mDXRuby, "DXRubyError", rb_eRuntimeError );
6381+
6382+ /* 定数登録 */
6383+ rb_define_const( mDXRuby, "VERSION", rb_str_new2( DXRUBY_VERSION ) );
6384+
6385+ {
6386+ VALUE temp;
6387+ temp = rb_eval_string( "$dxruby_no_include" );
6388+ if( temp == Qfalse || temp == Qnil )
6389+ {
6390+ rb_include_module( rb_cObject, mDXRuby );
6391+ }
6392+ }
6393+
6394+ /* シンボル定義 */
6395+ symbol_blend = ID2SYM(rb_intern("blend"));
6396+ symbol_angle = ID2SYM(rb_intern("angle"));
6397+ symbol_alpha = ID2SYM(rb_intern("alpha"));
6398+ symbol_scalex = ID2SYM(rb_intern("scalex"));
6399+ symbol_scaley = ID2SYM(rb_intern("scaley"));
6400+ symbol_centerx = ID2SYM(rb_intern("centerx"));
6401+ symbol_centery = ID2SYM(rb_intern("centery"));
6402+ symbol_z = ID2SYM(rb_intern("z"));
6403+ symbol_color = ID2SYM(rb_intern("color"));
6404+ symbol_add = ID2SYM(rb_intern("add"));
6405+ symbol_add2 = ID2SYM(rb_intern("add2"));
6406+ symbol_sub = ID2SYM(rb_intern("sub"));
6407+ symbol_italic = ID2SYM(rb_intern("italic"));
6408+ symbol_weight = ID2SYM(rb_intern("weight"));
6409+
6410+ /* 終了時に実行する関数 */
6411+ rb_set_end_proc( Window_shutdown, Qnil );
6412+
6413+ /* スプライト構造体の初期値設定 */
6414+ g_SpriteCount = 0;
6415+ g_SpriteAllocateCount = 128;
6416+ g_SpriteList = malloc( g_SpriteAllocateCount * sizeof(struct DXRubySpriteList) );
6417+ g_SpriteStruct = malloc( g_SpriteAllocateCount * sizeof(struct DXRubySprite) );
6418+
6419+ g_WindowInfo.width = 640;
6420+ g_WindowInfo.height = 480;
6421+ g_WindowInfo.windowed = Qtrue;
6422+ g_WindowInfo.created = Qfalse;
6423+ g_WindowInfo.scale = 1;
6424+ g_WindowInfo.enablemouse = Qtrue;
6425+ g_WindowInfo.mousewheelpos = 0;
6426+ g_WindowInfo.fps = 60;
6427+ g_WindowInfo.frameskip = Qfalse;
6428+ g_WindowInfo.r = 0;
6429+ g_WindowInfo.g = 0;
6430+ g_WindowInfo.b = 0;
6431+ g_WindowInfo.minfilter = D3DTEXF_LINEAR;
6432+ g_WindowInfo.magfilter = D3DTEXF_LINEAR;
6433+ g_WindowInfo.hIcon = 0;
6434+ g_WindowInfo.loop = 0;
6435+ g_WindowInfo.requestclose = 0;
6436+
6437+ /* 割り当て初期化 */
6438+ for( i = 0; i < 256; i++)
6439+ {
6440+ g_diKeyConfig[i] = -1;
6441+ }
6442+ for( i = 0; i < PADMAX; i++)
6443+ {
6444+ for( j = 0; j < 20; j++)
6445+ {
6446+ g_PadState[i].PadConfig[j] = -1;
6447+ }
6448+ }
6449+
6450+ /* デフォルトの割り当て */
6451+ Input_SetConfig( 0, P_LEFT , DIK_LEFT );
6452+ Input_SetConfig( 0, P_RIGHT , DIK_RIGHT );
6453+ Input_SetConfig( 0, P_UP , DIK_UP );
6454+ Input_SetConfig( 0, P_DOWN , DIK_DOWN );
6455+ Input_SetConfig( 0, P_BUTTON0, DIK_Z );
6456+ Input_SetConfig( 0, P_BUTTON1, DIK_X );
6457+ Input_SetConfig( 0, P_BUTTON2, DIK_C );
6458+
6459+ /* ウィンドウ作成(この時点では非表示) */
6460+ InitWindow();
6461+
6462+ /* DirectX Graphicsの初期化 */
6463+ InitDXGraphics();
6464+
6465+ /* DirectInput初期化 */
6466+ InitDirectInput();
6467+}
6468+
6469+
6470+/*--------------------------------------------------------------------
6471+ (内部関数)ウィンドウの生成
6472+ ---------------------------------------------------------------------*/
6473+static void InitWindow( void )
6474+{
6475+ WNDCLASSEX wcex;
6476+ RECT rect;
6477+
6478+ /* ウインドウ・クラスの登録 */
6479+ wcex.cbSize = sizeof( WNDCLASSEX );
6480+ wcex.style = CS_HREDRAW | CS_VREDRAW;
6481+ wcex.lpfnWndProc = (WNDPROC)MainWndProc;
6482+ wcex.cbClsExtra = 0;
6483+ wcex.cbWndExtra = 0;
6484+ wcex.hInstance = g_hInstance;
6485+ wcex.hIcon = NULL;
6486+ wcex.hIconSm = NULL;
6487+ wcex.hCursor = LoadCursor( NULL, IDC_ARROW );
6488+ wcex.hbrBackground = (HBRUSH)( COLOR_WINDOW + 1 );
6489+ wcex.lpszMenuName = NULL;
6490+ wcex.lpszClassName = "DXRuby";
6491+
6492+ if( !RegisterClassEx( &wcex ) )
6493+ {
6494+ rb_raise( eDXRubyError, "ウィンドウの初期化に失敗しました - RegusterClassEx" );
6495+ }
6496+
6497+ /* メイン・ウインドウ作成(ウインドウ・モード用) */
6498+ rect.top = 0;
6499+ rect.left = 0;
6500+ rect.right = g_WindowInfo.width;
6501+ rect.bottom = g_WindowInfo.height;
6502+
6503+ AdjustWindowRect( &rect, WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX, FALSE );
6504+
6505+ rect.right = rect.right - rect.left;
6506+ rect.bottom = rect.bottom - rect.top;
6507+ rect.left = 0;
6508+ rect.top = 0;
6509+
6510+ g_hWind = CreateWindow( TEXT("DXRuby"), TEXT("DXRuby Application"),
6511+ WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX,
6512+ CW_USEDEFAULT, CW_USEDEFAULT,
6513+ rect.right - rect.left, rect.bottom - rect.top,
6514+ NULL, NULL, g_hInstance, NULL );
6515+ if( g_hWind == NULL )
6516+ {
6517+ rb_raise( eDXRubyError, "ウィンドウの初期化に失敗しました - CreateWindow" );
6518+ }
6519+
6520+ GetWindowRect( g_hWind, &rect );
6521+ g_WindowInfo.x = rect.left;
6522+ g_WindowInfo.y = rect.top;
6523+}
6524+
6525+
6526+/*--------------------------------------------------------------------
6527+ (内部関数)DirectX Graphics初期化
6528+ ---------------------------------------------------------------------*/
6529+static void InitDXGraphics( void )
6530+{
6531+ D3DVIEWPORT9 vp;
6532+ HRESULT hr;
6533+
6534+ /* Direct3Dオブジェクトの作成 */
6535+ g_pD3D = Direct3DCreate9( D3D_SDK_VERSION );
6536+
6537+ if( g_pD3D == NULL )
6538+ {
6539+ rb_raise( eDXRubyError, "DirectX Graphicsの初期化に失敗しました - Direct3DCreate9" );
6540+ }
6541+
6542+ /* D3DDeviceオブジェクトの作成(ウインドウ・モード) */
6543+ ZeroMemory( &g_D3DPP, sizeof( g_D3DPP ) );
6544+
6545+ g_D3DPP.BackBufferWidth = 0;
6546+ g_D3DPP.BackBufferHeight = 0;
6547+ g_D3DPP.BackBufferFormat = D3DFMT_UNKNOWN;
6548+ g_D3DPP.BackBufferCount = 1;
6549+ g_D3DPP.MultiSampleType = D3DMULTISAMPLE_NONE;
6550+ g_D3DPP.MultiSampleQuality = 0;
6551+ g_D3DPP.SwapEffect = D3DSWAPEFFECT_DISCARD;
6552+ g_D3DPP.hDeviceWindow = g_hWind;
6553+ g_D3DPP.Windowed = TRUE;
6554+ g_D3DPP.EnableAutoDepthStencil = FALSE;
6555+ g_D3DPP.AutoDepthStencilFormat = D3DFMT_UNKNOWN;
6556+ g_D3DPP.Flags = 0;
6557+ g_D3DPP.FullScreen_RefreshRateInHz = 0;
6558+ g_D3DPP.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
6559+
6560+ hr = g_pD3D->lpVtbl->CreateDevice( g_pD3D, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, g_hWind,
6561+ D3DCREATE_HARDWARE_VERTEXPROCESSING, &g_D3DPP, &g_pD3DDevice );
6562+
6563+ if( FAILED( hr ) )
6564+ {
6565+ hr = g_pD3D->lpVtbl->CreateDevice( g_pD3D, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, g_hWind,
6566+ D3DCREATE_SOFTWARE_VERTEXPROCESSING, &g_D3DPP, &g_pD3DDevice );
6567+
6568+ if( FAILED( hr ) )
6569+ {
6570+ rb_raise( eDXRubyError, "DirectX Graphicsの初期化に失敗しました - CreateDevice" );
6571+ }
6572+ }
6573+
6574+ /* ビューポートの設定 */
6575+ vp.X = 0;
6576+ vp.Y = 0;
6577+ vp.Width = g_D3DPP.BackBufferWidth;
6578+ vp.Height = g_D3DPP.BackBufferHeight;
6579+ vp.MinZ = 0.0f;
6580+ vp.MaxZ = 1.0f;
6581+
6582+ hr = g_pD3DDevice->lpVtbl->SetViewport( g_pD3DDevice, &vp );
6583+
6584+ if( FAILED( hr ) )
6585+ {
6586+ rb_raise( eDXRubyError, "DirectX Graphicsの初期化に失敗しました - SetViewport" );
6587+ }
6588+
6589+ g_pD3DDevice->lpVtbl->Clear( g_pD3DDevice, 0, NULL, D3DCLEAR_TARGET,
6590+ D3DCOLOR_XRGB(0,0,0), 1.0f, 0 );
6591+
6592+ /* スプライトオブジェクト作成 */
6593+ hr = D3DXCreateSprite( g_pD3DDevice, &g_pD3DXSprite );
6594+
6595+ if( FAILED( hr ) )
6596+ {
6597+ rb_raise( eDXRubyError, "DirectX Graphicsの初期化に失敗しました - CreateSprite" );
6598+ }
6599+}
6600+
6601+
6602+/*--------------------------------------------------------------------
6603+ (内部関数)フレーム調整初期化
6604+ ---------------------------------------------------------------------*/
6605+static void InitSync( void )
6606+{
6607+ timeBeginPeriod( 1 );
6608+
6609+ /* パフォーマンスカウンタの秒間カウント値取得 */
6610+ if( QueryPerformanceFrequency( (LARGE_INTEGER *)&g_OneSecondCount ) )
6611+ {
6612+ /* パフォーマンスカウンタがある場合 */
6613+ g_isPerformanceCounter = 1;
6614+ QueryPerformanceCounter( (LARGE_INTEGER *)&g_OldTime );
6615+ }
6616+ else
6617+ {
6618+ /* パフォーマンスカウンタが無い場合 */
6619+ g_isPerformanceCounter = 0;
6620+ g_OneSecondCount = 1000;
6621+ g_OldTime = timeGetTime();
6622+ }
6623+}
6624+
6625+
6626+/* デバイス列挙関数 */
6627+BOOL CALLBACK EnumJoysticksCallback( const DIDEVICEINSTANCE* pdidInstance, void* pContext )
6628+{
6629+ HRESULT hr;
6630+
6631+ /* 列挙されたジョイスティックへのインターフェイスを取得する */
6632+ hr = g_pDInput->lpVtbl->CreateDevice( g_pDInput,
6633+ &pdidInstance->guidInstance,
6634+ &g_pDIDJoyPad[g_JoystickCount],
6635+ NULL );
6636+ if( SUCCEEDED( hr ) )
6637+ {
6638+ return (++g_JoystickCount == PADMAX)?(DIENUM_STOP):(DIENUM_CONTINUE);
6639+ }
6640+
6641+ return DIENUM_STOP;
6642+}
6643+
6644+/* オブジェクト(軸)列挙関数 */
6645+BOOL CALLBACK EnumAxisCallback( const DIDEVICEOBJECTINSTANCE* pdidoi, void *pContext )
6646+{
6647+ HRESULT hr;
6648+ DIPROPRANGE diprg = { sizeof(DIPROPRANGE), sizeof(DIPROPHEADER) };
6649+ struct DXRubyPadInfo *pad;
6650+
6651+ pad = (struct DXRubyPadInfo *)pContext;
6652+
6653+ diprg.diph.dwHow = DIPH_BYID;
6654+ diprg.diph.dwObj = pdidoi->dwType;
6655+
6656+ /*========================================================*/
6657+ /* 取得 */
6658+ hr = pad->pDIDJoyPad->lpVtbl->GetProperty( pad->pDIDJoyPad, DIPROP_RANGE, &diprg.diph );
6659+
6660+ if( FAILED( hr ) )
6661+ {
6662+ rb_raise( eDXRubyError, "DirectInputの初期化に失敗しました - GetProperty" );
6663+ }
6664+
6665+ /* x軸 */
6666+ if( memcmp( &pdidoi->guidType, &GUID_XAxis ,sizeof(GUID)) == 0 )
6667+ {
6668+ int xcenter;
6669+ xcenter = (diprg.lMin + diprg.lMax) / 2;
6670+ pad->left = (xcenter - diprg.lMin) / 2;
6671+ pad->right = (diprg.lMax - xcenter) / 2 + xcenter;
6672+ }
6673+
6674+ /* y軸 */
6675+ if( memcmp( &pdidoi->guidType, &GUID_YAxis ,sizeof(GUID)) == 0 )
6676+ {
6677+ int ycenter;
6678+ ycenter = (diprg.lMin + diprg.lMax) / 2;
6679+ pad->up = (ycenter - diprg.lMin) / 2;
6680+ pad->down = (diprg.lMax - ycenter) / 2 + ycenter;
6681+ }
6682+
6683+ return DIENUM_CONTINUE;
6684+}
6685+
6686+/*--------------------------------------------------------------------
6687+ (内部関数)DirectInput初期化
6688+ ---------------------------------------------------------------------*/
6689+static void InitDirectInput( void )
6690+{
6691+ HRESULT hr;
6692+ int i;
6693+
6694+/* DirectInput初期化 */
6695+
6696+ /* DirectInputオブジェクトの作成 */
6697+ hr = DirectInput8Create( g_hInstance, DIRECTINPUT_VERSION,
6698+ &IID_IDirectInput8, (void **)&g_pDInput, NULL );
6699+
6700+ if( FAILED( hr ) )
6701+ {
6702+ rb_raise( eDXRubyError, "DirectInputの初期化に失敗しました - DirectInput8Create" );
6703+ }
6704+
6705+/* キーボード */
6706+
6707+ /* デバイス・オブジェクトを作成(キーボード) */
6708+ hr = g_pDInput->lpVtbl->CreateDevice( g_pDInput, &GUID_SysKeyboard, &g_pDIDKeyBoard, NULL );
6709+
6710+ if( FAILED( hr ) )
6711+ {
6712+ rb_raise( eDXRubyError, "DirectInputの初期化に失敗しました - CreateDevice" );
6713+ }
6714+
6715+ /* データ形式を設定(キーボードですよ) */
6716+ hr = g_pDIDKeyBoard->lpVtbl->SetDataFormat( g_pDIDKeyBoard, &c_dfDIKeyboard );
6717+
6718+ if( FAILED( hr ) )
6719+ {
6720+ rb_raise( eDXRubyError, "DirectInputの初期化に失敗しました - SetDataFormat" );
6721+ }
6722+
6723+ /* キーボードのモードを設定(フォアグラウンド&非排他モード) */
6724+ hr = g_pDIDKeyBoard->lpVtbl->SetCooperativeLevel( g_pDIDKeyBoard, g_hWind, DISCL_NONEXCLUSIVE | DISCL_FOREGROUND );
6725+
6726+ if( FAILED( hr ) )
6727+ {
6728+ rb_raise( eDXRubyError, "DirectInputの初期化に失敗しました - SetCooperativeLevel" );
6729+ }
6730+
6731+ /* 入力制御開始 */
6732+ g_pDIDKeyBoard->lpVtbl->Acquire( g_pDIDKeyBoard );
6733+
6734+
6735+/* ゲームパッド */
6736+
6737+ for( i = 0; i < PADMAX; i++)
6738+ {
6739+ g_pDIDJoyPad[i] = NULL;
6740+ }
6741+ g_JoystickCount = 0;
6742+
6743+ /* ゲームデバイス列挙 */
6744+ hr = g_pDInput->lpVtbl->EnumDevices( g_pDInput, DI8DEVCLASS_GAMECTRL, EnumJoysticksCallback, NULL, DIEDFL_ATTACHEDONLY );
6745+
6746+ if( FAILED( hr ) )
6747+ {
6748+ rb_raise( eDXRubyError, "DirectInputの初期化に失敗しました - EnumDevices" );
6749+ }
6750+
6751+ /* ゲームデバイス初期化 */
6752+ for ( i = 0; i < g_JoystickCount; i++ )
6753+ {
6754+ /* データ形式を設定 */
6755+ hr = g_pDIDJoyPad[i]->lpVtbl->SetDataFormat( g_pDIDJoyPad[i], &c_dfDIJoystick );
6756+
6757+ if( FAILED( hr ) )
6758+ {
6759+ rb_raise( eDXRubyError, "DirectInputの初期化に失敗しました - SetDataFormat" );
6760+ }
6761+
6762+ /* キーボードのモードを設定(フォアグラウンド&非排他モード) */
6763+ hr = g_pDIDJoyPad[i]->lpVtbl->SetCooperativeLevel( g_pDIDJoyPad[i], g_hWind, DISCL_NONEXCLUSIVE | DISCL_FOREGROUND );
6764+
6765+ if( FAILED( hr ) )
6766+ {
6767+ rb_raise( eDXRubyError, "DirectInputの初期化に失敗しました - SetCooperativeLevel" );
6768+ }
6769+
6770+ /* オブジェクト列挙 */
6771+ g_PadInfo[i].pDIDJoyPad = g_pDIDJoyPad[i];
6772+ hr = g_pDIDJoyPad[i]->lpVtbl->EnumObjects( g_pDIDJoyPad[i], EnumAxisCallback, &g_PadInfo[i], DIDFT_AXIS );
6773+
6774+ if( FAILED( hr ) )
6775+ {
6776+ rb_raise( eDXRubyError, "DirectInputの初期化に失敗しました - EnumObjects" );
6777+ }
6778+
6779+ /* 入力制御開始 */
6780+ g_pDIDJoyPad[i]->lpVtbl->Acquire( g_pDIDJoyPad[i] );
6781+ }
6782+
6783+}
6784+
6785+
6786+
6787+
6788+static void AllocSpriteList( void )
6789+{
6790+ int i;
6791+
6792+ if( g_SpriteCount >= g_SpriteAllocateCount )
6793+ {
6794+ g_SpriteAllocateCount = g_SpriteAllocateCount * 3 / 2; /* 1.5倍にする */
6795+ g_SpriteList = realloc(g_SpriteList, g_SpriteAllocateCount * sizeof(struct DXRubySpriteList) );
6796+ g_SpriteStruct = realloc(g_SpriteStruct, g_SpriteAllocateCount * sizeof(struct DXRubySprite) );
6797+ for( i = 0; i < g_SpriteCount; i++)
6798+ {
6799+ g_SpriteList[i].sprite = &g_SpriteStruct[i];
6800+ }
6801+ }
6802+}
6803+
6804+
6805+/* マージソート */
6806+void merge( struct DXRubySpriteList *list, struct DXRubySpriteList *temp, int left, int mid, int right )
6807+{
6808+ int left_end, num_elements, tmp_pos;
6809+
6810+ left_end = mid - 1;
6811+ tmp_pos = left;
6812+ num_elements = right - left + 1;
6813+
6814+ while ((left <= left_end) && (mid <= right))
6815+ {
6816+ if (list[left].z <= list[mid].z)
6817+ temp[tmp_pos++] = list[left++];
6818+ else
6819+ temp[tmp_pos++] = list[mid++];
6820+ }
6821+
6822+ while (left <= left_end)
6823+ {
6824+ temp[tmp_pos++] = list[left++];
6825+ }
6826+ while (mid <= right)
6827+ {
6828+ temp[tmp_pos++] = list[mid++];
6829+ }
6830+
6831+ while (num_elements--)
6832+ {
6833+ list[right] = temp[right--];
6834+ }
6835+}
6836+void m_sort( struct DXRubySpriteList *list, struct DXRubySpriteList *temp, int left, int right )
6837+{
6838+ int mid;
6839+
6840+ if( right > left )
6841+ {
6842+ mid = (right + left) / 2;
6843+ m_sort( list, temp, left, mid );
6844+ m_sort( list, temp, mid+1, right );
6845+
6846+ merge( list, temp, left, mid+1, right );
6847+ }
6848+}
6849+void SortSpriteList( void )
6850+{
6851+ struct DXRubySpriteList *temp;
6852+ int i;
6853+
6854+ for( i = 0; i < g_SpriteCount; i++ )
6855+ {
6856+ if( g_SpriteList[i].z != 0.0f )
6857+ {
6858+ temp = malloc( sizeof(struct DXRubySpriteList)* g_SpriteCount );
6859+ m_sort( g_SpriteList, temp, 0, g_SpriteCount - 1 );
6860+ free(temp);
6861+ break;
6862+ }
6863+ }
6864+}
6865+
6866+
6867+/***********************
6868+ * 外部インターフェース
6869+ ***********************/
6870+
6871+/*--------------------------------------------------------------------
6872+ 描画設定(通常描画)
6873+ ---------------------------------------------------------------------*/
6874+void DXRuby_draw( int x, int y, VALUE vimage, float z )
6875+{
6876+ struct DXRubyImage *image;
6877+
6878+ AllocSpriteList();
6879+
6880+ /* 引数のイメージオブジェクトから中身を取り出す */
6881+ if( TYPE( vimage ) != T_DATA ) rb_raise(rb_eTypeError, "wrong argument type %s (expected DXRuby::Image)", rb_obj_classname( vimage ));
6882+ image = (struct DXRubyImage *)DATA_PTR( vimage );
6883+ if( RDATA( vimage )->dfree != (RUBY_DATA_FUNC)release_Image )
6884+ {
6885+ rb_raise(rb_eTypeError, "wrong argument type %s (expected DXRuby::Image)", rb_obj_classname( vimage ));
6886+ }
6887+
6888+ /* DXRubySpriteオブジェクト設定 */
6889+ g_SpriteStruct[g_SpriteCount].image = image;
6890+ g_SpriteStruct[g_SpriteCount].x = x;
6891+ g_SpriteStruct[g_SpriteCount].y = y;
6892+ g_SpriteStruct[g_SpriteCount].angle = 0.0f;
6893+ g_SpriteStruct[g_SpriteCount].scalex = 1.0f;
6894+ g_SpriteStruct[g_SpriteCount].scaley = 1.0f;
6895+ g_SpriteStruct[g_SpriteCount].alpha = 0xff;
6896+ g_SpriteStruct[g_SpriteCount].centerx = image->width / 2;
6897+ g_SpriteStruct[g_SpriteCount].centery = image->height / 2;
6898+ g_SpriteStruct[g_SpriteCount].blendflag = 0;
6899+ g_SpriteStruct[g_SpriteCount].fontflag = 0;
6900+ g_SpriteStruct[g_SpriteCount].vpflag = 0;
6901+ g_SpriteStruct[g_SpriteCount].value = vimage;
6902+
6903+ /* リストデータに追加 */
6904+ g_SpriteList[g_SpriteCount].sprite = &g_SpriteStruct[g_SpriteCount];
6905+ g_SpriteList[g_SpriteCount].z = z;
6906+ g_SpriteCount++;
6907+}
6908+
6909+
6910+/*--------------------------------------------------------------------
6911+ 描画設定(拡大縮小描画) フラグは0にするとcenter無視
6912+ ---------------------------------------------------------------------*/
6913+void DXRuby_drawScale( int x, int y, VALUE vimage, float scalex, float scaley, float centerx, float centery, float z, int flag )
6914+{
6915+ struct DXRubyImage *image;
6916+
6917+ AllocSpriteList();
6918+
6919+ /* 引数のイメージオブジェクトから中身を取り出す */
6920+ if( TYPE( vimage ) != T_DATA ) rb_raise(rb_eTypeError, "wrong argument type %s (expected DXRuby::Image)", rb_obj_classname( vimage ));
6921+ image = (struct DXRubyImage *)DATA_PTR( vimage );
6922+ if( RDATA( vimage )->dfree != (RUBY_DATA_FUNC)release_Image )
6923+ {
6924+ rb_raise(rb_eTypeError, "wrong argument type %s (expected DXRuby::Image)", rb_obj_classname( vimage ));
6925+ }
6926+
6927+ /* DXRubySpriteオブジェクト設定 */
6928+ g_SpriteStruct[g_SpriteCount].image = image;
6929+ g_SpriteStruct[g_SpriteCount].x = x;
6930+ g_SpriteStruct[g_SpriteCount].y = y;
6931+ g_SpriteStruct[g_SpriteCount].angle = 0.0f;
6932+ g_SpriteStruct[g_SpriteCount].scalex = scalex;
6933+ g_SpriteStruct[g_SpriteCount].scaley = scaley;
6934+ g_SpriteStruct[g_SpriteCount].centerx = flag ? centerx :image->width / 2;
6935+ g_SpriteStruct[g_SpriteCount].centery = flag ? centery : image->height / 2;
6936+ g_SpriteStruct[g_SpriteCount].alpha = 0xff;
6937+ g_SpriteStruct[g_SpriteCount].blendflag = 0;
6938+ g_SpriteStruct[g_SpriteCount].fontflag = 0;
6939+ g_SpriteStruct[g_SpriteCount].vpflag = 0;
6940+ g_SpriteStruct[g_SpriteCount].value = vimage;
6941+
6942+ /* リストデータに追加 */
6943+ g_SpriteList[g_SpriteCount].sprite = &g_SpriteStruct[g_SpriteCount];
6944+ g_SpriteList[g_SpriteCount].z = z;
6945+ g_SpriteCount++;
6946+}
6947+
6948+
6949+/*--------------------------------------------------------------------
6950+ 描画設定(回転描画) フラグは0にするとcenter無視
6951+ ---------------------------------------------------------------------*/
6952+void DXRuby_drawRot( int x, int y, VALUE vimage, float angle, int centerx, int centery, int z, int flag)
6953+{
6954+ struct DXRubyImage *image;
6955+
6956+ AllocSpriteList();
6957+
6958+ /* 引数のイメージオブジェクトから中身を取り出す */
6959+ if( TYPE( vimage ) != T_DATA ) rb_raise(rb_eTypeError, "wrong argument type %s (expected DXRuby::Image)", rb_obj_classname( vimage ));
6960+ image = (struct DXRubyImage *)DATA_PTR( vimage );
6961+ if( RDATA( vimage )->dfree != (RUBY_DATA_FUNC)release_Image )
6962+ {
6963+ rb_raise(rb_eTypeError, "wrong argument type %s (expected DXRuby::Image)", rb_obj_classname( vimage ));
6964+ }
6965+
6966+ /* DXRubySpriteオブジェクト設定 */
6967+ g_SpriteStruct[g_SpriteCount].image = image;
6968+ g_SpriteStruct[g_SpriteCount].x = x;
6969+ g_SpriteStruct[g_SpriteCount].y = y;
6970+ g_SpriteStruct[g_SpriteCount].angle = angle;
6971+ g_SpriteStruct[g_SpriteCount].scalex = 1.0f;
6972+ g_SpriteStruct[g_SpriteCount].scaley = 1.0f;
6973+ g_SpriteStruct[g_SpriteCount].alpha = 0xff;
6974+ g_SpriteStruct[g_SpriteCount].blendflag = 0;
6975+ g_SpriteStruct[g_SpriteCount].centerx = flag ? centerx : image->width / 2;
6976+ g_SpriteStruct[g_SpriteCount].centery = flag ? centery : image->height / 2;
6977+ g_SpriteStruct[g_SpriteCount].fontflag = 0;
6978+ g_SpriteStruct[g_SpriteCount].vpflag = 0;
6979+ g_SpriteStruct[g_SpriteCount].value = vimage;
6980+
6981+ /* リストデータに追加 */
6982+ g_SpriteList[g_SpriteCount].sprite = &g_SpriteStruct[g_SpriteCount];
6983+ g_SpriteList[g_SpriteCount].z = z;
6984+ g_SpriteCount++;
6985+}
6986+
6987+
6988+/*--------------------------------------------------------------------
6989+ 描画設定(半透明描画)
6990+ ---------------------------------------------------------------------*/
6991+void DXRuby_drawAlpha( int x, int y, VALUE vimage, int alpha, int z )
6992+{
6993+ struct DXRubyImage *image;
6994+
6995+ AllocSpriteList();
6996+
6997+ /* 引数のイメージオブジェクトから中身を取り出す */
6998+ if( TYPE( vimage ) != T_DATA ) rb_raise(rb_eTypeError, "wrong argument type %s (expected DXRuby::Image)", rb_obj_classname( vimage ));
6999+ image = (struct DXRubyImage *)DATA_PTR( vimage );
7000+ if( RDATA( vimage )->dfree != (RUBY_DATA_FUNC)release_Image )
7001+ {
7002+ rb_raise(rb_eTypeError, "wrong argument type %s (expected DXRuby::Image)", rb_obj_classname( vimage ));
7003+ }
7004+
7005+ /* DXRubySpriteオブジェクト設定 */
7006+ g_SpriteStruct[g_SpriteCount].image = image;
7007+ g_SpriteStruct[g_SpriteCount].x = x;
7008+ g_SpriteStruct[g_SpriteCount].y = y;
7009+ g_SpriteStruct[g_SpriteCount].angle = 0.0f;
7010+ g_SpriteStruct[g_SpriteCount].scalex = 1.0f;
7011+ g_SpriteStruct[g_SpriteCount].scaley = 1.0f;
7012+ g_SpriteStruct[g_SpriteCount].alpha = alpha;
7013+ g_SpriteStruct[g_SpriteCount].blendflag = 0;
7014+ g_SpriteStruct[g_SpriteCount].centerx = image->width / 2;
7015+ g_SpriteStruct[g_SpriteCount].centery = image->height / 2;
7016+ g_SpriteStruct[g_SpriteCount].fontflag = 0;
7017+ g_SpriteStruct[g_SpriteCount].vpflag = 0;
7018+ g_SpriteStruct[g_SpriteCount].value = vimage;
7019+
7020+ /* リストデータに追加 */
7021+ g_SpriteList[g_SpriteCount].sprite = &g_SpriteStruct[g_SpriteCount];
7022+ g_SpriteList[g_SpriteCount].z = z;
7023+ g_SpriteCount++;
7024+}
7025+
7026+
7027+/*--------------------------------------------------------------------
7028+ 描画設定(加算合成描画)
7029+ ---------------------------------------------------------------------*/
7030+void DXRuby_drawAdd( int x, int y, VALUE vimage, int z )
7031+{
7032+ struct DXRubyImage *image;
7033+
7034+ AllocSpriteList();
7035+
7036+ /* 引数のイメージオブジェクトから中身を取り出す */
7037+ if( TYPE( vimage ) != T_DATA ) rb_raise(rb_eTypeError, "wrong argument type %s (expected DXRuby::Image)", rb_obj_classname( vimage ));
7038+ image = (struct DXRubyImage *)DATA_PTR( vimage );
7039+ if( RDATA( vimage )->dfree != (RUBY_DATA_FUNC)release_Image )
7040+ {
7041+ rb_raise(rb_eTypeError, "wrong argument type %s (expected DXRuby::Image)", rb_obj_classname( vimage ));
7042+ }
7043+
7044+ /* DXRubySpriteオブジェクト設定 */
7045+ g_SpriteStruct[g_SpriteCount].image = image;
7046+ g_SpriteStruct[g_SpriteCount].x = x;
7047+ g_SpriteStruct[g_SpriteCount].y = y;
7048+ g_SpriteStruct[g_SpriteCount].angle = 0.0f;
7049+ g_SpriteStruct[g_SpriteCount].scalex = 1.0f;
7050+ g_SpriteStruct[g_SpriteCount].scaley = 1.0f;
7051+ g_SpriteStruct[g_SpriteCount].alpha = 0xff;
7052+ g_SpriteStruct[g_SpriteCount].blendflag = 4;
7053+ g_SpriteStruct[g_SpriteCount].centerx = image->width / 2;
7054+ g_SpriteStruct[g_SpriteCount].centery = image->height / 2;
7055+ g_SpriteStruct[g_SpriteCount].fontflag = 0;
7056+ g_SpriteStruct[g_SpriteCount].vpflag = 0;
7057+ g_SpriteStruct[g_SpriteCount].value = vimage;
7058+
7059+ /* リストデータに追加 */
7060+ g_SpriteList[g_SpriteCount].sprite = &g_SpriteStruct[g_SpriteCount];
7061+ g_SpriteList[g_SpriteCount].z = z;
7062+ g_SpriteCount++;
7063+}
7064+
7065+
7066+/*--------------------------------------------------------------------
7067+ 描画設定(減算合成描画)
7068+ ---------------------------------------------------------------------*/
7069+void DXRuby_drawSub( int x, int y, VALUE vimage, int z )
7070+{
7071+ struct DXRubyImage *image;
7072+
7073+ AllocSpriteList();
7074+
7075+ /* 引数のイメージオブジェクトから中身を取り出す */
7076+ if( TYPE( vimage ) != T_DATA ) rb_raise(rb_eTypeError, "wrong argument type %s (expected DXRuby::Image)", rb_obj_classname( vimage ));
7077+ image = (struct DXRubyImage *)DATA_PTR( vimage );
7078+ if( RDATA( vimage )->dfree != (RUBY_DATA_FUNC)release_Image )
7079+ {
7080+ rb_raise(rb_eTypeError, "wrong argument type %s (expected DXRuby::Image)", rb_obj_classname( vimage ));
7081+ }
7082+
7083+ /* DXRubySpriteオブジェクト設定 */
7084+ g_SpriteStruct[g_SpriteCount].image = image;
7085+ g_SpriteStruct[g_SpriteCount].x = x;
7086+ g_SpriteStruct[g_SpriteCount].y = y;
7087+ g_SpriteStruct[g_SpriteCount].angle = 0.0f;
7088+ g_SpriteStruct[g_SpriteCount].scalex = 1.0f;
7089+ g_SpriteStruct[g_SpriteCount].scaley = 1.0f;
7090+ g_SpriteStruct[g_SpriteCount].alpha = 0xff;
7091+ g_SpriteStruct[g_SpriteCount].blendflag = 6;
7092+ g_SpriteStruct[g_SpriteCount].centerx = image->width / 2;
7093+ g_SpriteStruct[g_SpriteCount].centery = image->height / 2;
7094+ g_SpriteStruct[g_SpriteCount].fontflag = 0;
7095+ g_SpriteStruct[g_SpriteCount].vpflag = 0;
7096+ g_SpriteStruct[g_SpriteCount].value = vimage;
7097+
7098+ /* リストデータに追加 */
7099+ g_SpriteList[g_SpriteCount].sprite = &g_SpriteStruct[g_SpriteCount];
7100+ g_SpriteList[g_SpriteCount].z = z;
7101+ g_SpriteCount++;
7102+}
7103+
7104+
7105+/*--------------------------------------------------------------------
7106+ 描画設定(フルオプション)
7107+ ---------------------------------------------------------------------*/
7108+void DXRuby_drawEx( int x, int y, VALUE vimage, float angle, float scalex, float scaley, float centerx, float centery, int alpha, int blend, int z, int flag )
7109+{
7110+ struct DXRubyImage *image;
7111+ AllocSpriteList();
7112+
7113+ /* 引数のイメージオブジェクトから中身を取り出す */
7114+ if( TYPE( vimage ) != T_DATA ) rb_raise(rb_eTypeError, "wrong argument type %s (expected DXRuby::Image)", rb_obj_classname( vimage ));
7115+ image = (struct DXRubyImage *)DATA_PTR( vimage );
7116+ if( RDATA( vimage )->dfree != (RUBY_DATA_FUNC)release_Image )
7117+ {
7118+ rb_raise(rb_eTypeError, "wrong argument type %s (expected DXRuby::Image)", rb_obj_classname( vimage ));
7119+ }
7120+
7121+ /* DXRubySpriteオブジェクト設定 */
7122+ g_SpriteStruct[g_SpriteCount].image = image;
7123+ g_SpriteStruct[g_SpriteCount].x = x;
7124+ g_SpriteStruct[g_SpriteCount].y = y;
7125+ g_SpriteStruct[g_SpriteCount].angle = angle;
7126+ g_SpriteStruct[g_SpriteCount].scalex = scalex;
7127+ g_SpriteStruct[g_SpriteCount].scaley = scaley;
7128+ g_SpriteStruct[g_SpriteCount].centerx = flag ? centerx : image->width / 2;
7129+ g_SpriteStruct[g_SpriteCount].centery = flag ? centery : image->height / 2;
7130+ g_SpriteStruct[g_SpriteCount].alpha = alpha;
7131+ g_SpriteStruct[g_SpriteCount].blendflag = blend;
7132+ g_SpriteStruct[g_SpriteCount].fontflag = 0;
7133+ g_SpriteStruct[g_SpriteCount].vpflag = 0;
7134+ g_SpriteStruct[g_SpriteCount].value = vimage;
7135+
7136+ /* リストデータに追加 */
7137+ g_SpriteList[g_SpriteCount].sprite = &g_SpriteStruct[g_SpriteCount];
7138+ g_SpriteList[g_SpriteCount].z = z;
7139+ g_SpriteCount++;
7140+}
7141+
7142+
7143+/*--------------------------------------------------------------------
7144+ イメージのロック
7145+ ---------------------------------------------------------------------*/
7146+void *DXRuby_lock( VALUE vimage, char **address, int *pitch, int *width, int *height )
7147+{
7148+ struct DXRubyImage *image;
7149+ D3DLOCKED_RECT texrect;
7150+ RECT rect;
7151+
7152+ /* 引数のイメージオブジェクトから中身を取り出す */
7153+ if( TYPE( vimage ) != T_DATA ) rb_raise(rb_eTypeError, "wrong argument type %s (expected DXRuby::Image)", rb_obj_classname( vimage ));
7154+ image = (struct DXRubyImage *)DATA_PTR( vimage );
7155+ if( RDATA( vimage )->dfree != (RUBY_DATA_FUNC)release_Image )
7156+ {
7157+ rb_raise(rb_eTypeError, "wrong argument type %s (expected DXRuby::Image)", rb_obj_classname( vimage ));
7158+ }
7159+
7160+ rect.left = (long)image->x;
7161+ rect.top = (long)image->y;
7162+ rect.right = (long)(image->x + image->width);
7163+ rect.bottom = (long)(image->y + image->height);
7164+ image->texture->pD3DTexture->lpVtbl->LockRect( image->texture->pD3DTexture, 0, &texrect, &rect, 0 );
7165+
7166+ // *((int*)((char *)texrect.pBits + x * 4 + y * texrect.Pitch)) = col;
7167+
7168+ *address = (char *)texrect.pBits;
7169+ *pitch = texrect.Pitch;
7170+ *width = (int)image->width;
7171+ *height = (int)image->height;
7172+
7173+ return image->texture->pD3DTexture;
7174+}
7175+
7176+
7177+/*--------------------------------------------------------------------
7178+ イメージのアンロック
7179+ ---------------------------------------------------------------------*/
7180+void DXRuby_unlock( void *texture )
7181+{
7182+ ((LPDIRECT3DTEXTURE9)texture)->lpVtbl->UnlockRect( (LPDIRECT3DTEXTURE9)texture, 0 );
7183+}
7184+
--- tags/1.0.8/sample/laser.rb (nonexistent)
+++ tags/1.0.8/sample/laser.rb (revision 189)
@@ -0,0 +1,154 @@
1+#! ruby -Ks
2+require 'dxruby'
3+require 'dxrubyex'
4+
5+image_houdai = Image.new(10,10,[0,255,0])
6+
7+ENEMY_OBJECTS = []
8+ENEMY_COLLISIONS = []
9+
10+class Enemy
11+ attr_reader :delete, :x, :y, :width, :height
12+ @@image = Image.new(50,50).circleFill(25,25,24,[255,0,255])
13+ @@image_damage = Image.new(50,50).circleFill(25,25,24,[255,200,255])
14+ def initialize
15+ @x = rand(590)
16+ @y = -49
17+ @speed = rand(5)
18+ @collision = CollisionCircle.new(self, 25, 25, 24)
19+ @delete = false
20+ @width = 50
21+ @height = 50
22+ @hp = 100
23+ end
24+
25+ def update
26+ @y += 1
27+ if @y >= 480
28+ @collision.delete
29+ @delete = true
30+ else
31+ @collision.set(@x,@y)
32+ ENEMY_COLLISIONS.push(@collision)
33+ end
34+ end
35+
36+ def hit(o) end
37+
38+ def damage(o)
39+ @hp -= 1
40+ if @hp == 0
41+ @delete = true
42+ else
43+ Window.draw(@x, @y, @@image_damage,2)
44+ end
45+ end
46+
47+ def draw
48+ Window.draw(@x, @y, @@image)
49+ end
50+end
51+
52+class Laser
53+ attr_reader :collision, :enemy, :x, :y
54+ @@image_laser = Image.new(1,1,[128,255,255,255])
55+ def initialize(x, y)
56+ @x = x
57+ @y = y
58+ @collision = [CollisionTriangle.new(self, 0,0,0,0,0,0),CollisionTriangle.new(self, 0,0,0,0,0,0)]
59+ @collision[0].set(@x,@y)
60+ @collision[1].set(@x,@y)
61+ @angle = 0
62+ @enemy = []
63+ end
64+
65+ def shot(d)
66+ @enemy.push(d)
67+ end
68+
69+ def get_near_enemy
70+ near_distance = 800
71+ near_enemy = nil
72+ @enemy.each do |e|
73+ distance = Math.sqrt((@x - (e.x + e.width/2))**2 + (@y - (e.y + e.height/2))**2)
74+ if distance < near_distance
75+ near_distance = distance
76+ near_enemy = e
77+ end
78+ end
79+ return near_enemy
80+ end
81+
82+ def rotation(x1,y1,x2,y2,x3,y3,x4,y4,angle)
83+ sina = Math.sin(angle/180.0*Math::PI)
84+ cosa = Math.cos(angle/180.0*Math::PI)
85+ result_x1 = x1 * cosa + y1 * sina
86+ result_y1 = x1 * sina - y1 * cosa
87+ result_x2 = x2 * cosa + y2 * sina
88+ result_y2 = x2 * sina - y2 * cosa
89+ result_x3 = x3 * cosa + y3 * sina
90+ result_y3 = x3 * sina - y3 * cosa
91+ result_x4 = x4 * cosa + y4 * sina
92+ result_y4 = x4 * sina - y4 * cosa
93+ return [result_x1, result_y1, result_x2, result_y2, result_x3, result_y3, result_x4, result_y4]
94+ end
95+
96+ def update
97+ if Input.mouseDown?(M_LBUTTON)
98+ mx,my = Input.mousePosX, Input.mousePosY
99+ @angle = Math.atan2(mx - @x, @y - my) / Math::PI * 180
100+ x1,y1,x2,y2,x3,y3,x4,y4 = rotation(-5,-800,5,-800,5,0,-5,0,@angle+180)
101+ @collision[0].setRange(x1,y1,x2,y2,x3,y3)
102+ @collision[1].setRange(x2,y2,x3,y3,x4,y4)
103+ end
104+ end
105+
106+ def draw(length)
107+ Window.drawEx(@x, @y, @@image_laser, :centerx=>0.5,:centery=>1,:scalex=>10,:scaley=>length,:angle=>@angle,:blend=>:add,:z=>1)
108+ end
109+end
110+
111+laser = [Laser.new(145, 474), Laser.new(505, 474)]
112+font = Font.new(32)
113+
114+count = 0
115+Window.loop do
116+ count += 1
117+ if count % 50 == 0
118+ ENEMY_OBJECTS.push(Enemy.new)
119+ end
120+
121+ if Input.mouseDown?(M_LBUTTON)
122+ laser[0].update
123+ laser[1].update
124+ end
125+
126+ ENEMY_OBJECTS.each do |e| e.update end
127+
128+ laser.each do |l|
129+ Collision.check(l.collision, ENEMY_COLLISIONS) if Input.mouseDown?(M_LBUTTON)
130+ enemy = l.get_near_enemy
131+ enemy.damage(l) if enemy
132+ if Input.mouseDown?(M_LBUTTON)
133+ if enemy
134+ length = Math::sqrt(((enemy.x + enemy.width/2) - (l.x+5))**2 + ((enemy.y + enemy.height/2) - (l.y+5))**2)
135+ else
136+ length = 800
137+ end
138+ l.draw(length)
139+ end
140+ end
141+
142+ ENEMY_OBJECTS.each do |e| e.draw end
143+ ENEMY_COLLISIONS.clear
144+ ENEMY_OBJECTS.delete_if do |e| e.delete end
145+
146+ laser[0].enemy.clear
147+ laser[1].enemy.clear
148+ Window.drawFont(0,0,Window.getLoad.to_i.to_s + " %", font, :z=>3)
149+
150+ Window.draw(140,470,image_houdai)
151+ Window.draw(500,470,image_houdai)
152+end
153+
154+
--- tags/1.0.8/sample/readme_sample.txt (nonexistent)
+++ tags/1.0.8/sample/readme_sample.txt (revision 189)
@@ -0,0 +1,50 @@
1+DXRuby サンプルプログラム
2+
3+まず最初に、ソースが汚くてごめんなさい。
4+テキトーに作ったものたちを参考になればって感じで詰め込んであります。
5+
6+8_puzzle
7+ ・・・8パズルです。画像を読み込んで遊んでみてください。
8+
9+block_destory
10+ ・・・英語でなんていうんですかね。こうですか、わかりません!ブロック崩しです。
11+
12+block_fall
13+ ・・・有名なアレモドキです。
14+
15+dot
16+ ・・・砂が降ってくるデモです。マウスでいじってください。
17+
18+drawtile
19+ ・・・Window.drawTileとWindow.setViewportのデモ。マップの2レイヤ描画をしています。
20+
21+flight
22+ ・・・空を飛んでるっぽい疑似3D表現のサンプルです。カーソルキーで動きます。
23+
24+mapedit
25+ ・・・疑似3Dの簡易マップエディタです。shift押しながらクリックで土地の上げ下げできます。
26+
27+meiro
28+ ・・・3D迷路です。
29+
30+minsanple
31+ ・・・最も簡単なサンプルです。
32+
33+race
34+ ・・・レースモドキです。ImageオブジェクトのcopyRectメソッドを使っています。
35+
36+sample
37+ ・・・Windowモジュールの各種機能のサンプルとなっています。
38+
39+soundeffect
40+ ・・・SoundEffectクラスのサンプルです。ZXCキーで音がでます。
41+
42+dxrubyex_sample1
43+ ・・・同梱のDXRubyExtensionのサンプルその1です。
44+
45+dxrubyex_sample2
46+ ・・・同梱のDXRubyExtensionのサンプルその2です。
47+
48+laser
49+ ・・・DXRubyExtensionを使ってレーザーを実装してみたサンプルです。
50+
--- tags/1.0.8/sample/drawtile.rb (nonexistent)
+++ tags/1.0.8/sample/drawtile.rb (revision 189)
@@ -0,0 +1,164 @@
1+# マップデータから背景描画サンプル
2+require 'dxruby'
3+
4+# マップデータ
5+map1 = [
6+ [1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
7+ [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 3, 3, 3, 3, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1],
8+ [1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 3, 3, 3, 1, 1, 1, 2, 1, 1, 1, 1, 1],
9+ [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 3, 3, 3, 1, 1, 1, 1, 1, 1, 1, 2, 1],
10+ [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 3, 1, 1, 1, 1, 1, 1, 1, 1],
11+ [1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1],
12+ [1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1],
13+ [1, 1, 1, 1, 1, 0, 0, 0, 3, 3, 3, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 3, 1, 1],
14+ [1, 1, 1, 2, 0, 0, 0, 3, 3, 3, 3, 2, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1],
15+ [1, 1, 1, 2, 0, 0, 0, 0, 3, 3, 3, 2, 2, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1],
16+ [1, 1, 2, 2, 0, 0, 0, 0, 0, 1, 1, 2, 2, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1],
17+ [1, 1, 2, 2, 0, 0, 0, 0, 0, 0, 1, 2, 2, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 3, 1, 1, 1],
18+ [1, 1, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 3, 3, 1, 1, 3, 3, 1, 1, 1],
19+ [1, 1, 1, 1, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 3, 3, 3, 3, 1, 1, 1, 1],
20+ [1, 1, 1, 1, 1, 2, 2, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 3, 3, 3, 3, 1, 1, 1, 1],
21+ [1, 1, 2, 1, 1, 1, 1, 2, 2, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 3, 3, 3, 3, 1, 1, 1, 1],
22+ [1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 3, 3, 3, 3, 3, 1, 1, 1, 1],
23+ [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 3, 3, 3, 3, 1, 1, 1, 1, 1],
24+ [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 1, 1, 1, 1, 1, 1, 0, 1, 3, 3, 3, 3, 3, 1, 1, 1, 1, 1],
25+ [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 1, 1, 1, 1, 3, 0, 3, 3, 3, 3, 1, 1, 1, 1, 1, 1],
26+ [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 0, 3, 3, 3, 1, 1, 1, 1, 1, 1, 1],
27+ [1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 3, 0, 3, 3, 3, 1, 1, 1, 1, 1, 1, 1],
28+ [1, 1, 1, 1, 1, 1, 1, 1, 3, 3, 3, 3, 3, 1, 1, 1, 1, 3, 3, 3, 0, 3, 3, 3, 3, 1, 1, 1, 1, 1, 2, 1],
29+ [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 1, 2, 3, 3, 3, 1, 1, 1, 1, 1, 2, 2, 2],
30+ [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2],
31+ [1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 3, 3, 3, 3, 3, 3, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2],
32+ [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 3, 3, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 1],
33+ [1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 1, 1],
34+ [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1],
35+ [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
36+ [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
37+ [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
38+]
39+
40+# 手前に描画する用のマップデータ(4は木のあたま。nilにすると描画しない)
41+map2 = [
42+ [nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 4, nil, nil, nil],
43+ [nil, 4, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 4, nil, nil, nil, nil, nil],
44+ [nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 4, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 4, nil],
45+ [nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil],
46+ [nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil],
47+ [nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil],
48+ [nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 4, nil, nil, nil, nil, nil, nil, nil, nil, nil],
49+ [nil, nil, nil, 4, nil, nil, nil, nil, nil, nil, nil, 4, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil],
50+ [nil, nil, nil, 4, nil, nil, nil, nil, nil, nil, nil, 4, 4, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil],
51+ [nil, nil, 4, 4, nil, nil, nil, nil, nil, nil, nil, 4, 4, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil],
52+ [nil, nil, 4, 4, nil, nil, nil, nil, nil, nil, nil, 4, 4, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil],
53+ [nil, nil, 4, 4, 4, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil],
54+ [nil, nil, nil, nil, 4, 4, 4, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil],
55+ [nil, nil, nil, nil, nil, 4, 4, 4, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil],
56+ [nil, nil, 4, nil, nil, nil, nil, 4, 4, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil],
57+ [nil, nil, nil, nil, nil, nil, nil, nil, 4, 4, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil],
58+ [nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil],
59+ [nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 4, 4, 4, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil],
60+ [nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 4, 4, 4, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil],
61+ [nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil],
62+ [nil, nil, nil, 4, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil],
63+ [nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 4, nil],
64+ [nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 4, nil, nil, nil, nil, nil, nil, nil, nil, 4, 4, 4],
65+ [nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 4, 4, 4, 4, 4],
66+ [nil, nil, nil, nil, nil, nil, nil, nil, 4, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 4, 4, 4, 4, 4, 4],
67+ [nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 4, 4, 4, 4, 4, nil],
68+ [nil, nil, nil, nil, nil, 4, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 4, 4, 4, nil, nil],
69+ [nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 4, nil, nil, nil, nil, nil, nil, nil, nil, nil],
70+ [nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 4, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil],
71+ [nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil],
72+ [nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil],
73+ [nil, nil, nil, nil, nil, nil, nil, nil, nil, 4, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil]
74+]
75+
76+
77+# 絵のデータを作る
78+mapimage = []
79+mapimage.push(Image.new(32, 32, [100, 100, 200])) # 海
80+mapimage.push(Image.new(32, 32, [50, 200, 50])) # 平地
81+mapimage.push(Image.new(32, 32, [50, 200, 50])) # 木の根元
82+mapimage[2].boxFill(13, 0, 18, 28, [200, 50, 50])
83+mapimage.push(Image.new(32, 32, [50, 200, 50])) # 山
84+for i in 1..30 do
85+ mapimage[3].line(15 - i/2, i, 16 + i/2, i, [200, 100, 100])
86+end
87+mapimage.push(Image.new(32, 32)) # 木のあたま。背景は透明色にしておく。
88+mapimage[4].boxFill(13, 16, 18, 31, [200, 50, 50])
89+mapimage[4].circleFill(16, 10, 8, [0, 255, 0])
90+
91+image = Image.new(32, 48). # 主人公
92+ circle(15, 5, 5, [255, 255, 255]).
93+ line(5, 18, 26, 18, [255, 255, 255]).
94+ line(15, 10, 15, 31, [255, 255, 255]).
95+ line(15, 31, 5, 47, [255, 255, 255]).
96+ line(15, 31, 25, 47, [255, 255, 255])
97+
98+# 座標初期位置
99+x = 0
100+y = 0
101+dx = 0
102+dy = 0
103+font = Font.new(32)
104+
105+# 0:入力待ち中、1:移動中
106+state = 0
107+
108+# 移動カウント
109+count = 0
110+
111+
112+Window.loop do
113+ # ビューポート設定
114+ Window.setViewport(32, 32, 640-64, 480-64, 0)
115+
116+ # 移動中はカウントアップするだけ
117+ if state == 1 then
118+ count = count + 4 # カウントアップ
119+ if count >= 32 then # カウント完了なら入力待ちに遷移
120+ state = 0
121+ count = 0
122+ x = x + dx # x座標移動
123+ y = y + dy # y座標移動
124+ # 座標ループ処理
125+ x = 0 if x > 31
126+ x = 31 if x < 0
127+ y = 0 if y > 31
128+ y = 31 if y < 0
129+ end
130+ end
131+
132+ # 入力待ち中
133+ if state == 0 then
134+ ix = Input.x
135+ iy = Input.y
136+ # 押されたチェック
137+ if ix + iy != 0 and (ix == 0 or iy == 0) then # ナナメは却下
138+ tempx = x + ix
139+ tempy = y + iy
140+ tempx = tempx - 32 if tempx > 31
141+ tempy = tempy - 32 if tempy > 31
142+ if map1[tempy][tempx] == 1 then
143+ state = 1 # スクロール中に遷移
144+ dx = ix
145+ dy = iy
146+ end
147+ end
148+ end
149+
150+ # 優先順位を変えて2回描画することで、キャラより手前にマップチップを描画することもできます。
151+ # ベースマップ描画
152+ Window.drawTile(32, 32, map1, mapimage, (x - 8.5) * 32 + count * dx, (y - 6) * 32 + count * dy, 18, 13, 0) # 優先順位0
153+
154+ # 人より手前に描画するマップ
155+ Window.drawTile(32, 32, map2, mapimage, (x - 8.5) * 32 + count * dx, (y - 6) * 32 + count * dy, 18, 13, 2) # 優先順位2
156+
157+ # 人描画
158+ Window.draw(9.5 * 32, 7 * 32 - 16, image, 1) # 人は優先順位をマップの間にしておく
159+
160+ # エスケープキーで終了
161+ break if Input.keyPush?(K_ESCAPE)
162+ Window.drawFont(32,32,Window.fps.to_s + " fps", font, :z=>3)
163+ Window.drawFont(32,64,Window.getLoad.to_i.to_s + " %", font, :z=>3)
164+end
--- tags/1.0.8/sample/8_puzzle.rb (nonexistent)
+++ tags/1.0.8/sample/8_puzzle.rb (revision 189)
@@ -0,0 +1,55 @@
1+#!ruby -Ks
2+# DXRuby サンプル 8パズル
3+# 左クリックでピースを移動、右クリックでシャッフル
4+# 使用可能な画像はjpg、png、bmpなど通常のフォーマットです。
5+require 'dxruby'
6+
7+filename = Window.openFilename([["スベテノファイル(*.*)", "*.*"]], "パズル用の画像を選択")
8+image = Image.loadToArray(filename, 3, 3)
9+
10+# 窓設定
11+width = image[0].width
12+height = image[0].height
13+if width < 32 then
14+ Window.scale = 48.0 / width
15+end
16+Window.width = image[0].width * 3
17+Window.height = image[0].height * 3
18+Window.caption = "8パズル"
19+
20+# パズルの情報
21+piece = [0,1,2,3,4,5,6,7,8]
22+
23+# クリック時の処理。空いてる位置のとなりだったら入れ替える。
24+def click(x, y, piece)
25+ i = piece.index(8) # 空いてるピース検索
26+ if (((i % 3) - x).abs == 1 and (i / 3) == y) or (((i / 3) - y).abs == 1 and (i % 3) == x) then
27+ piece[x + y * 3], piece[i] = piece[i], piece[x + y * 3] # 入れ替え a,b = b,aでswapできる
28+ end
29+end
30+
31+# メインループ
32+Window.loop do
33+
34+ # 右クリックでシャッフル(ランダムで1000回ほどクリックしてもらってます^^;)
35+ if Input.mousePush?(M_RBUTTON) then
36+ 1000.times do
37+ click(rand(3), rand(3), piece)
38+ end
39+ end
40+
41+ # 左クリック処理
42+ if Input.mousePush?(M_LBUTTON) then
43+ click((Input.mousePosX / Window.scale / image[0].width).to_i, (Input.mousePosY / Window.scale / image[0].height).to_i, piece)
44+ end
45+
46+ # 完了判定と描画
47+ for i in 0..8
48+ if piece[i] != 8 or piece == [0,1,2,3,4,5,6,7,8] then
49+ Window.draw(i % 3 * image[0].width , i / 3 * image[0].height, image[piece[i]])
50+ end
51+ end
52+
53+ # エスケープキーで終了
54+ break if Input.keyPush?(K_ESCAPE)
55+end
--- tags/1.0.8/sample/flight.rb (nonexistent)
+++ tags/1.0.8/sample/flight.rb (revision 189)
@@ -0,0 +1,75 @@
1+#ruby -Ks
2+# DXRuby サンプル 飛んでるようなもの
3+require 'dxruby'
4+
5+image = Image.new(32,32)
6+image.boxFill(13, 16, 18, 26, [255, 200, 50, 50]) # 木
7+image.line(13, 16, 13, 26, [255, 0, 0, 0])
8+image.line(18, 16, 18, 26, [255, 0, 0, 0])
9+image.circleFill(16, 8, 8, [255, 0, 255, 0])
10+image.circle(16, 8, 8, [255, 0, 0, 0])
11+
12+class Bg
13+ @@ground = Image.new(1000,600, [255, 0, 0, 255])
14+ attr_accessor :y, :angle
15+
16+ def initialize
17+ @y = 290
18+ @angle = 0
19+ end
20+
21+ def update
22+ @angle -= Input.x*1.8
23+ if @angle < -75 then
24+ @angle = -75
25+ end
26+ if @angle > 75 then
27+ @angle = 75
28+ end
29+ @y -= Input.y*5
30+ @y = 400 if @y > 400
31+ @y = 100 if @y < 100
32+ Window.drawRot(-180, @y, @@ground, angle, 500, 240-@y, 0)
33+ end
34+end
35+
36+bg = Bg.new
37+Window.bgcolor = [200,250,255]
38+x = 320
39+y = 240
40+z = []
41+Obj = Struct.new(:x, :y, :z)
42+font = Font.new(32)
43+angle = 0
44+objx = 0
45+
46+Window.loop do
47+
48+ z.push(Obj.new(rand(2000) - 680, 500, 5.0))
49+ z.push(Obj.new(rand(2000) - 680, 500, 5.0))
50+
51+ bg.update
52+
53+ rad = Math::PI/180.0*bg.angle
54+ sina = Math.sin(rad)
55+ cosa = Math.cos(rad)
56+ bgy1 = (530 - bg.y) / 290.0
57+ bgy2 = bg.y - 240
58+ z.delete_if do |obj|
59+ drawx = ((obj.x - 320) / obj.z * cosa - (((obj.y - 240) / obj.z - 50) * bgy1 + bgy2) * sina) + 320
60+ drawy = ((obj.x - 320) / obj.z * sina + (((obj.y - 240) / obj.z - 50) * bgy1 + bgy2) * cosa) + 240
61+
62+ Window.drawEx(drawx - image.width / 2, drawy - image.height / 2, image, :scalex=>5.0 / obj.z, :scaley=>5.0 / obj.z, :z=>5 - obj.z, :angle=>bg.angle)
63+
64+ obj.x += bg.angle / 3.0
65+ obj.z -= 0.15
66+ if obj.z < 0.5 then
67+ true
68+ else
69+ false
70+ end
71+ end
72+
73+ break if Input.keyPush?(K_ESCAPE)
74+ Window.drawFont(0, 448, Window.getLoad.to_i.to_s + " %", font)
75+end
--- tags/1.0.8/sample/meiro.rb (nonexistent)
+++ tags/1.0.8/sample/meiro.rb (revision 189)
@@ -0,0 +1,106 @@
1+#!ruby -Ks
2+# DXRuby サンプル 3D迷路
3+require 'dxruby'
4+
5+# マップ
6+map = [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
7+ [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
8+ [1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1],
9+ [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1],
10+ [1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 0, 1, 0, 1],
11+ [1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1],
12+ [1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1],
13+ [1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1],
14+ [1, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1],
15+ [1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1],
16+ [1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1],
17+ [1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1],
18+ [1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1],
19+ [1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 0, 1],
20+ [1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1],
21+ [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
22+ ]
23+
24+x = 1
25+y = 1
26+angle = 1
27+
28+# 向きによる増分
29+angledata = [[0, -1], [1, 0], [0, 1], [-1, 0]]
30+
31+block = Image.new(16, 16, [255, 255, 255, 255])
32+image = Array.new(4) {Array.new(3) {Image.new(256, 256)}}
33+jibun = Image.new(16, 16, [255, 255, 0, 0])
34+
35+# 3D画像生成
36+# 計算でかなり強引に作っている
37+# それぞれの距離ごとに綺麗な画像を作って読み込んだほうがよいと思います
38+for i in 0..3
39+ for j in 0..2
40+ if i != 3
41+ x1 = ((32 + 192 * (j - 1)) - 128) / (3 - i) + 128
42+ y1 = (32 - 128) / (3 - i) + 128
43+ x2 = ((224 + 192 * (j - 1)) - 128) / (3 - i) + 128
44+ y2 = (224 - 128) / (3 - i) + 128
45+ image[i][j].boxFill(x1, y1, x2, y2, [255, 255/(3 - i), 255/(3 - i), 255/(3 - i)])
46+ else
47+ x1 = 256
48+ y1 = 0
49+ x2 = 0
50+ y2 = 256
51+ end
52+ if j == 0
53+ x3 = (((224 + 192 * (j - 1)) - 128) / (4 - i) + 128)
54+ y3 = (32 - 128) / (4 - i) + 128
55+ y4 = (224 - 128) / (4 - i) + 128
56+ for k in 0..(x3-x2)
57+ image[i][j].line(k+x2, y1 + (y3 - y1) / (x3-x2) * k, k+x2, y2 + (y4 - y2) / (x3-x2) * k, [255,128/(4 - i),128/(4 - i),255/(4 - i)])
58+ end
59+ elsif j == 2
60+ x3 = (((32 + 192 * (j - 1)) - 128) / (4 - i) + 128)
61+ y3 = (32 - 128) / (4 - i) + 128
62+ y4 = (224 - 128) / (4 - i) + 128
63+ for k in 0..(x1 - x3)
64+ image[i][j].line(x1 - k, y1 + (y3 - y1) / (x1-x3) * k, x1 - k, y2 + (y4 - y2) / (x1-x3) * k, [255,128/(4 - i),128/(4 - i),255/(4 - i)])
65+ end
66+ end
67+ end
68+end
69+
70+Window.loop do
71+ # 左右おした
72+ angle += Input.x if Input.padPush?(P_LEFT) or Input.padPush?(P_RIGHT)
73+ angle = 0 if angle > 3
74+ angle = 3 if angle < 0
75+
76+ # 上おした
77+ if Input.padPush?(P_UP) or Input.padPush?(P_DOWN)
78+ newx = x + angledata[angle - Input.y - 1][0]
79+ newy = y + angledata[angle - Input.y - 1][1]
80+ x, y = newx, newy if map[newy][newx] == 0
81+ end
82+
83+ # 3D画面描画
84+ for i in 0..3
85+ for j in 0..2
86+ jx = x + angledata[angle - 3][0] * (j - 1) + angledata[angle - 2][0] * (i - 3)
87+ iy = y + angledata[angle - 2][1] * (i - 3) + angledata[angle - 3][1] * (j - 1)
88+ next if iy < 0 or iy > 15 or jx < 0 or jx > 15
89+ if map[iy][jx] == 1
90+ Window.draw(0, 0, image[i][j], i - (j - 1).abs)
91+ end
92+ end
93+ end
94+
95+ # 右のマップ
96+ for i in 0..15
97+ for j in 0..15
98+ Window.draw(j * 16 + 288, i * 16, block) if map[i][j] == 1
99+ end
100+ end
101+
102+ # 自分(赤の四角だけど)描画
103+ Window.draw(x * 16 + 288, y * 16, jibun)
104+
105+ break if Input.keyPush?(K_ESCAPE)
106+end
--- tags/1.0.8/sample/sample.rb (nonexistent)
+++ tags/1.0.8/sample/sample.rb (revision 189)
@@ -0,0 +1,110 @@
1+#!ruby -Ks
2+# DXRuby サンプルプログラム
3+
4+# ライブラリの取り込み
5+require 'dxruby'
6+
7+# 窓位置。省略するとOSデフォルト
8+#Window.x = 0
9+#Window.y = 0
10+
11+# スクリーンイメージサイズ。省略するとこのサイズ
12+#Window.width = 640
13+#Window.height = 480
14+
15+# ウィンドウのキャプション。省略すると「DXRuby Application」
16+Window.caption = "サンプル"
17+
18+# スクリーンイメージサイズに対するウィンドウの倍率。2にすると縦横2倍で表示される。
19+# 勝手にアンチエイリアシングされる。
20+# 省略すると1。
21+#Window.scale = 1
22+
23+# ウィンドウモードにするかどうか。trueでウィンドウ。falseでフルスクリーン。
24+# 省略するとtrue。
25+#Window.windowed = true
26+
27+# 秒間更新頻度を設定する。
28+# 省略すると60。
29+#Window.fps = 60
30+
31+# 重くてfpsが守れない場合に描画をスキップする指定。
32+# 省略するとfalse
33+#Window.frameskip = false
34+
35+# 画像ファイルを読み込んでイメージオブジェクトを作成する。
36+# jpgとかbmpとかpngとかが使える。
37+image = Image.load("data.png")
38+
39+# キャラの状態を設定する
40+x = 100
41+y = 100
42+rot = 0
43+scale = 1
44+alpha = 255
45+
46+# ウィンドウが閉じられたら自動的に終了するループ
47+Window.loop do
48+
49+ # キャラを動かしたりする
50+ # xとyメソッドはパッド入力をx座標とy座標の増分(-1、0、1)で返す。
51+ # 引数はパッド番号。0はキーボードと兼用。省略は0。
52+ x = x + Input.x
53+ y = y + Input.y
54+
55+ # Zを押したらクルクル回る
56+ # 第2引数は入力するボタン。
57+ # Zにはパッドのボタン0が標準で割り当てられている。
58+ if Input.keyDown?(K_Z) == true then
59+ rot = rot + 5
60+ if rot > 359 then
61+ rot = rot - 360
62+ end
63+ end
64+
65+ # Xを押したらサイズ変更
66+ # Xにはパッドのボタン1が標準で割り当てられている。
67+ if Input.keyDown?(K_X) == true then
68+ scale = scale + 0.05
69+ if scale > 2 then
70+ scale= 0.2
71+ end
72+ end
73+
74+ # Cを押したら半透明
75+ # Cにはパッドのボタン2が標準で割り当てられている。
76+ if Input.keyDown?(K_C) == true then
77+ alpha = alpha - 2
78+ if alpha < 0 then
79+ alpha= 255
80+ end
81+ end
82+
83+ # 普通に描画する
84+ Window.draw(x + 50, y + 100, image)
85+
86+ # なんかしてキャラを描画する
87+ Window.drawRot(x, y, image, rot) # 回転(0が基準で右回り。360で一周)
88+ Window.drawScale(x + 50, y, image, scale, scale) # 拡大縮小(1が基準で倍率を表す)
89+ Window.drawAlpha(x + 100, y, image, alpha) # 半透明(0が透明で255が通常描画)
90+
91+ # 全部同時に適用するメソッドはこちら
92+ Window.drawEx(x + 50, y + 50, image, :angle => rot, :scalex => scale, :scaley => scale, :alpha => alpha)
93+
94+ # エスケープキーで終了
95+ if Input.keyDown?(K_ESCAPE) == true then
96+ break
97+ end
98+
99+ # スクリーンショット機能
100+ if Input.keyPush?(K_F12) == true then
101+ if ! File.exist?("screenshot") then
102+ Dir.mkdir("screenshot")
103+ end
104+ Window.getScreenShot("screenshot/screenshot" + Time.now.strftime("%Y%m%d_%H%M%S") + ".jpg")
105+ end
106+end
107+
108+
109+
110+
--- tags/1.0.8/sample/block_destroy.rb (nonexistent)
+++ tags/1.0.8/sample/block_destroy.rb (revision 189)
@@ -0,0 +1,161 @@
1+#!ruby -Ks
2+# DXRuby サンプル ブロック崩しモドキ
3+# 左クリックでボールが飛びます。後はマウスで打ち返して。
4+require 'dxruby'
5+
6+Window.caption = "ブロック崩しモドキ"
7+
8+# ブロックの構造体
9+Block = Struct.new(:x, :y, :image)
10+
11+# 音データ作成
12+v = 80 # ボリューム
13+s1 = SoundEffect.new(50) do # 50mSecの効果音。ブロック内は1msの変化
14+ v = v - 4 if v > 0 # ボリュームダウン
15+ [220, v] # ブロックの戻りの配列が周波数とボリューム
16+end
17+v = 80
18+s2 = SoundEffect.new(50) do
19+ v = v - 4 if v > 0
20+ [440, v]
21+end
22+v = 80
23+s3 = SoundEffect.new(50) do
24+ v = v - 4 if v > 0
25+ [880, v]
26+end
27+
28+# 画像データ作成。
29+# パッドの画像
30+padimage = Image.new(100, 20)
31+padimage.boxFill(0, 0, 99, 19, [255, 255, 255])
32+
33+# ブロックの画像。ちょっと綺麗にしようと思ったらずいぶん増えちゃった
34+blockimage = [Image.new(60, 20, [255, 0, 0]),
35+ Image.new(60, 20, [255, 255, 0]),
36+ Image.new(60, 20, [0, 255, 0])]
37+blockimage[0].line(0, 0, 59, 0, [255, 150, 150])
38+blockimage[0].line(0, 0, 0, 19, [255, 150, 150])
39+blockimage[0].line(0, 19, 59, 19, [120, 0, 0])
40+blockimage[0].line(59, 0, 59, 19, [120, 0, 0])
41+blockimage[1].line(0, 0, 59, 0, [255, 255, 150])
42+blockimage[1].line(0, 0, 0, 19, [255, 255, 150])
43+blockimage[1].line(0, 19, 59, 19, [150, 150, 0])
44+blockimage[1].line(59, 0, 59, 19, [150, 150, 0])
45+blockimage[2].line(0, 0, 59, 0, [150, 255, 120])
46+blockimage[2].line(0, 0, 0, 19, [150, 255, 120])
47+blockimage[2].line(0, 19, 59, 19, [0, 150, 0])
48+blockimage[2].line(59, 0, 59, 19, [0, 150, 0])
49+
50+# 弾の画像
51+ballimage = Image.new(24, 24)
52+ballimage.circleFill(12, 12, 11, [255, 255, 255])
53+
54+# 玉の情報
55+tx = 0
56+ty = 416
57+dtx = 0
58+dty = 0
59+
60+# 0は初期化、1は玉が飛んでない。2は飛んでる。
61+state = 0
62+
63+block = []
64+
65+# メインループ
66+Window.loop do
67+ x = Input.mousePosX - 50
68+ x = 0 if x < 0
69+ x = 540 if x > 540
70+ y = Input.mousePosY - 10
71+ y = 220 if y < 220
72+ y = 460 if y > 460
73+
74+ case state
75+ when 0
76+ # ブロック配列初期化
77+ block.clear
78+ # ブロック生成
79+ for i in 0..9
80+ for j in 0..5
81+ block.push(Block.new(i * 64 + 2, j * 24 + 50, blockimage[j / 2]))
82+ end
83+ end
84+ state = 1
85+
86+ when 1
87+ # 飛んでないときはパッドにくっついている
88+ if Input.mousePush?(M_LBUTTON) then # マウスの左クリックで飛ばす
89+ state = 2
90+ dtx = rand(2) * 16 - 8
91+ dty = -8
92+ else # くっついてるとき
93+ tx = x + 38
94+ ty = y - 24
95+ end
96+
97+ when 2
98+ # ゲームメイン処理
99+ # ブロックとの判定
100+ block.delete_if do |b|
101+ flag = false
102+ # 横にブロックがあったら横にはねかえる
103+ if tx + dtx + 24 > b.x and tx + dtx < b.x + 60 and
104+ ty + 24 > b.y and ty < b.y + 20 then
105+ dtx = -dtx
106+ s3.play
107+ # ナナメにあった場合は縦にもはねかえる
108+ if tx + 24 > b.x and tx < b.x + 60 and
109+ ty + dty + 24 > b.y and ty + dty < b.y + 20 then
110+ dty = -dty
111+ end
112+ flag = true
113+
114+ # 縦にブロックがあったら縦にはねかえる
115+ elsif tx + 24 > b.x and tx < b.x + 60 and
116+ ty + dty + 24 > b.y and ty + dty < b.y + 20 then
117+ dty = -dty
118+ s3.play
119+ flag = true
120+ end
121+ flag
122+ end
123+ # 移動
124+ tx = tx + dtx
125+ ty = ty + dty
126+ # パッドとの判定
127+ if tx + 24 > x and tx < x + 100 and ty + 24 > y and ty < y + 20 and dty > 0 then
128+ dty = -8
129+ if tx < x + 38 - dtx * 2 then
130+ dtx = -8
131+ else
132+ dtx = 8
133+ end
134+ s1.play
135+ end
136+ # 画面外の判定
137+ if tx > 607 then
138+ dtx = -8
139+ s2.play
140+ end
141+ if tx < 8 then
142+ dtx = 8
143+ s2.play
144+ end
145+ if ty <= 0 then
146+ dty = 8
147+ s2.play
148+ end
149+ state = 1 if ty > 479 # ボールが落ちた
150+ state = 0 if block.size == 0 # ブロックが全部消えた
151+ end
152+
153+ # 画像描画
154+ Window.draw(x, y, padimage)
155+ Window.draw(tx, ty, ballimage)
156+ block.each do |b|
157+ Window.draw(b.x, b.y, b.image)
158+ end
159+
160+ break if Input.keyDown?(K_ESCAPE)
161+end
--- tags/1.0.8/sample/mapedit.rb (nonexistent)
+++ tags/1.0.8/sample/mapedit.rb (revision 189)
@@ -0,0 +1,270 @@
1+#!ruby -Ks
2+# DXRuby 簡易マップエディタ
3+require 'dxruby'
4+
5+# マップデータ
6+map=[
7+ [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
8+ [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
9+ [1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
10+ [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
11+ [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 3, 3, 1, 1, 1, 1, 1, 1, 1],
12+ [0, 0, 0, 0, 1, 4, 4, 4, 4, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 1, 1, 3, 3, 3, 3, 3, 1, 1, 1, 1, 1],
13+ [2, 2, 2, 2, 1, 1, 4, 4, 4, 4, 0, 0, 0, 0, 0, 4, 4, 1, 1, 1, 1, 1, 3, 3, 3, 3, 1, 3, 1, 1, 1, 1],
14+ [2, 2, 2, 1, 2, 1, 1, 4, 4, 4, 4, 0, 0, 0, 0, 4, 4, 4, 1, 1, 1, 1, 3, 3, 3, 3, 1, 3, 1, 3, 1, 1],
15+ [2, 2, 2, 1, 1, 1, 1, 1, 4, 4, 4, 0, 0, 0, 0, 0, 4, 4, 1, 1, 1, 1, 3, 1, 3, 3, 3, 3, 3, 3, 1, 1],
16+ [2, 2, 2, 2, 2, 2, 1, 1, 4, 4, 4, 0, 0, 0, 0, 0, 4, 4, 1, 1, 1, 1, 1, 3, 3, 3, 3, 3, 3, 3, 1, 1],
17+ [1, 2, 2, 2, 2, 2, 2, 1, 4, 4, 4, 0, 0, 0, 0, 0, 4, 4, 1, 1, 1, 1, 1, 1, 3, 3, 3, 3, 3, 3, 3, 1],
18+ [1, 1, 1, 2, 2, 1, 2, 1, 4, 4, 4, 0, 0, 0, 0, 0, 4, 4, 1, 1, 1, 1, 1, 1, 3, 3, 3, 3, 3, 3, 3, 3],
19+ [1, 1, 2, 1, 2, 2, 1, 4, 4, 4, 0, 0, 0, 0, 0, 0, 4, 4, 1, 1, 1, 1, 1, 1, 1, 3, 3, 3, 3, 3, 3, 3],
20+ [1, 1, 1, 2, 2, 1, 4, 4, 4, 0, 0, 0, 0, 0, 0, 4, 4, 4, 4, 1, 1, 1, 1, 1, 1, 1, 3, 3, 3, 3, 3, 3],
21+ [1, 1, 1, 2, 1, 1, 4, 0, 0, 0, 0, 0, 0, 0, 0, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 3, 3, 3],
22+ [1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3],
23+ [1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 4, 4, 4, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1],
24+ [1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 4, 4, 1, 4, 1, 4, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
25+ [1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 4, 4, 4, 4, 4, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
26+ [1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 4, 4, 4, 4, 4, 2, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
27+ [1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 4, 4, 4, 4, 4, 4, 1, 2, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1],
28+ [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 4, 4, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
29+ [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 4, 4, 4, 4, 1, 4, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1],
30+ [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 4, 4, 4, 4, 4, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1],
31+ [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 4, 4, 4, 4, 4, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 0],
32+ [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 4, 4, 4, 4, 4, 4, 4, 1, 1, 1, 1, 1, 1, 1, 0, 0],
33+ [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 1, 1, 1, 0, 0, 0],
34+ [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 4, 4, 4, 4, 4, 4, 4, 4, 0, 0, 0, 0],
35+ [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 4, 4, 4, 0, 0, 0, 0, 0, 0],
36+ [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
37+ [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
38+ [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1]
39+]
40+takasa=[
41+ [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 5, 5, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],
42+ [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],
43+ [3, 3, 3, 3, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],
44+ [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],
45+ [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 3, 3, 3, 3, 3, 3, 3],
46+ [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 5, 5, 5, 3, 3, 3, 3, 3],
47+ [4, 4, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 5, 6, 6, 6, 3, 3, 3, 3],
48+ [4, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 5, 7, 7, 8, 7, 3, 3, 3],
49+ [4, 3, 5, 5, 4, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 5, 6, 7, 8, 8, 6, 3, 3],
50+ [3, 6, 5, 5, 4, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 4, 5, 6, 6, 8, 9, 6, 5, 3],
51+ [4, 5, 3, 4, 4, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 5, 6, 6, 8, 7, 6, 6, 3],
52+ [3, 3, 4, 4, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 4, 5, 5, 6, 6, 6, 6, 6, 5],
53+ [3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 5, 5, 5, 6, 6, 6, 5],
54+ [3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 5, 5, 5, 5, 5, 5],
55+ [3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 5, 5, 5, 5],
56+ [3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 5],
57+ [3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 3, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4],
58+ [3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 4, 3, 4, 4, 3, 3, 3, 3, 3, 3, 3, 4],
59+ [3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 4],
60+ [3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 5, 5, 4, 4, 4, 3, 3, 3, 3, 3, 3],
61+ [3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 5, 4, 3, 3, 3, 3, 3, 3, 3, 3],
62+ [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3],
63+ [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3],
64+ [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 4, 3, 3, 3, 3, 3, 3],
65+ [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2],
66+ [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2],
67+ [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 2, 2, 2, 2, 2],
68+ [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 3, 2, 2, 2, 2, 2, 2, 2],
69+ [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],
70+ [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],
71+ [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],
72+ [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3]
73+]
74+# 絵のデータを作る
75+mapimage = Array.new(5) {Image.new(32, 32)}
76+for i in 0..7 do # ひし形に地面を描く
77+ mapimage[0].line(15 - i * 2, i + 16, 16 + i * 2, i + 16, [100, 100, 200]) # 水
78+ mapimage[0].line(15 - i * 2, 31 - i, 16 + i * 2, 31 - i, [100, 100, 200])
79+ mapimage[0][15 - i * 2, i + 16] = [0, 0, 0]
80+ mapimage[0][16 + i * 2, i + 16] = [0, 0, 0]
81+ for j in 1..3 do
82+ mapimage[j].line(15 - i * 2, i + 16, 16 + i * 2, i + 16, [50, 200, 50]) # 平地
83+ mapimage[j].line(15 - i * 2, 31 - i, 16 + i * 2, 31 - i, [50, 200, 50])
84+ mapimage[j][15 - i * 2, i + 16] = [0, 0, 0]
85+ mapimage[j][16 + i * 2, i + 16] = [0, 0, 0]
86+ end
87+ mapimage[4].line(15 - i * 2, i + 16, 16 + i * 2, i + 16, [200, 200, 150]) # 砂地
88+ mapimage[4].line(15 - i * 2, 31 - i, 16 + i * 2, 31 - i, [200, 200, 150])
89+ mapimage[4][15 - i * 2, i + 16] = [0, 0, 0]
90+ mapimage[4][16 + i * 2, i + 16] = [0, 0, 0]
91+end
92+mapimage[2].boxFill(13, 16, 18, 26, [200, 50, 50]) # 木
93+mapimage[2].line(13, 16, 13, 26, [0, 0, 0])
94+mapimage[2].line(18, 16, 18, 26, [0, 0, 0])
95+mapimage[2].circleFill(16, 8, 8, [0, 255, 0])
96+mapimage[2].circle(16, 8, 8, [0, 0, 0])
97+for i in 1..24 do # 山
98+ mapimage[3].line(15 - i*2/4, i, 16 + i*2/4, i, [200, 100, 100])
99+ mapimage[3][15 - i*2/4, i] = [0, 0, 0]
100+ mapimage[3][16 + i*2/4, i] = [0, 0, 0]
101+end
102+# 地面のサイド画像を作る
103+sideimage = Array.new(5) {Image.new(32, 16)}
104+for i in 0..15 do
105+ sideimage[0].line(i, i / 2, i, i / 2 + 8, [60, 60, 180]) # 水
106+ sideimage[0].line(31 - i, i / 2, 31 - i, i / 2 + 8, [130, 130, 200])
107+ for j in 1..3 do
108+ sideimage[j].line(i, i / 2, i, i / 2 + 8, [40, 150, 40]) # 水以外
109+ sideimage[j].line(31 - i, i / 2, 31 - i, i / 2 + 8, [100, 220, 100])
110+ end
111+ sideimage[4].line(i, i / 2, i, i / 2 + 8, [150, 150, 120]) # 砂地
112+ sideimage[4].line(31 - i, i / 2, 31 - i, i / 2 + 8, [220, 220, 170])
113+end
114+wakuimage = Image.new(36, 36, [255, 255, 255]). # 選択枠
115+ boxFill(2, 2, 33, 33, [0, 0, 0])
116+blackimage = Image.new(128, 480, [0, 0, 0]) # 右側背景
117+
118+select = 0
119+
120+# クリック位置判定関数
121+def check(x, y, map, takasa)
122+ # 手前から検索するために逆順
123+ 31.downto(0) do |i|
124+ 31.downto(0) do |j|
125+ # ひし形の中にあるかを調べる
126+ if ((j * 16 - i * 16 + 176 - x)/2).abs + (j * 8 + i * 8 - takasa[i][j]*8 + 24 - y).abs < 9 then
127+ return [i, j]
128+ end
129+ end
130+ end
131+ return nil
132+end
133+
134+# メインループ
135+Window.loop do
136+
137+ # マウスクリック
138+ if Input.mouseDown?(M_LBUTTON) or Input.mouseDown?(M_RBUTTON) then
139+ x, y = Input.mousePosX, Input.mousePosY
140+ if x >= 512 then # 右のほうなら
141+ for i in 0..mapimage.size-1
142+ if x >= 560 and x < 592 and y >= i * 64 + 64 and y < i * 64 + 96 then
143+ select = i
144+ break
145+ end