Skip to content

Commit fe6bbc5

Browse files
committed
Rename HandleKeyPress to ExecuteCommand.
1 parent bb4550f commit fe6bbc5

File tree

3 files changed

+28
-28
lines changed

3 files changed

+28
-28
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ if (${EMSCRIPTEN})
6161
set (SDLUsedLibraries -sUSE_SDL=2 -sUSE_SDL_TTF=2)
6262
target_compile_options (WebApp PUBLIC ${SDLUsedLibraries})
6363
target_link_options (WebApp PUBLIC ${SDLUsedLibraries})
64-
target_link_options (WebApp PUBLIC "-sEXPORTED_FUNCTIONS=[\"_main\", \"_ResizeWindow\", \"_HandleKeyPress\", \"_CreateNode\", \"_ContextMenuResponse\", \"_ParameterSettingsResponse\"]")
64+
target_link_options (WebApp PUBLIC "-sEXPORTED_FUNCTIONS=[\"_main\", \"_ResizeWindow\", \"_ExecuteCommand\", \"_CreateNode\", \"_ContextMenuResponse\", \"_ParameterSettingsResponse\"]")
6565
target_link_options (WebApp PUBLIC "-sEXTRA_EXPORTED_RUNTIME_METHODS=[\"ccall\", \"cwrap\"]")
6666
target_link_options (WebApp PUBLIC --preload-file Assets)
6767
add_definitions (-DSIZEOFSIZET=4)

Sources/WebApp/main.cpp

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ void ResizeWindow (int width, int height)
127127
gAppForBrowser->ResizeWindow (width, height);
128128
}
129129

130-
void HandleKeyPress (char* keyCode)
130+
void ExecuteCommand (char* keyCode)
131131
{
132132
if (gAppForBrowser == nullptr) {
133133
return;
@@ -139,27 +139,23 @@ void HandleKeyPress (char* keyCode)
139139
}
140140

141141
std::string keyCodeStr (keyCode);
142-
NUIE::Key pressedKey (NUIE::KeyCode::Undefined);
142+
NUIE::NodeEditor& nodeEditor = gAppForBrowser->GetNodeEditor ();
143143
if (keyCodeStr == "SelectAll") {
144-
pressedKey.SetKeyCode (NUIE::KeyCode::SelectAll);
144+
nodeEditor.OnKeyPress (NUIE::KeyCode::SelectAll);
145145
} else if (keyCodeStr == "Copy") {
146-
pressedKey.SetKeyCode (NUIE::KeyCode::Copy);
146+
nodeEditor.OnKeyPress (NUIE::KeyCode::Copy);
147147
} else if (keyCodeStr == "Paste") {
148-
pressedKey.SetKeyCode (NUIE::KeyCode::Paste);
148+
nodeEditor.OnKeyPress (NUIE::KeyCode::Paste);
149149
} else if (keyCodeStr == "Group") {
150-
pressedKey.SetKeyCode (NUIE::KeyCode::Group);
150+
nodeEditor.OnKeyPress (NUIE::KeyCode::Group);
151151
} else if (keyCodeStr == "Undo") {
152-
pressedKey.SetKeyCode (NUIE::KeyCode::Undo);
152+
nodeEditor.OnKeyPress (NUIE::KeyCode::Undo);
153153
} else if (keyCodeStr == "Redo") {
154-
pressedKey.SetKeyCode (NUIE::KeyCode::Redo);
154+
nodeEditor.OnKeyPress (NUIE::KeyCode::Redo);
155155
} else if (keyCodeStr == "Escape") {
156-
pressedKey.SetKeyCode (NUIE::KeyCode::Escape);
156+
nodeEditor.OnKeyPress (NUIE::KeyCode::Escape);
157157
} else if (keyCodeStr == "Delete") {
158-
pressedKey.SetKeyCode (NUIE::KeyCode::Delete);
159-
}
160-
if (pressedKey.IsValid ()) {
161-
NUIE::NodeEditor& nodeEditor = gAppForBrowser->GetNodeEditor ();
162-
nodeEditor.OnKeyPress (pressedKey);
158+
nodeEditor.OnKeyPress (NUIE::KeyCode::Delete);
163159
}
164160
}
165161

Sources/WebSite/script/application.js

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,37 +46,35 @@ Application.prototype.InitKeyboardEvents = function ()
4646
overCanvas = false;
4747
});
4848

49-
var handleKeyPressFunc = this.module.cwrap ('HandleKeyPress', null, ['string']);
50-
5149
$(window).keydown (function (ev) {
5250
if (!overCanvas) {
5351
return;
5452
}
55-
var keyCode = null;
53+
var command = null;
5654
var isControlPressed = ev.ctrlKey;
5755
if (isControlPressed) {
5856
if (ev.which == 65) {
59-
keyCode = 'SelectAll';
57+
command = 'SelectAll';
6058
} else if (ev.which == 67) {
61-
keyCode = 'Copy';
59+
command = 'Copy';
6260
} else if (ev.which == 86) {
63-
keyCode = 'Paste';
61+
command = 'Paste';
6462
} else if (ev.which == 71) {
65-
keyCode = 'Group';
63+
command = 'Group';
6664
} else if (ev.which == 90) {
67-
keyCode = 'Undo';
65+
command = 'Undo';
6866
} else if (ev.which == 89) {
69-
keyCode = 'Redo';
67+
command = 'Redo';
7068
}
7169
} else {
7270
if (ev.which == 8 || ev.which == 46) {
73-
keyCode = 'Delete';
71+
command = 'Delete';
7472
} else if (ev.which == 27) {
75-
keyCode = 'Escape';
73+
command = 'Escape';
7674
}
7775
}
78-
if (keyCode != null) {
79-
handleKeyPressFunc (keyCode);
76+
if (command != null) {
77+
myThis.ExecuteCommand (command);
8078
ev.preventDefault();
8179
}
8280
});
@@ -94,6 +92,12 @@ Application.prototype.InitMenu = function (menuDivName)
9492
nodeTree.BuildAsMenu ();
9593
};
9694

95+
Application.prototype.ExecuteCommand = function (command)
96+
{
97+
var executeCommandFunc = this.module.cwrap ('ExecuteCommand', null, ['string']);
98+
executeCommandFunc (command);
99+
};
100+
97101
Application.prototype.ResizeCanvas = function (width, height)
98102
{
99103
var resizeWindowFunc = Module.cwrap ('ResizeWindow', null, ['number', 'number']);

0 commit comments

Comments
 (0)