//================================================================================================
// Plugin for EQUINOX-3D
//
// "Hello world" minimal plugin code example
// Prints "Hello world" on the StatusPanel and in the command line
//
// To avoid cluttering the UI, example plugins are not loaded by default, when EQUINOX-3D is started.
// You can manually load them from the Plugin manager, or you can edit your Plugins/Plugins.list file,
// and comment out (e.g. with a trailing "#") or remove the "Load = FALSE;" line for a plugin.
//
// AUTHOR:  Gabor Nagy
// DATE:    2025-Mar-12 22:30:52
//
// Copyright (C) 2014-2026 by Gabor Nagy. All rights reserved.
//================================================================================================
#include <assert.h>
#include <stdio.h>

#include <ELists.h>
#include <EMalloc.h>
#include <EPlugins.h>

#include <E3D/Scene.h>

#include <E3D/UI/Panel.h>
#include <E3D/UI/StatusPanel.h>

#include <Xe/PushButton.h>

char*             E_PluginInfo = "Hello world example";  // This shows up in the information dialog box of the plugin manager (System->Plugins)

static EPlugin*   _Plugin = NULL;

static XeDWidget	  _Buttons[2];static int  _Buttons_Count = 0;  // We collect buttons into an array here, so we can easily free them when the plugin exits


// Don't forget to add this to Plugins/Plugins.list, so EQUINOX-3D actually loads your plugin!
/*
{
Name	= Examples/Hello world;
Object	= Examples/HelloWorld;
}
*/


//================================================
// ToolBar icon callback handler
//================================================
static void _CB(XeWidget PW, EPointer PClientData, EPointer PCallData)
{
	int  LNumber = 42;
	E3dp_PrintMessage(ELogMESSAGE, 5000, "Hello world. This is my first EQUINOX-3D plugin! Number = %d", LNumber);  // Message type, auto-removal timeout (ms), vararg list (like printf)
	printf("Hello world. This is my first EQUINOX-3D plugin! Number = %d\n", LNumber);fflush(stdout);
}


//========================================
// Entry point of the plugin
//========================================
int E_PluginInit(EPlugin* PPlugin)
{
	_Plugin = PPlugin;

// Use default plugin icon
//
// Location ("Create" tool panel, tooltip, )
	XePushButton_AddImg3(_Buttons[_Buttons_Count++], Plugin, "Tool->Create", "Hello world example", '\0', NULL, NULL, FALSE, "Hello world example", _CB, (EPointer)0);

// Add a button to the 'Create' menu as well
//
	_Buttons[_Buttons_Count++] = XePushButton_Add(Xe_App, "Menu->Create", "Hello world", '\0', NULL, NULL, FALSE, NULL, _CB, (EPointer)0);

	return(E_SUCCESS);
}


//========================================
// Exit method of the plugin
//========================================
int E_PluginExit(const EBool PExiting)
{
	if(!PExiting || Xe_GUIFreeOnExit)
	{
		int  LC = 0;for(;LC < _Buttons_Count;LC++) { XeItemFree(_Buttons[LC]); }
		_Buttons_Count = 0;
	}

	return(E_SUCCESS);
}
