@@ -24,6 +24,8 @@ def __init__(self, parent, manager=None):
2424 self .Bind (wx .EVT_PAINT , self .OnPaint )
2525 self .Bind (wx .EVT_LEFT_DOWN , self .OnMouseDown )
2626 self .Bind (wx .EVT_LEFT_UP , self .OnMouseUp )
27+ self .Bind (wx .EVT_RIGHT_DOWN , self .OnMouseDown )
28+ self .Bind (wx .EVT_RIGHT_UP , self .OnMouseUp )
2729 self .Bind (wx .EVT_MOTION , self .OnMouseMotion )
2830 self .Bind (wx .EVT_MOUSEWHEEL , self .OnMouseWheel )
2931 self .lastx , self .lasty = None , None
@@ -73,12 +75,24 @@ def OnMouseMotion(self, evt):
7375 x , y = evt .GetPosition ()
7476 dx , dy = x - self .lastx , y - self .lasty
7577 self .lastx , self .lasty = x , y
76- #self.manager.h -= dx/200
7778 angx = self .manager .angx - dx / 200
7879 angy = self .manager .angy + dy / 200
79- #print('ang', angx, angy)
8080 self .manager .set_pers (angx = angx , angy = angy )
8181 self .Refresh (False )
82+ if evt .Dragging () and evt .RightIsDown ():
83+ light = self .manager .light
84+ x , y = evt .GetPosition ()
85+ dx , dy = x - self .lastx , y - self .lasty
86+ self .lastx , self .lasty = x , y
87+ angx , angy = dx / 200 , dy / 200
88+ vx , vy , vz = self .manager .light
89+ ay = math .asin (vz / math .sqrt (vx ** 2 + vy ** 2 + vz ** 2 ))- angy
90+ xx = math .cos (angx )* vx - math .sin (angx )* vy
91+ yy = math .sin (angx )* vx + math .cos (angx )* vy
92+ ay = max (min (math .pi / 2 - 1e-4 , ay ), - math .pi / 2 + 1e-4 )
93+ zz , k = math .sin (ay ), math .cos (ay )/ math .sqrt (vx ** 2 + vy ** 2 )
94+ self .manager .set_light ((xx * k , yy * k , zz ))
95+ self .Refresh (False )
8296
8397 def save_bitmap (self , path ):
8498 context = wx .ClientDC ( self )
@@ -142,6 +156,14 @@ def __init__( self, parent, manager=None):
142156 #pan = wx.Panel(self.toolbar, size=(50, 50))
143157 self .btn_color = wx .ColourPickerCtrl ( self .toolbar , wx .ID_ANY , wx .Colour ( 128 , 128 , 128 ), wx .DefaultPosition , [(33 , 38 ), (- 1 , - 1 )][platform .system () in ['Windows' , 'Linux' ]], wx .CLRP_DEFAULT_STYLE )
144158 tsizer .Add ( self .btn_color , 0 , wx .ALIGN_CENTER | wx .ALL | (0 , wx .EXPAND )[platform .system () in ['Windows' , 'Linux' ]], 0 )
159+ tsizer .Add (wx .StaticLine ( self .toolbar , wx .ID_ANY , wx .DefaultPosition , wx .DefaultSize , wx .LI_VERTICAL ), 0 , wx .ALL | wx .EXPAND , 2 )
160+ self .cho_light = wx .Choice ( self .toolbar , wx .ID_ANY , wx .DefaultPosition , wx .DefaultSize , ['force light' , 'normal light' , 'weak light' , 'off light' ], 0 )
161+ self .cho_light .SetSelection ( 1 )
162+ tsizer .Add ( self .cho_light , 0 , wx .ALIGN_CENTER | wx .ALL , 1 )
163+ self .cho_bg = wx .Choice ( self .toolbar , wx .ID_ANY , wx .DefaultPosition , wx .DefaultSize , ['force scatter' , 'normal scatter' , 'weak scatter' , 'off scatter' ], 0 )
164+ self .cho_bg .SetSelection ( 1 )
165+ tsizer .Add ( self .cho_bg , 0 , wx .ALIGN_CENTER | wx .ALL , 1 )
166+
145167 self .toolbar .SetSizer ( tsizer )
146168 tsizer .Layout ()
147169
@@ -199,6 +221,8 @@ def __init__( self, parent, manager=None):
199221
200222 self .cho_obj .Bind ( wx .EVT_CHOICE , self .on_select )
201223 self .cho_mode .Bind ( wx .EVT_CHOICE , self .on_mode )
224+ self .cho_light .Bind ( wx .EVT_CHOICE , self .on_light )
225+ self .cho_bg .Bind ( wx .EVT_CHOICE , self .on_bg )
202226 self .chk_visible .Bind ( wx .EVT_CHECKBOX , self .on_visible )
203227 self .sli_blend .Bind ( wx .EVT_SCROLL , self .on_blend )
204228 self .col_color .Bind ( wx .EVT_COLOURPICKER_CHANGED , self .on_color )
@@ -229,6 +253,16 @@ def on_bgcolor(self, event):
229253 self .canvas .manager .set_background (c )
230254 self .canvas .Refresh (False )
231255
256+ def on_bg (self , event ):
257+ scatter = 3 - self .cho_bg .GetSelection ()
258+ self .canvas .manager .set_bright_scatter (scatter = scatter / 3 )
259+ self .canvas .Refresh (False )
260+
261+ def on_light (self , event ):
262+ bright = 3 - self .cho_light .GetSelection ()
263+ self .canvas .manager .set_bright_scatter (bright = bright / 3 )
264+ self .canvas .Refresh (False )
265+
232266 def on_save (self , evt ):
233267 dic = {'open' :wx .FD_OPEN , 'save' :wx .FD_SAVE }
234268 filt = 'PNG files (*.png)|*.png'
0 commit comments