Skip to content

Commit

Permalink
Finish applying resharper suggestions to oscar/
Browse files Browse the repository at this point in the history
  • Loading branch information
adamkewley committed Nov 22, 2024
1 parent f815618 commit 990164b
Show file tree
Hide file tree
Showing 49 changed files with 193 additions and 223 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include <oscar/Maths/Vec3.h>
#include <oscar/Platform/Log.h>
#include <oscar/Utils/Algorithms.h>
#include <oscar/Utils/Assertions.h>
#include <oscar/Utils/UID.h>

#include <array>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
#include <oscar/Platform/os.h>
#include <oscar/UI/Events/OpenTabEvent.h>
#include <oscar/Utils/Algorithms.h>
#include <oscar/Utils/Assertions.h>
#include <oscar/Utils/FilesystemHelpers.h>
#include <oscar/Utils/UID.h>

Expand Down
2 changes: 1 addition & 1 deletion src/OpenSimCreator/Platform/OpenSimCreatorApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
#include <oscar/Platform/AppMetadata.h>
#include <oscar/Platform/AppSettings.h>
#include <oscar/Platform/Log.h>
#include <oscar/Platform/os.h>
#include <oscar/UI/Tabs/TabRegistry.h>
#include <oscar/Utils/Assertions.h>
#include <oscar/Utils/Conversion.h>
#include <oscar/Utils/CStringView.h>
#include <oscar/Utils/EnumHelpers.h>
Expand Down
2 changes: 1 addition & 1 deletion src/OpenSimCreator/UI/MeshImporter/MeshImporterTab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@
#include <oscar/UI/Tabs/TabPrivate.h>
#include <oscar/UI/Widgets/CameraViewAxes.h>
#include <oscar/UI/Widgets/LogViewer.h>
#include <oscar/Utils/Assertions.h>
#include <oscar/Utils/CStringView.h>
#include <oscar/Utils/LifetimedPtr.h>
#include <oscar/Utils/ScopeGuard.h>
#include <oscar/Utils/UID.h>

Expand Down
2 changes: 1 addition & 1 deletion src/OpenSimCreator/UI/Shared/CoordinateEditorPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
#include <oscar/UI/Events/OpenPopupEvent.h>
#include <oscar/UI/oscimgui.h>
#include <oscar/UI/Panels/PanelPrivate.h>
#include <oscar/Utils/Assertions.h>
#include <oscar/Utils/CStringView.h>
#include <oscar/Utils/LifetimedPtr.h>

#include <algorithm>
#include <ranges>
Expand Down
2 changes: 1 addition & 1 deletion src/OpenSimCreator/UI/Shared/MainMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ osc::MainMenuFileTab::MainMenuFileTab(Widget& parent) :
)
}
{
rgs::sort(exampleOsimFiles, is_filename_lexographically_greater_than);
rgs::sort(exampleOsimFiles, is_filename_lexicographically_greater_than);
}

void osc::MainMenuFileTab::onDraw(IModelStatePair* maybeModel)
Expand Down
2 changes: 1 addition & 1 deletion src/oscar/UI/Popups/StandardPopup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ bool osc::StandardPopup::impl_begin_popup()
//
// else, do nothing - the popup's position will be determined
// by other means (unlike a modal, which usually takes control
// of the screen and, therefore, should proabably be centered
// of the screen and, therefore, should probably be centered
// in it)
if (maybe_position_) {
ui::set_next_panel_pos(
Expand Down
20 changes: 10 additions & 10 deletions src/oscar/UI/Widgets/GuiRuler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ void osc::GuiRuler::on_draw(
const float circle_radius = 5.0f;
const float line_thickness = 3.0f;

ui::DrawListView drawlist = ui::get_panel_draw_list();
const auto draw_tooltip_with_bg = [&drawlist, &text_background_color, &text_color](const Vec2& pos, CStringView tooltip_text)
ui::DrawListView draw_list = ui::get_panel_draw_list();
const auto draw_tooltip_with_bg = [&draw_list, &text_background_color, &text_color](const Vec2& pos, CStringView tooltip_text)
{
const Vec2 text_size = ui::calc_text_size(tooltip_text);
const float background_padding = 5.0f;
Expand All @@ -56,19 +56,19 @@ void osc::GuiRuler::on_draw(
{pos - background_padding},
{pos + text_size + background_padding},
};
drawlist.add_rect_filled(background_rect, text_background_color, edge_rounding);
drawlist.add_text(pos, text_color, tooltip_text);
draw_list.add_rect_filled(background_rect, text_background_color, edge_rounding);
draw_list.add_text(pos, text_color, tooltip_text);
};

if (state_ == State::WaitingForFirstPoint) {
if (not maybe_mouseover) {
// not mousing over anything
drawlist.add_circle_filled(Circle{mouse_pos, circle_radius}, circle_moused_over_nothing_color);
draw_list.add_circle_filled(Circle{mouse_pos, circle_radius}, circle_moused_over_nothing_color);
return;
}
else {
// mousing over something
drawlist.add_circle_filled(Circle{mouse_pos, circle_radius}, circle_color);
draw_list.add_circle_filled(Circle{mouse_pos, circle_radius}, circle_color);

if (ui::is_mouse_released(ui::MouseButton::Left)) {
state_ = State::WaitingForSecondPoint;
Expand All @@ -88,9 +88,9 @@ void osc::GuiRuler::on_draw(
const Vec2 line_midpoint = (start_screenpos + end_screenpos) / 2.0f;
const float line_world_length = length(maybe_mouseover->worldspace_location - start_world_pos_);

drawlist.add_circle_filled({start_screenpos, circle_radius}, circle_color);
drawlist.add_line(start_screenpos, end_screenpos, line_color, line_thickness);
drawlist.add_circle_filled({end_screenpos, circle_radius}, circle_color);
draw_list.add_circle_filled({start_screenpos, circle_radius}, circle_color);
draw_list.add_line(start_screenpos, end_screenpos, line_color, line_thickness);
draw_list.add_circle_filled({end_screenpos, circle_radius}, circle_color);

// label the line's length
{
Expand All @@ -104,7 +104,7 @@ void osc::GuiRuler::on_draw(
}
}
else {
drawlist.add_circle_filled({start_screenpos, circle_radius}, circle_color);
draw_list.add_circle_filled({start_screenpos, circle_radius}, circle_color);
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/oscar/UI/oscimgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -947,9 +947,9 @@ float osc::ui::get_cursor_pos_x()
return ImGui::GetCursorPosX();
}

void osc::ui::set_cursor_pos(Vec2 p)
void osc::ui::set_cursor_pos(Vec2 pos)
{
ImGui::SetCursorPos(p);
ImGui::SetCursorPos(pos);
}

void osc::ui::set_cursor_pos_x(float local_x)
Expand Down Expand Up @@ -1440,7 +1440,7 @@ void osc::ui::DrawList::render_to(RenderTexture& target)
c.set_view_matrix_override(identity<Mat4>());

{
// project screenspace overlays into NDC
// project screen-space overlays into NDC
float L = 0.0f;
float R = static_cast<float>(target.dimensions().x);
float T = 0.0f;
Expand Down Expand Up @@ -2348,7 +2348,7 @@ bool osc::ui::draw_float_circular_slider(
// figure out whether the user is (temporarily) editing the slider as an input text box
bool temporary_text_input_active = temporary_text_input_allowed and ImGui::TempInputIsActive(id);
if (not temporary_text_input_active) {
// tabbing or double clicking the slider temporarily transforms it into an input box
// tabbing or double-clicking the slider temporarily transforms it into an input box
const bool clicked = is_hovered and ui::is_mouse_clicked(MouseButton::Left, ui::ID{id});
const bool double_clicked = (is_hovered and g.IO.MouseClickedCount[0] == 2 and ImGui::TestKeyOwner(ImGuiKey_MouseLeft, id));
const bool make_active = (clicked or double_clicked or g.NavActivateId == id);
Expand Down Expand Up @@ -2686,7 +2686,7 @@ std::optional<Transform> osc::ui::Gizmo::draw_to(
const Mat4& view_matrix,
const Mat4& projection_matrix,
const Rect& screenspace_rect,
ImDrawList* drawlist)
ImDrawList* draw_list)
{
if (operation_ == GizmoOperation::None) {
return std::nullopt; // disabled
Expand All @@ -2706,7 +2706,7 @@ std::optional<Transform> osc::ui::Gizmo::draw_to(
dimensions_of(screenspace_rect).x,
dimensions_of(screenspace_rect).y
);
ImGuizmo::SetDrawlist(drawlist);
ImGuizmo::SetDrawlist(draw_list);
ImGuizmo::AllowAxisFlip(false); // user's didn't like this feature in UX sessions

// use rotation from the parent, translation from station
Expand Down
22 changes: 10 additions & 12 deletions src/oscar/UI/oscimgui.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@
#include <oscar/Maths/Mat4.h>
#include <oscar/Maths/Rect.h>
#include <oscar/Maths/Transform.h>
#include <oscar/Maths/Triangle.h>
#include <oscar/Maths/Vec.h>
#include <oscar/Maths/Vec2.h>
#include <oscar/Maths/Vec3.h>
#include <oscar/Platform/Key.h>
#include <oscar/Shims/Cpp23/utility.h>
#include <oscar/Utils/Conversion.h>
#include <oscar/Utils/CStringView.h>
#include <oscar/Utils/EnumHelpers.h>
#include <oscar/Utils/Flags.h>
#include <oscar/Utils/UID.h>

Expand Down Expand Up @@ -573,14 +571,14 @@ namespace osc::ui
// applies "dark" theme to current UI context
void apply_dark_theme();

// updates a polar comera's rotation, position, etc. from UI keyboard input state
// updates a polar camera's rotation, position, etc. from UI keyboard input state
bool update_polar_camera_from_keyboard_inputs(
PolarPerspectiveCamera&,
const Rect& viewport_rect,
std::optional<AABB> maybe_scene_aabb
);

// updates a polar comera's rotation, position, etc. from UI input state (all)
// updates a polar camera's rotation, position, etc. from UI input state (all)
bool update_polar_camera_from_all_inputs(
PolarPerspectiveCamera&,
const Rect& viewport_rect,
Expand All @@ -592,7 +590,7 @@ namespace osc::ui
EulerAngles&
);

// returns the UI content region available in screenspace as a `Rect`
// returns the UI content region available in screen-space as a `Rect`
Rect content_region_avail_as_screen_rect();

// draws a texture within the 2D UI
Expand Down Expand Up @@ -641,7 +639,7 @@ namespace osc::ui
Vec2 dimensions
);

// returns the screenspace bounding rectangle of the last-drawn item
// returns the screen-space bounding rectangle of the last-drawn item
Rect get_last_drawn_item_screen_rect();

// hittest the last-drawn item in the UI
Expand Down Expand Up @@ -924,8 +922,8 @@ namespace osc::ui
const Rect& screenspace_rect
);

// same as `draw`, but draws to the foreground drawlist, rather than the
// drawlist of the currently active panel
// same as `draw`, but draws to the foreground draw list, rather than the
// draw list of the currently active panel
std::optional<Transform> draw_to_foreground(
Mat4& model_matrix, // edited in-place
const Mat4& view_matrix,
Expand All @@ -949,7 +947,7 @@ namespace osc::ui
const Mat4& view_matrix,
const Mat4& projection_matrix,
const Rect& screenspace_rect,
ImDrawList* drawlist
ImDrawList* draw_list
);

UID id_;
Expand Down Expand Up @@ -1231,7 +1229,7 @@ namespace osc::ui
DragToolFlags = DragToolFlags::Default
);

// draws a draggable vertical guide line at an x-value in the plot area
// draws a draggable vertical guideline at an x-value in the plot area
bool drag_line_x(
int id,
double* x,
Expand All @@ -1240,7 +1238,7 @@ namespace osc::ui
DragToolFlags = DragToolFlags::Default
);

// draws a draggable horizontal guide line at a y-value in the plot area
// draws a draggable horizontal guideline at a y-value in the plot area
bool drag_line_y(
int id,
double* y,
Expand All @@ -1249,7 +1247,7 @@ namespace osc::ui
DragToolFlags = DragToolFlags::Default
);

// draws a tag on the x axis at the specified x value
// draws a tag on the x-axis at the specified x value
void tag_x(double x, const Color&, bool round = false);

// returns `true` if the plot area in the current plot is hovered
Expand Down
8 changes: 4 additions & 4 deletions src/oscar/UI/ui_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ static void ImGui_ImplSDL2_UpdateMouseData()
if (io.BackendFlags & ImGuiBackendFlags_HasMouseHoveredViewport) {
ImGuiID mouse_viewport_id = 0;
if (SDL_Window* sdl_mouse_window = SDL_GetWindowFromID(bd->MouseWindowID)) {
if (ImGuiViewport* mouse_viewport = ImGui::FindViewportByPlatformHandle(cpp20::bit_cast<void*>(sdl_mouse_window))) {
if (const ImGuiViewport* mouse_viewport = ImGui::FindViewportByPlatformHandle(cpp20::bit_cast<void*>(sdl_mouse_window))) {
mouse_viewport_id = mouse_viewport->ID;
}
}
Expand Down Expand Up @@ -500,7 +500,7 @@ static void ImGui_ImplOscar_NewFrame(App& app)
}

// Our io.AddMouseViewportEvent() calls will only be valid when not capturing.
// Technically speaking testing for 'bd->MouseButtonsDown == 0' would be more rygorous, but testing for payload reduces noise and potential side-effects.
// Technically speaking testing for 'bd->MouseButtonsDown == 0' would be more rigorous, but testing for payload reduces noise and potential side effects.
if (bd.MouseCanReportHoveredViewport and ImGui::GetDragDropPayload() == nullptr) {
io.BackendFlags |= ImGuiBackendFlags_HasMouseHoveredViewport;
}
Expand Down Expand Up @@ -568,10 +568,10 @@ void osc::ui::context::init(App& app)
#ifdef EMSCRIPTEN
io.IniFilename = nullptr;
#else
float dpi_scale_factor = [&]()
const float dpi_scale_factor = [&]()
{
// if the user explicitly enabled high_dpi_mode...
if (auto v = app.get_config().find_value("experimental_feature_flags/high_dpi_mode"); v and *v) {
if (const auto v = app.get_config().find_value("experimental_feature_flags/high_dpi_mode"); v and *v) {
return app.main_window_dpi() / 96.0f;
}
else {
Expand Down
Loading

0 comments on commit 990164b

Please sign in to comment.