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

[ source ] better checkbox #109

Open
float69 opened this issue Jul 18, 2021 · 3 comments
Open

[ source ] better checkbox #109

float69 opened this issue Jul 18, 2021 · 3 comments

Comments

@float69
Copy link

float69 commented Jul 18, 2021

static int stage = 0;

bool in_region = input::in_region(x, y, w, h);

auto arrow = [](int x, int y, color clr) -> void
{
	for (int i = 0; i < 3; i++)
		render::draw_filled_rect(x + i, y + i, 5 - i * 2, 1, clr);
};

if (input::key_clicked(VK_LBUTTON) && in_region)
{
	isComboOpen = !isComboOpen;
}

render::grad_rect(vec2_t(x - 1, y), vec2_t(w + 1, h), color(36, 36, 36), color(28, 28, 28));
render::draw_outline(x - 1, y, w + 1, h, color(60, 60, 60, 255));
render::draw_outline(x - 2, y - 1, w + 3, h + 2, color(4, 4, 4, 255));

render::text(x, y - 14, font, name, false, color::white());
render::text(x + 4, y + 2, font, items.at(*v), false, color::white());


arrow(x + w - 11, y + h / 2 - 1, isComboOpen ? variables::menu::accent : color::white());


if (input::key_clicked(VK_LBUTTON) && !in_region && !isComboOpen)
{
	isComboOpen = false;
}

if (isComboOpen)
{
	stage = min(stage + 1, 2);

	auto item = items;

	for (int i = 0; i < item.size(); i++)
	{
		csize_t control = { x, y + 10 + i * 18 + 12, w - 1, 18 };

		//render::grad_rect(vec2_t(x - 1, y + 22), vec2_t(w + 1, h + i * 22), color(36, 36, 36, 255), color(26, 26, 26, 255));
		//render::draw_filled_rect(x - 1, y + 22, w + 1, h + i * 22, color(36, 36, 36));


		render::draw_filled_rect(control.x - 2, control.y - 2, control.w + 4, control.h + 4, color(4, 4, 4, 255));
		render::draw_filled_rect(control.x - 1, control.y - 1, control.w + 2, control.h + 2, color(60, 60, 60, 255));
		render::draw_filled_rect(control.x, control.y, control.w, control.h, color(36, 36, 36, 255));

		bool in_region2 = input::in_region(control.x, control.y, control.w, control.h);


		render::text(control.x + 4, control.y + 2, render::fonts::verdana, items[i], false, *v == i ? color(variables::menu::accent.r, variables::menu::accent.g, variables::menu::accent.b, 255) : color::white());


		if (*v == i)
		{
			render::draw_filled_rect(control.x, control.y, control.w, control.h, color(0, 0, 0, 35));
			render::draw_line(control.x, control.y + 4, control.x, control.y + 12, color(variables::menu::accent.r, variables::menu::accent.g, variables::menu::accent.b, 255));
		}
		else if (in_region2)
		{
			render::draw_filled_rect(control.x, control.y, control.w, control.h, color(0, 0, 0, 65));
		}


		if (input::key_clicked(VK_LBUTTON) && in_region2)
		{
			*v = i;
		}

		if (stage == 2)
		{
			if (input::key_clicked(VK_LBUTTON) && !in_region2)
			{
				stage = 0; /* reset */
				isComboOpen = false;
			}
		}
	}
}
@gr1ndy
Copy link

gr1ndy commented Jul 18, 2021

ss?

@float69
Copy link
Author

float69 commented Jul 18, 2021

ss?

it don't have an ss, but it makes it so if you press on the text, it activates the checkbox.

@st3ph4nnn
Copy link

st3ph4nnn commented Aug 11, 2021

the code here is for a combobox as i understand?
also just add the text size.x to the region so u can do what u said and ur gucci

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

3 participants