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
void CRobotMain::StartDisplayInfo(const char *filename, int index)
void CRobotMain::StartDisplayInfo(const std::string& filename, int index)
{
if (m_cmdEdit) return;

View File

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

View File

@ -45,7 +45,8 @@ CControl::CControl()
m_textAlign = Gfx::TEXT_ALIGN_CENTER; //instead m_justify
m_bFocus = false;
m_bCapture = false;
m_icon = 0;
m_fontStretch = false;
m_bGlint = false;
m_glintCorner1 = 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 "common/logger.h"
#include "common/make_unique.h"
#include "common/misc.h"
#include "common/resources/inputstream.h"
@ -93,18 +94,16 @@ bool IsSep(int character)
//! Object's constructor.
CEdit::CEdit () : CControl ()
CEdit::CEdit()
: CControl(),
m_lineOffset(),
m_lineIndent()
{
Math::Point pos;
m_maxChar = 100;
m_text = std::vector<char>(m_maxChar+1, '\0');
m_len = 0;
std::fill_n(m_lineOffset, EDITLINEMAX, 0);
m_fontType = Gfx::FONT_COURIER;
m_scroll = 0;
m_bEdit = true;
m_bHilite = true;
m_bInsideScroll = true;
@ -118,6 +117,22 @@ CEdit::CEdit () : CControl ()
m_column = 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();
m_bUndoForce = true;
@ -129,9 +144,6 @@ CEdit::CEdit () : CControl ()
CEdit::~CEdit()
{
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)
{
CScroll* pc;
Math::Point start, end;
if ( eventType == EVENT_NULL ) eventType = GetUniqueEventType();
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;
MoveAdjust(); // readjusts multi-line mode
m_scroll = new Ui::CScroll();
pc = static_cast<CScroll*>(m_scroll);
pc->Create(pos, dim, -1, EVENT_NULL);
m_scroll = MakeUnique<Ui::CScroll>();
m_scroll->Create(pos, dim, -1, EVENT_NULL);
MoveAdjust();
}
@ -196,7 +204,7 @@ void CEdit::MoveAdjust()
height = m_dim.y-(m_bMulti?MARGY*2.0f:MARGY1);
m_lineVisible = static_cast<int>((height/m_lineHeight));
if ( m_scroll != 0 )
if (m_scroll != nullptr)
{
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);
if ( event.type == m_scroll->GetEventType() )
if (event.type == m_scroll->GetEventType())
{
Scroll();
return true;
@ -1127,7 +1135,7 @@ void CEdit::Draw()
DrawPart(pos, dim, 0); // red
}
if ( m_scroll != 0 && !m_bGeneric )
if (m_scroll != nullptr && !m_bGeneric)
{
m_scroll->Draw();
}
@ -2139,11 +2147,9 @@ void CEdit::SetFontSize(float size)
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;
Scroll(static_cast<int>(value + 0.5f), true);
}
@ -3195,9 +3201,7 @@ bool CEdit::SetFormat(int cursor1, int cursor2, int format)
void CEdit::UpdateScroll()
{
float value;
if ( m_scroll != nullptr )
if (m_scroll != nullptr)
{
if ( m_lineTotal <= m_lineVisible )
{
@ -3207,7 +3211,7 @@ void CEdit::UpdateScroll()
}
else
{
value = static_cast<float>(m_lineVisible) / m_lineTotal;
float value = static_cast<float>(m_lineVisible) / m_lineTotal;
m_scroll->SetVisibleRatio(value);
value = static_cast<float>(m_lineFirst) / (m_lineTotal - m_lineVisible);

View File

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

View File

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

View File

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

View File

@ -27,24 +27,19 @@
#include "graphics/engine/engine.h"
#include <string.h>
#include <stdio.h>
namespace Ui
{
// Object's constructor.
CImage::CImage() : CControl()
{
m_filename[0] = 0;
}
// Object's destructor.
CImage::~CImage()
{
if ( m_filename[0] != 0 )
if (!m_filename.empty())
{
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.
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);
}
strcpy(m_filename, name);
}
char* CImage::GetFilenameImage()
{
return m_filename;
m_filename = name;
}

View File

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

View File

@ -22,6 +22,9 @@
#include "app/app.h"
#include <boost/range/adaptor/reversed.hpp>
namespace Ui
{
@ -31,18 +34,12 @@ CInterface::CInterface()
m_event = CApplication::GetInstancePointer()->GetEventQueue();
m_engine = Gfx::CEngine::GetInstancePointer();
m_camera = nullptr;
for (int i = 0; i < MAXCONTROL; i++)
{
m_table[i] = nullptr;
}
}
// Object's destructor.
CInterface::~CInterface()
{
Flush();
}
@ -50,26 +47,24 @@ CInterface::~CInterface()
void CInterface::Flush()
{
for (int i = 0; i < MAXCONTROL; i++)
for (auto& control : m_controls)
{
delete m_table[i];
m_table[i] = nullptr;
control.reset();
}
}
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 -1;
}
template <typename T> inline T* CInterface::CreateControl(Math::Point pos, Math::Point dim, int icon, EventType eventMsg)
template <typename ControlClass>
ControlClass* CInterface::CreateControl(Math::Point pos, Math::Point dim, int icon, EventType eventMsg)
{
if (eventMsg == EVENT_NULL)
eventMsg = GetUniqueEventType();
@ -78,10 +73,11 @@ template <typename T> inline T* CInterface::CreateControl(Math::Point pos, Math:
if (index < 0)
return nullptr;
m_table[index] = new T();
T* pc = static_cast<T *>(m_table[index]);
pc->Create(pos, dim, icon, eventMsg);
return pc;
auto control = MakeUnique<ControlClass>();
control->Create(pos, dim, icon, eventMsg);
auto* controlPtr = control.get();
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_WINDOW8: index = 8; 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;
}
if (index < 0)
return nullptr;
delete m_table[index];
m_table[index] = new CWindow();
CWindow* pc = static_cast<CWindow *>(m_table[index]);
pc->Create(pos, dim, icon, eventMsg);
return pc;
auto window = MakeUnique<CWindow>();
window->Create(pos, dim, icon, eventMsg);
auto* windowPtr = window.get();
m_controls[index] = std::move(window);
return windowPtr;
}
// Creates a new button.
@ -220,10 +216,11 @@ CList* CInterface::CreateList(Math::Point pos, Math::Point dim, int icon, EventT
if (index < 0)
return nullptr;
m_table[index] = new CList();
CList* pc = static_cast<CList *>(m_table[index]);
pc->Create(pos, dim, icon, eventMsg, expand);
return pc;
auto list = MakeUnique<CList>();
list->Create(pos, dim, icon, eventMsg, expand);
auto* listPtr = list.get();
m_controls[index] = std::move(list);
return listPtr;
}
// 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)
{
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())
{
delete m_table[i];
m_table[i] = nullptr;
return true;
}
control.reset();
return true;
}
}
return false;
@ -277,12 +271,12 @@ bool CInterface::DeleteControl(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 m_table[i];
return control.get();
}
}
return nullptr;
@ -300,11 +294,11 @@ bool CInterface::EventProcess(const Event &event)
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;
}
}
@ -317,11 +311,11 @@ bool CInterface::EventProcess(const Event &event)
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;
}
}
@ -333,21 +327,21 @@ bool CInterface::GetTooltip(Math::Point pos, std::string &name)
void CInterface::Draw()
{
for (int i = 0; i < MAXCONTROL; i++)
for (auto& control : m_controls)
{
if ( m_table[i] != nullptr )
m_table[i]->Draw();
if (control != nullptr)
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;
m_table[i]->SetFocus(focus);
bool focus = control.get() == focusControl;
control->SetFocus(focus);
}
}
}

View File

@ -49,14 +49,15 @@
#include "ui/controls/target.h"
#include "ui/controls/window.h"
#include <memory>
#include <string>
#include <vector>
namespace Ui
{
const int MAXCONTROL = 100;
class CInterface
{
public:
@ -92,18 +93,19 @@ public:
void Draw();
void SetFocus(CControl* control);
void SetFocus(CControl* focusControl);
protected:
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;
Gfx::CEngine* m_engine;
Gfx::CCamera* m_camera;
CControl* m_table[MAXCONTROL];
std::array<std::unique_ptr<CControl>, MAXCONTROL> m_controls;
};
}
} // namespace Ui

View File

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

View File

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

View File

@ -66,9 +66,12 @@ CMap::CMap() : CControl()
m_half = m_terrain->GetMosaicCount() * m_terrain->GetBrickCount() * m_terrain->GetBrickSize() / 2.0f;
m_highlightRank = -1;
m_totalFix = 0;
m_totalMove = 0;
m_bRadar = false;
FlushObject();
m_fixImage[0] = 0;
m_mode = 0;
m_bToy = 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.
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.
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)
{
m_highlightRank = -1;
if ( m_bToy || m_fixImage[0] != 0 )
if ( m_bToy || !m_fixImage.empty())
return; // card with still image?
if ( pObj == nullptr )
return;
@ -333,10 +336,10 @@ void CMap::Draw()
if ( !m_bEnable )
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);
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->SetState(Gfx::ENG_RSTATE_NORMAL);
@ -443,7 +446,7 @@ void CMap::DrawFocus(Math::Point pos, float dir, ObjectType type, MapColor color
bool bEnding;
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;
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;
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.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()
{
if (m_fixImage[0] != 0) return; // still image?
if (! m_fixImage.empty()) return; // still image?
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;
int x, y;
if ( m_fixImage[0] != 0 ) return; // still image?
if (! m_fixImage.empty()) return; // still image?
// TODO: map texture manipulation
return;
@ -1129,13 +1132,11 @@ void CMap::UpdateTerrain(int bx, int by, int ex, int ey)
void CMap::FlushObject()
{
int i;
m_totalFix = 0; // object index fixed
m_totalMove = MAPMAXOBJECT-2; // moving vehicles index
m_bRadar = m_main->GetRadar();
for ( i=0 ; i<MAPMAXOBJECT ; i++ )
for (int i = 0; i < MAPMAXOBJECT; i++)
{
m_map[i].bUsed = false;
}
@ -1269,7 +1270,7 @@ void CMap::UpdateObject(CObject* pObj)
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;
}

View File

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

View File

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

View File

@ -26,6 +26,8 @@
#include "ui/controls/control.h"
#include <memory>
namespace Ui
{
@ -68,8 +70,8 @@ protected:
void DrawVertex(Math::Point pos, Math::Point dim, int icon);
protected:
CButton* m_buttonUp;
CButton* m_buttonDown;
std::unique_ptr<CButton> m_buttonUp;
std::unique_ptr<CButton> m_buttonDown;
float m_visibleValue;
float m_visibleRatio;
@ -78,11 +80,8 @@ protected:
bool m_bCapture;
Math::Point m_pressPos;
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()
{
m_buttonLeft = 0;
m_buttonRight = 0;
m_min = 0.0f;
m_max = 1.0f;
m_visibleValue = 0.0f;
@ -56,18 +53,14 @@ CSlider::CSlider() : CControl()
m_marginButton = 0.0f;
m_bHoriz = false;
m_eventUp = EVENT_NULL;
m_eventDown = EVENT_NULL;
m_bCapture = false;
m_pressValue = 0.0f;
}
// Object's destructor.
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) ||
(!m_bHoriz && m_dim.y < m_dim.x*4.0f) ) // very short slider?
{
delete m_buttonLeft;
m_buttonLeft = 0;
delete m_buttonRight;
m_buttonRight = 0;
m_buttonLeft.reset();
m_buttonRight.reset();
m_marginButton = 0.0f;
}
else
{
#if 1
if ( m_buttonLeft == 0 )
if (m_buttonLeft == nullptr)
{
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->SetRepeat(true);
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->SetRepeat(true);
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);
#endif
}
if ( m_buttonLeft != 0 )
if (m_buttonLeft != nullptr)
{
if ( m_bHoriz )
{
@ -157,7 +142,7 @@ void CSlider::MoveAdjust()
m_buttonLeft->SetDim(dim);
}
if ( m_buttonRight != 0 )
if (m_buttonRight != nullptr)
{
if ( m_bHoriz )
{
@ -211,8 +196,8 @@ bool CSlider::SetState(int state, bool bState)
if ( (state & STATE_ENABLE) ||
(state & STATE_SHADOW) )
{
if ( m_buttonLeft != 0 ) m_buttonLeft->SetState(state, bState);
if ( m_buttonRight != 0 ) m_buttonRight->SetState(state, bState);
if (m_buttonLeft != nullptr) m_buttonLeft->SetState(state, bState);
if (m_buttonRight != nullptr) m_buttonRight->SetState(state, bState);
}
return CControl::SetState(state, bState);
@ -223,8 +208,8 @@ bool CSlider::SetState(int state)
if ( (state & STATE_ENABLE) ||
(state & STATE_SHADOW) )
{
if ( m_buttonLeft != 0 ) m_buttonLeft->SetState(state);
if ( m_buttonRight != 0 ) m_buttonRight->SetState(state);
if (m_buttonLeft != nullptr) m_buttonLeft->SetState(state);
if (m_buttonRight != nullptr) m_buttonRight->SetState(state);
}
return CControl::SetState(state);
@ -235,8 +220,8 @@ bool CSlider::ClearState(int state)
if ( (state & STATE_ENABLE) ||
(state & STATE_SHADOW) )
{
if ( m_buttonLeft != 0 ) m_buttonLeft->ClearState(state);
if ( m_buttonRight != 0 ) m_buttonRight->ClearState(state);
if (m_buttonLeft != nullptr) m_buttonLeft->ClearState(state);
if (m_buttonRight != nullptr) m_buttonRight->ClearState(state);
}
return CControl::ClearState(state);
@ -254,16 +239,16 @@ bool CSlider::EventProcess(const Event &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_buttonRight != 0 && !m_bCapture )
if (m_buttonRight != nullptr && !m_bCapture)
{
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;
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));
}
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;
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_buttonLeft != 0 )
if (m_buttonLeft != nullptr)
{
m_buttonLeft->Draw();
}
@ -451,7 +436,7 @@ void CSlider::Draw()
DrawVertex(ppos, ddim, 2);
}
if ( m_buttonRight != 0 )
if (m_buttonRight != nullptr)
{
m_buttonRight->Draw();
}

View File

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

View File

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

View File

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

View File

@ -75,6 +75,11 @@ CDisplayInfo::CDisplayInfo()
m_lightSuppl = -1;
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.
@ -358,7 +363,7 @@ void CDisplayInfo::StartDisplayInfo(std::string filename, int index, bool bSoluc
m_main->SetEditLock(true, false);
m_main->SetEditFull(false);
m_bInitPause = m_pause->GetPauseType();
m_initPause = m_pause->GetPauseType();
m_pause->SetPause(PAUSE_SATCOM);
m_infoCamera = m_camera->GetType();
m_camera->SetType(Gfx::CAM_TYPE_INFO);
@ -834,7 +839,7 @@ void CDisplayInfo::StopDisplayInfo()
}
else
{
m_pause->SetPause(m_bInitPause);
m_pause->SetPause(m_initPause);
m_main->SetEditLock(false, false);
}
m_camera->SetType(m_infoCamera);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -93,12 +93,7 @@ CMainUserInterface::CMainUserInterface()
m_glintMouse = Math::Point(0.0f, 0.0f);
m_glintTime = 1000.0f;
for (int i = 0; i < 10; i++)
{
m_partiPhase[i] = 0;
m_partiTime[i] = 0.0f;
}
m_shotDelay = 0;
}
// Destructor of robot application.
@ -552,27 +547,27 @@ void CMainUserInterface::FrameParticle(float rTime)
for ( i=0 ; i<10 ; i++ )
{
if ( m_partiPhase[i] == 0 ) // waiting?
if ( m_particles[i].phase == 0 ) // waiting?
{
m_partiTime[i] -= rTime;
if ( m_partiTime[i] <= 0.0f )
m_particles[i].time -= rTime;
if ( m_particles[i].time <= 0.0f )
{
r = rand()%3;
if ( r == 0 )
{
ii = rand()%nParti;
m_partiPos[i].x = pParti[ii*5+0]/640.0f;
m_partiPos[i].y = (480.0f-pParti[ii*5+1])/480.0f;
m_partiTime[i] = pParti[ii*5+2]+Math::Rand()*pParti[ii*5+3];
m_partiPhase[i] = static_cast<int>(pParti[ii*5+4]);
if ( m_partiPhase[i] == 3 )
m_particles[i].pos.x = pParti[ii*5+0]/640.0f;
m_particles[i].pos.y = (480.0f-pParti[ii*5+1])/480.0f;
m_particles[i].time = pParti[ii*5+2]+Math::Rand()*pParti[ii*5+3];
m_particles[i].phase = static_cast<int>(pParti[ii*5+4]);
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
{
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,
Math::Rand()*0.4f+0.4f, 0.0f, 0.0f,
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 )
@ -600,51 +595,51 @@ void CMainUserInterface::FrameParticle(float rTime)
if ( ii == 0 )
{
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 )
{
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 )
{
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 )
{
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 )
{
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 )
{
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 )
{
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;
if ( m_partiTime[i] > 0.0f )
m_particles[i].time -= rTime;
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.y = m_partiPos[i].y;
pos.x = m_particles[i].pos.x;
pos.y = m_particles[i].pos.y;
pos.z = 0.0f;
pos.x += (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,
Math::Rand()*0.2f+0.2f, 0.0f, 0.0f,
Gfx::SH_INTERFACE);
pos.x = m_partiPos[i].x;
pos.y = m_partiPos[i].y;
pos.x = m_particles[i].pos.x;
pos.y = m_particles[i].pos.y;
pos.z = 0.0f;
speed.x = (Math::Rand()-0.5f)*0.5f;
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,
Gfx::SH_INTERFACE);
}
if ( m_partiPhase[i] == 2 ) // sparks?
if ( m_particles[i].phase == 2 ) // sparks?
{
pos.x = m_partiPos[i].x;
pos.y = m_partiPos[i].y;
pos.x = m_particles[i].pos.x;
pos.y = m_particles[i].pos.y;
pos.z = 0.0f;
pos.x += (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,
Math::Rand()*0.2f+0.2f, 0.0f, 0.0f,
Gfx::SH_INTERFACE);
pos.x = m_partiPos[i].x;
pos.y = m_partiPos[i].y;
pos.x = m_particles[i].pos.x;
pos.y = m_particles[i].pos.y;
pos.z = 0.0f;
speed.x = (Math::Rand()-0.5f)*0.5f;
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,
Gfx::SH_INTERFACE);
}
if ( m_partiPhase[i] == 3 ) // smoke?
if ( m_particles[i].phase == 3 ) // smoke?
{
pos.x = m_partiPos[i].x;
pos.y = m_partiPos[i].y;
pos.x = m_particles[i].pos.x;
pos.y = m_particles[i].pos.y;
pos.z = 0.0f;
pos.x += (Math::Rand()-0.5f)*0.03f;
pos.y += (Math::Rand()-0.5f)*0.03f;
@ -715,8 +710,8 @@ void CMainUserInterface::FrameParticle(float rTime)
}
else
{
m_partiPhase[i] = 0;
m_partiTime[i] = 2.0f+Math::Rand()*4.0f;
m_particles[i].phase = 0;
m_particles[i].time = 2.0f+Math::Rand()*4.0f;
}
}
}

View File

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

View File

@ -34,7 +34,8 @@ namespace Ui
{
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_settings = CSettings::GetInstancePointer();
m_program = nullptr;
m_script = nullptr;
m_bEditMaximized = false;
m_bEditMinimized = false;
@ -88,8 +91,9 @@ CStudio::CStudio()
m_bRealTime = true;
m_bRunning = false;
m_fixInfoTextTime = 0.0f;
m_helpFilename[0] = 0;
m_initPause = PAUSE_NONE;
m_dialog = SD_NULL;
m_editCamera = Gfx::CAM_TYPE_NULL;
}
// Object's destructor.
@ -135,7 +139,7 @@ bool CStudio::EventProcess(const Event &event)
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?
@ -451,7 +455,7 @@ void CStudio::SearchToken(CEdit* edit)
}
if ( level > 0 )
{
m_helpFilename[0] = 0;
m_helpFilename = "";
SetInfoText("", true);
return;
}
@ -552,7 +556,7 @@ void CStudio::StartEditScript(CScript *script, std::string name, Program* progra
m_main->SetEditLock(true, true);
m_main->SetEditFull(false);
m_bInitPause = m_pause->GetPauseType();
m_initPause = m_pause->GetPauseType();
m_main->SetSpeed(1.0f);
m_editCamera = m_camera->GetType();
m_camera->SetType(Gfx::CAM_TYPE_EDIT);
@ -884,7 +888,7 @@ bool CStudio::StopEditScript(bool bCancel)
m_interface->DeleteControl(EVENT_WINDOW3);
m_pause->SetPause(m_bInitPause);
m_pause->SetPause(m_initPause);
m_sound->MuteAll(false);
m_main->SetEditLock(false, true);
m_camera->SetType(m_editCamera);

View File

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