Add proper initializers and remove manual memory management in ui classes

master
Piotr Dziwinski 2015-08-11 22:47:07 +02:00
parent 34e4fb4508
commit 571cc96523
33 changed files with 635 additions and 996 deletions

View File

@ -1440,7 +1440,7 @@ void CRobotMain::StartDisplayInfo(int index, bool movie)
} }
//! Beginning of the displaying of instructions //! Beginning of the displaying of instructions
void CRobotMain::StartDisplayInfo(const char *filename, int index) void CRobotMain::StartDisplayInfo(const std::string& filename, int index)
{ {
if (m_cmdEdit) return; if (m_cmdEdit) return;

View File

@ -213,7 +213,7 @@ public:
void FlushDisplayInfo(); void FlushDisplayInfo();
void StartDisplayInfo(int index, bool movie); void StartDisplayInfo(int index, bool movie);
void StartDisplayInfo(const char *filename, int index); void StartDisplayInfo(const std::string& filename, int index);
void StopDisplayInfo(); void StopDisplayInfo();
char* GetDisplayInfoName(int index); char* GetDisplayInfoName(int index);
int GetDisplayInfoPosition(int index); int GetDisplayInfoPosition(int index);

View File

@ -45,7 +45,8 @@ CControl::CControl()
m_textAlign = Gfx::TEXT_ALIGN_CENTER; //instead m_justify m_textAlign = Gfx::TEXT_ALIGN_CENTER; //instead m_justify
m_bFocus = false; m_bFocus = false;
m_bCapture = false; m_bCapture = false;
m_icon = 0;
m_fontStretch = false;
m_bGlint = false; m_bGlint = false;
m_glintCorner1 = Math::Point(0.0f, 0.0f); m_glintCorner1 = Math::Point(0.0f, 0.0f);
m_glintCorner2 = Math::Point(0.0f, 0.0f); m_glintCorner2 = Math::Point(0.0f, 0.0f);

View File

@ -26,6 +26,7 @@
#include "app/input.h" #include "app/input.h"
#include "common/logger.h" #include "common/logger.h"
#include "common/make_unique.h"
#include "common/misc.h" #include "common/misc.h"
#include "common/resources/inputstream.h" #include "common/resources/inputstream.h"
@ -93,18 +94,16 @@ bool IsSep(int character)
//! Object's constructor. //! Object's constructor.
CEdit::CEdit () : CControl () CEdit::CEdit()
: CControl(),
m_lineOffset(),
m_lineIndent()
{ {
Math::Point pos;
m_maxChar = 100; m_maxChar = 100;
m_text = std::vector<char>(m_maxChar+1, '\0'); m_text = std::vector<char>(m_maxChar+1, '\0');
m_len = 0; m_len = 0;
std::fill_n(m_lineOffset, EDITLINEMAX, 0);
m_fontType = Gfx::FONT_COURIER; m_fontType = Gfx::FONT_COURIER;
m_scroll = 0;
m_bEdit = true; m_bEdit = true;
m_bHilite = true; m_bHilite = true;
m_bInsideScroll = true; m_bInsideScroll = true;
@ -118,6 +117,22 @@ CEdit::CEdit () : CControl ()
m_column = 0; m_column = 0;
m_imageTotal = 0; m_imageTotal = 0;
m_timeLastScroll = 0.0f;
m_timeBlink = 0.0f;
m_time = 0.0f;
m_historyCurrent = 0;
m_markerTotal = 0;
m_bMulti = false;
m_lineDescent = 0.0f;
m_timeLastClick = 0.0f;
m_bMultiFont = false;
m_lineAscent = 0.0f;
m_historyTotal = 0;
m_lineTotal = 0;
m_lineHeight = 0.0f;
m_lineVisible = 0;
m_lineFirst = 0;
HyperFlush(); HyperFlush();
m_bUndoForce = true; m_bUndoForce = true;
@ -129,9 +144,6 @@ CEdit::CEdit () : CControl ()
CEdit::~CEdit() CEdit::~CEdit()
{ {
FreeImage(); FreeImage();
delete m_scroll;
m_scroll = nullptr;
} }
@ -139,9 +151,6 @@ CEdit::~CEdit()
bool CEdit::Create(Math::Point pos, Math::Point dim, int icon, EventType eventType) bool CEdit::Create(Math::Point pos, Math::Point dim, int icon, EventType eventType)
{ {
CScroll* pc;
Math::Point start, end;
if ( eventType == EVENT_NULL ) eventType = GetUniqueEventType(); if ( eventType == EVENT_NULL ) eventType = GetUniqueEventType();
CControl::Create(pos, dim, icon, eventType); CControl::Create(pos, dim, icon, eventType);
@ -162,9 +171,8 @@ bool CEdit::Create(Math::Point pos, Math::Point dim, int icon, EventType eventTy
{ {
m_bMulti = true; m_bMulti = true;
MoveAdjust(); // readjusts multi-line mode MoveAdjust(); // readjusts multi-line mode
m_scroll = new Ui::CScroll(); m_scroll = MakeUnique<Ui::CScroll>();
pc = static_cast<CScroll*>(m_scroll); m_scroll->Create(pos, dim, -1, EVENT_NULL);
pc->Create(pos, dim, -1, EVENT_NULL);
MoveAdjust(); MoveAdjust();
} }
@ -196,7 +204,7 @@ void CEdit::MoveAdjust()
height = m_dim.y-(m_bMulti?MARGY*2.0f:MARGY1); height = m_dim.y-(m_bMulti?MARGY*2.0f:MARGY1);
m_lineVisible = static_cast<int>((height/m_lineHeight)); m_lineVisible = static_cast<int>((height/m_lineHeight));
if ( m_scroll != 0 ) if (m_scroll != nullptr)
{ {
if ( m_bInsideScroll ) if ( m_bInsideScroll )
{ {
@ -284,11 +292,11 @@ bool CEdit::EventProcess(const Event &event)
} }
} }
if ( m_scroll != nullptr && !m_bGeneric ) if (m_scroll != nullptr && !m_bGeneric)
{ {
m_scroll->EventProcess(event); m_scroll->EventProcess(event);
if ( event.type == m_scroll->GetEventType() ) if (event.type == m_scroll->GetEventType())
{ {
Scroll(); Scroll();
return true; return true;
@ -1127,7 +1135,7 @@ void CEdit::Draw()
DrawPart(pos, dim, 0); // red DrawPart(pos, dim, 0); // red
} }
if ( m_scroll != 0 && !m_bGeneric ) if (m_scroll != nullptr && !m_bGeneric)
{ {
m_scroll->Draw(); m_scroll->Draw();
} }
@ -2139,11 +2147,9 @@ void CEdit::SetFontSize(float size)
void CEdit::Scroll() void CEdit::Scroll()
{ {
float value; if (m_scroll != nullptr)
if ( m_scroll != nullptr )
{ {
value = m_scroll->GetVisibleValue(); float value = m_scroll->GetVisibleValue();
value *= m_lineTotal - m_lineVisible; value *= m_lineTotal - m_lineVisible;
Scroll(static_cast<int>(value + 0.5f), true); Scroll(static_cast<int>(value + 0.5f), true);
} }
@ -3195,9 +3201,7 @@ bool CEdit::SetFormat(int cursor1, int cursor2, int format)
void CEdit::UpdateScroll() void CEdit::UpdateScroll()
{ {
float value; if (m_scroll != nullptr)
if ( m_scroll != nullptr )
{ {
if ( m_lineTotal <= m_lineVisible ) if ( m_lineTotal <= m_lineVisible )
{ {
@ -3207,7 +3211,7 @@ void CEdit::UpdateScroll()
} }
else else
{ {
value = static_cast<float>(m_lineVisible) / m_lineTotal; float value = static_cast<float>(m_lineVisible) / m_lineTotal;
m_scroll->SetVisibleRatio(value); m_scroll->SetVisibleRatio(value);
value = static_cast<float>(m_lineFirst) / (m_lineTotal - m_lineVisible); value = static_cast<float>(m_lineFirst) / (m_lineTotal - m_lineVisible);

View File

@ -27,6 +27,7 @@
#include "ui/controls/control.h" #include "ui/controls/control.h"
#include <memory>
namespace Ui namespace Ui
{ {
@ -53,13 +54,13 @@ struct EditUndo
//! original text //! original text
std::vector<char> text; std::vector<char> text;
//! length of the text //! length of the text
int len; int len = 0;
//! offset cursor //! offset cursor
int cursor1; int cursor1 = 0;
//! offset cursor //! offset cursor
int cursor2; int cursor2 = 0;
//! the first line displayed. //! the first line displayed.
int lineFirst; int lineFirst = 0;
}; };
@ -78,11 +79,11 @@ struct ImageLine
//! name of the image (without icons/) //! name of the image (without icons/)
std::string name; std::string name;
//! vertical offset (v texture) //! vertical offset (v texture)
float offset; float offset = 0.0f;
//! height of the part (dv texture) //! height of the part (dv texture)
float height; float height = 0.0f;
//! width //! width
float width; float width = 0.0f;
}; };
struct HyperLink struct HyperLink
@ -98,7 +99,7 @@ struct HyperMarker
//! name of the marker //! name of the marker
std::string name; std::string name;
//! position in the text //! position in the text
int pos; int pos = 0;
}; };
struct HyperHistory struct HyperHistory
@ -106,7 +107,7 @@ struct HyperHistory
//! full file name text //! full file name text
std::string filename; std::string filename;
//! rank of the first displayed line //! rank of the first displayed line
int firstLine; int firstLine = 0;
}; };
@ -229,7 +230,7 @@ protected:
void UpdateScroll(); void UpdateScroll();
protected: protected:
CScroll* m_scroll; // vertical scrollbar on the right std::unique_ptr<CScroll> m_scroll; // vertical scrollbar on the right
int m_maxChar; // max length of the buffer m_text int m_maxChar; // max length of the buffer m_text
std::vector<char> m_text; // text (without zero terminator) std::vector<char> m_text; // text (without zero terminator)

View File

@ -21,6 +21,7 @@
#include "ui/controls/editvalue.h" #include "ui/controls/editvalue.h"
#include "common/event.h" #include "common/event.h"
#include "common/make_unique.h"
#include "common/misc.h" #include "common/misc.h"
#include "object/robotmain.h" #include "object/robotmain.h"
@ -39,10 +40,6 @@ namespace Ui
CEditValue::CEditValue() : CControl () CEditValue::CEditValue() : CControl ()
{ {
m_edit = 0;
m_buttonUp = 0;
m_buttonDown = 0;
m_type = EVT_100; // % m_type = EVT_100; // %
m_stepValue = 0.1f; // 10% m_stepValue = 0.1f; // 10%
m_minValue = 0.0f; // 0% m_minValue = 0.0f; // 0%
@ -55,9 +52,6 @@ CEditValue::CEditValue() : CControl ()
CEditValue::~CEditValue() CEditValue::~CEditValue()
{ {
delete m_edit;
delete m_buttonUp;
delete m_buttonDown;
} }
@ -65,28 +59,22 @@ CEditValue::~CEditValue()
bool CEditValue::Create(Math::Point pos, Math::Point dim, int icon, EventType eventType) bool CEditValue::Create(Math::Point pos, Math::Point dim, int icon, EventType eventType)
{ {
Ui::CEdit* pe;
Ui::CButton* pc;
if ( eventType == EVENT_NULL ) eventType = GetUniqueEventType(); if ( eventType == EVENT_NULL ) eventType = GetUniqueEventType();
CControl::Create(pos, dim, icon, eventType); CControl::Create(pos, dim, icon, eventType);
GlintDelete(); GlintDelete();
m_edit = new Ui::CEdit(); m_edit = MakeUnique<Ui::CEdit>();
pe = static_cast<Ui::CEdit*>(m_edit); m_edit->Create(pos, dim, 0, EVENT_NULL);
pe->Create(pos, dim, 0, EVENT_NULL); m_edit->SetMaxChar(4);
pe->SetMaxChar(4);
m_buttonUp = new Ui::CButton(); m_buttonUp = MakeUnique<Ui::CButton>();
pc = static_cast<Ui::CButton*>(m_buttonUp); m_buttonUp->Create(pos, dim, 49, EVENT_NULL); // ^
pc->Create(pos, dim, 49, EVENT_NULL); // ^ m_buttonUp->SetRepeat(true);
pc->SetRepeat(true);
m_buttonDown = new Ui::CButton(); m_buttonDown = MakeUnique<Ui::CButton>();
pc = static_cast<Ui::CButton*>(m_buttonDown); m_buttonDown->Create(pos, dim, 50, EVENT_NULL); // v
pc->Create(pos, dim, 50, EVENT_NULL); // v m_buttonDown->SetRepeat(true);
pc->SetRepeat(true);
MoveAdjust(); MoveAdjust();
return true; return true;
@ -109,7 +97,7 @@ void CEditValue::MoveAdjust()
{ {
Math::Point pos, dim; Math::Point pos, dim;
if ( m_edit != 0 ) if (m_edit != nullptr)
{ {
pos.x = m_pos.x; pos.x = m_pos.x;
pos.y = m_pos.y; pos.y = m_pos.y;
@ -119,7 +107,7 @@ void CEditValue::MoveAdjust()
m_edit->SetDim(dim); m_edit->SetDim(dim);
} }
if ( m_buttonUp != 0 ) if (m_buttonUp != nullptr)
{ {
pos.x = m_pos.x+m_dim.x-m_dim.y*0.6f; pos.x = m_pos.x+m_dim.x-m_dim.y*0.6f;
pos.y = m_pos.y+m_dim.y*0.5f; pos.y = m_pos.y+m_dim.y*0.5f;
@ -129,7 +117,7 @@ void CEditValue::MoveAdjust()
m_buttonUp->SetDim(dim); m_buttonUp->SetDim(dim);
} }
if ( m_buttonDown != 0 ) if (m_buttonDown != nullptr)
{ {
pos.x = m_pos.x+m_dim.x-m_dim.y*0.6f; pos.x = m_pos.x+m_dim.x-m_dim.y*0.6f;
pos.y = m_pos.y; pos.y = m_pos.y;
@ -145,21 +133,19 @@ void CEditValue::MoveAdjust()
bool CEditValue::EventProcess(const Event &event) bool CEditValue::EventProcess(const Event &event)
{ {
float value;
CControl::EventProcess(event); CControl::EventProcess(event);
if ( (m_state & STATE_VISIBLE) == 0 ) return true; if ( (m_state & STATE_VISIBLE) == 0 ) return true;
if ( (m_state & STATE_ENABLE) == 0 ) return true; if ( (m_state & STATE_ENABLE) == 0 ) return true;
if ( m_state & STATE_DEAD ) return true; if ( m_state & STATE_DEAD ) return true;
if ( m_edit != 0 ) if (m_edit != nullptr)
{ {
if ( m_edit->GetFocus() && if ( m_edit->GetFocus() &&
event.type == EVENT_KEY_DOWN && event.type == EVENT_KEY_DOWN &&
event.GetData<KeyEventData>()->key == KEY(RETURN) ) event.GetData<KeyEventData>()->key == KEY(RETURN) )
{ {
value = GetValue(); float value = GetValue();
if ( value > m_maxValue ) value = m_maxValue; if ( value > m_maxValue ) value = m_maxValue;
if ( value < m_minValue ) value = m_minValue; if ( value < m_minValue ) value = m_minValue;
SetValue(value, true); SetValue(value, true);
@ -173,11 +159,11 @@ bool CEditValue::EventProcess(const Event &event)
} }
} }
if ( m_buttonUp != 0 ) if (m_buttonUp != nullptr)
{ {
if ( event.type == m_buttonUp->GetEventType() ) if ( event.type == m_buttonUp->GetEventType() )
{ {
value = GetValue()+m_stepValue; float value = GetValue()+m_stepValue;
if ( value > m_maxValue ) value = m_maxValue; if ( value > m_maxValue ) value = m_maxValue;
SetValue(value, true); SetValue(value, true);
HiliteValue(event); HiliteValue(event);
@ -185,11 +171,11 @@ bool CEditValue::EventProcess(const Event &event)
if ( !m_buttonUp->EventProcess(event) ) return false; if ( !m_buttonUp->EventProcess(event) ) return false;
} }
if ( m_buttonDown != 0 ) if (m_buttonDown != nullptr)
{ {
if ( event.type == m_buttonDown->GetEventType() ) if ( event.type == m_buttonDown->GetEventType() )
{ {
value = GetValue()-m_stepValue; float value = GetValue()-m_stepValue;
if ( value < m_minValue ) value = m_minValue; if ( value < m_minValue ) value = m_minValue;
SetValue(value, true); SetValue(value, true);
HiliteValue(event); HiliteValue(event);
@ -201,7 +187,7 @@ bool CEditValue::EventProcess(const Event &event)
event.GetData<MouseWheelEventData>()->dir == WHEEL_UP && event.GetData<MouseWheelEventData>()->dir == WHEEL_UP &&
Detect(event.mousePos)) Detect(event.mousePos))
{ {
value = GetValue()+m_stepValue; float value = GetValue()+m_stepValue;
if ( value > m_maxValue ) value = m_maxValue; if ( value > m_maxValue ) value = m_maxValue;
SetValue(value, true); SetValue(value, true);
HiliteValue(event); HiliteValue(event);
@ -210,7 +196,7 @@ bool CEditValue::EventProcess(const Event &event)
event.GetData<MouseWheelEventData>()->dir == WHEEL_DOWN && event.GetData<MouseWheelEventData>()->dir == WHEEL_DOWN &&
Detect(event.mousePos)) Detect(event.mousePos))
{ {
value = GetValue()-m_stepValue; float value = GetValue()-m_stepValue;
if ( value < m_minValue ) value = m_minValue; if ( value < m_minValue ) value = m_minValue;
SetValue(value, true); SetValue(value, true);
HiliteValue(event); HiliteValue(event);
@ -224,18 +210,16 @@ bool CEditValue::EventProcess(const Event &event)
void CEditValue::HiliteValue(const Event &event) void CEditValue::HiliteValue(const Event &event)
{ {
int pos; if (m_edit == nullptr) return;
if ( m_edit == 0 ) return; int pos = m_edit->GetTextLength();
pos = m_edit->GetTextLength();
if ( m_type == EVT_100 && pos > 0 ) if ( m_type == EVT_100 && pos > 0 )
{ {
pos --; // not only selects the "%" pos --; // not only selects the "%"
} }
m_edit->SetCursor(pos, 0); m_edit->SetCursor(pos, 0);
m_interface->SetFocus(m_edit); m_interface->SetFocus(m_edit.get());
Event newEvent = event.Clone(); Event newEvent = event.Clone();
newEvent.type = EVENT_FOCUS; newEvent.type = EVENT_FOCUS;
@ -255,16 +239,16 @@ void CEditValue::Draw()
DrawShadow(m_pos, m_dim); DrawShadow(m_pos, m_dim);
} }
if ( m_edit != 0 ) if (m_edit != nullptr)
{ {
m_edit->Draw(); m_edit->Draw();
} }
if ( m_buttonUp != 0 ) if (m_buttonUp != nullptr)
{ {
m_buttonUp->SetState(STATE_DEAD, TestState(STATE_DEAD)); m_buttonUp->SetState(STATE_DEAD, TestState(STATE_DEAD));
m_buttonUp->Draw(); m_buttonUp->Draw();
} }
if ( m_buttonDown != 0 ) if (m_buttonDown != nullptr)
{ {
m_buttonDown->SetState(STATE_DEAD, TestState(STATE_DEAD)); m_buttonDown->SetState(STATE_DEAD, TestState(STATE_DEAD));
m_buttonDown->Draw(); m_buttonDown->Draw();

View File

@ -24,6 +24,7 @@
#include "ui/controls/control.h" #include "ui/controls/control.h"
#include <memory>
namespace Gfx namespace Gfx
{ {
@ -82,9 +83,9 @@ protected:
void HiliteValue(const Event &event); void HiliteValue(const Event &event);
Ui::CInterface* m_interface; Ui::CInterface* m_interface;
Ui::CEdit* m_edit; std::unique_ptr<Ui::CEdit> m_edit;
Ui::CButton* m_buttonUp; std::unique_ptr<Ui::CButton> m_buttonUp;
Ui::CButton* m_buttonDown; std::unique_ptr<Ui::CButton> m_buttonDown;
EditValueType m_type; EditValueType m_type;
float m_stepValue; float m_stepValue;
float m_minValue; float m_minValue;

View File

@ -27,24 +27,19 @@
#include "graphics/engine/engine.h" #include "graphics/engine/engine.h"
#include <string.h>
#include <stdio.h>
namespace Ui namespace Ui
{ {
// Object's constructor. // Object's constructor.
CImage::CImage() : CControl() CImage::CImage() : CControl()
{ {
m_filename[0] = 0;
} }
// Object's destructor. // Object's destructor.
CImage::~CImage() CImage::~CImage()
{ {
if ( m_filename[0] != 0 ) if (!m_filename.empty())
{ {
m_engine->DeleteTexture(m_filename); m_engine->DeleteTexture(m_filename);
} }
@ -71,19 +66,14 @@ bool CImage::Create(Math::Point pos, Math::Point dim, int icon, EventType eventT
// Specifies the name of the image display. // Specifies the name of the image display.
void CImage::SetFilenameImage(const char *name) void CImage::SetFilenameImage(const std::string& name)
{ {
if ( m_filename[0] != 0 ) if (!m_filename.empty())
{ {
m_engine->DeleteTexture(m_filename); m_engine->DeleteTexture(m_filename);
} }
strcpy(m_filename, name); m_filename = name;
}
char* CImage::GetFilenameImage()
{
return m_filename;
} }

View File

@ -45,13 +45,10 @@ public:
void Draw(); void Draw();
void SetFilenameImage(const char *name); void SetFilenameImage(const std::string& name);
char* GetFilenameImage();
protected: protected:
std::string m_filename;
protected:
char m_filename[100];
}; };

View File

@ -22,6 +22,9 @@
#include "app/app.h" #include "app/app.h"
#include <boost/range/adaptor/reversed.hpp>
namespace Ui namespace Ui
{ {
@ -31,18 +34,12 @@ CInterface::CInterface()
m_event = CApplication::GetInstancePointer()->GetEventQueue(); m_event = CApplication::GetInstancePointer()->GetEventQueue();
m_engine = Gfx::CEngine::GetInstancePointer(); m_engine = Gfx::CEngine::GetInstancePointer();
m_camera = nullptr; m_camera = nullptr;
for (int i = 0; i < MAXCONTROL; i++)
{
m_table[i] = nullptr;
}
} }
// Object's destructor. // Object's destructor.
CInterface::~CInterface() CInterface::~CInterface()
{ {
Flush();
} }
@ -50,26 +47,24 @@ CInterface::~CInterface()
void CInterface::Flush() void CInterface::Flush()
{ {
for (int i = 0; i < MAXCONTROL; i++) for (auto& control : m_controls)
{ {
delete m_table[i]; control.reset();
m_table[i] = nullptr;
} }
} }
int CInterface::GetNextFreeControl() int CInterface::GetNextFreeControl()
{ {
for (int i = 10; i < MAXCONTROL-1; i++) for (int i = 10; i < static_cast<int>(m_controls.size()) - 1; i++)
{ {
if (m_table[i] == nullptr) if (m_controls[i] == nullptr)
return i; return i;
} }
return -1; return -1;
} }
template <typename ControlClass>
template <typename T> inline T* CInterface::CreateControl(Math::Point pos, Math::Point dim, int icon, EventType eventMsg) ControlClass* CInterface::CreateControl(Math::Point pos, Math::Point dim, int icon, EventType eventMsg)
{ {
if (eventMsg == EVENT_NULL) if (eventMsg == EVENT_NULL)
eventMsg = GetUniqueEventType(); eventMsg = GetUniqueEventType();
@ -78,10 +73,11 @@ template <typename T> inline T* CInterface::CreateControl(Math::Point pos, Math:
if (index < 0) if (index < 0)
return nullptr; return nullptr;
m_table[index] = new T(); auto control = MakeUnique<ControlClass>();
T* pc = static_cast<T *>(m_table[index]); control->Create(pos, dim, icon, eventMsg);
pc->Create(pos, dim, icon, eventMsg); auto* controlPtr = control.get();
return pc; m_controls[index] = std::move(control);
return controlPtr;
} }
@ -105,18 +101,18 @@ CWindow* CInterface::CreateWindows(Math::Point pos, Math::Point dim, int icon, E
case EVENT_WINDOW7: index = 7; break; case EVENT_WINDOW7: index = 7; break;
case EVENT_WINDOW8: index = 8; break; case EVENT_WINDOW8: index = 8; break;
case EVENT_WINDOW9: index = 9; break; case EVENT_WINDOW9: index = 9; break;
case EVENT_TOOLTIP: index = MAXCONTROL-1; break; case EVENT_TOOLTIP: index = m_controls.size() - 1; break;
default: index = GetNextFreeControl(); break; default: index = GetNextFreeControl(); break;
} }
if (index < 0) if (index < 0)
return nullptr; return nullptr;
delete m_table[index]; auto window = MakeUnique<CWindow>();
m_table[index] = new CWindow(); window->Create(pos, dim, icon, eventMsg);
CWindow* pc = static_cast<CWindow *>(m_table[index]); auto* windowPtr = window.get();
pc->Create(pos, dim, icon, eventMsg); m_controls[index] = std::move(window);
return pc; return windowPtr;
} }
// Creates a new button. // Creates a new button.
@ -220,10 +216,11 @@ CList* CInterface::CreateList(Math::Point pos, Math::Point dim, int icon, EventT
if (index < 0) if (index < 0)
return nullptr; return nullptr;
m_table[index] = new CList(); auto list = MakeUnique<CList>();
CList* pc = static_cast<CList *>(m_table[index]); list->Create(pos, dim, icon, eventMsg, expand);
pc->Create(pos, dim, icon, eventMsg, expand); auto* listPtr = list.get();
return pc; m_controls[index] = std::move(list);
return listPtr;
} }
// Creates a new shortcut. // Creates a new shortcut.
@ -258,16 +255,13 @@ CMap* CInterface::CreateMap(Math::Point pos, Math::Point dim, int icon, EventTyp
bool CInterface::DeleteControl(EventType eventMsg) bool CInterface::DeleteControl(EventType eventMsg)
{ {
for (int i = 0; i < MAXCONTROL; i++) for (auto& control : m_controls)
{ {
if ( m_table[i] != nullptr ) if (control != nullptr &&
eventMsg == control->GetEventType())
{ {
if (eventMsg == m_table[i]->GetEventType()) control.reset();
{ return true;
delete m_table[i];
m_table[i] = nullptr;
return true;
}
} }
} }
return false; return false;
@ -277,12 +271,12 @@ bool CInterface::DeleteControl(EventType eventMsg)
CControl* CInterface::SearchControl(EventType eventMsg) CControl* CInterface::SearchControl(EventType eventMsg)
{ {
for (int i = 0; i < MAXCONTROL; i++) for (auto& control : m_controls)
{ {
if (m_table[i] != nullptr) if (control != nullptr &&
eventMsg == control->GetEventType())
{ {
if (eventMsg == m_table[i]->GetEventType()) return control.get();
return m_table[i];
} }
} }
return nullptr; return nullptr;
@ -300,11 +294,11 @@ bool CInterface::EventProcess(const Event &event)
m_engine->SetMouseType(m_camera->GetMouseDef(event.mousePos)); m_engine->SetMouseType(m_camera->GetMouseDef(event.mousePos));
} }
for (int i = MAXCONTROL-1; i >= 0; i--) for (auto& control : boost::adaptors::reverse(m_controls))
{ {
if (m_table[i] != nullptr && m_table[i]->TestState(STATE_ENABLE)) if (control != nullptr && control->TestState(STATE_ENABLE))
{ {
if ( !m_table[i]->EventProcess(event) ) if (! control->EventProcess(event))
return false; return false;
} }
} }
@ -317,11 +311,11 @@ bool CInterface::EventProcess(const Event &event)
bool CInterface::GetTooltip(Math::Point pos, std::string &name) bool CInterface::GetTooltip(Math::Point pos, std::string &name)
{ {
for (int i = MAXCONTROL-1; i >= 0; i--) for (auto& control : boost::adaptors::reverse(m_controls))
{ {
if (m_table[i] != nullptr) if (control != nullptr)
{ {
if (m_table[i]->GetTooltip(pos, name)) if (control->GetTooltip(pos, name))
return true; return true;
} }
} }
@ -333,21 +327,21 @@ bool CInterface::GetTooltip(Math::Point pos, std::string &name)
void CInterface::Draw() void CInterface::Draw()
{ {
for (int i = 0; i < MAXCONTROL; i++) for (auto& control : m_controls)
{ {
if ( m_table[i] != nullptr ) if (control != nullptr)
m_table[i]->Draw(); control->Draw();
} }
} }
void CInterface::SetFocus(CControl* control) void CInterface::SetFocus(CControl* focusControl)
{ {
for (int i = 0; i < MAXCONTROL; i++) for (auto& control : m_controls)
{ {
if (m_table[i] != nullptr) if (control != nullptr)
{ {
bool focus = m_table[i] == control; bool focus = control.get() == focusControl;
m_table[i]->SetFocus(focus); control->SetFocus(focus);
} }
} }
} }

View File

@ -49,14 +49,15 @@
#include "ui/controls/target.h" #include "ui/controls/target.h"
#include "ui/controls/window.h" #include "ui/controls/window.h"
#include <memory>
#include <string> #include <string>
#include <vector>
namespace Ui namespace Ui
{ {
const int MAXCONTROL = 100; const int MAXCONTROL = 100;
class CInterface class CInterface
{ {
public: public:
@ -92,18 +93,19 @@ public:
void Draw(); void Draw();
void SetFocus(CControl* control); void SetFocus(CControl* focusControl);
protected: protected:
int GetNextFreeControl(); int GetNextFreeControl();
template <typename T> inline T* CreateControl(Math::Point pos, Math::Point dim, int icon, EventType eventMsg);
template <typename ControlClass>
ControlClass* CreateControl(Math::Point pos, Math::Point dim, int icon, EventType eventMsg);
CEventQueue* m_event; CEventQueue* m_event;
Gfx::CEngine* m_engine; Gfx::CEngine* m_engine;
Gfx::CCamera* m_camera; Gfx::CCamera* m_camera;
std::array<std::unique_ptr<CControl>, MAXCONTROL> m_controls;
CControl* m_table[MAXCONTROL];
}; };
} } // namespace Ui

View File

@ -20,6 +20,8 @@
#include "ui/controls/list.h" #include "ui/controls/list.h"
#include "common/make_unique.h"
#include "graphics/engine/engine.h" #include "graphics/engine/engine.h"
#include <cassert> #include <cassert>
@ -33,25 +35,18 @@ const float MARGING = 4.0f;
// Object's constructor. // Object's constructor.
CList::CList() : CControl() CList::CList()
: CControl(),
m_tabs(),
m_justifs()
{ {
for (int i = 0; i < LISTMAXDISPLAY; i++)
m_button[i] = nullptr;
m_scroll = nullptr;
for (int i = 0; i < LISTMAXTOTAL; i++)
{
m_text[i][0] = 0;
m_check[i] = false;
m_enable[i] = true;
}
for (int i = 0; i < 10; i++) for (int i = 0; i < 10; i++)
{ {
m_tabs[i] = 0.0f; m_tabs[i] = 0.0f;
m_justifs[i] = Gfx::TEXT_ALIGN_LEFT; m_justifs[i] = Gfx::TEXT_ALIGN_LEFT;
} }
m_expand = 0.0f;
m_totalLine = 0; m_totalLine = 0;
m_displayLine = 0; m_displayLine = 0;
m_selectLine = -1; m_selectLine = -1;
@ -65,12 +60,6 @@ CList::CList() : CControl()
CList::~CList() CList::~CList()
{ {
for (int i = 0; i < LISTMAXDISPLAY; i++)
{
delete m_button[i];
}
delete m_scroll;
} }
@ -88,9 +77,8 @@ bool CList::Create(Math::Point pos, Math::Point dim, int icon, EventType eventMs
CControl::Create(pos, dim, icon, eventMsg); CControl::Create(pos, dim, icon, eventMsg);
m_scroll = new CScroll(); m_scroll = MakeUnique<CScroll>();
m_scroll->Create(pos, dim, 0, EVENT_NULL); m_scroll->Create(pos, dim, 0, EVENT_NULL);
m_eventScroll = m_scroll->GetEventType();
return MoveAdjust(); return MoveAdjust();
} }
@ -110,14 +98,8 @@ bool CList::MoveAdjust()
Math::Point ipos, idim, ppos, ddim; Math::Point ipos, idim, ppos, ddim;
float marging, h; float marging, h;
for (int i = 0; i < LISTMAXDISPLAY; i++) for (auto& button : m_buttons)
{ button.reset();
if (m_button[i] != nullptr)
{
delete m_button[i];
m_button[i] = nullptr;
}
}
if (m_icon == 0) if (m_icon == 0)
marging = MARGING; marging = MARGING;
@ -153,18 +135,18 @@ bool CList::MoveAdjust()
ddim.y = h; ddim.y = h;
for (int i = 0; i < m_displayLine; i++) for (int i = 0; i < m_displayLine; i++)
{ {
m_button[i] = new CButton(); auto button = MakeUnique<CButton>();
m_button[i]->Create(ppos, ddim, -1, EVENT_NULL); button->Create(ppos, ddim, -1, EVENT_NULL);
m_button[i]->SetTextAlign(Gfx::TEXT_ALIGN_LEFT); button->SetTextAlign(Gfx::TEXT_ALIGN_LEFT);
m_button[i]->SetState(STATE_SIMPLY); button->SetState(STATE_SIMPLY);
m_button[i]->SetFontType(m_fontType); button->SetFontType(m_fontType);
m_button[i]->SetFontSize(m_fontSize); button->SetFontSize(m_fontSize);
ppos.y -= h; ppos.y -= h;
m_eventButton[i] = m_button[i]->GetEventType(); m_buttons[i] = std::move(button);
} }
if ( m_scroll != nullptr ) if (m_scroll != nullptr)
{ {
ppos.x = ipos.x + idim.x - SCROLL_WIDTH; ppos.x = ipos.x + idim.x - SCROLL_WIDTH;
ppos.y = ipos.y; ppos.y = ipos.y;
@ -186,9 +168,9 @@ EventType CList::GetEventMsgButton(int i)
{ {
if (i < 0 || i >= m_displayLine) if (i < 0 || i >= m_displayLine)
return EVENT_NULL; return EVENT_NULL;
if (m_button[i] == nullptr) if (m_buttons[i] == nullptr)
return EVENT_NULL; return EVENT_NULL;
return m_button[i]->GetEventType(); return m_buttons[i]->GetEventType();
} }
// Returns the message from the elevator. // Returns the message from the elevator.
@ -221,8 +203,8 @@ bool CList::SetState(int state, bool bState)
{ {
for (int i = 0; i < m_displayLine; i++) for (int i = 0; i < m_displayLine; i++)
{ {
if (m_button[i] != nullptr) if (m_buttons[i] != nullptr)
m_button[i]->SetState(state, bState); m_buttons[i]->SetState(state, bState);
} }
if (m_scroll != nullptr) if (m_scroll != nullptr)
m_scroll->SetState(state, bState); m_scroll->SetState(state, bState);
@ -238,8 +220,8 @@ bool CList::SetState(int state)
{ {
for (int i = 0; i < m_displayLine; i++) for (int i = 0; i < m_displayLine; i++)
{ {
if (m_button[i] != nullptr) if (m_buttons[i] != nullptr)
m_button[i]->SetState(state); m_buttons[i]->SetState(state);
} }
if (m_scroll != nullptr) if (m_scroll != nullptr)
m_scroll->SetState(state); m_scroll->SetState(state);
@ -255,8 +237,8 @@ bool CList::ClearState(int state)
{ {
for (int i = 0; i < m_displayLine; i++) for (int i = 0; i < m_displayLine; i++)
{ {
if (m_button[i] != nullptr) if (m_buttons[i] != nullptr)
m_button[i]->ClearState(state); m_buttons[i]->ClearState(state);
} }
if (m_scroll != nullptr) if (m_scroll != nullptr)
m_scroll->ClearState(state); m_scroll->ClearState(state);
@ -274,18 +256,18 @@ bool CList::EventProcess(const Event &event)
{ {
int i = m_selectLine-m_firstLine; int i = m_selectLine-m_firstLine;
if (i >= 0 && i < 4 && m_button[i] != nullptr) if (i >= 0 && i < 4 && m_buttons[i] != nullptr)
{ {
m_blinkTime += event.rTime; m_blinkTime += event.rTime;
if (Math::Mod(m_blinkTime, 0.7f) < 0.3f) if (Math::Mod(m_blinkTime, 0.7f) < 0.3f)
{ {
m_button[i]->ClearState(STATE_ENABLE); m_buttons[i]->ClearState(STATE_ENABLE);
m_button[i]->ClearState(STATE_CHECK); m_buttons[i]->ClearState(STATE_CHECK);
} }
else else
{ {
m_button[i]->SetState(STATE_ENABLE); m_buttons[i]->SetState(STATE_ENABLE);
m_button[i]->SetState(STATE_CHECK); m_buttons[i]->SetState(STATE_CHECK);
} }
} }
} }
@ -323,8 +305,8 @@ bool CList::EventProcess(const Event &event)
{ {
if (i + m_firstLine >= m_totalLine) if (i + m_firstLine >= m_totalLine)
break; break;
if (m_button[i] != nullptr) if (m_buttons[i] != nullptr)
m_button[i]->EventProcess(event); m_buttons[i]->EventProcess(event);
} }
} }
@ -335,12 +317,12 @@ bool CList::EventProcess(const Event &event)
if (i + m_firstLine >= m_totalLine) if (i + m_firstLine >= m_totalLine)
break; break;
if (m_button[i] != nullptr) if (m_buttons[i] != nullptr)
{ {
if (!m_button[i]->EventProcess(event)) if (!m_buttons[i]->EventProcess(event))
return false; return false;
if (event.type == m_eventButton[i]) if (event.type == m_buttons[i]->GetEventType())
{ {
SetSelect(m_firstLine + i); SetSelect(m_firstLine + i);
@ -355,7 +337,7 @@ bool CList::EventProcess(const Event &event)
if (!m_scroll->EventProcess(event)) if (!m_scroll->EventProcess(event))
return false; return false;
if (event.type == m_eventScroll) if (event.type == m_scroll->GetEventType())
{ {
MoveScroll(); MoveScroll();
UpdateButton(); UpdateButton();
@ -408,9 +390,9 @@ void CList::Draw()
uv2.x = 156.0f / 256.0f; uv2.x = 156.0f / 256.0f;
uv2.y = 92.0f / 256.0f; uv2.y = 92.0f / 256.0f;
if (m_button[0] != nullptr) if (m_buttons[0] != nullptr)
{ {
dim = m_button[0]->GetDim(); dim = m_buttons[0]->GetDim();
dim.y *= m_displayLine; // background sounds spot behind dim.y *= m_displayLine; // background sounds spot behind
} }
} }
@ -428,10 +410,10 @@ void CList::Draw()
if ( m_totalLine < m_displayLine ) // no buttons to the bottom? if ( m_totalLine < m_displayLine ) // no buttons to the bottom?
{ {
i = m_totalLine; i = m_totalLine;
if ( m_button[i] != 0 ) if (m_buttons[i] != nullptr)
{ {
pos = m_button[i]->GetPos(); pos = m_buttons[i]->GetPos();
dim = m_button[i]->GetDim(); dim = m_buttons[i]->GetDim();
pos.y += dim.y * 1.1f; pos.y += dim.y * 1.1f;
dim.y *= 0.4f; dim.y *= 0.4f;
pos.y -= dim.y; pos.y -= dim.y;
@ -455,30 +437,30 @@ void CList::Draw()
if ( i + m_firstLine >= m_totalLine ) if ( i + m_firstLine >= m_totalLine )
break; break;
if ( m_button[i] != nullptr ) if ( m_buttons[i] != nullptr )
{ {
if ( !m_bBlink && i + m_firstLine < m_totalLine ) if ( !m_bBlink && i + m_firstLine < m_totalLine )
m_button[i]->SetState(STATE_ENABLE, m_enable[i+m_firstLine] && (m_state & STATE_ENABLE) ); m_buttons[i]->SetState(STATE_ENABLE, m_items[i+m_firstLine].enable && (m_state & STATE_ENABLE) );
m_button[i]->Draw(); // draws a box without text m_buttons[i]->Draw(); // draws a box without text
// draws text in the box // draws text in the box
pos = m_button[i]->GetPos(); pos = m_buttons[i]->GetPos();
dim = m_button[i]->GetDim(); dim = m_buttons[i]->GetDim();
if ( m_tabs[0] == 0.0f ) if ( m_tabs[0] == 0.0f )
{ {
ppos.x = pos.x + dim.y * 0.5f; ppos.x = pos.x + dim.y * 0.5f;
ppos.y = pos.y + dim.y * 0.5f; ppos.y = pos.y + dim.y * 0.5f;
ppos.y -= m_engine->GetText()->GetHeight(m_fontType, m_fontSize) / 2.0f; ppos.y -= m_engine->GetText()->GetHeight(m_fontType, m_fontSize) / 2.0f;
ddim.x = dim.x-dim.y; ddim.x = dim.x-dim.y;
DrawCase(m_text[i + m_firstLine], ppos, ddim.x, Gfx::TEXT_ALIGN_LEFT); DrawCase(m_items[i + m_firstLine].text, ppos, ddim.x, Gfx::TEXT_ALIGN_LEFT);
} }
else else
{ {
ppos.x = pos.x + dim.y * 0.5f; ppos.x = pos.x + dim.y * 0.5f;
ppos.y = pos.y + dim.y * 0.5f; ppos.y = pos.y + dim.y * 0.5f;
ppos.y -= m_engine->GetText()->GetHeight(m_fontType, m_fontSize) / 2.0f; ppos.y -= m_engine->GetText()->GetHeight(m_fontType, m_fontSize) / 2.0f;
pb = m_text[i + m_firstLine]; pb = m_items[i + m_firstLine].text;
for (int j = 0; j < 10; j++) for (int j = 0; j < 10; j++)
{ {
pe = strchr(pb, '\t'); pe = strchr(pb, '\t');
@ -500,8 +482,8 @@ void CList::Draw()
if ( (m_state & STATE_EXTEND) && i < m_totalLine) if ( (m_state & STATE_EXTEND) && i < m_totalLine)
{ {
pos = m_button[i]->GetPos(); pos = m_buttons[i]->GetPos();
dim = m_button[i]->GetDim(); dim = m_buttons[i]->GetDim();
pos.x += dim.x - dim.y * 0.75f; pos.x += dim.x - dim.y * 0.75f;
dim.x = dim.y * 0.75f; dim.x = dim.y * 0.75f;
pos.x += 2.0f / 640.0f; pos.x += 2.0f / 640.0f;
@ -509,7 +491,7 @@ void CList::Draw()
dim.x -= 4.0f / 640.0f; dim.x -= 4.0f / 640.0f;
dim.y -= 4.0f / 480.0f; dim.y -= 4.0f / 480.0f;
if ( m_check[i + m_firstLine] ) if (m_items[i + m_firstLine].check)
{ {
m_engine->SetTexture("textures/interface/button1.png"); m_engine->SetTexture("textures/interface/button1.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
@ -562,7 +544,7 @@ void CList::Draw()
} }
} }
if ( m_scroll != 0 ) if (m_scroll != nullptr)
m_scroll->Draw(); // draws the lift m_scroll->Draw(); // draws the lift
} }
@ -648,19 +630,17 @@ bool CList::GetSelectCap()
void CList::SetBlink(bool bEnable) void CList::SetBlink(bool bEnable)
{ {
int i;
m_bBlink = bEnable; m_bBlink = bEnable;
m_blinkTime = 0.0f; m_blinkTime = 0.0f;
i = m_selectLine-m_firstLine; int i = m_selectLine - m_firstLine;
if (i >= 0 && i < 4 && m_button[i] != nullptr) if (i >= 0 && i < 4 && m_buttons[i] != nullptr)
{ {
if ( !bEnable ) if ( !bEnable )
{ {
m_button[i]->SetState(STATE_CHECK); m_buttons[i]->SetState(STATE_CHECK);
m_button[i]->ClearState(STATE_ENABLE); m_buttons[i]->ClearState(STATE_ENABLE);
} }
} }
} }
@ -682,9 +662,9 @@ void CList::SetItemName(int i, const char* name)
m_totalLine = i+1; // expands the list m_totalLine = i+1; // expands the list
if ( name[0] == 0 ) if ( name[0] == 0 )
strcpy(m_text[i], " "); strcpy(m_items[i].text, " ");
else else
strcpy(m_text[i], name); strcpy(m_items[i].text, name);
UpdateButton(); UpdateButton();
UpdateScroll(); UpdateScroll();
@ -697,7 +677,7 @@ char* CList::GetItemName(int i)
if ( i < 0 || i >= m_totalLine ) if ( i < 0 || i >= m_totalLine )
return 0; return 0;
return m_text[i]; return m_items[i].text;
} }
@ -708,7 +688,7 @@ void CList::SetCheck(int i, bool bMode)
if ( i < 0 || i >= m_totalLine ) if ( i < 0 || i >= m_totalLine )
return; return;
m_check[i] = bMode; m_items[i].check = bMode;
} }
// Returns the bit "check" for a box. // Returns the bit "check" for a box.
@ -718,7 +698,7 @@ bool CList::GetCheck(int i)
if ( i < 0 || i >= m_totalLine ) if ( i < 0 || i >= m_totalLine )
return false; return false;
return m_check[i]; return m_items[i].check;
} }
@ -729,7 +709,7 @@ void CList::SetEnable(int i, bool bMode)
if ( i < 0 || i >= m_totalLine ) if ( i < 0 || i >= m_totalLine )
return; return;
m_enable[i] = bMode; m_items[i].enable = bMode;
} }
// Returns the bit "enable" for a box. // Returns the bit "enable" for a box.
@ -739,7 +719,7 @@ bool CList::GetEnable(int i)
if ( i < 0 || i >= m_totalLine ) if ( i < 0 || i >= m_totalLine )
return false; return false;
return m_enable[i]; return m_items[i].enable;
} }
@ -800,21 +780,21 @@ void CList::UpdateButton()
j = m_firstLine; j = m_firstLine;
for (i = 0; i < m_displayLine; i++) for (i = 0; i < m_displayLine; i++)
{ {
if (m_button[i] == nullptr) if (m_buttons[i] == nullptr)
continue; continue;
m_button[i]->SetState(STATE_CHECK, (j == m_selectLine)); m_buttons[i]->SetState(STATE_CHECK, (j == m_selectLine));
if ( j < m_totalLine ) if ( j < m_totalLine )
{ {
//? m_button[i]->SetName(m_text[j]); //? m_buttons[i]->SetName(m_text[j]);
m_button[i]->SetName(" "); // blank button m_buttons[i]->SetName(" "); // blank button
m_button[i]->SetState(STATE_ENABLE, (state & STATE_ENABLE)); m_buttons[i]->SetState(STATE_ENABLE, (state & STATE_ENABLE));
} }
else else
{ {
m_button[i]->SetName(" "); // blank button m_buttons[i]->SetName(" "); // blank button
m_button[i]->ClearState(STATE_ENABLE); m_buttons[i]->ClearState(STATE_ENABLE);
} }
j ++; j ++;
} }
@ -860,14 +840,11 @@ void CList::UpdateScroll()
void CList::MoveScroll() void CList::MoveScroll()
{ {
float pos; if (m_scroll == nullptr)
int n;
if ( m_scroll == 0 )
return; return;
n = m_totalLine - m_displayLine; int n = m_totalLine - m_displayLine;
pos = m_scroll->GetVisibleValue(); float pos = m_scroll->GetVisibleValue();
pos += m_scroll->GetArrowStep() / 2.0f; // it's magic! pos += m_scroll->GetArrowStep() / 2.0f; // it's magic!
m_firstLine = static_cast<int>(pos * n); m_firstLine = static_cast<int>(pos * n);
if ( m_firstLine < 0 ) if ( m_firstLine < 0 )

View File

@ -32,6 +32,8 @@
#include "ui/controls/button.h" #include "ui/controls/button.h"
#include "ui/controls/scroll.h" #include "ui/controls/scroll.h"
#include <array>
#include <memory>
namespace Ui namespace Ui
{ {
@ -43,85 +45,86 @@ const int LISTMAXTOTAL = 100; // maximum total number of lines
class CList : public CControl class CList : public CControl
{ {
public: public:
CList(); CList();
~CList(); ~CList();
bool Create(Math::Point pos, Math::Point dim, int icon, EventType eventMsg, float expand); bool Create(Math::Point pos, Math::Point dim, int icon, EventType eventMsg, float expand);
void SetPos(Math::Point pos) override; void SetPos(Math::Point pos) override;
void SetDim(Math::Point dim) override; void SetDim(Math::Point dim) override;
bool SetState(int state, bool bState) override; bool SetState(int state, bool bState) override;
bool SetState(int state) override; bool SetState(int state) override;
bool ClearState(int state) override; bool ClearState(int state) override;
bool EventProcess(const Event &event) override; bool EventProcess(const Event &event) override;
void Draw() override; void Draw() override;
void Flush(); void Flush();
void SetTotal(int i); void SetTotal(int i);
int GetTotal(); int GetTotal();
void SetSelect(int i); void SetSelect(int i);
int GetSelect(); int GetSelect();
void SetSelectCap(bool bEnable); void SetSelectCap(bool bEnable);
bool GetSelectCap(); bool GetSelectCap();
void SetBlink(bool bEnable); void SetBlink(bool bEnable);
bool GetBlink(); bool GetBlink();
void SetItemName(int i, const char* name); void SetItemName(int i, const char* name);
char* GetItemName(int i); char* GetItemName(int i);
void SetCheck(int i, bool bMode); void SetCheck(int i, bool bMode);
bool GetCheck(int i); bool GetCheck(int i);
void SetEnable(int i, bool bEnable); void SetEnable(int i, bool bEnable);
bool GetEnable(int i); bool GetEnable(int i);
void SetTabs(int i, float pos, Gfx::TextAlign justif=Gfx::TEXT_ALIGN_LEFT); void SetTabs(int i, float pos, Gfx::TextAlign justif=Gfx::TEXT_ALIGN_LEFT);
float GetTabs(int i); float GetTabs(int i);
void ShowSelect(bool bFixed); void ShowSelect(bool bFixed);
EventType GetEventMsgButton(int i); EventType GetEventMsgButton(int i);
EventType GetEventMsgScroll(); EventType GetEventMsgScroll();
protected: protected:
bool MoveAdjust(); bool MoveAdjust();
void UpdateButton(); void UpdateButton();
void UpdateScroll(); void UpdateScroll();
void MoveScroll(); void MoveScroll();
void DrawCase(char *text, Math::Point pos, float width, Gfx::TextAlign justif); void DrawCase(char *text, Math::Point pos, float width, Gfx::TextAlign justif);
private: private:
// Overridden to avoid warning about hiding the virtual function // Overridden to avoid warning about hiding the virtual function
virtual bool Create(Math::Point pos, Math::Point dim, int icon, EventType eventType) override; virtual bool Create(Math::Point pos, Math::Point dim, int icon, EventType eventType) override;
protected: protected:
CButton* m_button[LISTMAXDISPLAY]; std::array<std::unique_ptr<CButton>, LISTMAXDISPLAY> m_buttons;
CScroll* m_scroll; std::unique_ptr<CScroll> m_scroll;
EventType m_eventButton[LISTMAXDISPLAY]; float m_expand;
EventType m_eventScroll; int m_totalLine; // total number of lines
int m_displayLine; // number of visible lines
int m_selectLine; // selected line
int m_firstLine; // first visible line
bool m_bBlink;
bool m_bSelectCap;
float m_blinkTime;
float m_tabs[10];
Gfx::TextAlign m_justifs[10];
float m_expand; struct Item
int m_totalLine; // total number of lines {
int m_displayLine; // number of visible lines char text[100] = {0};
int m_selectLine; // selected line bool check = false;
int m_firstLine; // first visible line bool enable = true;
bool m_bBlink; };
bool m_bSelectCap; std::array<Item, LISTMAXTOTAL> m_items;
float m_blinkTime;
float m_tabs[10];
Gfx::TextAlign m_justifs[10];
char m_text[LISTMAXTOTAL][100];
char m_check[LISTMAXTOTAL];
char m_enable[LISTMAXTOTAL];
}; };

View File

@ -66,9 +66,12 @@ CMap::CMap() : CControl()
m_half = m_terrain->GetMosaicCount() * m_terrain->GetBrickCount() * m_terrain->GetBrickSize() / 2.0f; m_half = m_terrain->GetMosaicCount() * m_terrain->GetBrickCount() * m_terrain->GetBrickSize() / 2.0f;
m_highlightRank = -1; m_highlightRank = -1;
m_totalFix = 0;
m_totalMove = 0;
m_bRadar = false;
FlushObject(); FlushObject();
m_fixImage[0] = 0;
m_mode = 0; m_mode = 0;
m_bToy = false; m_bToy = false;
m_bDebug = false; m_bDebug = false;
@ -175,16 +178,16 @@ void CMap::SetWaterColor(Gfx::Color color)
// Specifies a fixed image in place of the drawing of the relief. // Specifies a fixed image in place of the drawing of the relief.
void CMap::SetFixImage(const char *filename) void CMap::SetFixImage(const std::string& filename)
{ {
strcpy(m_fixImage, filename); m_fixImage = filename;
} }
// Whether to use a still image. // Whether to use a still image.
bool CMap::GetFixImage() bool CMap::GetFixImage()
{ {
return (m_fixImage[0] != 0); return ! m_fixImage.empty();
} }
@ -241,7 +244,7 @@ Math::Point CMap::AdjustOffset(Math::Point offset)
void CMap::SetHighlight(CObject* pObj) void CMap::SetHighlight(CObject* pObj)
{ {
m_highlightRank = -1; m_highlightRank = -1;
if ( m_bToy || m_fixImage[0] != 0 ) if ( m_bToy || !m_fixImage.empty())
return; // card with still image? return; // card with still image?
if ( pObj == nullptr ) if ( pObj == nullptr )
return; return;
@ -333,10 +336,10 @@ void CMap::Draw()
if ( !m_bEnable ) if ( !m_bEnable )
return; return;
if ( m_fixImage[0] == 0 && m_map[MAPMAXOBJECT - 1].bUsed ) if (m_fixImage.empty() && m_map[MAPMAXOBJECT - 1].bUsed)
m_offset = AdjustOffset(m_map[MAPMAXOBJECT - 1].pos); m_offset = AdjustOffset(m_map[MAPMAXOBJECT - 1].pos);
if ( m_fixImage[0] == 0 ) // drawing of the relief? if (m_fixImage.empty()) // drawing of the relief?
{ {
m_engine->SetTexture("textures/interface/map.png"); m_engine->SetTexture("textures/interface/map.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
@ -443,7 +446,7 @@ void CMap::DrawFocus(Math::Point pos, float dir, ObjectType type, MapColor color
bool bEnding; bool bEnding;
int quart; int quart;
if ( m_bToy || m_fixImage[0] != 0 ) return; // map with still image? if (m_bToy || !m_fixImage.empty()) return; // map with still image?
if ( color != MAPCOLOR_MOVE ) return; if ( color != MAPCOLOR_MOVE ) return;
pos.x = (pos.x-m_offset.x)*(m_zoom*0.5f)/m_half+0.5f; pos.x = (pos.x-m_offset.x)*(m_zoom*0.5f)/m_half+0.5f;
@ -886,7 +889,7 @@ void CMap::DrawHighlight(Math::Point pos)
{ {
Math::Point dim, uv1, uv2; Math::Point dim, uv1, uv2;
if ( m_bToy || m_fixImage[0] != 0 ) return; // map with still image? if (m_bToy || !m_fixImage.empty()) return; // map with still image?
pos.x = (pos.x-m_offset.x)*(m_zoom*0.5f)/m_half+0.5f; pos.x = (pos.x-m_offset.x)*(m_zoom*0.5f)/m_half+0.5f;
pos.y = (pos.y-m_offset.y)*(m_zoom*0.5f)/m_half+0.5f; pos.y = (pos.y-m_offset.y)*(m_zoom*0.5f)/m_half+0.5f;
@ -1004,7 +1007,7 @@ void CMap::DrawVertex(Math::Point uv1, Math::Point uv2, float zoom)
void CMap::UpdateTerrain() void CMap::UpdateTerrain()
{ {
if (m_fixImage[0] != 0) return; // still image? if (! m_fixImage.empty()) return; // still image?
CImage img(Math::IntPoint(256, 256)); CImage img(Math::IntPoint(256, 256));
@ -1069,7 +1072,7 @@ void CMap::UpdateTerrain(int bx, int by, int ex, int ey)
float scale, water, level, intensity; float scale, water, level, intensity;
int x, y; int x, y;
if ( m_fixImage[0] != 0 ) return; // still image? if (! m_fixImage.empty()) return; // still image?
// TODO: map texture manipulation // TODO: map texture manipulation
return; return;
@ -1129,13 +1132,11 @@ void CMap::UpdateTerrain(int bx, int by, int ex, int ey)
void CMap::FlushObject() void CMap::FlushObject()
{ {
int i;
m_totalFix = 0; // object index fixed m_totalFix = 0; // object index fixed
m_totalMove = MAPMAXOBJECT-2; // moving vehicles index m_totalMove = MAPMAXOBJECT-2; // moving vehicles index
m_bRadar = m_main->GetRadar(); m_bRadar = m_main->GetRadar();
for ( i=0 ; i<MAPMAXOBJECT ; i++ ) for (int i = 0; i < MAPMAXOBJECT; i++)
{ {
m_map[i].bUsed = false; m_map[i].bUsed = false;
} }
@ -1269,7 +1270,7 @@ void CMap::UpdateObject(CObject* pObj)
if ( color == MAPCOLOR_NULL ) return; if ( color == MAPCOLOR_NULL ) return;
if ( m_fixImage[0] != 0 && !m_bDebug ) // map with still image? if (!m_fixImage.empty() && !m_bDebug) // map with still image?
{ {
if ( color != MAPCOLOR_MOVE ) return; if ( color != MAPCOLOR_MOVE ) return;
} }

View File

@ -58,12 +58,12 @@ enum MapColor
struct MapObject struct MapObject
{ {
char bUsed; bool bUsed = false;
CObject* object; CObject* object = nullptr;
MapColor color; MapColor color = MAPCOLOR_NULL;
ObjectType type; ObjectType type = OBJECT_NULL;
Math::Point pos; Math::Point pos;
float dir; float dir = 0.0f;
}; };
@ -81,7 +81,7 @@ public:
void UpdateTerrain(); void UpdateTerrain();
void UpdateTerrain(int bx, int by, int ex, int ey); void UpdateTerrain(int bx, int by, int ex, int ey);
void SetFixImage(const char *filename); void SetFixImage(const std::string& filename);
bool GetFixImage(); bool GetFixImage();
void SetOffset(float ox, float oy); void SetOffset(float ox, float oy);
@ -137,7 +137,7 @@ protected:
Math::Point m_mapPos; Math::Point m_mapPos;
Math::Point m_mapDim; Math::Point m_mapDim;
bool m_bRadar; bool m_bRadar;
char m_fixImage[100]; std::string m_fixImage;
int m_mode; int m_mode;
bool m_bToy; bool m_bToy;
bool m_bDebug; bool m_bDebug;

View File

@ -21,6 +21,7 @@
#include "ui/controls/scroll.h" #include "ui/controls/scroll.h"
#include "common/event.h" #include "common/event.h"
#include "common/make_unique.h"
#include "common/misc.h" #include "common/misc.h"
#include "graphics/engine/engine.h" #include "graphics/engine/engine.h"
@ -36,25 +37,18 @@ namespace Ui
CScroll::CScroll() : CControl() CScroll::CScroll() : CControl()
{ {
m_buttonUp = 0;
m_buttonDown = 0;
m_visibleValue = 0.0f; m_visibleValue = 0.0f;
m_visibleRatio = 1.0f; m_visibleRatio = 1.0f;
m_step = 0.0f; m_step = 0.0f;
m_eventUp = EVENT_NULL;
m_eventDown = EVENT_NULL;
m_bCapture = false; m_bCapture = false;
m_pressValue = 0.0f;
} }
// Object's destructor. // Object's destructor.
CScroll::~CScroll() CScroll::~CScroll()
{ {
delete m_buttonUp;
delete m_buttonDown;
} }
@ -86,39 +80,31 @@ void CScroll::SetDim(Math::Point dim)
void CScroll::MoveAdjust() void CScroll::MoveAdjust()
{ {
CButton* pc;
Math::Point pos, dim; Math::Point pos, dim;
if ( m_dim.y < m_dim.x*2.0f ) // very short lift? if ( m_dim.y < m_dim.x*2.0f ) // very short lift?
{ {
delete m_buttonUp; m_buttonUp.reset();
m_buttonUp = 0; m_buttonDown.reset();
delete m_buttonDown;
m_buttonDown = 0;
} }
else else
{ {
if ( m_buttonUp == 0 ) if (m_buttonUp == nullptr)
{ {
m_buttonUp = new CButton(); m_buttonUp = MakeUnique<CButton>();
pc = m_buttonUp; m_buttonUp->Create(Math::Point(0.0f, 0.0f), Math::Point(0.0f, 0.0f), 49, EVENT_NULL);
pc->Create(Math::Point(0.0f, 0.0f), Math::Point(0.0f, 0.0f), 49, EVENT_NULL); m_buttonUp->SetRepeat(true);
pc->SetRepeat(true);
m_eventUp = pc->GetEventType();
} }
if ( m_buttonDown == 0 ) if (m_buttonDown == nullptr)
{ {
m_buttonDown = new CButton(); m_buttonDown = MakeUnique<CButton>();
pc = m_buttonDown; m_buttonDown->Create(Math::Point(0.0f, 0.0f), Math::Point(0.0f, 0.0f), 50, EVENT_NULL);
pc->Create(Math::Point(0.0f, 0.0f), Math::Point(0.0f, 0.0f), 50, EVENT_NULL); m_buttonDown->SetRepeat(true);
pc->SetRepeat(true);
m_eventDown = pc->GetEventType();
} }
} }
if ( m_buttonUp != 0 ) if (m_buttonUp != nullptr)
{ {
pos.x = m_pos.x; pos.x = m_pos.x;
pos.y = m_pos.y+m_dim.y-m_dim.x/0.75f; pos.y = m_pos.y+m_dim.y-m_dim.x/0.75f;
@ -128,7 +114,7 @@ void CScroll::MoveAdjust()
m_buttonUp->SetDim(dim); m_buttonUp->SetDim(dim);
} }
if ( m_buttonDown != 0 ) if (m_buttonDown != nullptr)
{ {
pos.x = m_pos.x; pos.x = m_pos.x;
pos.y = m_pos.y; pos.y = m_pos.y;
@ -198,21 +184,18 @@ bool CScroll::ClearState(int state)
bool CScroll::EventProcess(const Event &event) bool CScroll::EventProcess(const Event &event)
{ {
Math::Point pos, dim;
float hButton, h, value;
CControl::EventProcess(event); CControl::EventProcess(event);
if ( m_buttonUp != 0 && !m_bCapture ) if (m_buttonUp != nullptr && !m_bCapture)
{ {
if ( !m_buttonUp->EventProcess(event) ) return false; if ( !m_buttonUp->EventProcess(event) ) return false;
} }
if ( m_buttonDown != 0 && !m_bCapture ) if (m_buttonDown != nullptr && !m_bCapture)
{ {
if ( !m_buttonDown->EventProcess(event) ) return false; if ( !m_buttonDown->EventProcess(event) ) return false;
} }
if ( event.type == m_eventUp && m_step > 0.0f ) if (m_buttonUp != nullptr && event.type == m_buttonUp->GetEventType() && m_step > 0.0f )
{ {
m_visibleValue -= m_step; m_visibleValue -= m_step;
if ( m_visibleValue < 0.0f ) m_visibleValue = 0.0f; if ( m_visibleValue < 0.0f ) m_visibleValue = 0.0f;
@ -221,7 +204,7 @@ bool CScroll::EventProcess(const Event &event)
m_event->AddEvent(Event(m_eventType)); m_event->AddEvent(Event(m_eventType));
} }
if ( event.type == m_eventDown && m_step > 0.0f ) if (m_buttonDown != nullptr && event.type == m_buttonDown->GetEventType() && m_step > 0.0f )
{ {
m_visibleValue += m_step; m_visibleValue += m_step;
if ( m_visibleValue > 1.0f ) m_visibleValue = 1.0f; if ( m_visibleValue > 1.0f ) m_visibleValue = 1.0f;
@ -230,7 +213,7 @@ bool CScroll::EventProcess(const Event &event)
m_event->AddEvent(Event(m_eventType)); m_event->AddEvent(Event(m_eventType));
} }
hButton = m_buttonUp?m_dim.x/0.75f:0.0f; float hButton = (m_buttonUp != nullptr) ? (m_dim.x/0.75f) : 0.0f;
if (event.type == EVENT_MOUSE_BUTTON_DOWN && if (event.type == EVENT_MOUSE_BUTTON_DOWN &&
event.GetData<MouseButtonEventData>()->button == MOUSE_BUTTON_LEFT && event.GetData<MouseButtonEventData>()->button == MOUSE_BUTTON_LEFT &&
@ -239,6 +222,8 @@ bool CScroll::EventProcess(const Event &event)
{ {
if ( CControl::Detect(event.mousePos) ) if ( CControl::Detect(event.mousePos) )
{ {
Math::Point pos, dim;
pos.y = m_pos.y+hButton; pos.y = m_pos.y+hButton;
dim.y = m_dim.y-hButton*2.0f; dim.y = m_dim.y-hButton*2.0f;
pos.y += dim.y*(1.0f-m_visibleRatio)*(1.0f-m_visibleValue); pos.y += dim.y*(1.0f-m_visibleRatio)*(1.0f-m_visibleValue);
@ -246,8 +231,8 @@ bool CScroll::EventProcess(const Event &event)
if ( event.mousePos.y < pos.y || if ( event.mousePos.y < pos.y ||
event.mousePos.y > pos.y+dim.y ) // click outside cabin? event.mousePos.y > pos.y+dim.y ) // click outside cabin?
{ {
h = (m_dim.y-hButton*2.0f)*(1.0f-m_visibleRatio); float h = (m_dim.y-hButton*2.0f)*(1.0f-m_visibleRatio);
value = 1.0f-(event.mousePos.y-(m_pos.y+hButton+dim.y*0.5f))/h; float value = 1.0f-(event.mousePos.y-(m_pos.y+hButton+dim.y*0.5f))/h;
if ( value < 0.0f ) value = 0.0f; if ( value < 0.0f ) value = 0.0f;
if ( value > 1.0f ) value = 1.0f; if ( value > 1.0f ) value = 1.0f;
m_visibleValue = value; m_visibleValue = value;
@ -263,10 +248,10 @@ bool CScroll::EventProcess(const Event &event)
if ( event.type == EVENT_MOUSE_MOVE && m_bCapture ) if ( event.type == EVENT_MOUSE_MOVE && m_bCapture )
{ {
h = (m_dim.y-hButton*2.0f)*(1.0f-m_visibleRatio); float h = (m_dim.y-hButton*2.0f)*(1.0f-m_visibleRatio);
if ( h != 0 ) if ( h != 0 )
{ {
value = m_pressValue - (event.mousePos.y-m_pressPos.y)/h; float value = m_pressValue - (event.mousePos.y-m_pressPos.y)/h;
if ( value < 0.0f ) value = 0.0f; if ( value < 0.0f ) value = 0.0f;
if ( value > 1.0f ) value = 1.0f; if ( value > 1.0f ) value = 1.0f;
@ -351,11 +336,11 @@ void CScroll::Draw()
} }
} }
if ( m_buttonUp != 0 ) if (m_buttonUp != nullptr)
{ {
m_buttonUp->Draw(); m_buttonUp->Draw();
} }
if ( m_buttonDown != 0 ) if (m_buttonDown != nullptr)
{ {
m_buttonDown->Draw(); m_buttonDown->Draw();
} }
@ -457,5 +442,5 @@ float CScroll::GetArrowStep()
return m_step; return m_step;
} }
} } // namespace Ui

View File

@ -26,6 +26,8 @@
#include "ui/controls/control.h" #include "ui/controls/control.h"
#include <memory>
namespace Ui namespace Ui
{ {
@ -68,8 +70,8 @@ protected:
void DrawVertex(Math::Point pos, Math::Point dim, int icon); void DrawVertex(Math::Point pos, Math::Point dim, int icon);
protected: protected:
CButton* m_buttonUp; std::unique_ptr<CButton> m_buttonUp;
CButton* m_buttonDown; std::unique_ptr<CButton> m_buttonDown;
float m_visibleValue; float m_visibleValue;
float m_visibleRatio; float m_visibleRatio;
@ -78,11 +80,8 @@ protected:
bool m_bCapture; bool m_bCapture;
Math::Point m_pressPos; Math::Point m_pressPos;
float m_pressValue; float m_pressValue;
EventType m_eventUp;
EventType m_eventDown;
}; };
} } // namespace Ui

View File

@ -45,9 +45,6 @@ const float HOLE_WIDTH = (5.0f/480.0f);
CSlider::CSlider() : CControl() CSlider::CSlider() : CControl()
{ {
m_buttonLeft = 0;
m_buttonRight = 0;
m_min = 0.0f; m_min = 0.0f;
m_max = 1.0f; m_max = 1.0f;
m_visibleValue = 0.0f; m_visibleValue = 0.0f;
@ -56,18 +53,14 @@ CSlider::CSlider() : CControl()
m_marginButton = 0.0f; m_marginButton = 0.0f;
m_bHoriz = false; m_bHoriz = false;
m_eventUp = EVENT_NULL;
m_eventDown = EVENT_NULL;
m_bCapture = false; m_bCapture = false;
m_pressValue = 0.0f;
} }
// Object's destructor. // Object's destructor.
CSlider::~CSlider() CSlider::~CSlider()
{ {
delete m_buttonLeft;
delete m_buttonRight;
} }
@ -104,40 +97,32 @@ void CSlider::MoveAdjust()
if ( ( m_bHoriz && m_dim.x < m_dim.y*4.0f) || if ( ( m_bHoriz && m_dim.x < m_dim.y*4.0f) ||
(!m_bHoriz && m_dim.y < m_dim.x*4.0f) ) // very short slider? (!m_bHoriz && m_dim.y < m_dim.x*4.0f) ) // very short slider?
{ {
delete m_buttonLeft; m_buttonLeft.reset();
m_buttonLeft = 0; m_buttonRight.reset();
delete m_buttonRight;
m_buttonRight = 0;
m_marginButton = 0.0f; m_marginButton = 0.0f;
} }
else else
{ {
#if 1 if (m_buttonLeft == nullptr)
if ( m_buttonLeft == 0 )
{ {
m_buttonLeft = new CButton(); m_buttonLeft = MakeUnique<CButton>();
m_buttonLeft->Create(Math::Point(0.0f, 0.0f), Math::Point(0.0f, 0.0f), m_bHoriz?55:49, EVENT_NULL); // </^ m_buttonLeft->Create(Math::Point(0.0f, 0.0f), Math::Point(0.0f, 0.0f), m_bHoriz?55:49, EVENT_NULL); // </^
m_buttonLeft->SetRepeat(true); m_buttonLeft->SetRepeat(true);
if ( m_state & STATE_SHADOW ) m_buttonLeft->SetState(STATE_SHADOW); if ( m_state & STATE_SHADOW ) m_buttonLeft->SetState(STATE_SHADOW);
m_eventUp = m_buttonLeft->GetEventType();
} }
if ( m_buttonRight == 0 ) if (m_buttonRight == nullptr)
{ {
m_buttonRight = new CButton(); m_buttonRight = MakeUnique<CButton>();
m_buttonRight->Create(Math::Point(0.0f, 0.0f), Math::Point(0.0f, 0.0f), m_bHoriz?48:50, EVENT_NULL); // >/v m_buttonRight->Create(Math::Point(0.0f, 0.0f), Math::Point(0.0f, 0.0f), m_bHoriz?48:50, EVENT_NULL); // >/v
m_buttonRight->SetRepeat(true); m_buttonRight->SetRepeat(true);
if ( m_state & STATE_SHADOW ) m_buttonRight->SetState(STATE_SHADOW); if ( m_state & STATE_SHADOW ) m_buttonRight->SetState(STATE_SHADOW);
m_eventDown = m_buttonRight->GetEventType();
} }
m_marginButton = m_bHoriz?(m_dim.y*0.75f):(m_dim.x/0.75f); m_marginButton = m_bHoriz?(m_dim.y*0.75f):(m_dim.x/0.75f);
#endif
} }
if ( m_buttonLeft != 0 ) if (m_buttonLeft != nullptr)
{ {
if ( m_bHoriz ) if ( m_bHoriz )
{ {
@ -157,7 +142,7 @@ void CSlider::MoveAdjust()
m_buttonLeft->SetDim(dim); m_buttonLeft->SetDim(dim);
} }
if ( m_buttonRight != 0 ) if (m_buttonRight != nullptr)
{ {
if ( m_bHoriz ) if ( m_bHoriz )
{ {
@ -211,8 +196,8 @@ bool CSlider::SetState(int state, bool bState)
if ( (state & STATE_ENABLE) || if ( (state & STATE_ENABLE) ||
(state & STATE_SHADOW) ) (state & STATE_SHADOW) )
{ {
if ( m_buttonLeft != 0 ) m_buttonLeft->SetState(state, bState); if (m_buttonLeft != nullptr) m_buttonLeft->SetState(state, bState);
if ( m_buttonRight != 0 ) m_buttonRight->SetState(state, bState); if (m_buttonRight != nullptr) m_buttonRight->SetState(state, bState);
} }
return CControl::SetState(state, bState); return CControl::SetState(state, bState);
@ -223,8 +208,8 @@ bool CSlider::SetState(int state)
if ( (state & STATE_ENABLE) || if ( (state & STATE_ENABLE) ||
(state & STATE_SHADOW) ) (state & STATE_SHADOW) )
{ {
if ( m_buttonLeft != 0 ) m_buttonLeft->SetState(state); if (m_buttonLeft != nullptr) m_buttonLeft->SetState(state);
if ( m_buttonRight != 0 ) m_buttonRight->SetState(state); if (m_buttonRight != nullptr) m_buttonRight->SetState(state);
} }
return CControl::SetState(state); return CControl::SetState(state);
@ -235,8 +220,8 @@ bool CSlider::ClearState(int state)
if ( (state & STATE_ENABLE) || if ( (state & STATE_ENABLE) ||
(state & STATE_SHADOW) ) (state & STATE_SHADOW) )
{ {
if ( m_buttonLeft != 0 ) m_buttonLeft->ClearState(state); if (m_buttonLeft != nullptr) m_buttonLeft->ClearState(state);
if ( m_buttonRight != 0 ) m_buttonRight->ClearState(state); if (m_buttonRight != nullptr) m_buttonRight->ClearState(state);
} }
return CControl::ClearState(state); return CControl::ClearState(state);
@ -254,16 +239,16 @@ bool CSlider::EventProcess(const Event &event)
CControl::EventProcess(event); CControl::EventProcess(event);
if ( m_buttonLeft != 0 && !m_bCapture ) if (m_buttonLeft != nullptr && !m_bCapture)
{ {
if ( !m_buttonLeft->EventProcess(event) ) return false; if ( !m_buttonLeft->EventProcess(event) ) return false;
} }
if ( m_buttonRight != 0 && !m_bCapture ) if (m_buttonRight != nullptr && !m_bCapture)
{ {
if ( !m_buttonRight->EventProcess(event) ) return false; if ( !m_buttonRight->EventProcess(event) ) return false;
} }
if ( event.type == m_eventUp && m_step > 0.0f ) if (m_buttonLeft != nullptr && event.type == m_buttonLeft->GetEventType() && m_step > 0.0f )
{ {
m_visibleValue -= m_bHoriz?m_step:-m_step; m_visibleValue -= m_bHoriz?m_step:-m_step;
if ( m_visibleValue < 0.0f ) m_visibleValue = 0.0f; if ( m_visibleValue < 0.0f ) m_visibleValue = 0.0f;
@ -273,7 +258,7 @@ bool CSlider::EventProcess(const Event &event)
m_event->AddEvent(Event(m_eventType)); m_event->AddEvent(Event(m_eventType));
} }
if ( event.type == m_eventDown && m_step > 0.0f ) if (m_buttonRight != nullptr && event.type == m_buttonRight->GetEventType() && m_step > 0.0f )
{ {
m_visibleValue += m_bHoriz?m_step:-m_step; m_visibleValue += m_bHoriz?m_step:-m_step;
if ( m_visibleValue < 0.0f ) m_visibleValue = 0.0f; if ( m_visibleValue < 0.0f ) m_visibleValue = 0.0f;
@ -382,7 +367,7 @@ void CSlider::Draw()
if ( (m_state & STATE_VISIBLE) == 0 ) return; if ( (m_state & STATE_VISIBLE) == 0 ) return;
if ( m_buttonLeft != 0 ) if (m_buttonLeft != nullptr)
{ {
m_buttonLeft->Draw(); m_buttonLeft->Draw();
} }
@ -451,7 +436,7 @@ void CSlider::Draw()
DrawVertex(ppos, ddim, 2); DrawVertex(ppos, ddim, 2);
} }
if ( m_buttonRight != 0 ) if (m_buttonRight != nullptr)
{ {
m_buttonRight->Draw(); m_buttonRight->Draw();
} }

View File

@ -23,6 +23,8 @@
#include "ui/controls/control.h" #include "ui/controls/control.h"
#include <memory>
namespace Ui namespace Ui
{ {
@ -61,8 +63,8 @@ protected:
virtual std::string GetLabel(); virtual std::string GetLabel();
protected: protected:
CButton* m_buttonLeft; std::unique_ptr<CButton> m_buttonLeft;
CButton* m_buttonRight; std::unique_ptr<CButton> m_buttonRight;
float m_min; float m_min;
float m_max; float m_max;
@ -75,9 +77,6 @@ protected:
bool m_bCapture; bool m_bCapture;
Math::Point m_pressPos; Math::Point m_pressPos;
float m_pressValue; float m_pressValue;
EventType m_eventUp;
EventType m_eventDown;
}; };

View File

@ -20,6 +20,7 @@
#include "ui/controls/window.h" #include "ui/controls/window.h"
#include <algorithm>
namespace Ui namespace Ui
@ -28,13 +29,6 @@ namespace Ui
CWindow::CWindow() : CControl() CWindow::CWindow() : CControl()
{ {
int i;
for ( i=0 ; i<MAXWINDOW ; i++ )
{
m_table[i] = 0;
}
m_bTrashEvent = true; m_bTrashEvent = true;
m_bMaximized = false; m_bMaximized = false;
m_bMinimized = false; m_bMinimized = false;
@ -43,14 +37,12 @@ CWindow::CWindow() : CControl()
m_minDim = Math::Point(0.0f, 0.0f); m_minDim = Math::Point(0.0f, 0.0f);
m_maxDim = Math::Point(1.0f, 1.0f); m_maxDim = Math::Point(1.0f, 1.0f);
m_buttonReduce = 0;
m_buttonFull = 0;
m_buttonClose = 0;
m_bMovable = false; m_bMovable = false;
m_bRedim = false; m_bRedim = false;
m_bClosable = false; m_bClosable = false;
m_bCapture = false; m_bCapture = false;
m_pressFlags = 0;
m_pressMouse = Gfx::ENG_MOUSE_NORM;
// m_fontStretch = NORMSTRETCH*1.2f; // m_fontStretch = NORMSTRETCH*1.2f;
} }
@ -59,7 +51,6 @@ CWindow::CWindow() : CControl()
CWindow::~CWindow() CWindow::~CWindow()
{ {
Flush();
} }
@ -67,20 +58,11 @@ CWindow::~CWindow()
void CWindow::Flush() void CWindow::Flush()
{ {
for (int i = 0 ; i < MAXWINDOW; i++) m_controls.clear();
{
delete m_table[i];
m_table[i] = nullptr;
}
delete m_buttonReduce; m_buttonReduce.reset();
m_buttonReduce = nullptr; m_buttonFull.reset();
m_buttonClose.reset();
delete m_buttonFull;
m_buttonFull = nullptr;
delete m_buttonClose;
m_buttonClose = nullptr;
} }
@ -94,273 +76,114 @@ bool CWindow::Create(Math::Point pos, Math::Point dim, int icon, EventType event
return true; return true;
} }
template<typename ControlClass>
ControlClass* CWindow::CreateControl(Math::Point pos, Math::Point dim, int icon, EventType eventMsg)
{
auto control = MakeUnique<ControlClass>();
control->Create(pos, dim, icon, eventMsg);
auto* controlPtr = control.get();
m_controls.push_back(std::move(control));
return controlPtr;
}
// Creates a new button. // Creates a new button.
CButton* CWindow::CreateButton(Math::Point pos, Math::Point dim, int icon, EventType eventMsg) CButton* CWindow::CreateButton(Math::Point pos, Math::Point dim, int icon, EventType eventMsg)
{ {
CButton* pc; return CreateControl<CButton>(pos, dim, icon, eventMsg);
int i;
if ( eventMsg == EVENT_NULL ) eventMsg = GetUniqueEventType();
for ( i=0 ; i<MAXWINDOW ; i++ )
{
if ( m_table[i] == 0 )
{
m_table[i] = new CButton();
pc = static_cast<CButton*>(m_table[i]);
pc->Create(pos, dim, icon, eventMsg);
return pc;
}
}
return 0;
} }
// Creates a new button. // Creates a new button.
CColor* CWindow::CreateColor(Math::Point pos, Math::Point dim, int icon, EventType eventMsg) CColor* CWindow::CreateColor(Math::Point pos, Math::Point dim, int icon, EventType eventMsg)
{ {
CColor* pc; return CreateControl<CColor>(pos, dim, icon, eventMsg);
int i;
if ( eventMsg == EVENT_NULL ) eventMsg = GetUniqueEventType();
for ( i=0 ; i<MAXWINDOW ; i++ )
{
if ( m_table[i] == 0 )
{
m_table[i] = new CColor();
pc = static_cast<CColor*>(m_table[i]);
pc->Create(pos, dim, icon, eventMsg);
return pc;
}
}
return 0;
} }
// Creates a new button. // Creates a new button.
CCheck* CWindow::CreateCheck(Math::Point pos, Math::Point dim, int icon, EventType eventMsg) CCheck* CWindow::CreateCheck(Math::Point pos, Math::Point dim, int icon, EventType eventMsg)
{ {
CCheck* pc; return CreateControl<CCheck>(pos, dim, icon, eventMsg);
int i;
if ( eventMsg == EVENT_NULL ) eventMsg = GetUniqueEventType();
for ( i=0 ; i<MAXWINDOW ; i++ )
{
if ( m_table[i] == 0 )
{
m_table[i] = new CCheck();
pc = static_cast<CCheck*>(m_table[i]);
pc->Create(pos, dim, icon, eventMsg);
return pc;
}
}
return 0;
} }
// Creates a new button. // Creates a new button.
CKey* CWindow::CreateKey(Math::Point pos, Math::Point dim, int icon, EventType eventMsg) CKey* CWindow::CreateKey(Math::Point pos, Math::Point dim, int icon, EventType eventMsg)
{ {
CKey* pc; return CreateControl<CKey>(pos, dim, icon, eventMsg);
int i;
if ( eventMsg == EVENT_NULL ) eventMsg = GetUniqueEventType();
for ( i=0 ; i<MAXWINDOW ; i++ )
{
if ( m_table[i] == 0 )
{
m_table[i] = new CKey();
pc = static_cast<CKey*>(m_table[i]);
pc->Create(pos, dim, icon, eventMsg);
return pc;
}
}
return 0;
} }
// Creates a new button. // Creates a new button.
CGroup* CWindow::CreateGroup(Math::Point pos, Math::Point dim, int icon, EventType eventMsg) CGroup* CWindow::CreateGroup(Math::Point pos, Math::Point dim, int icon, EventType eventMsg)
{ {
CGroup* pc; return CreateControl<CGroup>(pos, dim, icon, eventMsg);
int i;
if ( eventMsg == EVENT_NULL ) eventMsg = GetUniqueEventType();
for ( i=0 ; i<MAXWINDOW ; i++ )
{
if ( m_table[i] == 0 )
{
m_table[i] = new CGroup();
pc = static_cast<CGroup*>(m_table[i]);
pc->Create(pos, dim, icon, eventMsg);
return pc;
}
}
return 0;
} }
// Creates a new button. // Creates a new button.
CImage* CWindow::CreateImage(Math::Point pos, Math::Point dim, int icon, EventType eventMsg) CImage* CWindow::CreateImage(Math::Point pos, Math::Point dim, int icon, EventType eventMsg)
{ {
CImage* pc; return CreateControl<CImage>(pos, dim, icon, eventMsg);
int i;
if ( eventMsg == EVENT_NULL ) eventMsg = GetUniqueEventType();
for ( i=0 ; i<MAXWINDOW ; i++ )
{
if ( m_table[i] == 0 )
{
m_table[i] = new CImage();
pc = static_cast<CImage*>(m_table[i]);
pc->Create(pos, dim, icon, eventMsg);
return pc;
}
}
return 0;
} }
// Creates a new label. // Creates a new label.
CLabel* CWindow::CreateLabel(Math::Point pos, Math::Point dim, int icon, EventType eventMsg, std::string name) CLabel* CWindow::CreateLabel(Math::Point pos, Math::Point dim, int icon, EventType eventMsg, std::string name)
{ {
CLabel* pc; CLabel* label = CreateControl<CLabel>(pos, dim, icon, eventMsg);
int i;
if ( eventMsg == EVENT_NULL ) eventMsg = GetUniqueEventType(); auto p = name.find("\\");
if (p == std::string::npos)
label->SetName(name);
else
label->SetName(name.substr(0, p));
for ( i=0 ; i<MAXWINDOW ; i++ ) return label;
{
if ( m_table[i] == 0 )
{
m_table[i] = new CLabel();
pc = static_cast<CLabel*>(m_table[i]);
pc->Create(pos, dim, icon, eventMsg);
auto p = name.find("\\");
if ( p == std::string::npos )
pc->SetName(name);
else
pc->SetName(name.substr(0, p));
return pc;
}
}
return 0;
} }
// Creates a new editable pave. // Creates a new editable pave.
CEdit* CWindow::CreateEdit(Math::Point pos, Math::Point dim, int icon, EventType eventMsg) CEdit* CWindow::CreateEdit(Math::Point pos, Math::Point dim, int icon, EventType eventMsg)
{ {
CEdit* pc; return CreateControl<CEdit>(pos, dim, icon, eventMsg);
int i;
if ( eventMsg == EVENT_NULL ) eventMsg = GetUniqueEventType();
for ( i=0 ; i<MAXWINDOW ; i++ )
{
if ( m_table[i] == 0 )
{
m_table[i] = new CEdit();
pc = static_cast<CEdit*>(m_table[i]);
pc->Create(pos, dim, icon, eventMsg);
return pc;
}
}
return 0;
} }
// Creates a new editable pave. // Creates a new editable pave.
CEditValue* CWindow::CreateEditValue(Math::Point pos, Math::Point dim, int icon, EventType eventMsg) CEditValue* CWindow::CreateEditValue(Math::Point pos, Math::Point dim, int icon, EventType eventMsg)
{ {
CEditValue* pc; return CreateControl<CEditValue>(pos, dim, icon, eventMsg);
int i;
if ( eventMsg == EVENT_NULL ) eventMsg = GetUniqueEventType();
for ( i=0 ; i<MAXWINDOW ; i++ )
{
if ( m_table[i] == 0 )
{
m_table[i] = new CEditValue();
pc = static_cast<CEditValue*>(m_table[i]);
pc->Create(pos, dim, icon, eventMsg);
return pc;
}
}
return 0;
} }
// Creates a new elevator. // Creates a new elevator.
CScroll* CWindow::CreateScroll(Math::Point pos, Math::Point dim, int icon, EventType eventMsg) CScroll* CWindow::CreateScroll(Math::Point pos, Math::Point dim, int icon, EventType eventMsg)
{ {
CScroll* pc; if (eventMsg == EVENT_NULL)
int i; eventMsg = GetUniqueEventType();
if ( eventMsg == EVENT_NULL ) eventMsg = GetUniqueEventType(); return CreateControl<CScroll>(pos, dim, icon, eventMsg);
for ( i=0 ; i<MAXWINDOW ; i++ )
{
if ( m_table[i] == 0 )
{
m_table[i] = new CScroll();
pc = static_cast<CScroll*>(m_table[i]);
pc->Create(pos, dim, icon, eventMsg);
return pc;
}
}
return 0;
} }
// Creates a new cursor. // Creates a new cursor.
CSlider* CWindow::CreateSlider(Math::Point pos, Math::Point dim, int icon, EventType eventMsg) CSlider* CWindow::CreateSlider(Math::Point pos, Math::Point dim, int icon, EventType eventMsg)
{ {
CSlider* pc; if (eventMsg == EVENT_NULL)
int i; eventMsg = GetUniqueEventType();
if ( eventMsg == EVENT_NULL ) eventMsg = GetUniqueEventType(); return CreateControl<CSlider>(pos, dim, icon, eventMsg);
for ( i=0 ; i<MAXWINDOW ; i++ )
{
if ( m_table[i] == 0 )
{
m_table[i] = new CSlider();
pc = static_cast<CSlider*>(m_table[i]);
pc->Create(pos, dim, icon, eventMsg);
return pc;
}
}
return 0;
} }
CEnumSlider* CWindow::CreateEnumSlider(Math::Point pos, Math::Point dim, int icon, EventType eventMsg) CEnumSlider* CWindow::CreateEnumSlider(Math::Point pos, Math::Point dim, int icon, EventType eventMsg)
{ {
CEnumSlider* pc; if (eventMsg == EVENT_NULL)
int i; eventMsg = GetUniqueEventType();
if ( eventMsg == EVENT_NULL ) eventMsg = GetUniqueEventType(); return CreateControl<CEnumSlider>(pos, dim, icon, eventMsg);
for ( i=0 ; i<MAXWINDOW ; i++ )
{
if ( m_table[i] == 0 )
{
m_table[i] = new CEnumSlider();
pc = static_cast<CEnumSlider*>(m_table[i]);
pc->Create(pos, dim, icon, eventMsg);
return pc;
}
}
return 0;
} }
// Creates a new list. // Creates a new list.
@ -368,175 +191,99 @@ CEnumSlider* CWindow::CreateEnumSlider(Math::Point pos, Math::Point dim, int ico
// and try to scale items to some size, so that dim of the list would not change after // and try to scale items to some size, so that dim of the list would not change after
// adjusting // adjusting
CList* CWindow::CreateList(Math::Point pos, Math::Point dim, int icon, EventType eventMsg, CList* CWindow::CreateList(Math::Point pos, Math::Point dim, int icon, EventType eventMsg, float expand)
float expand)
{ {
CList* pc; if (eventMsg == EVENT_NULL)
int i; eventMsg = GetUniqueEventType();
if ( eventMsg == EVENT_NULL ) eventMsg = GetUniqueEventType(); auto list = MakeUnique<CList>();
list->Create(pos, dim, icon, eventMsg, expand);
for ( i=0 ; i<MAXWINDOW ; i++ ) auto* listPtr = list.get();
{ m_controls.push_back(std::move(list));
if ( m_table[i] == 0 ) return listPtr;
{
m_table[i] = new CList();
pc = static_cast<CList*>(m_table[i]);
pc->Create(pos, dim, icon, eventMsg, expand);
return pc;
}
}
return 0;
} }
// Creates a new shortcut. // Creates a new shortcut.
CShortcut* CWindow::CreateShortcut(Math::Point pos, Math::Point dim, int icon, EventType eventMsg) CShortcut* CWindow::CreateShortcut(Math::Point pos, Math::Point dim, int icon, EventType eventMsg)
{ {
CShortcut* ps; if (eventMsg == EVENT_NULL)
int i; eventMsg = GetUniqueEventType();
if ( eventMsg == EVENT_NULL ) eventMsg = GetUniqueEventType(); return CreateControl<CShortcut>(pos, dim, icon, eventMsg);
for ( i=0 ; i<MAXWINDOW ; i++ )
{
if ( m_table[i] == 0 )
{
m_table[i] = new CShortcut();
ps = static_cast<CShortcut*>(m_table[i]);
ps->Create(pos, dim, icon, eventMsg);
return ps;
}
}
return 0;
} }
// Creates a new card. // Creates a new card.
CMap* CWindow::CreateMap(Math::Point pos, Math::Point dim, int icon, EventType eventMsg) CMap* CWindow::CreateMap(Math::Point pos, Math::Point dim, int icon, EventType eventMsg)
{ {
CMap* pm; if (eventMsg == EVENT_NULL)
int i; eventMsg = GetUniqueEventType();
if ( eventMsg == EVENT_NULL ) eventMsg = GetUniqueEventType(); return CreateControl<CMap>(pos, dim, icon, eventMsg);
for ( i=0 ; i<MAXWINDOW ; i++ )
{
if ( m_table[i] == 0 )
{
m_table[i] = new CMap();
pm = static_cast<CMap*>(m_table[i]);
pm->Create(pos, dim, icon, eventMsg);
return pm;
}
}
return 0;
} }
// Creates a new gauge. // Creates a new gauge.
CGauge* CWindow::CreateGauge(Math::Point pos, Math::Point dim, int icon, EventType eventMsg) CGauge* CWindow::CreateGauge(Math::Point pos, Math::Point dim, int icon, EventType eventMsg)
{ {
CGauge* pc; if (eventMsg == EVENT_NULL)
int i; eventMsg = GetUniqueEventType();
if ( eventMsg == EVENT_NULL ) eventMsg = GetUniqueEventType(); return CreateControl<CGauge>(pos, dim, icon, eventMsg);
for ( i=0 ; i<MAXWINDOW ; i++ )
{
if ( m_table[i] == 0 )
{
m_table[i] = new CGauge();
pc = static_cast<CGauge*>(m_table[i]);
pc->Create(pos, dim, icon, eventMsg);
return pc;
}
}
return 0;
} }
// Creates a new compass. // Creates a new compass.
CCompass* CWindow::CreateCompass(Math::Point pos, Math::Point dim, int icon, EventType eventMsg) CCompass* CWindow::CreateCompass(Math::Point pos, Math::Point dim, int icon, EventType eventMsg)
{ {
CCompass* pc; if (eventMsg == EVENT_NULL)
int i; eventMsg = GetUniqueEventType();
if ( eventMsg == EVENT_NULL ) eventMsg = GetUniqueEventType(); return CreateControl<CCompass>(pos, dim, icon, eventMsg);
for ( i=0 ; i<MAXWINDOW ; i++ )
{
if ( m_table[i] == 0 )
{
m_table[i] = new CCompass();
pc = static_cast<CCompass*>(m_table[i]);
pc->Create(pos, dim, icon, eventMsg);
return pc;
}
}
return 0;
} }
// Creates a new target. // Creates a new target.
CTarget* CWindow::CreateTarget(Math::Point pos, Math::Point dim, int icon, EventType eventMsg) CTarget* CWindow::CreateTarget(Math::Point pos, Math::Point dim, int icon, EventType eventMsg)
{ {
CTarget* pc; if (eventMsg == EVENT_NULL)
int i; eventMsg = GetUniqueEventType();
if ( eventMsg == EVENT_NULL ) eventMsg = GetUniqueEventType(); return CreateControl<CTarget>(pos, dim, icon, eventMsg);
for ( i=0 ; i<MAXWINDOW ; i++ )
{
if ( m_table[i] == 0 )
{
m_table[i] = new CTarget();
pc = static_cast<CTarget*>(m_table[i]);
pc->Create(pos, dim, icon, eventMsg);
return pc;
}
}
return 0;
} }
// Removes a control. // Removes a control.
bool CWindow::DeleteControl(EventType eventMsg) bool CWindow::DeleteControl(EventType eventMsg)
{ {
int i; auto controlIt = std::find_if(m_controls.begin(), m_controls.end(),
[eventMsg](const std::unique_ptr<CControl>& control)
{
return control->GetEventType() == eventMsg;
});
for ( i=0 ; i<MAXWINDOW ; i++ ) if (controlIt == m_controls.end())
{ return false;
if ( m_table[i] != 0 )
{ m_controls.erase(controlIt);
if ( eventMsg == m_table[i]->GetEventType() ) return true;
{
delete m_table[i];
m_table[i] = 0;
return true;
}
}
}
return false;
} }
// Gives a control. // Gives a control.
CControl* CWindow::SearchControl(EventType eventMsg) CControl* CWindow::SearchControl(EventType eventMsg)
{ {
int i; auto controlIt = std::find_if(m_controls.begin(), m_controls.end(),
[eventMsg](const std::unique_ptr<CControl>& control)
{
return control->GetEventType() == eventMsg;
});
for ( i=0 ; i<MAXWINDOW ; i++ ) if (controlIt == m_controls.end())
{ return nullptr;
if ( m_table[i] != 0 )
{ return controlIt->get();
if ( eventMsg == m_table[i]->GetEventType() )
{
return m_table[i];
}
}
}
return 0;
} }
@ -544,31 +291,24 @@ CControl* CWindow::SearchControl(EventType eventMsg)
bool CWindow::GetTooltip(Math::Point pos, std::string &name) bool CWindow::GetTooltip(Math::Point pos, std::string &name)
{ {
int i; for (auto& control : m_controls)
for ( i=MAXWINDOW-1 ; i>=0 ; i-- )
{ {
if ( m_table[i] != 0 ) if (control->GetTooltip(pos, name))
{ return true;
if ( m_table[i]->GetTooltip(pos, name) )
{
return true;
}
}
} }
if ( m_buttonClose != 0 && if (m_buttonClose != nullptr &&
m_buttonClose->GetTooltip(pos, name) ) m_buttonClose->GetTooltip(pos, name))
{ {
return true; return true;
} }
if ( m_buttonFull != 0 && if (m_buttonFull != nullptr &&
m_buttonFull->GetTooltip(pos, name) ) m_buttonFull->GetTooltip(pos, name))
{ {
return true; return true;
} }
if ( m_buttonReduce != 0 && if (m_buttonReduce != nullptr &&
m_buttonReduce->GetTooltip(pos, name) ) m_buttonReduce->GetTooltip(pos, name))
{ {
return true; return true;
} }
@ -587,40 +327,29 @@ bool CWindow::GetTooltip(Math::Point pos, std::string &name)
void CWindow::SetName(std::string name, bool tooltip) void CWindow::SetName(std::string name, bool tooltip)
{ {
CButton* pc;
bool bAdjust;
CControl::SetName(name, tooltip); CControl::SetName(name, tooltip);
delete m_buttonReduce; m_buttonReduce.reset();
m_buttonReduce = nullptr; m_buttonFull.reset();
m_buttonClose.reset();
delete m_buttonFull; bool bAdjust = false;
m_buttonFull = nullptr;
delete m_buttonClose;
m_buttonClose = nullptr;
bAdjust = false;
if ( m_name.length() > 0 && m_bRedim ) // title bar exists? if ( m_name.length() > 0 && m_bRedim ) // title bar exists?
{ {
m_buttonReduce = new CButton(); m_buttonReduce = MakeUnique<CButton>();
pc = m_buttonReduce; m_buttonReduce->Create(m_pos, m_dim, 0, EVENT_NULL);
pc->Create(m_pos, m_dim, 0, EVENT_NULL);
m_buttonFull = new CButton(); m_buttonFull = MakeUnique<CButton>();
pc = m_buttonFull; m_buttonFull->Create(m_pos, m_dim, 0, EVENT_NULL);
pc->Create(m_pos, m_dim, 0, EVENT_NULL);
bAdjust = true; bAdjust = true;
} }
if ( m_name.length() > 0 && m_bClosable ) // title bar exists? if ( m_name.length() > 0 && m_bClosable ) // title bar exists?
{ {
m_buttonClose = new CButton(); m_buttonClose = MakeUnique<CButton>();
pc = m_buttonClose; m_buttonClose->Create(m_pos, m_dim, 0, EVENT_NULL);
pc->Create(m_pos, m_dim, 0, EVENT_NULL);
bAdjust = true; bAdjust = true;
} }
@ -653,15 +382,15 @@ void CWindow::SetDim(Math::Point dim)
void CWindow::MoveAdjust() void CWindow::MoveAdjust()
{ {
Math::Point pos, dim; float h = m_engine->GetText()->GetHeight(m_fontType, m_fontSize);
float h, offset; Math::Point dim;
h = m_engine->GetText()->GetHeight(m_fontType, m_fontSize);
dim.y = h*1.2f; dim.y = h*1.2f;
dim.x = dim.y*0.75f; dim.x = dim.y*0.75f;
if ( m_buttonClose != 0 ) float offset = 0.0f;
if (m_buttonClose != nullptr)
{ {
Math::Point pos;
pos.x = m_pos.x+m_dim.x-0.01f-dim.x; pos.x = m_pos.x+m_dim.x-0.01f-dim.x;
pos.y = m_pos.y+m_dim.y-0.01f-h*1.2f; pos.y = m_pos.y+m_dim.y-0.01f-h*1.2f;
m_buttonClose->SetPos(pos); m_buttonClose->SetPos(pos);
@ -673,16 +402,18 @@ void CWindow::MoveAdjust()
offset = 0.0f; offset = 0.0f;
} }
if ( m_buttonFull != 0 ) if (m_buttonFull != nullptr)
{ {
Math::Point pos;
pos.x = m_pos.x+m_dim.x-0.01f-dim.x-offset; pos.x = m_pos.x+m_dim.x-0.01f-dim.x-offset;
pos.y = m_pos.y+m_dim.y-0.01f-h*1.2f; pos.y = m_pos.y+m_dim.y-0.01f-h*1.2f;
m_buttonFull->SetPos(pos); m_buttonFull->SetPos(pos);
m_buttonFull->SetDim(dim); m_buttonFull->SetDim(dim);
} }
if ( m_buttonReduce != 0 ) if (m_buttonReduce != nullptr)
{ {
Math::Point pos;
pos.x = m_pos.x+m_dim.x-0.01f-dim.x*2.0f-offset; pos.x = m_pos.x+m_dim.x-0.01f-dim.x*2.0f-offset;
pos.y = m_pos.y+m_dim.y-0.01f-h*1.2f; pos.y = m_pos.y+m_dim.y-0.01f-h*1.2f;
m_buttonReduce->SetPos(pos); m_buttonReduce->SetPos(pos);
@ -790,7 +521,7 @@ void CWindow::AdjustButtons()
{ {
std::string res; std::string res;
if ( m_buttonFull != 0 ) if (m_buttonFull != nullptr)
{ {
if ( m_bMaximized ) if ( m_bMaximized )
{ {
@ -806,7 +537,7 @@ void CWindow::AdjustButtons()
} }
} }
if ( m_buttonReduce != 0 ) if (m_buttonReduce != nullptr)
{ {
if ( m_bMinimized ) if ( m_bMinimized )
{ {
@ -822,7 +553,7 @@ void CWindow::AdjustButtons()
} }
} }
if ( m_buttonClose != 0 ) if (m_buttonClose != nullptr)
{ {
m_buttonClose->SetIcon(11); // x m_buttonClose->SetIcon(11); // x
GetResource(RES_TEXT, RT_WINDOW_CLOSE, res); GetResource(RES_TEXT, RT_WINDOW_CLOSE, res);
@ -846,7 +577,7 @@ bool CWindow::GetTrashEvent()
EventType CWindow::GetEventTypeReduce() EventType CWindow::GetEventTypeReduce()
{ {
if ( m_buttonReduce == 0 ) return EVENT_NULL; if (m_buttonReduce == nullptr) return EVENT_NULL;
return m_buttonReduce->GetEventType(); return m_buttonReduce->GetEventType();
} }
@ -854,7 +585,7 @@ EventType CWindow::GetEventTypeReduce()
EventType CWindow::GetEventTypeFull() EventType CWindow::GetEventTypeFull()
{ {
if ( m_buttonFull == 0 ) return EVENT_NULL; if (m_buttonFull == nullptr) return EVENT_NULL;
return m_buttonFull->GetEventType(); return m_buttonFull->GetEventType();
} }
@ -862,7 +593,7 @@ EventType CWindow::GetEventTypeFull()
EventType CWindow::GetEventTypeClose() EventType CWindow::GetEventTypeClose()
{ {
if ( m_buttonClose == 0 ) return EVENT_NULL; if (m_buttonClose == nullptr) return EVENT_NULL;
return m_buttonClose->GetEventType(); return m_buttonClose->GetEventType();
} }
@ -923,9 +654,6 @@ int CWindow::BorderDetect(Math::Point pos)
bool CWindow::EventProcess(const Event &event) bool CWindow::EventProcess(const Event &event)
{ {
Math::Point pos;
int i, flags;
if ( event.type == EVENT_MOUSE_MOVE ) if ( event.type == EVENT_MOUSE_MOVE )
{ {
if ( m_bCapture ) if ( m_bCapture )
@ -939,7 +667,7 @@ bool CWindow::EventProcess(const Event &event)
if ( m_name.length() > 0 && m_bMovable && // title bar? if ( m_name.length() > 0 && m_bMovable && // title bar?
Detect(event.mousePos) ) Detect(event.mousePos) )
{ {
flags = BorderDetect(event.mousePos); int flags = BorderDetect(event.mousePos);
if ( flags == -1 ) if ( flags == -1 )
{ {
m_pressMouse = Gfx::ENG_MOUSE_MOVE; // + m_pressMouse = Gfx::ENG_MOUSE_MOVE; // +
@ -973,26 +701,21 @@ bool CWindow::EventProcess(const Event &event)
if ( !m_bCapture ) if ( !m_bCapture )
{ {
for ( i=MAXWINDOW-1 ; i>=0 ; i-- ) for (auto& control : m_controls)
{ {
if ( m_table[i] != 0 ) if (! control->EventProcess(event))
{ return false;
if ( !m_table[i]->EventProcess(event) )
{
return false;
}
}
} }
if ( m_buttonReduce != 0 ) if (m_buttonReduce != nullptr)
{ {
m_buttonReduce->EventProcess(event); m_buttonReduce->EventProcess(event);
} }
if ( m_buttonFull != 0 ) if (m_buttonFull != nullptr)
{ {
m_buttonFull->EventProcess(event); m_buttonFull->EventProcess(event);
} }
if ( m_buttonClose != 0 ) if (m_buttonClose != nullptr)
{ {
m_buttonClose->EventProcess(event); m_buttonClose->EventProcess(event);
} }
@ -1019,7 +742,7 @@ bool CWindow::EventProcess(const Event &event)
if ( event.type == EVENT_MOUSE_MOVE && m_bCapture ) if ( event.type == EVENT_MOUSE_MOVE && m_bCapture )
{ {
pos = event.mousePos; Math::Point pos = event.mousePos;
if ( m_pressFlags == -1 ) // all moves? if ( m_pressFlags == -1 ) // all moves?
{ {
m_pos.x += pos.x-m_pressPos.x; m_pos.x += pos.x-m_pressPos.x;
@ -1070,7 +793,7 @@ bool CWindow::EventProcess(const Event &event)
if (event.type == EVENT_MOUSE_BUTTON_UP && if (event.type == EVENT_MOUSE_BUTTON_UP &&
event.GetData<MouseButtonEventData>()->button == MOUSE_BUTTON_LEFT && event.GetData<MouseButtonEventData>()->button == MOUSE_BUTTON_LEFT &&
m_bCapture ) m_bCapture)
{ {
m_bCapture = false; m_bCapture = false;
} }
@ -1083,10 +806,6 @@ bool CWindow::EventProcess(const Event &event)
void CWindow::Draw() void CWindow::Draw()
{ {
Math::Point pos, dim;
float width, h, sw;
int i;
if ( (m_state & STATE_VISIBLE) == 0 ) return; if ( (m_state & STATE_VISIBLE) == 0 ) return;
if ( m_state & STATE_SHADOW ) if ( m_state & STATE_SHADOW )
@ -1098,8 +817,9 @@ void CWindow::Draw()
if ( m_name.length() > 0 ) // title bar? if ( m_name.length() > 0 ) // title bar?
{ {
h = m_engine->GetText()->GetHeight(m_fontType, m_fontSize); float h = m_engine->GetText()->GetHeight(m_fontType, m_fontSize);
Math::Point pos, dim;
// Draws the shadow under the title bar. // Draws the shadow under the title bar.
{ {
Math::Point sPos, sDim; Math::Point sPos, sDim;
@ -1111,7 +831,7 @@ void CWindow::Draw()
DrawShadow(pos, dim); DrawShadow(pos, dim);
} }
width = m_dim.x; float width = m_dim.x;
if ( m_bRedim ) width -= h*1.2f*0.75f*2.0f; if ( m_bRedim ) width -= h*1.2f*0.75f*2.0f;
if ( m_bClosable ) width -= h*1.2f*0.75f; if ( m_bClosable ) width -= h*1.2f*0.75f;
@ -1121,7 +841,7 @@ void CWindow::Draw()
dim.y = h*1.2f; dim.y = h*1.2f;
DrawVertex(pos, dim, (m_state&STATE_ENABLE)?2:9); DrawVertex(pos, dim, (m_state&STATE_ENABLE)?2:9);
sw = m_engine->GetText()->GetStringWidth(m_name, m_fontType, m_fontSize); float sw = m_engine->GetText()->GetStringWidth(m_name, m_fontType, m_fontSize);
if ( m_state&STATE_ENABLE ) if ( m_state&STATE_ENABLE )
{ {
@ -1138,28 +858,25 @@ void CWindow::Draw()
pos.y = m_pos.y+m_dim.y-0.01f-h*1.10f; pos.y = m_pos.y+m_dim.y-0.01f-h*1.10f;
m_engine->GetText()->DrawText(m_name, m_fontType, m_fontSize, pos, width, Gfx::TEXT_ALIGN_CENTER, 0); m_engine->GetText()->DrawText(m_name, m_fontType, m_fontSize, pos, width, Gfx::TEXT_ALIGN_CENTER, 0);
if ( m_buttonReduce != 0 ) if (m_buttonReduce != nullptr)
{ {
m_buttonReduce->Draw(); m_buttonReduce->Draw();
} }
if ( m_buttonFull != 0 ) if (m_buttonFull != nullptr)
{ {
m_buttonFull->Draw(); m_buttonFull->Draw();
} }
if ( m_buttonClose != 0 ) if (m_buttonClose != nullptr)
{ {
m_buttonClose->Draw(); m_buttonClose->Draw();
} }
} }
for ( i=0 ; i<MAXWINDOW ; i++ ) for (auto& control : m_controls)
{ {
if ( m_table[i] != 0 ) control->Draw();
{
m_table[i]->Draw();
}
} }
} }

View File

@ -43,14 +43,13 @@
#include "ui/controls/slider.h" #include "ui/controls/slider.h"
#include "ui/controls/target.h" #include "ui/controls/target.h"
#include <memory>
#include <string> #include <string>
#include <vector>
namespace Ui namespace Ui
{ {
const int MAXWINDOW = 100;
class CWindow : public CControl class CWindow : public CControl
{ {
public: public:
@ -125,9 +124,11 @@ protected:
void MoveAdjust(); void MoveAdjust();
void DrawVertex(Math::Point pos, Math::Point dim, int icon); void DrawVertex(Math::Point pos, Math::Point dim, int icon);
void DrawHach(Math::Point pos, Math::Point dim); void DrawHach(Math::Point pos, Math::Point dim);
template<typename ControlClass>
ControlClass* CreateControl(Math::Point pos, Math::Point dim, int icon, EventType eventMsg);
protected: protected:
CControl* m_table[MAXWINDOW]; std::vector<std::unique_ptr<CControl>> m_controls;
bool m_bTrashEvent; bool m_bTrashEvent;
bool m_bMaximized; bool m_bMaximized;
@ -137,9 +138,9 @@ protected:
Math::Point m_minDim; Math::Point m_minDim;
Math::Point m_maxDim; Math::Point m_maxDim;
CButton* m_buttonReduce; std::unique_ptr<CButton> m_buttonReduce;
CButton* m_buttonFull; std::unique_ptr<CButton> m_buttonFull;
CButton* m_buttonClose; std::unique_ptr<CButton> m_buttonClose;
bool m_bMovable; bool m_bMovable;
bool m_bRedim; bool m_bRedim;

View File

@ -75,6 +75,11 @@ CDisplayInfo::CDisplayInfo()
m_lightSuppl = -1; m_lightSuppl = -1;
m_toto = 0; m_toto = 0;
m_bSoluce = false;
m_initPause = PAUSE_NONE;
m_bEditLock = false;
m_infoCamera = Gfx::CAM_TYPE_NULL;
m_index = -1;
} }
// Object's destructor. // Object's destructor.
@ -358,7 +363,7 @@ void CDisplayInfo::StartDisplayInfo(std::string filename, int index, bool bSoluc
m_main->SetEditLock(true, false); m_main->SetEditLock(true, false);
m_main->SetEditFull(false); m_main->SetEditFull(false);
m_bInitPause = m_pause->GetPauseType(); m_initPause = m_pause->GetPauseType();
m_pause->SetPause(PAUSE_SATCOM); m_pause->SetPause(PAUSE_SATCOM);
m_infoCamera = m_camera->GetType(); m_infoCamera = m_camera->GetType();
m_camera->SetType(Gfx::CAM_TYPE_INFO); m_camera->SetType(Gfx::CAM_TYPE_INFO);
@ -834,7 +839,7 @@ void CDisplayInfo::StopDisplayInfo()
} }
else else
{ {
m_pause->SetPause(m_bInitPause); m_pause->SetPause(m_initPause);
m_main->SetEditLock(false, false); m_main->SetEditLock(false, false);
} }
m_camera->SetType(m_infoCamera); m_camera->SetType(m_infoCamera);

View File

@ -94,7 +94,7 @@ protected:
Math::Point m_infoFinalDim; Math::Point m_infoFinalDim;
int m_lightSuppl; int m_lightSuppl;
bool m_bEditLock; bool m_bEditLock;
PauseType m_bInitPause; PauseType m_initPause;
bool m_bSoluce; bool m_bSoluce;
CObject* m_toto; CObject* m_toto;
}; };

View File

@ -43,7 +43,11 @@
namespace Ui namespace Ui
{ {
namespace
{
const float FONTSIZE = 12.0f; const float FONTSIZE = 12.0f;
} // anonymous namespace
@ -55,15 +59,6 @@ CDisplayText::CDisplayText()
m_interface = CRobotMain::GetInstancePointer()->GetInterface(); m_interface = CRobotMain::GetInstancePointer()->GetInterface();
m_sound = CApplication::GetInstancePointer()->GetSound(); m_sound = CApplication::GetInstancePointer()->GetSound();
for (int i=0 ; i<MAXDTLINE ; i++ )
{
m_bExist[i] = false;
m_visitGoal[i] = Math::Vector(0.0f, 0.0f, 0.0f);
m_visitDist[i] = 0.0f;
m_visitHeight[i] = 0.0f;
m_time[i] = 0.0f; // nothing displayed
}
m_bHide = false; m_bHide = false;
m_bEnable = true; m_bEnable = true;
m_delayFactor = 1.0f; m_delayFactor = 1.0f;
@ -88,22 +83,26 @@ void CDisplayText::DeleteObject()
bool CDisplayText::EventProcess(const Event &event) bool CDisplayText::EventProcess(const Event &event)
{ {
int i; if (m_engine->GetPause()) return true;
if ( m_engine->GetPause() ) return true; if (event.type == EVENT_FRAME)
if ( event.type == EVENT_FRAME )
{ {
for ( i=0 ; i<MAXDTLINE ; i++ ) for (auto& line : m_textLines)
{ {
if ( !m_bExist[i] ) break; if (! line.exist) break;
m_time[i] -= event.rTime; line.time -= event.rTime;
} }
while ( true )
while (true)
{ {
if ( !m_bExist[0] || if (!m_textLines.front().exist ||
m_time[0] > 0.0f ) break; m_textLines.front().time > 0.0f)
if ( !ClearLastText() ) break; {
break;
}
if (!ClearLastText())
break;
} }
} }
@ -115,14 +114,12 @@ bool CDisplayText::EventProcess(const Event &event)
void CDisplayText::DisplayError(Error err, CObject* pObj, float time) void CDisplayText::DisplayError(Error err, CObject* pObj, float time)
{ {
Math::Vector pos; if (pObj == nullptr)
float h, d; return;
if ( pObj == 0 ) return; Math::Vector pos = pObj->GetPosition();
float h = GetIdealHeight(pObj);
pos = pObj->GetPosition(); float d = GetIdealDist(pObj);
h = GetIdealHeight(pObj);
d = GetIdealDist(pObj);
DisplayError(err, pos, h, d, time); DisplayError(err, pos, h, d, time);
} }
@ -175,14 +172,11 @@ void CDisplayText::DisplayError(Error err, Math::Vector goal, float height,
void CDisplayText::DisplayText(const char *text, CObject* pObj, void CDisplayText::DisplayText(const char *text, CObject* pObj,
float time, TextType type) float time, TextType type)
{ {
Math::Vector pos; if (pObj == nullptr) return;
float h, d;
if ( pObj == 0 ) return; Math::Vector pos = pObj->GetPosition();
float h = GetIdealHeight(pObj);
pos = pObj->GetPosition(); float d = GetIdealDist(pObj);
h = GetIdealHeight(pObj);
d = GetIdealDist(pObj);
DisplayText(text, pos, h, d, time, type); DisplayText(text, pos, h, d, time, type);
} }
@ -264,11 +258,13 @@ void CDisplayText::DisplayText(const char *text, Math::Vector goal, float height
button->ClearState(STATE_ENABLE); button->ClearState(STATE_ENABLE);
} }
m_bExist[nLine] = true; TextLine line;
m_visitGoal[nLine] = goal; line.exist = true;
m_visitDist[nLine] = dist; line.visitGoal = goal;
m_visitHeight[nLine] = height; line.visitDist = dist;
m_time[nLine] = time*m_delayFactor; line.visitHeight = height;
line.time = time*m_delayFactor;
m_textLines[nLine] = line;
toto = SearchToto(); toto = SearchToto();
if ( toto != 0 ) if ( toto != 0 )
@ -318,24 +314,18 @@ void CDisplayText::DisplayText(const char *text, Math::Vector goal, float height
void CDisplayText::ClearText() void CDisplayText::ClearText()
{ {
Ui::CWindow* pw; Ui::CWindow* pw = static_cast<Ui::CWindow*>(m_interface->SearchControl(EVENT_WINDOW2));
int i;
pw = static_cast<Ui::CWindow*>(m_interface->SearchControl(EVENT_WINDOW2)); for (int i = 0; i < MAXDTLINE; i++)
for ( i=0 ; i<MAXDTLINE ; i++ )
{ {
if ( pw != 0 ) if (pw != nullptr)
{ {
pw->DeleteControl(EventType(EVENT_DT_GROUP0+i)); pw->DeleteControl(EventType(EVENT_DT_GROUP0+i));
pw->DeleteControl(EventType(EVENT_DT_LABEL0+i)); pw->DeleteControl(EventType(EVENT_DT_LABEL0+i));
pw->DeleteControl(EventType(EVENT_DT_VISIT0+i)); pw->DeleteControl(EventType(EVENT_DT_VISIT0+i));
} }
m_bExist[i] = false;
m_visitGoal[i] = Math::Vector(0.0f, 0.0f, 0.0f); m_textLines[i] = TextLine();
m_visitDist[i] = 0.0f;
m_visitHeight[i] = 0.0f;
m_time[i] = 0.0f;
} }
} }
@ -415,16 +405,13 @@ bool CDisplayText::ClearLastText()
pg1->SetIcon(pg2->GetIcon()); pg1->SetIcon(pg2->GetIcon());
pl1->SetName(pl2->GetName()); pl1->SetName(pl2->GetName());
m_time[i] = m_time[i+1]; m_textLines[i] = m_textLines[i+1];
m_visitGoal[i] = m_visitGoal[i+1];
m_visitDist[i] = m_visitDist[i+1];
m_visitHeight[i] = m_visitHeight[i+1]; // shift
} }
pw->DeleteControl(EventType(EVENT_DT_VISIT0+i)); pw->DeleteControl(EventType(EVENT_DT_VISIT0+i));
pw->DeleteControl(EventType(EVENT_DT_GROUP0+i)); pw->DeleteControl(EventType(EVENT_DT_GROUP0+i));
pw->DeleteControl(EventType(EVENT_DT_LABEL0+i)); pw->DeleteControl(EventType(EVENT_DT_LABEL0+i));
m_bExist[i] = false; m_textLines[i].exist = false;
return true; return true;
} }
@ -449,33 +436,27 @@ void CDisplayText::SetEnable(bool bEnable)
Math::Vector CDisplayText::GetVisitGoal(EventType event) Math::Vector CDisplayText::GetVisitGoal(EventType event)
{ {
int i; int i = event - EVENT_DT_VISIT0;
if (i < 0 || i >= MAXDTLINE) return Math::Vector(0.0f, 0.0f, 0.0f);
i = event-EVENT_DT_VISIT0; return m_textLines[i].visitGoal;
if ( i < 0 || i >= MAXDTLINE ) return Math::Vector(0.0f, 0.0f, 0.0f);
return m_visitGoal[i];
} }
// Returns the distance during a visit. // Returns the distance during a visit.
float CDisplayText::GetVisitDist(EventType event) float CDisplayText::GetVisitDist(EventType event)
{ {
int i; int i = event-EVENT_DT_VISIT0;
if (i < 0 || i >= MAXDTLINE) return 0.0f;
i = event-EVENT_DT_VISIT0; return m_textLines[i].visitDist;
if ( i < 0 || i >= MAXDTLINE ) return 0.0f;
return m_visitDist[i];
} }
// Returns the height on a visit. // Returns the height on a visit.
float CDisplayText::GetVisitHeight(EventType event) float CDisplayText::GetVisitHeight(EventType event)
{ {
int i; int i = event-EVENT_DT_VISIT0;
if (i < 0 || i >= MAXDTLINE) return 0.0f;
i = event-EVENT_DT_VISIT0; return m_textLines[i].visitHeight;
if ( i < 0 || i >= MAXDTLINE ) return 0.0f;
return m_visitHeight[i];
} }
@ -590,5 +571,5 @@ CObject* CDisplayText::SearchToto()
return CObjectManager::GetInstancePointer()->FindNearest(nullptr, OBJECT_TOTO); return CObjectManager::GetInstancePointer()->FindNearest(nullptr, OBJECT_TOTO);
} }
} } // namespace Ui

View File

@ -21,16 +21,13 @@
#pragma once #pragma once
#include "common/event.h" #include "common/event.h"
#include "common/global.h" #include "common/global.h"
#include "sound/sound.h" #include <array>
class CObject; class CObject;
class CSound; class CSoundInterface;
namespace Gfx namespace Gfx
{ {
@ -92,11 +89,15 @@ protected:
Ui::CInterface* m_interface; Ui::CInterface* m_interface;
CSoundInterface* m_sound; CSoundInterface* m_sound;
bool m_bExist[MAXDTLINE]; struct TextLine
float m_time[MAXDTLINE]; {
Math::Vector m_visitGoal[MAXDTLINE]; bool exist = false;
float m_visitDist[MAXDTLINE]; float time = 0.0f;
float m_visitHeight[MAXDTLINE]; Math::Vector visitGoal;
float visitDist = 0.0f;
float visitHeight = 0.0f;
};
std::array<TextLine, MAXDTLINE> m_textLines;
bool m_bHide; bool m_bHide;
bool m_bEnable; bool m_bEnable;

View File

@ -55,6 +55,10 @@ CMainDialog::CMainDialog()
m_settings = CSettings::GetInstancePointer(); m_settings = CSettings::GetInstancePointer();
m_dialogOpen = false; m_dialogOpen = false;
m_dialogType = {};
m_dialogFireParticles = false;
m_dialogTime = 0.0f;
m_dialogParti = 0.0f;
} }
// Destructor of robot application. // Destructor of robot application.

View File

@ -80,7 +80,8 @@ protected:
CSoundInterface* m_sound; CSoundInterface* m_sound;
CSettings* m_settings; CSettings* m_settings;
enum class DialogType { enum class DialogType
{
Question, Question,
PauseMenu PauseMenu
}; };

View File

@ -44,6 +44,8 @@ CMainShort::CMainShort()
m_interface = m_main->GetInterface(); m_interface = m_main->GetInterface();
m_shortcuts.clear(); m_shortcuts.clear();
m_bBuilding = false;
} }
// Destructor of the application card. // Destructor of the application card.

View File

@ -93,12 +93,7 @@ CMainUserInterface::CMainUserInterface()
m_glintMouse = Math::Point(0.0f, 0.0f); m_glintMouse = Math::Point(0.0f, 0.0f);
m_glintTime = 1000.0f; m_glintTime = 1000.0f;
m_shotDelay = 0;
for (int i = 0; i < 10; i++)
{
m_partiPhase[i] = 0;
m_partiTime[i] = 0.0f;
}
} }
// Destructor of robot application. // Destructor of robot application.
@ -552,27 +547,27 @@ void CMainUserInterface::FrameParticle(float rTime)
for ( i=0 ; i<10 ; i++ ) for ( i=0 ; i<10 ; i++ )
{ {
if ( m_partiPhase[i] == 0 ) // waiting? if ( m_particles[i].phase == 0 ) // waiting?
{ {
m_partiTime[i] -= rTime; m_particles[i].time -= rTime;
if ( m_partiTime[i] <= 0.0f ) if ( m_particles[i].time <= 0.0f )
{ {
r = rand()%3; r = rand()%3;
if ( r == 0 ) if ( r == 0 )
{ {
ii = rand()%nParti; ii = rand()%nParti;
m_partiPos[i].x = pParti[ii*5+0]/640.0f; m_particles[i].pos.x = pParti[ii*5+0]/640.0f;
m_partiPos[i].y = (480.0f-pParti[ii*5+1])/480.0f; m_particles[i].pos.y = (480.0f-pParti[ii*5+1])/480.0f;
m_partiTime[i] = pParti[ii*5+2]+Math::Rand()*pParti[ii*5+3]; m_particles[i].time = pParti[ii*5+2]+Math::Rand()*pParti[ii*5+3];
m_partiPhase[i] = static_cast<int>(pParti[ii*5+4]); m_particles[i].phase = static_cast<int>(pParti[ii*5+4]);
if ( m_partiPhase[i] == 3 ) if ( m_particles[i].phase == 3 )
{ {
m_sound->Play(SOUND_PSHHH, SoundPos(m_partiPos[i]), 0.3f+Math::Rand()*0.3f); m_sound->Play(SOUND_PSHHH, SoundPos(m_particles[i].pos), 0.3f+Math::Rand()*0.3f);
} }
else else
{ {
m_sound->Play(SOUND_GGG, SoundPos(m_partiPos[i]), 0.1f+Math::Rand()*0.4f); m_sound->Play(SOUND_GGG, SoundPos(m_particles[i].pos), 0.1f+Math::Rand()*0.4f);
} }
} }
@ -591,7 +586,7 @@ void CMainUserInterface::FrameParticle(float rTime)
rand()%2?Gfx::PARTIGLINT:Gfx::PARTICONTROL, rand()%2?Gfx::PARTIGLINT:Gfx::PARTICONTROL,
Math::Rand()*0.4f+0.4f, 0.0f, 0.0f, Math::Rand()*0.4f+0.4f, 0.0f, 0.0f,
Gfx::SH_INTERFACE); Gfx::SH_INTERFACE);
m_partiTime[i] = 0.5f+Math::Rand()*0.5f; m_particles[i].time = 0.5f+Math::Rand()*0.5f;
} }
if ( r == 2 ) if ( r == 2 )
@ -600,51 +595,51 @@ void CMainUserInterface::FrameParticle(float rTime)
if ( ii == 0 ) if ( ii == 0 )
{ {
m_sound->Play(SOUND_ENERGY, SoundRand(), 0.2f+Math::Rand()*0.2f); m_sound->Play(SOUND_ENERGY, SoundRand(), 0.2f+Math::Rand()*0.2f);
m_partiTime[i] = 1.0f+Math::Rand()*1.0f; m_particles[i].time = 1.0f+Math::Rand()*1.0f;
} }
if ( ii == 1 ) if ( ii == 1 )
{ {
m_sound->Play(SOUND_STATION, SoundRand(), 0.2f+Math::Rand()*0.2f); m_sound->Play(SOUND_STATION, SoundRand(), 0.2f+Math::Rand()*0.2f);
m_partiTime[i] = 1.0f+Math::Rand()*2.0f; m_particles[i].time = 1.0f+Math::Rand()*2.0f;
} }
if ( ii == 2 ) if ( ii == 2 )
{ {
m_sound->Play(SOUND_ALARM, SoundRand(), 0.1f+Math::Rand()*0.1f); m_sound->Play(SOUND_ALARM, SoundRand(), 0.1f+Math::Rand()*0.1f);
m_partiTime[i] = 2.0f+Math::Rand()*4.0f; m_particles[i].time = 2.0f+Math::Rand()*4.0f;
} }
if ( ii == 3 ) if ( ii == 3 )
{ {
m_sound->Play(SOUND_INFO, SoundRand(), 0.1f+Math::Rand()*0.1f); m_sound->Play(SOUND_INFO, SoundRand(), 0.1f+Math::Rand()*0.1f);
m_partiTime[i] = 2.0f+Math::Rand()*4.0f; m_particles[i].time = 2.0f+Math::Rand()*4.0f;
} }
if ( ii == 4 ) if ( ii == 4 )
{ {
m_sound->Play(SOUND_RADAR, SoundRand(), 0.2f+Math::Rand()*0.2f); m_sound->Play(SOUND_RADAR, SoundRand(), 0.2f+Math::Rand()*0.2f);
m_partiTime[i] = 0.5f+Math::Rand()*1.0f; m_particles[i].time = 0.5f+Math::Rand()*1.0f;
} }
if ( ii == 5 ) if ( ii == 5 )
{ {
m_sound->Play(SOUND_GFLAT, SoundRand(), 0.3f+Math::Rand()*0.3f); m_sound->Play(SOUND_GFLAT, SoundRand(), 0.3f+Math::Rand()*0.3f);
m_partiTime[i] = 2.0f+Math::Rand()*4.0f; m_particles[i].time = 2.0f+Math::Rand()*4.0f;
} }
if ( ii == 6 ) if ( ii == 6 )
{ {
m_sound->Play(SOUND_ALARMt, SoundRand(), 0.1f+Math::Rand()*0.1f); m_sound->Play(SOUND_ALARMt, SoundRand(), 0.1f+Math::Rand()*0.1f);
m_partiTime[i] = 2.0f+Math::Rand()*4.0f; m_particles[i].time = 2.0f+Math::Rand()*4.0f;
} }
} }
} }
} }
if ( m_partiPhase[i] != 0 ) // generates? if ( m_particles[i].phase != 0 ) // generates?
{ {
m_partiTime[i] -= rTime; m_particles[i].time -= rTime;
if ( m_partiTime[i] > 0.0f ) if ( m_particles[i].time > 0.0f )
{ {
if ( m_partiPhase[i] == 1 ) // sparks? if ( m_particles[i].phase == 1 ) // sparks?
{ {
pos.x = m_partiPos[i].x; pos.x = m_particles[i].pos.x;
pos.y = m_partiPos[i].y; pos.y = m_particles[i].pos.y;
pos.z = 0.0f; pos.z = 0.0f;
pos.x += (Math::Rand()-0.5f)*0.01f; pos.x += (Math::Rand()-0.5f)*0.01f;
pos.y += (Math::Rand()-0.5f)*0.01f; pos.y += (Math::Rand()-0.5f)*0.01f;
@ -656,8 +651,8 @@ void CMainUserInterface::FrameParticle(float rTime)
m_particle->CreateParticle(pos, speed, dim, Gfx::PARTIBLITZ, m_particle->CreateParticle(pos, speed, dim, Gfx::PARTIBLITZ,
Math::Rand()*0.2f+0.2f, 0.0f, 0.0f, Math::Rand()*0.2f+0.2f, 0.0f, 0.0f,
Gfx::SH_INTERFACE); Gfx::SH_INTERFACE);
pos.x = m_partiPos[i].x; pos.x = m_particles[i].pos.x;
pos.y = m_partiPos[i].y; pos.y = m_particles[i].pos.y;
pos.z = 0.0f; pos.z = 0.0f;
speed.x = (Math::Rand()-0.5f)*0.5f; speed.x = (Math::Rand()-0.5f)*0.5f;
speed.y = (0.3f+Math::Rand()*0.3f); speed.y = (0.3f+Math::Rand()*0.3f);
@ -669,10 +664,10 @@ void CMainUserInterface::FrameParticle(float rTime)
Math::Rand()*0.5f+0.5f, 2.0f, 0.0f, Math::Rand()*0.5f+0.5f, 2.0f, 0.0f,
Gfx::SH_INTERFACE); Gfx::SH_INTERFACE);
} }
if ( m_partiPhase[i] == 2 ) // sparks? if ( m_particles[i].phase == 2 ) // sparks?
{ {
pos.x = m_partiPos[i].x; pos.x = m_particles[i].pos.x;
pos.y = m_partiPos[i].y; pos.y = m_particles[i].pos.y;
pos.z = 0.0f; pos.z = 0.0f;
pos.x += (Math::Rand()-0.5f)*0.01f; pos.x += (Math::Rand()-0.5f)*0.01f;
pos.y += (Math::Rand()-0.5f)*0.01f; pos.y += (Math::Rand()-0.5f)*0.01f;
@ -684,8 +679,8 @@ void CMainUserInterface::FrameParticle(float rTime)
m_particle->CreateParticle(pos, speed, dim, Gfx::PARTIBLITZ, m_particle->CreateParticle(pos, speed, dim, Gfx::PARTIBLITZ,
Math::Rand()*0.2f+0.2f, 0.0f, 0.0f, Math::Rand()*0.2f+0.2f, 0.0f, 0.0f,
Gfx::SH_INTERFACE); Gfx::SH_INTERFACE);
pos.x = m_partiPos[i].x; pos.x = m_particles[i].pos.x;
pos.y = m_partiPos[i].y; pos.y = m_particles[i].pos.y;
pos.z = 0.0f; pos.z = 0.0f;
speed.x = (Math::Rand()-0.5f)*0.5f; speed.x = (Math::Rand()-0.5f)*0.5f;
speed.y = (0.3f+Math::Rand()*0.3f); speed.y = (0.3f+Math::Rand()*0.3f);
@ -696,10 +691,10 @@ void CMainUserInterface::FrameParticle(float rTime)
Math::Rand()*0.5f+0.5f, 2.0f, 0.0f, Math::Rand()*0.5f+0.5f, 2.0f, 0.0f,
Gfx::SH_INTERFACE); Gfx::SH_INTERFACE);
} }
if ( m_partiPhase[i] == 3 ) // smoke? if ( m_particles[i].phase == 3 ) // smoke?
{ {
pos.x = m_partiPos[i].x; pos.x = m_particles[i].pos.x;
pos.y = m_partiPos[i].y; pos.y = m_particles[i].pos.y;
pos.z = 0.0f; pos.z = 0.0f;
pos.x += (Math::Rand()-0.5f)*0.03f; pos.x += (Math::Rand()-0.5f)*0.03f;
pos.y += (Math::Rand()-0.5f)*0.03f; pos.y += (Math::Rand()-0.5f)*0.03f;
@ -715,8 +710,8 @@ void CMainUserInterface::FrameParticle(float rTime)
} }
else else
{ {
m_partiPhase[i] = 0; m_particles[i].phase = 0;
m_partiTime[i] = 2.0f+Math::Rand()*4.0f; m_particles[i].time = 2.0f+Math::Rand()*4.0f;
} }
} }
} }

View File

@ -128,9 +128,13 @@ protected:
Math::Point m_glintMouse; Math::Point m_glintMouse;
float m_glintTime; float m_glintTime;
int m_partiPhase[10]; struct Particle
float m_partiTime[10]; {
Math::Point m_partiPos[10]; int phase = 0;
float time = 0.0f;
Math::Point pos;
};
std::array<Particle, 10> m_particles;
}; };
} // namespace Ui } // namespace Ui

View File

@ -34,7 +34,8 @@ namespace Ui
{ {
CScreenLoading::CScreenLoading() CScreenLoading::CScreenLoading()
: m_visible(false) : m_visible(false),
m_lastProgress(0.0f)
{ {
} }

View File

@ -81,6 +81,9 @@ CStudio::CStudio()
m_pause = CPauseManager::GetInstancePointer(); m_pause = CPauseManager::GetInstancePointer();
m_settings = CSettings::GetInstancePointer(); m_settings = CSettings::GetInstancePointer();
m_program = nullptr;
m_script = nullptr;
m_bEditMaximized = false; m_bEditMaximized = false;
m_bEditMinimized = false; m_bEditMinimized = false;
@ -88,8 +91,9 @@ CStudio::CStudio()
m_bRealTime = true; m_bRealTime = true;
m_bRunning = false; m_bRunning = false;
m_fixInfoTextTime = 0.0f; m_fixInfoTextTime = 0.0f;
m_helpFilename[0] = 0; m_initPause = PAUSE_NONE;
m_dialog = SD_NULL; m_dialog = SD_NULL;
m_editCamera = Gfx::CAM_TYPE_NULL;
} }
// Object's destructor. // Object's destructor.
@ -135,7 +139,7 @@ bool CStudio::EventProcess(const Event &event)
if ( event.type == EVENT_STUDIO_LIST ) // list clicked? if ( event.type == EVENT_STUDIO_LIST ) // list clicked?
{ {
m_main->StartDisplayInfo(const_cast<char *>(m_helpFilename.c_str()), -1); // TODO change to std::string when RobotMain changes m_main->StartDisplayInfo(m_helpFilename, -1);
} }
if ( event.type == EVENT_STUDIO_NEW ) // new? if ( event.type == EVENT_STUDIO_NEW ) // new?
@ -451,7 +455,7 @@ void CStudio::SearchToken(CEdit* edit)
} }
if ( level > 0 ) if ( level > 0 )
{ {
m_helpFilename[0] = 0; m_helpFilename = "";
SetInfoText("", true); SetInfoText("", true);
return; return;
} }
@ -552,7 +556,7 @@ void CStudio::StartEditScript(CScript *script, std::string name, Program* progra
m_main->SetEditLock(true, true); m_main->SetEditLock(true, true);
m_main->SetEditFull(false); m_main->SetEditFull(false);
m_bInitPause = m_pause->GetPauseType(); m_initPause = m_pause->GetPauseType();
m_main->SetSpeed(1.0f); m_main->SetSpeed(1.0f);
m_editCamera = m_camera->GetType(); m_editCamera = m_camera->GetType();
m_camera->SetType(Gfx::CAM_TYPE_EDIT); m_camera->SetType(Gfx::CAM_TYPE_EDIT);
@ -884,7 +888,7 @@ bool CStudio::StopEditScript(bool bCancel)
m_interface->DeleteControl(EVENT_WINDOW3); m_interface->DeleteControl(EVENT_WINDOW3);
m_pause->SetPause(m_bInitPause); m_pause->SetPause(m_initPause);
m_sound->MuteAll(false); m_sound->MuteAll(false);
m_main->SetEditLock(false, true); m_main->SetEditLock(false, true);
m_camera->SetType(m_editCamera); m_camera->SetType(m_editCamera);

View File

@ -116,7 +116,7 @@ protected:
float m_fixInfoTextTime; float m_fixInfoTextTime;
bool m_bRunning; bool m_bRunning;
bool m_bRealTime; bool m_bRealTime;
PauseType m_bInitPause; PauseType m_initPause;
std::string m_helpFilename; std::string m_helpFilename;
StudioDialog m_dialog; StudioDialog m_dialog;