Skip to content

Commit

Permalink
refactor: small cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
stdNullPtr committed Dec 15, 2024
1 parent 257faab commit dbaba65
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 61 deletions.
49 changes: 21 additions & 28 deletions um-client/src/render/DrawCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,78 +4,71 @@ namespace render
{
RenderObjectType DrawCache::get_type() const
{
return type;
return type_;
}

ImVec2 DrawCache::get_top_left() const
{
return topLeft;
return top_left_;
}

ImVec2 DrawCache::get_bottom_right() const
{
return bottomRight;
return bottom_right_;
}

ImVec4 DrawCache::get_color() const
{
return color;
return color_;
}

float DrawCache::get_thickness() const
{
return thickness;
return thickness_;
}

ImVec2 DrawCache::get_position() const
{
return position;
}

bool DrawCache::get_render_only_when_menu_open() const
{
return render_only_when_menu_open;
return position_;
}

int DrawCache::get_line_position() const
{
return line_position;
return line_position_;
}

std::string DrawCache::get_text() const
{
return text;
return text_;
}

float DrawCache::get_radius() const
{
return radius;
return radius_;
}

DrawCache DrawCache::build_rect(const ImVec2& topLeft, const ImVec2& bottomRight, const bool& filled, const ImVec4& col, const float& thick, const bool& renderOnlyWhenMenuOpen)
DrawCache DrawCache::build_rect(const ImVec2& top_left, const ImVec2& bottom_right, const bool& filled, const ImVec4& col, const float& thick)
{
DrawCache cache;

cache.type = filled ? RenderObjectType::rect_filled : RenderObjectType::rect;
cache.topLeft = topLeft;
cache.bottomRight = bottomRight;
cache.color = col;
cache.thickness = thick;
cache.render_only_when_menu_open = renderOnlyWhenMenuOpen;
cache.type_ = filled ? RenderObjectType::rect_filled : RenderObjectType::rect;
cache.top_left_ = top_left;
cache.bottom_right_ = bottom_right;
cache.color_ = col;
cache.thickness_ = thick;

return cache;
}

DrawCache DrawCache::build_text(const std::string& text, const ImVec2& position, const ImVec4& col, const int& line_position, const bool& renderOnlyWhenMenuOpen)
DrawCache DrawCache::build_text(const std::string& text, const ImVec2& position, const ImVec4& col, const int& line_position)
{
DrawCache cache;

cache.type = RenderObjectType::text;
cache.position = position;
cache.color = col;
cache.text = text;
cache.line_position = line_position;
cache.render_only_when_menu_open = renderOnlyWhenMenuOpen;
cache.type_ = RenderObjectType::text;
cache.position_ = position;
cache.color_ = col;
cache.text_ = text;
cache.line_position_ = line_position;

return cache;
}
Expand Down
24 changes: 11 additions & 13 deletions um-client/src/render/DrawCache.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,29 @@ namespace render
DrawCache() = default;

private:
RenderObjectType type;
RenderObjectType type_;

// COMMON
ImVec4 color;
ImVec2 position;
bool render_only_when_menu_open;
ImVec4 color_;
ImVec2 position_;

// RECT
ImVec2 topLeft;
ImVec2 bottomRight;
float thickness;
ImVec2 top_left_;
ImVec2 bottom_right_;
float thickness_;

// TEXT
int line_position;
std::string text;
int line_position_;
std::string text_;

//CIRCLE
float radius;
float radius_;

public:
[[nodiscard]] RenderObjectType get_type() const;

[[nodiscard]] ImVec4 get_color() const;
[[nodiscard]] ImVec2 get_position() const;
[[nodiscard]] bool get_render_only_when_menu_open() const;

[[nodiscard]] ImVec2 get_top_left() const;
[[nodiscard]] ImVec2 get_bottom_right() const;
Expand All @@ -50,8 +48,8 @@ namespace render

[[nodiscard]] float get_radius() const;

static DrawCache build_rect(const ImVec2& topLeft, const ImVec2& bottomRight, const bool& filled = false, const ImVec4& col = {255.0f, 0.0f, 0.0f, 255.0f}, const float& thick = 2.0f, const bool& renderOnlyWhenMenuOpen = false);
static DrawCache build_rect(const ImVec2& top_left, const ImVec2& bottom_right, const bool& filled = false, const ImVec4& col = {255.0f, 0.0f, 0.0f, 255.0f}, const float& thick = 2.0f);

static DrawCache build_text(const std::string& text, const ImVec2& position, const ImVec4& col, const int& line_position, const bool& renderOnlyWhenMenuOpen = false);
static DrawCache build_text(const std::string& text, const ImVec2& position, const ImVec4& col, const int& line_position);
};
}
35 changes: 15 additions & 20 deletions um-client/src/render/Render.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ namespace render

ImGui::SliderFloat(XOR("Thickness"), &g::esp_box_thickness, 1.0f, 3.0f);
ImGui::SliderFloat(XOR("Aim FOV"), &g::aim_fov, 5.0f, 200.0f);
draw_list->AddCircle(g::screen_center, g::aim_fov, IM_COL32_WHITE);
draw_list->AddCircle(g::screen_center, g::aim_fov, IM_COL32_WHITE, 0, 2.0f);
ImGui::SliderInt(XOR("Extra info X"), &g::additional_screen_info_position_x, 50, 300);
ImGui::SliderInt(XOR("Extra info Y"), &g::additional_screen_info_position_y, 0, 700);

Expand All @@ -235,11 +235,6 @@ namespace render

for (const auto& object : draw_objects)
{
if (object.get_render_only_when_menu_open() && !show_menu)
{
continue;
}

switch (object.get_type())
{
case RenderObjectType::rect:
Expand Down Expand Up @@ -275,36 +270,36 @@ namespace render
break;
}

const ImVec2 requestedPosition{object.get_position()};
const ImVec2 requested_position{object.get_position()};

const int linePosition{object.get_line_position()};
const ImVec2 textSize{ImGui::CalcTextSize(text.c_str())};
const ImVec2 position{requestedPosition.x - textSize.x / 2.0f, requestedPosition.y + textSize.y * static_cast<float>(linePosition)};
const int line_position{object.get_line_position()};
const ImVec2 text_size{ImGui::CalcTextSize(text.c_str())};
const ImVec2 position{requested_position.x - text_size.x / 2.0f, requested_position.y + text_size.y * static_cast<float>(line_position)};
#pragma region shadow
const ImVec4 shadowColor{0.1f, 0.1f, 0.1f, color.w * 0.5f};
constexpr float shadowOffset{1.0f};
const ImVec4 shadow_color{0.1f, 0.1f, 0.1f, color.w * 0.5f};
constexpr float shadow_offset{1.0f};

draw_list->AddText(
ImVec2(position.x + shadowOffset, position.y),
ImGui::ColorConvertFloat4ToU32(shadowColor),
ImVec2(position.x + shadow_offset, position.y),
ImGui::ColorConvertFloat4ToU32(shadow_color),
text.c_str(),
text.c_str() + text.size()
);
draw_list->AddText(
ImVec2(position.x - shadowOffset, position.y),
ImGui::ColorConvertFloat4ToU32(shadowColor),
ImVec2(position.x - shadow_offset, position.y),
ImGui::ColorConvertFloat4ToU32(shadow_color),
text.c_str(),
text.c_str() + text.size()
);
draw_list->AddText(
ImVec2(position.x, position.y + shadowOffset),
ImGui::ColorConvertFloat4ToU32(shadowColor),
ImVec2(position.x, position.y + shadow_offset),
ImGui::ColorConvertFloat4ToU32(shadow_color),
text.c_str(),
text.c_str() + text.size()
);
draw_list->AddText(
ImVec2(position.x, position.y - shadowOffset),
ImGui::ColorConvertFloat4ToU32(shadowColor),
ImVec2(position.x, position.y - shadow_offset),
ImGui::ColorConvertFloat4ToU32(shadow_color),
text.c_str(),
text.c_str() + text.size()
);
Expand Down

0 comments on commit dbaba65

Please sign in to comment.