| 1863 | //----------------------------------------------------------------------------- |
| 1864 | |
| 1865 | static void DemoWindowWidgetsImages() |
| 1866 | { |
| 1867 | if (ImGui::TreeNode("Images")) |
| 1868 | { |
| 1869 | IMGUI_DEMO_MARKER("Widgets/Images"); |
| 1870 | ImGuiIO& io = ImGui::GetIO(); |
| 1871 | ImGui::TextWrapped( |
| 1872 | "Below we are displaying the font texture (which is the only texture we have access to in this demo). " |
| 1873 | "Use the 'ImTextureID' type as storage to pass pointers or identifier to your own texture data. " |
| 1874 | "Hover the texture for a zoomed view!"); |
| 1875 | |
| 1876 | // Below we are displaying the font texture because it is the only texture we have access to inside the demo! |
| 1877 | // Read description about ImTextureID/ImTextureRef and FAQ for details about texture identifiers. |
| 1878 | // If you use one of the default imgui_impl_XXXX.cpp rendering backend, they all have comments at the top |
| 1879 | // of their respective source file to specify what they are using as texture identifier, for example: |
| 1880 | // - The imgui_impl_dx11.cpp renderer expect a 'ID3D11ShaderResourceView*' pointer. |
| 1881 | // - The imgui_impl_opengl3.cpp renderer expect a GLuint OpenGL texture identifier, etc. |
| 1882 | // So with the DirectX11 backend, you call ImGui::Image() with a 'ID3D11ShaderResourceView*' cast to ImTextureID. |
| 1883 | // - If you decided that ImTextureID = MyEngineTexture*, then you can pass your MyEngineTexture* pointers |
| 1884 | // to ImGui::Image(), and gather width/height through your own functions, etc. |
| 1885 | // - You can use ShowMetricsWindow() to inspect the draw data that are being passed to your renderer, |
| 1886 | // it will help you debug issues if you are confused about it. |
| 1887 | // - Consider using the lower-level ImDrawList::AddImage() API, via ImGui::GetWindowDrawList()->AddImage(). |
| 1888 | // - Read https://github.com/ocornut/imgui/blob/master/docs/FAQ.md |
| 1889 | // - Read https://github.com/ocornut/imgui/wiki/Image-Loading-and-Displaying-Examples |
| 1890 | |
| 1891 | // Grab the current texture identifier used by the font atlas. |
| 1892 | ImFontAtlas* atlas = io.Fonts; |
| 1893 | ImTextureRef my_tex_id = atlas->TexRef; |
| 1894 | float my_tex_w = (float)atlas->TexData->Width; // Regular user code should never have to care about TexData-> fields, but since we want to display the entire texture here, we pull Width/Height from it. |
| 1895 | float my_tex_h = (float)atlas->TexData->Height; |
| 1896 | ImGui::Text("%.0fx%.0f", my_tex_w, my_tex_h); |
| 1897 | |
| 1898 | // Basic drawing |
| 1899 | ImGui::SeparatorText("Image()/ImageWithBg() function"); |
| 1900 | ImVec2 uv_min = ImVec2(0.0f, 0.0f); // Top-left |
| 1901 | ImVec2 uv_max = ImVec2(1.0f, 1.0f); // Lower-right |
| 1902 | ImGui::PushStyleVar(ImGuiStyleVar_ImageBorderSize, IM_MAX(1.0f, ImGui::GetStyle().ImageBorderSize)); |
| 1903 | ImGui::ImageWithBg(my_tex_id, ImVec2(my_tex_w, my_tex_h), uv_min, uv_max, ImVec4(0.0f, 0.0f, 0.0f, 1.0f)); |
| 1904 | ImGui::PopStyleVar(); |
| 1905 | |
| 1906 | // Fancy widget |
| 1907 | ImGui::SeparatorText("Interactive Image Viewer"); |
| 1908 | static ExampleImageViewerData image_viewer; |
| 1909 | ImVec2 canvas_size(ImGui::GetContentRegionAvail().x, my_tex_h * 2.0f); |
| 1910 | ExampleImageViewer_DrawOptions(&image_viewer); |
| 1911 | ExampleImageViewer_DrawCanvas(&image_viewer, canvas_size, my_tex_id, (int)my_tex_w, (int)my_tex_h); |
| 1912 | |
| 1913 | IMGUI_DEMO_MARKER("Widgets/Images/Textured buttons"); |
| 1914 | ImGui::SeparatorText("Textured Buttons"); |
| 1915 | ImGui::TextWrapped("And now some textured buttons.."); |
| 1916 | static int pressed_count = 0; |
| 1917 | for (int i = 0; i < 8; i++) |
| 1918 | { |
| 1919 | // UV coordinates are often (0.0f, 0.0f) and (1.0f, 1.0f) to display an entire textures. |
| 1920 | // Here are trying to display only a 32x32 pixels area of the texture, hence the UV computation. |
| 1921 | // Read about UV coordinates here: https://github.com/ocornut/imgui/wiki/Image-Loading-and-Displaying-Examples |
| 1922 | ImGui::PushID(i); |
no test coverage detected