{"size": 1289, "ext": "js", "max_stars_repo_path": "src/js/modules/image/opacity.js", "max_stars_repo_name": "aliraffay/boota", "max_stars_repo_stars_event_min_datetime": "2015-01-04T10:09:19.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T15:36:34.000Z", "max_issues_repo_path": "src/js/modules/image/opacity.js", "max_issues_repo_name": "samwolf1982/miniPaint", "max_issues_repo_issues_event_min_datetime": "2015-01-03T15:47:03.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T02:37:45.000Z", "max_forks_repo_path": "src/js/modules/image/opacity.js", "max_forks_repo_name": "samwolf1982/miniPaint", "max_forks_repo_forks_event_min_datetime": "2015-01-01T23:00:54.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T10:47:00.000Z"}
{"max_stars_count": 1375, "max_issues_count": 228, "max_forks_count": 437, "avg_line_length": 22.6140350877, "max_line_length": 85, "alphanum_fraction": 0.6392552366}
import app from './../../app.js';
import config from './../../config.js';
import Dialog_class from './../../libs/popup.js';

class Image_opacity_class {

	constructor() {
		this.POP = new Dialog_class();
	}

	opacity() {
		var _this = this;
		var initial_opacity = config.layer.opacity;

		var settings = {
			title: 'Opacity',
			params: [
				{name: "opacity", title: "Alpha:", value: config.layer.opacity, range: [0, 100]},
			],
			on_change: function (params, canvas_preview, w, h) {
				_this.opacity_handler(params, false);
			},
			on_finish: function (params) {
				config.layer.opacity = initial_opacity;
				_this.opacity_handler(params);
			},
			on_cancel: function (params) {
				config.layer.opacity = initial_opacity;
				config.need_render = true;
			},
		};
		this.POP.show(settings);
	}

	opacity_handler(data, is_final = true) {
		var value = parseInt(data.opacity);
		if (value < 0)
			value = 0;
		if (value > 100)
			value = 100;
		if (is_final) {
			app.State.do_action(
				new app.Actions.Bundle_action('change_opacity', 'Change Opacity', [
					new app.Actions.Update_layer_action(config.layer.id, {
						opacity: value
					})
				])
			);
		} else {
			config.layer.opacity = value;
			config.need_render = true;
		}
	}
}

export default Image_opacity_class;
