Подведи собственные итоги года совместно с YOUGAME и забери ценные призы! Перейти

Сломался color selector после апдейта

  • Автор темы Автор темы JIoJIka
  • Дата начала Дата начала
Забаненный
Участник
Участник
Статус
Оффлайн
Регистрация
23 Сен 2019
Сообщения
1,062
Реакции
190
Здравствуйте, после обновления кс го, у меня сломался color selector, что делать?
Вот код
C++:
Expand Collapse Copy
float Pi = 3.141592653589793;

float xy2polar1(int x, int y);
float xy2polar2(int x, int y);
float rad2deg(float rad);
color hsv2rgb(float hue, float saturation, int value);

void c_menu::color_selector(std::string name, color * colour, int type) {
    bool pressed = false;
    bool open = false;

    static bool selected_opened = false;
    static bool click_rest;
    static bool rest;
    static std::string name_selected;

    int x_position = groupbox_width - 40;
    int y_position = y_offset - 16;

    if (type == 2)
        x_position -= 40;

    render_manager::filled_rect(x_position + 2, y_position + 2, 31, 10, color(35, 35, 35, 255));
    render_manager::filled_rect(x_position + 2, y_position + 2, 31, 10, color(colour->r, colour->g, colour->b, colour->a));
    render_manager::rect(x_position, y_position, 35, 14, color(60, 56, 89));
    if(open)
        render_manager::rect(x_position, y_position, 35, 14, color(colour->r, colour->g, colour->b, colour->a));

    if (menu.menu_opened) {
        if (GetAsyncKeyState(VK_LBUTTON) && mouse_in_params(x_position - 1, y_position - 1, 32, 13) && !click_rest) {
            name_selected = name;
            pressed = true;
            click_rest = true;
        }
        else if (!GetAsyncKeyState(VK_LBUTTON) && mouse_in_params(x_position - 1, y_position - 1, 32, 13)) {
            click_rest = false;
        }
        if (pressed)
        {
            if (!rest) {
                menu.is_color_tick_selected = !menu.is_color_tick_selected;
                selected_opened = !selected_opened;
            }
            rest = true;
        }
        else
            rest = false;

        if (name_selected == name)
            open = selected_opened;
    }

    if (open) {
        x_position = _pos.x + 800;
        
        render_manager::filled_rect(x_position + 25, y_position, 160, 210, color(26, 21, 67));
        render_manager::rect(x_position + 25, y_position, 160, 210, color(47, 45, 73));

        circle(x_position + 39, y_position + 10, 65);

        XYSlider(x_position + 5, y_position + 145, 10, "Brightness", &brightness);

        XYSlider(x_position + 5, y_position + 170, 255, "Alpha", &colour->a);
        // handle input
        if (mouse_in_params(x_position + 39, y_position + 10, 130, 130)) {
            
            HDC hdc = GetDC(nullptr);

            COLORREF selected_colour;
            selected_colour = GetPixel(hdc, mouse_pos().x, mouse_pos().y);

            render_manager::filled_rect(mouse_pos().x + 20, mouse_pos().y - 10, 36, 14, color(GetRValue(selected_colour), GetGValue(selected_colour), GetBValue(selected_colour)));
            render_manager::rect(mouse_pos().x + 20, mouse_pos().y - 10, 36, 14, color(60, 56, 89));

            if (GetRValue(selected_colour) == 26 && GetGValue(selected_colour) == 21 && GetBValue(selected_colour) == 57)
                return;
            if (GetAsyncKeyState(VK_LBUTTON)) {
                colour->r = GetRValue(selected_colour);
                colour->g = GetGValue(selected_colour);
                colour->b = GetBValue(selected_colour);
            }
        }
        
    }
    if (type == 2)
        x_position += 40;
}
void c_menu::circle(int x1, int y1, int radius) {
    int rad = radius;
    int x, y;

    for (x = -rad; x < rad; x++) {
        for (y = -rad; y < rad; y++) {
            float r = xy2polar1(x, y);
            float phi = xy2polar2(x, y);

            if (r > rad)
                continue;

            float deg = rad2deg(phi);

            float adjustedX = x + rad + x1;
            float adjustedY = y + rad + y1;

            float hue = deg;
            float saturation = r / rad;

            render_manager::rect(adjustedX, adjustedY, 1, 1, hsv2rgb(hue, saturation, 1.0));
        }
    }
}
float xy2polar1(int x, int y) {
    float r = sqrt(x * x + y * y);
    return r;
}
float xy2polar2(int x, int y) {
    float phi = atan2(y, x);
    return phi;
}
float rad2deg(float rad) {
    return (rad + Pi) / (2 * Pi) * 360;
}
color hsv2rgb(float hue, float saturation, int value) {
    float chroma = value * saturation;
    float hue1 = hue / 60;
    float x = chroma * (1 - abs(fmod(hue1, 2.0) - 1));
    float r1, g1, b1;
    r1 = 0; g1 = 0; b1 = 0;
    if (hue1 >= 0 && hue1 <= 1) {
        r1 = chroma;
        g1 = x;
        b1 = 0;
    }
    else if (hue1 >= 1 && hue1 <= 2) {
        r1 = x;
        g1 = chroma;
        b1 = 0;
    }
    else if (hue1 >= 2 && hue1 <= 3) {
        r1 = 0;
        g1 = chroma;
        b1 = x;
    }
    else if (hue1 >= 3 && hue1 <= 4) {
        r1 = 0;
        g1 = x;
        b1 = chroma;
    }
    else if (hue1 >= 4 && hue1 <= 5) {
        r1 = x;
        g1 = 0;
        b1 = chroma;
    }
    else if (hue1 >= 5 && hue1 <= 6) {
        r1 = chroma;
        g1 = 0;
        b1 = x;
    }

    float m = value - chroma;
    float r, g, b;
    r = 255; g = 255; b = 255;
    r = r1 + m;
    g = g1 + m;
    b = b1 + m;
    return color(r * 255, g * 255, b * 255);
}
void c_menu::XYSlider(int x, int y, int max, const char* text, float* item) {
    //x -= 19;
    int slider_size = 140;

    float _pixel_value = max / slider_size;

    if (menu.menu_opened) {

        if (GetAsyncKeyState(VK_LBUTTON) && mouse_in_params(x + 29, y + 14, slider_size + 1, 16))
            * item = abs(mouse_pos().x - (x + 29)) * _pixel_value;

        if (*item > max) {
            *item = max;
        }

        if (*item < 0) {
            *item = 0;
        }
        if (*item > 245)
            * item = 255;
    }

    if (*item)
    {
        if (*item == max)
            render_manager::vertical_gradient_rect(x + 29, y + 14, slider_size, 10, color(228, 39, 100), color(167, 33, 87));
        else
            render_manager::vertical_gradient_rect(x + 29, y + 14, (*item / _pixel_value), 10, color(228, 39, 100), color(167, 33, 87));
    }

    render_manager::rect(x + 27, y + 12, slider_size + 4, 10 + 4, color(47, 45, 73));
    if (mouse_in_params(x + 27, y + 6, 140, 16)) {
        render_manager::rect(x + 27, y + 12, slider_size + 4, 10 + 4, color(145, 61, 111));
        render_manager::rect(x + 28, y + 13, slider_size + 2, 10 + 2, color(121, 2, 56));
    }

    render_manager::text(text, x + 29, y - 3, render_manager::fonts::menu_font, color(171, 169, 209));
}
Если знаете откуда можно спастить, оставьте ссылку на ресурс.
 
Назад
Сверху Снизу