55#include < object/object.h>
66#include < render/3d.h>
77#include < ship/ship.h>
8- #include < io/key.h >
8+ #include " ui/ControlBindings.h "
99#include < io/spacemouse.h>
1010
1111#include " object.h"
@@ -23,62 +23,43 @@ const fix MIN_FRAMETIME = (F1_0 / 120);
2323
2424const float REDUCER = 100 .0f ;
2525
26- void process_movement_keys (int key, vec3d* mvec, angles* angs) {
27- int raw_key;
28-
26+ void process_movement_keys (const fso::fred::ControlBindings& bindings, vec3d* mvec, angles* angs) {
2927 mvec->xyz .x = 0 .0f ;
3028 mvec->xyz .y = 0 .0f ;
3129 mvec->xyz .z = 0 .0f ;
3230 angs->p = 0 .0f ;
3331 angs->b = 0 .0f ;
3432 angs->h = 0 .0f ;
3533
36- raw_key = key & 0xff ;
37-
38- switch (raw_key) {
39- case KEY_PAD1 :
34+ if (bindings.isPressed (fso::fred::ControlAction::MoveLeft)) {
4035 mvec->xyz .x += -1 .0f ;
41- break ;
42- case KEY_PAD3 :
43- mvec->xyz .x += +1 .0f ;
44- break ;
45- case KEY_PADPLUS :
36+ }
37+ if (bindings.isPressed (fso::fred::ControlAction::MoveRight)) {
38+ mvec->xyz .x += 1 .0f ;
39+ }
40+ if (bindings.isPressed (fso::fred::ControlAction::MoveForward)) {
41+ mvec->xyz .y += 1 .0f ;
42+ }
43+ if (bindings.isPressed (fso::fred::ControlAction::MoveBackward)) {
4644 mvec->xyz .y += -1 .0f ;
47- break ;
48- case KEY_PADMINUS :
49- mvec->xyz .y += +1 .0f ;
50- break ;
51- case KEY_A :
52- mvec->xyz .z += +1 .0f ;
53- break ;
54- case KEY_Z :
45+ }
46+ if (bindings.isPressed (fso::fred::ControlAction::MoveUp)) {
47+ mvec->xyz .z += 1 .0f ;
48+ }
49+ if (bindings.isPressed (fso::fred::ControlAction::MoveDown)) {
5550 mvec->xyz .z += -1 .0f ;
56- break ;
57- case KEY_PAD4 :
51+ }
52+ if (bindings. isPressed (fso::fred::ControlAction::YawLeft)) {
5853 angs->h += -0 .1f ;
59- break ;
60- case KEY_PAD6 :
61- angs->h += + 0 .1f ;
62- break ;
63- case KEY_PAD8 :
54+ }
55+ if (bindings. isPressed (fso::fred::ControlAction::YawRight)) {
56+ angs->h += 0 .1f ;
57+ }
58+ if (bindings. isPressed (fso::fred::ControlAction::PitchUp)) {
6459 angs->p += -0 .1f ;
65- break ;
66- case KEY_PAD2 :
67- angs->p += +0 .1f ;
68- break ;
69- case KEY_PAD7 :
70- angs->b += -0 .1f ;
71- break ;
72- case KEY_PAD9 :
73- angs->b += +0 .1f ;
74- break ;
7560 }
76-
77- if (key & KEY_SHIFTED ) {
78- vm_vec_scale (mvec, 5 .0f );
79- angs->p *= 5 .0f ;
80- angs->b *= 5 .0f ;
81- angs->h *= 5 .0f ;
61+ if (bindings.isPressed (fso::fred::ControlAction::PitchDown)) {
62+ angs->p += 0 .1f ;
8263 }
8364}
8465void align_vector_to_axis (vec3d* v) {
@@ -293,37 +274,19 @@ void EditorViewport::move_mouse(int btn, int mdx, int mdy) {
293274}
294275
295276// /////////////////////////////////////////////////
296- void EditorViewport::process_system_keys (int key) {
297- // mprintf(("Key = %d\n", key));
298- switch (key) {
299- case KEY_LAPOSTRO :
300- // /! \todo cycle through axis-constraints for rotations.
301- // CFREDView::GetView()->cycle_constraint();
302- break ;
303-
304- case KEY_R : // for some stupid reason, an accelerator for 'R' doesn't work.
305- // /! \todo Change editing mode to 'move and rotate'.
306- // Editing_mode = 2;
307- break ;
308-
309- case KEY_SPACEBAR :
277+ void EditorViewport::process_system_keys () {
278+ auto & bindings = ControlBindings::instance ();
279+ if (bindings.takeTriggered (ControlAction::ToggleSelectionLock)) {
310280 Selection_lock = !Selection_lock;
311- break ;
312-
313- case KEY_ESC :
314- // /! \todo Cancel drag.
315- // if (button_down)
316- // cancel_drag();
317-
318- break ;
319281 }
282+
320283}
321284
322- void EditorViewport::process_controls (vec3d* pos, matrix* orient, float frametime, int key, int mode) {
285+ void EditorViewport::process_controls (vec3d* pos, matrix* orient, float frametime, int mode) {
323286 static std::unique_ptr<io::spacemouse::SpaceMouse> spacemouse = io::spacemouse::SpaceMouse::searchSpaceMice (0 );
324287
325288 if (Flying_controls_mode) {
326- grid_read_camera_controls (&view_controls, frametime );
289+ memset (&view_controls, 0 , sizeof (control_info) );
327290
328291 if (spacemouse != nullptr ) {
329292 auto spacemouse_movement = spacemouse->getMovement ();
@@ -336,9 +299,17 @@ void EditorViewport::process_controls(vec3d* pos, matrix* orient, float frametim
336299 view_controls.forward += spacemouse_movement.translation .xyz .y ;
337300 }
338301
339- if (key_get_shift_status ()) {
340- memset (&view_controls, 0 , sizeof (control_info));
341- }
302+ auto & bindings = ControlBindings::instance ();
303+ view_controls.pitch += bindings.isPressed (ControlAction::PitchUp) ? -1 .0f : 0 .0f ;
304+ view_controls.pitch += bindings.isPressed (ControlAction::PitchDown) ? 1 .0f : 0 .0f ;
305+ view_controls.heading += bindings.isPressed (ControlAction::YawLeft) ? -1 .0f : 0 .0f ;
306+ view_controls.heading += bindings.isPressed (ControlAction::YawRight) ? 1 .0f : 0 .0f ;
307+ view_controls.sideways += bindings.isPressed (ControlAction::MoveLeft) ? -1 .0f : 0 .0f ;
308+ view_controls.sideways += bindings.isPressed (ControlAction::MoveRight) ? 1 .0f : 0 .0f ;
309+ view_controls.forward += bindings.isPressed (ControlAction::MoveForward) ? 1 .0f : 0 .0f ;
310+ view_controls.forward += bindings.isPressed (ControlAction::MoveBackward) ? -1 .0f : 0 .0f ;
311+ view_controls.vertical += bindings.isPressed (ControlAction::MoveUp) ? 1 .0f : 0 .0f ;
312+ view_controls.vertical += bindings.isPressed (ControlAction::MoveDown) ? -1 .0f : 0 .0f ;
342313
343314 if ((fabs (view_controls.pitch ) > (frametime / 100 )) || (fabs (view_controls.vertical ) > (frametime / 100 ))
344315 || (fabs (view_controls.heading ) > (frametime / 100 )) || (fabs (view_controls.sideways ) > (frametime / 100 ))
@@ -358,7 +329,7 @@ void EditorViewport::process_controls(vec3d* pos, matrix* orient, float frametim
358329 angles rotangs;
359330 matrix newmat, rotmat;
360331
361- process_movement_keys (key , &movement_vec, &rotangs);
332+ process_movement_keys (ControlBindings::instance () , &movement_vec, &rotangs);
362333 if (spacemouse != nullptr ) {
363334 auto spacemouse_movement = spacemouse->getMovement ();
364335 spacemouse_movement.handleNonlinearities (Fred_spacemouse_nonlinearity);
@@ -412,7 +383,7 @@ bool EditorViewport::inc_mission_time() {
412383}
413384
414385void EditorViewport::game_do_frame (const int cur_object_index) {
415- int key, cmode;
386+ int cmode;
416387 vec3d viewer_position, control_pos;
417388 object* objp;
418389 matrix control_orient;
@@ -432,8 +403,7 @@ void EditorViewport::game_do_frame(const int cur_object_index) {
432403 viewpoint = 0 ;
433404 }
434405
435- key = key_inkey ();
436- process_system_keys (key);
406+ process_system_keys ();
437407 cmode = Control_mode;
438408 if ((viewpoint == 1 ) && !cmode) {
439409 cmode = 2 ;
@@ -445,14 +415,14 @@ void EditorViewport::game_do_frame(const int cur_object_index) {
445415 // if ((key & KEY_MASK) == key) // unmodified
446416 switch (cmode) {
447417 case 0 : // Control the viewer's location and orientation
448- process_controls (&view_pos, &view_orient, f2fl (Frametime), key, 1 );
418+ process_controls (&view_pos, &view_orient, f2fl (Frametime), 1 );
449419 control_pos = view_pos;
450420 control_orient = view_orient;
451421 break ;
452422
453423 case 2 : // Control viewpoint object
454424 if (!Objects[view_obj].flags [Object::Object_Flags::Locked_from_editing]) {
455- process_controls (&Objects[view_obj].pos , &Objects[view_obj].orient , f2fl (Frametime), key );
425+ process_controls (&Objects[view_obj].pos , &Objects[view_obj].orient , f2fl (Frametime));
456426 object_moved (&Objects[view_obj]);
457427 control_pos = Objects[view_obj].pos ;
458428 control_orient = Objects[view_obj].orient ;
@@ -470,7 +440,7 @@ void EditorViewport::game_do_frame(const int cur_object_index) {
470440 leader_orient = leader->orient ; // save original orientation
471441 vm_copy_transpose (&leader_transpose, &leader_orient);
472442
473- process_controls (&leader->pos , &leader->orient , f2fl (Frametime), key );
443+ process_controls (&leader->pos , &leader->orient , f2fl (Frametime));
474444 vm_vec_sub (&delta_pos, &leader->pos , &leader_old_pos); // get position change
475445 control_pos = leader->pos ;
476446 control_orient = leader->orient ;
@@ -1300,6 +1270,31 @@ int EditorViewport::drag_rotate_objects(int mouse_dx, int mouse_dy) {
13001270 editor->missionChanged ();
13011271 return rval;
13021272}
1273+ void EditorViewport::cancel_drag () {
1274+ if (!button_down) {
1275+ return ;
1276+ }
1277+
1278+ auto objp = GET_FIRST (&obj_used_list);
1279+ while (objp != END_OF_LIST (&obj_used_list)) {
1280+ Assert (objp->type != OBJ_NONE );
1281+ if (objp->flags [Object::Object_Flags::Marked]) {
1282+ const auto obj_index = OBJ_INDEX (objp);
1283+ if (!IS_VEC_NULL (&rotation_backup[obj_index].orient .vec .rvec ) && !IS_VEC_NULL (&rotation_backup[obj_index].orient .vec .uvec )
1284+ && !IS_VEC_NULL (&rotation_backup[obj_index].orient .vec .fvec )) {
1285+ objp->pos = rotation_backup[obj_index].pos ;
1286+ objp->orient = rotation_backup[obj_index].orient ;
1287+ }
1288+ }
1289+
1290+ objp = GET_NEXT (objp);
1291+ }
1292+
1293+ button_down = false ;
1294+ moved = false ;
1295+ Dup_drag = 0 ;
1296+ needsUpdate ();
1297+ }
13031298void EditorViewport::view_universe (bool just_marked) {
13041299 int max = 0 ;
13051300 float dist, largest = 20 .0f ;
0 commit comments