assign new pixmap via constructor and operator
fluxgen fluxgen
2 files changed,
84 insertions(+),
7 deletions(-)
M
src/FbTk/FbPixmap.cc
→
src/FbTk/FbPixmap.cc
@@ -19,7 +19,7 @@ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: FbPixmap.cc,v 1.1 2003/04/25 12:29:49 fluxgen Exp $ +// $Id: FbPixmap.cc,v 1.2 2003/04/27 00:12:17 fluxgen Exp $ #include "FbPixmap.hh" #include "App.hh"@@ -31,9 +31,18 @@ m_width(0), m_height(0),
m_depth(0) { } FbPixmap::FbPixmap(const FbPixmap &the_copy):m_pm(0), - m_width(0), m_height(0), - m_depth(0) { + m_width(0), m_height(0), + m_depth(0) { copy(the_copy); +} + +FbPixmap::FbPixmap(Pixmap pm):m_pm(0), + m_width(0), m_height(0), + m_depth(0) { + if (pm == 0) + return; + // assign X pixmap to this + (*this) = pm; } FbPixmap::FbPixmap(Drawable src,@@ -96,9 +105,69 @@ copy(the_copy);
return *this; } +FbPixmap &FbPixmap::operator = (Pixmap pm) { + // free pixmap before we set new + free(); + + if (pm == 0) + return *this; + + // get width, height and depth for the pixmap + Window root; + int x, y; + unsigned int border_width, bpp; + XGetGeometry(FbTk::App::instance()->display(), + pm, + &root, + &x, &y, + &m_width, &m_height, + &border_width, + &bpp); + + m_depth = bpp; + + m_pm = pm; + + return *this; +} + void FbPixmap::copy(const FbPixmap &the_copy) { - free(); - create(the_copy.drawable(), the_copy.width(), the_copy.height(), the_copy.depth()); + + bool create_new = false; + + if (the_copy.width() != width() || + the_copy.height() != height() || + the_copy.depth() != depth() || + drawable() == 0) + create_new = true; + + if (create_new) + free(); + + if (the_copy.drawable() != 0) { + if (create_new) { + create(the_copy.drawable(), + the_copy.width(), the_copy.height(), + the_copy.depth()); + } + + if (drawable()) { + Display *dpy = FbTk::App::instance()->display(); + GC temp_gc = XCreateGC(dpy, + drawable(), + 0, 0); + + copyArea(the_copy.drawable(), + temp_gc, + 0, 0, + 0, 0, + width(), height()); + + XFreeGC(dpy, temp_gc); + + } + + } } void FbPixmap::free() {
M
src/FbTk/FbPixmap.hh
→
src/FbTk/FbPixmap.hh
@@ -19,7 +19,7 @@ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: FbPixmap.hh,v 1.1 2003/04/25 12:29:49 fluxgen Exp $ +// $Id: FbPixmap.hh,v 1.2 2003/04/27 00:10:28 fluxgen Exp $ #ifndef FBTK_FBPIXMAP_HH #define FBTK_FBPIXMAP_HH@@ -32,11 +32,16 @@ /// a wrapper for X Pixmap
class FbPixmap { public: FbPixmap(); - FbPixmap(const FbPixmap ©); + /// copy pixmap + explicit FbPixmap(const FbPixmap ©); + /// creates a FbPixmap from X pixmap + explicit FbPixmap(Pixmap pm); FbPixmap(Drawable src, unsigned int width, unsigned int height, int depth); + ~FbPixmap(); + void copyArea(Drawable src, GC gc, int src_x, int src_y, int dest_x, int dest_y,@@ -48,7 +53,10 @@ unsigned int width, unsigned int height);
void fillPolygon(GC gc, XPoint *points, int npoints, int shape, int mode); void copy(const FbPixmap &the_copy); + FbPixmap &operator = (const FbPixmap ©); + /// sets new pixmap + FbPixmap &operator = (Pixmap pm); inline Drawable drawable() const { return m_pm; } inline unsigned int width() const { return m_width; }