dialogs/BlockPreviewDialog.py
changeset 1253 00b7d3c64c80
parent 1252 18cd1357e8d3
child 1311 85ca4fa0720b
equal deleted inserted replaced
1252:18cd1357e8d3 1253:00b7d3c64c80
   267         min_width, min_height = self.GetMinElementSize()
   267         min_width, min_height = self.GetMinElementSize()
   268         width = max(self.MinElementSize[0], min_width)
   268         width = max(self.MinElementSize[0], min_width)
   269         height = max(self.MinElementSize[1], min_height)
   269         height = max(self.MinElementSize[1], min_height)
   270         self.Element.SetSize(width, height)
   270         self.Element.SetSize(width, height)
   271         
   271         
   272         # Get element bounding box to center in preview
   272         # Get element position and bounding box to center in preview
       
   273         posx, posy = self.Element.GetPosition()
   273         bbox = self.Element.GetBoundingBox()
   274         bbox = self.Element.GetBoundingBox()
   274         
   275         
   275         # Get Preview panel size
   276         # Get Preview panel size
   276         client_size = self.Preview.GetClientSize()
   277         client_size = self.Preview.GetClientSize()
   277         
   278         
   278         # If graphic element is too big to be displayed in preview panel,
   279         # If graphic element is too big to be displayed in preview panel,
   279         # calculate preview panel scale so that graphic element fit inside
   280         # calculate preview panel scale so that graphic element fit inside
   280         scale = (max(float(bbox.width) / client_size.width, 
   281         scale = (max(float(bbox.width) / client_size.width, 
   281                      float(bbox.height) / client_size.height) * 1.2
   282                      float(bbox.height) / client_size.height) * 1.1
   282                  if bbox.width * 1.1 > client_size.width or 
   283                  if bbox.width * 1.1 > client_size.width or 
   283                     bbox.height * 1.1 > client_size.height
   284                     bbox.height * 1.1 > client_size.height
   284                  else 1.0)
   285                  else 1.0)
   285         dc.SetUserScale(1.0 / scale, 1.0 / scale)
   286         dc.SetUserScale(1.0 / scale, 1.0 / scale)
   286         
   287         
   287         # Center graphic element in preview panel
   288         # Center graphic element in preview panel
   288         x = int(client_size.width * scale - bbox.width) / 2
   289         x = int(client_size.width * scale - bbox.width) / 2 + posx - bbox.x
   289         y = int(client_size.height * scale - bbox.height) / 2
   290         y = int(client_size.height * scale - bbox.height) / 2 + posy - bbox.y
   290         self.Element.SetPosition(x, y)
   291         self.Element.SetPosition(x, y)
   291         
   292         
   292         # Draw graphic element
   293         # Draw graphic element
   293         self.Element.Draw(dc)
   294         self.Element.Draw(dc)
   294     
   295