Handle modifier keys differently to avoid Apple flagging us as wishing to monitor input from other applications

Fixes #291
This commit is contained in:
2023-01-12 21:43:45 -05:00
parent 35a890a577
commit 3bdcf02be0
13 changed files with 221 additions and 88 deletions

View File

@@ -258,6 +258,7 @@
<ClCompile Include="..\..\..\src\tools\menu_accel.win.cpp" />
<ClCompile Include="..\..\..\src\tools\prefs.win.cpp" />
<ClCompile Include="..\..\..\src\tools\undo.cpp" />
<ClCompile Include="..\..\..\src\tools\keymods.cpp" />
<ClCompile Include="..\..\..\src\tools\winutil.win.cpp" />
<ClCompile Include="..\..\..\src\tools\framerate_limiter.cpp" />
<ClCompile Include="..\..\..\src\universe\creature.cpp" />
@@ -350,6 +351,7 @@
<ClInclude Include="..\..\..\src\tools\prefs.hpp" />
<ClInclude Include="..\..\..\src\tools\undo.hpp" />
<ClInclude Include="..\..\..\src\tools\vector2d.hpp" />
<ClInclude Include="..\..\..\src\tools\keymods.hpp" />
<ClInclude Include="..\..\..\src\tools\winutil.hpp" />
<ClInclude Include="..\..\..\src\tools\framerate_limiter.hpp" />
<ClInclude Include="..\..\..\src\universe\creature.hpp" />

View File

@@ -608,6 +608,9 @@
<ClCompile Include="..\..\..\src\universe\creature.cpp">
<Filter>Universe</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\tools\keymods.cpp">
<Filter>Tools</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\tools\winutil.win.cpp">
<Filter>Tools</Filter>
</ClCompile>
@@ -824,6 +827,9 @@
<ClInclude Include="..\..\..\src\universe\creature.hpp">
<Filter>Universe</Filter>
</ClInclude>
<ClInclude Include="..\..\..\src\tools\keymods.hpp">
<Filter>Tools</Filter>
</ClInclude>
<ClInclude Include="..\..\..\src\tools\winutil.hpp">
<Filter>Tools</Filter>
</ClInclude>

View File

@@ -408,6 +408,7 @@
<ClCompile Include="..\..\..\src\tools\menu_accel.win.cpp" />
<ClCompile Include="..\..\..\src\tools\prefs.win.cpp" />
<ClCompile Include="..\..\..\src\tools\undo.cpp" />
<ClCompile Include="..\..\..\src\tools\keymods.cpp" />
<ClCompile Include="..\..\..\src\tools\winutil.win.cpp" />
<ClCompile Include="..\..\..\src\universe\creature.cpp" />
<ClCompile Include="..\..\..\src\universe\living.cpp" />
@@ -497,6 +498,7 @@
<ClInclude Include="..\..\..\src\tools\prefs.hpp" />
<ClInclude Include="..\..\..\src\tools\undo.hpp" />
<ClInclude Include="..\..\..\src\tools\vector2d.hpp" />
<ClInclude Include="..\..\..\src\tools\keymods.hpp" />
<ClInclude Include="..\..\..\src\tools\winutil.hpp" />
<ClInclude Include="..\..\..\src\universe\creature.hpp" />
<ClInclude Include="..\..\..\src\universe\living.hpp" />

View File

@@ -689,6 +689,9 @@
<ClCompile Include="..\..\..\src\tools\undo.cpp">
<Filter>Tools</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\tools\keymods.cpp">
<Filter>Tools</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\tools\winutil.win.cpp">
<Filter>Tools</Filter>
</ClCompile>
@@ -915,6 +918,9 @@
<ClInclude Include="..\..\..\src\tools\vector2d.hpp">
<Filter>Tools</Filter>
</ClInclude>
<ClInclude Include="..\..\..\src\tools\keymods.hpp">
<Filter>Tools</Filter>
</ClInclude>
<ClInclude Include="..\..\..\src\tools\winutil.hpp">
<Filter>Tools</Filter>
</ClInclude>

View File

@@ -80,6 +80,8 @@
912DFE8F18E2872400B00D75 /* boe.menus.mac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 912DFE8E18E2872300B00D75 /* boe.menus.mac.mm */; };
913D6C050FC57A8E00E12527 /* boeresources.icns in Resources */ = {isa = PBXBuildFile; fileRef = 913D6C040FC57A8E00E12527 /* boeresources.icns */; };
91430438296C0088003A3967 /* vector2d.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 91430437296C0088003A3967 /* vector2d.cpp */; };
9143044A2970EDC1003A3967 /* keymods.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 914304482970EDC1003A3967 /* keymods.cpp */; };
9143044B2970EDC1003A3967 /* keymods.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 914304492970EDC1003A3967 /* keymods.hpp */; };
9149924B25913E3F00B5BE97 /* container.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9149924525913E3F00B5BE97 /* container.cpp */; };
9149924C25913E3F00B5BE97 /* container.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 9149924625913E3F00B5BE97 /* container.hpp */; };
9149924D25913E3F00B5BE97 /* led.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9149924725913E3F00B5BE97 /* led.cpp */; };
@@ -651,6 +653,8 @@
913D6C040FC57A8E00E12527 /* boeresources.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; name = boeresources.icns; path = icons/mac/boeresources.icns; sourceTree = "<group>"; };
913FB40A1A5C90840067B9D2 /* pictypes.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = pictypes.hpp; sourceTree = "<group>"; };
91430437296C0088003A3967 /* vector2d.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = vector2d.cpp; sourceTree = "<group>"; };
914304482970EDC1003A3967 /* keymods.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = keymods.cpp; sourceTree = "<group>"; };
914304492970EDC1003A3967 /* keymods.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = keymods.hpp; sourceTree = "<group>"; };
914698FA1A7362C200F20F5E /* living.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = living.hpp; sourceTree = "<group>"; };
914698FB1A7362D900F20F5E /* living.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = living.cpp; sourceTree = "<group>"; };
914698FD1A747BED00F20F5E /* creature.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = creature.hpp; sourceTree = "<group>"; };
@@ -1261,6 +1265,8 @@
9179A4621A47D4E200FEF872 /* vector2d.hpp */,
919145FE18E63B41005CF3A4 /* winutil.hpp */,
91C2A6E11B823CCD00346948 /* gitrev.sh */,
914304482970EDC1003A3967 /* keymods.cpp */,
914304492970EDC1003A3967 /* keymods.hpp */,
);
name = tools;
path = ../../src/tools;
@@ -1639,6 +1645,7 @@
91F3205123E65EA3009650AF /* framerate_limiter.hpp in Headers */,
9149924C25913E3F00B5BE97 /* container.hpp in Headers */,
9149924E25913E3F00B5BE97 /* led.hpp in Headers */,
9143044B2970EDC1003A3967 /* keymods.hpp in Headers */,
9149925025913E3F00B5BE97 /* ledgroup.hpp in Headers */,
91499254259140FF00B5BE97 /* keycodes.hpp in Headers */,
);
@@ -2056,6 +2063,7 @@
91E128E71BC1E6DD00C8BE1D /* basicbtns.cpp in Sources */,
91E128ED1BC2076B00C8BE1D /* 3choice.cpp in Sources */,
91E128EE1BC2076B00C8BE1D /* choicedlog.cpp in Sources */,
9143044A2970EDC1003A3967 /* keymods.cpp in Sources */,
91E128EF1BC2076B00C8BE1D /* pictchoice.cpp in Sources */,
91E128F01BC2076B00C8BE1D /* strchoice.cpp in Sources */,
91E128F11BC2076B00C8BE1D /* strdlog.cpp in Sources */,

View File

@@ -20,6 +20,7 @@
#include "dialogxml/widgets/scrollbar.hpp"
#include "dialogxml/widgets/scrollpane.hpp"
#include "dialogxml/widgets/stack.hpp"
#include "tools/keymods.hpp"
#include "tools/winutil.hpp"
#include "mathutil.hpp"
#include "tools/cursors.hpp"
@@ -556,86 +557,79 @@ void cDialog::handle_events() {
// This method handles one event received by the dialog.
void cDialog::handle_one_event(const sf::Event& currentEvent) {
using kb = sf::Keyboard;
using Key = sf::Keyboard::Key;
cKey key;
// HACK: This needs to be stored between consecutive invocations of this function
static cKey pendingKey = {true};
std::string itemHit = "";
location where;
if(kb.handleModifier(currentEvent)) return;
switch(currentEvent.type) {
case sf::Event::KeyPressed:
switch(currentEvent.key.code){
case kb::Up:
case Key::Up:
key.spec = true;
key.k = key_up;
break;
case kb::Right:
case Key::Right:
key.spec = true;
key.k = key_right;
break;
case kb::Left:
case Key::Left:
key.spec = true;
key.k = key_left;
break;
case kb::Down:
case Key::Down:
key.spec = true;
key.k = key_down;
break;
case kb::Escape:
case Key::Escape:
key.spec = true;
key.k = key_esc;
break;
case kb::Return: // TODO: Also enter (keypad)
case Key::Return: // TODO: Also enter (keypad)
key.spec = true;
key.k = key_enter;
break;
case kb::BackSpace:
case Key::BackSpace:
key.spec = true;
key.k = key_bsp;
break;
case kb::Delete:
case Key::Delete:
key.spec = true;
key.k = key_del;
break;
case kb::Tab:
case Key::Tab:
key.spec = true;
key.k = key_tab;
break;
case kb::Insert:
case Key::Insert:
key.spec = true;
key.k = key_insert;
break;
case kb::F1:
case Key::F1:
key.spec = true;
key.k = key_help;
break;
case kb::Home:
case Key::Home:
key.spec = true;
key.k = key_home;
break;
case kb::End:
case Key::End:
key.spec = true;
key.k = key_end;
break;
case kb::PageUp:
case Key::PageUp:
key.spec = true;
key.k = key_pgup;
break;
case kb::PageDown:
case Key::PageDown:
key.spec = true;
key.k = key_pgdn;
break;
case kb::LShift:
case kb::RShift:
case kb::LAlt:
case kb::RAlt:
case kb::LControl:
case kb::RControl:
case kb::LSystem:
case kb::RSystem:
return;
default:
key.spec = false;
key.c = keyToChar(currentEvent.key.code, false);
@@ -676,14 +670,10 @@ void cDialog::handle_one_event(const sf::Event& currentEvent) {
break;
case sf::Event::MouseButtonPressed:
key.mod = mod_none;
if(kb::isKeyPressed(kb::LControl)) key.mod += mod_ctrl;
if(kb::isKeyPressed(kb::RControl)) key.mod += mod_ctrl;
if(kb::isKeyPressed(kb::LSystem)) key.mod += mod_ctrl;
if(kb::isKeyPressed(kb::RSystem)) key.mod += mod_ctrl;
if(kb::isKeyPressed(kb::LAlt)) key.mod += mod_alt;
if(kb::isKeyPressed(kb::RAlt)) key.mod += mod_alt;
if(kb::isKeyPressed(kb::LShift)) key.mod += mod_shift;
if(kb::isKeyPressed(kb::RShift)) key.mod += mod_shift;
if(kb.isCtrlPressed()) key.mod += mod_ctrl;
if(kb.isMetaPressed()) key.mod += mod_ctrl;
if(kb.isAltPressed()) key.mod += mod_alt;
if(kb.isShiftPressed()) key.mod += mod_shift;
where = {currentEvent.mouseButton.x, currentEvent.mouseButton.y};
process_click(where, key.mod);
break;

View File

@@ -14,6 +14,7 @@
#include "dialogxml/dialogs/dialog.hpp"
#include "dialogxml/dialogs/strdlog.hpp"
#include "gfx/render_shapes.hpp"
#include "tools/keymods.hpp"
#include "tools/winutil.hpp"
#include "tools/cursors.hpp"
@@ -124,7 +125,7 @@ bool cTextField::handleClick(location clickLoc) {
bool hadSelection = selectionPoint != insertionPoint;
bool is_double = click_timer.getElapsedTime().asMilliseconds() < 500;
click_timer.restart();
bool is_shift = sf::Keyboard::isKeyPressed(sf::Keyboard::LShift) || sf::Keyboard::isKeyPressed(sf::Keyboard::RShift);
bool is_shift = kb.isShiftPressed();
set_ip(clickLoc, is_shift ? &cTextField::selectionPoint : &cTextField::insertionPoint);
if(!is_shift) selectionPoint = insertionPoint;
if(is_double && !is_shift && !hadSelection) {

View File

@@ -30,6 +30,7 @@
#include "dialogxml/dialogs/dialog.hpp"
#include "dialogxml/widgets/scrollbar.hpp"
#include "boe.menus.hpp"
#include "tools/keymods.hpp"
#include "tools/winutil.hpp"
#include "tools/cursors.hpp"
#include "spell.hpp"
@@ -1188,10 +1189,7 @@ bool handle_action(const sf::Event& event) {
handle_look(destination, need_redraw, need_reprint);
// If option/ctrl not pressed, looking done, so restore center
bool look_done = true;
if(sf::Keyboard::isKeyPressed(sf::Keyboard::LAlt)) look_done = false;
if(sf::Keyboard::isKeyPressed(sf::Keyboard::RAlt)) look_done = false;
if(sf::Keyboard::isKeyPressed(sf::Keyboard::LControl)) look_done = false;
if(sf::Keyboard::isKeyPressed(sf::Keyboard::RControl)) look_done = false;
if(kb.isAltPressed() || kb.isCtrlPressed()) look_done = false;
if(look_done) {
if(right_button) overall_mode = previous_mode;
else if(overall_mode == MODE_LOOK_COMBAT) {
@@ -1572,23 +1570,22 @@ bool handle_keystroke(const sf::Event& event){
bool are_done = false;
location pass_point; // TODO: This isn't needed
std::ostringstream sout;
using kb = sf::Keyboard;
using Key = sf::Keyboard::Key;
Key keypad[10] = {
kb::Numpad0,kb::Numpad1,kb::Numpad2,kb::Numpad3,
kb::Numpad4,kb::Numpad5,kb::Numpad6,
kb::Numpad7,kb::Numpad8,kb::Numpad9
Key::Numpad0,Key::Numpad1,Key::Numpad2,Key::Numpad3,
Key::Numpad4,Key::Numpad5,Key::Numpad6,
Key::Numpad7,Key::Numpad8,Key::Numpad9
};
location terrain_click[10] = {
{150,185},{120,215},{150,215},{180,215},
{120,185},{150,185},{180,185},
{120,155},{150,155},{180,135}
};
Key talk_chars[9] = {kb::L,kb::N,kb::J,kb::B,kb::S,kb::R,kb::D,kb::G,kb::A};
Key shop_chars[8] = {kb::A,kb::B,kb::C,kb::D,kb::E,kb::F,kb::G,kb::H};
Key talk_chars[9] = {Key::L,Key::N,Key::J,Key::B,Key::S,Key::R,Key::D,Key::G,Key::A};
Key shop_chars[8] = {Key::A,Key::B,Key::C,Key::D,Key::E,Key::F,Key::G,Key::H};
if(map_visible && event.key.code == kb::Escape
if(map_visible && event.key.code == Key::Escape
&& (overall_mode != MODE_TALKING) && (overall_mode != MODE_SHOPPING)) {
mini_map.setVisible(false);
map_visible = false;
@@ -1607,36 +1604,36 @@ bool handle_keystroke(const sf::Event& event){
// print_buf();
Key chr2 = event.key.code;
if(chr2 == kb::LShift || chr2 == kb::LAlt || chr2 == kb::LControl || chr2 == kb::LSystem) return false;
if(chr2 == kb::RShift || chr2 == kb::RAlt || chr2 == kb::RControl || chr2 == kb::RSystem) return false;
if(chr2 == Key::LShift || chr2 == Key::LAlt || chr2 == Key::LControl || chr2 == Key::LSystem) return false;
if(chr2 == Key::RShift || chr2 == Key::RAlt || chr2 == Key::RControl || chr2 == Key::RSystem) return false;
if(chr2 == kb::Up && !kb::isKeyPressed(kb::Down)) {
if(kb::isKeyPressed(kb::Left)) chr2 = kb::Numpad7;
else if(kb::isKeyPressed(kb::Right)) chr2 = kb::Numpad9;
else chr2 = kb::Numpad8;
} else if(chr2 == kb::Down && !kb::isKeyPressed(kb::Up)) {
if(kb::isKeyPressed(kb::Left)) chr2 = kb::Numpad1;
else if(kb::isKeyPressed(kb::Right)) chr2 = kb::Numpad3;
else chr2 = kb::Numpad2;
} else if(chr2 == kb::Left && !kb::isKeyPressed(kb::Right)) {
if(kb::isKeyPressed(kb::Up)) chr2 = kb::Numpad7;
else if(kb::isKeyPressed(kb::Down)) chr2 = kb::Numpad1;
else chr2 = kb::Numpad4;
} else if(chr2 == kb::Right && !kb::isKeyPressed(kb::Left)) {
if(kb::isKeyPressed(kb::Up)) chr2 = kb::Numpad9;
else if(kb::isKeyPressed(kb::Down)) chr2 = kb::Numpad3;
else chr2 = kb::Numpad6;
} else if(chr2 == kb::Home) chr2 = kb::Numpad7;
else if(chr2 == kb::End) chr2 = kb::Numpad1;
else if(chr2 == kb::PageUp) chr2 = kb::Numpad9;
else if(chr2 == kb::PageDown) chr2 = kb::Numpad3;
if(chr2 == Key::Up && !kb.isDownPressed()) {
if(kb.isLeftPressed()) chr2 = Key::Numpad7;
else if(kb.isRightPressed()) chr2 = Key::Numpad9;
else chr2 = Key::Numpad8;
} else if(chr2 == Key::Down && !kb.isUpPressed()) {
if(kb.isLeftPressed()) chr2 = Key::Numpad1;
else if(kb.isRightPressed()) chr2 = Key::Numpad3;
else chr2 = Key::Numpad2;
} else if(chr2 == Key::Left && !kb.isRightPressed()) {
if(kb.isUpPressed()) chr2 = Key::Numpad7;
else if(kb.isDownPressed()) chr2 = Key::Numpad1;
else chr2 = Key::Numpad4;
} else if(chr2 == Key::Right && !kb.isLeftPressed()) {
if(kb.isUpPressed()) chr2 = Key::Numpad9;
else if(kb.isDownPressed()) chr2 = Key::Numpad3;
else chr2 = Key::Numpad6;
} else if(chr2 == Key::Home) chr2 = Key::Numpad7;
else if(chr2 == Key::End) chr2 = Key::Numpad1;
else if(chr2 == Key::PageUp) chr2 = Key::Numpad9;
else if(chr2 == Key::PageDown) chr2 = Key::Numpad3;
sf::Event pass_event = {sf::Event::MouseButtonPressed};
if(overall_mode == MODE_TALKING) {
if(chr2 == kb::Escape)
chr2 = kb::D;
if(chr2 == kb::Space)
chr2 = kb::G;
if(chr2 == Key::Escape)
chr2 = Key::D;
if(chr2 == Key::Space)
chr2 = Key::G;
for(short i = 0; i < 9; i++)
if(chr2 == talk_chars[i] && (!talk_end_forced || i == 6 || i == 5)) {
int j = talk_end_forced ? i - 5 : i;
@@ -1649,7 +1646,7 @@ bool handle_keystroke(const sf::Event& event){
}
}
else if(overall_mode == MODE_SHOPPING) { // shopping keystrokes
if(chr2 == kb::Escape) {
if(chr2 == Key::Escape) {
play_sound(37);
end_shop_mode();
}
@@ -1666,7 +1663,7 @@ bool handle_keystroke(const sf::Event& event){
for(short i = 0; i < 10; i++)
if(chr2 == keypad[i]) {
if(i == 0) {
chr2 = kb::Z;
chr2 = Key::Z;
}
else {
pass_point = mainPtr.mapCoordsToPixel(terrain_click[i], mainView);
@@ -1683,7 +1680,7 @@ bool handle_keystroke(const sf::Event& event){
char chr = keyToChar(chr2, event.key.shift);
// F1 should bring up help.
// TODO: So should the help key, if it exists (but SFML doesn't support the help key)
if(chr2 == kb::F1) chr = '?';
if(chr2 == Key::F1) chr = '?';
switch(chr) {
@@ -2134,7 +2131,7 @@ bool handle_scroll(const sf::Event& event) {
int amount = event.mouseWheel.delta;
if(scrollableModes.count(overall_mode) && pos.in(world_screen)) {
if(sf::Keyboard::isKeyPressed(sf::Keyboard::LControl) || sf::Keyboard::isKeyPressed(sf::Keyboard::RControl))
if(kb.isCtrlPressed())
center.x = minmax(4, univ.town->max_dim - 5, center.x - amount);
else center.y = minmax(4, univ.town->max_dim - 5, center.y - amount);
}
@@ -2603,7 +2600,6 @@ void handle_death() {
void start_new_game(bool force) {
std::string choice;
using kb = sf::Keyboard;
if(!force)
choice = cChoiceDlog("new-party",{"okay","cancel"}).show();
@@ -2617,12 +2613,7 @@ void start_new_game(bool force) {
// display_intro();
// If system key held down, create debug party
#ifdef __APPLE__
if(kb::isKeyPressed(kb::LSystem) || kb::isKeyPressed(kb::RSystem))
#else
if(kb::isKeyPressed(kb::LControl) || kb::isKeyPressed(kb::RControl))
#endif
party_type = PARTY_DEBUG;
if(kb.isSystemPressed()) party_type = PARTY_DEBUG;
// And now, reconstruct the universe.
new(&univ) cUniverse(party_type);

View File

@@ -15,6 +15,7 @@
#include "sounds.hpp"
#include "fileio/fileio.hpp"
#include "dialogxml/dialogs/choicedlog.hpp"
#include "tools/keymods.hpp"
#include "tools/winutil.hpp"
#include "boe.menus.hpp"
#include "mathutil.hpp"
@@ -38,7 +39,6 @@ enum_map(eStartButton, rectangle) startup_button;
// TODO: Always returns false, so make it void
bool handle_startup_press(location the_point) {
using kb = sf::Keyboard;
std::string scen_name;
bool force_party = false;
@@ -75,7 +75,7 @@ bool handle_startup_press(location the_point) {
case STARTBTN_JOIN:
if(!party_in_memory) {
if(kb::isKeyPressed(kb::LAlt) || kb::isKeyPressed(kb::RAlt)) {
if(kb.isAltPressed()) {
force_party = true;
start_new_game(true);
} else {

View File

@@ -18,6 +18,7 @@
#include "scen.menus.hpp"
#include "mathutil.hpp"
#include "fileio/fileio.hpp"
#include "tools/keymods.hpp"
#include "tools/winutil.hpp"
#include "tools/cursors.hpp"
#include "dialogxml/widgets/scrollbar.hpp"
@@ -1532,16 +1533,15 @@ static bool handle_toolpal_action(location cur_point2) {
}
void handle_action(location the_point,sf::Event /*event*/) {
using kb = sf::Keyboard;
std::string s2;
bool option_hit = false,ctrl_hit = false;
location spot_hit;
location cur_point,cur_point2;
rectangle temp_rect;
if(kb::isKeyPressed(kb::LAlt) || kb::isKeyPressed(kb::RAlt))
if(kb.isAltPressed())
option_hit = true;
if(kb::isKeyPressed(kb::LControl) || kb::isKeyPressed(kb::RControl))
if(kb.isCtrlPressed())
ctrl_hit = true;
if(handle_lb_action(the_point))
@@ -1782,7 +1782,7 @@ void handle_scroll(const sf::Event& event) {
location pos { translate_mouse_coordinates({event.mouseMove.x,event.mouseMove.y}) };
int amount = event.mouseWheel.delta;
if(overall_mode < MODE_MAIN_SCREEN && pos.in(terrain_rect)) {
if(sf::Keyboard::isKeyPressed(sf::Keyboard::LControl) || sf::Keyboard::isKeyPressed(sf::Keyboard::RControl))
if(kb.isCtrlPressed())
cen_x = minmax(4, town->max_dim - 5, cen_x - amount);
else cen_y = minmax(4, town->max_dim - 5, cen_y - amount);
}

View File

@@ -5,6 +5,7 @@ tools = Split("""
undo.cpp
framerate_limiter.cpp
drawable_manager.cpp
keymods.cpp
../location.cpp
../mathutil.cpp
../porting.cpp

93
src/tools/keymods.cpp Normal file
View File

@@ -0,0 +1,93 @@
//
// keymods.cpp
// Common
//
// Created by Celtic Minstrel on 2023-01-12.
//
#include "keymods.hpp"
#include <SFML/Window/Keyboard.hpp>
keymods_t kb;
bool keymods_t::isAltPressed() const {
return alt;
}
bool keymods_t::isCtrlPressed() const {
return ctrl;
}
bool keymods_t::isShiftPressed() const {
return shift;
}
bool keymods_t::isMetaPressed() const {
return meta;
}
bool keymods_t::isSystemPressed() const {
#ifdef __APPLE__
return meta;
#else
return ctrl;
#endif
}
bool keymods_t::isUpPressed() const {
return up;
}
bool keymods_t::isDownPressed() const {
return down;
}
bool keymods_t::isLeftPressed() const {
return left;
}
bool keymods_t::isRightPressed() const {
return right;
}
bool keymods_t::handleModifier(const sf::Event& evt) {
if(evt.type != sf::Event::KeyPressed && evt.type != sf::Event::KeyReleased) {
return false;
}
using Key = sf::Keyboard::Key;
bool newState = evt.type == sf::Event::KeyPressed;
switch(evt.key.code) {
case Key::LShift:
case Key::RShift:
shift = newState;
break;
case Key::LAlt:
case Key::RAlt:
alt = newState;
break;
case Key::LControl:
case Key::RControl:
ctrl = newState;
break;
case Key::LSystem:
case Key::RSystem:
meta = newState;
break;
case Key::Left:
left = newState;
break;
case Key::Right:
right = newState;
break;
case Key::Up:
up = newState;
break;
case Key::Down:
down = newState;
break;
default: return false;
}
return true;
}

33
src/tools/keymods.hpp Normal file
View File

@@ -0,0 +1,33 @@
//
// keymods.hpp
// Common
//
// Created by Celtic Minstrel on 2023-01-12.
//
#ifndef BOE_keymods_hpp
#define BOE_keymods_hpp
#include <SFML/Window/Event.hpp>
class keymods_t {
bool alt = false, ctrl = false, shift = false, meta = false;
bool up = false, down = false, left = false, right = false;
public:
bool isAltPressed() const;
bool isCtrlPressed() const;
bool isShiftPressed() const;
// Windows key, Command key, Meta key, etc
bool isMetaPressed() const;
// System is a special pseudo-key - it's Command on Mac and Control on other systems
bool isSystemPressed() const;
bool isUpPressed() const;
bool isDownPressed() const;
bool isLeftPressed() const;
bool isRightPressed() const;
bool handleModifier(const sf::Event& evt);
};
extern keymods_t kb;
#endif /* keymods_hpp */