Skip to content

Commit

Permalink
mac key name cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
efroemling committed Nov 2, 2023
1 parent 4047a5c commit 544e26f
Show file tree
Hide file tree
Showing 17 changed files with 108 additions and 55 deletions.
56 changes: 28 additions & 28 deletions .efrocachemap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
### 1.7.28 (build 21554, api 8, 2023-11-01)
### 1.7.28 (build 21556, api 8, 2023-11-01)

- Massively cleaned up code related to rendering and window systems (OpenGL,
SDL, etc). This code had been growing into a nasty tangle for 15 years
Expand Down
2 changes: 1 addition & 1 deletion src/assets/ba_data/python/baenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@

# Build number and version of the ballistica binary we expect to be
# using.
TARGET_BALLISTICA_BUILD = 21554
TARGET_BALLISTICA_BUILD = 21556
TARGET_BALLISTICA_VERSION = '1.7.28'


Expand Down
8 changes: 7 additions & 1 deletion src/assets/ba_data/python/bauiv1lib/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ def __init__(
displayname: str | bui.Lstr | None = None,
changesound: bool = True,
textscale: float = 1.0,
as_percent: bool = False,
):
if displayname is None:
displayname = configkey
Expand All @@ -103,6 +104,7 @@ def __init__(
self._increment = increment
self._callback = callback
self._value = bui.app.config.resolve(configkey)
self._as_percent = as_percent

self.nametext = bui.textwidget(
parent=parent,
Expand Down Expand Up @@ -166,4 +168,8 @@ def _changed(self) -> None:
bui.app.config.apply_and_commit()

def _update_display(self) -> None:
bui.textwidget(edit=self.valuetext, text=f'{self._value:.1f}')
if self._as_percent:
val = f'{round(self._value*100.0)}%'
else:
val = f'{self._value:.1f}'
bui.textwidget(edit=self.valuetext, text=val)
6 changes: 4 additions & 2 deletions src/assets/ba_data/python/bauiv1lib/settings/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ def __init__(
displayname=bui.Lstr(resource=self._r + '.soundVolumeText'),
minval=0.0,
maxval=1.0,
increment=0.1,
increment=0.05,
as_percent=True,
)
if bui.app.ui_v1.use_toolbars:
bui.widget(
Expand All @@ -137,9 +138,10 @@ def __init__(
displayname=bui.Lstr(resource=self._r + '.musicVolumeText'),
minval=0.0,
maxval=1.0,
increment=0.1,
increment=0.05,
callback=music.music_volume_changed,
changesound=False,
as_percent=True,
)

v -= 0.5 * spacing
Expand Down
6 changes: 6 additions & 0 deletions src/ballistica/base/app_adapter/app_adapter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -302,4 +302,10 @@ auto AppAdapter::DoClipboardGetText() -> std::string {
return "";
}

auto AppAdapter::GetKeyName(int keycode) -> std::string {
BA_LOG_ONCE(LogLevel::kWarning,
"CorePlatform::GetKeyName not implemented here.");
return "?";
}

} // namespace ballistica::base
3 changes: 3 additions & 0 deletions src/ballistica/base/app_adapter/app_adapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,9 @@ class AppAdapter {
/// context. By default this is simply the main thread.
virtual void DoPushGraphicsContextRunnable(Runnable* runnable);

// Return a name for a ballistica keyboard keycode.
virtual auto GetKeyName(int keycode) -> std::string;

protected:
virtual ~AppAdapter();

Expand Down
5 changes: 5 additions & 0 deletions src/ballistica/base/app_adapter/app_adapter_apple.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "ballistica/base/logic/logic.h"
#include "ballistica/base/platform/apple/apple_utils.h"
#include "ballistica/base/platform/apple/from_swift.h"
#include "ballistica/base/platform/support/min_sdl_key_names.h"
#include "ballistica/base/support/app_config.h"
#include "ballistica/shared/ballistica.h"
#include "ballistica/shared/foundation/event_loop.h"
Expand Down Expand Up @@ -282,6 +283,10 @@ auto AppAdapterApple::DoClipboardGetText() -> std::string {
#endif
}

auto AppAdapterApple::GetKeyName(int keycode) -> std::string {
return MinSDL_GetKeyName(keycode);
}

} // namespace ballistica::base

#endif // BA_XCODE_BUILD
1 change: 1 addition & 0 deletions src/ballistica/base/app_adapter/app_adapter_apple.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class AppAdapterApple : public AppAdapter {

auto GetKeyRepeatDelay() -> float override;
auto GetKeyRepeatInterval() -> float override;
auto GetKeyName(int keycode) -> std::string override;

protected:
void DoPushMainThreadRunnable(Runnable* runnable) override;
Expand Down
4 changes: 4 additions & 0 deletions src/ballistica/base/app_adapter/app_adapter_sdl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,10 @@ auto AppAdapterSDL::DoClipboardGetText() -> std::string {
return out_s;
}

auto AppAdapterSDL::GetKeyName(int keycode) -> std::string {
return SDL_GetKeyName(static_cast<SDL_Keycode>(keycode));
}

} // namespace ballistica::base

#endif // BA_SDL_BUILD
2 changes: 2 additions & 0 deletions src/ballistica/base/app_adapter/app_adapter_sdl.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ class AppAdapterSDL : public AppAdapter {

auto GetGraphicsSettings() -> GraphicsSettings* override;

auto GetKeyName(int keycode) -> std::string override;

protected:
void DoPushMainThreadRunnable(Runnable* runnable) override;
void RunMainThreadEventLoopToCompletion() override;
Expand Down
2 changes: 1 addition & 1 deletion src/ballistica/base/input/device/keyboard_input.cc
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ void KeyboardInput::UpdateArrowKeys_(SDL_Keycode key) {
}

auto KeyboardInput::GetButtonName(int index) -> std::string {
return g_base->platform->GetKeyName(index);
return g_base->app_adapter->GetKeyName(index);
}

auto KeyboardInput::GetRawDeviceName() -> std::string { return "Keyboard"; }
Expand Down
15 changes: 0 additions & 15 deletions src/ballistica/base/platform/base_platform.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include "ballistica/base/base.h"
#include "ballistica/base/input/input.h"
#include "ballistica/base/logic/logic.h"
#include "ballistica/base/platform/support/min_sdl_key_names.h"
#include "ballistica/base/python/base_python.h"
#include "ballistica/base/ui/ui.h"
#include "ballistica/core/core.h"
Expand All @@ -27,20 +26,6 @@ void BasePlatform::PostInit() {

BasePlatform::~BasePlatform() = default;

auto BasePlatform::GetKeyName(int keycode) -> std::string {
// On our actual SDL platforms we're trying to be *pure* sdl so
// call their function for this. Otherwise we call our own version
// of it which is basically the same thing (at least for now).
#if BA_MINSDL_BUILD
return MinSDL_GetKeyName(keycode);
#elif BA_SDL_BUILD
return SDL_GetKeyName(static_cast<SDL_Keycode>(keycode));
#else
Log(LogLevel::kWarn, "CorePlatform::GetKeyName not implemented here.");
return "?";
#endif
}

void BasePlatform::LoginAdapterGetSignInToken(const std::string& login_type,
int attempt_id) {
// Default implementation simply calls completion callback immediately.
Expand Down
5 changes: 0 additions & 5 deletions src/ballistica/base/platform/base_platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,6 @@ class BasePlatform {
/// Called when the app should set itself up to intercept ctrl-c presses.
virtual void SetupInterruptHandling();

#pragma mark INPUT DEVICES -----------------------------------------------------

// Return a name for a ballistica keycode.
virtual auto GetKeyName(int keycode) -> std::string;

#pragma mark ACCOUNTS ----------------------------------------------------------

/// Called when a Python LoginAdapter is requesting an explicit sign-in.
Expand Down
16 changes: 16 additions & 0 deletions src/ballistica/base/platform/support/min_sdl_key_names.h
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,22 @@ auto MinSDL_GetKeyName(int keycode) -> std::string {
static char name[8];
char* end;

// Handle a few specially per platform.
if (g_buildconfig.ostype_macos()) {
switch (key) {
case SDLK_LGUI:
return "Left Command";
case SDLK_RGUI:
return "Right Command";
case SDLK_LALT:
return "Left Option";
case SDLK_RALT:
return "Right Option";
default:
break;
}
}

if (key & SDLK_SCANCODE_MASK) {
return GetScancodeName((SDL_Scancode)(key & ~SDLK_SCANCODE_MASK));
}
Expand Down
2 changes: 1 addition & 1 deletion src/ballistica/shared/ballistica.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ auto main(int argc, char** argv) -> int {
namespace ballistica {

// These are set automatically via script; don't modify them here.
const int kEngineBuildNumber = 21554;
const int kEngineBuildNumber = 21556;
const char* kEngineVersion = "1.7.28";
const int kEngineApiVersion = 8;

Expand Down
28 changes: 28 additions & 0 deletions tools/efrotools/xcodebuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class SigningConfig:

class _Section(Enum):
COMPILEC = 'CompileC'
COMPILEXCSTRINGS = 'CompileXCStrings'
SWIFTCOMPILE = 'SwiftCompile'
SWIFTGENERATEPCH = 'SwiftGeneratePch'
SWIFTDRIVER = 'SwiftDriver'
Expand Down Expand Up @@ -91,6 +92,7 @@ class _Section(Enum):
EXTRACTAPPINTENTSMETADATA = 'ExtractAppIntentsMetadata'
SWIFTMERGEGENERATEDHEADERS = 'SwiftMergeGeneratedHeaders'
GENERATEDSYMFILE = 'GenerateDSYMFile'
GENERATEASSETSYMBOLS = 'GenerateAssetSymbols'


class XCodeBuild:
Expand Down Expand Up @@ -575,6 +577,12 @@ def _print_filtered_line(self, line: str) -> None:
line,
ignore_line_starts=['builtin-validationUtility'],
)
elif self._section is _Section.COMPILEXCSTRINGS:
self._print_simple_section_line(
line,
prefix='Compiling strings',
ignore_line_start_tails=['/xcstringstool'],
)
elif self._section is _Section.CONVERTICONSETFILE:
self._print_simple_section_line(
line,
Expand Down Expand Up @@ -653,6 +661,9 @@ def _print_filtered_line(self, line: str) -> None:
'/copypng',
'/iconutil',
],
ignore_containing=[
'note: detected encoding of input file as Unicode (UTF-8)'
],
)
elif self._section is _Section.PROCESSPRODUCTPACKAGING:
if '.net.froemling.ballistica.ios"' in line:
Expand Down Expand Up @@ -689,6 +700,17 @@ def _print_filtered_line(self, line: str) -> None:
'"com.apple.Music.library.read",',
],
)
elif self._section is _Section.GENERATEASSETSYMBOLS:
self._print_simple_section_line(
line,
ignore_containing=[
'/* com.apple.actool.compilation-results */',
'/GeneratedAssetSymbols-Index.plist',
'/GeneratedAssetSymbols.h',
'/GeneratedAssetSymbols.swift',
],
)

elif self._section is _Section.PROCESSPRODUCTPACKAGINGDER:
self._print_simple_section_line(
line,
Expand Down Expand Up @@ -944,12 +966,16 @@ def _print_simple_section_line(
prefix_index: int | None = None,
ignore_line_starts: list[str] | None = None,
ignore_line_start_tails: list[str] | None = None,
ignore_containing: list[str] | None = None,
prefix_unexpected: bool = True,
) -> None:
# pylint: disable=too-many-branches
if ignore_line_starts is None:
ignore_line_starts = []
if ignore_line_start_tails is None:
ignore_line_start_tails = []
if ignore_containing is None:
ignore_containing = []

# First line of the section.
if self._section_line_count == 0:
Expand All @@ -975,6 +1001,8 @@ def _print_simple_section_line(
return
if any(splits[0].endswith(tail) for tail in ignore_line_start_tails):
return
if any(c in line for c in ignore_containing):
return

# Fall back on printing anything we don't recognize.
if prefix is None and prefix_unexpected:
Expand Down

0 comments on commit 544e26f

Please sign in to comment.