cleaning, using FbPixmap

This commit is contained in:
fluxgen 2004-01-11 12:52:37 +00:00
parent abe0204256
commit 766a385c83

View file

@ -22,12 +22,14 @@
// 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: TextureRender.cc,v 1.5 2003/10/02 16:14:41 rathnor Exp $ // $Id: TextureRender.cc,v 1.6 2004/01/11 12:52:37 fluxgen Exp $
#include "TextureRender.hh" #include "TextureRender.hh"
#include "ImageControl.hh" #include "ImageControl.hh"
#include "App.hh" #include "App.hh"
#include "FbPixmap.hh"
#include "GContext.hh"
#include <iostream> #include <iostream>
#include <string> #include <string>
@ -114,94 +116,85 @@ Pixmap TextureRender::renderSolid(const FbTk::Texture &texture) {
Display *disp = FbTk::App::instance()->display(); Display *disp = FbTk::App::instance()->display();
Pixmap pixmap = XCreatePixmap(disp, FbPixmap pixmap(RootWindow(disp, control.screenNum()),
RootWindow(disp, control.screenNum()), width, width, height,
height, control.depth()); control.depth());
if (pixmap == None) {
if (pixmap.drawable() == None) {
cerr<<"FbTk::TextureRender::render_solid(): error creating pixmap"<<endl; cerr<<"FbTk::TextureRender::render_solid(): error creating pixmap"<<endl;
return None; return None;
} }
XGCValues gcv;
GC gc, hgc, lgc;
gcv.foreground = texture.color().pixel(); FbTk::GContext gc(pixmap),
gcv.fill_style = FillSolid; hgc(pixmap), lgc(pixmap);
gc = XCreateGC(disp, pixmap, GCForeground | GCFillStyle, &gcv);
gcv.foreground = texture.hiColor().pixel(); gc.setForeground(texture.color());
hgc = XCreateGC(disp, pixmap, GCForeground, &gcv); gc.setFillStyle(FillSolid);
gcv.foreground = texture.loColor().pixel(); hgc.setForeground(texture.hiColor());
lgc = XCreateGC(disp, pixmap, GCForeground, &gcv);
XFillRectangle(disp, pixmap, gc, 0, 0, width, height); pixmap.fillRectangle(gc.gc(), 0, 0, width, height);
using namespace FbTk; using namespace FbTk;
if (texture.type() & Texture::INTERLACED) { if (texture.type() & Texture::INTERLACED) {
gcv.foreground = texture.colorTo().pixel(); lgc.setForeground(texture.colorTo());
GC igc = XCreateGC(disp, pixmap,
GCForeground, &gcv);
register unsigned int i = 0; register unsigned int i = 0;
for (; i < height; i += 2) for (; i < height; i += 2)
XDrawLine(disp, pixmap, igc, 0, i, width, i); pixmap.drawLine(lgc.gc(), 0, i, width, i);
XFreeGC(disp, igc);
} }
lgc.setForeground(texture.loColor());
if (texture.type() & Texture::BEVEL1) { if (texture.type() & Texture::BEVEL1) {
if (texture.type() & Texture::RAISED) { if (texture.type() & Texture::RAISED) {
XDrawLine(disp, pixmap, lgc, pixmap.drawLine(lgc.gc(),
0, height - 1, width - 1, height - 1); 0, height - 1, width - 1, height - 1);
XDrawLine(disp, pixmap, lgc, pixmap.drawLine(lgc.gc(),
width - 1, height - 1, width - 1, 0); width - 1, height - 1, width - 1, 0);
XDrawLine(disp, pixmap, hgc, pixmap.drawLine(hgc.gc(),
0, 0, width - 1, 0); 0, 0, width - 1, 0);
XDrawLine(disp, pixmap, hgc, pixmap.drawLine(hgc.gc(),
0, height - 1, 0, 0); 0, height - 1, 0, 0);
} else if (texture.type() & Texture::SUNKEN) { } else if (texture.type() & Texture::SUNKEN) {
XDrawLine(disp, pixmap, hgc, pixmap.drawLine(hgc.gc(),
0, height - 1, width - 1, height - 1); 0, height - 1, width - 1, height - 1);
XDrawLine(disp, pixmap, hgc, pixmap.drawLine(hgc.gc(),
width - 1, height - 1, width - 1, 0); width - 1, height - 1, width - 1, 0);
XDrawLine(disp, pixmap, lgc, pixmap.drawLine(lgc.gc(),
0, 0, width - 1, 0); 0, 0, width - 1, 0);
XDrawLine(disp, pixmap, lgc, pixmap.drawLine(lgc.gc(),
0, height - 1, 0, 0); 0, height - 1, 0, 0);
} }
} else if (texture.type() & Texture::BEVEL2) { } else if (texture.type() & Texture::BEVEL2) {
if (texture.type() & Texture::RAISED) { if (texture.type() & Texture::RAISED) {
XDrawLine(disp, pixmap, lgc, pixmap.drawLine(lgc.gc(),
1, height - 3, width - 3, height - 3); 1, height - 3, width - 3, height - 3);
XDrawLine(disp, pixmap, lgc, pixmap.drawLine(lgc.gc(),
width - 3, height - 3, width - 3, 1); width - 3, height - 3, width - 3, 1);
XDrawLine(disp, pixmap, hgc, pixmap.drawLine(hgc.gc(),
1, 1, width - 3, 1); 1, 1, width - 3, 1);
XDrawLine(disp, pixmap, hgc, pixmap.drawLine(hgc.gc(),
1, height - 3, 1, 1); 1, height - 3, 1, 1);
} else if (texture.type() & Texture::SUNKEN) { } else if (texture.type() & Texture::SUNKEN) {
XDrawLine(disp, pixmap, hgc, pixmap.drawLine(hgc.gc(),
1, height - 3, width - 3, height - 3); 1, height - 3, width - 3, height - 3);
XDrawLine(disp, pixmap, hgc, pixmap.drawLine(hgc.gc(),
width - 3, height - 3, width - 3, 1); width - 3, height - 3, width - 3, 1);
XDrawLine(disp, pixmap, lgc, pixmap.drawLine(lgc.gc(),
1, 1, width - 3, 1); 1, 1, width - 3, 1);
XDrawLine(disp, pixmap, lgc, pixmap.drawLine(lgc.gc(),
1, height - 3, 1, 1); 1, height - 3, 1, 1);
} }
} }
XFreeGC(disp, gc); return pixmap.release();
XFreeGC(disp, hgc);
XFreeGC(disp, lgc);
return pixmap;
} }
@ -666,11 +659,10 @@ return image;
Pixmap TextureRender::renderPixmap() { Pixmap TextureRender::renderPixmap() {
Display *disp = FbTk::App::instance()->display(); Display *disp = FbTk::App::instance()->display();
Pixmap pixmap = FbPixmap pixmap(RootWindow(disp, control.screenNum()),
XCreatePixmap(disp, width, height, control.depth());
RootWindow(disp, control.screenNum()), width, height, control.depth());
if (pixmap == None) { if (pixmap.drawable() == None) {
cerr<<"TextureRender::renderPixmap(): error creating pixmap"<<endl; cerr<<"TextureRender::renderPixmap(): error creating pixmap"<<endl;
return None; return None;
} }
@ -678,15 +670,13 @@ Pixmap TextureRender::renderPixmap() {
XImage *image = renderXImage(); XImage *image = renderXImage();
if (! image) { if (! image) {
XFreePixmap(disp, pixmap);
return None; return None;
} else if (! image->data) { } else if (! image->data) {
XDestroyImage(image); XDestroyImage(image);
XFreePixmap(disp, pixmap);
return None; return None;
} }
XPutImage(disp, pixmap, XPutImage(disp, pixmap.drawable(),
DefaultGC(disp, control.screenNum()), DefaultGC(disp, control.screenNum()),
image, 0, 0, 0, 0, width, height); image, 0, 0, 0, 0, width, height);
@ -697,7 +687,7 @@ Pixmap TextureRender::renderPixmap() {
XDestroyImage(image); XDestroyImage(image);
return pixmap; return pixmap.release();
} }