mirror of
https://github.com/mattrberry/crab.git
synced 2025-02-06 08:45:53 +01:00
redesign the structure of the menu bar
This commit is contained in:
parent
eefeeb6b63
commit
b86aabd8e0
5 changed files with 79 additions and 53 deletions
|
@ -1,8 +1,10 @@
|
||||||
abstract class Controller
|
abstract class Controller
|
||||||
alias Action = Tuple(String, Proc(Nil), Bool)
|
class_getter shader : String? = nil
|
||||||
|
|
||||||
abstract def emu : Emu
|
abstract def emu : Emu
|
||||||
|
|
||||||
|
# Window Config
|
||||||
|
|
||||||
abstract def width : Int32
|
abstract def width : Int32
|
||||||
abstract def height : Int32
|
abstract def height : Int32
|
||||||
|
|
||||||
|
@ -12,8 +14,6 @@ abstract class Controller
|
||||||
def render_windows : Nil
|
def render_windows : Nil
|
||||||
end
|
end
|
||||||
|
|
||||||
getter actions = [] of Action
|
|
||||||
|
|
||||||
def window_width : Int32
|
def window_width : Int32
|
||||||
width
|
width
|
||||||
end
|
end
|
||||||
|
@ -22,15 +22,27 @@ abstract class Controller
|
||||||
height
|
height
|
||||||
end
|
end
|
||||||
|
|
||||||
class_getter shader : String? = nil
|
# Control
|
||||||
|
|
||||||
|
def run_until_frame : Nil
|
||||||
|
emu.run_until_frame
|
||||||
|
end
|
||||||
|
|
||||||
|
# Audio
|
||||||
|
|
||||||
|
abstract def sync? : Bool
|
||||||
|
|
||||||
|
def toggle_sync : Nil
|
||||||
|
emu.toggle_sync
|
||||||
|
end
|
||||||
|
|
||||||
|
# Video
|
||||||
|
|
||||||
def get_framebuffer : Slice(UInt16)
|
def get_framebuffer : Slice(UInt16)
|
||||||
emu.ppu.framebuffer
|
emu.ppu.framebuffer
|
||||||
end
|
end
|
||||||
|
|
||||||
def run_until_frame : Nil
|
# Input
|
||||||
emu.run_until_frame
|
|
||||||
end
|
|
||||||
|
|
||||||
def handle_controller_event(event : SDL::Event::JoyHat | SDL::Event::JoyButton) : Nil
|
def handle_controller_event(event : SDL::Event::JoyHat | SDL::Event::JoyButton) : Nil
|
||||||
emu.handle_controller_event(event)
|
emu.handle_controller_event(event)
|
||||||
|
@ -40,7 +52,11 @@ abstract class Controller
|
||||||
emu.handle_input(input, pressed)
|
emu.handle_input(input, pressed)
|
||||||
end
|
end
|
||||||
|
|
||||||
def toggle_sync : Nil
|
# Debug
|
||||||
emu.toggle_sync
|
|
||||||
|
def render_debug_items : Nil
|
||||||
|
end
|
||||||
|
|
||||||
|
def render_windows : Nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -11,10 +11,9 @@ class GBController < Controller
|
||||||
@emu.post_init
|
@emu.post_init
|
||||||
end
|
end
|
||||||
|
|
||||||
def render_menu : Nil
|
# Audio
|
||||||
if ImGui.begin_menu "Game Boy (Color)"
|
|
||||||
@emu.toggle_sync if ImGui.menu_item("Audio Sync", "", emu.apu.sync)
|
def sync? : Bool
|
||||||
ImGui.end_menu
|
@emu.apu.sync
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -13,12 +13,16 @@ class GBAController < Controller
|
||||||
@emu.post_init
|
@emu.post_init
|
||||||
end
|
end
|
||||||
|
|
||||||
def render_menu : Nil
|
# Audio
|
||||||
if ImGui.begin_menu "Game Boy Advance"
|
|
||||||
@emu.toggle_sync if ImGui.menu_item("Audio Sync", "", emu.apu.sync)
|
def sync? : Bool
|
||||||
ImGui.menu_item("Debug", "", pointerof(@debug_window))
|
@emu.apu.sync
|
||||||
ImGui.end_menu
|
end
|
||||||
end
|
|
||||||
|
# Debug
|
||||||
|
|
||||||
|
def render_debug_items : Nil
|
||||||
|
ImGui.menu_item("Debug", "", pointerof(@debug_window))
|
||||||
end
|
end
|
||||||
|
|
||||||
def render_windows : Nil
|
def render_windows : Nil
|
||||||
|
|
|
@ -12,22 +12,31 @@ class StubbedController < Controller
|
||||||
def initialize(*args, **kwargs)
|
def initialize(*args, **kwargs)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Control
|
||||||
|
|
||||||
|
def run_until_frame : Nil
|
||||||
|
end
|
||||||
|
|
||||||
|
# Audio
|
||||||
|
|
||||||
|
def sync? : Bool
|
||||||
|
true
|
||||||
|
end
|
||||||
|
|
||||||
|
def toggle_sync : Nil
|
||||||
|
end
|
||||||
|
|
||||||
|
# Video
|
||||||
|
|
||||||
def get_framebuffer : Slice(UInt16)
|
def get_framebuffer : Slice(UInt16)
|
||||||
Slice(UInt16).new 0
|
Slice(UInt16).new 0
|
||||||
end
|
end
|
||||||
|
|
||||||
def run_until_frame : Nil
|
# Input
|
||||||
end
|
|
||||||
|
|
||||||
def handle_controller_event(event : SDL::Event::JoyHat | SDL::Event::JoyButton) : Nil
|
def handle_controller_event(event : SDL::Event::JoyHat | SDL::Event::JoyButton) : Nil
|
||||||
end
|
end
|
||||||
|
|
||||||
def handle_input(input : Input, pressed : Bool) : Nil
|
def handle_input(input : Input, pressed : Bool) : Nil
|
||||||
end
|
end
|
||||||
|
|
||||||
def toggle_sync : Nil
|
|
||||||
end
|
|
||||||
|
|
||||||
def actions(& : Action ->)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -22,8 +22,6 @@ class SDLOpenGLImGuiFrontend < Frontend
|
||||||
@last_time = Time.utc
|
@last_time = Time.utc
|
||||||
@seconds : Int32 = Time.utc.second
|
@seconds : Int32 = Time.utc.second
|
||||||
|
|
||||||
@enable_blend = false
|
|
||||||
@blending = false
|
|
||||||
@enable_overlay = false
|
@enable_overlay = false
|
||||||
@pause = false
|
@pause = false
|
||||||
@recents : Array(String) = recents
|
@recents : Array(String) = recents
|
||||||
|
@ -49,7 +47,7 @@ class SDLOpenGLImGuiFrontend < Frontend
|
||||||
LibGL.use_program(@shader_programs[@controller.class])
|
LibGL.use_program(@shader_programs[@controller.class])
|
||||||
@opengl_info = OpenGLInfo.new
|
@opengl_info = OpenGLInfo.new
|
||||||
@io = setup_imgui
|
@io = setup_imgui
|
||||||
LibSDL.gl_set_swap_interval(1) if @controller.class == StubbedController
|
LibSDL.gl_set_swap_interval(1) if stubbed?
|
||||||
|
|
||||||
@file_explorer = ImGui::FileExplorer.new
|
@file_explorer = ImGui::FileExplorer.new
|
||||||
@keybindings = ImGui::Keybindings.new
|
@keybindings = ImGui::Keybindings.new
|
||||||
|
@ -98,8 +96,6 @@ class SDLOpenGLImGuiFrontend < Frontend
|
||||||
LibGL.use_program(@shader_programs[@controller.class])
|
LibGL.use_program(@shader_programs[@controller.class])
|
||||||
|
|
||||||
LibSDL.gl_set_swap_interval(0)
|
LibSDL.gl_set_swap_interval(0)
|
||||||
@enable_blend = false
|
|
||||||
@blending = false
|
|
||||||
@enable_overlay = false
|
@enable_overlay = false
|
||||||
@pause = false
|
@pause = false
|
||||||
end
|
end
|
||||||
|
@ -137,15 +133,6 @@ class SDLOpenGLImGuiFrontend < Frontend
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private def toggle_blending : Nil
|
|
||||||
if @blending
|
|
||||||
LibGL.disable(LibGL::BLEND)
|
|
||||||
else
|
|
||||||
LibGL.enable(LibGL::BLEND)
|
|
||||||
end
|
|
||||||
@blending = @enable_blend = !@blending
|
|
||||||
end
|
|
||||||
|
|
||||||
private def render_game : Nil
|
private def render_game : Nil
|
||||||
LibGL.tex_image_2d(
|
LibGL.tex_image_2d(
|
||||||
LibGL::TEXTURE_2D,
|
LibGL::TEXTURE_2D,
|
||||||
|
@ -161,6 +148,10 @@ class SDLOpenGLImGuiFrontend < Frontend
|
||||||
LibGL.draw_arrays(LibGL::TRIANGLE_STRIP, 0, 4)
|
LibGL.draw_arrays(LibGL::TRIANGLE_STRIP, 0, 4)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private def stubbed? : Bool
|
||||||
|
@controller.class == StubbedController
|
||||||
|
end
|
||||||
|
|
||||||
private def render_imgui : Nil
|
private def render_imgui : Nil
|
||||||
ImGui::OpenGL3.new_frame
|
ImGui::OpenGL3.new_frame
|
||||||
ImGui::SDL2.new_frame(@window)
|
ImGui::SDL2.new_frame(@window)
|
||||||
|
@ -171,13 +162,11 @@ class SDLOpenGLImGuiFrontend < Frontend
|
||||||
open_bios_selection = false
|
open_bios_selection = false
|
||||||
open_keybindings = false
|
open_keybindings = false
|
||||||
|
|
||||||
if (LibSDL.get_mouse_focus || @controller.class == StubbedController) && !@file_explorer.open? && !@keybindings.open?
|
if (LibSDL.get_mouse_focus || stubbed?) && !@file_explorer.open? && !@keybindings.open?
|
||||||
if ImGui.begin_main_menu_bar
|
if ImGui.begin_main_menu_bar
|
||||||
if ImGui.begin_menu "File"
|
if ImGui.begin_menu "File"
|
||||||
previously_paused = @pause
|
|
||||||
|
|
||||||
open_rom_selection = ImGui.menu_item "Open ROM"
|
open_rom_selection = ImGui.menu_item "Open ROM"
|
||||||
open_bios_selection = ImGui.menu_item "Select BIOS" unless @controller.class == StubbedController
|
open_bios_selection = ImGui.menu_item "Select BIOS" unless stubbed?
|
||||||
if ImGui.begin_menu "Recent", @recents.size > 0
|
if ImGui.begin_menu "Recent", @recents.size > 0
|
||||||
@recents.each do |recent|
|
@recents.each do |recent|
|
||||||
load_new_rom(recent) if ImGui.menu_item recent
|
load_new_rom(recent) if ImGui.menu_item recent
|
||||||
|
@ -190,19 +179,28 @@ class SDLOpenGLImGuiFrontend < Frontend
|
||||||
ImGui.end_menu
|
ImGui.end_menu
|
||||||
end
|
end
|
||||||
ImGui.separator
|
ImGui.separator
|
||||||
ImGui.menu_item "Overlay", "", pointerof(@enable_overlay)
|
|
||||||
# ImGui.menu_item "Blend", "", pointerof(@enable_blend) todo: re-implement blending now that frames are cleared
|
|
||||||
ImGui.menu_item "Pause", "", pointerof(@pause)
|
|
||||||
open_keybindings = ImGui.menu_item "Keybindings"
|
open_keybindings = ImGui.menu_item "Keybindings"
|
||||||
ImGui.separator
|
ImGui.separator
|
||||||
exit if ImGui.menu_item "Exit", "Ctrl+Q"
|
exit if ImGui.menu_item "Exit", "Ctrl+Q"
|
||||||
ImGui.end_menu
|
ImGui.end_menu
|
||||||
|
|
||||||
toggle_blending if @enable_blend ^ @blending
|
|
||||||
LibSDL.gl_set_swap_interval(@pause.to_unsafe) if previously_paused ^ @pause
|
|
||||||
end
|
end
|
||||||
|
|
||||||
@controller.render_menu
|
if ImGui.begin_menu "Emulation"
|
||||||
|
previously_paused = @pause
|
||||||
|
|
||||||
|
ImGui.menu_item "Pause", "", pointerof(@pause)
|
||||||
|
@controller.toggle_sync if ImGui.menu_item "Audio Sync", selected: @controller.sync?, enabled: !stubbed?
|
||||||
|
|
||||||
|
LibSDL.gl_set_swap_interval(@pause.to_unsafe) if previously_paused ^ @pause
|
||||||
|
ImGui.end_menu
|
||||||
|
end
|
||||||
|
|
||||||
|
if ImGui.begin_menu "Debug"
|
||||||
|
ImGui.menu_item "Overlay", "", pointerof(@enable_overlay)
|
||||||
|
ImGui.separator
|
||||||
|
@controller.render_debug_items
|
||||||
|
ImGui.end_menu
|
||||||
|
end
|
||||||
|
|
||||||
overlay_height += ImGui.get_window_size.y
|
overlay_height += ImGui.get_window_size.y
|
||||||
ImGui.end_main_menu_bar
|
ImGui.end_main_menu_bar
|
||||||
|
|
Loading…
Add table
Reference in a new issue