44
55from .._utils import controller_types
66from .._plot_area import PlotArea
7- from ._base import BaseGUI
7+ from ._base import Popup
88
99
1010def flip_axis (subplot : PlotArea , axis : str , flip : bool ):
@@ -21,40 +21,27 @@ def flip_axis(subplot: PlotArea, axis: str, flip: bool):
2121 setattr (camera .local , axis_attr , scale * - 1 )
2222
2323
24- class RightClickMenu (BaseGUI ):
25- def __init__ (self , owner , fa_icons , size = None ):
26- super ().__init__ (owner = owner , fa_icons = fa_icons , size = None )
27- self ._last_right_click_pos = None
24+ class RightClickMenu (Popup ):
25+ def __init__ (self , figure , fa_icons ):
26+ super ().__init__ (figure = figure , fa_icons = fa_icons )
2827
28+ self ._last_right_click_pos = None
2929 self ._mouse_down : bool = False
3030
31- self .owner .renderer .event_filters ["right-click-menu" ] = np .array (
32- [[- 1 , - 1 ], [- 1 , - 1 ]]
33- )
34-
35- self .owner .renderer .event_filters ["controller-menu" ] = np .array (
36- [[- 1 , - 1 ], [- 1 , - 1 ]]
37- )
38-
39- def reset_event_filters (self ):
40- for k in ["right-click-menu" , "controller-menu" ]:
41- self .owner .renderer .event_filters [k ][:] = [- 1 , - 1 ], [- 1 , - 1 ]
42-
43- def set_event_filter (self , name : str ):
44- x1 , y1 = imgui .get_window_pos ()
45- width , height = imgui .get_window_size ()
46- x2 , y2 = x1 + width , y1 + height
47-
48- self .owner .renderer .event_filters [name ][:] = [x1 - 1 , y1 - 1 ], [x2 + 4 , y2 + 4 ]
31+ self .is_open : bool = False
4932
5033 def get_subplot (self ) -> PlotArea | bool :
5134 if self ._last_right_click_pos is None :
5235 return False
5336
54- for subplot in self .owner :
37+ for subplot in self ._figure :
5538 if subplot .viewport .is_inside (* self ._last_right_click_pos ):
5639 return subplot
5740
41+ def cleanup (self ):
42+ self .clear_event_filters ()
43+ self .is_open = False
44+
5845 def update (self ):
5946 if imgui .is_mouse_down (1 ) and not self ._mouse_down :
6047 self ._mouse_down = True
@@ -70,7 +57,7 @@ def update(self):
7057 imgui .open_popup (f"right-click-menu" )
7158
7259 if not imgui .is_popup_open ("right-click-menu" ):
73- self .reset_event_filters ()
60+ self .cleanup ()
7461
7562 if imgui .begin_popup (f"right-click-menu" ):
7663 self .set_event_filter ("right-click-menu" )
@@ -81,6 +68,7 @@ def update(self):
8168 # subplot is returned
8269 imgui .end_popup ()
8370 imgui .close_current_popup ()
71+ self .cleanup ()
8472 return
8573
8674 name = self .get_subplot ().name
0 commit comments