1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 """
23 Contains a custom widget for previewing a resize operation
24 """
25
26 import cairo
27 import gtk
28
29 import graphics
30
31
33 """
34 Widget for previewing a resize operation.
35 """
36
37 __gsignals__ = {"expose-event" : "override"}
38
39 - def __init__(self, tileWidth, tileHeight , thumb):
40 """
41 @type tileWidth: int
42 @param tileWidth: current width of map in tiles
43 @type tileHeight: int
44 @param tileHeight: current height of map in tiles
45 @type thumb: cairo.ImageSurface
46 @param thumb: thumbnail image of the map
47 """
48 gtk.DrawingArea.__init__(self)
49 self.__tWidth = thumb.get_width()
50 self.__tHeight = thumb.get_height()
51 self.__pixelSize = int(max(thumb.get_width(), thumb.get_height()))
52 self.__oldWidth = tileWidth
53 self.__oldHeight = tileHeight
54 self.__thumb = thumb
55 self.__newWidth = tileWidth
56 self.__newHeight = tileHeight
57 self.__scaleFactor = 1.0
58 self.__top = 0
59 self.__bottom = 0
60 self.__left = 0
61 self.__right = 0
62 self.__checkerBoard = graphics.getCheckerPattern(16)
63 self.set_size_request(thumb.get_width(), thumb.get_height())
64
66 self.__top = top
67 self.__newHeight = self.__oldHeight + self.__top + self.__bottom
68 self.__setDimentions()
69
71 self.__bottom = bottom
72 self.__newHeight = self.__oldHeight + self.__top + self.__bottom
73 self.__setDimentions()
74
76 self.__left = left
77 self.__newWidth = self.__oldWidth + self.__left + self.__right
78 self.__setDimentions()
79
81 self.__right = right
82 self.__newWidth = self.__oldWidth + self.__left + self.__right
83 self.__setDimentions()
84
86 """
87 Redraws the widget
88 """
89 context = self.window.cairo_create()
90 context.set_source(self.__checkerBoard)
91 context.paint()
92 context.scale(self.__scaleFactor, self.__scaleFactor)
93 tileWidth = float(self.__tHeight) / float(self.__oldHeight)
94 context.set_source_surface(self.__thumb, self.__left * tileWidth,
95 self.__top * tileWidth)
96 context.rectangle(self.__left * tileWidth,
97 self.__top * tileWidth, self.__tWidth, self.__tHeight)
98 context.fill()
99
101
102
103 w = self.__pixelSize
104 h = self.__pixelSize
105
106 gd = max(self.__oldWidth, self.__oldHeight)
107 if self.__newWidth > self.__newHeight:
108 h = self.__pixelSize * (float(self.__newHeight) / float(self.__newWidth))
109 self.__scaleFactor = gd / float(self.__newWidth)
110 else:
111 w = self.__pixelSize * (float(self.__newWidth) / float(self.__newHeight))
112 self.__scaleFactor = gd / float(self.__newHeight)
113 self.set_size_request(int(w), int(h))
114 self.queue_draw()
115