From b26f794662a434319847857d079c0efddb3ed356 Mon Sep 17 00:00:00 2001 From: Wilson Silva Date: Thu, 26 Oct 2023 17:15:46 +0700 Subject: [PATCH] Replace Raylib.text_format with native string interpolation and formatting --- examples/audio/audio_mixed_processor-broken.rb | 2 +- examples/core/core_custom_frame_control.rb | 6 +++--- examples/core/core_input_gamepad.rb | 8 ++++---- examples/core/core_input_multitouch.rb | 4 +--- examples/core/core_random_values.rb | 2 +- examples/core/core_window_flags.rb | 2 +- examples/core/core_window_letterbox.rb | 4 ++-- examples/core/core_world_screen.rb | 2 +- examples/shapes/shapes_collision_area.rb | 2 +- examples/text/text_font_filters.rb | 4 ++-- examples/text/text_input_box.rb | 2 +- examples/textures/textures_bunnymark.rb | 4 ++-- examples/textures/textures_sprite_anim.rb | 2 +- 13 files changed, 21 insertions(+), 23 deletions(-) diff --git a/examples/audio/audio_mixed_processor-broken.rb b/examples/audio/audio_mixed_processor-broken.rb index dbbf98b..6a4ec1d 100644 --- a/examples/audio/audio_mixed_processor-broken.rb +++ b/examples/audio/audio_mixed_processor-broken.rb @@ -90,7 +90,7 @@ Raylib.clear_background(Raylib::RAYWHITE) Raylib.draw_text("MUSIC SHOULD BE PLAYING!", 255, 150, 20, Raylib::LIGHTGRAY) - Raylib.draw_text(Raylib.text_format("EXPONENT = %.2f", :float, $exponent), 215, 180, 20, Raylib::LIGHTGRAY) + Raylib.draw_text("EXPONENT = %.2f" % $exponent, 215, 180, 20, Raylib::LIGHTGRAY) Raylib.draw_rectangle(199, 199, 402, 34, Raylib::LIGHTGRAY) 400.times do |i| diff --git a/examples/core/core_custom_frame_control.rb b/examples/core/core_custom_frame_control.rb index 8c395ea..a5f7a57 100644 --- a/examples/core/core_custom_frame_control.rb +++ b/examples/core/core_custom_frame_control.rb @@ -82,13 +82,13 @@ Raylib.draw_circle(position.to_i, Raylib.get_screen_height / 2 - 25, 50, Raylib::RED) - Raylib.draw_text(Raylib.text_format("%03.0f ms", :double, time_counter * 1000.0), position.to_i - 40, Raylib.get_screen_height / 2 - 100, 20, Raylib::MAROON) - Raylib.draw_text(Raylib.text_format("PosX: %03.0f", :double, position), position.to_i - 50, Raylib.get_screen_height / 2 + 40, 20, Raylib::BLACK) + Raylib.draw_text("%03.0f ms" % (time_counter * 1000.0), position.to_i - 40, Raylib.get_screen_height / 2 - 100, 20, Raylib::MAROON) + Raylib.draw_text("PosX: %03.0f" % position, position.to_i - 50, Raylib.get_screen_height / 2 + 40, 20, Raylib::BLACK) Raylib.draw_text("Circle is moving at a constant 200 pixels/sec,\nindependently of the frame rate.", 10, 10, 20, Raylib::DARKGRAY) Raylib.draw_text("PRESS SPACE to PAUSE MOVEMENT", 10, Raylib.get_screen_height - 60, 20, Raylib::GRAY) Raylib.draw_text("PRESS UP | DOWN to CHANGE TARGET FPS", 10, Raylib.get_screen_height - 30, 20, Raylib::GRAY) - Raylib.draw_text(Raylib.text_format("TARGET FPS: %i", :int, target_fps), Raylib.get_screen_width - 220, 10, 20, Raylib::LIME) + Raylib.draw_text("TARGET FPS: #{target_fps}", Raylib.get_screen_width - 220, 10, 20, Raylib::LIME) # TODO: This is causing Infinity (FloatDomainError) error # Raylib.draw_text(Raylib.text_format("CURRENT FPS: %i", :int, (1.0 / delta_time).to_i), Raylib.get_screen_width - 220, 40, 20, Raylib::GREEN) diff --git a/examples/core/core_input_gamepad.rb b/examples/core/core_input_gamepad.rb index 7baae76..81c5ffa 100644 --- a/examples/core/core_input_gamepad.rb +++ b/examples/core/core_input_gamepad.rb @@ -51,7 +51,7 @@ Raylib.clear_background(Raylib::RAYWHITE) if Raylib.is_gamepad_available(0) - Raylib.draw_text(Raylib.text_format("GP1: %s", :string, Raylib.get_gamepad_name(0)), 10, 10, 10, Raylib::BLACK) + Raylib.draw_text("GP1: #{Raylib.get_gamepad_name(0)}", 10, 10, 10, Raylib::BLACK) # Implement drawing logic gamepad_name = Raylib.get_gamepad_name(0) @@ -170,18 +170,18 @@ end axis_count = Raylib.get_gamepad_axis_count(0) - Raylib.draw_text(Raylib.text_format("DETECTED AXIS [%i]:", :int, axis_count), 10, 50, 10, Raylib::MAROON) + Raylib.draw_text("DETECTED AXIS [#{axis_count}]:", 10, 50, 10, Raylib::MAROON) axis_count.times do |i| Raylib.draw_text( - Raylib.text_format("AXIS %i: %.02f", :int, i, :float, Raylib.get_gamepad_axis_movement(0, i)), 20, 70 + 20 * i, 10, Raylib::DARKGRAY + "AXIS %i: %.02f" % [i, Raylib.get_gamepad_axis_movement(0, i)], 20, 70 + 20 * i, 10, Raylib::DARKGRAY ) end detected_button = Raylib.get_gamepad_button_pressed if detected_button != Raylib::GAMEPAD_BUTTON_UNKNOWN - Raylib.draw_text(Raylib.text_format("DETECTED BUTTON: %i", :int, detected_button), 10, 430, 10, Raylib::RED) + Raylib.draw_text("DETECTED BUTTON: #{detected_button}", 10, 430, 10, Raylib::RED) else Raylib.draw_text("DETECTED BUTTON: NONE", 10, 430, 10, Raylib::GRAY) end diff --git a/examples/core/core_input_multitouch.rb b/examples/core/core_input_multitouch.rb index 2cdc182..30c98d3 100644 --- a/examples/core/core_input_multitouch.rb +++ b/examples/core/core_input_multitouch.rb @@ -51,9 +51,7 @@ touch_positions.each do |touch_position| if touch_position.x > 0 && touch_position.y > 0 Raylib.draw_circle_v(touch_position, 34, Raylib::ORANGE) - Raylib.draw_text( - Raylib.text_format("%d", :int, i), touch_position.x - 10, touch_position.y - 70, 40, Raylib::BLACK - ) + Raylib.draw_text(i.to_s, touch_position.x - 10, touch_position.y - 70, 40, Raylib::BLACK) end end diff --git a/examples/core/core_random_values.rb b/examples/core/core_random_values.rb index 5fc4384..8114ffc 100644 --- a/examples/core/core_random_values.rb +++ b/examples/core/core_random_values.rb @@ -48,7 +48,7 @@ Raylib.draw_text("Every 2 seconds a new random value is generated:", 130, 100, 20, Raylib::MAROON) - Raylib.draw_text(Raylib.text_format("%i", :int, rand_value), 360, 180, 80, Raylib::LIGHTGRAY) + Raylib.draw_text(rand_value.to_s, 360, 180, 80, Raylib::LIGHTGRAY) Raylib.end_drawing end diff --git a/examples/core/core_window_flags.rb b/examples/core/core_window_flags.rb index 75e184f..276cf54 100644 --- a/examples/core/core_window_flags.rb +++ b/examples/core/core_window_flags.rb @@ -163,7 +163,7 @@ def draw_window_flag_state(flag_name, flag_value, key, y_position) Raylib.draw_fps(10, 10) Raylib.draw_text( - Raylib.text_format("Screen Size: [%i, %i]", :int, Raylib.get_screen_width, :int, Raylib.get_screen_height), + "Screen Size: [#{Raylib.get_screen_width}, #{Raylib.get_screen_height}]", 10, 40, 10, diff --git a/examples/core/core_window_letterbox.rb b/examples/core/core_window_letterbox.rb index e79e1f0..d7f1be1 100644 --- a/examples/core/core_window_letterbox.rb +++ b/examples/core/core_window_letterbox.rb @@ -76,8 +76,8 @@ end Raylib.draw_text("If executed inside a window,\nyou can resize the window,\nand see the screen scaling!", 10, 25, 20, Raylib::WHITE) - Raylib.draw_text(Raylib.text_format("Default Mouse: [%i , %i]", :int, mouse.x.to_i, :int, mouse.y.to_i), 350, 25, 20, Raylib::GREEN) - Raylib.draw_text(Raylib.text_format("Virtual Mouse: [%i , %i]", :int, virtual_mouse.x.to_i, :int, virtual_mouse.y.to_i), 350, 55, 20, Raylib::YELLOW) + Raylib.draw_text("Default Mouse: [#{mouse.x.to_i} , #{mouse.y.to_i}]", 350, 25, 20, Raylib::GREEN) + Raylib.draw_text("Virtual Mouse: [#{virtual_mouse.x.to_i} , #{virtual_mouse.y.to_i}]", 350, 55, 20, Raylib::YELLOW) Raylib.end_texture_mode Raylib.begin_drawing diff --git a/examples/core/core_world_screen.rb b/examples/core/core_world_screen.rb index 7b30907..f3368f4 100644 --- a/examples/core/core_world_screen.rb +++ b/examples/core/core_world_screen.rb @@ -76,7 +76,7 @@ ) Raylib.draw_text( - Raylib.text_format("Cube position in screen space coordinates: [%i, %i]", :int, cube_screen_position.x, :int, cube_screen_position.y), + "Cube position in screen space coordinates: [#{cube_screen_position.x.to_i}, #{cube_screen_position.y.to_i}]", 10, 10, 20, diff --git a/examples/shapes/shapes_collision_area.rb b/examples/shapes/shapes_collision_area.rb index 82caad9..6f0000e 100644 --- a/examples/shapes/shapes_collision_area.rb +++ b/examples/shapes/shapes_collision_area.rb @@ -101,7 +101,7 @@ # Draw collision area Raylib.draw_text( - Raylib.text_format('Collision Area: %i', :int, box_collision.width * box_collision.height), + Raylib.text_format("Collision Area: #{(box_collision.width * box_collision.height).to}"), (Raylib.get_screen_width / 2) - 100, SCREEN_UPPER_LIMIT + 10, 20, Raylib::BLACK ) diff --git a/examples/text/text_font_filters.rb b/examples/text/text_font_filters.rb index fc624fb..1107570 100644 --- a/examples/text/text_font_filters.rb +++ b/examples/text/text_font_filters.rb @@ -98,8 +98,8 @@ Raylib.draw_text_ex(font, msg, font_position, font_size, 0, Raylib::BLACK) Raylib.draw_rectangle(0, SCREEN_HEIGHT - 80, SCREEN_WIDTH, 80, Raylib::LIGHTGRAY) - Raylib.draw_text(Raylib.text_format('Font size: %02.02f', :float, font_size), 20, SCREEN_HEIGHT - 50, 10, Raylib::DARKGRAY) - Raylib.draw_text(Raylib.text_format('Text size: [%02.02f, %02.02f]', :float, text_size.x, :float, text_size.y), 20, SCREEN_HEIGHT - 30, 10, Raylib::DARKGRAY) + Raylib.draw_text('Font size: %02.02f' % font_size, 20, SCREEN_HEIGHT - 50, 10, Raylib::DARKGRAY) + Raylib.draw_text('Text size: [%02.02f, %02.02f]' % [text_size.x, text_size.y], 20, SCREEN_HEIGHT - 30, 10, Raylib::DARKGRAY) Raylib.draw_text('CURRENT TEXTURE FILTER:', 250, 400, 20, Raylib::GRAY) case current_font_filter diff --git a/examples/text/text_input_box.rb b/examples/text/text_input_box.rb index cc18aae..40061b4 100644 --- a/examples/text/text_input_box.rb +++ b/examples/text/text_input_box.rb @@ -96,7 +96,7 @@ def is_any_key_pressed Raylib.draw_text(name, text_box.x.to_i + 5, text_box.y.to_i + 8, 40, Raylib::MAROON) - Raylib.draw_text(Raylib.text_format('INPUT CHARS: %i/%i', :int, letter_count, :int, MAX_INPUT_CHARS), 315, 250, 20, Raylib::DARKGRAY) + Raylib.draw_text("INPUT CHARS: #{letter_count}/#{MAX_INPUT_CHARS}", 315, 250, 20, Raylib::DARKGRAY) if mouse_on_text if letter_count < MAX_INPUT_CHARS diff --git a/examples/textures/textures_bunnymark.rb b/examples/textures/textures_bunnymark.rb index 95a9fd4..457219b 100644 --- a/examples/textures/textures_bunnymark.rb +++ b/examples/textures/textures_bunnymark.rb @@ -116,8 +116,8 @@ def self.create(position, speed, color) end Raylib.draw_rectangle(0, 0, SCREEN_WIDTH, 40, Raylib::BLACK) - Raylib.draw_text(Raylib.text_format('bunnies: %i', :int, bunnies_count), 120, 10, 20, Raylib::GREEN) - Raylib.draw_text(Raylib.text_format('batched draw calls: %i', :int, 1 + (bunnies_count / MAX_BATCH_ELEMENTS)), 320, 10, 20, Raylib::MAROON) + Raylib.draw_text("bunnies: #{bunnies_count}", 120, 10, 20, Raylib::GREEN) + Raylib.draw_text("batched draw calls: #{1 + (bunnies_count / MAX_BATCH_ELEMENTS)}", 320, 10, 20, Raylib::MAROON) Raylib.draw_fps(10, 10) Raylib.end_drawing diff --git a/examples/textures/textures_sprite_anim.rb b/examples/textures/textures_sprite_anim.rb index 0ca1ab1..a3c9949 100644 --- a/examples/textures/textures_sprite_anim.rb +++ b/examples/textures/textures_sprite_anim.rb @@ -71,7 +71,7 @@ ) Raylib.draw_text('FRAME SPEED: ', 165, 210, 10, Raylib::DARKGRAY) - Raylib.draw_text(Raylib.text_format('%02i FPS', :int, frames_speed), 575, 210, 10, Raylib::DARKGRAY) + Raylib.draw_text('%02i FPS' % frames_speed, 575, 210, 10, Raylib::DARKGRAY) Raylib.draw_text('PRESS RIGHT/LEFT KEYS to CHANGE SPEED!', 290, 240, 10, Raylib::DARKGRAY) MAX_FRAME_SPEED.times do |i|