Skip to content

Commit

Permalink
Add slider to change crosshair size
Browse files Browse the repository at this point in the history
  • Loading branch information
bslenul committed Nov 16, 2023
1 parent 402e8bc commit 89b19dc
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 10 deletions.
1 change: 1 addition & 0 deletions core/cfg/option.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ std::array<Option<int>, 4> CrosshairColor {
Option<int>("rend.CrossHairColor3"),
Option<int>("rend.CrossHairColor4"),
};
Option<int> CrosshairSize("rend.CrosshairSize", 40);
Option<int> SkipFrame("ta.skip");
Option<int> MaxThreads("pvr.MaxThreads", 3);
Option<int> AutoSkipFrame("pvr.AutoSkipFrame", 0);
Expand Down
1 change: 1 addition & 0 deletions core/cfg/option.h
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,7 @@ extern Option<bool> PerStripSorting;
extern Option<bool> DelayFrameSwapping; // Delay swapping frame until FB_R_SOF matches FB_W_SOF
extern Option<bool> WidescreenGameHacks;
extern std::array<Option<int>, 4> CrosshairColor;
extern Option<int> CrosshairSize;
extern Option<int> SkipFrame;
extern Option<int> MaxThreads;
extern Option<int> AutoSkipFrame; // 0: none, 1: some, 2: more
Expand Down
2 changes: 1 addition & 1 deletion core/rend/dx11/dx11_overlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ void DX11Overlay::draw(u32 width, u32 height, bool vmu, bool crosshair)
float halfHeight = lightgun_crosshair_size / 2.f * config::RenderResolution / 480.f;
x /= config::ScreenStretching / 100.f;
#else
float halfWidth = XHAIR_WIDTH * settings.display.uiScale / 2.f;
float halfWidth = config::CrosshairSize * settings.display.uiScale / 2.f;
float halfHeight = halfWidth;
#endif
D3D11_VIEWPORT vp{};
Expand Down
2 changes: 1 addition & 1 deletion core/rend/dx9/d3d_overlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ void D3DOverlay::draw(u32 width, u32 height, bool vmu, bool crosshair)
continue;

auto [x, y] = getCrosshairPosition(i);
float halfWidth = XHAIR_WIDTH * settings.display.uiScale / 2.f;
float halfWidth = config::CrosshairSize * settings.display.uiScale / 2.f;
RECT rect { (long) (x - halfWidth), (long) (y - halfWidth), (long) (x + halfWidth), (long) (y + halfWidth) };
D3DCOLOR color = (config::CrosshairColor[i] & 0xFF00FF00)
| ((config::CrosshairColor[i] >> 16) & 0xFF)
Expand Down
6 changes: 3 additions & 3 deletions core/rend/gles/opengl_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ void OpenGLDriver::displayCrosshairs()

ImVec2 pos;
std::tie(pos.x, pos.y) = getCrosshairPosition(i);
pos.x -= (XHAIR_WIDTH * settings.display.uiScale) / 2.f;
pos.y += (XHAIR_WIDTH * settings.display.uiScale) / 2.f;
ImVec2 pos_b(pos.x + XHAIR_WIDTH * settings.display.uiScale, pos.y - XHAIR_HEIGHT * settings.display.uiScale);
pos.x -= (config::CrosshairSize * settings.display.uiScale) / 2.f;
pos.y += (config::CrosshairSize * settings.display.uiScale) / 2.f;
ImVec2 pos_b(pos.x + config::CrosshairSize * settings.display.uiScale, pos.y - config::CrosshairSize * settings.display.uiScale);

ImGui::GetWindowDrawList()->AddImage(crosshairTexId, pos, pos_b, ImVec2(0, 1), ImVec2(1, 0), config::CrosshairColor[i]);
}
Expand Down
6 changes: 6 additions & 0 deletions core/rend/gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1700,6 +1700,7 @@ static void gui_display_settings()
ImGui::Spacing();
header("Dreamcast Devices");
{
bool is_there_any_xhair = false;
for (int bus = 0; bus < MAPLE_PORTS; bus++)
{
ImGui::Text("Device %c", bus + 'A');
Expand Down Expand Up @@ -1790,10 +1791,15 @@ static void gui_display_settings()
config::CrosshairColor[bus] = 0;
}
}
is_there_any_xhair |= enabled;
ImGui::PopID();
}
ImGui::PopItemWidth();
}
{
DisabledScope scope(!is_there_any_xhair);
OptionSlider("Crosshair Size", config::CrosshairSize, 10, 100);
}
OptionCheckbox("Per Game VMU A1", config::PerGameVmu, "When enabled, each game has its own VMU on port 1 of controller A.");
}

Expand Down
3 changes: 0 additions & 3 deletions core/rend/osd.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ void push_vmu_screen(int bus_id, int bus_port, u8* buffer);
const u32 *getCrosshairTextureData();
std::pair<float, float> getCrosshairPosition(int playerNum);

constexpr int XHAIR_WIDTH = 40;
constexpr int XHAIR_HEIGHT = 40;

static inline bool crosshairsNeeded()
{
if (config::CrosshairColor[0] == 0 && config::CrosshairColor[1] == 0
Expand Down
4 changes: 2 additions & 2 deletions core/rend/vulkan/overlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,8 @@ void VulkanOverlay::Draw(vk::CommandBuffer commandBuffer, vk::Extent2D viewport,
float h = lightgun_crosshair_size * scaling;
x /= config::ScreenStretching / 100.f;
#else
float w = XHAIR_WIDTH * scaling;
float h = XHAIR_HEIGHT * scaling;
float w = config::CrosshairSize * scaling;
float h = config::CrosshairSize * scaling;
#endif
x -= w / 2;
y -= h / 2;
Expand Down

0 comments on commit 89b19dc

Please sign in to comment.