@@ -193,6 +193,9 @@ def on_draw(self, area, cairo_context):
193193 ############################################################################
194194
195195 def build_selection_fit_operation (self ):
196+ """Special way to build an operation, not from the present crop tool,
197+ but from the selection menu. The parameters are determined automatically
198+ from the state of the selection manager."""
196199 self ._update_expansion_color ()
197200 selection = self .get_selection ()
198201 new_origin_x = min (0 , selection .selection_x )
@@ -244,23 +247,60 @@ def do_tool_operation(self, operation):
244247 self .common_end_operation (operation )
245248
246249 def _crop_temp_pixbuf (self , x , y , width , height , is_selection , rgba ):
250+ """Crop and/or expand the temp pixbuf according to given parameters."""
251+
252+ # Coordinates of the origin of the source pixbuf (temp_p)
247253 src_x = max (x , 0 )
248254 src_y = max (y , 0 )
249255
256+ # Coordinates of the origin of the destination pixbuf (new_pixbuf)
250257 if is_selection :
251258 dest_x = 0
252259 dest_y = 0
253260 else :
254261 dest_x = max (- 1 * x , 0 )
255262 dest_y = max (- 1 * y , 0 )
256263
257- new_pixbuf = GdkPixbuf .Pixbuf .new (GdkPixbuf .Colorspace .RGB , True , 8 , width , height )
264+ # Dotted lines == new sizes; plain line == old sizes.
265+ #
266+ # If the origin has been cropped, `src` == the new coordinates, and
267+ # `dest` == 0 (in the considered direction x or y):
268+ #
269+ # dest____________________
270+ # | |
271+ # | src------------------|
272+ # | ⁝ |
273+ # |___⁝___________________|
274+ #
275+ # With the selection, it's not possible to expand, so we're always in
276+ # this first case, with `dest` == 0.
277+ # Else (if it hasn't moved, or if it has been expanded) `src` has to be
278+ # 0 (because the coordinates GdkPixbuf will use can't be negative), and
279+ # `dest` is (-1 * the new coordinates):
280+ #
281+ # dest---------------------
282+ # ⁝ ⁝
283+ # ⁝ src__________________⁝
284+ # ⁝ | |
285+ # ⁝___|___________________|
286+ #
287+ # The sign inversion is completely artificial (again: it's because the
288+ # coordinates GdkPixbuf will use can't be negative).
289+
290+ # Initialisation of an EMPTY pixbuf with the wanted size and color
291+ new_pixbuf = GdkPixbuf .Pixbuf .new (GdkPixbuf .Colorspace .RGB , True , 8 , \
292+ width , height )
258293 new_pixbuf .fill (rgba )
259294
260295 temp_p = self .get_image ().temp_pixbuf
296+ # The width/height we want (mesured from the respective origins of the
297+ # `src` and the `dest` rectangles)
261298 min_w = min (width - dest_x , temp_p .get_width () - src_x )
262299 min_h = min (height - dest_y , temp_p .get_height () - src_y )
263300
301+ # Copy an area of the source pixbuf `temp_p`; the area starts at `src_*`
302+ # and has the dimensions `min_*`. It's painted on the destination pixbuf
303+ # (`new_pixbuf`) starting at the coordinates `dest_*`.
264304 temp_p .copy_area (src_x , src_y , min_w , min_h , new_pixbuf , dest_x , dest_y )
265305 self .get_image ().set_temp_pixbuf (new_pixbuf )
266306
0 commit comments