void scrollarea::consume_gui_event(event_info e) {
				if (!is_needed()) return;
				auto& gr = e.owner;
				auto& wnd = gr.state;
				if (e == gui_event::ldown && box) {
					gr.rect_held_by_lmb = box;
					if (flags & orientation::HORIZONTAL) {
						box->rc.center_x(wnd.mouse.pos.x - get_rect_absolute().l);
						update_scroll_x();
					}
					if (flags & orientation::VERTICAL) {
						box->rc.center_y(wnd.mouse.pos.y - get_rect_absolute().t);
						update_scroll_y();
					}
					box->rc_pos_before_dragging = vec2i(box->rc.l, box->rc.t);
				}
			}
Exemple #2
0
void item_button::draw_proc(draw_info in, bool draw_inside, bool draw_border, bool draw_connector, bool decrease_alpha, bool decrease_border_alpha, bool draw_container_opened_mark) {
	if (is_inventory_root())
		return;
	
	auto parent_slot = item->get<components::item>().current_slot;

	rgba inside_col = cyan;
	rgba border_col = cyan;

	if (parent_slot->for_categorized_items_only) {
		border_col = pink;
		inside_col = violet;
	}

	inside_col.a = 20;
	border_col.a = 190;

	if (detector.is_hovered) {
		inside_col.a = 30;
		border_col.a = 220;
	}

	if (detector.current_appearance == decltype(detector)::appearance::pushed) {
		inside_col.a = 60;
		border_col.a = 255;
	}

	if (decrease_alpha) {
		inside_col.a = 15;
	}

	if (decrease_border_alpha) {
		border_col = slightly_visible_white;
	}

	if (draw_inside) {
		draw_stretched_texture(in, augs::gui::material(assets::texture_id::BLANK, inside_col));

		iterate_children_attachments(true, &in.v, border_col);

		auto& item_data = item->get<components::item>();

		float bottom_number_val = -1.f;
		auto* container = item->find<components::container>();
		bool append_x = false;

		auto label_color = border_col;

		if (item_data.charges > 1) {
			bottom_number_val = item_data.charges;
			append_x = true;
		}
		else if (DRAW_FREE_SPACE_INSIDE_CONTAINER_ICONS && item[slot_function::ITEM_DEPOSIT].alive()) {
			bottom_number_val = item[slot_function::ITEM_DEPOSIT].calculate_free_space_with_parent_containers();

			if (item[slot_function::ITEM_DEPOSIT]->for_categorized_items_only)
				label_color.rgb() = pink.rgb();
			else
				label_color.rgb() = cyan.rgb();
		}

		if (bottom_number_val > -1.f) {
			std::wstring label_wstr;
			
			if (append_x) {
				label_wstr = L'x';
				label_wstr += augs::to_wstring(bottom_number_val);
			}
			else
				label_wstr = augs::to_wstring(bottom_number_val, 2);

			// else label_wstr = L'{' + label_wstr + L'}';

			auto bottom_number = augs::gui::text::format(label_wstr, augs::gui::text::style(assets::font_id::GUI_FONT, label_color));

			charges_caption.set_text(bottom_number);
			charges_caption.bottom_right(get_rect_absolute());
			charges_caption.draw(in);
		}
	}

	if (draw_border) {
		augs::gui::solid_stroke stroke;
		stroke.set_material(augs::gui::material(assets::texture_id::BLANK, border_col));
		stroke.draw(in.v, *this);
	}

	if (draw_connector && get_meta(parent_slot).gui_element_entity != parent_slot.container_entity) {
		draw_pixel_line_connector(get_rect_absolute(), get_meta(parent_slot.container_entity).get_rect_absolute(), in, border_col);
	}

	if (draw_container_opened_mark) {
		if (item->find<components::container>()) {
			components::sprite container_status_sprite;
			if(is_container_open)
				container_status_sprite.set(assets::CONTAINER_OPEN_ICON, border_col);
			else
				container_status_sprite.set(assets::CONTAINER_CLOSED_ICON, border_col);

			shared::state_for_drawing_renderable state;
			state.screen_space_mode = true;
			state.overridden_target_buffer = &in.v;
			state.renderable_transform.pos.set(get_rect_absolute().r - container_status_sprite.size.x + 2, get_rect_absolute().t + 1
				//- container_status_sprite.size.y + 2
				);
			container_status_sprite.draw(state);
		}
	}
}