From c2464d4c71bbc0154287f0b0441aef05e27cf084 Mon Sep 17 00:00:00 2001 From: erihel Date: Fri, 17 Aug 2012 22:43:07 +0200 Subject: * changes to ui classes --- src/ui/button.h | 2 +- src/ui/check.h | 2 +- src/ui/color.h | 2 +- src/ui/compass.h | 2 +- src/ui/control.h | 14 +- src/ui/displayinfo.h | 2 +- src/ui/displaytext.h | 2 +- src/ui/edit.h | 19 +- src/ui/editvalue.h | 5 +- src/ui/gauge.h | 2 +- src/ui/group.h | 2 +- src/ui/image.h | 7 +- src/ui/interface.cpp | 550 +++++++++++++-------------------------------------- src/ui/interface.h | 135 +++++++------ src/ui/key.cpp | 179 ++++++----------- src/ui/key.h | 37 ++-- src/ui/label.cpp | 51 ++--- src/ui/label.h | 24 +-- src/ui/list.h | 118 ++++++----- src/ui/map.h | 14 +- src/ui/scroll.h | 71 ++++--- src/ui/shortcut.h | 27 ++- src/ui/slider.h | 75 ++++--- src/ui/target.h | 27 ++- src/ui/window.h | 73 +++---- 25 files changed, 541 insertions(+), 901 deletions(-) (limited to 'src/ui') diff --git a/src/ui/button.h b/src/ui/button.h index 38b2dab..4f1740d 100644 --- a/src/ui/button.h +++ b/src/ui/button.h @@ -29,7 +29,7 @@ class CButton : public CControl { public: - CButton(CInstanceManager* iMan); + CButton(); virtual ~CButton(); bool Create(Math::Point pos, Math::Point dim, int icon, EventType eventType); diff --git a/src/ui/check.h b/src/ui/check.h index 3af6849..66375c0 100644 --- a/src/ui/check.h +++ b/src/ui/check.h @@ -29,7 +29,7 @@ class CD3DEngine; class CCheck : public CControl { public: - CCheck(CInstanceManager* iMan); + CCheck(); virtual ~CCheck(); bool Create(Math::Point pos, Math::Point dim, int icon, EventType eventType); diff --git a/src/ui/color.h b/src/ui/color.h index 151a4df..740b7e9 100644 --- a/src/ui/color.h +++ b/src/ui/color.h @@ -30,7 +30,7 @@ class CColor : public CControl { public: - CColor(CInstanceManager* iMan); + CColor(); virtual ~CColor(); bool Create(Math::Point pos, Math::Point dim, int icon, EventType eventType); diff --git a/src/ui/compass.h b/src/ui/compass.h index ac5f608..fcbf860 100644 --- a/src/ui/compass.h +++ b/src/ui/compass.h @@ -29,7 +29,7 @@ class CCompass : public CControl { public: - CCompass(CInstanceManager* iMan); + CCompass(); virtual ~CCompass(); bool Create(Math::Point pos, Math::Point dim, int icon, EventType eventType); diff --git a/src/ui/control.h b/src/ui/control.h index b211ff6..ef49b65 100644 --- a/src/ui/control.h +++ b/src/ui/control.h @@ -26,12 +26,14 @@ #include "graphics/engine/text.h" #include "graphics/engine/particle.h" +#include "sound/sound.h" + class CInstanceManager; class CEvent; //class Gfx::CEngine; class CRobotMain; //class Gfx::CParticle; -class CSound; +//class CSound; enum ControlState @@ -60,7 +62,7 @@ enum ControlState class CControl { public: - CControl(CInstanceManager* iMan); + CControl(); virtual ~CControl(); virtual bool Create(Math::Point pos, Math::Point dim, int icon, EventType eventType); @@ -78,8 +80,8 @@ public: virtual int GetState(); virtual void SetIcon(int icon); virtual int GetIcon(); - virtual void SetName(char* name, bool bTooltip=true); - virtual char* GetName(); + virtual void SetName(const char* name, bool bTooltip=true); + virtual const char* GetName(); virtual void SetTextAlign(Gfx::TextAlign mode); virtual int GetTextAlign(); virtual void SetFontSize(float size); @@ -88,8 +90,8 @@ public: virtual float GetFontStretch(); virtual void SetFontType(Gfx::FontType font); virtual Gfx::FontType GetFontType(); - virtual bool SetTooltip(char* name); - virtual bool GetTooltip(Math::Point pos, char* name); + virtual bool SetTooltip(const char* name); + virtual bool GetTooltip(Math::Point pos, const char* name); virtual void SetFocus(bool bFocus); virtual bool GetFocus(); diff --git a/src/ui/displayinfo.h b/src/ui/displayinfo.h index 29677d4..dbc9bed 100644 --- a/src/ui/displayinfo.h +++ b/src/ui/displayinfo.h @@ -37,7 +37,7 @@ class CLight; class CDisplayInfo { public: - CDisplayInfo(CInstanceManager* iMan); + CDisplayInfo(); ~CDisplayInfo(); bool EventProcess(const Event &event); diff --git a/src/ui/displaytext.h b/src/ui/displaytext.h index c2eea98..93a3c8b 100644 --- a/src/ui/displaytext.h +++ b/src/ui/displaytext.h @@ -45,7 +45,7 @@ const int MAXDTLINE = 4; class CDisplayText { public: - CDisplayText(CInstanceManager* iMan); + CDisplayText(); ~CDisplayText(); void DeleteObject(); diff --git a/src/ui/edit.h b/src/ui/edit.h index dbd94d1..73bd062 100644 --- a/src/ui/edit.h +++ b/src/ui/edit.h @@ -19,14 +19,11 @@ #pragma once -#include "common/struct.h" -#include "ui/control.h" - - -class CD3DEngine; -class CScroll; - +#include +#include +#include +#include const int EDITSTUDIOMAX = 20000; // maximum number of characters in CBOT edit const int EDITLINEMAX = 1000; // maximum total number of lines @@ -85,10 +82,10 @@ struct HyperHistory class CEdit : public CControl { public: - CEdit(CInstanceManager* iMan); + CEdit(); virtual ~CEdit(); - bool Create(Math::Point pos, Math::Point dim, int icon, EventMsg eventMsg); + bool Create(Math::Point pos, Math::Point dim, int icon, EventType eventMsg); void SetPos(Math::Point pos); void SetDim(Math::Point dim); @@ -145,8 +142,8 @@ public: void HyperFlush(); void HyperHome(char *filename); - bool HyperTest(EventMsg event); - bool HyperGo(EventMsg event); + bool HyperTest(EventType event); + bool HyperGo(EventType event); void SetFontSize(float size); diff --git a/src/ui/editvalue.h b/src/ui/editvalue.h index dbb7812..758450a 100644 --- a/src/ui/editvalue.h +++ b/src/ui/editvalue.h @@ -21,6 +21,7 @@ #include "ui/control.h" +#include "common/event.h" enum EditValueType { @@ -39,10 +40,10 @@ class CButton; class CEditValue : public CControl { public: - CEditValue(CInstanceManager* iMan); + CEditValue(); virtual ~CEditValue(); - bool Create(Math::Point pos, Math::Point dim, int icon, EventMsg eventMsg); + bool Create(Math::Point pos, Math::Point dim, int icon, EventType eventMsg); void SetPos(Math::Point pos); void SetDim(Math::Point dim); diff --git a/src/ui/gauge.h b/src/ui/gauge.h index 1686c56..26ce8e9 100644 --- a/src/ui/gauge.h +++ b/src/ui/gauge.h @@ -29,7 +29,7 @@ class CGauge : public CControl { public: - CGauge(CInstanceManager* iMan); + CGauge(); virtual ~CGauge(); bool Create(Math::Point pos, Math::Point dim, int icon, EventType eventType); diff --git a/src/ui/group.h b/src/ui/group.h index b54829d..12c4003 100644 --- a/src/ui/group.h +++ b/src/ui/group.h @@ -29,7 +29,7 @@ class CD3DEngine; class CGroup : public CControl { public: - CGroup(CInstanceManager* iMan); + CGroup(); virtual ~CGroup(); bool Create(Math::Point pos, Math::Point dim, int icon, EventType eventType); diff --git a/src/ui/image.h b/src/ui/image.h index 85c5962..b6b88c3 100644 --- a/src/ui/image.h +++ b/src/ui/image.h @@ -19,8 +19,9 @@ #pragma once -#include "ui/control.h" +#include +#include class CD3DEngine; @@ -29,10 +30,10 @@ class CD3DEngine; class CImage : public CControl { public: - CImage(CInstanceManager* iMan); + CImage(); virtual ~CImage(); - bool Create(Math::Point pos, Math::Point dim, int icon, EventMsg eventMsg); + bool Create(Math::Point pos, Math::Point dim, int icon, EventType eventMsg); bool EventProcess(const Event &event); diff --git a/src/ui/interface.cpp b/src/ui/interface.cpp index 50d2352..afedfc9 100644 --- a/src/ui/interface.cpp +++ b/src/ui/interface.cpp @@ -1,5 +1,6 @@ // * This file is part of the COLOBOT source code // * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch +// * Copyright (C) 2012 Polish Portal of Colobot (PPC) // * // * This program is free software: you can redistribute it and/or modify // * it under the terms of the GNU General Public License as published by @@ -17,55 +18,19 @@ // interface.cpp -#include -#include -#include - -#include "common/struct.h" -#include "old/d3dengine.h" -#include "old/math3d.h" -#include "common/event.h" -#include "common/misc.h" -#include "common/iman.h" -#include "ui/control.h" -#include "ui/button.h" -#include "ui/color.h" -#include "ui/check.h" -#include "ui/key.h" -#include "ui/group.h" -#include "ui/image.h" -#include "ui/label.h" -#include "ui/edit.h" -#include "ui/editvalue.h" -#include "ui/scroll.h" -#include "ui/slider.h" -#include "ui/list.h" -#include "ui/shortcut.h" -#include "ui/compass.h" -#include "ui/target.h" -#include "ui/map.h" -#include "ui/window.h" -#include "old/camera.h" -#include "ui/interface.h" - - - - -// Object's constructor. - -CInterface::CInterface(CInstanceManager* iMan) -{ - int i; +#include - m_iMan = iMan; - m_iMan->AddInstance(CLASS_INTERFACE, this); - m_engine = (CD3DEngine*)m_iMan->SearchInstance(CLASS_ENGINE); - m_camera = 0; +CInterface::CInterface() +{ + m_iMan = CInstanceManager::GetInstancePointer(); + m_iMan->AddInstance(CLASS_INTERFACE, this); + m_event = static_cast( m_iMan->SearchInstance(CLASS_EVENT) ); + m_engine = static_cast( m_iMan->SearchInstance(CLASS_ENGINE) ); - for ( i=0 ; iDeleteInstance(CLASS_INTERFACE, this); } @@ -81,424 +47,222 @@ CInterface::~CInterface() void CInterface::Flush() { - int i; - - for ( i=0 ; iCreate(pos, dim, icon, eventMsg); - return pc; - } + for (int i = 10; i < MAXCONTROL-1; i++) { + if (m_table[i] == nullptr) + return i; } - return 0; + return -1; } -// Creates a new button. -CButton* CInterface::CreateButton(Math::Point pos, Math::Point dim, int icon, EventMsg eventMsg) +template inline T* CInterface::CreateControl(Math::Point pos, Math::Point dim, int icon, EventType eventMsg) { - CButton* pc; - int i; + T* pc; + int index; + Event event; - if ( eventMsg == EVENT_NULL ) eventMsg = GetUniqueEventMsg(); - - for ( i=10 ; iCreate(pos, dim, icon, eventMsg); - return pc; - } + if (eventMsg == EVENT_NULL) { + m_event->GetEvent(event); + eventMsg = event.type; } - return 0; + + if ((index = GetNextFreeControl()) < 0) + return nullptr; + + m_table[index] = new T(); + pc = static_cast(m_table[index]); + pc->Create(pos, dim, icon, eventMsg); + return pc; } + // Creates a new button. -CColor* CInterface::CreateColor(Math::Point pos, Math::Point dim, int icon, EventMsg eventMsg) +CWindow* CInterface::CreateWindows(Math::Point pos, Math::Point dim, int icon, EventType eventMsg) { - CColor* pc; - int i; + CWindow* pc; + int index; + Event event; - if ( eventMsg == EVENT_NULL ) eventMsg = GetUniqueEventMsg(); + if (eventMsg == EVENT_NULL) { + m_event->GetEvent(event); + eventMsg = event.type; + } - for ( i=10 ; iCreate(pos, dim, icon, eventMsg); - return pc; - } + switch (eventMsg) { + case EVENT_WINDOW0: index = 0; break; + case EVENT_WINDOW1: index = 1; break; + case EVENT_WINDOW2: index = 2; break; + case EVENT_WINDOW3: index = 3; break; + case EVENT_WINDOW4: index = 4; break; + case EVENT_WINDOW5: index = 5; break; + case EVENT_WINDOW6: index = 6; break; + case EVENT_WINDOW7: index = 7; break; + case EVENT_WINDOW8: index = 8; break; + case EVENT_WINDOW9: index = 9; break; + case EVENT_TOOLTIP: index = MAXCONTROL-1; break; + default: index = GetNextFreeControl(); break; } - return 0; + + if (index < 0) + return nullptr; + + m_table[index] = new CWindow(); + pc = static_cast(m_table[index]); + pc->Create(pos, dim, icon, eventMsg); + return pc; } // Creates a new button. -CCheck* CInterface::CreateCheck(Math::Point pos, Math::Point dim, int icon, EventMsg eventMsg) +CButton* CInterface::CreateButton(Math::Point pos, Math::Point dim, int icon, EventType eventMsg) { - CCheck* pc; - int i; - - if ( eventMsg == EVENT_NULL ) eventMsg = GetUniqueEventMsg(); - - for ( i=10 ; iCreate(pos, dim, icon, eventMsg); - return pc; - } - } - return 0; + return CreateControl(pos, dim, icon, eventMsg); } // Creates a new button. -CKey* CInterface::CreateKey(Math::Point pos, Math::Point dim, int icon, EventMsg eventMsg) +CColor* CInterface::CreateColor(Math::Point pos, Math::Point dim, int icon, EventType eventMsg) { - CKey* pc; - int i; - - if ( eventMsg == EVENT_NULL ) eventMsg = GetUniqueEventMsg(); - - for ( i=10 ; iCreate(pos, dim, icon, eventMsg); - return pc; - } - } - return 0; + return CreateControl(pos, dim, icon, eventMsg); } // Creates a new button. -CGroup* CInterface::CreateGroup(Math::Point pos, Math::Point dim, int icon, EventMsg eventMsg) +CCheck* CInterface::CreateCheck(Math::Point pos, Math::Point dim, int icon, EventType eventMsg) { - CGroup* pc; - int i; + return CreateControl(pos, dim, icon, eventMsg); +} - if ( eventMsg == EVENT_NULL ) eventMsg = GetUniqueEventMsg(); +// Creates a new button. - for ( i=10 ; iCreate(pos, dim, icon, eventMsg); - return pc; - } - } - return 0; +CKey* CInterface::CreateKey(Math::Point pos, Math::Point dim, int icon, EventType eventMsg) +{ + return CreateControl(pos, dim, icon, eventMsg); } // Creates a new button. -CImage* CInterface::CreateImage(Math::Point pos, Math::Point dim, int icon, EventMsg eventMsg) +CGroup* CInterface::CreateGroup(Math::Point pos, Math::Point dim, int icon, EventType eventMsg) { - CImage* pc; - int i; + return CreateControl(pos, dim, icon, eventMsg); +} - if ( eventMsg == EVENT_NULL ) eventMsg = GetUniqueEventMsg(); +// Creates a new button. - for ( i=10 ; iCreate(pos, dim, icon, eventMsg); - return pc; - } - } - return 0; +CImage* CInterface::CreateImage(Math::Point pos, Math::Point dim, int icon, EventType eventMsg) +{ + return CreateControl(pos, dim, icon, eventMsg); } // Creates a new label. -CLabel* CInterface::CreateLabel(Math::Point pos, Math::Point dim, int icon, EventMsg eventMsg, - char *name) +CLabel* CInterface::CreateLabel(Math::Point pos, Math::Point dim, int icon, EventType eventMsg, const char *name) { - CLabel* pc; - int i; - - if ( eventMsg == EVENT_NULL ) eventMsg = GetUniqueEventMsg(); - - for ( i=10 ; iCreate(pos, dim, icon, eventMsg); - pc->SetName(name); - return pc; - } - } - return 0; + CLabel* pc = CreateControl(pos, dim, icon, eventMsg); + if (pc != nullptr) + pc->SetName(name); + return pc; } // Creates a new pave editable. -CEdit* CInterface::CreateEdit(Math::Point pos, Math::Point dim, int icon, EventMsg eventMsg) +CEdit* CInterface::CreateEdit(Math::Point pos, Math::Point dim, int icon, EventType eventMsg) { - CEdit* pc; - int i; - - if ( eventMsg == EVENT_NULL ) eventMsg = GetUniqueEventMsg(); - - for ( i=10 ; iCreate(pos, dim, icon, eventMsg); - return pc; - } - } - return 0; + return CreateControl(pos, dim, icon, eventMsg); } // Creates a new pave editable. -CEditValue* CInterface::CreateEditValue(Math::Point pos, Math::Point dim, int icon, EventMsg eventMsg) +CEditValue* CInterface::CreateEditValue(Math::Point pos, Math::Point dim, int icon, EventType eventMsg) { - CEditValue* pc; - int i; - - if ( eventMsg == EVENT_NULL ) eventMsg = GetUniqueEventMsg(); - - for ( i=10 ; iCreate(pos, dim, icon, eventMsg); - return pc; - } - } - return 0; + return CreateControl(pos, dim, icon, eventMsg); } // Creates a new lift. -CScroll* CInterface::CreateScroll(Math::Point pos, Math::Point dim, int icon, EventMsg eventMsg) +CScroll* CInterface::CreateScroll(Math::Point pos, Math::Point dim, int icon, EventType eventMsg) { - CScroll* pc; - int i; - - if ( eventMsg == EVENT_NULL ) eventMsg = GetUniqueEventMsg(); - - for ( i=10 ; iCreate(pos, dim, icon, eventMsg); - return pc; - } - } - return 0; + return CreateControl(pos, dim, icon, eventMsg); } // Creates a new cursor. -CSlider* CInterface::CreateSlider(Math::Point pos, Math::Point dim, int icon, EventMsg eventMsg) +CSlider* CInterface::CreateSlider(Math::Point pos, Math::Point dim, int icon, EventType eventMsg) { - CSlider* pc; - int i; - - if ( eventMsg == EVENT_NULL ) eventMsg = GetUniqueEventMsg(); - - for ( i=10 ; iCreate(pos, dim, icon, eventMsg); - return pc; - } - } - return 0; + return CreateControl(pos, dim, icon, eventMsg); } // Creates a new list. -CList* CInterface::CreateList(Math::Point pos, Math::Point dim, int icon, EventMsg eventMsg, - float expand) +CList* CInterface::CreateList(Math::Point pos, Math::Point dim, int icon, EventType eventMsg, float expand) { - CList* pc; - int i; + CList* pc; + int index; + Event event; - if ( eventMsg == EVENT_NULL ) eventMsg = GetUniqueEventMsg(); - - for ( i=10 ; iCreate(pos, dim, icon, eventMsg, expand); - return pc; - } + if (eventMsg == EVENT_NULL) { + m_event->GetEvent(event); + eventMsg = event.type; } - return 0; + + if ((index = GetNextFreeControl()) < 0) + return nullptr; + + m_table[index] = new CList(); + pc = static_cast(m_table[index]); + pc->Create(pos, dim, icon, eventMsg, expand); + return pc; } // Creates a new shortcut. -CShortcut* CInterface::CreateShortcut(Math::Point pos, Math::Point dim, int icon, EventMsg eventMsg) +CShortcut* CInterface::CreateShortcut(Math::Point pos, Math::Point dim, int icon, EventType eventMsg) { - CShortcut* ps; - int i; - - if ( eventMsg == EVENT_NULL ) eventMsg = GetUniqueEventMsg(); - - for ( i=10 ; iCreate(pos, dim, icon, eventMsg); - return ps; - } - } - return 0; + return CreateControl(pos, dim, icon, eventMsg); } // Creates a new compass. -CCompass* CInterface::CreateCompass(Math::Point pos, Math::Point dim, int icon, EventMsg eventMsg) +CCompass* CInterface::CreateCompass(Math::Point pos, Math::Point dim, int icon, EventType eventMsg) { - CCompass* pc; - int i; - - if ( eventMsg == EVENT_NULL ) eventMsg = GetUniqueEventMsg(); - - for ( i=10 ; iCreate(pos, dim, icon, eventMsg); - return pc; - } - } - return 0; + return CreateControl(pos, dim, icon, eventMsg); } // Creates a new target. -CTarget* CInterface::CreateTarget(Math::Point pos, Math::Point dim, int icon, EventMsg eventMsg) +CTarget* CInterface::CreateTarget(Math::Point pos, Math::Point dim, int icon, EventType eventMsg) { - CTarget* pc; - int i; - - if ( eventMsg == EVENT_NULL ) eventMsg = GetUniqueEventMsg(); - - for ( i=10 ; iCreate(pos, dim, icon, eventMsg); - return pc; - } - } - return 0; + return CreateControl(pos, dim, icon, eventMsg); } // Creates a new map. -CMap* CInterface::CreateMap(Math::Point pos, Math::Point dim, int icon, EventMsg eventMsg) +CMap* CInterface::CreateMap(Math::Point pos, Math::Point dim, int icon, EventType eventMsg) { - CMap* pm; - int i; - - if ( eventMsg == EVENT_NULL ) eventMsg = GetUniqueEventMsg(); - - for ( i=10 ; iCreate(pos, dim, icon, eventMsg); - return pm; - } - } - return 0; + return CreateControl(pos, dim, icon, eventMsg); } // Removes a control. -bool CInterface::DeleteControl(EventMsg eventMsg) +bool CInterface::DeleteControl(EventType eventMsg) { - int i; - - for ( i=0 ; iRetEventMsg() ) - { + for (int i = 0; i < MAXCONTROL; i++) { + if ( m_table[i] != nullptr ) { + if (eventMsg == m_table[i]->GetEventType()) { delete m_table[i]; - m_table[i] = 0; + m_table[i] = nullptr; return true; } } @@ -508,47 +272,32 @@ bool CInterface::DeleteControl(EventMsg eventMsg) // Gives a control. -CControl* CInterface::SearchControl(EventMsg eventMsg) +CControl* CInterface::SearchControl(EventType eventMsg) { - int i; - - for ( i=0 ; iRetEventMsg() ) - { + for (int i = 0; i < MAXCONTROL; i++) { + if (m_table[i] != nullptr) { + if (eventMsg == m_table[i]->GetEventType()) return m_table[i]; - } } } - return 0; + return nullptr; } // Management of an event. bool CInterface::EventProcess(const Event &event) { - int i; - - if ( event.event == EVENT_MOUSEMOVE ) - { - if ( m_camera == 0 ) - { - m_camera = (CCamera*)m_iMan->SearchInstance(CLASS_CAMERA); + if (event.type == EVENT_MOUSE_MOVE) { + if (m_camera == nullptr) { + m_camera = static_cast(m_iMan->SearchInstance(CLASS_CAMERA)); } - m_engine->SetMouseType(m_camera->RetMouseDef(event.pos)); + m_engine->SetMouseType(m_camera->GetMouseDef(event.pos)); } - for ( i=MAXCONTROL-1 ; i>=0 ; i-- ) - { - if ( m_table[i] != 0 && - m_table[i]->TestState(STATE_ENABLE) ) - { + for (int i = MAXCONTROL-1; i >= 0; i--) { + if (m_table[i] != nullptr && m_table[i]->TestState(STATE_ENABLE)) { if ( !m_table[i]->EventProcess(event) ) - { return false; - } } } @@ -558,18 +307,12 @@ bool CInterface::EventProcess(const Event &event) // Gives the tooltip binding to the window. -bool CInterface::GetTooltip(Math::Point pos, char* name) +bool CInterface::GetTooltip(Math::Point pos, const char* name) { - int i; - - for ( i=MAXCONTROL-1 ; i>=0 ; i-- ) - { - if ( m_table[i] != 0 ) - { - if ( m_table[i]->GetTooltip(pos, name) ) - { + for (int i = MAXCONTROL-1; i >= 0; i--) { + if (m_table[i] != nullptr) { + if (m_table[i]->GetTooltip(pos, name)) return true; - } } } return false; @@ -580,26 +323,17 @@ bool CInterface::GetTooltip(Math::Point pos, char* name) void CInterface::Draw() { - D3DMATERIAL7 material; - int i; - - ZeroMemory( &material, sizeof(D3DMATERIAL7) ); + /*ZeroMemory( &material, sizeof(D3DMATERIAL7) ); material.diffuse.r = 1.0f; material.diffuse.g = 1.0f; material.diffuse.b = 1.0f; material.ambient.r = 0.5f; material.ambient.g = 0.5f; material.ambient.b = 0.5f; - m_engine->SetMaterial(material); + m_engine->SetMaterial(material);*/ - for ( i=0 ; i=0 ; i-- ) - { - if ( m_table[i] != 0 ) - { + for (int i = 0; i < MAXCONTROL; i++) { + if ( m_table[i] != nullptr ) m_table[i]->Draw(); - } } } - - diff --git a/src/ui/interface.h b/src/ui/interface.h index 8aa7f44..d8f4d62 100644 --- a/src/ui/interface.h +++ b/src/ui/interface.h @@ -1,5 +1,6 @@ // * This file is part of the COLOBOT source code // * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch +// * Copyright (C) 2012 Polish Portal of Colobot (PPC) // * // * This program is free software: you can redistribute it and/or modify // * it under the terms of the GNU General Public License as published by @@ -19,32 +20,34 @@ #pragma once -#include "common/event.h" -#include "math/point.h" - - -class CInstanceManager; -class CD3DEngine; -class CControl; -class CWindow; -class CButton; -class CColor; -class CCheck; -class CKey; -class CGroup; -class CImage; -class CLabel; -class CEdit; -class CEditValue; -class CScroll; -class CSlider; -class CList; -class CShortcut; -class CMap; -class CGauge; -class CCompass; -class CTarget; -class CCamera; +#include +#include +#include +#include + +#include + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include const int MAXCONTROL = 100; @@ -52,44 +55,48 @@ const int MAXCONTROL = 100; class CInterface { -public: - CInterface(CInstanceManager* iMan); - ~CInterface(); - - bool EventProcess(const Event &event); - bool GetTooltip(Math::Point pos, char* name); - - void Flush(); - CWindow* CreateWindows(Math::Point pos, Math::Point dim, int icon, EventMsg eventMsg); - CButton* CreateButton(Math::Point pos, Math::Point dim, int icon, EventMsg eventMsg); - CColor* CreateColor(Math::Point pos, Math::Point dim, int icon, EventMsg eventMsg); - CCheck* CreateCheck(Math::Point pos, Math::Point dim, int icon, EventMsg eventMsg); - CKey* CreateKey(Math::Point pos, Math::Point dim, int icon, EventMsg eventMsg); - CGroup* CreateGroup(Math::Point pos, Math::Point dim, int icon, EventMsg eventMsg); - CImage* CreateImage(Math::Point pos, Math::Point dim, int icon, EventMsg eventMsg); - CLabel* CreateLabel(Math::Point pos, Math::Point dim, int icon, EventMsg eventMsg, char *name); - CEdit* CreateEdit(Math::Point pos, Math::Point dim, int icon, EventMsg eventMsg); - CEditValue* CreateEditValue(Math::Point pos, Math::Point dim, int icon, EventMsg eventMsg); - CScroll* CreateScroll(Math::Point pos, Math::Point dim, int icon, EventMsg eventMsg); - CSlider* CreateSlider(Math::Point pos, Math::Point dim, int icon, EventMsg eventMsg); - CList* CreateList(Math::Point pos, Math::Point dim, int icon, EventMsg eventMsg, float expand=1.2f); - CShortcut* CreateShortcut(Math::Point pos, Math::Point dim, int icon, EventMsg eventMsg); - CCompass* CreateCompass(Math::Point pos, Math::Point dim, int icon, EventMsg eventMsg); - CTarget* CreateTarget(Math::Point pos, Math::Point dim, int icon, EventMsg eventMsg); - CMap* CreateMap(Math::Point pos, Math::Point dim, int icon, EventMsg eventMsg); - bool DeleteControl(EventMsg eventMsg); - CControl* SearchControl(EventMsg eventMsg); - - void Draw(); - -protected: - -protected: - CInstanceManager* m_iMan; - CD3DEngine* m_engine; - CCamera* m_camera; - - CControl* m_table[MAXCONTROL]; + public: + CInterface(); + ~CInterface(); + + bool EventProcess(const Event &event); + bool GetTooltip(Math::Point pos, const char* name); + + void Flush(); + CButton* CreateButton(Math::Point pos, Math::Point dim, int icon, EventType eventMsg); + CColor* CreateColor(Math::Point pos, Math::Point dim, int icon, EventType eventMsg); + CCheck* CreateCheck(Math::Point pos, Math::Point dim, int icon, EventType eventMsg); + CKey* CreateKey(Math::Point pos, Math::Point dim, int icon, EventType eventMsg); + CGroup* CreateGroup(Math::Point pos, Math::Point dim, int icon, EventType eventMsg); + CImage* CreateImage(Math::Point pos, Math::Point dim, int icon, EventType eventMsg); + CEdit* CreateEdit(Math::Point pos, Math::Point dim, int icon, EventType eventMsg); + CEditValue* CreateEditValue(Math::Point pos, Math::Point dim, int icon, EventType eventMsg); + CScroll* CreateScroll(Math::Point pos, Math::Point dim, int icon, EventType eventMsg); + CSlider* CreateSlider(Math::Point pos, Math::Point dim, int icon, EventType eventMsg); + CShortcut* CreateShortcut(Math::Point pos, Math::Point dim, int icon, EventType eventMsg); + CCompass* CreateCompass(Math::Point pos, Math::Point dim, int icon, EventType eventMsg); + CTarget* CreateTarget(Math::Point pos, Math::Point dim, int icon, EventType eventMsg); + CMap* CreateMap(Math::Point pos, Math::Point dim, int icon, EventType eventMsg); + + CWindow* CreateWindows(Math::Point pos, Math::Point dim, int icon, EventType eventMsg); + CList* CreateList(Math::Point pos, Math::Point dim, int icon, EventType eventMsg, float expand=1.2f); + CLabel* CreateLabel(Math::Point pos, Math::Point dim, int icon, EventType eventMsg, const char *name); + + bool DeleteControl(EventType eventMsg); + CControl* SearchControl(EventType eventMsg); + + void Draw(); + + protected: + int GetNextFreeControl(); + template inline T* CreateControl(Math::Point pos, Math::Point dim, int icon, EventType eventMsg); + + CInstanceManager* m_iMan; + CEventQueue* m_event; + Gfx::CEngine* m_engine; + Gfx::CCamera* m_camera; + + CControl* m_table[MAXCONTROL]; }; diff --git a/src/ui/key.cpp b/src/ui/key.cpp index a1eebb3..0d73ed0 100644 --- a/src/ui/key.cpp +++ b/src/ui/key.cpp @@ -1,5 +1,6 @@ // * This file is part of the COLOBOT source code // * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch +// * Copyright (C) 2012 Polish Portal of Colobot (PPC) // * // * This program is free software: you can redistribute it and/or modify // * it under the terms of the GNU General Public License as published by @@ -17,54 +18,32 @@ // key.cpp -#include -#include -#include +#include -#include "common/struct.h" -#include "old/d3dengine.h" -#include "old/math3d.h" -#include "common/event.h" -#include "common/misc.h" -#include "common/iman.h" -#include "common/restext.h" -#include "old/sound.h" -#include "old/text.h" -#include "ui/key.h" - - - - -// Constructs the name of a button. void GetKeyName(char *name, int key) { - if ( !GetResource(RES_KEY, key, name) ) - { - if ( (key >= '0' && key <= '9') || - (key >= 'A' && key <= 'Z') || - (key >= 'a' && key <= 'z') ) - { + if ( !GetResource(RES_KEY, key, name) ) { + if (isalnum(key)) { name[0] = key; name[1] = 0; } - else - { + else { sprintf(name, "Code %d", key); } } } - - // Object's constructor. -CKey::CKey(CInstanceManager* iMan) : CControl(iMan) +CKey::CKey() : CControl() { m_key[0] = 0; m_key[1] = 0; m_bCatch = false; + + m_app = CApplication::GetInstancePointer(); } // Object's destructor. @@ -76,18 +55,18 @@ CKey::~CKey() // Creates a new button. -bool CKey::Create(Math::Point pos, Math::Point dim, int icon, EventMsg eventMsg) +bool CKey::Create(Math::Point pos, Math::Point dim, int icon, EventType eventMsg) { - char name[100]; - char* p; + char name[100]; + Event event; - if ( eventMsg == EVENT_NULL ) eventMsg = GetUniqueEventMsg(); + if (eventMsg == EVENT_NULL) { + m_event->GetEvent(event); + eventMsg = event.type; + } CControl::Create(pos, dim, icon, eventMsg); - GetResource(RES_EVENT, eventMsg, name); - p = strchr(name, '\\'); - if ( p != 0 ) *p = 0; SetName(name); return true; @@ -98,24 +77,17 @@ bool CKey::Create(Math::Point pos, Math::Point dim, int icon, EventMsg eventMsg) bool CKey::EventProcess(const Event &event) { - if ( m_state & STATE_DEAD ) return true; + if (m_state & STATE_DEAD) + return true; CControl::EventProcess(event); - if ( event.event == EVENT_LBUTTONDOWN ) - { - if ( Detect(event.pos) ) - { - m_bCatch = true; - } - else - { - m_bCatch = false; - } + if (event.type == EVENT_MOUSE_BUTTON_DOWN) { + if (event.mouseButton.button == 1) // left + m_bCatch = Detect(event.pos); } - if ( event.event == EVENT_KEYDOWN && m_bCatch ) - { + if (event.type == EVENT_MOUSE_BUTTON_DOWN && m_bCatch) { m_bCatch = false; if ( TestKey(event.param) ) // impossible ? @@ -124,21 +96,17 @@ bool CKey::EventProcess(const Event &event) } else { - if ( event.param == m_key[0] || - event.param == m_key[1] ) - { + if ( event.param == m_key[0] || event.param == m_key[1] ) { m_key[0] = event.param; m_key[1] = 0; - } - else - { + } else { m_key[1] = m_key[0]; m_key[0] = event.param; } m_sound->Play(SOUND_CLICK); Event newEvent = event; - newEvent.event = m_eventMsg; + newEvent.type = m_eventType; m_event->AddEvent(newEvent); } return false; @@ -152,25 +120,17 @@ bool CKey::EventProcess(const Event &event) bool CKey::TestKey(int key) { - int i, j; + if ( key == VK_PAUSE || key == VK_SNAPSHOT ) return true; // blocked key - if ( key == VK_PAUSE || - key == VK_SNAPSHOT ) return true; // blocked key - - for ( i=0 ; i<20 ; i++ ) - { - for ( j=0 ; j<2 ; j++ ) - { - if ( key == m_engine->RetKey(i, j) ) // key used? - { - m_engine->SetKey(i, j, 0); // nothing! - } + for (int i = 0; i < 20; i++) { + for (int j = 0; j < 2; j++) { + if (key == m_app->GetKey(i, j) ) // key used? + m_app->SetKey(i, j, 0); // nothing! } - if ( m_engine->RetKey(i, 0) == 0 ) // first free option? - { - m_engine->SetKey(i, 0, m_engine->RetKey(i, 1)); // shift - m_engine->SetKey(i, 1, 0); + if ( m_app->GetKey(i, 0) == 0 ) { // first free option? + m_app->SetKey(i, 0, m_app->GetKey(i, 1)); // shift + m_app->SetKey(i, 1, 0); } } @@ -182,106 +142,97 @@ bool CKey::TestKey(int key) void CKey::Draw() { - Math::Point iDim, pos; - float zoomExt, zoomInt, h; - int icon; - char text[100]; + Math::Point iDim, pos; + float zoomExt, zoomInt, h; + int icon; + char text[100]; - if ( (m_state & STATE_VISIBLE) == 0 ) return; + if ( (m_state & STATE_VISIBLE) == 0 ) + return; iDim = m_dim; m_dim.x = 200.0f/640.0f; if ( m_state & STATE_SHADOW ) - { DrawShadow(m_pos, m_dim); - } + m_engine->SetTexture("button1.tga"); - m_engine->SetState(D3DSTATENORMAL); + m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); // was D3DSTATENORMAL zoomExt = 1.00f; zoomInt = 0.95f; icon = 2; - if ( m_key[0] == 0 && - m_key[1] == 0 ) // no shortcut? - { + if ( m_key[0] == 0 && m_key[1] == 0 ) // no shortcut? icon = 3; - } - if ( m_state & STATE_DEFAULT ) - { + + if ( m_state & STATE_DEFAULT ) { DrawPart(23, 1.3f, 0.0f); zoomExt *= 1.15f; zoomInt *= 1.15f; } + if ( m_state & STATE_HILIGHT ) - { icon = 1; - } + if ( m_state & STATE_CHECK ) - { icon = 0; - } - if ( m_state & STATE_PRESS ) - { + + if ( m_state & STATE_PRESS ) { icon = 3; zoomInt *= 0.9f; } + if ( (m_state & STATE_ENABLE) == 0 ) - { icon = 7; - } + if ( m_state & STATE_DEAD ) - { icon = 17; - } + if ( m_bCatch ) - { icon = 23; - } - DrawPart(icon, zoomExt, 8.0f/256.0f); // draws the button - h = m_engine->RetText()->RetHeight(m_fontSize, m_fontType)/2.0f; + DrawPart(icon, zoomExt, 8.0f / 256.0f); // draws the button + + h = m_engine->GetText()->GetHeight(m_fontType, m_fontSize) / 2.0f; GetKeyName(text, m_key[0]); - if ( m_key[1] != 0 ) - { + if ( m_key[1] != 0 ) { GetResource(RES_TEXT, RT_KEY_OR, text+strlen(text)); GetKeyName(text+strlen(text), m_key[1]); } - pos.x = m_pos.x+m_dim.x*0.5f; - pos.y = m_pos.y+m_dim.y*0.5f; + pos.x = m_pos.x + m_dim.x * 0.5f; + pos.y = m_pos.y + m_dim.y * 0.5f; pos.y -= h; - m_engine->RetText()->DrawText(text, pos, m_dim.x, 0, m_fontSize, m_fontStretch, m_fontType, 0); + m_engine->GetText()->DrawText(std::string(text), m_fontType, m_fontSize, pos, m_dim.x, Gfx::TEXT_ALIGN_CENTER, 0); m_dim = iDim; - if ( m_state & STATE_DEAD ) return; + if ( m_state & STATE_DEAD ) + return; // Draws the name. - pos.x = m_pos.x+(214.0f/640.0f); - pos.y = m_pos.y+m_dim.y*0.5f; + pos.x = m_pos.x + (214.0f / 640.0f); + pos.y = m_pos.y + m_dim.y * 0.5f; pos.y -= h; - m_engine->RetText()->DrawText(m_name, pos, m_dim.x, 1, m_fontSize, m_fontStretch, m_fontType, 0); + m_engine->GetText()->DrawText(std::string(m_name), m_fontType, m_fontSize, pos, m_dim.x, Gfx::TEXT_ALIGN_RIGHT, 0); } void CKey::SetKey(int option, int key) { - if ( option < 0 || - option > 1 ) return; + if ( option < 0 || option > 1 ) return; m_key[option] = key; } -int CKey::RetKey(int option) +int CKey::GetKey(int option) { - if ( option < 0 || - option > 1 ) return 0; + if ( option < 0 || option > 1 ) return 0; return m_key[option]; } diff --git a/src/ui/key.h b/src/ui/key.h index 314f39b..db7d856 100644 --- a/src/ui/key.h +++ b/src/ui/key.h @@ -1,5 +1,6 @@ // * This file is part of the COLOBOT source code // * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch +// * Copyright (C) 2012 Polish Portal of Colobot (PPC) // * // * This program is free software: you can redistribute it and/or modify // * it under the terms of the GNU General Public License as published by @@ -18,35 +19,39 @@ #pragma once +#include +#include -#include "ui/control.h" +#include +#include +#include +#include -class CD3DEngine; - +#include class CKey : public CControl { -public: - CKey(CInstanceManager* iMan); - virtual ~CKey(); + public: + CKey(); + virtual ~CKey(); - bool Create(Math::Point pos, Math::Point dim, int icon, EventMsg eventMsg); + bool Create(Math::Point pos, Math::Point dim, int icon, EventType eventMsg); + bool EventProcess(const Event &event); - bool EventProcess(const Event &event); + void Draw(); - void Draw(); + void SetKey(int option, int key); + int GetKey(int option); - void SetKey(int option, int key); - int RetKey(int option); + protected: + bool TestKey(int key); -protected: - bool TestKey(int key); + int m_key[2]; + bool m_bCatch; -protected: - int m_key[2]; - bool m_bCatch; + CApplication *m_app; }; diff --git a/src/ui/label.cpp b/src/ui/label.cpp index cd96493..261f3fc 100644 --- a/src/ui/label.cpp +++ b/src/ui/label.cpp @@ -1,5 +1,6 @@ // * This file is part of the COLOBOT source code // * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch +// * Copyright (C) 2012 Polish Portal of Colobot (PPC) // * // * This program is free software: you can redistribute it and/or modify // * it under the terms of the GNU General Public License as published by @@ -17,25 +18,12 @@ // label.cpp -#include -#include -#include - -#include "common/struct.h" -#include "old/d3dengine.h" -#include "old/math3d.h" -#include "common/event.h" -#include "common/misc.h" -#include "common/iman.h" -#include "old/text.h" -#include "ui/label.h" - - +#include // Object's constructor. -CLabel::CLabel(CInstanceManager* iMan) : CControl(iMan) +CLabel::CLabel() : CControl() { } @@ -48,9 +36,14 @@ CLabel::~CLabel() // Creates a new button. -bool CLabel::Create(Math::Point pos, Math::Point dim, int icon, EventMsg eventMsg) +bool CLabel::Create(Math::Point pos, Math::Point dim, int icon, EventType eventMsg) { - if ( eventMsg == EVENT_NULL ) eventMsg = GetUniqueEventMsg(); + Event event; + + if (eventMsg == EVENT_NULL) { + m_event->GetEvent(event); + eventMsg = event.type; + } CControl::Create(pos, dim, icon, eventMsg); return true; @@ -72,22 +65,16 @@ void CLabel::Draw() { Math::Point pos; - if ( (m_state & STATE_VISIBLE) == 0 ) return; + if ( (m_state & STATE_VISIBLE) == 0 ) + return; - pos.y = m_pos.y+m_dim.y/2.0f; + pos.y = m_pos.y + m_dim.y / 2.0f; - if ( m_justif > 0 ) - { - pos.x = m_pos.x; + switch (m_justif) { + case Gfx::TEXT_ALIGN_LEFT: pos.x = m_pos.x; break; + case Gfx::TEXT_ALIGN_CENTER: pos.x = m_pos.x + m_dim.x / 2.0f; break; + case Gfx::TEXT_ALIGN_RIGHT: pos.x = m_pos.x + m_dim.x; break; } - if ( m_justif == 0 ) - { - pos.x = m_pos.x+m_dim.x/2.0f; - } - if ( m_justif < 0 ) - { - pos.x = m_pos.x+m_dim.x; - } - m_engine->RetText()->DrawText(m_name, pos, m_dim.x, m_justif, m_fontSize, m_fontStretch, m_fontType, 0); -} + m_engine->GetText()->DrawText(std::string(m_name), m_fontType, m_fontSize, pos, m_dim.x, m_justif, 0); +} diff --git a/src/ui/label.h b/src/ui/label.h index d3cb915..f65e1dd 100644 --- a/src/ui/label.h +++ b/src/ui/label.h @@ -1,5 +1,6 @@ // * This file is part of the COLOBOT source code // * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch +// * Copyright (C) 2012 Polish Portal of Colobot (PPC) // * // * This program is free software: you can redistribute it and/or modify // * it under the terms of the GNU General Public License as published by @@ -19,28 +20,21 @@ #pragma once -#include "ui/control.h" - - -class CD3DEngine; +#include +#include class CLabel : public CControl { -public: - CLabel(CInstanceManager* iMan); - virtual ~CLabel(); - - bool Create(Math::Point pos, Math::Point dim, int icon, EventMsg eventMsg); - - bool EventProcess(const Event &event); - - void Draw(); + public: + CLabel(); + virtual ~CLabel(); -protected: + bool Create(Math::Point pos, Math::Point dim, int icon, EventType eventMsg); + bool EventProcess(const Event &event); -protected: + void Draw(); }; diff --git a/src/ui/list.h b/src/ui/list.h index cc9e646..c7c278d 100644 --- a/src/ui/list.h +++ b/src/ui/list.h @@ -19,13 +19,9 @@ #pragma once -#include "ui/control.h" -#include "common/event.h" +#include - -class CD3DEngine; -class CButton; -class CScroll; +#include const int LISTMAXDISPLAY = 20; // maximum number of visible lines @@ -35,81 +31,81 @@ const int LISTMAXTOTAL = 100; // maximum total number of lines class CList : public CControl { -public: - CList(CInstanceManager* iMan); - ~CList(); + public: + CList(); + ~CList(); - bool Create(Math::Point pos, Math::Point dim, int icon, EventMsg eventMsg, float expand); + bool Create(Math::Point pos, Math::Point dim, int icon, EventType eventMsg, float expand); - void SetPos(Math::Point pos); - void SetDim(Math::Point dim); + void SetPos(Math::Point pos); + void SetDim(Math::Point dim); - bool SetState(int state, bool bState); - bool SetState(int state); - bool ClearState(int state); + bool SetState(int state, bool bState); + bool SetState(int state); + bool ClearState(int state); - bool EventProcess(const Event &event); - void Draw(); + bool EventProcess(const Event &event); + void Draw(); - void Flush(); + void Flush(); - void SetTotal(int i); - int RetTotal(); + void SetTotal(int i); + int RetTotal(); - void SetSelect(int i); - int RetSelect(); + void SetSelect(int i); + int RetSelect(); - void SetSelectCap(bool bEnable); - bool RetSelectCap(); + void SetSelectCap(bool bEnable); + bool RetSelectCap(); - void SetBlink(bool bEnable); - bool RetBlink(); + void SetBlink(bool bEnable); + bool RetBlink(); - void SetName(int i, char* name); - char* RetName(int i); + void SetName(int i, char* name); + char* RetName(int i); - void SetCheck(int i, bool bMode); - bool RetCheck(int i); + void SetCheck(int i, bool bMode); + bool RetCheck(int i); - void SetEnable(int i, bool bEnable); - bool RetEnable(int i); + void SetEnable(int i, bool bEnable); + bool RetEnable(int i); - void SetTabs(int i, float pos, int justif=1); - float RetTabs(int i); + void SetTabs(int i, float pos, int justif=1); + float RetTabs(int i); - void ShowSelect(bool bFixed); + void ShowSelect(bool bFixed); - EventMsg RetEventMsgButton(int i); - EventMsg RetEventMsgScroll(); + EventType RetEventMsgButton(int i); + EventType RetEventMsgScroll(); -protected: - bool MoveAdjust(); - void UpdateButton(); - void UpdateScroll(); - void MoveScroll(); - void DrawCase(char *text, Math::Point pos, float width, int justif); + protected: + bool MoveAdjust(); + void UpdateButton(); + void UpdateScroll(); + void MoveScroll(); + void DrawCase(char *text, Math::Point pos, float width, int justif); -protected: - CButton* m_button[LISTMAXDISPLAY]; - CScroll* m_scroll; + protected: + CButton* m_button[LISTMAXDISPLAY]; + CScroll* m_scroll; - EventMsg m_eventButton[LISTMAXDISPLAY]; - EventMsg m_eventScroll; + 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]; - int 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]; + int m_justifs[10]; - char m_text[LISTMAXTOTAL][100]; - char m_check[LISTMAXTOTAL]; - char m_enable[LISTMAXTOTAL]; + char m_text[LISTMAXTOTAL][100]; + char m_check[LISTMAXTOTAL]; + char m_enable[LISTMAXTOTAL]; }; diff --git a/src/ui/map.h b/src/ui/map.h index efdf54b..693398c 100644 --- a/src/ui/map.h +++ b/src/ui/map.h @@ -19,16 +19,14 @@ #pragma once -#include "ui/control.h" -#include "object/object.h" +#include +#include + +#include -class CD3DEngine; class CTerrain; class CWater; -class CRobotMain; - - const int MAPMAXOBJECT = 100; @@ -62,10 +60,10 @@ struct MapObject class CMap : public CControl { public: - CMap(CInstanceManager* iMan); + CMap(); ~CMap(); - bool Create(Math::Point pos, Math::Point dim, int icon, EventMsg eventMsg); + bool Create(Math::Point pos, Math::Point dim, int icon, EventType eventMsg); bool EventProcess(const Event &event); void Draw(); diff --git a/src/ui/scroll.h b/src/ui/scroll.h index 6854e61..a82fea0 100644 --- a/src/ui/scroll.h +++ b/src/ui/scroll.h @@ -19,12 +19,9 @@ #pragma once -#include "ui/control.h" - - -class CD3DEngine; -class CButton; +#include +#include const float SCROLL_WIDTH = (15.0f/640.0f); @@ -32,50 +29,50 @@ const float SCROLL_WIDTH = (15.0f/640.0f); class CScroll : public CControl { -public: - CScroll(CInstanceManager* iMan); - ~CScroll(); + public: + CScroll(); + ~CScroll(); - bool Create(Math::Point pos, Math::Point dim, int icon, EventMsg eventMsg); + bool Create(Math::Point pos, Math::Point dim, int icon, EventType eventMsg); - void SetPos(Math::Point pos); - void SetDim(Math::Point dim); + void SetPos(Math::Point pos); + void SetDim(Math::Point dim); - bool SetState(int state, bool bState); - bool SetState(int state); - bool ClearState(int state); + bool SetState(int state, bool bState); + bool SetState(int state); + bool ClearState(int state); - bool EventProcess(const Event &event); - void Draw(); + bool EventProcess(const Event &event); + void Draw(); - void SetVisibleValue(float value); - float RetVisibleValue(); + void SetVisibleValue(float value); + float RetVisibleValue(); - void SetVisibleRatio(float value); - float RetVisibleRatio(); + void SetVisibleRatio(float value); + float RetVisibleRatio(); - void SetArrowStep(float step); - float RetArrowStep(); + void SetArrowStep(float step); + float RetArrowStep(); -protected: - void MoveAdjust(); - void AdjustGlint(); - void DrawVertex(Math::Point pos, Math::Point dim, int icon); + protected: + void MoveAdjust(); + void AdjustGlint(); + void DrawVertex(Math::Point pos, Math::Point dim, int icon); -protected: - CButton* m_buttonUp; - CButton* m_buttonDown; + protected: + CButton* m_buttonUp; + CButton* m_buttonDown; - float m_visibleValue; - float m_visibleRatio; - float m_step; + float m_visibleValue; + float m_visibleRatio; + float m_step; - bool m_bCapture; - Math::Point m_pressPos; - float m_pressValue; + bool m_bCapture; + Math::Point m_pressPos; + float m_pressValue; - EventMsg m_eventUp; - EventMsg m_eventDown; + EventType m_eventUp; + EventType m_eventDown; }; diff --git a/src/ui/shortcut.h b/src/ui/shortcut.h index b918ccc..d819bf2 100644 --- a/src/ui/shortcut.h +++ b/src/ui/shortcut.h @@ -18,31 +18,28 @@ #pragma once +#include -#include "ui/control.h" - - -class CD3DEngine; - +#include class CShortcut : public CControl { -public: - CShortcut(CInstanceManager* iMan); - ~CShortcut(); + public: + CShortcut(); + ~CShortcut(); - bool Create(Math::Point pos, Math::Point dim, int icon, EventMsg eventMsg); + bool Create(Math::Point pos, Math::Point dim, int icon, EventType eventMsg); - bool EventProcess(const Event &event); + bool EventProcess(const Event &event); - void Draw(); + void Draw(); -protected: - void DrawVertex(int icon, float zoom); + protected: + void DrawVertex(int icon, float zoom); -protected: - float m_time; + protected: + float m_time; }; diff --git a/src/ui/slider.h b/src/ui/slider.h index 1ec9ea5..e79b348 100644 --- a/src/ui/slider.h +++ b/src/ui/slider.h @@ -19,63 +19,60 @@ #pragma once -#include "ui/control.h" - - -class CD3DEngine; -class CButton; +#include +#include class CSlider : public CControl { -public: - CSlider(CInstanceManager* iMan); - ~CSlider(); + public: + CSlider(); + ~CSlider(); - bool Create(Math::Point pos, Math::Point dim, int icon, EventMsg eventMsg); + bool Create(Math::Point pos, Math::Point dim, int icon, EventType eventMsg); - void SetPos(Math::Point pos); - void SetDim(Math::Point dim); + void SetPos(Math::Point pos); + void SetDim(Math::Point dim); - bool SetState(int state, bool bState); - bool SetState(int state); - bool ClearState(int state); + bool SetState(int state, bool bState); + bool SetState(int state); + bool ClearState(int state); - bool EventProcess(const Event &event); - void Draw(); + bool EventProcess(const Event &event); + void Draw(); - void SetLimit(float min, float max); + void SetLimit(float min, float max); - void SetVisibleValue(float value); - float RetVisibleValue(); + void SetVisibleValue(float value); + float RetVisibleValue(); - void SetArrowStep(float step); - float RetArrowStep(); + void SetArrowStep(float step); + float RetArrowStep(); -protected: - void MoveAdjust(); - void AdjustGlint(); - void DrawVertex(Math::Point pos, Math::Point dim, int icon); + protected: + void MoveAdjust(); + void AdjustGlint(); + void DrawVertex(Math::Point pos, Math::Point dim, int icon); -protected: - CButton* m_buttonLeft; - CButton* m_buttonRight; + protected: + CButton* m_buttonLeft; + CButton* m_buttonRight; - float m_min; - float m_max; - float m_visibleValue; - float m_step; + float m_min; + float m_max; + float m_visibleValue; + float m_step; - bool m_bHoriz; - float m_marginButton; + bool m_bHoriz; + float m_marginButton; - bool m_bCapture; - Math::Point m_pressPos; - float m_pressValue; + bool m_bCapture; + Math::Point m_pressPos; + float m_pressValue; - EventMsg m_eventUp; - EventMsg m_eventDown; + EventType m_eventUp; + EventType m_eventDown; }; diff --git a/src/ui/target.h b/src/ui/target.h index ae0c7af..a2615b4 100644 --- a/src/ui/target.h +++ b/src/ui/target.h @@ -19,30 +19,25 @@ #pragma once -#include "ui/control.h" - - -class CD3DEngine; -class CObject; +#include +#include class CTarget : public CControl { -public: - CTarget(CInstanceManager* iMan); - ~CTarget(); - - bool Create(Math::Point pos, Math::Point dim, int icon, EventMsg eventMsg); + public: + CTarget(); + ~CTarget(); - bool EventProcess(const Event &event); - void Draw(); - bool GetTooltip(Math::Point pos, char* name); + bool Create(Math::Point pos, Math::Point dim, int icon, EventType eventMsg); -protected: - CObject* DetectFriendObject(Math::Point pos); + bool EventProcess(const Event &event); + void Draw(); + bool GetTooltip(Math::Point pos, char* name); -protected: + protected: + CObject* DetectFriendObject(Math::Point pos); }; diff --git a/src/ui/window.h b/src/ui/window.h index 3acf3b4..8884c6f 100644 --- a/src/ui/window.h +++ b/src/ui/window.h @@ -19,27 +19,8 @@ #pragma once -#include "ui/control.h" - - -class CD3DEngine; -class CButton; -class CColor; -class CCheck; -class CKey; -class CGroup; -class CImage; -class CLabel; -class CEdit; -class CEditValue; -class CScroll; -class CSlider; -class CList; -class CShortcut; -class CMap; -class CGauge; -class CCompass; -class CTarget; +#include +#include const int MAXWINDOW = 100; @@ -48,34 +29,34 @@ const int MAXWINDOW = 100; class CWindow : public CControl { public: - CWindow(CInstanceManager* iMan); + CWindow(); ~CWindow(); void Flush(); - bool Create(Math::Point pos, Math::Point dim, int icon, EventMsg eventMsg); - CButton* CreateButton(Math::Point pos, Math::Point dim, int icon, EventMsg eventMsg); - CColor* CreateColor(Math::Point pos, Math::Point dim, int icon, EventMsg eventMsg); - CCheck* CreateCheck(Math::Point pos, Math::Point dim, int icon, EventMsg eventMsg); - CKey* CreateKey(Math::Point pos, Math::Point dim, int icon, EventMsg eventMsg); - CGroup* CreateGroup(Math::Point pos, Math::Point dim, int icon, EventMsg eventMsg); - CImage* CreateImage(Math::Point pos, Math::Point dim, int icon, EventMsg eventMsg); - CLabel* CreateLabel(Math::Point pos, Math::Point dim, int icon, EventMsg eventMsg, char *name); - CEdit* CreateEdit(Math::Point pos, Math::Point dim, int icon, EventMsg eventMsg); - CEditValue* CreateEditValue(Math::Point pos, Math::Point dim, int icon, EventMsg eventMsg); - CScroll* CreateScroll(Math::Point pos, Math::Point dim, int icon, EventMsg eventMsg); - CSlider* CreateSlider(Math::Point pos, Math::Point dim, int icon, EventMsg eventMsg); - CList* CreateList(Math::Point pos, Math::Point dim, int icon, EventMsg eventMsg, float expand=1.2f); - CShortcut* CreateShortcut(Math::Point pos, Math::Point dim, int icon, EventMsg eventMsg); - CMap* CreateMap(Math::Point pos, Math::Point dim, int icon, EventMsg eventMsg); - CGauge* CreateGauge(Math::Point pos, Math::Point dim, int icon, EventMsg eventMsg); - CCompass* CreateCompass(Math::Point pos, Math::Point dim, int icon, EventMsg eventMsg); - CTarget* CreateTarget(Math::Point pos, Math::Point dim, int icon, EventMsg eventMsg); - bool DeleteControl(EventMsg eventMsg); - CControl* SearchControl(EventMsg eventMsg); - - EventMsg RetEventMsgReduce(); - EventMsg RetEventMsgFull(); - EventMsg RetEventMsgClose(); + bool Create(Math::Point pos, Math::Point dim, int icon, EventType eventMsg); + CButton* CreateButton(Math::Point pos, Math::Point dim, int icon, EventType eventMsg); + CColor* CreateColor(Math::Point pos, Math::Point dim, int icon, EventType eventMsg); + CCheck* CreateCheck(Math::Point pos, Math::Point dim, int icon, EventType eventMsg); + CKey* CreateKey(Math::Point pos, Math::Point dim, int icon, EventType eventMsg); + CGroup* CreateGroup(Math::Point pos, Math::Point dim, int icon, EventType eventMsg); + CImage* CreateImage(Math::Point pos, Math::Point dim, int icon, EventType eventMsg); + CLabel* CreateLabel(Math::Point pos, Math::Point dim, int icon, EventType eventMsg, char *name); + CEdit* CreateEdit(Math::Point pos, Math::Point dim, int icon, EventType eventMsg); + CEditValue* CreateEditValue(Math::Point pos, Math::Point dim, int icon, EventType eventMsg); + CScroll* CreateScroll(Math::Point pos, Math::Point dim, int icon, EventType eventMsg); + CSlider* CreateSlider(Math::Point pos, Math::Point dim, int icon, EventType eventMsg); + CList* CreateList(Math::Point pos, Math::Point dim, int icon, EventType eventMsg, float expand=1.2f); + CShortcut* CreateShortcut(Math::Point pos, Math::Point dim, int icon, EventType eventMsg); + CMap* CreateMap(Math::Point pos, Math::Point dim, int icon, EventType eventMsg); + CGauge* CreateGauge(Math::Point pos, Math::Point dim, int icon, EventType eventMsg); + CCompass* CreateCompass(Math::Point pos, Math::Point dim, int icon, EventType eventMsg); + CTarget* CreateTarget(Math::Point pos, Math::Point dim, int icon, EventType eventMsg); + bool DeleteControl(EventType eventMsg); + CControl* SearchControl(EventType eventMsg); + + EventType RetEventTypeReduce(); + EventType RetEventTypeFull(); + EventType RetEventTypeClose(); void SetName(char* name); -- cgit v1.2.3-1-g7c22 From ea6269c4110282a3e7c05bec9c7f17ffd1bd5191 Mon Sep 17 00:00:00 2001 From: erihel Date: Fri, 17 Aug 2012 23:03:52 +0200 Subject: * ui/key.cpp compiles * csoundinterface to ccontrol --- src/ui/control.cpp | 2 +- src/ui/control.h | 2 +- src/ui/interface.cpp | 4 ++++ src/ui/interface.h | 2 ++ src/ui/key.cpp | 11 +++++------ src/ui/key.h | 4 ++++ 6 files changed, 17 insertions(+), 8 deletions(-) (limited to 'src/ui') diff --git a/src/ui/control.cpp b/src/ui/control.cpp index 867958c..61fd6dd 100644 --- a/src/ui/control.cpp +++ b/src/ui/control.cpp @@ -51,7 +51,7 @@ CControl::CControl(CInstanceManager* iMan) m_event = static_cast< CEventQueue* > ( m_iMan->SearchInstance(CLASS_EVENT) ); m_main = static_cast< CRobotMain* > ( m_iMan->SearchInstance(CLASS_MAIN) ); m_particle = static_cast< Gfx::CParticle* > (m_iMan->SearchInstance(CLASS_PARTICULE)); - m_sound = static_cast< CSound* > (m_iMan->SearchInstance(CLASS_SOUND)); + m_sound = static_cast< CSoundInterface* > (m_iMan->SearchInstance(CLASS_SOUND)); m_eventType = EVENT_NULL; m_state = STATE_ENABLE|STATE_VISIBLE|STATE_GLINT; m_fontSize = Gfx::FONT_SIZE_SMALL; diff --git a/src/ui/control.h b/src/ui/control.h index ef49b65..d336ede 100644 --- a/src/ui/control.h +++ b/src/ui/control.h @@ -116,7 +116,7 @@ protected: CEventQueue* m_event; CRobotMain* m_main; Gfx::CParticle* m_particle; - CSound* m_sound; + CSoundInterface* m_sound; Math::Point m_pos; // corner upper / left Math::Point m_dim; // dimensions diff --git a/src/ui/interface.cpp b/src/ui/interface.cpp index afedfc9..0398e7f 100644 --- a/src/ui/interface.cpp +++ b/src/ui/interface.cpp @@ -20,6 +20,8 @@ #include +namespace Ui { + CInterface::CInterface() { @@ -337,3 +339,5 @@ void CInterface::Draw() m_table[i]->Draw(); } } + +} diff --git a/src/ui/interface.h b/src/ui/interface.h index d8f4d62..43f2698 100644 --- a/src/ui/interface.h +++ b/src/ui/interface.h @@ -49,6 +49,7 @@ #include #include +namespace Ui { const int MAXCONTROL = 100; @@ -100,3 +101,4 @@ class CInterface }; +} diff --git a/src/ui/key.cpp b/src/ui/key.cpp index 0d73ed0..de668bc 100644 --- a/src/ui/key.cpp +++ b/src/ui/key.cpp @@ -20,6 +20,7 @@ #include +namespace Ui { void GetKeyName(char *name, int key) { @@ -90,12 +91,9 @@ bool CKey::EventProcess(const Event &event) if (event.type == EVENT_MOUSE_BUTTON_DOWN && m_bCatch) { m_bCatch = false; - if ( TestKey(event.param) ) // impossible ? - { + if ( TestKey(event.param) ) { // impossible ? m_sound->Play(SOUND_TZOING); - } - else - { + } else { if ( event.param == m_key[0] || event.param == m_key[1] ) { m_key[0] = event.param; m_key[1] = 0; @@ -120,7 +118,7 @@ bool CKey::EventProcess(const Event &event) bool CKey::TestKey(int key) { - if ( key == VK_PAUSE || key == VK_SNAPSHOT ) return true; // blocked key + if ( key == KEY(PAUSE) || key == KEY(PRINT) ) return true; // blocked key for (int i = 0; i < 20; i++) { for (int j = 0; j < 2; j++) { @@ -237,3 +235,4 @@ int CKey::GetKey(int option) return m_key[option]; } +} diff --git a/src/ui/key.h b/src/ui/key.h index db7d856..5ca71b0 100644 --- a/src/ui/key.h +++ b/src/ui/key.h @@ -27,9 +27,11 @@ #include #include #include +#include #include +namespace Ui { class CKey : public CControl { @@ -55,3 +57,5 @@ class CKey : public CControl }; +} + -- cgit v1.2.3-1-g7c22 From a00032d07565b39b8cd1a485b0dd02df87cc18e7 Mon Sep 17 00:00:00 2001 From: erihel Date: Fri, 17 Aug 2012 23:05:59 +0200 Subject: * ui/label.cpp compiles --- src/ui/label.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/ui') diff --git a/src/ui/label.cpp b/src/ui/label.cpp index 261f3fc..ec7b2cb 100644 --- a/src/ui/label.cpp +++ b/src/ui/label.cpp @@ -70,11 +70,11 @@ void CLabel::Draw() pos.y = m_pos.y + m_dim.y / 2.0f; - switch (m_justif) { + switch (m_textAlign) { case Gfx::TEXT_ALIGN_LEFT: pos.x = m_pos.x; break; case Gfx::TEXT_ALIGN_CENTER: pos.x = m_pos.x + m_dim.x / 2.0f; break; case Gfx::TEXT_ALIGN_RIGHT: pos.x = m_pos.x + m_dim.x; break; } - m_engine->GetText()->DrawText(std::string(m_name), m_fontType, m_fontSize, pos, m_dim.x, m_justif, 0); + m_engine->GetText()->DrawText(std::string(m_name), m_fontType, m_fontSize, pos, m_dim.x, m_textAlign, 0); } -- cgit v1.2.3-1-g7c22 From c02ac93379287fd83b134c34aa925c85fcda8e26 Mon Sep 17 00:00:00 2001 From: erihel Date: Fri, 17 Aug 2012 23:56:29 +0200 Subject: * list.cpp compiles --- src/ui/label.cpp | 4 + src/ui/label.h | 2 + src/ui/list.cpp | 649 ++++++++++++++++++++++++------------------------------ src/ui/list.h | 35 +-- src/ui/scroll.cpp | 16 +- src/ui/scroll.h | 6 +- 6 files changed, 332 insertions(+), 380 deletions(-) (limited to 'src/ui') diff --git a/src/ui/label.cpp b/src/ui/label.cpp index ec7b2cb..fb5f1d8 100644 --- a/src/ui/label.cpp +++ b/src/ui/label.cpp @@ -20,6 +20,8 @@ #include +namespace Ui { + // Object's constructor. @@ -78,3 +80,5 @@ void CLabel::Draw() m_engine->GetText()->DrawText(std::string(m_name), m_fontType, m_fontSize, pos, m_dim.x, m_textAlign, 0); } + +} diff --git a/src/ui/label.h b/src/ui/label.h index f65e1dd..303b698 100644 --- a/src/ui/label.h +++ b/src/ui/label.h @@ -24,6 +24,7 @@ #include +namespace Ui { class CLabel : public CControl { @@ -38,3 +39,4 @@ class CLabel : public CControl }; +} diff --git a/src/ui/list.cpp b/src/ui/list.cpp index 9fbc5d9..9f1d579 100644 --- a/src/ui/list.cpp +++ b/src/ui/list.cpp @@ -1,5 +1,6 @@ // * This file is part of the COLOBOT source code // * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch +// * Copyright (C) 2012 Polish Portal of Colobot (PPC) // * // * This program is free software: you can redistribute it and/or modify // * it under the terms of the GNU General Public License as published by @@ -17,50 +18,31 @@ // list.cpp -#include -#include -#include - -#include "common/struct.h" -#include "old/d3dengine.h" -#include "old/math3d.h" -#include "common/event.h" -#include "common/misc.h" -#include "common/iman.h" -#include "ui/button.h" -#include "ui/scroll.h" -#include "old/text.h" -#include "ui/list.h" +#include +namespace Ui { const float MARGING = 4.0f; - // Object's constructor. -CList::CList(CInstanceManager* iMan) : CControl(iMan) +CList::CList() : CControl() { - int i; - - for ( i=0 ; iGetEvent(event); + eventMsg = event.type; + } + + CControl::Create(pos, dim, icon, eventMsg); - m_scroll = new CScroll(m_iMan); + m_scroll = new CScroll(); m_scroll->Create(pos, dim, 0, EVENT_NULL); - m_eventScroll = m_scroll->RetEventMsg(); + m_eventScroll = m_scroll->GetEventType(); return MoveAdjust(); } @@ -107,52 +94,54 @@ bool CList::Create(Math::Point pos, Math::Point dim, int icon, EventMsg eventMsg bool CList::MoveAdjust() { - Math::Point ipos, idim, ppos, ddim; - float marging, h; - int i; + Math::Point ipos, idim, ppos, ddim; + float marging, h; - for ( i=0 ; iRetText()->RetHeight(m_fontSize, m_fontType)*m_expand; + h = m_engine->GetText()->GetHeight(m_fontType, m_fontSize) * m_expand; - m_displayLine = (int)(idim.y/h); - if ( m_displayLine == 0 ) return false; - if ( m_displayLine > LISTMAXDISPLAY ) m_displayLine = LISTMAXDISPLAY; - idim.y = h*m_displayLine; - m_dim.y = idim.y+marging*2.0f/480.f; + m_displayLine = static_cast(idim.y / h); + if (m_displayLine == 0) + return false; + if (m_displayLine > LISTMAXDISPLAY) + m_displayLine = LISTMAXDISPLAY; + idim.y = h * m_displayLine; + m_dim.y = idim.y + marging * 2.0f / 480.f; ppos.x = ipos.x; - ppos.y = ipos.y+idim.y-h; - ddim.x = idim.x-SCROLL_WIDTH; + ppos.y = ipos.y + idim.y - h; + ddim.x = idim.x - SCROLL_WIDTH; ddim.y = h; - for ( i=0 ; iCreate(ppos, ddim, -1, EVENT_NULL); - m_button[i]->SetJustif(1); + m_button[i]->SetTextAlign(Gfx::TEXT_ALIGN_CENTER); m_button[i]->SetState(STATE_SIMPLY); m_button[i]->SetFontType(m_fontType); m_button[i]->SetFontSize(m_fontSize); ppos.y -= h; - m_eventButton[i] = m_button[i]->RetEventMsg(); + m_eventButton[i] = m_button[i]->GetEventType(); } - if ( m_scroll != 0 ) - { - ppos.x = ipos.x+idim.x-SCROLL_WIDTH; + if ( m_scroll != nullptr ) { + ppos.x = ipos.x + idim.x - SCROLL_WIDTH; ppos.y = ipos.y; ddim.x = SCROLL_WIDTH; ddim.y = idim.y; @@ -168,19 +157,22 @@ bool CList::MoveAdjust() // Returns the message of a button. -EventMsg CList::RetEventMsgButton(int i) +EventType CList::GetEventMsgButton(int i) { - if ( i < 0 || i >= m_displayLine ) return EVENT_NULL; - if ( m_button[i] == 0 ) return EVENT_NULL; - return m_button[i]->RetEventMsg(); + if (i < 0 || i >= m_displayLine) + return EVENT_NULL; + if (m_button[i] == nullptr) + return EVENT_NULL; + return m_button[i]->GetEventType(); } // Returns the message from the elevator. -EventMsg CList::RetEventMsgScroll() +EventType CList::GetEventMsgScroll() { - if ( m_scroll == 0 ) return EVENT_NULL; - return m_scroll->RetEventMsg(); + if (m_scroll == nullptr) + return EVENT_NULL; + return m_scroll->GetEventType(); } @@ -189,6 +181,7 @@ void CList::SetPos(Math::Point pos) CControl::SetPos(pos); } + void CList::SetDim(Math::Point dim) { m_dim = dim; @@ -199,47 +192,43 @@ void CList::SetDim(Math::Point dim) bool CList::SetState(int state, bool bState) { - int i; - - if ( state & STATE_ENABLE ) - { - for ( i=0 ; iSetState(state, bState); + if (state & STATE_ENABLE) { + for (int i = 0; i < m_displayLine; i++) { + if (m_button[i] != nullptr) + m_button[i]->SetState(state, bState); } - if ( m_scroll != 0 ) m_scroll->SetState(state, bState); + if (m_scroll != nullptr) + m_scroll->SetState(state, bState); } return CControl::SetState(state, bState); } + bool CList::SetState(int state) { - int i; - - if ( state & STATE_ENABLE ) - { - for ( i=0 ; iSetState(state); + if (state & STATE_ENABLE) { + for (int i = 0; i < m_displayLine; i++) { + if (m_button[i] != nullptr) + m_button[i]->SetState(state); } - if ( m_scroll != 0 ) m_scroll->SetState(state); + if (m_scroll != nullptr) + m_scroll->SetState(state); } return CControl::SetState(state); } + bool CList::ClearState(int state) { - int i; - - if ( state & STATE_ENABLE ) - { - for ( i=0 ; iClearState(state); + if (state & STATE_ENABLE) { + for (int i = 0; i < m_displayLine; i++) { + if (m_button[i] != nullptr) + m_button[i]->ClearState(state); } - if ( m_scroll != 0 ) m_scroll->ClearState(state); + if (m_scroll != nullptr) + m_scroll->ClearState(state); } return CControl::ClearState(state); @@ -250,47 +239,38 @@ bool CList::ClearState(int state) bool CList::EventProcess(const Event &event) { - int i; - - if ( m_bBlink && // blinks? - event.event == EVENT_FRAME ) - { + int i; + if (m_bBlink && event.type == EVENT_FRAME) { i = m_selectLine-m_firstLine; - if ( i >= 0 && i < 4 && - m_button[i] != 0 ) - { + if (i >= 0 && i < 4 && m_button[i] != nullptr) { 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_button[i]->ClearState(STATE_CHECK); - } - else - { + } else { m_button[i]->SetState(STATE_ENABLE); m_button[i]->SetState(STATE_CHECK); } } } - if ( (m_state & STATE_VISIBLE) == 0 ) return true; - if ( (m_state & STATE_ENABLE) == 0 ) return true; + if ((m_state & STATE_VISIBLE) == 0) + return true; + if ((m_state & STATE_ENABLE) == 0) + return true; - if ( event.event == EVENT_KEYDOWN && - event.param == VK_WHEELUP && - Detect(event.pos) ) - { - if ( m_firstLine > 0 ) m_firstLine --; + if (event.type == EVENT_KEY_DOWN && event.mouseButton.button == 5 && Detect(event.pos)) { + if (m_firstLine > 0) + m_firstLine--; UpdateScroll(); UpdateButton(); return true; } - if ( event.event == EVENT_KEYDOWN && - event.param == VK_WHEELDOWN && - Detect(event.pos) ) - { - if ( m_firstLine < m_totalLine-m_displayLine ) m_firstLine ++; + + if (event.type == EVENT_KEY_DOWN && event.mouseButton.button == 4 && Detect(event.pos)) { + if (m_firstLine < m_totalLine - m_displayLine) + m_firstLine++; UpdateScroll(); UpdateButton(); return true; @@ -298,46 +278,41 @@ bool CList::EventProcess(const Event &event) CControl::EventProcess(event); - if ( event.event == EVENT_MOUSEMOVE && Detect(event.pos) ) - { - m_engine->SetMouseType(D3DMOUSENORM); - for ( i=0 ; i= m_totalLine ) break; - if ( m_button[i] != 0 ) - { + if (event.type == EVENT_MOUSE_MOVE && Detect(event.pos)) { + m_engine->SetMouseType(Gfx::ENG_MOUSE_NORM); + for (i = 0; i < m_displayLine; i++) { + if (i + m_firstLine >= m_totalLine) + break; + if (m_button[i] != nullptr) m_button[i]->EventProcess(event); - } } } - if ( m_bSelectCap ) - { - for ( i=0 ; i= m_totalLine ) break; - if ( m_button[i] != 0 ) - { - if ( !m_button[i]->EventProcess(event) ) return false; - - if ( event.event == m_eventButton[i] ) - { - SetSelect(m_firstLine+i); + if (m_bSelectCap) { + for (i = 0; i < m_displayLine; i++) { + if (i + m_firstLine >= m_totalLine) + break; + + if (m_button[i] != nullptr) { + if (!m_button[i]->EventProcess(event)) + return false; + + if (event.type == m_eventButton[i]) { + SetSelect(m_firstLine + i); Event newEvent = event; - newEvent.event = m_eventMsg; + newEvent.type = m_eventType; m_event->AddEvent(newEvent); // selected line changes } } } } - if ( m_scroll != 0 ) - { - if ( !m_scroll->EventProcess(event) ) return false; + if (m_scroll != nullptr) { + if (!m_scroll->EventProcess(event)) + return false; - if ( event.event == m_eventScroll ) - { + if (event.type == m_eventScroll) { MoveScroll(); UpdateButton(); } @@ -353,46 +328,40 @@ void CList::Draw() { Math::Point uv1, uv2, corner, pos, dim, ppos, ddim; float dp; - int i, j; + int i; char text[100]; char *pb, *pe; - if ( (m_state & STATE_VISIBLE) == 0 ) return; + if ((m_state & STATE_VISIBLE) == 0) + return; - if ( m_state & STATE_SHADOW ) - { + if (m_state & STATE_SHADOW) DrawShadow(m_pos, m_dim); - } - dp = 0.5f/256.0f; + dp = 0.5f / 256.0f; - if ( m_icon != -1 ) - { + if (m_icon != -1) { dim = m_dim; - if ( m_icon == 0 ) - { + if (m_icon == 0) { m_engine->SetTexture("button2.tga"); - m_engine->SetState(D3DSTATENORMAL); + m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); - uv1.x = 128.0f/256.0f; - uv1.y = 64.0f/256.0f; // u-v texture - uv2.x = 160.0f/256.0f; - uv2.y = 96.0f/256.0f; - } - else - { + uv1.x = 128.0f / 256.0f; + uv1.y = 64.0f / 256.0f; // u-v texture + uv2.x = 160.0f / 256.0f; + uv2.y = 96.0f / 256.0f; + } else { m_engine->SetTexture("button2.tga"); - m_engine->SetState(D3DSTATENORMAL); + m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); - uv1.x = 132.0f/256.0f; - uv1.y = 68.0f/256.0f; // u-v texture - uv2.x = 156.0f/256.0f; - uv2.y = 92.0f/256.0f; + uv1.x = 132.0f / 256.0f; + uv1.y = 68.0f / 256.0f; // u-v texture + uv2.x = 156.0f / 256.0f; + uv2.y = 92.0f / 256.0f; - if ( m_button[0] != 0 ) - { - dim = m_button[0]->RetDim(); + if (m_button[0] != nullptr) { + dim = m_button[0]->GetDim(); dim.y *= m_displayLine; // background sounds spot behind } } @@ -402,28 +371,26 @@ void CList::Draw() uv2.x -= dp; uv2.y -= dp; - corner.x = 10.0f/640.0f; - corner.y = 10.0f/480.0f; - DrawIcon(m_pos, dim, uv1, uv2, corner, 8.0f/256.0f); + corner.x = 10.0f / 640.0f; + corner.y = 10.0f / 480.0f; + DrawIcon(m_pos, dim, uv1, uv2, corner, 8.0f / 256.0f); } - if ( m_totalLine < m_displayLine ) // no buttons to the bottom? - { + if ( m_totalLine < m_displayLine ) { // no buttons to the bottom? i = m_totalLine; - if ( m_button[i] != 0 ) - { - pos = m_button[i]->RetPos(); - dim = m_button[i]->RetDim(); - pos.y += dim.y*1.1f; + if ( m_button[i] != 0 ) { + pos = m_button[i]->GetPos(); + dim = m_button[i]->GetDim(); + pos.y += dim.y * 1.1f; dim.y *= 0.4f; pos.y -= dim.y; m_engine->SetTexture("button2.tga"); - m_engine->SetState(D3DSTATETTw); - uv1.x = 120.0f/256.0f; - uv1.y = 64.0f/256.0f; - uv2.x = 128.0f/256.0f; - uv2.y = 48.0f/256.0f; + m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE); // was D3DSTATETTw + uv1.x = 120.0f / 256.0f; + uv1.y = 64.0f / 256.0f; + uv2.x = 128.0f / 256.0f; + uv2.y = 48.0f / 256.0f; uv1.x += dp; uv1.y -= dp; uv2.x -= dp; @@ -432,108 +399,93 @@ void CList::Draw() } } - for ( i=0 ; i= m_totalLine ) break; + for (i = 0; i < m_displayLine; i++) { + if ( i + m_firstLine >= m_totalLine ) + break; - if ( m_button[i] != 0 ) - { - if ( !m_bBlink && i+m_firstLine < m_totalLine ) - { + if ( m_button[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_button[i]->Draw(); // draws a box without text // draws text in the box - pos = m_button[i]->RetPos(); - dim = m_button[i]->RetDim(); - 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->RetText()->RetHeight(m_fontSize, m_fontType)/2.0f; + pos = m_button[i]->GetPos(); + dim = m_button[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, 1); - } - else - { - ppos.x = pos.x+dim.y*0.5f; - ppos.y = pos.y+dim.y*0.5f; - ppos.y -= m_engine->RetText()->RetHeight(m_fontSize, m_fontType)/2.0f; - pb = m_text[i+m_firstLine]; - for ( j=0 ; j<10 ; j++ ) - { + DrawCase(m_text[i + m_firstLine], ppos, ddim.x, Gfx::TEXT_ALIGN_CENTER); + } 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]; + for (int j = 0; j < 10; j++) { pe = strchr(pb, '\t'); if ( pe == 0 ) - { strcpy(text, pb); - } - else - { - strncpy(text, pb, pe-pb); - text[pe-pb] = 0; + else { + strncpy(text, pb, pe - pb); + text[pe - pb] = 0; } DrawCase(text, ppos, m_tabs[j], m_justifs[j]); - if ( pe == 0 ) break; + if ( pe == 0 ) + break; ppos.x += m_tabs[j]; - pb = pe+1; + pb = pe + 1; } } - if ( (m_state & STATE_EXTEND) && i < m_totalLine ) - { - pos = m_button[i]->RetPos(); - dim = m_button[i]->RetDim(); - pos.x += dim.x-dim.y*0.75f; - dim.x = dim.y*0.75f; - pos.x += 2.0f/640.0f; - pos.y += 2.0f/480.0f; - dim.x -= 4.0f/640.0f; - dim.y -= 4.0f/480.0f; - - if ( m_check[i+m_firstLine] ) - { + if ( (m_state & STATE_EXTEND) && i < m_totalLine) { + pos = m_button[i]->GetPos(); + dim = m_button[i]->GetDim(); + pos.x += dim.x - dim.y * 0.75f; + dim.x = dim.y * 0.75f; + pos.x += 2.0f / 640.0f; + pos.y += 2.0f / 480.0f; + dim.x -= 4.0f / 640.0f; + dim.y -= 4.0f / 480.0f; + + if ( m_check[i + m_firstLine] ) { m_engine->SetTexture("button1.tga"); - m_engine->SetState(D3DSTATENORMAL); - uv1.x = 64.0f/256.0f; - uv1.y = 0.0f/256.0f; - uv2.x = 96.0f/256.0f; - uv2.y = 32.0f/256.0f; + m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); + uv1.x = 64.0f / 256.0f; + uv1.y = 0.0f / 256.0f; + uv2.x = 96.0f / 256.0f; + uv2.y = 32.0f / 256.0f; uv1.x += dp; uv1.y += dp; uv2.x -= dp; uv2.y -= dp; DrawIcon(pos, dim, uv1, uv2); // square shape - m_engine->SetState(D3DSTATETTw); - uv1.x = 0.0f/256.0f; // v - uv1.y = 64.0f/256.0f; - uv2.x = 32.0f/256.0f; - uv2.y = 96.0f/256.0f; + m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE); // was D3DSTATETTw + uv1.x = 0.0f / 256.0f; // v + uv1.y = 64.0f / 256.0f; + uv2.x = 32.0f / 256.0f; + uv2.y = 96.0f / 256.0f; uv1.x += dp; uv1.y += dp; uv2.x -= dp; uv2.y -= dp; DrawIcon(pos, dim, uv1, uv2); // draws v - } - else - { + } else { m_engine->SetTexture("button1.tga"); - m_engine->SetState(D3DSTATETTw); - if ( i+m_firstLine == m_selectLine ) - { - uv1.x =224.0f/256.0f; // < - uv1.y =192.0f/256.0f; - uv2.x =256.0f/256.0f; - uv2.y =224.0f/256.0f; - } - else - { - uv1.x = 96.0f/256.0f; // x - uv1.y = 32.0f/256.0f; - uv2.x =128.0f/256.0f; - uv2.y = 64.0f/256.0f; + m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE); // was D3DSTATETTw + if ( i + m_firstLine == m_selectLine ) { + uv1.x =224.0f / 256.0f; // < + uv1.y =192.0f / 256.0f; + uv2.x =256.0f / 256.0f; + uv2.y =224.0f / 256.0f; + } else { + uv1.x = 96.0f / 256.0f; // x + uv1.y = 32.0f / 256.0f; + uv2.x =128.0f / 256.0f; + uv2.y = 64.0f / 256.0f; } uv1.x += dp; uv1.y += dp; @@ -546,29 +498,18 @@ void CList::Draw() } if ( m_scroll != 0 ) - { m_scroll->Draw(); // draws the lift - } } // Displays text in a box. -void CList::DrawCase(char *text, Math::Point pos, float width, int justif) +void CList::DrawCase(char *text, Math::Point pos, float width, Gfx::TextAlign justif) { - if ( justif == 1 ) - { - m_engine->RetText()->DrawText(text, pos, width, 1, m_fontSize, m_fontStretch, m_fontType, 0); - } - else if ( justif == 0 ) - { - pos.x += width/2.0f; - m_engine->RetText()->DrawText(text, pos, width, 0, m_fontSize, m_fontStretch, m_fontType, 0); - } + if (justif == Gfx::TEXT_ALIGN_LEFT) + pos.x += width / 2.0f; else - { pos.x += width; - m_engine->RetText()->DrawText(text, pos, width, -1, m_fontSize, m_fontStretch, m_fontType, 0); - } + m_engine->GetText()->DrawText(std::string(text), m_fontType, m_fontSize, pos, width, justif, 0); } @@ -593,7 +534,7 @@ void CList::SetTotal(int i) // Returns the total number of lines. -int CList::RetTotal() +int CList::GetTotal() { return m_totalLine; } @@ -604,11 +545,8 @@ int CList::RetTotal() void CList::SetSelect(int i) { if ( m_bSelectCap ) - { m_selectLine = i; - } - else - { + else { m_firstLine = i; UpdateScroll(); } @@ -618,16 +556,12 @@ void CList::SetSelect(int i) // Returns the selected line. -int CList::RetSelect() +int CList::GetSelect() { if ( m_bSelectCap ) - { return m_selectLine; - } else - { return m_firstLine; - } } @@ -638,7 +572,7 @@ void CList::SetSelectCap(bool bEnable) m_bSelectCap = bEnable; } -bool CList::RetSelectCap() +bool CList::GetSelectCap() { return m_bSelectCap; } @@ -648,25 +582,22 @@ bool CList::RetSelectCap() void CList::SetBlink(bool bEnable) { - int i; + int i; m_bBlink = bEnable; m_blinkTime = 0.0f; i = m_selectLine-m_firstLine; - if ( i >= 0 && i < 4 && - m_button[i] != 0 ) - { - if ( !bEnable ) - { + if (i >= 0 && i < 4 && m_button[i] != nullptr) { + if ( !bEnable ) { m_button[i]->SetState(STATE_CHECK); m_button[i]->ClearState(STATE_ENABLE); } } } -bool CList::RetBlink() +bool CList::GetBlink() { return m_bBlink; } @@ -676,30 +607,27 @@ bool CList::RetBlink() void CList::SetName(int i, char* name) { - if ( i < 0 || i >= LISTMAXTOTAL ) return; + if ( i < 0 || i >= LISTMAXTOTAL ) + return; if ( i >= m_totalLine ) - { m_totalLine = i+1; // expands the list - } if ( name[0] == 0 ) - { strcpy(m_text[i], " "); - } else - { strcpy(m_text[i], name); - } + UpdateButton(); UpdateScroll(); } // Returns the text of a line. -char* CList::RetName(int i) +char* CList::GetName(int i) { - if ( i < 0 || i >= m_totalLine ) return 0; + if ( i < 0 || i >= m_totalLine ) + return 0; return m_text[i]; } @@ -709,16 +637,18 @@ char* CList::RetName(int i) void CList::SetCheck(int i, bool bMode) { - if ( i < 0 || i >= m_totalLine ) return; + if ( i < 0 || i >= m_totalLine ) + return; m_check[i] = bMode; } // Returns the bit "check" for a box. -bool CList::RetCheck(int i) +bool CList::GetCheck(int i) { - if ( i < 0 || i >= m_totalLine ) return false; + if ( i < 0 || i >= m_totalLine ) + return false; return m_check[i]; } @@ -728,16 +658,18 @@ bool CList::RetCheck(int i) void CList::SetEnable(int i, bool bMode) { - if ( i < 0 || i >= m_totalLine ) return; + if ( i < 0 || i >= m_totalLine ) + return; m_enable[i] = bMode; } // Returns the bit "enable" for a box. -bool CList::RetEnable(int i) +bool CList::GetEnable(int i) { - if ( i < 0 || i >= m_totalLine ) return false; + if ( i < 0 || i >= m_totalLine ) + return false; return m_enable[i]; } @@ -745,16 +677,18 @@ bool CList::RetEnable(int i) // Management of the position of the tabs. -void CList::SetTabs(int i, float pos, int justif) +void CList::SetTabs(int i, float pos, Gfx::TextAlign justif) { - if ( i < 0 || i >= 10 ) return; + if ( i < 0 || i >= 10 ) + return; m_tabs[i] = pos; m_justifs[i] = justif; } -float CList::RetTabs(int i) +float CList::GetTabs(int i) { - if ( i < 0 || i >= 10 ) return 0.0f; + if ( i < 0 || i >= 10 ) + return 0.0f; return m_tabs[i]; } @@ -765,19 +699,20 @@ void CList::ShowSelect(bool bFixed) { int sel; - if ( bFixed && - m_selectLine >= m_firstLine && - m_selectLine < m_firstLine+m_displayLine ) return; // all good + if ( bFixed && m_selectLine >= m_firstLine && m_selectLine < m_firstLine+m_displayLine ) + return; // all good sel = m_selectLine; // Down from 1/2 * h. - sel += m_displayLine/2; - if ( sel > m_totalLine-1 ) sel = m_totalLine-1; + sel += m_displayLine / 2; + if ( sel > m_totalLine - 1 ) + sel = m_totalLine - 1; // Back to h-1. - sel -= m_displayLine-1; - if ( sel < 0 ) sel = 0; + sel -= m_displayLine - 1; + if ( sel < 0 ) + sel = 0; m_firstLine = sel; @@ -790,25 +725,22 @@ void CList::ShowSelect(bool bFixed) void CList::UpdateButton() { - int state, i, j; + int state, i, j; - state = CControl::RetState(); + state = CControl::GetState(); j = m_firstLine; - for ( i=0 ; iSetState(STATE_CHECK, (j == m_selectLine)); - if ( j < m_totalLine ) - { + 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)); - } - else - { + } else { m_button[i]->SetName(" "); // blank button m_button[i]->ClearState(STATE_ENABLE); } @@ -820,27 +752,28 @@ void CList::UpdateButton() void CList::UpdateScroll() { - float ratio, value, step; + float ratio, value, step; - if ( m_scroll == 0 ) return; + if (m_scroll == nullptr) + return; - if ( m_totalLine <= m_displayLine ) - { + if (m_totalLine <= m_displayLine) { ratio = 1.0f; value = 0.0f; step = 0.0f; - } - else - { - ratio = (float)m_displayLine/m_totalLine; + } else { + ratio = (float)m_displayLine / m_totalLine; if ( ratio > 1.0f ) ratio = 1.0f; - value = (float)m_firstLine/(m_totalLine-m_displayLine); - if ( value < 0.0f ) value = 0.0f; - if ( value > 1.0f ) value = 1.0f; + value = (float)m_firstLine / (m_totalLine - m_displayLine); + if ( value < 0.0f ) + value = 0.0f; + if ( value > 1.0f ) + value = 1.0f; - step = (float)1.0f/(m_totalLine-m_displayLine); - if ( step < 0.0f ) step = 0.0f; + step = (float)1.0f/ (m_totalLine - m_displayLine); + if ( step < 0.0f ) + step = 0.0f; } m_scroll->SetVisibleRatio(ratio); @@ -852,17 +785,21 @@ void CList::UpdateScroll() void CList::MoveScroll() { - float pos; - int n; + float pos; + int n; - if ( m_scroll == 0 ) return; + if ( m_scroll == 0 ) + return; - n = m_totalLine-m_displayLine; - pos = m_scroll->RetVisibleValue(); - pos += m_scroll->RetArrowStep()/2.0f; // it's magic! - m_firstLine = (int)(pos*n); - if ( m_firstLine < 0 ) m_firstLine = 0; - if ( m_firstLine > n ) m_firstLine = n; + n = m_totalLine - m_displayLine; + pos = m_scroll->GetVisibleValue(); + pos += m_scroll->GetArrowStep() / 2.0f; // it's magic! + m_firstLine = (int)(pos * n); + if ( m_firstLine < 0 ) + m_firstLine = 0; + if ( m_firstLine > n ) + m_firstLine = n; } +} diff --git a/src/ui/list.h b/src/ui/list.h index c7c278d..c963203 100644 --- a/src/ui/list.h +++ b/src/ui/list.h @@ -1,5 +1,6 @@ // * This file is part of the COLOBOT source code // * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch +// * Copyright (C) 2012 Polish Portal of Colobot (PPC) // * // * This program is free software: you can redistribute it and/or modify // * it under the terms of the GNU General Public License as published by @@ -20,9 +21,15 @@ #include +#include +#include #include +#include + + +namespace Ui { const int LISTMAXDISPLAY = 20; // maximum number of visible lines const int LISTMAXTOTAL = 100; // maximum total number of lines @@ -50,40 +57,40 @@ class CList : public CControl void Flush(); void SetTotal(int i); - int RetTotal(); + int GetTotal(); void SetSelect(int i); - int RetSelect(); + int GetSelect(); void SetSelectCap(bool bEnable); - bool RetSelectCap(); + bool GetSelectCap(); void SetBlink(bool bEnable); - bool RetBlink(); + bool GetBlink(); void SetName(int i, char* name); - char* RetName(int i); + char* GetName(int i); void SetCheck(int i, bool bMode); - bool RetCheck(int i); + bool GetCheck(int i); void SetEnable(int i, bool bEnable); - bool RetEnable(int i); + bool GetEnable(int i); - void SetTabs(int i, float pos, int justif=1); - float RetTabs(int i); + void SetTabs(int i, float pos, Gfx::TextAlign justif=Gfx::TEXT_ALIGN_CENTER); + float GetTabs(int i); void ShowSelect(bool bFixed); - EventType RetEventMsgButton(int i); - EventType RetEventMsgScroll(); + EventType GetEventMsgButton(int i); + EventType GetEventMsgScroll(); protected: bool MoveAdjust(); void UpdateButton(); void UpdateScroll(); void MoveScroll(); - void DrawCase(char *text, Math::Point pos, float width, int justif); + void DrawCase(char *text, Math::Point pos, float width, Gfx::TextAlign justif); protected: CButton* m_button[LISTMAXDISPLAY]; @@ -101,7 +108,7 @@ class CList : public CControl bool m_bSelectCap; float m_blinkTime; float m_tabs[10]; - int m_justifs[10]; + Gfx::TextAlign m_justifs[10]; char m_text[LISTMAXTOTAL][100]; char m_check[LISTMAXTOTAL]; @@ -109,3 +116,5 @@ class CList : public CControl }; +} + diff --git a/src/ui/scroll.cpp b/src/ui/scroll.cpp index 051de8d..5526c80 100644 --- a/src/ui/scroll.cpp +++ b/src/ui/scroll.cpp @@ -35,7 +35,7 @@ // Object's constructor. -CScroll::CScroll(CInstanceManager* iMan) : CControl(iMan) +CScroll::CScroll() : CControl() { m_buttonUp = 0; m_buttonDown = 0; @@ -106,7 +106,7 @@ void CScroll::MoveAdjust() pc = (CButton*)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->RetEventMsg(); + m_eventUp = pc->GetEventMsg(); } if ( m_buttonDown == 0 ) @@ -115,7 +115,7 @@ void CScroll::MoveAdjust() pc = (CButton*)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->RetEventMsg(); + m_eventDown = pc->GetEventMsg(); } } @@ -299,7 +299,7 @@ bool CScroll::EventProcess(const Event &event) m_buttonUp != 0 ) { Event newEvent = event; - newEvent.event = m_buttonUp->RetEventMsg(); + newEvent.event = m_buttonUp->GetEventMsg(); m_event->AddEvent(newEvent); } if ( event.event == EVENT_KEYDOWN && @@ -308,7 +308,7 @@ bool CScroll::EventProcess(const Event &event) m_buttonDown != 0 ) { Event newEvent = event; - newEvent.event = m_buttonDown->RetEventMsg(); + newEvent.event = m_buttonDown->GetEventMsg(); m_event->AddEvent(newEvent); } @@ -437,7 +437,7 @@ void CScroll::SetVisibleValue(float value) AdjustGlint(); } -float CScroll::RetVisibleValue() +float CScroll::GetVisibleValue() { return m_visibleValue; } @@ -451,7 +451,7 @@ void CScroll::SetVisibleRatio(float value) AdjustGlint(); } -float CScroll::RetVisibleRatio() +float CScroll::GetVisibleRatio() { return m_visibleRatio; } @@ -462,7 +462,7 @@ void CScroll::SetArrowStep(float step) m_step = step; } -float CScroll::RetArrowStep() +float CScroll::GetArrowStep() { return m_step; } diff --git a/src/ui/scroll.h b/src/ui/scroll.h index a82fea0..289d309 100644 --- a/src/ui/scroll.h +++ b/src/ui/scroll.h @@ -46,13 +46,13 @@ class CScroll : public CControl void Draw(); void SetVisibleValue(float value); - float RetVisibleValue(); + float GetVisibleValue(); void SetVisibleRatio(float value); - float RetVisibleRatio(); + float GetVisibleRatio(); void SetArrowStep(float step); - float RetArrowStep(); + float GetArrowStep(); protected: void MoveAdjust(); -- cgit v1.2.3-1-g7c22 From 48ad79a03c12b923dfdb3795a2138445859cf779 Mon Sep 17 00:00:00 2001 From: erihel Date: Sat, 18 Aug 2012 11:30:29 +0200 Subject: * minor changes to control.cpp to compile it without errors --- src/ui/control.cpp | 4 ++-- src/ui/control.h | 26 +++++++++++++------------- 2 files changed, 15 insertions(+), 15 deletions(-) (limited to 'src/ui') diff --git a/src/ui/control.cpp b/src/ui/control.cpp index 61fd6dd..9893fc8 100644 --- a/src/ui/control.cpp +++ b/src/ui/control.cpp @@ -43,9 +43,9 @@ // Object's constructor. -CControl::CControl(CInstanceManager* iMan) +CControl::CControl() { - m_iMan = iMan; + m_iMan = CInstanceManager::GetInstancePointer(); m_engine = static_cast< Gfx::CEngine* > ( m_iMan->SearchInstance(CLASS_ENGINE) ); m_event = static_cast< CEventQueue* > ( m_iMan->SearchInstance(CLASS_EVENT) ); diff --git a/src/ui/control.h b/src/ui/control.h index d336ede..dcae4f2 100644 --- a/src/ui/control.h +++ b/src/ui/control.h @@ -20,18 +20,18 @@ //#include "old/text.h" -#include "common/struct.h" -#include "common/event.h" -#include "graphics/engine/engine.h" -#include "graphics/engine/text.h" -#include "graphics/engine/particle.h" +#include +#include -#include "sound/sound.h" +#include +#include +#include -class CInstanceManager; -class CEvent; +#include + +// class CEvent; //class Gfx::CEngine; -class CRobotMain; +// class CRobotMain; //class Gfx::CParticle; //class CSound; @@ -80,8 +80,8 @@ public: virtual int GetState(); virtual void SetIcon(int icon); virtual int GetIcon(); - virtual void SetName(const char* name, bool bTooltip=true); - virtual const char* GetName(); + virtual void SetName(char* name, bool bTooltip=true); + virtual char* GetName(); virtual void SetTextAlign(Gfx::TextAlign mode); virtual int GetTextAlign(); virtual void SetFontSize(float size); @@ -90,8 +90,8 @@ public: virtual float GetFontStretch(); virtual void SetFontType(Gfx::FontType font); virtual Gfx::FontType GetFontType(); - virtual bool SetTooltip(const char* name); - virtual bool GetTooltip(Math::Point pos, const char* name); + virtual bool SetTooltip(char* name); + virtual bool GetTooltip(Math::Point pos, char* name); virtual void SetFocus(bool bFocus); virtual bool GetFocus(); -- cgit v1.2.3-1-g7c22 From 8d4a3ed57915af2acf8b3dcd9a8aec5a75806ca6 Mon Sep 17 00:00:00 2001 From: erihel Date: Sat, 18 Aug 2012 21:04:51 +0200 Subject: * wrong enum used for text alignment * wrong event function used --- src/ui/interface.cpp | 24 ++++++------------------ src/ui/key.cpp | 8 ++------ src/ui/label.cpp | 12 ++++-------- src/ui/label.h | 1 + src/ui/list.cpp | 18 +++++++----------- src/ui/list.h | 1 + 6 files changed, 21 insertions(+), 43 deletions(-) (limited to 'src/ui') diff --git a/src/ui/interface.cpp b/src/ui/interface.cpp index 0398e7f..6c96501 100644 --- a/src/ui/interface.cpp +++ b/src/ui/interface.cpp @@ -72,12 +72,8 @@ template inline T* CInterface::CreateControl(Math::Point pos, Math: { T* pc; int index; - Event event; - - if (eventMsg == EVENT_NULL) { - m_event->GetEvent(event); - eventMsg = event.type; - } + if (eventMsg == EVENT_NULL) + eventMsg = GetUniqueEventType(); if ((index = GetNextFreeControl()) < 0) return nullptr; @@ -95,12 +91,8 @@ CWindow* CInterface::CreateWindows(Math::Point pos, Math::Point dim, int icon, E { CWindow* pc; int index; - Event event; - - if (eventMsg == EVENT_NULL) { - m_event->GetEvent(event); - eventMsg = event.type; - } + if (eventMsg == EVENT_NULL) + eventMsg = GetUniqueEventType(); switch (eventMsg) { case EVENT_WINDOW0: index = 0; break; @@ -212,12 +204,8 @@ CList* CInterface::CreateList(Math::Point pos, Math::Point dim, int icon, EventT { CList* pc; int index; - Event event; - - if (eventMsg == EVENT_NULL) { - m_event->GetEvent(event); - eventMsg = event.type; - } + if (eventMsg == EVENT_NULL) + eventMsg = GetUniqueEventType(); if ((index = GetNextFreeControl()) < 0) return nullptr; diff --git a/src/ui/key.cpp b/src/ui/key.cpp index de668bc..0cf74bc 100644 --- a/src/ui/key.cpp +++ b/src/ui/key.cpp @@ -59,12 +59,8 @@ CKey::~CKey() bool CKey::Create(Math::Point pos, Math::Point dim, int icon, EventType eventMsg) { char name[100]; - Event event; - - if (eventMsg == EVENT_NULL) { - m_event->GetEvent(event); - eventMsg = event.type; - } + if (eventMsg == EVENT_NULL) + eventMsg = GetUniqueEventType(); CControl::Create(pos, dim, icon, eventMsg); GetResource(RES_EVENT, eventMsg, name); diff --git a/src/ui/label.cpp b/src/ui/label.cpp index fb5f1d8..c5da211 100644 --- a/src/ui/label.cpp +++ b/src/ui/label.cpp @@ -40,12 +40,8 @@ CLabel::~CLabel() bool CLabel::Create(Math::Point pos, Math::Point dim, int icon, EventType eventMsg) { - Event event; - - if (eventMsg == EVENT_NULL) { - m_event->GetEvent(event); - eventMsg = event.type; - } + if (eventMsg == EVENT_NULL) + eventMsg = GetUniqueEventType(); CControl::Create(pos, dim, icon, eventMsg); return true; @@ -73,9 +69,9 @@ void CLabel::Draw() pos.y = m_pos.y + m_dim.y / 2.0f; switch (m_textAlign) { - case Gfx::TEXT_ALIGN_LEFT: pos.x = m_pos.x; break; + case Gfx::TEXT_ALIGN_RIGHT: pos.x = m_pos.x; break; case Gfx::TEXT_ALIGN_CENTER: pos.x = m_pos.x + m_dim.x / 2.0f; break; - case Gfx::TEXT_ALIGN_RIGHT: pos.x = m_pos.x + m_dim.x; break; + case Gfx::TEXT_ALIGN_LEFT: pos.x = m_pos.x + m_dim.x; break; } m_engine->GetText()->DrawText(std::string(m_name), m_fontType, m_fontSize, pos, m_dim.x, m_textAlign, 0); diff --git a/src/ui/label.h b/src/ui/label.h index 303b698..6fe2e31 100644 --- a/src/ui/label.h +++ b/src/ui/label.h @@ -23,6 +23,7 @@ #include #include +#include namespace Ui { diff --git a/src/ui/list.cpp b/src/ui/list.cpp index 9f1d579..73a48e3 100644 --- a/src/ui/list.cpp +++ b/src/ui/list.cpp @@ -42,7 +42,7 @@ CList::CList() : CControl() for (int i = 0; i < 10; i++) { m_tabs[i] = 0.0f; - m_justifs[i] = Gfx::TEXT_ALIGN_CENTER; + m_justifs[i] = Gfx::TEXT_ALIGN_RIGHT; } m_totalLine = 0; @@ -72,14 +72,10 @@ CList::~CList() bool CList::Create(Math::Point pos, Math::Point dim, int icon, EventType eventMsg, float expand) { - Event event; m_expand = expand; - if (eventMsg == EVENT_NULL) { - m_event->GetEvent(event); - eventMsg = event.type; - } - + if (eventMsg == EVENT_NULL) + eventMsg = GetUniqueEventType(); CControl::Create(pos, dim, icon, eventMsg); @@ -131,7 +127,7 @@ bool CList::MoveAdjust() 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_CENTER); + m_button[i]->SetTextAlign(Gfx::TEXT_ALIGN_RIGHT); m_button[i]->SetState(STATE_SIMPLY); m_button[i]->SetFontType(m_fontType); m_button[i]->SetFontSize(m_fontSize); @@ -417,7 +413,7 @@ void CList::Draw() 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_CENTER); + DrawCase(m_text[i + m_firstLine], ppos, ddim.x, Gfx::TEXT_ALIGN_RIGHT); } else { ppos.x = pos.x + dim.y * 0.5f; ppos.y = pos.y + dim.y * 0.5f; @@ -505,9 +501,9 @@ void CList::Draw() void CList::DrawCase(char *text, Math::Point pos, float width, Gfx::TextAlign justif) { - if (justif == Gfx::TEXT_ALIGN_LEFT) + if (justif == Gfx::TEXT_ALIGN_CENTER) pos.x += width / 2.0f; - else + else if (justif == Gfx::TEXT_ALIGN_LEFT) pos.x += width; m_engine->GetText()->DrawText(std::string(text), m_fontType, m_fontSize, pos, width, justif, 0); } diff --git a/src/ui/list.h b/src/ui/list.h index c963203..2fc5e4d 100644 --- a/src/ui/list.h +++ b/src/ui/list.h @@ -25,6 +25,7 @@ #include #include +#include #include -- cgit v1.2.3-1-g7c22