Jump to content

Managed Gui with InterfacePlugin


photo

Recommended Posts

Hi,

we are currently working on an application where the user needs to drag/drop various widgets around the screen. The user should also be able to move them out of App-border, so InterfacePlugin should fit our needs. Creating an InterfaceWindow during runtime in C# is fine, but calling Interface::ReleaseWindow() anytime during application lifetime crashes the system. Is this a known behavior?

Also, when removing the Widget from the InterfaceWindow and attaching them to the main App again (via Gui.Get().AddChild()), any repositioning are not working, if the ScreenPositionX/Y-parameters were negative before. It seems the engine will set them to zero again, while not respecting the previously set position parameters.

 

I know the InterfacePlugin is marked as deprecated, but while waiting for the new Gui-System we currently need a way to handle external Gui-windows on our own.

Best

Christian

Edited by christian.wolf2
Link to comment

Hi Christian,

New window manager is coming very soon, so the best option is to wait for it. Release is planned for this summer (maybe even in July with 2.16 update).

If you can create a minimal test example with this C# crash - we can probably look into it, but there is no guarantee that we can fix this, sorry (depends on the complexity of the bug itself).

Thanks!

  • Like 1
  • Thanks 2

How to submit a good bug report
---
FTP server for test scenes and user uploads:

Link to comment

Hi silent,

18 hours ago, silent said:

New window manager is coming very soon, so the best option is to wait for it. Release is planned for this summer (maybe even in July with 2.16 update).

This sounds very awesome for us. While our application will get into beta release at the end of this month, we can delay the shipment a little bit longer to migrate the "old" UI system to the new one.

 

For an example it is pretty easy because this happen in C++ as well. I modified the InterfaceWindow- sample from the C++/Widgets menu with a simple timer (you can just copy/paste the complete example below).

Spoiler
/* Copyright (C) 2005-2021, UNIGINE. All rights reserved.
 *
 * This file is a part of the UNIGINE 2 SDK.
 *
 * Your use and / or redistribution of this software in source and / or
 * binary form, with or without modification, is subject to: (i) your
 * ongoing acceptance of and compliance with the terms and conditions of
 * the UNIGINE License Agreement; and (ii) your inclusion of this notice
 * in any version of this software that you use or redistribute.
 * A copy of the UNIGINE License Agreement is available by contacting
 * UNIGINE. at http://unigine.com/
 */


#include <UnigineApp.h>
#include <UnigineEngine.h>
#include <UnigineGui.h>
#include <UnigineLogic.h>
#include <UnigineWidgets.h>

#include <plugins/UnigineInterface.h>

using namespace Unigine;

//////////////////////////////////////////////////////////////////////////
// System logic class
//////////////////////////////////////////////////////////////////////////

class AppSystemLogic : public SystemLogic
{
public:
	AppSystemLogic() {}
	virtual ~AppSystemLogic() {}
	
	int init() override
	{
		// get gui
		GuiPtr gui = Gui::get();
		
		// get engine
		EnginePtr engine;

		// create window
		auto window = WidgetWindow::create(gui, "Hello from C# world", 4, 4);
		window->setWidth(320);
		window->setSizeable(1);

		// create label
		auto label = WidgetLabel::create(gui, "This is an external InterfaceWindow");
		window->addChild(label);
		label->setFontSize(18);

		// find Interface plugin
		int num = engine->findPlugin("Interface");
		if (num == -1)
			Log::fatal("Can't find Interface plugin\n");

		// Interface plugin API
		interface_plugin = (Plugins::Interface *)engine->getPluginData(num);
		if (interface_plugin == NULL)
			Log::fatal("Can't get Interface plugin\n");

		// create InterfaceWindow
		interface_window = interface_plugin->createWindow(0, NULL);
		interface_window->setWidget(window);

		window->arrange();
		int position_x = App::getPositionX() + (App::getWidth() - window->getWidth()) / 2;
		int position_y = App::getPositionY() + (App::getHeight() - window->getHeight()) / 2;
		interface_window->setPosition(position_x, position_y);
		interface_window->setHidden(0);

		timer = 1.f;

		return 1;
	}

	int update() override
	{
		timer -= App::getIFps();

		if (timer <= 0.f && interface_plugin != nullptr)
		{
			WidgetPtr contentWidget = interface_window->getWidget();
			interface_window->getGui()->removeChild(contentWidget);
			Gui::get()->addChild(contentWidget, Gui::ALIGN_OVERLAP);

			interface_plugin->releaseWindow(interface_window);
			interface_plugin = nullptr;
		}


		return 1;
	}

	int shutdown() override
	{
		// clear window
		interface_plugin->releaseWindow(interface_window);

		return 1;
	}

private:
	Plugins::Interface *interface_plugin;
	Plugins::InterfaceWindow *interface_window;
	float timer;
};

//////////////////////////////////////////////////////////////////////////
// Main
//////////////////////////////////////////////////////////////////////////

int main(int argc, char **argv)
{
	// init engine
	Engine::InitParameters init_params;
	init_params.window_title = "UNIGINE Engine: Creating WidgetWindow with Interface plugin";

	Unigine::EnginePtr engine(init_params, argc, argv);

	// enter main loop
	AppSystemLogic system_logic;
	engine->main(&system_logic, NULL, NULL);

	return 0;
}

 

 

After timer runs out, the window will be attached properly to the main Gui. When you try to click on the window (for normal dragging) the engine raises an exception. Hope that helps.

Best

Christian

  • Thanks 1
Link to comment
×
×
  • Create New...