2012-06-26 20:23:05 +00:00
|
|
|
// * This file is part of the COLOBOT source code
|
|
|
|
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
|
2012-08-17 20:43:07 +00:00
|
|
|
// * Copyright (C) 2012 Polish Portal of Colobot (PPC)
|
2012-06-26 20:23:05 +00:00
|
|
|
// *
|
|
|
|
// * This program is free software: you can redistribute it and/or modify
|
|
|
|
// * it under the terms of the GNU General Public License as published by
|
|
|
|
// * the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// * (at your option) any later version.
|
|
|
|
// *
|
|
|
|
// * This program is distributed in the hope that it will be useful,
|
|
|
|
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// * GNU General Public License for more details.
|
|
|
|
// *
|
|
|
|
// * You should have received a copy of the GNU General Public License
|
|
|
|
// * along with this program. If not, see http://www.gnu.org/licenses/.
|
|
|
|
|
|
|
|
|
2012-09-18 22:04:21 +00:00
|
|
|
#include "ui/interface.h"
|
2012-06-26 20:23:05 +00:00
|
|
|
|
2013-02-16 21:37:43 +00:00
|
|
|
#include "app/app.h"
|
|
|
|
|
2012-08-17 21:03:52 +00:00
|
|
|
namespace Ui {
|
|
|
|
|
2012-06-26 20:23:05 +00:00
|
|
|
|
2012-08-17 20:43:07 +00:00
|
|
|
CInterface::CInterface()
|
|
|
|
{
|
2013-02-16 21:37:43 +00:00
|
|
|
m_event = CApplication::GetInstancePointer()->GetEventQueue();
|
|
|
|
m_engine = Gfx::CEngine::GetInstancePointer();
|
2012-09-16 18:00:25 +00:00
|
|
|
m_camera = nullptr;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
2013-10-12 16:48:28 +00:00
|
|
|
for (int i = 0; i < MAXCONTROL; i++)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
2012-08-17 20:43:07 +00:00
|
|
|
m_table[i] = nullptr;
|
2012-06-26 20:23:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Object's destructor.
|
|
|
|
|
|
|
|
CInterface::~CInterface()
|
|
|
|
{
|
|
|
|
Flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Purge all controls.
|
|
|
|
|
|
|
|
void CInterface::Flush()
|
|
|
|
{
|
2013-10-12 16:48:28 +00:00
|
|
|
for (int i = 0; i < MAXCONTROL; i++)
|
2013-05-26 15:47:54 +00:00
|
|
|
{
|
2014-08-09 20:45:07 +00:00
|
|
|
delete m_table[i];
|
|
|
|
m_table[i] = nullptr;
|
2012-06-26 20:23:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-08-17 20:43:07 +00:00
|
|
|
int CInterface::GetNextFreeControl()
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
2013-05-26 15:47:54 +00:00
|
|
|
for (int i = 10; i < MAXCONTROL-1; i++)
|
|
|
|
{
|
2012-08-17 20:43:07 +00:00
|
|
|
if (m_table[i] == nullptr)
|
|
|
|
return i;
|
2012-06-26 20:23:05 +00:00
|
|
|
}
|
2012-08-17 20:43:07 +00:00
|
|
|
return -1;
|
2012-06-26 20:23:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-08-17 20:43:07 +00:00
|
|
|
template <typename T> inline T* CInterface::CreateControl(Math::Point pos, Math::Point dim, int icon, EventType eventMsg)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
2012-08-18 19:04:51 +00:00
|
|
|
if (eventMsg == EVENT_NULL)
|
|
|
|
eventMsg = GetUniqueEventType();
|
2012-08-17 20:43:07 +00:00
|
|
|
|
2013-10-12 16:48:28 +00:00
|
|
|
int index = GetNextFreeControl();
|
|
|
|
if (index < 0)
|
2012-08-17 20:43:07 +00:00
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
m_table[index] = new T();
|
2013-10-12 16:48:28 +00:00
|
|
|
T* pc = static_cast<T *>(m_table[index]);
|
2012-08-17 20:43:07 +00:00
|
|
|
pc->Create(pos, dim, icon, eventMsg);
|
|
|
|
return pc;
|
2012-06-26 20:23:05 +00:00
|
|
|
}
|
|
|
|
|
2012-08-17 20:43:07 +00:00
|
|
|
|
2012-06-26 20:23:05 +00:00
|
|
|
// Creates a new button.
|
|
|
|
|
2012-08-17 20:43:07 +00:00
|
|
|
CWindow* CInterface::CreateWindows(Math::Point pos, Math::Point dim, int icon, EventType eventMsg)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
2012-08-18 19:04:51 +00:00
|
|
|
if (eventMsg == EVENT_NULL)
|
|
|
|
eventMsg = GetUniqueEventType();
|
2012-06-26 20:23:05 +00:00
|
|
|
|
2013-10-12 16:48:28 +00:00
|
|
|
int index = -1;
|
2013-05-26 15:47:54 +00:00
|
|
|
switch (eventMsg)
|
|
|
|
{
|
2012-08-17 20:43:07 +00:00
|
|
|
case EVENT_WINDOW0: index = 0; break;
|
|
|
|
case EVENT_WINDOW1: index = 1; break;
|
|
|
|
case EVENT_WINDOW2: index = 2; break;
|
|
|
|
case EVENT_WINDOW3: index = 3; break;
|
|
|
|
case EVENT_WINDOW4: index = 4; break;
|
|
|
|
case EVENT_WINDOW5: index = 5; break;
|
|
|
|
case EVENT_WINDOW6: index = 6; break;
|
|
|
|
case EVENT_WINDOW7: index = 7; break;
|
|
|
|
case EVENT_WINDOW8: index = 8; break;
|
|
|
|
case EVENT_WINDOW9: index = 9; break;
|
|
|
|
case EVENT_TOOLTIP: index = MAXCONTROL-1; break;
|
|
|
|
default: index = GetNextFreeControl(); break;
|
2012-06-26 20:23:05 +00:00
|
|
|
}
|
2012-08-17 20:43:07 +00:00
|
|
|
|
|
|
|
if (index < 0)
|
|
|
|
return nullptr;
|
|
|
|
|
2013-10-12 16:48:28 +00:00
|
|
|
delete m_table[index];
|
2012-08-17 20:43:07 +00:00
|
|
|
m_table[index] = new CWindow();
|
2013-10-12 16:48:28 +00:00
|
|
|
CWindow* pc = static_cast<CWindow *>(m_table[index]);
|
2012-08-17 20:43:07 +00:00
|
|
|
pc->Create(pos, dim, icon, eventMsg);
|
|
|
|
return pc;
|
2012-06-26 20:23:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Creates a new button.
|
|
|
|
|
2012-08-17 20:43:07 +00:00
|
|
|
CButton* CInterface::CreateButton(Math::Point pos, Math::Point dim, int icon, EventType eventMsg)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
2012-08-17 20:43:07 +00:00
|
|
|
return CreateControl<CButton>(pos, dim, icon, eventMsg);
|
2012-06-26 20:23:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Creates a new button.
|
|
|
|
|
2012-08-17 20:43:07 +00:00
|
|
|
CColor* CInterface::CreateColor(Math::Point pos, Math::Point dim, int icon, EventType eventMsg)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
2012-08-17 20:43:07 +00:00
|
|
|
return CreateControl<CColor>(pos, dim, icon, eventMsg);
|
2012-06-26 20:23:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Creates a new button.
|
|
|
|
|
2012-08-17 20:43:07 +00:00
|
|
|
CCheck* CInterface::CreateCheck(Math::Point pos, Math::Point dim, int icon, EventType eventMsg)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
2012-08-17 20:43:07 +00:00
|
|
|
return CreateControl<CCheck>(pos, dim, icon, eventMsg);
|
|
|
|
}
|
2012-06-26 20:23:05 +00:00
|
|
|
|
2012-08-17 20:43:07 +00:00
|
|
|
// Creates a new button.
|
2012-06-26 20:23:05 +00:00
|
|
|
|
2012-08-17 20:43:07 +00:00
|
|
|
CKey* CInterface::CreateKey(Math::Point pos, Math::Point dim, int icon, EventType eventMsg)
|
|
|
|
{
|
|
|
|
return CreateControl<CKey>(pos, dim, icon, eventMsg);
|
2012-06-26 20:23:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Creates a new button.
|
|
|
|
|
2012-08-17 20:43:07 +00:00
|
|
|
CGroup* CInterface::CreateGroup(Math::Point pos, Math::Point dim, int icon, EventType eventMsg)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
2012-08-17 20:43:07 +00:00
|
|
|
return CreateControl<CGroup>(pos, dim, icon, eventMsg);
|
|
|
|
}
|
2012-06-26 20:23:05 +00:00
|
|
|
|
2012-08-17 20:43:07 +00:00
|
|
|
// Creates a new button.
|
2012-06-26 20:23:05 +00:00
|
|
|
|
2012-08-17 20:43:07 +00:00
|
|
|
CImage* CInterface::CreateImage(Math::Point pos, Math::Point dim, int icon, EventType eventMsg)
|
|
|
|
{
|
|
|
|
return CreateControl<CImage>(pos, dim, icon, eventMsg);
|
2012-06-26 20:23:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Creates a new label.
|
|
|
|
|
2012-08-31 20:28:07 +00:00
|
|
|
CLabel* CInterface::CreateLabel(Math::Point pos, Math::Point dim, int icon, EventType eventMsg, std::string name)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
2012-08-17 20:43:07 +00:00
|
|
|
CLabel* pc = CreateControl<CLabel>(pos, dim, icon, eventMsg);
|
|
|
|
if (pc != nullptr)
|
|
|
|
pc->SetName(name);
|
|
|
|
return pc;
|
2012-06-26 20:23:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Creates a new pave editable.
|
|
|
|
|
2012-08-17 20:43:07 +00:00
|
|
|
CEdit* CInterface::CreateEdit(Math::Point pos, Math::Point dim, int icon, EventType eventMsg)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
2012-08-17 20:43:07 +00:00
|
|
|
return CreateControl<CEdit>(pos, dim, icon, eventMsg);
|
2012-06-26 20:23:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Creates a new pave editable.
|
|
|
|
|
2012-08-17 20:43:07 +00:00
|
|
|
CEditValue* CInterface::CreateEditValue(Math::Point pos, Math::Point dim, int icon, EventType eventMsg)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
2012-08-17 20:43:07 +00:00
|
|
|
return CreateControl<CEditValue>(pos, dim, icon, eventMsg);
|
2012-06-26 20:23:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Creates a new lift.
|
|
|
|
|
2012-08-17 20:43:07 +00:00
|
|
|
CScroll* CInterface::CreateScroll(Math::Point pos, Math::Point dim, int icon, EventType eventMsg)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
2012-08-17 20:43:07 +00:00
|
|
|
return CreateControl<CScroll>(pos, dim, icon, eventMsg);
|
2012-06-26 20:23:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Creates a new cursor.
|
|
|
|
|
2012-08-17 20:43:07 +00:00
|
|
|
CSlider* CInterface::CreateSlider(Math::Point pos, Math::Point dim, int icon, EventType eventMsg)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
2012-08-17 20:43:07 +00:00
|
|
|
return CreateControl<CSlider>(pos, dim, icon, eventMsg);
|
2012-06-26 20:23:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Creates a new list.
|
2013-04-25 19:11:36 +00:00
|
|
|
// if expand is less then zero, then the list would try to use expand's absolute value,
|
|
|
|
// and try to scale items to some size, so that dim of the list would not change after
|
|
|
|
// adjusting
|
2012-06-26 20:23:05 +00:00
|
|
|
|
2012-08-17 20:43:07 +00:00
|
|
|
CList* CInterface::CreateList(Math::Point pos, Math::Point dim, int icon, EventType eventMsg, float expand)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
2012-08-18 19:04:51 +00:00
|
|
|
if (eventMsg == EVENT_NULL)
|
|
|
|
eventMsg = GetUniqueEventType();
|
2012-08-17 20:43:07 +00:00
|
|
|
|
2013-10-12 16:48:28 +00:00
|
|
|
int index = GetNextFreeControl();
|
|
|
|
if (index < 0)
|
2012-08-17 20:43:07 +00:00
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
m_table[index] = new CList();
|
2013-10-12 16:48:28 +00:00
|
|
|
CList* pc = static_cast<CList *>(m_table[index]);
|
2012-08-17 20:43:07 +00:00
|
|
|
pc->Create(pos, dim, icon, eventMsg, expand);
|
|
|
|
return pc;
|
2012-06-26 20:23:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Creates a new shortcut.
|
|
|
|
|
2012-08-17 20:43:07 +00:00
|
|
|
CShortcut* CInterface::CreateShortcut(Math::Point pos, Math::Point dim, int icon, EventType eventMsg)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
2012-08-17 20:43:07 +00:00
|
|
|
return CreateControl<CShortcut>(pos, dim, icon, eventMsg);
|
2012-06-26 20:23:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Creates a new compass.
|
|
|
|
|
2012-08-17 20:43:07 +00:00
|
|
|
CCompass* CInterface::CreateCompass(Math::Point pos, Math::Point dim, int icon, EventType eventMsg)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
2012-08-17 20:43:07 +00:00
|
|
|
return CreateControl<CCompass>(pos, dim, icon, eventMsg);
|
2012-06-26 20:23:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Creates a new target.
|
|
|
|
|
2012-08-17 20:43:07 +00:00
|
|
|
CTarget* CInterface::CreateTarget(Math::Point pos, Math::Point dim, int icon, EventType eventMsg)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
2012-08-17 20:43:07 +00:00
|
|
|
return CreateControl<CTarget>(pos, dim, icon, eventMsg);
|
2012-06-26 20:23:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Creates a new map.
|
|
|
|
|
2012-08-17 20:43:07 +00:00
|
|
|
CMap* CInterface::CreateMap(Math::Point pos, Math::Point dim, int icon, EventType eventMsg)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
2012-08-17 20:43:07 +00:00
|
|
|
return CreateControl<CMap>(pos, dim, icon, eventMsg);
|
2012-06-26 20:23:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Removes a control.
|
|
|
|
|
2012-08-17 20:43:07 +00:00
|
|
|
bool CInterface::DeleteControl(EventType eventMsg)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
2013-05-26 15:47:54 +00:00
|
|
|
for (int i = 0; i < MAXCONTROL; i++)
|
|
|
|
{
|
|
|
|
if ( m_table[i] != nullptr )
|
|
|
|
{
|
|
|
|
if (eventMsg == m_table[i]->GetEventType())
|
|
|
|
{
|
2012-06-26 20:23:05 +00:00
|
|
|
delete m_table[i];
|
2012-08-17 20:43:07 +00:00
|
|
|
m_table[i] = nullptr;
|
2012-06-26 20:23:05 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Gives a control.
|
|
|
|
|
2012-08-17 20:43:07 +00:00
|
|
|
CControl* CInterface::SearchControl(EventType eventMsg)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
2013-05-26 15:47:54 +00:00
|
|
|
for (int i = 0; i < MAXCONTROL; i++)
|
|
|
|
{
|
|
|
|
if (m_table[i] != nullptr)
|
|
|
|
{
|
2012-08-17 20:43:07 +00:00
|
|
|
if (eventMsg == m_table[i]->GetEventType())
|
2012-06-26 20:23:05 +00:00
|
|
|
return m_table[i];
|
|
|
|
}
|
|
|
|
}
|
2012-08-17 20:43:07 +00:00
|
|
|
return nullptr;
|
2012-06-26 20:23:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Management of an event.
|
|
|
|
|
|
|
|
bool CInterface::EventProcess(const Event &event)
|
|
|
|
{
|
2013-02-16 21:37:43 +00:00
|
|
|
if (event.type == EVENT_MOUSE_MOVE)
|
|
|
|
{
|
|
|
|
if (m_camera == nullptr)
|
|
|
|
m_camera = CRobotMain::GetInstancePointer()->GetCamera();
|
|
|
|
|
2012-09-21 22:38:17 +00:00
|
|
|
m_engine->SetMouseType(m_camera->GetMouseDef(event.mousePos));
|
2012-06-26 20:23:05 +00:00
|
|
|
}
|
|
|
|
|
2013-02-16 21:37:43 +00:00
|
|
|
for (int i = MAXCONTROL-1; i >= 0; i--)
|
|
|
|
{
|
|
|
|
if (m_table[i] != nullptr && m_table[i]->TestState(STATE_ENABLE))
|
|
|
|
{
|
2012-06-26 20:23:05 +00:00
|
|
|
if ( !m_table[i]->EventProcess(event) )
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Gives the tooltip binding to the window.
|
|
|
|
|
2012-08-31 20:28:07 +00:00
|
|
|
bool CInterface::GetTooltip(Math::Point pos, std::string &name)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
2013-02-16 21:37:43 +00:00
|
|
|
for (int i = MAXCONTROL-1; i >= 0; i--)
|
|
|
|
{
|
|
|
|
if (m_table[i] != nullptr)
|
|
|
|
{
|
2012-08-17 20:43:07 +00:00
|
|
|
if (m_table[i]->GetTooltip(pos, name))
|
2012-06-26 20:23:05 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Draws all buttons.
|
|
|
|
|
|
|
|
void CInterface::Draw()
|
|
|
|
{
|
2013-02-16 21:37:43 +00:00
|
|
|
for (int i = 0; i < MAXCONTROL; i++)
|
|
|
|
{
|
2012-08-17 20:43:07 +00:00
|
|
|
if ( m_table[i] != nullptr )
|
2012-06-26 20:23:05 +00:00
|
|
|
m_table[i]->Draw();
|
|
|
|
}
|
|
|
|
}
|
2012-08-17 21:03:52 +00:00
|
|
|
|
2013-05-26 15:47:54 +00:00
|
|
|
} // namespace Ui
|
|
|
|
|