aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfluxgen <fluxgen>2003-04-27 23:56:13 (GMT)
committerfluxgen <fluxgen>2003-04-27 23:56:13 (GMT)
commit45fff3a4b21e60c93f8c4a6fa9601f7005dac4eb (patch)
treea367a479e3e763b3aa274ddc2443f5fa2fb58575
parent1db7e5fb0cce6cdfaa34a7bc3426587b3b288444 (diff)
downloadfluxbox-45fff3a4b21e60c93f8c4a6fa9601f7005dac4eb.zip
fluxbox-45fff3a4b21e60c93f8c4a6fa9601f7005dac4eb.tar.bz2
fixed scaling and bug in copyArea
-rw-r--r--src/FbTk/FbPixmap.cc70
1 files changed, 67 insertions, 3 deletions
diff --git a/src/FbTk/FbPixmap.cc b/src/FbTk/FbPixmap.cc
index c966ab6..c627779 100644
--- a/src/FbTk/FbPixmap.cc
+++ b/src/FbTk/FbPixmap.cc
@@ -19,11 +19,15 @@
19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20// DEALINGS IN THE SOFTWARE. 20// DEALINGS IN THE SOFTWARE.
21 21
22// $Id: FbPixmap.cc,v 1.2 2003/04/27 00:12:17 fluxgen Exp $ 22// $Id: FbPixmap.cc,v 1.3 2003/04/27 23:56:13 fluxgen Exp $
23 23
24#include "FbPixmap.hh" 24#include "FbPixmap.hh"
25#include "App.hh" 25#include "App.hh"
26 26
27#include <X11/Xutil.h>
28#include <iostream>
29using namespace std;
30
27namespace FbTk { 31namespace FbTk {
28 32
29FbPixmap::FbPixmap():m_pm(0), 33FbPixmap::FbPixmap():m_pm(0),
@@ -67,8 +71,8 @@ void FbPixmap::copyArea(Drawable src, GC gc,
67 XCopyArea(FbTk::App::instance()->display(), 71 XCopyArea(FbTk::App::instance()->display(),
68 src, m_pm, gc, 72 src, m_pm, gc,
69 src_x, src_y, 73 src_x, src_y,
70 dest_x, dest_y, 74 width, height,
71 width, height); 75 dest_x, dest_y);
72} 76}
73 77
74void FbPixmap::fillRectangle(GC gc, int x, int y, 78void FbPixmap::fillRectangle(GC gc, int x, int y,
@@ -170,6 +174,66 @@ void FbPixmap::copy(const FbPixmap &the_copy) {
170 } 174 }
171} 175}
172 176
177void FbPixmap::scale(unsigned int dest_width, unsigned int dest_height) {
178 if (drawable() == 0 ||
179 (dest_width == width() && dest_height == height()))
180 return;
181
182 Display *dpy = FbTk::App::instance()->display();
183
184 XImage *src_image = XGetImage(dpy, drawable(),
185 0, 0, // pos
186 width(), height(), // size
187 ~0, // plane mask
188 ZPixmap); // format
189 if (src_image == 0)
190 return;
191
192 // create new pixmap with dest size
193 FbPixmap new_pm(drawable(), dest_width, dest_height, depth());
194
195 GC gc = XCreateGC(dpy, drawable(), 0, 0);
196
197 // calc zoom
198 float zoom_x = static_cast<float>(width())/static_cast<float>(dest_width);
199 float zoom_y = static_cast<float>(height())/static_cast<float>(dest_height);
200
201 // start scaling
202 float src_x = 0, src_y = 0;
203 for (int tx=0; tx<dest_width; ++tx, src_x += zoom_x) {
204 src_y = 0;
205 for (int ty=0; ty<dest_height; ++ty, src_y += zoom_y) {
206 XSetForeground(dpy, gc, XGetPixel(src_image,
207 static_cast<int>(src_x),
208 static_cast<int>(src_y)));
209 XDrawPoint(dpy, new_pm.drawable(), gc, tx, ty);
210
211
212 }
213 }
214
215 XFreeGC(dpy, gc);
216
217 XDestroyImage(src_image);
218
219 // free old pixmap and set new from new_pm
220 free();
221
222 m_width = new_pm.width();
223 m_height = new_pm.height();
224 m_depth = new_pm.depth();
225 m_pm = new_pm.release();
226}
227
228Pixmap FbPixmap::release() {
229 Pixmap ret = m_pm;
230 m_pm = 0;
231 m_width = 0;
232 m_height = 0;
233 m_depth = 0;
234 return ret;
235}
236
173void FbPixmap::free() { 237void FbPixmap::free() {
174 if (m_pm != 0) { 238 if (m_pm != 0) {
175 XFreePixmap(FbTk::App::instance()->display(), m_pm); 239 XFreePixmap(FbTk::App::instance()->display(), m_pm);