<commit_before>/*
 * Copyright (c) 2012-2017 <NAME> and individual contributors.
 * License: https://github.com/dbartolini/crown/blob/master/LICENSE
 */

#if CROWN_TOOLS

#include <imgui.h>
#include <iconfontheaders/icons_material_design.h>
#include <time.h>

#include "core/containers/vector.h"
#include "core/filesystem/filesystem_disk.h"
#include "core/filesystem/path.h"
#include "core/filesystem/file.h"
#include "core/json/json.h"
#include "core/json/sjson.h"
#include "core/json/json_object.h"
#include "core/network/socket.h"
#include "core/strings/dynamic_string.h"
#include "device/device.h"
#include "device/device_event_queue.h"
#include "device/input_device.h"
#include "device/input_manager.h"
#include "device/input_types.h"
#include "device/device_options.h"
#include "device/log.h"
#include "resource/resource_manager.h"
#include "resource/texture_resource.h"
#include "device/pipeline.h"

#include "imgui_context.h"
#include "tool_api.h"

#if CROWN_PLATFORM_POSIX
	#include <sys/time.h>
#endif

namespace { const crown::log_internal::System LEVEL_EDITOR = { "LevelEditor" }; }

namespace crown
{
static u16 _width = 1280;
static u16 _height = 720;

//-----------------------------------------------------------------------------
struct Inspector
{
	// Inspector
	char _name[1024];
	float _position[3];
	float _rotation[3];
	float _scale[3];
	char _sprite[1024];
	char _material[1024];
	bool _visible;
	char _state_machine[1024];
	bool _open;

	Inspector()
		: _visible(true)
		, _open(true)
	{
		memset(_name, 0, sizeof(_name));
		memset(_sprite, 0, sizeof(_sprite));
		memset(_material, 0, sizeof(_material));
		memset(_position, 0, sizeof(_position));
		memset(_rotation, 0, sizeof(_rotation));
		memset(_scale, 0, sizeof(_scale));
		memset(_state_machine, 0, sizeof(_state_machine));
	}

	void draw()
	{
		if (!_open) return;
		if (ImGui::BeginDock("Inspector", &_open))
		{
			ImGui::SetNextTreeNodeOpen(true);
			if (ImGui::TreeNode("Unit"))
			{
				ImGui::InputText("Name", _name, sizeof(_name));
				ImGui::TreePop();
			}

			ImGui::SetNextTreeNodeOpen(true);
			if (ImGui::TreeNode("Transform"))
			{
				ImGui::InputFloat3("Position", _position, ImGuiInputTextFlags_CharsDecimal);
				ImGui::InputFloat3("Rotation", _rotation, ImGuiInputTextFlags_CharsDecimal);
				ImGui::InputFloat3("Scale", _scale, ImGuiInputTextFlags_CharsDecimal);

				ImGui::TreePop();
			}

			ImGui::SetNextTreeNodeOpen(true);
			if (ImGui::TreeNode("Renderer"))
			{
				ImGui::InputText("Sprite", _sprite, sizeof(_sprite));
				ImGui::InputText("Material", _material, sizeof(_material));
				ImGui::Checkbox("Visible", &_visible);
				ImGui::TreePop();
			}

			ImGui::SetNextTreeNodeOpen(true);
			if (ImGui::TreeNode("Animation"))
			{
				ImGui::InputText("State Machine", _state_machine, sizeof(_state_machine));
				ImGui::TreePop();
			}
		}
		ImGui::EndDock();
	}
};

//-----------------------------------------------------------------------------
struct SceneView
{
	ImVec2 _pos;
	ImVec2 _size;
	ImVec2 _mouse_curr;
	ImVec2 _mouse_last;
	bool _open;

	SceneView()
		: _open(true)
	{
	}

	void draw()
	{
		if (!_open) return;

		ImGui::SetNextWindowPos(ImVec2(0, 25));
		if (ImGui::BeginDock("Scene View"
			, &_open
			, ImGuiWindowFlags_NoScrollbar
			| ImGuiWindowFlags_NoScrollWithMouse
			| ImGuiWindowFlags_NoTitleBar))
		{
			uint16_t w, h;
			device()->resolution(w, h);
			bgfx::TextureHandle txh = device()->_pipeline->_buffers[0];
			CE_ENSURE(bgfx::isValid(txh));
			ImGui::Image((void*)(uintptr_t)txh.idx
				, ImVec2(w, h)
#if CROWN_PLATFORM_WINDOWS
				, ImVec2(0, 0)<commit_msg>tools-imgui: add titlebar to SceneView<commit_after>/*
 * Copyright (c) 2012-2017 <NAME> and individual contributors.
 * License: https://github.com/dbartolini/crown/blob/master/LICENSE
 */

#if CROWN_TOOLS

#include <imgui.h>
#include <iconfontheaders/icons_material_design.h>
#include <time.h>

#include "core/containers/vector.h"
#include "core/filesystem/filesystem_disk.h"
#include "core/filesystem/path.h"
#include "core/filesystem/file.h"
#include "core/json/json.h"
#include "core/json/sjson.h"
#include "core/json/json_object.h"
#include "core/network/socket.h"
#include "core/strings/dynamic_string.h"
#include "device/device.h"
#include "device/device_event_queue.h"
#include "device/input_device.h"
#include "device/input_manager.h"
#include "device/input_types.h"
#include "device/device_options.h"
#include "device/log.h"
#include "resource/resource_manager.h"
#include "resource/texture_resource.h"
#include "device/pipeline.h"

#include "imgui_context.h"
#include "tool_api.h"

#if CROWN_PLATFORM_POSIX
	#include <sys/time.h>
#endif

namespace { const crown::log_internal::System LEVEL_EDITOR = { "LevelEditor" }; }

namespace crown
{
static u16 _width = 1280;
static u16 _height = 720;

//-----------------------------------------------------------------------------
struct Inspector
{
	// Inspector
	char _name[1024];
	float _position[3];
	float _rotation[3];
	float _scale[3];
	char _sprite[1024];
	char _material[1024];
	bool _visible;
	char _state_machine[1024];
	bool _open;

	Inspector()
		: _visible(true)
		, _open(true)
	{
		memset(_name, 0, sizeof(_name));
		memset(_sprite, 0, sizeof(_sprite));
		memset(_material, 0, sizeof(_material));
		memset(_position, 0, sizeof(_position));
		memset(_rotation, 0, sizeof(_rotation));
		memset(_scale, 0, sizeof(_scale));
		memset(_state_machine, 0, sizeof(_state_machine));
	}

	void draw()
	{
		if (!_open) return;
		if (ImGui::BeginDock("Inspector", &_open))
		{
			ImGui::SetNextTreeNodeOpen(true);
			if (ImGui::TreeNode("Unit"))
			{
				ImGui::InputText("Name", _name, sizeof(_name));
				ImGui::TreePop();
			}

			ImGui::SetNextTreeNodeOpen(true);
			if (ImGui::TreeNode("Transform"))
			{
				ImGui::InputFloat3("Position", _position, ImGuiInputTextFlags_CharsDecimal);
				ImGui::InputFloat3("Rotation", _rotation, ImGuiInputTextFlags_CharsDecimal);
				ImGui::InputFloat3("Scale", _scale, ImGuiInputTextFlags_CharsDecimal);

				ImGui::TreePop();
			}

			ImGui::SetNextTreeNodeOpen(true);
			if (ImGui::TreeNode("Renderer"))
			{
				ImGui::InputText("Sprite", _sprite, sizeof(_sprite));
				ImGui::InputText("Material", _material, sizeof(_material));
				ImGui::Checkbox("Visible", &_visible);
				ImGui::TreePop();
			}

			ImGui::SetNextTreeNodeOpen(true);
			if (ImGui::TreeNode("Animation"))
			{
				ImGui::InputText("State Machine", _state_machine, sizeof(_state_machine));
				ImGui::TreePop();
			}
		}
		ImGui::EndDock();
	}
};

//-----------------------------------------------------------------------------
struct SceneView
{
	ImVec2 _pos;
	ImVec2 _size;
	ImVec2 _mouse_curr;
	ImVec2 _mouse_last;
	bool _open;

	SceneView()
		: _open(true)
	{
	}

	void draw()
	{
		if (!_open) return;

		ImGui::SetNextWindowPos(ImVec2(0, 25));
		if (ImGui::BeginDock("Scene View"
			, &_open
			, ImGuiWindowFlags_NoScrollbar
			| ImGuiWindowFlags_NoScrollWithMouse
			))
		{
			uint16_t w, h;
			device()->resolution(w, h);
			bgfx::TextureHandle txh = device()->_pipeline->_buffers[0];
			CE_ENSURE(bgfx::isValid(txh));
			ImGui::Image((void*)(uintptr_t)txh.idx
				, ImVec2(w, h)
#if CROWN_PLATFORM_WINDOWS
				, ImVec2(0, 0)
{'fraction_non_alphanumeric': 0.19259567387687188, 'fraction_numerical': 0.01747088186356073, 'mean_word_length': 4.061754385964912, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 19, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7460002', 'n_tokens_mistral': 2878, 'n_tokens_neox': 2568, 'n_words': 438}