branches/micko/src/emu/guiengine.c
r0 | r23972 | |
| 1 | /*************************************************************************** |
| 2 | |
| 3 | guiengine.c |
| 4 | |
| 5 | GUI engine of the core MAME system. |
| 6 | |
| 7 | **************************************************************************** |
| 8 | |
| 9 | Copyright Miodrag Milanovic |
| 10 | All rights reserved. |
| 11 | |
| 12 | Redistribution and use in source and binary forms, with or without |
| 13 | modification, are permitted provided that the following conditions are |
| 14 | met: |
| 15 | |
| 16 | * Redistributions of source code must retain the above copyright |
| 17 | notice, this list of conditions and the following disclaimer. |
| 18 | * Redistributions in binary form must reproduce the above copyright |
| 19 | notice, this list of conditions and the following disclaimer in |
| 20 | the documentation and/or other materials provided with the |
| 21 | distribution. |
| 22 | * Neither the name 'MAME' nor the names of its contributors may be |
| 23 | used to endorse or promote products derived from this software |
| 24 | without specific prior written permission. |
| 25 | |
| 26 | THIS SOFTWARE IS PROVIDED BY MIODRAG MILANOVIC ''AS IS'' AND ANY EXPRESS OR |
| 27 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 28 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 29 | DISCLAIMED. IN NO EVENT SHALL MIODRAG MILANOVIC BE LIABLE FOR ANY DIRECT, |
| 30 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 31 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 32 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 33 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 34 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING |
| 35 | IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 36 | POSSIBILITY OF SUCH DAMAGE. |
| 37 | |
| 38 | ***************************************************************************/ |
| 39 | #include <Rocket/Core.h> |
| 40 | #include <Rocket/Debugger.h> |
| 41 | #include <Rocket/Controls.h> |
| 42 | |
| 43 | #include "emu.h" |
| 44 | #include "emuopts.h" |
| 45 | #include "osdepend.h" |
| 46 | |
| 47 | |
| 48 | class ShellSystemInterface : public Rocket::Core::SystemInterface |
| 49 | { |
| 50 | public: |
| 51 | /// Get the number of seconds elapsed since the start of the application |
| 52 | /// @returns Seconds elapsed |
| 53 | virtual float GetElapsedTime() { return 0; } |
| 54 | }; |
| 55 | |
| 56 | class ShellRenderInterfaceOpenGL : public Rocket::Core::RenderInterface |
| 57 | { |
| 58 | public: |
| 59 | ShellRenderInterfaceOpenGL() |
| 60 | { |
| 61 | } |
| 62 | |
| 63 | /// Called by Rocket when it wants to render geometry that it does not wish to optimise. |
| 64 | virtual void RenderGeometry(Rocket::Core::Vertex* vertices, int num_vertices, int* indices, int num_indices, Rocket::Core::TextureHandle texture, const Rocket::Core::Vector2f& translation) |
| 65 | { |
| 66 | } |
| 67 | |
| 68 | /// Called by Rocket when it wants to compile geometry it believes will be static for the forseeable future. |
| 69 | virtual Rocket::Core::CompiledGeometryHandle CompileGeometry(Rocket::Core::Vertex* vertices, int num_vertices, int* indices, int num_indices, Rocket::Core::TextureHandle texture) |
| 70 | { |
| 71 | return (Rocket::Core::CompiledGeometryHandle) NULL; |
| 72 | } |
| 73 | |
| 74 | /// Called by Rocket when it wants to render application-compiled geometry. |
| 75 | virtual void RenderCompiledGeometry(Rocket::Core::CompiledGeometryHandle geometry, const Rocket::Core::Vector2f& translation) |
| 76 | { |
| 77 | } |
| 78 | |
| 79 | /// Called by Rocket when it wants to release application-compiled geometry. |
| 80 | virtual void ReleaseCompiledGeometry(Rocket::Core::CompiledGeometryHandle geometry) |
| 81 | { |
| 82 | } |
| 83 | |
| 84 | /// Called by Rocket when it wants to enable or disable scissoring to clip content. |
| 85 | virtual void EnableScissorRegion(bool enable) |
| 86 | { |
| 87 | } |
| 88 | /// Called by Rocket when it wants to change the scissor region. |
| 89 | virtual void SetScissorRegion(int x, int y, int width, int height) |
| 90 | { |
| 91 | } |
| 92 | |
| 93 | /// Called by Rocket when a texture is required by the library. |
| 94 | virtual bool LoadTexture(Rocket::Core::TextureHandle& texture_handle, Rocket::Core::Vector2i& texture_dimensions, const Rocket::Core::String& source) |
| 95 | { |
| 96 | return true; |
| 97 | } |
| 98 | /// Called by Rocket when a texture is required to be built from an internally-generated sequence of pixels. |
| 99 | virtual bool GenerateTexture(Rocket::Core::TextureHandle& texture_handle, const Rocket::Core::byte* source, const Rocket::Core::Vector2i& source_dimensions) |
| 100 | { |
| 101 | return true; |
| 102 | } |
| 103 | /// Called by Rocket when a loaded texture is no longer required. |
| 104 | virtual void ReleaseTexture(Rocket::Core::TextureHandle texture_handle) |
| 105 | { |
| 106 | } |
| 107 | }; |
| 108 | |
| 109 | ShellRenderInterfaceOpenGL opengl_renderer; |
| 110 | ShellSystemInterface system_interface; |
| 111 | Rocket::Core::Context* context = NULL; |
| 112 | |
| 113 | //************************************************************************** |
| 114 | // GUI ENGINE |
| 115 | //************************************************************************** |
| 116 | |
| 117 | //------------------------------------------------- |
| 118 | // gui_engine - constructor |
| 119 | //------------------------------------------------- |
| 120 | |
| 121 | gui_engine::gui_engine(running_machine &machine) |
| 122 | : m_machine(machine) |
| 123 | { |
| 124 | context = NULL; |
| 125 | } |
| 126 | |
| 127 | //------------------------------------------------- |
| 128 | // ~gui_engine - destructor |
| 129 | //------------------------------------------------- |
| 130 | |
| 131 | gui_engine::~gui_engine() |
| 132 | { |
| 133 | shutdown(); |
| 134 | } |
| 135 | |
| 136 | //------------------------------------------------- |
| 137 | // initialize - initialize lua hookup to emu engine |
| 138 | //------------------------------------------------- |
| 139 | |
| 140 | void gui_engine::initialize() |
| 141 | { |
| 142 | // Rocket initialisation. |
| 143 | Rocket::Core::SetRenderInterface(&opengl_renderer); |
| 144 | |
| 145 | Rocket::Core::SetSystemInterface(&system_interface); |
| 146 | |
| 147 | Rocket::Core::Initialise(); |
| 148 | // Initialise the Rocket Controls library. |
| 149 | Rocket::Controls::Initialise(); |
| 150 | |
| 151 | // Create the main Rocket context and set it on the shell's input layer. |
| 152 | context = Rocket::Core::CreateContext("main", Rocket::Core::Vector2i(1920, 1080)); |
| 153 | if (context == NULL) |
| 154 | { |
| 155 | Rocket::Core::Shutdown(); |
| 156 | printf("Failed"); |
| 157 | return; |
| 158 | } |
| 159 | Rocket::Debugger::Initialise(context); |
| 160 | |
| 161 | machine().add_notifier(MACHINE_NOTIFY_EXIT, machine_notify_delegate(FUNC(gui_engine::shutdown), this)); |
| 162 | } |
| 163 | |
| 164 | //------------------------------------------------- |
| 165 | // shutdown - close and cleanup of gui engine |
| 166 | //------------------------------------------------- |
| 167 | |
| 168 | void gui_engine::shutdown() |
| 169 | { |
| 170 | // Shutdown Rocket. |
| 171 | if (context!=NULL) |
| 172 | { |
| 173 | context->RemoveReference(); |
| 174 | Rocket::Core::Shutdown(); |
| 175 | context = NULL; |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | void gui_engine::update() |
| 180 | { |
| 181 | context->Update(); |
| 182 | context->Render(); |
| 183 | } |
branches/micko/src/emu/guiengine.h
r0 | r23972 | |
| 1 | /*************************************************************************** |
| 2 | |
| 3 | guiengine.h |
| 4 | |
| 5 | GUI engine of the core MAME system. |
| 6 | |
| 7 | **************************************************************************** |
| 8 | |
| 9 | Copyright Miodrag Milanovic |
| 10 | All rights reserved. |
| 11 | |
| 12 | Redistribution and use in source and binary forms, with or without |
| 13 | modification, are permitted provided that the following conditions are |
| 14 | met: |
| 15 | |
| 16 | * Redistributions of source code must retain the above copyright |
| 17 | notice, this list of conditions and the following disclaimer. |
| 18 | * Redistributions in binary form must reproduce the above copyright |
| 19 | notice, this list of conditions and the following disclaimer in |
| 20 | the documentation and/or other materials provided with the |
| 21 | distribution. |
| 22 | * Neither the name 'MAME' nor the names of its contributors may be |
| 23 | used to endorse or promote products derived from this software |
| 24 | without specific prior written permission. |
| 25 | |
| 26 | THIS SOFTWARE IS PROVIDED BY MIODRAG MILANOVIC ''AS IS'' AND ANY EXPRESS OR |
| 27 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 28 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 29 | DISCLAIMED. IN NO EVENT SHALL MIODRAG MILANOVIC BE LIABLE FOR ANY DIRECT, |
| 30 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 31 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 32 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 33 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 34 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING |
| 35 | IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 36 | POSSIBILITY OF SUCH DAMAGE. |
| 37 | |
| 38 | ***************************************************************************/ |
| 39 | |
| 40 | #pragma once |
| 41 | |
| 42 | #ifndef __EMU_H__ |
| 43 | #error Dont include this file directly; include emu.h instead. |
| 44 | #endif |
| 45 | |
| 46 | #ifndef __GUI_ENGINE_H__ |
| 47 | #define __GUI_ENGINE_H__ |
| 48 | |
| 49 | class gui_engine |
| 50 | { |
| 51 | public: |
| 52 | // construction/destruction |
| 53 | gui_engine(running_machine &machine); |
| 54 | ~gui_engine(); |
| 55 | |
| 56 | // getters |
| 57 | running_machine &machine() const { return m_machine; } |
| 58 | |
| 59 | void initialize(); |
| 60 | void shutdown(); |
| 61 | void update(); |
| 62 | private: |
| 63 | // internal state |
| 64 | running_machine & m_machine; // reference to our machine |
| 65 | }; |
| 66 | |
| 67 | #endif /* __GUI_ENGINE_H__ */ |