rubysdl-2.2.0/0000755000175000017500000000000012376257217013047 5ustar uwabamiuwabamirubysdl-2.2.0/rubysdl_ttf.c0000644000175000017500000002300712376257217015556 0ustar uwabamiuwabami/* Ruby/SDL Ruby extension library for SDL Copyright (C) 2001-2007 Ohbayashi Ippei This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifdef HAVE_SDL_TTF #include "rubysdl.h" #include typedef struct { TTF_Font* font; } TTFont; typedef SDL_Surface* (*RenderFunc)(TTF_Font *,const char *,SDL_Color,SDL_Color); static int ttf_init = 0; static VALUE cTTFFont = Qnil; static void Font_free(TTFont *f) { if(!rubysdl_is_quit() && f->font) TTF_CloseFont(f->font); free(f); } DEFINE_GET_STRUCT(TTFont, Get_TTFont, cTTFFont, "SDL::TT::Font"); TTF_Font* Get_TTF_Font(VALUE obj) { TTFont* f = Get_TTFont(obj); if (f->font == NULL) rb_raise(eSDLError, "TTF is alreadly closed"); return f->font; } static VALUE TTF_s_alloc(VALUE klass) { TTFont* f = ALLOC(TTFont); f->font = NULL; return Data_Wrap_Struct(klass, 0, Font_free, f); } static VALUE TTF_create(TTF_Font* font) { VALUE newobj = TTF_s_alloc(cTTFFont); Get_TTFont(newobj)->font = font; return newobj; } static VALUE TTF_s_init(VALUE klass) { if(TTF_Init() == -1) rb_raise(eSDLError,"Couldn't initialize TTF engine: %s",TTF_GetError()); ttf_init = 1; return Qnil; } static VALUE TTF_s_init_p(VALUE class) { return INT2BOOL(TTF_WasInit()); } static VALUE Font_s_open(int argc, VALUE *argv, VALUE class) { TTF_Font *font; VALUE filename, size, index; rb_scan_args( argc, argv, "21", &filename, &size, &index ); ExportFilenameStringValue(filename); if(NIL_P(index)) font = TTF_OpenFont(RSTRING_PTR(filename), NUM2INT(size)); else font = TTF_OpenFontIndex(RSTRING_PTR(filename), NUM2INT(size), NUM2INT(index)); if(font == NULL) rb_raise(eSDLError,"Couldn't open font %s: %s", RSTRING_PTR(filename), TTF_GetError()); return TTF_create(font); } static VALUE Font_style(VALUE self) { return INT2FIX(TTF_GetFontStyle(Get_TTF_Font(self))); } static VALUE Font_set_style(VALUE self, VALUE style) { TTF_SetFontStyle(Get_TTF_Font(self), NUM2UINT(style)); return Qnil; } static VALUE Font_faces(VALUE self) { return UINT2NUM(TTF_FontFaces(Get_TTF_Font(self))); } static VALUE Font_fixedWidth_p(VALUE self) { return INT2BOOL(TTF_FontFaceIsFixedWidth(Get_TTF_Font(self))); } static VALUE string_or_nil(char* str) { if (str) return rb_str_new2(str); else return Qnil; } static VALUE Font_familyName(VALUE self) { return string_or_nil(TTF_FontFaceFamilyName(Get_TTF_Font(self))); } static VALUE Font_styleName(VALUE self) { return string_or_nil(TTF_FontFaceStyleName(Get_TTF_Font(self))); } static VALUE Font_textSize(VALUE self, VALUE text) { int w,h; StringValue(text); #ifdef ENABLE_M17N text = rb_str_export_to_enc(text, utf8_enc); #endif TTF_SizeUTF8(Get_TTF_Font(self), StringValueCStr(text), &w, &h); return rb_ary_new3(2, INT2FIX(w), INT2FIX(h)); } static VALUE Font_height(VALUE self) { return INT2FIX(TTF_FontHeight(Get_TTF_Font(self))); } static VALUE Font_ascent(VALUE self) { return INT2FIX(TTF_FontAscent(Get_TTF_Font(self))); } static VALUE Font_descent(VALUE self) { return INT2FIX(TTF_FontDescent(Get_TTF_Font(self))); } static VALUE Font_lineSkip(VALUE self) { return INT2FIX(TTF_FontLineSkip(Get_TTF_Font(self))); } static SDL_Color rgb_to_SDL_Color(VALUE r, VALUE g, VALUE b) { SDL_Color color; color.r = NUM2UINT(r); color.g = NUM2UINT(g); color.b = NUM2UINT(b); color.unused = 0; return color; } static VALUE render(VALUE self, VALUE text, VALUE fgr,VALUE fgg,VALUE fgb, VALUE bgr,VALUE bgg,VALUE bgb, int convert_enc, RenderFunc renderer) { SDL_Surface *surface; StringValue(text); #ifdef ENABLE_M17N if (convert_enc) text = rb_str_export_to_enc(text, utf8_enc); #endif surface = renderer(Get_TTF_Font(self), StringValueCStr(text), rgb_to_SDL_Color(fgr, fgg, fgb), rgb_to_SDL_Color(bgr, bgg, bgb)); if(surface == NULL) return Qnil; return Surface_create(surface); } static SDL_Surface* wrap_RenderUTF8_Solid(TTF_Font *font, const char *text, SDL_Color fg, SDL_Color bg) { return TTF_RenderUTF8_Solid(font,text,fg); } static SDL_Surface* wrap_RenderUTF8_Blended(TTF_Font *font, const char *text, SDL_Color fg, SDL_Color bg) { return TTF_RenderUTF8_Blended(font,text,fg); } /* 1 is ruby's zero */ static VALUE Font_renderSolidUTF8(VALUE self, VALUE text, VALUE r, VALUE g, VALUE b) { return render(self, text, r, g, b, 1, 1, 1, 0, wrap_RenderUTF8_Solid); } static VALUE Font_renderBlendedUTF8(VALUE self, VALUE text, VALUE r, VALUE g, VALUE b) { return render(self, text, r, g, b, 1, 1, 1, 0, wrap_RenderUTF8_Blended); } static VALUE Font_renderShadedUTF8(VALUE self, VALUE text, VALUE fgr,VALUE fgg,VALUE fgb, VALUE bgr,VALUE bgg,VALUE bgb) { return render(self, text, fgr, fgg, fgb, bgr, bgg, bgb, 0, TTF_RenderUTF8_Shaded); } static VALUE Font_renderSolid(VALUE self, VALUE text, VALUE r, VALUE g, VALUE b) { return render(self, text, r, g, b, 1, 1, 1, 1, wrap_RenderUTF8_Solid); } static VALUE Font_renderBlended(VALUE self, VALUE text, VALUE r, VALUE g, VALUE b) { return render(self, text, r, g, b, 1, 1, 1, 1, wrap_RenderUTF8_Blended); } static VALUE Font_renderShaded(VALUE self, VALUE text, VALUE fgr,VALUE fgg,VALUE fgb, VALUE bgr,VALUE bgg,VALUE bgb) { return render(self, text, fgr, fgg, fgb, bgr, bgg, bgb, 1, TTF_RenderUTF8_Shaded); } static VALUE Font_close(VALUE self) { TTFont* f = Get_TTFont(self); if(!rubysdl_is_quit() && f->font) TTF_CloseFont(f->font); f->font = NULL; return Qnil; } static VALUE Font_closed(VALUE self) { return INT2BOOL(Get_TTFont(self)->font == NULL); } static VALUE Font_hinting(VALUE self) { return INT2FIX(TTF_GetFontHinting(Get_TTF_Font(self))); } static VALUE Font_set_hinting(VALUE self, VALUE hinting) { TTF_SetFontHinting(Get_TTF_Font(self), NUM2INT(hinting)); return Qnil; } void rubysdl_init_TTF(VALUE mSDL) { cTTFFont = rb_define_class_under(mSDL, "TTF", rb_cObject); rb_undef_alloc_func(cTTFFont); rb_define_singleton_method(cTTFFont,"init",TTF_s_init,0); rb_define_singleton_method(cTTFFont,"init?", TTF_s_init_p,0); rb_define_singleton_method(cTTFFont,"open",Font_s_open,-1); rb_define_method(cTTFFont,"style",Font_style,0); rb_define_method(cTTFFont,"style=",Font_set_style,1); rb_define_method(cTTFFont,"textSize",Font_textSize,1); rb_define_method(cTTFFont,"faces",Font_faces,0); rb_define_method(cTTFFont,"fixedWidth?",Font_fixedWidth_p,0); rb_define_method(cTTFFont,"familyName",Font_familyName,0); rb_define_method(cTTFFont,"styleName",Font_styleName,0); rb_define_method(cTTFFont,"hinting",Font_hinting,0); rb_define_method(cTTFFont,"hinting=",Font_set_hinting,1); rb_define_method(cTTFFont,"height",Font_height,0); rb_define_method(cTTFFont,"ascent",Font_ascent,0); rb_define_method(cTTFFont,"descent",Font_descent,0); rb_define_method(cTTFFont,"lineSkip",Font_lineSkip,0); rb_define_method(cTTFFont,"renderSolidUTF8",Font_renderSolidUTF8,4); rb_define_method(cTTFFont,"renderBlendedUTF8",Font_renderBlendedUTF8,4); rb_define_method(cTTFFont,"renderShadedUTF8",Font_renderShadedUTF8,7); rb_define_method(cTTFFont,"renderSolid",Font_renderSolid,4); rb_define_method(cTTFFont,"renderBlended",Font_renderBlended,4); rb_define_method(cTTFFont,"renderShaded",Font_renderShaded,7); rb_define_method(cTTFFont,"close", Font_close, 0); rb_define_method(cTTFFont,"closed?", Font_closed, 0); rb_define_const(cTTFFont,"STYLE_NORMAL",UINT2NUM(TTF_STYLE_NORMAL)); rb_define_const(cTTFFont,"STYLE_BOLD",UINT2NUM(TTF_STYLE_BOLD)); rb_define_const(cTTFFont,"STYLE_ITALIC",UINT2NUM(TTF_STYLE_ITALIC)); rb_define_const(cTTFFont,"STYLE_UNDERLINE",UINT2NUM(TTF_STYLE_UNDERLINE)); rb_define_const(cTTFFont,"HINTING_NORMAL",INT2NUM(TTF_HINTING_NORMAL)); rb_define_const(cTTFFont,"HINTING_LIGHT",INT2NUM(TTF_HINTING_LIGHT)); rb_define_const(cTTFFont,"HINTING_MONO",INT2NUM(TTF_HINTING_MONO)); rb_define_const(cTTFFont,"HINTING_NONE",INT2NUM(TTF_HINTING_NONE)); } void rubysdl_quit_TTF(void) { if(ttf_init) TTF_Quit(); } #else /* HAVE_SDL_TTF */ void rubysdl_init_TTF(void) { } void rubysdl_quit_TTF(void) { } #endif /* HAVE_SDL_TTF */ rubysdl-2.2.0/NEWS.ja0000644000175000017500000002464512376257217014152 0ustar uwabamiuwabamiversion 2.2.0 以下の定数を追加(thanks to oscdir for SDL::GL::*, thanks to Rafael Sevilla for SDL::Event::*) * SDL::Event::APPMOUSEFOCUS * SDL::Event::APPINPUTFOCUS * SDL::Event::APPACTIVE * SDL::GL::STEREO * SDL::GL::MULTISAMPLEBUFFERS * SDL::GL::MULTISAMPLESAMPLES * SDL::GL::ACCELERATED_VISUAL * SDL::GL::SWAP_CONTROL 以下のメソッドを追加(thanks to soutaro) * SDL::TTF#hinting * SDL::TTF#hinting= SDL::Mixer::Wave.destroyed_ を SDL::Mixer::Wave.destroyed? に rename (thanks to akicho8) version 2.1.3.1 バンドルしたSGEを使うためのオプション名を変更 Windows が CFLAGS に -Dmain=SDL_main というのを含んでいることへの対処法を変更 version 2.1.3 以下のメソッドのバグを修正 * SDL::TTF#draw* ドキュメントの修正 FreeBSDでコンパイル時にエラーが生じる問題を修正(Thanks Rusmir Dusko) スレッドまわりの挙動を修正 SGE をバンドル(できる限り使わないでください) version 2.1.2 Rubyの文字列とCの文字列の変換を厳密にするようにした 以下のメソッドのバグを修正 * SDL::Surface#draw_bezier ドキュメントの修正 version 2.1.1 Ruby 1.9とMacOS Xでコンパイルできない問題を修正 sdl.so を sdl_ext という名前に変更 以下の定数を追加 * SDL::Mixer::NO_FADING * SDL::Mixer::FADING_OUT * SDL::Mixer::FADING_IN * SDL::TRANSFORM_AA(for compatible with 1.x) * SDL::TRANSFORM_TMAP(for compatible with 1.x) * SDL::TRANSFORM_SAFE(for compatible with 1.x) ドキュメントの修正 古いドキュメントを削除 version 2.1.0 以下のメソッドを追加 * SDL::TTF#close * SDL::TTF#closed? * SDL::BMFont#close * SDL::BMFont#closed? * SDL::Kanji#close * SDL::Kanji#closed? * SDL::Surface#destroyed? * SDL::Joystick#closed? * SDL::Mixer::Wave#destroyed? * SDL::Mixer::Music#destroyed? * SDL::Kanji#get_coding_system ドキュメントの修正 以下のメソッドの呼びだし中に1.9でスレッド切り替え可能に変更 * SDL::Event#wait * SDL.delay 以下のメソッドでRubyのm17n機能を利用するように変更 * SDL::WM.set_caption * SDL::WM.caption * SDL::TTF#draw_solid * SDL::TTF#draw_blended * SDL::TTF#draw_shaded * SDL::TTF#render_solid * SDL::TTF#render_blended * SDL::TTF#render_shaded * SDL::Kanji#put * SDL::Kanji#putTate * SDL::SDLSKK#str 以下のメソッドのバグを修正 * SDL::MPEG#move version 2.0.1b サンプルのバグを修正 SDL::MPEG.infoを修正 version 2.0.1 コンパイルできない場合があるのを修正 SDL::Surface.blitでビデオメモリがロストした場合に 例外SDL::Surface::VideoMemoryLostを発生させるようにした。 version 2.0 ruby 1.9で使えるように変更 SDL_RWops対応を修正し、SDL::Mixer::Wave.load_from_ioが使えるようにした。 ドキュメントの改善(特に英語版) 以下のメソッドを追加 * SDL::Surface#load_bmp_from_string * SDL::Surface#load_from_string * SDL::Mixer::Wave#load_from_string * SDL::Mixer.playing_channels version 2.0 alpha 1 内部構造を大幅に変更 SDL::Event2をSDL::Eventに変更し、かつてのSDL::Eventは廃止 以下のメソッドを廃止 * SDL::Surface#draw_ellispe * SDL::Surface#draw_filled_ellispe * SDL::Surface#rotate_surface * SDL::Surface#rotate_scaled_surface * SDL.rotate * SDL.rotate_blit * SDL.rotate_scaled_blit * SDL.rotate_xy_scaled 以下のメソッドを追加 * SDL::Surface#destroy * SDL::Joystick#close * SDL::Mixer#close * SDL::Mixer::Wave#destroy * SDL::Mixer::Music#destroy SDL::GLモジュールを追加 SDL::PixelFormat(SDL::Surface::Formatのほうが良い?)の実装を変更 Surfaceのフォーマットを指定するのにSDL::PixelFormatが使えるように変更 以下の描画メソッドの(antialias, fill, alphaをあらわす)引数を追加 * SDL::Surface#draw_line * SDL::Surface#draw_circle * SDL::Surface#draw_rect * SDL::Surface#draw_ellipse * SDL::Surface#draw_bezier 以下のようにメソッドを移動、旧来のものも利用はできます * SDL.auto_lock? -> SDL::Surface.auto_lock? * SDL.auto_lock_on -> SDL::Surface.auto_lock_on * SDL.auto_lock_off -> SDL::Surface.auto_lock_off * SDL.transform_blit -> SDL::Surface#transform_blit * SDL.blitSurface -> SDL::Surface.blit * SDL.get_video_surface -> SDL::Screen.get * SDL.set_video_mode -> SDL::Screen.open * SDL.check_video_mode -> SDL::Screen.check_mode * SDL.list_modes -> SDL::Screen.list_modes * SDL.set_gamma -> SDL::Screen.set_gamma * SDL.get_gamma_ramp -> SDL::Screen.get_gamma_ramp * SDL.set_gamma_ramp -> SDL::Screen.set_gamma_ramp * SDL.video_driver_name -> SDL::Screen.driver_name * SDL.video_info -> SDL::Screen.info * SDL::Surface#get_rgb -> SDL::PixelFormat#get_rgb * SDL::Surface#get_rgba -> SDL::PixelFormat#get_rgba * SDL::Surface#map_rgb -> SDL::PixelFormat#map_rgb * SDL::Surface#map_rgba -> SDL::PixelFormat#map_rgba * SDL::Surface#get_palette -> SDL::PixelFormat#palette * SDL::Surface#bpp -> SDL::PixelFormat#bpp * SDL::Surface#bytes_per_pixel -> SDL::PixelFormat#bytes_per_pixel * SDL::Surface#[RGBA]mask -> SDL::PixelFormat#[RGBA]mask * SDL::Surface#[RGBA]shift -> SDL::PixelFormat#[RGBA]shift * SDL::Surface#[RGBA]loss -> SDL::PixelFormat#[RGBA]loss * SDL::Surface#colorkey -> SDL::PixelFormat#colorkey * SDL::Surface#alpha -> SDL::PixelFormat#alpha * SDL.get_GL_attr -> SDL::GL.get_attr * SDL.set_GL_attr -> SDL::GL.set_attr * SDL.GL_swap_buffers -> SDL::GL.swap_buffers 以下のように定数を移動。旧来のものも利用はできます。 * GL_RED_SIZE -> GL::RED_SIZE * GL_GREEN_SIZE -> GL::GREEN_SIZE * GL_BLUE_SIZE -> GL::BLUE_SIZE * GL_ALPHA_SIZE -> GL::ALPHA_SIZE * GL_BUFFER_SIZE -> GL::BUFFER_SIZE * GL_DOUBLEBUFFER -> GL::DOUBLEBUFFER * GL_DEPTH_SIZE -> GL::DEPTH_SIZE * GL_STENCIL_SIZE -> GL::STENCIL_SIZE * GL_ACCUM_RED_SIZE -> GL::ACCUM_RED_SIZE * GL_ACCUM_GREEN_SIZE -> GL::ACCUM_GREEN_SIZE * GL_ACCUM_BLUE_SIZE -> GL::ACCUM_BLUE_SIZE * GL_ACCUM_ALPHA_SIZE -> GL::ACCUM_ALPHA_SIZE OpenGL関連のドキュメントを追加 version 1.3.1 SMPEG有、SDL_mixer無の場合の問題を修正 以下のメソッドを追加 SDL::Surface#Rloss SDL::Surface#Gloss SDL::Surface#Bloss SDL::Surface#Aloss SDL::Surface#Rshift SDL::Surface#Gshift SDL::Surface#Bshift SDL::Surface#Ashift SDL::Surface#pitch SDL::Surface#bytes_per_pixel 以下のメソッドを修正 SDL::Surface.pixels version 1.3.0 ドキュメントを修正/改善 定数SDL::NOFRAMEが定義されていなかったのを修正 以下のメソッドを追加 SDL::Screen#update_rects SDL::Event2.pump SDL::Screen.open SDL::Surface.blit SDL::Mixer.driver_name 以下のメソッドを修正 SDL.video_driver_name version 1.2.0 日本語のリファレンスのMPEGの項目を加筆 以下のメソッドを追加 SDL::MPEG#render_final SDL::Surface.load_bmp_from_io SDL::Surface.load_from_io SDL::Mixer::Wave.load_from_io SDL::Mixer::Music.load_from_string SMPEG有、SDL_mixer無の場合にコンパイルできないバグを修正 version 1.1.0 日本語のリファレンスを全面改訂 以下のメソッドを追加 SDL::CD.framesToMSF SDL::CD.MSFToFrames SDL::CD#in_drive? SDL::Mixer.playChannelTimed SDL::Mixer.fadeInChannel SDL::Mixer.fadeInChannelTimed SDL::Mixer.expire SDL::Mixer.fading SDL::Mixer.fadeOut SDL::Mixer.fadingMusic SDL::Mouse.show? SDL::CollisionMap#w SDL::CollisionMap#h SDL::BMFont#textSize SDL::TTF#init? 以下のクラスを追加 SDL::Event2::VideoExpose 以下のメソッドのバグを修正 SDL::Key.press? SDL::TTF#familyName SDL::TTF#styleName 以下のクラスの終了時バグを修正 SDL::BMFont キーリピート関連の定数を追加 version 1.0.0 以下のメソッドを追加 SDL::Surface#drawBezier SDL::Surface#drawAABezier SDL::Surface#drawBezierAlpha SDL::Surface#drawAABezierAlpha 以下のメソッドのバグを修正 SDL::MPEG#setDisplay version 0.9.5 以下のメソッドのバグを修正 SDL::Surface#getPalette SDL::Surface#copyRect 以下のメソッドを追加 SDL::WM.grubInput SDL.quit SDL.putenv SDL.getenv ささいなtypoを修正 ドキュメントを一部修正(SDL::TTF#textSize) version 0.9.4 SDL::Surface#pixels, SDL::Surface#[RGBA]mask, SDL::Surface.new_fromを追加 SDL::Surface.newを拡張 OpenGL関連のドキュメントを最低限の分追加 version 0.9.3 sgeのbitmap font描画機能を追加 SDL_kanjiによるbdf font描画機能を追加 SDL::TTF#height, #ascent, #descent, #lineSkipを追加 SDL::Surface#copyRectを追加 warningがでる点を修正 SDLSKKインターフェースの致命的なバグを修正 OpenGLをデフォルトで有効にした version 0.9.2 sgeのアルファ付き図形描画、アンチエイリアズ付き図形描画をサポート SDL.transformBlitをsetAlphaでのalphaの設定を有効にする version 0.9.1 SDL::EventとSDL::Event2の致命的なバグを修正 version 0.9 SDLSKK 0.4をサポート、0.3のサポートを停止 衝突判定機能を追加 ( thanks to Wayne Conrad ) MPEG再生機能を強化。複数のMPEGファイルを読みこめるようにする、SDL_Mixerによる 音声再生機能との共存を可能にするなどの変更をした。 サンプルを追加。( thanks to Simon Strandgaard ) version 0.8.3 以下のメソッドを追加(typoのため) ( thanks to Wayne Conrad ) SDL::Surface#drawEllipse SDL::Surface#drawFilledEllipse 以下のメソッドを修正( thanks to moumar ) SDL.videoInfo version 0.8.2 SDLSKK 0.3をサポート、0.2以前はサポートしないことにした Joystick機能のバグを修正 以下のメソッドを追加 SDL::Screen#toggleFullScreen SDL::Key.getKeyName ドキュメントにaliasを記述 version 0.8.1 バグ修正 version 0.8 SDLSKKのサポートを加える。 終了処理の変更(たむらさんのパッチなどによる) アンダーバー区切りのメソッド名を利用できるようにした( blit_surface など ) メソッド名を変更 SDL::CD.name -> SDL::CD.indexName SDL::Joystick.name -> SDL::Joystick.indexName 以下のメソッドの追加 SDL::Mixer.allocateChannels SDL::TTF#renderSolidUTF8 SDL::TTF#renderBlendedUTF8 SDL::TTF#renderShadedUTF8 SDL::TTF#faces SDL::TTF#fixedWidth? SDL::TTF#familyName SDL::TTF#styleName SDL.videoDriverName SDL.getGammaRamp SDL.setGammaRamp SDL::Surface#saveBMP SDL::Surface#displayFormatAlpha SDL::Surface#getClipRect SDL.autoLock? SDL.autoLockON SDL.autoLockOFF 以下のメソッドを拡張 SDL.blitSurface2 rubysdl-2.2.0/README.ja0000644000175000017500000001750712376257217014332 0ustar uwabamiuwabami Ruby/SDL 2.2.0 大林一平 = 概要 これは、RubyからSDLの機能を使うための拡張ライブラリです。 SDLとは、Win32,Linux,BeOS,MacOS,FreeBSD,Solaris等で動く、クロスプラットフォームなゲーム開発用ライブラリです。 = 動作環境 LinuxのX上、Win32 また、FreeBSDで動作が確認され、Portsが作られたそうです。 BeOS上でも動くそうです。 MacOSXでも動いたそうです。ただしRubyに手を入れる必要があるようです。 それ以外では確認していません。 = 必要なライブラリ このライブラリは、rubyの処理系の他、以下のライブラリを必要とします。 SDL_mixer,SDL_ttf,SDL_image,SGE,smpeg,SDLSKKはなくてもかまいません。 SDL(必須) http://www.libsdl.org/ SDL_mixer(オプション) http://www.libsdl.org/projects/SDL_mixer/index.html SDL_ttf(オプション) http://www.libsdl.org/projects/SDL_ttf/index.html SDL_image(オプション) http://www.libsdl.org/projects/SDL_image/index.html SGE(オプション) http://www.etek.chalmers.se/~e8cal1/sge/ SMPEG(オプション) http://www.icculus.org/smpeg/ SDLSKK(オプション) http://www.kmc.gr.jp/~ohai/sdlskk.html また、SDL_kanjiを利用していますが、これはアーカイブに含めているので 別に用意する必要はありません。 = インストール Linux上でのインストールを説明します。Unix系のOSならどれでも同じよう にできると思います。 Debian、Vine、その他様々なディストリビューションにはRuby/SDLのパッケージ があるのでそれを利用してもよいでしょう。 Windows上では別に用意しているバイナリを使用したほうが楽でしょう。 FreeBSDにはPortがあるのでそれを利用してください。 (1)rubyのインストール rubyのドキュメント等に従ってインストールしてください。 (2)SDLのインストール ソースを展開してコンパイルする場合は、以下の通りにしてください。 ./configure make make install (3)SGEのインストール make; make installでインストールされます。 (4)SDL_mixer,SDL_ttf,SDL_image,SMPEG,SDLSKKのインストール 附属のドキュメントに従ってインストールしてください。 (5)この拡張ライブラリ(Ruby/SDL)のインストール このライブラリのソースを展開したディレクトリ内で ruby extconf.rb make make install としてください。 (6) (MacOS Xのみ) rsdl のインストール gem install rsdl で rsdl をインストールしてください。 = Gemによるインストール gem でもインストールできます。 gem install rubysdl です。 = SGEをインストールせずに使う Ruby/SDLが内部で SGE を持っています。 gem install rubysdl -- --enable-bundled-sge もしくは ruby extconf.rb --enable-bundled-sge で使えます。 ただし、この仕組みはできれば使わないでください。 SGEが別にインストール可能ならそちらを使ってください。 = 使い方 require 'sdl'で使えます。 MacOS Xの場合のみ、 ruby コマンドでなく rsdl コマンドで インタプリタを起動してください。 詳しくは、以下のファイルやドキュメントを見てください。 sample/*.rb サンプル 以下のサンプルがあります。 testsprite.rb 画像表示のサンプル playwave.rb PCMファイル演奏のサンプル sample.wav が必要 movesp.rb キー入力のサンプル alpha.rb アルファブレンディングのサンプル sgetest.rb sgeのプリミティブ描画のサンプル font.rb True Type Fontのサンプル playmod.rb modファイル演奏のサンプル sample.it が必要 testgl.rb OpenGLのサンプル cursor.rb マウスカーソルを変更するサンプルp transformblit.rb 回転縮小拡大のサンプル joy2.rb ジョイパッド入力のサンプル plaympeg.rb mpeg表示のサンプル sample.mpgが必要 sdlskk.rb SDLSKKのサンプル。フォントや辞書等必要 詳しくはサンプルのコメントを見てください bfont.rb ビットマップフォント表示のサンプル kanji.rb SDL_Kanji機能のサンプル。8x16.bdfとjiskan16.bdf という2つのbdfファイルが必要 collision.rb 衝突検出機能のサンプル その他 rubysdl_ref.rd, rubysdl_ref.html リファレンス Ruby/SDLのリファレンスマニュアルです。 rubysdl_doc_old.rd 古いリファレンス 古いリファレンスです。 SDLのドキュメント SDLのインストールのときに展開したファイルの中にあるはずです。 また、 http://www.tacoworks.jp/software/SDLdoc-jp/index-j.html から日本語のドキュメントも手に入ります。 リファレンスに書かれていないことはこれを見てください。 doc/ Makefile rsd.rb *.rsd リファレンスマニュアルの元データです。 = OpenGLについて このライブラリによってOpenGLへのアクセスが可能になります。 (1) SDLからOpenGLを使えるように設定する。 (2) http://ruby-opengl.rubyforge.org/ をインストールする。 (3) ruby extconf.rb をするときに、--enable-opengl を指定する。 (4) make ; make install する。 この場合はRubyのスクリプト内でrequire 'opengl'をする必要があります。 インターフェースは ruby-opengl そのものなので、 これの使いかたは、SDLのドキュメント、OpenGLのドキュメント、 および sample/testgl.rb を見て調べてください。 = ライセンス GNU LGPL(GNU Lesser General Public License) version 2.1 以降に従います。 詳しくはLICENSEを見てください。 ただし、sample/ 以下にあるサンプルプログラムはこれには従わず、 自由に利用してよいです。 = 謝辞 以下の人達に感謝します。 * FreeBSDでの動作確認をし、Portsを作っていただいたAkinori MUSHAさん。 * さまざまな意見を送ってくださり、いくつものパッチを送ってくださったり したたむらさん。 * そしてもうひとつのSDLのRuby拡張ライブラリ"RUDL"の作者である Danny van Bruggen さん(いくつかのアイデアをこのライブラリから得ました)。 * rubysdl_ttf.cの機能拡張パッチやVine、Debianのパッケージ作成などを していただいたやまだあきらさん。 * いくつかのパッチを下さった Wayne Conrad さん、Christian Neukirchenさん、 Keffin Barnabyさん。 * サンプルを提供してくださった Simon Strandgaard さん。 * 有用な情報、バグレポートをくださった Rorien Dunnさん、Dennis Rankeさん、 Keita Urashima, Dwayne C. Litzenberger さん。 * SDLの存在を教えてくれ、Ruby/SDLを作るきっかけを与えてくれた田畑さん。 * SDLdoc 日本語翻訳プロジェクトにかかわったみなさま * サンプル用のフォントを提供してくれた原さん。 * #sdl-fan-jp@friend chat のみなさま * Windows版の管理をしてくださるサイロスさん = その他 まだテストされていない機能が多くあります(パレット関連 やMPEG関連のメソッドいくつかなど)。 = 作者 大林一平: いろいろ サイロス誠: Windowsサポート yhara: MacOS Xサポート 要望、バグ報告、使用した感想等は、ohai@kmc.gr.jpにメールを出して ください。 以上 rubysdl-2.2.0/rubysdl_pixel.c0000644000175000017500000000725712376257217016113 0ustar uwabamiuwabami/* Ruby/SDL Ruby extension library for SDL Copyright (C) 2001-2007 Ohbayashi Ippei This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* * this file is copied from SGE library. */ /* sge's copyright */ /* * * * SDL Graphics Extension * Basic drawing functions * * Started 990815 * * License: LGPL v2+ (see the file LICENSE) * (c)1999-2001 Anders Lindstr */ /* pixel access functions,from sge_draw.cpp */ #include "rubysdl.h" #if SDL_VERSIONNUM(SDL_MAJOR_VERSION, SDL_MINOR_VERSION, SDL_PATCHLEVEL) >= SDL_VERSIONNUM(1, 1, 5) #define clip_xmin(pnt) pnt->clip_rect.x #define clip_xmax(pnt) pnt->clip_rect.x + pnt->clip_rect.w-1 #define clip_ymin(pnt) pnt->clip_rect.y #define clip_ymax(pnt) pnt->clip_rect.y + pnt->clip_rect.h-1 #else #define clip_xmin(pnt) pnt->clip_minx #define clip_xmax(pnt) pnt->clip_maxx #define clip_ymin(pnt) pnt->clip_miny #define clip_ymax(pnt) pnt->clip_maxy #endif #ifdef HAVE_SGE #include #endif void rubysdl_putPixel(SDL_Surface *surface, Sint16 x, Sint16 y, Uint32 color) { #ifdef HAVE_SGE sge_PutPixel(surface,x, y, color); #else Uint8 *pix; int shift; if(x>=clip_xmin(surface) && x<=clip_xmax(surface) && y>=clip_ymin(surface) && y<=clip_ymax(surface)){ switch (surface->format->BytesPerPixel) { case 1: /* Assuming 8-bpp */ *((Uint8 *)surface->pixels + y*surface->pitch + x) = color; break; case 2: /* Probably 15-bpp or 16-bpp */ *((Uint16 *)surface->pixels + y*surface->pitch/2 + x) = color; break; case 3: /* Slow 24-bpp mode, usually not used */ /* Gack - slow, but endian correct */ pix = (Uint8 *)surface->pixels + y * surface->pitch + x*3; shift = surface->format->Rshift; *(pix+shift/8) = color>>shift; shift = surface->format->Gshift; *(pix+shift/8) = color>>shift; shift = surface->format->Bshift; *(pix+shift/8) = color>>shift; break; case 4: /* Probably 32-bpp */ *((Uint32 *)surface->pixels + y*surface->pitch/4 + x) = color; break; } } #endif } Uint32 rubysdl_getPixel(SDL_Surface *surface, Sint16 x, Sint16 y) { #ifdef HAVE_SGE return sge_GetPixel(surface, x, y); #else Uint8 *pix; int shift; Uint32 color=0; switch (surface->format->BytesPerPixel) { case 1: /* Assuming 8-bpp */ return *((Uint8 *)surface->pixels + y*surface->pitch + x); break; case 2: /* Probably 15-bpp or 16-bpp */ return *((Uint16 *)surface->pixels + y*surface->pitch/2 + x); break; case 3: /* Slow 24-bpp mode, usually not used */ pix = (Uint8 *)surface->pixels + y * surface->pitch + x*3; shift = surface->format->Rshift; color = *(pix+shift/8)<format->Gshift; color|= *(pix+shift/8)<format->Bshift; color|= *(pix+shift/8)<format->Ashift; color|= *(pix+shift/8)<pixels + y*surface->pitch/4 + x); break; } return 0; #endif } rubysdl-2.2.0/rubysdl_event.c0000644000175000017500000003672412376257217016114 0ustar uwabamiuwabami/* Ruby/SDL Ruby extension library for SDL Copyright (C) 2001-2007 Ohbayashi Ippei This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "rubysdl.h" #ifdef HAVE_RUBY_THREAD_H #include #endif static VALUE cEvent; static VALUE cActiveEvent; static VALUE cKeyDownEvent; static VALUE cKeyUpEvent; static VALUE cMouseMotionEvent; static VALUE cMouseButtonDownEvent; static VALUE cMouseButtonUpEvent; static VALUE cJoyAxisEvent; static VALUE cJoyBallEvent; static VALUE cJoyHatEvent; static VALUE cJoyButtonUpEvent; static VALUE cJoyButtonDownEvent; static VALUE cQuitEvent; static VALUE cSysWMEvent; static VALUE cVideoResizeEvent; typedef VALUE (*event_creator)(SDL_Event *); static event_creator event_creators[SDL_NUMEVENTS]; static VALUE createNoEvent(SDL_Event *event) { return Qnil; } static VALUE createActiveEvent(SDL_Event *event) { VALUE obj = rb_obj_alloc(cActiveEvent); rb_iv_set(obj, "@gain", INT2BOOL(event->active.gain)); rb_iv_set(obj, "@state", INT2FIX(event->active.state)); return obj; } static VALUE createKeyEvent(VALUE obj, SDL_Event *event) { rb_iv_set(obj, "@press", INT2BOOL(event->key.state == SDL_PRESSED)); rb_iv_set(obj, "@sym", INT2FIX(event->key.keysym.sym)); rb_iv_set(obj, "@mod", UINT2NUM(event->key.keysym.mod)); rb_iv_set(obj, "@unicode", UINT2NUM(event->key.keysym.unicode)); return obj; } static VALUE createKeyDownEvent(SDL_Event *event) { VALUE obj = rb_obj_alloc(cKeyDownEvent); return createKeyEvent(obj, event); } static VALUE createKeyUpEvent(SDL_Event *event) { VALUE obj = rb_obj_alloc(cKeyUpEvent); return createKeyEvent(obj, event); } static VALUE createMouseMotionEvent(SDL_Event *event) { VALUE obj = rb_obj_alloc(cMouseMotionEvent); rb_iv_set(obj, "@state", INT2FIX(event->motion.state)); rb_iv_set(obj, "@x", INT2FIX(event->motion.x)); rb_iv_set(obj, "@y", INT2FIX(event->motion.y)); rb_iv_set(obj, "@xrel", INT2FIX(event->motion.xrel)); rb_iv_set(obj, "@yrel", INT2FIX(event->motion.yrel)); return obj; } static VALUE createMouseButtonEvent(VALUE obj, SDL_Event *event) { rb_iv_set(obj, "@button", INT2FIX(event->button.button)); rb_iv_set(obj, "@press", INT2BOOL(event->button.state == SDL_PRESSED)); rb_iv_set(obj, "@x", INT2FIX(event->button.x)); rb_iv_set(obj, "@y", INT2FIX(event->button.y)); return obj; } static VALUE createMouseButtonDownEvent(SDL_Event *event) { VALUE obj = rb_obj_alloc(cMouseButtonDownEvent); return createMouseButtonEvent(obj, event); } static VALUE createMouseButtonUpEvent(SDL_Event *event) { VALUE obj = rb_obj_alloc(cMouseButtonUpEvent); return createMouseButtonEvent(obj, event); } static VALUE createJoyAxisEvent(SDL_Event *event) { VALUE obj = rb_obj_alloc(cJoyAxisEvent); rb_iv_set(obj, "@which", INT2FIX(event->jaxis.which)); rb_iv_set(obj, "@axis", INT2FIX(event->jaxis.axis)); rb_iv_set(obj, "@value", INT2FIX(event->jaxis.value)); return obj; } static VALUE createJoyBallEvent(SDL_Event *event) { VALUE obj = rb_obj_alloc(cJoyBallEvent); rb_iv_set(obj, "@which", INT2FIX(event->jball.which)); rb_iv_set(obj, "@ball", INT2FIX(event->jball.ball)); rb_iv_set(obj, "@xrel", INT2FIX(event->jball.xrel)); rb_iv_set(obj, "@yrel", INT2FIX(event->jball.yrel)); return obj; } static VALUE createJoyHatEvent(SDL_Event *event) { VALUE obj = rb_obj_alloc(cJoyHatEvent); rb_iv_set(obj, "@which", INT2FIX(event->jhat.which)); rb_iv_set(obj, "@hat", INT2FIX(event->jhat.hat)); rb_iv_set(obj, "@value", INT2FIX(event->jhat.value)); return obj; } static VALUE createJoyButtonEvent(VALUE obj, SDL_Event *event) { rb_iv_set(obj, "@which", INT2FIX(event->jbutton.which)); rb_iv_set(obj, "@button", INT2FIX(event->jbutton.button)); rb_iv_set(obj, "@press", INT2BOOL(event->jbutton.state == SDL_PRESSED)); return obj; } static VALUE createJoyButtonUpEvent(SDL_Event *event) { VALUE obj = rb_obj_alloc(cJoyButtonUpEvent); return createJoyButtonEvent(obj, event); } static VALUE createJoyButtonDownEvent(SDL_Event *event) { VALUE obj = rb_obj_alloc(cJoyButtonDownEvent); return createJoyButtonEvent(obj, event); } static VALUE createQuitEvent(SDL_Event *event) { VALUE obj = rb_obj_alloc(cQuitEvent); return obj; } static VALUE createSysWMEvent(SDL_Event *event) { VALUE obj = rb_obj_alloc(cSysWMEvent); return obj; } static VALUE createVideoResizeEvent(SDL_Event *event) { VALUE obj = rb_obj_alloc(cVideoResizeEvent); rb_iv_set(obj, "@w", INT2FIX(event->resize.w)); rb_iv_set(obj, "@h", INT2FIX(event->resize.h)); return obj; } /* class method */ static VALUE Event_s_poll(VALUE class) { SDL_Event event; if( SDL_PollEvent(&event) == 1) return event_creators[event.type](&event); else return Qnil; } #if defined(HAVE_RB_THREAD_CALL_WITHOUT_GVL) static void* wait_event(void* ev) { return (void*)(intptr_t)SDL_WaitEvent((SDL_Event*)ev); } #elif defined(HAVE_RB_THREAD_BLOCKING_REGION) static VALUE wait_event(void* ev) { return SDL_WaitEvent((SDL_Event*)ev); } #endif #if defined(HAVE_RB_THREAD_CALL_WITHOUT_GVL) || defined(HAVE_RB_THREAD_BLOCKING_REGION) static void ubf_SDL_WaitEvent(void* unused) { SDL_Event ev; ev.type = SDL_USEREVENT; ev.user.code = 19002; /* Code for interrupt */ ev.user.data1 = ev.user.data2 = NULL; SDL_PushEvent(&ev); } #endif static VALUE Event_s_wait(VALUE class) { SDL_Event event; /* Ruby 1.9 and above: Release the global VM lock while calling * SDL_WaitEvent, allowing other Ruby threads to execute. * Ruby 1.8 and below: Call SDL_WaitEvent directly. * No other threads can execute during this call. */ #if defined(HAVE_RB_THREAD_CALL_WITHOUT_GVL) if ((intptr_t)rb_thread_call_without_gvl(wait_event, &event, ubf_SDL_WaitEvent, NULL) == 1) #elif defined(HAVE_RB_THREAD_BLOCKING_REGION) if( rb_thread_blocking_region(wait_event, &event, ubf_SDL_WaitEvent, NULL) == 1) #else if( SDL_WaitEvent(&event) == 1) #endif return event_creators[event.type](&event); else rb_raise(eSDLError, "Event handling error"); } static VALUE Event_s_pump(VALUE class) { SDL_PumpEvents(); return Qnil; } static VALUE Event_s_new(VALUE class) { return rb_obj_alloc(class); } static VALUE Event_s_push(VALUE class, VALUE event) { SDL_Event e; VALUE eventClass; eventClass = CLASS_OF(event); if(eventClass == cActiveEvent){ e.type = SDL_ACTIVEEVENT; e.active.gain = rb_iv_get(event, "@gain"); e.active.state = NUM2INT(rb_iv_get(event, "@state")); }else if(eventClass == cKeyDownEvent){ e.type=SDL_KEYDOWN; e.key.state = (rb_iv_get(event, "@press"))?SDL_PRESSED:SDL_RELEASED; e.key.keysym.sym = NUM2INT(rb_iv_get(event, "@sym")); e.key.keysym.mod = NUM2UINT(rb_iv_get(event, "@mod")); e.key.keysym.unicode = NUM2UINT( rb_iv_get(event, "@unicode") ); }else if(eventClass == cKeyUpEvent){ e.type = SDL_KEYUP; e.key.state = (rb_iv_get(event, "@press"))?SDL_PRESSED:SDL_RELEASED; e.key.keysym.sym = NUM2INT(rb_iv_get(event, "@sym")); e.key.keysym.mod = NUM2UINT(rb_iv_get(event, "@mod")); e.key.keysym.unicode = NUM2UINT( rb_iv_get(event, "@unicode") ); }else if(eventClass == cMouseMotionEvent){ e.type=SDL_MOUSEMOTION; e.motion.state = NUM2INT(rb_iv_get(event, "@state")); e.motion.x = NUM2INT(rb_iv_get(event, "@x")); e.motion.y = NUM2INT(rb_iv_get(event, "@y")); e.motion.xrel = NUM2INT(rb_iv_get(event, "@xrel")); e.motion.yrel = NUM2INT(rb_iv_get(event, "@yrel")); }else if(eventClass == cMouseButtonDownEvent){ e.type = SDL_MOUSEBUTTONDOWN; e.button.button = NUM2INT(rb_iv_get(event, "@button")); e.button.state = (rb_iv_get(event, "@press"))?SDL_PRESSED:SDL_RELEASED; e.button.x = NUM2INT(rb_iv_get(event, "@x")); e.button.y = NUM2INT(rb_iv_get(event, "@y")); }else if(eventClass == cMouseButtonUpEvent){ e.type = SDL_MOUSEBUTTONUP; e.button.button = NUM2INT(rb_iv_get(event, "@button")); e.button.state = (rb_iv_get(event, "@press"))?SDL_PRESSED:SDL_RELEASED; e.button.x = NUM2INT(rb_iv_get(event, "@x")); e.button.y = NUM2INT(rb_iv_get(event, "@y"));\ }else if(eventClass == cJoyAxisEvent){ e.type = SDL_JOYAXISMOTION; e.jaxis.which = NUM2INT(rb_iv_get(event, "@which")); e.jaxis.axis = NUM2INT(rb_iv_get(event, "@axis")); e.jaxis.value = NUM2INT(rb_iv_get(event, "@value")); }else if(eventClass == cJoyBallEvent){ e.type = SDL_JOYBALLMOTION; e.jball.which = NUM2INT(rb_iv_get(event, "@which")); e.jball.ball = NUM2INT(rb_iv_get(event, "@ball")); e.jball.xrel = NUM2INT(rb_iv_get(event, "@xrel")); e.jball.yrel = NUM2INT(rb_iv_get(event, "@yrel")); }else if(eventClass == cJoyHatEvent){ e.type = SDL_JOYHATMOTION; e.jhat.which = NUM2INT(rb_iv_get(event, "@which")); e.jhat.hat = NUM2INT(rb_iv_get(event, "@hat")); e.jhat.value = NUM2INT(rb_iv_get(event, "@value")); }else if(eventClass == cJoyButtonUpEvent){ e.type = SDL_JOYBUTTONUP; e.jbutton.which = NUM2INT(rb_iv_get(event, "@which")); e.jbutton.button = NUM2INT(rb_iv_get(event, "@button")); e.jbutton.state = (rb_iv_get(event, "@press"))?SDL_PRESSED:SDL_RELEASED; }else if(eventClass == cJoyButtonDownEvent){ e.type = SDL_JOYBUTTONDOWN; e.jbutton.which = NUM2INT(rb_iv_get(event, "@which")); e.jbutton.button = NUM2INT(rb_iv_get(event, "@button")); e.jbutton.state = (rb_iv_get(event, "@press"))?SDL_PRESSED:SDL_RELEASED; }else if(eventClass == cQuitEvent){ e.type = SDL_QUIT; }else if(eventClass == cSysWMEvent){ e.type = SDL_SYSWMEVENT; }else if(eventClass == cVideoResizeEvent){ e.type = SDL_VIDEORESIZE; e.resize.w = NUM2INT(rb_iv_get(event, "@w")); e.resize.h = NUM2INT(rb_iv_get(event, "@h")); }else { rb_raise(eSDLError, "This object couldn't be pushed"); } if(SDL_PushEvent(&e) == -1) rb_raise(eSDLError, "the event couldn't be pushed"); return Qnil; } static VALUE Event_s_getAppState(VALUE class) { return INT2FIX(SDL_GetAppState()); } static VALUE Event_s_enableUNICODE(VALUE class) { SDL_EnableUNICODE(1); return Qnil; } static VALUE Event_s_disableUNICODE(VALUE class) { SDL_EnableUNICODE(0); return Qnil; } static VALUE Event_s_is_enableUNICODE(VALUE class) { return INT2BOOL(SDL_EnableUNICODE(-1)); } void rubysdl_init_Event(VALUE mSDL) { int i; cEvent=rb_define_class_under(mSDL, "Event", rb_cObject); rb_define_singleton_method(cEvent, "poll", Event_s_poll, 0); rb_define_singleton_method(cEvent, "wait", Event_s_wait, 0); rb_define_singleton_method(cEvent, "pump", Event_s_pump, 0); rb_define_singleton_method(cEvent, "new", Event_s_new, 0); rb_define_singleton_method(cEvent, "push", Event_s_push, 1); rb_define_singleton_method(cEvent, "appState", Event_s_getAppState, 0); rb_define_singleton_method(cEvent, "enableUNICODE", Event_s_enableUNICODE, 0); rb_define_singleton_method(cEvent, "disableUNICODE", Event_s_disableUNICODE, 0); rb_define_singleton_method(cEvent, "enableUNICODE?", Event_s_is_enableUNICODE, 0); cActiveEvent=rb_define_class_under(cEvent, "Active", cEvent); rb_define_attr(cActiveEvent, "gain", 1, 1); rb_define_attr(cActiveEvent, "state", 1, 1); cKeyDownEvent=rb_define_class_under(cEvent, "KeyDown", cEvent); rb_define_attr(cKeyDownEvent, "press", 1, 1); rb_define_attr(cKeyDownEvent, "sym", 1, 1); rb_define_attr(cKeyDownEvent, "mod", 1, 1); rb_define_attr(cKeyDownEvent, "unicode", 1, 1); cKeyUpEvent=rb_define_class_under(cEvent, "KeyUp", cEvent); rb_define_attr(cKeyUpEvent, "press", 1, 1); rb_define_attr(cKeyUpEvent, "sym", 1, 1); rb_define_attr(cKeyUpEvent, "mod", 1, 1); rb_define_attr(cKeyUpEvent, "unicode", 1, 1); cMouseMotionEvent=rb_define_class_under(cEvent, "MouseMotion", cEvent); rb_define_attr(cMouseMotionEvent, "state", 1, 1); rb_define_attr(cMouseMotionEvent, "x", 1, 1); rb_define_attr(cMouseMotionEvent, "y", 1, 1); rb_define_attr(cMouseMotionEvent, "xrel", 1, 1); rb_define_attr(cMouseMotionEvent, "yrel", 1, 1); cMouseButtonDownEvent=rb_define_class_under(cEvent, "MouseButtonDown", cEvent); rb_define_attr(cMouseButtonDownEvent, "button", 1, 1); rb_define_attr(cMouseButtonDownEvent, "press", 1, 1); rb_define_attr(cMouseButtonDownEvent, "x", 1, 1); rb_define_attr(cMouseButtonDownEvent, "y", 1, 1); cMouseButtonUpEvent=rb_define_class_under(cEvent, "MouseButtonUp", cEvent); rb_define_attr(cMouseButtonUpEvent, "button", 1, 1); rb_define_attr(cMouseButtonUpEvent, "press", 1, 1); rb_define_attr(cMouseButtonUpEvent, "x", 1, 1); rb_define_attr(cMouseButtonUpEvent, "y", 1, 1); cJoyAxisEvent=rb_define_class_under(cEvent, "JoyAxis", cEvent); rb_define_attr(cJoyAxisEvent, "which", 1, 1); rb_define_attr(cJoyAxisEvent, "axis", 1, 1); rb_define_attr(cJoyAxisEvent, "value", 1, 1); cJoyBallEvent=rb_define_class_under(cEvent, "JoyBall", cEvent); rb_define_attr(cJoyBallEvent, "which", 1, 1); rb_define_attr(cJoyBallEvent, "ball", 1, 1); rb_define_attr(cJoyBallEvent, "xrel", 1, 1); rb_define_attr(cJoyBallEvent, "yrel", 1, 1); cJoyHatEvent=rb_define_class_under(cEvent, "JoyHat", cEvent); rb_define_attr(cJoyHatEvent, "which", 1, 1); rb_define_attr(cJoyHatEvent, "hat", 1, 1); rb_define_attr(cJoyHatEvent, "value", 1, 1); cJoyButtonUpEvent=rb_define_class_under(cEvent, "JoyButtonUp", cEvent); rb_define_attr(cJoyButtonUpEvent, "which", 1, 1); rb_define_attr(cJoyButtonUpEvent, "button", 1, 1); rb_define_attr(cJoyButtonUpEvent, "press", 1, 1); cJoyButtonDownEvent=rb_define_class_under(cEvent, "JoyButtonDown", cEvent); rb_define_attr(cJoyButtonDownEvent, "which", 1, 1); rb_define_attr(cJoyButtonDownEvent, "button", 1, 1); rb_define_attr(cJoyButtonDownEvent, "press", 1, 1); cQuitEvent=rb_define_class_under(cEvent, "Quit", cEvent); cSysWMEvent=rb_define_class_under(cEvent, "SysWM", cEvent); cVideoResizeEvent=rb_define_class_under(cEvent, "VideoResize", cEvent); rb_define_attr(cVideoResizeEvent, "w", 1, 1); rb_define_attr(cVideoResizeEvent, "h", 1, 1); for(i=0;ifont == NULL) rb_raise(eSDLError, "Kanji Font data is already disposed"); return kfont->font; } static void Font_free(KFont* kfont) { if (kfont->font) Kanji_CloseFont(kfont->font); free(kfont); } static VALUE Font_s_alloc(VALUE klass) { KFont* kfont = ALLOC(KFont); kfont->font = NULL; return Data_Wrap_Struct(klass, 0, Font_free, kfont); } static VALUE Font_create(Kanji_Font* font) { VALUE newobj = Font_s_alloc(cKanjiFont); Get_KFont(newobj)->font = font; return newobj; } #ifdef ENABLE_M17N static rb_encoding* get_enc(Kanji_Font* font) { switch (font->sys) { case KANJI_JIS: return iso2022jp_enc; break; case KANJI_EUC: return eucjp_enc; break; case KANJI_SJIS: return sjis_enc; break; default: rb_raise(eSDLError, "Unsupported Kanji encoding"); return NULL; break; } } #endif static VALUE Font_s_open(VALUE klass, VALUE filename, VALUE size) { Kanji_Font* font; ExportFilenameStringValue(filename); font = Kanji_OpenFont(RSTRING_PTR(filename), NUM2INT(size)); if(font == NULL) rb_raise(eSDLError,"Couldn't open bdf font: %s", RSTRING_PTR(filename)); return Font_create(font); } static VALUE Font_close(VALUE self) { KFont* kfont; kfont = Get_KFont(self); if (kfont->font) Kanji_CloseFont(kfont->font); kfont->font = NULL; return Qnil; } static VALUE Font_closed(VALUE self) { return INT2BOOL(Get_KFont(self)->font == NULL); } static VALUE Font_setCodingSystem(VALUE self, VALUE sys) { Kanji_SetCodingSystem(Get_Kanji_Font(self), NUM2INT(sys)); return Qnil; } static VALUE Font_getCodingSystem(VALUE self) { return INT2NUM(Get_Kanji_Font(self)->sys); } static VALUE Font_add(VALUE self, VALUE filename) { ExportFilenameStringValue(filename); if(Kanji_AddFont(Get_Kanji_Font(self), RSTRING_PTR(filename)) == -1) rb_raise(eSDLError, "Couldn't use font: %s", RSTRING_PTR(filename)); return Qnil; } static VALUE Font_textwidth(VALUE self, VALUE text) { Kanji_Font* font; font = Get_Kanji_Font(self); ExportStringValueToEnc(text, get_enc(font)); return INT2FIX(Kanji_FontWidth(font, RSTRING_PTR(text))); } static VALUE Font_width(VALUE self) { return INT2FIX(Kanji_FontWidth(Get_Kanji_Font(self), NULL)); } static VALUE Font_height(VALUE self) { return INT2FIX(Kanji_FontHeight(Get_Kanji_Font(self))); } static void Font_put(VALUE self, VALUE surface, VALUE text, VALUE x, VALUE y, VALUE r, VALUE g, VALUE b, Drawer draw) { SDL_Color color; Kanji_Font* font; font = Get_Kanji_Font(self); ExportStringValueToEnc(text, get_enc(font)); color.r = NUM2INT(r);color.g = NUM2INT(g); color.b = NUM2INT(b); draw(Get_Kanji_Font(self), NUM2INT(x), NUM2INT(y), Get_SDL_Surface(surface), RSTRING_PTR(text), color); } static VALUE Font_putText(VALUE self, VALUE surface, VALUE text, VALUE x, VALUE y, VALUE r, VALUE g, VALUE b) { Font_put(self, surface, text, x, y, r, g, b, Kanji_PutText); return Qnil; } static VALUE Font_putTextTate(VALUE self, VALUE surface, VALUE text, VALUE x, VALUE y, VALUE r, VALUE g, VALUE b) { Font_put(self, surface, text, x, y, r, g, b, Kanji_PutTextTate); return Qnil; } void rubysdl_init_Kanji(VALUE mSDL) { cKanjiFont = rb_define_class_under(mSDL, "Kanji", rb_cObject); rb_undef_alloc_func(cKanjiFont); rb_define_singleton_method(cKanjiFont, "open", Font_s_open, 2); rb_define_method(cKanjiFont, "close", Font_close, 0); rb_define_method(cKanjiFont, "closed?", Font_closed, 0); rb_define_method(cKanjiFont, "add", Font_add, 1); rb_define_method(cKanjiFont, "setCodingSystem", Font_setCodingSystem, 1); rb_define_method(cKanjiFont, "getCodingSystem", Font_getCodingSystem, 0); rb_define_method(cKanjiFont, "textwidth", Font_textwidth, 1); rb_define_method(cKanjiFont, "width", Font_width, 0); rb_define_method(cKanjiFont, "height", Font_height, 0); rb_define_method(cKanjiFont, "put", Font_putText, 7); rb_define_method(cKanjiFont, "putTate", Font_putTextTate, 7); rb_define_const(cKanjiFont, "SJIS", INT2NUM(KANJI_SJIS)); rb_define_const(cKanjiFont, "EUC", INT2NUM(KANJI_EUC)); rb_define_const(cKanjiFont, "JIS", INT2NUM(KANJI_JIS)); } rubysdl-2.2.0/rubysdl_sdlskk.c0000644000175000017500000002167412376257217016264 0ustar uwabamiuwabami/* Ruby/SDL Ruby extension library for SDL Copyright (C) 2001-2007 Ohbayashi Ippei This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifdef HAVE_SDLSKK #include "rubysdl.h" #include #include static VALUE cEvent = Qnil; static VALUE cKeyDownEvent = Qnil; static VALUE cContext = Qnil; static VALUE cDictionary = Qnil; static VALUE cRomKanaRuleTable = Qnil; static VALUE cKeybind = Qnil; DEFINE_GET_STRUCT(SDLSKK_Context, Get_SDLSKK_Context, cContext, "SDL::SKK::Context"); DEFINE_GET_STRUCT(SDLSKK_Dictionary, Get_SDLSKK_Dictionary, cDictionary, "SDL::SKK::Dictionary"); DEFINE_GET_STRUCT(SDLSKK_RomKanaRuleTable, Get_SDLSKK_RomKanaRuleTable, cRomKanaRuleTable, "SDL::SKK::RomKanaRuleTable"); DEFINE_GET_STRUCT(SDLSKK_Keybind, Get_SDLSKK_Keybind, cKeybind, "SDL::SKK::Keybind"); typedef SDL_Surface* (*Renderer)(SDLSKK_Context*,TTF_Font*,SDL_Color); static void skk_error_handler(SDLSKK_Error err) { switch( err ){ case SDLSKK_NOERROR: return; case SDLSKK_MEMERROR: rb_fatal("SDLSKK: memory allocation error"); } } static VALUE SKK_set_encoding(VALUE mod, VALUE encoding) { SDLSKK_set_encoding(NUM2INT(encoding)); return Qnil; } static VALUE SKK_get_encoding(VALUE mod) { return INT2FIX(SDLSKK_get_encoding()); } static VALUE Context_s_new(VALUE klass, VALUE dict, VALUE rule_table, VALUE keybind, VALUE use_minibuffer) { SDLSKK_Context* c_context; VALUE context; c_context = SDLSKK_Context_new(Get_SDLSKK_Dictionary(dict), Get_SDLSKK_RomKanaRuleTable(rule_table), Get_SDLSKK_Keybind(keybind), RTEST(use_minibuffer)); if(c_context == NULL) rb_raise(eSDLError,"Couldn't create Context"); context = Data_Wrap_Struct(klass, 0, SDLSKK_Context_delete ,c_context); rb_iv_set(context, "dict", dict); rb_iv_set(context, "rule_table", rule_table); return context; } static VALUE Context_input(VALUE self, VALUE event) { if(rb_obj_is_kind_of(event, cKeyDownEvent)){ SDL_Event ev; ev.type = SDL_KEYDOWN; ev.key.keysym.sym = NUM2INT(rb_iv_get(event, "@sym")); ev.key.keysym.unicode = NUM2UINT(rb_iv_get(event, "@unicode")); ev.key.keysym.mod = NUM2INT(rb_iv_get(event, "@mod")); SDLSKK_Context_input_event(Get_SDLSKK_Context(self), &ev); return Qnil; }else if(rb_obj_is_kind_of(event, cEvent)){ return Qnil; }else{ rb_raise( rb_eArgError,"type mismatch(expect SDL::Event or SDL::Event2)"); } /* NOT REACHED */ } static VALUE Context_str(VALUE self) { char cstr[10000]; #ifdef ENABLE_M17N rb_encoding* enc; switch (SDLSKK_get_encoding()) { case SDLSKK_UTF8: enc = utf8_enc; case SDLSKK_EUCJP: enc = eucjp_enc; break; case SDLSKK_SJIS: enc = sjis_enc; break; default: rb_raise(eSDLError, "SDLSKK encoding error"); } #endif SDLSKK_Context_get_str(Get_SDLSKK_Context(self), cstr, sizeof(cstr)); #ifdef ENABLE_M17N return ENC_STR_NEW2(cstr, enc); #else return rb_str_new2(cstr); #endif } static VALUE render_str(VALUE self, VALUE font, VALUE r, VALUE g, VALUE b, Renderer func) { SDL_Surface* surface; SDL_Color color; color.r = NUM2UINT(r); color.g = NUM2UINT(g); color.b = NUM2UINT(b); surface = func(Get_SDLSKK_Context(self), Get_TTF_Font(font), color); if(surface == NULL) return Qnil; return Surface_create(surface); } static VALUE Context_render_str(VALUE self, VALUE font, VALUE r, VALUE g, VALUE b) { return render_str(self, font, r, g, b, SDLSKK_Context_render_display_str); } static VALUE Context_render_minibuffer_str(VALUE self, VALUE font, VALUE r, VALUE g,VALUE b) { return render_str(self, font, r, g, b, SDLSKK_Context_render_minibuffer_str); } static VALUE Context_get_basic_mode(VALUE self) { return INT2BOOL(SDLSKK_Context_get_basic_mode(Get_SDLSKK_Context(self))); } static VALUE Context_clear(VALUE self) { SDLSKK_Context_clear(Get_SDLSKK_Context(self)); return Qnil; } static VALUE Context_clear_text(VALUE self) { SDLSKK_Context_clear_text(Get_SDLSKK_Context(self)); return Qnil; } static VALUE Dictionary_s_new(VALUE klass) { SDLSKK_Dictionary* dict; dict = SDLSKK_Dict_new(); if(dict == NULL) rb_raise(eSDLError, "Couldn't create SDL::SKK::Dictionary"); return Data_Wrap_Struct(klass, 0, SDLSKK_Dict_delete, dict); } static VALUE Dictionary_load(VALUE self, VALUE filename, VALUE users) { SDLSKK_Dictionary* dict = Get_SDLSKK_Dictionary(self); ExportFilenameStringValue(filename); if(!SDLSKK_Dict_load(dict, RSTRING_PTR(filename), RTEST(users))) rb_raise(eSDLError, "Couldn't load %s", RSTRING_PTR(filename)); return Qnil; } static VALUE Dictionary_save(VALUE self, VALUE filename) { SDLSKK_Dictionary* dict = Get_SDLSKK_Dictionary(self); ExportFilenameStringValue(filename); if(!SDLSKK_Dict_save_user_dict(dict, RSTRING_PTR(filename))) rb_raise(eSDLError, "Couldn't save %s", RSTRING_PTR(filename)); return Qnil; } static VALUE RomKanaRuleTable_s_new(VALUE klass, VALUE table_file) { SDLSKK_RomKanaRuleTable* rule_table; ExportFilenameStringValue(table_file); rule_table = SDLSKK_RomKanaRuleTable_new(RSTRING_PTR(table_file)); if(rule_table == NULL) rb_raise(eSDLError, "Couldn't load %s", RSTRING_PTR(table_file)); return Data_Wrap_Struct(klass, 0, SDLSKK_RomKanaRuleTable_delete, rule_table); } static VALUE Keybind_s_new(VALUE klass) { return Data_Wrap_Struct(klass, 0, SDLSKK_Keybind_delete, SDLSKK_Keybind_new()); } static VALUE Keybind_set_key(VALUE self, VALUE key_str, VALUE cmd_str) { SDLSKK_Keybind_set_key(Get_SDLSKK_Keybind(self), StringValueCStr(key_str), StringValueCStr(cmd_str)); return Qnil; } static VALUE Keybind_set_default_key(VALUE self) { SDLSKK_Keybind_set_default_key(Get_SDLSKK_Keybind(self)); return Qnil; } static VALUE Keybind_unset_key(VALUE self, VALUE key_str) { SDLSKK_Keybind_unset_key(Get_SDLSKK_Keybind(self), StringValueCStr(key_str)); return Qnil; } void rubysdl_init_SKK(VALUE mSDL) { VALUE mSDLSKK; cEvent = rb_const_get(mSDL, rb_intern("Event")); cKeyDownEvent = rb_const_get(cEvent, rb_intern("KeyDown")); mSDLSKK = rb_define_module_under(mSDL, "SKK"); cContext = rb_define_class_under(mSDLSKK, "Context", rb_cObject); cDictionary = rb_define_class_under(mSDLSKK, "Dictionary", rb_cObject); cRomKanaRuleTable = rb_define_class_under(mSDLSKK, "RomKanaRuleTable", rb_cObject); cKeybind = rb_define_class_under(mSDLSKK, "Keybind", rb_cObject); rb_undef_alloc_func(cContext); rb_undef_alloc_func(cDictionary); rb_undef_alloc_func(cRomKanaRuleTable); rb_undef_alloc_func(cKeybind); rb_define_module_function(mSDLSKK, "encoding=", SKK_set_encoding, 1); rb_define_module_function(mSDLSKK, "encoding", SKK_get_encoding, 0); rb_define_singleton_method(cContext, "new", Context_s_new, 4); rb_define_method(cContext, "input", Context_input, 1); rb_define_method(cContext, "str", Context_str, 0); rb_define_method(cContext, "render_str", Context_render_str, 4); rb_define_method(cContext, "render_minibuffer_str", Context_render_minibuffer_str, 4); rb_define_method(cContext, "get_basic_mode", Context_get_basic_mode, 0); rb_define_method(cContext, "clear", Context_clear, 0); rb_define_method(cContext, "clear_text", Context_clear_text, 0); rb_define_singleton_method(cDictionary, "new", Dictionary_s_new, 0); rb_define_method(cDictionary, "load", Dictionary_load, 2); rb_define_method(cDictionary, "save", Dictionary_save, 1); rb_define_singleton_method(cRomKanaRuleTable, "new", RomKanaRuleTable_s_new, 1); rb_define_singleton_method(cKeybind, "new", Keybind_s_new, 0); rb_define_method(cKeybind, "set_key", Keybind_set_key, 2); rb_define_method(cKeybind, "set_default_key", Keybind_set_default_key, 0); rb_define_method(cKeybind, "unset_key", Keybind_unset_key, 1); SDLSKK_set_error_func(skk_error_handler); rb_define_const(mSDLSKK, "EUCJP", INT2NUM(SDLSKK_EUCJP)); rb_define_const(mSDLSKK, "UTF8", INT2NUM(SDLSKK_UTF8)); rb_define_const(mSDLSKK, "SJIS", INT2NUM(SDLSKK_SJIS)); } #else /* HAVE_SDLSKK */ #include "rubysdl.h" void rubysdl_init_SKK(VALUE mSDL) { } #endif /* HAVE_SDLSKK */ rubysdl-2.2.0/rubysdl_main.c0000644000175000017500000000752612376257217015715 0ustar uwabamiuwabami/* Ruby/SDL Ruby extension library for SDL Copyright (C) 2001-2007 Ohbayashi Ippei This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #define DEF_GLOBAL #include "rubysdl.h" static VALUE sdl_s_init(VALUE mod, VALUE flags) { if( SDL_Init(NUM2UINT(flags)) < 0 ) rb_raise(eSDLError, "Couldn't initialize SDL: %s", SDL_GetError()); return Qnil; } static VALUE sdl_s_initSubSystem(VALUE mod, VALUE flags) { if( SDL_InitSubSystem(NUM2UINT(flags)) < 0 ) rb_raise(eSDLError, "Couldn't initialize SDL subsystem: %s", SDL_GetError()); return Qnil; } static VALUE sdl_s_inited_system(VALUE mod, VALUE flags) { return UINT2NUM(SDL_WasInit(NUM2UINT(flags))); } static VALUE sdl_s_putenv(VALUE mod, VALUE var) { SafeStringValue(var); if( putenv(StringValueCStr(var)) < 0 ){ rb_raise(eSDLError, "Can't put environ variable: %s", StringValueCStr(var)); } return Qnil; } static VALUE sdl_s_getenv(VALUE mod, VALUE name) { char* result; SafeStringValue(name); result = getenv(StringValueCStr(name)); if(result == NULL){ rb_raise(eSDLError, "Can't get environ variable: %s", StringValueCStr(name)); } return rb_str_new2(result); } static int is_quit=0; int rubysdl_is_quit(void) { return is_quit; } static void sdl_quit(VALUE v) { if(rubysdl_is_quit()) return; rubysdl_quit_Mixer(); rubysdl_quit_TTF(); SDL_Quit(); is_quit = 1; } static VALUE sdl_s_quit(VALUE obj) { sdl_quit(0); return Qnil; } void Init_sdl_ext() { VALUE mSDL = rb_define_module("SDL"); VALUE cSurface; #ifdef ENABLE_M17N utf8_enc = rb_utf8_encoding(); eucjp_enc = rb_enc_find("EUC-JP"); iso2022jp_enc = rb_enc_find("ISO-2022-JP"); sjis_enc = rb_enc_find("SJIS"); #endif eSDLError = rb_define_class_under(mSDL, "Error", rb_eStandardError); rb_define_module_function(mSDL, "init", sdl_s_init, 1); rb_define_module_function(mSDL, "initedSystem", sdl_s_inited_system, 1); rb_define_module_function(mSDL, "initSubSystem", sdl_s_initSubSystem, 1); rb_define_module_function(mSDL, "quit", sdl_s_quit, 0); rb_define_module_function(mSDL, "putenv", sdl_s_putenv, 1); rb_define_module_function(mSDL, "getenv", sdl_s_getenv, 1); rb_define_const(mSDL, "INIT_TIMER", UINT2NUM(SDL_INIT_TIMER)); rb_define_const(mSDL, "INIT_AUDIO", UINT2NUM(SDL_INIT_AUDIO)); rb_define_const(mSDL, "INIT_VIDEO", UINT2NUM(SDL_INIT_VIDEO)); rb_define_const(mSDL, "INIT_CDROM", UINT2NUM(SDL_INIT_CDROM)); rb_define_const(mSDL, "INIT_JOYSTICK", UINT2NUM(SDL_INIT_JOYSTICK)); rb_define_const(mSDL, "INIT_NOPARACHUTE", UINT2NUM(SDL_INIT_NOPARACHUTE)); rb_define_const(mSDL, "INIT_EVENTTHREAD", UINT2NUM(SDL_INIT_EVENTTHREAD)); rb_define_const(mSDL, "INIT_EVERYTHING", UINT2NUM(SDL_INIT_EVERYTHING)); cSurface = rubysdl_init_video(mSDL); rubysdl_init_sge(mSDL, cSurface); rubysdl_init_GL(mSDL); rubysdl_init_image(mSDL, cSurface); rubysdl_init_Event(mSDL); rubysdl_init_Key(mSDL); rubysdl_init_Mouse(mSDL); rubysdl_init_Joystick(mSDL); rubysdl_init_CD(mSDL); rubysdl_init_time(mSDL); rubysdl_init_WM(mSDL); rubysdl_init_Kanji(mSDL); rubysdl_init_TTF(mSDL); rubysdl_init_Mixer(mSDL); rubysdl_init_MPEG(mSDL); rubysdl_init_SKK(mSDL); rb_set_end_proc(sdl_quit, 0); } rubysdl-2.2.0/rubysdl_cdrom.c0000644000175000017500000001357312376257217016074 0ustar uwabamiuwabami/* Ruby/SDL Ruby extension library for SDL Copyright (C) 2001-2007 Ohbayashi Ippei This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "rubysdl.h" static VALUE cCD; typedef struct{ SDL_CD* cd; } CD; DEFINE_GET_STRUCT(CD, GetCD, cCD, "SDL::CD"); static SDL_CD* Get_SDL_CD(VALUE obj) { CD* cd = GetCD(obj); if(cd->cd == NULL) rb_raise(rb_eRuntimeError, "CD is closed"); return cd->cd; } static void CD_free(CD* cd) { if( !rubysdl_is_quit() && cd->cd ) SDL_CDClose(cd->cd); free(cd); } static VALUE CD_s_alloc(VALUE klass) { CD* cd = ALLOC(CD); cd->cd = NULL; return Data_Wrap_Struct(cCD, 0, CD_free, cd); } static VALUE CD_initialize(VALUE self, VALUE drive) { CD* cd = GetCD(self); cd->cd = SDL_CDOpen(NUM2INT(drive)); if(cd->cd == NULL) rb_raise(eSDLError, "Couldn't open drive %d: %s", NUM2INT(drive), SDL_GetError()); return Qnil; } static VALUE CD_s_numDrive(VALUE klass) { return INT2FIX(SDL_CDNumDrives()); } static VALUE CD_s_name(VALUE klass, VALUE drive) { return rb_str_new2(SDL_CDName(NUM2INT(drive))); } static VALUE CD_s_open(VALUE klass, VALUE drive) { VALUE newobj = CD_s_alloc(klass); CD_initialize(newobj, drive); return newobj; } static VALUE CD_status(VALUE self) { return INT2FIX(SDL_CDStatus(Get_SDL_CD(self))); } static VALUE CD_play(VALUE self, VALUE start, VALUE length) { if( SDL_CDPlay(Get_SDL_CD(self), NUM2INT(start), NUM2INT(length))==-1 ) rb_raise(eSDLError, "Couldn't play cd :%s", SDL_GetError() ); return Qnil; } static VALUE CD_playTracks(VALUE self, VALUE start_track, VALUE start_frame, VALUE ntracks, VALUE nframes) { if( SDL_CDPlayTracks(Get_SDL_CD(self), NUM2INT(start_track), NUM2INT(start_frame), NUM2INT(ntracks), NUM2INT(nframes))==-1 ) rb_raise(eSDLError, "Couldn't play cd :%s", SDL_GetError() ); return Qnil; } static VALUE CD_pause(VALUE self) { if( SDL_CDPause(Get_SDL_CD(self))==-1 ) rb_raise(eSDLError, "cd pause failed :%s", SDL_GetError()); return Qnil; } static VALUE CD_resume(VALUE self) { if( SDL_CDResume(Get_SDL_CD(self))==-1 ) rb_raise(eSDLError, "cd resume failed :%s", SDL_GetError()); return Qnil; } static VALUE CD_stop(VALUE self) { if( SDL_CDStop(Get_SDL_CD(self))==-1 ) rb_raise(eSDLError, "cd pause failed :%s", SDL_GetError()); return Qnil; } static VALUE CD_eject(VALUE self) { if( SDL_CDEject(Get_SDL_CD(self))==-1 ) rb_raise(eSDLError, "cd eject failed :%s", SDL_GetError()); return Qnil; } static VALUE CD_numTracks(VALUE self) { return INT2NUM(Get_SDL_CD(self)->numtracks); } static VALUE CD_currentTrack(VALUE self) { return INT2NUM(Get_SDL_CD(self)->cur_track); } static VALUE CD_currentFrame(VALUE self) { return INT2NUM(Get_SDL_CD(self)->cur_frame); } static VALUE CD_trackType(VALUE self, VALUE track) { return INT2FIX(Get_SDL_CD(self)->track[NUM2INT(track)].type); } static VALUE CD_trackLength(VALUE self, VALUE track) { return INT2FIX(Get_SDL_CD(self)->track[NUM2INT(track)].length); } static VALUE CD_s_framesToMSF(VALUE klass, VALUE frames) { int m, s, f; FRAMES_TO_MSF(NUM2INT(frames), &m, &s, &f); return rb_ary_new3(3, INT2FIX(m), INT2FIX(s), INT2FIX(f)); } static VALUE CD_s_MSFToFrames(VALUE klass, VALUE m, VALUE s, VALUE f) { return INT2FIX(MSF_TO_FRAMES(NUM2INT(m),NUM2INT(s),NUM2INT(f))); } static VALUE CD_close(VALUE self) { CD* cd = GetCD(self); if( !rubysdl_is_quit() && cd->cd ) SDL_CDClose(cd->cd); cd->cd = NULL; return Qnil; } static VALUE CD_closed(VALUE self) { return INT2BOOL(GetCD(self)->cd == NULL); } void rubysdl_init_CD(VALUE mSDL) { cCD = rb_define_class_under(mSDL, "CD", rb_cObject); rb_define_alloc_func(cCD, CD_s_alloc); rb_define_private_method(cCD, "initialize", CD_initialize, 1); rb_define_singleton_method(cCD, "numDrive", CD_s_numDrive, 0); rb_define_singleton_method(cCD, "indexName", CD_s_name, 1); rb_define_singleton_method(cCD, "open", CD_s_open, 1); rb_define_singleton_method(cCD, "framesToMSF", CD_s_framesToMSF,1); rb_define_singleton_method(cCD,"MSFToFrames",CD_s_MSFToFrames,3); rb_define_method(cCD, "status", CD_status, 0); rb_define_method(cCD, "play", CD_play, 2); rb_define_method(cCD, "playTracks", CD_playTracks, 4); rb_define_method(cCD, "pause", CD_pause, 0); rb_define_method(cCD, "resume", CD_resume, 0); rb_define_method(cCD, "stop", CD_stop, 0); rb_define_method(cCD, "eject", CD_eject, 0); rb_define_method(cCD, "numTracks", CD_numTracks, 0); rb_define_method(cCD, "currentTrack", CD_currentTrack, 0); rb_define_method(cCD, "currentFrame", CD_currentFrame, 0); rb_define_method(cCD, "trackType", CD_trackType, 1); rb_define_method(cCD, "trackLength", CD_trackLength, 1); rb_define_method(cCD, "close", CD_close, 0); rb_define_method(cCD, "closed?", CD_closed, 0); rb_define_const(cCD, "TRAYEMPTY", INT2NUM(CD_TRAYEMPTY)); rb_define_const(cCD, "STOPPED", INT2NUM(CD_STOPPED)); rb_define_const(cCD, "PLAYING", INT2NUM(CD_PLAYING)); rb_define_const(cCD, "PAUSED", INT2NUM(CD_PAUSED)); rb_define_const(cCD, "ERROR", INT2NUM(CD_ERROR)); rb_define_const(cCD, "AUDIO_TRACK", UINT2NUM(SDL_AUDIO_TRACK)); rb_define_const(cCD, "DATA_TRACK", UINT2NUM(SDL_DATA_TRACK)); rb_define_const(cCD, "FPS", UINT2NUM(CD_FPS)); } rubysdl-2.2.0/NEWS.en0000644000175000017500000002143112376257217014150 0ustar uwabamiuwabamiversion 2.2.0 Add following constants (thanks to oscdir for SDL::GL::*, thanks to Rafael Sevilla for SDL::Event::*) * SDL::Event::APPMOUSEFOCUS * SDL::Event::APPINPUTFOCUS * SDL::Event::APPACTIVE * SDL::GL::STEREO * SDL::GL::MULTISAMPLEBUFFERS * SDL::GL::MULTISAMPLESAMPLES * SDL::GL::ACCELERATED_VISUAL * SDL::GL::SWAP_CONTROL Add following methods(thanks to soutaro) * SDL::TTF#hinting * SDL::TTF#hinting= Rename SDL::Mixer::Wave.destroyed_ to SDL::Mixer::Wave.destroyed? (thanks to akicho8) version 2.1.3.1 Change the name of the option for bundled SGE Change the way of workaround for -Dmain=SDL_main on Windows platform version 2.1.3 Fix following methods * SDL::TTF#draw* Update documents Fix compilation problem on FreeBSD(Thanks Rusmir Dusko) Fix codes about multi-thread Bundle SGE(Please do not use this bundled SGE if you have other way to use SGE) version 2.1.2 Improbe the handling of strings Fix following methods * SDL::Surface#draw_bezier Update documents version 2.1.1 Fix a compile problem on MacOS X Rename sdl.so to sdl_ext Add following constants * SDL::Mixer::NO_FADING * SDL::Mixer::FADING_OUT * SDL::Mixer::FADING_IN * SDL::TRANSFORM_AA(for compatible with 1.x) * SDL::TRANSFORM_TMAP(for compatible with 1.x) * SDL::TRANSFORM_SAFE(for compatible with 1.x) Fix documents Remove obsolete documents version 2.1.0 add following methods * SDL::TTF#close * SDL::TTF#closed? * SDL::BMFont#close * SDL::BMFont#closed? * SDL::Kanji#close * SDL::Kanji#closed? * SDL::Surface#destroyed? * SDL::Joystick#closed? * SDL::Mixer::Wave#destroyed? * SDL::Mixer::Music#destroyed? * SDL::Kanji#get_coding_system modify documents Async following methods on Ruby 1.9 * SDL::Event#wait * SDL.delay Ruby m17n support on Ruby 1.9 * SDL::WM.set_caption * SDL::WM.caption * SDL::TTF#draw_solid * SDL::TTF#draw_blended * SDL::TTF#draw_shaded * SDL::TTF#render_solid * SDL::TTF#render_blended * SDL::TTF#render_shaded * SDL::Kanji#put * SDL::Kanji#putTate * SDL::SDLSKK#str Fix the bug of following methods * SDL::MPEG#move version 2.0.1b fix sample bug fix SDL::MPEG.info version 2.0.1 fix some compile errors/warnings raise SDL::Surface::VideoMemoryLost when video memory is lost when calling SDL::Surface.blit version 2.0 some changes for ruby 1.9 fix SDL_RWops code Fix/Improve documents Improve English documents Add following methods * SDL::Surface#load_bmp_from_string * SDL::Surface#load_from_string * SDL::Mixer::Wave#load_from_string * SDL::Mixer.playing_channels version 2.0 alpha 1 Remove following methods * SDL::Surface#draw_ellispe * SDL::Surface#draw_filled_ellispe * SDL::Surface#rotate_surface * SDL::Surface#rotate_scaled_surface * SDL.rotate * SDL.rotate_blit * SDL.rotate_scaled_blit * SDL.rotate_xy_scaled Remove Old SDL::Event, and rename SDL::Event2 to SDL::Event Change internal implementation Add following methods * SDL::Surface#destroy * SDL::Joystick#close * SDL::Mixer#close * SDL::Mixer::Wave#destroy * SDL::Mixer::Music#destroy Add module SDL::GL Change behavior of following methods * SDL::Surface#draw_line * SDL::Surface#draw_circle * SDL::Surface#draw_rect * SDL::Surface#draw_ellipse * SDL::Surface#draw_bezier Rename following methods * SDL.auto_lock? -> SDL::Surface.auto_lock? * SDL.auto_lock_on -> SDL::Surface.auto_lock_on * SDL.auto_lock_off -> SDL::Surface.auto_lock_off * SDL.transform_blit -> SDL::Surface#transform_blit * SDL.blitSurface -> SDL::Surface.blit * SDL.get_video_surface -> SDL::Screen.get * SDL.set_video_mode -> SDL::Screen.open * SDL.check_video_mode -> SDL::Screen.check_mode * SDL.list_modes -> SDL::Screen.list_modes * SDL.set_gamma -> SDL::Screen.set_gamma * SDL.get_gamma_ramp -> SDL::Screen.get_gamma_ramp * SDL.set_gamma_ramp -> SDL::Screen.set_gamma_ramp * SDL.video_driver_name -> SDL::Screen.driver_name * SDL.video_info -> SDL::Screen.info * SDL::Surface#get_rgb -> SDL::PixelFormat#get_rgb * SDL::Surface#get_rgba -> SDL::PixelFormat#get_rgba * SDL::Surface#map_rgb -> SDL::PixelFormat#map_rgb * SDL::Surface#map_rgba -> SDL::PixelFormat#map_rgba * SDL::Surface#get_palette -> SDL::PixelFormat#palette * SDL::Surface#bpp -> SDL::PixelFormat#bpp * SDL::Surface#bytes_per_pixel -> SDL::PixelFormat#bytes_per_pixel * SDL::Surface#[RGBA]mask -> SDL::PixelFormat#[RGBA]mask * SDL::Surface#[RGBA]shift -> SDL::PixelFormat#[RGBA]shift * SDL::Surface#[RGBA]loss -> SDL::PixelFormat#[RGBA]loss * SDL::Surface#colorkey -> SDL::PixelFormat#colorkey * SDL::Surface#alpha -> SDL::PixelFormat#alpha * SDL.get_GL_attr -> SDL::GL.get_attr * SDL.set_GL_attr -> SDL::GL.set_attr * SDL.GL_swap_buffers -> SDL::GL.swap_buffers Move following constants * GL_RED_SIZE -> GL::RED_SIZE * GL_GREEN_SIZE -> GL::GREEN_SIZE * GL_BLUE_SIZE -> GL::BLUE_SIZE * GL_ALPHA_SIZE -> GL::ALPHA_SIZE * GL_BUFFER_SIZE -> GL::BUFFER_SIZE * GL_DOUBLEBUFFER -> GL::DOUBLEBUFFER * GL_DEPTH_SIZE -> GL::DEPTH_SIZE * GL_STENCIL_SIZE -> GL::STENCIL_SIZE * GL_ACCUM_RED_SIZE -> GL::ACCUM_RED_SIZE * GL_ACCUM_GREEN_SIZE -> GL::ACCUM_GREEN_SIZE * GL_ACCUM_BLUE_SIZE -> GL::ACCUM_BLUE_SIZE * GL_ACCUM_ALPHA_SIZE -> GL::ACCUM_ALPHA_SIZE version 1.3.1 Fix the bug that we cannot compile when SMEPG is installed but SDL_mixer is not installed.(1.2.0's change is incomplete) Add following methods SDL::Surface#Rloss SDL::Surface#Gloss SDL::Surface#Bloss SDL::Surface#Aloss SDL::Surface#Rshift SDL::Surface#Gshift SDL::Surface#Bshift SDL::Surface#Ashift SDL::Surface#pitch SDL::Surface#bytes_per_pixel Fix following methods SDL::Surface.pixels version 1.3.0 Fix/Improve documents Add constant SDL::NOFRAME Add following methods SDL::Screen.update_rects SDL::Event2.pump SDL::Mixer.driver_name SDL::Surface.blit SDL::Mixer.driver_name Fix following methods SDL.video_driver_name version 1.2.0 Add Japanese reference Add following methods SDL::MPEG#render_final SDL::Surface.load_bmp_from_io SDL::Surface.load_from_io SDL::Mixer::Wave.load_from_io SDL::Mixer::Music.load_from_string Fix the bug that we cannot compile when SMEPG is installed but SDL_mixer is not installed. version 1.1.0 Change Japanese reference Add following methods SDL::CD.framesToMSF SDL::CD.MSFToFrames SDL::CD#in_drive? SDL::Mixer.playChannelTimed SDL::Mixer.fadeInChannel SDL::Mixer.fadeInChannelTimed SDL::Mixer.expire SDL::Mixer.fading SDL::Mixer.fadeOut SDL::Mixer.fadingMusic SDL::Mouse.show? SDL::CollisionMap#w SDL::CollisionMap#h SDL::BMFont#textSize SDL::TTF#init? Add following class SDL::Event2::VideoExpose Fix bugs in SDL::Key.press? SDL::TTF#familyName SDL::TTF#styleName SDL::BMFont Add some constants about key repeat version 1.0.0 Add following methods SDL::Surface#drawBezier SDL::Surface#drawAABezier SDL::Surface#drawBezierAlpha SDL::Surface#drawAABezierAlpha Fix bugs in SDL::MPEG#setDisplay version 0.9.5 Fix bugs in SDL::Surface#getPalette and SDL::Surface#copyRect Add SDL::WM.grubInput, SDL.quit, SDL.putenv and SDL.getenv Fix trivial typo Fix documentation of SDL::TTF#textSize version 0.9.4 Add SDL::Surface#pixels, SDL::Surface#[RGBA]mask and SDL::Surface.new_from Modyfy SDL::Surface.new Add a little OpenGL document version 0.9.3 Support bitmap font drawing with sge Support bdf font drawing with SDL_kanji Add following methods SDL::TTF#height SDL::TTF#ascent SDL::TTF#descent SDL::TTF#lineSkip SDL::Surface#copyRect Fix some warnings Fix a critical bug in SDLSKK module Setup OpenGL by default version 0.9.2 Primitive draw with anti-alias and alpha blending is now available. Modify SDL.transformBlit for alpha blending. version 0.9.1 Fix two critical bugs in event module. version 0.9 Support SDLSKK 0.4, and stop supporting 0.3. Add collision detection function. ( thanks to Wayne Conrad ) Improve MPEG playback function. Enable to load multiple mpeg files. Add sample. ( thanks to Simon Strandgaard ) version 0.8.3 Add following methods because of typo. ( thanks to Wayne Conrad ) SDL::Surface#drawEllipse SDL::Surface#drawFilledEllipse Fix following method. ( thanks to moumar ) SDL.videoInfo version 0.8.2 Support SDLSKK 0.3, and stop supporting 0.2. Bug fix about Joystick subsystem. Add following methods. SDL::Screen#toggleFullScreen SDL::Key.getKeyName Add aliases into documents. version 0.8.1 bug fix version 0.8 Support SDLSKK. Change SDL's finalizer (Thanks to Tamura). Change some methods' name. SDL::CD.name -> SDL::CD.indexName SDL::Joystick.name -> SDL::Joystick.indexName Add Ruby like ( uncapitalized and separated by underbars ) aliases. Add following methods. SDL::Mixer.allocateChannels SDL::TTF#renderSolidUTF8 SDL::TTF#renderBlendedUTF8 SDL::TTF#renderShadedUTF8 SDL::TTF#faces SDL::TTF#fixedWidth? SDL::TTF#familyName SDL::TTF#styleName SDL.videoDriverName SDL.getGammaRamp SDL.setGammaRamp SDL::Surface#saveBMP SDL::Surface#displayFormatAlpha SDL::Surface#getClipRect SDL.autoLock? SDL.autoLockON SDL.autoLockOFF Extend following method. SDL.blitSurace2rubysdl-2.2.0/rubysdl.gemspec0000644000175000017500000000133112376257217016076 0ustar uwabamiuwabami# -*- Ruby -*- Gem::Specification.new do |spec| spec.name = "rubysdl" spec.version = "2.2.0" spec.summary = "The simple ruby extension library to use SDL" spec.description = <<-EOS Ruby/SDL is an extension library to use SDL(Simple DirectMedia Layer). This library enables you to control audio, keyboard, mouse, joystick, 3D hardware via OpenGL, and 2D video framebuffer. Ruby/SDL is used by games and visual demos. EOS spec.license = "LGPL" spec.author = "Ohbayashi Ippei" spec.email = "ohai@kmc.gr.jp" spec.homepage = "http://www.kmc.gr.jp/~ohai/rubysdl.en.html" spec.files = `git ls-files`.split(/\n/) spec.test_files = [] spec.extensions = ["extconf.rb"] spec.has_rdoc = false end rubysdl-2.2.0/MANIFEST0000644000175000017500000000307212376257217014202 0ustar uwabamiuwabamiMANIFEST README.ja README.en NEWS.ja NEWS.en LICENSE depend extconf.rb lib/rubysdl_aliases.rb lib/sdl.rb lib/rubysdl_compatible_ver1.rb rubysdl.h rubysdl_ref.rd rubysdl_ref.html rubysdl_ref.en.rd rubysdl_ref.en.html rubysdl_event.c rubysdl_event_key.c rubysdl_main.c rubysdl_mixer.c rubysdl_mouse.c rubysdl_sge_video.c rubysdl_time.c rubysdl_video.c rubysdl_wm.c rubysdl_ttf.c rubysdl_cdrom.c rubysdl_joystick.c rubysdl_image.c rubysdl_opengl.c rubysdl_pixel.c rubysdl_smpeg.c rubysdl_sdlskk.c rubysdl_kanji.c rubysdl_rwops.c SDL_kanji.c SDL_kanji.h sample/testsprite.rb sample/playwave.rb sample/movesp.rb sample/alpha.rb sample/sgetest.rb sample/font.rb sample/cdrom.rb sample/playmod.rb sample/testgl.rb sample/testgl_old.rb sample/icon.bmp sample/cursor.rb sample/event2.rb sample/joy2.rb sample/plaympeg.rb sample/cursor.bmp sample/transformblit.rb sample/randrect.rb sample/sdlskk.rb sample/ellipses.rb sample/collision.rb sample/stetris.rb sample/aadraw.rb sample/alphadraw.rb sample/fpstimer.rb sample/bfont.rb sample/font.bmp sample/kanji.rb sample/sample.ttf sample/load_from_io.rb sample/icon.png sample/icon.bmp.gz doc/Makefile doc/rsd.rb doc/cdrom.rsd doc/collision.rsd doc/event.rsd doc/font.rsd doc/general.rsd doc/init.rsd doc/joystick.rsd doc/mixer.rsd doc/mpeg.rsd doc/sdlskk.rsd doc/time.rsd doc/video.rsd doc/wm.rsd doc-en/Makefile doc-en/cdrom.rsd doc-en/collision.rsd doc-en/event.rsd doc-en/font.rsd doc-en/general.rsd doc-en/init.rsd doc-en/joystick.rsd doc-en/mixer.rsd doc-en/mpeg.rsd doc-en/opengl.rsd doc-en/sdlskk.rsd doc-en/time.rsd doc-en/video.rsd doc-en/wm.rsd rubysdl-2.2.0/rubysdl_event_key.c0000644000175000017500000004141412376257217016754 0ustar uwabamiuwabami/* Ruby/SDL Ruby extension library for SDL Copyright (C) 2001-2007 Ohbayashi Ippei This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "rubysdl.h" static Uint8* key_state = NULL; static SDLMod mod_state; static VALUE mKey; static void define_const(void) { rb_define_const(mKey, "UNKNOWN", INT2NUM(SDLK_UNKNOWN)); rb_define_const(mKey, "FIRST", INT2NUM(SDLK_FIRST)); rb_define_const(mKey, "BACKSPACE", INT2NUM(SDLK_BACKSPACE)); rb_define_const(mKey, "TAB", INT2NUM(SDLK_TAB)); rb_define_const(mKey, "CLEAR", INT2NUM(SDLK_CLEAR)); rb_define_const(mKey, "RETURN", INT2NUM(SDLK_RETURN)); rb_define_const(mKey, "PAUSE", INT2NUM(SDLK_PAUSE)); rb_define_const(mKey, "ESCAPE", INT2NUM(SDLK_ESCAPE)); rb_define_const(mKey, "SPACE", INT2NUM(SDLK_SPACE)); rb_define_const(mKey, "EXCLAIM", INT2NUM(SDLK_EXCLAIM)); rb_define_const(mKey, "QUOTEDBL", INT2NUM(SDLK_QUOTEDBL)); rb_define_const(mKey, "HASH", INT2NUM(SDLK_HASH)); rb_define_const(mKey, "DOLLAR", INT2NUM(SDLK_DOLLAR)); rb_define_const(mKey, "AMPERSAND", INT2NUM(SDLK_AMPERSAND)); rb_define_const(mKey, "QUOTE", INT2NUM(SDLK_QUOTE)); rb_define_const(mKey, "LEFTPAREN", INT2NUM(SDLK_LEFTPAREN)); rb_define_const(mKey, "RIGHTPAREN", INT2NUM(SDLK_RIGHTPAREN)); rb_define_const(mKey, "ASTERISK", INT2NUM(SDLK_ASTERISK)); rb_define_const(mKey, "PLUS", INT2NUM(SDLK_PLUS)); rb_define_const(mKey, "COMMA", INT2NUM(SDLK_COMMA)); rb_define_const(mKey, "MINUS", INT2NUM(SDLK_MINUS)); rb_define_const(mKey, "PERIOD", INT2NUM(SDLK_PERIOD)); rb_define_const(mKey, "SLASH", INT2NUM(SDLK_SLASH)); rb_define_const(mKey, "K0", INT2NUM(SDLK_0)); rb_define_const(mKey, "K1", INT2NUM(SDLK_1)); rb_define_const(mKey, "K2", INT2NUM(SDLK_2)); rb_define_const(mKey, "K3", INT2NUM(SDLK_3)); rb_define_const(mKey, "K4", INT2NUM(SDLK_4)); rb_define_const(mKey, "K5", INT2NUM(SDLK_5)); rb_define_const(mKey, "K6", INT2NUM(SDLK_6)); rb_define_const(mKey, "K7", INT2NUM(SDLK_7)); rb_define_const(mKey, "K8", INT2NUM(SDLK_8)); rb_define_const(mKey, "K9", INT2NUM(SDLK_9)); rb_define_const(mKey, "COLON", INT2NUM(SDLK_COLON)); rb_define_const(mKey, "SEMICOLON", INT2NUM(SDLK_SEMICOLON)); rb_define_const(mKey, "LESS", INT2NUM(SDLK_LESS)); rb_define_const(mKey, "EQUALS", INT2NUM(SDLK_EQUALS)); rb_define_const(mKey, "GREATER", INT2NUM(SDLK_GREATER)); rb_define_const(mKey, "QUESTION", INT2NUM(SDLK_QUESTION)); rb_define_const(mKey, "AT", INT2NUM(SDLK_AT)); /* Skip uppercase letters */ rb_define_const(mKey, "LEFTBRACKET", INT2NUM(SDLK_LEFTBRACKET)); rb_define_const(mKey, "BACKSLASH", INT2NUM(SDLK_BACKSLASH)); rb_define_const(mKey, "RIGHTBRACKET", INT2NUM(SDLK_RIGHTBRACKET)); rb_define_const(mKey, "CARET", INT2NUM(SDLK_CARET)); rb_define_const(mKey, "UNDERSCORE", INT2NUM(SDLK_UNDERSCORE)); rb_define_const(mKey, "BACKQUOTE", INT2NUM(SDLK_BACKQUOTE)); rb_define_const(mKey, "A", INT2NUM(SDLK_a)); rb_define_const(mKey, "B", INT2NUM(SDLK_b)); rb_define_const(mKey, "C", INT2NUM(SDLK_c)); rb_define_const(mKey, "D", INT2NUM(SDLK_d)); rb_define_const(mKey, "E", INT2NUM(SDLK_e)); rb_define_const(mKey, "F", INT2NUM(SDLK_f)); rb_define_const(mKey, "G", INT2NUM(SDLK_g)); rb_define_const(mKey, "H", INT2NUM(SDLK_h)); rb_define_const(mKey, "I", INT2NUM(SDLK_i)); rb_define_const(mKey, "J", INT2NUM(SDLK_j)); rb_define_const(mKey, "K", INT2NUM(SDLK_k)); rb_define_const(mKey, "L", INT2NUM(SDLK_l)); rb_define_const(mKey, "M", INT2NUM(SDLK_m)); rb_define_const(mKey, "N", INT2NUM(SDLK_n)); rb_define_const(mKey, "O", INT2NUM(SDLK_o)); rb_define_const(mKey, "P", INT2NUM(SDLK_p)); rb_define_const(mKey, "Q", INT2NUM(SDLK_q)); rb_define_const(mKey, "R", INT2NUM(SDLK_r)); rb_define_const(mKey, "S", INT2NUM(SDLK_s)); rb_define_const(mKey, "T", INT2NUM(SDLK_t)); rb_define_const(mKey, "U", INT2NUM(SDLK_u)); rb_define_const(mKey, "V", INT2NUM(SDLK_v)); rb_define_const(mKey, "W", INT2NUM(SDLK_w)); rb_define_const(mKey, "X", INT2NUM(SDLK_x)); rb_define_const(mKey, "Y", INT2NUM(SDLK_y)); rb_define_const(mKey, "Z", INT2NUM(SDLK_z)); rb_define_const(mKey, "DELETE", INT2NUM(SDLK_DELETE)); /* End of ASCII mapped keysyms */ /* International keyboard syms */ rb_define_const(mKey, "WORLD_0", INT2NUM(SDLK_WORLD_0)); rb_define_const(mKey, "WORLD_1", INT2NUM(SDLK_WORLD_1)); rb_define_const(mKey, "WORLD_2", INT2NUM(SDLK_WORLD_2)); rb_define_const(mKey, "WORLD_3", INT2NUM(SDLK_WORLD_3)); rb_define_const(mKey, "WORLD_4", INT2NUM(SDLK_WORLD_4)); rb_define_const(mKey, "WORLD_5", INT2NUM(SDLK_WORLD_5)); rb_define_const(mKey, "WORLD_6", INT2NUM(SDLK_WORLD_6)); rb_define_const(mKey, "WORLD_7", INT2NUM(SDLK_WORLD_7)); rb_define_const(mKey, "WORLD_8", INT2NUM(SDLK_WORLD_8)); rb_define_const(mKey, "WORLD_9", INT2NUM(SDLK_WORLD_9)); rb_define_const(mKey, "WORLD_10", INT2NUM(SDLK_WORLD_10)); rb_define_const(mKey, "WORLD_11", INT2NUM(SDLK_WORLD_11)); rb_define_const(mKey, "WORLD_12", INT2NUM(SDLK_WORLD_12)); rb_define_const(mKey, "WORLD_13", INT2NUM(SDLK_WORLD_13)); rb_define_const(mKey, "WORLD_14", INT2NUM(SDLK_WORLD_14)); rb_define_const(mKey, "WORLD_15", INT2NUM(SDLK_WORLD_15)); rb_define_const(mKey, "WORLD_16", INT2NUM(SDLK_WORLD_16)); rb_define_const(mKey, "WORLD_17", INT2NUM(SDLK_WORLD_17)); rb_define_const(mKey, "WORLD_18", INT2NUM(SDLK_WORLD_18)); rb_define_const(mKey, "WORLD_19", INT2NUM(SDLK_WORLD_19)); rb_define_const(mKey, "WORLD_20", INT2NUM(SDLK_WORLD_20)); rb_define_const(mKey, "WORLD_21", INT2NUM(SDLK_WORLD_21)); rb_define_const(mKey, "WORLD_22", INT2NUM(SDLK_WORLD_22)); rb_define_const(mKey, "WORLD_23", INT2NUM(SDLK_WORLD_23)); rb_define_const(mKey, "WORLD_24", INT2NUM(SDLK_WORLD_24)); rb_define_const(mKey, "WORLD_25", INT2NUM(SDLK_WORLD_25)); rb_define_const(mKey, "WORLD_26", INT2NUM(SDLK_WORLD_26)); rb_define_const(mKey, "WORLD_27", INT2NUM(SDLK_WORLD_27)); rb_define_const(mKey, "WORLD_28", INT2NUM(SDLK_WORLD_28)); rb_define_const(mKey, "WORLD_29", INT2NUM(SDLK_WORLD_29)); rb_define_const(mKey, "WORLD_30", INT2NUM(SDLK_WORLD_30)); rb_define_const(mKey, "WORLD_31", INT2NUM(SDLK_WORLD_31)); rb_define_const(mKey, "WORLD_32", INT2NUM(SDLK_WORLD_32)); rb_define_const(mKey, "WORLD_33", INT2NUM(SDLK_WORLD_33)); rb_define_const(mKey, "WORLD_34", INT2NUM(SDLK_WORLD_34)); rb_define_const(mKey, "WORLD_35", INT2NUM(SDLK_WORLD_35)); rb_define_const(mKey, "WORLD_36", INT2NUM(SDLK_WORLD_36)); rb_define_const(mKey, "WORLD_37", INT2NUM(SDLK_WORLD_37)); rb_define_const(mKey, "WORLD_38", INT2NUM(SDLK_WORLD_38)); rb_define_const(mKey, "WORLD_39", INT2NUM(SDLK_WORLD_39)); rb_define_const(mKey, "WORLD_40", INT2NUM(SDLK_WORLD_40)); rb_define_const(mKey, "WORLD_41", INT2NUM(SDLK_WORLD_41)); rb_define_const(mKey, "WORLD_42", INT2NUM(SDLK_WORLD_42)); rb_define_const(mKey, "WORLD_43", INT2NUM(SDLK_WORLD_43)); rb_define_const(mKey, "WORLD_44", INT2NUM(SDLK_WORLD_44)); rb_define_const(mKey, "WORLD_45", INT2NUM(SDLK_WORLD_45)); rb_define_const(mKey, "WORLD_46", INT2NUM(SDLK_WORLD_46)); rb_define_const(mKey, "WORLD_47", INT2NUM(SDLK_WORLD_47)); rb_define_const(mKey, "WORLD_48", INT2NUM(SDLK_WORLD_48)); rb_define_const(mKey, "WORLD_49", INT2NUM(SDLK_WORLD_49)); rb_define_const(mKey, "WORLD_50", INT2NUM(SDLK_WORLD_50)); rb_define_const(mKey, "WORLD_51", INT2NUM(SDLK_WORLD_51)); rb_define_const(mKey, "WORLD_52", INT2NUM(SDLK_WORLD_52)); rb_define_const(mKey, "WORLD_53", INT2NUM(SDLK_WORLD_53)); rb_define_const(mKey, "WORLD_54", INT2NUM(SDLK_WORLD_54)); rb_define_const(mKey, "WORLD_55", INT2NUM(SDLK_WORLD_55)); rb_define_const(mKey, "WORLD_56", INT2NUM(SDLK_WORLD_56)); rb_define_const(mKey, "WORLD_57", INT2NUM(SDLK_WORLD_57)); rb_define_const(mKey, "WORLD_58", INT2NUM(SDLK_WORLD_58)); rb_define_const(mKey, "WORLD_59", INT2NUM(SDLK_WORLD_59)); rb_define_const(mKey, "WORLD_60", INT2NUM(SDLK_WORLD_60)); rb_define_const(mKey, "WORLD_61", INT2NUM(SDLK_WORLD_61)); rb_define_const(mKey, "WORLD_62", INT2NUM(SDLK_WORLD_62)); rb_define_const(mKey, "WORLD_63", INT2NUM(SDLK_WORLD_63)); rb_define_const(mKey, "WORLD_64", INT2NUM(SDLK_WORLD_64)); rb_define_const(mKey, "WORLD_65", INT2NUM(SDLK_WORLD_65)); rb_define_const(mKey, "WORLD_66", INT2NUM(SDLK_WORLD_66)); rb_define_const(mKey, "WORLD_67", INT2NUM(SDLK_WORLD_67)); rb_define_const(mKey, "WORLD_68", INT2NUM(SDLK_WORLD_68)); rb_define_const(mKey, "WORLD_69", INT2NUM(SDLK_WORLD_69)); rb_define_const(mKey, "WORLD_70", INT2NUM(SDLK_WORLD_70)); rb_define_const(mKey, "WORLD_71", INT2NUM(SDLK_WORLD_71)); rb_define_const(mKey, "WORLD_72", INT2NUM(SDLK_WORLD_72)); rb_define_const(mKey, "WORLD_73", INT2NUM(SDLK_WORLD_73)); rb_define_const(mKey, "WORLD_74", INT2NUM(SDLK_WORLD_74)); rb_define_const(mKey, "WORLD_75", INT2NUM(SDLK_WORLD_75)); rb_define_const(mKey, "WORLD_76", INT2NUM(SDLK_WORLD_76)); rb_define_const(mKey, "WORLD_77", INT2NUM(SDLK_WORLD_77)); rb_define_const(mKey, "WORLD_78", INT2NUM(SDLK_WORLD_78)); rb_define_const(mKey, "WORLD_79", INT2NUM(SDLK_WORLD_79)); rb_define_const(mKey, "WORLD_80", INT2NUM(SDLK_WORLD_80)); rb_define_const(mKey, "WORLD_81", INT2NUM(SDLK_WORLD_81)); rb_define_const(mKey, "WORLD_82", INT2NUM(SDLK_WORLD_82)); rb_define_const(mKey, "WORLD_83", INT2NUM(SDLK_WORLD_83)); rb_define_const(mKey, "WORLD_84", INT2NUM(SDLK_WORLD_84)); rb_define_const(mKey, "WORLD_85", INT2NUM(SDLK_WORLD_85)); rb_define_const(mKey, "WORLD_86", INT2NUM(SDLK_WORLD_86)); rb_define_const(mKey, "WORLD_87", INT2NUM(SDLK_WORLD_87)); rb_define_const(mKey, "WORLD_88", INT2NUM(SDLK_WORLD_88)); rb_define_const(mKey, "WORLD_89", INT2NUM(SDLK_WORLD_89)); rb_define_const(mKey, "WORLD_90", INT2NUM(SDLK_WORLD_90)); rb_define_const(mKey, "WORLD_91", INT2NUM(SDLK_WORLD_91)); rb_define_const(mKey, "WORLD_92", INT2NUM(SDLK_WORLD_92)); rb_define_const(mKey, "WORLD_93", INT2NUM(SDLK_WORLD_93)); rb_define_const(mKey, "WORLD_94", INT2NUM(SDLK_WORLD_94)); rb_define_const(mKey, "WORLD_95", INT2NUM(SDLK_WORLD_95)); /* Numeric keypad */ rb_define_const(mKey, "KP0", INT2NUM(SDLK_KP0)); rb_define_const(mKey, "KP1", INT2NUM(SDLK_KP1)); rb_define_const(mKey, "KP2", INT2NUM(SDLK_KP2)); rb_define_const(mKey, "KP3", INT2NUM(SDLK_KP3)); rb_define_const(mKey, "KP4", INT2NUM(SDLK_KP4)); rb_define_const(mKey, "KP5", INT2NUM(SDLK_KP5)); rb_define_const(mKey, "KP6", INT2NUM(SDLK_KP6)); rb_define_const(mKey, "KP7", INT2NUM(SDLK_KP7)); rb_define_const(mKey, "KP8", INT2NUM(SDLK_KP8)); rb_define_const(mKey, "KP9", INT2NUM(SDLK_KP9)); rb_define_const(mKey, "KP_PERIOD", INT2NUM(SDLK_KP_PERIOD)); rb_define_const(mKey, "KP_DIVIDE", INT2NUM(SDLK_KP_DIVIDE)); rb_define_const(mKey, "KP_MULTIPLY", INT2NUM(SDLK_KP_MULTIPLY)); rb_define_const(mKey, "KP_MINUS", INT2NUM(SDLK_KP_MINUS)); rb_define_const(mKey, "KP_PLUS", INT2NUM(SDLK_KP_PLUS)); rb_define_const(mKey, "KP_ENTER", INT2NUM(SDLK_KP_ENTER)); rb_define_const(mKey, "KP_EQUALS", INT2NUM(SDLK_KP_EQUALS)); /* Arrows + Home/End pad */ rb_define_const(mKey, "UP", INT2NUM(SDLK_UP)); rb_define_const(mKey, "DOWN", INT2NUM(SDLK_DOWN)); rb_define_const(mKey, "RIGHT", INT2NUM(SDLK_RIGHT)); rb_define_const(mKey, "LEFT", INT2NUM(SDLK_LEFT)); rb_define_const(mKey, "INSERT", INT2NUM(SDLK_INSERT)); rb_define_const(mKey, "HOME", INT2NUM(SDLK_HOME)); rb_define_const(mKey, "END", INT2NUM(SDLK_END)); rb_define_const(mKey, "PAGEUP", INT2NUM(SDLK_PAGEUP)); rb_define_const(mKey, "PAGEDOWN", INT2NUM(SDLK_PAGEDOWN)); /* Function keys */ rb_define_const(mKey, "F1", INT2NUM(SDLK_F1)); rb_define_const(mKey, "F2", INT2NUM(SDLK_F2)); rb_define_const(mKey, "F3", INT2NUM(SDLK_F3)); rb_define_const(mKey, "F4", INT2NUM(SDLK_F4)); rb_define_const(mKey, "F5", INT2NUM(SDLK_F5)); rb_define_const(mKey, "F6", INT2NUM(SDLK_F6)); rb_define_const(mKey, "F7", INT2NUM(SDLK_F7)); rb_define_const(mKey, "F8", INT2NUM(SDLK_F8)); rb_define_const(mKey, "F9", INT2NUM(SDLK_F9)); rb_define_const(mKey, "F10", INT2NUM(SDLK_F10)); rb_define_const(mKey, "F11", INT2NUM(SDLK_F11)); rb_define_const(mKey, "F12", INT2NUM(SDLK_F12)); rb_define_const(mKey, "F13", INT2NUM(SDLK_F13)); rb_define_const(mKey, "F14", INT2NUM(SDLK_F14)); rb_define_const(mKey, "F15", INT2NUM(SDLK_F15)); /* Key state modifier keys */ rb_define_const(mKey, "NUMLOCK", INT2NUM(SDLK_NUMLOCK)); rb_define_const(mKey, "CAPSLOCK", INT2NUM(SDLK_CAPSLOCK)); rb_define_const(mKey, "SCROLLOCK", INT2NUM(SDLK_SCROLLOCK)); rb_define_const(mKey, "RSHIFT", INT2NUM(SDLK_RSHIFT)); rb_define_const(mKey, "LSHIFT", INT2NUM(SDLK_LSHIFT)); rb_define_const(mKey, "RCTRL", INT2NUM(SDLK_RCTRL)); rb_define_const(mKey, "LCTRL", INT2NUM(SDLK_LCTRL)); rb_define_const(mKey, "RALT", INT2NUM(SDLK_RALT)); rb_define_const(mKey, "LALT", INT2NUM(SDLK_LALT)); rb_define_const(mKey, "RMETA", INT2NUM(SDLK_RMETA)); rb_define_const(mKey, "LMETA", INT2NUM(SDLK_LMETA)); rb_define_const(mKey, "LSUPER", INT2NUM(SDLK_LSUPER)); rb_define_const(mKey, "RSUPER", INT2NUM(SDLK_RSUPER)); rb_define_const(mKey, "MODE", INT2NUM(SDLK_MODE)); /* Miscellaneous function keys */ rb_define_const(mKey, "HELP", INT2NUM(SDLK_HELP)); rb_define_const(mKey, "PRINT", INT2NUM(SDLK_PRINT)); rb_define_const(mKey, "SYSREQ", INT2NUM(SDLK_SYSREQ)); rb_define_const(mKey, "BREAK", INT2NUM(SDLK_BREAK)); rb_define_const(mKey, "MENU", INT2NUM(SDLK_MENU)); rb_define_const(mKey, "POWER", INT2NUM(SDLK_POWER)); rb_define_const(mKey, "EURO", INT2NUM(SDLK_EURO)); rb_define_const(mKey, "LAST", INT2NUM(SDLK_LAST)); /* key mods */ rb_define_const(mKey, "MOD_NONE", UINT2NUM(KMOD_NONE)); rb_define_const(mKey, "MOD_LSHIFT", UINT2NUM(KMOD_LSHIFT)); rb_define_const(mKey, "MOD_RSHIFT", UINT2NUM(KMOD_RSHIFT)); rb_define_const(mKey, "MOD_LCTRL", UINT2NUM(KMOD_LCTRL)); rb_define_const(mKey, "MOD_RCTRL", UINT2NUM(KMOD_RCTRL)); rb_define_const(mKey, "MOD_LALT", UINT2NUM(KMOD_LALT)); rb_define_const(mKey, "MOD_RALT", UINT2NUM(KMOD_RALT)); rb_define_const(mKey, "MOD_LMETA", UINT2NUM(KMOD_LMETA)); rb_define_const(mKey, "MOD_RMETA", UINT2NUM(KMOD_RMETA)); rb_define_const(mKey, "MOD_NUM", UINT2NUM(KMOD_NUM)); rb_define_const(mKey, "MOD_CAPS", UINT2NUM(KMOD_CAPS)); rb_define_const(mKey, "MOD_MODE", UINT2NUM(KMOD_MODE)); rb_define_const(mKey, "MOD_RESERVED", UINT2NUM(KMOD_RESERVED)); rb_define_const(mKey, "MOD_CTRL", UINT2NUM(KMOD_CTRL)); rb_define_const(mKey, "MOD_SHIFT", UINT2NUM(KMOD_SHIFT)); rb_define_const(mKey, "MOD_ALT", UINT2NUM(KMOD_ALT)); rb_define_const(mKey, "MOD_META", UINT2NUM(KMOD_META)); /* key repeat constants*/ rb_define_const(mKey, "DEFAULT_REPEAT_DELAY", INT2NUM(SDL_DEFAULT_REPEAT_DELAY)); rb_define_const(mKey, "DEFAULT_REPEAT_INTERVAL", INT2NUM(SDL_DEFAULT_REPEAT_INTERVAL)); } static VALUE Key_s_scan(VALUE mod) { key_state=SDL_GetKeyState(NULL); mod_state=SDL_GetModState(); return Qnil; } static VALUE Key_s_press_p(VALUE mod, VALUE keysym) { int sym = NUM2INT(keysym); if(sym < SDLK_FIRST || SDLK_LAST < sym ) rb_raise(eSDLError, "%d is out of key", sym); if(key_state == NULL) rb_raise(eSDLError, "You should call SDL::Key#scan before calling SDL::Key#press?"); return INT2BOOL(key_state[sym]==SDL_PRESSED); } static VALUE Key_s_modState(VALUE mod) { return UINT2NUM(mod_state); } static VALUE Key_s_enableKeyRepeat(VALUE mod, VALUE delay, VALUE interval) { if( SDL_EnableKeyRepeat(NUM2INT(delay), NUM2INT(interval))==-1 ){ rb_raise(eSDLError, "enable key repeat fail: %s", SDL_GetError()); } return Qnil; } static VALUE Key_s_disableKeyRepeat(VALUE mod) { if( SDL_EnableKeyRepeat(0, 0)==-1 ){ rb_raise(eSDLError, "disable key repeat fail: %s", SDL_GetError()); } return Qnil; } static VALUE Key_s_getKeyName(VALUE mod, VALUE key) { return rb_str_new2(SDL_GetKeyName(NUM2UINT(key))); } void rubysdl_init_Key(VALUE mSDL) { mKey = rb_define_module_under(mSDL, "Key"); rb_define_module_function(mKey, "scan", Key_s_scan, 0); rb_define_module_function(mKey, "press?", Key_s_press_p, 1); rb_define_module_function(mKey, "modState", Key_s_modState, 0); rb_define_module_function(mKey, "enableKeyRepeat", Key_s_enableKeyRepeat, 2); rb_define_module_function(mKey, "disableKeyRepeat", Key_s_disableKeyRepeat, 0); rb_define_module_function(mKey, "getKeyName", Key_s_getKeyName, 1); define_const(); } rubysdl-2.2.0/README.en0000644000175000017500000001034512376257217014333 0ustar uwabamiuwabami Ruby/SDL 2.2.0 Ohbayashi Ippei = What's Ruby/SDL Ruby/SDL is the ruby extension library to use SDL. SDL(Simple DirectMedia Layer) is a cross-platform multimedia library designed to provide fast access to the graphics framebuffer and audio devices. See http://www.libsdl.org/ if you want to know SDL in detail. = Platform This library supports Linux, Win32, MacOS X. This library perhaps works on FreeBSD and other standard Unix-like systems. = Library Needed Ruby/SDL needs Ruby and SDL and optionally uses SDL_image, SDL_mixer, SDL_ttf, SGE, OpenGL and SMPEG. Indispensable Ruby http://www.ruby-lang.org/ SDL http://www.libsdl.org/ Optional SDL_mixer http://www.libsdl.org/projects/SDL_mixer/index.html SDL_ttf http://www.libsdl.org/projects/SDL_ttf/index.html SDL_image http://www.libsdl.org/projects/SDL_image/index.html SGE http://www.etek.chalmers.se/~e8cal1/sge/ SMPEG http://www.icculus.org/smpeg/ SDLSKK http://www.kmc.gr.jp/~ohai/sdlskk.en.html = INSTALL Some packages are available: Debian's .deb, FreeBSD's ports, or Windows' zipfile. RubyGems are also available. You can install Ruby/SDL: gem install rubysdl You can install from source code as follows: (1)install Ruby See Ruby's document and install. (2)install SDL Extract SDL's source and run './configure'. And run 'make','make install'. (3)install SGE Run 'make' and 'make install'. (4)install SDL_mixer, SDL_ttf, SDL_image, SMPEG and SDLSKK See documents of these libraries and install them . (5)install this extension library,Ruby/SDL Run 'ruby extconf.rb','make' and 'make install'. (6) (Mac OS X user only) install rsdl Run 'gem install rsdl'. rsdl is a wrapper of the Ruby interpreter. This wrapper prepares Cocoa framework before running the interpreter. = Use SGE without installing the library You can use SGE without intalling: gem install rubysdl -- --enable-bundled-sge or ruby extconf.rb --enable-bundled-sge However, please do not use this option if you have other way. Please install SGE separately if possible. = USE Ruby/SDL Write "require 'sdl'" in your Ruby script. If your system is OS X, you must use rsdl command as an interpreter instead of ruby command. See following documents and samples if you want to know the detail. sample/*.rb Ruby/SDL samples. In some scripts, you have to prepare data such as "sample.wav" and "sample.mpg". rubysdl_ref.en.html The reference manual rubysdl_ref.en.rd RD style reference manual(the contents is same as rubysdl_ref.en.html) documents of SDL This is in SDL archive. Please read this when you want to know what does't describe these documents. = OpenGL You can use OpenGL with this library. (1) Setup OpenGL and SDL. (2) Install ruby-opengl (http://ruby-opengl.rubyforge.org/) (3) Run "ruby extconf.rb", "make", and "make install" (4) Write "require 'sdl'; require 'opengl'" in your script. We use OpenGL through ruby-opengl. Please see SDL's document,OpenGL document and sample/testgl.rb . = LICENSE This library is distributed under GNU LGPL version 2.1 or later, which can be found in the file "LICENSE". But samples, the Ruby scripts sample/*.rb, are not under LGPL, and you can use their files freely. = Thanks Thanks to ... Tamura : some patches and advertising Akinori MUSHA : Porting on FreeBSD Danny van Bruggen : some ideas are from his library "RUDL" akira yamada : patch of SDL::TTF, making packages of Vine and Debian. Wayne Conrad : some patches Christian Neukirchen, Kent Dahl : send a patch Keffin Barnaby : some patches Rorien Dunn, Dennis Ranke, Keita Urashima : bug reports and useful information Yusuke TABATA : introduce me into SDL world SDLdoc Japanese translation project : base of Ruby/SDL's reference manual Hara Yutaka: Sample TrueTypeFont, MacOS X support Members of #sdl-fan-jp @ FriendChat: bug reports and advices Cyross Makoto: Windows support Dwayne C. Litzenberger: Some patches = OTHER Some functions, especially SDL::MPEG methods and pallete handling methods, are not tested. = AUTHORS Ippei Obayashi: main developer Cyross Makoto: Windows suppport yhara: MacOS X support Please send comments and bug reports to the author. Author's mail address: ohai@kmc.gr.jp rubysdl-2.2.0/rubysdl_time.c0000644000175000017500000000223312376257217015715 0ustar uwabamiuwabami/* Ruby/SDL Ruby extension library for SDL Copyright (C) 2001-2007 Ohbayashi Ippei This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "rubysdl.h" static VALUE sdl_getTicks(VALUE mod) { return UINT2NUM(SDL_GetTicks()); } static VALUE sdl_delay(VALUE mod,VALUE ms) { Uint32 t = NUM2UINT(ms); SDL_Delay(t); return Qnil; } void rubysdl_init_time(VALUE mSDL) { rb_define_module_function(mSDL,"getTicks",sdl_getTicks,0); rb_define_module_function(mSDL,"delay",sdl_delay,1); } rubysdl-2.2.0/rubysdl_image.c0000644000175000017500000000450512376257217016045 0ustar uwabamiuwabami/* Ruby/SDL Ruby extension library for SDL Copyright (C) 2001-2007 Ohbayashi Ippei This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "rubysdl.h" #ifdef HAVE_SDL_IMAGE #include static VALUE Surface_s_load(VALUE klass, VALUE filename) { SDL_Surface *surface; ExportFilenameStringValue(filename); surface = IMG_Load(RSTRING_PTR(filename)); if(surface == NULL) rb_raise(eSDLError,"Couldn't load %s: %s", RSTRING_PTR(filename), SDL_GetError()); return Surface_create(surface); } static VALUE Surface_s_loadFromIO(VALUE class,VALUE io) { volatile VALUE guard = io; SDL_Surface *surface; surface = IMG_Load_RW(rubysdl_RWops_from_ruby_obj(io), 1); if(surface==NULL){ rb_raise(eSDLError,"Couldn't load image from IO: %s", SDL_GetError()); } RB_GC_GUARD(guard); return Surface_create(surface); } static VALUE Surface_s_loadFromString(VALUE class,VALUE str) { SDL_Surface *surface; SafeStringValue(str); surface = IMG_Load_RW(SDL_RWFromConstMem(RSTRING_PTR(str), RSTRING_LEN(str)), 1); if(surface==NULL){ rb_raise(eSDLError,"Couldn't load image from String: %s", SDL_GetError()); } return Surface_create(surface); } void rubysdl_init_image(VALUE mSDL, VALUE cSurface) { rb_define_singleton_method(cSurface, "load", Surface_s_load, 1); rb_define_singleton_method(cSurface, "loadFromIO", Surface_s_loadFromIO, 1); rb_define_singleton_method(cSurface, "loadFromString", Surface_s_loadFromString, 1); } #else /* HAVE_SDL_IMAGE */ void rubysdl_init_image(VALUE mSDL, VALUE cSurface) { } #endif /* HAVE_SDL_IMAGE */ rubysdl-2.2.0/checksums.yaml.gz0000444000175000017500000000041412376257217016334 0ustar uwabamiuwabami7Se;R0 D"#YesLEä8lfvz軗 )%ʼn`z ]aO=4Ѵu\6#||P?`cajzv{Ys8rJ. CcJ'iB !َIr3f2u20F*JbnS`jc(k T b9GE\L^UsG7#G/9`rubysdl-2.2.0/SDL_kanji.h0000644000175000017500000000240312376257217015015 0ustar uwabamiuwabami#ifndef SDLbdf_h_ #define SDLbdf_h_ #include /* Set up for C function definitions, even when using C++ */ #ifdef __cplusplus extern "C" { #endif typedef enum { KANJI_SJIS, KANJI_EUC, KANJI_JIS } Kanji_CodingSystem; typedef struct { int k_size; int a_size; Kanji_CodingSystem sys; /* 邢ǁA܂ɂ͂ȂȁB */ Uint32* moji[96*96+256]; } Kanji_Font; Kanji_Font* Kanji_OpenFont(const char* file, int size); int Kanji_AddFont(Kanji_Font* font, const char* file); void Kanji_SetCodingSystem(Kanji_Font* font, Kanji_CodingSystem sys); int Kanji_FontHeight(Kanji_Font* font); /* text == 0 Ȃ ASCII ꕶ̕Ԃ */ int Kanji_FontWidth(Kanji_Font* font, const char* text); SDL_Surface* Kanji_CreateSurface(Kanji_Font* font, const char* text, SDL_Color fg, int bpp); int Kanji_PutText(Kanji_Font* font, int dx, int dy, SDL_Surface* dst, const char* text, SDL_Color fg); SDL_Surface* Kanji_CreateSurfaceTate(Kanji_Font* font, const char* text, SDL_Color fg, int bpp); int Kanji_PutTextTate(Kanji_Font* font, int dx, int dy, SDL_Surface* dst, const char* text, SDL_Color fg); void Kanji_CloseFont(Kanji_Font* font); /* Ends C function definitions when using C++ */ #ifdef __cplusplus }; #endif #endif rubysdl-2.2.0/win32/0000755000175000017500000000000012376257217014011 5ustar uwabamiuwabamirubysdl-2.2.0/win32/README.en.win320000644000175000017500000000400312376257217016230 0ustar uwabamiuwabami Ruby/SDL 2.1.0 Win32's binary Ohbayashi Ippei 1 What's Ruby/SDL? Ruby/SDL is the ruby extension library to use SDL. SDL(Simple DirectMedia Layer) is a cross-platform multimedia library designed to provide fast access to the graphics framebuffer and audio device. See http://www.libsdl.org/ if you want to know SDL in detail. 2 Platform This library supports Linux on X,Win32,FreeBSD and BeOS. And this archive contains compiled Ruby/SDL for win32 mingw's Ruby. This binary is tested on WindowsXP, Ruby 1.8.5-p12 mswin32 and SDL 1.2.11. 3 Install First, install mingw32 Ruby. You can get that from http://www.garbagecollect.jp/ruby/mswin32/en/download/release.html Therefore, you should run command prompt, change directory(cd) here, and type ruby install_rubysdl.rb then all files are copyed and finish installation. 3.1 Another way to install Copy ext\sdl.so, ext\opengl.so, lib\sdl.rb, lib\rubysdl_aliases.rb and all DLL files in dll\ to appropriate folder. If you have installed Ruby at C:\ruby ( in other words ruby.exe is under C:\ruby\bin ) , you'll copy sdl.so, and opengl.so to C:\ruby\lib\ruby\site-ruby\1.8\i386-msvcrt, copy sdl.rb and rubysdl_aliases.rb to C:\ruby\lib\ruby\site-ruby\1.8\, and copy all DLL files to PATH directory. Therefore that's all right. 4 How to use You can find documents and samples in this archive. 5 License sdl.so, sdl.rb are under LGPL version 2.1. opengl.so is under Ruby's Licence. Ohbayashi Ippei has sdl.so, rubysdl_aliases and sdl.rb 's copyright, and Yoshiyuki Kusano hase opengl.so's copyright. 6 Note Perhaps you cannot use hardware surface. 7 Version information Ruby 1.8.5-p12 SDL 1.2.11 SDL_image 1.2.5 SDL_ttf 2.0.7 SDL_mixer 1.2.7 SGE 030809 + patch for overflow error Ruby/opengl 0.32g iconv 1.11 sdlskk 0.4+ 8 Other Please send comments and bug reports to the author or rubyforge's BTS. RubyForge's project page: http://rubyforge.org/projects/rubysdl/ Author's mail address: ohai@kmc.gr.jp rubysdl-2.2.0/win32/install_rubysdl.rb0000644000175000017500000000136712376257217017557 0ustar uwabamiuwabami require 'rbconfig' require 'fileutils' require 'optparse' dlldir = nil option = { :noop => false, :verbose => true } ARGV.options do |opt| opt.on('--dlldir DIR'){|dir| dlldir = dir} opt.on('--no-harm'){ option[:noop] = true } opt.on('--quiet'){ option[:verbose] = false } opt.parse! end dlldir ||= Config::CONFIG["bindir"] sitelibdir = Config::CONFIG["sitelibdir"] sitearchdir = Config::CONFIG["sitearchdir"] FileUtils.mkpath(dlldir, option) FileUtils.mkpath(sitelibdir, option) FileUtils.mkpath(sitearchdir, option) Dir.glob("dll/*.dll"){|fname| FileUtils.install(fname, dlldir, option)} Dir.glob("ext/*.so"){|fname| FileUtils.install(fname, sitearchdir, option)} Dir.glob("lib/*.rb"){|fname| FileUtils.install(fname, sitelibdir, option)} rubysdl-2.2.0/win32/mkpkg.sh0000644000175000017500000000350112376257217015455 0ustar uwabamiuwabami#!/bin/sh # current directory should be rubysdl/win32 if [ "$1" = "" ]; then echo "usage: $0 VERSION" exit 1 fi VERSION=$1 RUBY_VERSION=1.8.4 OPENGLDIR=../../opengl-0.32g DLLDIR=../../lib DIRNAME=rubysdl-$VERSION-mswin32-${RUBY_VERSION} RUBYARCHIVE=ruby-1.8.4-i386-mswin32.zip PACKAGE=${DIRNAME}.zip PACK_PACKAGE=${DIRNAME}-pack.zip mkdir $DIRNAME mkdir $DIRNAME/lib mkdir $DIRNAME/ext mkdir $DIRNAME/dll mkdir $DIRNAME/doc mkdir $DIRNAME/sample mkdir ruby (cd ruby; unzip -q ../$RUBYARCHIVE) PACKDOCDIR=ruby/doc/rubysdl-$VERSION echo $PACKDOCDIR mkdir $PACKDOCDIR mkdir $PACKDOCDIR/sample mkdir $PACKDOCDIR/doc for fname in `cat ../MANIFEST`; do case $fname in sample/*) cp ../$fname $DIRNAME/sample/ cp ../$fname $PACKDOCDIR/sample/ ;; doc/*) cp ../$fname $DIRNAME/doc/ cp ../$fname $PACKDOCDIR/doc/ ;; esac done make -C ../doc/ cp ../doc/rubysdl_ref.rd ../doc/rubysdl_ref.html $DIRNAME cp ../rubysdl_doc_old.rd ../rubysdl_doc.en.rd $DIRNAME cp ../doc/rubysdl_ref.rd ../doc/rubysdl_ref.html $PACKDOCDIR cp ../rubysdl_doc_old.rd ../rubysdl_doc.en.rd $PACKDOCDIR cp README.en.win32 README.ja.win32 $DIRNAME cp ../README.ja ../README.en $DIRNAME cp ../NEWS.ja ../NEWS.en $DIRNAME cp ../sdl.so $OPENGLDIR/opengl.so $DIRNAME/ext cp ../lib/*.rb $DIRNAME/lib cp $DLLDIR/*.dll $DIRNAME/dll PACK_LIBDIR=ruby/lib/ruby/site_ruby/1.8 PACK_EXTDIR=$PACK_LIBDIR/i386-msvcrt cp README.en.win32 README.ja.win32 $PACKDOCDIR cp ../NEWS.ja ../NEWS.en $PACKDOCDIR cp ../README.ja ../README.en $PACKDOCDIR cp ../sdl.so $OPENGLDIR/opengl.so ruby/lib/ruby/site_ruby/1.8/i386-msvcrt cp ../lib/*.rb ruby/lib/ruby/site_ruby/1.8/ cp $DLLDIR/*.dll ruby/bin cp install_rubysdl.rb $DIRNAME zip -q -r $PACKAGE $DIRNAME zip -q -r $PACK_PACKAGE ruby rm -r $DIRNAME rm -r ruby rubysdl-2.2.0/win32/README.ja.win320000644000175000017500000000460512376257217016230 0ustar uwabamiuwabami Ruby/SDL 2.1.0 win32 oCi шꕽ 1 Tv ́ARubySDL̋@\g߂̊gCułB SDLƂ́AWin32,Linux,BeOS,MacOS,FreeBSD,SolarisœANXvbgtH[ȃQ[JpCułB 2 ‹ ̃CuLinuxXAWin32AFreeBSDABeOSœ삪mFĂ܂B ̃A[JCuɂ́Amswin32 Ruby p̃RpCς݂̃Cu ܂܂Ă܂B ́ARuby 1.8.5-p12œmFĂ܂B 3 CXg[ Win32ł̃CXg[܂B ܂A http://www.ruby-lang.org/ja/install.cgi?cmd=view;name=mswin32+%28%A5%D0%A5%A4%A5%CA%A5%EA%29 ̉QlɂRubyCXg[ĂB RubýA http://www.garbagecollect.jp/ruby/mswin32/ja/ ɂoCig܂B ɃR}hvvgNÃA[JCuWJtH_ cd ňړ܂B̌ ruby install_rubysdl.rb ƂƕKvȃt@CCXg[܂B ܂A ruby install_rubysdl.rb --help Ƃ邱ƂŃIvV\܂B ȏŃCXg[͊łB 3.1 ʕ@̂ŃCXg[ ̃A[JCuɊ܂܂ dll/*.dll, lib/*.rb, ext/*.so Ƃt@CKȃtH_ɃRs[@łCXg[ł܂B rubyCXg[ĂtH_ C:\ruby\ Ƃ(‚܂ C:\ruby\bin ruby.exe Ƃ) C:\ruby\lib\ruby\site-ruby\1.8\ sdl.rb rubysdl_aliases.rb A C:\ruby\lib\ruby\site-ruby\1.8\i386-msvcrt sdl.soopengl.so ꂼRs[ĂBDLL̓pX̒ʂtH_ɃRs[ĂB 4 g A[JCuɃhLgTvĂ̂ł QƂĂB 5 CZX GNU LGPL(GNU Lesser General Public License) version 2.1 ȍ~ɏ]܂B Aopengl.so Yoshiyuki Kusano 񂪍̂łA 쌠͔ނɂÃCZX Ruby's License ɏ]܂B ̑RubySDL֘AȂǓ̃t@C͂ꂼ꒘쌠ҁACZX قȂ܂BŜƂĂGPLƍlĂ܂܂B 6 ӂȂ ActiveRubył̃oCi͗p”\łB 7 o[W Ruby 1.8.5 SDL 1.2.11 SDL_image 1.2.5 SDL_ttf 2.0.7 SDL_mixer 1.2.7 SGE 030809 + patch for overflow error Ruby/opengl 0.32g iconv 1.11 sdlskk 0.4+ 8 ̑ v]AoO񍐓́Aohai@kmc.gr.jpɃ[oĂB http://rubyforge.org/projects/rubysdl/BTS܂̂łł 񍐂͉”\łB܂Aruby-listAruby-extĂ܂̂ŁA ɕ񍐂ĂĂ\łB rubysdl-2.2.0/depend0000644000175000017500000000145412376257217014235 0ustar uwabamiuwabamirubysdl_event.o: rubysdl_event.c rubysdl.h rubysdl_event_key.o: rubysdl_event_key.c rubysdl.h rubysdl_main.o: rubysdl_main.c rubysdl.h rubysdl_video.o: rubysdl_video.c rubysdl.h rubysdl_mixer.o: rubysdl_mixer.c rubysdl.h rubysdl_time.o: rubysdl_time.c rubysdl.h rubysdl_wm.o: rubysdl_wm.c rubysdl.h rubysdl_mouse.o: rubysdl_mouse.c rubysdl.h rubysdl_sge_video.o: rubysdl_sge_video.c rubysdl.h rubysdl_image.o: rubysdl_image.c rubysdl.h rubysdl_ttf.o: rubysdl_ttf.c rubysdl.h rubysdl_joystick.o: rubysdl_joystick.c rubysdl.h rubysdl_cdrom.o: rubysdl_cdrom.c rubysdl.h rubysdl_pixel.o: rubysdl_pixel.c rubysdl.h rubysdl_smpeg.o: rubysdl_smpeg.c rubysdl.h rubysdl_sdlskk.o: rubysdl_sdlskk.c rubysdl.h rubysdl_kanji.o: rubysdl_kanji.c rubysdl.h SDL_kanji.h SDL_kanji.o: SDL_kanji.c SDL_kanji.h CLEANOBJS += sge/*.o rubysdl-2.2.0/doc-en/0000755000175000017500000000000012376257217014214 5ustar uwabamiuwabamirubysdl-2.2.0/doc-en/video.rsd0000644000175000017500000016741012376257217016045 0ustar uwabamiuwabami= Video * ((