mirror of
https://github.com/Yonokid/PyTaiko.git
synced 2026-02-04 11:40:13 +01:00
modify outlinedtext drawing
This commit is contained in:
@@ -141,7 +141,7 @@ class Background:
|
||||
self.is_clear = gauge_1p.is_clear
|
||||
self.is_rainbow = gauge_1p.is_rainbow
|
||||
self.don_bg.update(current_time_ms, self.is_clear)
|
||||
if self.don_bg_2 is not None:
|
||||
if self.don_bg_2 is not None and gauge_2p is not None:
|
||||
self.don_bg_2.update(current_time_ms, gauge_2p.is_clear)
|
||||
if self.bg_normal is not None:
|
||||
self.bg_normal.update(current_time_ms)
|
||||
|
||||
@@ -20,7 +20,7 @@ class BaseFever:
|
||||
self.bounce_down.start()
|
||||
self.bounce_up.start()
|
||||
|
||||
def update(self, current_time_ms: int, bpm: float):
|
||||
def update(self, current_time_ms: float, bpm: float):
|
||||
self.bounce_up.update(current_time_ms)
|
||||
self.bounce_down.update(current_time_ms)
|
||||
if self.bounce_down.is_finished:
|
||||
|
||||
@@ -57,7 +57,6 @@ class SongBox:
|
||||
if audio.is_sound_playing(f'genre_voice_{i}'):
|
||||
audio.stop_sound(f'genre_voice_{i}')
|
||||
self.name = None
|
||||
self.black_name = None
|
||||
self.hori_name = None
|
||||
self.yellow_box = None
|
||||
self.open_anim = Animation.create_move(133, start_position=0, total_distance=150, delay=83.33)
|
||||
@@ -83,9 +82,6 @@ class SongBox:
|
||||
if self.box_texture is not None:
|
||||
ray.unload_texture(self.box_texture)
|
||||
self.box_texture = None
|
||||
if self.black_name is not None:
|
||||
self.black_name.unload()
|
||||
self.black_name = None
|
||||
if self.hori_name is not None:
|
||||
self.hori_name.unload()
|
||||
self.hori_name = None
|
||||
@@ -156,13 +152,11 @@ class SongBox:
|
||||
self.score_history = ScoreHistory(self.scores, get_current_ms())
|
||||
|
||||
if not is_open_prev and self.is_open:
|
||||
if self.black_name is None:
|
||||
self.black_name = OutlinedText(self.text_name, 40, ray.WHITE, ray.BLACK, outline_thickness=5, vertical=True)
|
||||
if self.tja is not None or self.is_back:
|
||||
self.yellow_box = YellowBox(self.black_name, self.is_back, tja=self.tja)
|
||||
self.yellow_box = YellowBox(self.name, self.is_back, tja=self.tja)
|
||||
self.yellow_box.create_anim()
|
||||
else:
|
||||
self.hori_name = OutlinedText(self.text_name, 40, ray.WHITE, ray.BLACK, outline_thickness=5)
|
||||
self.hori_name = OutlinedText(self.text_name, 40, ray.WHITE, outline_thickness=5)
|
||||
self.open_anim.start()
|
||||
self.open_fade.start()
|
||||
self.wait = get_current_ms()
|
||||
@@ -173,7 +167,7 @@ class SongBox:
|
||||
elif not self.is_open and is_open_prev and audio.is_sound_playing(f'genre_voice_{self.texture_index}'):
|
||||
audio.stop_sound(f'genre_voice_{self.texture_index}')
|
||||
if self.tja_count is not None and self.tja_count > 0 and self.tja_count_text is None:
|
||||
self.tja_count_text = OutlinedText(str(self.tja_count), 35, ray.WHITE, ray.BLACK, outline_thickness=5)#, horizontal_spacing=1.2)
|
||||
self.tja_count_text = OutlinedText(str(self.tja_count), 35, ray.WHITE, outline_thickness=5)#, horizontal_spacing=1.2)
|
||||
if self.box_texture is None and self.box_texture_path is not None:
|
||||
self.box_texture = ray.load_texture(self.box_texture_path)
|
||||
|
||||
@@ -181,7 +175,7 @@ class SongBox:
|
||||
self.open_fade.update(get_current_ms())
|
||||
|
||||
if self.name is None:
|
||||
self.name = OutlinedText(self.text_name, 40, ray.WHITE, SongBox.OUTLINE_MAP.get(self.name_texture_index, ray.Color(101, 0, 82, 255)), outline_thickness=5, vertical=True)
|
||||
self.name = OutlinedText(self.text_name, 40, ray.WHITE, outline_thickness=5, vertical=True)
|
||||
|
||||
if self.score_history is not None:
|
||||
self.score_history.update(get_current_ms())
|
||||
@@ -202,8 +196,7 @@ class SongBox:
|
||||
if self.is_back:
|
||||
tex.draw_texture('box', 'back_text', x=x, y=y)
|
||||
elif self.name is not None:
|
||||
dest = ray.Rectangle(x + 47 - int(self.name.texture.width / 2), y+35, self.name.texture.width, min(self.name.texture.height, 417))
|
||||
self.name.draw(self.name.default_src, dest, ray.Vector2(0, 0), 0, ray.WHITE)
|
||||
self.name.draw(outline_color=SongBox.OUTLINE_MAP.get(self.name_texture_index, ray.Color(101, 0, 82, 255)), x=x + 47 - int(self.name.texture.width / 2), y=y+35, y2=min(self.name.texture.height, 417)-self.name.texture.height)
|
||||
|
||||
if self.tja is not None and self.tja.ex_data.new:
|
||||
tex.draw_texture('yellow_box', 'ex_data_new_song_balloon', x=x, y=y)
|
||||
@@ -235,8 +228,7 @@ class SongBox:
|
||||
tex.draw_texture('box', 'folder_top', x=x, y=y - self.open_anim.attribute, color=color, frame=self.texture_index)
|
||||
tex.draw_texture('box', 'folder_top_edge', x=x+268, y=y - self.open_anim.attribute, color=color, frame=self.texture_index)
|
||||
dest_width = min(300, self.hori_name.texture.width)
|
||||
dest = ray.Rectangle((x + 48) - (dest_width//2), y + 107 - self.open_anim.attribute, dest_width, self.hori_name.texture.height)
|
||||
self.hori_name.draw(self.hori_name.default_src, dest, ray.Vector2(0, 0), 0, color)
|
||||
self.hori_name.draw(outline_color=ray.BLACK, x=(x + 48) - (dest_width//2), y=y + 107 - self.open_anim.attribute, x2=dest_width-self.hori_name.texture.width, color=color)
|
||||
|
||||
tex.draw_texture('box', 'folder_texture_left', frame=self.texture_index, x=x - self.open_anim.attribute)
|
||||
offset = 1 if self.texture_index == 3 or self.texture_index >= 9 and self.texture_index not in {10,11,12} else 0
|
||||
@@ -256,8 +248,7 @@ class SongBox:
|
||||
tex.draw_texture('yellow_box', 'song_count_num', color=color)
|
||||
tex.draw_texture('yellow_box', 'song_count_songs', color=color)
|
||||
dest_width = min(124, self.tja_count_text.texture.width)
|
||||
dest = ray.Rectangle(560 - (dest_width//2), 126, dest_width, self.tja_count_text.texture.height)
|
||||
self.tja_count_text.draw(self.tja_count_text.default_src, dest, ray.Vector2(0, 0), 0, color)
|
||||
self.tja_count_text.draw(outline_color=ray.BLACK, x=560 - (dest_width//2), y=126, x2=dest_width-self.tja_count_text.texture.width, color=color)
|
||||
if self.texture_index != 9:
|
||||
tex.draw_texture('box', 'folder_graphic', color=color, frame=self.texture_index)
|
||||
tex.draw_texture('box', 'folder_text', color=color, frame=self.texture_index)
|
||||
@@ -268,6 +259,7 @@ class SongBox:
|
||||
if self.is_open and get_current_ms() >= self.wait + 83.33:
|
||||
if self.score_history is not None and get_current_ms() >= self.history_wait + 3000:
|
||||
self.score_history.draw()
|
||||
|
||||
def draw(self, x: int, y: int, is_ura: bool, fade_override=None):
|
||||
if self.is_open and get_current_ms() >= self.wait + 83.33:
|
||||
if self.yellow_box is not None:
|
||||
@@ -288,7 +280,7 @@ class YellowBox:
|
||||
if self.tja is not None:
|
||||
subtitle_text = self.tja.metadata.subtitle.get(global_data.config['general']['language'], '')
|
||||
font_size = 30 if len(subtitle_text) < 30 else 20
|
||||
self.subtitle = OutlinedText(subtitle_text, font_size, ray.WHITE, ray.BLACK, outline_thickness=5, vertical=True)
|
||||
self.subtitle = OutlinedText(subtitle_text, font_size, ray.WHITE, outline_thickness=5, vertical=True)
|
||||
|
||||
self.left_out = tex.get_animation(9)
|
||||
self.right_out = tex.get_animation(10)
|
||||
@@ -458,13 +450,11 @@ class YellowBox:
|
||||
tex.draw_texture('box', 'back_text_highlight', x=x)
|
||||
elif self.name is not None:
|
||||
texture = self.name.texture
|
||||
dest = ray.Rectangle(x + 30, 35 + self.top_y_out.attribute, texture.width, min(texture.height, 417))
|
||||
self.name.draw(self.name.default_src, dest, ray.Vector2(0, 0), 0, ray.WHITE)
|
||||
self.name.draw(outline_color=ray.BLACK, x=x + 30, y=35 + self.top_y_out.attribute, y2=min(texture.height, 417)-texture.height, color=ray.WHITE)
|
||||
if self.subtitle is not None:
|
||||
texture = self.subtitle.texture
|
||||
y = self.bottom_y - min(texture.height, 410) + 10 + self.top_y_out.attribute - self.top_y_out.start_position
|
||||
dest = ray.Rectangle(x - 15, y, texture.width, min(texture.height, 410))
|
||||
self.subtitle.draw(self.subtitle.default_src, dest, ray.Vector2(0, 0), 0, ray.WHITE)
|
||||
self.subtitle.draw(outline_color=ray.BLACK, x=x-15, y=y, y2=min(texture.height, 410)-texture.height)
|
||||
|
||||
def _draw_yellow_box(self):
|
||||
tex.draw_texture('yellow_box', 'yellow_box_bottom_right', x=self.right_x)
|
||||
@@ -542,8 +532,7 @@ class GenreBG:
|
||||
tex.draw_texture('box', 'folder_background_folder_edge', x=((offset+dest_width)//2)+20, y=y-2, fade=self.fade_in.attribute, frame=self.end_box.texture_index)
|
||||
if self.diff_num is not None:
|
||||
tex.draw_texture('diff_sort', 'star_num', frame=self.diff_num, x=-150 + (dest_width//2), y=-143)
|
||||
dest = ray.Rectangle((1280//2) - (dest_width//2)-(offset//2), y-60, dest_width, self.title.texture.height)
|
||||
self.title.draw(self.title.default_src, dest, ray.Vector2(0, 0), 0, ray.fade(ray.WHITE, self.fade_in.attribute))
|
||||
self.title.draw(outline_color=ray.BLACK, x=(1280//2) - (dest_width//2)-(offset//2), y=y-60, x2=dest_width - self.title.texture.width, color=ray.fade(ray.WHITE, self.fade_in.attribute))
|
||||
|
||||
class ScoreHistory:
|
||||
"""The score information that appears while hovering over a song"""
|
||||
@@ -1042,7 +1031,7 @@ class FileNavigator:
|
||||
if selected_item.collection == Directory.COLLECTIONS[3]:
|
||||
diff_sort = self.diff_sort_level
|
||||
diffs = ['かんたん', 'ふつう', 'むずかしい', 'おに']
|
||||
hori_name = OutlinedText(diffs[min(3, self.diff_sort_diff)], 40, ray.WHITE, ray.BLACK, outline_thickness=5)
|
||||
hori_name = OutlinedText(diffs[min(3, self.diff_sort_diff)], 40, ray.WHITE, outline_thickness=5)
|
||||
self.genre_bg = GenreBG(start_box, end_box, hori_name, diff_sort)
|
||||
|
||||
def select_current_item(self):
|
||||
|
||||
@@ -17,8 +17,8 @@ class Nameplate:
|
||||
dan (int): The player's dan level.
|
||||
is_gold (bool): Whether the player's dan is gold.
|
||||
"""
|
||||
self.name = OutlinedText(name, 22, ray.WHITE, ray.BLACK, outline_thickness=3.0)
|
||||
self.title = OutlinedText(title, 20, ray.BLACK, ray.WHITE, outline_thickness=0)
|
||||
self.name = OutlinedText(name, 22, ray.WHITE, outline_thickness=3.0)
|
||||
self.title = OutlinedText(title, 20, ray.BLACK, outline_thickness=0)
|
||||
self.dan_index = dan
|
||||
self.player_num = player_num
|
||||
self.is_gold = is_gold
|
||||
@@ -64,10 +64,8 @@ class Nameplate:
|
||||
if self.player_num != -1:
|
||||
tex.draw_texture('nameplate', f'{self.player_num}p', x=x, y=y, fade=fade)
|
||||
|
||||
dest = ray.Rectangle(x+136 - (min(255 - offset*4, self.name.texture.width)//2) + offset, y+24, min(255 - offset*4, self.name.texture.width), self.name.texture.height)
|
||||
self.name.draw(self.name.default_src, dest, ray.Vector2(0, 0), 0, ray.fade(ray.WHITE, fade))
|
||||
dest = ray.Rectangle(x+136 - (min(255 - offset*2, self.title.texture.width)//2) + title_offset, y-3, min(255 - offset*2, self.title.texture.width), self.title.texture.height)
|
||||
self.title.draw(self.title.default_src, dest, ray.Vector2(0, 0), 0, ray.fade(ray.WHITE, fade))
|
||||
self.name.draw(outline_color=ray.BLACK, x=x+136 - (min(255 - offset*4, self.name.texture.width)//2) + offset, y=y+24, x2=min(255 - offset*4, self.name.texture.width)-self.name.texture.width, color=ray.fade(ray.WHITE, fade))
|
||||
self.title.draw(x=x+136 - (min(255 - offset*2, self.title.texture.width)//2) + title_offset, y=y-3, x2=min(255 - offset*2, self.title.texture.width)-self.title.texture.width, color=ray.fade(ray.WHITE, fade))
|
||||
|
||||
class Indicator:
|
||||
"""Indicator class for displaying drum navigation."""
|
||||
|
||||
@@ -519,8 +519,10 @@ class TJAParser:
|
||||
return
|
||||
|
||||
current_note = play_note_list[-1]
|
||||
if current_note.type in {1, 2}:
|
||||
current_note.moji = se_notes[current_note.type][0]
|
||||
if current_note.type == 1:
|
||||
current_note.moji = 0
|
||||
elif current_note.type == 2:
|
||||
current_note.moji = 3
|
||||
else:
|
||||
current_note.moji = se_notes[current_note.type]
|
||||
|
||||
|
||||
@@ -16,8 +16,8 @@ class Transition:
|
||||
self.chara_down = global_tex.get_animation(2)
|
||||
self.song_info_fade = global_tex.get_animation(3)
|
||||
self.song_info_fade_out = global_tex.get_animation(4)
|
||||
self.title = OutlinedText(title, 40, ray.WHITE, ray.BLACK, outline_thickness=5)
|
||||
self.subtitle = OutlinedText(subtitle, 30, ray.WHITE, ray.BLACK, outline_thickness=5)
|
||||
self.title = OutlinedText(title, 40, ray.WHITE)
|
||||
self.subtitle = OutlinedText(subtitle, 30, ray.WHITE)
|
||||
self.is_second = is_second
|
||||
|
||||
def start(self):
|
||||
@@ -48,13 +48,13 @@ class Transition:
|
||||
global_tex.draw_texture('rainbow_transition', 'text_bg', y=-self.rainbow_up.attribute - offset, color=color_2)
|
||||
|
||||
texture = self.title.texture
|
||||
y = 1176 - texture.height//2 - int(self.rainbow_up.attribute) - offset
|
||||
dest = ray.Rectangle(1280//2 - texture.width//2, y - 20, texture.width, texture.height)
|
||||
self.title.draw(self.title.default_src, dest, ray.Vector2(0, 0), 0, color_1)
|
||||
x = 1280//2 - texture.width//2
|
||||
y = 1176 - texture.height//2 - int(self.rainbow_up.attribute) - offset - 20
|
||||
self.title.draw(outline_color=ray.BLACK, x=x, y=y, color=color_1)
|
||||
|
||||
texture = self.subtitle.texture
|
||||
dest = ray.Rectangle(1280//2 - texture.width//2, y + 30, texture.width, texture.height)
|
||||
self.subtitle.draw(self.subtitle.default_src, dest, ray.Vector2(0, 0), 0, color_1)
|
||||
x = 1280//2 - texture.width//2
|
||||
self.subtitle.draw(outline_color=ray.BLACK, x=x, y=y + 30, color=color_1)
|
||||
|
||||
def draw(self):
|
||||
"""Draw the transition effect."""
|
||||
|
||||
@@ -262,7 +262,7 @@ for file in Path('cache/image').iterdir():
|
||||
|
||||
class OutlinedText:
|
||||
"""Create an outlined text object."""
|
||||
def __init__(self, text: str, font_size: int, color: ray.Color, outline_color: ray.Color, outline_thickness=5.0, vertical=False):
|
||||
def __init__(self, text: str, font_size: int, color: ray.Color, outline_thickness=5.0, vertical=False):
|
||||
"""
|
||||
Create an outlined text object.
|
||||
|
||||
@@ -286,30 +286,15 @@ class OutlinedText:
|
||||
else:
|
||||
self.texture = self._create_text_horizontal(text, font_size, color, ray.BLANK, self.font)
|
||||
outline_size = ray.ffi.new('float*', self.outline_thickness)
|
||||
if isinstance(outline_color, tuple):
|
||||
outline_color_alloc = ray.ffi.new("float[4]", [
|
||||
outline_color[0] / 255.0,
|
||||
outline_color[1] / 255.0,
|
||||
outline_color[2] / 255.0,
|
||||
outline_color[3] / 255.0
|
||||
])
|
||||
else:
|
||||
outline_color_alloc = ray.ffi.new("float[4]", [
|
||||
outline_color.r / 255.0,
|
||||
outline_color.g / 255.0,
|
||||
outline_color.b / 255.0,
|
||||
outline_color.a / 255.0
|
||||
])
|
||||
texture_size = ray.ffi.new("float[2]", [self.texture.width, self.texture.height])
|
||||
|
||||
self.shader = ray.load_shader('shader/outline.vs', 'shader/outline.fs')
|
||||
outline_size_loc = ray.get_shader_location(self.shader, "outlineSize")
|
||||
outline_color_loc = ray.get_shader_location(self.shader, "outlineColor")
|
||||
texture_size_loc = ray.get_shader_location(self.shader, "textureSize")
|
||||
self.outline_size_loc = ray.get_shader_location(self.shader, "outlineSize")
|
||||
self.outline_color_loc = ray.get_shader_location(self.shader, "outlineColor")
|
||||
self.texture_size_loc = ray.get_shader_location(self.shader, "textureSize")
|
||||
self.alpha_loc = ray.get_shader_location(self.shader, "alpha")
|
||||
ray.set_shader_value(self.shader, outline_size_loc, outline_size, SHADER_UNIFORM_FLOAT)
|
||||
ray.set_shader_value(self.shader, outline_color_loc, outline_color_alloc, SHADER_UNIFORM_VEC4)
|
||||
ray.set_shader_value(self.shader, texture_size_loc, texture_size, SHADER_UNIFORM_VEC2)
|
||||
ray.set_shader_value(self.shader, self.outline_size_loc, outline_size, SHADER_UNIFORM_FLOAT)
|
||||
ray.set_shader_value(self.shader, self.texture_size_loc, texture_size, SHADER_UNIFORM_VEC2)
|
||||
|
||||
self.default_src = ray.Rectangle(0, 0, self.texture.width, self.texture.height)
|
||||
|
||||
@@ -517,25 +502,50 @@ class OutlinedText:
|
||||
ray.unload_image(image)
|
||||
return texture
|
||||
|
||||
def draw(self, src: ray.Rectangle, dest: ray.Rectangle, origin: ray.Vector2, rotation: float, color: ray.Color):
|
||||
def draw(self, outline_color: ray.Color=ray.BLANK, color: ray.Color=ray.WHITE, scale: float = 1.0, center: bool = False,
|
||||
x: float = 0, y: float = 0, x2: float = 0, y2: float = 0,
|
||||
origin: ray.Vector2 = ray.Vector2(0,0), rotation: float = 0, fade: float = 1.1) -> None:
|
||||
"""
|
||||
Draw the outlined text object.
|
||||
|
||||
Args:
|
||||
src (ray.Rectangle): The source rectangle of the texture.
|
||||
dest (ray.Rectangle): The destination rectangle of the texture.
|
||||
origin (ray.Vector2): The origin of the texture.
|
||||
rotation (float): The rotation of the texture.
|
||||
color (ray.Color): The color of the text.
|
||||
Wrapper function for raylib's draw_texture_pro().
|
||||
Parameters:
|
||||
outline_color (ray.Color): The color to outline the text.
|
||||
color (ray.Color): The color to tint the text.
|
||||
x (float): An x-value added to the top-left corner of the text.
|
||||
y (float): The y-value added to the top-left corner of the text.
|
||||
x2 (float): The x-value added to the bottom-right corner of the text.
|
||||
y2 (float): The y-value added to the bottom-right corner of the text.
|
||||
origin (ray.Vector2): The origin point of the text.
|
||||
rotation (float): The rotation angle of the text.
|
||||
fade (float): The fade factor to apply to the text.
|
||||
"""
|
||||
if isinstance(outline_color, tuple):
|
||||
outline_color_alloc = ray.ffi.new("float[4]", [
|
||||
outline_color[0] / 255.0,
|
||||
outline_color[1] / 255.0,
|
||||
outline_color[2] / 255.0,
|
||||
outline_color[3] / 255.0
|
||||
])
|
||||
else:
|
||||
outline_color_alloc = ray.ffi.new("float[4]", [
|
||||
outline_color.r / 255.0,
|
||||
outline_color.g / 255.0,
|
||||
outline_color.b / 255.0,
|
||||
outline_color.a / 255.0
|
||||
])
|
||||
ray.set_shader_value(self.shader, self.outline_color_loc, outline_color_alloc, SHADER_UNIFORM_VEC4)
|
||||
if isinstance(color, tuple):
|
||||
alpha_value = ray.ffi.new('float*', color[3] / 255.0)
|
||||
else:
|
||||
alpha_value = ray.ffi.new('float*', color.a / 255.0)
|
||||
ray.set_shader_value(self.shader, self.alpha_loc, alpha_value, SHADER_UNIFORM_FLOAT)
|
||||
if fade != 1.1:
|
||||
final_color = ray.fade(color, fade)
|
||||
else:
|
||||
final_color = color
|
||||
dest_rect = ray.Rectangle(x, y, self.texture.width+x2, self.texture.height+y2)
|
||||
if self.outline_thickness > 0:
|
||||
ray.begin_shader_mode(self.shader)
|
||||
ray.draw_texture_pro(self.texture, src, dest, origin, rotation, color)
|
||||
ray.draw_texture_pro(self.texture, self.default_src, dest_rect, origin, rotation, final_color)
|
||||
if self.outline_thickness > 0:
|
||||
ray.end_shader_mode()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user