0
$\begingroup$

I have an addon with that you can define widgets (like panels) that are drawn into the 3d view. The are defined using gpu module, that has this coordinate system:

enter image description here

So the widget would be at about (800, 100), but of course the user would rather define the panel like this (upper left hand corner is origin):

enter image description here

I already keep the x and y in a separate Python class and I paint the panel with the gpu module like this:

def update(self, x, y):

    self.x_screen = x
    self.y_screen = y

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

    # bottom left, top left, top right, bottom right
    vertices = (
                (self.x_screen, self.y_screen), 
                (self.x_screen, self.y_screen - self.height), 
                (self.x_screen + self.width, self.y_screen - self.height),
                (self.x_screen + self.width, self.y_screen))

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

Is there a nice way to convert the Y-axis so that I dont have to recalculate the Y-axis manually to define the vertices of the batch?

$\endgroup$
0
$\begingroup$

Ok guys, it wasnt that hard, just had to change about 4 parts in the code where I get the height of the area and do a simple height - y to get the y position (same for the mouse cursor)

$\endgroup$

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.