Class: Teien::View
- Inherits:
-
Ogre::FrameListener
- Object
- Ogre::FrameListener
- Teien::View
- Includes:
- Dispatcher
- Defined in:
- lib/teien/ui/view.rb
Instance Attribute Summary collapse
-
#camera ⇒ Object
Returns the value of attribute camera.
-
#keyboard ⇒ Object
Returns the value of attribute keyboard.
-
#mouse ⇒ Object
Returns the value of attribute mouse.
-
#objects ⇒ Object
Returns the value of attribute objects.
-
#root ⇒ Object
Returns the value of attribute root.
-
#scene_mgr ⇒ Object
Returns the value of attribute scene_mgr.
-
#tray_mgr ⇒ Object
Returns the value of attribute tray_mgr.
-
#window ⇒ Object
Returns the value of attribute window.
-
#window_title ⇒ Object
Returns the value of attribute window_title.
Instance Method Summary collapse
- #create_object(obj) ⇒ Object
- #finalize ⇒ Object
-
#frame_rendering_queued(evt) ⇒ Object
Called through @root.render_one_frame(delta).
- #init_managers ⇒ Object
- #init_resources ⇒ Object
-
#initialize ⇒ View
constructor
A new instance of View.
- #key_pressed(keyEvent) ⇒ Object
- #key_released(keyEvent) ⇒ Object
- #load_plugins ⇒ Object
- #mouse_moved(evt) ⇒ Object
- #mouse_pressed(mouseEvent, mouseButtonID) ⇒ Object
- #mouse_released(mouseEvent, mouseButtonID) ⇒ Object
- #prepare_render_loop ⇒ Object
- #set_ambient_light(color) ⇒ Object
- #setup(base_object_manager) ⇒ Object
-
#show_all_animation(entity) ⇒ Object
Shows the animation infomation of the entity.
- #start ⇒ Object
- #stop ⇒ Object
-
#take_screen_shot(name) ⇒ Object
Takes a screen shot.
-
#update(delta) ⇒ Object
Called by the main loop periodically.
Methods included from Dispatcher
#notify, #notify_reversely, #register_receiver
Constructor Details
#initialize ⇒ View
Returns a new instance of View.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/teien/ui/view.rb', line 30 def initialize() super() @adjustFlag = false @root = nil @camera = nil @window = nil @mouse = nil @keyboard = nil @scene_mgr = nil @tray_mgr = nil @inputManager = nil @window_title = "" @objects = Hash.new end |
Instance Attribute Details
#camera ⇒ Object
Returns the value of attribute camera.
21 22 23 |
# File 'lib/teien/ui/view.rb', line 21 def camera @camera end |
#keyboard ⇒ Object
Returns the value of attribute keyboard.
24 25 26 |
# File 'lib/teien/ui/view.rb', line 24 def keyboard @keyboard end |
#mouse ⇒ Object
Returns the value of attribute mouse.
23 24 25 |
# File 'lib/teien/ui/view.rb', line 23 def mouse @mouse end |
#objects ⇒ Object
Returns the value of attribute objects.
28 29 30 |
# File 'lib/teien/ui/view.rb', line 28 def objects @objects end |
#root ⇒ Object
Returns the value of attribute root.
20 21 22 |
# File 'lib/teien/ui/view.rb', line 20 def root @root end |
#scene_mgr ⇒ Object
Returns the value of attribute scene_mgr.
25 26 27 |
# File 'lib/teien/ui/view.rb', line 25 def scene_mgr @scene_mgr end |
#tray_mgr ⇒ Object
Returns the value of attribute tray_mgr.
26 27 28 |
# File 'lib/teien/ui/view.rb', line 26 def tray_mgr @tray_mgr end |
#window ⇒ Object
Returns the value of attribute window.
22 23 24 |
# File 'lib/teien/ui/view.rb', line 22 def window @window end |
#window_title ⇒ Object
Returns the value of attribute window_title.
27 28 29 |
# File 'lib/teien/ui/view.rb', line 27 def window_title @window_title end |
Instance Method Details
#create_object(obj) ⇒ Object
192 193 194 195 196 197 198 199 |
# File 'lib/teien/ui/view.rb', line 192 def create_object(obj) view_object = ViewObjectFactory::create_object(obj, self) obj.register_receiver(view_object) view_object.object = obj @objects[obj.name] = view_object if view_object end |
#finalize ⇒ Object
178 179 180 181 182 183 184 185 186 |
# File 'lib/teien/ui/view.rb', line 178 def finalize stop() if (@inputManger != nil) @inputManager.destroy_input_object(@keyboard) @inputManager.destroy_input_object(@mouse) @inputManager = nil end @root.shutdown() end |
#frame_rendering_queued(evt) ⇒ Object
Called through @root.render_one_frame(delta).
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 |
# File 'lib/teien/ui/view.rb', line 222 def frame_rendering_queued(evt) @keyboard.capture() @mouse.capture() animation_manager = Teien::get_component("animation_manager") @objects.each_value {|obj| if obj.object.attached_objects.length > 0 obj.update_attached_objects(self) end animation = animation_manager.animations[obj.object.name] obj.update_animation(evt.timeSinceLastFrame, animation) if animation } @tray_mgr.frame_rendering_queued(evt) if (@adjustFlag != true) @tray_mgr.adjust_trays() # fix a caption invisible bug. @adjustFlag = true end return true end |
#init_managers ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/teien/ui/view.rb', line 114 def init_managers @root.add_frame_listener(self) # initialize InputManager windowHnd = Ogre::Intp.new @window.get_custom_attribute("WINDOW", windowHnd) windowHndStr = sprintf("%d", windowHnd.value()) pl = Ois::ParamList.new pl["WINDOW"] = windowHndStr # initialize input manager @inputManager = Ois::InputManager::create_input_system(pl) @keyboard = @inputManager.create_input_object(Ois::OISKeyboard, true).to_keyboard() @mouse = @inputManager.create_input_object(Ois::OISMouse, true).to_mouse() # initialize trayManager Ogre::ResourceGroupManager::get_singleton().initialise_resource_group("Essential") @tray_mgr = Ogrebites::SdkTrayManager.new("Base", @window, @mouse); ms = @mouse.get_mouse_state() ms.width = @window.get_width() ms.height = @window.get_height() end |
#init_resources ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/teien/ui/view.rb', line 90 def init_resources puts "ResourcesCfgFile: #{@resources_cfg}" # Load resource paths from config file cfg = Ogre::ConfigFile.new cfg.load(@resources_cfg) resourceDir = cfg.get_setting("ResourceFolder") resourceDir += "/" if (resourceDir.length > 0) && (resourceDir[-1] != '/') cfg.each_settings {|secName, keyName, valueName| next if (keyName == "ResourceFolder") fullPath = resourceDir + valueName if @base_object_manager.resources_cfg fullPath.sub!("<ConfigFileFolder>", File.dirname(@base_object_manager.resources_cfg)) end fullPath.sub!("<SystemResourceFolder>", Ruby::Ogre::get_resource_folder) Ogre::ResourceGroupManager::get_singleton().add_resource_location(fullPath, keyName, secName) } end |
#key_pressed(keyEvent) ⇒ Object
245 246 247 248 |
# File 'lib/teien/ui/view.rb', line 245 def key_pressed(keyEvent) notify(:key_pressed, keyEvent) return true end |
#key_released(keyEvent) ⇒ Object
250 251 252 253 |
# File 'lib/teien/ui/view.rb', line 250 def key_released(keyEvent) notify(:key_released, keyEvent) return true end |
#load_plugins ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/teien/ui/view.rb', line 72 def load_plugins puts "PluginsCfgFile: #{@plugins_cfg}" cfg = Ogre::ConfigFile.new cfg.load(@plugins_cfg) pluginDir = cfg.get_setting("PluginFolder") pluginDir += "/" if (pluginDir.length > 0) && (pluginDir[-1] != '/') cfg.each_settings {|secName, keyName, valueName| fullPath = pluginDir + valueName if @base_object_manager.resources_cfg fullPath.sub!("<ConfigFileFolder>", File.dirname(@base_object_manager.plugins_cfg)) end fullPath.sub!("<SystemPluginFolder>", Ruby::Ogre::get_plugin_folder) @root.load_plugin(fullPath) if (keyName == "Plugin") } end |
#mouse_moved(evt) ⇒ Object
255 256 257 258 259 |
# File 'lib/teien/ui/view.rb', line 255 def mouse_moved(evt) return true if @tray_mgr.inject_mouse_move(evt) notify(:mouse_moved, evt) return true end |
#mouse_pressed(mouseEvent, mouseButtonID) ⇒ Object
261 262 263 264 265 |
# File 'lib/teien/ui/view.rb', line 261 def mouse_pressed(mouseEvent, mouseButtonID) return true if @tray_mgr.inject_mouse_down(mouseEvent, mouseButtonID) notify(:mouse_pressed, mouseEvent, mouseButtonID) return true end |
#mouse_released(mouseEvent, mouseButtonID) ⇒ Object
267 268 269 270 271 |
# File 'lib/teien/ui/view.rb', line 267 def mouse_released(mouseEvent, mouseButtonID) return true if @tray_mgr.inject_mouse_up(mouseEvent, mouseButtonID) notify(:mouse_released, mouseEvent, mouseButtonID) return true end |
#prepare_render_loop ⇒ Object
165 166 167 168 |
# File 'lib/teien/ui/view.rb', line 165 def prepare_render_loop @root.get_render_system()._init_render_targets() @root.clear_event_times() end |
#set_ambient_light(color) ⇒ Object
188 189 190 |
# File 'lib/teien/ui/view.rb', line 188 def set_ambient_light(color) @scene_mgr.set_ambient_light(color) end |
#setup(base_object_manager) ⇒ Object
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 |
# File 'lib/teien/ui/view.rb', line 46 def setup(base_object_manager) puts "view setup" @base_object_manager = base_object_manager @plugins_cfg = @base_object_manager.plugins_cfg ? @base_object_manager.plugins_cfg : "config/plugins.cfg" @resources_cfg = @base_object_manager.resources_cfg ? @base_object_manager.resources_cfg : "config/resources.cfg" @root = Ogre::Root.new("") load_plugins() if File.exist?("ogre.cfg") return false unless (@root.restore_config()) else return false unless (@root.show_config_dialog()) end @window = @root.initialise(true, @window_title) init_resources() init_managers() start() prepare_render_loop() return true end |
#show_all_animation(entity) ⇒ Object
Shows the animation infomation of the entity.
207 208 209 210 211 212 213 |
# File 'lib/teien/ui/view.rb', line 207 def show_all_animation(entity) puts "Animations:" animSet = entity.get_all_animation_states() animSet.each_animation_state() {|state| puts "name: #{state.get_animation_name()}, len: #{state.get_length()}" } end |
#start ⇒ Object
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 |
# File 'lib/teien/ui/view.rb', line 137 def start() # initialize scene_mgr @scene_mgr = @root.create_scene_manager(Ogre::ST_GENERIC) @scene_mgr.set_shadow_technique(Ogre::SHADOWTYPE_STENCIL_ADDITIVE) # initialize a camera @camera = @scene_mgr.create_camera("FixCamera") # Create one viewport, entire window @vp = @window.(@camera) @vp.set_background_colour(Ogre::ColourValue.new(0, 0, 0)) # Alter the camera aspect ratio to match the viewport @camera.set_aspect_ratio(Float(@vp.get_actual_width()) / Float(@vp.get_actual_height())); # set listeners. @keyListener = KeyListener.new(self) @keyboard.set_event_callback(@keyListener) @mouseListener = MouseListener.new(self) @mouse.set_event_callback(@mouseListener) @trayListener = TrayListener.new(self) @tray_mgr.set_listener(@trayListener) # load resources into ResourceGroupManager. @tray_mgr.(1, 0) Ogre::ResourceGroupManager::get_singleton().initialise_resource_group("General") @tray_mgr.() Ogre::TextureManager::get_singleton().set_default_num_mipmaps(5) end |
#stop ⇒ Object
170 171 172 173 174 175 176 |
# File 'lib/teien/ui/view.rb', line 170 def stop @scene_mgr.clear_scene() if (@scene_mgr != nil) @root.destroy_scene_manager(@scene_mgr) if (@scene_mgr != nil) @scene_mgr = nil @window.() @tray_mgr.() end |
#take_screen_shot(name) ⇒ Object
Takes a screen shot.
202 203 204 |
# File 'lib/teien/ui/view.rb', line 202 def take_screen_shot(name) @window.(name + "_", ".png") end |
#update(delta) ⇒ Object
Called by the main loop periodically
216 217 218 219 |
# File 'lib/teien/ui/view.rb', line 216 def update(delta) Ogre::WindowEventUtilities.() return @root.render_one_frame(delta) end |