summaryrefslogtreecommitdiffstats
path: root/src/ui
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/edit.cpp4
-rw-r--r--src/ui/key.cpp169
-rw-r--r--src/ui/key.h45
-rw-r--r--src/ui/maindialog.cpp117
-rw-r--r--src/ui/mainshort.cpp2
-rw-r--r--src/ui/mainshort.h2
-rw-r--r--src/ui/studio.cpp4
7 files changed, 151 insertions, 192 deletions
diff --git a/src/ui/edit.cpp b/src/ui/edit.cpp
index 547e73a..e14b19d 100644
--- a/src/ui/edit.cpp
+++ b/src/ui/edit.cpp
@@ -1794,7 +1794,7 @@ bool CEdit::ReadText(const char *filename, int addSize)
if ( SearchKey(buffer+i+5, slot) )
{
CRobotMain* main = CRobotMain::GetInstancePointer();
- res = main->GetInputBinding(slot).key;
+ res = main->GetInputBinding(slot).primary;
if ( res != 0 )
{
if ( GetResource(RES_KEY, res, iName) )
@@ -1813,7 +1813,7 @@ bool CEdit::ReadText(const char *filename, int addSize)
m_format[j] = font;
j ++;
- res = main->GetInputBinding(slot).joy;
+ res = main->GetInputBinding(slot).secondary;
if ( res != 0 )
{
if ( GetResource(RES_KEY, res, iName) )
diff --git a/src/ui/key.cpp b/src/ui/key.cpp
index 26d99ac..9a76127 100644
--- a/src/ui/key.cpp
+++ b/src/ui/key.cpp
@@ -15,65 +15,48 @@
// * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/.
-// key.cpp
-
-
#include "ui/key.h"
-#include <string.h>
+#include "common/global.h"
+
+#include <cstring>
namespace Ui {
-void GetKeyName(char *name, int key)
+
+void GetKeyName(char* name, unsigned int key)
{
- if ( !GetResource(RES_KEY, key, name) ) {
- if (isalnum(key)) {
- name[0] = key;
- name[1] = 0;
- }
- else {
- sprintf(name, "Code %d", key);
- }
- }
+ if (!GetResource(RES_KEY, key, name))
+ sprintf(name, "Code %d", key);
}
-// Object's constructor.
-
CKey::CKey() : CControl()
{
- m_key[0] = 0;
- m_key[1] = 0;
- m_bCatch = false;
+ m_catch = false;
- m_app = CApplication::GetInstancePointer();
+ m_robotMain = CRobotMain::GetInstancePointer();
}
-// Object's destructor.
-
CKey::~CKey()
{
+ m_robotMain = nullptr;
}
-
-// Creates a new button.
-
bool CKey::Create(Math::Point pos, Math::Point dim, int icon, EventType eventMsg)
{
- char name[100];
if (eventMsg == EVENT_NULL)
eventMsg = GetUniqueEventType();
CControl::Create(pos, dim, icon, eventMsg);
+
+ char name[100];
GetResource(RES_EVENT, eventMsg, name);
SetName(std::string(name));
return true;
}
-
-// Management of an event.
-
bool CKey::EventProcess(const Event &event)
{
if (m_state & STATE_DEAD)
@@ -81,24 +64,31 @@ bool CKey::EventProcess(const Event &event)
CControl::EventProcess(event);
- if (event.type == EVENT_MOUSE_BUTTON_DOWN) {
+ if (event.type == EVENT_MOUSE_BUTTON_DOWN)
+ {
if (event.mouseButton.button == MOUSE_BUTTON_LEFT) // left
- m_bCatch = Detect(event.mousePos);
+ m_catch = Detect(event.mousePos);
}
- if (event.type == EVENT_KEY_DOWN && m_bCatch) {
- m_bCatch = false;
+ if (event.type == EVENT_KEY_DOWN && m_catch)
+ {
+ m_catch = false;
- if ( TestKey(event.key.key) ) { // impossible ?
+ if (TestKey(event.key.key)) // impossible ?
+ {
m_sound->Play(SOUND_TZOING);
- } else {
- // TODO: test for virtual, joystick, etc.
- if ( event.key.key == m_key[0] || event.key.key == m_key[1] ) {
- m_key[0] = event.key.key;
- m_key[1] = 0;
- } else {
- m_key[1] = m_key[0];
- m_key[0] = event.key.key;
+ }
+ else
+ {
+ if (event.key.key == m_binding.primary || event.key.key == m_binding.secondary)
+ {
+ m_binding.secondary = KEY_INVALID;
+ m_binding.primary = event.key.key;
+ }
+ else
+ {
+ m_binding.secondary = m_binding.primary;
+ m_binding.primary = event.key.key;
}
m_sound->Play(SOUND_CLICK);
@@ -112,96 +102,88 @@ bool CKey::EventProcess(const Event &event)
return true;
}
-
-// Seeks when a key is already used.
-
-bool CKey::TestKey(int key)
+bool CKey::TestKey(unsigned int key)
{
- if ( key == KEY(PAUSE) || key == KEY(PRINT) ) return true; // blocked key
+ if (key == KEY(PAUSE) || key == KEY(PRINT)) return true; // blocked key
- /* TODO: input bindings
- 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!
- }
+ for (int i = 0; i < INPUT_SLOT_MAX; i++)
+ {
+ InputSlot slot = static_cast<InputSlot>(i);
+ InputBinding b = m_robotMain->GetInputBinding(slot);
+ if (key == b.primary || key == b.secondary)
+ m_robotMain->SetInputBinding(slot, InputBinding()); // nothing!
- 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);
- }
- } */
+ if (b.primary == KEY_INVALID) // first free option?
+ m_robotMain->SetInputBinding(slot, InputBinding(b.secondary, b.primary)); // shift
+ }
return false; // not used
}
-
-// Draws button.
-
void CKey::Draw()
{
- Math::Point iDim, pos;
- float zoomExt, zoomInt, h;
- int icon;
- char text[100];
-
- if ( (m_state & STATE_VISIBLE) == 0 )
+ if ((m_state & STATE_VISIBLE) == 0)
return;
- iDim = m_dim;
+ Math::Point iDim = m_dim;
m_dim.x = 200.0f/640.0f;
- if ( m_state & STATE_SHADOW )
+ if (m_state & STATE_SHADOW)
DrawShadow(m_pos, m_dim);
m_engine->SetTexture("button1.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); // was D3DSTATENORMAL
- zoomExt = 1.00f;
- zoomInt = 0.95f;
+ float zoomExt = 1.00f;
+ float zoomInt = 0.95f;
- icon = 2;
- if ( m_key[0] == 0 && m_key[1] == 0 ) // no shortcut?
+ int icon = 2;
+ if (m_binding.primary == KEY_INVALID && m_binding.secondary == KEY_INVALID) // 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 )
+ if (m_state & STATE_HILIGHT)
icon = 1;
- if ( m_state & STATE_CHECK )
+ 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 )
+ if ((m_state & STATE_ENABLE) == 0)
icon = 7;
- if ( m_state & STATE_DEAD )
+ if (m_state & STATE_DEAD)
icon = 17;
- if ( m_bCatch )
+ if (m_catch)
icon = 23;
DrawPart(icon, zoomExt, 8.0f / 256.0f); // draws the button
- h = m_engine->GetText()->GetHeight(m_fontType, m_fontSize) / 2.0f;
+ float h = m_engine->GetText()->GetHeight(m_fontType, m_fontSize) / 2.0f;
- GetKeyName(text, m_key[0]);
- if ( m_key[1] != 0 ) {
+ char text[100];
+ GetKeyName(text, m_binding.primary);
+ if (m_binding.secondary != KEY_INVALID)
+ {
GetResource(RES_TEXT, RT_KEY_OR, text+strlen(text));
- GetKeyName(text+strlen(text), m_key[1]);
+ GetKeyName(text+strlen(text), m_binding.secondary);
}
+ Math::Point pos;
pos.x = m_pos.x + m_dim.x * 0.5f;
pos.y = m_pos.y + m_dim.y * 0.5f;
pos.y -= h;
@@ -209,7 +191,7 @@ void CKey::Draw()
m_dim = iDim;
- if ( m_state & STATE_DEAD )
+ if (m_state & STATE_DEAD)
return;
// Draws the name.
@@ -219,20 +201,15 @@ void CKey::Draw()
m_engine->GetText()->DrawText(std::string(m_name), m_fontType, m_fontSize, pos, m_dim.x, Gfx::TEXT_ALIGN_LEFT, 0);
}
-
-
-void CKey::SetKey(int option, int key)
+void CKey::SetBinding(InputBinding b)
{
- if ( option < 0 || option > 1 ) return;
-
- m_key[option] = key;
+ m_binding = b;
}
-int CKey::GetKey(int option)
+InputBinding CKey::GetBinding()
{
- if ( option < 0 || option > 1 ) return 0;
-
- return m_key[option];
+ return m_binding;
}
-}
+
+} // namespace Ui
diff --git a/src/ui/key.h b/src/ui/key.h
index 1943f61..2332c9b 100644
--- a/src/ui/key.h
+++ b/src/ui/key.h
@@ -15,13 +15,13 @@
// * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/.
-// key.h
+/**
+ * \file ui/key.h
+ * \brief Key slot control
+ */
#pragma once
-#include <cctype>
-#include <string>
-
#include "ui/control.h"
#include "common/iman.h"
@@ -29,33 +29,40 @@
#include "common/restext.h"
#include "common/key.h"
-#include "app/app.h"
namespace Ui {
class CKey : public CControl
{
- public:
- CKey();
- virtual ~CKey();
+public:
+ CKey();
+ virtual ~CKey();
- bool Create(Math::Point pos, Math::Point dim, int icon, EventType eventMsg);
- bool EventProcess(const Event &event);
+ //! Creates a new key slot button
+ bool Create(Math::Point pos, Math::Point dim, int icon, EventType eventMsg);
+ //! Management of an event
+ bool EventProcess(const Event &event);
- void Draw();
+ //! Draws button
+ void Draw();
- void SetKey(int option, int key);
- int GetKey(int option);
+ //! Management of binding
+ //@{
+ void SetBinding(InputBinding b);
+ InputBinding GetBinding();
+ //@}
- protected:
- bool TestKey(int key);
+protected:
+ //! Checks if a key is already used
+ bool TestKey(unsigned int key);
- unsigned int m_key[2];
- bool m_bCatch;
+protected:
+ CRobotMain* m_robotMain;
- CApplication *m_app;
+ InputBinding m_binding;
+ bool m_catch;
};
-}
+} // namespace Ui
diff --git a/src/ui/maindialog.cpp b/src/ui/maindialog.cpp
index d7295eb..5136a41 100644
--- a/src/ui/maindialog.cpp
+++ b/src/ui/maindialog.cpp
@@ -8,7 +8,7 @@
// *
// * This program is distributed in the hope that it will be useful,
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
-// * MERCHANTABILITY or FITNESS FOR A Gfx::PARTICULAR PURPOSE. See the
+// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// * GNU General Public License for more details.
// *
// * You should have received a copy of the GNU General Public License
@@ -5476,7 +5476,6 @@ void CMainDialog::SetupMemorize()
{
float fValue;
int iValue, i, j;
- char key[500];
char num[10];
GetProfile().SetLocalProfileString("Directory", "scene", m_sceneDir);
@@ -5518,21 +5517,16 @@ void CMainDialog::SetupMemorize()
// GetProfile()->SetLocalProfileInt("Setup", "UseJoystick", m_engine->GetJoystick());
// GetProfile()->SetLocalProfileInt("Setup", "MidiVolume", m_sound->GetMidiVolume());
- // key[0] = 0;
- // for ( i=0 ; i<100 ; i++ )
- // {
- // if ( m_engine->GetKey(i, 0) == 0 ) break;
-
- // for ( j=0 ; j<2 ; j++ )
- // {
- // iValue = m_engine->GetKey(i, j);
- // sprintf(num, "%d%c", iValue, j==0?'+':' ');
- // strcat(key, num);
- // }
- // }
+ std::stringstream key;
+ for (int i = 0; i < INPUT_SLOT_MAX; i++)
+ {
+ InputBinding b = m_main->GetInputBinding(static_cast<InputSlot>(i));
- /* TODO: profile
- SetLocalProfileString("Setup", "KeyMap", key); */
+ key << b.primary << " ";
+ key << b.secondary << " ";
+ }
+
+ GetProfile().SetLocalProfileString("Setup", "KeyMap", key.str());
#if _NET
if ( m_accessEnable )
@@ -5556,9 +5550,8 @@ void CMainDialog::SetupMemorize()
void CMainDialog::SetupRecall()
{
float fValue;
- int iValue, i, j;
+ int iValue;
std::string key;
- char* p;
if ( GetProfile().GetLocalProfileString("Directory", "scene", key) )
{
@@ -5747,22 +5740,18 @@ void CMainDialog::SetupRecall()
m_engine->SetEditIndentValue(iValue);
}
- // if ( GetLocalProfileString("Setup", "KeyMap", key, 500) )
- // {
- // p = key;
- // for ( i=0 ; i<100 ; i++ )
- // {
- // if ( p[0] == 0 ) break;
-
- // for ( j=0 ; j<2 ; j++ )
- // {
- // sscanf(p, "%d", &iValue);
- // m_engine->SetKey(i, j, iValue);
- // while ( *p >= '0' && *p <= '9' ) p++;
- // while ( *p == ' ' || *p == '+' ) p++;
- // }
- // }
- // }
+ if (GetProfile().GetLocalProfileString("Setup", "KeyMap", key))
+ {
+ std::stringstream skey;
+ skey.str(key);
+ for (int i = 0; i < INPUT_SLOT_MAX; i++)
+ {
+ InputBinding b;
+ skey >> b.primary;
+ skey >> b.secondary;
+ m_main->SetInputBinding(static_cast<InputSlot>(i), b);
+ }
+ }
#if _NET
if ( m_accessEnable )
@@ -5837,7 +5826,7 @@ void CMainDialog::ChangeSetupQuality(int quality)
// Redefinable keys:
-static int key_table[KEY_TOTAL] =
+static InputSlot key_table[KEY_TOTAL] =
{
INPUT_SLOT_LEFT,
INPUT_SLOT_RIGHT,
@@ -5891,37 +5880,30 @@ static EventType key_event[KEY_TOTAL] =
void CMainDialog::UpdateKey()
{
- CWindow* pw;
- CScroll* ps;
- CKey* pk;
- Math::Point pos, dim;
- int first, i;
+ CWindow* pw = static_cast<CWindow*>(m_interface->SearchControl(EVENT_WINDOW5));
+ if (pw == nullptr) return;
- pw = static_cast<CWindow*>(m_interface->SearchControl(EVENT_WINDOW5));
- if ( pw == 0 ) return;
-
- ps = static_cast<CScroll*>(pw->SearchControl(EVENT_INTERFACE_KSCROLL));
- if ( ps == 0 ) return;
+ CScroll* ps = static_cast<CScroll*>(pw->SearchControl(EVENT_INTERFACE_KSCROLL));
+ if (ps == nullptr) return;
- first = static_cast<int>(ps->GetVisibleValue()*(KEY_TOTAL-KEY_VISIBLE));
+ int first = static_cast<int>(ps->GetVisibleValue()*(KEY_TOTAL-KEY_VISIBLE));
- for ( i=0 ; i<KEY_TOTAL ; i++ )
- {
+ for (int i = 0; i < KEY_TOTAL; i++)
pw->DeleteControl(key_event[i]);
- }
+ Math::Point dim;
dim.x = 400.0f/640.0f;
dim.y = 20.0f/480.0f;
+ Math::Point pos;
pos.x = 110.0f/640.0f;
pos.y = 168.0f/480.0f + dim.y*(KEY_VISIBLE-1);
- for ( i=0 ; i<KEY_VISIBLE ; i++ )
+ for (int i = 0; i < KEY_VISIBLE; i++)
{
pw->CreateKey(pos, dim, -1, key_event[first+i]);
- pk = static_cast<CKey*>(pw->SearchControl(key_event[first+i]));
- if ( pk == 0 ) break;
- /* TODO: set input bindings
- pk->SetKey(0, m_engine->GetKey(key_table[first+i], 0));
- pk->SetKey(1, m_engine->GetKey(key_table[first+i], 1)); */
+ CKey* pk = static_cast<CKey*>(pw->SearchControl(key_event[first+i]));
+ if (pk == nullptr) break;
+
+ pk->SetBinding(m_main->GetInputBinding(key_table[first+i]));
pos.y -= dim.y;
}
}
@@ -5930,26 +5912,20 @@ void CMainDialog::UpdateKey()
void CMainDialog::ChangeKey(EventType event)
{
- CWindow* pw;
- CScroll* ps;
- CKey* pk;
- int i;
-
- pw = static_cast<CWindow*>(m_interface->SearchControl(EVENT_WINDOW5));
- if ( pw == 0 ) return;
+ CWindow* pw = static_cast<CWindow*>(m_interface->SearchControl(EVENT_WINDOW5));
+ if (pw == nullptr) return;
- ps = static_cast<CScroll*>(pw->SearchControl(EVENT_INTERFACE_KSCROLL));
- if ( ps == 0 ) return;
+ CScroll* ps = static_cast<CScroll*>(pw->SearchControl(EVENT_INTERFACE_KSCROLL));
+ if (ps == nullptr) return;
- for ( i=0 ; i<KEY_TOTAL ; i++ )
+ for (int i = 0; i < KEY_TOTAL; i++)
{
if ( key_event[i] == event )
{
- pk = static_cast<CKey*>(pw->SearchControl(key_event[i]));
- if ( pk == 0 ) break;
- /* TODO: set key binding
- m_engine->SetKey(key_table[i], 0, pk->GetKey(0));
- m_engine->SetKey(key_table[i], 1, pk->GetKey(1)); */
+ CKey* pk = static_cast<CKey*>(pw->SearchControl(key_event[i]));
+ if (pk == nullptr) break;
+
+ m_main->SetInputBinding(key_table[i], pk->GetBinding());
}
}
}
@@ -6803,4 +6779,3 @@ bool CMainDialog::NextMission()
} // namespace Ui
-
diff --git a/src/ui/mainshort.cpp b/src/ui/mainshort.cpp
index ac6d7fc..55b9612 100644
--- a/src/ui/mainshort.cpp
+++ b/src/ui/mainshort.cpp
@@ -30,7 +30,7 @@ CMainShort::CMainShort()
m_iMan->AddInstance(CLASS_SHORT, this);
m_interface = static_cast<CInterface*>(m_iMan->SearchInstance(CLASS_INTERFACE));
- m_event = static_cast<CEvent*>(m_iMan->SearchInstance(CLASS_EVENT));
+ m_event = static_cast<CEventQueue*>(m_iMan->SearchInstance(CLASS_EVENT));
m_engine = static_cast<Gfx::CEngine*>(m_iMan->SearchInstance(CLASS_ENGINE));
m_main = static_cast<CRobotMain*>(m_iMan->SearchInstance(CLASS_MAIN));
diff --git a/src/ui/mainshort.h b/src/ui/mainshort.h
index e97bdcc..0912e68 100644
--- a/src/ui/mainshort.h
+++ b/src/ui/mainshort.h
@@ -47,7 +47,7 @@ class CMainShort
protected:
CInstanceManager* m_iMan;
- CEvent* m_event;
+ CEventQueue* m_event;
Gfx::CEngine* m_engine;
CInterface* m_interface;
CRobotMain* m_main;
diff --git a/src/ui/studio.cpp b/src/ui/studio.cpp
index a581baa..2f58c95 100644
--- a/src/ui/studio.cpp
+++ b/src/ui/studio.cpp
@@ -241,8 +241,8 @@ bool CStudio::EventProcess(const Event &event)
if ( event.type == EVENT_KEY_DOWN )
{
- if ( event.key.key == m_main->GetInputBinding(INPUT_SLOT_CBOT).key ||
- event.key.key == m_main->GetInputBinding(INPUT_SLOT_CBOT).joy )
+ if ( event.key.key == m_main->GetInputBinding(INPUT_SLOT_CBOT).primary ||
+ event.key.key == m_main->GetInputBinding(INPUT_SLOT_CBOT).secondary )
{
if ( m_helpFilename.length() > 0 )
{