From 4e9eac4824ba042f0a192b51758ce68293c16582 Mon Sep 17 00:00:00 2001
From: fluxgen <fluxgen>
Date: Sun, 27 Apr 2003 00:12:17 +0000
Subject: assign new pixmap via constructor and operator

---
 src/FbTk/FbPixmap.cc | 79 ++++++++++++++++++++++++++++++++++++++++++++++++----
 src/FbTk/FbPixmap.hh | 12 ++++++--
 2 files changed, 84 insertions(+), 7 deletions(-)

diff --git a/src/FbTk/FbPixmap.cc b/src/FbTk/FbPixmap.cc
index 7f358d1..c966ab6 100644
--- a/src/FbTk/FbPixmap.cc
+++ b/src/FbTk/FbPixmap.cc
@@ -19,7 +19,7 @@
 // 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,11 +31,20 @@ FbPixmap::FbPixmap():m_pm(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, 
                    unsigned int width, unsigned int height,
                    int depth):m_pm(0), 
@@ -96,9 +105,69 @@ FbPixmap &FbPixmap::operator = (const FbPixmap &the_copy) {
     return *this;
 }
 
-void FbPixmap::copy(const FbPixmap &the_copy) {
+FbPixmap &FbPixmap::operator = (Pixmap pm) {
+    // free pixmap before we set new
     free();
-    create(the_copy.drawable(), the_copy.width(), the_copy.height(), the_copy.depth());
+
+    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) {
+
+    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() {
diff --git a/src/FbTk/FbPixmap.hh b/src/FbTk/FbPixmap.hh
index 05f05e3..a8f9472 100644
--- a/src/FbTk/FbPixmap.hh
+++ b/src/FbTk/FbPixmap.hh
@@ -19,7 +19,7 @@
 // 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 @@ namespace FbTk {
 class FbPixmap {
 public:    
     FbPixmap();
-    FbPixmap(const FbPixmap &copy);
+    /// copy pixmap 
+    explicit FbPixmap(const FbPixmap &copy);
+    /// 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 @@ public:
     void fillPolygon(GC gc, XPoint *points, int npoints,
                      int shape, int mode);
     void copy(const FbPixmap &the_copy);
+
     FbPixmap &operator = (const FbPixmap &copy);
+    /// sets new pixmap
+    FbPixmap &operator = (Pixmap pm);
 
     inline Drawable drawable() const { return m_pm; }
     inline unsigned int width() const { return m_width; }
-- 
cgit v0.11.2