Add a 'New' and 'Save As' button and improve save behaviour, additional minor improvements - fix #20
This commit is contained in:
parent
6b748229ed
commit
ca40971e53
7 changed files with 232 additions and 170 deletions
|
@ -1,12 +1,14 @@
|
|||
extends Control
|
||||
|
||||
@onready var code_editor = %CodeEdit
|
||||
|
||||
@onready var open_shader_dialog = %OpenShaderDialog
|
||||
@onready var save_shader_dialog = %SaveShaderDialog
|
||||
|
||||
@onready var image_viewport = %ImageViewport
|
||||
@onready var ui_control_filesave = %SaveImageDialog
|
||||
|
||||
@onready var image_viewport = get_tree().root.get_node("Main/%ImageViewport")
|
||||
@onready var camera = get_tree().root.get_node("Main/%Camera")
|
||||
|
||||
# # # # # # # # # # #
|
||||
# GDShader keywords #
|
||||
# https://github.com/godotengine/godot/blob/e96ad5af98547df71b50c4c4695ac348638113e0/servers/rendering/shader_language.cpp
|
||||
|
@ -183,28 +185,36 @@ func _input(event):
|
|||
func update():
|
||||
code_editor.text = Filesystem.shader.code
|
||||
|
||||
#
|
||||
|
||||
func _on_new_shader_button_pressed():
|
||||
Filesystem.reset()
|
||||
self.update()
|
||||
image_viewport.update()
|
||||
|
||||
func _on_open_shader_button_pressed():
|
||||
open_shader_dialog.show()
|
||||
|
||||
func _on_save_shader_button_pressed():
|
||||
Filesystem.shader.code = code_editor.text
|
||||
if Filesystem.last_shader_savepath == "":
|
||||
_on_save_shader_as_button_pressed()
|
||||
else:
|
||||
_on_save_shader_dialog_file_selected(Filesystem.last_shader_savepath)
|
||||
|
||||
func _on_save_shader_as_button_pressed() -> void:
|
||||
Filesystem.shader.code = code_editor.text
|
||||
if Filesystem.last_shader_savepath == "":
|
||||
save_shader_dialog.current_file = "filter.gdshader"
|
||||
else:
|
||||
save_shader_dialog.current_path = Filesystem.last_shader_savepath
|
||||
save_shader_dialog.show()
|
||||
|
||||
func _on_open_shader_dialog_file_selected(path: String):
|
||||
Filesystem.load_shader(path)
|
||||
image_viewport.update()
|
||||
self.update()
|
||||
|
||||
func _on_save_shader_dialog_file_selected(path):
|
||||
Filesystem.save_shader(path, code_editor.text)
|
||||
func _on_fit_image_button_pressed():
|
||||
camera.fit_image()
|
||||
|
||||
func _on_apply_shader_button_pressed():
|
||||
var shader = Shader.new()
|
||||
shader.code = code_editor.text
|
||||
Filesystem.shader = shader
|
||||
Filesystem.shader.code = code_editor.text
|
||||
image_viewport.update()
|
||||
|
||||
func _on_save_image_button_pressed():
|
||||
|
@ -212,5 +222,15 @@ func _on_save_image_button_pressed():
|
|||
ui_control_filesave.current_path = Filesystem.last_image_savepath
|
||||
ui_control_filesave.show()
|
||||
|
||||
#
|
||||
|
||||
func _on_open_shader_dialog_file_selected(path: String):
|
||||
Filesystem.load_shader(path)
|
||||
image_viewport.update()
|
||||
self.update()
|
||||
|
||||
func _on_save_shader_dialog_file_selected(path):
|
||||
Filesystem.save_shader(path)
|
||||
|
||||
func _on_save_image_dialog_file_selected(path):
|
||||
Filesystem.save_result(path)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
extends Node
|
||||
|
||||
@onready var shader: Shader = load("res://src/shader/template.gdshader")
|
||||
@onready var template_shader: Shader = load("res://src/shader/template.gdshader")
|
||||
@onready var shader: Shader = template_shader.duplicate()
|
||||
var original_image: ImageTexture
|
||||
var result: Image
|
||||
|
||||
|
@ -9,6 +10,14 @@ var last_image_savepath = ""
|
|||
var last_shader_savepath = ""
|
||||
var last_original_image_path = ""
|
||||
|
||||
func reset():
|
||||
self.shader = self.template_shader.duplicate()
|
||||
self.last_image_savepath = ""
|
||||
self.last_shader_savepath = ""
|
||||
self.last_original_image_path = ""
|
||||
self.original_image = null
|
||||
self.result = null
|
||||
|
||||
func get_absolute_path(p: String) -> String:
|
||||
# this only works on Linux!
|
||||
if !p.begins_with("/"):
|
||||
|
@ -50,10 +59,10 @@ func load_shader(path: String):
|
|||
self.cwd = path.substr(0, path.rfind("/"))
|
||||
self.last_shader_savepath = path
|
||||
|
||||
func save_shader(path: String, content: String):
|
||||
func save_shader(path: String):
|
||||
print("Save ", path)
|
||||
var file = FileAccess.open(path, FileAccess.WRITE)
|
||||
file.store_string(content)
|
||||
file.store_string(self.shader.code)
|
||||
if "/" in path: # update current working directory
|
||||
self.cwd = path.substr(0, path.rfind("/"))
|
||||
self.last_shader_savepath = path
|
||||
|
|
|
@ -15,6 +15,7 @@ func update():
|
|||
fit_image = true
|
||||
Filesystem.load_original_image(original_image_path)
|
||||
if Filesystem.original_image == null:
|
||||
image_viewport_display.hide()
|
||||
return
|
||||
image_sprite.texture = Filesystem.original_image
|
||||
image_sprite.offset = Filesystem.original_image.get_size() / 2
|
||||
|
|
|
@ -8,4 +8,6 @@ func _ready():
|
|||
editor_window.position.x + editor_window.size.x + 50,
|
||||
editor_window.position.y)
|
||||
get_window().title = ProjectSettings.get_setting("application/config/name") + " - Viewer"
|
||||
get_window().min_size = Vector2i(400, 400)
|
||||
editor_window.title = ProjectSettings.get_setting("application/config/name") + " - Editor"
|
||||
editor_window.min_size = Vector2i(560, 400)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue