#include bool ui::in_range(const math::position_t& _position, const math::dimension_t& _dimension) { const auto cursor_position = g::p::input_mgr.get_cursor_pos(); if (cursor_position.x < _position.x || cursor_position.x > _position.x + _dimension.w) return false; if (cursor_position.y < _position.y || cursor_position.y > _position.y + _dimension.h) return false; return true; } void ui::section(const math::position_t& _position, const math::dimension_t& _dimension, respawn::color_t color, const char* name) { const float name_offset = (12.0f + g::p::render.get_text_width(name, 14) + 2.0f); g::p::render.draw_rect_filled({ 25, 25, 25 }, _position.x, _position.y, _position.x + _dimension.w, _position.y + _dimension.h); // top left - bottom left. g::p::render.draw_line(color, _position.x, _position.y, _position.x, _position.y + _dimension.h); // bottom left - bottom right. g::p::render.draw_line(color, _position.x, _position.y + _dimension.h, _position.x + _dimension.w, _position.y + _dimension.h); // bottom right - top right. g::p::render.draw_line(color, _position.x + _dimension.w, _position.y, _position.x + _dimension.w, _position.y + _dimension.h); // top left - top right. g::p::render.draw_line(color, _position.x + name_offset, _position.y, _position.x + _dimension.w, _position.y); g::p::render.draw_text(color, 2, 14, _position.x + 4.0f, _position.y - 5.0f, name); } void ui::checkbox(const math::position_t _position, const char* text, bool* variable) { if (variable == nullptr) return; const float text_width = static_cast(g::p::render.get_text_width(text, 14)) + 15.0f; const auto box_color = *variable ? respawn::color_t( 0, 245, 233 ) : respawn::colors::black; const float checkbox_center_x = (math::roundf(_position.x) + (10.0f / 2.0f)), checkbox_center_y = (math::roundf(_position.y) + (10.0f / 2.0f)); g::p::render.draw_rect_filled(box_color, checkbox_center_x - 3.0f, checkbox_center_y - 3.0f, checkbox_center_x + 3.0f, checkbox_center_y + 3.0f); g::p::render.draw_rect({ 46, 158, 153 }, checkbox_center_x - 5.0f, checkbox_center_y - 5.0f, checkbox_center_x + 5.0f, checkbox_center_y + 5.0f); g::p::render.draw_text({ 0, 245, 233 }, 2, 14, _position.x + 15.0f, _position.y - 2.0f, text); if (!in_range(_position, { text_width, 15.0f })) return; if (si::paint.was_button_down(VK_LBUTTON)) *variable = !*variable; } void ui::checkbox_triple(const math::position_t _position, const char* text, int* variable) { if (variable == nullptr) return; const float text_width = static_cast(g::p::render.get_text_width(text, 14)) + 15.0f; const auto box_color = *variable ? respawn::color_t(0, 245, 233) : respawn::colors::black; const float checkbox_center_x = (math::roundf(_position.x) + (10.0f / 2.0f)), checkbox_center_y = (math::roundf(_position.y) + (10.0f / 2.0f)); switch (*variable) { case 1: g::p::render.draw_rect_filled(box_color, checkbox_center_x, checkbox_center_y, checkbox_center_x + 3.0f, checkbox_center_y + 3.0f); break; case 2: g::p::render.draw_rect_filled(box_color, checkbox_center_x - 3.0f, checkbox_center_y - 3.0f, checkbox_center_x + 3.0f, checkbox_center_y + 3.0f); break; } g::p::render.draw_rect({ 46, 158, 153 }, checkbox_center_x - 5.0f, checkbox_center_y - 5.0f, checkbox_center_x + 5.0f, checkbox_center_y + 5.0f); g::p::render.draw_text_ex({ 0, 245, 233 }, 2, 14, _position.x + 15.0f, _position.y - 2.0f, _XS("%s (%i)"), text, *variable); if (!in_range(_position, { text_width, 15.0f })) return; if (si::paint.was_button_down(VK_LBUTTON)) { if (*variable < 2) ++(*variable); else *variable = 0; } } void ui::slider(math::position_t _position, math::dimension_t _dimension, const char* text, int* variable, int min, int max) { if (variable == nullptr) return; const auto cursor_position = g::p::input_mgr.get_cursor_pos(); const auto bar_color = static_cast(*variable) ? respawn::colors::green : respawn::colors::black; const float delta = _dimension.w / static_cast(max) * static_cast(*variable); char label[72]; util::format_string(label, sizeof(label), _XS("%s %i/%i"), text, static_cast(*variable), static_cast(max)); g::p::render.draw_text(respawn::colors::white, 2, 14, _position.x + 2.0f, _position.y, label); _position.y += 15.0f; g::p::render.draw_rect_filled({ 50, 50, 50 }, _position.x, _position.y, _position.x + _dimension.w, _position.y + _dimension.h); g::p::render.draw_rect_filled(bar_color, _position.x, _position.y, _position.x + delta, _position.y + _dimension.h); g::p::render.draw_rect(respawn::colors::black, _position.x, _position.y, _position.x + _dimension.w, _position.y + _dimension.h); g::p::render.draw_rect_filled({ 45, 45, 45 }, _position.x + delta - 5, _position.y - 2.0f, _position.x + delta, _position.y + _dimension.h + 2.0f); g::p::render.draw_rect({ 25, 25, 45 }, _position.x + delta - 5.0f, _position.y - 2.0f, _position.x + delta, _position.y + _dimension.h + 2.0f); if (!in_range({ _position.x, _position.y - 2.0f }, { _dimension.w, _dimension.h + 2.0f })) return; if (si::paint.is_button_down(VK_LBUTTON)) { const float scale = (max - min) / _dimension.w; const float value = min + (cursor_position.x - _position.x) * scale; auto value_to_set = static_cast(value); if (value_to_set < min) value_to_set = min; else if (value_to_set > max) value_to_set = max; *variable = value_to_set; } } void ui::slider_float(math::position_t _position, math::dimension_t _dimension, const char* text, float* variable, float min, float max) { if (variable == nullptr) return; const auto cursor_position = g::p::input_mgr.get_cursor_pos(); const auto bar_color = static_cast(*variable) ? respawn::colors::green : respawn::colors::black; const float delta = _dimension.w / static_cast(max) * static_cast(*variable); char label[72]; util::format_string(label, sizeof(label), _XS("%s %i/%i"), text, static_cast(*variable), static_cast(max)); g::p::render.draw_text(respawn::colors::white, 2, 14, _position.x + 2.0f, _position.y, label); _position.y += 15.0f; g::p::render.draw_rect_filled({ 50, 50, 50 }, _position.x, _position.y, _position.x + _dimension.w, _position.y + _dimension.h); g::p::render.draw_rect_filled(bar_color, _position.x, _position.y, _position.x + delta, _position.y + _dimension.h); g::p::render.draw_rect(respawn::colors::black, _position.x, _position.y, _position.x + _dimension.w, _position.y + _dimension.h); g::p::render.draw_rect_filled({ 45, 45, 45 }, _position.x + delta - 5, _position.y - 2.0f, _position.x + delta, _position.y + _dimension.h + 2.0f); g::p::render.draw_rect({ 25, 25, 45 }, _position.x + delta - 5.0f, _position.y - 2.0f, _position.x + delta, _position.y + _dimension.h + 2.0f); if (!in_range({ _position.x, _position.y - 2.0f }, { _dimension.w, _dimension.h + 2.0f })) return; if (si::paint.is_button_down(VK_LBUTTON)) { const float scale = (max - min) / _dimension.w; const float value = min + (cursor_position.x - _position.x) * scale; auto value_to_set = value; if (value_to_set < min) value_to_set = min; else if (value_to_set > max) value_to_set = max; *variable = value_to_set; } } bool ui::button( const math::position_t& _position, const math::dimension_t& _dimension, respawn::color_t background_color, respawn::color_t text_color, const char* text ) { const auto text_width = g::p::render.get_text_width(text, 11); g::p::render.draw_rect_filled(background_color, _position.x, _position.y, _position.x + _dimension.w, _position.y + _dimension.h); g::p::render.draw_rect(respawn::colors::black, _position.x, _position.y, _position.x + _dimension.w, _position.y + _dimension.h); g::p::render.draw_text( text_color, 2, 11, (_position.x + (_dimension.w / 2.f)) - (text_width / 2.f), _position.y + (_dimension.h / 4.f), text ); if (!in_range(_position, _dimension)) return false; const bool is_clicked = si::paint.was_button_down(VK_LBUTTON); return is_clicked; }