Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI: add optional backdrop to the modal operator overlay to improve readability #294

Closed
Weisl opened this issue Nov 16, 2022 · 2 comments
Closed
Labels
Minor Prio it's a bug but not affecting the experience or causing many issues. UI User Interface Improvements
Milestone

Comments

@Weisl
Copy link
Owner

Weisl commented Nov 16, 2022

Mesh_02_small

@Weisl Weisl added this to the 1.3 milestone Nov 16, 2022
@Weisl Weisl added UI User Interface Improvements Minor Prio it's a bug but not affecting the experience or causing many issues. labels May 23, 2023
@Weisl Weisl modified the milestones: 1.3, 1.4 Jun 1, 2023
@Weisl
Copy link
Owner Author

Weisl commented Jun 1, 2023

I don't manage to draw a box in the viewport

@Weisl Weisl modified the milestones: 1.4, 1.3 Jun 1, 2023
@Weisl
Copy link
Owner Author

Weisl commented Jun 1, 2023

ChatGPT code to draw a rectangle

import bpy
import gpu
from gpu_extras.batch import batch_for_shader

vertices = (
    (100, 100), (300, 100),
    (100, 200), (300, 200))

indices = (
    (0, 1, 2), (2, 1, 3))

shader = gpu.shader.from_builtin('2D_UNIFORM_COLOR')
batch = batch_for_shader(shader, 'TRIS', {"pos": vertices}, indices=indices)


def draw_callback_2d(self, context):
    shader.bind()
    shader.uniform_float("color", (0, 0.5, 0.5, 1.0))
    batch.draw(shader)


class DrawOperator(bpy.types.Operator):
    bl_idname = "object.draw_operator"
    bl_label = "Draw Operator"

    def modal(self, context, event):
        if event.type == 'ESC':
            bpy.types.SpaceView3D.draw_handler_remove(self._handle_2d, 'WINDOW')
            return {'CANCELLED'}

        return {'PASS_THROUGH'}

    def invoke(self, context, event):
        if context.area.type == 'VIEW_3D':
            self._handle_2d = bpy.types.SpaceView3D.draw_handler_add(draw_callback_2d, (self, context), 'WINDOW', 'POST_PIXEL')

            context.window_manager.modal_handler_add(self)
            return {'RUNNING_MODAL'}
        else:
            self.report({'WARNING'}, "View3D not found, cannot run operator")
            return {'CANCELLED'}


def register():
    bpy.utils.register_class(DrawOperator)


def unregister():
    bpy.utils.unregister_class(DrawOperator)


if __name__ == "__main__":
    register()

Weisl added a commit that referenced this issue Jun 4, 2023
@Weisl Weisl closed this as completed Jun 4, 2023
@Weisl Weisl changed the title Modal Overlay can be hardly readable (Add background) UI: add optional backdrop to the modal operator overlay to improve readability Jun 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Minor Prio it's a bug but not affecting the experience or causing many issues. UI User Interface Improvements
Projects
None yet
Development

No branches or pull requests

1 participant