Browse Source

Fixes for ocornut-imgui integrations: mouse wheel, render callbacks

ocornut 10 years ago
parent
commit
eccbae09b1

+ 1 - 1
examples/09-hdr/hdr.cpp

@@ -265,7 +265,7 @@ int _main_(int /*_argc*/, char** /*_argv*/)
 			, mouseState.m_my
 			, (mouseState.m_buttons[entry::MouseButton::Left  ] ? IMGUI_MBUT_LEFT  : 0)
 			| (mouseState.m_buttons[entry::MouseButton::Right ] ? IMGUI_MBUT_RIGHT : 0)
-			, 0
+			, mouseState.m_mz
 			, width
 			, height
 			);

+ 1 - 1
examples/11-fontsdf/fontsdf.cpp

@@ -132,7 +132,7 @@ int _main_(int /*_argc*/, char** /*_argv*/)
 			, mouseState.m_my
 			, (mouseState.m_buttons[entry::MouseButton::Left  ] ? IMGUI_MBUT_LEFT  : 0)
 			| (mouseState.m_buttons[entry::MouseButton::Right ] ? IMGUI_MBUT_RIGHT : 0)
-			, 0
+			, mouseState.m_mz
 			, width
 			, height
 			);

+ 1 - 1
examples/12-lod/lod.cpp

@@ -119,7 +119,7 @@ int _main_(int /*_argc*/, char** /*_argv*/)
 			, mouseState.m_my
 			, (mouseState.m_buttons[entry::MouseButton::Left  ] ? IMGUI_MBUT_LEFT  : 0)
 			| (mouseState.m_buttons[entry::MouseButton::Right ] ? IMGUI_MBUT_RIGHT : 0)
-			, 0
+			, mouseState.m_mz
 			, width
 			, height
 			);

+ 1 - 1
examples/13-stencil/stencil.cpp

@@ -945,7 +945,7 @@ int _main_(int /*_argc*/, char** /*_argv*/)
 			, mouseState.m_my
 			, (mouseState.m_buttons[entry::MouseButton::Left  ] ? IMGUI_MBUT_LEFT  : 0)
 			| (mouseState.m_buttons[entry::MouseButton::Right ] ? IMGUI_MBUT_RIGHT : 0)
-			, 0
+			, mouseState.m_mz
 			, viewState.m_width
 			, viewState.m_height
 			);

+ 1 - 1
examples/14-shadowvolumes/shadowvolumes.cpp

@@ -2128,7 +2128,7 @@ int _main_(int /*_argc*/, char** /*_argv*/)
 			, mouseState.m_my
 			, (mouseState.m_buttons[entry::MouseButton::Left  ] ? IMGUI_MBUT_LEFT  : 0)
 			| (mouseState.m_buttons[entry::MouseButton::Right ] ? IMGUI_MBUT_RIGHT : 0)
-			, 0
+			, mouseState.m_mz
 			, viewState.m_width
 			, viewState.m_height
 			);

+ 1 - 1
examples/16-shadowmaps/shadowmaps.cpp

@@ -1974,7 +1974,7 @@ int _main_(int /*_argc*/, char** /*_argv*/)
 			, mouseState.m_my
 			, (mouseState.m_buttons[entry::MouseButton::Left  ] ? IMGUI_MBUT_LEFT  : 0)
 			| (mouseState.m_buttons[entry::MouseButton::Right ] ? IMGUI_MBUT_RIGHT : 0)
-			, 0
+			, mouseState.m_mz
 			, viewState.m_width
 			, viewState.m_height
 			);

+ 1 - 1
examples/17-drawstress/drawstress.cpp

@@ -141,7 +141,7 @@ BX_NO_INLINE bool mainloop()
 				, mouseState.m_my
 				, (mouseState.m_buttons[entry::MouseButton::Left  ] ? IMGUI_MBUT_LEFT  : 0)
 				| (mouseState.m_buttons[entry::MouseButton::Right ] ? IMGUI_MBUT_RIGHT : 0)
-				, 0
+				, mouseState.m_mz
 				, width
 				, height
 				);

+ 1 - 1
examples/18-ibl/ibl.cpp

@@ -311,7 +311,7 @@ int _main_(int /*_argc*/, char** /*_argv*/)
 			, mouseState.m_my
 			, (mouseState.m_buttons[entry::MouseButton::Left  ] ? IMGUI_MBUT_LEFT  : 0)
 			| (mouseState.m_buttons[entry::MouseButton::Right ] ? IMGUI_MBUT_RIGHT : 0)
-			, 0
+			, mouseState.m_mz
 			, width
 			, height
 			);

+ 1 - 1
examples/19-oit/oit.cpp

@@ -244,7 +244,7 @@ int _main_(int /*_argc*/, char** /*_argv*/)
 			, mouseState.m_my
 			, (mouseState.m_buttons[entry::MouseButton::Left  ] ? IMGUI_MBUT_LEFT  : 0)
 			| (mouseState.m_buttons[entry::MouseButton::Right ] ? IMGUI_MBUT_RIGHT : 0)
-			, 0
+			, mouseState.m_mz
 			, width
 			, height
 			);

+ 1 - 1
examples/21-deferred/deferred.cpp

@@ -407,7 +407,7 @@ int _main_(int /*_argc*/, char** /*_argv*/)
 				, mouseState.m_my
 				, (mouseState.m_buttons[entry::MouseButton::Left  ] ? IMGUI_MBUT_LEFT  : 0)
 				| (mouseState.m_buttons[entry::MouseButton::Right ] ? IMGUI_MBUT_RIGHT : 0)
-				, 0
+				, mouseState.m_mz
 				, width
 				, height
 				);

+ 1 - 1
examples/24-nbody/nbody.cpp

@@ -221,7 +221,7 @@ int _main_(int /*_argc*/, char** /*_argv*/)
 					, mouseState.m_my
 					, (mouseState.m_buttons[entry::MouseButton::Left  ] ? IMGUI_MBUT_LEFT  : 0)
 					| (mouseState.m_buttons[entry::MouseButton::Right ] ? IMGUI_MBUT_RIGHT : 0)
-					, 0
+					, mouseState.m_mz
 					, width
 					, height
 					);

+ 1 - 1
examples/common/imgui/imgui.cpp

@@ -824,7 +824,7 @@ struct Imgui
 		const int32_t mx = int32_t(float(_mx)*xscale);
 		const int32_t my = int32_t(float(_my)*yscale);
 
-		IMGUI_beginFrame(mx, my, _button, _width, _height, _inputChar, _view);
+		IMGUI_beginFrame(mx, my, _button, _scroll, _width, _height, _inputChar, _view);
 		nvgBeginFrameScaled(m_nvg, m_viewWidth, m_viewHeight, m_surfaceWidth, m_surfaceHeight, 1.0f);
 		nvgViewId(m_nvg, _view);
 

+ 16 - 5
examples/common/imgui/ocornut_imgui.cpp

@@ -35,7 +35,6 @@ struct OcornutImguiContext
 		{
 			bgfx::TransientVertexBuffer tvb;
 
-
 			const ImDrawList* cmd_list   = _lists[ii];
 			const ImDrawVert* vtx_buffer = cmd_list->vtx_buffer.begin();
             uint32_t vtx_size = (uint32_t)cmd_list->vtx_buffer.size();
@@ -56,6 +55,12 @@ struct OcornutImguiContext
             const ImDrawCmd* pcmd_end   = cmd_list->commands.end();
 			for (const ImDrawCmd* pcmd = pcmd_begin; pcmd != pcmd_end; pcmd++)
 			{
+                if (pcmd->user_callback)
+                {
+                    pcmd->user_callback(cmd_list, pcmd);
+                    vtx_offset += pcmd->vtx_count;
+                    continue;
+                }
 				if (0 == pcmd->vtx_count)
 				{
 					continue;
@@ -92,6 +97,7 @@ struct OcornutImguiContext
 	{
 		m_viewId = 255;
 		m_allocator = _allocator;
+        m_lastScroll = 0;
 
 		ImGuiIO& io = ImGui::GetIO();
 		io.RenderDrawListsFn = renderDrawLists;
@@ -177,15 +183,19 @@ struct OcornutImguiContext
 		m_allocator = NULL;
 	}
 
-	void beginFrame(int32_t _mx, int32_t _my, uint8_t _button, int _width, int _height, char _inputChar, uint8_t _viewId)
+	void beginFrame(int32_t _mx, int32_t _my, uint8_t _button, int32_t _scroll, int _width, int _height, char _inputChar, uint8_t _viewId)
 	{
 		m_viewId = _viewId;
 		ImGuiIO& io = ImGui::GetIO();
-		io.AddInputCharacter(_inputChar & 0x7f); // ASCII or GTFO! :)
+        if (_inputChar < 0x7f)
+		    io.AddInputCharacter(_inputChar); // ASCII or GTFO! :(
 		io.DisplaySize = ImVec2((float)_width, (float)_height);
 		io.DeltaTime = 1.0f / 60.0f;
 		io.MousePos = ImVec2((float)_mx, (float)_my);
 		io.MouseDown[0] = 0 != (_button & IMGUI_MBUT_LEFT);
+        io.MouseDown[1] = 0 != (_button & IMGUI_MBUT_RIGHT);
+        io.MouseWheel = (float)(_scroll - m_lastScroll);
+        m_lastScroll = _scroll;
 
 #if 0
 		io.KeysDown[ImGuiKey_Tab]        = inputGetKeyState(entry::Key::Tab);
@@ -223,6 +233,7 @@ struct OcornutImguiContext
 	bgfx::TextureHandle m_texture;
 	bgfx::UniformHandle s_tex;
 	uint8_t m_viewId;
+    int32_t m_lastScroll;
 };
 
 static OcornutImguiContext s_ctx;
@@ -252,9 +263,9 @@ void IMGUI_destroy()
 	s_ctx.destroy();
 }
 
-void IMGUI_beginFrame(int32_t _mx, int32_t _my, uint8_t _button, int _width, int _height, char _inputChar, uint8_t _viewId)
+void IMGUI_beginFrame(int32_t _mx, int32_t _my, uint8_t _button, int32_t _scroll, int _width, int _height, char _inputChar, uint8_t _viewId)
 {
-	s_ctx.beginFrame(_mx, _my, _button, _width, _height, _inputChar, _viewId);
+	s_ctx.beginFrame(_mx, _my, _button, _scroll, _width, _height, _inputChar, _viewId);
 }
 
 void IMGUI_endFrame()

+ 1 - 1
examples/common/imgui/ocornut_imgui.h

@@ -12,7 +12,7 @@ namespace bx { struct AllocatorI; }
 
 void IMGUI_create(const void* _data, uint32_t _size, float _fontSize, bx::AllocatorI* _allocator);
 void IMGUI_destroy();
-void IMGUI_beginFrame(int32_t _mx, int32_t _my, uint8_t _button, int _width, int _height, char _inputChar, uint8_t _viewId);
+void IMGUI_beginFrame(int32_t _mx, int32_t _my, uint8_t _button, int32_t _scroll, int _width, int _height, char _inputChar, uint8_t _viewId);
 void IMGUI_endFrame();
 
 #endif // OCORNUT_IMGUI_H_HEADER_GUARD