| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -149,11 +149,11 @@ def resize(self, event): | |||
| 149 | 149 | ||
| 150 | 150 | def draw(self): | |
| 151 | 151 | FigureCanvasAgg.draw(self) | |
| 152 | - tkagg.blit(self._tkphoto, self.renderer._renderer, 2) | ||
| 152 | + tkagg.blit(self._tkphoto, self.renderer._renderer, colormode=2) | ||
| 153 | 153 | self._master.update_idletasks() | |
| 154 | 154 | ||
| 155 | 155 | def blit(self, bbox=None): | |
| 156 | - tkagg.blit(self._tkphoto, self.renderer._renderer, 2) | ||
| 156 | + tkagg.blit(self._tkphoto, self.renderer._renderer, bbox=bbox, colormode=2) | ||
| 157 | 157 | self._master.update_idletasks() | |
| 158 | 158 | ||
| 159 | 159 | show = draw | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,17 +1,17 @@ | |||
| 1 | 1 | import _tkagg | |
| 2 | 2 | import Tkinter as Tk | |
| 3 | 3 | ||
| 4 | - def blit(photoimage, aggimage, colormode=1): | ||
| 4 | + def blit(photoimage, aggimage, bbox=None, colormode=1): | ||
| 5 | 5 | tk = photoimage.tk | |
| 6 | 6 | try: | |
| 7 | - tk.call("PyAggImagePhoto", photoimage, id(aggimage), colormode) | ||
| 7 | + tk.call("PyAggImagePhoto", photoimage, id(aggimage), colormode, id(bbox)) | ||
| 8 | 8 | except Tk.TclError, v: | |
| 9 | 9 | try: | |
| 10 | 10 | try: | |
| 11 | 11 | _tkagg.tkinit(tk.interpaddr(), 1) | |
| 12 | 12 | except AttributeError: | |
| 13 | 13 | _tkagg.tkinit(id(tk), 0) | |
| 14 | - tk.call("PyAggImagePhoto", photoimage, id(aggimage), colormode) | ||
| 14 | + tk.call("PyAggImagePhoto", photoimage, id(aggimage), colormode, id(bbox)) | ||
| 15 | 15 | except (ImportError, AttributeError, Tk.TclError): | |
| 16 | 16 | raise | |
| 17 | 17 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -13,6 +13,7 @@ | |||
| 13 | 13 | #include <stdlib.h> | |
| 14 | 14 | ||
| 15 | 15 | #include "_backend_agg.h" | |
| 16 | + #include "_transforms.h" | ||
| 16 | 17 | ||
| 17 | 18 | extern "C" { | |
| 18 | 19 | #ifdef __APPLE__ | |
@@ -41,10 +42,15 @@ PyAggImagePhoto(ClientData clientdata, Tcl_Interp* interp, | |||
| 41 | 42 | Tk_PhotoHandle photo; | |
| 42 | 43 | Tk_PhotoImageBlock block; | |
| 43 | 44 | PyObject* aggo; | |
| 45 | + | ||
| 46 | + // vars for blitting | ||
| 47 | + PyObject* bboxo; | ||
| 48 | + Bbox* bbox; | ||
| 49 | + double l,b,r,t; | ||
| 44 | 50 | ||
| 45 | 51 | long mode; | |
| 46 | 52 | long nval; | |
| 47 | - if (argc != 4) { | ||
| 53 | + if (argc != 5) { | ||
| 48 | 54 | Tcl_AppendResult(interp, "usage: ", argv[0], | |
| 49 | 55 | " destPhoto srcImage", (char *) NULL); | |
| 50 | 56 | return TCL_ERROR; | |
@@ -69,6 +75,23 @@ PyAggImagePhoto(ClientData clientdata, Tcl_Interp* interp, | |||
| 69 | 75 | return TCL_ERROR; | |
| 70 | 76 | } | |
| 71 | 77 | ||
| 78 | + /* check for bbox/blitting */ | ||
| 79 | + bboxo = (PyObject*)atol(argv[4]); | ||
| 80 | + if (bboxo != Py_None) { | ||
| 81 | + bbox = (Bbox*)bboxo; | ||
| 82 | + l = bbox->ll_api()->x_api()->val(); | ||
| 83 | + b = bbox->ll_api()->y_api()->val(); | ||
| 84 | + r = bbox->ur_api()->x_api()->val(); | ||
| 85 | + t = bbox->ur_api()->y_api()->val(); | ||
| 86 | + // int casts messes up precision, so must round | ||
| 87 | + l = round(l); | ||
| 88 | + b = round(b); | ||
| 89 | + r = round(r); | ||
| 90 | + t = round(t); | ||
| 91 | + } else { | ||
| 92 | + bbox = NULL; | ||
| 93 | + } | ||
| 94 | + | ||
| 72 | 95 | /* setup tkblock */ | |
| 73 | 96 | block.pixelSize = 1; | |
| 74 | 97 | if (mode == 0) { | |
@@ -87,16 +110,22 @@ PyAggImagePhoto(ClientData clientdata, Tcl_Interp* interp, | |||
| 87 | 110 | block.pixelSize = 4; | |
| 88 | 111 | nval = 4; | |
| 89 | 112 | } | |
| 90 | - } | ||
| 113 | + } | ||
| 114 | + | ||
| 91 | 115 | block.width = aggRenderer->get_width(); | |
| 92 | 116 | block.height = aggRenderer->get_height(); | |
| 93 | 117 | //std::cout << "w,h: " << block.width << " " << block.height << std::endl; | |
| 94 | 118 | block.pitch = block.width * nval; | |
| 95 | 119 | block.pixelPtr = aggRenderer->pixBuffer; | |
| 96 | - /* Clear current contents */ | ||
| 97 | - Tk_PhotoBlank(photo); | ||
| 98 | - /* Copy opaque block to photo image, and leave the rest to TK */ | ||
| 99 | - Tk_PhotoPutBlock(photo, &block, 0, 0, block.width, block.height); | ||
| 120 | + | ||
| 121 | + if (bbox) { | ||
| 122 | + Tk_PhotoPutBlock(photo, &block, (int)l, (int)b, (int)(r-l), (int)(t-b)); | ||
| 123 | + } else { | ||
| 124 | + /* Clear current contents */ | ||
| 125 | + Tk_PhotoBlank(photo); | ||
| 126 | + /* Copy opaque block to photo image, and leave the rest to TK */ | ||
| 127 | + Tk_PhotoPutBlock(photo, &block, 0, 0, block.width, block.height); | ||
| 128 | + } | ||
| 100 | 129 | ||
| 101 | 130 | return TCL_OK; | |
| 102 | 131 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments