Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions arcade/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ def configure_logging(level: Optional[int] = None):
from .draw_commands import draw_line_strip
from .draw_commands import draw_lines
from .draw_commands import draw_lrtb_rectangle_filled
from .draw_commands import draw_lrbt_rectangle_filled
from .draw_commands import draw_lrtb_rectangle_outline
from .draw_commands import draw_lrbt_rectangle_outline
from .draw_commands import draw_lrwh_rectangle_textured
from .draw_commands import draw_parabola_filled
from .draw_commands import draw_parabola_outline
Expand Down Expand Up @@ -301,7 +303,9 @@ def configure_logging(level: Optional[int] = None):
'draw_line_strip',
'draw_lines',
'draw_lrtb_rectangle_filled',
'draw_lrbt_rectangle_filled',
'draw_lrtb_rectangle_outline',
'draw_lrbt_rectangle_outline',
'draw_lrwh_rectangle_textured',
'draw_parabola_filled',
'draw_parabola_outline',
Expand Down
74 changes: 71 additions & 3 deletions arcade/draw_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
Texture,
get_window,
)
from arcade.utils import warning, ReplacementWarning

# --- BEGIN ARC FUNCTIONS # # #

Expand Down Expand Up @@ -617,11 +618,18 @@ def draw_triangle_outline(x1: float, y1: float,
# --- BEGIN RECTANGLE FUNCTIONS # # #


@warning(
warning_type=ReplacementWarning,
new_name="draw_lrbt_rectangle_outline"
)
def draw_lrtb_rectangle_outline(left: float, right: float, top: float,
bottom: float, color: Color,
border_width: float = 1):
"""
Draw a rectangle by specifying left, right, top, and bottom edges.
Draw a rectangle by specifying left, right, top and bottom edges.

.. deprecated:: 3.0
Use :py:func:`draw_lrbt_rectangle_outline` instead!

:param float left: The x coordinate of the left edge of the rectangle.
:param float right: The x coordinate of the right edge of the rectangle.
Expand All @@ -632,7 +640,6 @@ def draw_lrtb_rectangle_outline(left: float, right: float, top: float,
:Raises AttributeError: Raised if left > right or top < bottom.

"""

if left > right:
raise AttributeError("Left coordinate must be less than or equal to "
"the right coordinate")
Expand All @@ -649,6 +656,36 @@ def draw_lrtb_rectangle_outline(left: float, right: float, top: float,
border_width)


def draw_lrbt_rectangle_outline(left: float, right: float, bottom: float, top: float, color: Color,
border_width: float = 1):
"""
Draw a rectangle by specifying left, right, bottom and top edges.

:param float left: The x coordinate of the left edge of the rectangle.
:param float right: The x coordinate of the right edge of the rectangle.
:param float bottom: The y coordinate of the rectangle bottom.
:param float top: The y coordinate of the top of the rectangle.
:param Color color: The color of the rectangle.
:param float border_width: The width of the border in pixels. Defaults to one.
:Raises ValueError: Raised if left > right or top < bottom.

"""
if left > right:
raise ValueError("Left coordinate must be less than or equal to "
"the right coordinate")

if bottom > top:
raise ValueError("Bottom coordinate must be less than or equal to "
"the top coordinate")

center_x = (left + right) / 2
center_y = (top + bottom) / 2
width = right - left
height = top - bottom
draw_rectangle_outline(center_x, center_y, width, height, color,
border_width)


def draw_xywh_rectangle_outline(bottom_left_x: float, bottom_left_y: float,
width: float, height: float,
color: Color,
Expand Down Expand Up @@ -706,10 +743,17 @@ def draw_rectangle_outline(center_x: float, center_y: float, width: float,
_generic_draw_line_strip(point_list, color, gl.GL_TRIANGLE_STRIP)


@warning(
warning_type=ReplacementWarning,
new_name="draw_lrbt_rectangle_filled"
)
def draw_lrtb_rectangle_filled(left: float, right: float, top: float,
bottom: float, color: Color):
"""
Draw a rectangle by specifying left, right, top, and bottom edges.
Draw a rectangle by specifying left, right, top and bottom edges.

.. deprecated:: 3.0
Use :py:func:`draw_lrbt_rectangle_filled` instead!

:param float left: The x coordinate of the left edge of the rectangle.
:param float right: The x coordinate of the right edge of the rectangle.
Expand All @@ -731,6 +775,30 @@ def draw_lrtb_rectangle_filled(left: float, right: float, top: float,
draw_rectangle_filled(center_x, center_y, width, height, color)


def draw_lrbt_rectangle_filled(left: float, right: float, bottom: float, top: float, color: Color):
"""
Draw a rectangle by specifying left, right, bottom and top edges.

:param float left: The x coordinate of the left edge of the rectangle.
:param float right: The x coordinate of the right edge of the rectangle.
:param float bottom: The y coordinate of the rectangle bottom.
:param float top: The y coordinate of the top of the rectangle.
:param Color color: The color of the rectangle.
:Raises ValueError: Raised if left > right or top < bottom.
"""
if left > right:
raise ValueError(f"Left coordinate {left} must be less than or equal to the right coordinate {right}")

if bottom > top:
raise ValueError(f"Bottom coordinate {bottom} must be less than or equal to the top coordinate {top}")

center_x = (left + right) / 2
center_y = (top + bottom) / 2
width = right - left + 1
height = top - bottom + 1
draw_rectangle_filled(center_x, center_y, width, height, color)


def draw_xywh_rectangle_filled(bottom_left_x: float, bottom_left_y: float,
width: float, height: float,
color: Color):
Expand Down
2 changes: 1 addition & 1 deletion arcade/examples/net_process_animal_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def on_draw(self):
# Draw a progress bar to show how long until we request a new fact
progress = 1.0 - ((time.time() - self.last_updated) / self.update_interval)
if progress > 0:
arcade.draw_lrtb_rectangle_filled(
arcade.draw_lrbt_rectangle_filled(
left=0, right=self.window.width * progress,
bottom=0, top=20,
color=arcade.color.LIGHT_KHAKI
Expand Down
4 changes: 2 additions & 2 deletions arcade/examples/particle_fireworks.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,9 +340,9 @@ def on_draw(self):
self.clear()
for e in self.emitters:
e.draw()
arcade.draw_lrtb_rectangle_filled(0, SCREEN_WIDTH, 25, 0, arcade.color.DARK_GREEN)
arcade.draw_lrbt_rectangle_filled(0, SCREEN_WIDTH, 0, 25, arcade.color.DARK_GREEN)
mid = SCREEN_WIDTH / 2
arcade.draw_lrtb_rectangle_filled(mid - 2, mid + 2, SPINNER_HEIGHT, 10, arcade.color.DARK_BROWN)
arcade.draw_lrbt_rectangle_filled(mid - 2, mid + 2, 10, SPINNER_HEIGHT, arcade.color.DARK_BROWN)

def on_key_press(self, key, modifiers):
if key == arcade.key.ESCAPE:
Expand Down
4 changes: 2 additions & 2 deletions arcade/examples/sections_demo_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ def on_draw(self):
""" Draw this section """
if self.selected:
# Section is selected when mouse is within its boundaries
arcade.draw_lrtb_rectangle_filled(self.left, self.right, self.top,
self.bottom, arcade.color.GRAY)
arcade.draw_lrbt_rectangle_filled(self.left, self.right, self.bottom,
self.top, arcade.color.GRAY)
arcade.draw_text(f'You\'re are on the {self.name}', self.left + 30,
self.top - 50, arcade.color.BLACK, 16)

Expand Down
32 changes: 16 additions & 16 deletions arcade/examples/sections_demo_3.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ def __init__(self, left: int, bottom: int, width: int, height: int):

def on_draw(self):
# draw modal frame and button
arcade.draw_lrtb_rectangle_filled(self.left, self.right, self.top,
self.bottom, arcade.color.GRAY)
arcade.draw_lrtb_rectangle_outline(self.left, self.right, self.top,
self.bottom, arcade.color.WHITE)
arcade.draw_lrbt_rectangle_filled(self.left, self.right, self.bottom,
self.top, arcade.color.GRAY)
arcade.draw_lrbt_rectangle_outline(self.left, self.right, self.bottom,
self.top, arcade.color.WHITE)
self.draw_button()

def draw_button(self):
Expand Down Expand Up @@ -100,10 +100,10 @@ def ball(self):

def on_draw(self):
# draw game info
arcade.draw_lrtb_rectangle_filled(self.left, self.right, self.top,
self.bottom, COLOR_DARK)
arcade.draw_lrtb_rectangle_outline(self.left, self.right, self.top,
self.bottom, COLOR_LIGHT)
arcade.draw_lrbt_rectangle_filled(self.left, self.right, self.bottom,
self.top, COLOR_DARK)
arcade.draw_lrbt_rectangle_outline(self.left, self.right, self.bottom,
self.top, COLOR_LIGHT)
arcade.draw_text(f'Ball bounce count: {self.ball.bounce_count}',
self.left + 20, self.top - self.height / 1.6,
COLOR_LIGHT)
Expand Down Expand Up @@ -158,10 +158,10 @@ def draw_button_show_modal(self):
self.bottom + 95, COLOR_DARK, 10)

def on_draw(self):
arcade.draw_lrtb_rectangle_filled(self.left, self.right, self.top,
self.bottom, COLOR_DARK)
arcade.draw_lrtb_rectangle_outline(self.left, self.right, self.top,
self.bottom, COLOR_LIGHT)
arcade.draw_lrbt_rectangle_filled(self.left, self.right, self.bottom,
self.top, COLOR_DARK)
arcade.draw_lrbt_rectangle_outline(self.left, self.right, self.bottom,
self.top, COLOR_LIGHT)
self.draw_button_stop()
self.draw_button_toggle_info_bar()

Expand Down Expand Up @@ -234,10 +234,10 @@ def on_update(self, delta_time: float):
self.ball.bounce_count += 1

def on_draw(self):
arcade.draw_lrtb_rectangle_filled(self.left, self.right, self.top,
self.bottom, COLOR_DARK)
arcade.draw_lrtb_rectangle_outline(self.left, self.right, self.top,
self.bottom, COLOR_LIGHT)
arcade.draw_lrbt_rectangle_filled(self.left, self.right, self.bottom,
self.top, COLOR_DARK)
arcade.draw_lrbt_rectangle_outline(self.left, self.right, self.bottom,
self.top, COLOR_LIGHT)
self.sprite_list.draw()

def on_key_press(self, symbol: int, modifiers: int):
Expand Down
2 changes: 1 addition & 1 deletion arcade/examples/sprite_move_scrolling_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def on_draw(self):
right_boundary = self.width - VIEWPORT_MARGIN
top_boundary = self.height - VIEWPORT_MARGIN
bottom_boundary = VIEWPORT_MARGIN
arcade.draw_lrtb_rectangle_outline(left_boundary, right_boundary, top_boundary, bottom_boundary,
arcade.draw_lrbt_rectangle_outline(left_boundary, right_boundary, bottom_boundary, top_boundary,
arcade.color.RED, 2)

def on_key_press(self, key, modifiers):
Expand Down
4 changes: 2 additions & 2 deletions arcade/examples/view_pause_screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ def on_draw(self):
player_sprite.draw()

# draw an orange filter over him
arcade.draw_lrtb_rectangle_filled(left=player_sprite.left,
arcade.draw_lrbt_rectangle_filled(left=player_sprite.left,
right=player_sprite.right,
top=player_sprite.top,
bottom=player_sprite.bottom,
top=player_sprite.top,
color=arcade.color.ORANGE[:3] + (200,))

arcade.draw_text("PAUSED", WIDTH / 2, HEIGHT / 2 + 50,
Expand Down
2 changes: 1 addition & 1 deletion arcade/experimental/shapes_perf.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
# [x] draw_triangle_outline
# [x] draw_rectangle_outline
# [x] draw_xywh_rectangle_outline
# [x] draw_lrtb_rectangle_filled
# [x] draw_lrbt_rectangle_filled
# [x] draw_xywh_rectangle_filled
# [x] draw_rectangle_filled
# [x] draw_scaled_texture_rectangle
Expand Down
4 changes: 2 additions & 2 deletions arcade/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,10 +540,10 @@ def draw_debug(
bottom = self.bottom

# Draw background
arcade.draw_lrtb_rectangle_filled(left, right, top, bottom, color=background_color)
arcade.draw_lrbt_rectangle_filled(left, right, bottom, top, color=background_color)

# Draw outline
arcade.draw_lrtb_rectangle_outline(left, right, top, bottom, color=outline_color)
arcade.draw_lrbt_rectangle_outline(left, right, bottom, top, color=outline_color)

# Draw anchor
arcade.draw_point(self.x, self.y, color=anchor_color, size=6)
Expand Down
10 changes: 9 additions & 1 deletion arcade/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,16 @@ class PerformanceWarning(Warning):
pass


def warning(message: str, warning_type: Type[Warning]):
class ReplacementWarning(Warning):
"""Use this for issuing warnings about naming and functionality changes."""
pass


def warning(warning_type: Type[Warning], message: str = "", **kwargs):
def actual_warning_decorator(func):
nonlocal message
if warning_type == ReplacementWarning and not message:
message = f"{func.__name__} is deprecated. Use {kwargs.get('new_name', '')} instead."
@functools.wraps(func)
def wrapper(*args, **kwargs):
warnings.warn(message, warning_type)
Expand Down
2 changes: 1 addition & 1 deletion doc/tutorials/crt_filter/bloom_filter_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def on_draw(self):
self.bloom_filter.use()
self.bloom_filter.clear()
self.sprite_list.draw()
# arcade.draw_lrtb_rectangle_outline(0, self.width - 25, self.height - 5, 0, arcade.color.WHITE, 5)
# arcade.draw_lrbt_rectangle_outline(0, self.width - 25, 0, self.height - 5, arcade.color.WHITE, 5)

# Switch back to our window and draw the CRT filter do
# draw its stuff to the screen
Expand Down