Example #1
0
void LayersDialog::update(float elapsed_time) {
	if (layering() == NULL) return;


	vector< DialogBin > &bins = layering()->bins;
	float &dialog_tween = layering()->dialog_tween;
	dialog_tween += elapsed_time;
	if (dialog_tween > 1.0f) dialog_tween = 1.0f;
	for (unsigned int b = 0; b < bins.size(); ++b) {
		Box2f box = bins[b].get_box(dialog_tween);
		if (box.contains(mouse_pos)) {
			bins[b].arrows += elapsed_time * 4.0f;
			if (bins[b].arrows > 1.0f) bins[b].arrows = 1.0f;
		} else {
			bins[b].arrows -= elapsed_time * 1.5f;
			if (bins[b].arrows < 0.0f) bins[b].arrows = 0.0f;
		}
		Box2f tex = bins[b].get_tex_box(dialog_tween);
		if (tex.contains(mouse_pos)) {
			bins[b].zoom_out += elapsed_time * 3.0f;
			if (bins[b].zoom_out > 1.0f) bins[b].zoom_out = 1.0f;
		} else {
			bins[b].zoom_out -= elapsed_time * 3.0f;
			if (bins[b].zoom_out < 0.0f) bins[b].zoom_out = 0.0f;
		}
	}
}
Example #2
0
bool LayersDialog::handle_event(SDL_Event const &event, Vector2f local_mouse) {
	mouse_pos = local_mouse;
	if (layering() == NULL) return false;

	if (event.type == SDL_MOUSEBUTTONDOWN) {
		vector< DialogBin > const &bins = layering()->bins;
		ListGraph &stacking = layering()->stacking;
		const float dialog_tween = layering()->dialog_tween;
		const vector< vector< uint32_t > > &layers = layering()->layers;
		const Vector2ui dialog_point = layering()->dialog_point;
		const vector< uint32_t > &tags = layering()->tags;
		const unsigned int width = layering()->width;
		const unsigned int height = layering()->height;
		for (unsigned int b = 0; b < bins.size(); ++b) {
			Box2f box = bins[b].get_box(dialog_tween);
			if (box.contains(local_mouse)) {
				if (bins[b].layer >= layers.size()) continue;
				bool up = local_mouse.y > box.center().y;
				if (dialog_point.x < width && dialog_point.y < height && tags.size() == width * height) {
					unsigned int t = tags[dialog_point.y * width + dialog_point.x];
					assert(t < stacking.lists.size());
					for (unsigned int i = 0; i < stacking.lists[t].size(); ++i) {
						if (stacking.lists[t][i] == bins[b].layer) {
							if (up && i + 1 < stacking.lists[t].size()) {
								stacking.flip_rel(t, bins[b].layer, stacking.lists[t][i+1], true);
								layering()->update_image();
							}
							if (!up && i - 1 < stacking.lists[t].size()) {
								stacking.flip_rel(t, bins[b].layer, stacking.lists[t][i-1], false);
								layering()->update_image();
							}
							break;
						}
					}
				}
				return true;
			}
		}
	}
	return false;
}