Giter Club home page Giter Club logo

Comments (6)

schroef avatar schroef commented on August 16, 2024

Okay, i found it. I didnt check the addon menu properly :)

This is really well done man! Im working on some addons and was always wondering how people make the custom UI items in the 3dview port. Is it okay i look at how you did that?

from archipack.

s-leger avatar s-leger commented on August 16, 2024

Hi,
Feel free to inspire, re-use the way you like !

Archipack's sample may be overkill, as it does override regular preset_loader operator and hide bgl logic behind an abstraction layer.
archipack_presets.py and archipack_gl.py

You may take a look at asset flinger implementation (wich was inspiration for archipack preset menu).
Asset flinger github repo

As a side note, bgl module is currently not supported in 2.8 series and a complete rewrite is planed, so this api is likely to change.
Also keep in mind that some folders are read only - this is the main reason for your issue, presets have to move into user profile folder to be writeable.

from archipack.

schroef avatar schroef commented on August 16, 2024

Aha, thanks for explaining! Im helping a guy with a addon for Thea Render engine and have done many adds for this render engine. What i like i that GUI in the 3dview when something is added, just like HardOps has. This makes it much more clear that something is happening. At the moment when we render in the view port, there is only simple text which can be set to a certain size. I would like to make this a bit more visible if i can do so.

I also like those foldout menu's, I wanted to use those small + menu but not really got how that worked. This is done much easier using a simple boolean and if else statement.

screen shot 2018-01-11 at 12 08 05 pm

I do see something about BGL in API 2.78 https://docs.blender.org/api/blender_python_api_current/bgl.html
I will see if i can understand all of that. What ive seen so far is that there are tons of functions involved to show something on top of blender GUI in viewport.

from archipack.

s-leger avatar s-leger commented on August 16, 2024

Yep, drawing using gl is painfull, but archipack provide an abstraction layer to do so.
see Feedback panel
The feedback panel does rely on archipack addon preferences for colors and font sizes (parameters are in init.py).

from archipack.

schroef avatar schroef commented on August 16, 2024

I did look into it and got some simple square. Not sure how you manage to have the rectangle below the text. I did also have this with mine, but when its rendering the text stays and the rectangle becomes darker and darker.

Do you draw the whole block as a new image or something?

Finding the code in the files took me a while as well as to figure it all out. I think i should start with a very simple square, than add more dynamic aspects and more interaction if needed.

from archipack.

s-leger avatar s-leger commented on August 16, 2024

Hi,
Feedback panel and Preset menu are full real-time gl only.
Obviously i'm using images in thumbs, but that's it.

From what you say it seem you are adding the draw handler more than once.

I can't figure if you try to use FeedbackPanel or Preset menu ?
Could you share the code ?

Here is a complete sample of proper Feedback usage in a modal.

import bpy
from bpy.types import Operator
from .archipack_gl import FeedbackPanel

class DEMO_OP_Feedback(Operator):
    bl_idname = "demo.feedback"
    bl_label = "Feedback"
    bl_description = "Feedback panel in modal"
    bl_options = {'REGISTER', 'UNDO'}
    
    feedback = None
    _handle = None
    
    # draw callback
    def draw_callback(self, _self, context):
        self.feedback.draw(context)
    
    def invoke(self, context, event):
        # Create a panel instance
        self.feedback = FeedbackPanel(title="Main Title")
        self.feedback.instructions(context, "Sub title", "hint", [
            ('SHIFT', 'deselect'),
            ('CTRL', 'contains'),
            ('A', 'All'),
            ('I', 'Inverse'),
            ('ESC or RIGHTMOUSE', 'exit when done')
        ])
        # Enable panel
        self.feedback.enable()
        
        # panel draw handler to be added only once at beginning
        args = (self, context)
        self._handle = bpy.types.SpaceView3D.draw_handler_add(
            self.draw_callback, 
            args, 
            'WINDOW', 
            'POST_PIXEL')
        
        # add modal handler
        context.window_manager.modal_handler_add(self)
        return {'RUNNING_MODAL'}
       
    def modal(self, context, event):
        
        # tag area for gl redraw
        context.area.tag_redraw()
        
        # exit condition
        if event.type in {'ESC', 'RIGHTMOUSE'}:
            # Ensure you remove your draw handler on exit
            bpy.types.SpaceView3D.draw_handler_remove(self._handle, 'WINDOW')
            self.feedback.disable()
            return {'FINISHED'}
                
        # do whatever you need
        
        if user_do_something:
            # here you are able to change feedback on the fly, calling instructions again
            self.feedback.instructions(context, 'Title', 'Hints about usage', [
                ('SHORTCUT', 'Hints about shortcut'),
                ...
            ])
            
        if no_feeddback_need_for_this_action:
            # disable / enable feedback drawing at any time too
            self.feedback.disable()
        
        return {'RUNNING_MODAL'}

from archipack.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.