Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
st3ph4nnn opened this issue Aug 9, 2021 · 3 comments
Open

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

st3ph4nnn opened this issue Aug 9, 2021 · 3 comments

Comments

@st3ph4nnn
Copy link

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
Copy link

PLZ WITHOUT ANTIPASTE

@wainer1337
Copy link

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

@maecry
Copy link

maecry commented Jun 1, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants