From cc55fa7836a5abc8a31b4944c9c9537b042de5b5 Mon Sep 17 00:00:00 2001 From: Tyrone Slothrop Date: Sat, 25 Jun 2022 16:22:39 +0100 Subject: [PATCH] Create shapes_draw_rounded_rectangle.py Port shapes_draw_rounded_reactangle example. --- .../shapes/shapes_draw_rounded_rectangle.py | 85 +++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 examples/shapes/shapes_draw_rounded_rectangle.py diff --git a/examples/shapes/shapes_draw_rounded_rectangle.py b/examples/shapes/shapes_draw_rounded_rectangle.py new file mode 100644 index 0000000..ab948c8 --- /dev/null +++ b/examples/shapes/shapes_draw_rounded_rectangle.py @@ -0,0 +1,85 @@ +#/******************************************************************************************* +#* +#* raylib [shapes] example - draw rectangle rounded (with gui options) +#* +#* This example has been created using raylib 2.5 (www.raylib.com) +#* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) +#* +#* Example contributed by Vlad Adrian (@demizdor) and reviewed by Ramon Santamaria (@raysan5) +#* +#* Copyright (c) 2018 Vlad Adrian (@demizdor) and Ramon Santamaria (@raysan5) +#* +#********************************************************************************************/ + +import pyray +from raylib.colors import ( + RAYWHITE, + LIGHTGRAY, + DARKGRAY, + GOLD, + MAROON, +) + +#// Initialization +#//-------------------------------------------------------------------------------------- +SCREEN_WIDTH = 800 +SCREEN_HEIGHT = 450 + +pyray.init_window(SCREEN_WIDTH, SCREEN_HEIGHT, "raylib [shapes] example - draw rectangle rounded") + +roundness = 0.2 +width = 200 +height = 100 +segments = 0 +lineThick = 1 + +drawRect = False +drawRoundedRect = True +drawRoundedLines = False + +pyray.set_target_fps(60) #// Set our game to run at 60 frames-per-second +#//-------------------------------------------------------------------------------------- + +#// Main game loop +while not pyray.window_should_close(): #// Detect window close button or ESC key + + #// Update + #//---------------------------------------------------------------------------------- + rec = pyray.Rectangle( (pyray.get_screen_width()-width-250)/2, (pyray.get_screen_height()-height)/2, width, height ) + #//---------------------------------------------------------------------------------- + + #// Draw + #//---------------------------------------------------------------------------------- + pyray.begin_drawing() + pyray.clear_background(RAYWHITE) + + pyray.draw_line(560,0,560,pyray.get_screen_height(),pyray.fade(LIGHTGRAY,0.6)) + pyray.draw_rectangle(560,0,pyray.get_screen_width()-500,pyray.get_screen_height(),pyray.fade(LIGHTGRAY,0.3)) + + if drawRect: + pyray.draw_rectangle_rec(rec,pyray.fade(GOLD,0.6)) + if drawRoundedRect: + pyray.draw_rectangle_rounded(rec,roundness,segments,pyray.fade(MAROON,0.2)) + if drawRoundedLines: + pyray.draw_rectangle_rounded_lines(rec,roundness,segments,lineThick,pyray.fade(MAROON,0.4)) + + #// Draw GUI controls + #//------------------------------------------------------------------------------ + width = int( pyray.gui_slider_bar(pyray.Rectangle(640,40,105,20),"Width",0,width,0,pyray.get_screen_width()-300) ) + height = int( pyray.gui_slider_bar(pyray.Rectangle(640,70,105,20),"Height",0,height,0,pyray.get_screen_height()-50) ) + roundness = pyray.gui_slider_bar(pyray.Rectangle(640,140,105,20),"Roundness",0,roundness,0,1) + lineThick = int( pyray.gui_slider_bar(pyray.Rectangle(640,170,105,20),"Thickness",0,lineThick,0,20) ) + segments = int( pyray.gui_slider_bar(pyray.Rectangle(640,240,105,20),"Segments",0,segments,0,60) ) + + drawRoundedRect = pyray.gui_check_box(pyray.Rectangle(640,320,20,20),"DrawRoundedRect",drawRoundedRect) + drawRoundedLines = pyray.gui_check_box(pyray.Rectangle(640,350,20,20),"DrawRoundedLines",drawRoundedLines) + drawRect = pyray.gui_check_box(pyray.Rectangle(640,380,20,20),"DrawRect",drawRect) + #//------------------------------------------------------------------------------ + + pyray.draw_text(pyray.text_format( "MODE: %s" % "MANUAL" if segments >= 4 else "AUTO" ), 640, 280, 10, MAROON if segments >= 4 else DARKGRAY ) + pyray.draw_fps(10,10) + pyray.end_drawing() + #//------------------------------------------------------------------------------ + +# De-Initialization +pyray.close_window() # Close window and OpenGL context \ No newline at end of file