drawing
drawing copied to clipboard
Center image area on window
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
thanks Andrea
While i agree it looks better, it is not be possible currently, so this issue might stay opened for years
Is it possible now? If you start drawing it looks strange.
The issue doesn't look closed
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:
Let me know if you'd like me to open a pull request. :)
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
(i say that because you change the cursor callback, which i highly suspect to be currently wrong)
gotcha. I will hold off on this PR then until the callbacks are in a known working state.