From 7b6c2f6c23a58be5401975ff67407133ae528ddf Mon Sep 17 00:00:00 2001 From: Eduardo Date: Wed, 27 Sep 2023 02:15:58 +0200 Subject: [PATCH] set shaders to move with the scroll of the list --- scenes/todo_list/ToDoList.gd | 7 +++++++ scenes/todo_list/ToDoList.tscn | 2 +- .../to-do_list_screen_lines.gdshader | 18 +++++++++++------- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/scenes/todo_list/ToDoList.gd b/scenes/todo_list/ToDoList.gd index 3af00dd..6518edd 100644 --- a/scenes/todo_list/ToDoList.gd +++ b/scenes/todo_list/ToDoList.gd @@ -2,6 +2,12 @@ extends Node signal scene_changed(scene_name) +@onready var background = $Background +@onready var scroll_container = $ScrollContainer + +func _process(_delta): + background.material.set_shader_parameter("position", scroll_container.scroll_vertical) + func _notification(what): if what == NOTIFICATION_WM_GO_BACK_REQUEST: _on_Back_pressed() @@ -19,3 +25,4 @@ func DEBUG_put_lots_of_tasks(how_many: int): func _on_ready(): DEBUG_put_lots_of_tasks(50) + diff --git a/scenes/todo_list/ToDoList.tscn b/scenes/todo_list/ToDoList.tscn index a26a38f..e0b3948 100644 --- a/scenes/todo_list/ToDoList.tscn +++ b/scenes/todo_list/ToDoList.tscn @@ -13,7 +13,7 @@ shader_parameter/line_width = 6.0 shader_parameter/interline_space = 100.0 shader_parameter/right_line_space = 150.0 shader_parameter/start_lines = 250.0 -shader_parameter/position = 0.07 +shader_parameter/position = 0.0 [node name="ToDoList" type="Node"] script = ExtResource("1_733o8") diff --git a/themes/default/backgrounds/to-do_list_screen_lines.gdshader b/themes/default/backgrounds/to-do_list_screen_lines.gdshader index 1af3b0a..74ce5ec 100644 --- a/themes/default/backgrounds/to-do_list_screen_lines.gdshader +++ b/themes/default/backgrounds/to-do_list_screen_lines.gdshader @@ -5,17 +5,21 @@ uniform float line_width = 6.0; uniform float interline_space = 100.0; uniform float right_line_space = 150.0; uniform float start_lines = 250.0; -uniform float position: hint_range(0.0, 1.0, 0.01) = .07; +uniform float position: hint_range(0.0, 1000, 1) = 0; void fragment() { - if(FRAGCOORD.y > start_lines) { - if(mod(FRAGCOORD.y + start_lines, interline_space) < line_width) { + float calc_start = position - start_lines; + + // dont draw at top + if (FRAGCOORD.y > calc_start * -1.) { + // draw horizontal lines + if (mod(FRAGCOORD.y + calc_start, interline_space) < line_width) { COLOR = line_color; } - if(FRAGCOORD.x > line_width) { - if(mod(FRAGCOORD.x, 1. / SCREEN_PIXEL_SIZE.x - right_line_space) < line_width) { - COLOR = line_color; - } + // draw the right vertical line + float c = 1. / SCREEN_PIXEL_SIZE.x - right_line_space; + if (c - line_width < FRAGCOORD.x && FRAGCOORD.x < c) { + COLOR = line_color; } } -- 2.30.2