1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
|
= Initialize
TOC
Before SDL can be used in a program it must be initialized
with @[init]. @[init] initializes all the subsystems that
the user requests (video, audio, joystick, timers and/or cdrom).
== Methods
%%%
NAME init
TYPE .
PURPOSE Initializes SDL
PROTO
init(flags)
DESC
Initializes SDL. This should be called before all other
Ruby/SDL methods. The $[flags] parameter specifies what
part(s) of SDL to initialize.
:SDL::INIT_AUDIO
Initialize autio subsystems.
:SDL::INIT_VIDEO
Initialize ((<Video>)) subsystem.
:SDL::INIT_CDROM
Initialize ((<CD-ROM>)) subsystem.
:SDL::INIT_JOYSTICK
Initialize ((<Joystick>)) subsystem.
:SDL::INIT_EVERYTHING
Initialize all of the avobe.
EXCEPTION *
%%
NAME quit
TYPE .
PURPOSE Shut down SDL
PROTO
quit
DESC
This method shots down all SDL subsystem and frees the resources
allocated to them. Because this method is automatically called
when ruby stops, you don't have to call this function normally.
You should know SDL and Ruby/SDL very well when you use
this method.
%%
NAME inited_system
TYPE .
PURPOSE Check which subsystems are initialized
RVAL UINT
PROTO
inited_system(flags)
initedSystem(flags)
DESC
This method allows you to see which SDL subsytems have
been @[initialized|init]. $[flags] is a bitwise OR'd
combination of the subsystems you wish to check
(see @[init] for a list of subsystem flags).
RET
Returns a bitwised OR'd combination of the initialized subsystems.
EXAMPLE
# Here are several ways you can use SDL.inited_system
# Get init data on all the subsystem
subsystem_init = SDL.inited_system(SDL::INIT_EVERYTHING)
if subsystem_init & SDL::INIT_VIDEO
puts "video is initialized"
else
puts "video is not initialized"
end
# Just check for one specfic subsystem
if SDL.inited_system(SDL::INIT_VIDEO) != 0
puts "Video is initialized"
else
puts "Video is not initialized "
end
# Check for two subsystem
subsystem_mask = SDL::INIT_VIDEO|SDL::INIT_AUDIO;
if SDL.inited_system(subsystem_mask) == subsystem_mask
puts "Video and Audio initialized."
else
puts "Video and Audio not initialized"
end
SEEALSO
init
%%
NAME getenv
TYPE .
PURPOSE Get an environmental variable
RVAL String
PROTO
getenv(var)
DESC
Returns the environment variable string matched by $[var].
%%
NAME putenv
TYPE .
PURPOSE Change or add an environmental variable
PROTO
putenv(string)
DESC
Add or Change the value of environmental variables.
The argument $[string] is of the form "name=value"
If you want to change SDL_WINDOWID or SDL_VIDEODRIVER environmental variable
to modify the behavior of SDL in your program, you should use
this function instead of ENV.
EXCEPTION *
EXAMPLE
# from http://moriq.tdiary.net/20051006.html
# Apollo with Ruby/SDL
require 'phi'
require 'sdl'
# Create form
form = Phi::Form.new
$terminated = false
form.on_close{ $terminated = true }
form.caption = "Ruby/SDL on Phi::Form"
# Create a panel on new form
panel = Phi::Panel.new(form)
panel.align = Phi::AL_LEFT
# Put SDL window on panel with WINDOWID hack
SDL.putenv("SDL_VIDEODRIVER=windib")
SDL.putenv("SDL_WINDOWID=#{panel.handle}")
form.show
# initialize SDL
SDL.init(SDL::INIT_VIDEO)
screen = SDL.setVideoMode(640, 480, 16, SDL::SWSURFACE)
# main loop
unless $terminated
while event = SDL::Event2.poll
case event
when SDL::Event2::KeyDown, SDL::Event2::Quit
exit
end
end
sleep 0.05
end
|