drawing icon indicating copy to clipboard operation
drawing copied to clipboard

Center image area on window

Open dasnoopy opened this issue 6 years ago • 7 comments

Hi, I recently discover your app , really nice job! I'm playing with it and even if is still in beta , it work well for basic drawing tasks.

Getting back on topic could it be possibie to ~~have an option to~~ place the image centered on the window? something like this

center

thanks Andrea

dasnoopy avatar Feb 28 '19 06:02 dasnoopy

While i agree it looks better, it is not be possible currently, so this issue might stay opened for years

maoschanz avatar Feb 28 '19 10:02 maoschanz

Is it possible now? If you start drawing it looks strange. Drawing

linuxr01 avatar Jul 05 '19 07:07 linuxr01

The issue doesn't look closed

maoschanz avatar Jul 05 '19 09:07 maoschanz

You can use cairo_context_translate() in your on_draw() to translate the canvas to the center. Here I added to the example I posted in issue #121.

	def on_draw(self, area, cairo_context):
		"""Signal callback. Executed when self.drawing_area is redrawn."""

		surface = self.get_surface()

		allocation = self.get_allocation()
		width = allocation.width
		height = allocation.height
		image_width = surface.get_width()
		image_height = surface.get_height()

		# Fill background with a color
		cairo_context.new_path()
		cairo_context.set_source_rgb(1, 0, 0)
		cairo_context.move_to(0, 0)
		cairo_context.rel_line_to(height, 0)
		cairo_context.rel_line_to(height, width)
		cairo_context.rel_line_to(0, width)
		cairo_context.close_path()
		cairo_context.fill()
		cairo_context.paint()

		# Draw the image on top
		cairo_context.translate((width / 2) - (image_width / 2), (height / 2) - (image_height / 2))
		cairo_context.scale(self.zoom_level, self.zoom_level)
		cairo_context.set_source_surface(surface, \
		                                 -1 * self.scroll_x, -1 * self.scroll_y)
		cairo_context.paint()

		self.active_tool().on_draw(area, cairo_context)

Then all the coordinates in the cursor callbacks need to be updated like this:

		event_x, event_y = self.get_event_coords(event)
		allocation = self.get_allocation()
		width = allocation.width
		height = allocation.height
		surface_width = self.surface.get_width()
		surface_height = self.surface.get_height()
		event_x -= (width - surface_width) / 2
		event_y -= (height - surface_height) / 2

I tested it out locally. Here are the results:

centered-canvas

Let me know if you'd like me to open a pull request. :)

fabiocolacio avatar Mar 28 '20 22:03 fabiocolacio

i wanted to think about this issue once the zoom will work entirely as i expect, but if you already have a solution and you don't see any major bug when you zoom in or out, or when the image is bigger than the window, you can open a PR now

maoschanz avatar Mar 28 '20 22:03 maoschanz

(i say that because you change the cursor callback, which i highly suspect to be currently wrong)

maoschanz avatar Mar 28 '20 22:03 maoschanz

gotcha. I will hold off on this PR then until the callbacks are in a known working state.

fabiocolacio avatar Mar 28 '20 23:03 fabiocolacio