]> git.saurik.com Git - wxWidgets.git/commitdiff
memdc and bitmap fixes
authorRobert Roebling <robert@roebling.de>
Mon, 13 Jul 1998 17:00:29 +0000 (17:00 +0000)
committerRobert Roebling <robert@roebling.de>
Mon, 13 Jul 1998 17:00:29 +0000 (17:00 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@260 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/gtk/dcclient.h
include/wx/gtk/dcmemory.h
include/wx/gtk1/dcclient.h
include/wx/gtk1/dcmemory.h
src/gtk/bitmap.cpp
src/gtk/dcclient.cpp
src/gtk/dcmemory.cpp
src/gtk1/bitmap.cpp
src/gtk1/dcclient.cpp
src/gtk1/dcmemory.cpp
user/wxTest/wxTest.cpp

index 7ae3e3099c75f8b26ce3648e672cb749b3e8ffa9..b85fb317d1f9d3d0be0a38778ec40ceac90b65b3 100644 (file)
@@ -99,6 +99,7 @@ class wxPaintDC: public wxDC
     GdkGC        *m_textGC;
     GdkGC        *m_bgGC;
     GdkColormap  *m_cmap;
+    bool          m_isDrawable;
     
     void SetUpDC(void);
     GdkWindow *GetWindow(void);
index 7afbb3295d640c2f22d3aa229b8147f9b4bac740..c5854c5110f9c8c3945f0576004d952c883c947e 100644 (file)
@@ -38,7 +38,7 @@ class WXDLLEXPORT wxMemoryDC: public wxPaintDC
     wxMemoryDC( wxDC *dc ); // Create compatible DC
     ~wxMemoryDC(void);
     virtual void SelectObject( const wxBitmap& bitmap );
-    void GetSize( int *width, int *height );
+    void GetSize( int *width, int *height ) const;
 
   private: 
     friend wxPaintDC;
index 7ae3e3099c75f8b26ce3648e672cb749b3e8ffa9..b85fb317d1f9d3d0be0a38778ec40ceac90b65b3 100644 (file)
@@ -99,6 +99,7 @@ class wxPaintDC: public wxDC
     GdkGC        *m_textGC;
     GdkGC        *m_bgGC;
     GdkColormap  *m_cmap;
+    bool          m_isDrawable;
     
     void SetUpDC(void);
     GdkWindow *GetWindow(void);
index 7afbb3295d640c2f22d3aa229b8147f9b4bac740..c5854c5110f9c8c3945f0576004d952c883c947e 100644 (file)
@@ -38,7 +38,7 @@ class WXDLLEXPORT wxMemoryDC: public wxPaintDC
     wxMemoryDC( wxDC *dc ); // Create compatible DC
     ~wxMemoryDC(void);
     virtual void SelectObject( const wxBitmap& bitmap );
-    void GetSize( int *width, int *height );
+    void GetSize( int *width, int *height ) const;
 
   private: 
     friend wxPaintDC;
index 05c3136acc931d021e1589e97e9bc9ede7f71add..7ae387a2f5968f063e75b413cee7ec904f6b4b7c 100644 (file)
@@ -89,6 +89,9 @@ wxBitmapRefData::wxBitmapRefData(void)
   m_height = 0;
   m_bpp = 0;
   m_palette = NULL;
+#ifdef USE_GDK_IMLIB
+  m_image = NULL;
+#endif
 };
 
 wxBitmapRefData::~wxBitmapRefData(void)
@@ -121,7 +124,8 @@ wxBitmap::wxBitmap( int width, int height, int depth )
   M_BMPDATA->m_mask = NULL;
   M_BMPDATA->m_pixmap = 
     gdk_pixmap_new( (GdkWindow*) &gdk_root_parent, width, height, depth );
-  gdk_window_get_size( M_BMPDATA->m_pixmap, &(M_BMPDATA->m_width), &(M_BMPDATA->m_height) );
+  M_BMPDATA->m_width = width;
+  M_BMPDATA->m_height = height;
   M_BMPDATA->m_bpp = depth;
    
   if (wxTheBitmapList) wxTheBitmapList->AddBitmap(this);
@@ -144,6 +148,8 @@ wxBitmap::wxBitmap( char **bits )
     M_BMPDATA->m_mask->m_bitmap = mask;
   };
   
+  gdk_window_get_size( M_BMPDATA->m_pixmap, &(M_BMPDATA->m_width), &(M_BMPDATA->m_height) );
+  
 #else
 
   M_BMPDATA->m_image = gdk_imlib_create_image_from_xpm_data( bits );
@@ -151,7 +157,6 @@ wxBitmap::wxBitmap( char **bits )
   
 #endif
                                  
-  gdk_window_get_size( M_BMPDATA->m_pixmap, &(M_BMPDATA->m_width), &(M_BMPDATA->m_height) );
   M_BMPDATA->m_bpp = 24; // ?
    
   if (wxTheBitmapList) wxTheBitmapList->AddBitmap(this);
@@ -184,7 +189,8 @@ wxBitmap::wxBitmap( const char bits[], int width, int height, int WXUNUSED(depth
   M_BMPDATA->m_mask = NULL;
   M_BMPDATA->m_bitmap = 
     gdk_bitmap_create_from_data( (GdkWindow*) &gdk_root_parent, (gchar *) bits, width, height );
-  gdk_window_get_size( M_BMPDATA->m_bitmap, &(M_BMPDATA->m_width), &(M_BMPDATA->m_height) );
+  M_BMPDATA->m_width = width;
+  M_BMPDATA->m_height = height;
   M_BMPDATA->m_bpp = 1;
 
   if (wxTheBitmapList) wxTheBitmapList->AddBitmap(this);
@@ -377,7 +383,8 @@ void wxBitmap::Render(void)
 #ifdef USE_GDK_IMLIB
 
   gdk_imlib_render( M_BMPDATA->m_image, M_BMPDATA->m_image->rgb_width, M_BMPDATA->m_image->rgb_height );
-  
+  M_BMPDATA->m_width = M_BMPDATA->m_image->rgb_width;
+  M_BMPDATA->m_height = M_BMPDATA->m_image->rgb_height;
   M_BMPDATA->m_pixmap = gdk_imlib_move_image( M_BMPDATA->m_image );
   GdkBitmap *mask = gdk_imlib_move_mask( M_BMPDATA->m_image );
   if (mask)
index ee102dc06a446b54107a1f38e0db1705ba22fde2..6f44374a4b79ab14315e6bec334d4c8ea2d25936 100644 (file)
@@ -100,6 +100,9 @@ wxPaintDC::wxPaintDC( wxWindow *window )
     m_cmap = gtk_widget_get_colormap( window->m_wxwindow );
   else
     m_cmap = gtk_widget_get_colormap( window->m_widget );
+    
+  m_isDrawable = TRUE;
+        
   SetUpDC();
   
   long x = 0;
@@ -517,7 +520,18 @@ void wxPaintDC::Clear(void)
   if (!Ok()) return;
   
   DestroyClippingRegion();
-  gdk_window_clear( m_window );
+  
+  if (m_isDrawable)
+  {
+    gdk_window_clear( m_window );
+  }
+  else
+  {
+    int width = 0;
+    int height = 0;
+    GetSize( &width, &height );
+    gdk_draw_rectangle( m_window, m_brushGC, TRUE, 0, 0, width, height );
+  };
 };
 
 void wxPaintDC::SetFont( const wxFont &font )
index e947cd2ca79af57f0a13be67d08b4c553efb2f5c..66c5549f5278feb1f698e28a1a870bb7f775032c 100644 (file)
@@ -51,6 +51,8 @@ void wxMemoryDC::SelectObject( const wxBitmap& bitmap )
     }
     
     SetUpDC();
+    
+    m_isDrawable = FALSE;
   }
   else
   {
@@ -59,7 +61,7 @@ void wxMemoryDC::SelectObject( const wxBitmap& bitmap )
   };
 };
 
-void wxMemoryDC::GetSize( int *width, int *height )
+void wxMemoryDC::GetSize( int *width, int *height ) const
 {
   if (m_selected.Ok())
   {
index 05c3136acc931d021e1589e97e9bc9ede7f71add..7ae387a2f5968f063e75b413cee7ec904f6b4b7c 100644 (file)
@@ -89,6 +89,9 @@ wxBitmapRefData::wxBitmapRefData(void)
   m_height = 0;
   m_bpp = 0;
   m_palette = NULL;
+#ifdef USE_GDK_IMLIB
+  m_image = NULL;
+#endif
 };
 
 wxBitmapRefData::~wxBitmapRefData(void)
@@ -121,7 +124,8 @@ wxBitmap::wxBitmap( int width, int height, int depth )
   M_BMPDATA->m_mask = NULL;
   M_BMPDATA->m_pixmap = 
     gdk_pixmap_new( (GdkWindow*) &gdk_root_parent, width, height, depth );
-  gdk_window_get_size( M_BMPDATA->m_pixmap, &(M_BMPDATA->m_width), &(M_BMPDATA->m_height) );
+  M_BMPDATA->m_width = width;
+  M_BMPDATA->m_height = height;
   M_BMPDATA->m_bpp = depth;
    
   if (wxTheBitmapList) wxTheBitmapList->AddBitmap(this);
@@ -144,6 +148,8 @@ wxBitmap::wxBitmap( char **bits )
     M_BMPDATA->m_mask->m_bitmap = mask;
   };
   
+  gdk_window_get_size( M_BMPDATA->m_pixmap, &(M_BMPDATA->m_width), &(M_BMPDATA->m_height) );
+  
 #else
 
   M_BMPDATA->m_image = gdk_imlib_create_image_from_xpm_data( bits );
@@ -151,7 +157,6 @@ wxBitmap::wxBitmap( char **bits )
   
 #endif
                                  
-  gdk_window_get_size( M_BMPDATA->m_pixmap, &(M_BMPDATA->m_width), &(M_BMPDATA->m_height) );
   M_BMPDATA->m_bpp = 24; // ?
    
   if (wxTheBitmapList) wxTheBitmapList->AddBitmap(this);
@@ -184,7 +189,8 @@ wxBitmap::wxBitmap( const char bits[], int width, int height, int WXUNUSED(depth
   M_BMPDATA->m_mask = NULL;
   M_BMPDATA->m_bitmap = 
     gdk_bitmap_create_from_data( (GdkWindow*) &gdk_root_parent, (gchar *) bits, width, height );
-  gdk_window_get_size( M_BMPDATA->m_bitmap, &(M_BMPDATA->m_width), &(M_BMPDATA->m_height) );
+  M_BMPDATA->m_width = width;
+  M_BMPDATA->m_height = height;
   M_BMPDATA->m_bpp = 1;
 
   if (wxTheBitmapList) wxTheBitmapList->AddBitmap(this);
@@ -377,7 +383,8 @@ void wxBitmap::Render(void)
 #ifdef USE_GDK_IMLIB
 
   gdk_imlib_render( M_BMPDATA->m_image, M_BMPDATA->m_image->rgb_width, M_BMPDATA->m_image->rgb_height );
-  
+  M_BMPDATA->m_width = M_BMPDATA->m_image->rgb_width;
+  M_BMPDATA->m_height = M_BMPDATA->m_image->rgb_height;
   M_BMPDATA->m_pixmap = gdk_imlib_move_image( M_BMPDATA->m_image );
   GdkBitmap *mask = gdk_imlib_move_mask( M_BMPDATA->m_image );
   if (mask)
index ee102dc06a446b54107a1f38e0db1705ba22fde2..6f44374a4b79ab14315e6bec334d4c8ea2d25936 100644 (file)
@@ -100,6 +100,9 @@ wxPaintDC::wxPaintDC( wxWindow *window )
     m_cmap = gtk_widget_get_colormap( window->m_wxwindow );
   else
     m_cmap = gtk_widget_get_colormap( window->m_widget );
+    
+  m_isDrawable = TRUE;
+        
   SetUpDC();
   
   long x = 0;
@@ -517,7 +520,18 @@ void wxPaintDC::Clear(void)
   if (!Ok()) return;
   
   DestroyClippingRegion();
-  gdk_window_clear( m_window );
+  
+  if (m_isDrawable)
+  {
+    gdk_window_clear( m_window );
+  }
+  else
+  {
+    int width = 0;
+    int height = 0;
+    GetSize( &width, &height );
+    gdk_draw_rectangle( m_window, m_brushGC, TRUE, 0, 0, width, height );
+  };
 };
 
 void wxPaintDC::SetFont( const wxFont &font )
index e947cd2ca79af57f0a13be67d08b4c553efb2f5c..66c5549f5278feb1f698e28a1a870bb7f775032c 100644 (file)
@@ -51,6 +51,8 @@ void wxMemoryDC::SelectObject( const wxBitmap& bitmap )
     }
     
     SetUpDC();
+    
+    m_isDrawable = FALSE;
   }
   else
   {
@@ -59,7 +61,7 @@ void wxMemoryDC::SelectObject( const wxBitmap& bitmap )
   };
 };
 
-void wxMemoryDC::GetSize( int *width, int *height )
+void wxMemoryDC::GetSize( int *width, int *height ) const
 {
   if (m_selected.Ok())
   {
index c9d48c20455842e96c18301d82eafbefe32d845b..e6e58613dd838689baebd8abe547124f2bf9a88d 100644 (file)
@@ -348,6 +348,7 @@ void MyCanvas::OnPaint( wxPaintEvent &WXUNUSED(event) )
 
   wxMemoryDC memDC;
   memDC.SelectObject( *my_backstore );
+  memDC.Clear();
   memDC.SetBrush( *wxBLACK_BRUSH );
   memDC.SetPen( *wxWHITE_PEN );
   memDC.DrawRectangle( 0, 0, 150, 150 );