move to imgui 1.88 and utilize new crystal-imgui semantics

This commit is contained in:
Matthew Berry 2022-09-28 17:37:11 -07:00
parent 4551104192
commit b052a6d130
5 changed files with 100 additions and 129 deletions

View file

@ -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:

View file

@ -30,74 +30,54 @@ 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
@emu.scheduler.events.each do |event| @emu.scheduler.events.each do |event|
ImGui.table_next_row ImGui.table_next_row
ImGui.table_set_column_index 0 ImGui.table_set_column_index 0
ImGui.text_unformatted (event.cycles - cycles).to_s ImGui.text_unformatted (event.cycles - cycles).to_s
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 end
ImGui.end_table
end end
ImGui.end
end end
end end
private def render_palettes_tab_item : Nil private def render_palettes_tab_item : Nil
pram = @emu.ppu.pram.to_unsafe.as(UInt16*) ImGui.tab_item("Palettes") do
flags = ImGui::ImGuiColorEditFlags::NoAlpha | ImGui::ImGuiColorEditFlags::NoPicker | pram = @emu.ppu.pram.to_unsafe.as(UInt16*)
ImGui::ImGuiColorEditFlags::NoOptions | ImGui::ImGuiColorEditFlags::NoInputs | flags = ImGui::ImGuiColorEditFlags::NoAlpha | ImGui::ImGuiColorEditFlags::NoPicker |
ImGui::ImGuiColorEditFlags::NoLabel | ImGui::ImGuiColorEditFlags::NoSidePreview | ImGui::ImGuiColorEditFlags::NoOptions | ImGui::ImGuiColorEditFlags::NoInputs |
ImGui::ImGuiColorEditFlags::NoDragDrop | ImGui::ImGuiColorEditFlags::NoBorder ImGui::ImGuiColorEditFlags::NoLabel | ImGui::ImGuiColorEditFlags::NoSidePreview |
with_style(ImGui::ImGuiStyleVar::ItemSpacing, ImGui::ImVec2.new(0, 0)) do ImGui::ImGuiColorEditFlags::NoDragDrop | ImGui::ImGuiColorEditFlags::NoBorder
2.times do |idx| ImGui.with_style_var(ImGui::ImGuiStyleVar::ItemSpacing, ImGui::ImVec2.new(0, 0)) do
group do 2.times do |idx|
16.times do |palette_row| ImGui.group do
16.times do |palette_col| 16.times do |palette_row|
color = (pram + 0x100 * idx)[palette_row * 16 + palette_col] 16.times do |palette_col|
rgb = ImGui::ImVec4.new((color & 0x1F) / 0x1F, (color >> 5 & 0x1F) / 0x1F, (color >> 10 & 0x1F) / 0x1F, 1) color = (pram + 0x100 * idx)[palette_row * 16 + palette_col]
ImGui.color_button("", rgb, flags, ImGui::ImVec2.new(10, 10)) rgb = ImGui::ImVec4.new((color & 0x1F) / 0x1F, (color >> 5 & 0x1F) / 0x1F, (color >> 10 & 0x1F) / 0x1F, 1)
ImGui.same_line unless palette_col == 15 ImGui.color_button("", rgb, flags, ImGui::ImVec2.new(10, 10))
ImGui.same_line unless palette_col == 15
end
end end
end end
ImGui.same_line(spacing: 4_f32) if idx == 0
end end
ImGui.same_line(spacing: 4_f32) if idx == 0
end end
end end
ImGui.end_tab_item
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

View file

@ -226,62 +226,56 @@ 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
ImGui.separator ImGui.separator
if ImGui.menu_item "Clear" if ImGui.menu_item "Clear"
@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" end
ImGui.end_menu
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
LibSDL.set_window_size(@window, @controller.window_width * @scale, @controller.window_height * @scale) LibSDL.set_window_size(@window, @controller.window_width * @scale, @controller.window_height * @scale)
end end
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 end
ImGui.end_menu
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,17 +287,17 @@ 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")
ImGui.separator ImGui.separator
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

View file

@ -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

View file

@ -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