graphics/GraphicCommons.py
changeset 563 3f92a5e18804
parent 554 08c26c62f5a7
child 566 6014ef82a98a
--- a/graphics/GraphicCommons.py	Thu Sep 22 10:56:52 2011 +0200
+++ b/graphics/GraphicCommons.py	Thu Sep 22 15:33:31 2011 +0200
@@ -226,6 +226,12 @@
                    "DT": generate_datetime,
                    "TOD": generate_timeofday}
 
+def MiterPen(colour, width=1, style=wx.SOLID):
+    pen = wx.Pen(colour, width, style)
+    pen.SetJoin(wx.JOIN_MITER)
+    pen.SetCap(wx.CAP_PROJECTING)
+    return pen
+
 #-------------------------------------------------------------------------------
 #                            Debug Data Consumer Class
 #-------------------------------------------------------------------------------
@@ -439,40 +445,49 @@
     def Redraw(self, dc = None):
         if not dc:
             dc = self.drawingSurface.GetLogicalDC()
+        scalex, scaley = dc.GetUserScale()
+        dc.SetUserScale(1, 1)
         dc.SetPen(wx.Pen(wx.WHITE, 1, wx.DOT))
         dc.SetBrush(wx.TRANSPARENT_BRUSH)
         dc.SetLogicalFunction(wx.XOR)
         if self.lastBox:
             # Erase last box
-            dc.DrawRectangle(self.lastBox.x, self.lastBox.y, self.lastBox.width,
-                self.lastBox.height)
+            dc.DrawRectangle(self.lastBox.x * scalex, self.lastBox.y * scaley, 
+                             self.lastBox.width * scalex, self.lastBox.height * scaley)
         if self.currentBox:
             # Draw current box
-            dc.DrawRectangle(self.currentBox.x, self.currentBox.y, self.currentBox.width,
-                self.currentBox.height)
+            dc.DrawRectangle(self.currentBox.x * scalex, self.currentBox.y * scaley, 
+                             self.currentBox.width * scalex, self.currentBox.height * scaley)
+        dc.SetUserScale(scalex, scaley)
     
     # Erase last box
     def Erase(self, dc = None):
         if not dc:
             dc = self.drawingSurface.GetLogicalDC()
+        scalex, scaley = dc.GetUserScale()
+        dc.SetUserScale(1, 1)
         dc.SetPen(wx.Pen(wx.WHITE, 1, wx.DOT))
         dc.SetBrush(wx.TRANSPARENT_BRUSH)
         dc.SetLogicalFunction(wx.XOR)
         if self.lastBox:
-            dc.DrawRectangle(self.lastBox.x, self.lastBox.y, self.lastBox.width,
-                self.lastBox.height)
-    
+            dc.DrawRectangle(self.lastBox.x * scalex, self.lastBox.y * scaley, 
+                             self.lastBox.width * scalex, self.lastBox.height * scalex)
+        dc.SetUserScale(scalex, scaley)
+
     # Draw current box
     def Draw(self, dc = None):
         if not dc:
             dc = self.drawingSurface.GetLogicalDC()
+        scalex, scaley = dc.GetUserScale()
+        dc.SetUserScale(1, 1)
         dc.SetPen(wx.Pen(wx.WHITE, 1, wx.DOT))
         dc.SetBrush(wx.TRANSPARENT_BRUSH)
         dc.SetLogicalFunction(wx.XOR)
         if self.currentBox:
             # Draw current box
-            dc.DrawRectangle(self.currentBox.x, self.currentBox.y, self.currentBox.width,
-                self.currentBox.height)
+            dc.DrawRectangle(self.currentBox.x * scalex, self.currentBox.y * scaley, 
+                             self.currentBox.width * scalex, self.currentBox.height * scaley)
+        dc.SetUserScale(scalex, scaley)
 
 #-------------------------------------------------------------------------------
 #                               Viewer ToolTip
@@ -506,7 +521,7 @@
     def OnPaint(self, event):
         dc = wx.AutoBufferedPaintDC(self)
         dc.Clear()
-        dc.SetPen(wx.BLACK_PEN)
+        dc.SetPen(MiterPen(wx.BLACK))
         dc.SetBrush(wx.Brush(wx.Colour(255, 238, 170)))
         dc.BeginDrawing()
         w, h = dc.GetTextExtent(self.Tip)
@@ -664,11 +679,13 @@
     
     # Returns the RedrawRect
     def GetRedrawRect(self, movex = 0, movey = 0):
+        dc = self.Parent.GetLogicalDC()
+        scalex, scaley = dc.GetUserScale()
         rect = wx.Rect()
-        rect.x = self.BoundingBox.x - HANDLE_SIZE - 2 - abs(movex)
-        rect.y = self.BoundingBox.y - HANDLE_SIZE - 2 - abs(movey)
-        rect.width = self.BoundingBox.width + 2 * (HANDLE_SIZE + abs(movex)) + 4
-        rect.height = self.BoundingBox.height + 2 * (HANDLE_SIZE + abs(movey)) + 4
+        rect.x = self.BoundingBox.x - int(HANDLE_SIZE / scalex) - 3 - abs(movex)
+        rect.y = self.BoundingBox.y - int(HANDLE_SIZE / scaley) - 3 - abs(movey)
+        rect.width = self.BoundingBox.width + 2 * (int(HANDLE_SIZE / scalex) + abs(movex) + 1) + 4
+        rect.height = self.BoundingBox.height + 2 * (int(HANDLE_SIZE / scaley) + abs(movey) + 1) + 4
         return rect
     
     def Refresh(self, rect = None):
@@ -689,28 +706,40 @@
         self.Refresh()
     
     # Test if the point is on a handle of this element
-    def TestHandle(self, pt):
-        extern_rect = wx.Rect(self.BoundingBox.x - HANDLE_SIZE - 2, self.BoundingBox.y - HANDLE_SIZE - 2, 
-            self.BoundingBox.width + 2 * HANDLE_SIZE + 4, self.BoundingBox.height + 2 * HANDLE_SIZE + 4)
-        intern_rect = wx.Rect(self.BoundingBox.x - 2, self.BoundingBox.y - 2, 
-            self.BoundingBox.width + 4, self.BoundingBox.height + 4)
+    def TestHandle(self, event):
+        dc = self.Parent.GetLogicalDC()
+        scalex, scaley = dc.GetUserScale()
+        pos = event.GetPosition()
+        pt = wx.Point(*self.Parent.CalcUnscrolledPosition(pos.x, pos.y))
+        
+        left = (self.BoundingBox.x - 2) * scalex - HANDLE_SIZE
+        center = (self.BoundingBox.x + self.BoundingBox.width / 2) * scalex - HANDLE_SIZE / 2
+        right = (self.BoundingBox.x + self.BoundingBox.width + 2) * scalex
+        
+        top = (self.BoundingBox.y - 2) * scaley - HANDLE_SIZE
+        middle = (self.BoundingBox.y + self.BoundingBox.height / 2) * scaley - HANDLE_SIZE / 2
+        bottom = (self.BoundingBox.y + self.BoundingBox.height + 2) * scaley
+        
+        extern_rect = wx.Rect(left, top, right + HANDLE_SIZE - left, bottom + HANDLE_SIZE - top)
+        intern_rect = wx.Rect(left + HANDLE_SIZE, top + HANDLE_SIZE, right - left - HANDLE_SIZE, bottom - top - HANDLE_SIZE)
+        
         # Verify that this element is selected
         if self.Selected and extern_rect.InsideXY(pt.x, pt.y) and not intern_rect.InsideXY(pt.x, pt.y):
             # Find if point is on a handle horizontally
-            if self.BoundingBox.x - HANDLE_SIZE - 2 <= pt.x < self.BoundingBox.x - 2:
+            if left <= pt.x < left + HANDLE_SIZE:
                 handle_x = 1
-            elif self.BoundingBox.x + (self.BoundingBox.width - HANDLE_SIZE) / 2 <= pt.x < self.BoundingBox.x + (self.BoundingBox.width + HANDLE_SIZE) / 2:
+            elif center <= pt.x < center + HANDLE_SIZE:
                 handle_x = 2
-            elif self.BoundingBox.x + self.BoundingBox.width + 2 <= pt.x < self.BoundingBox.x + self.BoundingBox.width + HANDLE_SIZE + 2:
+            elif right <= pt.x < right + HANDLE_SIZE:
                 handle_x = 3
             else:
                 handle_x = 0
             # Find if point is on a handle vertically
-            if self.BoundingBox.y - HANDLE_SIZE - 2 <= pt.y < self.BoundingBox.y - 2:
+            if top <= pt.y < top + HANDLE_SIZE:
                 handle_y = 1
-            elif self.BoundingBox.y + (self.BoundingBox.height - HANDLE_SIZE) / 2 <= pt.y < self.BoundingBox.y + (self.BoundingBox.height + HANDLE_SIZE) / 2:
+            elif middle <= pt.y < middle + HANDLE_SIZE:
                 handle_y = 2
-            elif self.BoundingBox.y + self.BoundingBox.height - 2 <= pt.y < self.BoundingBox.y + self.BoundingBox.height + HANDLE_SIZE + 2:
+            elif bottom <= pt.y < bottom + HANDLE_SIZE:
                 handle_y = 3
             else:
                 handle_y = 0
@@ -723,7 +752,7 @@
     def OnLeftDown(self, event, dc, scaling):
         pos = event.GetLogicalPosition(dc)
         # Test if an handle have been clicked
-        handle = self.TestHandle(pos)
+        handle = self.TestHandle(event)
         # Find which type of handle have been clicked,
         # Save a resize event and change the cursor
         cursor = HANDLE_CURSORS.get(handle, 1)
@@ -792,7 +821,7 @@
         # If cursor just pass over the element, changes the cursor if it is on a handle
         else:
             pos = event.GetLogicalPosition(dc)
-            handle = self.TestHandle(pos)
+            handle = self.TestHandle(event)
             # Find which type of handle have been clicked,
             # Save a resize event and change the cursor
             cursor = HANDLE_CURSORS.get(handle, 0)
@@ -914,11 +943,17 @@
     
     # Draws the highlightment of this element if it is highlighted (can be overwritten)
     def DrawHighlightment(self, dc):
-        dc.SetPen(wx.Pen(HIGHLIGHTCOLOR))
+        scalex, scaley = dc.GetUserScale()
+        dc.SetUserScale(1, 1)
+        dc.SetPen(MiterPen(HIGHLIGHTCOLOR))
         dc.SetBrush(wx.Brush(HIGHLIGHTCOLOR))
         dc.SetLogicalFunction(wx.AND)
-        dc.DrawRectangle(self.Pos.x - 2, self.Pos.y - 2, self.Size.width + 5, self.Size.height + 5)
+        dc.DrawRectangle(int(round((self.Pos.x - 1) * scalex)) - 2, 
+                         int(round((self.Pos.y - 1) * scaley)) - 2, 
+                         int(round((self.Size.width + 3) * scalex)) + 5, 
+                         int(round((self.Size.height + 3) * scaley)) + 5)
         dc.SetLogicalFunction(wx.COPY)
+        dc.SetUserScale(scalex, scaley)
     
     # Draws the handles of this element if it is selected
     def Draw(self, dc):
@@ -926,21 +961,25 @@
             if self.Highlighted:
                 self.DrawHighlightment(dc)
             if self.Selected:
-                dc.SetPen(wx.BLACK_PEN)
+                scalex, scaley = dc.GetUserScale()
+                dc.SetUserScale(1, 1)
+                dc.SetPen(MiterPen(wx.BLACK))
                 dc.SetBrush(wx.BLACK_BRUSH)
-                dc.DrawRectangle(self.BoundingBox.x - HANDLE_SIZE - 2, self.BoundingBox.y - HANDLE_SIZE - 2, HANDLE_SIZE, HANDLE_SIZE)
-                dc.DrawRectangle(self.BoundingBox.x + (self.BoundingBox.width - HANDLE_SIZE) / 2,
-                    self.BoundingBox.y - HANDLE_SIZE - 2, HANDLE_SIZE, HANDLE_SIZE)
-                dc.DrawRectangle(self.BoundingBox.x + self.BoundingBox.width + 2, 
-                    self.BoundingBox.y - HANDLE_SIZE - 2, HANDLE_SIZE, HANDLE_SIZE)
-                dc.DrawRectangle(self.BoundingBox.x + self.BoundingBox.width + 2, 
-                    self.BoundingBox.y + (self.BoundingBox.height - HANDLE_SIZE) / 2, HANDLE_SIZE, HANDLE_SIZE)
-                dc.DrawRectangle(self.BoundingBox.x + self.BoundingBox.width + 2, 
-                    self.BoundingBox.y + self.BoundingBox.height + 2, HANDLE_SIZE, HANDLE_SIZE)
-                dc.DrawRectangle(self.BoundingBox.x + (self.BoundingBox.width - HANDLE_SIZE) / 2, 
-                    self.BoundingBox.y + self.BoundingBox.height + 2, HANDLE_SIZE, HANDLE_SIZE)
-                dc.DrawRectangle(self.BoundingBox.x - HANDLE_SIZE - 2, self.BoundingBox.y + self.BoundingBox.height + 2, HANDLE_SIZE, HANDLE_SIZE)
-                dc.DrawRectangle(self.BoundingBox.x - HANDLE_SIZE - 2, self.BoundingBox.y + (self.BoundingBox.height - HANDLE_SIZE) / 2, HANDLE_SIZE, HANDLE_SIZE)
+                
+                left = (self.BoundingBox.x - 2) * scalex - HANDLE_SIZE
+                center = (self.BoundingBox.x + self.BoundingBox.width / 2) * scalex - HANDLE_SIZE / 2
+                right = (self.BoundingBox.x + self.BoundingBox.width + 2) * scalex
+                
+                top = (self.BoundingBox.y - 2) * scaley - HANDLE_SIZE
+                middle = (self.BoundingBox.y + self.BoundingBox.height / 2) * scaley - HANDLE_SIZE / 2
+                bottom = (self.BoundingBox.y + self.BoundingBox.height + 2) * scaley
+                
+                for x, y in [(left, top), (center, top), (right, top),
+                             (left, middle), (right, middle),
+                             (left, bottom), (center, bottom), (right, bottom)]:
+                    dc.DrawRectangle(x, y, HANDLE_SIZE, HANDLE_SIZE)
+                
+                dc.SetUserScale(scalex, scaley)
 
 
 #-------------------------------------------------------------------------------
@@ -1545,26 +1584,28 @@
     
     # Draws the highlightment of this element if it is highlighted
     def DrawHighlightment(self, dc):
-        dc.SetPen(wx.Pen(HIGHLIGHTCOLOR))
+        scalex, scaley = dc.GetUserScale()
+        dc.SetUserScale(1, 1)
+        pen = MiterPen(HIGHLIGHTCOLOR, 2 * scalex + 5)
+        pen.SetCap(wx.CAP_BUTT)
+        dc.SetPen(pen)
         dc.SetBrush(wx.Brush(HIGHLIGHTCOLOR))
         dc.SetLogicalFunction(wx.AND)
         parent_pos = self.ParentBlock.GetPosition()
         posx = parent_pos[0] + self.Pos.x
         posy = parent_pos[1] + self.Pos.y
-        width = CONNECTOR_SIZE
-        height = CONNECTOR_SIZE
+        xstart = parent_pos[0] + self.Pos.x 
+        ystart = parent_pos[1] + self.Pos.y
         if self.Direction[0] < 0:
-            posx += CONNECTOR_SIZE * self.Direction[0]
-        elif self.Direction[0] == 0:
-            posx -= 2
-            width = 5
+            xstart += 1
         if self.Direction[1] < 0:
-            posy += CONNECTOR_SIZE * self.Direction[1]
-        elif self.Direction[1] == 0:
-            posy -= 2
-            height = 5
-        dc.DrawRectangle(posx, posy, width, height)
+            ystart += 1
+        xend = xstart + CONNECTOR_SIZE * self.Direction[0]
+        yend = ystart + CONNECTOR_SIZE * self.Direction[1]
+        dc.DrawLine(round((xstart + self.Direction[0]) * scalex), round((ystart + self.Direction[1]) * scaley), 
+                    round(xend * scalex), round(yend * scaley))
         dc.SetLogicalFunction(wx.COPY)
+        dc.SetUserScale(scalex, scaley)
     
     def AddError(self, infos, start, end):
         if len(infos) == 0:
@@ -1576,25 +1617,25 @@
     # Draws the connector
     def Draw(self, dc):
         if self.Selected:
-            dc.SetPen(wx.Pen(wx.BLUE, 3))
+            dc.SetPen(MiterPen(wx.BLUE, 3))
             dc.SetBrush(wx.WHITE_BRUSH)
         elif len(self.Errors) > 0:
-            dc.SetPen(wx.RED_PEN)
+            dc.SetPen(MiterPen(wx.RED))
             dc.SetBrush(wx.Brush(wx.Colour(255, 255, 0)))
         else:
             if not self.Valid:
-                dc.SetPen(wx.RED_PEN)
+                dc.SetPen(MiterPen(wx.RED))
             elif isinstance(self.Value, BooleanType) and self.Value:
                 if self.Forced:
-                    dc.SetPen(wx.CYAN_PEN)
+                    dc.SetPen(MiterPen(wx.CYAN))
                 else:
-                    dc.SetPen(wx.GREEN_PEN)
+                    dc.SetPen(MiterPen(wx.GREEN))
             elif self.Value == "undefined":
-                dc.SetPen(wx.Pen(wx.NamedColour("orange")))
+                dc.SetPen(MiterPen(wx.NamedColour("orange")))
             elif self.Forced:
-                dc.SetPen(wx.Pen(wx.BLUE))
+                dc.SetPen(MiterPen(wx.BLUE))
             else:
-                dc.SetPen(wx.BLACK_PEN)
+                dc.SetPen(MiterPen(wx.BLACK))
             dc.SetBrush(wx.WHITE_BRUSH)
         parent_pos = self.ParentBlock.GetPosition()
         
@@ -1609,7 +1650,7 @@
             ycenter = parent_pos[1] + self.Pos.y + (CONNECTOR_SIZE * self.Direction[1]) / 2
             dc.DrawCircle(xcenter, ycenter, CONNECTOR_SIZE / 2)
         else:
-            xstart = parent_pos[0] + self.Pos.x
+            xstart = parent_pos[0] + self.Pos.x 
             ystart = parent_pos[1] + self.Pos.y
             if self.Edge == "rising":
                 # If connector has a rising edge, draw a right arrow
@@ -1619,6 +1660,10 @@
                 # If connector has a falling edge, draw a left arrow
                 dc.DrawLine(xstart, ystart, xstart + 4, ystart - 4)
                 dc.DrawLine(xstart, ystart, xstart + 4, ystart + 4)
+            if self.Direction[0] < 0:
+                xstart += 1
+            if self.Direction[1] < 0:
+                ystart += 1
             if self.Selected:
                 xend = xstart + (CONNECTOR_SIZE - 2) * self.Direction[0]
                 yend = ystart + (CONNECTOR_SIZE - 2) * self.Direction[1]
@@ -2699,21 +2744,31 @@
     
     # Draws the highlightment of this element if it is highlighted
     def DrawHighlightment(self, dc):
-        dc.SetPen(wx.Pen(HIGHLIGHTCOLOR))
+        scalex, scaley = dc.GetUserScale()
+        dc.SetUserScale(1, 1)
+        dc.SetPen(MiterPen(HIGHLIGHTCOLOR, (2 * scalex + 5)))
         dc.SetBrush(wx.Brush(HIGHLIGHTCOLOR))
         dc.SetLogicalFunction(wx.AND)
         # Draw the start and end points if they are not connected or the mouse is over them
         if len(self.Points) > 0 and (not self.StartConnected or self.OverStart):
-            dc.DrawCircle(self.Points[0].x, self.Points[0].y, POINT_RADIUS + 2)
+            dc.DrawCircle(round(self.Points[0].x * scalex), 
+                          round(self.Points[0].y * scaley), 
+                          (POINT_RADIUS + 1) * scalex + 2)
         if len(self.Points) > 1 and (not self.EndConnected or self.OverEnd):
-            dc.DrawCircle(self.Points[-1].x, self.Points[-1].y, POINT_RADIUS + 2)
-        for i in xrange(len(self.Points) - 1):
-            posx = min(self.Points[i].x, self.Points[i + 1].x) - 2
-            posy = min(self.Points[i].y, self.Points[i + 1].y) - 2
-            width = abs(self.Points[i + 1].x - self.Points[i].x) + 5
-            height = abs(self.Points[i + 1].y - self.Points[i].y) + 5
-            dc.DrawRectangle(posx, posy, width, height)
+            dc.DrawCircle(self.Points[-1].x * scalex, self.Points[-1].y * scaley, (POINT_RADIUS + 1) * scalex + 2)
+        # Draw the wire lines and the last point (it seems that DrawLines stop before the last point)
+        if len(self.Points) > 1:
+            points = [wx.Point(round((self.Points[0].x - self.Segments[0][0]) * scalex), 
+                               round((self.Points[0].y - self.Segments[0][1]) * scaley))]
+            points.extend([wx.Point(round(point.x * scalex), round(point.y * scaley)) for point in self.Points[1:-1]])
+            points.append(wx.Point(round((self.Points[-1].x + self.Segments[-1][0]) * scalex), 
+                                   round((self.Points[-1].y + self.Segments[-1][1]) * scaley)))
+        else:
+            points = []
+        dc.DrawLines(points)
         dc.SetLogicalFunction(wx.COPY)
+        dc.SetUserScale(scalex, scaley)
+        
         if self.StartConnected is not None:
             self.StartConnected.DrawHighlightment(dc)
             self.StartConnected.Draw(dc)
@@ -2725,23 +2780,23 @@
     def Draw(self, dc):
         Graphic_Element.Draw(self, dc)
         if not self.Valid:
-            dc.SetPen(wx.RED_PEN)
+            dc.SetPen(MiterPen(wx.RED))
             dc.SetBrush(wx.RED_BRUSH)
         elif isinstance(self.Value, BooleanType) and self.Value:
             if self.Forced:
-                dc.SetPen(wx.CYAN_PEN)
+                dc.SetPen(MiterPen(wx.CYAN))
                 dc.SetBrush(wx.CYAN_BRUSH)
             else:
-                dc.SetPen(wx.GREEN_PEN)
+                dc.SetPen(MiterPen(wx.GREEN))
                 dc.SetBrush(wx.GREEN_BRUSH)
         elif self.Value == "undefined":
-            dc.SetPen(wx.Pen(wx.NamedColour("orange")))
+            dc.SetPen(MiterPen(wx.NamedColour("orange")))
             dc.SetBrush(wx.Brush(wx.NamedColour("orange")))
         elif self.Forced:
-            dc.SetPen(wx.Pen(wx.BLUE))
+            dc.SetPen(MiterPen(wx.BLUE))
             dc.SetBrush(wx.BLUE_BRUSH)
         else:
-            dc.SetPen(wx.BLACK_PEN)
+            dc.SetPen(MiterPen(wx.BLACK))
             dc.SetBrush(wx.BLACK_BRUSH)
         # Draw the start and end points if they are not connected or the mouse is over them
         if len(self.Points) > 0 and (not self.StartConnected or self.OverStart):
@@ -2749,11 +2804,16 @@
         if len(self.Points) > 1 and (not self.EndConnected or self.OverEnd):
             dc.DrawCircle(self.Points[-1].x, self.Points[-1].y, POINT_RADIUS)
         # Draw the wire lines and the last point (it seems that DrawLines stop before the last point)
-        dc.DrawLines(self.Points)
-        dc.DrawPoint(self.Points[-1].x, self.Points[-1].y)
+        if len(self.Points) > 1:
+            points = [wx.Point(self.Points[0].x - self.Segments[0][0], self.Points[0].y - self.Segments[0][1])]
+            points.extend([point for point in self.Points[1:-1]])
+            points.append(wx.Point(self.Points[-1].x + self.Segments[-1][0], self.Points[-1].y + self.Segments[-1][1]))
+        else:
+            points = []
+        dc.DrawLines(points)
         # Draw the segment selected in red
         if not getattr(dc, "printing", False) and self.SelectedSegment is not None:
-            dc.SetPen(wx.Pen(wx.BLUE, 3))
+            dc.SetPen(MiterPen(wx.BLUE, 3))
             if self.SelectedSegment == len(self.Segments) - 1:
                 end = 0
             else:
@@ -2900,21 +2960,31 @@
     
     # Draws the highlightment of this element if it is highlighted
     def DrawHighlightment(self, dc):
-        dc.SetPen(wx.Pen(HIGHLIGHTCOLOR))
+        scalex, scaley = dc.GetUserScale()
+        dc.SetUserScale(1, 1)
+        dc.SetPen(MiterPen(HIGHLIGHTCOLOR))
         dc.SetBrush(wx.Brush(HIGHLIGHTCOLOR))
         dc.SetLogicalFunction(wx.AND)
-        polygon = [wx.Point(self.Pos.x - 2, self.Pos.y - 2), 
-                   wx.Point(self.Pos.x + self.Size[0] - 8, self.Pos.y - 2),
-                   wx.Point(self.Pos.x + self.Size[0] + 2, self.Pos.y + 8),
-                   wx.Point(self.Pos.x + self.Size[0] + 2, self.Pos.y + self.Size[1] + 2),
-                   wx.Point(self.Pos.x - 2, self.Pos.y + self.Size[1] + 2)]
+        
+        left = (self.Pos.x - 1) * scalex - 2
+        right = (self.Pos.x + self.Size[0] + 1) * scalex + 2
+        top = (self.Pos.y - 1) * scaley - 2
+        bottom = (self.Pos.y + self.Size[1] + 1) * scaley + 2
+        angle_top = (self.Pos.x + self.Size[0] - 9) * scalex + 2
+        angle_right = (self.Pos.y + 9) * scaley - 2
+        
+        polygon = [wx.Point(left, top), wx.Point(angle_top, top),
+                   wx.Point(right, angle_right), wx.Point(right, bottom),
+                   wx.Point(left, bottom)]
         dc.DrawPolygon(polygon)
+        
         dc.SetLogicalFunction(wx.COPY)
+        dc.SetUserScale(scalex, scaley)
         
     # Draws the comment and its content
     def Draw(self, dc):
         Graphic_Element.Draw(self, dc)
-        dc.SetPen(wx.BLACK_PEN)
+        dc.SetPen(MiterPen(wx.BLACK))
         dc.SetBrush(wx.WHITE_BRUSH)
         # Draws the comment shape
         polygon = [wx.Point(self.Pos.x, self.Pos.y),