designer1337 / csgo-cheat-base

simple csgo internal base.
MIT License
238 stars 50 forks source link

[pasta friendly] nice combobox & multicombobox for your pHack #111

Open st3ph4nnn opened 2 years ago

st3ph4nnn commented 2 years ago

since many people ask for it and most of the sources released here are not proper, i thought i would share what i made for myself. i've commented the code so if anyone doesnt understand they can learn hopefully. there's a little "anti paste" the function get_pos() but if you have enough brain you should figure what it does

combobox:

   void gui::combobox(std::string text, int x, int y, int w, int h, unsigned long font, const std::vector<std::string> elements, int* current) {
static bool open = false; // if we dont use "static" it wont stay opened.

if (get_pos(x, y, w, h)) // figure this yourself
    open = !open; // flip the bool.

std::size_t size = elements.size(); // get the array size, so we can loop thru it

render::draw_filled_rect(x + 2, y - 1, w, open ? 15 + (size * 15) : h, groupbox_background_alt); // increasing the h if its opened, we could also do the same with Y and render more rectangles but nah
render::draw_outline(x + 2, y - 1, w, open ? 15 + (size * 15) : h, outline_color); // increasing the h if its opened, we could also do the same with Y and render more rectangles but nah
render::text(x + ( w / 2 ), y + 2, font, elements[*current], true, text_color); // render the item selected.
render::text(x + w + 10, y + 1, font, text, false, text_color); // the label

if (open) {
    for (int i = 0; i < size; i++) { // loop thru the array
        if (get_pos(x, y, w, h + 15 + (i * 15))) { // figure get_pos yourself.
            *current = i; // set the current item to i, basically the element u click.
            return;
        }

        render::text(x + ( w / 2 ), y + 15 + (i * 15), font, elements[i], true, i == *current ? active : idle); // render all the elements
    }
}

multicombobox (also has a little add on feature)

    void gui::multi_combobox(std::string text, int x, int y, int w, int h, unsigned long font, const std::vector<std::string> elements, bool* item) {
static bool open = false; // if we dont use "static" it wont stay opened.

if (get_pos(x, y, w, h)) // figure this yourself
    open = !open; // flip the bool.

std::size_t size = elements.size();// get the array size, so we can loop thru it

render::draw_filled_rect(x + 2, y - 1, w, open ? 15 + (size * 15) : h, groupbox_background_alt); // draw some stuff, as usual we use the height and no the y cuz yes
render::draw_outline(x + 2, y - 1, w, open ? 15 + (size * 15) : h, outline_color); // draw some stuff, as usual we use the height and no the y cuz yes

// nice little feature i thought of, feel free to use it lol
std::string display;
for (int i = 0; i < size; i++) {
    if (item[i]) {
        if (!(render::get_text_size(font, display).x > w / 1.5))
            display += elements[i] + "; ";
        else
            display = elements[i] + "; ...";
    }
}
// text rendering
render::text(x + (w / 2), y + 2, font, display.empty() ? "nothing" : display, true, text_color); // if the display string is empty, render "nothing" else render display.
render::text(x + w + 10, y + 1, font, text, false, text_color); // label

if (open) {
    for (int i = 0; i < size; i++) { // loop thru the array
        if (get_pos(x, y, w, h + 15 + (i * 15))) // figure get_pos yourself
            item[i] = !item[i]; // since we use a bool array, we just flip the corresponding bool in that array

        render::text(x + (w / 2), y + 15 + (i * 15), font, elements[i], true, item[i] == true ? active : idle); // render the elements
    }
}

example use of it:

inline int main_combo{0}; inline bool test[3] = { false, false, false };

gui::combobox("cadua is awesome", variables::menu::x + 15, variables::menu::y + 110, 120, 20, render::fonts::menu_font, { "yess", "noo" }, &main_combo); gui::multi_combobox("tommy i love you", variables::menu::x + 15, variables::menu::y + 160, 120, 20, render::fonts::menu_font, { "what de fok", "no what", "wait" }, test);

screenshots:

image

image

MyNameIsKodak commented 2 years ago

PLZ WITHOUT ANTIPASTE

wainer1337 commented 2 years ago

if you gonna say "pasta friendly", and you gonna release a source with antipaste, you look kinda retarderd...

maecry commented 2 years ago

@wainer1337 you can clearly figure that out in like 2 seconds lol, you're the retarded paster here tbh