set(IMG_SOURCE_animate_mode_off_icon animate_mode_icons 0)
set(IMG_SOURCE_animate_mode_on_icon animate_mode_icons 1)

set(IMG_SOURCE_interpolation_type_tcb_icon interpolation_type_icons 1)
set(IMG_SOURCE_interpolation_type_linear_icon interpolation_type_icons 2)
set(IMG_SOURCE_interpolation_type_ease_icon interpolation_type_icons 3)
set(IMG_SOURCE_interpolation_type_const_icon interpolation_type_icons 4)
set(IMG_SOURCE_interpolation_type_clamped_icon interpolation_type_icons 5)
# set(IMG_SOURCE_interpolation_type_unknown_icon interpolation_type_icons 6)
set(IMG_SOURCE_valuenode_forbidanimation_icon interpolation_type_icons 7)

set(IMG_SOURCE_action_doc_new_icon action_doc_icons 1)
set(IMG_SOURCE_action_doc_open_icon action_doc_icons 2)
set(IMG_SOURCE_action_doc_save_icon action_doc_icons 3)
set(IMG_SOURCE_action_doc_saveas_icon action_doc_icons 4)
set(IMG_SOURCE_action_doc_saveall_icon action_doc_icons 5)
set(IMG_SOURCE_action_doc_undo_icon action_doc_icons 6)
set(IMG_SOURCE_action_doc_redo_icon action_doc_icons 7)

set(IMG_SOURCE_canvas_icon canvas_and_importimage_icons 2)
set(IMG_SOURCE_layer_other_importimage_icon canvas_and_importimage_icons 1)

set(IMG_SOURCE_animate_seek_next_keyframe_icon framedial_icons 0)
set(IMG_SOURCE_animate_seek_prev_keyframe_icon framedial_icons 1)
set(IMG_SOURCE_animate_seek_next_frame_icon framedial_icons 2)
set(IMG_SOURCE_animate_seek_prev_frame_icon framedial_icons 3)
set(IMG_SOURCE_animate_seek_begin_icon framedial_icons 4)
set(IMG_SOURCE_animate_seek_end_icon framedial_icons 5)
set(IMG_SOURCE_animate_play_icon framedial_icons 6)
set(IMG_SOURCE_animate_stop_icon framedial_icons 7)
set(IMG_SOURCE_animate_pause_icon framedial_icons 8)
set(IMG_SOURCE_animate_loop_icon framedial_icons 9)
set(IMG_SOURCE_animate_bounds_icon framedial_icons 10)
set(IMG_SOURCE_animate_bound_lower_icon framedial_icons 11)
set(IMG_SOURCE_animate_bound_upper_icon framedial_icons 12)

set(IMG_SOURCE_keyframe_lock_past_on_icon keyframe_lock_icons 0)
set(IMG_SOURCE_keyframe_lock_past_off_icon keyframe_lock_icons 1)
set(IMG_SOURCE_keyframe_lock_future_on_icon keyframe_lock_icons 2)
set(IMG_SOURCE_keyframe_lock_future_off_icon keyframe_lock_icons 3)

set(IMG_SOURCE_utils_chain_link_on_icon utils_chain_link_icons 0)
set(IMG_SOURCE_utils_chain_link_off_icon utils_chain_link_icons 1)

set(ICONS
	animate_mode_off_icon
	animate_mode_on_icon

	interpolation_type_tcb_icon
	interpolation_type_linear_icon
	interpolation_type_ease_icon
	interpolation_type_const_icon
	interpolation_type_clamped_icon
	valuenode_forbidanimation_icon

	action_doc_new_icon
	action_doc_open_icon
	action_doc_save_icon
	action_doc_saveas_icon
	action_doc_saveall_icon
	action_doc_undo_icon
	action_doc_redo_icon

	canvas_icon

	animate_seek_next_keyframe_icon
	animate_seek_prev_keyframe_icon
	animate_seek_next_frame_icon
	animate_seek_prev_frame_icon
	animate_seek_end_icon
	animate_seek_begin_icon
	animate_play_icon
	animate_stop_icon
	animate_pause_icon
	animate_loop_icon
	animate_bounds_icon
	animate_bound_lower_icon
	animate_bound_upper_icon

	keyframe_lock_past_on_icon
	keyframe_lock_past_off_icon
	keyframe_lock_future_on_icon
	keyframe_lock_future_off_icon

	utils_chain_link_on_icon
	utils_chain_link_off_icon

	action_add_to_set_icon
	action_export_icon
	action_flat_interpolation_icon
	action_interpolate_interpolation_icon
	action_peak_interpolation_icon
	action_remove_from_set_icon
	action_rounded_interpolation_icon
	action_set_layer_description_icon
	action_squared_interpolation_icon
	action_unexport_icon
	clear_redo_icon
	clear_undo_icon
	decr_resolution_icon
	duck_angle_icon
	duck_position_icon
	duck_radius_icon
	duck_tangent_icon
	duck_vertex_icon
	duck_width_icon
	duplicate_icon
	graphs_icon
	group_icon
	history_icon
	incr_resolution_icon
	info_icon
	jack_icon
	keyframe_icon
	layer_blur_blur_icon
	layer_blur_motion_icon
	layer_blur_radial_icon
	layer_distortion_curvewarp_icon
	layer_distortion_insideout_icon
	layer_distortion_noise_icon
	layer_distortion_spherize_icon
	layer_distortion_stretch_icon
	layer_distortion_twirl_icon
	layer_distortion_warp_icon
	layer_example_metaballs_icon
	layer_example_simplecircle_icon
	layer_filter_clamp_icon
	layer_filter_colorcorrect_icon
	layer_filter_halftone2_icon
	layer_filter_halftone3_icon
	layer_filter_lumakey_icon
	layer_fractal_julia_icon
	layer_fractal_mandelbrot_icon
	layer_geometry_advanced_outline_icon
	layer_geometry_checkerboard_icon
	layer_geometry_circle_icon
	layer_geometry_outline_icon
	layer_geometry_polygon_icon
	layer_geometry_rectangle_icon
	layer_geometry_region_icon
	layer_geometry_solidcolor_icon
	layer_geometry_star_icon
	layer_gradient_conical_icon
	layer_gradient_curve_icon
	layer_gradient_linear_icon
	layer_gradient_noise_icon
	layer_gradient_radial_icon
	layer_gradient_spiral_icon
	layer_icon
	layer_other_duplicate_icon
	layer_other_group_icon
	layer_other_importimage_icon
	layer_other_plant_icon
	layer_other_skeleton_icon
	layer_other_sound_icon
	layer_other_stroboscope_icon
	layer_other_supersample_icon
	layer_other_switch_icon
	layer_other_text_icon
	layer_other_timeloop_icon
	layer_other_xorpattern_icon
	layer_stylize_bevel_icon
	layer_stylize_shade_icon
	layer_transform_rotate_icon
	layer_transform_scale_icon
	layer_transform_translate_icon
	layer_transform_zoom_icon
	library_icon
	meta_data_icon
	navigator_icon
	onion_skin_icon
	palette_icon
	parameters_icon
	preview_options_icon
	background_rendering_icon
	rename_icon
	render_options_icon
	reset_colors_icon
	resize_disabled_icon
	resize_up_left_icon
	resize_up_icon
	resize_up_right_icon
	resize_left_icon
	resize_right_icon
	resize_down_left_icon
	resize_down_icon
	resize_down_right_icon
	resize_transparent_icon
	select_all_child_layers_icon
	set_fill_color
	set_icon
	set_outline_color
	show_grid_icon
	show_guideline_icon
	sif_icon
	snap_grid_icon
	snap_guideline_icon
	swap_colors_icon
	time_track_icon
	tool_brush_icon
	tool_circle_icon
	tool_cutout_icon
	tool_draw_icon
	tool_eyedrop_icon
	tool_fill_icon
	tool_gradient_icon
	tool_mirror_icon
	tool_normal_icon
	tool_polyline_icon
	tool_rectangle_icon
	tool_rotate_icon
	tool_scale_icon
	tool_sketch_icon
	tool_smooth_move_icon
	tool_spline_icon
	tool_skeleton_icon
	tool_star_icon
	tool_text_icon
	tool_width_icon
	tool_zoom_icon
	type_angle_icon
	type_bool_icon
	type_canvas_icon
	type_color_icon
	type_gradient_icon
	type_integer_icon
	type_list_icon
	type_real_icon
	type_segment_icon
	type_splinepoint_icon
	type_string_icon
	type_time_icon
	type_vector_icon
	utils_timetrack_align_icon
	valuenode_icon
)

set(IMAGES
	about_icon
	logo
	synfig_icon
	${ICONS}
)

set(PIXMAPS_DIR ${SYNFIG_BUILD_ROOT}/share/synfig/icons/classic)

file(MAKE_DIRECTORY ${PIXMAPS_DIR})

## TODO: configure icon size
#
# Implement icon sizes after Synfig Studio uses Gtk::IconTheme
# For now just render to the default document size like Autotools does
#
# Note to protential future contributors:
# Not all icons are of aspect 1:1, eg- toggle button chain link
# so the below code is faulty and needs to be corrected
#
#foreach (ICON IN ITEMS ${ICONS})
#	set(IMG_SIZE_${ICON} 32 32)
#endforeach()

foreach (IMAGE IN ITEMS ${IMAGES})
	if (IMG_SOURCE_${IMAGE})
		list(GET IMG_SOURCE_${IMAGE} 0 SRC)
		list(GET IMG_SOURCE_${IMAGE} 1 TIME)
	else()
		set(SRC ${IMAGE})
		set(TIME 0)
	endif()
	# Wait for Gtk::IconTheme
#	if (IMG_SIZE_${IMAGE})
#		list(GET IMG_SIZE_${IMAGE} 0 W)
#		list(GET IMG_SIZE_${IMAGE} 1 H)
#	else()
#		set(W 0)
#		set(H 0)
#	endif()
	add_custom_command(
		OUTPUT ${PIXMAPS_DIR}/${IMAGE}.png
		# Wait for Gtk::IconTheme
#		COMMAND synfig_bin ${SRC}.sif -o ${PIXMAPS_DIR}/${IMAGE}.png --time ${TIME}f -w ${W} -h ${H} --quiet
		COMMAND synfig_bin ${SRC}.sif -o ${PIXMAPS_DIR}/${IMAGE}.png --time ${TIME}f --quiet
		WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
		DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${SRC}.sif synfig_bin
	)

	list(APPEND PIXMAPS ${PIXMAPS_DIR}/${IMAGE}.png)
	install(
		FILES ${PIXMAPS_DIR}/${IMAGE}.png
		DESTINATION share/synfig/icons/classic
	)
endforeach()

# Scalable Icon
file(
	COPY ${CMAKE_CURRENT_SOURCE_DIR}/org.synfig.SynfigStudio.svg
	DESTINATION ${SYNFIG_BUILD_ROOT}/share/icons/hicolor/scalable/apps
)

install(
	FILES ${CMAKE_CURRENT_SOURCE_DIR}/org.synfig.SynfigStudio.svg
	DESTINATION share/icons/hicolor/scalable/apps
)

# Synfig Splash Screen
if(${CMAKE_BUILD_TYPE} MATCHES Debug)
	set(SYNFIG_SPLASH_SCREEN ${CMAKE_CURRENT_BINARY_DIR}/splash_screen_development.sif)
	configure_file(
		${CMAKE_CURRENT_SOURCE_DIR}/splash_screen_development.sif.in
		${SYNFIG_SPLASH_SCREEN}
		@ONLY
	)

	set(LOGO_ICON ${CMAKE_CURRENT_SOURCE_DIR}/logo.sif)
	file(COPY ${LOGO_ICON} DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
else()
	set(SYNFIG_SPLASH_SCREEN ${CMAKE_CURRENT_SOURCE_DIR}/splash_screen.sif)
endif()

set(SPLASH_SCREEN_DIR ${SYNFIG_BUILD_ROOT}/share/synfig/images)
file(MAKE_DIRECTORY ${SPLASH_SCREEN_DIR})
add_custom_command(
	OUTPUT ${SPLASH_SCREEN_DIR}/splash_screen.png
	COMMAND synfig_bin ${SYNFIG_SPLASH_SCREEN} -o ${SPLASH_SCREEN_DIR}/splash_screen.png --time 0f --quiet
	DEPENDS ${SYNFIG_SPLASH_SCREEN} synfig_bin
)

list(APPEND PIXMAPS ${SPLASH_SCREEN_DIR}/splash_screen.png)
install(
	FILES ${SPLASH_SCREEN_DIR}/splash_screen.png
	DESTINATION share/synfig/images
)

# WIN32 Icon
if(WIN32)
	add_custom_command(
		OUTPUT ${PIXMAPS_DIR}/synfig_icon.ico
		COMMAND synfig_bin ${CMAKE_CURRENT_SOURCE_DIR}/synfig_icon.sif -o ${PIXMAPS_DIR}/synfig_icon.ico --time 0f --quiet
		DEPENDS ${SYNFIG_SPLASH_SCREEN} synfig_bin
	)

	list(APPEND PIXMAPS ${PIXMAPS_DIR}/synfig_icon.ico)
	install(
		FILES ${PIXMAPS_DIR}/synfig_icon.ico
		DESTINATION share/pixmaps/synfigstudio
	)
endif()

add_custom_target(
	build_images
	DEPENDS synfig_bin ${PIXMAPS}
)
