Skip to content

Commit

Permalink
Updated code with latest Blender compatibility changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mmmrqs committed Jul 29, 2024
1 parent 7f97766 commit 361df15
Show file tree
Hide file tree
Showing 10 changed files with 144 additions and 45 deletions.
13 changes: 8 additions & 5 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
bl_info = {"name": "BL UI Widgets",
"description": "UI Widgets to draw in the 3D view",
"author": "Marcelo M. Marques (fork of Jayanam's original project)",
"version": (1, 0, 6),
"version": (1, 0, 7),
"blender": (3, 0, 0),
"location": "View3D > side panel ([N]), [BL_UI_Widget] tab",
"support": "COMMUNITY",
Expand All @@ -35,17 +35,20 @@
# Note: Because the way Blender's Preferences window displays the Addon version number,
# I am forced to keep this file in sync with the greatest version number of all modules.

# v1.0.6 (07.29.2024) - by Marcelo M. Marques
# Chang: updated version to keep this file in sync with greatest module version

# v1.0.6 (05.27.2023) - by Marcelo M. Marques
# Chang: updated version to keep this file in sync
# Chang: updated version to keep this file in sync with greatest module version

# v1.0.5 (03.06.2023) - by Marcelo M. Marques
# Chang: updated version to keep this file in sync
# Chang: updated version to keep this file in sync with greatest module version

# v1.0.4 (09.28.2022) - by Marcelo M. Marques
# Chang: updated version to keep this file in sync
# Chang: updated version to keep this file in sync with greatest module version

# v1.0.3 (09.25.2021) - by Marcelo M. Marques
# Chang: updated version to keep this file in sync
# Chang: updated version to keep this file in sync with greatest module version

# v1.0.2 (10.31.2021) - by Marcelo M. Marques
# Chang: updated version with improvements and some clean up
Expand Down
29 changes: 22 additions & 7 deletions bl_ui_button.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
bl_info = {"name": "BL UI Widgets",
"description": "UI Widgets to draw in the 3D view",
"author": "Marcelo M. Marques (fork of Jayanam's original project)",
"version": (1, 0, 3),
"version": (1, 0, 4),
"blender": (3, 0, 0),
"location": "View3D > viewport area",
"support": "COMMUNITY",
Expand All @@ -32,14 +32,17 @@

# --- ### Change log

# v1.0.4 (07.29.2024) - by Marcelo M. Marques
# Chang: Conditionally removed deprecated blf.size() dpi argument

# v1.0.3 (05.27.2023) - by atticus-lv
# Added: 'bind_operator' function to automatically get info from a given operator idname and bind it to the button

# v1.0.2 (10.31.2021) - by Marcelo M. Marques
# Chang: improved reliability on 'mouse_down' and 'mouse_up' overridable functions by conditioning the returned value
# Chang: Improved reliability on 'mouse_down' and 'mouse_up' overridable functions by conditioning the returned value

# v1.0.1 (09.20.2021) - by Marcelo M. Marques
# Chang: just some pep8 code formatting
# Chang: Just some pep8 code formatting

# v1.0.0 (09.01.2021) - by Marcelo M. Marques
# Added: Logic to scale the button according to both Blender's ui scale configuration and this addon 'preferences' setup
Expand Down Expand Up @@ -396,10 +399,16 @@ def draw_text(self):
if text_kerning:
blf.enable(0, blf.KERNING_DEFAULT)

blf.size(0, leveraged_text_size, 72)
if bpy.app.version >= (4, 0, 0): # 4.00 issue: removed deprecated blf.size() dpi argument
blf.size(0, leveraged_text_size)
else:
blf.size(0, leveraged_text_size, 72)
normal1 = blf.dimensions(0, "W")[1] # This is to keep a regular pattern since letters differ in height

blf.size(0, scaled_size, 72)
if bpy.app.version >= (4, 0, 0): # 4.00 issue: removed deprecated blf.size() dpi argument
blf.size(0, scaled_size)
else:
blf.size(0, scaled_size, 72)
length1 = blf.dimensions(0, self._text)[0]
height1 = blf.dimensions(0, "W")[1]

Expand All @@ -411,9 +420,15 @@ def draw_text(self):
textwo_size = self._textwo_size
leveraged_text_size = self.leverage_text_size(textwo_size, "widget")
scaled_size = int(self.over_scale(leveraged_text_size))
blf.size(0, leveraged_text_size, 72)
if bpy.app.version >= (4, 0, 0): # 4.00 issue: removed deprecated blf.size() dpi argument
blf.size(0, leveraged_text_size)
else:
blf.size(0, leveraged_text_size, 72)
normal2 = blf.dimensions(0, "W")[1] # This is to keep a regular pattern since letters differ in height
blf.size(0, scaled_size, 72)
if bpy.app.version >= (4, 0, 0): # 4.00 issue: removed deprecated blf.size() dpi argument
blf.size(0, scaled_size)
else:
blf.size(0, scaled_size, 72)
length2 = blf.dimensions(0, self._textwo)[0]
height2 = blf.dimensions(0, "W")[1]
else:
Expand Down
23 changes: 18 additions & 5 deletions bl_ui_checkbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
bl_info = {"name": "BL UI Widgets",
"description": "UI Widgets to draw in the 3D view",
"author": "Marcelo M. Marques (fork of Jayanam's original project)",
"version": (1, 0, 2),
"version": (1, 0, 3),
"blender": (3, 0, 0),
"location": "View3D > viewport area",
"support": "COMMUNITY",
Expand All @@ -32,11 +32,15 @@

# --- ### Change log

# v1.0.3 (07.29.2024) - by Marcelo M. Marques
# Chang: Conditionally removed deprecated 2D_/3D_ prefix for built-in shader names
# Chang: Conditionally removed deprecated blf.size() dpi argument

# v1.0.2 (05.08.2023) - by atticus-lv
# Chang: Replaced bgl mode (to be deprecated soon) by gpu module

# v1.0.1 (09.20.2021) - by Marcelo M. Marques
# Chang: just some pep8 code formatting
# Chang: Just some pep8 code formatting

# v1.0.0 (09.01.2021) - by Marcelo M. Marques
# Added: Logic to scale the checkbox according to both Blender's ui scale configuration and this addon 'preferences' setup
Expand Down Expand Up @@ -288,7 +292,10 @@ def draw(self):
# Take the checkmark color and "dark" it by either 40% or 20%
color = self.shade_color(color, (0.4 if color[0] > 0.5 else 0.2))

self.shader_mark = gpu.shader.from_builtin('2D_UNIFORM_COLOR')
if bpy.app.version >= (4, 0, 0): # 4.00 issue: removed deprecated 2D_/3D_ prefix for built-in shader names
self.shader_mark = gpu.shader.from_builtin('UNIFORM_COLOR')
else:
self.shader_mark = gpu.shader.from_builtin('2D_UNIFORM_COLOR')

self.shader_mark.bind()
self.shader_mark.uniform_float("color", color)
Expand Down Expand Up @@ -351,10 +358,16 @@ def draw_text(self):
margin_space = (" " * rounded_scale) if rounded_scale > 0 else " "
spaced_text = margin_space + self._text + margin_space

blf.size(0, leveraged_text_size, 72)
if bpy.app.version >= (4, 0, 0): # 4.00 issue: removed deprecated blf.size() dpi argument
blf.size(0, leveraged_text_size)
else:
blf.size(0, leveraged_text_size, 72)
normal = blf.dimensions(0, "W")[1] # This is to keep a regular pattern since letters differ in height

blf.size(0, scaled_size, 72)
if bpy.app.version >= (4, 0, 0): # 4.00 issue: removed deprecated blf.size() dpi argument
blf.size(0, scaled_size)
else:
blf.size(0, scaled_size, 72)
length = blf.dimensions(0, spaced_text)[0]
height = blf.dimensions(0, "W")[1]

Expand Down
2 changes: 1 addition & 1 deletion bl_ui_draw_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
# Chang: Renamed function 'validate()' to 'valid_handler()' for better understanding of its purpose.

# v1.0.1 (09.20.2021) - by Marcelo M. Marques
# Chang: just some pep8 code formatting
# Chang: Just some pep8 code formatting

# v1.0.0 (09.01.2021) - by Marcelo M. Marques
# Added: 'terminate_execution' function that can be overriden by programmer in the subclass to control termination of the panel widget.
Expand Down
12 changes: 9 additions & 3 deletions bl_ui_label.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
bl_info = {"name": "BL UI Widgets",
"description": "UI Widgets to draw in the 3D view",
"author": "Marcelo M. Marques (fork of Jayanam's original project)",
"version": (1, 0, 1),
"version": (1, 0, 2),
"blender": (2, 80, 75),
"location": "View3D > viewport area",
"support": "COMMUNITY",
Expand All @@ -32,8 +32,11 @@

# --- ### Change log

# v1.0.2 (07.29.2024) - by Marcelo M. Marques
# Chang: conditionally removed deprecated blf.size() dpi argument

# v1.0.1 (09.20.2021) - by Marcelo M. Marques
# Chang: just some pep8 code formatting
# Chang: Just some pep8 code formatting

# v1.0.0 (09.01.2021) - by Marcelo M. Marques
# Added: Logic to scale the label's text according to both Blender's ui scale configuration and this addon 'preferences' setup
Expand Down Expand Up @@ -316,7 +319,10 @@ def draw(self):

self.verify_screen_position(area_height)

blf.size(0, text_size, 72)
if bpy.app.version >= (4, 0, 0): # 4.00 issue: removed deprecated blf.size() dpi argument
blf.size(0, text_size)
else:
blf.size(0, text_size, 72)

blf.position(0, self.over_scale(self.x_screen), self.over_scale(self.y_screen), 0)

Expand Down
10 changes: 8 additions & 2 deletions bl_ui_slider.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
bl_info = {"name": "BL UI Widgets",
"description": "UI Widgets to draw in the 3D view",
"author": "Marcelo M. Marques (fork of Jayanam's original project)",
"version": (1, 0, 4),
"version": (1, 0, 5),
"blender": (3, 0, 0),
"location": "View3D > viewport area",
"support": "COMMUNITY",
Expand All @@ -32,6 +32,9 @@

# --- ### Change log

# v1.0.5 (07.29.2024) - by Marcelo M. Marques
# Chang: Conditionally removed deprecated 2D_/3D_ prefix for built-in shader names

# v1.0.4 (05.08.2023) - by atticus-lv
# Chang: Replaced bgl mode (to be deprecated soon) by gpu module

Expand Down Expand Up @@ -590,7 +593,10 @@ def draw(self):
capped_pos_x = slider_bar[1]
if capped_width > 0:

self.shader_slider = gpu.shader.from_builtin('2D_UNIFORM_COLOR')
if bpy.app.version >= (4, 0, 0): # 4.00 issue: removed deprecated 2D_/3D_ prefix for built-in shader names
self.shader_slider = gpu.shader.from_builtin('UNIFORM_COLOR')
else:
self.shader_slider = gpu.shader.from_builtin('2D_UNIFORM_COLOR')

# used to be: if scaled_radius == 0 or scaled_radius > 10 or self._rounded_corners == (0, 0, 0, 0):
if self.scaled_radius(self._radius, self.slider.height) > 10:
Expand Down
29 changes: 22 additions & 7 deletions bl_ui_textbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
bl_info = {"name": "BL UI Widgets",
"description": "UI Widgets to draw in the 3D view",
"author": "Marcelo M. Marques (fork of Jayanam's original project)",
"version": (1, 0, 3),
"version": (1, 0, 4),
"blender": (3, 0, 0),
"location": "View3D > viewport area",
"support": "COMMUNITY",
Expand All @@ -32,14 +32,18 @@

# --- ### Change log

# v1.0.4 (07.29.2024) - by Marcelo M. Marques
# Chang: Conditionally removed deprecated 2D_/3D_ prefix for built-in shader names
# Chang: Conditionally removed deprecated blf.size() dpi argument

# v1.0.3 (05.08.2023) - by atticus-lv
# Chang: Replaced bgl mode (to be deprecated soon) by gpu module

# v1.0.2 (10.31.2021) - by Marcelo M. Marques
# Added: Logic to change state during a mouse move action so that the textbox background color is correctly set

# v1.0.1 (09.20.2021) - by Marcelo M. Marques
# Chang: just some pep8 code formatting
# Chang: Just some pep8 code formatting

# v1.0.0 (09.01.2021) - by Marcelo M. Marques
# Added: 'text_highlight' property to allow different text color on the selected textbox (value is standard color tuple).
Expand Down Expand Up @@ -280,7 +284,10 @@ def get_cursor_pos_px(self):
text_kerning = (widget_style.font_kerning_style == 'FITTED') if self._text_kerning is None else self._text_kerning
if text_kerning:
blf.enable(0, blf.KERNING_DEFAULT)
blf.size(0, scaled_size, 72)
if bpy.app.version >= (4, 0, 0): # 4.00 issue: removed deprecated blf.size() dpi argument
blf.size(0, scaled_size)
else:
blf.size(0, scaled_size, 72)

if self.__marked_pos[0] == 0:
start = 0
Expand Down Expand Up @@ -314,7 +321,10 @@ def get_cursor_pos_char(self):
text_kerning = (widget_style.font_kerning_style == 'FITTED') if self._text_kerning is None else self._text_kerning
if text_kerning:
blf.enable(0, blf.KERNING_DEFAULT)
blf.size(0, scaled_size, 72)
if bpy.app.version >= (4, 0, 0): # 4.00 issue: removed deprecated blf.size() dpi argument
blf.size(0, scaled_size)
else:
blf.size(0, scaled_size, 72)

mark_target = self.__drag_start_x + self.__drag_length
text_startx = self.over_scale(self.x_screen + self._text_margin)
Expand Down Expand Up @@ -355,9 +365,14 @@ def update_cursor(self):
# Overrides base class function
def update(self, x, y):
super().update(x, y)
self.shader_cursor = gpu.shader.from_builtin('2D_UNIFORM_COLOR')
self.shader_marked = gpu.shader.from_builtin('2D_UNIFORM_COLOR')
self.update_cursor()
if bpy.app.version >= (4, 0, 0): # 4.00 issue: removed deprecated 2D_/3D_ prefix for built-in shader names
self.shader_cursor = gpu.shader.from_builtin('UNIFORM_COLOR')
self.shader_marked = gpu.shader.from_builtin('UNIFORM_COLOR')
self.update_cursor()
else:
self.shader_cursor = gpu.shader.from_builtin('2D_UNIFORM_COLOR')
self.shader_marked = gpu.shader.from_builtin('2D_UNIFORM_COLOR')
self.update_cursor()

# Overrides base class function
def draw(self):
Expand Down
30 changes: 24 additions & 6 deletions bl_ui_tooltip.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
bl_info = {"name": "BL UI Widgets",
"description": "UI Widgets to draw in the 3D view",
"author": "Marcelo M. Marques",
"version": (1, 0, 1),
"version": (1, 0, 2),
"blender": (2, 80, 75),
"location": "View3D > viewport area",
"support": "COMMUNITY",
Expand All @@ -32,6 +32,9 @@

# --- ### Change log

# v1.0.2 (07.29.2024) - by Marcelo M. Marques
# Chang: conditionally removed deprecated blf.size() dpi argument

# v1.0.1 (09.20.2021) - by Marcelo M. Marques
# Chang: just some pep8 code formatting

Expand Down Expand Up @@ -281,9 +284,15 @@ def get_tooltip_measurements(self):

if text_kerning:
blf.enable(0, blf.KERNING_DEFAULT)
blf.size(0, text_size, 72)
if bpy.app.version >= (4, 0, 0): # 4.00 issue: removed deprecated blf.size() dpi argument
blf.size(0, text_size)
else:
blf.size(0, text_size, 72)
text_normal = blf.dimensions(0, "W")[1] # This is to keep a regular pattern since letters differ in height
blf.size(0, scaled_text_size, 72)
if bpy.app.version >= (4, 0, 0): # 4.00 issue: removed deprecated blf.size() dpi argument
blf.size(0, scaled_text_size)
else:
blf.size(0, scaled_text_size, 72)
text_height = blf.dimensions(0, "W")[1]
if text_kerning:
blf.disable(0, blf.KERNING_DEFAULT)
Expand Down Expand Up @@ -362,7 +371,10 @@ def text_wrap(self, text, text_size, text_kerning, max_width_px, max_lines_count
line_break = "\n"
text = text.rstrip()

blf.size(0, text_size, 72)
if bpy.app.version >= (4, 0, 0): # 4.00 issue: removed deprecated blf.size() dpi argument
blf.size(0, text_size)
else:
blf.size(0, text_size, 72)
if text_kerning:
blf.enable(0, blf.KERNING_DEFAULT)

Expand Down Expand Up @@ -451,9 +463,15 @@ def draw_text(self):

if text_kerning:
blf.enable(0, blf.KERNING_DEFAULT)
blf.size(0, leveraged_text_size, 72)
if bpy.app.version >= (4, 0, 0): # 4.00 issue: removed deprecated blf.size() dpi argument
blf.size(0, leveraged_text_size)
else:
blf.size(0, leveraged_text_size, 72)
text_normal = blf.dimensions(0, "W")[1] # This is to keep a regular pattern since letters differ in height
blf.size(0, scaled_text_size, 72)
if bpy.app.version >= (4, 0, 0): # 4.00 issue: removed deprecated blf.size() dpi argument
blf.size(0, scaled_text_size)
else:
blf.size(0, scaled_text_size, 72)
text_height = blf.dimensions(0, "W")[1] # This is to keep a regular pattern since letters differ in height
if text_kerning:
blf.disable(0, blf.KERNING_DEFAULT)
Expand Down
5 changes: 4 additions & 1 deletion bl_ui_up_down.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,10 @@ def create_up_down_buttons(self):

)

self.shader = gpu.shader.from_builtin('2D_UNIFORM_COLOR')
if bpy.app.version >= (4, 0, 0): # 4.00 issue: removed deprecated 2D_/3D_ prefix for built-in shader names
self.shader = gpu.shader.from_builtin('UNIFORM_COLOR')
else:
self.shader = gpu.shader.from_builtin('2D_UNIFORM_COLOR')
self.batch_up = batch_for_shader(self.shader, 'TRIS', {"pos" : vertices_up})
self.batch_down = batch_for_shader(self.shader, 'TRIS', {"pos" : vertices_down})

Expand Down
Loading

0 comments on commit 361df15

Please sign in to comment.