Skip to content

Commit

Permalink
Merge pull request #3 from Qubus0/checkered_alpha_background
Browse files Browse the repository at this point in the history
feat(color preview): add checkered background if color has alpha
  • Loading branch information
Qubus0 authored Apr 30, 2022
2 parents b908ba3 + 77d758e commit 2487877
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 12 deletions.
24 changes: 19 additions & 5 deletions addons/ColorPreview/ColorPreview.gd
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ func gutter_draw_color_preview(line: int, gutter: int, area: Rect2) -> void:

# spacing the squares so they don't merge
var padding = size / 6
icon_region.position += Vector2(padding, padding)
icon_region.size -= Vector2(padding, padding) * 2
icon_region = icon_region.grow(-padding)

var icon_corner_region = PackedVector2Array([
icon_region.end,
icon_region.end + Vector2(-icon_region.size.x / 2, 0.0),
Expand All @@ -171,9 +171,23 @@ func gutter_draw_color_preview(line: int, gutter: int, area: Rect2) -> void:
var line_color = get_line_color(current_textedit, line)

# black is falsey, comparing to null allows us to preview it
if line_color != null:
if line_color is Color:
line_color = line_color as Color

if line_color.a < 1: # transparent -> add checkered bg + no-alpha corner
current_textedit.draw_rect(icon_region, Color.WHITE)
current_textedit.draw_rect( Rect2(
Vector2(icon_region.position.x + icon_region.size.x/2, icon_region.position.y),
icon_region.size/2
), Color.DIM_GRAY)
current_textedit.draw_rect( Rect2(
Vector2(icon_region.position.x, icon_region.position.y + icon_region.size.y/2),
icon_region.size/2
), Color.DIM_GRAY)

current_textedit.draw_colored_polygon(icon_corner_region, Color(line_color, 1.0))

current_textedit.draw_rect(icon_region, line_color)
current_textedit.draw_colored_polygon(icon_corner_region, Color(line_color, 1.0))
current_textedit.set_line_gutter_clickable(line, gutter_position, true)

if hovering:
Expand Down Expand Up @@ -213,7 +227,7 @@ func set_line_color(textedit: TextEdit, line: int, color = null) -> void:

func get_line_color(textedit: TextEdit, line: int):
var meta = textedit.get_line_gutter_metadata(line, gutter_position)
return meta if meta != null else null
return meta if meta is Color else null


### ### ### COLOR PICKER ### ### ###
Expand Down
11 changes: 6 additions & 5 deletions addons/ColorPreview/Picker.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene format=3 uid="uid://bd8slp7oko0my"]
[gd_scene format=3 uid="uid://dlhe1fiimv8if"]

[node name="Popup" type="Popup"]
size = Vector2i(465, 775)
Expand All @@ -8,10 +8,11 @@ content_scale_aspect = 1
content_scale_factor = 1.5

[node name="ColorPicker" type="ColorPicker" parent="."]
offset_left = 9.0
offset_top = 9.0
offset_right = 299.0
offset_bottom = 506.0
offset_left = 5.0
offset_top = 5.0
offset_right = 295.0
offset_bottom = 502.0
deferred_mode = true
__meta__ = {
"_edit_use_custom_anchors": false
}
4 changes: 2 additions & 2 deletions addons/ColorPreview/plugin.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

name="ColorPreview"
description="An Editor Plugin which lets you preview and adjust colors from code directly next to them"
author="Ste"
version="2.0"
author="Ste and Contributors"
version="2.1.0"
script="ColorPreview.gd"
Binary file modified colors.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 2487877

Please sign in to comment.