mirror of
https://github.com/tonytins/CozyPixelStudio.git
synced 2025-12-19 04:04:43 -05:00
Var transparent mode (#444)
* allowed and enabled per_pixel_transparency * Added a Transparency menu * Added an Alternate screen for transparency * Added transparency methods Added the transparency methods plus modified fullscreen such that it resets transparency on toggling hence, Removing the issue of blackness * Modified the shader to allow transparency * Added a material to ViewportContainer Fixed the bug that darkens image when decreasing opacity * Update Global.gd * Update Main.gd * Update TopMenuContainer.gd
This commit is contained in:
parent
40f6a24fdc
commit
dc469dd4b5
7 changed files with 85 additions and 2 deletions
|
|
@ -3,7 +3,7 @@ extends Panel
|
|||
|
||||
enum FileMenuId {NEW, OPEN, OPEN_LAST_PROJECT, SAVE, SAVE_AS, EXPORT, EXPORT_AS, QUIT}
|
||||
enum EditMenuId {UNDO, REDO, COPY, CUT, PASTE, DELETE, CLEAR_SELECTION, PREFERENCES}
|
||||
enum ViewMenuId {TILE_MODE, MIRROR_VIEW, SHOW_GRID, SHOW_PIXEL_GRID, SHOW_RULERS, SHOW_GUIDES, SHOW_ANIMATION_TIMELINE, ZEN_MODE, FULLSCREEN_MODE}
|
||||
enum ViewMenuId {TILE_MODE, WINDOW_TRANSPARENCY, MIRROR_VIEW, SHOW_GRID, SHOW_PIXEL_GRID, SHOW_RULERS, SHOW_GUIDES, SHOW_ANIMATION_TIMELINE, ZEN_MODE, FULLSCREEN_MODE}
|
||||
enum ImageMenuId {SCALE_IMAGE,CENTRALIZE_IMAGE, CROP_IMAGE, RESIZE_CANVAS, FLIP, ROTATE, INVERT_COLORS, DESATURATION, OUTLINE, HSV, GRADIENT, SHADER}
|
||||
enum HelpMenuId {VIEW_SPLASH_SCREEN, ONLINE_DOCS, ISSUE_TRACKER, CHANGELOG, ABOUT_PIXELORAMA}
|
||||
|
||||
|
|
@ -82,6 +82,7 @@ func setup_edit_menu() -> void:
|
|||
func setup_view_menu() -> void:
|
||||
var view_menu_items := { # order as in ViewMenuId enum
|
||||
"Tile Mode" : 0,
|
||||
"Window Transparency" : 0,
|
||||
"Mirror View" : InputMap.get_action_list("mirror_view")[0].get_scancode_with_modifiers(),
|
||||
"Show Grid" : InputMap.get_action_list("show_grid")[0].get_scancode_with_modifiers(),
|
||||
"Show Pixel Grid" : InputMap.get_action_list("show_pixel_grid")[0].get_scancode_with_modifiers(),
|
||||
|
|
@ -97,6 +98,8 @@ func setup_view_menu() -> void:
|
|||
for item in view_menu_items.keys():
|
||||
if item == "Tile Mode":
|
||||
setup_tile_mode_submenu(item)
|
||||
elif item == "Window Transparency":
|
||||
setup_window_transparency_submenu(item)
|
||||
else:
|
||||
view_menu.add_check_item(item, i, view_menu_items[item])
|
||||
i += 1
|
||||
|
|
@ -113,6 +116,12 @@ func setup_tile_mode_submenu(item : String):
|
|||
view_menu.add_submenu_item(item, Global.tile_mode_submenu.get_name())
|
||||
|
||||
|
||||
func setup_window_transparency_submenu(item : String):
|
||||
Global.window_transparency_submenu.connect("id_pressed", self, "window_transparency_submenu_id_pressed")
|
||||
view_menu.add_child(Global.window_transparency_submenu)
|
||||
view_menu.add_submenu_item(item, Global.window_transparency_submenu.get_name())
|
||||
|
||||
|
||||
func setup_image_menu() -> void:
|
||||
var image_menu_items := { # order as in ImageMenuId enum
|
||||
"Scale Image" : 0,
|
||||
|
|
@ -292,6 +301,29 @@ func tile_mode_submenu_id_pressed(id : int) -> void:
|
|||
Global.canvas.grid.update()
|
||||
|
||||
|
||||
func window_transparency_submenu_id_pressed(id : float) -> void:
|
||||
if OS.window_fullscreen:
|
||||
for i in 11:
|
||||
Global.window_transparency_submenu.set_item_checked(i, i == 10)
|
||||
window_transparency(1)
|
||||
else:
|
||||
for i in 11:
|
||||
Global.window_transparency_submenu.set_item_checked(i, i == id)
|
||||
window_transparency(id/10)
|
||||
|
||||
|
||||
func window_transparency(value :float) -> void:
|
||||
if value == 1:
|
||||
get_node("../../AlternateTransparentBackground").visible = false
|
||||
else:
|
||||
get_node("../../AlternateTransparentBackground").visible = true
|
||||
var checker :ColorRect = get_parent().get_node("UI/CanvasAndTimeline/ViewportAndRulers/HSplitContainer/ViewportandVerticalRuler/ViewportContainer/Viewport/TransparentChecker")
|
||||
var color :Color = Global.control.theme.get_stylebox("panel", "PanelContainer").bg_color
|
||||
color.a = value
|
||||
get_node("../../AlternateTransparentBackground").color = color
|
||||
checker.transparency(value)
|
||||
|
||||
|
||||
func toggle_mirror_view() -> void:
|
||||
Global.mirror_view = !Global.mirror_view
|
||||
view_menu.set_item_checked(ViewMenuId.MIRROR_VIEW, Global.mirror_view)
|
||||
|
|
@ -350,6 +382,9 @@ func toggle_zen_mode() -> void:
|
|||
func toggle_fullscreen() -> void:
|
||||
OS.window_fullscreen = !OS.window_fullscreen
|
||||
view_menu.set_item_checked(ViewMenuId.FULLSCREEN_MODE, OS.window_fullscreen)
|
||||
# if window is fullscreen then reset transparency
|
||||
if OS.window_fullscreen:
|
||||
window_transparency_submenu_id_pressed(10)
|
||||
|
||||
|
||||
func image_menu_id_pressed(id : int) -> void:
|
||||
|
|
|
|||
|
|
@ -26,3 +26,18 @@ func _on_TransparentChecker_resized() -> void:
|
|||
func fit_rect(rect : Rect2) -> void:
|
||||
rect_position = rect.position
|
||||
rect_size = rect.size
|
||||
|
||||
|
||||
func transparency(value :float) -> void:
|
||||
# first make viewport transparent then background and then viewport
|
||||
if value == 1:
|
||||
get_parent().transparent_bg = false
|
||||
get_tree().get_root().set_transparent_background(false)
|
||||
else:
|
||||
OS.window_per_pixel_transparency_enabled = true
|
||||
get_parent().transparent_bg = true
|
||||
get_tree().get_root().set_transparent_background(true)
|
||||
|
||||
# this controls opacity 0 for transparent, 1 or a greater value than 1 is opaque
|
||||
# i have set a minimum amount for the fade (We would'nt want the canvas to dissapear now would we?)
|
||||
material.set("shader_param/alpha",clamp(value,0.1,1))
|
||||
|
|
|
|||
|
|
@ -1,5 +1,8 @@
|
|||
extends ViewportContainer
|
||||
|
||||
func _ready():
|
||||
material = CanvasItemMaterial.new()
|
||||
material.blend_mode = CanvasItemMaterial.BLEND_MODE_PREMULT_ALPHA
|
||||
|
||||
func _on_ViewportContainer_mouse_entered() -> void:
|
||||
Global.has_focus = true
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue