Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small GUI change #660

Open
wants to merge 27 commits into
base: android
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
<application android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:allowBackup="true"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:theme="@style/AppTheme"
android:hardwareAccelerated="true"
android:appCategory="game"
android:isGame="true"
Expand All @@ -94,13 +94,16 @@
<!-- Example of setting SDL hints from AndroidManifest.xml:
<meta-data android:name="SDL_ENV.SDL_ACCELEROMETER_AS_JOYSTICK" android:value="0"/>
-->


<meta-data android:name="android.game_mode_config"
android:resource="@xml/game_mode_config" />

<activity android:name="Emulator"
android:alwaysRetainTaskState="true"
android:launchMode="singleInstance"
android:configChanges="layoutDirection|locale|orientation|uiMode|screenLayout|screenSize|smallestScreenSize|keyboard|keyboardHidden|navigation"
android:preferMinimalPostProcessing="true"
android:theme="@style/Theme.Design.NoActionBar"
android:theme="@style/AppTheme"
android:exported="true"
tools:targetApi="r">

Expand Down
6 changes: 3 additions & 3 deletions android/src/main/java/org/vita3k/emulator/Emulator.java
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,8 @@ public void setControllerOverlayState(int overlay_mask, boolean edit, boolean re
}

@Keep
public void setControllerOverlayScale(float scale){
getmOverlay().setScale(scale);
public void setControllerOverlayScale(float scale, float scale_joystick){
getmOverlay().setScale(scale, scale_joystick);
}

@Keep
Expand Down Expand Up @@ -311,4 +311,4 @@ public boolean isDefaultOrientationLandscape() {
}

public native void filedialogReturn(String result_path, int result_fd);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
private InputOverlayDrawableDpad mDpadBeingConfigured;
private InputOverlayDrawableJoystick mJoystickBeingConfigured;
private static float mGlobalScale = 1.0f;
private static float mJoyScale = 1.0f;
private static int mGlobalOpacity = 100;

private Timer mTimer;
Expand Down Expand Up @@ -604,9 +605,10 @@ public void resetButtonPlacement()
refreshControls();
}

public void setScale(float scale){
if(scale != mGlobalScale){
public void setScale(float scale, float scale_joystick){
if(scale != mGlobalScale || scale_joystick != mJoyScale){
mGlobalScale = scale;
mJoyScale = scale_joystick;
refreshControls();
}
}
Expand Down Expand Up @@ -819,7 +821,7 @@ private static InputOverlayDrawableJoystick initializeOverlayJoystick(Context co

// Decide scale based on user preference
float scale = 0.275f;
scale *= mGlobalScale;
scale *= mJoyScale;

// Initialize the InputOverlayDrawableJoystick.
final Bitmap bitmapOuter =
Expand Down Expand Up @@ -1009,4 +1011,4 @@ public static class ControlId {
public static final int axis_right_x = 2;
public static final int axis_right_y = 3;
}
}
}
10 changes: 8 additions & 2 deletions android/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
<resources>

<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
</style>
<style name="AppTheme" parent="android:Theme.NoTitleBar.Fullscreen">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowLayoutInDisplayCutoutMode">
shortEdges <!-- default, shortEdges, or never -->
</item>
</style>

</resources>
6 changes: 6 additions & 0 deletions android/src/main/res/xml/game_mode_config.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<game-mode-config
xmlns:android="http://schemas.android.com/apk/res/android"
android:supportsBatteryGameMode="true"
android:supportsPerformanceGameMode="true"
/>
12 changes: 10 additions & 2 deletions vita3k/app/src/app_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,16 @@ static bool load_custom_driver(const std::string &driver_name) {
load_library_parameter.handle = vulkan_handle;

if (SDL_Vulkan_LoadLibrary(reinterpret_cast<const char *>(&load_library_parameter)) < 0) {
LOG_ERROR("Could not load custom diver, error {}", SDL_GetError());
return false;
LOG_ERROR("Could not load custom driver, error {}", SDL_GetError());
app::error_dialog("Could not load custom driver.\napp will use system driver instead");
vulkan_handle = dlopen("libvulkan.so", RTLD_NOW | RTLD_LOCAL);
if (vulkan_handle == nullptr)
{
char *error = dlerror();
LOG_WARN( "Failed to load system Vulkan driver: %s", error ? error : "");
app::error_dialog("Could not load system vulkan driver\napp will exit.");
return false;
}
}

return true;
Expand Down
2 changes: 2 additions & 0 deletions vita3k/config/include/config/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ enum PerfomanceOverleyPosition {
code(bool, "log-uniforms", false, log_uniforms) \
code(bool, "log-compat-warn", false, log_compat_warn) \
code(bool, "validation-layer", true, validation_layer) \
code(bool, "debug-menu", false, debug_menu) \
code(bool, "pstv-mode", false, pstv_mode) \
code(bool, "show-mode", false, show_mode) \
code(bool, "demo-mode", false, demo_mode) \
Expand Down Expand Up @@ -110,6 +111,7 @@ enum PerfomanceOverleyPosition {
code(bool, "overlay-show-touch-switch", false, overlay_show_touch_switch) \
code(float, "overlay-scale", 1.0f, overlay_scale) \
code(int, "overlay-opacity", 100, overlay_opacity) \
code(float, "overlay-scale-joystick", 1.0f, overlay_scale_joystick) \
code(int, "keyboard-button-select", 229, keyboard_button_select) \
code(int, "keyboard-button-start", 40, keyboard_button_start) \
code(int, "keyboard-button-up", 82, keyboard_button_up) \
Expand Down
2 changes: 1 addition & 1 deletion vita3k/gui/include/gui/functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ void update_notice_info(GuiState &gui, EmuEnvState &emuenv, const std::string &t
void update_time_app_used(GuiState &gui, EmuEnvState &emuenv, const std::string &app);
void save_notice_list(EmuEnvState &emuenv);
void set_controller_overlay_state(int overlay_mask, bool edit = false, bool reset = false);
void set_controller_overlay_scale(float scale);
void set_controller_overlay_scale(float scale, float joystick);
void set_controller_overlay_opacity(int opacity);
int get_overlay_display_mask(const Config &cfg);

Expand Down
3 changes: 2 additions & 1 deletion vita3k/gui/src/about_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,13 @@ void draw_about_dialog(GuiState &gui, EmuEnvState &emuenv) {
const ImVec2 display_size(emuenv.viewport_size.x, emuenv.viewport_size.y);
const ImVec2 RES_SCALE(display_size.x / emuenv.res_width_dpi_scale, display_size.y / emuenv.res_height_dpi_scale);
const ImVec2 SCALE(RES_SCALE.x * emuenv.dpi_scale, RES_SCALE.y * emuenv.dpi_scale);
const ImVec2 CENTER_POS = ImGui::GetMainViewport()->GetCenter();
static const auto BUTTON_SIZE = ImVec2(120.f * emuenv.dpi_scale, 0.f);

auto &lang = gui.lang.about;
auto &common = emuenv.common_dialog.lang.common;

ImGui::SetNextWindowPos(ImVec2(display_size.x / 2.f, display_size.y / 2.f), ImGuiCond_Always, ImVec2(0.5f, 0.5f));
ImGui::SetNextWindowPos(CENTER_POS, ImGuiCond_Always, ImVec2(0.5f, 0.5f));
ImGui::Begin("##about", &gui.help_menu.about_dialog, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_AlwaysAutoResize);
ImGui::SetWindowFontScale(RES_SCALE.x);
auto title_str = lang["title"].c_str();
Expand Down
3 changes: 3 additions & 0 deletions vita3k/gui/src/controllers_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,9 @@ void draw_controllers_dialog(GuiState &gui, EmuEnvState &emuenv) {
if (ImGui::Button(common["close"].c_str(), BUTTON_SIZE))
rebinds_is_open = false;

#ifdef ANDROID
ImGui::ScrollWhenDragging(); // because only in Android was hard to press scroll slider
#endif
ImGui::End();
}
}
Expand Down
35 changes: 27 additions & 8 deletions vita3k/gui/src/controls_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ void set_controller_overlay_state(int overlay_mask, bool edit, bool reset) {
env->DeleteLocalRef(clazz);
}

void set_controller_overlay_scale(float scale) {
void set_controller_overlay_scale(float scale, float joystick) {
// retrieve the JNI environment.
JNIEnv *env = reinterpret_cast<JNIEnv *>(SDL_AndroidGetJNIEnv());

Expand All @@ -84,10 +84,10 @@ void set_controller_overlay_scale(float scale) {
jclass clazz(env->GetObjectClass(activity));

// find the identifier of the method to call
jmethodID method_id = env->GetMethodID(clazz, "setControllerOverlayScale", "(F)V");
jmethodID method_id = env->GetMethodID(clazz, "setControllerOverlayScale", "(FF)V");

// effectively call the Java method
env->CallVoidMethod(activity, method_id, scale);
env->CallVoidMethod(activity, method_id, scale, joystick);

// clean up the local references.
env->DeleteLocalRef(activity);
Expand Down Expand Up @@ -119,8 +119,10 @@ void draw_controls_dialog(GuiState &gui, EmuEnvState &emuenv) {
static bool overlay_editing = false;

const ImVec2 display_size(emuenv.viewport_size.x, emuenv.viewport_size.y);
const ImVec2 center_pos = ImGui::GetMainViewport()->GetCenter(); // Always center this window when appearing
const auto BUTTON_SIZE = ImVec2(120.f * emuenv.dpi_scale, 0.f);
const auto RES_SCALE = ImVec2(display_size.x / emuenv.res_width_dpi_scale, display_size.y / emuenv.res_height_dpi_scale);
ImGui::SetNextWindowPos(ImVec2(display_size.x / 2.f, display_size.y / 2.f), ImGuiCond_Always, ImVec2(0.5f, 0.5f));
ImGui::SetNextWindowPos(center_pos, ImGuiCond_Always, ImVec2(0.5f, 0.5f));
ImGui::Begin("Overlay", &gui.controls_menu.controls_dialog, ImGuiWindowFlags_AlwaysAutoResize);
ImGui::SetWindowFontScale(RES_SCALE.x);

Expand All @@ -139,25 +141,34 @@ void draw_controls_dialog(GuiState &gui, EmuEnvState &emuenv) {
config::serialize_config(emuenv.cfg, emuenv.cfg.config_path);

const char *overlay_edit_text = overlay_editing ? "Hide Gamepad Overlay" : "Modify Gamepad Overlay";
ImGui::SetCursorPosX((ImGui::GetWindowWidth() / 2.f) - (gmpd / 2.f)); // recenter button
if (ImGui::Button(overlay_edit_text)) {
overlay_editing = !overlay_editing;
set_controller_overlay_state(overlay_editing ? get_overlay_display_mask(emuenv.cfg) : 0, overlay_editing);
}
ImGui::Spacing();
if (overlay_editing && ImGui::SliderFloat("Overlay scale", &emuenv.cfg.overlay_scale, 0.25f, 4.0f, "%.3f", ImGuiSliderFlags_NoInput | ImGuiSliderFlags_NoRoundToFormat | ImGuiSliderFlags_Logarithmic)) {
set_controller_overlay_scale(emuenv.cfg.overlay_scale);
if (ImGui::SliderFloat("Overlay scale", &emuenv.cfg.overlay_scale, 0.25f, 4.0f, "%.3f", ImGuiSliderFlags_NoInput | ImGuiSliderFlags_NoRoundToFormat | ImGuiSliderFlags_Logarithmic)) {
set_controller_overlay_scale(emuenv.cfg.overlay_scale, emuenv.cfg.overlay_scale_joystick);
config::serialize_config(emuenv.cfg, emuenv.cfg.config_path);
}
ImGui::Spacing();
if (overlay_editing && ImGui::SliderInt("Overlay opacity", &emuenv.cfg.overlay_opacity, 0, 100, "%d%%")) {
if (ImGui::SliderFloat("Overlay scale joystick", &emuenv.cfg.overlay_scale_joystick, 0.25f, 4.0f, "%.3f", ImGuiSliderFlags_NoInput | ImGuiSliderFlags_NoRoundToFormat | ImGuiSliderFlags_Logarithmic)) {
set_controller_overlay_scale(emuenv.cfg.overlay_scale, emuenv.cfg.overlay_scale_joystick);
config::serialize_config(emuenv.cfg, emuenv.cfg.config_path);
}
ImGui::Spacing();
if (ImGui::SliderInt("Overlay opacity", &emuenv.cfg.overlay_opacity, 0, 100, "%d%%")) {
set_controller_overlay_opacity(emuenv.cfg.overlay_opacity);
config::serialize_config(emuenv.cfg, emuenv.cfg.config_path);
}
ImGui::Spacing();
ImGui::SetCursorPosX((ImGui::GetWindowWidth() / 2.f) - (gmpd / 2.f));
if (overlay_editing && ImGui::Button("Reset Gamepad")) {
set_controller_overlay_state(get_overlay_display_mask(emuenv.cfg), true, true);
emuenv.cfg.overlay_scale = 1.0f;
emuenv.cfg.overlay_scale_joystick = 1.0f;
emuenv.cfg.overlay_opacity = 100;
set_controller_overlay_scale(emuenv.cfg.overlay_scale);
set_controller_overlay_scale(emuenv.cfg.overlay_scale, emuenv.cfg.overlay_scale_joystick);
set_controller_overlay_opacity(emuenv.cfg.overlay_opacity);
config::serialize_config(emuenv.cfg, emuenv.cfg.config_path);
}
Expand All @@ -169,6 +180,14 @@ void draw_controls_dialog(GuiState &gui, EmuEnvState &emuenv) {
}
ImGui::Text("L2/R2 triggers will be displayed only if PSTV mode is enabled.");

auto &common = emuenv.common_dialog.lang.common;
ImGui::SetCursorPosX((ImGui::GetWindowSize().x / 2.f) - (BUTTON_SIZE.x / 2.f));
if (ImGui::Button(common["close"].c_str(), BUTTON_SIZE)){
overlay_editing = false;
set_controller_overlay_state(0);
gui.controls_menu.controls_dialog = false;
}
ImGui::ScrollWhenDragging();
ImGui::End();
}

Expand Down
2 changes: 1 addition & 1 deletion vita3k/gui/src/gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ void init(GuiState &gui, EmuEnvState &emuenv) {

#ifdef ANDROID
// must be called once for the java side to get the scale
set_controller_overlay_scale(emuenv.cfg.overlay_scale);
set_controller_overlay_scale(emuenv.cfg.overlay_scale, emuenv.cfg.overlay_scale_joystick);
set_controller_overlay_opacity(emuenv.cfg.overlay_opacity);
#endif
}
Expand Down
2 changes: 1 addition & 1 deletion vita3k/gui/src/live_area.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1062,7 +1062,7 @@ void draw_live_area_screen(GuiState &gui, EmuEnvState &emuenv) {
const auto SELECT_SIZE = ImVec2(GATE_SIZE.x - (10.f * SCALE.x), GATE_SIZE.y - (5.f * SCALE.y));
const auto SELECT_POS = ImVec2(GATE_POS.x + (5.f * SCALE.y), GATE_POS.y + (2.f * SCALE.y));

const auto BUTTON_SIZE = ImVec2(72.f * SCALE.x, 30.f * SCALE.y);
const auto BUTTON_SIZE = ImVec2(80.f * SCALE.x, 55.f * SCALE.y);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need change it, problem here is not size, is how button size is scalled on android, because code for respect aspect ratio is disable on android
i not have this problem in my side
Buton size is all time same and fine

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in my phone that button was hard to press, most often vita3k notification got pressed instead esc.
or should i move a bit lower instead resize it?


if (gui.live_area_contents[app_path].contains("gate")) {
ImGui::SetCursorPos(GATE_POS);
Expand Down
4 changes: 3 additions & 1 deletion vita3k/gui/src/main_menubar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,9 @@ void draw_main_menu_bar(GuiState &gui, EmuEnvState &emuenv) {

draw_file_menu(gui, emuenv);
draw_emulation_menu(gui, emuenv);
draw_debug_menu(gui, gui.debug_menu);
if(emuenv.cfg.debug_menu)
draw_debug_menu(gui, gui.debug_menu);

draw_config_menu(gui, emuenv);
draw_controls_menu(gui);
draw_help_menu(gui);
Expand Down
2 changes: 2 additions & 0 deletions vita3k/gui/src/settings_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1353,6 +1353,8 @@ void draw_settings_dialog(GuiState &gui, EmuEnvState &emuenv) {
ImGui::SetTooltip("%s", lang.debug["validation_layer_description"].c_str());
}
ImGui::Spacing();
ImGui::Checkbox(lang.debug["debug_menu"].c_str(), &emuenv.cfg.debug_menu);
ImGui::Spacing();
if (ImGui::Button(emuenv.kernel.debugger.watch_code ? lang.debug["unwatch_code"].c_str() : lang.debug["watch_code"].c_str())) {
emuenv.kernel.debugger.watch_code = !emuenv.kernel.debugger.watch_code;
emuenv.kernel.debugger.update_watches();
Expand Down
1 change: 1 addition & 0 deletions vita3k/lang/include/lang/state.h
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,7 @@ struct LangState {
{ "dump_elfs_description", "Dump loaded code as ELFs." },
{ "validation_layer", "Validation Layer (Reboot required)" },
{ "validation_layer_description", "Enable Vulkan validation layer." },
{ "debug_menu", "Enable debug menu in menubar" },
{ "unwatch_code", "Unwatch Code" },
{ "watch_code", "Watch Code" },
{ "unwatch_memory", "Unwatch Memory" },
Expand Down