summaryrefslogtreecommitdiffstats
path: root/src/ui/control.cpp
diff options
context:
space:
mode:
authorerihel <erihel@gmail.com>2012-08-31 22:28:07 +0200
committererihel <erihel@gmail.com>2012-08-31 22:28:07 +0200
commit6ba0f42f22a170625f15879e01b4653a4ac153a1 (patch)
tree129478ed8c5e4fd167c7c77c8ce00b88c5a4f83b /src/ui/control.cpp
parent5408fe92527a4df01e4d66a2cdfdbbbea5738afc (diff)
downloadcolobot-6ba0f42f22a170625f15879e01b4653a4ac153a1.tar.gz
colobot-6ba0f42f22a170625f15879e01b4653a4ac153a1.tar.bz2
colobot-6ba0f42f22a170625f15879e01b4653a4ac153a1.zip
latest changes; few more classes should compile now
Diffstat (limited to 'src/ui/control.cpp')
-rw-r--r--src/ui/control.cpp104
1 files changed, 29 insertions, 75 deletions
diff --git a/src/ui/control.cpp b/src/ui/control.cpp
index 37392d7..59e9f00 100644
--- a/src/ui/control.cpp
+++ b/src/ui/control.cpp
@@ -16,28 +16,7 @@
// * along with this program. If not, see http://www.gnu.org/licenses/.
-//#include <windows.h>
-#include <stdio.h>
-//#include <d3d.h>
-
-#include "graphics/core/device.h"
-//#include "common/struct.h"
-//#include "old/d3dengine.h"
-#include "graphics/engine/engine.h"
-#include "common/language.h"
-#include "common/restext.h"
-//#include "old/math3d.h"
-#include "common/event.h"
-#include "common/misc.h"
-#include "object/robotmain.h"
-//#include "old/particule.h"
-#include "graphics/engine/particle.h"
-#include "common/iman.h"
-//#include "old/text.h"
-#include "graphics/engine/text.h"
-//#include "old/sound.h"
-#include "sound/sound.h"
-#include "ui/control.h"
+#include <ui/control.h>
@@ -60,8 +39,6 @@ CControl::CControl()
m_fontType = Gfx::FONT_COLOBOT;
m_textAlign = Gfx::TEXT_ALIGN_CENTER; //instead m_justify
// m_justif = 0;
- m_name[0] = 0;
- m_tooltip[0] = 0;
m_bFocus = false;
m_bCapture = false;
@@ -84,10 +61,11 @@ CControl::~CControl()
bool CControl::Create(Math::Point pos, Math::Point dim, int icon, EventType eventType)
{
- char text[100];
- char* p;
+ char text[100];
+ std::string str_text;
- if ( eventType == EVENT_NULL ) eventType = GetUniqueEventType();
+ if ( eventType == EVENT_NULL )
+ eventType = GetUniqueEventType();
m_pos = pos;
m_dim = dim;
@@ -99,17 +77,13 @@ bool CControl::Create(Math::Point pos, Math::Point dim, int icon, EventType even
GlintCreate(pos);
GetResource(RES_EVENT, m_eventType, text);
- p = strchr(text, '\\');
- if ( p == 0 )
- {
+ str_text = std::string(text);
+ auto p = str_text.find("\\");
+ if ( p == std::string::npos ) {
if ( icon != -1 )
- {
- strcpy(m_tooltip, text);
- }
- }
- else
- {
- strcpy(m_tooltip, p+1); // text after "\\"
+ m_tooltip = str_text;
+ } else {
+ m_tooltip = str_text.substr(p + 1);
}
return true;
@@ -202,41 +176,21 @@ int CControl::GetIcon()
// Management of the button name.
-void CControl::SetName(char* name, bool bTooltip)
+void CControl::SetName(std::string name, bool bTooltip)
{
- char* p;
-
- if ( bTooltip )
- {
- p = strchr(name, '\\');
- if ( p == 0 )
- {
- strncpy(m_name, name, 100);
- m_name[100-1] = 0;
+ if ( bTooltip ) {
+ auto p = name.find("\\");
+ if ( p == std::string::npos )
+ m_name = name;
+ else {
+ m_tooltip = name.substr(p + 1);
+ m_name = name.substr(0, p);
}
- else
- {
- char buffer[100];
-
- strncpy(m_tooltip, p+1, 100); // text after "\\"
- m_tooltip[100-1] = 0;
-
- strncpy(buffer, name, 100);
- buffer[100-1] = 0;
- p = strchr(buffer, '\\');
- if ( p != 0 ) *p = 0;
- strncpy(m_name, buffer, 100);
- m_name[100-1] = 0;
- }
- }
- else
- {
- strncpy(m_name, name, 100);
- m_name[100-1] = 0;
- }
+ } else
+ m_name = name;
}
-char* CControl::GetName()
+std::string CControl::GetName()
{
return m_name;
}
@@ -298,21 +252,21 @@ Gfx::FontType CControl::GetFontType()
// Specifies the tooltip.
-bool CControl::SetTooltip(char* name)
+bool CControl::SetTooltip(std::string name)
{
- strcpy(m_tooltip, name);
+ m_tooltip = name;
return true;
}
-bool CControl::GetTooltip(Math::Point pos, char* name)
+bool CControl::GetTooltip(Math::Point pos, std::string &name)
{
- if ( m_tooltip[0] == 0 ) return false;
- if ( (m_state & STATE_VISIBLE) == 0 ) return false;
+ if ( m_tooltip.length() == 0 ) return false;
+ if ( (m_state & STATE_VISIBLE) == 0 ) return false;
if ( (m_state & STATE_ENABLE) == 0 ) return false;
if ( m_state & STATE_DEAD ) return false;
if ( !Detect(pos) ) return false;
- strcpy(name, m_tooltip);
+ name = m_tooltip;
return true;
}
@@ -454,7 +408,7 @@ void CControl::GlintFrame(const Event &event)
(m_state & STATE_ENABLE ) == 0 ||
(m_state & STATE_VISIBLE) == 0 ) return;
- if ( !m_main->RetGlint() ) return;
+ if ( !m_main->GetGlint() ) return;
m_glintProgress += event.rTime;