mirror of
https://github.com/mattrberry/crab.git
synced 2024-12-26 09:58:25 +01:00
move to imgui 1.88 and utilize new crystal-imgui semantics
This commit is contained in:
parent
4551104192
commit
b052a6d130
5 changed files with 100 additions and 129 deletions
|
@ -22,10 +22,10 @@ dependencies:
|
||||||
github: nulldotpro/LibGL
|
github: nulldotpro/LibGL
|
||||||
imgui:
|
imgui:
|
||||||
github: oprypin/crystal-imgui
|
github: oprypin/crystal-imgui
|
||||||
tag: v1.87
|
tag: v1.88
|
||||||
imgui-backends:
|
imgui-backends:
|
||||||
github: mattrberry/crystal-imgui-backends
|
github: mattrberry/crystal-imgui-backends
|
||||||
tag: v1.87
|
tag: v1.88
|
||||||
|
|
||||||
development_dependencies:
|
development_dependencies:
|
||||||
stumpy_png:
|
stumpy_png:
|
||||||
|
|
|
@ -30,18 +30,17 @@ class GBAController < Controller
|
||||||
|
|
||||||
def render_windows : Nil
|
def render_windows : Nil
|
||||||
if @debug_window
|
if @debug_window
|
||||||
ImGui.begin("Video", pointerof(@debug_window))
|
ImGui.window("Video", pointerof(@debug_window)) do
|
||||||
if ImGui.begin_tab_bar "VideoTabBar"
|
ImGui.tab_bar "VideoTabBar" do
|
||||||
render_palettes_tab_item if ImGui.begin_tab_item "Palettes"
|
render_palettes_tab_item
|
||||||
ImGui.end_tab_bar
|
end
|
||||||
end
|
end
|
||||||
ImGui.end
|
|
||||||
end
|
end
|
||||||
if @scheduler_window
|
if @scheduler_window
|
||||||
cycles = @emu.scheduler.cycles
|
cycles = @emu.scheduler.cycles
|
||||||
ImGui.begin("Scheduler", pointerof(@scheduler_window))
|
ImGui.window("Scheduler", pointerof(@scheduler_window)) do
|
||||||
ImGui.text("Total cycles: #{cycles}")
|
ImGui.text("Total cycles: #{cycles}")
|
||||||
if ImGui.begin_table("Table", 2)
|
ImGui.table("Table", 2) do
|
||||||
ImGui.table_setup_column("Cycles")
|
ImGui.table_setup_column("Cycles")
|
||||||
ImGui.table_setup_column("Type")
|
ImGui.table_setup_column("Type")
|
||||||
ImGui.table_headers_row
|
ImGui.table_headers_row
|
||||||
|
@ -52,21 +51,21 @@ class GBAController < Controller
|
||||||
ImGui.table_set_column_index 1
|
ImGui.table_set_column_index 1
|
||||||
ImGui.text_unformatted event.type.to_s
|
ImGui.text_unformatted event.type.to_s
|
||||||
end
|
end
|
||||||
ImGui.end_table
|
|
||||||
end
|
end
|
||||||
ImGui.end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private def render_palettes_tab_item : Nil
|
private def render_palettes_tab_item : Nil
|
||||||
|
ImGui.tab_item("Palettes") do
|
||||||
pram = @emu.ppu.pram.to_unsafe.as(UInt16*)
|
pram = @emu.ppu.pram.to_unsafe.as(UInt16*)
|
||||||
flags = ImGui::ImGuiColorEditFlags::NoAlpha | ImGui::ImGuiColorEditFlags::NoPicker |
|
flags = ImGui::ImGuiColorEditFlags::NoAlpha | ImGui::ImGuiColorEditFlags::NoPicker |
|
||||||
ImGui::ImGuiColorEditFlags::NoOptions | ImGui::ImGuiColorEditFlags::NoInputs |
|
ImGui::ImGuiColorEditFlags::NoOptions | ImGui::ImGuiColorEditFlags::NoInputs |
|
||||||
ImGui::ImGuiColorEditFlags::NoLabel | ImGui::ImGuiColorEditFlags::NoSidePreview |
|
ImGui::ImGuiColorEditFlags::NoLabel | ImGui::ImGuiColorEditFlags::NoSidePreview |
|
||||||
ImGui::ImGuiColorEditFlags::NoDragDrop | ImGui::ImGuiColorEditFlags::NoBorder
|
ImGui::ImGuiColorEditFlags::NoDragDrop | ImGui::ImGuiColorEditFlags::NoBorder
|
||||||
with_style(ImGui::ImGuiStyleVar::ItemSpacing, ImGui::ImVec2.new(0, 0)) do
|
ImGui.with_style_var(ImGui::ImGuiStyleVar::ItemSpacing, ImGui::ImVec2.new(0, 0)) do
|
||||||
2.times do |idx|
|
2.times do |idx|
|
||||||
group do
|
ImGui.group do
|
||||||
16.times do |palette_row|
|
16.times do |palette_row|
|
||||||
16.times do |palette_col|
|
16.times do |palette_col|
|
||||||
color = (pram + 0x100 * idx)[palette_row * 16 + palette_col]
|
color = (pram + 0x100 * idx)[palette_row * 16 + palette_col]
|
||||||
|
@ -79,25 +78,6 @@ class GBAController < Controller
|
||||||
ImGui.same_line(spacing: 4_f32) if idx == 0
|
ImGui.same_line(spacing: 4_f32) if idx == 0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
ImGui.end_tab_item
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def group(&) : Nil
|
|
||||||
ImGui.begin_group
|
|
||||||
yield
|
|
||||||
ImGui.end_group
|
|
||||||
end
|
|
||||||
|
|
||||||
def child(*args, **kwargs, &) : Nil
|
|
||||||
if ImGui.begin_child(*args, **kwargs)
|
|
||||||
yield
|
|
||||||
end
|
|
||||||
ImGui.end_child
|
|
||||||
end
|
|
||||||
|
|
||||||
def with_style(*args, **kwargs, &) : Nil
|
|
||||||
ImGui.push_style_var(*args, **kwargs)
|
|
||||||
yield
|
|
||||||
ImGui.pop_style_var
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -226,11 +226,11 @@ class SDLOpenGLImGuiFrontend < Frontend
|
||||||
open_keybindings = false
|
open_keybindings = false
|
||||||
|
|
||||||
if show_menu_bar?
|
if show_menu_bar?
|
||||||
if ImGui.begin_main_menu_bar
|
if ImGui.main_menu_bar do
|
||||||
if ImGui.begin_menu "File"
|
ImGui.menu "File" do
|
||||||
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 stubbed?
|
open_bios_selection = ImGui.menu_item "Select BIOS" unless stubbed?
|
||||||
if ImGui.begin_menu "Recent", @config.recents.size > 0
|
ImGui.menu "Recent", @config.recents.size > 0 do
|
||||||
@config.recents.each do |recent|
|
@config.recents.each do |recent|
|
||||||
load_new_rom(recent) if ImGui.menu_item recent
|
load_new_rom(recent) if ImGui.menu_item recent
|
||||||
end
|
end
|
||||||
|
@ -239,27 +239,24 @@ class SDLOpenGLImGuiFrontend < Frontend
|
||||||
@config.recents.clear
|
@config.recents.clear
|
||||||
@config.commit
|
@config.commit
|
||||||
end
|
end
|
||||||
ImGui.end_menu
|
|
||||||
end
|
end
|
||||||
ImGui.separator
|
ImGui.separator
|
||||||
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
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if ImGui.begin_menu "Emulation"
|
ImGui.menu "Emulation" do
|
||||||
pause = @pause
|
pause = @pause
|
||||||
|
|
||||||
ImGui.menu_item "Pause", "Ctrl+P", pointerof(pause)
|
ImGui.menu_item "Pause", "Ctrl+P", pointerof(pause)
|
||||||
@controller.toggle_sync if ImGui.menu_item "Audio Sync", "Tab", @controller.sync?, !stubbed?
|
@controller.toggle_sync if ImGui.menu_item "Audio Sync", "Tab", @controller.sync?, !stubbed?
|
||||||
|
|
||||||
pause(pause)
|
pause(pause)
|
||||||
ImGui.end_menu
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if ImGui.begin_menu "Audio/Video"
|
ImGui.menu "Audio/Video" do
|
||||||
if ImGui.begin_menu "Frame size"
|
ImGui.menu "Frame size" do
|
||||||
(1..8).each do |scale|
|
(1..8).each do |scale|
|
||||||
if ImGui.menu_item "#{scale}x", selected: scale == @scale
|
if ImGui.menu_item "#{scale}x", selected: scale == @scale
|
||||||
@scale = scale
|
@scale = scale
|
||||||
|
@ -268,20 +265,17 @@ class SDLOpenGLImGuiFrontend < Frontend
|
||||||
end
|
end
|
||||||
ImGui.separator
|
ImGui.separator
|
||||||
@window.fullscreen = @fullscreen if ImGui.menu_item "Fullscreen", "Ctrl+F", pointerof(@fullscreen)
|
@window.fullscreen = @fullscreen if ImGui.menu_item "Fullscreen", "Ctrl+F", pointerof(@fullscreen)
|
||||||
ImGui.end_menu
|
|
||||||
end
|
end
|
||||||
ImGui.end_menu
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if ImGui.begin_menu "Debug"
|
ImGui.menu "Debug" do
|
||||||
ImGui.menu_item "Overlay", "", pointerof(@enable_overlay)
|
ImGui.menu_item "Overlay", "", pointerof(@enable_overlay)
|
||||||
ImGui.separator
|
ImGui.separator
|
||||||
@controller.render_debug_items
|
@controller.render_debug_items
|
||||||
ImGui.end_menu
|
|
||||||
end
|
end
|
||||||
|
|
||||||
overlay_height += ImGui.get_window_size.y
|
overlay_height += ImGui.get_window_size.y
|
||||||
ImGui.end_main_menu_bar
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -293,9 +287,9 @@ class SDLOpenGLImGuiFrontend < Frontend
|
||||||
if @enable_overlay
|
if @enable_overlay
|
||||||
ImGui.set_next_window_pos(ImGui::ImVec2.new 10, overlay_height)
|
ImGui.set_next_window_pos(ImGui::ImVec2.new 10, overlay_height)
|
||||||
ImGui.set_next_window_bg_alpha(0.5)
|
ImGui.set_next_window_bg_alpha(0.5)
|
||||||
ImGui.begin("Overlay", pointerof(@enable_overlay),
|
ImGui.window("Overlay", pointerof(@enable_overlay),
|
||||||
ImGui::ImGuiWindowFlags::NoDecoration | ImGui::ImGuiWindowFlags::NoMove |
|
ImGui::ImGuiWindowFlags::NoDecoration | ImGui::ImGuiWindowFlags::NoMove |
|
||||||
ImGui::ImGuiWindowFlags::NoSavedSettings)
|
ImGui::ImGuiWindowFlags::NoSavedSettings) do
|
||||||
io_framerate = @io.framerate
|
io_framerate = @io.framerate
|
||||||
ImGui.text("FPS: #{io_framerate.format(decimal_places: 1)}")
|
ImGui.text("FPS: #{io_framerate.format(decimal_places: 1)}")
|
||||||
ImGui.text("Frame time: #{(1000 / io_framerate).format(decimal_places: 3)}ms")
|
ImGui.text("Frame time: #{(1000 / io_framerate).format(decimal_places: 3)}ms")
|
||||||
|
@ -303,7 +297,7 @@ class SDLOpenGLImGuiFrontend < Frontend
|
||||||
ImGui.text("OpenGL")
|
ImGui.text("OpenGL")
|
||||||
ImGui.text(" Version: #{@opengl_info.version}")
|
ImGui.text(" Version: #{@opengl_info.version}")
|
||||||
ImGui.text(" Shading: #{@opengl_info.shading}")
|
ImGui.text(" Shading: #{@opengl_info.shading}")
|
||||||
ImGui.end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@controller.render_windows
|
@controller.render_windows
|
||||||
|
|
|
@ -22,7 +22,7 @@ module ImGui
|
||||||
ImGui.open_popup(name.to_s) if open_popup
|
ImGui.open_popup(name.to_s) if open_popup
|
||||||
center = ImGui.get_main_viewport.get_center
|
center = ImGui.get_main_viewport.get_center
|
||||||
ImGui.set_next_window_pos(center, ImGui::ImGuiCond::Appearing, ImGui::ImVec2.new(0.5, 0.5))
|
ImGui.set_next_window_pos(center, ImGui::ImGuiCond::Appearing, ImGui::ImVec2.new(0.5, 0.5))
|
||||||
if ImGui.begin_popup_modal(name.to_s, flags: ImGui::ImGuiWindowFlags::AlwaysAutoResize)
|
ImGui.popup_modal(name.to_s, flags: ImGui::ImGuiWindowFlags::AlwaysAutoResize) do
|
||||||
parts = @config.explorer_dir.parts
|
parts = @config.explorer_dir.parts
|
||||||
parts.each_with_index do |part, idx|
|
parts.each_with_index do |part, idx|
|
||||||
ImGui.same_line unless idx == 0
|
ImGui.same_line unless idx == 0
|
||||||
|
@ -31,7 +31,7 @@ module ImGui
|
||||||
display_size = ImGui.get_main_viewport.size
|
display_size = ImGui.get_main_viewport.size
|
||||||
width = Math.min(display_size.x - 40, 600)
|
width = Math.min(display_size.x - 40, 600)
|
||||||
height = Math.min(display_size.y - 40, 16 * ImGui.get_text_line_height_with_spacing)
|
height = Math.min(display_size.y - 40, 16 * ImGui.get_text_line_height_with_spacing)
|
||||||
if ImGui.begin_list_box("##files", ImGui::ImVec2.new(width, height))
|
ImGui.list_box("##files", ImGui::ImVec2.new(width, height)) do
|
||||||
@matched_entries.each_with_index do |entry, idx|
|
@matched_entries.each_with_index do |entry, idx|
|
||||||
next if entry[:hidden] && !@match_hidden
|
next if entry[:hidden] && !@match_hidden
|
||||||
next if entry[:file?] && !extensions.nil? && !extensions.includes?(entry[:extension])
|
next if entry[:file?] && !extensions.nil? && !extensions.includes?(entry[:extension])
|
||||||
|
@ -53,16 +53,14 @@ module ImGui
|
||||||
end
|
end
|
||||||
ImGui.set_item_default_focus if is_selected
|
ImGui.set_item_default_focus if is_selected
|
||||||
end
|
end
|
||||||
ImGui.end_list_box
|
|
||||||
end
|
end
|
||||||
ImGui.begin_group
|
ImGui.group do
|
||||||
open_file(name) if ImGui.button "Open"
|
open_file(name) if ImGui.button "Open"
|
||||||
ImGui.same_line
|
ImGui.same_line
|
||||||
close if ImGui.button "Cancel"
|
close if ImGui.button "Cancel"
|
||||||
ImGui.same_line(spacing: 10)
|
ImGui.same_line(spacing: 10)
|
||||||
ImGui.checkbox("Show hidden files?", pointerof(@match_hidden))
|
ImGui.checkbox("Show hidden files?", pointerof(@match_hidden))
|
||||||
ImGui.end_group
|
end
|
||||||
ImGui.end_popup
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,7 @@ module ImGui
|
||||||
center = ImGui.get_main_viewport.get_center
|
center = ImGui.get_main_viewport.get_center
|
||||||
ImGui.set_next_window_pos(center, ImGui::ImGuiCond::Appearing, ImGui::ImVec2.new(0.5, 0.5))
|
ImGui.set_next_window_pos(center, ImGui::ImGuiCond::Appearing, ImGui::ImVec2.new(0.5, 0.5))
|
||||||
hovered_button_color = ImGui.get_style_color_vec4(ImGui::ImGuiCol::ButtonHovered)
|
hovered_button_color = ImGui.get_style_color_vec4(ImGui::ImGuiCol::ButtonHovered)
|
||||||
if ImGui.begin_popup_modal(POPUP_NAME, flags: ImGui::ImGuiWindowFlags::AlwaysAutoResize)
|
ImGui.popup_modal(POPUP_NAME, flags: ImGui::ImGuiWindowFlags::AlwaysAutoResize) do
|
||||||
Input.each do |input|
|
Input.each do |input|
|
||||||
selected = @selection == input
|
selected = @selection == input
|
||||||
keycode = @editing_keycodes.key_for?(input)
|
keycode = @editing_keycodes.key_for?(input)
|
||||||
|
@ -58,7 +58,6 @@ module ImGui
|
||||||
apply if ImGui.button "Apply"
|
apply if ImGui.button "Apply"
|
||||||
ImGui.same_line
|
ImGui.same_line
|
||||||
close if ImGui.button "Cancel"
|
close if ImGui.button "Cancel"
|
||||||
ImGui.end_popup
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue