| | 559 | |
|---|
| | 560 | def test_correct_repaint_offset(): |
|---|
| | 561 | ''' |
|---|
| | 562 | Ensure that there is no off by one error when repainting. |
|---|
| | 563 | |
|---|
| | 564 | A 1600*1600 pixbuf viewed in a 700*700 image view widget at zoom |
|---|
| | 565 | 1.0 should be perfectly centered so that draw starts at |
|---|
| | 566 | coordinates 450, 450. However, there may be a mishandled floating |
|---|
| | 567 | point conversion which causes the draw to start at 449, 449. See |
|---|
| | 568 | #31. |
|---|
| | 569 | ''' |
|---|
| | 570 | class DummyTool(gobject.GObject, gtkimageview.IImageTool): |
|---|
| | 571 | def __init__(self): |
|---|
| | 572 | gobject.GObject.__init__(self) |
|---|
| | 573 | self.drawn_coords = (0, 0) |
|---|
| | 574 | def do_button_press(self, ev_button): |
|---|
| | 575 | pass |
|---|
| | 576 | def do_button_release(self, ev_button): |
|---|
| | 577 | pass |
|---|
| | 578 | def do_motion_notify(self, ev_motion): |
|---|
| | 579 | pass |
|---|
| | 580 | def do_pixbuf_changed(self, reset_fit, rect): |
|---|
| | 581 | pass |
|---|
| | 582 | def do_paint_image(self, opts, drawable): |
|---|
| | 583 | self.drawn_coords = opts.zoom_rect.x, opts.zoom_rect.y |
|---|
| | 584 | def do_cursor_at_point(self, x, y): |
|---|
| | 585 | pass |
|---|
| | 586 | gobject.type_register(DummyTool) |
|---|
| | 587 | |
|---|
| | 588 | pixbuf = gdk.Pixbuf(gdk.COLORSPACE_RGB, False, 8, 1600, 1600) |
|---|
| | 589 | tool = DummyTool() |
|---|
| | 590 | |
|---|
| | 591 | view = gtkimageview.ImageView() |
|---|
| | 592 | view.set_tool(tool) |
|---|
| | 593 | view.set_show_frame(False) |
|---|
| | 594 | view.set_pixbuf(pixbuf) |
|---|
| | 595 | view.size_allocate((0, 0, 700, 700)) |
|---|
| | 596 | view.window = gdk.Window(None, |
|---|
| | 597 | 700, 700, |
|---|
| | 598 | gdk.WINDOW_TOPLEVEL, |
|---|
| | 599 | 0, |
|---|
| | 600 | gdk.INPUT_OUTPUT) |
|---|
| | 601 | view.set_zoom(1.0) |
|---|
| | 602 | ev = gdk.Event(gdk.EXPOSE) |
|---|
| | 603 | ev.area = view.allocation |
|---|
| | 604 | view.do_expose_event(view, ev) |
|---|
| | 605 | assert tool.drawn_coords == (450, 450) |
|---|
| | 606 | |
|---|