The open source OpenXR runtime

st/gui: draw gui_widget_native_images with header, scale slider and rotation checkbox

Part-of: <https://gitlab.freedesktop.org/monado/monado/-/merge_requests/2303>

authored by

Fernando Velazquez Innella and committed by
Marge Bot
44179cd1 3eabdc77

+76 -7
+9
src/xrt/state_trackers/gui/gui_scene_debug.c
··· 444 444 static void 445 445 on_native_images_debug_var(const char *name, void *ptr, struct draw_state *state) 446 446 { 447 + bool gui_header = !state->inhibit_sink_headers; 448 + 447 449 struct debug_scene *ds = state->ds; 448 450 struct u_native_images_debug *unid = (struct u_native_images_debug *)ptr; 451 + 452 + if (gui_header) { 453 + const ImGuiTreeNodeFlags_ flags = ImGuiTreeNodeFlags_DefaultOpen; 454 + if (!igCollapsingHeaderBoolPtr(name, NULL, flags)) { 455 + return; 456 + } 457 + } 449 458 450 459 struct gui_widget_native_images *gwni = gui_widget_native_images_storage_ensure(&ds->gwnis, unid); 451 460 if (gwni == NULL) {
+61 -7
src/xrt/state_trackers/gui/gui_widget_native_images.c
··· 15 15 #include "util/u_native_images_debug.h" 16 16 17 17 #include "gui_ogl.h" 18 + #include "gui_imgui.h" 18 19 #include "gui_widget_native_images.h" 19 20 20 21 #include <assert.h> ··· 71 72 gwni->flip_y = unid->flip_y; 72 73 } 73 74 75 + /* 76 + * 77 + * Misc helpers and interface functions. 78 + * 79 + */ 80 + 81 + static void 82 + window_draw_misc(struct gui_widget_native_images *gwni) 83 + { 84 + igSliderFloat("", &gwni->scale, 20.0, 300.f, "Scale %f%%", ImGuiSliderFlags_None); 85 + 86 + static ImVec2 button_dims = {0, 0}; 87 + 88 + igSameLine(0.0f, 4.0f); 89 + bool minus = igButton("-", button_dims); 90 + 91 + igSameLine(0.0f, 4.0f); 92 + bool plus = igButton("+", button_dims); 93 + 94 + static const double scales[] = { 95 + 25.0, 50.0, 100.0, 200.0, 300.0, 96 + }; 97 + 98 + if (plus) { 99 + for (uint32_t i = 0; i < ARRAY_SIZE(scales); i++) { 100 + if (gwni->scale >= scales[i]) { 101 + continue; 102 + } 103 + gwni->scale = scales[i]; 104 + break; 105 + } 106 + } else if (minus) { 107 + // Initial length always greater then 0 so safe. 108 + for (uint32_t i = ARRAY_SIZE(scales); i-- > 0;) { 109 + if (gwni->scale <= scales[i]) { 110 + continue; 111 + } 112 + gwni->scale = scales[i]; 113 + break; 114 + } 115 + } 116 + 117 + igSameLine(0, 30); 118 + 119 + igCheckbox("Rotate 180 degrees", &gwni->rotate_180); 120 + } 74 121 75 122 /* 76 123 * ··· 83 130 { 84 131 U_ZERO(gwni); 85 132 gwni->active_index = GUI_WIDGET_SWAPCHAIN_INVALID_INDEX; 133 + gwni->scale = 50.0f; 86 134 } 87 135 88 136 void ··· 115 163 return; 116 164 } 117 165 166 + igPushIDPtr(gwni); 167 + 168 + window_draw_misc(gwni); 169 + 118 170 uint32_t tex_id = gwni->textures[gwni->active_index]; 119 171 120 - gui_ogl_draw_image( // 121 - gwni->width, // width 122 - gwni->height, // height 123 - tex_id, // tex_id 124 - 0.5f, // scale 125 - false, // rotate_180 126 - gwni->flip_y); // flip_y 172 + gui_ogl_draw_image( // 173 + gwni->width, // width 174 + gwni->height, // height 175 + tex_id, // tex_id 176 + gwni->scale / 100.0f, // scale 177 + gwni->rotate_180, // rotate_180 178 + gwni->flip_y); // flip_y 179 + 180 + igPopID(); 127 181 } 128 182 129 183 void
+6
src/xrt/state_trackers/gui/gui_widget_native_images.h
··· 42 42 //! Dimensions. 43 43 uint32_t width, height; 44 44 45 + //! Scale 46 + float scale; 47 + 48 + //! Rotate the image by 180 degrees 49 + bool rotate_180; 50 + 45 51 //! Set to GUI_WIDGET_SWAPCHAIN_INVALID_INDEX on invalid. 46 52 uint32_t active_index; 47 53