]> git.saurik.com Git - wxWidgets.git/commitdiff
The Image sample now does anti-aliasing, oh well.
authorRobert Roebling <robert@roebling.de>
Fri, 22 Jan 1999 18:08:54 +0000 (18:08 +0000)
committerRobert Roebling <robert@roebling.de>
Fri, 22 Jan 1999 18:08:54 +0000 (18:08 +0000)
  Made internal use of OnIdle - er - internal. (I.e.
    it doesn't use EVT_IDLE anymore and thus cannot
    be overridden by users)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1450 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/gtk/frame.h
include/wx/gtk/window.h
include/wx/gtk1/frame.h
include/wx/gtk1/window.h
samples/image/image.cpp
src/gtk/app.cpp
src/gtk/frame.cpp
src/gtk/window.cpp
src/gtk1/app.cpp
src/gtk1/frame.cpp
src/gtk1/window.cpp

index 4e02f0632430b7f2ebe523ba6d4bd65a7824e4cc..2265c07ffbacdcd47407f62e80c9dbbcaa8eec2e 100644 (file)
@@ -102,7 +102,6 @@ public:
   void OnActivate( wxActivateEvent &WXUNUSED(event) ) { } // called from docview.cpp
   void OnSize( wxSizeEvent &event );
   void OnCloseWindow( wxCloseEvent& event );
-  void OnIdle(wxIdleEvent& event );
 
   // implementation
   
@@ -111,6 +110,8 @@ public:
   void DoMenuUpdates();
   void DoMenuUpdates(wxMenu* menu);
 
+  virtual void OnInternalIdle();
+
   wxMenuBar    *m_frameMenuBar;
   wxStatusBar  *m_frameStatusBar;
   wxToolBar    *m_frameToolBar;
index 2169590c56339f3aafc2c9fadd9c3335f29b1b48..f7ca89a62db4cf7d3556319821000bbdee98f51c 100644 (file)
@@ -177,7 +177,6 @@ public:
   { wxPoint pt(ConvertDialogToPixels(wxPoint(sz.x, sz.y))); return wxSize(pt.x, pt.y); }
 
   void OnSize( wxSizeEvent &event );
-  void OnIdle( wxIdleEvent& event );
 
   virtual bool Show( bool show );
   virtual void Enable( bool enable );
@@ -316,22 +315,24 @@ public:
 
   // implementation
 
-          void        PreCreation( wxWindow *parent, wxWindowID id, const wxPoint &pos,
-                                   const wxSize &size, long style, const wxString &name );
-          void        PostCreation();
-  virtual GtkWidget  *GetConnectWidget();
-  virtual bool        IsOwnGtkWindow( GdkWindow *window );
-          void        ConnectWidget( GtkWidget *widget );
-
-          bool        HasVMT();
+  void PreCreation( wxWindow *parent, wxWindowID id, const wxPoint &pos,
+                    const wxSize &size, long style, const wxString &name );
+  void PostCreation();
+  
+  virtual GtkWidget* GetConnectWidget();
+  virtual bool IsOwnGtkWindow( GdkWindow *window );
+  void ConnectWidget( GtkWidget *widget );
 
-  virtual wxPoint     GetClientAreaOrigin() const;
-  virtual void        AdjustForParentClientOrigin( int& x, int& y, int sizeFlags );
+  bool HasVMT();
 
-          GtkStyle   *GetWidgetStyle();
-          void        SetWidgetStyle();
-  virtual void        ApplyWidgetStyle();
+  virtual wxPoint GetClientAreaOrigin() const;
+  virtual void AdjustForParentClientOrigin( int& x, int& y, int sizeFlags );
 
+  GtkStyle *GetWidgetStyle();
+  void SetWidgetStyle();
+  virtual void ApplyWidgetStyle();
+  
+  virtual void OnInternalIdle();
 
   wxWindow            *m_parent;
   wxList               m_children;
index 4e02f0632430b7f2ebe523ba6d4bd65a7824e4cc..2265c07ffbacdcd47407f62e80c9dbbcaa8eec2e 100644 (file)
@@ -102,7 +102,6 @@ public:
   void OnActivate( wxActivateEvent &WXUNUSED(event) ) { } // called from docview.cpp
   void OnSize( wxSizeEvent &event );
   void OnCloseWindow( wxCloseEvent& event );
-  void OnIdle(wxIdleEvent& event );
 
   // implementation
   
@@ -111,6 +110,8 @@ public:
   void DoMenuUpdates();
   void DoMenuUpdates(wxMenu* menu);
 
+  virtual void OnInternalIdle();
+
   wxMenuBar    *m_frameMenuBar;
   wxStatusBar  *m_frameStatusBar;
   wxToolBar    *m_frameToolBar;
index 2169590c56339f3aafc2c9fadd9c3335f29b1b48..f7ca89a62db4cf7d3556319821000bbdee98f51c 100644 (file)
@@ -177,7 +177,6 @@ public:
   { wxPoint pt(ConvertDialogToPixels(wxPoint(sz.x, sz.y))); return wxSize(pt.x, pt.y); }
 
   void OnSize( wxSizeEvent &event );
-  void OnIdle( wxIdleEvent& event );
 
   virtual bool Show( bool show );
   virtual void Enable( bool enable );
@@ -316,22 +315,24 @@ public:
 
   // implementation
 
-          void        PreCreation( wxWindow *parent, wxWindowID id, const wxPoint &pos,
-                                   const wxSize &size, long style, const wxString &name );
-          void        PostCreation();
-  virtual GtkWidget  *GetConnectWidget();
-  virtual bool        IsOwnGtkWindow( GdkWindow *window );
-          void        ConnectWidget( GtkWidget *widget );
-
-          bool        HasVMT();
+  void PreCreation( wxWindow *parent, wxWindowID id, const wxPoint &pos,
+                    const wxSize &size, long style, const wxString &name );
+  void PostCreation();
+  
+  virtual GtkWidget* GetConnectWidget();
+  virtual bool IsOwnGtkWindow( GdkWindow *window );
+  void ConnectWidget( GtkWidget *widget );
 
-  virtual wxPoint     GetClientAreaOrigin() const;
-  virtual void        AdjustForParentClientOrigin( int& x, int& y, int sizeFlags );
+  bool HasVMT();
 
-          GtkStyle   *GetWidgetStyle();
-          void        SetWidgetStyle();
-  virtual void        ApplyWidgetStyle();
+  virtual wxPoint GetClientAreaOrigin() const;
+  virtual void AdjustForParentClientOrigin( int& x, int& y, int sizeFlags );
 
+  GtkStyle *GetWidgetStyle();
+  void SetWidgetStyle();
+  virtual void ApplyWidgetStyle();
+  
+  virtual void OnInternalIdle();
 
   wxWindow            *m_parent;
   wxList               m_children;
index cdbac91bc3aaa708777f84dd10f25ab46b1d8d6d..56c4b6ddc793cc313d58ef2ac81d0a32f1e3ba8e 100644 (file)
@@ -34,9 +34,11 @@ public:
     MyCanvas( wxWindow *parent, wxWindowID, const wxPoint &pos, const wxSize &size );
     ~MyCanvas();
     void OnPaint( wxPaintEvent &event );
+    void CreateAntiAliasedBitmap();
 
     wxBitmap  *my_horse;
     wxBitmap  *my_square;
+    wxBitmap  *my_anti;
 
     DECLARE_DYNAMIC_CLASS(MyCanvas)
     DECLARE_EVENT_TABLE()
@@ -107,12 +109,15 @@ MyCanvas::MyCanvas( wxWindow *parent, const wxWindowID id,
   
   image.LoadFile( dir + wxString("test.png"), wxBITMAP_TYPE_PNG );
   my_square = new wxBitmap( image.ConvertToBitmap() );
+  
+  CreateAntiAliasedBitmap();
 }
 
 MyCanvas::~MyCanvas()
 {
   delete my_horse;
   delete my_square;
+  delete my_anti;
 }
 
 void MyCanvas::OnPaint( wxPaintEvent &WXUNUSED(event) )
@@ -120,15 +125,65 @@ void MyCanvas::OnPaint( wxPaintEvent &WXUNUSED(event) )
   wxPaintDC dc( this );
   PrepareDC( dc );
 
-  dc.DrawText( "Loaded image", 30, 100 );
-  if (my_square->Ok()) dc.DrawBitmap( *my_square, 30, 120 );
+  dc.DrawText( "Loaded image", 30, 10 );
+  if (my_square->Ok()) dc.DrawBitmap( *my_square, 30, 30 );
 
-  dc.DrawText( "Drawn directly", 150, 100 );
+  dc.DrawText( "Drawn directly", 150, 10 );
   dc.SetBrush( wxBrush( "orange", wxSOLID ) );
   dc.SetPen( *wxWHITE_PEN );
-  dc.DrawRectangle( 150, 120, 100, 100 );
+  dc.DrawRectangle( 150, 30, 100, 100 );
+
+  if (my_horse->Ok()) dc.DrawBitmap( *my_horse, 30, 140 );
+  
+  if (my_anti->Ok()) dc.DrawBitmap( *my_anti, 250, 140 );
+}
 
-  if (my_horse->Ok()) dc.DrawBitmap( *my_horse, 30, 240 );
+void MyCanvas::CreateAntiAliasedBitmap()
+{
+  wxBitmap bitmap( 300, 300 );
+  wxMemoryDC dc;
+  dc.SelectObject( bitmap );
+  
+  dc.SetPen( *wxTRANSPARENT_PEN );
+  
+  dc.Clear();
+  
+  dc.SetFont( wxFont( 24, wxDECORATIVE, wxDEFAULT, wxDEFAULT ) );
+  dc.SetTextForeground( "RED" );
+  dc.DrawText( "This is anti-aliased Text.", 20, 20 );
+  dc.DrawText( "And a Rectangle.", 20, 60 );
+  
+  dc.SetBrush( *wxRED_BRUSH );
+  dc.DrawRoundedRectangle( 20, 100, 200, 180, 20 );
+  
+  wxImage original( bitmap );
+  wxImage anti( 150, 150 );
+  
+  /* This is quite slow, but safe. Use wxImage::GetData() for speed instead. */
+  
+  for (int y = 1; y < 149; y++)
+    for (int x = 1; x < 149; x++)
+    {
+       int red = original.GetRed( x*2, y*2 ) +
+                 original.GetRed( x*2-1, y*2 ) + 
+                 original.GetRed( x*2, y*2+1 ) + 
+                 original.GetRed( x*2+1, y*2+1 );
+       red = red/4; 
+       
+       int green = original.GetGreen( x*2, y*2 ) +
+                   original.GetGreen( x*2-1, y*2 ) + 
+                   original.GetGreen( x*2, y*2+1 ) + 
+                   original.GetGreen( x*2+1, y*2+1 );
+       green = green/4; 
+       
+       int blue = original.GetBlue( x*2, y*2 ) +
+                  original.GetBlue( x*2-1, y*2 ) + 
+                  original.GetBlue( x*2, y*2+1 ) + 
+                  original.GetBlue( x*2+1, y*2+1 );
+       blue = blue/4; 
+       anti.SetRGB( x, y, red, green, blue );
+    }
+  my_anti = new wxBitmap( anti.ConvertToBitmap() );
 }
 
 // MyFrame
index 7b938e76671dc60dbb27fae6c25ad7d987baa4b9..0df66f47b8aa14f080c97599f04409a063745f57 100644 (file)
@@ -302,6 +302,9 @@ bool wxApp::SendIdleEvents( wxWindow* win )
 
     wxIdleEvent event;
     event.SetEventObject(win);
+    
+    win->OnInternalIdle();
+    
     win->ProcessEvent(event);
 
     if (event.MoreRequested())
index 934ea9d990e2af54d5e212675f43dee610c66bec..e47d0a2613b02fee0c4a448cf67c1ac145577054 100644 (file)
@@ -101,7 +101,6 @@ static gint gtk_frame_configure_callback( GtkWidget *WXUNUSED(widget), GdkEventC
 BEGIN_EVENT_TABLE(wxFrame, wxWindow)
     EVT_SIZE(wxFrame::OnSize)
     EVT_CLOSE(wxFrame::OnCloseWindow)
-    EVT_IDLE(wxFrame::OnIdle)
 END_EVENT_TABLE()
 
 IMPLEMENT_DYNAMIC_CLASS(wxFrame,wxWindow)
@@ -457,7 +456,7 @@ void wxFrame::GtkOnSize( int WXUNUSED(x), int WXUNUSED(y), int width, int height
     m_resizing = FALSE;
 }
 
-void wxFrame::OnIdle(wxIdleEvent& WXUNUSED(event) )
+void wxFrame::OnInternalIdle()
 {
     if (!m_sizeSet)
         GtkOnSize( m_x, m_y, m_width, m_height );
index 5a527820d616836de767841bc17bac39673e8cfe..936b4a76a283f53f4859a94017a050a75455cc08 100644 (file)
@@ -1257,7 +1257,6 @@ BEGIN_EVENT_TABLE(wxWindow, wxEvtHandler)
     EVT_SIZE(wxWindow::OnSize)
     EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged)
     EVT_INIT_DIALOG(wxWindow::OnInitDialog)
-    EVT_IDLE(wxWindow::OnIdle)
     EVT_KEY_DOWN(wxWindow::OnKeyDown)
 END_EVENT_TABLE()
 
@@ -1791,6 +1790,11 @@ void wxWindow::SetSize( int x, int y, int width, int height, int sizeFlags )
     m_resizing = FALSE;
 }
 
+void wxWindow::OnInternalIdle()
+{
+    UpdateWindowUI();
+}
+
 void wxWindow::SetSize( int width, int height )
 {
     SetSize( -1, -1, width, height, wxSIZE_USE_EXISTING );
@@ -3449,7 +3453,3 @@ void wxWindow::GetPositionConstraint(int *x, int *y) const
     GetPosition(x, y);
 }
 
-void wxWindow::OnIdle(wxIdleEvent& WXUNUSED(event) )
-{
-    UpdateWindowUI();
-}
index 7b938e76671dc60dbb27fae6c25ad7d987baa4b9..0df66f47b8aa14f080c97599f04409a063745f57 100644 (file)
@@ -302,6 +302,9 @@ bool wxApp::SendIdleEvents( wxWindow* win )
 
     wxIdleEvent event;
     event.SetEventObject(win);
+    
+    win->OnInternalIdle();
+    
     win->ProcessEvent(event);
 
     if (event.MoreRequested())
index 934ea9d990e2af54d5e212675f43dee610c66bec..e47d0a2613b02fee0c4a448cf67c1ac145577054 100644 (file)
@@ -101,7 +101,6 @@ static gint gtk_frame_configure_callback( GtkWidget *WXUNUSED(widget), GdkEventC
 BEGIN_EVENT_TABLE(wxFrame, wxWindow)
     EVT_SIZE(wxFrame::OnSize)
     EVT_CLOSE(wxFrame::OnCloseWindow)
-    EVT_IDLE(wxFrame::OnIdle)
 END_EVENT_TABLE()
 
 IMPLEMENT_DYNAMIC_CLASS(wxFrame,wxWindow)
@@ -457,7 +456,7 @@ void wxFrame::GtkOnSize( int WXUNUSED(x), int WXUNUSED(y), int width, int height
     m_resizing = FALSE;
 }
 
-void wxFrame::OnIdle(wxIdleEvent& WXUNUSED(event) )
+void wxFrame::OnInternalIdle()
 {
     if (!m_sizeSet)
         GtkOnSize( m_x, m_y, m_width, m_height );
index 5a527820d616836de767841bc17bac39673e8cfe..936b4a76a283f53f4859a94017a050a75455cc08 100644 (file)
@@ -1257,7 +1257,6 @@ BEGIN_EVENT_TABLE(wxWindow, wxEvtHandler)
     EVT_SIZE(wxWindow::OnSize)
     EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged)
     EVT_INIT_DIALOG(wxWindow::OnInitDialog)
-    EVT_IDLE(wxWindow::OnIdle)
     EVT_KEY_DOWN(wxWindow::OnKeyDown)
 END_EVENT_TABLE()
 
@@ -1791,6 +1790,11 @@ void wxWindow::SetSize( int x, int y, int width, int height, int sizeFlags )
     m_resizing = FALSE;
 }
 
+void wxWindow::OnInternalIdle()
+{
+    UpdateWindowUI();
+}
+
 void wxWindow::SetSize( int width, int height )
 {
     SetSize( -1, -1, width, height, wxSIZE_USE_EXISTING );
@@ -3449,7 +3453,3 @@ void wxWindow::GetPositionConstraint(int *x, int *y) const
     GetPosition(x, y);
 }
 
-void wxWindow::OnIdle(wxIdleEvent& WXUNUSED(event) )
-{
-    UpdateWindowUI();
-}