This commit is contained in:
fluxgen 2003-09-10 21:37:05 +00:00
parent 8c9818a84b
commit d9f17a17c3

View file

@ -19,10 +19,11 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// $Id: FbPixmap.cc,v 1.7 2003/08/12 00:25:23 fluxgen Exp $ // $Id: FbPixmap.cc,v 1.8 2003/09/10 21:37:05 fluxgen Exp $
#include "FbPixmap.hh" #include "FbPixmap.hh"
#include "App.hh" #include "App.hh"
#include "GContext.hh"
#include <X11/Xutil.h> #include <X11/Xutil.h>
#include <iostream> #include <iostream>
@ -115,20 +116,14 @@ void FbPixmap::copy(const FbPixmap &the_copy) {
if (drawable()) { if (drawable()) {
Display *dpy = FbTk::App::instance()->display(); Display *dpy = FbTk::App::instance()->display();
GC temp_gc = XCreateGC(dpy, GContext gc(drawable());
drawable(),
0, 0);
copyArea(the_copy.drawable(), copyArea(the_copy.drawable(),
temp_gc, gc.gc(),
0, 0, 0, 0,
0, 0, 0, 0,
width(), height()); width(), height());
XFreeGC(dpy, temp_gc);
} }
} }
} }
@ -178,17 +173,16 @@ void FbPixmap::rotate() {
// reverse height/width for new pixmap // reverse height/width for new pixmap
FbPixmap new_pm(drawable(), height(), width(), depth()); FbPixmap new_pm(drawable(), height(), width(), depth());
GC gc = XCreateGC(dpy, drawable(), 0, 0); GContext gc(drawable());
// copy new area // copy new area
for (int y = 0; y < height(); ++y) { for (int y = 0; y < height(); ++y) {
for (int x = 0; x < width(); ++x) { for (int x = 0; x < width(); ++x) {
XSetForeground(dpy, gc, XGetPixel(src_image, x, y)); gc.setForeground(XGetPixel(src_image, x, y));
// revers coordinates // revers coordinates
XDrawPoint(dpy, new_pm.drawable(), gc, y, x); XDrawPoint(dpy, new_pm.drawable(), gc.gc(), y, x);
} }
} }
XFreeGC(dpy, gc);
XDestroyImage(src_image); XDestroyImage(src_image);
// free old pixmap and set new from new_pm // free old pixmap and set new from new_pm
@ -218,8 +212,7 @@ void FbPixmap::scale(unsigned int dest_width, unsigned int dest_height) {
// create new pixmap with dest size // create new pixmap with dest size
FbPixmap new_pm(drawable(), dest_width, dest_height, depth()); FbPixmap new_pm(drawable(), dest_width, dest_height, depth());
GC gc = XCreateGC(dpy, drawable(), 0, 0); GContext gc(drawable());
// calc zoom // calc zoom
float zoom_x = static_cast<float>(width())/static_cast<float>(dest_width); float zoom_x = static_cast<float>(width())/static_cast<float>(dest_width);
float zoom_y = static_cast<float>(height())/static_cast<float>(dest_height); float zoom_y = static_cast<float>(height())/static_cast<float>(dest_height);
@ -229,16 +222,13 @@ void FbPixmap::scale(unsigned int dest_width, unsigned int dest_height) {
for (int tx=0; tx<dest_width; ++tx, src_x += zoom_x) { for (int tx=0; tx<dest_width; ++tx, src_x += zoom_x) {
src_y = 0; src_y = 0;
for (int ty=0; ty<dest_height; ++ty, src_y += zoom_y) { for (int ty=0; ty<dest_height; ++ty, src_y += zoom_y) {
XSetForeground(dpy, gc, XGetPixel(src_image, gc.setForeground(XGetPixel(src_image,
static_cast<int>(src_x), static_cast<int>(src_x),
static_cast<int>(src_y))); static_cast<int>(src_y)));
XDrawPoint(dpy, new_pm.drawable(), gc, tx, ty); XDrawPoint(dpy, new_pm.drawable(), gc.gc(), tx, ty);
} }
} }
XFreeGC(dpy, gc);
XDestroyImage(src_image); XDestroyImage(src_image);
// free old pixmap and set new from new_pm // free old pixmap and set new from new_pm
@ -250,6 +240,11 @@ void FbPixmap::scale(unsigned int dest_width, unsigned int dest_height) {
m_pm = new_pm.release(); m_pm = new_pm.release();
} }
void FbPixmap::resize(unsigned int width, unsigned int height) {
FbPixmap pm(drawable(), width, height, depth());
*this = pm.release();
}
Pixmap FbPixmap::release() { Pixmap FbPixmap::release() {
Pixmap ret = m_pm; Pixmap ret = m_pm;
m_pm = 0; m_pm = 0;