Add coordinates under cursor overlay and copy function (#868)

dev-buzzingcars
krzys-h 2016-12-27 14:58:41 +01:00
parent b6cda6cd4c
commit 8d52e27c2b
3 changed files with 92 additions and 2 deletions

View File

@ -172,7 +172,7 @@ enum EventType
EVENT_LABEL16 = 106,
EVENT_LABEL17 = 107,
EVENT_LABEL18 = 108,
EVENT_LABEL19 = 109,
EVENT_LABEL19 = 109, // cursor position overlay
EVENT_LIST0 = 110,
EVENT_LIST1 = 111,

View File

@ -20,6 +20,9 @@
#include "ui/debug_menu.h"
#include "common/event.h"
#include "common/stringutils.h"
#include "app/app.h"
#include "graphics/engine/lightning.h"
#include "graphics/engine/terrain.h"
@ -34,8 +37,11 @@
#include "ui/controls/button.h"
#include "ui/controls/check.h"
#include "ui/controls/interface.h"
#include "ui/controls/label.h"
#include "ui/controls/window.h"
#include <SDL_clipboard.h>
namespace Ui
{
@ -55,11 +61,18 @@ CDebugMenu::~CDebugMenu()
void CDebugMenu::ToggleInterface()
{
if (m_interface->SearchControl(EVENT_WINDOW7) == nullptr)
if (!IsActive())
{
CreateInterface();
CLabel* pl = m_interface->CreateLabel(Math::Point(0.0f, 0.9f), Math::Point(1.0f, 0.1f), -1, EVENT_LABEL19, "??");
pl->SetFontType(Gfx::FONT_COURIER);
}
else
{
m_interface->DeleteControl(EVENT_LABEL19);
DestroyInterface();
}
}
const Math::Point dim = Math::Point(33.0f/640.0f, 33.0f/480.0f);
const float ox = 3.0f/640.0f, oy = 3.0f/480.0f;
@ -359,6 +372,18 @@ bool CDebugMenu::EventProcess(const Event &event)
}
break;
case EVENT_FRAME:
HandleFrameUpdate(event);
break;
case EVENT_KEY_DOWN:
if (event.GetData<KeyEventData>()->key == KEY(c) && (event.kmodState & KMOD_CTRL) != 0)
{
if (IsActive())
{
return !HandleCopy(event.mousePos);
}
}
default:
break;
@ -427,4 +452,38 @@ bool CDebugMenu::HandleTeleport(Math::Point mousePos)
return true;
}
void CDebugMenu::HandleFrameUpdate(const Event &event)
{
std::string str = "-";
Math::Vector pos;
int obj;
if ((obj = m_engine->DetectObject(event.mousePos, pos, true)) != -1)
str = StrUtils::Format("pos=% 3.2f; % 3.2f height=% 3.2f objId=% 4d", pos.x, pos.z, pos.y, obj);
CLabel* pl = static_cast<CLabel*>(m_interface->SearchControl(EVENT_LABEL19));
if (pl == nullptr) return;
pl->SetName(str.c_str());
}
bool CDebugMenu::HandleCopy(Math::Point mousePos)
{
Math::Vector pos;
if (m_engine->DetectObject(mousePos, pos, true) == -1)
{
m_sound->Play(SOUND_CLICK, 1.0f, 0.5f);
return false;
}
std::string str = StrUtils::Format("pos=%.2f;%.2f", pos.x, pos.z);
GetLogger()->Debug("%s\n", str.c_str());
SDL_SetClipboardText(str.c_str());
return true;
}
bool CDebugMenu::IsActive()
{
return m_interface->SearchControl(EVENT_WINDOW7) != nullptr;
}
}

View File

@ -37,24 +37,55 @@ namespace Ui
{
class CInterface;
/**
* \class CDebugMenu
* \brief Handles debug menu (F11)
*
* There should always be only one instance of this class for each associated CRobotMain class.
*/
class CDebugMenu
{
public:
//! Creates the CDebugMenu instance
CDebugMenu(CRobotMain* main, Gfx::CEngine* engine, CObjectManager* objMan, CSoundInterface* sound);
//! Destroys the CDebugMenu instance
//! \note Does not clean up the interface, should be called only when CRobotMain is destroyed
virtual ~CDebugMenu();
//! Toggle the debug interface
void ToggleInterface();
//! Check if the debug interface is open
bool IsActive();
//! Event processing
bool EventProcess(const Event& event);
protected:
//! Create the main page of debug interface
void CreateInterface();
//! Create the spawn object interface
void CreateSpawnInterface();
//! Update controls in the debug interface
void UpdateInterface();
//! Destroy the debug interface window
void DestroyInterface();
//! Handle frame update
//! This is used to update the cursor coordinates overlay
void HandleFrameUpdate(const Event &event);
//! Handle spawning a new object at mouse position
//! \return true on success, false on error
bool HandleSpawnObject(ObjectType type, Math::Point mousePos);
//! Handle lightning at position
//! \return true on success, false on error
bool HandleLightning(Math::Point mousePos);
//! Handle teleport to position
//! \return true on success, false on error
bool HandleTeleport(Math::Point mousePos);
//! Handle ctrl+c (copy coordinates under cursor to clipboard)
//! \return true on success, false on error
bool HandleCopy(Math::Point mousePos);
protected:
CRobotMain* m_main;