[ LiB ]


Ruby comes with a few toolkits, including FXRuby and OpenGL. FXRuby is a Ruby interface to the FOX toolkit, which is designed for creating graphical user interfaces and which is written in C++.

The Fox toolkit has a home at http://www.fox-toolkit.org/.

FXRuby and OpenGL for Ruby are partners in many projects. They are often used together, and Fox provides a few widgets for providing OpenGL support. FXGLCanvas and FXGLViewer are FXGLVisual objects. FXGLVisual can be used to create new visual applications and includes options for double buffering ( VISUAL_DOUBLEBUFFER ) and stereo sound ( VISUAL_STEREO ):

 MyVisualObject = FXGLVisual.new(MyApplication, VISUAL_STEREO) 

The FXGLCanvas widget is an OpenGL window with minimal functionality:

 MyCanvas = FXGLCanvas.new (MyApplication, visual_to_use) 

The FXGLViewer widget is a higher-level OpenGL window with more functionality and is built the same way:

 MyViewer = FXGLViewer.new (MyApplication, visual_to_use) 

There are a number of important differences between the standard FOX API and the actual FXRuby API. FXRuby uses Ruby strings instead of the standard Fox FXStrings. Since Ruby handles underlying memory management, some of the drudgery of handling pointers and arrays in FOX can be skipped . Many of the FOX classes have been extended with built-in Ruby methods such as each , initialize , and catch . There are also differences in multi-threading and the return values to a few interfaces.

With the FXRuby included in the standard Ruby package comes a number of FXRuby samples. These are in the (surprise!) Samples directory. FXRuby is fairly easy to include in a Ruby script. Once installed, Ruby's require and include commands can be used to bring in the library:

 #!/usr/bin/env ruby require "fox" include Fox 

A new FXRuby application is declared by calling the FXApp class with its new constructor:

 MyApplication = FXApp.new() 

FXRuby requires a main or parent window; these can be declared in the same way using the new method of FXMainWindow . This function ties into the newly created MyApplication Fox application and is also fed the window title:

 main = FXMainWindow.new(MyApplication, "FXWindow") 

You can create a GUI button in the main window by using FXButton :

 FXButton.new(main, "Press This Button!") 

Finally, you must create MyApplication with a create method, show it on the screen with a show method, and then turn it on with a run method:

 MyApplication.create() main.show(PLACEMENT_SCREEN) MyApplication.run() 

[ LiB ]

Game Programming with Pyton, Lua and Ruby
Game Programming with Pyton, Lua and Ruby
Year: 2005
Pages: 133

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net