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
imgui:
github: oprypin/crystal-imgui
tag: v1.87
tag: v1.88
imgui-backends:
github: mattrberry/crystal-imgui-backends
tag: v1.87
tag: v1.88
development_dependencies:
stumpy_png:

View file

@ -30,18 +30,17 @@ class GBAController < Controller
def render_windows : Nil
if @debug_window
ImGui.begin("Video", pointerof(@debug_window))
if ImGui.begin_tab_bar "VideoTabBar"
render_palettes_tab_item if ImGui.begin_tab_item "Palettes"
ImGui.end_tab_bar
ImGui.window("Video", pointerof(@debug_window)) do
ImGui.tab_bar "VideoTabBar" do
render_palettes_tab_item
end
end
ImGui.end
end
if @scheduler_window
cycles = @emu.scheduler.cycles
ImGui.begin("Scheduler", pointerof(@scheduler_window))
ImGui.window("Scheduler", pointerof(@scheduler_window)) do
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("Type")
ImGui.table_headers_row
@ -52,21 +51,21 @@ class GBAController < Controller
ImGui.table_set_column_index 1
ImGui.text_unformatted event.type.to_s
end
ImGui.end_table
end
ImGui.end
end
end
end
private def render_palettes_tab_item : Nil
ImGui.tab_item("Palettes") do
pram = @emu.ppu.pram.to_unsafe.as(UInt16*)
flags = ImGui::ImGuiColorEditFlags::NoAlpha | ImGui::ImGuiColorEditFlags::NoPicker |
ImGui::ImGuiColorEditFlags::NoOptions | ImGui::ImGuiColorEditFlags::NoInputs |
ImGui::ImGuiColorEditFlags::NoLabel | ImGui::ImGuiColorEditFlags::NoSidePreview |
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|
group do
ImGui.group do
16.times do |palette_row|
16.times do |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
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

View file

@ -226,11 +226,11 @@ class SDLOpenGLImGuiFrontend < Frontend
open_keybindings = false
if show_menu_bar?
if ImGui.begin_main_menu_bar
if ImGui.begin_menu "File"
if ImGui.main_menu_bar do
ImGui.menu "File" do
open_rom_selection = ImGui.menu_item "Open ROM"
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|
load_new_rom(recent) if ImGui.menu_item recent
end
@ -239,27 +239,24 @@ class SDLOpenGLImGuiFrontend < Frontend
@config.recents.clear
@config.commit
end
ImGui.end_menu
end
ImGui.separator
open_keybindings = ImGui.menu_item "Keybindings"
ImGui.separator
exit if ImGui.menu_item "Exit", "Ctrl+Q"
ImGui.end_menu
end
if ImGui.begin_menu "Emulation"
ImGui.menu "Emulation" do
pause = @pause
ImGui.menu_item "Pause", "Ctrl+P", pointerof(pause)
@controller.toggle_sync if ImGui.menu_item "Audio Sync", "Tab", @controller.sync?, !stubbed?
pause(pause)
ImGui.end_menu
end
if ImGui.begin_menu "Audio/Video"
if ImGui.begin_menu "Frame size"
ImGui.menu "Audio/Video" do
ImGui.menu "Frame size" do
(1..8).each do |scale|
if ImGui.menu_item "#{scale}x", selected: scale == @scale
@scale = scale
@ -268,20 +265,17 @@ class SDLOpenGLImGuiFrontend < Frontend
end
ImGui.separator
@window.fullscreen = @fullscreen if ImGui.menu_item "Fullscreen", "Ctrl+F", pointerof(@fullscreen)
ImGui.end_menu
end
ImGui.end_menu
end
if ImGui.begin_menu "Debug"
ImGui.menu "Debug" do
ImGui.menu_item "Overlay", "", pointerof(@enable_overlay)
ImGui.separator
@controller.render_debug_items
ImGui.end_menu
end
overlay_height += ImGui.get_window_size.y
ImGui.end_main_menu_bar
end
end
end
@ -293,9 +287,9 @@ class SDLOpenGLImGuiFrontend < Frontend
if @enable_overlay
ImGui.set_next_window_pos(ImGui::ImVec2.new 10, overlay_height)
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::NoSavedSettings)
ImGui::ImGuiWindowFlags::NoSavedSettings) do
io_framerate = @io.framerate
ImGui.text("FPS: #{io_framerate.format(decimal_places: 1)}")
ImGui.text("Frame time: #{(1000 / io_framerate).format(decimal_places: 3)}ms")
@ -303,7 +297,7 @@ class SDLOpenGLImGuiFrontend < Frontend
ImGui.text("OpenGL")
ImGui.text(" Version: #{@opengl_info.version}")
ImGui.text(" Shading: #{@opengl_info.shading}")
ImGui.end
end
end
@controller.render_windows

View file

@ -22,7 +22,7 @@ module ImGui
ImGui.open_popup(name.to_s) if open_popup
center = ImGui.get_main_viewport.get_center
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.each_with_index do |part, idx|
ImGui.same_line unless idx == 0
@ -31,7 +31,7 @@ module ImGui
display_size = ImGui.get_main_viewport.size
width = Math.min(display_size.x - 40, 600)
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|
next if entry[:hidden] && !@match_hidden
next if entry[:file?] && !extensions.nil? && !extensions.includes?(entry[:extension])
@ -53,16 +53,14 @@ module ImGui
end
ImGui.set_item_default_focus if is_selected
end
ImGui.end_list_box
end
ImGui.begin_group
ImGui.group do
open_file(name) if ImGui.button "Open"
ImGui.same_line
close if ImGui.button "Cancel"
ImGui.same_line(spacing: 10)
ImGui.checkbox("Show hidden files?", pointerof(@match_hidden))
ImGui.end_group
ImGui.end_popup
end
end
end

View file

@ -41,7 +41,7 @@ module ImGui
center = ImGui.get_main_viewport.get_center
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)
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|
selected = @selection == input
keycode = @editing_keycodes.key_for?(input)
@ -58,7 +58,6 @@ module ImGui
apply if ImGui.button "Apply"
ImGui.same_line
close if ImGui.button "Cancel"
ImGui.end_popup
end
end