Skip to content

Instantly share code, notes, and snippets.

@SuddenDevelopment
Created December 21, 2022 12:35
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SuddenDevelopment/bc57f541737e980bd16191cca180bace to your computer and use it in GitHub Desktop.
Save SuddenDevelopment/bc57f541737e980bd16191cca180bace to your computer and use it in GitHub Desktop.
Display a 2d button gizmo in the 3dview window for an addon UI
from bpy.types import (
GizmoGroup
)
import bpy
bl_info = {
"name": "POC buttons",
"description": "POC 2D BUTTON script refactored from GP Animator Desk addon",
"author": "Anthony Aragues, P.Świda",
"version": (0, 0, 1),
"blender": (3, 4, 0),
"location": "3d window",
"wiki_url": "",
"tracker_url": "",
"category": "UI"
}
class AD_3DVIEW_UI_Buttons(GizmoGroup):
bl_idname = "GP Animator Desk UI Buttons"
bl_label = "GP Animator Desk UI Buttons"
bl_space_type = 'VIEW_3D'
bl_region_type = 'WINDOW'
bl_options = {'PERSISTENT', 'SCALE'}
@classmethod
def poll(cls, context):
# modify this to whatever conditions you need for showing this gizmo group
return True
def draw_prepare(self, context):
# set the x and y for the gizmo, by default starting from bottom left == the center of the gizmo
self.button_gizmo.matrix_basis[0][3] = context.region.width/2
self.button_gizmo.matrix_basis[1][3] = 40
self.button_gizmo.color = (1, 0, 0)
self.button_gizmo.color_highlight = self.button_gizmo.color
self.button_gizmo.alpha = 1
return
def setup(self, context):
# array not necessary, but might be useful if setting up several
# a collection might be better where each gizmo props are read and set. But his is fine for POC to understand
gizmos = []
gizmos.append(self.gizmos.new("GIZMO_GT_button_2d"))
gizmos[0].icon = 'BLENDER'
gizmos[0].draw_options = {'BACKDROP', 'OUTLINE'}
gizmos[0].alpha = 0.8
gizmos[0].color = 0, 0, 0
gizmos[0].color_highlight = 0.0, 0.0, 0.0
gizmos[0].alpha_highlight = 0.3
gizmos[0].scale_basis = (80 * 0.35) / 1.8
gizmos[0].show_drag = False
self.button_gizmo = gizmos[0]
def register():
bpy.utils.register_class(AD_3DVIEW_UI_Buttons)
def unregister():
bpy.utils.unregister_class(AD_3DVIEW_UI_Buttons)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment